[ClavaWeaver] Adds example node filter for Lara Common Language
@@ -40,6 +40,7 @@ import pt.up.fe.specs.clava.ClavaLog;
import pt.up.fe.specs.clava.ClavaNode;
import pt.up.fe.specs.clava.ClavaOptions;
import pt.up.fe.specs.clava.Include;
+import pt.up.fe.specs.clava.ast.decl.FunctionDecl;
import pt.up.fe.specs.clava.ast.extra.App;
import pt.up.fe.specs.clava.ast.extra.TranslationUnit;
import pt.up.fe.specs.clava.context.ClavaContext;
@@ -2011,7 +2012,36 @@ public class CxxWeaver extends ACxxWeaver {
@Override
public AstMethods getAstMethods() {
+ // var temp = getFactory().builtinType("int");
+ // temp.getChildren().stream()
+ // .filter(CxxWeaver::lclFilter)
+ // .collect(Collectors.toList());
+
return new TreeNodeAstMethods<>(this, ClavaNode.class, node -> CxxJoinpoints.create(node),
node -> ClavaCommonLanguage.getJoinPointName(node), node -> node.getScopeChildren());
}
+
+ public static boolean lclFilter(ClavaNode node) {
+ // Function
+ if (node instanceof FunctionDecl) {
+ var functionDecl = (FunctionDecl) node;
+ var declaration = functionDecl.getDeclaration();
+ var definition = functionDecl.getDefinition();
+
+ SpecsCheck.checkArgument(declaration.isPresent() || definition.isPresent(),
+ () -> "Expected at least one of them to be present");
+
+ // XOR, if only one of them is present, current node must be one of them
+ if (declaration.isEmpty() ^ definition.isEmpty()) {
+ return true;
+ }
+
+ // Both are present, only return current node if it is the definition
+ // Using == since they must be the same object
+ return definition.get() == node;
+ }
+
+ // No other cases
+ return true;
+ }
}
