diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java index 866ad77d1cb..d8b206e7d17 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java @@ -138,6 +138,9 @@ public class AST2BaseTest extends TestCase { assertEquals( CPPVisitor.getProblems(tu).length, 0 ); assertEquals( tu.getPreprocessorProblems().length, 0 ); } + if( expectNoProblems ) + assertEquals( 0, tu.getPreprocessorProblems().length ); + return tu; } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java index 54118d9cf82..0e29707de26 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java @@ -453,46 +453,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest { } } - /** - [--Start Example(CPP 8.5.3-1): - int g(int); - void f() - { - int i; - int& r = i; // r refers to i - r = 1; // the value of i becomes 1 - int* p = &r; // p points to i - int& rr = r; // rr refers to what r refers to, that is, to i - int (&rg)(int) = g; // rg refers to the function g - rg(i); //calls function g - int a[3]; - int (&ra)[3] = a; // ra refers to the array a - ra[1] = i; // modifies a[1] - } - --End Example] - */ - public void test8_5_3s1() { // TODO raised bug 90648 - StringBuffer buffer = new StringBuffer(); - buffer.append("int g(int);\n"); //$NON-NLS-1$ - buffer.append("void f()\n"); //$NON-NLS-1$ - buffer.append("{\n"); //$NON-NLS-1$ - buffer.append("int i;\n"); //$NON-NLS-1$ - buffer.append("int& r = i; // r refers to i\n"); //$NON-NLS-1$ - buffer.append("r = 1; // the value of i becomes 1\n"); //$NON-NLS-1$ - buffer.append("int* p = &r; // p points to i\n"); //$NON-NLS-1$ - buffer.append("int& rr = r; // rr refers to what r refers to, that is, to i\n"); //$NON-NLS-1$ - buffer.append("int (&rg)(int) = g; // rg refers to the function g\n"); //$NON-NLS-1$ - buffer.append("rg(i); //calls function g\n"); //$NON-NLS-1$ - buffer.append("int a[3];\n"); //$NON-NLS-1$ - buffer.append("int (&ra)[3] = a; // ra refers to the array a\n"); //$NON-NLS-1$ - buffer.append("ra[1] = i; // modifies a[1]\n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); - assertTrue(false); - } catch (Exception e) { - } - } /** [--Start Example(CPP 10.2-3b): diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java index 8cf5352a9b3..ec65bbe5498 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java @@ -1584,10 +1584,10 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { StringBuffer buffer = new StringBuffer(); buffer.append("int foo() {\n"); //$NON-NLS-1$ buffer.append("int x=5;\n"); //$NON-NLS-1$ - buffer.append("while (-­x >= 0)\n"); //$NON-NLS-1$ + buffer.append("while (--x >= 0)\n"); //$NON-NLS-1$ buffer.append("int i;\n"); //$NON-NLS-1$ buffer.append("//can be equivalently rewritten as\n"); //$NON-NLS-1$ - buffer.append("while (-­x >= 0) {\n"); //$NON-NLS-1$ + buffer.append("while (--x >= 0) {\n"); //$NON-NLS-1$ buffer.append("int i;\n"); //$NON-NLS-1$ buffer.append("}\n"); //$NON-NLS-1$ buffer.append("}\n"); //$NON-NLS-1$ @@ -1711,7 +1711,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { public void test6_8s1() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("int foo() {\n"); //$NON-NLS-1$ - buffer.append("T(a)­>m = 7; // expressionstatement\n"); //$NON-NLS-1$ + buffer.append("T(a)->m = 7; // expressionstatement\n"); //$NON-NLS-1$ buffer.append("T(a)++; //expressionstatement\n"); //$NON-NLS-1$ buffer.append("T(a,5)< 0) + clearCache(names[0]); + } + int bestIndex = 0; + int bestValue = issues[0]; + for (int i = 1; i < issues.length; ++i) { + if (issues[i] < bestValue) { + bestIndex = i; + bestValue = issues[i]; + } + } + + return reduceAmbiguity(visitor, nodez, bestIndex); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java new file mode 100644 index 00000000000..0c5293c0c03 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java @@ -0,0 +1,35 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression; + +public class CPPASTAmbiguousExpression extends CPPASTAmbiguity implements + IASTAmbiguousExpression { + + private IASTExpression [] exp = new IASTExpression[2]; + + public void addExpression(IASTExpression e) { + exp = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, exp, e ); + } + + public IASTExpression[] getExpressions() { + return (IASTExpression[]) ArrayUtil.removeNulls( IASTExpression.class, exp ); + } + + protected IASTNode[] getNodes() { + return getExpressions(); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java new file mode 100644 index 00000000000..e051dd0bd29 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java @@ -0,0 +1,34 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement; + +public class CPPASTAmbiguousStatement extends CPPASTAmbiguity implements + IASTAmbiguousStatement { + + private IASTStatement [] stmts = new IASTStatement[2]; + + public void addStatement(IASTStatement s) { + stmts = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, stmts, s ); + } + + public IASTStatement[] getStatements() { + return (IASTStatement[]) ArrayUtil.removeNulls( IASTStatement.class, stmts ); + } + + protected IASTNode[] getNodes() { + return getStatements(); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java index 8dc559cd2aa..9d4ca742fbd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java @@ -13,33 +13,48 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTArrayModifier extends CPPASTNode implements - IASTArrayModifier { + IASTArrayModifier, IASTAmbiguityParent { private IASTExpression exp; - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.IASTArrayModifier#getConstantExpression() */ public IASTExpression getConstantExpression() { return exp; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.IASTArrayModifier#setConstantExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) */ public void setConstantExpression(IASTExpression expression) { exp = expression; } - - public boolean accept( ASTVisitor action ){ - if( exp != null ) - if( !exp.accept( action ) ) return false; - + + public boolean accept(ASTVisitor action) { + if (exp != null) + if (!exp.accept(action)) + return false; + return true; } + + public void replace(IASTNode child, IASTNode other) { + if (child == exp) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + exp = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java index 7fc34003de5..d5d09f7c93f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java @@ -13,12 +13,14 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTArraySubscriptExpression extends CPPASTNode implements - IASTArraySubscriptExpression { + IASTArraySubscriptExpression, IASTAmbiguityParent { private IASTExpression subscriptExp; private IASTExpression arrayExpression; @@ -66,4 +68,19 @@ public class CPPASTArraySubscriptExpression extends CPPASTNode implements return true; } + public void replace(IASTNode child, IASTNode other) { + if( child == subscriptExp ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + subscriptExp = (IASTExpression) other; + } + if( child == arrayExpression ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + arrayExpression = (IASTExpression) other; + } + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java index 63f34a1c23b..859f2b6b0e8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java @@ -12,13 +12,15 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTBinaryExpression extends CPPASTNode implements - ICPPASTBinaryExpression { + ICPPASTBinaryExpression, IASTAmbiguityParent { private int op; private IASTExpression operand1; @@ -80,4 +82,19 @@ public class CPPASTBinaryExpression extends CPPASTNode implements return true; } + public void replace(IASTNode child, IASTNode other) { + if( child == operand1 ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + operand1 = (IASTExpression) other; + } + if( child == operand2 ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + operand2 = (IASTExpression) other; + } + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java index 9ce0d79d7ff..b7277fef9a8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java @@ -13,12 +13,14 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTCaseStatement extends CPPASTNode implements - IASTCaseStatement { + IASTCaseStatement, IASTAmbiguityParent { private IASTExpression expression; /* (non-Javadoc) @@ -47,4 +49,13 @@ public class CPPASTCaseStatement extends CPPASTNode implements return true; } + public void replace(IASTNode child, IASTNode other) { + if( child == expression ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + expression = (IASTExpression) other; + } + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java index 97ec73610bb..85885a14ae7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java @@ -12,14 +12,16 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTCatchHandler extends CPPASTNode implements - ICPPASTCatchHandler { + ICPPASTCatchHandler, IASTAmbiguityParent { private boolean isCatchAll; private IASTStatement body; @@ -79,4 +81,13 @@ public class CPPASTCatchHandler extends CPPASTNode implements if( body != null ) if( !body.accept( action ) ) return false; return true; } + + public void replace(IASTNode child, IASTNode other) { + if( body == child ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + body = (IASTStatement) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java index 927827e3667..d3ebca85ffd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java @@ -12,15 +12,17 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTCompoundStatement extends CPPASTNode implements - IASTCompoundStatement { + IASTCompoundStatement, IASTAmbiguityParent { private int currentIndex = 0; private void removeNullStatements() { @@ -94,4 +96,18 @@ public class CPPASTCompoundStatement extends CPPASTNode implements } return true; } + + public void replace(IASTNode child, IASTNode other) { + IASTStatement [] s = getStatements(); + for( int i = 0; i < s.length; ++i ) + { + if( s[i] == child ) + { + other.setParent( s[i].getParent() ); + other.setPropertyInParent( s[i].getPropertyInParent() ); + s[i] = (IASTStatement) other; + break; + } + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java index 9130b62bd6c..7277f122831 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java @@ -13,12 +13,14 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTConditionalExpression extends CPPASTNode implements - IASTConditionalExpression { + IASTConditionalExpression, IASTAmbiguityParent { private IASTExpression condition; private IASTExpression negative; private IASTExpression postive; @@ -79,4 +81,25 @@ public class CPPASTConditionalExpression extends CPPASTNode implements if( negative != null ) if( !negative.accept( action ) ) return false; return true; } + + public void replace(IASTNode child, IASTNode other) { + if( child == condition ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + condition = (IASTExpression) other; + } + if( child == postive ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + postive = (IASTExpression) other; + } + if( child == negative ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + negative = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java index 20155fb37df..c19fd92b0e5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java @@ -13,56 +13,82 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTConstructorChainInitializer extends CPPASTNode implements - ICPPASTConstructorChainInitializer { + ICPPASTConstructorChainInitializer, IASTAmbiguityParent { private IASTName name; + private IASTExpression value; - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer#getMemberInitializerId() */ public IASTName getMemberInitializerId() { return name; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer#setMemberInitializerId(org.eclipse.cdt.core.dom.ast.IASTName) */ public void setMemberInitializerId(IASTName name) { this.name = name; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer#getInitializerValue() */ public IASTExpression getInitializerValue() { return value; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer#setInitializerValue(org.eclipse.cdt.core.dom.ast.IASTExpression) */ public void setInitializerValue(IASTExpression expression) { value = expression; } - public boolean accept( ASTVisitor action ){ - if( name != null ) if( !name.accept( action ) ) return false; - if( value != null ) if( !value.accept( action ) ) return false; + public boolean accept(ASTVisitor action) { + if (name != null) + if (!name.accept(action)) + return false; + if (value != null) + if (!value.accept(action)) + return false; return true; } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTNameOwner#getRoleForName(org.eclipse.cdt.core.dom.ast.IASTName) - */ - public int getRoleForName(IASTName n) { - if( name == n ) return r_reference; - return r_unclear; - } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.IASTNameOwner#getRoleForName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public int getRoleForName(IASTName n) { + if (name == n) + return r_reference; + return r_unclear; + } + + public void replace(IASTNode child, IASTNode other) { + if (child == value) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + value = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java index 977131443c9..98d579aa3cb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java @@ -13,12 +13,14 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDoStatement; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ -public class CPPASTDoStatement extends CPPASTNode implements IASTDoStatement { +public class CPPASTDoStatement extends CPPASTNode implements IASTDoStatement, IASTAmbiguityParent { private IASTStatement body; private IASTExpression condition; @@ -62,4 +64,19 @@ public class CPPASTDoStatement extends CPPASTNode implements IASTDoStatement { if( condition != null ) if( !condition.accept( action ) ) return false; return true; } + + public void replace(IASTNode child, IASTNode other) { + if( body == child ) + { + other.setPropertyInParent( body.getPropertyInParent() ); + other.setParent( body.getParent() ); + body = (IASTStatement) other; + } + if( child == condition ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + condition = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java index 6c4754c64bb..4d8404be39b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java @@ -13,12 +13,14 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ -public class CPPASTEnumerator extends CPPASTNode implements IASTEnumerator { +public class CPPASTEnumerator extends CPPASTNode implements IASTEnumerator, IASTAmbiguityParent { private IASTName name; private IASTExpression value; @@ -71,4 +73,13 @@ public class CPPASTEnumerator extends CPPASTNode implements IASTEnumerator { return r_declaration; return r_reference; } + + public void replace(IASTNode child, IASTNode other) { + if( child == value ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + value = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java index 16d9ab6ab7f..3075040a449 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java @@ -13,12 +13,14 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpressionList; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTExpressionList extends CPPASTNode implements - IASTExpressionList { + IASTExpressionList, IASTAmbiguityParent { /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTExpressionList#getExpressions() */ @@ -83,4 +85,15 @@ public class CPPASTExpressionList extends CPPASTNode implements return true; } + + public void replace(IASTNode child, IASTNode other) { + IASTExpression[] ez = getExpressions(); + for (int i = 0; i < ez.length; ++i) { + if (child == ez[i]) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + ez[i] = (IASTExpression) other; + } + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java index 3387d429ca1..60bd9fd4234 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java @@ -13,12 +13,14 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTExpressionStatement extends CPPASTNode implements - IASTExpressionStatement { + IASTExpressionStatement, IASTAmbiguityParent { private IASTExpression expression; /* (non-Javadoc) @@ -47,4 +49,13 @@ public class CPPASTExpressionStatement extends CPPASTNode implements return true; } + public void replace(IASTNode child, IASTNode other) { + if( child == expression ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + expression = (IASTExpression) other; + } + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDeclarator.java index 1e99c13346a..d419ddf5f78 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDeclarator.java @@ -14,12 +14,14 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; import org.eclipse.cdt.core.dom.ast.IASTInitializer; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTFieldDeclarator extends CPPASTDeclarator implements - IASTFieldDeclarator { + IASTFieldDeclarator, IASTAmbiguityParent { private IASTExpression bitField; @@ -45,4 +47,14 @@ public class CPPASTFieldDeclarator extends CPPASTDeclarator implements return true; } + public void replace(IASTNode child, IASTNode other) { + if( child == bitField ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + bitField = (IASTExpression) other; + } + + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java index c309ce26a8a..a553a1ed6ed 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java @@ -13,13 +13,15 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTFieldReference extends CPPASTNode implements - ICPPASTFieldReference { + ICPPASTFieldReference, IASTAmbiguityParent { private boolean isTemplate; private IASTExpression owner; @@ -105,5 +107,14 @@ public class CPPASTFieldReference extends CPPASTNode implements return r_unclear; } + public void replace(IASTNode child, IASTNode other) { + if( child == owner ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + owner = (IASTExpression) other; + } + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java index df329de0b1b..7f0122986eb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java @@ -14,13 +14,15 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTForStatement; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ -public class CPPASTForStatement extends CPPASTNode implements IASTForStatement { +public class CPPASTForStatement extends CPPASTNode implements IASTForStatement, IASTAmbiguityParent { private IScope scope = null; private IASTExpression initialExpression; @@ -124,4 +126,31 @@ public class CPPASTForStatement extends CPPASTNode implements IASTForStatement { if( body != null ) if( !body.accept( action ) ) return false; return true; } + + public void replace(IASTNode child, IASTNode other) { + if( body == child ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + body = (IASTStatement) other; + } + if( child == condition ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + condition = (IASTExpression) other; + } + if( child == iterationExpression ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + iterationExpression = (IASTExpression) other; + } + if( child == initialExpression ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + initialExpression = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java index aec89f36b71..f3b11009631 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java @@ -13,12 +13,14 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTFunctionCallExpression extends CPPASTNode implements - IASTFunctionCallExpression { + IASTFunctionCallExpression, IASTAmbiguityParent { private IASTExpression functionName; private IASTExpression parameter; @@ -63,4 +65,20 @@ public class CPPASTFunctionCallExpression extends CPPASTNode implements if( parameter != null ) if( !parameter.accept( action ) ) return false; return true; } + + public void replace(IASTNode child, IASTNode other) { + if( child == functionName ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + functionName = (IASTExpression) other; + } + if( child == parameter ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + parameter = (IASTExpression) other; + } + + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java index cefb57be037..7f26aafa28e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java @@ -14,15 +14,17 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTFunctionDefinition extends CPPASTNode implements - IASTFunctionDefinition { + IASTFunctionDefinition, IASTAmbiguityParent { private IASTDeclSpecifier declSpecifier; private IASTFunctionDeclarator declarator; @@ -92,4 +94,13 @@ public class CPPASTFunctionDefinition extends CPPASTNode implements return true; } + public void replace(IASTNode child, IASTNode other) { + if( bodyStatement == child ) + { + other.setPropertyInParent( bodyStatement.getPropertyInParent() ); + other.setParent( bodyStatement.getParent() ); + bodyStatement = (IASTStatement) other; + } + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java index e58c49b82b5..e06d5005d7e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java @@ -13,12 +13,14 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTIfStatement; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ -public class CPPASTIfStatement extends CPPASTNode implements IASTIfStatement { +public class CPPASTIfStatement extends CPPASTNode implements IASTIfStatement, IASTAmbiguityParent { private IASTExpression condition; private IASTStatement thenClause; private IASTStatement elseClause; @@ -78,4 +80,19 @@ public class CPPASTIfStatement extends CPPASTNode implements IASTIfStatement { if( elseClause != null ) if( !elseClause.accept( action ) ) return false; return true; } + + public void replace(IASTNode child, IASTNode other) { + if( thenClause == child ) + { + other.setParent( child.getParent() ); + other.setPropertyInParent( child.getPropertyInParent() ); + thenClause = (IASTStatement) other; + } + else if( elseClause == child ) + { + other.setParent( child.getParent() ); + other.setPropertyInParent( child.getPropertyInParent() ); + elseClause = (IASTStatement) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java index de58127ce80..8206af6afa5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java @@ -13,12 +13,14 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTInitializerExpression extends CPPASTNode implements - IASTInitializerExpression { + IASTInitializerExpression, IASTAmbiguityParent { private IASTExpression exp; @@ -48,4 +50,13 @@ public class CPPASTInitializerExpression extends CPPASTNode implements return true; } + public void replace(IASTNode child, IASTNode other) { + if( child == exp ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + exp = (IASTExpression) other; + } + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java index f301b76ee4f..841ff2a81ac 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java @@ -12,14 +12,16 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; 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.core.dom.ast.cpp.ICPPASTNewExpression; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTNewExpression extends CPPASTNode implements - ICPPASTNewExpression { + ICPPASTNewExpression, IASTAmbiguityParent { private boolean global; private IASTExpression placement; @@ -162,4 +164,20 @@ public class CPPASTNewExpression extends CPPASTNode implements if( initializer != null ) if( !initializer.accept( action ) ) return false; return true; } + + public void replace(IASTNode child, IASTNode other) { + if( child == placement ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + placement = (IASTExpression) other; + } + if( child == initializer ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + initializer = (IASTExpression) other; + } + + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java index 2b44d1f57ff..94441038695 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java @@ -12,38 +12,57 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTReturnStatement extends CPPASTNode implements - IASTReturnStatement { + IASTReturnStatement, IASTAmbiguityParent { private IASTExpression retValue; - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.IASTReturnStatement#getReturnValue() */ public IASTExpression getReturnValue() { return retValue; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.IASTReturnStatement#setReturnValue(org.eclipse.cdt.core.dom.ast.IASTExpression) */ public void setReturnValue(IASTExpression returnValue) { retValue = returnValue; } - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitStatements ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } - } - if( retValue != null ) if( !retValue.accept( action ) ) return false; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + if (retValue != null) + if (!retValue.accept(action)) + return false; return true; } + + public void replace(IASTNode child, IASTNode other) { + if (child == retValue) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + retValue = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java index 8607ac242b3..34cf9dff69a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java @@ -12,13 +12,15 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTSimpleTypeConstructorExpression extends CPPASTNode implements - ICPPASTSimpleTypeConstructorExpression { + ICPPASTSimpleTypeConstructorExpression, IASTAmbiguityParent { private int st; private IASTExpression init; @@ -63,4 +65,13 @@ public class CPPASTSimpleTypeConstructorExpression extends CPPASTNode implements if( init != null ) if( !init.accept( action ) ) return false; return true; } + + public void replace(IASTNode child, IASTNode other) { + if( child == init ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + init = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java index caae8586a8e..816b7e7b1aa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java @@ -12,14 +12,16 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTSwitchStatement extends CPPASTNode implements - IASTSwitchStatement { + IASTSwitchStatement, IASTAmbiguityParent { private IASTExpression controller; private IASTStatement body; @@ -64,4 +66,21 @@ public class CPPASTSwitchStatement extends CPPASTNode implements if( body != null ) if( !body.accept( action ) ) return false; return true; } + + public void replace(IASTNode child, IASTNode other) { + if( body == child ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + body = (IASTStatement) other; + } + if( child == controller ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + controller = (IASTExpression) other; + } + + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java index a2e52bcba28..412d2d402b6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java @@ -17,13 +17,12 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ -public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId { -// private static final char[] EMPTY_CHAR_ARRAY = { }; -// private static final String EMPTY_STRING = ""; //$NON-NLS-1$ +public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, IASTAmbiguityParent { private IASTName templateName; /* (non-Javadoc) @@ -184,4 +183,15 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId { public void setBinding(IBinding binding) { this.binding = binding; } + + public void replace(IASTNode child, IASTNode other) { + IASTNode[] ez = getTemplateArguments(); + for (int i = 0; i < ez.length; ++i) { + if (child == ez[i]) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + ez[i] = other; + } + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java index 89a2b2e361e..6baaee32441 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java @@ -13,15 +13,17 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTTemplatedTypeTemplateParameter extends CPPASTNode implements - ICPPASTTemplatedTypeTemplateParameter { + ICPPASTTemplatedTypeTemplateParameter, IASTAmbiguityParent { public ICPPASTTemplateParameter[] getTemplateParameters() { if( parameters == null ) return ICPPASTTemplateParameter.EMPTY_TEMPLATEPARAMETER_ARRAY; @@ -119,4 +121,13 @@ public class CPPASTTemplatedTypeTemplateParameter extends CPPASTNode implements return r_declaration; return r_unclear; } + + public void replace(IASTNode child, IASTNode other) { + if( child == defaultValue ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + defaultValue = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java index 97343125b23..4d4c17d3583 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java @@ -11,15 +11,17 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTTryBlockStatement extends CPPASTNode implements - ICPPASTTryBlockStatement { + ICPPASTTryBlockStatement, IASTAmbiguityParent { /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator#addCatchHandler(org.eclipse.cdt.core.dom.ast.IASTStatement) @@ -97,4 +99,12 @@ public class CPPASTTryBlockStatement extends CPPASTNode implements return true; } + public void replace(IASTNode child, IASTNode other) { + if( tryBody == child ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + tryBody = (IASTStatement) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java index 6d0ae15d063..48ef90df23b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java @@ -13,13 +13,15 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTTypenameExpression extends CPPASTNode implements - ICPPASTTypenameExpression { + ICPPASTTypenameExpression, IASTAmbiguityParent { private boolean isTemplate; private IASTName name; @@ -89,4 +91,14 @@ public class CPPASTTypenameExpression extends CPPASTNode implements return r_reference; return r_unclear; } + + public void replace(IASTNode child, IASTNode other) { + if( child == init ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + init = (IASTExpression) other; + } + + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java index 474da234bdc..39d325e92f6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java @@ -12,13 +12,15 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTUnaryExpression extends CPPASTNode implements - IASTUnaryExpression { + IASTUnaryExpression, IASTAmbiguityParent { private int operator; private IASTExpression operand; @@ -63,4 +65,14 @@ public class CPPASTUnaryExpression extends CPPASTNode implements if( operand != null ) if( !operand.accept( action ) ) return false; return true; } + + public void replace(IASTNode child, IASTNode other) { + if( child == operand ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + operand = (IASTExpression) other; + } + + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java index 27be3f1b476..96068c86e5b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java @@ -13,14 +13,16 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTWhileStatement extends CPPASTNode implements - ICPPASTWhileStatement { + ICPPASTWhileStatement, IASTAmbiguityParent { private IASTExpression condition; private IASTStatement body; private IASTDeclaration condition2; @@ -80,4 +82,20 @@ public class CPPASTWhileStatement extends CPPASTNode implements if( body != null ) if( !body.accept( action ) ) return false; return true; } + + public void replace(IASTNode child, IASTNode other) { + if( body == child ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + body = (IASTStatement) other; + } + if( child == condition ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + condition = (IASTExpression) other; + } + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index 932f391628c..a0d10b62be4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; @@ -134,10 +135,11 @@ import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ParseError; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser; import org.eclipse.cdt.internal.core.dom.parser.BacktrackException; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement; import org.eclipse.cdt.internal.core.parser.SimpleDeclarationStrategy; import org.eclipse.cdt.internal.core.parser.TemplateParameterManager; import org.eclipse.cdt.internal.core.parser.token.OperatorTokenDuple; @@ -168,6 +170,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected CPPASTTranslationUnit translationUnit; + private static final IASTNode[] EMPTY_NODE_ARRAY = new IASTNode[0]; + private static class ScopeStack { private int[] stack; @@ -1460,41 +1464,49 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (templateIdScopes.size() > 0) { templateIdScopes.push(IToken.tLPAREN); } - boolean isTypeId = true; - IASTExpression lhs = null; - IASTTypeId typeId = null; - IToken m = mark(); - try { - boolean amb = false; - if (LT(1) == IToken.tIDENTIFIER) - amb = true; - typeId = typeId(false, false); - if (amb - && typeId.getDeclSpecifier() instanceof IASTNamedTypeSpecifier) { - if (!queryIsTypeName(((IASTNamedTypeSpecifier) typeId - .getDeclSpecifier()).getName())) { - backup(m); - throwBacktrack(((CPPASTNode) typeId).getOffset(), - ((CPPASTNode) typeId).getLength()); - } - } - } catch (BacktrackException b) { - typeId = null; - isTypeId = false; - lhs = expression(); - } - lastOffset = consume(IToken.tRPAREN).getEndOffset(); - if (templateIdScopes.size() > 0) { - templateIdScopes.pop(); - } - if (isTypeId && typeId != null) - firstExpression = buildTypeIdExpression( - ICPPASTTypeIdExpression.op_typeid, typeId, so, - lastOffset); - else - firstExpression = buildUnaryExpression( - ICPPASTUnaryExpression.op_typeid, lhs, so, lastOffset); - break; + IASTNode [] n = parseTypeIdOrUnaryExpression(); + lastOffset = consume(IToken.tRPAREN).getEndOffset(); + if (templateIdScopes.size() > 0) { + templateIdScopes.pop(); + } + + switch( n.length ) + { + case 0: + throwBacktrack( LA(1) ); + break; + case 1: + if( n[0] instanceof IASTTypeId ) + { + firstExpression = buildTypeIdExpression( + ICPPASTTypeIdExpression.op_typeid, (IASTTypeId) n[0], so, + lastOffset); + } + else if( n[0] instanceof IASTExpression ) + { + firstExpression = buildUnaryExpression( + ICPPASTUnaryExpression.op_typeid, (IASTExpression) n[0], so, lastOffset); + } + break; + case 2: + IASTAmbiguousExpression ambExpr = createAmbiguousExpression(); + IASTExpression e1 = buildTypeIdExpression( + ICPPASTTypeIdExpression.op_typeid, (IASTTypeId) n[0], so, + lastOffset); + IASTExpression e2 = buildUnaryExpression( + ICPPASTUnaryExpression.op_typeid, (IASTExpression) n[1], so, lastOffset); + ambExpr.addExpression( e1 ); + e1.setParent( ambExpr ); + e1.setPropertyInParent( IASTAmbiguousExpression.SUBEXPRESSION ); + ambExpr.addExpression( e2 ); + e2.setParent( ambExpr ); + e2.setPropertyInParent( IASTAmbiguousExpression.SUBEXPRESSION ); + ((ASTNode)ambExpr).setOffsetAndLength( (ASTNode) e2 ); + firstExpression = ambExpr; + break; + } + + break; default: firstExpression = primaryExpression(); } @@ -1648,7 +1660,61 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } - /** + protected IASTAmbiguousExpression createAmbiguousExpression() { + return new CPPASTAmbiguousExpression(); + } + + protected IASTNode[] parseTypeIdOrUnaryExpression() throws EndOfFileException { + IASTTypeId typeId = null; + IASTExpression unaryExpression = null; + IToken typeIdLA = null, unaryExpressionLA = null; + IToken mark = mark(); + try + { + typeId = typeId( false, false ); + typeIdLA = LA(1); + } + catch( BacktrackException bte ) + { + typeId = null; + } + backup( mark ); + try + { + unaryExpression = unaryExpression(); + unaryExpressionLA = LA(1); + } + catch( BacktrackException bte ) + { + unaryExpression = null; + } + IASTNode [] result; + if( unaryExpression == null && typeId != null ) + { + backup( typeIdLA ); + result = new IASTNode[1]; + result[0] = typeId; + return result; + } + if( unaryExpression != null && typeId == null ) + { + backup( unaryExpressionLA ); + result = new IASTNode[1]; + result[0] = unaryExpression; + return result; + } + if( unaryExpression != null && typeId != null && typeIdLA == unaryExpressionLA ) + { + result = new IASTNode[2]; + result[0] = typeId; + result[1] = unaryExpression; + return result; + } + return EMPTY_NODE_ARRAY; + + } + + /** * @return */ protected IASTArraySubscriptExpression createArraySubscriptExpression() { @@ -5010,40 +5076,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return result; } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser#resolveOtherAmbiguitiesAsDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement, - * org.eclipse.cdt.core.dom.ast.IASTExpressionStatement) - */ - protected boolean resolveOtherAmbiguitiesAsDeclaration( - IASTDeclarationStatement ds, - IASTExpressionStatement expressionStatement) { - if (expressionStatement.getExpression() instanceof IASTArraySubscriptExpression) { - IASTArraySubscriptExpression arraySub = (IASTArraySubscriptExpression) expressionStatement - .getExpression(); - if (!(arraySub.getArrayExpression() instanceof IASTIdExpression - || arraySub.getArrayExpression() instanceof IASTArraySubscriptExpression || arraySub - .getArrayExpression() instanceof IASTFieldReference)) - return true; - } - // A & B = C; - if (expressionStatement.getExpression() instanceof IASTBinaryExpression) { - IASTBinaryExpression exp = (IASTBinaryExpression) expressionStatement - .getExpression(); - if (exp.getOperator() == IASTBinaryExpression.op_assign) { - IASTExpression lhs = exp.getOperand1(); - if (lhs instanceof IASTBinaryExpression - && ((IASTBinaryExpression) lhs).getOperator() == IASTBinaryExpression.op_binaryAnd) { - - return true; - } - } - } - - return super.resolveOtherAmbiguitiesAsDeclaration(ds, - expressionStatement); - } /* * (non-Javadoc) @@ -5104,52 +5136,21 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } - static class HeuristicTypeDetector extends CPPASTVisitor { - IASTName searchName; + + private static class EmptyVisitor extends CPPASTVisitor { + { + shouldVisitStatements = true; + } + } + + private static final EmptyVisitor EMPTY_VISITOR = new EmptyVisitor(); - boolean found = false; - { - shouldVisitDeclarations = true; - } + protected ASTVisitor createVisitor() { + return EMPTY_VISITOR; + } - public HeuristicTypeDetector(IASTName name) { - this.searchName = name; - } - - public int visit(IASTDeclaration declaration) { - if (declaration instanceof IASTSimpleDeclaration) { - IASTSimpleDeclaration sd = (IASTSimpleDeclaration) declaration; - if (sd.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) { - IASTDeclarator[] declarators = sd.getDeclarators(); - for (int i = 0; i < declarators.length; ++i) - if (CharArrayUtils.equals(declarators[i].getName() - .toCharArray(), searchName.toCharArray())) { - found = true; - return PROCESS_ABORT; - } - } else if (sd.getDeclSpecifier() instanceof IASTCompositeTypeSpecifier) { - IASTCompositeTypeSpecifier comp = (IASTCompositeTypeSpecifier) sd - .getDeclSpecifier(); - if (CharArrayUtils.equals(comp.getName().toCharArray(), - searchName.toCharArray())) { - found = true; - return PROCESS_ABORT; - } - } - } - return PROCESS_CONTINUE; - } - } - - protected boolean queryIsTypeName(IASTName name) { - HeuristicTypeDetector visitor = new HeuristicTypeDetector(name); - translationUnit.accept(visitor); - return visitor.found; - } - - protected void resolveAmbiguities() { - // TODO Auto-generated method stub - - } + protected IASTAmbiguousStatement createAmbiguousStatement() { + return new CPPASTAmbiguousStatement(); + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java index ec9f627be9d..dbc98e371db 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java @@ -18,6 +18,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IExtendedScannerInfo; @@ -2000,6 +2001,9 @@ abstract class BaseScanner implements IScanner { } // skip over anything we don't handle + char [] x = new char [1]; + x[0] = buffer[pos]; + handleProblem( IASTProblem.SCANNER_BAD_CHARACTER, pos, x ); } }