1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 01:36:01 +02:00

Types of binary expressions involving arrays. Bug 313037.

This commit is contained in:
Sergey Prigogin 2010-05-17 06:57:58 +00:00
parent da79fc4ed3
commit 34c589670a
4 changed files with 209 additions and 277 deletions

View file

@ -199,8 +199,7 @@ public class AST2Tests extends AST2BaseTest {
// int x // int x
IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) declarations[0]; IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) declarations[0];
IASTSimpleDeclSpecifier declspec_x = (IASTSimpleDeclSpecifier) decl_x IASTSimpleDeclSpecifier declspec_x = (IASTSimpleDeclSpecifier) decl_x.getDeclSpecifier();
.getDeclSpecifier();
assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_x.getType()); assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_x.getType());
IASTDeclarator declor_x = decl_x.getDeclarators()[0]; IASTDeclarator declor_x = decl_x.getDeclarators()[0];
IASTName name_x = declor_x.getName(); IASTName name_x = declor_x.getName();
@ -241,8 +240,7 @@ public class AST2Tests extends AST2BaseTest {
assertEquals("z", name_z.toString()); //$NON-NLS-1$ assertEquals("z", name_z.toString()); //$NON-NLS-1$
// = x + y // = x + y
IASTEqualsInitializer initializer = (IASTEqualsInitializer) declor_z IASTEqualsInitializer initializer = (IASTEqualsInitializer) declor_z.getInitializer();
.getInitializer();
IASTBinaryExpression init_z = (IASTBinaryExpression) initializer.getInitializerClause(); IASTBinaryExpression init_z = (IASTBinaryExpression) initializer.getInitializerClause();
assertEquals(IASTBinaryExpression.op_plus, init_z.getOperator()); assertEquals(IASTBinaryExpression.op_plus, init_z.getOperator());
IASTIdExpression ref_x = (IASTIdExpression) init_z.getOperand1(); IASTIdExpression ref_x = (IASTIdExpression) init_z.getOperand1();
@ -264,8 +262,7 @@ public class AST2Tests extends AST2BaseTest {
var_y.getScope()); var_y.getScope());
IVariable var_z = (IVariable) name_z.resolveBinding(); IVariable var_z = (IVariable) name_z.resolveBinding();
assertEquals(((ICFunctionScope) func_f.getFunctionScope()) assertEquals(((ICFunctionScope) func_f.getFunctionScope()).getBodyScope(), var_z.getScope());
.getBodyScope(), var_z.getScope());
// make sure the variable referenced is the same one we declared above // make sure the variable referenced is the same one we declared above
assertEquals(var_x, name_ref_x.resolveBinding()); assertEquals(var_x, name_ref_x.resolveBinding());
@ -398,13 +395,11 @@ public class AST2Tests extends AST2BaseTest {
.getOperand1(); .getOperand1();
// the reference to myS // the reference to myS
IASTIdExpression ref_myS = (IASTIdExpression) fieldref.getFieldOwner(); IASTIdExpression ref_myS = (IASTIdExpression) fieldref.getFieldOwner();
IASTLiteralExpression lit_5 = (IASTLiteralExpression) assexpr IASTLiteralExpression lit_5 = (IASTLiteralExpression) assexpr.getOperand2();
.getOperand2();
assertEquals("5", lit_5.toString()); //$NON-NLS-1$ assertEquals("5", lit_5.toString()); //$NON-NLS-1$
// Logical Bindings In Test // Logical Bindings In Test
ICompositeType type_struct = (ICompositeType) name_struct ICompositeType type_struct = (ICompositeType) name_struct.resolveBinding();
.resolveBinding();
ITypedef typedef_S = (ITypedef) name_S.resolveBinding(); ITypedef typedef_S = (ITypedef) name_S.resolveBinding();
// make sure the typedef is hooked up correctly // make sure the typedef is hooked up correctly
assertEquals(type_struct, typedef_S.getType()); assertEquals(type_struct, typedef_S.getType());
@ -430,8 +425,7 @@ public class AST2Tests extends AST2BaseTest {
assertEquals(decls.length, 1); assertEquals(decls.length, 1);
assertEquals(decls[0], name_x); assertEquals(decls[0], name_x);
decls = tu.getDeclarationsInAST(def_f.getDeclarator().getName() decls = tu.getDeclarationsInAST(def_f.getDeclarator().getName().resolveBinding());
.resolveBinding());
assertEquals(decls.length, 1); assertEquals(decls.length, 1);
assertEquals(decls[0], def_f.getDeclarator().getName()); assertEquals(decls[0], def_f.getDeclarator().getName());
@ -528,8 +522,7 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse("int r, s;", ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int r, s;", ParserLanguage.C); //$NON-NLS-1$
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
.getDeclarations()[0];
IASTDeclarator[] declarators = decl.getDeclarators(); IASTDeclarator[] declarators = decl.getDeclarators();
assertEquals(2, declarators.length); assertEquals(2, declarators.length);
@ -571,32 +564,25 @@ public class AST2Tests extends AST2BaseTest {
// struct A; // struct A;
IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu
.getDeclarations()[0]; .getDeclarations()[0];
IASTElaboratedTypeSpecifier compTypeSpec = (IASTElaboratedTypeSpecifier) decl1 IASTElaboratedTypeSpecifier compTypeSpec = (IASTElaboratedTypeSpecifier) decl1.getDeclSpecifier();
.getDeclSpecifier();
assertEquals(0, decl1.getDeclarators().length); assertEquals(0, decl1.getDeclarators().length);
IASTName nameA1 = compTypeSpec.getName(); IASTName nameA1 = compTypeSpec.getName();
// void f() { // void f() {
IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations()[1];
.getDeclarations()[1]; IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody();
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef
.getBody();
assertEquals(2, compoundStatement.getStatements().length); assertEquals(2, compoundStatement.getStatements().length);
// struct A; // struct A;
IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compoundStatement IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compoundStatement.getStatements()[0];
.getStatements()[0]; IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) declStatement.getDeclaration();
IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) declStatement
.getDeclaration();
compTypeSpec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier(); compTypeSpec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier();
assertEquals(0, decl2.getDeclarators().length); assertEquals(0, decl2.getDeclarators().length);
IASTName nameA2 = compTypeSpec.getName(); IASTName nameA2 = compTypeSpec.getName();
// struct A * a; // struct A * a;
declStatement = (IASTDeclarationStatement) compoundStatement declStatement = (IASTDeclarationStatement) compoundStatement.getStatements()[1];
.getStatements()[1]; IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) declStatement.getDeclaration();
IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) declStatement
.getDeclaration();
compTypeSpec = (IASTElaboratedTypeSpecifier) decl3.getDeclSpecifier(); compTypeSpec = (IASTElaboratedTypeSpecifier) decl3.getDeclSpecifier();
IASTName nameA3 = compTypeSpec.getName(); IASTName nameA3 = compTypeSpec.getName();
IASTDeclarator dtor = decl3.getDeclarators()[0]; IASTDeclarator dtor = decl3.getDeclarators()[0];
@ -610,8 +596,7 @@ public class AST2Tests extends AST2BaseTest {
IVariable var = (IVariable) namea.resolveBinding(); IVariable var = (IVariable) namea.resolveBinding();
IType str3pointer = var.getType(); IType str3pointer = var.getType();
assertTrue(str3pointer instanceof IPointerType); assertTrue(str3pointer instanceof IPointerType);
ICompositeType str3 = (ICompositeType) ((IPointerType) str3pointer) ICompositeType str3 = (ICompositeType) ((IPointerType) str3pointer).getType();
.getType();
ICompositeType str4 = (ICompositeType) nameA3.resolveBinding(); ICompositeType str4 = (ICompositeType) nameA3.resolveBinding();
assertNotNull(str1); assertNotNull(str1);
assertNotNull(str2); assertNotNull(str2);
@ -624,8 +609,7 @@ public class AST2Tests extends AST2BaseTest {
assertEquals(decls.length, 1); assertEquals(decls.length, 1);
assertEquals(decls[0], nameA1); assertEquals(decls[0], nameA1);
decls = tu.getDeclarationsInAST(fndef.getDeclarator().getName() decls = tu.getDeclarationsInAST(fndef.getDeclarator().getName().resolveBinding());
.resolveBinding());
assertEquals(decls.length, 1); assertEquals(decls.length, 1);
assertEquals(decls[0], fndef.getDeclarator().getName()); assertEquals(decls[0], fndef.getDeclarator().getName());
@ -657,25 +641,19 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
// struct A; // struct A;
IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations()[0];
.getDeclarations()[0]; IASTElaboratedTypeSpecifier compTypeSpec = (IASTElaboratedTypeSpecifier) decl1.getDeclSpecifier();
IASTElaboratedTypeSpecifier compTypeSpec = (IASTElaboratedTypeSpecifier) decl1
.getDeclSpecifier();
assertEquals(0, decl1.getDeclarators().length); assertEquals(0, decl1.getDeclarators().length);
IASTName nameA1 = compTypeSpec.getName(); IASTName nameA1 = compTypeSpec.getName();
// void f() { // void f() {
IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations()[1];
.getDeclarations()[1]; IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody();
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef
.getBody();
assertEquals(1, compoundStatement.getStatements().length); assertEquals(1, compoundStatement.getStatements().length);
// struct A * a; // struct A * a;
IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compoundStatement IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compoundStatement.getStatements()[0];
.getStatements()[0]; IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) declStatement.getDeclaration();
IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) declStatement
.getDeclaration();
compTypeSpec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier(); compTypeSpec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier();
IASTName nameA2 = compTypeSpec.getName(); IASTName nameA2 = compTypeSpec.getName();
IASTDeclarator dtor = decl2.getDeclarators()[0]; IASTDeclarator dtor = decl2.getDeclarators()[0];
@ -698,8 +676,7 @@ public class AST2Tests extends AST2BaseTest {
assertEquals(decls.length, 1); assertEquals(decls.length, 1);
assertEquals(decls[0], nameA1); assertEquals(decls[0], nameA1);
decls = tu.getDeclarationsInAST(fndef.getDeclarator().getName() decls = tu.getDeclarationsInAST(fndef.getDeclarator().getName().resolveBinding());
.resolveBinding());
assertEquals(decls.length, 1); assertEquals(decls.length, 1);
assertEquals(decls[0], fndef.getDeclarator().getName()); assertEquals(decls[0], fndef.getDeclarator().getName());
@ -729,16 +706,13 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
// struct A; // struct A;
IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations()[0];
.getDeclarations()[0]; IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) decl1.getDeclSpecifier();
IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) decl1
.getDeclSpecifier();
assertEquals(0, decl1.getDeclarators().length); assertEquals(0, decl1.getDeclarators().length);
IASTName name_A1 = elabTypeSpec.getName(); IASTName name_A1 = elabTypeSpec.getName();
// struct A * a; // struct A * a;
IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu.getDeclarations()[1];
.getDeclarations()[1];
elabTypeSpec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier(); elabTypeSpec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier();
IASTName name_A2 = elabTypeSpec.getName(); IASTName name_A2 = elabTypeSpec.getName();
IASTDeclarator dtor = decl2.getDeclarators()[0]; IASTDeclarator dtor = decl2.getDeclarators()[0];
@ -747,10 +721,8 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(dtor.getPointerOperators()[0] instanceof ICASTPointer); assertTrue(dtor.getPointerOperators()[0] instanceof ICASTPointer);
// struct A { // struct A {
IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) tu.getDeclarations()[2];
.getDeclarations()[2]; ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) decl3.getDeclSpecifier();
ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) decl3
.getDeclSpecifier();
IASTName name_Adef = compTypeSpec.getName(); IASTName name_Adef = compTypeSpec.getName();
// int i; // int i;
@ -760,17 +732,13 @@ public class AST2Tests extends AST2BaseTest {
IASTName name_i = dtor.getName(); IASTName name_i = dtor.getName();
// void f() { // void f() {
IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations()[3];
.getDeclarations()[3]; IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody();
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef
.getBody();
assertEquals(1, compoundStatement.getStatements().length); assertEquals(1, compoundStatement.getStatements().length);
// a->i; // a->i;
IASTExpressionStatement exprstmt = (IASTExpressionStatement) compoundStatement IASTExpressionStatement exprstmt = (IASTExpressionStatement) compoundStatement.getStatements()[0];
.getStatements()[0]; IASTFieldReference fieldref = (IASTFieldReference) exprstmt.getExpression();
IASTFieldReference fieldref = (IASTFieldReference) exprstmt
.getExpression();
IASTIdExpression id_a = (IASTIdExpression) fieldref.getFieldOwner(); IASTIdExpression id_a = (IASTIdExpression) fieldref.getFieldOwner();
IASTName name_aref = id_a.getName(); IASTName name_aref = id_a.getName();
IASTName name_iref = fieldref.getFieldName(); IASTName name_iref = fieldref.getFieldName();
@ -843,26 +811,19 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
IASTSimpleDeclaration declaration1 = (IASTSimpleDeclaration) tu IASTSimpleDeclaration declaration1 = (IASTSimpleDeclaration) tu.getDeclarations()[0];
.getDeclarations()[0]; IASTCompositeTypeSpecifier typeSpec = (IASTCompositeTypeSpecifier) declaration1.getDeclSpecifier();
IASTCompositeTypeSpecifier typeSpec = (IASTCompositeTypeSpecifier) declaration1
.getDeclSpecifier();
IASTName x_1 = typeSpec.getName(); IASTName x_1 = typeSpec.getName();
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[1];
.getDeclarations()[1];
assertTrue(fdef.getDeclarator() instanceof IASTStandardFunctionDeclarator); assertTrue(fdef.getDeclarator() instanceof IASTStandardFunctionDeclarator);
IASTParameterDeclaration param = ((IASTStandardFunctionDeclarator) fdef IASTParameterDeclaration param = ((IASTStandardFunctionDeclarator) fdef.getDeclarator()).getParameters()[0];
.getDeclarator()).getParameters()[0];
IASTName x_2 = param.getDeclarator().getName(); IASTName x_2 = param.getDeclarator().getName();
IASTCompoundStatement compound = (IASTCompoundStatement) fdef.getBody(); IASTCompoundStatement compound = (IASTCompoundStatement) fdef.getBody();
IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compound IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compound.getStatements()[0];
.getStatements()[0]; IASTSimpleDeclaration declaration2 = (IASTSimpleDeclaration) declStatement.getDeclaration();
IASTSimpleDeclaration declaration2 = (IASTSimpleDeclaration) declStatement IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier) declaration2.getDeclSpecifier();
.getDeclaration();
IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier) declaration2
.getDeclSpecifier();
IASTName x_3 = elab.getName(); IASTName x_3 = elab.getName();
ICompositeType x1 = (ICompositeType) x_1.resolveBinding(); ICompositeType x1 = (ICompositeType) x_1.resolveBinding();
@ -882,8 +843,7 @@ public class AST2Tests extends AST2BaseTest {
assertEquals(decls.length, 1); assertEquals(decls.length, 1);
assertEquals(decls[0], x_1); assertEquals(decls[0], x_1);
decls = tu.getDeclarationsInAST(fdef.getDeclarator().getName() decls = tu.getDeclarationsInAST(fdef.getDeclarator().getName().resolveBinding());
.resolveBinding());
assertEquals(decls.length, 1); assertEquals(decls.length, 1);
assertEquals(decls[0], fdef.getDeclarator().getName()); assertEquals(decls[0], fdef.getDeclarator().getName());
@ -895,8 +855,7 @@ public class AST2Tests extends AST2BaseTest {
assertEquals(decls.length, 1); assertEquals(decls.length, 1);
assertEquals(decls[0], x_1); assertEquals(decls[0], x_1);
decls = tu.getDeclarationsInAST(declaration2.getDeclarators()[0].getName() decls = tu.getDeclarationsInAST(declaration2.getDeclarators()[0].getName().resolveBinding());
.resolveBinding());
assertEquals(decls.length, 1); assertEquals(decls.length, 1);
assertEquals(decls[0], declaration2.getDeclarators()[0].getName()); assertEquals(decls[0], declaration2.getDeclarators()[0].getName());
@ -1044,11 +1003,9 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C);
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
IASTFunctionDefinition fDef = (IASTFunctionDefinition) tu IASTFunctionDefinition fDef = (IASTFunctionDefinition) tu.getDeclarations()[0];
.getDeclarations()[0];
assertTrue(fDef.getDeclarator() instanceof IASTStandardFunctionDeclarator); assertTrue(fDef.getDeclarator() instanceof IASTStandardFunctionDeclarator);
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) fDef IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) fDef.getDeclarator();
.getDeclarator();
IASTName fName = fDtor.getName(); IASTName fName = fDtor.getName();
IASTParameterDeclaration a = fDtor.getParameters()[0]; IASTParameterDeclaration a = fDtor.getParameters()[0];
@ -1098,15 +1055,12 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
// void f(); // void f();
IASTSimpleDeclaration fdecl = (IASTSimpleDeclaration) tu IASTSimpleDeclaration fdecl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
.getDeclarations()[0]; IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) fdecl.getDeclarators()[0];
IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) fdecl
.getDeclarators()[0];
IASTName name_f = fdtor.getName(); IASTName name_f = fdtor.getName();
// void g() { // void g() {
IASTFunctionDefinition gdef = (IASTFunctionDefinition) tu IASTFunctionDefinition gdef = (IASTFunctionDefinition) tu.getDeclarations()[1];
.getDeclarations()[1];
// f(); // f();
IASTCompoundStatement compound = (IASTCompoundStatement) gdef.getBody(); IASTCompoundStatement compound = (IASTCompoundStatement) gdef.getBody();
@ -1120,8 +1074,7 @@ public class AST2Tests extends AST2BaseTest {
assertNull(fcall.getParameterExpression()); assertNull(fcall.getParameterExpression());
// void f() {} // void f() {}
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[2];
.getDeclarations()[2];
assertTrue(fdef.getDeclarator() instanceof IASTStandardFunctionDeclarator); assertTrue(fdef.getDeclarator() instanceof IASTStandardFunctionDeclarator);
fdtor = (IASTStandardFunctionDeclarator) fdef.getDeclarator(); fdtor = (IASTStandardFunctionDeclarator) fdef.getDeclarator();
IASTName name_fdef = fdtor.getName(); IASTName name_fdef = fdtor.getName();
@ -1170,8 +1123,7 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
// void f() { // void f() {
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[0];
.getDeclarations()[0];
IASTCompoundStatement compound = (IASTCompoundStatement) fdef.getBody(); IASTCompoundStatement compound = (IASTCompoundStatement) fdef.getBody();
// for( // for(
@ -1183,23 +1135,20 @@ public class AST2Tests extends AST2BaseTest {
IASTDeclarator dtor = initDecl.getDeclarators()[0]; IASTDeclarator dtor = initDecl.getDeclarators()[0];
IASTName name_i = dtor.getName(); IASTName name_i = dtor.getName();
// i < 5; // i < 5;
IASTBinaryExpression exp = (IASTBinaryExpression) for_stmt IASTBinaryExpression exp = (IASTBinaryExpression) for_stmt.getConditionExpression();
.getConditionExpression();
IASTIdExpression id_i = (IASTIdExpression) exp.getOperand1(); IASTIdExpression id_i = (IASTIdExpression) exp.getOperand1();
IASTName name_i2 = id_i.getName(); IASTName name_i2 = id_i.getName();
IASTLiteralExpression lit_5 = (IASTLiteralExpression) exp.getOperand2(); IASTLiteralExpression lit_5 = (IASTLiteralExpression) exp.getOperand2();
assertEquals(IASTLiteralExpression.lk_integer_constant, lit_5.getKind()); assertEquals(IASTLiteralExpression.lk_integer_constant, lit_5.getKind());
// i++) { // i++) {
IASTUnaryExpression un = (IASTUnaryExpression) for_stmt IASTUnaryExpression un = (IASTUnaryExpression) for_stmt.getIterationExpression();
.getIterationExpression();
IASTIdExpression id_i2 = (IASTIdExpression) un.getOperand(); IASTIdExpression id_i2 = (IASTIdExpression) un.getOperand();
IASTName name_i3 = id_i2.getName(); IASTName name_i3 = id_i2.getName();
assertEquals(IASTUnaryExpression.op_postFixIncr, un.getOperator()); assertEquals(IASTUnaryExpression.op_postFixIncr, un.getOperator());
// i; // i;
compound = (IASTCompoundStatement) for_stmt.getBody(); compound = (IASTCompoundStatement) for_stmt.getBody();
IASTExpressionStatement exprSt = (IASTExpressionStatement) compound IASTExpressionStatement exprSt = (IASTExpressionStatement) compound.getStatements()[0];
.getStatements()[0];
IASTIdExpression id_i3 = (IASTIdExpression) exprSt.getExpression(); IASTIdExpression id_i3 = (IASTIdExpression) exprSt.getExpression();
IASTName name_i4 = id_i3.getName(); IASTName name_i4 = id_i3.getName();
@ -1338,18 +1287,14 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
// test tu.getDeclarationsInAST(IBinding) // test tu.getDeclarationsInAST(IBinding)
IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations()[0];
.getDeclarations()[0]; IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu.getDeclarations()[1];
IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu
.getDeclarations()[1];
IASTName name_X1 = decl1.getDeclarators()[0].getName(); IASTName name_X1 = decl1.getDeclarators()[0].getName();
IASTName name_f = decl2.getDeclarators()[0].getName(); IASTName name_f = decl2.getDeclarators()[0].getName();
IASTName name_X2 = ((IASTNamedTypeSpecifier) ((IASTStandardFunctionDeclarator) decl2 IASTName name_X2 = ((IASTNamedTypeSpecifier) ((IASTStandardFunctionDeclarator) decl2
.getDeclarators()[0]).getParameters()[0].getDeclSpecifier()) .getDeclarators()[0]).getParameters()[0].getDeclSpecifier()).getName();
.getName();
IASTName name_x = ((IASTStandardFunctionDeclarator) decl2 IASTName name_x = ((IASTStandardFunctionDeclarator) decl2
.getDeclarators()[0]).getParameters()[0].getDeclarator() .getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
.getName();
IASTName[] decls = tu.getDeclarationsInAST(name_X1.resolveBinding()); IASTName[] decls = tu.getDeclarationsInAST(name_X1.resolveBinding());
assertEquals(decls.length, 1); assertEquals(decls.length, 1);
@ -1397,42 +1342,34 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C);
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations()[0];
.getDeclarations()[0];
assertEquals(decl1.getDeclarators().length, 0); assertEquals(decl1.getDeclarators().length, 0);
ICASTEnumerationSpecifier enumSpec = (ICASTEnumerationSpecifier) decl1 ICASTEnumerationSpecifier enumSpec = (ICASTEnumerationSpecifier) decl1.getDeclSpecifier();
.getDeclSpecifier();
IASTEnumerator e1 = enumSpec.getEnumerators()[0]; IASTEnumerator e1 = enumSpec.getEnumerators()[0];
IASTEnumerator e2 = enumSpec.getEnumerators()[1]; IASTEnumerator e2 = enumSpec.getEnumerators()[1];
IASTEnumerator e3 = enumSpec.getEnumerators()[2]; IASTEnumerator e3 = enumSpec.getEnumerators()[2];
IASTName name_hue = enumSpec.getName(); IASTName name_hue = enumSpec.getName();
IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu.getDeclarations()[1];
.getDeclarations()[1];
IASTDeclarator dtor = decl2.getDeclarators()[0]; IASTDeclarator dtor = decl2.getDeclarators()[0];
IASTName name_col = dtor.getName(); IASTName name_col = dtor.getName();
dtor = decl2.getDeclarators()[1]; dtor = decl2.getDeclarators()[1];
IASTName name_cp = dtor.getName(); IASTName name_cp = dtor.getName();
IASTElaboratedTypeSpecifier spec = (IASTElaboratedTypeSpecifier) decl2 IASTElaboratedTypeSpecifier spec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier();
.getDeclSpecifier();
assertEquals(spec.getKind(), IASTElaboratedTypeSpecifier.k_enum); assertEquals(spec.getKind(), IASTElaboratedTypeSpecifier.k_enum);
IASTName name_hue2 = spec.getName(); IASTName name_hue2 = spec.getName();
IASTFunctionDefinition fn = (IASTFunctionDefinition) tu IASTFunctionDefinition fn = (IASTFunctionDefinition) tu.getDeclarations()[2];
.getDeclarations()[2];
IASTCompoundStatement compound = (IASTCompoundStatement) fn.getBody(); IASTCompoundStatement compound = (IASTCompoundStatement) fn.getBody();
IASTExpressionStatement expStatement1 = (IASTExpressionStatement) compound IASTExpressionStatement expStatement1 = (IASTExpressionStatement) compound.getStatements()[0];
.getStatements()[0]; IASTBinaryExpression exp = (IASTBinaryExpression) expStatement1.getExpression();
IASTBinaryExpression exp = (IASTBinaryExpression) expStatement1
.getExpression();
assertEquals(exp.getOperator(), IASTBinaryExpression.op_assign); assertEquals(exp.getOperator(), IASTBinaryExpression.op_assign);
IASTIdExpression id1 = (IASTIdExpression) exp.getOperand1(); IASTIdExpression id1 = (IASTIdExpression) exp.getOperand1();
IASTIdExpression id2 = (IASTIdExpression) exp.getOperand2(); IASTIdExpression id2 = (IASTIdExpression) exp.getOperand2();
IASTName r_col = id1.getName(); IASTName r_col = id1.getName();
IASTName r_blue = id2.getName(); IASTName r_blue = id2.getName();
IASTExpressionStatement expStatement2 = (IASTExpressionStatement) compound IASTExpressionStatement expStatement2 = (IASTExpressionStatement) compound.getStatements()[1];
.getStatements()[1];
exp = (IASTBinaryExpression) expStatement2.getExpression(); exp = (IASTBinaryExpression) expStatement2.getExpression();
assertEquals(exp.getOperator(), IASTBinaryExpression.op_assign); assertEquals(exp.getOperator(), IASTBinaryExpression.op_assign);
id1 = (IASTIdExpression) exp.getOperand1(); id1 = (IASTIdExpression) exp.getOperand1();
@ -1441,8 +1378,7 @@ public class AST2Tests extends AST2BaseTest {
IASTName r_cp = id1.getName(); IASTName r_cp = id1.getName();
IASTName r_col2 = id2.getName(); IASTName r_col2 = id2.getName();
IASTIfStatement ifStatement = (IASTIfStatement) compound IASTIfStatement ifStatement = (IASTIfStatement) compound.getStatements()[2];
.getStatements()[2];
exp = (IASTBinaryExpression) ifStatement.getConditionExpression(); exp = (IASTBinaryExpression) ifStatement.getConditionExpression();
ue = (IASTUnaryExpression) exp.getOperand1(); ue = (IASTUnaryExpression) exp.getOperand1();
id1 = (IASTIdExpression) ue.getOperand(); id1 = (IASTIdExpression) ue.getOperand();
@ -1696,32 +1632,23 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C);
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
.getDeclarations()[0]; IASTCompositeTypeSpecifier compSpec = (IASTCompositeTypeSpecifier) decl.getDeclSpecifier();
IASTCompositeTypeSpecifier compSpec = (IASTCompositeTypeSpecifier) decl
.getDeclSpecifier();
ICompositeType A = (ICompositeType) compSpec.getName().resolveBinding(); ICompositeType A = (ICompositeType) compSpec.getName().resolveBinding();
IASTName name_a1 = decl.getDeclarators()[0].getName(); IASTName name_a1 = decl.getDeclarators()[0].getName();
IVariable a1 = (IVariable) decl.getDeclarators()[0].getName() IVariable a1 = (IVariable) decl.getDeclarators()[0].getName().resolveBinding();
.resolveBinding();
decl = (IASTSimpleDeclaration) tu.getDeclarations()[1]; decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
IASTName name_A2 = ((IASTElaboratedTypeSpecifier) decl IASTName name_A2 = ((IASTElaboratedTypeSpecifier) decl.getDeclSpecifier()).getName();
.getDeclSpecifier()).getName();
IASTName name_AP = decl.getDeclarators()[0].getName(); IASTName name_AP = decl.getDeclarators()[0].getName();
ITypedef AP = (ITypedef) decl.getDeclarators()[0].getName() ITypedef AP = (ITypedef) decl.getDeclarators()[0].getName().resolveBinding();
.resolveBinding();
decl = (IASTSimpleDeclaration) tu.getDeclarations()[2]; decl = (IASTSimpleDeclaration) tu.getDeclarations()[2];
IASTName name_A3 = ((IASTElaboratedTypeSpecifier) decl IASTName name_A3 = ((IASTElaboratedTypeSpecifier) decl.getDeclSpecifier()).getName();
.getDeclSpecifier()).getName(); IVariable a2 = (IVariable) decl.getDeclarators()[0].getName().resolveBinding();
IVariable a2 = (IVariable) decl.getDeclarators()[0].getName()
.resolveBinding();
IASTName name_a2 = decl.getDeclarators()[0].getName(); IASTName name_a2 = decl.getDeclarators()[0].getName();
decl = (IASTSimpleDeclaration) tu.getDeclarations()[3]; decl = (IASTSimpleDeclaration) tu.getDeclarations()[3];
IVariable a3 = (IVariable) decl.getDeclarators()[0].getName() IVariable a3 = (IVariable) decl.getDeclarators()[0].getName().resolveBinding();
.resolveBinding();
IASTName name_a3 = decl.getDeclarators()[0].getName(); IASTName name_a3 = decl.getDeclarators()[0].getName();
IASTName name_AP2 = ((IASTNamedTypeSpecifier) decl.getDeclSpecifier()) IASTName name_AP2 = ((IASTNamedTypeSpecifier) decl.getDeclSpecifier()).getName();
.getName();
IType t_a1 = a1.getType(); IType t_a1 = a1.getType();
assertSame(t_a1, A); assertSame(t_a1, A);
@ -1738,8 +1665,7 @@ public class AST2Tests extends AST2BaseTest {
assertSame(((IPointerType) t_AP).getType(), A); assertSame(((IPointerType) t_AP).getType(), A);
// test tu.getDeclarationsInAST(IBinding) // test tu.getDeclarationsInAST(IBinding)
IASTName[] decls = tu.getDeclarationsInAST(compSpec.getName() IASTName[] decls = tu.getDeclarationsInAST(compSpec.getName().resolveBinding());
.resolveBinding());
assertEquals(decls.length, 1); assertEquals(decls.length, 1);
assertEquals(decls[0], compSpec.getName()); assertEquals(decls[0], compSpec.getName());
@ -1864,46 +1790,37 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C);
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
.getDeclarations()[0]; IASTElaboratedTypeSpecifier elabSpec = (IASTElaboratedTypeSpecifier) decl.getDeclSpecifier();
IASTElaboratedTypeSpecifier elabSpec = (IASTElaboratedTypeSpecifier) decl
.getDeclSpecifier();
ICompositeType A = (ICompositeType) elabSpec.getName().resolveBinding(); ICompositeType A = (ICompositeType) elabSpec.getName().resolveBinding();
IASTName name_A1 = elabSpec.getName(); IASTName name_A1 = elabSpec.getName();
assertTrue(name_A1.isDeclaration()); assertTrue(name_A1.isDeclaration());
decl = (IASTSimpleDeclaration) tu.getDeclarations()[1]; decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
IFunction f = (IFunction) decl.getDeclarators()[0].getName() IFunction f = (IFunction) decl.getDeclarators()[0].getName().resolveBinding();
.resolveBinding();
IASTName name_f = decl.getDeclarators()[0].getName(); IASTName name_f = decl.getDeclarators()[0].getName();
IASTName name_i = ((IASTStandardFunctionDeclarator) decl IASTName name_i = ((IASTStandardFunctionDeclarator) decl
.getDeclarators()[0]).getParameters()[0].getDeclarator() .getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
.getName();
IASTName name_c = ((IASTStandardFunctionDeclarator) decl IASTName name_c = ((IASTStandardFunctionDeclarator) decl
.getDeclarators()[0]).getParameters()[1].getDeclarator() .getDeclarators()[0]).getParameters()[1].getDeclarator().getName();
.getName();
decl = (IASTSimpleDeclaration) tu.getDeclarations()[2]; decl = (IASTSimpleDeclaration) tu.getDeclarations()[2];
IVariable g = (IVariable) decl.getDeclarators()[0] IVariable g = (IVariable) decl.getDeclarators()[0]
.getNestedDeclarator().getName().resolveBinding(); .getNestedDeclarator().getName().resolveBinding();
IASTName name_g = decl.getDeclarators()[0].getNestedDeclarator() IASTName name_g = decl.getDeclarators()[0].getNestedDeclarator().getName();
.getName();
IASTName name_A2 = ((IASTElaboratedTypeSpecifier) ((IASTStandardFunctionDeclarator) decl IASTName name_A2 = ((IASTElaboratedTypeSpecifier) ((IASTStandardFunctionDeclarator) decl
.getDeclarators()[0]).getParameters()[0].getDeclSpecifier()) .getDeclarators()[0]).getParameters()[0].getDeclSpecifier()).getName();
.getName();
decl = (IASTSimpleDeclaration) tu.getDeclarations()[3]; decl = (IASTSimpleDeclaration) tu.getDeclarations()[3];
IVariable h = (IVariable) decl.getDeclarators()[0] IVariable h = (IVariable) decl.getDeclarators()[0]
.getNestedDeclarator().getNestedDeclarator().getName() .getNestedDeclarator().getNestedDeclarator().getName().resolveBinding();
.resolveBinding();
IASTName name_h = decl.getDeclarators()[0].getNestedDeclarator() IASTName name_h = decl.getDeclarators()[0].getNestedDeclarator()
.getNestedDeclarator().getName(); .getNestedDeclarator().getName();
IASTName name_A3 = ((IASTElaboratedTypeSpecifier) ((IASTStandardFunctionDeclarator) decl IASTName name_A3 = ((IASTElaboratedTypeSpecifier) ((IASTStandardFunctionDeclarator) decl
.getDeclarators()[0].getNestedDeclarator()).getParameters()[0] .getDeclarators()[0].getNestedDeclarator()).getParameters()[0]
.getDeclSpecifier()).getName(); .getDeclSpecifier()).getName();
IASTName name_d = ((IASTStandardFunctionDeclarator) decl IASTName name_d = ((IASTStandardFunctionDeclarator) decl
.getDeclarators()[0]).getParameters()[0].getDeclarator() .getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
.getName();
IFunctionType t_f = f.getType(); IFunctionType t_f = f.getType();
IType t_f_return = t_f.getReturnType(); IType t_f_return = t_f.getReturnType();
@ -2012,30 +1929,21 @@ public class AST2Tests extends AST2BaseTest {
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
assertNotNull(tu); assertNotNull(tu);
IASTDeclaration[] declarations = tu.getDeclarations(); IASTDeclaration[] declarations = tu.getDeclarations();
IASTName name_Coord = ((IASTSimpleDeclaration) declarations[0]) IASTName name_Coord = ((IASTSimpleDeclaration) declarations[0]).getDeclarators()[0].getName();
.getDeclarators()[0].getName();
IASTName name_x = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) declarations[0]) IASTName name_x = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) declarations[0])
.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0] .getDeclSpecifier()).getMembers()[0]).getDeclarators()[0].getName();
.getName();
IASTName name_y = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) declarations[0]) IASTName name_y = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) declarations[0])
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0] .getDeclSpecifier()).getMembers()[1]).getDeclarators()[0].getName();
.getName(); IASTName name_Point = ((IASTSimpleDeclaration) declarations[1]).getDeclarators()[0].getName();
IASTName name_Point = ((IASTSimpleDeclaration) declarations[1])
.getDeclarators()[0].getName();
IASTName name_pos = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) declarations[1]) IASTName name_pos = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) declarations[1])
.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0] .getDeclSpecifier()).getMembers()[0]).getDeclarators()[0].getName();
.getName();
IASTName name_width = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) declarations[1]) IASTName name_width = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) declarations[1])
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0] .getDeclSpecifier()).getMembers()[1]).getDeclarators()[0].getName();
.getName();
IASTFunctionDefinition main = (IASTFunctionDefinition) declarations[2]; IASTFunctionDefinition main = (IASTFunctionDefinition) declarations[2];
IASTStatement[] statements = ((IASTCompoundStatement) main.getBody()) IASTStatement[] statements = ((IASTCompoundStatement) main.getBody()).getStatements();
.getStatements();
IASTSimpleDeclaration xy = (IASTSimpleDeclaration) ((IASTDeclarationStatement) statements[0]) IASTSimpleDeclaration xy = (IASTSimpleDeclaration) ((IASTDeclarationStatement) statements[0]).getDeclaration();
.getDeclaration(); IASTName name_Coord2 = ((IASTNamedTypeSpecifier) xy.getDeclSpecifier()).getName();
IASTName name_Coord2 = ((IASTNamedTypeSpecifier) xy.getDeclSpecifier())
.getName();
IASTName name_xy = xy.getDeclarators()[0].getName(); IASTName name_xy = xy.getDeclarators()[0].getName();
IASTDeclarator declarator_xy = xy.getDeclarators()[0]; IASTDeclarator declarator_xy = xy.getDeclarators()[0];
IASTInitializer[] initializers1 = ((IASTInitializerList) ((IASTEqualsInitializer) declarator_xy.getInitializer()) IASTInitializer[] initializers1 = ((IASTInitializerList) ((IASTEqualsInitializer) declarator_xy.getInitializer())
@ -2125,10 +2033,8 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C);
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
IASTSimpleDeclaration S_decl = (IASTSimpleDeclaration) tu IASTSimpleDeclaration S_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
.getDeclarations()[0]; IASTFunctionDefinition f_def = (IASTFunctionDefinition) tu.getDeclarations()[1];
IASTFunctionDefinition f_def = (IASTFunctionDefinition) tu
.getDeclarations()[1];
IASTName a1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl IASTName a1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl
.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0] .getDeclSpecifier()).getMembers()[0]).getDeclarators()[0]
@ -2167,8 +2073,7 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C);
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
IASTSimpleDeclaration S_decl = (IASTSimpleDeclaration) tu IASTSimpleDeclaration S_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
.getDeclarations()[0];
IASTName a1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl IASTName a1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl
.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0] .getDeclSpecifier()).getMembers()[0]).getDeclarators()[0]
@ -2364,10 +2269,8 @@ public class AST2Tests extends AST2BaseTest {
"int f(int g(void)) { return g();}", ParserLanguage.C); //$NON-NLS-1$ "int f(int g(void)) { return g();}", ParserLanguage.C); //$NON-NLS-1$
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
IASTFunctionDefinition def = (IASTFunctionDefinition) tu IASTFunctionDefinition def = (IASTFunctionDefinition) tu.getDeclarations()[0];
.getDeclarations()[0]; IFunction f = (IFunction) def.getDeclarator().getName().resolveBinding();
IFunction f = (IFunction) def.getDeclarator().getName()
.resolveBinding();
IType ft = ((CFunction) f).getType(); IType ft = ((CFunction) f).getType();
assertTrue(ft instanceof IFunctionType); assertTrue(ft instanceof IFunctionType);
@ -2403,8 +2306,7 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
.getDeclarations()[0];
IVariable v = (IVariable) ((IASTStandardFunctionDeclarator) decl IVariable v = (IVariable) ((IASTStandardFunctionDeclarator) decl
.getDeclarators()[0]).getNestedDeclarator().getName() .getDeclarators()[0]).getNestedDeclarator().getName()
.resolveBinding(); .resolveBinding();
@ -2431,8 +2333,7 @@ public class AST2Tests extends AST2BaseTest {
assertEquals(((IBasicType) vpt_2_2).getType(), IBasicType.t_int); assertEquals(((IBasicType) vpt_2_2).getType(), IBasicType.t_int);
// test tu.getDeclarationsInAST(IBinding) // test tu.getDeclarationsInAST(IBinding)
IASTName[] decls = tu IASTName[] decls = tu.getDeclarationsInAST(((IASTStandardFunctionDeclarator) decl
.getDeclarationsInAST(((IASTStandardFunctionDeclarator) decl
.getDeclarators()[0]).getNestedDeclarator().getName() .getDeclarators()[0]).getNestedDeclarator().getName()
.resolveBinding()); .resolveBinding());
assertEquals(decls.length, 1); assertEquals(decls.length, 1);
@ -2451,28 +2352,22 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations()[0];
.getDeclarations()[0]; ITypedef dword = (ITypedef) decl1.getDeclarators()[0].getName().resolveBinding();
ITypedef dword = (ITypedef) decl1.getDeclarators()[0].getName()
.resolveBinding();
IType dword_t = dword.getType(); IType dword_t = dword.getType();
assertTrue(dword_t instanceof IBasicType); assertTrue(dword_t instanceof IBasicType);
assertEquals(((IBasicType) dword_t).getType(), IBasicType.t_void); assertEquals(((IBasicType) dword_t).getType(), IBasicType.t_void);
IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu.getDeclarations()[1];
.getDeclarations()[1]; ITypedef v = (ITypedef) decl2.getDeclarators()[0].getName().resolveBinding();
ITypedef v = (ITypedef) decl2.getDeclarators()[0].getName()
.resolveBinding();
IType v_t_1 = v.getType(); IType v_t_1 = v.getType();
assertTrue(v_t_1 instanceof ITypedef); assertTrue(v_t_1 instanceof ITypedef);
IType v_t_2 = ((ITypedef) v_t_1).getType(); IType v_t_2 = ((ITypedef) v_t_1).getType();
assertTrue(v_t_2 instanceof IBasicType); assertTrue(v_t_2 instanceof IBasicType);
assertEquals(((IBasicType) v_t_2).getType(), IBasicType.t_void); assertEquals(((IBasicType) v_t_2).getType(), IBasicType.t_void);
IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) tu.getDeclarations()[2];
.getDeclarations()[2]; IFunction signal = (IFunction) decl3.getDeclarators()[0].getName().resolveBinding();
IFunction signal = (IFunction) decl3.getDeclarators()[0].getName()
.resolveBinding();
IFunctionType signal_t = signal.getType(); IFunctionType signal_t = signal.getType();
IType signal_ret = signal_t.getReturnType(); IType signal_ret = signal_t.getReturnType();
assertTrue(signal_ret instanceof ITypedef); assertTrue(signal_ret instanceof ITypedef);
@ -2511,18 +2406,14 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C);
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations()[0];
.getDeclarations()[0]; ITypedef dword = (ITypedef) decl1.getDeclarators()[0].getName().resolveBinding();
ITypedef dword = (ITypedef) decl1.getDeclarators()[0].getName()
.resolveBinding();
IType dword_t = dword.getType(); IType dword_t = dword.getType();
assertTrue(dword_t instanceof IBasicType); assertTrue(dword_t instanceof IBasicType);
assertEquals(((IBasicType) dword_t).getType(), IBasicType.t_void); assertEquals(((IBasicType) dword_t).getType(), IBasicType.t_void);
IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu.getDeclarations()[1];
.getDeclarations()[1]; ITypedef pfv = (ITypedef) decl2.getDeclarators()[0].getNestedDeclarator().getName().resolveBinding();
ITypedef pfv = (ITypedef) decl2.getDeclarators()[0]
.getNestedDeclarator().getName().resolveBinding();
IType pfv_t_1 = pfv.getType(); IType pfv_t_1 = pfv.getType();
assertTrue(pfv_t_1 instanceof IPointerType); assertTrue(pfv_t_1 instanceof IPointerType);
IType pfv_t_2 = ((IPointerType) pfv_t_1).getType(); IType pfv_t_2 = ((IPointerType) pfv_t_1).getType();
@ -2537,10 +2428,8 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(pfv_t_2_parm instanceof IBasicType); assertTrue(pfv_t_2_parm instanceof IBasicType);
assertEquals(((IBasicType) pfv_t_2_parm).getType(), IBasicType.t_int); assertEquals(((IBasicType) pfv_t_2_parm).getType(), IBasicType.t_int);
IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) tu.getDeclarations()[2];
.getDeclarations()[2]; IFunction signal = (IFunction) decl3.getDeclarators()[0].getName().resolveBinding();
IFunction signal = (IFunction) decl3.getDeclarators()[0].getName()
.resolveBinding();
IFunctionType signal_t = signal.getType(); IFunctionType signal_t = signal.getType();
IType signal_ret_1 = signal_t.getReturnType(); IType signal_ret_1 = signal_t.getReturnType();
assertTrue(signal_ret_1 instanceof ITypedef); assertTrue(signal_ret_1 instanceof ITypedef);
@ -2565,24 +2454,19 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(signal_parm_t2_1 instanceof IPointerType); assertTrue(signal_parm_t2_1 instanceof IPointerType);
IType signal_parm_t2_2 = ((IPointerType) signal_parm_t2_1).getType(); IType signal_parm_t2_2 = ((IPointerType) signal_parm_t2_1).getType();
assertTrue(signal_parm_t2_2 instanceof IFunctionType); assertTrue(signal_parm_t2_2 instanceof IFunctionType);
IType signal_parm_t2_ret_1 = ((IFunctionType) signal_parm_t2_2) IType signal_parm_t2_ret_1 = ((IFunctionType) signal_parm_t2_2).getReturnType();
.getReturnType();
assertTrue(signal_parm_t2_ret_1 instanceof ITypedef); assertTrue(signal_parm_t2_ret_1 instanceof ITypedef);
IType signal_parm_t2_ret_2 = ((ITypedef) signal_parm_t2_ret_1) IType signal_parm_t2_ret_2 = ((ITypedef) signal_parm_t2_ret_1).getType();
.getType();
assertTrue(signal_parm_t2_ret_2 instanceof IBasicType); assertTrue(signal_parm_t2_ret_2 instanceof IBasicType);
assertEquals(((IBasicType) signal_parm_t2_ret_2).getType(), assertEquals(((IBasicType) signal_parm_t2_ret_2).getType(),
IBasicType.t_void); IBasicType.t_void);
assertTrue(((ITypedef) signal_parm_t2_ret_1).getName().equals("DWORD")); //$NON-NLS-1$ assertTrue(((ITypedef) signal_parm_t2_ret_1).getName().equals("DWORD")); //$NON-NLS-1$
// test tu.getDeclarationsInAST(IBinding) // test tu.getDeclarationsInAST(IBinding)
IASTName name_pfv = decl2.getDeclarators()[0].getNestedDeclarator() IASTName name_pfv = decl2.getDeclarators()[0].getNestedDeclarator().getName();
.getName(); IASTName name_pfv1 = ((IASTNamedTypeSpecifier) decl3.getDeclSpecifier()).getName();
IASTName name_pfv1 = ((IASTNamedTypeSpecifier) decl3.getDeclSpecifier())
.getName();
IASTName name_pfv2 = ((IASTNamedTypeSpecifier) ((IASTStandardFunctionDeclarator) decl3 IASTName name_pfv2 = ((IASTNamedTypeSpecifier) ((IASTStandardFunctionDeclarator) decl3
.getDeclarators()[0]).getParameters()[1].getDeclSpecifier()) .getDeclarators()[0]).getParameters()[1].getDeclSpecifier()).getName();
.getName();
IASTName[] decls = tu.getDeclarationsInAST(name_pfv1.resolveBinding()); IASTName[] decls = tu.getDeclarationsInAST(name_pfv1.resolveBinding());
assertEquals(decls.length, 1); assertEquals(decls.length, 1);
@ -2605,12 +2489,9 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(tu.isFrozen()); assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) { for (int i = 0; i < NUM_TESTS; i++) {
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
.getDeclarations()[0]; ITypedef fv = (ITypedef) decl.getDeclarators()[0].getName().resolveBinding();
ITypedef fv = (ITypedef) decl.getDeclarators()[0].getName() ITypedef pfv = (ITypedef) decl.getDeclarators()[1].getNestedDeclarator().getName().resolveBinding();
.resolveBinding();
ITypedef pfv = (ITypedef) decl.getDeclarators()[1]
.getNestedDeclarator().getName().resolveBinding();
IType fv_t = fv.getType(); IType fv_t = fv.getType();
assertEquals(((IBasicType) ((IFunctionType) fv_t).getReturnType()) assertEquals(((IBasicType) ((IFunctionType) fv_t).getReturnType())
@ -2632,13 +2513,11 @@ public class AST2Tests extends AST2BaseTest {
IType signal1_t = signal1.getType(); IType signal1_t = signal1.getType();
decl = (IASTSimpleDeclaration) tu.getDeclarations()[2]; decl = (IASTSimpleDeclaration) tu.getDeclarations()[2];
IFunction signal2 = (IFunction) decl.getDeclarators()[0].getName() IFunction signal2 = (IFunction) decl.getDeclarators()[0].getName().resolveBinding();
.resolveBinding();
IType signal2_t = signal2.getType(); IType signal2_t = signal2.getType();
decl = (IASTSimpleDeclaration) tu.getDeclarations()[3]; decl = (IASTSimpleDeclaration) tu.getDeclarations()[3];
IFunction signal3 = (IFunction) decl.getDeclarators()[0].getName() IFunction signal3 = (IFunction) decl.getDeclarators()[0].getName().resolveBinding();
.resolveBinding();
IType signal3_t = signal3.getType(); IType signal3_t = signal3.getType();
assertEquals( assertEquals(
@ -7154,6 +7033,31 @@ public class AST2Tests extends AST2BaseTest {
} }
} }
// char array[10];
// char* ptr;
//
// void test() {
// array + 1;
// 1 + array;
// ptr + 1;
// 1 + ptr;
// }
public void testPointerExpression_131037() throws Exception {
for (ParserLanguage lang : ParserLanguage.values()) {
IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), lang);
assertTrue(tu.isFrozen());
for (IASTDeclaration d : tu.getDeclarations()) {
if (d instanceof IASTFunctionDefinition) {
for (IASTStatement s : ((IASTCompoundStatement) ((IASTFunctionDefinition) d).getBody()).getStatements()) {
IType t = ((IASTBinaryExpression) ((IASTExpressionStatement) s).getExpression()).getExpressionType();
assertTrue(t instanceof IPointerType || t instanceof IArrayType);
assertEquals("char", ((IPointerType) t).getType().toString());
}
}
}
}
}
// extern int a[]; // extern int a[];
// int a[1]; // int a[1];
public void testIncompleteArrays_269926() throws Exception { public void testIncompleteArrays_269926() throws Exception {

View file

@ -17,9 +17,11 @@ import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
@ -211,14 +213,18 @@ public class CASTBinaryExpression extends ASTNode implements
case op_notequals: case op_notequals:
return new CBasicType(Kind.eInt, 0, this); return new CBasicType(Kind.eInt, 0, this);
case IASTBinaryExpression.op_plus: case IASTBinaryExpression.op_plus:
if (t2 instanceof IPointerType) { if (t1 instanceof IArrayType) {
return arrayTypeToPointerType((ICArrayType) t1);
} else if (t2 instanceof IPointerType) {
return t2; return t2;
} else if (t2 instanceof IArrayType) {
return arrayTypeToPointerType((ICArrayType) t2);
} }
break; break;
case IASTBinaryExpression.op_minus: case IASTBinaryExpression.op_minus:
if (t2 instanceof IPointerType) { if (t2 instanceof IPointerType || t2 instanceof IArrayType) {
if (t1 instanceof IPointerType) { if (t1 instanceof IPointerType || t1 instanceof IArrayType) {
return CVisitor.getPtrDiffType(this); return CVisitor.getPtrDiffType(this);
} }
return t1; return t1;
@ -228,6 +234,13 @@ public class CASTBinaryExpression extends ASTNode implements
return t1; return t1;
} }
private IType arrayTypeToPointerType(ICArrayType type) {
return new CPointerType(type.getType(),
(type.isConst() ? CPointerType.IS_CONST : 0) |
(type.isRestrict() ? CPointerType.IS_RESTRICT : 0) |
(type.isVolatile() ? CPointerType.IS_VOLATILE : 0));
}
public boolean isLValue() { public boolean isLValue() {
switch (getOperator()) { switch (getOperator()) {
case op_assign: case op_assign:

View file

@ -11,6 +11,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
@ -205,4 +206,9 @@ public class CBasicType implements ICBasicType, ISerializableType {
} }
return t_unspecified; return t_unspecified;
} }
@Override
public String toString() {
return ASTTypeUtil.getType(this);
}
} }

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
@ -314,14 +315,18 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr
return new CPPBasicType(Kind.eBoolean, 0, this); return new CPPBasicType(Kind.eBoolean, 0, this);
case IASTBinaryExpression.op_plus: case IASTBinaryExpression.op_plus:
if (type2 instanceof IPointerType) { if (type1 instanceof IArrayType) {
return arrayTypeToPointerType((IArrayType) type1);
} else if (type2 instanceof IPointerType) {
return type2; return type2;
} else if (type2 instanceof IArrayType) {
return arrayTypeToPointerType((IArrayType) type2);
} }
break; break;
case IASTBinaryExpression.op_minus: case IASTBinaryExpression.op_minus:
if (type2 instanceof IPointerType) { if (type2 instanceof IPointerType || type2 instanceof IArrayType) {
if (type1 instanceof IPointerType) { if (type1 instanceof IPointerType || type1 instanceof IArrayType) {
return CPPVisitor.getPointerDiffType(this); return CPPVisitor.getPointerDiffType(this);
} }
return type1; return type1;
@ -337,4 +342,8 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr
} }
return type1; return type1;
} }
private IType arrayTypeToPointerType(IArrayType type) {
return new CPPPointerType(type.getType());
}
} }