[ClangAstParser] Adds restriction about when variable can move to TagDecl
Variables that move into TagDecl must be of the same class;
@@ -123,10 +123,17 @@ public class MoveDeclsToTagDecl implements SimplePreClavaRule {
return true;
}
- // Check if another variable declaration of the same TagDecl
+ // Check if another variable declaration of the same TagDecl,
+ // and if of the same class type
// If so, keep going backwards
+ var currentSiblingNamedDecl = getNamedDeclWithType(currentSibling);
+ if (currentSiblingNamedDecl.isPresent()) {
+
+ // Must be of the same class
+ if (!currentSiblingNamedDecl.get().getClass().equals(decl.getClass())) {
+ return false;
+ }
- if (getNamedDeclWithType(currentSibling).isPresent()) {
var siblingTagDecl = getTagDecl((NamedDecl) currentSibling);
if (siblingTagDecl != null && tagDecl.equals(siblingTagDecl)) {
continue;
