Skip to content

Commit

Permalink
collect names util function
Browse files Browse the repository at this point in the history
  • Loading branch information
ckrause committed Dec 17, 2023
1 parent 31fa07b commit 12c1f82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/form/expression_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,13 @@ bool ExpressionUtil::canBeNegative(const Expression& e) {
}
return false;
}

void ExpressionUtil::collectNames(const Expression& e, Expression::Type type,
std::set<std::string>& target) {
if (e.type == type) {
target.insert(e.name);
}
for (auto c : e.children) {
collectNames(*c, type, target);
}
}
5 changes: 5 additions & 0 deletions src/form/expression_util.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <set>

#include "form/expression.hpp"

class ExpressionUtil {
Expand All @@ -15,4 +17,7 @@ class ExpressionUtil {
static bool isSimpleFunction(const Expression& e, bool strict = true);

static bool canBeNegative(const Expression& e);

static void collectNames(const Expression& e, Expression::Type type,
std::set<std::string>& target);
};

0 comments on commit 12c1f82

Please sign in to comment.