[ClavaWeaver] Fixes CxxAttributes.isInsideHeader()
@@ -71,25 +71,32 @@ public class CxxAttributes {
* CompoundStmt
*/
private static boolean isInsideHeader(ClavaNode node, Collection<Class<?>> headerClasses) {
- ClavaNode currentNode = node;
- while (currentNode != null) {
- ClavaNode nodeToTest = currentNode;
- boolean isHeader = headerClasses.stream()
- .filter(aClass -> aClass.isInstance(nodeToTest))
- .findFirst()
- .isPresent();
- // If we find an instance, is inside header
- if (isHeader) {
- return true;
+
+ // If node is a header or a CompoundStmt, return immediately
+ if(node instanceof CompoundStmt || isHeader(node, headerClasses)) {
+ return false;
}
+ ClavaNode currentNode = node.getParent();
+
+
+ while (currentNode != null) {
// If we find a CompoundStmt before the loop, is not in a loop header
if (currentNode instanceof CompoundStmt) {
return false;
}
+ ClavaNode nodeToTest = currentNode;
+
+ boolean isHeader = isHeader(nodeToTest, headerClasses);
+
+ // If we find an instance, is inside header
+ if (isHeader) {
+ return true;
+ }
+
currentNode = currentNode.getParent();
}
@@ -97,6 +104,14 @@ public class CxxAttributes {
return false;
}
+ private static boolean isHeader(ClavaNode nodeToTest, Collection<Class<?>> headerClasses) {
+ boolean isHeader = headerClasses.stream()
+ .filter(aClass -> aClass.isInstance(nodeToTest))
+ .findFirst()
+ .isPresent();
+ return isHeader;
+ }
+
public static Optional<? extends ClavaNode> getCurrentRegion(ClavaNode node) {
// Check if top region
