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

View file

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

View file

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

View file

@ -16,5 +16,6 @@ package org.eclipse.cdt.core.dom.ast;
* @author Doug Schaefer
*/
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
*/
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 INITIALIZER = new ASTNodeProperty( "Initializer"); //$NON-NLS-1$

View file

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

View file

@ -16,5 +16,5 @@ package org.eclipse.cdt.core.dom.ast;
* @author Doug Schaefer
*/
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 */
package org.eclipse.cdt.core.dom.ast;
import java.util.List;
/**
* @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 List getExpressions();
public IASTExpression [] getExpressions();
public void addExpression( IASTExpression expression );
}

View file

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

View file

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

View file

@ -16,5 +16,6 @@ package org.eclipse.cdt.core.dom.ast;
* @author Doug Schaefer
*/
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;
import java.util.List;
/**
* This is an an initializer that is a list of initializers.
@ -25,7 +24,7 @@ public interface IASTInitializerList extends IASTInitializer {
*
* @return
*/
public List getInitializers();
public IASTInitializer[] getInitializers();
public void addInitializer( IASTInitializer initializer );
}

View file

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

View file

@ -16,6 +16,7 @@ package org.eclipse.cdt.core.dom.ast;
* @author Doug Schaefer
*/
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 DECLARATOR = new ASTNodeProperty( "Declarator"); //$NON-NLS-1$

View file

@ -10,7 +10,6 @@
**********************************************************************/
package org.eclipse.cdt.core.dom.ast;
import java.util.List;
/**
* 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
*/
public List getDeclarators();
public IASTDeclarator[] getDeclarators();
public void addDeclarator( IASTDeclarator declarator );

View file

@ -16,5 +16,6 @@ package org.eclipse.cdt.core.dom.ast;
* @author Doug Schaefer
*/
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
*/
public List getDeclarations();
public IASTDeclaration[] getDeclarations();
public void addDeclaration( IASTDeclaration declaration );

View file

@ -21,6 +21,7 @@ public interface IBinding {
* @return name
*/
public String getName();
public char[] getNameCharArray();
/**
* Every name has a scope.
@ -29,4 +30,5 @@ public interface IBinding {
*/
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;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IBinding;
/**
* @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;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
/**
* @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;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
/**
* @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 */
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.IASTName;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
/**
@ -57,15 +54,16 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements
private int currentIndex = 0;
private IASTDeclaration [] declarations = null;
private IScope scope = null;
private static final int DEFAULT_DECLARATIONS_LIST_SIZE = 4;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#getMembers()
*/
public List getMembers() {
if( declarations == null ) return Collections.EMPTY_LIST;
public IASTDeclaration [] getMembers() {
if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
removeNullDeclarations();
return Arrays.asList( declarations );
return declarations;
}
/* (non-Javadoc)
@ -104,4 +102,13 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements
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 */
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.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
/**
* @author jcamelon
@ -39,16 +36,17 @@ public class CASTCompoundStatement extends CASTNode implements
private IASTStatement [] statements = null;
private IScope scope = null;
private static final int DEFAULT_STATEMENT_LIST_SIZE = 8;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompoundStatement#getStatements()
*/
public List getStatements() {
if( statements == null ) return Collections.EMPTY_LIST;
public IASTStatement[] getStatements() {
if( statements == null ) return IASTStatement.EMPTY_STATEMENT_ARRAY;
removeNullStatements();
return Arrays.asList( statements );
return statements;
}
/* (non-Javadoc)
@ -70,4 +68,13 @@ public class CASTCompoundStatement extends CASTNode implements
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 */
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.c.ICASTEnumerationSpecifier;
@ -46,11 +42,10 @@ public class CASTEnumerationSpecifier extends CASTBaseDeclSpecifier implements
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier#getEnumerators()
*/
public List getEnumerators() {
if( enumerators == null ) return Collections.EMPTY_LIST;
public IASTEnumerator[] getEnumerators() {
if( enumerators == null ) return IASTEnumerator.EMPTY_ENUMERATOR_ARRAY;
removeNullEnumerators();
return Arrays.asList( enumerators );
return enumerators;
}
private void removeNullEnumerators() {

View file

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

View file

@ -13,11 +13,13 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
/**
* @author jcamelon
*/
public class CASTForStatement extends CASTNode implements IASTForStatement {
private IScope scope = null;
private IASTExpression initialExpression;
private IASTDeclaration initDeclaration;
@ -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 */
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.IASTParameterDeclaration;
@ -49,10 +45,10 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator#getParameters()
*/
public List getParameters() {
if( parameters == null ) return Collections.EMPTY_LIST;
public IASTParameterDeclaration[] getParameters() {
if( parameters == null ) return IASTParameterDeclaration.EMPTY_PARAMETERDECLARATION_ARRAY;
removeNullParameters();
return Arrays.asList( parameters );
return parameters;
}
/* (non-Javadoc)

View file

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

View file

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

View file

@ -9,8 +9,6 @@
* IBM Rational Software - Initial API and implementation */
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;
@ -29,7 +27,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
private int currentIndex = 0;
//Binding
private CFileScope compilationUnit = null;
private CScope compilationUnit = null;
public void addDeclaration( IASTDeclaration d )
{
@ -52,10 +50,10 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations()
*/
public List getDeclarations() {
if( decls == null ) return Collections.EMPTY_LIST;
public IASTDeclaration[] getDeclarations() {
if( decls == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
removeNullDeclarations();
return Arrays.asList( decls );
return decls;
}
/**
@ -80,7 +78,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
*/
public IScope getScope() {
if( compilationUnit == null )
compilationUnit = new CFileScope();
compilationUnit = new CScope( this );
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;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
@ -29,6 +30,9 @@ public class CEnumeration implements IEnumeration {
this.enumSpec = spec;
}
public IASTNode getPhysicalNode(){
return enumSpec;
}
private ICASTEnumerationSpecifier checkForDefinition( ICASTEnumerationSpecifier spec ){
return spec;
}
@ -39,13 +43,15 @@ public class CEnumeration implements IEnumeration {
public String getName() {
return enumSpec.getName().toString();
}
public char[] getNameCharArray(){
return ((CASTName) enumSpec.getName()).toCharArray();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/
public IScope getScope() {
// TODO Auto-generated method stub
return null;
return CVisitor.getContainingScope( enumSpec );
}
}

View file

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

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.IASTFunctionDeclarator;
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.IFunction;
import org.eclipse.cdt.core.dom.ast.IScope;
@ -26,37 +27,67 @@ import org.eclipse.cdt.core.dom.ast.IScope;
* @author aniefer
*/
public class CFunction implements IFunction {
final private IASTFunctionDeclarator declarator;
private IASTFunctionDeclarator [] declarators = null;
private IASTFunctionDeclarator definition;
final private IScope functionScope;
public CFunction( IASTFunctionDeclarator declarator ){
declarator = checkForDefinition( declarator );
this.declarator = declarator;
if( declarator.getParent() instanceof IASTFunctionDefinition )
definition = declarator;
else {
declarators = new IASTFunctionDeclarator [] { declarator };
}
this.functionScope = new CFunctionScope( this );
}
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 );
public IASTNode getPhysicalNode(){
return ( definition != null ) ? definition : declarators[0];
}
return dtor;
public void addDeclarator( IASTFunctionDeclarator fnDeclarator ){
if( fnDeclarator instanceof IASTFunctionDefinition )
definition = fnDeclarator;
else {
if( declarators == null ){
declarators = new IASTFunctionDeclarator[] { fnDeclarator };
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)
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
*/
public List getParameters() {
List params = declarator.getParameters();
int size = params.size();
IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarators[0];
IASTParameterDeclaration[] params = dtor.getParameters();
int size = params.length;
List result = new ArrayList( size );
if( size > 0 ){
for( int i = 0; i < size; i++ ){
IASTParameterDeclaration p = (IASTParameterDeclaration) params.get(i);
IASTParameterDeclaration p = params[i];
result.add( p.getDeclarator().getName().resolveBinding() );
}
}
@ -67,14 +98,20 @@ public class CFunction implements IFunction {
* @see org.eclipse.cdt.core.dom.ast.IBinding#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)
* @see org.eclipse.cdt.core.dom.ast.IBinding#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)
@ -84,7 +121,7 @@ public class CFunction implements IFunction {
return functionScope;
}
public IASTDeclaration getDeclaration(){
return (IASTDeclaration) declarator.getParent();
}
// public IASTDeclaration getDeclaration(){
// 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.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.IASTStatement;
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.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;
/**
@ -27,11 +34,46 @@ import org.eclipse.cdt.internal.core.parser2.c.CVisitor.BaseVisitorAction;
*/
public class CFunctionScope implements ICFunctionScope {
private final CFunction function;
private CharArrayObjectMap bindings = CharArrayObjectMap.EMPTY_MAP;
public CFunctionScope( CFunction 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)
* @see org.eclipse.cdt.core.dom.ast.IScope#getParent()
*/
@ -48,16 +90,18 @@ public class CFunctionScope implements ICFunctionScope {
public List getLabels(){
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++ ){
IASTLabelStatement labelStatement = (IASTLabelStatement) action.labels.get(i);
IBinding binding = labelStatement.getName().resolveBinding();
if( binding != null )
bindings.add( binding );
list.add( binding );
}
return bindings;
return list;
}
static private class FindLabelsAction extends BaseVisitorAction {
@ -75,4 +119,6 @@ public class CFunctionScope implements ICFunctionScope {
return true;
}
}
}

View file

@ -15,6 +15,7 @@
package org.eclipse.cdt.internal.core.parser2.c;
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.IScope;
@ -28,7 +29,9 @@ public class CLabel implements ILabel {
public CLabel( IASTLabelStatement statement ){
labelStatement = statement;
}
public IASTNode getPhysicalNode(){
return labelStatement;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.ILabel#getLabelStatement()
*/
@ -42,6 +45,9 @@ public class CLabel implements ILabel {
public String getName() {
return labelStatement.getName().toString();
}
public char[] getNameCharArray(){
return ((CASTName) labelStatement.getName()).toCharArray();
}
/* (non-Javadoc)
* @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.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
@ -29,26 +28,29 @@ public class CParameter implements IParameter {
final private IASTParameterDeclaration parameterDeclaration;
public CParameter( IASTParameterDeclaration parameterDeclaration ){
parameterDeclaration = checkForDefinition( parameterDeclaration );
//parameterDeclaration = checkForDefinition( parameterDeclaration );
this.parameterDeclaration = parameterDeclaration;
}
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;
public IASTNode getPhysicalNode(){
return parameterDeclaration;
}
// 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)
@ -73,6 +75,9 @@ public class CParameter implements IParameter {
public String getName() {
return parameterDeclaration.getDeclarator().getName().toString();
}
public char[] getNameCharArray(){
return ((CASTName)parameterDeclaration.getDeclarator().getName()).toCharArray();
}
/* (non-Javadoc)
* @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.List;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
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.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IBinding;
@ -30,66 +33,77 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
* @author aniefer
*/
public class CStructure implements ICompositeType {
final private IASTDeclSpecifier declSpecifier;
private IASTElaboratedTypeSpecifier[] declarations = null;
private ICASTCompositeTypeSpecifier definition;
//final private IASTDeclSpecifier declSpecifier;
public CStructure( IASTDeclSpecifier declSpec ){
declSpec = checkForDefinition( declSpec );
this.declSpecifier = declSpec;
if( declSpec instanceof IASTCompositeTypeSpecifier )
definition = (ICASTCompositeTypeSpecifier) declSpec;
else {
declarations = new IASTElaboratedTypeSpecifier[] { (IASTElaboratedTypeSpecifier) declSpec };
}
}
private IASTDeclSpecifier checkForDefinition( IASTDeclSpecifier declSpec ){
if( declSpec instanceof ICASTCompositeTypeSpecifier )
return declSpec;
public IASTNode getPhysicalNode(){
return ( definition != null ) ? (IASTNode)definition : (IASTNode)declarations[0];
}
private ICASTCompositeTypeSpecifier checkForDefinition( IASTElaboratedTypeSpecifier declSpec ){
IASTDeclSpecifier spec = CVisitor.findDefinition( (ICASTElaboratedTypeSpecifier) declSpec );
if( spec != null && spec instanceof ICASTCompositeTypeSpecifier ){
declSpec = spec;
ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) spec;
((CASTName)compTypeSpec.getName()).setBinding( this );
return compTypeSpec;
}
return declSpec;
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/
public String getName() {
if( declSpecifier instanceof ICASTCompositeTypeSpecifier )
return ((ICASTCompositeTypeSpecifier)declSpecifier).getName().toString();
else if( declSpecifier instanceof ICASTElaboratedTypeSpecifier )
return ((ICASTElaboratedTypeSpecifier)declSpecifier).getName().toString();
if( definition != null )
return definition.getName().toString();
return ""; //$NON-NLS-1$
return declarations[0].getName().toString();
}
public char[] getNameCharArray() {
if( definition != null )
return ((CASTName)definition.getName()).toCharArray();
return ((CASTName)declarations[0].getName()).toCharArray();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/
public IScope getScope() {
return CVisitor.getContainingScope( declSpecifier );
IASTDeclSpecifier declSpec = (IASTDeclSpecifier) ( ( definition != null ) ? (IASTNode)definition : declarations[0] );
return CVisitor.getContainingScope( declSpec );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getFields()
*/
public List getFields() {
if( !( declSpecifier instanceof ICASTCompositeTypeSpecifier ) ){
//error
if( definition == null ){
ICASTCompositeTypeSpecifier temp = checkForDefinition( declarations[0] );
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 );
if( size > 0 ){
for( int i = 0; i < size; i++ ){
IASTNode node = (IASTNode) members.get(i);
IASTNode node = members[i];
if( node instanceof IASTSimpleDeclaration ){
List declarators = ((IASTSimpleDeclaration)node).getDeclarators();
for( int j = 0; j < declarators.size(); j++ ){
IASTDeclarator declarator = (IASTDeclarator) declarators.get(i);
IASTDeclarator[] declarators = ((IASTSimpleDeclaration)node).getDeclarators();
for( int j = 0; j < declarators.length; j++ ){
IASTDeclarator declarator = declarators[i];
IBinding binding = declarator.getName().resolveBinding();
if( binding != null )
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)
*/
public IField findField(String name) {
if( !( declSpecifier instanceof ICASTCompositeTypeSpecifier ) ){
//error
if( definition == null ){
ICASTCompositeTypeSpecifier temp = checkForDefinition( declarations[0] );
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 ){
for( int i = 0; i < size; i++ ){
IASTNode node = (IASTNode) members.get(i);
IASTNode node = members[i];
if( node instanceof IASTSimpleDeclaration ){
List declarators = ((IASTSimpleDeclaration)node).getDeclarators();
for( int j = 0; j < declarators.size(); j++ ){
IASTDeclarator declarator = (IASTDeclarator) declarators.get(j);
IASTDeclarator[] declarators = ((IASTSimpleDeclaration)node).getDeclarators();
for( int j = 0; j < declarators.length; j++ ){
IASTDeclarator declarator = declarators[j];
if( name.equals( declarator.getName().toString() ) ){
IBinding binding = declarator.getName().resolveBinding();
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.IASTDeclarator;
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.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
@ -31,6 +32,10 @@ public class CTypeDef implements ITypedef {
public CTypeDef( IASTName name ){
this.name = name;
}
public IASTNode getPhysicalNode(){
return name;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.ITypedef#getType()
*/
@ -53,6 +58,9 @@ public class CTypeDef implements ITypedef {
public String getName() {
return name.toString();
}
public char[] getNameCharArray(){
return ((CASTName) name).toCharArray();
}
/* (non-Javadoc)
* @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.IASTElaboratedTypeSpecifier;
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.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
@ -31,30 +32,32 @@ public class CVariable implements IVariable {
final IASTName name;
public CVariable( IASTName name ){
name = checkForDefinition( name );
// name = checkForDefinition( name );
this.name = name;
}
private IASTName checkForDefinition( IASTName nm ){
IASTDeclarator dtor = (IASTDeclarator) nm.getParent();
IASTSimpleDeclaration dcl = (IASTSimpleDeclaration) dtor.getParent();
IASTDeclSpecifier declSpec = dcl.getDeclSpecifier();
if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_extern ){
IASTDeclarator prev = dtor, tmp = CVisitor.findDefinition( dtor, CVisitor.AT_BEGINNING );
while( tmp != null && tmp != prev ){
CASTName n = (CASTName) tmp.getName();
IASTDeclSpecifier spec = ((IASTSimpleDeclaration)tmp.getParent()).getDeclSpecifier();
if( spec.getStorageClass() != IASTDeclSpecifier.sc_extern ){
nm = n;
}
n.setBinding( this );
prev = tmp;
tmp = CVisitor.findDefinition( tmp, CVisitor.AT_NEXT );
}
}
return nm;
public IASTNode getPhysicalNode(){
return name;
}
// private IASTName checkForDefinition( IASTName nm ){
// IASTDeclarator dtor = (IASTDeclarator) nm.getParent();
// IASTSimpleDeclaration dcl = (IASTSimpleDeclaration) dtor.getParent();
// IASTDeclSpecifier declSpec = dcl.getDeclSpecifier();
// if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_extern ){
// IASTDeclarator prev = dtor, tmp = CVisitor.findDefinition( dtor, CVisitor.AT_BEGINNING );
// while( tmp != null && tmp != prev ){
// CASTName n = (CASTName) tmp.getName();
// IASTDeclSpecifier spec = ((IASTSimpleDeclaration)tmp.getParent()).getDeclSpecifier();
// if( spec.getStorageClass() != IASTDeclSpecifier.sc_extern ){
// nm = n;
// }
// n.setBinding( this );
// prev = tmp;
// tmp = CVisitor.findDefinition( tmp, CVisitor.AT_NEXT );
// }
// }
//
// return nm;
// }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#getType()
*/
@ -81,6 +84,9 @@ public class CVariable implements IVariable {
public String getName() {
return name.toString();
}
public char[]getNameCharArray(){
return ((CASTName)name).toCharArray();
}
/* (non-Javadoc)
* @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.IASTCaseStatement;
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.IASTConditionalExpression;
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.IASTDeclarator;
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.IASTExpressionList;
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.ICompositeType;
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.ILabel;
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.ICASTTypedefNameSpecifier;
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.parser.util.CharArrayUtils;
@ -121,7 +125,7 @@ public class CVisitor {
protected static final int AT_BEGINNING = 1;
protected static final int AT_NEXT = 2;
static protected void createBinding( CASTName name ){
static protected void createBinding( IASTName name ){
IBinding binding = null;
IASTNode parent = name.getParent();
@ -144,21 +148,22 @@ public class CVisitor {
} else if( parent instanceof IASTEnumerator ) {
binding = createBinding( (IASTEnumerator) parent );
}
name.setBinding( binding );
((CASTName)name).setBinding( binding );
}
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 ){
return new CEnumerator( enumerator );
IEnumerator binding = new CEnumerator( enumerator );
((ICScope)binding.getScope()).addBinding( binding );
return binding;
}
private static IBinding createBinding( IASTStatement statement ){
if( statement instanceof IASTGotoStatement ){
IScope scope = getContainingScope( statement );
while( scope != null && !( scope instanceof ICFunctionScope) ){
scope = scope.getParent();
}
if( scope != null && scope instanceof ICFunctionScope ){
CFunctionScope functionScope = (CFunctionScope) scope;
List labels = functionScope.getLabels();
@ -170,7 +175,9 @@ public class CVisitor {
}
}
} 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;
}
@ -178,17 +185,19 @@ public class CVisitor {
IASTNode parent = elabTypeSpec.getParent();
if( parent instanceof IASTSimpleDeclaration ){
IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) parent;
if( declaration.getDeclarators().size() == 0 ){
if( declaration.getDeclarators().length == 0 ){
//forward declaration
IBinding binding = resolveBinding( elabTypeSpec, CURRENT_SCOPE | TAGS );
if( binding == null )
if( binding == null ){
binding = new CStructure( elabTypeSpec );
((ICScope) binding.getScope()).addBinding( binding );
}
return binding;
}
return resolveBinding( elabTypeSpec, COMPLETE | TAGS );
} else if( parent instanceof IASTTypeId || parent instanceof IASTParameterDeclaration ){
IASTNode blockItem = getContainingBlockItem( parent );
return findBinding( blockItem, (CASTName) elabTypeSpec.getName(), COMPLETE | TAGS );
return findBinding( blockItem, elabTypeSpec.getName(), COMPLETE | TAGS );
}
return null;
}
@ -228,12 +237,14 @@ public class CVisitor {
* @param parent
* @return
*/
private static IBinding createBinding(IASTDeclarator declarator, CASTName name) {
private static IBinding createBinding(IASTDeclarator declarator, IASTName name) {
IBinding binding = null;
IASTNode parent = declarator.getParent();
if( declarator instanceof IASTFunctionDeclarator ){
binding = resolveBinding( parent, CURRENT_SCOPE );
if( binding == null )
if( binding != null )
((CFunction)binding).addDeclarator( (IASTFunctionDeclarator) declarator );
else
binding = new CFunction( (IASTFunctionDeclarator) declarator );
} else if( parent instanceof IASTSimpleDeclaration ){
binding = createBinding( (IASTSimpleDeclaration) parent, name );
@ -245,7 +256,10 @@ public class CVisitor {
}
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;
if( simpleDeclaration.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ){
binding = new CTypeDef( name );
((ICScope) binding.getScope()).addBinding( binding );
} else if( simpleDeclaration.getParent() instanceof ICASTCompositeTypeSpecifier ){
binding = new CField( name );
((ICScope) binding.getScope()).addBinding( binding );
} else {
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;
@ -282,31 +303,31 @@ public class CVisitor {
IASTFunctionDeclarator functionDeclartor = functionDef.getDeclarator();
IASTName name = functionDeclartor.getName();
IASTNode blockItem = getContainingBlockItem( node );
return findBinding( blockItem, (CASTName) name, bits );
return findBinding( blockItem, name, bits );
} else if( node instanceof IASTIdExpression ){
IASTNode blockItem = getContainingBlockItem( node );
return findBinding( blockItem, (CASTName) ((IASTIdExpression)node).getName(), bits );
return findBinding( blockItem, ((IASTIdExpression)node).getName(), bits );
} else if( node instanceof ICASTTypedefNameSpecifier ){
IASTNode blockItem = getContainingBlockItem( node );
return findBinding( blockItem, (CASTName) ((ICASTTypedefNameSpecifier)node).getName(), bits );
return findBinding( blockItem, ((ICASTTypedefNameSpecifier)node).getName(), bits );
} else if( node instanceof ICASTElaboratedTypeSpecifier ){
IASTNode blockItem = getContainingBlockItem( node );
return findBinding( blockItem, (CASTName) ((ICASTElaboratedTypeSpecifier)node).getName(), bits );
return findBinding( blockItem, ((ICASTElaboratedTypeSpecifier)node).getName(), bits );
} else if( node instanceof ICASTCompositeTypeSpecifier ){
IASTNode blockItem = getContainingBlockItem( node );
return findBinding( blockItem, (CASTName) ((ICASTCompositeTypeSpecifier)node).getName(), bits );
return findBinding( blockItem, ((ICASTCompositeTypeSpecifier)node).getName(), bits );
} else if( node instanceof IASTParameterDeclaration ){
IASTParameterDeclaration param = (IASTParameterDeclaration) node;
IASTFunctionDeclarator fDtor = (IASTFunctionDeclarator) param.getParent();
if( fDtor.getParent() instanceof IASTFunctionDefinition ){
return null;
}
IASTFunctionDeclarator fdef = findDefinition( fDtor );
if( fdef != null ){
int index = fDtor.getParameters().indexOf( param );
if( index >= 0 && index < fdef.getParameters().size() ){
IASTParameterDeclaration pdef = (IASTParameterDeclaration) fdef.getParameters().get( index );
return pdef.getDeclarator().getName().resolveBinding();
IFunction function = (IFunction) fDtor.getName().resolveBinding();
if( function.getPhysicalNode() != fDtor ) {
IASTParameterDeclaration [] ps = fDtor.getParameters();
int index = -1;
for( index = 0; index < ps.length; index++ )
if( ps[index] == param ) break;
List params = function.getParameters();
if( index >= 0 && index < params.size() ){
return (IBinding) params.get( index );
}
}
} else if( node instanceof IASTTypeId ){
@ -325,6 +346,22 @@ public class CVisitor {
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
* @return
@ -335,6 +372,10 @@ public class CVisitor {
return ((IASTTranslationUnit)parent).getScope();
} else if( parent instanceof IASTDeclarationStatement ){
return getContainingScope( (IASTStatement) parent );
} else if( parent instanceof IASTForStatement ){
return ((IASTForStatement)parent).getScope();
} else if( parent instanceof IASTCompositeTypeSpecifier ){
return ((IASTCompositeTypeSpecifier)parent).getScope();
}
return null;
@ -342,19 +383,31 @@ public class CVisitor {
public static IScope getContainingScope( IASTStatement statement ){
IASTNode parent = statement.getParent();
if( parent instanceof IASTStatement ){
return getContainingScope( (IASTStatement)parent );
IScope scope = null;
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 ){
IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent ).getDeclarator();
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 ){
return null;
IASTNode parent = compTypeSpec.getParent();
return getContainingScope( (IASTSimpleDeclaration) parent );
}
/**
@ -392,24 +445,34 @@ public class CVisitor {
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;
while( blockItem != null ){
IASTNode parent = blockItem.getParent();
List list = null;
IASTNode [] nodes = null;
ICScope scope = null;
if( parent instanceof IASTCompoundStatement ){
IASTCompoundStatement compound = (IASTCompoundStatement) parent;
list = compound.getStatements();
nodes = compound.getStatements();
scope = (ICScope) compound.getScope();
} else if ( parent instanceof IASTTranslationUnit ){
IASTTranslationUnit translation = (IASTTranslationUnit) parent;
list = translation.getDeclarations();
nodes = translation.getDeclarations();
scope = (ICScope) translation.getScope();
}
if( list != null ){
for( int i = 0; i < list.size(); i++ ){
IASTNode node = (IASTNode) list.get(i);
if( node == blockItem )
if( scope != null ){
int namespaceType = (bits & TAGS) != 0 ? ICScope.NAMESPACE_TYPE_TAG
: ICScope.NAMESPACE_TYPE_OTHER;
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;
if( node instanceof IASTDeclarationStatement ){
IASTDeclarationStatement declStatement = (IASTDeclarationStatement) node;
@ -453,15 +516,13 @@ public class CVisitor {
return null;
}
private static IBinding checkForBinding( IASTDeclaration declaration, CASTName name ){
private static IBinding checkForBinding( IASTDeclaration declaration, IASTName name ){
if( declaration instanceof IASTSimpleDeclaration ){
IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration;
List declarators = simpleDeclaration.getDeclarators();
int size = declarators.size();
for( int i = 0; i < size; i++ ){
IASTDeclarator declarator = (IASTDeclarator) declarators.get(i);
CASTName declaratorName = (CASTName) declarator.getName();
IASTDeclarator [] declarators = simpleDeclaration.getDeclarators();
for( int i = 0; i < declarators.length; i++ ){
IASTDeclarator declarator = declarators[i];
IASTName declaratorName = declarator.getName();
if( CharArrayUtils.equals( declaratorName.toCharArray(), name.toCharArray() ) ){
return declaratorName.resolveBinding();
}
@ -470,26 +531,27 @@ public class CVisitor {
//decl spec
IASTDeclSpecifier declSpec = simpleDeclaration.getDeclSpecifier();
if( declSpec instanceof ICASTElaboratedTypeSpecifier ){
CASTName elabName = (CASTName) ((ICASTElaboratedTypeSpecifier)declSpec).getName();
IASTName elabName = ((ICASTElaboratedTypeSpecifier)declSpec).getName();
if( CharArrayUtils.equals( elabName.toCharArray(), name.toCharArray() ) ){
return elabName.resolveBinding();
}
} else if( declSpec instanceof ICASTCompositeTypeSpecifier ){
CASTName compName = (CASTName) ((ICASTCompositeTypeSpecifier)declSpec).getName();
IASTName compName = ((ICASTCompositeTypeSpecifier)declSpec).getName();
if( CharArrayUtils.equals( compName.toCharArray(), name.toCharArray() ) ){
return compName.resolveBinding();
}
} else if( declSpec instanceof ICASTEnumerationSpecifier ){
ICASTEnumerationSpecifier enumeration = (ICASTEnumerationSpecifier) declSpec;
CASTName eName = (CASTName) enumeration.getName();
IASTName eName = enumeration.getName();
if( CharArrayUtils.equals( eName.toCharArray(), name.toCharArray() ) ){
return eName.resolveBinding();
}
//check enumerators too
List list = enumeration.getEnumerators();
for( int i = 0; i < list.size(); i++ ) {
IASTEnumerator enumerator = (IASTEnumerator) list.get(i);
eName = (CASTName) enumerator.getName();
IASTEnumerator [] list = enumeration.getEnumerators();
for( int i = 0; i < list.length; i++ ) {
IASTEnumerator enumerator = list[i];
if( enumerator == null ) break;
eName = enumerator.getName();
if( CharArrayUtils.equals( eName.toCharArray(), name.toCharArray() ) ){
return eName.resolveBinding();
}
@ -498,18 +560,19 @@ public class CVisitor {
}
} else if( declaration instanceof IASTFunctionDefinition ){
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration;
IASTFunctionDeclarator declarator = functionDef.getDeclarator();
CASTFunctionDeclarator declarator = (CASTFunctionDeclarator) functionDef.getDeclarator();
//check the function itself
CASTName declName = (CASTName) declarator.getName();
IASTName declName = declarator.getName();
if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){
return declName.resolveBinding();
}
//check the parameters
List parameters = declarator.getParameters();
for( int i = 0; i < parameters.size(); i++ ){
IASTParameterDeclaration parameterDeclaration = (IASTParameterDeclaration) parameters.get(i);
declName = (CASTName) parameterDeclaration.getDeclarator().getName();
IASTParameterDeclaration [] parameters = declarator.getParameters();
for( int i = 0; i < parameters.length; i++ ){
IASTParameterDeclaration parameterDeclaration = parameters[i];
if( parameterDeclaration == null ) break;
declName = parameterDeclaration.getDeclarator().getName();
if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){
return declName.resolveBinding();
}
@ -518,7 +581,7 @@ public class CVisitor {
return null;
}
private static IBinding checkForBinding( IASTStatement statement, CASTName name ){
private static IBinding checkForBinding( IASTStatement statement, IASTName name ){
if( statement instanceof IASTDeclarationStatement ){
return checkForBinding( ((IASTDeclarationStatement)statement).getDeclaration(), name );
} else if( statement instanceof IASTForStatement ){
@ -531,20 +594,19 @@ public class CVisitor {
}
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 ){
return (IASTFunctionDeclarator) findDefinition( declarator, declarator.getName().toString(), AT_BEGINNING );
return (IASTFunctionDeclarator) findDefinition( declarator, declarator.getName().toCharArray(), AT_NEXT );
}
protected static IASTDeclSpecifier findDefinition( ICASTElaboratedTypeSpecifier declSpec ){
String elabName = declSpec.getName().toString();
return (IASTDeclSpecifier) findDefinition(declSpec, elabName, AT_BEGINNING);
return (IASTDeclSpecifier) findDefinition(declSpec, declSpec.getName().toCharArray(), 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 parent = blockItem.getParent();
List list = null;
IASTNode [] list = null;
if( parent instanceof IASTCompoundStatement ){
IASTCompoundStatement compound = (IASTCompoundStatement) parent;
list = compound.getStatements();
@ -554,8 +616,8 @@ public class CVisitor {
}
boolean begun = ( beginAtLoc == AT_BEGINNING );
if( list != null ){
for( int i = 0; i < list.size(); i++ ){
IASTNode node = (IASTNode) list.get(i);
for( int i = 0; i < list.length; i++ ){
IASTNode node = list[i];
if( node == blockItem ){
begun = true;
continue;
@ -576,18 +638,16 @@ public class CVisitor {
IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) node;
if( simpleDecl.getDeclSpecifier() instanceof ICASTCompositeTypeSpecifier ){
ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) simpleDecl.getDeclSpecifier();
IASTName name = compTypeSpec.getName();
if( name.toString().equals( declName ) ){
if( CharArrayUtils.equals( compTypeSpec.getName().toCharArray(), declName ) ){
return compTypeSpec;
}
}
} else if( node instanceof IASTSimpleDeclaration && decl instanceof IASTDeclarator ){
IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) node;
List dtors = simpleDecl.getDeclarators();
for( int j = 0; j < dtors.size(); j++ ){
IASTDeclarator dtor = (IASTDeclarator) dtors.get( j );
if( dtor.getName().toString().equals( declName ) ){
return dtor;
IASTDeclarator [] dtors = simpleDecl.getDeclarators();
for( int j = 0; dtors != null && j < dtors.length; j++ ){
if( CharArrayUtils.equals( dtors[j].getName().toCharArray(), declName ) ){
return dtors[j];
}
}
}
@ -602,9 +662,9 @@ public class CVisitor {
}
public static void visitTranslationUnit( IASTTranslationUnit tu, BaseVisitorAction action ){
List decls = tu.getDeclarations();
for( int i = 0; i < decls.size(); i++ ){
if( !visitDeclaration( (IASTDeclaration) decls.get(i), action ) ) return;
IASTDeclaration[] decls = tu.getDeclarations();
for( int i = 0; i < decls.length; i++ ){
if( !visitDeclaration( decls[i], action ) ) return;
}
}
@ -621,9 +681,9 @@ public class CVisitor {
if( declaration instanceof IASTSimpleDeclaration ){
IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) declaration;
if( !visitDeclSpecifier( simpleDecl.getDeclSpecifier(), action ) ) return false;
List list = simpleDecl.getDeclarators();
for( int i = 0; i < list.size(); i++ ){
if( !visitDeclarator( (IASTDeclarator) list.get(i), action ) ) return false;
IASTDeclarator [] list = simpleDecl.getDeclarators();
for( int i = 0; list != null && i < list.length; i++ ){
if( !visitDeclarator( list[i], action ) ) return false;
}
} else if( declaration instanceof IASTFunctionDefinition ){
IASTFunctionDefinition fnDef = (IASTFunctionDefinition) declaration;
@ -646,9 +706,9 @@ public class CVisitor {
if( !visitInitializer( declarator.getInitializer(), action ) ) return false;
if( declarator instanceof IASTFunctionDeclarator ){
List list = ((IASTFunctionDeclarator)declarator).getParameters();
for( int i = 0; i < list.size(); i++ ){
IASTParameterDeclaration param = (IASTParameterDeclaration) list.get(i);
IASTParameterDeclaration [] list = ((IASTFunctionDeclarator)declarator).getParameters();
for( int i = 0; i < list.length; i++ ){
IASTParameterDeclaration param = list[i];
if( !visitDeclSpecifier( param.getDeclSpecifier(), action ) ) return false;
if( !visitDeclarator( param.getDeclarator(), action ) ) return false;
}
@ -664,9 +724,10 @@ public class CVisitor {
if( initializer instanceof IASTInitializerExpression ){
if( !visitExpression( ((IASTInitializerExpression) initializer).getExpression(), action ) ) return false;
} else if( initializer instanceof IASTInitializerList ){
List list = ((IASTInitializerList) initializer).getInitializers();
for( int i = 0; i < list.size(); i++ )
if( !visitInitializer( (IASTInitializer) list.get(i), action ) ) return false;
IASTInitializer [] list = ((IASTInitializerList) initializer).getInitializers();
for( int i = 0; i < list.length; i++ ){
if( !visitInitializer( list[i], action ) ) return false;
}
}
return true;
}
@ -687,9 +748,9 @@ public class CVisitor {
ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) declSpec;
if( !visitName( compTypeSpec.getName(), action ) ) return false;
List list = compTypeSpec.getMembers();
for( int i = 0; i < list.size(); i++ ){
if( !visitDeclaration( (IASTDeclaration) list.get(i), action ) ) return false;
IASTDeclaration [] list = compTypeSpec.getMembers();
for( int i = 0; i < list.length; i++ ){
if( !visitDeclaration( list[i], action ) ) return false;
}
} else if( declSpec instanceof ICASTElaboratedTypeSpecifier ){
if( !visitName( ((ICASTElaboratedTypeSpecifier) declSpec).getName(), action ) ) return false;
@ -698,11 +759,10 @@ public class CVisitor {
} else if( declSpec instanceof ICASTEnumerationSpecifier ){
ICASTEnumerationSpecifier enumSpec = (ICASTEnumerationSpecifier) declSpec;
if( !visitName( enumSpec.getName(), action ) ) return false;
List list = enumSpec.getEnumerators();
for( int i = 0; i < list.size(); i++ ){
if( !visitEnumerator( (IASTEnumerator) list.get(i), action ) ) return false;
IASTEnumerator [] list = enumSpec.getEnumerators();
for( int i = 0; i < list.length; i++ ){
if( !visitEnumerator( list[i], action ) ) return false;
}
}
return true;
}
@ -720,9 +780,10 @@ public class CVisitor {
if( !action.processStatement( statement ) ) return false;
if( statement instanceof IASTCompoundStatement ){
List list = ((IASTCompoundStatement) statement).getStatements();
for( int i = 0; i < list.size(); i++ ){
if( !visitStatement( (IASTStatement) list.get(i), action ) ) return false;
IASTStatement [] list = ((IASTCompoundStatement) statement).getStatements();
for( int i = 0; i < list.length; i++ ){
if( list[i] == null ) break;
if( !visitStatement( list[i], action ) ) return false;
}
} else if( statement instanceof IASTDeclarationStatement ){
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).getPositiveResultExpression(), action ) ) return false;
} else if( expression instanceof IASTExpressionList ){
List list = ((IASTExpressionList)expression).getExpressions();
for( int i = 0; i < list.size(); i++){
if( !visitExpression( (IASTExpression) list.get(i), action ) ) return false;
IASTExpression[] list = ((IASTExpressionList)expression).getExpressions();
for( int i = 0; i < list.length; i++){
if( list[i] == null ) break;
if( !visitExpression( list[i], action ) ) return false;
}
} else if( expression instanceof IASTFieldReference ){
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.IASTName;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
/**
@ -86,10 +87,10 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#getMembers()
*/
public List getMembers() {
if( declarations == null ) return Collections.EMPTY_LIST;
public IASTDeclaration[] getMembers() {
if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
removeNullDeclarations();
return Arrays.asList( declarations );
return declarations;
}
@ -147,4 +148,12 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
private int currentIndex2 = 0;
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;
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.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
/**
* @author jcamelon
@ -46,10 +43,10 @@ public class CPPASTCompoundStatement extends CPPASTNode implements
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompoundStatement#getStatements()
*/
public List getStatements() {
if( statements == null ) return Collections.EMPTY_LIST;
public IASTStatement[] getStatements() {
if( statements == null ) return IASTStatement.EMPTY_STATEMENT_ARRAY;
removeNullStatements();
return Arrays.asList( statements );
return statements;
}
/* (non-Javadoc)
@ -71,4 +68,12 @@ public class CPPASTCompoundStatement extends CPPASTNode implements
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;
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.IASTName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
@ -48,10 +44,10 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier#getEnumerators()
*/
public List getEnumerators() {
if( enumerators == null ) return Collections.EMPTY_LIST;
public IASTEnumerator[] getEnumerators() {
if( enumerators == null ) return IASTEnumerator.EMPTY_ENUMERATOR_ARRAY;
removeNullEnumerators();
return Arrays.asList( enumerators );
return enumerators;
}
private void removeNullEnumerators() {

View file

@ -10,10 +10,6 @@
**********************************************************************/
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.IASTExpressionList;
@ -25,10 +21,10 @@ public class CPPASTExpressionList extends CPPASTNode implements
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTExpressionList#getExpressions()
*/
public List getExpressions() {
if( expressions == null ) return Collections.EMPTY_LIST;
public IASTExpression [] getExpressions() {
if( expressions == null ) return IASTExpression.EMPTY_EXPRESSION_ARRAY;
removeNullExpressions();
return Arrays.asList( expressions );
return expressions;
}
/* (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.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
/**
* @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)
* @see org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator#getParameters()
*/
public List getParameters() {
if( parameters == null ) return Collections.EMPTY_LIST;
public IASTParameterDeclaration [] getParameters() {
if( parameters == null ) return IASTParameterDeclaration.EMPTY_PARAMETERDECLARATION_ARRAY;
removeNullParameters();
return Arrays.asList( parameters );
return parameters;
}
/* (non-Javadoc)

View file

@ -10,10 +10,6 @@
**********************************************************************/
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.IASTInitializerList;
@ -28,10 +24,10 @@ public class CPPASTInitializerList extends CPPASTNode implements
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators()
*/
public List getInitializers() {
if( initializers == null ) return Collections.EMPTY_LIST;
public IASTInitializer [] getInitializers() {
if( initializers == null ) return IASTInitializer.EMPTY_INIALIZER_ARRAY;
removeNullInitializers();
return Arrays.asList( initializers );
return initializers;
}
public void addInitializer( IASTInitializer d )

View file

@ -108,5 +108,13 @@ public class CPPASTQualifiedName extends CPPASTNode implements ICPPASTQualifiedN
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;
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.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
@ -36,10 +32,10 @@ public class CPPASTSimpleDeclaration extends CPPASTNode implements
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators()
*/
public List getDeclarators() {
if( declarators == null ) return Collections.EMPTY_LIST;
public IASTDeclarator[] getDeclarators() {
if( declarators == null ) return IASTDeclarator.EMPTY_DECLARATOR_ARRAY;
removeNullDeclarators();
return Arrays.asList( declarators );
return declarators;
}
public void addDeclarator( IASTDeclarator d )

View file

@ -116,4 +116,12 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId {
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;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@ -49,10 +47,10 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations()
*/
public List getDeclarations() {
if( decls == null ) return Collections.EMPTY_LIST;
public IASTDeclaration[] getDeclarations() {
if( decls == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
removeNullDeclarations();
return Arrays.asList( decls );
return decls;
}
/**