Skip to content

Commit

Permalink
Use getChildren() method instead of accessing children vector directly
Browse files Browse the repository at this point in the history
  • Loading branch information
marcauberer committed Jan 5, 2025
1 parent 482a65f commit 5b86ec7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/ast/ASTNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,12 @@ bool FctCallNode::hasReturnValueReceiver() const {
const ASTNode *node = parent;
while (!node->isAssignExpr()) {
// As soon as we have a node with more than one child, we know that the return value is used
if (node->children.size() > 1)
if (node->getChildren().size() > 1)
return true;
node = node->parent;
}
// Also check the condition of the assign expression
return node->children.size() > 1 || !node->parent->isExprStmt();
return node->getChildren().size() > 1 || !node->parent->isExprStmt();
}

bool LambdaFuncNode::returnsOnAllControlPaths(bool *overrideUnreachable) const {
Expand Down
10 changes: 8 additions & 2 deletions src/ast/ASTNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ class ASTNode {
node->parent = this;
}

void resizeToNumberOfManifestations(size_t manifestationCount) { // NOLINT(misc-no-recursion)
ALWAYS_INLINE const std::vector<ASTNode *> &getChildren() const { return children; }

void resizeToNumberOfManifestations(const size_t manifestationCount) { // NOLINT(misc-no-recursion)
// Resize children
for (ASTNode *child : children) {
for (ASTNode *child : getChildren()) {
assert(child != nullptr);
child->resizeToNumberOfManifestations(manifestationCount);
}
Expand Down Expand Up @@ -105,18 +107,21 @@ class ASTNode {
[[nodiscard]] const QualType &getEvaluatedSymbolType(const size_t idx) const { // NOLINT(misc-no-recursion)
if (!symbolTypes.empty() && !symbolTypes.at(idx).is(TY_INVALID))
return symbolTypes.at(idx);
const std::vector<ASTNode *> &children = getChildren();
if (children.size() != 1)
throw CompilerError(INTERNAL_ERROR, "Cannot deduce evaluated symbol type");
return children.front()->getEvaluatedSymbolType(idx);
}

[[nodiscard]] virtual bool hasCompileTimeValue() const { // NOLINT(misc-no-recursion)
const std::vector<ASTNode *> &children = getChildren();
if (children.size() != 1)
return false;
return children.front()->hasCompileTimeValue();
}

[[nodiscard]] virtual CompileTimeValue getCompileTimeValue() const { // NOLINT(misc-no-recursion)
const std::vector<ASTNode *> &children = getChildren();
if (children.size() != 1)
return {};
return children.front()->getCompileTimeValue();
Expand All @@ -125,6 +130,7 @@ class ASTNode {
[[nodiscard]] std::string getErrorMessage() const;

[[nodiscard]] virtual bool returnsOnAllControlPaths(bool *doSetPredecessorsUnreachable) const { // NOLINT(misc-no-recursion)
const std::vector<ASTNode *> &children = getChildren();
return children.size() == 1 && children.front()->returnsOnAllControlPaths(doSetPredecessorsUnreachable);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ast/AbstractASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace spice::compiler {
std::any AbstractASTVisitor::visit(ASTNode *node) { return node->accept(this); }

std::any AbstractASTVisitor::visitChildren(ASTNode *node) {
for (ASTNode *child : node->children) {
for (ASTNode *child : node->getChildren()) {
assert(child != nullptr);
child->accept(this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ast/ParallelizableASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace spice::compiler {
std::any ParallelizableASTVisitor::visit(const ASTNode *node) { return node->accept(this); }

std::any ParallelizableASTVisitor::visitChildren(const ASTNode *node) {
for (const ASTNode *child : node->children)
for (const ASTNode *child : node->getChildren())
if (child != nullptr)
child->accept(this);
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/visualizer/ASTVisualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class ASTVisualizer final : CompilerPass, public AbstractASTVisitor {
parentNodeIds.push(nodeId); // Set parentNodeId for children

// Visit all the children
for (ASTNode *child : node->children)
for (ASTNode *child : node->getChildren())
if (child != nullptr)
result << " " << std::any_cast<std::string>(visit(child));

Expand Down

0 comments on commit 5b86ec7

Please sign in to comment.