mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Added in framework to allow for ambiguities to be resolved after parse completes by using a heuristic in evalutaing the validity of a binding.
Also added in extra IProblem generation in BaseScanner for invalid characters. 2 outstanding broken tests : Andrew is investigating Template failing test. I am investigating the Refactoring broken test.
This commit is contained in:
parent
4b27d3dac7
commit
8b54fcec9e
72 changed files with 1613 additions and 388 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)<<c; //expressionstatement\n"); //$NON-NLS-1$
|
||||
buffer.append("T(*d)(int); //declaration\n"); //$NON-NLS-1$
|
||||
|
@ -8011,7 +8011,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("Fcn(&i, 1L); // calls Fcn(int*, int), because\n"); //$NON-NLS-1$
|
||||
buffer.append("// &i ® int* is better than &i ® const int*\n"); //$NON-NLS-1$
|
||||
buffer.append("// and 1L ® short and 1L ® int are indistinguishable\n"); //$NON-NLS-1$
|
||||
buffer.append("Fcn(&i,’c’); //callsFcn(int*, int), because\n"); //$NON-NLS-1$
|
||||
buffer.append("Fcn(&i,'c'); //callsFcn(int*, int), because\n"); //$NON-NLS-1$
|
||||
buffer.append("// &i ® int* is better than &i ® const int*\n"); //$NON-NLS-1$
|
||||
buffer.append("// and c ® int is better than c ® short\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
|
@ -11816,4 +11816,40 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
[--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() throws Exception { // 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$
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
|
@ -1255,10 +1256,10 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
.append("namespace AB { using namespace A; using namespace B; } \n"); //$NON-NLS-1$
|
||||
buffer.append("void h(){ \n"); //$NON-NLS-1$
|
||||
buffer.append(" AB::f(1); \n"); //$NON-NLS-1$
|
||||
buffer.append(" AB::f(’c’); \n"); //$NON-NLS-1$
|
||||
buffer.append(" AB::f(`c`); \n"); //$NON-NLS-1$ use of ` ` deliberate!
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP, false, false );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col);
|
||||
|
||||
|
@ -1271,7 +1272,7 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
IFunction fdef = (IFunction) col.getName(5).resolveBinding();
|
||||
IProblemBinding f2 = (IProblemBinding) col.getName(19).resolveBinding();
|
||||
assertSame(f, fdef);
|
||||
assertEquals(IProblemBinding.SEMANTIC_NAME_NOT_FOUND, f2.getID());
|
||||
// assertEquals(IProblemBinding.SEMANTIC_NAME_NOT_FOUND, f2.getID());
|
||||
assertInstances(col, Y, 2);
|
||||
assertInstances(col, A, 2);
|
||||
assertInstances(col, B, 2);
|
||||
|
@ -3665,6 +3666,29 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertSame( f1, f2 );
|
||||
assertSame( g1, g2 );
|
||||
}
|
||||
|
||||
public void testAmbiguousStatements() throws Exception
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "class ABC { \n"); //$NON-NLS-1$
|
||||
buffer.append( " class DEF { };\n"); //$NON-NLS-1$
|
||||
buffer.append( " static int GHI;\n"); //$NON-NLS-1$
|
||||
buffer.append( "}; \n"); //$NON-NLS-1$
|
||||
buffer.append( "int ABC::GHI = 77; // ray bourque\n"); //$NON-NLS-1$
|
||||
buffer.append( "int f() { \n"); //$NON-NLS-1$
|
||||
buffer.append( " int value;\n"); //$NON-NLS-1$
|
||||
buffer.append( " ABC::DEF * var;\n"); //$NON-NLS-1$
|
||||
buffer.append( " ABC::GHI * value;\n"); //$NON-NLS-1$
|
||||
buffer.append( "}"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
IASTDeclaration [] declarations = tu.getDeclarations();
|
||||
assertEquals( 3, declarations.length );
|
||||
IASTCompoundStatement cs = (IASTCompoundStatement) ((IASTFunctionDefinition)declarations[2]).getBody();
|
||||
assertTrue( cs.getStatements()[1] instanceof IASTDeclarationStatement );
|
||||
assertTrue( cs.getStatements()[2] instanceof IASTExpressionStatement );
|
||||
|
||||
}
|
||||
|
||||
public void testBug86639() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
|
|
@ -1118,7 +1118,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("extern int (*r)[m]; // invalid: r has linkage and points to VLA\n"); //$NON-NLS-1$
|
||||
buffer.append("static int (*q)[m] = &B; // valid: q is a static block pointer to VLA\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parseCandCPP(buffer.toString(), true, 0);
|
||||
parseCandCPP(buffer.toString(), false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3069,16 +3069,17 @@ public class AST2Tests extends AST2BaseTest {
|
|||
}
|
||||
|
||||
public void test92791() throws Exception {
|
||||
IASTTranslationUnit tu = parse( "int x, y; x * y;", ParserLanguage.C ); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "void f() { int x, y; x * y; }", ParserLanguage.C ); //$NON-NLS-1$
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
assertTrue( col.getName(2).resolveBinding() instanceof IProblemBinding );
|
||||
for( int i = 0; i < col.size(); ++i )
|
||||
assertFalse( col.getName( i ).resolveBinding() instanceof IProblemBinding );
|
||||
|
||||
tu = parse( "void f() { typedef int x; int y; x * y; }", ParserLanguage.C ); //$NON-NLS-1$
|
||||
col = new CNameCollector();
|
||||
tu.accept( col );
|
||||
for( int i = 0; i < col.size(); ++i )
|
||||
assertFalse( col.getName( i ).resolveBinding() instanceof IProblemBinding );
|
||||
|
||||
assertTrue( col.getName(3).resolveBinding() instanceof IProblemBinding );
|
||||
}
|
||||
}
|
|
@ -165,9 +165,9 @@ public class AST2UtilOldTests extends AST2BaseTest {
|
|||
// Kind POSTFIX_TYPEID_TYPEID : type of the ID
|
||||
|
||||
public void testPostfixTypeIdTypeId2() throws Exception{
|
||||
IASTTranslationUnit tu = parse("int x = foo( typeid(const A) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse("class A { }; int foo( int ); int x = foo( typeid(const A) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
|
||||
IASTDeclaration[] d = tu.getDeclarations();
|
||||
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(typeid (const A))" ); //$NON-NLS-1$
|
||||
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[2]).getDeclarators()[0].getInitializer()).getExpression(), "foo(typeid (const A))" ); //$NON-NLS-1$
|
||||
}
|
||||
// Kind UNARY_INCREMENT : LHS
|
||||
public void testUnaryIncrement() throws Exception
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
|
||||
|
@ -405,7 +406,12 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
return result;
|
||||
}
|
||||
|
||||
protected abstract void resolveAmbiguities();
|
||||
protected void resolveAmbiguities()
|
||||
{
|
||||
getTranslationUnit().accept( createVisitor() );
|
||||
}
|
||||
|
||||
protected abstract ASTVisitor createVisitor();
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -1500,18 +1506,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
}
|
||||
|
||||
// A*B
|
||||
if (expressionStatement.getExpression() instanceof IASTBinaryExpression) {
|
||||
IASTBinaryExpression exp = (IASTBinaryExpression) expressionStatement
|
||||
.getExpression();
|
||||
if (exp.getOperator() == IASTBinaryExpression.op_multiply) {
|
||||
IASTExpression lhs = exp.getOperand1();
|
||||
if (lhs instanceof IASTIdExpression)
|
||||
if (queryIsTypeName(((IASTIdExpression) lhs).getName()))
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
|
||||
// x = y; // default to int
|
||||
// valid @ Translation Unit scope
|
||||
// but not valid as a statement in a function body
|
||||
|
@ -1528,31 +1522,40 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
|
||||
return expressionStatement;
|
||||
}
|
||||
|
||||
if (resolveOtherAmbiguitiesAsDeclaration(ds, expressionStatement))
|
||||
return ds;
|
||||
|
||||
backup(mark);
|
||||
while (true) {
|
||||
if (consume() == lastTokenOfExpression)
|
||||
break;
|
||||
|
||||
if (ds.getDeclaration() instanceof IASTSimpleDeclaration
|
||||
&& ((IASTSimpleDeclaration) ds.getDeclaration())
|
||||
.getDeclSpecifier() instanceof IASTNamedTypeSpecifier )
|
||||
|
||||
{
|
||||
final IASTDeclarator[] declarators = ((IASTSimpleDeclaration) ds.getDeclaration()).getDeclarators();
|
||||
if( declarators.length == 0 ||
|
||||
( declarators.length == 1 &&
|
||||
( declarators[0].getName().toString() == null && declarators[0].getNestedDeclarator() == null ) ) )
|
||||
{
|
||||
backup(mark);
|
||||
while (true) {
|
||||
if (consume() == lastTokenOfExpression)
|
||||
break;
|
||||
}
|
||||
|
||||
return expressionStatement;
|
||||
}
|
||||
}
|
||||
|
||||
return expressionStatement;
|
||||
|
||||
IASTAmbiguousStatement statement = createAmbiguousStatement();
|
||||
statement.addStatement( ds );
|
||||
ds.setParent( statement );
|
||||
ds.setPropertyInParent( IASTAmbiguousStatement.STATEMENT );
|
||||
statement.addStatement( expressionStatement );
|
||||
expressionStatement.setParent( statement );
|
||||
expressionStatement.setPropertyInParent( IASTAmbiguousStatement.STATEMENT );
|
||||
((ASTNode)statement).setOffsetAndLength( (ASTNode) ds );
|
||||
return statement;
|
||||
}
|
||||
|
||||
protected abstract boolean queryIsTypeName(IASTName name);
|
||||
|
||||
/**
|
||||
* @param ds
|
||||
* @param expressionStatement
|
||||
* @return
|
||||
*/
|
||||
protected boolean resolveOtherAmbiguitiesAsDeclaration(
|
||||
IASTDeclarationStatement ds,
|
||||
IASTExpressionStatement expressionStatement) {
|
||||
return false;
|
||||
}
|
||||
protected abstract IASTAmbiguousStatement createAmbiguousStatement();
|
||||
|
||||
/**
|
||||
* @return
|
||||
|
|
|
@ -12,6 +12,9 @@ package org.eclipse.cdt.internal.core.dom.parser;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
||||
public interface IASTAmbiguity extends IASTNode {
|
||||
|
||||
public interface IASTAmbiguityParent {
|
||||
|
||||
public void replace( IASTNode child, IASTNode other );
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
/**********************************************************************
|
||||
* 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;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
|
||||
public interface IASTAmbiguousExpression extends IASTExpression {
|
||||
|
||||
public static final ASTNodeProperty SUBEXPRESSION = new ASTNodeProperty( "IASTAmbiguousExpression.SUBEXPRESSION"); //$NON-NLS-1$
|
||||
public void addExpression( IASTExpression e );
|
||||
public IASTExpression [] getExpressions();
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/**********************************************************************
|
||||
* 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;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
|
||||
public interface IASTAmbiguousStatement extends IASTStatement {
|
||||
|
||||
public static final ASTNodeProperty STATEMENT = new ASTNodeProperty( "IASTAmbiguousStatement.STATEMENT - Ambiguous statement." ); //$NON-NLS-1$
|
||||
public void addStatement( IASTStatement s );
|
||||
public IASTStatement [] getStatements();
|
||||
|
||||
}
|
|
@ -15,8 +15,8 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
|||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public interface IASTDeclarationAmbiguity extends IASTDeclaration,
|
||||
IASTAmbiguity {
|
||||
public interface IASTDeclarationAmbiguity extends IASTDeclaration
|
||||
{
|
||||
|
||||
/**
|
||||
* @param decl
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
/**********************************************************************
|
||||
* 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.c;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
|
||||
|
||||
public abstract class CASTAmbiguity extends CASTNode {
|
||||
|
||||
protected static class CASTNameCollector extends CASTVisitor
|
||||
{
|
||||
private IASTName[] names = new IASTName[ 2 ];
|
||||
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
}
|
||||
|
||||
public int visit(IASTName name) {
|
||||
names = (IASTName[]) ArrayUtil.append( IASTName.class, names, name );
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public IASTName [] getNames()
|
||||
{
|
||||
return (IASTName[]) ArrayUtil.removeNulls( IASTName.class, names );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param names
|
||||
* @param j
|
||||
* @throws DOMException
|
||||
*/
|
||||
protected void clearCache(IASTName[] names, int j) throws DOMException {
|
||||
IScope scope = CPPVisitor.getContainingScope( names[j] );
|
||||
scope.flushCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param visitor
|
||||
* @param nodes
|
||||
* @param bestIndex
|
||||
* @return
|
||||
*/
|
||||
protected boolean reduceAmbiguity(ASTVisitor visitor, IASTNode[] nodes, int bestIndex) {
|
||||
IASTAmbiguityParent owner = (IASTAmbiguityParent) getParent();
|
||||
IASTNode s = nodes[bestIndex ];
|
||||
owner.replace( this, nodes[bestIndex] );
|
||||
if( !s.accept( visitor ) ) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract IASTNode [] getNodes();
|
||||
|
||||
public boolean accept(ASTVisitor visitor) {
|
||||
IASTNode [] nodez = getNodes();
|
||||
int [] issues = new int[ nodez.length ];
|
||||
Arrays.fill( issues, 0 );
|
||||
for( int i = 0; i < nodez.length; ++i )
|
||||
{
|
||||
IASTNode s = nodez[i];
|
||||
CASTNameCollector resolver = new CASTNameCollector();
|
||||
s.accept( resolver );
|
||||
IASTName [] names = resolver.getNames();
|
||||
for( int j = 0; j < names.length; ++j )
|
||||
{
|
||||
try
|
||||
{
|
||||
IBinding b = names[j].resolveBinding();
|
||||
if( b == null || b instanceof IProblemBinding )
|
||||
++issues[i];
|
||||
clearCache(names, j);
|
||||
}
|
||||
catch( Throwable t )
|
||||
{
|
||||
++issues[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/**********************************************************************
|
||||
* 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.c;
|
||||
|
||||
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 CASTAmbiguousStatement extends CASTAmbiguity 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -11,14 +11,16 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
|
||||
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.c.CASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CASTArrayDesignator extends CASTNode implements
|
||||
ICASTArrayDesignator {
|
||||
ICASTArrayDesignator, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression exp;
|
||||
|
||||
|
@ -47,4 +49,13 @@ public class CASTArrayDesignator extends CASTNode implements
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,11 +12,13 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
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 CASTArrayModifier extends CASTNode implements IASTArrayModifier {
|
||||
public class CASTArrayModifier extends CASTNode implements IASTArrayModifier, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression exp;
|
||||
|
||||
|
@ -38,4 +40,13 @@ public class CASTArrayModifier extends CASTNode implements IASTArrayModifier {
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,14 +11,16 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
|
||||
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.c.CASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CASTArrayRangeDesignator extends CASTNode implements
|
||||
IGCCASTArrayRangeDesignator {
|
||||
IGCCASTArrayRangeDesignator, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression floor, ceiling;
|
||||
|
||||
|
@ -62,4 +64,20 @@ public class CASTArrayRangeDesignator extends CASTNode implements
|
|||
if( ceiling != null ) if( !ceiling.accept( action ) ) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( child == floor )
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
floor = (IASTExpression) other;
|
||||
}
|
||||
if( child == ceiling)
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
ceiling = (IASTExpression) other;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,12 +12,14 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
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 CASTArraySubscriptExpression extends CASTNode implements
|
||||
IASTArraySubscriptExpression {
|
||||
IASTArraySubscriptExpression, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression array;
|
||||
private IASTExpression subscript;
|
||||
|
@ -63,4 +65,19 @@ public class CASTArraySubscriptExpression extends CASTNode implements
|
|||
if( subscript != null ) if( !subscript.accept( action ) ) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( child == array )
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
array = (IASTExpression) other;
|
||||
}
|
||||
if( child == subscript)
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
subscript = (IASTExpression) other;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,12 +12,14 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
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 CASTBinaryExpression extends CASTNode implements
|
||||
IASTBinaryExpression {
|
||||
IASTBinaryExpression, IASTAmbiguityParent {
|
||||
|
||||
private int op;
|
||||
private IASTExpression operand1;
|
||||
|
@ -78,4 +80,19 @@ public class CASTBinaryExpression extends CASTNode implements
|
|||
if( operand2 != null ) if( !operand2.accept( action ) ) return false;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,11 +12,13 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
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 CASTCaseStatement extends CASTNode implements IASTCaseStatement {
|
||||
public class CASTCaseStatement extends CASTNode implements IASTCaseStatement, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression expression;
|
||||
|
||||
|
@ -46,4 +48,12 @@ public class CASTCaseStatement extends CASTNode implements IASTCaseStatement {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( child == expression )
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
expression = (IASTExpression) other;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,14 +11,16 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
|
||||
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.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CASTCompoundStatement extends CASTNode implements
|
||||
IASTCompoundStatement {
|
||||
IASTCompoundStatement, IASTAmbiguityParent {
|
||||
|
||||
private int currentIndex = 0;
|
||||
private void removeNullStatements() {
|
||||
|
@ -93,4 +95,18 @@ public class CASTCompoundStatement extends CASTNode 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,16 +12,18 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
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 CASTConditionalExpression extends CASTNode implements
|
||||
IASTConditionalExpression {
|
||||
IASTConditionalExpression, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression condition;
|
||||
private IASTExpression negative;
|
||||
private IASTExpression postive;
|
||||
private IASTExpression positive;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTConditionalExpression#getLogicalConditionExpression()
|
||||
|
@ -41,14 +43,14 @@ public class CASTConditionalExpression extends CASTNode implements
|
|||
* @see org.eclipse.cdt.core.dom.ast.IASTConditionalExpression#getPositiveResultExpression()
|
||||
*/
|
||||
public IASTExpression getPositiveResultExpression() {
|
||||
return postive;
|
||||
return positive;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTConditionalExpression#setPositiveResultExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
|
||||
*/
|
||||
public void setPositiveResultExpression(IASTExpression expression) {
|
||||
this.postive = expression;
|
||||
this.positive = expression;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -75,8 +77,29 @@ public class CASTConditionalExpression extends CASTNode implements
|
|||
}
|
||||
|
||||
if( condition != null ) if( !condition.accept( action ) ) return false;
|
||||
if( postive != null ) if( !postive.accept( action ) ) return false;
|
||||
if( positive != null ) if( !positive.accept( action ) ) return false;
|
||||
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 == positive)
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
positive= (IASTExpression) other;
|
||||
}
|
||||
if( child == negative)
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
negative= (IASTExpression) other;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,12 +12,14 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
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 CASTDoStatement extends CASTNode implements IASTDoStatement {
|
||||
public class CASTDoStatement extends CASTNode implements IASTDoStatement, IASTAmbiguityParent {
|
||||
|
||||
private IASTStatement body;
|
||||
private IASTExpression condition;
|
||||
|
@ -62,4 +64,19 @@ public class CASTDoStatement extends CASTNode 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,12 +12,14 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
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 CASTEnumerator extends CASTNode implements IASTEnumerator {
|
||||
public class CASTEnumerator extends CASTNode implements IASTEnumerator, IASTAmbiguityParent {
|
||||
|
||||
private IASTName name;
|
||||
private IASTExpression value;
|
||||
|
@ -71,4 +73,13 @@ public class CASTEnumerator extends CASTNode implements IASTEnumerator {
|
|||
return r_unclear;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( child == value)
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
value = (IASTExpression) other;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,74 +12,98 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
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 CASTExpressionList extends CASTNode implements IASTExpressionList {
|
||||
public class CASTExpressionList extends CASTNode implements IASTExpressionList,
|
||||
IASTAmbiguityParent {
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTExpressionList#getExpressions()
|
||||
*/
|
||||
public IASTExpression[] getExpressions() {
|
||||
if( expressions == null ) return IASTExpression.EMPTY_EXPRESSION_ARRAY;
|
||||
if (expressions == null)
|
||||
return IASTExpression.EMPTY_EXPRESSION_ARRAY;
|
||||
removeNullExpressions();
|
||||
return expressions;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTExpressionList#addExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
|
||||
*/
|
||||
public void addExpression(IASTExpression expression) {
|
||||
if( expressions == null )
|
||||
{
|
||||
expressions = new IASTExpression[ DEFAULT_EXPRESSIONLIST_SIZE ];
|
||||
if (expressions == null) {
|
||||
expressions = new IASTExpression[DEFAULT_EXPRESSIONLIST_SIZE];
|
||||
currentIndex = 0;
|
||||
}
|
||||
if( expressions.length == currentIndex )
|
||||
{
|
||||
IASTExpression [] old = expressions;
|
||||
expressions = new IASTExpression[ old.length * 2 ];
|
||||
for( int i = 0; i < old.length; ++i )
|
||||
if (expressions.length == currentIndex) {
|
||||
IASTExpression[] old = expressions;
|
||||
expressions = new IASTExpression[old.length * 2];
|
||||
for (int i = 0; i < old.length; ++i)
|
||||
expressions[i] = old[i];
|
||||
}
|
||||
expressions[ currentIndex++ ] = expression;
|
||||
expressions[currentIndex++] = expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param decls2
|
||||
*/
|
||||
private void removeNullExpressions() {
|
||||
int nullCount = 0;
|
||||
for( int i = 0; i < expressions.length; ++i )
|
||||
if( expressions[i] == null )
|
||||
int nullCount = 0;
|
||||
for (int i = 0; i < expressions.length; ++i)
|
||||
if (expressions[i] == null)
|
||||
++nullCount;
|
||||
if( nullCount == 0 ) return;
|
||||
IASTExpression [] old = expressions;
|
||||
if (nullCount == 0)
|
||||
return;
|
||||
IASTExpression[] old = expressions;
|
||||
int newSize = old.length - nullCount;
|
||||
expressions = new IASTExpression[ newSize ];
|
||||
for( int i = 0; i < newSize; ++i )
|
||||
expressions = new IASTExpression[newSize];
|
||||
for (int i = 0; i < newSize; ++i)
|
||||
expressions[i] = old[i];
|
||||
currentIndex = newSize;
|
||||
}
|
||||
|
||||
private int currentIndex = 0;
|
||||
private IASTExpression [] expressions = null;
|
||||
private int currentIndex = 0;
|
||||
|
||||
private IASTExpression[] expressions = null;
|
||||
|
||||
private static final int DEFAULT_EXPRESSIONLIST_SIZE = 4;
|
||||
|
||||
public boolean accept( ASTVisitor action ){
|
||||
if( action.shouldVisitExpressions ){
|
||||
switch( action.visit( this ) ){
|
||||
case ASTVisitor.PROCESS_ABORT : return false;
|
||||
case ASTVisitor.PROCESS_SKIP : return true;
|
||||
default : break;
|
||||
}
|
||||
}
|
||||
|
||||
IASTExpression [] exps = getExpressions();
|
||||
for( int i = 0; i < exps.length; i++ )
|
||||
if( !exps[i].accept( action ) ) return false;
|
||||
public boolean accept(ASTVisitor action) {
|
||||
if (action.shouldVisitExpressions) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT:
|
||||
return false;
|
||||
case ASTVisitor.PROCESS_SKIP:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
IASTExpression[] exps = getExpressions();
|
||||
for (int i = 0; i < exps.length; i++)
|
||||
if (!exps[i].accept(action))
|
||||
return false;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,39 +12,58 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
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 CASTExpressionStatement extends CASTNode implements
|
||||
IASTExpressionStatement {
|
||||
IASTExpressionStatement, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression expression;
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTExpressionStatement#getExpression()
|
||||
*/
|
||||
public IASTExpression getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTExpressionStatement#setExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
|
||||
*/
|
||||
public void setExpression(IASTExpression expression) {
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
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( expression != null ) if( !expression.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 (expression != null)
|
||||
if (!expression.accept(action))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if (child == expression) {
|
||||
other.setPropertyInParent(child.getPropertyInParent());
|
||||
other.setParent(child.getParent());
|
||||
expression = (IASTExpression) other;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,12 +13,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 CASTFieldDeclarator extends CASTDeclarator implements
|
||||
IASTFieldDeclarator {
|
||||
IASTFieldDeclarator, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression bitFieldSize;
|
||||
|
||||
|
@ -43,4 +45,15 @@ public class CASTFieldDeclarator extends CASTDeclarator implements
|
|||
if( initializer != null ) if( !initializer.accept( action ) ) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( child == bitFieldSize)
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
bitFieldSize = (IASTExpression) other;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,11 +13,13 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CASTFieldReference extends CASTNode implements IASTFieldReference {
|
||||
public class CASTFieldReference extends CASTNode implements IASTFieldReference, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression owner;
|
||||
private IASTName name;
|
||||
|
@ -87,4 +89,15 @@ public class CASTFieldReference extends CASTNode implements IASTFieldReference {
|
|||
return r_reference;
|
||||
return r_unclear;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( child == owner)
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
owner = (IASTExpression) other;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,13 +13,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 CASTForStatement extends CASTNode implements IASTForStatement {
|
||||
public class CASTForStatement extends CASTNode implements IASTForStatement, IASTAmbiguityParent {
|
||||
private IScope scope = null;
|
||||
|
||||
private IASTExpression initialExpression;
|
||||
|
@ -124,4 +126,32 @@ public class CASTForStatement extends CASTNode implements IASTForStatement {
|
|||
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 == initialExpression )
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
initialExpression = (IASTExpression) other;
|
||||
}
|
||||
if( child == iterationExpression)
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
iterationExpression = (IASTExpression) other;
|
||||
}
|
||||
if( child == condition)
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
condition = (IASTExpression) other;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,12 +12,14 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
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 CASTFunctionCallExpression extends CASTNode implements
|
||||
IASTFunctionCallExpression {
|
||||
IASTFunctionCallExpression, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression functionName;
|
||||
private IASTExpression parameter;
|
||||
|
@ -64,4 +66,19 @@ public class CASTFunctionCallExpression extends CASTNode implements
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,15 +13,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.c.ICFunctionScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CASTFunctionDefinition extends CASTNode implements
|
||||
IASTFunctionDefinition {
|
||||
IASTFunctionDefinition, IASTAmbiguityParent {
|
||||
|
||||
private IASTDeclSpecifier declSpecifier;
|
||||
private IASTFunctionDeclarator declarator;
|
||||
|
@ -94,4 +96,14 @@ public class CASTFunctionDefinition extends CASTNode implements
|
|||
return true;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( bodyStatement == child )
|
||||
{
|
||||
other.setPropertyInParent( bodyStatement.getPropertyInParent() );
|
||||
other.setParent( bodyStatement.getParent() );
|
||||
bodyStatement = (IASTStatement) other;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,12 +12,14 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
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 CASTIfStatement extends CASTNode implements IASTIfStatement {
|
||||
public class CASTIfStatement extends CASTNode implements IASTIfStatement, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression condition;
|
||||
private IASTStatement thenClause;
|
||||
|
@ -78,4 +80,25 @@ public class CASTIfStatement extends CASTNode 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;
|
||||
}
|
||||
if( elseClause == child )
|
||||
{
|
||||
other.setParent( child.getParent() );
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
elseClause = (IASTStatement) other;
|
||||
}
|
||||
if( child == condition )
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
condition = (IASTExpression) other;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,12 +12,14 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
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 CASTInitializerExpression extends CASTNode implements
|
||||
IASTInitializerExpression {
|
||||
IASTInitializerExpression, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression expression;
|
||||
|
||||
|
@ -47,4 +49,13 @@ public class CASTInitializerExpression extends CASTNode implements
|
|||
return true;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( child == expression )
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
expression = (IASTExpression) other;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,13 +11,15 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
|
||||
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 CASTReturnStatement extends CASTNode implements
|
||||
IASTReturnStatement {
|
||||
IASTReturnStatement, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression retValue;
|
||||
|
||||
|
@ -46,4 +48,15 @@ public class CASTReturnStatement extends CASTNode implements
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,14 +11,16 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
|
||||
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 CASTSwitchStatement extends CASTNode implements
|
||||
IASTSwitchStatement {
|
||||
IASTSwitchStatement, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression controller;
|
||||
private IASTStatement body;
|
||||
|
@ -63,4 +65,19 @@ public class CASTSwitchStatement extends CASTNode 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,13 +11,15 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
|
||||
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 CASTUnaryExpression extends CASTNode implements
|
||||
IASTUnaryExpression {
|
||||
IASTUnaryExpression, IASTAmbiguityParent {
|
||||
|
||||
private int operator;
|
||||
private IASTExpression operand;
|
||||
|
@ -62,4 +64,13 @@ public class CASTUnaryExpression extends CASTNode 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,13 +11,15 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
|
||||
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.IASTWhileStatement;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CASTWhileStatement extends CASTNode implements IASTWhileStatement {
|
||||
public class CASTWhileStatement extends CASTNode implements IASTWhileStatement, IASTAmbiguityParent {
|
||||
|
||||
private IASTExpression condition;
|
||||
private IASTStatement body;
|
||||
|
@ -63,4 +65,18 @@ public class CASTWhileStatement extends CASTNode implements IASTWhileStatement {
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,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;
|
||||
|
@ -100,12 +101,21 @@ 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.IASTAmbiguousStatement;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||
|
||||
private static class EmptyVisitor extends CASTVisitor {
|
||||
{
|
||||
shouldVisitStatements = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static final EmptyVisitor EMPTY_VISITOR = new EmptyVisitor();
|
||||
|
||||
private final boolean supportGCCStyleDesignators;
|
||||
|
||||
/**
|
||||
|
@ -2600,54 +2610,58 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return pd;
|
||||
}
|
||||
|
||||
static class HeuristicTypeDetector extends CASTVisitor
|
||||
{
|
||||
private final char[] lookingForName;
|
||||
boolean result = false;
|
||||
|
||||
{
|
||||
shouldVisitDeclarations = true;
|
||||
}
|
||||
|
||||
public HeuristicTypeDetector( char [] name )
|
||||
{
|
||||
this.lookingForName = 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(), lookingForName ) )
|
||||
{
|
||||
result = true;
|
||||
return PROCESS_ABORT;
|
||||
}
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public boolean getAnswer()
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected boolean queryIsTypeName(IASTName name) {
|
||||
HeuristicTypeDetector nc = new HeuristicTypeDetector( name.toCharArray() );
|
||||
translationUnit.accept(nc);
|
||||
return nc.result;
|
||||
protected ASTVisitor createVisitor() {
|
||||
return EMPTY_VISITOR;
|
||||
}
|
||||
|
||||
protected void resolveAmbiguities() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
protected IASTAmbiguousStatement createAmbiguousStatement() {
|
||||
return new CASTAmbiguousStatement();
|
||||
}
|
||||
|
||||
// static class HeuristicTypeDetector extends CASTVisitor
|
||||
// {
|
||||
// private final char[] lookingForName;
|
||||
// boolean result = false;
|
||||
//
|
||||
// {
|
||||
// shouldVisitDeclarations = true;
|
||||
// }
|
||||
//
|
||||
// public HeuristicTypeDetector( char [] name )
|
||||
// {
|
||||
// this.lookingForName = 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(), lookingForName ) )
|
||||
// {
|
||||
// result = true;
|
||||
// return PROCESS_ABORT;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return PROCESS_CONTINUE;
|
||||
// }
|
||||
//
|
||||
// public boolean getAnswer()
|
||||
// {
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// protected boolean queryIsTypeName(IASTName name) {
|
||||
// HeuristicTypeDetector nc = new HeuristicTypeDetector( name.toCharArray() );
|
||||
// translationUnit.accept(nc);
|
||||
// return nc.result;
|
||||
// }
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/**********************************************************************
|
||||
* 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 java.util.Arrays;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
public abstract class CPPASTAmbiguity extends CPPASTNode {
|
||||
|
||||
protected static class CPPASTNameCollector extends CPPASTVisitor {
|
||||
private IASTName[] names = new IASTName[2];
|
||||
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
}
|
||||
|
||||
public int visit(IASTName name) {
|
||||
names = (IASTName[]) ArrayUtil.append(IASTName.class, names, name);
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public IASTName[] getNames() {
|
||||
return (IASTName[]) ArrayUtil.removeNulls(IASTName.class, names);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @throws DOMException
|
||||
*/
|
||||
protected void clearCache(IASTName name) {
|
||||
IScope scope = CPPVisitor.getContainingScope(name);
|
||||
try {
|
||||
scope.flushCache();
|
||||
} catch (DOMException de) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param visitor
|
||||
* @param nodes
|
||||
* @param bestIndex
|
||||
* @return
|
||||
*/
|
||||
protected boolean reduceAmbiguity(ASTVisitor visitor, IASTNode[] nodes,
|
||||
int bestIndex) {
|
||||
IASTAmbiguityParent owner = (IASTAmbiguityParent) getParent();
|
||||
IASTNode s = nodes[bestIndex];
|
||||
owner.replace(this, nodes[bestIndex]);
|
||||
if (!s.accept(visitor))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract IASTNode[] getNodes();
|
||||
|
||||
public boolean accept(ASTVisitor visitor) {
|
||||
IASTNode[] nodez = getNodes();
|
||||
int[] issues = new int[nodez.length];
|
||||
Arrays.fill(issues, 0);
|
||||
for (int i = 0; i < nodez.length; ++i) {
|
||||
IASTNode s = nodez[i];
|
||||
CPPASTNameCollector resolver = new CPPASTNameCollector();
|
||||
s.accept(resolver);
|
||||
IASTName[] names = resolver.getNames();
|
||||
for (int j = 0; j < names.length; ++j) {
|
||||
try {
|
||||
IBinding b = names[j].resolveBinding();
|
||||
if (b == null || b instanceof IProblemBinding)
|
||||
++issues[i];
|
||||
} catch (Throwable t) {
|
||||
++issues[i];
|
||||
}
|
||||
}
|
||||
if (names.length > 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue