1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

- change interface gets to return arrays instead of lists

- added getScope as needed
- added IASTName.toCharArray()
- modified CVisitor to use scopes to store bindings

these changes reduce binding time for windows.h from minutes to ~1300 ms
This commit is contained in:
Andrew Niefer 2004-11-25 22:07:17 +00:00
parent bdbb88046a
commit e22e2cadc1
55 changed files with 819 additions and 486 deletions

View file

@ -184,9 +184,9 @@ public class AST2BaseTest extends TestCase {
buffer.append( code ); buffer.append( code );
buffer.append( ";\n}"); //$NON-NLS-1$ buffer.append( ";\n}"); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), language ); IASTTranslationUnit tu = parse( buffer.toString(), language );
IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations().get(0); IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
IASTCompoundStatement cs = (IASTCompoundStatement) f.getBody(); IASTCompoundStatement cs = (IASTCompoundStatement) f.getBody();
IASTExpressionStatement s = (IASTExpressionStatement) cs.getStatements().get( 1 ); IASTExpressionStatement s = (IASTExpressionStatement) cs.getStatements()[1];
return s.getExpression(); return s.getExpression();
} }

View file

@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; 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.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
@ -52,6 +53,7 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTPointer; import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.core.parser.ParserException; import org.eclipse.cdt.internal.core.parser.ParserException;
@ -74,22 +76,19 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse(buff.toString(), ParserLanguage.C ); IASTTranslationUnit tu = parse(buff.toString(), ParserLanguage.C );
IScope globalScope = tu.getScope(); IScope globalScope = tu.getScope();
List declarations = tu.getDeclarations(); IASTDeclaration[] declarations = tu.getDeclarations();
// int x // int x
IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) declarations IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) declarations[0];
.get(0);
IASTSimpleDeclSpecifier declspec_x = (IASTSimpleDeclSpecifier) decl_x IASTSimpleDeclSpecifier declspec_x = (IASTSimpleDeclSpecifier) decl_x
.getDeclSpecifier(); .getDeclSpecifier();
assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_x.getType()); assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_x.getType());
IASTDeclarator declor_x = (IASTDeclarator) decl_x.getDeclarators().get( IASTDeclarator declor_x = decl_x.getDeclarators()[0];
0);
IASTName name_x = declor_x.getName(); IASTName name_x = declor_x.getName();
assertEquals("x", name_x.toString()); //$NON-NLS-1$ assertEquals("x", name_x.toString()); //$NON-NLS-1$
// function - void f() // function - void f()
IASTFunctionDefinition funcdef_f = (IASTFunctionDefinition) declarations IASTFunctionDefinition funcdef_f = (IASTFunctionDefinition) declarations[1];
.get(1);
IASTSimpleDeclSpecifier declspec_f = (IASTSimpleDeclSpecifier) funcdef_f IASTSimpleDeclSpecifier declspec_f = (IASTSimpleDeclSpecifier) funcdef_f
.getDeclSpecifier(); .getDeclSpecifier();
assertEquals(IASTSimpleDeclSpecifier.t_void, declspec_f.getType()); assertEquals(IASTSimpleDeclSpecifier.t_void, declspec_f.getType());
@ -99,8 +98,7 @@ public class AST2Tests extends AST2BaseTest {
assertEquals("f", name_f.toString()); //$NON-NLS-1$ assertEquals("f", name_f.toString()); //$NON-NLS-1$
// parameter - int y // parameter - int y
IASTParameterDeclaration decl_y = (IASTParameterDeclaration) declor_f IASTParameterDeclaration decl_y = declor_f.getParameters()[0];
.getParameters().get(0);
IASTSimpleDeclSpecifier declspec_y = (IASTSimpleDeclSpecifier) decl_y IASTSimpleDeclSpecifier declspec_y = (IASTSimpleDeclSpecifier) decl_y
.getDeclSpecifier(); .getDeclSpecifier();
assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_y.getType()); assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_y.getType());
@ -111,15 +109,13 @@ public class AST2Tests extends AST2BaseTest {
// int z // int z
IASTCompoundStatement body_f = (IASTCompoundStatement) funcdef_f IASTCompoundStatement body_f = (IASTCompoundStatement) funcdef_f
.getBody(); .getBody();
IASTDeclarationStatement declstmt_z = (IASTDeclarationStatement) body_f IASTDeclarationStatement declstmt_z = (IASTDeclarationStatement) body_f.getStatements()[0];
.getStatements().get(0);
IASTSimpleDeclaration decl_z = (IASTSimpleDeclaration) declstmt_z IASTSimpleDeclaration decl_z = (IASTSimpleDeclaration) declstmt_z
.getDeclaration(); .getDeclaration();
IASTSimpleDeclSpecifier declspec_z = (IASTSimpleDeclSpecifier) decl_z IASTSimpleDeclSpecifier declspec_z = (IASTSimpleDeclSpecifier) decl_z
.getDeclSpecifier(); .getDeclSpecifier();
assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_z.getType()); assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_z.getType());
IASTDeclarator declor_z = (IASTDeclarator) decl_z.getDeclarators().get( IASTDeclarator declor_z = decl_z.getDeclarators()[0];
0);
IASTName name_z = declor_z.getName(); IASTName name_z = declor_z.getName();
assertEquals("z", name_z.toString()); //$NON-NLS-1$ assertEquals("z", name_z.toString()); //$NON-NLS-1$
@ -145,7 +141,7 @@ public class AST2Tests extends AST2BaseTest {
assertEquals(func_f.getFunctionScope(), var_y.getScope()); assertEquals(func_f.getFunctionScope(), var_y.getScope());
IVariable var_z = (IVariable) name_z.resolveBinding(); IVariable var_z = (IVariable) name_z.resolveBinding();
assertEquals(func_f.getFunctionScope(), var_z.getScope()); assertEquals(((ICFunctionScope)func_f.getFunctionScope()).getBodyScope(), var_z.getScope());
// make sure the variable referenced is the same one we declared above // make sure the variable referenced is the same one we declared above
assertEquals(var_x, name_ref_x.resolveBinding()); assertEquals(var_x, name_ref_x.resolveBinding());
@ -165,7 +161,7 @@ public class AST2Tests extends AST2BaseTest {
buff.append("}"); //$NON-NLS-1$ buff.append("}"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buff.toString(), ParserLanguage.C ); IASTTranslationUnit tu = parse(buff.toString(), ParserLanguage.C );
IASTSimpleDeclaration decl = (IASTSimpleDeclaration)tu.getDeclarations().get(0); IASTSimpleDeclaration decl = (IASTSimpleDeclaration)tu.getDeclarations()[0];
IASTCompositeTypeSpecifier type = (IASTCompositeTypeSpecifier)decl.getDeclSpecifier(); IASTCompositeTypeSpecifier type = (IASTCompositeTypeSpecifier)decl.getDeclSpecifier();
// it's a typedef // it's a typedef
@ -174,29 +170,26 @@ public class AST2Tests extends AST2BaseTest {
IASTName name_struct = type.getName(); IASTName name_struct = type.getName();
assertNull("", name_struct.toString()); //$NON-NLS-1$ assertNull("", name_struct.toString()); //$NON-NLS-1$
// member - x // member - x
IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) type IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) type.getMembers()[0];
.getMembers().get(0);
IASTSimpleDeclSpecifier spec_x = (IASTSimpleDeclSpecifier) decl_x IASTSimpleDeclSpecifier spec_x = (IASTSimpleDeclSpecifier) decl_x
.getDeclSpecifier(); .getDeclSpecifier();
// it's an int // it's an int
assertEquals(IASTSimpleDeclSpecifier.t_int, spec_x.getType()); assertEquals(IASTSimpleDeclSpecifier.t_int, spec_x.getType());
IASTDeclarator tor_x = (IASTDeclarator) decl_x IASTDeclarator tor_x = decl_x.getDeclarators()[0];
.getDeclarators().get(0);
IASTName name_x = tor_x.getName(); IASTName name_x = tor_x.getName();
assertEquals("x", name_x.toString()); //$NON-NLS-1$ assertEquals("x", name_x.toString()); //$NON-NLS-1$
// declarator S // declarator S
IASTDeclarator tor_S = (IASTDeclarator) decl.getDeclarators().get(0); IASTDeclarator tor_S = decl.getDeclarators()[0];
IASTName name_S = tor_S.getName(); IASTName name_S = tor_S.getName();
assertEquals("S", name_S.toString()); //$NON-NLS-1$ assertEquals("S", name_S.toString()); //$NON-NLS-1$
// function f // function f
IASTFunctionDefinition def_f = (IASTFunctionDefinition) tu IASTFunctionDefinition def_f = (IASTFunctionDefinition) tu.getDeclarations()[1];
.getDeclarations().get(1);
// f's body // f's body
IASTCompoundStatement body_f = (IASTCompoundStatement) def_f.getBody(); IASTCompoundStatement body_f = (IASTCompoundStatement) def_f.getBody();
// the declaration statement for myS // the declaration statement for myS
IASTDeclarationStatement declstmt_myS = (IASTDeclarationStatement)body_f.getStatements().get(0); IASTDeclarationStatement declstmt_myS = (IASTDeclarationStatement)body_f.getStatements()[0];
// the declaration for myS // the declaration for myS
IASTSimpleDeclaration decl_myS = (IASTSimpleDeclaration)declstmt_myS.getDeclaration(); IASTSimpleDeclaration decl_myS = (IASTSimpleDeclaration)declstmt_myS.getDeclaration();
// the type specifier for myS // the type specifier for myS
@ -204,11 +197,11 @@ public class AST2Tests extends AST2BaseTest {
// the type name for myS // the type name for myS
IASTName name_type_myS = type_spec_myS.getName(); IASTName name_type_myS = type_spec_myS.getName();
// the declarator for myS // the declarator for myS
IASTDeclarator tor_myS = (IASTDeclarator)decl_myS.getDeclarators().get(0); IASTDeclarator tor_myS = decl_myS.getDeclarators()[0];
// the name for myS // the name for myS
IASTName name_myS = tor_myS.getName(); IASTName name_myS = tor_myS.getName();
// the assignment expression statement // the assignment expression statement
IASTExpressionStatement exprstmt = (IASTExpressionStatement)body_f.getStatements().get(1); IASTExpressionStatement exprstmt = (IASTExpressionStatement)body_f.getStatements()[1];
// the assignment expression // the assignment expression
IASTBinaryExpression assexpr = (IASTBinaryExpression)exprstmt.getExpression(); IASTBinaryExpression assexpr = (IASTBinaryExpression)exprstmt.getExpression();
// the field reference to myS.x // the field reference to myS.x
@ -286,12 +279,12 @@ public class AST2Tests extends AST2BaseTest {
public void testMultipleDeclarators() throws Exception { public void testMultipleDeclarators() throws Exception {
IASTTranslationUnit tu = parse( "int r, s;" , ParserLanguage.C ); //$NON-NLS-1$ IASTTranslationUnit tu = parse( "int r, s;" , ParserLanguage.C ); //$NON-NLS-1$
IASTSimpleDeclaration decl = (IASTSimpleDeclaration)tu.getDeclarations().get(0); IASTSimpleDeclaration decl = (IASTSimpleDeclaration)tu.getDeclarations()[0];
List declarators = decl.getDeclarators(); IASTDeclarator[] declarators = decl.getDeclarators();
assertEquals( 2, declarators.size() ); assertEquals( 2, declarators.length );
IASTDeclarator dtor1 = (IASTDeclarator) declarators.get(0); IASTDeclarator dtor1 = declarators[0];
IASTDeclarator dtor2 = (IASTDeclarator) declarators.get(1); IASTDeclarator dtor2 = declarators[1];
IASTName name1 = dtor1.getName(); IASTName name1 = dtor1.getName();
IASTName name2 = dtor2.getName(); IASTName name2 = dtor2.getName();
@ -311,29 +304,29 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
//struct A; //struct A;
IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations().get(0); IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTElaboratedTypeSpecifier compTypeSpec = (IASTElaboratedTypeSpecifier) decl1.getDeclSpecifier(); IASTElaboratedTypeSpecifier compTypeSpec = (IASTElaboratedTypeSpecifier) decl1.getDeclSpecifier();
assertEquals( 0, decl1.getDeclarators().size() ); assertEquals( 0, decl1.getDeclarators().length );
IASTName nameA1 = compTypeSpec.getName(); IASTName nameA1 = compTypeSpec.getName();
//void f() { //void f() {
IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations().get(1); IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations()[1];
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody(); IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody();
assertEquals( 2, compoundStatement.getStatements().size() ); assertEquals( 2, compoundStatement.getStatements().length );
// struct A; // struct A;
IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compoundStatement.getStatements().get( 0 ); IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compoundStatement.getStatements()[0];
IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) declStatement.getDeclaration(); IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) declStatement.getDeclaration();
compTypeSpec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier(); compTypeSpec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier();
assertEquals( 0, decl2.getDeclarators().size() ); assertEquals( 0, decl2.getDeclarators().length );
IASTName nameA2 = compTypeSpec.getName(); IASTName nameA2 = compTypeSpec.getName();
// struct A * a; // struct A * a;
declStatement = (IASTDeclarationStatement) compoundStatement.getStatements().get(1); declStatement = (IASTDeclarationStatement) compoundStatement.getStatements()[1];
IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) declStatement.getDeclaration(); IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) declStatement.getDeclaration();
compTypeSpec = (IASTElaboratedTypeSpecifier) decl3.getDeclSpecifier(); compTypeSpec = (IASTElaboratedTypeSpecifier) decl3.getDeclSpecifier();
IASTName nameA3 = compTypeSpec.getName(); IASTName nameA3 = compTypeSpec.getName();
IASTDeclarator dtor = (IASTDeclarator) decl3.getDeclarators().get(0); IASTDeclarator dtor = decl3.getDeclarators()[0];
IASTName namea = dtor.getName(); IASTName namea = dtor.getName();
assertEquals( 1, dtor.getPointerOperators().size() ); assertEquals( 1, dtor.getPointerOperators().size() );
assertTrue( dtor.getPointerOperators().get(0) instanceof ICASTPointer ); assertTrue( dtor.getPointerOperators().get(0) instanceof ICASTPointer );
@ -361,22 +354,22 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
//struct A; //struct A;
IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations().get(0); IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTElaboratedTypeSpecifier compTypeSpec = (IASTElaboratedTypeSpecifier) decl1.getDeclSpecifier(); IASTElaboratedTypeSpecifier compTypeSpec = (IASTElaboratedTypeSpecifier) decl1.getDeclSpecifier();
assertEquals( 0, decl1.getDeclarators().size() ); assertEquals( 0, decl1.getDeclarators().length );
IASTName nameA1 = compTypeSpec.getName(); IASTName nameA1 = compTypeSpec.getName();
//void f() { //void f() {
IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations().get(1); IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations()[1];
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody(); IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody();
assertEquals( 1, compoundStatement.getStatements().size() ); assertEquals( 1, compoundStatement.getStatements().length );
// struct A * a; // struct A * a;
IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compoundStatement.getStatements().get(0); IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compoundStatement.getStatements()[0];
IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) declStatement.getDeclaration(); IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) declStatement.getDeclaration();
compTypeSpec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier(); compTypeSpec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier();
IASTName nameA2 = compTypeSpec.getName(); IASTName nameA2 = compTypeSpec.getName();
IASTDeclarator dtor = (IASTDeclarator) decl2.getDeclarators().get(0); IASTDeclarator dtor = decl2.getDeclarators()[0];
IASTName namea = dtor.getName(); IASTName namea = dtor.getName();
assertEquals( 1, dtor.getPointerOperators().size() ); assertEquals( 1, dtor.getPointerOperators().size() );
assertTrue( dtor.getPointerOperators().get(0) instanceof ICASTPointer ); assertTrue( dtor.getPointerOperators().get(0) instanceof ICASTPointer );
@ -403,37 +396,37 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
//struct A; //struct A;
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations().get(0); IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) decl.getDeclSpecifier(); IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) decl.getDeclSpecifier();
assertEquals( 0, decl.getDeclarators().size() ); assertEquals( 0, decl.getDeclarators().length );
IASTName name_A1 = elabTypeSpec.getName(); IASTName name_A1 = elabTypeSpec.getName();
//struct A * a; //struct A * a;
decl = (IASTSimpleDeclaration) tu.getDeclarations().get(1); decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
elabTypeSpec = (IASTElaboratedTypeSpecifier) decl.getDeclSpecifier(); elabTypeSpec = (IASTElaboratedTypeSpecifier) decl.getDeclSpecifier();
IASTName name_A2 = elabTypeSpec.getName(); IASTName name_A2 = elabTypeSpec.getName();
IASTDeclarator dtor = (IASTDeclarator) decl.getDeclarators().get(0); IASTDeclarator dtor = decl.getDeclarators()[0];
IASTName name_a = dtor.getName(); IASTName name_a = dtor.getName();
assertEquals( 1, dtor.getPointerOperators().size() ); assertEquals( 1, dtor.getPointerOperators().size() );
assertTrue( dtor.getPointerOperators().get(0) instanceof ICASTPointer ); assertTrue( dtor.getPointerOperators().get(0) instanceof ICASTPointer );
//struct A { //struct A {
decl = (IASTSimpleDeclaration) tu.getDeclarations().get(2); decl = (IASTSimpleDeclaration) tu.getDeclarations()[2];
ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) decl.getDeclSpecifier(); ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) decl.getDeclSpecifier();
IASTName name_Adef = compTypeSpec.getName(); IASTName name_Adef = compTypeSpec.getName();
// int i; // int i;
decl = (IASTSimpleDeclaration) compTypeSpec.getMembers().get(0); decl = (IASTSimpleDeclaration) compTypeSpec.getMembers()[0];
dtor = (IASTDeclarator) decl.getDeclarators().get(0); dtor = decl.getDeclarators()[0];
IASTName name_i = dtor.getName(); IASTName name_i = dtor.getName();
//void f() { //void f() {
IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations().get(3); IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations()[3];
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody(); IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody();
assertEquals( 1, compoundStatement.getStatements().size() ); assertEquals( 1, compoundStatement.getStatements().length );
// a->i; // a->i;
IASTExpressionStatement exprstmt = (IASTExpressionStatement)compoundStatement.getStatements().get(0); IASTExpressionStatement exprstmt = (IASTExpressionStatement)compoundStatement.getStatements()[0];
IASTFieldReference fieldref = (IASTFieldReference)exprstmt.getExpression(); IASTFieldReference fieldref = (IASTFieldReference)exprstmt.getExpression();
IASTIdExpression id_a = (IASTIdExpression) fieldref.getFieldOwner(); IASTIdExpression id_a = (IASTIdExpression) fieldref.getFieldOwner();
IASTName name_aref = id_a.getName(); IASTName name_aref = id_a.getName();
@ -466,16 +459,16 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) tu.getDeclarations().get(0); IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTCompositeTypeSpecifier typeSpec = (IASTCompositeTypeSpecifier) declaration.getDeclSpecifier(); IASTCompositeTypeSpecifier typeSpec = (IASTCompositeTypeSpecifier) declaration.getDeclSpecifier();
IASTName x_1 = typeSpec.getName(); IASTName x_1 = typeSpec.getName();
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations().get(1); IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[1];
IASTParameterDeclaration param = (IASTParameterDeclaration) fdef.getDeclarator().getParameters().get(0); IASTParameterDeclaration param = fdef.getDeclarator().getParameters()[0];
IASTName x_2 = param.getDeclarator().getName(); IASTName x_2 = param.getDeclarator().getName();
IASTCompoundStatement compound = (IASTCompoundStatement) fdef.getBody(); IASTCompoundStatement compound = (IASTCompoundStatement) fdef.getBody();
IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compound.getStatements().get(0); IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compound.getStatements()[0];
declaration = (IASTSimpleDeclaration) declStatement.getDeclaration(); declaration = (IASTSimpleDeclaration) declStatement.getDeclaration();
IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier) declaration.getDeclSpecifier(); IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier) declaration.getDeclSpecifier();
IASTName x_3 = elab.getName(); IASTName x_3 = elab.getName();
@ -500,26 +493,26 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
//void f( //void f(
IASTSimpleDeclaration f_decl = (IASTSimpleDeclaration) tu.getDeclarations().get(0); IASTSimpleDeclaration f_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) f_decl.getDeclarators().get(0); IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) f_decl.getDeclarators()[0];
IASTName f_name1 = dtor.getName(); IASTName f_name1 = dtor.getName();
// int a ); // int a );
IASTParameterDeclaration param = (IASTParameterDeclaration) dtor.getParameters().get(0); IASTParameterDeclaration param = dtor.getParameters()[0];
IASTDeclarator paramDtor = param.getDeclarator(); IASTDeclarator paramDtor = param.getDeclarator();
IASTName name_param1 = paramDtor.getName(); IASTName name_param1 = paramDtor.getName();
//void f( //void f(
IASTFunctionDefinition f_defn = (IASTFunctionDefinition) tu.getDeclarations().get(1); IASTFunctionDefinition f_defn = (IASTFunctionDefinition) tu.getDeclarations()[1];
dtor = f_defn.getDeclarator(); dtor = f_defn.getDeclarator();
IASTName f_name2 = dtor.getName(); IASTName f_name2 = dtor.getName();
// int b ); // int b );
param = (IASTParameterDeclaration) dtor.getParameters().get(0); param = dtor.getParameters()[0];
paramDtor = param.getDeclarator(); paramDtor = param.getDeclarator();
IASTName name_param2 = paramDtor.getName(); IASTName name_param2 = paramDtor.getName();
// b; // b;
IASTCompoundStatement compound = (IASTCompoundStatement) f_defn.getBody(); IASTCompoundStatement compound = (IASTCompoundStatement) f_defn.getBody();
IASTExpressionStatement expStatement = (IASTExpressionStatement) compound.getStatements().get(0); IASTExpressionStatement expStatement = (IASTExpressionStatement) compound.getStatements()[0];
IASTIdExpression idexp = (IASTIdExpression) expStatement.getExpression(); IASTIdExpression idexp = (IASTIdExpression) expStatement.getExpression();
IASTName name_param3 = idexp.getName(); IASTName name_param3 = idexp.getName();
@ -553,14 +546,14 @@ public class AST2Tests extends AST2BaseTest {
StringBuffer buffer = new StringBuffer( "void f( int a, int b ) { } \n" ); //$NON-NLS-1$ StringBuffer buffer = new StringBuffer( "void f( int a, int b ) { } \n" ); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
IASTFunctionDefinition fDef = (IASTFunctionDefinition) tu.getDeclarations().get(0); IASTFunctionDefinition fDef = (IASTFunctionDefinition) tu.getDeclarations()[0];
IASTFunctionDeclarator fDtor = fDef.getDeclarator(); IASTFunctionDeclarator fDtor = fDef.getDeclarator();
IASTName fName = fDtor.getName(); IASTName fName = fDtor.getName();
IASTParameterDeclaration a = (IASTParameterDeclaration) fDtor.getParameters().get( 0 ); IASTParameterDeclaration a = fDtor.getParameters()[0];
IASTName name_a = a.getDeclarator().getName(); IASTName name_a = a.getDeclarator().getName();
IASTParameterDeclaration b = (IASTParameterDeclaration) fDtor.getParameters().get( 1 ); IASTParameterDeclaration b = fDtor.getParameters()[1];
IASTName name_b = b.getDeclarator().getName(); IASTName name_b = b.getDeclarator().getName();
IFunction function = (IFunction) fName.resolveBinding(); IFunction function = (IFunction) fName.resolveBinding();
@ -588,23 +581,23 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
//void f(); //void f();
IASTSimpleDeclaration fdecl = (IASTSimpleDeclaration) tu.getDeclarations().get(0); IASTSimpleDeclaration fdecl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTFunctionDeclarator fdtor = (IASTFunctionDeclarator) fdecl.getDeclarators().get(0); IASTFunctionDeclarator fdtor = (IASTFunctionDeclarator) fdecl.getDeclarators()[0];
IASTName name_f = fdtor.getName(); IASTName name_f = fdtor.getName();
//void g() { //void g() {
IASTFunctionDefinition gdef = (IASTFunctionDefinition) tu.getDeclarations().get(1); IASTFunctionDefinition gdef = (IASTFunctionDefinition) tu.getDeclarations()[1];
// f(); // f();
IASTCompoundStatement compound = (IASTCompoundStatement) gdef.getBody(); IASTCompoundStatement compound = (IASTCompoundStatement) gdef.getBody();
IASTExpressionStatement expStatement = (IASTExpressionStatement) compound.getStatements().get(0); IASTExpressionStatement expStatement = (IASTExpressionStatement) compound.getStatements()[0];
IASTFunctionCallExpression fcall = (IASTFunctionCallExpression) expStatement.getExpression(); IASTFunctionCallExpression fcall = (IASTFunctionCallExpression) expStatement.getExpression();
IASTIdExpression fcall_id = (IASTIdExpression) fcall.getFunctionNameExpression(); IASTIdExpression fcall_id = (IASTIdExpression) fcall.getFunctionNameExpression();
IASTName name_fcall = fcall_id.getName(); IASTName name_fcall = fcall_id.getName();
assertNull( fcall.getParameterExpression() ); assertNull( fcall.getParameterExpression() );
//void f() {} //void f() {}
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations().get(2); IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[2];
fdtor = fdef.getDeclarator(); fdtor = fdef.getDeclarator();
IASTName name_fdef = fdtor.getName(); IASTName name_fdef = fdtor.getName();
@ -629,15 +622,15 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
//void f() { //void f() {
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations().get(0); IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[0];
IASTCompoundStatement compound = (IASTCompoundStatement) fdef.getBody(); IASTCompoundStatement compound = (IASTCompoundStatement) fdef.getBody();
// for( // for(
IASTForStatement for_stmt = (IASTForStatement) compound.getStatements().get(0); IASTForStatement for_stmt = (IASTForStatement) compound.getStatements()[0];
// int i = 0; // int i = 0;
assertNull( for_stmt.getInitExpression() ); assertNull( for_stmt.getInitExpression() );
IASTSimpleDeclaration initDecl = (IASTSimpleDeclaration) for_stmt.getInitDeclaration(); IASTSimpleDeclaration initDecl = (IASTSimpleDeclaration) for_stmt.getInitDeclaration();
IASTDeclarator dtor = (IASTDeclarator) initDecl.getDeclarators().get(0); IASTDeclarator dtor = initDecl.getDeclarators()[0];
IASTName name_i = dtor.getName(); IASTName name_i = dtor.getName();
// i < 5; // i < 5;
IASTBinaryExpression exp = (IASTBinaryExpression) for_stmt.getCondition(); IASTBinaryExpression exp = (IASTBinaryExpression) for_stmt.getCondition();
@ -653,7 +646,7 @@ public class AST2Tests extends AST2BaseTest {
// i; // i;
compound = (IASTCompoundStatement) for_stmt.getBody(); compound = (IASTCompoundStatement) for_stmt.getBody();
IASTExpressionStatement exprSt = (IASTExpressionStatement) compound.getStatements().get(0); IASTExpressionStatement exprSt = (IASTExpressionStatement) compound.getStatements()[0];
IASTIdExpression id_i3 = (IASTIdExpression) exprSt.getExpression(); IASTIdExpression id_i3 = (IASTIdExpression) exprSt.getExpression();
IASTName name_i4 = id_i3.getName(); IASTName name_i4 = id_i3.getName();
@ -677,13 +670,13 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) tu.getDeclarations().get(0); IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTCompositeTypeSpecifier compType = (IASTCompositeTypeSpecifier) simpleDecl.getDeclSpecifier(); IASTCompositeTypeSpecifier compType = (IASTCompositeTypeSpecifier) simpleDecl.getDeclSpecifier();
IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) compType.getMembers().get(0); IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) compType.getMembers()[0];
IASTName name_x1 = ((IASTDeclarator) decl_x.getDeclarators().get(0)).getName(); IASTName name_x1 = decl_x.getDeclarators()[0].getName();
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations().get(1); IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[1];
IASTCompoundStatement body = (IASTCompoundStatement) fdef.getBody(); IASTCompoundStatement body = (IASTCompoundStatement) fdef.getBody();
IASTExpressionStatement expStatement = (IASTExpressionStatement) body.getStatements().get(0); IASTExpressionStatement expStatement = (IASTExpressionStatement) body.getStatements()[0];
IASTFieldReference fieldRef = (IASTFieldReference) expStatement.getExpression(); IASTFieldReference fieldRef = (IASTFieldReference) expStatement.getExpression();
IASTName name_x2 = fieldRef.getFieldName(); IASTName name_x2 = fieldRef.getFieldName();
@ -743,26 +736,26 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations().get( 0 ); IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
assertEquals( decl.getDeclarators().size(), 0 ); assertEquals( decl.getDeclarators().length, 0 );
ICASTEnumerationSpecifier enumSpec = (ICASTEnumerationSpecifier) decl.getDeclSpecifier(); ICASTEnumerationSpecifier enumSpec = (ICASTEnumerationSpecifier) decl.getDeclSpecifier();
IASTEnumerator e1 = (IASTEnumerator) enumSpec.getEnumerators().get(0); IASTEnumerator e1 = enumSpec.getEnumerators()[0];
IASTEnumerator e2 = (IASTEnumerator) enumSpec.getEnumerators().get(1); IASTEnumerator e2 = enumSpec.getEnumerators()[1];
IASTEnumerator e3 = (IASTEnumerator) enumSpec.getEnumerators().get(2); IASTEnumerator e3 = enumSpec.getEnumerators()[2];
IASTName name_hue = enumSpec.getName(); IASTName name_hue = enumSpec.getName();
decl = (IASTSimpleDeclaration) tu.getDeclarations().get(1); decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
IASTDeclarator dtor = (IASTDeclarator) decl.getDeclarators().get(0); IASTDeclarator dtor = decl.getDeclarators()[0];
IASTName name_col = dtor.getName(); IASTName name_col = dtor.getName();
dtor = (IASTDeclarator) decl.getDeclarators().get(1); dtor = decl.getDeclarators()[1];
IASTName name_cp = dtor.getName(); IASTName name_cp = dtor.getName();
IASTElaboratedTypeSpecifier spec = (IASTElaboratedTypeSpecifier) decl.getDeclSpecifier(); IASTElaboratedTypeSpecifier spec = (IASTElaboratedTypeSpecifier) decl.getDeclSpecifier();
assertEquals( spec.getKind(), IASTElaboratedTypeSpecifier.k_enum ); assertEquals( spec.getKind(), IASTElaboratedTypeSpecifier.k_enum );
IASTName name_hue2 = spec.getName(); IASTName name_hue2 = spec.getName();
IASTFunctionDefinition fn = (IASTFunctionDefinition) tu.getDeclarations().get(2); IASTFunctionDefinition fn = (IASTFunctionDefinition) tu.getDeclarations()[2];
IASTCompoundStatement compound = (IASTCompoundStatement) fn.getBody(); IASTCompoundStatement compound = (IASTCompoundStatement) fn.getBody();
IASTExpressionStatement expStatement = (IASTExpressionStatement) compound.getStatements().get(0); IASTExpressionStatement expStatement = (IASTExpressionStatement) compound.getStatements()[0];
IASTBinaryExpression exp = (IASTBinaryExpression) expStatement.getExpression(); IASTBinaryExpression exp = (IASTBinaryExpression) expStatement.getExpression();
assertEquals( exp.getOperator(), IASTBinaryExpression.op_assign ); assertEquals( exp.getOperator(), IASTBinaryExpression.op_assign );
IASTIdExpression id1 = (IASTIdExpression) exp.getOperand1(); IASTIdExpression id1 = (IASTIdExpression) exp.getOperand1();
@ -770,7 +763,7 @@ public class AST2Tests extends AST2BaseTest {
IASTName r_col = id1.getName(); IASTName r_col = id1.getName();
IASTName r_blue = id2.getName(); IASTName r_blue = id2.getName();
expStatement = (IASTExpressionStatement) compound.getStatements().get(1); expStatement = (IASTExpressionStatement) compound.getStatements()[1];
exp = (IASTBinaryExpression) expStatement.getExpression(); exp = (IASTBinaryExpression) expStatement.getExpression();
assertEquals( exp.getOperator(), IASTBinaryExpression.op_assign ); assertEquals( exp.getOperator(), IASTBinaryExpression.op_assign );
id1 = (IASTIdExpression) exp.getOperand1(); id1 = (IASTIdExpression) exp.getOperand1();
@ -779,7 +772,7 @@ public class AST2Tests extends AST2BaseTest {
IASTName r_cp = id1.getName(); IASTName r_cp = id1.getName();
IASTName r_col2 = id2.getName(); IASTName r_col2 = id2.getName();
IASTIfStatement ifStatement = (IASTIfStatement) compound.getStatements().get(2); IASTIfStatement ifStatement = (IASTIfStatement) compound.getStatements()[2];
exp = (IASTBinaryExpression) ifStatement.getCondition(); exp = (IASTBinaryExpression) ifStatement.getCondition();
ue = (IASTUnaryExpression) exp.getOperand1(); ue = (IASTUnaryExpression) exp.getOperand1();
id1 = (IASTIdExpression) ue.getOperand(); id1 = (IASTIdExpression) ue.getOperand();
@ -820,20 +813,20 @@ public class AST2Tests extends AST2BaseTest {
public void testPointerToFunction() throws Exception public void testPointerToFunction() throws Exception
{ {
IASTTranslationUnit tu = parse( "int (*pfi)();", ParserLanguage.C ); //$NON-NLS-1$ IASTTranslationUnit tu = parse( "int (*pfi)();", ParserLanguage.C ); //$NON-NLS-1$
assertEquals( tu.getDeclarations().size(), 1 ); assertEquals( tu.getDeclarations().length, 1 );
IASTSimpleDeclaration d = (IASTSimpleDeclaration) tu.getDeclarations().get(0); IASTSimpleDeclaration d = (IASTSimpleDeclaration) tu.getDeclarations()[0];
assertEquals( d.getDeclarators().size(), 1 ); assertEquals( d.getDeclarators().length, 1 );
IASTFunctionDeclarator f = (IASTFunctionDeclarator) d.getDeclarators().get(0); IASTFunctionDeclarator f = (IASTFunctionDeclarator) d.getDeclarators()[0];
assertNull( f.getName().toString() ); assertNull( f.getName().toString() );
assertNotNull( f.getNestedDeclarator() ); assertNotNull( f.getNestedDeclarator() );
assertEquals( f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$ assertEquals( f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$
assertTrue( f.getPointerOperators().isEmpty() ); assertTrue( f.getPointerOperators().isEmpty() );
assertFalse( f.getNestedDeclarator().getPointerOperators().isEmpty() ); assertFalse( f.getNestedDeclarator().getPointerOperators().isEmpty() );
tu = parse( "int (*pfi)();", ParserLanguage.CPP ); //$NON-NLS-1$ tu = parse( "int (*pfi)();", ParserLanguage.CPP ); //$NON-NLS-1$
assertEquals( tu.getDeclarations().size(), 1 ); assertEquals( tu.getDeclarations().length, 1 );
d = (IASTSimpleDeclaration) tu.getDeclarations().get(0); d = (IASTSimpleDeclaration) tu.getDeclarations()[0];
assertEquals( d.getDeclarators().size(), 1 ); assertEquals( d.getDeclarators().length, 1 );
f = (IASTFunctionDeclarator) d.getDeclarators().get(0); f = (IASTFunctionDeclarator) d.getDeclarators()[0];
assertNull( f.getName().toString() ); assertNull( f.getName().toString() );
assertNotNull( f.getNestedDeclarator() ); assertNotNull( f.getNestedDeclarator() );
assertEquals( f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$ assertEquals( f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$
@ -849,9 +842,9 @@ public class AST2Tests extends AST2BaseTest {
buffer.append( "};\n"); //$NON-NLS-1$ buffer.append( "};\n"); //$NON-NLS-1$
buffer.append( "int X:: * pmi = &X::a;\n"); //$NON-NLS-1$ buffer.append( "int X:: * pmi = &X::a;\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP ); IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
assertEquals( tu.getDeclarations().size(), 2 ); assertEquals( tu.getDeclarations().length, 2 );
IASTSimpleDeclaration p2m = (IASTSimpleDeclaration) tu.getDeclarations().get(1); IASTSimpleDeclaration p2m = (IASTSimpleDeclaration) tu.getDeclarations()[1];
IASTDeclarator d = (IASTDeclarator) p2m.getDeclarators().get(0); IASTDeclarator d = p2m.getDeclarators()[0];
ICPPASTPointerToMember po = (ICPPASTPointerToMember) d.getPointerOperators().get(0); ICPPASTPointerToMember po = (ICPPASTPointerToMember) d.getPointerOperators().get(0);
assertEquals( po.getName().toString(), "X::"); //$NON-NLS-1$ assertEquals( po.getName().toString(), "X::"); //$NON-NLS-1$
} }

View file

@ -10,7 +10,6 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
import java.util.List;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
@ -46,7 +45,9 @@ public interface IASTCompositeTypeSpecifier extends IASTDeclSpecifier {
* *
* @return List of IASTDeclaration * @return List of IASTDeclaration
*/ */
public List getMembers(); public IASTDeclaration[] getMembers();
public void addMemberDeclaration( IASTDeclaration declaration ); public void addMemberDeclaration( IASTDeclaration declaration );
public IScope getScope();
} }

View file

@ -10,7 +10,6 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
import java.util.List;
/** /**
* This represents a block of statements. * This represents a block of statements.
@ -26,8 +25,9 @@ public interface IASTCompoundStatement extends IASTStatement {
* *
* @return List of IASTStatement * @return List of IASTStatement
*/ */
public List getStatements(); public IASTStatement[] getStatements();
public void addStatement( IASTStatement statement ); public void addStatement( IASTStatement statement );
public IScope getScope();
} }

View file

@ -16,5 +16,6 @@ package org.eclipse.cdt.core.dom.ast;
* @author Doug Schaefer * @author Doug Schaefer
*/ */
public interface IASTDeclaration extends IASTNode { public interface IASTDeclaration extends IASTNode {
public static final IASTDeclaration [] EMPTY_DECLARATION_ARRAY = new IASTDeclaration[0];
} }

View file

@ -16,6 +16,7 @@ import java.util.List;
* @author Doug Schaefer * @author Doug Schaefer
*/ */
public interface IASTDeclarator extends IASTNode { public interface IASTDeclarator extends IASTNode {
public static final IASTDeclarator[] EMPTY_DECLARATOR_ARRAY = new IASTDeclarator[0];
ASTNodeProperty POINTER_OPERATOR = new ASTNodeProperty( "Pointer Operator"); //$NON-NLS-1$ ASTNodeProperty POINTER_OPERATOR = new ASTNodeProperty( "Pointer Operator"); //$NON-NLS-1$
ASTNodeProperty INITIALIZER = new ASTNodeProperty( "Initializer"); //$NON-NLS-1$ ASTNodeProperty INITIALIZER = new ASTNodeProperty( "Initializer"); //$NON-NLS-1$

View file

@ -9,7 +9,6 @@
* IBM Rational Software - Initial API and implementation */ * IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
import java.util.List;
/** /**
* @author jcamelon * @author jcamelon
@ -20,6 +19,7 @@ public interface IASTEnumerationSpecifier extends IASTDeclSpecifier {
* @author jcamelon * @author jcamelon
*/ */
public interface IASTEnumerator extends IASTNode { public interface IASTEnumerator extends IASTNode {
public static final IASTEnumerator[] EMPTY_ENUMERATOR_ARRAY = new IASTEnumerator[0];
public static final ASTNodeProperty ENUMERATOR_NAME = new ASTNodeProperty( "Enumerator Name"); //$NON-NLS-1$ public static final ASTNodeProperty ENUMERATOR_NAME = new ASTNodeProperty( "Enumerator Name"); //$NON-NLS-1$
public void setName( IASTName name ); public void setName( IASTName name );
@ -33,7 +33,7 @@ public interface IASTEnumerationSpecifier extends IASTDeclSpecifier {
public static final ASTNodeProperty ENUMERATOR = new ASTNodeProperty( "Enumerator" ); //$NON-NLS-1$ public static final ASTNodeProperty ENUMERATOR = new ASTNodeProperty( "Enumerator" ); //$NON-NLS-1$
public void addEnumerator( IASTEnumerator enumerator ); public void addEnumerator( IASTEnumerator enumerator );
public List getEnumerators(); public IASTEnumerator[] getEnumerators();
public static final ASTNodeProperty ENUMERATION_NAME = new ASTNodeProperty( "Enum Name"); //$NON-NLS-1$ public static final ASTNodeProperty ENUMERATION_NAME = new ASTNodeProperty( "Enum Name"); //$NON-NLS-1$
public void setName( IASTName name ); public void setName( IASTName name );

View file

@ -16,5 +16,5 @@ package org.eclipse.cdt.core.dom.ast;
* @author Doug Schaefer * @author Doug Schaefer
*/ */
public interface IASTExpression extends IASTNode { public interface IASTExpression extends IASTNode {
public static final IASTExpression [] EMPTY_EXPRESSION_ARRAY = new IASTExpression[0];
} }

View file

@ -9,7 +9,6 @@
* IBM Rational Software - Initial API and implementation */ * IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
import java.util.List;
/** /**
* @author jcamelon * @author jcamelon
@ -18,7 +17,7 @@ public interface IASTExpressionList extends IASTExpression {
public static final ASTNodeProperty NESTED_EXPRESSION = new ASTNodeProperty( "Nested Expression"); //$NON-NLS-1$ public static final ASTNodeProperty NESTED_EXPRESSION = new ASTNodeProperty( "Nested Expression"); //$NON-NLS-1$
public List getExpressions(); public IASTExpression [] getExpressions();
public void addExpression( IASTExpression expression ); public void addExpression( IASTExpression expression );
} }

View file

@ -68,4 +68,5 @@ public interface IASTForStatement extends IASTStatement {
public IASTStatement getBody(); public IASTStatement getBody();
public void setBody( IASTStatement statement ); public void setBody( IASTStatement statement );
public IScope getScope();
} }

View file

@ -10,7 +10,6 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
import java.util.List;
/** /**
* This is a declarator for a function. * This is a declarator for a function.
@ -25,7 +24,7 @@ public interface IASTFunctionDeclarator extends IASTDeclarator {
* *
* @return List of IASTParameterDeclaration * @return List of IASTParameterDeclaration
*/ */
public List getParameters(); public IASTParameterDeclaration[] getParameters();
public void addParameterDeclaration( IASTParameterDeclaration parameter ); public void addParameterDeclaration( IASTParameterDeclaration parameter );

View file

@ -16,5 +16,6 @@ package org.eclipse.cdt.core.dom.ast;
* @author Doug Schaefer * @author Doug Schaefer
*/ */
public interface IASTInitializer extends IASTNode { public interface IASTInitializer extends IASTNode {
public final static IASTInitializer[] EMPTY_INIALIZER_ARRAY = new IASTInitializer[0];
} }

View file

@ -10,7 +10,6 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
import java.util.List;
/** /**
* This is an an initializer that is a list of initializers. * This is an an initializer that is a list of initializers.
@ -25,7 +24,7 @@ public interface IASTInitializerList extends IASTInitializer {
* *
* @return * @return
*/ */
public List getInitializers(); public IASTInitializer[] getInitializers();
public void addInitializer( IASTInitializer initializer ); public void addInitializer( IASTInitializer initializer );
} }

View file

@ -28,4 +28,5 @@ public interface IASTName extends IASTNode {
*/ */
public IBinding resolveBinding(); public IBinding resolveBinding();
public char[] toCharArray();
} }

View file

@ -16,6 +16,7 @@ package org.eclipse.cdt.core.dom.ast;
* @author Doug Schaefer * @author Doug Schaefer
*/ */
public interface IASTParameterDeclaration extends IASTNode { public interface IASTParameterDeclaration extends IASTNode {
public static final IASTParameterDeclaration [] EMPTY_PARAMETERDECLARATION_ARRAY = new IASTParameterDeclaration[0];
ASTNodeProperty DECL_SPECIFIER = new ASTNodeProperty( "Decl Specifier"); //$NON-NLS-1$ ASTNodeProperty DECL_SPECIFIER = new ASTNodeProperty( "Decl Specifier"); //$NON-NLS-1$
ASTNodeProperty DECLARATOR = new ASTNodeProperty( "Declarator"); //$NON-NLS-1$ ASTNodeProperty DECLARATOR = new ASTNodeProperty( "Declarator"); //$NON-NLS-1$

View file

@ -10,7 +10,6 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
import java.util.List;
/** /**
* This is a simple declaration which contains a sequence of declSpecifiers * This is a simple declaration which contains a sequence of declSpecifiers
@ -38,7 +37,7 @@ public interface IASTSimpleDeclaration extends IASTDeclaration, IASTNode {
* *
* @return list of IASTDeclarator * @return list of IASTDeclarator
*/ */
public List getDeclarators(); public IASTDeclarator[] getDeclarators();
public void addDeclarator( IASTDeclarator declarator ); public void addDeclarator( IASTDeclarator declarator );

View file

@ -16,5 +16,6 @@ package org.eclipse.cdt.core.dom.ast;
* @author Doug Schaefer * @author Doug Schaefer
*/ */
public interface IASTStatement extends IASTNode { public interface IASTStatement extends IASTNode {
public static final IASTStatement[] EMPTY_STATEMENT_ARRAY = new IASTStatement[0];
} }

View file

@ -26,7 +26,7 @@ public interface IASTTranslationUnit extends IASTNode {
* *
* @return List of IASTDeclaration * @return List of IASTDeclaration
*/ */
public List getDeclarations(); public IASTDeclaration[] getDeclarations();
public void addDeclaration( IASTDeclaration declaration ); public void addDeclaration( IASTDeclaration declaration );

View file

@ -21,6 +21,7 @@ public interface IBinding {
* @return name * @return name
*/ */
public String getName(); public String getName();
public char[] getNameCharArray();
/** /**
* Every name has a scope. * Every name has a scope.
@ -28,5 +29,6 @@ public interface IBinding {
* @return the scope of this name * @return the scope of this name
*/ */
public IScope getScope(); public IScope getScope();
public IASTNode getPhysicalNode();
} }

View file

@ -10,15 +10,15 @@
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Nov 17, 2004 * Created on Nov 25, 2004
*/ */
package org.eclipse.cdt.core.dom.ast.c; package org.eclipse.cdt.core.dom.ast.c;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IBinding;
/** /**
* @author aniefer * @author aniefer
*/ */
public interface ICBlockScope extends IScope { public interface ICCompositeTypeScope extends ICScope {
public IBinding getBinding( char[] name );
} }

View file

@ -14,11 +14,14 @@
*/ */
package org.eclipse.cdt.core.dom.ast.c; package org.eclipse.cdt.core.dom.ast.c;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
/** /**
* @author aniefer * @author aniefer
*/ */
public interface ICFunctionScope extends IScope { public interface ICFunctionScope extends ICScope {
public IScope getBodyScope();
public IBinding getBinding( char[] name );
} }

View file

@ -10,15 +10,20 @@
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Nov 17, 2004 * Created on Nov 25, 2004
*/ */
package org.eclipse.cdt.core.dom.ast.c; package org.eclipse.cdt.core.dom.ast.c;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
/** /**
* @author aniefer * @author aniefer
*/ */
public interface ICFileScope extends IScope { public interface ICScope extends IScope {
public static final int NAMESPACE_TYPE_TAG = 0;
public static final int NAMESPACE_TYPE_OTHER = 1;
void addBinding( IBinding binding );
public IBinding getBinding( int namespaceType, char [] name );
} }

View file

@ -9,12 +9,9 @@
* IBM Rational Software - Initial API and implementation */ * IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser2.c; package org.eclipse.cdt.internal.core.parser2.c;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
/** /**
@ -57,15 +54,16 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements
private int currentIndex = 0; private int currentIndex = 0;
private IASTDeclaration [] declarations = null; private IASTDeclaration [] declarations = null;
private IScope scope = null;
private static final int DEFAULT_DECLARATIONS_LIST_SIZE = 4; private static final int DEFAULT_DECLARATIONS_LIST_SIZE = 4;
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#getMembers() * @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#getMembers()
*/ */
public List getMembers() { public IASTDeclaration [] getMembers() {
if( declarations == null ) return Collections.EMPTY_LIST; if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
removeNullDeclarations(); removeNullDeclarations();
return Arrays.asList( declarations ); return declarations;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -104,4 +102,13 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements
currentIndex = newSize; currentIndex = newSize;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#getScope()
*/
public IScope getScope() {
if( scope == null )
scope = new CCompositeTypeScope( this );
return scope;
}
} }

View file

@ -9,12 +9,9 @@
* IBM Rational Software - Initial API and implementation */ * IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser2.c; package org.eclipse.cdt.internal.core.parser2.c;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
/** /**
* @author jcamelon * @author jcamelon
@ -39,16 +36,17 @@ public class CASTCompoundStatement extends CASTNode implements
private IASTStatement [] statements = null; private IASTStatement [] statements = null;
private IScope scope = null;
private static final int DEFAULT_STATEMENT_LIST_SIZE = 8; private static final int DEFAULT_STATEMENT_LIST_SIZE = 8;
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompoundStatement#getStatements() * @see org.eclipse.cdt.core.dom.ast.IASTCompoundStatement#getStatements()
*/ */
public List getStatements() { public IASTStatement[] getStatements() {
if( statements == null ) return Collections.EMPTY_LIST; if( statements == null ) return IASTStatement.EMPTY_STATEMENT_ARRAY;
removeNullStatements(); removeNullStatements();
return Arrays.asList( statements ); return statements;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -70,4 +68,13 @@ public class CASTCompoundStatement extends CASTNode implements
statements[ currentIndex++ ] = statement; statements[ currentIndex++ ] = statement;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompoundStatement#resolveBinding()
*/
public IScope getScope() {
if( scope == null )
scope = new CScope( this );
return scope;
}
} }

View file

@ -9,10 +9,6 @@
* IBM Rational Software - Initial API and implementation */ * IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser2.c; package org.eclipse.cdt.internal.core.parser2.c;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
@ -46,11 +42,10 @@ public class CASTEnumerationSpecifier extends CASTBaseDeclSpecifier implements
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier#getEnumerators() * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier#getEnumerators()
*/ */
public List getEnumerators() { public IASTEnumerator[] getEnumerators() {
if( enumerators == null ) return Collections.EMPTY_LIST; if( enumerators == null ) return IASTEnumerator.EMPTY_ENUMERATOR_ARRAY;
removeNullEnumerators(); removeNullEnumerators();
return Arrays.asList( enumerators ); return enumerators;
} }
private void removeNullEnumerators() { private void removeNullEnumerators() {

View file

@ -9,10 +9,6 @@
* IBM Rational Software - Initial API and implementation */ * IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser2.c; package org.eclipse.cdt.internal.core.parser2.c;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
@ -24,10 +20,10 @@ public class CASTExpressionList extends CASTNode implements IASTExpressionList {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTExpressionList#getExpressions() * @see org.eclipse.cdt.core.dom.ast.IASTExpressionList#getExpressions()
*/ */
public List getExpressions() { public IASTExpression[] getExpressions() {
if( expressions == null ) return Collections.EMPTY_LIST; if( expressions == null ) return IASTExpression.EMPTY_EXPRESSION_ARRAY;
removeNullExpressions(); removeNullExpressions();
return Arrays.asList( expressions ); return expressions;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -13,12 +13,14 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
/** /**
* @author jcamelon * @author jcamelon
*/ */
public class CASTForStatement extends CASTNode implements IASTForStatement { public class CASTForStatement extends CASTNode implements IASTForStatement {
private IScope scope = null;
private IASTExpression initialExpression; private IASTExpression initialExpression;
private IASTDeclaration initDeclaration; private IASTDeclaration initDeclaration;
private IASTExpression condition; private IASTExpression condition;
@ -96,4 +98,13 @@ public class CASTForStatement extends CASTNode implements IASTForStatement {
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTForStatement#getScope()
*/
public IScope getScope() {
if( scope == null )
scope = new CScope( this );
return scope;
}
} }

View file

@ -9,10 +9,6 @@
* IBM Rational Software - Initial API and implementation */ * IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser2.c; package org.eclipse.cdt.internal.core.parser2.c;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
@ -49,10 +45,10 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator#getParameters() * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator#getParameters()
*/ */
public List getParameters() { public IASTParameterDeclaration[] getParameters() {
if( parameters == null ) return Collections.EMPTY_LIST; if( parameters == null ) return IASTParameterDeclaration.EMPTY_PARAMETERDECLARATION_ARRAY;
removeNullParameters(); removeNullParameters();
return Arrays.asList( parameters ); return parameters;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -9,10 +9,6 @@
* IBM Rational Software - Initial API and implementation */ * IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser2.c; package org.eclipse.cdt.internal.core.parser2.c;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
@ -28,10 +24,10 @@ public class CASTInitializerList extends CASTNode implements
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators() * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators()
*/ */
public List getInitializers() { public IASTInitializer[] getInitializers() {
if( initializers == null ) return Collections.EMPTY_LIST; if( initializers == null ) return IASTInitializer.EMPTY_INIALIZER_ARRAY;
removeNullInitializers(); removeNullInitializers();
return Arrays.asList( initializers ); return initializers;
} }
public void addInitializer( IASTInitializer d ) public void addInitializer( IASTInitializer d )

View file

@ -9,10 +9,6 @@
* IBM Rational Software - Initial API and implementation */ * IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser2.c; package org.eclipse.cdt.internal.core.parser2.c;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
@ -35,10 +31,10 @@ public class CASTSimpleDeclaration extends CASTNode implements
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators() * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators()
*/ */
public List getDeclarators() { public IASTDeclarator[] getDeclarators() {
if( declarators == null ) return Collections.EMPTY_LIST; if( declarators == null ) return IASTDeclarator.EMPTY_DECLARATOR_ARRAY;
removeNullDeclarators(); removeNullDeclarators();
return Arrays.asList( declarators ); return declarators;
} }
public void addDeclarator( IASTDeclarator d ) public void addDeclarator( IASTDeclarator d )

View file

@ -9,8 +9,6 @@
* IBM Rational Software - Initial API and implementation */ * IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.parser2.c; package org.eclipse.cdt.internal.core.parser2.c;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@ -29,7 +27,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
private int currentIndex = 0; private int currentIndex = 0;
//Binding //Binding
private CFileScope compilationUnit = null; private CScope compilationUnit = null;
public void addDeclaration( IASTDeclaration d ) public void addDeclaration( IASTDeclaration d )
{ {
@ -52,10 +50,10 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations()
*/ */
public List getDeclarations() { public IASTDeclaration[] getDeclarations() {
if( decls == null ) return Collections.EMPTY_LIST; if( decls == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
removeNullDeclarations(); removeNullDeclarations();
return Arrays.asList( decls ); return decls;
} }
/** /**
@ -80,7 +78,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
*/ */
public IScope getScope() { public IScope getScope() {
if( compilationUnit == null ) if( compilationUnit == null )
compilationUnit = new CFileScope(); compilationUnit = new CScope( this );
return compilationUnit; return compilationUnit;
} }

View file

@ -0,0 +1,75 @@
/*******************************************************************************
* 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 Corporation - initial API and implementation
*******************************************************************************/
/*
* Created on Nov 25, 2004
*/
package org.eclipse.cdt.internal.core.parser2.c;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
import org.eclipse.cdt.core.dom.ast.c.ICScope;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
/**
* @author aniefer
*/
public class CCompositeTypeScope implements ICCompositeTypeScope {
private ICASTCompositeTypeSpecifier compositeTypeSpec = null;
private CharArrayObjectMap bindings = CharArrayObjectMap.EMPTY_MAP;
public CCompositeTypeScope( ICASTCompositeTypeSpecifier compTypeSpec ){
compositeTypeSpec = compTypeSpec;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICScope#addBinding(org.eclipse.cdt.core.dom.ast.IBinding)
*/
public void addBinding( IBinding binding ) {
if( bindings == CharArrayObjectMap.EMPTY_MAP )
bindings = new CharArrayObjectMap( 1 );
bindings.put( binding.getNameCharArray(), binding );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICScope#getBinding(int, char[])
*/
public IBinding getBinding( int namespaceType, char[] name ) {
if( namespaceType == ICScope.NAMESPACE_TYPE_OTHER )
return getBinding( name );
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope#getBinding(char[])
*/
public IBinding getBinding( char[] name ) {
return (IBinding) bindings.get( name );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#getParent()
*/
public IScope getParent() {
return CVisitor.getContainingScope( compositeTypeSpec );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/
public List find( String name ) {
// TODO Auto-generated method stub
return null;
}
}

View file

@ -14,6 +14,7 @@
*/ */
package org.eclipse.cdt.internal.core.parser2.c; package org.eclipse.cdt.internal.core.parser2.c;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
@ -29,6 +30,9 @@ public class CEnumeration implements IEnumeration {
this.enumSpec = spec; this.enumSpec = spec;
} }
public IASTNode getPhysicalNode(){
return enumSpec;
}
private ICASTEnumerationSpecifier checkForDefinition( ICASTEnumerationSpecifier spec ){ private ICASTEnumerationSpecifier checkForDefinition( ICASTEnumerationSpecifier spec ){
return spec; return spec;
} }
@ -39,13 +43,15 @@ public class CEnumeration implements IEnumeration {
public String getName() { public String getName() {
return enumSpec.getName().toString(); return enumSpec.getName().toString();
} }
public char[] getNameCharArray(){
return ((CASTName) enumSpec.getName()).toCharArray();
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/ */
public IScope getScope() { public IScope getScope() {
// TODO Auto-generated method stub return CVisitor.getContainingScope( enumSpec );
return null;
} }
} }

View file

@ -14,6 +14,7 @@
*/ */
package org.eclipse.cdt.internal.core.parser2.c; package org.eclipse.cdt.internal.core.parser2.c;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
@ -27,19 +28,25 @@ public class CEnumerator implements IEnumerator {
public CEnumerator( IASTEnumerator enumtor ){ public CEnumerator( IASTEnumerator enumtor ){
this.enumerator= enumtor; this.enumerator= enumtor;
} }
public IASTNode getPhysicalNode(){
return enumerator;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName() * @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/ */
public String getName() { public String getName() {
return enumerator.getName().toString(); return enumerator.getName().toString();
} }
public char[] getNameCharArray(){
return ((CASTName) enumerator.getName()).toCharArray();
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/ */
public IScope getScope() { public IScope getScope() {
// TODO Auto-generated method stub return CVisitor.getContainingScope( enumerator );
return null;
} }
} }

View file

@ -1,37 +0,0 @@
/**********************************************************************
* Copyright (c) 2002-2004 IBM Canada and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.internal.core.parser2.c;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.c.ICFileScope;
/**
* @author aniefer
*/
public class CFileScope implements ICFileScope{
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#getParent()
*/
public IScope getParent() {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/
public List find(String name) {
return null;
}
}

View file

@ -17,6 +17,7 @@ import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
@ -26,37 +27,67 @@ import org.eclipse.cdt.core.dom.ast.IScope;
* @author aniefer * @author aniefer
*/ */
public class CFunction implements IFunction { public class CFunction implements IFunction {
final private IASTFunctionDeclarator declarator; private IASTFunctionDeclarator [] declarators = null;
private IASTFunctionDeclarator definition;
final private IScope functionScope; final private IScope functionScope;
public CFunction( IASTFunctionDeclarator declarator ){ public CFunction( IASTFunctionDeclarator declarator ){
declarator = checkForDefinition( declarator ); if( declarator.getParent() instanceof IASTFunctionDefinition )
this.declarator = declarator; definition = declarator;
else {
declarators = new IASTFunctionDeclarator [] { declarator };
}
this.functionScope = new CFunctionScope( this ); this.functionScope = new CFunctionScope( this );
} }
private IASTFunctionDeclarator checkForDefinition( IASTFunctionDeclarator dtor ){ public IASTNode getPhysicalNode(){
if( dtor.getParent() instanceof IASTFunctionDefinition ) return ( definition != null ) ? definition : declarators[0];
return dtor; }
public void addDeclarator( IASTFunctionDeclarator fnDeclarator ){
IASTFunctionDeclarator def = CVisitor.findDefinition( dtor ); if( fnDeclarator instanceof IASTFunctionDefinition )
if( def != null && def != dtor ){ definition = fnDeclarator;
dtor = def; else {
((CASTName)dtor.getName()).setBinding( this ); if( declarators == null ){
} declarators = new IASTFunctionDeclarator[] { fnDeclarator };
return dtor; return;
} }
for( int i = 0; i < declarators.length; i++ ){
if( declarators[i] == null ){
declarators[i] = fnDeclarator;
return;
}
}
IASTFunctionDeclarator tmp [] = new IASTFunctionDeclarator [ declarators.length * 2 ];
System.arraycopy( declarators, 0, tmp, 0, declarators.length );
tmp[ declarators.length ] = fnDeclarator;
declarators = tmp;
}
}
// private IASTFunctionDeclarator checkForDefinition( IASTFunctionDeclarator dtor ){
// if( dtor.getParent() instanceof IASTFunctionDefinition )
// return dtor;
//
// IASTFunctionDeclarator def = CVisitor.findDefinition( dtor );
// if( def != null && def != dtor ){
// dtor = def;
// ((CASTName)dtor.getName()).setBinding( this );
// }
// return dtor;
// }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters() * @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
*/ */
public List getParameters() { public List getParameters() {
List params = declarator.getParameters(); IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarators[0];
int size = params.size(); IASTParameterDeclaration[] params = dtor.getParameters();
int size = params.length;
List result = new ArrayList( size ); List result = new ArrayList( size );
if( size > 0 ){ if( size > 0 ){
for( int i = 0; i < size; i++ ){ for( int i = 0; i < size; i++ ){
IASTParameterDeclaration p = (IASTParameterDeclaration) params.get(i); IASTParameterDeclaration p = params[i];
result.add( p.getDeclarator().getName().resolveBinding() ); result.add( p.getDeclarator().getName().resolveBinding() );
} }
} }
@ -67,14 +98,20 @@ public class CFunction implements IFunction {
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName() * @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/ */
public String getName() { public String getName() {
return declarator.getName().toString(); IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarators[0];
return dtor.getName().toString();
}
public char[] getNameCharArray(){
IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarators[0];
return ((CASTName) dtor.getName()).toCharArray();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/ */
public IScope getScope() { public IScope getScope() {
return CVisitor.getContainingScope( (IASTDeclaration) declarator.getParent() ); IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarators[0];
return CVisitor.getContainingScope( (IASTDeclaration) dtor.getParent() );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -84,7 +121,7 @@ public class CFunction implements IFunction {
return functionScope; return functionScope;
} }
public IASTDeclaration getDeclaration(){ // public IASTDeclaration getDeclaration(){
return (IASTDeclaration) declarator.getParent(); // return (IASTDeclaration) declarator.getParent();
} // }
} }

View file

@ -14,11 +14,18 @@ package org.eclipse.cdt.internal.core.parser2.c;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ILabel;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope; import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
import org.eclipse.cdt.core.dom.ast.c.ICScope;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.internal.core.parser2.c.CVisitor.BaseVisitorAction; import org.eclipse.cdt.internal.core.parser2.c.CVisitor.BaseVisitorAction;
/** /**
@ -27,11 +34,46 @@ import org.eclipse.cdt.internal.core.parser2.c.CVisitor.BaseVisitorAction;
*/ */
public class CFunctionScope implements ICFunctionScope { public class CFunctionScope implements ICFunctionScope {
private final CFunction function; private final CFunction function;
private CharArrayObjectMap bindings = CharArrayObjectMap.EMPTY_MAP;
public CFunctionScope( CFunction function ){ public CFunctionScope( CFunction function ){
this.function = function; this.function = function;
} }
public void addBinding( IBinding binding ) {
//only labels have function scope
if( !(binding instanceof ILabel) )
return;
if( bindings == CharArrayObjectMap.EMPTY_MAP )
bindings = new CharArrayObjectMap(1);
bindings.put( binding.getNameCharArray(), binding );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICScope#getBinding(int, char[])
*/
public IBinding getBinding( int namespaceType, char[] name ) {
if( namespaceType == ICScope.NAMESPACE_TYPE_OTHER )
return getBinding( name );
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICFunctionScope#getBinding(char[])
*/
public IBinding getBinding( char[] name ) {
return (IBinding) bindings.get( name );
}
public IScope getBodyScope(){
IASTFunctionDeclarator fdtor = (IASTFunctionDeclarator) function.getPhysicalNode();
IASTFunctionDefinition fdef = (IASTFunctionDefinition) fdtor.getParent();
IASTStatement statement = fdef.getBody();
if( statement instanceof IASTCompoundStatement ){
return ((IASTCompoundStatement)statement).getScope();
}
return null;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#getParent() * @see org.eclipse.cdt.core.dom.ast.IScope#getParent()
*/ */
@ -48,16 +90,18 @@ public class CFunctionScope implements ICFunctionScope {
public List getLabels(){ public List getLabels(){
FindLabelsAction action = new FindLabelsAction(); FindLabelsAction action = new FindLabelsAction();
CVisitor.visitDeclaration( function.getDeclaration(), action ); IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) function.getPhysicalNode();
if( dtor.getParent() instanceof IASTFunctionDefinition )
CVisitor.visitDeclaration( (IASTDeclaration) dtor.getParent(), action );
List bindings = new ArrayList(); List list = new ArrayList();
for( int i = 0; i < action.labels.size(); i++ ){ for( int i = 0; i < action.labels.size(); i++ ){
IASTLabelStatement labelStatement = (IASTLabelStatement) action.labels.get(i); IASTLabelStatement labelStatement = (IASTLabelStatement) action.labels.get(i);
IBinding binding = labelStatement.getName().resolveBinding(); IBinding binding = labelStatement.getName().resolveBinding();
if( binding != null ) if( binding != null )
bindings.add( binding ); list.add( binding );
} }
return bindings; return list;
} }
static private class FindLabelsAction extends BaseVisitorAction { static private class FindLabelsAction extends BaseVisitorAction {
@ -75,4 +119,6 @@ public class CFunctionScope implements ICFunctionScope {
return true; return true;
} }
} }
} }

View file

@ -15,6 +15,7 @@
package org.eclipse.cdt.internal.core.parser2.c; package org.eclipse.cdt.internal.core.parser2.c;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.ILabel; import org.eclipse.cdt.core.dom.ast.ILabel;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
@ -28,7 +29,9 @@ public class CLabel implements ILabel {
public CLabel( IASTLabelStatement statement ){ public CLabel( IASTLabelStatement statement ){
labelStatement = statement; labelStatement = statement;
} }
public IASTNode getPhysicalNode(){
return labelStatement;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.ILabel#getLabelStatement() * @see org.eclipse.cdt.core.dom.ast.ILabel#getLabelStatement()
*/ */
@ -42,6 +45,9 @@ public class CLabel implements ILabel {
public String getName() { public String getName() {
return labelStatement.getName().toString(); return labelStatement.getName().toString();
} }
public char[] getNameCharArray(){
return ((CASTName) labelStatement.getName()).toCharArray();
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()

View file

@ -13,8 +13,7 @@ package org.eclipse.cdt.internal.core.parser2.c;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
@ -29,26 +28,29 @@ public class CParameter implements IParameter {
final private IASTParameterDeclaration parameterDeclaration; final private IASTParameterDeclaration parameterDeclaration;
public CParameter( IASTParameterDeclaration parameterDeclaration ){ public CParameter( IASTParameterDeclaration parameterDeclaration ){
parameterDeclaration = checkForDefinition( parameterDeclaration ); //parameterDeclaration = checkForDefinition( parameterDeclaration );
this.parameterDeclaration = parameterDeclaration; this.parameterDeclaration = parameterDeclaration;
} }
private IASTParameterDeclaration checkForDefinition( IASTParameterDeclaration paramDecl ){ public IASTNode getPhysicalNode(){
IASTFunctionDeclarator fnDtor = (IASTFunctionDeclarator) paramDecl.getParent(); return parameterDeclaration;
if( fnDtor.getParent() instanceof IASTFunctionDefinition )
return paramDecl;
IASTFunctionDeclarator fDef = CVisitor.findDefinition( fnDtor );
if( fDef != null && fDef instanceof IASTFunctionDefinition ){
int index = fnDtor.getParameters().indexOf( paramDecl );
if( index >= 0 && index < fDef.getParameters().size() ) {
IASTParameterDeclaration pDef = (IASTParameterDeclaration) fDef.getParameters().get( index );
((CASTName)pDef.getDeclarator().getName()).setBinding( this );
paramDecl = pDef;
}
}
return paramDecl;
} }
// private IASTParameterDeclaration checkForDefinition( IASTParameterDeclaration paramDecl ){
// IASTFunctionDeclarator fnDtor = (IASTFunctionDeclarator) paramDecl.getParent();
// if( fnDtor.getParent() instanceof IASTFunctionDefinition )
// return paramDecl;
//
// IASTFunctionDeclarator fDef = CVisitor.findDefinition( fnDtor );
// if( fDef != null && fDef instanceof IASTFunctionDefinition ){
// int index = fnDtor.getParameters().indexOf( paramDecl );
// if( index >= 0 && index < fDef.getParameters().size() ) {
// IASTParameterDeclaration pDef = (IASTParameterDeclaration) fDef.getParameters().get( index );
// ((CASTName)pDef.getDeclarator().getName()).setBinding( this );
// paramDecl = pDef;
// }
// }
// return paramDecl;
// }
/* (non-Javadoc) /* (non-Javadoc)
@ -73,6 +75,9 @@ public class CParameter implements IParameter {
public String getName() { public String getName() {
return parameterDeclaration.getDeclarator().getName().toString(); return parameterDeclaration.getDeclarator().getName().toString();
} }
public char[] getNameCharArray(){
return ((CASTName)parameterDeclaration.getDeclarator().getName()).toCharArray();
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()

View file

@ -0,0 +1,67 @@
/*******************************************************************************
* 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 Corporation - initial API and implementation
*******************************************************************************/
/*
* Created on Nov 25, 2004
*/
package org.eclipse.cdt.internal.core.parser2.c;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.c.ICScope;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
/**
* @author aniefer
*/
public class CScope implements ICScope {
private IASTNode physicalNode = null;
private CharArrayObjectMap [] bindings = { CharArrayObjectMap.EMPTY_MAP, CharArrayObjectMap.EMPTY_MAP };
int lastBinding = -1;
public CScope( IASTNode physical ){
physicalNode = physical;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#getParent()
*/
public IScope getParent() {
return CVisitor.getContainingScope( physicalNode );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/
public List find( String name ) {
// TODO Auto-generated method stub
return null;
}
public void addBinding( IBinding binding ) {
int type = ( binding instanceof ICompositeType || binding instanceof IEnumeration ) ?
NAMESPACE_TYPE_TAG : NAMESPACE_TYPE_OTHER;
if( bindings[type] == CharArrayObjectMap.EMPTY_MAP )
bindings[type] = new CharArrayObjectMap(1);
bindings[type].put( binding.getNameCharArray(), binding );
}
public IBinding getBinding( int namespaceType, char [] name ){
return (IBinding) bindings[namespaceType].get( name );
}
}

View file

@ -14,8 +14,11 @@ package org.eclipse.cdt.internal.core.parser2.c;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
@ -30,66 +33,77 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
* @author aniefer * @author aniefer
*/ */
public class CStructure implements ICompositeType { public class CStructure implements ICompositeType {
final private IASTDeclSpecifier declSpecifier; private IASTElaboratedTypeSpecifier[] declarations = null;
private ICASTCompositeTypeSpecifier definition;
//final private IASTDeclSpecifier declSpecifier;
public CStructure( IASTDeclSpecifier declSpec ){ public CStructure( IASTDeclSpecifier declSpec ){
declSpec = checkForDefinition( declSpec ); if( declSpec instanceof IASTCompositeTypeSpecifier )
this.declSpecifier = declSpec; definition = (ICASTCompositeTypeSpecifier) declSpec;
else {
declarations = new IASTElaboratedTypeSpecifier[] { (IASTElaboratedTypeSpecifier) declSpec };
}
} }
private IASTDeclSpecifier checkForDefinition( IASTDeclSpecifier declSpec ){ public IASTNode getPhysicalNode(){
if( declSpec instanceof ICASTCompositeTypeSpecifier ) return ( definition != null ) ? (IASTNode)definition : (IASTNode)declarations[0];
return declSpec; }
private ICASTCompositeTypeSpecifier checkForDefinition( IASTElaboratedTypeSpecifier declSpec ){
IASTDeclSpecifier spec = CVisitor.findDefinition( (ICASTElaboratedTypeSpecifier) declSpec ); IASTDeclSpecifier spec = CVisitor.findDefinition( (ICASTElaboratedTypeSpecifier) declSpec );
if( spec != null && spec instanceof ICASTCompositeTypeSpecifier ){ if( spec != null && spec instanceof ICASTCompositeTypeSpecifier ){
declSpec = spec;
ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) spec; ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) spec;
((CASTName)compTypeSpec.getName()).setBinding( this ); ((CASTName)compTypeSpec.getName()).setBinding( this );
return compTypeSpec;
} }
return declSpec; return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName() * @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/ */
public String getName() { public String getName() {
if( declSpecifier instanceof ICASTCompositeTypeSpecifier ) if( definition != null )
return ((ICASTCompositeTypeSpecifier)declSpecifier).getName().toString(); return definition.getName().toString();
else if( declSpecifier instanceof ICASTElaboratedTypeSpecifier )
return ((ICASTElaboratedTypeSpecifier)declSpecifier).getName().toString(); return declarations[0].getName().toString();
}
return ""; //$NON-NLS-1$ public char[] getNameCharArray() {
if( definition != null )
return ((CASTName)definition.getName()).toCharArray();
return ((CASTName)declarations[0].getName()).toCharArray();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/ */
public IScope getScope() { public IScope getScope() {
return CVisitor.getContainingScope( declSpecifier ); IASTDeclSpecifier declSpec = (IASTDeclSpecifier) ( ( definition != null ) ? (IASTNode)definition : declarations[0] );
return CVisitor.getContainingScope( declSpec );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getFields() * @see org.eclipse.cdt.core.dom.ast.ICompositeType#getFields()
*/ */
public List getFields() { public List getFields() {
if( !( declSpecifier instanceof ICASTCompositeTypeSpecifier ) ){ if( definition == null ){
//error ICASTCompositeTypeSpecifier temp = checkForDefinition( declarations[0] );
return null; if( temp == null )
} return null;
definition = temp;
ICASTCompositeTypeSpecifier compositeTypeSpec = (ICASTCompositeTypeSpecifier) declSpecifier; }
List members = compositeTypeSpec.getMembers();
int size = members.size(); IASTDeclaration[] members = definition.getMembers();
int size = members.length;
List fields = new ArrayList( size ); List fields = new ArrayList( size );
if( size > 0 ){ if( size > 0 ){
for( int i = 0; i < size; i++ ){ for( int i = 0; i < size; i++ ){
IASTNode node = (IASTNode) members.get(i); IASTNode node = members[i];
if( node instanceof IASTSimpleDeclaration ){ if( node instanceof IASTSimpleDeclaration ){
List declarators = ((IASTSimpleDeclaration)node).getDeclarators(); IASTDeclarator[] declarators = ((IASTSimpleDeclaration)node).getDeclarators();
for( int j = 0; j < declarators.size(); j++ ){ for( int j = 0; j < declarators.length; j++ ){
IASTDeclarator declarator = (IASTDeclarator) declarators.get(i); IASTDeclarator declarator = declarators[i];
IBinding binding = declarator.getName().resolveBinding(); IBinding binding = declarator.getName().resolveBinding();
if( binding != null ) if( binding != null )
fields.add( binding ); fields.add( binding );
@ -105,21 +119,22 @@ public class CStructure implements ICompositeType {
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(org.eclipse.cdt.core.dom.ast.IASTName) * @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(org.eclipse.cdt.core.dom.ast.IASTName)
*/ */
public IField findField(String name) { public IField findField(String name) {
if( !( declSpecifier instanceof ICASTCompositeTypeSpecifier ) ){ if( definition == null ){
//error ICASTCompositeTypeSpecifier temp = checkForDefinition( declarations[0] );
return null; if( temp == null )
} return null;
definition = temp;
ICASTCompositeTypeSpecifier compositeTypeSpec = (ICASTCompositeTypeSpecifier) declSpecifier; }
List members = compositeTypeSpec.getMembers();
int size = members.size(); IASTDeclaration[] members = definition.getMembers();
int size = members.length;
if( size > 0 ){ if( size > 0 ){
for( int i = 0; i < size; i++ ){ for( int i = 0; i < size; i++ ){
IASTNode node = (IASTNode) members.get(i); IASTNode node = members[i];
if( node instanceof IASTSimpleDeclaration ){ if( node instanceof IASTSimpleDeclaration ){
List declarators = ((IASTSimpleDeclaration)node).getDeclarators(); IASTDeclarator[] declarators = ((IASTSimpleDeclaration)node).getDeclarators();
for( int j = 0; j < declarators.size(); j++ ){ for( int j = 0; j < declarators.length; j++ ){
IASTDeclarator declarator = (IASTDeclarator) declarators.get(j); IASTDeclarator declarator = declarators[j];
if( name.equals( declarator.getName().toString() ) ){ if( name.equals( declarator.getName().toString() ) ){
IBinding binding = declarator.getName().resolveBinding(); IBinding binding = declarator.getName().resolveBinding();
if( binding instanceof IField ) if( binding instanceof IField )

View file

@ -15,6 +15,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
@ -31,6 +32,10 @@ public class CTypeDef implements ITypedef {
public CTypeDef( IASTName name ){ public CTypeDef( IASTName name ){
this.name = name; this.name = name;
} }
public IASTNode getPhysicalNode(){
return name;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.ITypedef#getType() * @see org.eclipse.cdt.core.dom.ast.ITypedef#getType()
*/ */
@ -53,6 +58,9 @@ public class CTypeDef implements ITypedef {
public String getName() { public String getName() {
return name.toString(); return name.toString();
} }
public char[] getNameCharArray(){
return ((CASTName) name).toCharArray();
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()

View file

@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
@ -31,30 +32,32 @@ public class CVariable implements IVariable {
final IASTName name; final IASTName name;
public CVariable( IASTName name ){ public CVariable( IASTName name ){
name = checkForDefinition( name ); // name = checkForDefinition( name );
this.name = name; this.name = name;
} }
public IASTNode getPhysicalNode(){
private IASTName checkForDefinition( IASTName nm ){ return name;
IASTDeclarator dtor = (IASTDeclarator) nm.getParent(); }
IASTSimpleDeclaration dcl = (IASTSimpleDeclaration) dtor.getParent(); // private IASTName checkForDefinition( IASTName nm ){
IASTDeclSpecifier declSpec = dcl.getDeclSpecifier(); // IASTDeclarator dtor = (IASTDeclarator) nm.getParent();
if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_extern ){ // IASTSimpleDeclaration dcl = (IASTSimpleDeclaration) dtor.getParent();
IASTDeclarator prev = dtor, tmp = CVisitor.findDefinition( dtor, CVisitor.AT_BEGINNING ); // IASTDeclSpecifier declSpec = dcl.getDeclSpecifier();
while( tmp != null && tmp != prev ){ // if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_extern ){
CASTName n = (CASTName) tmp.getName(); // IASTDeclarator prev = dtor, tmp = CVisitor.findDefinition( dtor, CVisitor.AT_BEGINNING );
IASTDeclSpecifier spec = ((IASTSimpleDeclaration)tmp.getParent()).getDeclSpecifier(); // while( tmp != null && tmp != prev ){
if( spec.getStorageClass() != IASTDeclSpecifier.sc_extern ){ // CASTName n = (CASTName) tmp.getName();
nm = n; // IASTDeclSpecifier spec = ((IASTSimpleDeclaration)tmp.getParent()).getDeclSpecifier();
} // if( spec.getStorageClass() != IASTDeclSpecifier.sc_extern ){
n.setBinding( this ); // nm = n;
prev = tmp; // }
tmp = CVisitor.findDefinition( tmp, CVisitor.AT_NEXT ); // n.setBinding( this );
} // prev = tmp;
} // tmp = CVisitor.findDefinition( tmp, CVisitor.AT_NEXT );
// }
return nm; // }
} //
// return nm;
// }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#getType() * @see org.eclipse.cdt.core.dom.ast.IVariable#getType()
*/ */
@ -81,6 +84,9 @@ public class CVariable implements IVariable {
public String getName() { public String getName() {
return name.toString(); return name.toString();
} }
public char[]getNameCharArray(){
return ((CASTName)name).toCharArray();
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()

View file

@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression; 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.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
@ -24,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTDoStatement; import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
@ -54,6 +56,7 @@ import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.ILabel; import org.eclipse.cdt.core.dom.ast.ILabel;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
@ -67,6 +70,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression; import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope; import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
import org.eclipse.cdt.core.dom.ast.c.ICScope;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
@ -121,7 +125,7 @@ public class CVisitor {
protected static final int AT_BEGINNING = 1; protected static final int AT_BEGINNING = 1;
protected static final int AT_NEXT = 2; protected static final int AT_NEXT = 2;
static protected void createBinding( CASTName name ){ static protected void createBinding( IASTName name ){
IBinding binding = null; IBinding binding = null;
IASTNode parent = name.getParent(); IASTNode parent = name.getParent();
@ -144,21 +148,22 @@ public class CVisitor {
} else if( parent instanceof IASTEnumerator ) { } else if( parent instanceof IASTEnumerator ) {
binding = createBinding( (IASTEnumerator) parent ); binding = createBinding( (IASTEnumerator) parent );
} }
name.setBinding( binding ); ((CASTName)name).setBinding( binding );
} }
private static IBinding createBinding( ICASTEnumerationSpecifier enumeration ){ private static IBinding createBinding( ICASTEnumerationSpecifier enumeration ){
return new CEnumeration( enumeration ); IEnumeration binding = new CEnumeration( enumeration );
((ICScope)binding.getScope()).addBinding( binding );
return binding;
} }
private static IBinding createBinding( IASTEnumerator enumerator ){ private static IBinding createBinding( IASTEnumerator enumerator ){
return new CEnumerator( enumerator ); IEnumerator binding = new CEnumerator( enumerator );
((ICScope)binding.getScope()).addBinding( binding );
return binding;
} }
private static IBinding createBinding( IASTStatement statement ){ private static IBinding createBinding( IASTStatement statement ){
if( statement instanceof IASTGotoStatement ){ if( statement instanceof IASTGotoStatement ){
IScope scope = getContainingScope( statement ); IScope scope = getContainingScope( statement );
while( scope != null && !( scope instanceof ICFunctionScope) ){
scope = scope.getParent();
}
if( scope != null && scope instanceof ICFunctionScope ){ if( scope != null && scope instanceof ICFunctionScope ){
CFunctionScope functionScope = (CFunctionScope) scope; CFunctionScope functionScope = (CFunctionScope) scope;
List labels = functionScope.getLabels(); List labels = functionScope.getLabels();
@ -170,7 +175,9 @@ public class CVisitor {
} }
} }
} else if( statement instanceof IASTLabelStatement ){ } else if( statement instanceof IASTLabelStatement ){
return new CLabel( (IASTLabelStatement) statement ); IBinding binding = new CLabel( (IASTLabelStatement) statement );
((ICFunctionScope) binding.getScope()).addBinding( binding );
return binding;
} }
return null; return null;
} }
@ -178,17 +185,19 @@ public class CVisitor {
IASTNode parent = elabTypeSpec.getParent(); IASTNode parent = elabTypeSpec.getParent();
if( parent instanceof IASTSimpleDeclaration ){ if( parent instanceof IASTSimpleDeclaration ){
IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) parent; IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) parent;
if( declaration.getDeclarators().size() == 0 ){ if( declaration.getDeclarators().length == 0 ){
//forward declaration //forward declaration
IBinding binding = resolveBinding( elabTypeSpec, CURRENT_SCOPE | TAGS ); IBinding binding = resolveBinding( elabTypeSpec, CURRENT_SCOPE | TAGS );
if( binding == null ) if( binding == null ){
binding = new CStructure( elabTypeSpec ); binding = new CStructure( elabTypeSpec );
((ICScope) binding.getScope()).addBinding( binding );
}
return binding; return binding;
} }
return resolveBinding( elabTypeSpec, COMPLETE | TAGS ); return resolveBinding( elabTypeSpec, COMPLETE | TAGS );
} else if( parent instanceof IASTTypeId || parent instanceof IASTParameterDeclaration ){ } else if( parent instanceof IASTTypeId || parent instanceof IASTParameterDeclaration ){
IASTNode blockItem = getContainingBlockItem( parent ); IASTNode blockItem = getContainingBlockItem( parent );
return findBinding( blockItem, (CASTName) elabTypeSpec.getName(), COMPLETE | TAGS ); return findBinding( blockItem, elabTypeSpec.getName(), COMPLETE | TAGS );
} }
return null; return null;
} }
@ -228,12 +237,14 @@ public class CVisitor {
* @param parent * @param parent
* @return * @return
*/ */
private static IBinding createBinding(IASTDeclarator declarator, CASTName name) { private static IBinding createBinding(IASTDeclarator declarator, IASTName name) {
IBinding binding = null; IBinding binding = null;
IASTNode parent = declarator.getParent(); IASTNode parent = declarator.getParent();
if( declarator instanceof IASTFunctionDeclarator ){ if( declarator instanceof IASTFunctionDeclarator ){
binding = resolveBinding( parent, CURRENT_SCOPE ); binding = resolveBinding( parent, CURRENT_SCOPE );
if( binding == null ) if( binding != null )
((CFunction)binding).addDeclarator( (IASTFunctionDeclarator) declarator );
else
binding = new CFunction( (IASTFunctionDeclarator) declarator ); binding = new CFunction( (IASTFunctionDeclarator) declarator );
} else if( parent instanceof IASTSimpleDeclaration ){ } else if( parent instanceof IASTSimpleDeclaration ){
binding = createBinding( (IASTSimpleDeclaration) parent, name ); binding = createBinding( (IASTSimpleDeclaration) parent, name );
@ -245,7 +256,10 @@ public class CVisitor {
} }
private static IBinding createBinding( ICASTCompositeTypeSpecifier compositeTypeSpec ){ private static IBinding createBinding( ICASTCompositeTypeSpecifier compositeTypeSpec ){
return new CStructure( compositeTypeSpec ); ICompositeType binding = new CStructure( compositeTypeSpec );
ICScope scope = (ICScope) binding.getScope();
scope.addBinding( binding );
return binding;
} }
@ -257,10 +271,17 @@ public class CVisitor {
IBinding binding = null; IBinding binding = null;
if( simpleDeclaration.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ){ if( simpleDeclaration.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ){
binding = new CTypeDef( name ); binding = new CTypeDef( name );
((ICScope) binding.getScope()).addBinding( binding );
} else if( simpleDeclaration.getParent() instanceof ICASTCompositeTypeSpecifier ){ } else if( simpleDeclaration.getParent() instanceof ICASTCompositeTypeSpecifier ){
binding = new CField( name ); binding = new CField( name );
((ICScope) binding.getScope()).addBinding( binding );
} else { } else {
binding = new CVariable( name ); CScope scope = (CScope) CVisitor.getContainingScope( simpleDeclaration );
binding = scope.getBinding( ICScope.NAMESPACE_TYPE_OTHER, name.toCharArray() );
if( binding == null ){
binding = new CVariable( name );
scope.addBinding( binding );
}
} }
return binding; return binding;
@ -282,31 +303,31 @@ public class CVisitor {
IASTFunctionDeclarator functionDeclartor = functionDef.getDeclarator(); IASTFunctionDeclarator functionDeclartor = functionDef.getDeclarator();
IASTName name = functionDeclartor.getName(); IASTName name = functionDeclartor.getName();
IASTNode blockItem = getContainingBlockItem( node ); IASTNode blockItem = getContainingBlockItem( node );
return findBinding( blockItem, (CASTName) name, bits ); return findBinding( blockItem, name, bits );
} else if( node instanceof IASTIdExpression ){ } else if( node instanceof IASTIdExpression ){
IASTNode blockItem = getContainingBlockItem( node ); IASTNode blockItem = getContainingBlockItem( node );
return findBinding( blockItem, (CASTName) ((IASTIdExpression)node).getName(), bits ); return findBinding( blockItem, ((IASTIdExpression)node).getName(), bits );
} else if( node instanceof ICASTTypedefNameSpecifier ){ } else if( node instanceof ICASTTypedefNameSpecifier ){
IASTNode blockItem = getContainingBlockItem( node ); IASTNode blockItem = getContainingBlockItem( node );
return findBinding( blockItem, (CASTName) ((ICASTTypedefNameSpecifier)node).getName(), bits ); return findBinding( blockItem, ((ICASTTypedefNameSpecifier)node).getName(), bits );
} else if( node instanceof ICASTElaboratedTypeSpecifier ){ } else if( node instanceof ICASTElaboratedTypeSpecifier ){
IASTNode blockItem = getContainingBlockItem( node ); IASTNode blockItem = getContainingBlockItem( node );
return findBinding( blockItem, (CASTName) ((ICASTElaboratedTypeSpecifier)node).getName(), bits ); return findBinding( blockItem, ((ICASTElaboratedTypeSpecifier)node).getName(), bits );
} else if( node instanceof ICASTCompositeTypeSpecifier ){ } else if( node instanceof ICASTCompositeTypeSpecifier ){
IASTNode blockItem = getContainingBlockItem( node ); IASTNode blockItem = getContainingBlockItem( node );
return findBinding( blockItem, (CASTName) ((ICASTCompositeTypeSpecifier)node).getName(), bits ); return findBinding( blockItem, ((ICASTCompositeTypeSpecifier)node).getName(), bits );
} else if( node instanceof IASTParameterDeclaration ){ } else if( node instanceof IASTParameterDeclaration ){
IASTParameterDeclaration param = (IASTParameterDeclaration) node; IASTParameterDeclaration param = (IASTParameterDeclaration) node;
IASTFunctionDeclarator fDtor = (IASTFunctionDeclarator) param.getParent(); IASTFunctionDeclarator fDtor = (IASTFunctionDeclarator) param.getParent();
if( fDtor.getParent() instanceof IASTFunctionDefinition ){ IFunction function = (IFunction) fDtor.getName().resolveBinding();
return null; if( function.getPhysicalNode() != fDtor ) {
} IASTParameterDeclaration [] ps = fDtor.getParameters();
IASTFunctionDeclarator fdef = findDefinition( fDtor ); int index = -1;
if( fdef != null ){ for( index = 0; index < ps.length; index++ )
int index = fDtor.getParameters().indexOf( param ); if( ps[index] == param ) break;
if( index >= 0 && index < fdef.getParameters().size() ){ List params = function.getParameters();
IASTParameterDeclaration pdef = (IASTParameterDeclaration) fdef.getParameters().get( index ); if( index >= 0 && index < params.size() ){
return pdef.getDeclarator().getName().resolveBinding(); return (IBinding) params.get( index );
} }
} }
} else if( node instanceof IASTTypeId ){ } else if( node instanceof IASTTypeId ){
@ -325,6 +346,22 @@ public class CVisitor {
return null; return null;
} }
public static IScope getContainingScope( IASTNode node ){
if( node instanceof IASTDeclaration )
return getContainingScope( (IASTDeclaration) node );
else if( node instanceof IASTStatement )
return getContainingScope( (IASTStatement) node );
else if( node instanceof IASTDeclSpecifier )
return getContainingScope( (IASTDeclSpecifier) node );
else if( node instanceof IASTParameterDeclaration )
return getContainingScope( (IASTParameterDeclaration) node );
else if( node instanceof IASTEnumerator ){
//put the enumerators in the same scope as the enumeration
return getContainingScope( (IASTEnumerationSpecifier) node.getParent() );
}
return null;
}
/** /**
* @param declaration * @param declaration
* @return * @return
@ -335,6 +372,10 @@ public class CVisitor {
return ((IASTTranslationUnit)parent).getScope(); return ((IASTTranslationUnit)parent).getScope();
} else if( parent instanceof IASTDeclarationStatement ){ } else if( parent instanceof IASTDeclarationStatement ){
return getContainingScope( (IASTStatement) parent ); return getContainingScope( (IASTStatement) parent );
} else if( parent instanceof IASTForStatement ){
return ((IASTForStatement)parent).getScope();
} else if( parent instanceof IASTCompositeTypeSpecifier ){
return ((IASTCompositeTypeSpecifier)parent).getScope();
} }
return null; return null;
@ -342,19 +383,31 @@ public class CVisitor {
public static IScope getContainingScope( IASTStatement statement ){ public static IScope getContainingScope( IASTStatement statement ){
IASTNode parent = statement.getParent(); IASTNode parent = statement.getParent();
if( parent instanceof IASTStatement ){ IScope scope = null;
return getContainingScope( (IASTStatement)parent ); if( parent instanceof IASTCompoundStatement ){
IASTCompoundStatement compound = (IASTCompoundStatement) parent;
scope = compound.getScope();
} else if( parent instanceof IASTStatement ){
scope = getContainingScope( (IASTStatement)parent );
} else if( parent instanceof IASTFunctionDefinition ){ } else if( parent instanceof IASTFunctionDefinition ){
IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent ).getDeclarator(); IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent ).getDeclarator();
IFunction function = (IFunction) fnDeclarator.getName().resolveBinding(); IFunction function = (IFunction) fnDeclarator.getName().resolveBinding();
return function.getFunctionScope(); scope = function.getFunctionScope();
} }
return null; if( statement instanceof IASTGotoStatement || statement instanceof IASTLabelStatement ){
//labels have function scope
while( scope != null && !(scope instanceof ICFunctionScope) ){
scope = scope.getParent();
}
}
return scope;
} }
public static IScope getContainingScope( IASTDeclSpecifier compTypeSpec ){ public static IScope getContainingScope( IASTDeclSpecifier compTypeSpec ){
return null; IASTNode parent = compTypeSpec.getParent();
return getContainingScope( (IASTSimpleDeclaration) parent );
} }
/** /**
@ -392,24 +445,34 @@ public class CVisitor {
return getContainingBlockItem( parent ); return getContainingBlockItem( parent );
} }
protected static IBinding findBinding( IASTNode blockItem, CASTName name, int bits ){ protected static IBinding findBinding( IASTNode blockItem, IASTName name, int bits ){
IBinding binding = null; IBinding binding = null;
while( blockItem != null ){ while( blockItem != null ){
IASTNode parent = blockItem.getParent(); IASTNode parent = blockItem.getParent();
List list = null; IASTNode [] nodes = null;
ICScope scope = null;
if( parent instanceof IASTCompoundStatement ){ if( parent instanceof IASTCompoundStatement ){
IASTCompoundStatement compound = (IASTCompoundStatement) parent; IASTCompoundStatement compound = (IASTCompoundStatement) parent;
list = compound.getStatements(); nodes = compound.getStatements();
scope = (ICScope) compound.getScope();
} else if ( parent instanceof IASTTranslationUnit ){ } else if ( parent instanceof IASTTranslationUnit ){
IASTTranslationUnit translation = (IASTTranslationUnit) parent; IASTTranslationUnit translation = (IASTTranslationUnit) parent;
list = translation.getDeclarations(); nodes = translation.getDeclarations();
scope = (ICScope) translation.getScope();
} }
if( list != null ){ if( scope != null ){
for( int i = 0; i < list.size(); i++ ){ int namespaceType = (bits & TAGS) != 0 ? ICScope.NAMESPACE_TYPE_TAG
IASTNode node = (IASTNode) list.get(i); : ICScope.NAMESPACE_TYPE_OTHER;
if( node == blockItem ) binding = scope.getBinding( namespaceType, name.toCharArray() );
if( binding != null )
return binding;
}
if( nodes != null ){
for( int i = 0; i < nodes.length; i++ ){
IASTNode node = nodes[i];
if( node == null || node == blockItem )
break; break;
if( node instanceof IASTDeclarationStatement ){ if( node instanceof IASTDeclarationStatement ){
IASTDeclarationStatement declStatement = (IASTDeclarationStatement) node; IASTDeclarationStatement declStatement = (IASTDeclarationStatement) node;
@ -453,15 +516,13 @@ public class CVisitor {
return null; return null;
} }
private static IBinding checkForBinding( IASTDeclaration declaration, CASTName name ){ private static IBinding checkForBinding( IASTDeclaration declaration, IASTName name ){
if( declaration instanceof IASTSimpleDeclaration ){ if( declaration instanceof IASTSimpleDeclaration ){
IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration; IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration;
List declarators = simpleDeclaration.getDeclarators(); IASTDeclarator [] declarators = simpleDeclaration.getDeclarators();
int size = declarators.size(); for( int i = 0; i < declarators.length; i++ ){
IASTDeclarator declarator = declarators[i];
for( int i = 0; i < size; i++ ){ IASTName declaratorName = declarator.getName();
IASTDeclarator declarator = (IASTDeclarator) declarators.get(i);
CASTName declaratorName = (CASTName) declarator.getName();
if( CharArrayUtils.equals( declaratorName.toCharArray(), name.toCharArray() ) ){ if( CharArrayUtils.equals( declaratorName.toCharArray(), name.toCharArray() ) ){
return declaratorName.resolveBinding(); return declaratorName.resolveBinding();
} }
@ -470,26 +531,27 @@ public class CVisitor {
//decl spec //decl spec
IASTDeclSpecifier declSpec = simpleDeclaration.getDeclSpecifier(); IASTDeclSpecifier declSpec = simpleDeclaration.getDeclSpecifier();
if( declSpec instanceof ICASTElaboratedTypeSpecifier ){ if( declSpec instanceof ICASTElaboratedTypeSpecifier ){
CASTName elabName = (CASTName) ((ICASTElaboratedTypeSpecifier)declSpec).getName(); IASTName elabName = ((ICASTElaboratedTypeSpecifier)declSpec).getName();
if( CharArrayUtils.equals( elabName.toCharArray(), name.toCharArray() ) ){ if( CharArrayUtils.equals( elabName.toCharArray(), name.toCharArray() ) ){
return elabName.resolveBinding(); return elabName.resolveBinding();
} }
} else if( declSpec instanceof ICASTCompositeTypeSpecifier ){ } else if( declSpec instanceof ICASTCompositeTypeSpecifier ){
CASTName compName = (CASTName) ((ICASTCompositeTypeSpecifier)declSpec).getName(); IASTName compName = ((ICASTCompositeTypeSpecifier)declSpec).getName();
if( CharArrayUtils.equals( compName.toCharArray(), name.toCharArray() ) ){ if( CharArrayUtils.equals( compName.toCharArray(), name.toCharArray() ) ){
return compName.resolveBinding(); return compName.resolveBinding();
} }
} else if( declSpec instanceof ICASTEnumerationSpecifier ){ } else if( declSpec instanceof ICASTEnumerationSpecifier ){
ICASTEnumerationSpecifier enumeration = (ICASTEnumerationSpecifier) declSpec; ICASTEnumerationSpecifier enumeration = (ICASTEnumerationSpecifier) declSpec;
CASTName eName = (CASTName) enumeration.getName(); IASTName eName = enumeration.getName();
if( CharArrayUtils.equals( eName.toCharArray(), name.toCharArray() ) ){ if( CharArrayUtils.equals( eName.toCharArray(), name.toCharArray() ) ){
return eName.resolveBinding(); return eName.resolveBinding();
} }
//check enumerators too //check enumerators too
List list = enumeration.getEnumerators(); IASTEnumerator [] list = enumeration.getEnumerators();
for( int i = 0; i < list.size(); i++ ) { for( int i = 0; i < list.length; i++ ) {
IASTEnumerator enumerator = (IASTEnumerator) list.get(i); IASTEnumerator enumerator = list[i];
eName = (CASTName) enumerator.getName(); if( enumerator == null ) break;
eName = enumerator.getName();
if( CharArrayUtils.equals( eName.toCharArray(), name.toCharArray() ) ){ if( CharArrayUtils.equals( eName.toCharArray(), name.toCharArray() ) ){
return eName.resolveBinding(); return eName.resolveBinding();
} }
@ -498,18 +560,19 @@ public class CVisitor {
} }
} else if( declaration instanceof IASTFunctionDefinition ){ } else if( declaration instanceof IASTFunctionDefinition ){
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration; IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration;
IASTFunctionDeclarator declarator = functionDef.getDeclarator(); CASTFunctionDeclarator declarator = (CASTFunctionDeclarator) functionDef.getDeclarator();
//check the function itself //check the function itself
CASTName declName = (CASTName) declarator.getName(); IASTName declName = declarator.getName();
if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){ if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){
return declName.resolveBinding(); return declName.resolveBinding();
} }
//check the parameters //check the parameters
List parameters = declarator.getParameters(); IASTParameterDeclaration [] parameters = declarator.getParameters();
for( int i = 0; i < parameters.size(); i++ ){ for( int i = 0; i < parameters.length; i++ ){
IASTParameterDeclaration parameterDeclaration = (IASTParameterDeclaration) parameters.get(i); IASTParameterDeclaration parameterDeclaration = parameters[i];
declName = (CASTName) parameterDeclaration.getDeclarator().getName(); if( parameterDeclaration == null ) break;
declName = parameterDeclaration.getDeclarator().getName();
if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){ if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){
return declName.resolveBinding(); return declName.resolveBinding();
} }
@ -518,7 +581,7 @@ public class CVisitor {
return null; return null;
} }
private static IBinding checkForBinding( IASTStatement statement, CASTName name ){ private static IBinding checkForBinding( IASTStatement statement, IASTName name ){
if( statement instanceof IASTDeclarationStatement ){ if( statement instanceof IASTDeclarationStatement ){
return checkForBinding( ((IASTDeclarationStatement)statement).getDeclaration(), name ); return checkForBinding( ((IASTDeclarationStatement)statement).getDeclaration(), name );
} else if( statement instanceof IASTForStatement ){ } else if( statement instanceof IASTForStatement ){
@ -531,20 +594,19 @@ public class CVisitor {
} }
protected static IASTDeclarator findDefinition( IASTDeclarator declarator, int beginAtLoc ){ protected static IASTDeclarator findDefinition( IASTDeclarator declarator, int beginAtLoc ){
return (IASTDeclarator) findDefinition( declarator, declarator.getName().toString(), beginAtLoc ); return (IASTDeclarator) findDefinition( declarator, declarator.getName().toCharArray(), beginAtLoc );
} }
protected static IASTFunctionDeclarator findDefinition( IASTFunctionDeclarator declarator ){ protected static IASTFunctionDeclarator findDefinition( IASTFunctionDeclarator declarator ){
return (IASTFunctionDeclarator) findDefinition( declarator, declarator.getName().toString(), AT_BEGINNING ); return (IASTFunctionDeclarator) findDefinition( declarator, declarator.getName().toCharArray(), AT_NEXT );
} }
protected static IASTDeclSpecifier findDefinition( ICASTElaboratedTypeSpecifier declSpec ){ protected static IASTDeclSpecifier findDefinition( ICASTElaboratedTypeSpecifier declSpec ){
String elabName = declSpec.getName().toString(); return (IASTDeclSpecifier) findDefinition(declSpec, declSpec.getName().toCharArray(), AT_BEGINNING);
return (IASTDeclSpecifier) findDefinition(declSpec, elabName, AT_BEGINNING);
} }
private static IASTNode findDefinition(IASTNode decl, String declName, int beginAtLoc) { private static IASTNode findDefinition(IASTNode decl, char [] declName, int beginAtLoc) {
IASTNode blockItem = getContainingBlockItem( decl ); IASTNode blockItem = getContainingBlockItem( decl );
IASTNode parent = blockItem.getParent(); IASTNode parent = blockItem.getParent();
List list = null; IASTNode [] list = null;
if( parent instanceof IASTCompoundStatement ){ if( parent instanceof IASTCompoundStatement ){
IASTCompoundStatement compound = (IASTCompoundStatement) parent; IASTCompoundStatement compound = (IASTCompoundStatement) parent;
list = compound.getStatements(); list = compound.getStatements();
@ -554,8 +616,8 @@ public class CVisitor {
} }
boolean begun = ( beginAtLoc == AT_BEGINNING ); boolean begun = ( beginAtLoc == AT_BEGINNING );
if( list != null ){ if( list != null ){
for( int i = 0; i < list.size(); i++ ){ for( int i = 0; i < list.length; i++ ){
IASTNode node = (IASTNode) list.get(i); IASTNode node = list[i];
if( node == blockItem ){ if( node == blockItem ){
begun = true; begun = true;
continue; continue;
@ -576,18 +638,16 @@ public class CVisitor {
IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) node; IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) node;
if( simpleDecl.getDeclSpecifier() instanceof ICASTCompositeTypeSpecifier ){ if( simpleDecl.getDeclSpecifier() instanceof ICASTCompositeTypeSpecifier ){
ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) simpleDecl.getDeclSpecifier(); ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) simpleDecl.getDeclSpecifier();
IASTName name = compTypeSpec.getName(); if( CharArrayUtils.equals( compTypeSpec.getName().toCharArray(), declName ) ){
if( name.toString().equals( declName ) ){
return compTypeSpec; return compTypeSpec;
} }
} }
} else if( node instanceof IASTSimpleDeclaration && decl instanceof IASTDeclarator ){ } else if( node instanceof IASTSimpleDeclaration && decl instanceof IASTDeclarator ){
IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) node; IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) node;
List dtors = simpleDecl.getDeclarators(); IASTDeclarator [] dtors = simpleDecl.getDeclarators();
for( int j = 0; j < dtors.size(); j++ ){ for( int j = 0; dtors != null && j < dtors.length; j++ ){
IASTDeclarator dtor = (IASTDeclarator) dtors.get( j ); if( CharArrayUtils.equals( dtors[j].getName().toCharArray(), declName ) ){
if( dtor.getName().toString().equals( declName ) ){ return dtors[j];
return dtor;
} }
} }
} }
@ -602,9 +662,9 @@ public class CVisitor {
} }
public static void visitTranslationUnit( IASTTranslationUnit tu, BaseVisitorAction action ){ public static void visitTranslationUnit( IASTTranslationUnit tu, BaseVisitorAction action ){
List decls = tu.getDeclarations(); IASTDeclaration[] decls = tu.getDeclarations();
for( int i = 0; i < decls.size(); i++ ){ for( int i = 0; i < decls.length; i++ ){
if( !visitDeclaration( (IASTDeclaration) decls.get(i), action ) ) return; if( !visitDeclaration( decls[i], action ) ) return;
} }
} }
@ -621,9 +681,9 @@ public class CVisitor {
if( declaration instanceof IASTSimpleDeclaration ){ if( declaration instanceof IASTSimpleDeclaration ){
IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) declaration; IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) declaration;
if( !visitDeclSpecifier( simpleDecl.getDeclSpecifier(), action ) ) return false; if( !visitDeclSpecifier( simpleDecl.getDeclSpecifier(), action ) ) return false;
List list = simpleDecl.getDeclarators(); IASTDeclarator [] list = simpleDecl.getDeclarators();
for( int i = 0; i < list.size(); i++ ){ for( int i = 0; list != null && i < list.length; i++ ){
if( !visitDeclarator( (IASTDeclarator) list.get(i), action ) ) return false; if( !visitDeclarator( list[i], action ) ) return false;
} }
} else if( declaration instanceof IASTFunctionDefinition ){ } else if( declaration instanceof IASTFunctionDefinition ){
IASTFunctionDefinition fnDef = (IASTFunctionDefinition) declaration; IASTFunctionDefinition fnDef = (IASTFunctionDefinition) declaration;
@ -646,9 +706,9 @@ public class CVisitor {
if( !visitInitializer( declarator.getInitializer(), action ) ) return false; if( !visitInitializer( declarator.getInitializer(), action ) ) return false;
if( declarator instanceof IASTFunctionDeclarator ){ if( declarator instanceof IASTFunctionDeclarator ){
List list = ((IASTFunctionDeclarator)declarator).getParameters(); IASTParameterDeclaration [] list = ((IASTFunctionDeclarator)declarator).getParameters();
for( int i = 0; i < list.size(); i++ ){ for( int i = 0; i < list.length; i++ ){
IASTParameterDeclaration param = (IASTParameterDeclaration) list.get(i); IASTParameterDeclaration param = list[i];
if( !visitDeclSpecifier( param.getDeclSpecifier(), action ) ) return false; if( !visitDeclSpecifier( param.getDeclSpecifier(), action ) ) return false;
if( !visitDeclarator( param.getDeclarator(), action ) ) return false; if( !visitDeclarator( param.getDeclarator(), action ) ) return false;
} }
@ -664,9 +724,10 @@ public class CVisitor {
if( initializer instanceof IASTInitializerExpression ){ if( initializer instanceof IASTInitializerExpression ){
if( !visitExpression( ((IASTInitializerExpression) initializer).getExpression(), action ) ) return false; if( !visitExpression( ((IASTInitializerExpression) initializer).getExpression(), action ) ) return false;
} else if( initializer instanceof IASTInitializerList ){ } else if( initializer instanceof IASTInitializerList ){
List list = ((IASTInitializerList) initializer).getInitializers(); IASTInitializer [] list = ((IASTInitializerList) initializer).getInitializers();
for( int i = 0; i < list.size(); i++ ) for( int i = 0; i < list.length; i++ ){
if( !visitInitializer( (IASTInitializer) list.get(i), action ) ) return false; if( !visitInitializer( list[i], action ) ) return false;
}
} }
return true; return true;
} }
@ -687,9 +748,9 @@ public class CVisitor {
ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) declSpec; ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) declSpec;
if( !visitName( compTypeSpec.getName(), action ) ) return false; if( !visitName( compTypeSpec.getName(), action ) ) return false;
List list = compTypeSpec.getMembers(); IASTDeclaration [] list = compTypeSpec.getMembers();
for( int i = 0; i < list.size(); i++ ){ for( int i = 0; i < list.length; i++ ){
if( !visitDeclaration( (IASTDeclaration) list.get(i), action ) ) return false; if( !visitDeclaration( list[i], action ) ) return false;
} }
} else if( declSpec instanceof ICASTElaboratedTypeSpecifier ){ } else if( declSpec instanceof ICASTElaboratedTypeSpecifier ){
if( !visitName( ((ICASTElaboratedTypeSpecifier) declSpec).getName(), action ) ) return false; if( !visitName( ((ICASTElaboratedTypeSpecifier) declSpec).getName(), action ) ) return false;
@ -698,11 +759,10 @@ public class CVisitor {
} else if( declSpec instanceof ICASTEnumerationSpecifier ){ } else if( declSpec instanceof ICASTEnumerationSpecifier ){
ICASTEnumerationSpecifier enumSpec = (ICASTEnumerationSpecifier) declSpec; ICASTEnumerationSpecifier enumSpec = (ICASTEnumerationSpecifier) declSpec;
if( !visitName( enumSpec.getName(), action ) ) return false; if( !visitName( enumSpec.getName(), action ) ) return false;
List list = enumSpec.getEnumerators(); IASTEnumerator [] list = enumSpec.getEnumerators();
for( int i = 0; i < list.size(); i++ ){ for( int i = 0; i < list.length; i++ ){
if( !visitEnumerator( (IASTEnumerator) list.get(i), action ) ) return false; if( !visitEnumerator( list[i], action ) ) return false;
} }
} }
return true; return true;
} }
@ -720,9 +780,10 @@ public class CVisitor {
if( !action.processStatement( statement ) ) return false; if( !action.processStatement( statement ) ) return false;
if( statement instanceof IASTCompoundStatement ){ if( statement instanceof IASTCompoundStatement ){
List list = ((IASTCompoundStatement) statement).getStatements(); IASTStatement [] list = ((IASTCompoundStatement) statement).getStatements();
for( int i = 0; i < list.size(); i++ ){ for( int i = 0; i < list.length; i++ ){
if( !visitStatement( (IASTStatement) list.get(i), action ) ) return false; if( list[i] == null ) break;
if( !visitStatement( list[i], action ) ) return false;
} }
} else if( statement instanceof IASTDeclarationStatement ){ } else if( statement instanceof IASTDeclarationStatement ){
if( !visitDeclaration( ((IASTDeclarationStatement)statement).getDeclaration(), action ) ) return false; if( !visitDeclaration( ((IASTDeclarationStatement)statement).getDeclaration(), action ) ) return false;
@ -784,9 +845,10 @@ public class CVisitor {
if( !visitExpression( ((IASTConditionalExpression)expression).getNegativeResultExpression(), action ) ) return false; if( !visitExpression( ((IASTConditionalExpression)expression).getNegativeResultExpression(), action ) ) return false;
if( !visitExpression( ((IASTConditionalExpression)expression).getPositiveResultExpression(), action ) ) return false; if( !visitExpression( ((IASTConditionalExpression)expression).getPositiveResultExpression(), action ) ) return false;
} else if( expression instanceof IASTExpressionList ){ } else if( expression instanceof IASTExpressionList ){
List list = ((IASTExpressionList)expression).getExpressions(); IASTExpression[] list = ((IASTExpressionList)expression).getExpressions();
for( int i = 0; i < list.size(); i++){ for( int i = 0; i < list.length; i++){
if( !visitExpression( (IASTExpression) list.get(i), action ) ) return false; if( list[i] == null ) break;
if( !visitExpression( list[i], action ) ) return false;
} }
} else if( expression instanceof IASTFieldReference ){ } else if( expression instanceof IASTFieldReference ){
if( !visitExpression( ((IASTFieldReference)expression).getFieldOwner(), action ) ) return false; if( !visitExpression( ((IASTFieldReference)expression).getFieldOwner(), action ) ) return false;

View file

@ -16,6 +16,7 @@ import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
/** /**
@ -86,10 +87,10 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#getMembers() * @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#getMembers()
*/ */
public List getMembers() { public IASTDeclaration[] getMembers() {
if( declarations == null ) return Collections.EMPTY_LIST; if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
removeNullDeclarations(); removeNullDeclarations();
return Arrays.asList( declarations ); return declarations;
} }
@ -147,4 +148,12 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
private int currentIndex2 = 0; private int currentIndex2 = 0;
private ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier [] baseSpecs = null; private ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier [] baseSpecs = null;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#getScope()
*/
public IScope getScope() {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -10,12 +10,9 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.internal.core.parser2.cpp; package org.eclipse.cdt.internal.core.parser2.cpp;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
/** /**
* @author jcamelon * @author jcamelon
@ -46,10 +43,10 @@ public class CPPASTCompoundStatement extends CPPASTNode implements
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompoundStatement#getStatements() * @see org.eclipse.cdt.core.dom.ast.IASTCompoundStatement#getStatements()
*/ */
public List getStatements() { public IASTStatement[] getStatements() {
if( statements == null ) return Collections.EMPTY_LIST; if( statements == null ) return IASTStatement.EMPTY_STATEMENT_ARRAY;
removeNullStatements(); removeNullStatements();
return Arrays.asList( statements ); return statements;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -71,4 +68,12 @@ public class CPPASTCompoundStatement extends CPPASTNode implements
statements[ currentIndex++ ] = statement; statements[ currentIndex++ ] = statement;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompoundStatement#resolveScope()
*/
public IScope getScope() {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -10,10 +10,6 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.internal.core.parser2.cpp; package org.eclipse.cdt.internal.core.parser2.cpp;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
@ -48,10 +44,10 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier#getEnumerators() * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier#getEnumerators()
*/ */
public List getEnumerators() { public IASTEnumerator[] getEnumerators() {
if( enumerators == null ) return Collections.EMPTY_LIST; if( enumerators == null ) return IASTEnumerator.EMPTY_ENUMERATOR_ARRAY;
removeNullEnumerators(); removeNullEnumerators();
return Arrays.asList( enumerators ); return enumerators;
} }
private void removeNullEnumerators() { private void removeNullEnumerators() {

View file

@ -10,10 +10,6 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.internal.core.parser2.cpp; package org.eclipse.cdt.internal.core.parser2.cpp;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
@ -25,10 +21,10 @@ public class CPPASTExpressionList extends CPPASTNode implements
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTExpressionList#getExpressions() * @see org.eclipse.cdt.core.dom.ast.IASTExpressionList#getExpressions()
*/ */
public List getExpressions() { public IASTExpression [] getExpressions() {
if( expressions == null ) return Collections.EMPTY_LIST; if( expressions == null ) return IASTExpression.EMPTY_EXPRESSION_ARRAY;
removeNullExpressions(); removeNullExpressions();
return Arrays.asList( expressions ); return expressions;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -14,6 +14,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
/** /**
* @author jcamelon * @author jcamelon
@ -97,4 +98,12 @@ public class CPPASTForStatement extends CPPASTNode implements IASTForStatement {
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTForStatement#getScope()
*/
public IScope getScope() {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -55,10 +55,10 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator#getParameters() * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator#getParameters()
*/ */
public List getParameters() { public IASTParameterDeclaration [] getParameters() {
if( parameters == null ) return Collections.EMPTY_LIST; if( parameters == null ) return IASTParameterDeclaration.EMPTY_PARAMETERDECLARATION_ARRAY;
removeNullParameters(); removeNullParameters();
return Arrays.asList( parameters ); return parameters;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -10,10 +10,6 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.internal.core.parser2.cpp; package org.eclipse.cdt.internal.core.parser2.cpp;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
@ -28,10 +24,10 @@ public class CPPASTInitializerList extends CPPASTNode implements
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators() * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators()
*/ */
public List getInitializers() { public IASTInitializer [] getInitializers() {
if( initializers == null ) return Collections.EMPTY_LIST; if( initializers == null ) return IASTInitializer.EMPTY_INIALIZER_ARRAY;
removeNullInitializers(); removeNullInitializers();
return Arrays.asList( initializers ); return initializers;
} }
public void addInitializer( IASTInitializer d ) public void addInitializer( IASTInitializer d )

View file

@ -107,6 +107,14 @@ public class CPPASTQualifiedName extends CPPASTNode implements ICPPASTQualifiedN
removeNullNames(); removeNullNames();
return Arrays.asList( names ); return Arrays.asList( names );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTName#toCharArray()
*/
public char[] toCharArray() {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -10,10 +10,6 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.internal.core.parser2.cpp; package org.eclipse.cdt.internal.core.parser2.cpp;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
@ -36,10 +32,10 @@ public class CPPASTSimpleDeclaration extends CPPASTNode implements
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators() * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators()
*/ */
public List getDeclarators() { public IASTDeclarator[] getDeclarators() {
if( declarators == null ) return Collections.EMPTY_LIST; if( declarators == null ) return IASTDeclarator.EMPTY_DECLARATOR_ARRAY;
removeNullDeclarators(); removeNullDeclarators();
return Arrays.asList( declarators ); return declarators;
} }
public void addDeclarator( IASTDeclarator d ) public void addDeclarator( IASTDeclarator d )

View file

@ -116,4 +116,12 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId {
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTName#toCharArray()
*/
public char[] toCharArray() {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -10,8 +10,6 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.internal.core.parser2.cpp; package org.eclipse.cdt.internal.core.parser2.cpp;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@ -49,10 +47,10 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations()
*/ */
public List getDeclarations() { public IASTDeclaration[] getDeclarations() {
if( decls == null ) return Collections.EMPTY_LIST; if( decls == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
removeNullDeclarations(); removeNullDeclarations();
return Arrays.asList( decls ); return decls;
} }
/** /**