Bug 471621 - Have CPPASTAlignmentSpecifier implement IASTAmbiguityParent
authorNathan Ridge <zeratul976@hotmail.com>
Fri, 3 Jul 2015 22:55:06 +0000 (18:55 -0400)
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>
Tue, 7 Jul 2015 19:59:38 +0000 (15:59 -0400)
This is necessary because the expression inside the alignment specifier
may be an ambiguous expression.

Change-Id: Ibb38410fea21251d866ddc58de6dc29b73623732
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAlignmentSpecifier.java

index 3572b97..81fc46e 100644 (file)
@@ -13,10 +13,13 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
 import org.eclipse.cdt.core.dom.ast.ASTVisitor;
 import org.eclipse.cdt.core.dom.ast.IASTAlignmentSpecifier;
 import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
 import org.eclipse.cdt.core.dom.ast.IASTTypeId;
 import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
 
-public class CPPASTAlignmentSpecifier extends ASTNode implements IASTAlignmentSpecifier {
+public class CPPASTAlignmentSpecifier extends ASTNode implements IASTAlignmentSpecifier,
+               IASTAmbiguityParent {
        // Precisely one of these is null.
        private IASTExpression fExpression;
        private IASTTypeId fTypeId;
@@ -66,4 +69,17 @@ public class CPPASTAlignmentSpecifier extends ASTNode implements IASTAlignmentSp
                }
                return fTypeId.accept(visitor);
        }
+
+       @Override
+       public void replace(IASTNode child, IASTNode other) {
+               if (child instanceof IASTExpression && other instanceof IASTExpression && fExpression == child) {
+                       fExpression = (IASTExpression) other;
+                       other.setParent(child.getParent());
+                       other.setPropertyInParent(child.getPropertyInParent());
+               } else if (child instanceof IASTTypeId && other instanceof IASTTypeId && fTypeId == child) {
+                       fTypeId = (IASTTypeId) other;
+                       other.setParent(child.getParent());
+                       other.setPropertyInParent(child.getPropertyInParent());
+               }
+       }
 }