mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 12:03:16 +02:00
Fixed Bug 85049 - [Parser2] B * bp; declaration parsed as binary expression.
This commit is contained in:
parent
b9cfea60b3
commit
98145350e0
7 changed files with 4679 additions and 4498 deletions
|
@ -13,9 +13,9 @@
|
|||
*/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
||||
|
@ -1596,17 +1596,26 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
public void testFindTypeBinding_2() throws Exception {
|
||||
IASTTranslationUnit tu = parse(
|
||||
"struct B; void f() { B * bp; }", ParserLanguage.CPP); //$NON-NLS-1$
|
||||
|
||||
IASTCompoundStatement compound = (IASTCompoundStatement) ((IASTFunctionDefinition) tu
|
||||
.getDeclarations()[1]).getBody();
|
||||
IASTBinaryExpression exp = (IASTBinaryExpression) ((IASTExpressionStatement) compound
|
||||
.getStatements()[0]).getExpression();
|
||||
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) ((IASTDeclarationStatement) compound
|
||||
.getStatements()[0]).getDeclaration();
|
||||
IBinding binding = CPPSemantics.findTypeBinding(compound,
|
||||
((IASTIdExpression) exp.getOperand1()).getName());
|
||||
((ICPPASTNamedTypeSpecifier)decl.getDeclSpecifier()).getName());
|
||||
assertNotNull(binding);
|
||||
assertTrue(binding instanceof ICPPClassType);
|
||||
}
|
||||
|
||||
public void testBug85049() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer( "struct B { };\n" ); //$NON-NLS-1$
|
||||
buffer.append( "void g() {\n" ); //$NON-NLS-1$
|
||||
buffer.append( "B * bp; //1\n" ); //$NON-NLS-1$
|
||||
buffer.append( "}\n" ); //$NON-NLS-1$
|
||||
IASTTranslationUnit t = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
IASTFunctionDefinition g = (IASTFunctionDefinition) t.getDeclarations()[1];
|
||||
IASTCompoundStatement body = (IASTCompoundStatement) g.getBody();
|
||||
assertTrue( body.getStatements()[0] instanceof IASTDeclarationStatement );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -168,9 +168,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
var_y.getScope());
|
||||
|
||||
IVariable var_z = (IVariable) name_z.resolveBinding();
|
||||
assertEquals(
|
||||
((ICFunctionScope) func_f.getFunctionScope()).getBodyScope(), 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());
|
||||
|
@ -233,7 +232,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
buff.append("}"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buff.toString(), ParserLanguage.C);
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
IASTCompositeTypeSpecifier type = (IASTCompositeTypeSpecifier) decl
|
||||
.getDeclSpecifier();
|
||||
|
||||
|
@ -243,7 +243,8 @@ 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()[0];
|
||||
IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) type
|
||||
.getMembers()[0];
|
||||
IASTSimpleDeclSpecifier spec_x = (IASTSimpleDeclSpecifier) decl_x
|
||||
.getDeclSpecifier();
|
||||
// it's an int
|
||||
|
@ -284,7 +285,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTBinaryExpression assexpr = (IASTBinaryExpression) exprstmt
|
||||
.getExpression();
|
||||
// the field reference to myS.x
|
||||
IASTFieldReference fieldref = (IASTFieldReference) assexpr.getOperand1();
|
||||
IASTFieldReference fieldref = (IASTFieldReference) assexpr
|
||||
.getOperand1();
|
||||
// the reference to myS
|
||||
IASTIdExpression ref_myS = (IASTIdExpression) fieldref.getFieldOwner();
|
||||
IASTLiteralExpression lit_5 = (IASTLiteralExpression) assexpr
|
||||
|
@ -350,10 +352,12 @@ public class AST2Tests extends AST2BaseTest {
|
|||
validateSimpleUnaryExpressionC("~x", IASTUnaryExpression.op_tilde); //$NON-NLS-1$
|
||||
validateSimpleUnaryExpressionC("*x", IASTUnaryExpression.op_star); //$NON-NLS-1$
|
||||
validateSimpleUnaryExpressionC("&x", IASTUnaryExpression.op_amper); //$NON-NLS-1$
|
||||
validateSimpleUnaryExpressionC("sizeof x", IASTUnaryExpression.op_sizeof); //$NON-NLS-1$
|
||||
validateSimpleUnaryExpressionC(
|
||||
"sizeof x", IASTUnaryExpression.op_sizeof); //$NON-NLS-1$
|
||||
validateSimpleTypeIdExpressionC(
|
||||
"sizeof( int )", IASTTypeIdExpression.op_sizeof); //$NON-NLS-1$
|
||||
validateSimpleUnaryTypeIdExpression("(int)x", IASTCastExpression.op_cast); //$NON-NLS-1$
|
||||
validateSimpleUnaryTypeIdExpression(
|
||||
"(int)x", IASTCastExpression.op_cast); //$NON-NLS-1$
|
||||
validateSimplePostfixInitializerExpressionC("(int) { 5 }"); //$NON-NLS-1$
|
||||
validateSimplePostfixInitializerExpressionC("(int) { 5, }"); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC("x=y", IASTBinaryExpression.op_assign); //$NON-NLS-1$
|
||||
|
@ -382,29 +386,36 @@ public class AST2Tests extends AST2BaseTest {
|
|||
validateSimpleBinaryExpressionC("x/y", IASTBinaryExpression.op_divide); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC("x*y", IASTBinaryExpression.op_multiply); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC("x%y", IASTBinaryExpression.op_modulo); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC("x<<y", IASTBinaryExpression.op_shiftLeft); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC(
|
||||
"x<<y", IASTBinaryExpression.op_shiftLeft); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC(
|
||||
"x>>y", IASTBinaryExpression.op_shiftRight); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC("x<y", IASTBinaryExpression.op_lessThan); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC(
|
||||
"x>y", IASTBinaryExpression.op_greaterThan); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC("x<=y", IASTBinaryExpression.op_lessEqual); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC(
|
||||
"x<=y", IASTBinaryExpression.op_lessEqual); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC(
|
||||
"x>=y", IASTBinaryExpression.op_greaterEqual); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC("x==y", IASTBinaryExpression.op_equals); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC("x!=y", IASTBinaryExpression.op_notequals); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC("x&y", IASTBinaryExpression.op_binaryAnd); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC("x^y", IASTBinaryExpression.op_binaryXor); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC(
|
||||
"x!=y", IASTBinaryExpression.op_notequals); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC(
|
||||
"x&y", IASTBinaryExpression.op_binaryAnd); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC(
|
||||
"x^y", IASTBinaryExpression.op_binaryXor); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC("x|y", IASTBinaryExpression.op_binaryOr); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC(
|
||||
"x&&y", IASTBinaryExpression.op_logicalAnd); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC("x||y", IASTBinaryExpression.op_logicalOr); //$NON-NLS-1$
|
||||
validateSimpleBinaryExpressionC(
|
||||
"x||y", IASTBinaryExpression.op_logicalOr); //$NON-NLS-1$
|
||||
validateConditionalExpressionC("x ? y : x"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testMultipleDeclarators() throws Exception {
|
||||
IASTTranslationUnit tu = parse("int r, s;", ParserLanguage.C); //$NON-NLS-1$
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
IASTDeclarator[] declarators = decl.getDeclarators();
|
||||
assertEquals(2, declarators.length);
|
||||
|
||||
|
@ -807,10 +818,12 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTName name_param2 = paramDtor.getName();
|
||||
|
||||
// b;
|
||||
IASTCompoundStatement compound = (IASTCompoundStatement) f_defn.getBody();
|
||||
IASTCompoundStatement compound = (IASTCompoundStatement) f_defn
|
||||
.getBody();
|
||||
IASTExpressionStatement expStatement = (IASTExpressionStatement) compound
|
||||
.getStatements()[0];
|
||||
IASTIdExpression idexp = (IASTIdExpression) expStatement.getExpression();
|
||||
IASTIdExpression idexp = (IASTIdExpression) expStatement
|
||||
.getExpression();
|
||||
IASTName name_param3 = idexp.getName();
|
||||
|
||||
//bindings
|
||||
|
@ -998,7 +1011,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTDeclarator dtor = initDecl.getDeclarators()[0];
|
||||
IASTName name_i = dtor.getName();
|
||||
// i < 5;
|
||||
IASTBinaryExpression exp = (IASTBinaryExpression) for_stmt.getCondition();
|
||||
IASTBinaryExpression exp = (IASTBinaryExpression) for_stmt
|
||||
.getCondition();
|
||||
IASTIdExpression id_i = (IASTIdExpression) exp.getOperand1();
|
||||
IASTName name_i2 = id_i.getName();
|
||||
IASTLiteralExpression lit_5 = (IASTLiteralExpression) exp.getOperand2();
|
||||
|
@ -1082,8 +1096,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertSame(x1, x2);
|
||||
|
||||
// test tu.getDeclarations(IBinding)
|
||||
IASTName[] decls = tu
|
||||
.getDeclarations(compType.getName().resolveBinding());
|
||||
IASTName[] decls = tu.getDeclarations(compType.getName()
|
||||
.resolveBinding());
|
||||
assertEquals(decls.length, 1);
|
||||
assertEquals(decls[0], compType.getName());
|
||||
|
||||
|
@ -1164,7 +1178,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
.getDeclarators()[0]).getParameters()[0].getDeclSpecifier())
|
||||
.getName();
|
||||
IASTName name_x = ((IASTStandardFunctionDeclarator) decl2
|
||||
.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
|
||||
.getDeclarators()[0]).getParameters()[0].getDeclarator()
|
||||
.getName();
|
||||
|
||||
IASTName[] decls = tu.getDeclarations(name_X1.resolveBinding());
|
||||
assertEquals(decls.length, 1);
|
||||
|
@ -1230,7 +1245,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(spec.getKind(), IASTElaboratedTypeSpecifier.k_enum);
|
||||
IASTName name_hue2 = spec.getName();
|
||||
|
||||
IASTFunctionDefinition fn = (IASTFunctionDefinition) tu.getDeclarations()[2];
|
||||
IASTFunctionDefinition fn = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[2];
|
||||
IASTCompoundStatement compound = (IASTCompoundStatement) fn.getBody();
|
||||
IASTExpressionStatement expStatement1 = (IASTExpressionStatement) compound
|
||||
.getStatements()[0];
|
||||
|
@ -1252,7 +1268,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTName r_cp = id1.getName();
|
||||
IASTName r_col2 = id2.getName();
|
||||
|
||||
IASTIfStatement ifStatement = (IASTIfStatement) compound.getStatements()[2];
|
||||
IASTIfStatement ifStatement = (IASTIfStatement) compound
|
||||
.getStatements()[2];
|
||||
exp = (IASTBinaryExpression) ifStatement.getCondition();
|
||||
ue = (IASTUnaryExpression) exp.getOperand1();
|
||||
id1 = (IASTIdExpression) ue.getOperand();
|
||||
|
@ -1318,7 +1335,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(decls.length, 1);
|
||||
assertEquals(decls[0], name_cp);
|
||||
|
||||
decls = tu.getDeclarations(fn.getDeclarator().getName().resolveBinding());
|
||||
decls = tu.getDeclarations(fn.getDeclarator().getName()
|
||||
.resolveBinding());
|
||||
assertEquals(decls.length, 1);
|
||||
assertEquals(decls[0], fn.getDeclarator().getName());
|
||||
|
||||
|
@ -1385,7 +1403,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
buffer.append("int X:: * pmi = &X::a;\n"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
assertEquals(tu.getDeclarations().length, 2);
|
||||
IASTSimpleDeclaration p2m = (IASTSimpleDeclaration) tu.getDeclarations()[1];
|
||||
IASTSimpleDeclaration p2m = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[1];
|
||||
IASTDeclarator d = p2m.getDeclarators()[0];
|
||||
ICPPASTPointerToMember po = (ICPPASTPointerToMember) d
|
||||
.getPointerOperators()[0];
|
||||
|
@ -1401,7 +1420,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
buffer.append("}"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
IASTSimpleDeclaration A = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[1];
|
||||
IASTFunctionDefinition f = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[1];
|
||||
IASTCompoundStatement body = (IASTCompoundStatement) f.getBody();
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
IASTDeclarationStatement ds = (IASTDeclarationStatement) body
|
||||
|
@ -1426,7 +1446,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
IVariable a = (IVariable) decl.getDeclarators()[0].getName()
|
||||
.resolveBinding();
|
||||
decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
|
||||
|
@ -1526,7 +1547,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
IASTCompositeTypeSpecifier compSpec = (IASTCompositeTypeSpecifier) decl
|
||||
.getDeclSpecifier();
|
||||
ICompositeType A = (ICompositeType) compSpec.getName().resolveBinding();
|
||||
|
@ -1534,14 +1556,14 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IVariable a1 = (IVariable) decl.getDeclarators()[0].getName()
|
||||
.resolveBinding();
|
||||
decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
|
||||
IASTName name_A2 = ((IASTElaboratedTypeSpecifier) decl.getDeclSpecifier())
|
||||
.getName();
|
||||
IASTName name_A2 = ((IASTElaboratedTypeSpecifier) decl
|
||||
.getDeclSpecifier()).getName();
|
||||
IASTName name_AP = decl.getDeclarators()[0].getName();
|
||||
ITypedef AP = (ITypedef) decl.getDeclarators()[0].getName()
|
||||
.resolveBinding();
|
||||
decl = (IASTSimpleDeclaration) tu.getDeclarations()[2];
|
||||
IASTName name_A3 = ((IASTElaboratedTypeSpecifier) decl.getDeclSpecifier())
|
||||
.getName();
|
||||
IASTName name_A3 = ((IASTElaboratedTypeSpecifier) decl
|
||||
.getDeclSpecifier()).getName();
|
||||
IVariable a2 = (IVariable) decl.getDeclarators()[0].getName()
|
||||
.resolveBinding();
|
||||
IASTName name_a2 = decl.getDeclarators()[0].getName();
|
||||
|
@ -1567,8 +1589,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertSame(((IPointerType) t_AP).getType(), A);
|
||||
|
||||
// test tu.getDeclarations(IBinding)
|
||||
IASTName[] decls = tu
|
||||
.getDeclarations(compSpec.getName().resolveBinding());
|
||||
IASTName[] decls = tu.getDeclarations(compSpec.getName()
|
||||
.resolveBinding());
|
||||
assertEquals(decls.length, 1);
|
||||
assertEquals(decls[0], compSpec.getName());
|
||||
|
||||
|
@ -1609,7 +1631,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
IASTName name_a = decl.getDeclarators()[0].getName();
|
||||
IVariable a = (IVariable) decl.getDeclarators()[0].getName()
|
||||
.resolveBinding();
|
||||
|
@ -1678,7 +1701,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
IASTElaboratedTypeSpecifier elabSpec = (IASTElaboratedTypeSpecifier) decl
|
||||
.getDeclSpecifier();
|
||||
ICompositeType A = (ICompositeType) elabSpec.getName().resolveBinding();
|
||||
|
@ -1688,14 +1712,16 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IFunction f = (IFunction) decl.getDeclarators()[0].getName()
|
||||
.resolveBinding();
|
||||
IASTName name_f = decl.getDeclarators()[0].getName();
|
||||
IASTName name_i = ((IASTStandardFunctionDeclarator) decl.getDeclarators()[0])
|
||||
.getParameters()[0].getDeclarator().getName();
|
||||
IASTName name_c = ((IASTStandardFunctionDeclarator) decl.getDeclarators()[0])
|
||||
.getParameters()[1].getDeclarator().getName();
|
||||
IASTName name_i = ((IASTStandardFunctionDeclarator) decl
|
||||
.getDeclarators()[0]).getParameters()[0].getDeclarator()
|
||||
.getName();
|
||||
IASTName name_c = ((IASTStandardFunctionDeclarator) decl
|
||||
.getDeclarators()[0]).getParameters()[1].getDeclarator()
|
||||
.getName();
|
||||
|
||||
decl = (IASTSimpleDeclaration) tu.getDeclarations()[2];
|
||||
IVariable g = (IVariable) decl.getDeclarators()[0].getNestedDeclarator()
|
||||
.getName().resolveBinding();
|
||||
IVariable g = (IVariable) decl.getDeclarators()[0]
|
||||
.getNestedDeclarator().getName().resolveBinding();
|
||||
IASTName name_g = decl.getDeclarators()[0].getNestedDeclarator()
|
||||
.getName();
|
||||
IASTName name_A2 = ((IASTElaboratedTypeSpecifier) ((IASTStandardFunctionDeclarator) decl
|
||||
|
@ -1703,15 +1729,17 @@ public class AST2Tests extends AST2BaseTest {
|
|||
.getName();
|
||||
|
||||
decl = (IASTSimpleDeclaration) tu.getDeclarations()[3];
|
||||
IVariable h = (IVariable) decl.getDeclarators()[0].getNestedDeclarator()
|
||||
.getNestedDeclarator().getName().resolveBinding();
|
||||
IVariable h = (IVariable) decl.getDeclarators()[0]
|
||||
.getNestedDeclarator().getNestedDeclarator().getName()
|
||||
.resolveBinding();
|
||||
IASTName name_h = decl.getDeclarators()[0].getNestedDeclarator()
|
||||
.getNestedDeclarator().getName();
|
||||
IASTName name_A3 = ((IASTElaboratedTypeSpecifier) ((IASTStandardFunctionDeclarator) decl
|
||||
.getDeclarators()[0].getNestedDeclarator()).getParameters()[0]
|
||||
.getDeclSpecifier()).getName();
|
||||
IASTName name_d = ((IASTStandardFunctionDeclarator) decl.getDeclarators()[0])
|
||||
.getParameters()[0].getDeclarator().getName();
|
||||
IASTName name_d = ((IASTStandardFunctionDeclarator) decl
|
||||
.getDeclarators()[0]).getParameters()[0].getDeclarator()
|
||||
.getName();
|
||||
|
||||
IFunctionType t_f = f.getType();
|
||||
IType t_f_return = t_f.getReturnType();
|
||||
|
@ -1737,7 +1765,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertSame(((IPointerType) t_g_func_p1).getType(), A);
|
||||
|
||||
//h is a pointer to a function that returns a pointer to a function
|
||||
//the returned pointer to function returns void and takes 1 parameter int
|
||||
//the returned pointer to function returns void and takes 1 parameter
|
||||
// int
|
||||
// the *h function takes 1 parameter struct A**
|
||||
IType t_h = h.getType();
|
||||
assertTrue(t_h instanceof IPointerType);
|
||||
|
@ -1817,15 +1846,19 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTName name_Coord = ((IASTSimpleDeclaration) declarations[0])
|
||||
.getDeclarators()[0].getName();
|
||||
IASTName name_x = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) declarations[0])
|
||||
.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0].getName();
|
||||
.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0]
|
||||
.getName();
|
||||
IASTName name_y = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) declarations[0])
|
||||
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0].getName();
|
||||
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0]
|
||||
.getName();
|
||||
IASTName name_Point = ((IASTSimpleDeclaration) declarations[1])
|
||||
.getDeclarators()[0].getName();
|
||||
IASTName name_pos = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) declarations[1])
|
||||
.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0].getName();
|
||||
.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0]
|
||||
.getName();
|
||||
IASTName name_width = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) declarations[1])
|
||||
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0].getName();
|
||||
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0]
|
||||
.getName();
|
||||
IASTFunctionDefinition main = (IASTFunctionDefinition) declarations[2];
|
||||
IASTStatement[] statements = ((IASTCompoundStatement) main.getBody())
|
||||
.getStatements();
|
||||
|
@ -1845,8 +1878,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTSimpleDeclaration point = (IASTSimpleDeclaration) ((IASTDeclarationStatement) statements[1])
|
||||
.getDeclaration();
|
||||
IASTName name_Point2 = ((IASTNamedTypeSpecifier) point.getDeclSpecifier())
|
||||
.getName();
|
||||
IASTName name_Point2 = ((IASTNamedTypeSpecifier) point
|
||||
.getDeclSpecifier()).getName();
|
||||
IASTName name_point = point.getDeclarators()[0].getName();
|
||||
IASTDeclarator declarator_point = point.getDeclarators()[0];
|
||||
IASTInitializer[] initializers2 = ((IASTInitializerList) declarator_point
|
||||
|
@ -1856,7 +1889,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTName name_pos2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers2[1])
|
||||
.getDesignators()[0]).getName();
|
||||
IASTName name_xy2 = ((IASTIdExpression) ((IASTUnaryExpression) ((IASTInitializerExpression) ((ICASTDesignatedInitializer) initializers2[1])
|
||||
.getOperandInitializer()).getExpression()).getOperand()).getName();
|
||||
.getOperandInitializer()).getExpression()).getOperand())
|
||||
.getName();
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
ICASTDesignatedInitializer designatedInitializer = (ICASTDesignatedInitializer) initializers1[i];
|
||||
|
@ -1920,17 +1954,19 @@ public class AST2Tests extends AST2BaseTest {
|
|||
.getDeclarations()[1];
|
||||
|
||||
IASTName a1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl
|
||||
.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0].getName();
|
||||
.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0]
|
||||
.getName();
|
||||
IASTName b1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl
|
||||
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0].getName();
|
||||
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0]
|
||||
.getName();
|
||||
IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) ((IASTSimpleDeclaration) ((IASTDeclarationStatement) ((IASTCompoundStatement) f_def
|
||||
.getBody()).getStatements()[0]).getDeclaration()).getDeclarators()[0]
|
||||
.getInitializer()).getInitializers()[0]).getDesignators()[0])
|
||||
.getName();
|
||||
.getBody()).getStatements()[0]).getDeclaration())
|
||||
.getDeclarators()[0].getInitializer()).getInitializers()[0])
|
||||
.getDesignators()[0]).getName();
|
||||
IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) ((IASTSimpleDeclaration) ((IASTDeclarationStatement) ((IASTCompoundStatement) f_def
|
||||
.getBody()).getStatements()[0]).getDeclaration()).getDeclarators()[0]
|
||||
.getInitializer()).getInitializers()[1]).getDesignators()[0])
|
||||
.getName();
|
||||
.getBody()).getStatements()[0]).getDeclaration())
|
||||
.getDeclarators()[0].getInitializer()).getInitializers()[1])
|
||||
.getDesignators()[0]).getName();
|
||||
|
||||
assertEquals(a1.resolveBinding(), a2.resolveBinding());
|
||||
assertEquals(b1.resolveBinding(), b2.resolveBinding());
|
||||
|
@ -1956,9 +1992,11 @@ public class AST2Tests extends AST2BaseTest {
|
|||
.getDeclarations()[0];
|
||||
|
||||
IASTName a1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl
|
||||
.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0].getName();
|
||||
.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0]
|
||||
.getName();
|
||||
IASTName b1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl
|
||||
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0].getName();
|
||||
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0]
|
||||
.getName();
|
||||
IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) S_decl
|
||||
.getDeclarators()[0].getInitializer()).getInitializers()[0])
|
||||
.getDesignators()[0]).getName();
|
||||
|
@ -1995,9 +2033,11 @@ public class AST2Tests extends AST2BaseTest {
|
|||
.getDeclarations()[3];
|
||||
|
||||
IASTName a1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl
|
||||
.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0].getName();
|
||||
.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0]
|
||||
.getName();
|
||||
IASTName b1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl
|
||||
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0].getName();
|
||||
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0]
|
||||
.getName();
|
||||
IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) x_decl
|
||||
.getDeclarators()[0].getInitializer()).getInitializers()[0])
|
||||
.getDesignators()[0]).getName();
|
||||
|
@ -2048,7 +2088,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTTranslationUnit tu = parse(
|
||||
"void f(int parm[const 3]);", ParserLanguage.C); //$NON-NLS-1$
|
||||
|
||||
IASTSimpleDeclaration def = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTSimpleDeclaration def = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
IFunction f = (IFunction) def.getDeclarators()[0].getName()
|
||||
.resolveBinding();
|
||||
|
||||
|
@ -2058,7 +2099,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
// test tu.getDeclarations(IBinding)
|
||||
IASTName name_parm = ((IASTStandardFunctionDeclarator) def
|
||||
.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
|
||||
.getDeclarators()[0]).getParameters()[0].getDeclarator()
|
||||
.getName();
|
||||
IASTName[] decls = tu.getDeclarations(name_parm.resolveBinding());
|
||||
assertEquals(decls.length, 1);
|
||||
assertEquals(decls[0], name_parm);
|
||||
|
@ -2072,7 +2114,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTFunctionDefinition def1 = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[0];
|
||||
IFunction f = (IFunction) def1.getDeclarator().getName().resolveBinding();
|
||||
IFunction f = (IFunction) def1.getDeclarator().getName()
|
||||
.resolveBinding();
|
||||
IASTFunctionDefinition def2 = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[1];
|
||||
IFunction f2 = (IFunction) def2.getDeclarator().getName()
|
||||
|
@ -2105,10 +2148,11 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(decls.length, 1);
|
||||
assertEquals(decls[0], def2.getDeclarator().getName());
|
||||
|
||||
decls = tu.getDeclarations(def3.getDeclarator().getNestedDeclarator().getName()
|
||||
.resolveBinding());
|
||||
decls = tu.getDeclarations(def3.getDeclarator().getNestedDeclarator()
|
||||
.getName().resolveBinding());
|
||||
assertEquals(decls.length, 1);
|
||||
assertEquals(decls[0], def3.getDeclarator().getNestedDeclarator().getName());
|
||||
assertEquals(decls[0], def3.getDeclarator().getNestedDeclarator()
|
||||
.getName());
|
||||
}
|
||||
|
||||
// any parameter to type function returning T is adjusted to be pointer to
|
||||
|
@ -2119,7 +2163,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTFunctionDefinition def = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[0];
|
||||
IFunction f = (IFunction) def.getDeclarator().getName().resolveBinding();
|
||||
IFunction f = (IFunction) def.getDeclarator().getName()
|
||||
.resolveBinding();
|
||||
|
||||
IType ft = ((CFunction) f).getType();
|
||||
assertTrue(ft instanceof IFunctionType);
|
||||
|
@ -2150,7 +2195,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTTranslationUnit tu = parse(
|
||||
"int (*v[])(int *x, int *y);", ParserLanguage.C); //$NON-NLS-1$
|
||||
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
IVariable v = (IVariable) ((IASTStandardFunctionDeclarator) decl
|
||||
.getDeclarators()[0]).getNestedDeclarator().getName()
|
||||
.resolveBinding();
|
||||
|
@ -2258,8 +2304,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu
|
||||
.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();
|
||||
assertTrue(pfv_t_1 instanceof IPointerType);
|
||||
IType pfv_t_2 = ((IPointerType) pfv_t_1).getType();
|
||||
|
@ -2289,7 +2335,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertTrue(signal_ret_ret_1 instanceof ITypedef);
|
||||
IType signal_ret_ret_2 = ((ITypedef) signal_ret_ret_1).getType();
|
||||
assertTrue(signal_ret_ret_2 instanceof IBasicType);
|
||||
assertEquals(((IBasicType) signal_ret_ret_2).getType(), IBasicType.t_void);
|
||||
assertEquals(((IBasicType) signal_ret_ret_2).getType(),
|
||||
IBasicType.t_void);
|
||||
assertTrue(((ITypedef) signal_ret_ret_1).getName().equals("DWORD")); //$NON-NLS-1$
|
||||
|
||||
IType signal_parm_t1 = signal_t.getParameterTypes()[0];
|
||||
|
@ -2304,7 +2351,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IType signal_parm_t2_ret_1 = ((IFunctionType) signal_parm_t2_2)
|
||||
.getReturnType();
|
||||
assertTrue(signal_parm_t2_ret_1 instanceof ITypedef);
|
||||
IType signal_parm_t2_ret_2 = ((ITypedef) signal_parm_t2_ret_1).getType();
|
||||
IType signal_parm_t2_ret_2 = ((ITypedef) signal_parm_t2_ret_1)
|
||||
.getType();
|
||||
assertTrue(signal_parm_t2_ret_2 instanceof IBasicType);
|
||||
assertEquals(((IBasicType) signal_parm_t2_ret_2).getType(),
|
||||
IBasicType.t_void);
|
||||
|
@ -2336,24 +2384,25 @@ public class AST2Tests extends AST2BaseTest {
|
|||
buffer.append("pfv signal3(int, pfv);\n"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
ITypedef fv = (ITypedef) decl.getDeclarators()[0].getName()
|
||||
.resolveBinding();
|
||||
ITypedef pfv = (ITypedef) decl.getDeclarators()[1].getNestedDeclarator()
|
||||
.getName().resolveBinding();
|
||||
ITypedef pfv = (ITypedef) decl.getDeclarators()[1]
|
||||
.getNestedDeclarator().getName().resolveBinding();
|
||||
|
||||
IType fv_t = fv.getType();
|
||||
assertEquals(((IBasicType) ((IFunctionType) fv_t).getReturnType())
|
||||
.getType(), IBasicType.t_void);
|
||||
assertEquals(((IBasicType) ((IFunctionType) fv_t).getParameterTypes()[0])
|
||||
assertEquals(
|
||||
((IBasicType) ((IFunctionType) fv_t).getParameterTypes()[0])
|
||||
.getType(), IBasicType.t_int);
|
||||
|
||||
IType pfv_t = pfv.getType();
|
||||
assertEquals(((IBasicType) ((IFunctionType) ((IPointerType) pfv_t)
|
||||
.getType()).getReturnType()).getType(), IBasicType.t_void);
|
||||
assertEquals(
|
||||
((IBasicType) ((IFunctionType) ((IPointerType) pfv.getType())
|
||||
.getType()).getParameterTypes()[0]).getType(),
|
||||
assertEquals(((IBasicType) ((IFunctionType) ((IPointerType) pfv
|
||||
.getType()).getType()).getParameterTypes()[0]).getType(),
|
||||
IBasicType.t_int);
|
||||
|
||||
decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
|
||||
|
@ -2540,23 +2589,30 @@ public class AST2Tests extends AST2BaseTest {
|
|||
buffer.append("else if( a > 0 )\n"); //$NON-NLS-1$
|
||||
buffer.append("g( *(&a + 2) );\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
|
||||
IASTIfStatement if_statement = (IASTIfStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition)tu.getDeclarations()[0]).getBody()).getStatements()[0];
|
||||
assertEquals( ((IASTBinaryExpression)if_statement.getCondition()).getOperator(), IASTBinaryExpression.op_equals );
|
||||
IASTIfStatement second_if_statement = (IASTIfStatement) if_statement.getElseClause();
|
||||
assertEquals( ((IASTBinaryExpression)second_if_statement.getCondition()).getOperator(), IASTBinaryExpression.op_lessThan );
|
||||
IASTIfStatement third_if_statement = (IASTIfStatement) second_if_statement.getElseClause();
|
||||
assertEquals( ((IASTBinaryExpression)third_if_statement.getCondition()).getOperator(), IASTBinaryExpression.op_greaterThan );
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
IASTIfStatement if_statement = (IASTIfStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) tu
|
||||
.getDeclarations()[0]).getBody()).getStatements()[0];
|
||||
assertEquals(((IASTBinaryExpression) if_statement.getCondition())
|
||||
.getOperator(), IASTBinaryExpression.op_equals);
|
||||
IASTIfStatement second_if_statement = (IASTIfStatement) if_statement
|
||||
.getElseClause();
|
||||
assertEquals(
|
||||
((IASTBinaryExpression) second_if_statement.getCondition())
|
||||
.getOperator(), IASTBinaryExpression.op_lessThan);
|
||||
IASTIfStatement third_if_statement = (IASTIfStatement) second_if_statement
|
||||
.getElseClause();
|
||||
assertEquals(((IASTBinaryExpression) third_if_statement.getCondition())
|
||||
.getOperator(), IASTBinaryExpression.op_greaterThan);
|
||||
}
|
||||
|
||||
public void testBug84090_LabelReferences() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "void f() { \n"); //$NON-NLS-1$
|
||||
buffer.append( " while(1){ \n"); //$NON-NLS-1$
|
||||
buffer.append( " if( 1 ) goto end; \n"); //$NON-NLS-1$
|
||||
buffer.append( " } \n"); //$NON-NLS-1$
|
||||
buffer.append( " end: ; \n"); //$NON-NLS-1$
|
||||
buffer.append( "} \n"); //$NON-NLS-1$
|
||||
buffer.append("void f() { \n"); //$NON-NLS-1$
|
||||
buffer.append(" while(1){ \n"); //$NON-NLS-1$
|
||||
buffer.append(" if( 1 ) goto end; \n"); //$NON-NLS-1$
|
||||
buffer.append(" } \n"); //$NON-NLS-1$
|
||||
buffer.append(" end: ; \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
|
@ -2565,9 +2621,9 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(col.size(), 3);
|
||||
ILabel end = (ILabel) col.getName(1).resolveBinding();
|
||||
|
||||
IASTName [] refs = tu.getReferences( end );
|
||||
assertEquals( refs.length, 1 );
|
||||
assertSame( refs[0].resolveBinding(), end );
|
||||
IASTName[] refs = tu.getReferences(end);
|
||||
assertEquals(refs.length, 1);
|
||||
assertSame(refs[0].resolveBinding(), end);
|
||||
}
|
||||
|
||||
public void testBug84092_EnumReferences() throws Exception {
|
||||
|
@ -2582,36 +2638,38 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(collector.size(), 5);
|
||||
IEnumeration col = (IEnumeration) collector.getName(0).resolveBinding();
|
||||
|
||||
IASTName [] refs = tu.getReferences( col );
|
||||
assertEquals( refs.length, 1 );
|
||||
assertSame( refs[0].resolveBinding(), col );
|
||||
IASTName[] refs = tu.getReferences(col);
|
||||
assertEquals(refs.length, 1);
|
||||
assertSame(refs[0].resolveBinding(), col);
|
||||
}
|
||||
|
||||
public void testBug84096_FieldDesignatorRef() throws Exception {
|
||||
IASTTranslationUnit tu = parse("struct s { int a; } ss = { .a = 1 }; \n", ParserLanguage.C); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(
|
||||
"struct s { int a; } ss = { .a = 1 }; \n", ParserLanguage.C); //$NON-NLS-1$
|
||||
CNameCollector collector = new CNameCollector();
|
||||
CVisitor.visitTranslationUnit(tu, collector);
|
||||
|
||||
assertEquals(collector.size(), 4);
|
||||
IField a = (IField) collector.getName(1).resolveBinding();
|
||||
|
||||
IASTName [] refs = tu.getReferences( a );
|
||||
assertEquals( refs.length, 1 );
|
||||
assertSame( refs[0].resolveBinding(), a );
|
||||
IASTName[] refs = tu.getReferences(a);
|
||||
assertEquals(refs.length, 1);
|
||||
assertSame(refs[0].resolveBinding(), a);
|
||||
}
|
||||
|
||||
public void testProblems() throws Exception {
|
||||
|
||||
IASTTranslationUnit tu = parse( " a += ;", ParserLanguage.C, true, false ); //$NON-NLS-1$
|
||||
IASTProblem [] ps = CVisitor.getProblems( tu );
|
||||
assertEquals( ps.length, 1 );
|
||||
IASTTranslationUnit tu = parse(
|
||||
" a += ;", ParserLanguage.C, true, false); //$NON-NLS-1$
|
||||
IASTProblem[] ps = CVisitor.getProblems(tu);
|
||||
assertEquals(ps.length, 1);
|
||||
ps[0].getMessage();
|
||||
}
|
||||
|
||||
public void testEnumerationForwards() throws Exception{
|
||||
public void testEnumerationForwards() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "enum e; \n;" ); //$NON-NLS-1$
|
||||
buffer.append( "enum e{ one }; \n;" ); //$NON-NLS-1$
|
||||
buffer.append("enum e; \n;"); //$NON-NLS-1$
|
||||
buffer.append("enum e{ one }; \n;"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
|
@ -2620,13 +2678,13 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(col.size(), 3);
|
||||
IEnumeration e = (IEnumeration) col.getName(0).resolveBinding();
|
||||
IEnumerator[] etors = e.getEnumerators();
|
||||
assertTrue( etors.length == 1 );
|
||||
assertFalse( etors[0] instanceof IProblemBinding );
|
||||
assertTrue(etors.length == 1);
|
||||
assertFalse(etors[0] instanceof IProblemBinding);
|
||||
|
||||
assertInstances( col, e, 2 );
|
||||
assertInstances(col, e, 2);
|
||||
}
|
||||
|
||||
public void testBug84185() throws Exception{
|
||||
public void testBug84185() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("void f() { \n"); //$NON-NLS-1$
|
||||
buffer.append(" int ( *p ) [2]; \n"); //$NON-NLS-1$
|
||||
|
@ -2639,14 +2697,15 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
assertEquals(col.size(), 3);
|
||||
IVariable p = (IVariable) col.getName(1).resolveBinding();
|
||||
assertTrue( p.getType() instanceof IPointerType );
|
||||
assertTrue( ((IPointerType)p.getType()).getType() instanceof IArrayType );
|
||||
IArrayType at = (IArrayType) ((IPointerType)p.getType()).getType();
|
||||
assertTrue( at.getType() instanceof IBasicType );
|
||||
assertTrue(p.getType() instanceof IPointerType);
|
||||
assertTrue(((IPointerType) p.getType()).getType() instanceof IArrayType);
|
||||
IArrayType at = (IArrayType) ((IPointerType) p.getType()).getType();
|
||||
assertTrue(at.getType() instanceof IBasicType);
|
||||
|
||||
assertInstances( col, p, 2 );
|
||||
assertInstances(col, p, 2);
|
||||
}
|
||||
public void testBug84185_2() throws Exception{
|
||||
|
||||
public void testBug84185_2() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("void f() { \n"); //$NON-NLS-1$
|
||||
buffer.append(" int ( *p ) [2]; \n"); //$NON-NLS-1$
|
||||
|
@ -2662,12 +2721,13 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IVariable p_ref = (IVariable) col.getName(2).resolveBinding();
|
||||
IVariable p_decl = (IVariable) col.getName(1).resolveBinding();
|
||||
|
||||
assertSame( p_ref, p_decl );
|
||||
assertSame(p_ref, p_decl);
|
||||
}
|
||||
|
||||
public void testBug84176() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer( "// example from: C99 6.5.2.5-16\n" ); //$NON-NLS-1$
|
||||
buffer.append( "struct s { int i; };\n"); //$NON-NLS-1$
|
||||
StringBuffer buffer = new StringBuffer(
|
||||
"// example from: C99 6.5.2.5-16\n"); //$NON-NLS-1$
|
||||
buffer.append("struct s { int i; };\n"); //$NON-NLS-1$
|
||||
buffer.append("void f (void)\n"); //$NON-NLS-1$
|
||||
buffer.append("{\n"); //$NON-NLS-1$
|
||||
buffer.append(" struct s *p = 0, *q;\n"); //$NON-NLS-1$
|
||||
|
@ -2675,13 +2735,13 @@ public class AST2Tests extends AST2BaseTest {
|
|||
buffer.append("q = p;\n"); //$NON-NLS-1$
|
||||
buffer.append("p = &((struct s){ j++ }); \n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
parse( buffer.toString(), ParserLanguage.C );
|
||||
parse(buffer.toString(), ParserLanguage.C);
|
||||
}
|
||||
|
||||
public void testBug84266() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "struct s { double i; } f(void); \n"); //$NON-NLS-1$
|
||||
buffer.append( "struct s f(void){} \n"); //$NON-NLS-1$
|
||||
buffer.append("struct s { double i; } f(void); \n"); //$NON-NLS-1$
|
||||
buffer.append("struct s f(void){} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
|
@ -2690,15 +2750,16 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(col.size(), 7);
|
||||
|
||||
ICompositeType s_ref = (ICompositeType) col.getName(4).resolveBinding();
|
||||
ICompositeType s_decl = (ICompositeType) col.getName(0).resolveBinding();
|
||||
ICompositeType s_decl = (ICompositeType) col.getName(0)
|
||||
.resolveBinding();
|
||||
|
||||
assertSame( s_ref, s_decl );
|
||||
CVisitor.clearBindings( tu );
|
||||
assertSame(s_ref, s_decl);
|
||||
CVisitor.clearBindings(tu);
|
||||
|
||||
s_decl = (ICompositeType) col.getName(0).resolveBinding();
|
||||
s_ref = (ICompositeType) col.getName(4).resolveBinding();
|
||||
|
||||
assertSame( s_ref, s_decl );
|
||||
assertSame(s_ref, s_decl);
|
||||
}
|
||||
|
||||
public void testBug84266_2() throws Exception {
|
||||
|
@ -2709,7 +2770,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(col.size(), 3);
|
||||
|
||||
ICompositeType s = (ICompositeType) col.getName(0).resolveBinding();
|
||||
assertNotNull( s );
|
||||
assertNotNull(s);
|
||||
|
||||
tu = parse("struct s f(void){}", ParserLanguage.C); //$NON-NLS-1$
|
||||
col = new CNameCollector();
|
||||
|
@ -2718,17 +2779,18 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(col.size(), 3);
|
||||
|
||||
s = (ICompositeType) col.getName(0).resolveBinding();
|
||||
assertNotNull( s );
|
||||
assertNotNull(s);
|
||||
}
|
||||
|
||||
public void testBug84250() throws Exception {
|
||||
assertTrue( ((IASTDeclarationStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) parse( "void f() { int (*p) [2]; }", ParserLanguage.C ).getDeclarations()[0]).getBody()).getStatements()[0]).getDeclaration() instanceof IASTSimpleDeclaration ); //$NON-NLS-1$
|
||||
assertTrue(((IASTDeclarationStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) parse(
|
||||
"void f() { int (*p) [2]; }", ParserLanguage.C).getDeclarations()[0]).getBody()).getStatements()[0]).getDeclaration() instanceof IASTSimpleDeclaration); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testBug84186() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "struct s1 { struct s2 *s2p; /* ... */ }; // D1 \n"); //$NON-NLS-1$
|
||||
buffer.append( "struct s2 { struct s1 *s1p; /* ... */ }; // D2 \n"); //$NON-NLS-1$
|
||||
buffer.append("struct s1 { struct s2 *s2p; /* ... */ }; // D1 \n"); //$NON-NLS-1$
|
||||
buffer.append("struct s2 { struct s1 *s1p; /* ... */ }; // D2 \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
|
@ -2737,24 +2799,25 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(col.size(), 6);
|
||||
|
||||
ICompositeType s_ref = (ICompositeType) col.getName(1).resolveBinding();
|
||||
ICompositeType s_decl = (ICompositeType) col.getName(3).resolveBinding();
|
||||
ICompositeType s_decl = (ICompositeType) col.getName(3)
|
||||
.resolveBinding();
|
||||
|
||||
assertSame( s_ref, s_decl );
|
||||
CVisitor.clearBindings( tu );
|
||||
assertSame(s_ref, s_decl);
|
||||
CVisitor.clearBindings(tu);
|
||||
|
||||
s_decl = (ICompositeType) col.getName(3).resolveBinding();
|
||||
s_ref = (ICompositeType) col.getName(1).resolveBinding();
|
||||
|
||||
assertSame( s_ref, s_decl );
|
||||
assertSame(s_ref, s_decl);
|
||||
}
|
||||
|
||||
public void testBug84267() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "typedef struct { int a; } S; \n"); //$NON-NLS-1$
|
||||
buffer.append( "void g( S* (*funcp) (void) ) { \n"); //$NON-NLS-1$
|
||||
buffer.append( " (*funcp)()->a; \n"); //$NON-NLS-1$
|
||||
buffer.append( " funcp()->a; \n"); //$NON-NLS-1$
|
||||
buffer.append( "} \n"); //$NON-NLS-1$
|
||||
buffer.append("typedef struct { int a; } S; \n"); //$NON-NLS-1$
|
||||
buffer.append("void g( S* (*funcp) (void) ) { \n"); //$NON-NLS-1$
|
||||
buffer.append(" (*funcp)()->a; \n"); //$NON-NLS-1$
|
||||
buffer.append(" funcp()->a; \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
|
@ -2763,27 +2826,27 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(col.size(), 11);
|
||||
|
||||
ITypedef S = (ITypedef) col.getName(2).resolveBinding();
|
||||
IField a = (IField) col.getName( 10 ).resolveBinding();
|
||||
IField a = (IField) col.getName(10).resolveBinding();
|
||||
IParameter funcp = (IParameter) col.getName(7).resolveBinding();
|
||||
assertNotNull( funcp );
|
||||
assertInstances( col, funcp, 3 );
|
||||
assertInstances( col, a, 3 );
|
||||
assertNotNull(funcp);
|
||||
assertInstances(col, funcp, 3);
|
||||
assertInstances(col, a, 3);
|
||||
|
||||
assertTrue( funcp.getType() instanceof IPointerType );
|
||||
assertTrue(funcp.getType() instanceof IPointerType);
|
||||
IType t = ((IPointerType) funcp.getType()).getType();
|
||||
assertTrue( t instanceof IFunctionType );
|
||||
assertTrue(t instanceof IFunctionType);
|
||||
IFunctionType ft = (IFunctionType) t;
|
||||
assertTrue( ft.getReturnType() instanceof IPointerType );
|
||||
assertSame( ((IPointerType)ft.getReturnType()).getType(), S );
|
||||
assertTrue(ft.getReturnType() instanceof IPointerType);
|
||||
assertSame(((IPointerType) ft.getReturnType()).getType(), S);
|
||||
}
|
||||
|
||||
public void testBug84228() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "void f( int m, int c[m][m] ); \n" ); //$NON-NLS-1$
|
||||
buffer.append( "void f( int m, int c[m][m] ){ \n" ); //$NON-NLS-1$
|
||||
buffer.append( " int x; \n" ); //$NON-NLS-1$
|
||||
buffer.append( " { int x = x; } \n" ); //$NON-NLS-1$
|
||||
buffer.append( "} \n" ); //$NON-NLS-1$
|
||||
buffer.append("void f( int m, int c[m][m] ); \n"); //$NON-NLS-1$
|
||||
buffer.append("void f( int m, int c[m][m] ){ \n"); //$NON-NLS-1$
|
||||
buffer.append(" int x; \n"); //$NON-NLS-1$
|
||||
buffer.append(" { int x = x; } \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
|
@ -2796,43 +2859,44 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IVariable x2 = (IVariable) col.getName(11).resolveBinding();
|
||||
IVariable x1 = (IVariable) col.getName(10).resolveBinding();
|
||||
|
||||
assertSame( x2, x3 );
|
||||
assertNotSame( x1, x2 );
|
||||
assertSame(x2, x3);
|
||||
assertNotSame(x1, x2);
|
||||
|
||||
assertInstances( col, m, 6 );
|
||||
assertInstances( col, x1, 1 );
|
||||
assertInstances( col, x2, 2 );
|
||||
assertInstances(col, m, 6);
|
||||
assertInstances(col, x1, 1);
|
||||
assertInstances(col, x2, 2);
|
||||
|
||||
IASTName [] ds = tu.getDeclarations( x2 );
|
||||
assertEquals( ds.length, 1 );
|
||||
assertSame( ds[0], col.getName(11) );
|
||||
IASTName[] ds = tu.getDeclarations(x2);
|
||||
assertEquals(ds.length, 1);
|
||||
assertSame(ds[0], col.getName(11));
|
||||
}
|
||||
|
||||
public void testBug84236() throws Exception
|
||||
{
|
||||
public void testBug84236() throws Exception {
|
||||
String code = "double maximum(double a[ ][*]);"; //$NON-NLS-1$
|
||||
IASTSimpleDeclaration d = (IASTSimpleDeclaration) parse( code, ParserLanguage.C ).getDeclarations()[0];
|
||||
IASTStandardFunctionDeclarator fd = (IASTStandardFunctionDeclarator) d.getDeclarators()[0];
|
||||
IASTSimpleDeclaration d = (IASTSimpleDeclaration) parse(code,
|
||||
ParserLanguage.C).getDeclarations()[0];
|
||||
IASTStandardFunctionDeclarator fd = (IASTStandardFunctionDeclarator) d
|
||||
.getDeclarators()[0];
|
||||
IASTParameterDeclaration p = fd.getParameters()[0];
|
||||
IASTArrayDeclarator a = (IASTArrayDeclarator) p.getDeclarator();
|
||||
ICASTArrayModifier star = (ICASTArrayModifier) a.getArrayModifiers()[1];
|
||||
assertTrue( star.isVariableSized() );
|
||||
assertTrue(star.isVariableSized());
|
||||
|
||||
}
|
||||
|
||||
public void testBug84696() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "struct A {\n int a; \n};\n" ); //$NON-NLS-1$
|
||||
buffer.append( "struct B: virtual A { };\n" ); //$NON-NLS-1$
|
||||
buffer.append( "struct C: B { };\n" ); //$NON-NLS-1$
|
||||
buffer.append( "struct D: B { };\n" ); //$NON-NLS-1$
|
||||
buffer.append( "struct E: public C, public D { };\n" ); //$NON-NLS-1$
|
||||
buffer.append( "struct F: public A { };\n" ); //$NON-NLS-1$
|
||||
buffer.append( "void f() {\n" ); //$NON-NLS-1$
|
||||
buffer.append( "E e;\n" ); //$NON-NLS-1$
|
||||
buffer.append( "e.B::a = 0;\n" ); //$NON-NLS-1$
|
||||
buffer.append( "F f;\n" ); //$NON-NLS-1$
|
||||
buffer.append( "f.A::a = 1;\n}\n" ); //$NON-NLS-1$
|
||||
buffer.append("struct A {\n int a; \n};\n"); //$NON-NLS-1$
|
||||
buffer.append("struct B: virtual A { };\n"); //$NON-NLS-1$
|
||||
buffer.append("struct C: B { };\n"); //$NON-NLS-1$
|
||||
buffer.append("struct D: B { };\n"); //$NON-NLS-1$
|
||||
buffer.append("struct E: public C, public D { };\n"); //$NON-NLS-1$
|
||||
buffer.append("struct F: public A { };\n"); //$NON-NLS-1$
|
||||
buffer.append("void f() {\n"); //$NON-NLS-1$
|
||||
buffer.append("E e;\n"); //$NON-NLS-1$
|
||||
buffer.append("e.B::a = 0;\n"); //$NON-NLS-1$
|
||||
buffer.append("F f;\n"); //$NON-NLS-1$
|
||||
buffer.append("f.A::a = 1;\n}\n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
|
@ -2846,21 +2910,36 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertNotNull(A);
|
||||
assertNotNull(B);
|
||||
|
||||
assertInstances( col, A, 4 );
|
||||
assertInstances( col, B, 4 );
|
||||
assertInstances(col, A, 4);
|
||||
assertInstances(col, B, 4);
|
||||
}
|
||||
|
||||
public void testBug85049() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer("typedef int B;\n"); //$NON-NLS-1$
|
||||
buffer.append("void g() {\n"); //$NON-NLS-1$
|
||||
buffer.append("B * bp; //1\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
IASTTranslationUnit t = parse(buffer.toString(), ParserLanguage.C );
|
||||
IASTFunctionDefinition g = (IASTFunctionDefinition) t.getDeclarations()[1];
|
||||
IASTCompoundStatement body = (IASTCompoundStatement) g.getBody();
|
||||
assertTrue(body.getStatements()[0] instanceof IASTDeclarationStatement);
|
||||
}
|
||||
|
||||
public void testBug84466() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "struct B {};\n" ); //$NON-NLS-1$
|
||||
buffer.append( "struct D : B {};\n" ); //$NON-NLS-1$
|
||||
buffer.append( "void foo(D* dp)\n{\n" ); //$NON-NLS-1$
|
||||
buffer.append( "B* bp = dynamic_cast<B*>(dp);\n}\n" ); //$NON-NLS-1$
|
||||
buffer.append("struct B {};\n"); //$NON-NLS-1$
|
||||
buffer.append("struct D : B {};\n"); //$NON-NLS-1$
|
||||
buffer.append("void foo(D* dp)\n{\n"); //$NON-NLS-1$
|
||||
buffer.append("B* bp = dynamic_cast<B*>(dp);\n}\n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
ICPPASTCastExpression dynamic_cast = (ICPPASTCastExpression)((IASTInitializerExpression)((IASTSimpleDeclaration)((IASTDeclarationStatement)((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[2]).getBody()).getStatements()[0]).getDeclaration()).getDeclarators()[0].getInitializer()).getExpression();
|
||||
ICPPASTCastExpression dynamic_cast = (ICPPASTCastExpression) ((IASTInitializerExpression) ((IASTSimpleDeclaration) ((IASTDeclarationStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) tu
|
||||
.getDeclarations()[2]).getBody()).getStatements()[0])
|
||||
.getDeclaration()).getDeclarators()[0].getInitializer())
|
||||
.getExpression();
|
||||
|
||||
assertEquals(dynamic_cast.getOperator(), ICPPASTCastExpression.op_dynamic_cast);
|
||||
assertEquals(dynamic_cast.getOperator(),
|
||||
ICPPASTCastExpression.op_dynamic_cast);
|
||||
|
||||
}
|
||||
}
|
|
@ -9,8 +9,6 @@
|
|||
* IBM Rational Software - Initial API and implementation */
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
|
||||
|
@ -32,7 +30,9 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
@ -70,16 +70,21 @@ import org.eclipse.cdt.core.parser.ParserMode;
|
|||
public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||
|
||||
protected final IParserLogService log;
|
||||
|
||||
protected final IScanner scanner;
|
||||
|
||||
protected final ParserMode mode;
|
||||
|
||||
protected final boolean supportStatementsInExpressions;
|
||||
|
||||
protected final boolean supportTypeOfUnaries;
|
||||
|
||||
protected final boolean supportAlignOfUnaries;
|
||||
|
||||
protected AbstractGNUSourceCodeParser(IScanner scanner,
|
||||
IParserLogService logService, ParserMode parserMode,
|
||||
boolean supportStatementsInExpressions, boolean supportTypeOfUnaries,
|
||||
boolean supportAlignOfUnaries) {
|
||||
boolean supportStatementsInExpressions,
|
||||
boolean supportTypeOfUnaries, boolean supportAlignOfUnaries) {
|
||||
this.scanner = scanner;
|
||||
this.log = logService;
|
||||
this.mode = parserMode;
|
||||
|
@ -359,8 +364,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
|
||||
protected IToken simpleDeclarationMark;
|
||||
|
||||
private static final int DEFAULT_COMPOUNDSTATEMENT_LIST_SIZE = 8;
|
||||
|
||||
public IASTTranslationUnit parse() {
|
||||
long startTime = System.currentTimeMillis();
|
||||
translationUnit();
|
||||
|
@ -434,7 +437,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
* to do a best-effort parse for our client.
|
||||
*
|
||||
* @throws EndOfFileException
|
||||
* We can potentially hit EndOfFile here as we are skipping ahead.
|
||||
* We can potentially hit EndOfFile here as we are skipping
|
||||
* ahead.
|
||||
*/
|
||||
protected void failParseWithErrorHandling() throws EndOfFileException {
|
||||
failParse();
|
||||
|
@ -455,14 +459,17 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
throws EndOfFileException, BacktrackException {
|
||||
int startingOffset = consume(IToken.tLBRACE).getOffset();
|
||||
|
||||
List statements = Collections.EMPTY_LIST;
|
||||
IASTCompoundStatement result = createCompoundStatement();
|
||||
((ASTNode) result).setOffset(startingOffset);
|
||||
result.setParent(mostRelevantScopeNode);
|
||||
result.setPropertyInParent(IASTFunctionDefinition.FUNCTION_BODY);
|
||||
while (LT(1) != IToken.tRBRACE) {
|
||||
int checkToken = LA(1).hashCode();
|
||||
try {
|
||||
IASTStatement s = statement();
|
||||
if (statements == Collections.EMPTY_LIST)
|
||||
statements = new ArrayList(DEFAULT_COMPOUNDSTATEMENT_LIST_SIZE);
|
||||
statements.add(s);
|
||||
result.addStatement(s);
|
||||
s.setParent(result);
|
||||
s.setPropertyInParent(IASTCompoundStatement.NESTED_STATEMENT);
|
||||
} catch (BacktrackException b) {
|
||||
IASTProblem p = failParse(b);
|
||||
IASTProblemStatement ps = createProblemStatement();
|
||||
|
@ -471,24 +478,15 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
((ASTNode) p).getLength());
|
||||
p.setParent(ps);
|
||||
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
|
||||
if (statements == Collections.EMPTY_LIST)
|
||||
statements = new ArrayList(DEFAULT_COMPOUNDSTATEMENT_LIST_SIZE);
|
||||
statements.add(ps);
|
||||
result.addStatement(ps);
|
||||
ps.setParent(result);
|
||||
ps.setPropertyInParent(IASTCompoundStatement.NESTED_STATEMENT);
|
||||
if (LA(1).hashCode() == checkToken)
|
||||
failParseWithErrorHandling();
|
||||
}
|
||||
}
|
||||
int lastOffset = consume(IToken.tRBRACE).getEndOffset();
|
||||
|
||||
IASTCompoundStatement result = createCompoundStatement();
|
||||
((ASTNode) result).setOffsetAndLength(startingOffset, lastOffset
|
||||
- startingOffset);
|
||||
for (int i = 0; i < statements.size(); ++i) {
|
||||
IASTStatement s = (IASTStatement) statements.get(i);
|
||||
result.addStatement(s);
|
||||
s.setParent(result);
|
||||
s.setPropertyInParent(IASTCompoundStatement.NESTED_STATEMENT);
|
||||
}
|
||||
((ASTNode) result).setLength(lastOffset - startingOffset);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -503,15 +501,16 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
protected abstract IASTCompoundStatement createCompoundStatement();
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTExpression compoundStatementExpression()
|
||||
throws EndOfFileException, BacktrackException {
|
||||
int startingOffset = consume(IToken.tLPAREN).getOffset();
|
||||
IASTCompoundStatement compoundStatement = null;
|
||||
if (mode == ParserMode.QUICK_PARSE || mode == ParserMode.STRUCTURAL_PARSE)
|
||||
if (mode == ParserMode.QUICK_PARSE
|
||||
|| mode == ParserMode.STRUCTURAL_PARSE)
|
||||
skipOverCompoundStatement();
|
||||
else if (mode == ParserMode.COMPLETION_PARSE
|
||||
|| mode == ParserMode.SELECTION_PARSE) {
|
||||
|
@ -592,8 +591,9 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
protected abstract IASTExpression multiplicativeExpression()
|
||||
throws BacktrackException, EndOfFileException;
|
||||
|
||||
protected abstract IASTTypeId typeId(boolean skipArrayMods, boolean forNewExpression)
|
||||
throws BacktrackException, EndOfFileException;
|
||||
protected abstract IASTTypeId typeId(boolean skipArrayMods,
|
||||
boolean forNewExpression) throws BacktrackException,
|
||||
EndOfFileException;
|
||||
|
||||
protected abstract IASTExpression castExpression()
|
||||
throws BacktrackException, EndOfFileException;
|
||||
|
@ -808,8 +808,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
|
||||
/**
|
||||
* @param expression
|
||||
* @return @throws
|
||||
* BacktrackException
|
||||
* @return
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTExpression conditionalExpression() throws BacktrackException,
|
||||
EndOfFileException {
|
||||
|
@ -832,7 +832,9 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
thirdExpression.setParent(result);
|
||||
thirdExpression
|
||||
.setPropertyInParent(IASTConditionalExpression.NEGATIVE_RESULT);
|
||||
((ASTNode)result).setOffsetAndLength( ((ASTNode)firstExpression).getOffset(), calculateEndOffset(thirdExpression) - ((ASTNode)firstExpression).getOffset() );
|
||||
((ASTNode) result).setOffsetAndLength(((ASTNode) firstExpression)
|
||||
.getOffset(), calculateEndOffset(thirdExpression)
|
||||
- ((ASTNode) firstExpression).getOffset());
|
||||
return result;
|
||||
}
|
||||
return firstExpression;
|
||||
|
@ -879,12 +881,12 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
protected abstract IASTUnaryExpression createUnaryExpression();
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* BacktrackException
|
||||
* @return
|
||||
* @throws BacktrackException
|
||||
* @throws EndOfFileException
|
||||
*/
|
||||
protected IASTExpression unaryAlignofExpression() throws EndOfFileException,
|
||||
BacktrackException {
|
||||
protected IASTExpression unaryAlignofExpression()
|
||||
throws EndOfFileException, BacktrackException {
|
||||
int offset = consume(IGCCToken.t___alignof__).getOffset();
|
||||
IASTTypeId d = null;
|
||||
IASTExpression unaryExpression = null;
|
||||
|
@ -953,7 +955,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
|
||||
protected IASTStatement handleFunctionBody() throws BacktrackException,
|
||||
EndOfFileException {
|
||||
if (mode == ParserMode.QUICK_PARSE || mode == ParserMode.STRUCTURAL_PARSE) {
|
||||
if (mode == ParserMode.QUICK_PARSE
|
||||
|| mode == ParserMode.STRUCTURAL_PARSE) {
|
||||
IToken curr = LA(1);
|
||||
IToken last = skipOverCompoundStatement();
|
||||
IASTCompoundStatement cs = createCompoundStatement();
|
||||
|
@ -1035,8 +1038,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return true if we have encountered a typename up to this point, false
|
||||
* otherwise
|
||||
* @return true if we have encountered a typename up to this point,
|
||||
* false otherwise
|
||||
*/
|
||||
public boolean haveEncounteredTypename() {
|
||||
return encounteredTypename;
|
||||
|
@ -1075,7 +1078,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
|
||||
/**
|
||||
* Parse an enumeration specifier, as according to the ANSI specs in C & C++.
|
||||
* Parse an enumeration specifier, as according to the ANSI specs in C &
|
||||
* C++.
|
||||
*
|
||||
* enumSpecifier: "enum" (name)? "{" (enumerator-list) "}" enumerator-list:
|
||||
* enumerator-definition enumerator-list , enumerator-definition
|
||||
|
@ -1083,8 +1087,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
* enumerator: identifier
|
||||
*
|
||||
* @param owner
|
||||
* IParserCallback object that represents the declaration that owns
|
||||
* this type specifier.
|
||||
* IParserCallback object that represents the declaration that
|
||||
* owns this type specifier.
|
||||
*
|
||||
* @throws BacktrackException
|
||||
* request a backtrack
|
||||
|
@ -1167,7 +1171,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
result.addEnumerator(enumerator);
|
||||
enumerator.setParent(result);
|
||||
enumerator.setPropertyInParent(IASTEnumerationSpecifier.ENUMERATOR);
|
||||
enumerator
|
||||
.setPropertyInParent(IASTEnumerationSpecifier.ENUMERATOR);
|
||||
|
||||
consume(IToken.tCOMMA);
|
||||
}
|
||||
|
@ -1306,8 +1311,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
EndOfFileException;
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTDeclaration asmDeclaration() throws EndOfFileException,
|
||||
|
@ -1350,8 +1355,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
* @return
|
||||
*/
|
||||
protected IASTExpression buildTypeIdUnaryExpression(int op,
|
||||
IASTTypeId typeId, IASTExpression subExpression, int startingOffset,
|
||||
int lastOffset) {
|
||||
IASTTypeId typeId, IASTExpression subExpression,
|
||||
int startingOffset, int lastOffset) {
|
||||
IASTCastExpression result = createCastExpression();
|
||||
result.setOperator(op);
|
||||
((ASTNode) result).setOffsetAndLength(startingOffset, lastOffset
|
||||
|
@ -1371,8 +1376,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
protected abstract IASTCastExpression createCastExpression();
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTStatement parseDeclarationOrExpressionStatement()
|
||||
|
@ -1390,8 +1395,9 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
lastTokenOfExpression = consume(IToken.tSEMI);
|
||||
expressionStatement = createExpressionStatement();
|
||||
expressionStatement.setExpression(expression);
|
||||
((ASTNode) expressionStatement).setOffsetAndLength(mark.getOffset(),
|
||||
lastTokenOfExpression.getEndOffset() - mark.getOffset());
|
||||
((ASTNode) expressionStatement).setOffsetAndLength(
|
||||
mark.getOffset(), lastTokenOfExpression.getEndOffset()
|
||||
- mark.getOffset());
|
||||
expression.setParent(expressionStatement);
|
||||
expression.setPropertyInParent(IASTExpressionStatement.EXPFRESSION);
|
||||
} catch (BacktrackException b) {
|
||||
|
@ -1429,9 +1435,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
|
||||
if (expressionStatement == null && ds == null)
|
||||
throwBacktrack(savedBt);
|
||||
//resolve ambiguities
|
||||
//A * B = C;
|
||||
//A & B = C;
|
||||
// resolve ambiguities
|
||||
// A * B = C;
|
||||
if (expressionStatement.getExpression() instanceof IASTBinaryExpression) {
|
||||
IASTBinaryExpression exp = (IASTBinaryExpression) expressionStatement
|
||||
.getExpression();
|
||||
|
@ -1442,19 +1447,27 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
|
||||
return ds;
|
||||
}
|
||||
if (lhs instanceof IASTBinaryExpression
|
||||
&& ((IASTBinaryExpression) lhs).getOperator() == IASTBinaryExpression.op_binaryAnd) {
|
||||
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
|
||||
// A*B
|
||||
if (expressionStatement.getExpression() instanceof IASTBinaryExpression) {
|
||||
IASTBinaryExpression exp = (IASTBinaryExpression) expressionStatement
|
||||
.getExpression();
|
||||
if (exp.getOperator() == IASTBinaryExpression.op_multiply) {
|
||||
IASTExpression lhs = exp.getOperand1();
|
||||
if (lhs instanceof IASTIdExpression)
|
||||
if (queryIsTypeName(((IASTIdExpression) lhs).getName()))
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
|
||||
// x = y; // default to int
|
||||
// valid @ Translation Unit scope
|
||||
// but not valid as a statement in a function body
|
||||
if (ds.getDeclaration() instanceof IASTSimpleDeclaration
|
||||
&& ((IASTSimpleDeclaration) ds.getDeclaration()).getDeclSpecifier() instanceof IASTSimpleDeclSpecifier
|
||||
&& ((IASTSimpleDeclaration) ds.getDeclaration())
|
||||
.getDeclSpecifier() instanceof IASTSimpleDeclSpecifier
|
||||
&& ((IASTSimpleDeclSpecifier) ((IASTSimpleDeclaration) ds
|
||||
.getDeclaration()).getDeclSpecifier()).getType() == IASTSimpleDeclSpecifier.t_unspecified) {
|
||||
backup(mark);
|
||||
|
@ -1466,7 +1479,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
return expressionStatement;
|
||||
}
|
||||
|
||||
if( resolveOtherAmbiguitiesAsDeclaration( ds, expressionStatement ) )
|
||||
if (resolveOtherAmbiguitiesAsDeclaration(ds, expressionStatement))
|
||||
return ds;
|
||||
|
||||
backup(mark);
|
||||
|
@ -1479,17 +1492,27 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param ds
|
||||
* @param expressionStatement
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
protected boolean resolveOtherAmbiguitiesAsDeclaration(IASTDeclarationStatement ds, IASTExpressionStatement expressionStatement) {
|
||||
protected boolean queryIsTypeName(IASTName name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @param ds
|
||||
* @param expressionStatement
|
||||
* @return
|
||||
*/
|
||||
protected boolean resolveOtherAmbiguitiesAsDeclaration(
|
||||
IASTDeclarationStatement ds,
|
||||
IASTExpressionStatement expressionStatement) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTStatement parseLabelStatement() throws EndOfFileException,
|
||||
|
@ -1507,8 +1530,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTStatement parseNullStatement() throws EndOfFileException,
|
||||
|
@ -1523,8 +1546,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTStatement parseGotoStatement() throws EndOfFileException,
|
||||
|
@ -1544,8 +1567,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTStatement parseBreakStatement() throws EndOfFileException,
|
||||
|
@ -1560,8 +1583,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTStatement parseContinueStatement() throws EndOfFileException,
|
||||
|
@ -1570,14 +1593,14 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
int lastOffset = consume(IToken.tSEMI).getEndOffset();
|
||||
|
||||
IASTContinueStatement continue_statement = createContinueStatement();
|
||||
((ASTNode) continue_statement).setOffsetAndLength(startOffset, lastOffset
|
||||
- startOffset);
|
||||
((ASTNode) continue_statement).setOffsetAndLength(startOffset,
|
||||
lastOffset - startOffset);
|
||||
return continue_statement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTStatement parseReturnStatement() throws EndOfFileException,
|
||||
|
@ -1603,8 +1626,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTStatement parseForStatement() throws EndOfFileException,
|
||||
|
@ -1656,8 +1679,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTStatement parseDoStatement() throws EndOfFileException,
|
||||
|
@ -1683,8 +1706,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTStatement parseWhileStatement() throws EndOfFileException,
|
||||
|
@ -1710,8 +1733,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTStatement parseSwitchStatement() throws EndOfFileException,
|
||||
|
@ -1736,8 +1759,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTStatement parseIfStatement() throws EndOfFileException,
|
||||
|
@ -1780,22 +1803,27 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
new_if_statement.setThenClause(thenClause);
|
||||
thenClause.setParent(new_if_statement);
|
||||
thenClause.setPropertyInParent(IASTIfStatement.THEN);
|
||||
((ASTNode)new_if_statement).setLength( calculateEndOffset( thenClause ) - ((ASTNode)new_if_statement).getOffset() );
|
||||
((ASTNode) new_if_statement)
|
||||
.setLength(calculateEndOffset(thenClause)
|
||||
- ((ASTNode) new_if_statement).getOffset());
|
||||
}
|
||||
if (LT(1) == IToken.t_else) {
|
||||
consume(IToken.t_else);
|
||||
if (LT(1) == IToken.t_if) {
|
||||
//an else if, don't recurse, just loop and do another if
|
||||
// an else if, don't recurse, just loop and do another if
|
||||
|
||||
if (if_statement != null) {
|
||||
if_statement.setElseClause(new_if_statement);
|
||||
new_if_statement.setParent(if_statement);
|
||||
new_if_statement.setPropertyInParent(IASTIfStatement.ELSE);
|
||||
((ASTNode)if_statement).setLength( calculateEndOffset( new_if_statement ) - ((ASTNode)if_statement).getOffset() );
|
||||
new_if_statement
|
||||
.setPropertyInParent(IASTIfStatement.ELSE);
|
||||
((ASTNode) if_statement)
|
||||
.setLength(calculateEndOffset(new_if_statement)
|
||||
- ((ASTNode) if_statement).getOffset());
|
||||
}
|
||||
if( result == null && if_statement != null )
|
||||
if (result == null && if_statement != null)
|
||||
result = if_statement;
|
||||
if( result == null )
|
||||
if (result == null)
|
||||
result = new_if_statement;
|
||||
|
||||
if_statement = new_if_statement;
|
||||
|
@ -1809,11 +1837,13 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
if_statement.setElseClause(new_if_statement);
|
||||
new_if_statement.setParent(if_statement);
|
||||
new_if_statement.setPropertyInParent(IASTIfStatement.ELSE);
|
||||
((ASTNode)if_statement).setLength( calculateEndOffset( new_if_statement ) - ((ASTNode)if_statement).getOffset() ) ;
|
||||
((ASTNode) if_statement)
|
||||
.setLength(calculateEndOffset(new_if_statement)
|
||||
- ((ASTNode) if_statement).getOffset());
|
||||
} else {
|
||||
if( result == null && if_statement != null )
|
||||
if (result == null && if_statement != null)
|
||||
result = if_statement;
|
||||
if( result == null )
|
||||
if (result == null)
|
||||
result = new_if_statement;
|
||||
if_statement = new_if_statement;
|
||||
}
|
||||
|
@ -1825,11 +1855,12 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
new_if_statement.setParent(if_statement);
|
||||
new_if_statement.setPropertyInParent(IASTIfStatement.ELSE);
|
||||
((ASTNode) new_if_statement)
|
||||
.setLength(calculateEndOffset(new_if_statement) - start);
|
||||
.setLength(calculateEndOffset(new_if_statement)
|
||||
- start);
|
||||
}
|
||||
if( result == null && if_statement != null )
|
||||
if (result == null && if_statement != null)
|
||||
result = if_statement;
|
||||
if( result == null )
|
||||
if (result == null)
|
||||
result = new_if_statement;
|
||||
|
||||
if_statement = new_if_statement;
|
||||
|
@ -1837,7 +1868,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
break if_loop;
|
||||
}
|
||||
|
||||
reconcileLengths( result );
|
||||
reconcileLengths(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1845,25 +1876,25 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
* @param result
|
||||
*/
|
||||
protected void reconcileLengths(IASTIfStatement result) {
|
||||
if( result == null ) return;
|
||||
if (result == null)
|
||||
return;
|
||||
IASTIfStatement current = result;
|
||||
while( current.getElseClause() instanceof IASTIfStatement )
|
||||
while (current.getElseClause() instanceof IASTIfStatement)
|
||||
current = (IASTIfStatement) current.getElseClause();
|
||||
|
||||
while( current != null )
|
||||
{
|
||||
ASTNode r = ((ASTNode)current);
|
||||
if( current.getElseClause() != null )
|
||||
{
|
||||
ASTNode else_clause = ((ASTNode)current.getElseClause() );
|
||||
r.setLength( else_clause.getOffset() + else_clause.getLength() - r.getOffset() );
|
||||
}
|
||||
else
|
||||
{
|
||||
while (current != null) {
|
||||
ASTNode r = ((ASTNode) current);
|
||||
if (current.getElseClause() != null) {
|
||||
ASTNode else_clause = ((ASTNode) current.getElseClause());
|
||||
r.setLength(else_clause.getOffset() + else_clause.getLength()
|
||||
- r.getOffset());
|
||||
} else {
|
||||
ASTNode then_clause = (ASTNode) current.getThenClause();
|
||||
r.setLength( then_clause.getOffset() + then_clause.getLength() - r.getOffset() );
|
||||
r.setLength(then_clause.getOffset() + then_clause.getLength()
|
||||
- r.getOffset());
|
||||
}
|
||||
if( current.getParent() != null && current.getParent() instanceof IASTIfStatement )
|
||||
if (current.getParent() != null
|
||||
&& current.getParent() instanceof IASTIfStatement)
|
||||
current = (IASTIfStatement) current.getParent();
|
||||
else
|
||||
current = null;
|
||||
|
@ -1876,20 +1907,19 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
protected abstract IASTProblemExpression createProblemExpression();
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTStatement parseCompoundStatement() throws EndOfFileException,
|
||||
BacktrackException {
|
||||
IASTCompoundStatement compound = compoundStatement();
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTStatement parseDefaultStatement() throws EndOfFileException,
|
||||
|
@ -1898,13 +1928,14 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
int lastOffset = consume(IToken.tCOLON).getEndOffset();
|
||||
|
||||
IASTDefaultStatement df = createDefaultStatement();
|
||||
((ASTNode) df).setOffsetAndLength(startOffset, lastOffset - startOffset);
|
||||
((ASTNode) df)
|
||||
.setOffsetAndLength(startOffset, lastOffset - startOffset);
|
||||
return df;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return @throws
|
||||
* EndOfFileException
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTStatement parseCaseStatement() throws EndOfFileException,
|
||||
|
@ -1914,7 +1945,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
int lastOffset = consume(IToken.tCOLON).getEndOffset();
|
||||
|
||||
IASTCaseStatement cs = createCaseStatement();
|
||||
((ASTNode) cs).setOffsetAndLength(startOffset, lastOffset - startOffset);
|
||||
((ASTNode) cs)
|
||||
.setOffsetAndLength(startOffset, lastOffset - startOffset);
|
||||
cs.setExpression(case_exp);
|
||||
case_exp.setParent(cs);
|
||||
case_exp.setPropertyInParent(IASTCaseStatement.EXPRESSION);
|
||||
|
@ -1940,7 +1972,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
*/
|
||||
protected int figureEndOffset(IASTDeclSpecifier declSpecifier,
|
||||
IASTDeclarator declarator) {
|
||||
if (declarator == null || ((ASTNode)declarator).getLength() == 0 )
|
||||
if (declarator == null || ((ASTNode) declarator).getLength() == 0)
|
||||
return calculateEndOffset(declSpecifier);
|
||||
return calculateEndOffset(declarator);
|
||||
}
|
||||
|
@ -1949,7 +1981,9 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
* @param token
|
||||
*/
|
||||
protected void throwBacktrack(IToken token) throws BacktrackException {
|
||||
throwBacktrack( token.getOffset(), token.getLength() );
|
||||
throwBacktrack(token.getOffset(), token.getLength());
|
||||
}
|
||||
|
||||
protected IASTNode mostRelevantScopeNode;
|
||||
|
||||
}
|
|
@ -35,12 +35,12 @@ public class CEnumeration implements IEnumeration {
|
|||
|
||||
private IASTName [] declarations = null;
|
||||
private IASTName definition = null;
|
||||
public CEnumeration( IASTName enum ){
|
||||
ASTNodeProperty prop = enum.getPropertyInParent();
|
||||
public CEnumeration( IASTName enumeration ){
|
||||
ASTNodeProperty prop = enumeration.getPropertyInParent();
|
||||
if( prop == IASTElaboratedTypeSpecifier.TYPE_NAME )
|
||||
declarations = new IASTName[] { enum };
|
||||
declarations = new IASTName[] { enumeration };
|
||||
else
|
||||
definition = enum;
|
||||
definition = enumeration;
|
||||
}
|
||||
|
||||
public void addDeclaration( IASTName decl ){
|
||||
|
|
|
@ -1976,4 +1976,25 @@ public class CVisitor {
|
|||
visitTranslationUnit( tu, action );
|
||||
return action.getReferences();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param startingPoint
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static IBinding findTypeBinding(IASTNode startingPoint, IASTName name) {
|
||||
if( startingPoint instanceof IASTTranslationUnit )
|
||||
{
|
||||
IASTDeclaration [] declarations = ((IASTTranslationUnit)startingPoint).getDeclarations();
|
||||
if( declarations.length > 0 )
|
||||
return findBinding( declarations[declarations.length - 1], name, COMPLETE | INCLUDE_BLOCK_ITEM );
|
||||
}
|
||||
if( startingPoint instanceof IASTCompoundStatement )
|
||||
{
|
||||
IASTStatement [] statements = ((IASTCompoundStatement)startingPoint).getStatements();
|
||||
if( statements.length > 0 )
|
||||
return findBinding( statements[ statements.length - 1 ], name, COMPLETE | INCLUDE_BLOCK_ITEM );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@ import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
|
@ -65,6 +64,7 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
|
@ -72,6 +72,8 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
|
||||
|
@ -548,6 +550,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
|
||||
translationUnit.setLocationResolver(scanner.getLocationResolver());
|
||||
mostRelevantScopeNode = translationUnit;
|
||||
|
||||
int lastBacktrack = -1;
|
||||
while (true) {
|
||||
|
@ -2533,4 +2536,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return pd;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser#queryIsTypeName(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||
*/
|
||||
protected boolean queryIsTypeName(IASTName name) {
|
||||
//TODO fix me
|
||||
IBinding b = CVisitor.findTypeBinding( mostRelevantScopeNode, name );
|
||||
if( b == null ) return false;
|
||||
if( b instanceof ITypedef ) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -74,6 +74,8 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
|
||||
|
@ -1832,8 +1834,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
private static final int DEFAULT_POINTEROPS_LIST_SIZE = 4;
|
||||
private static final int DEFAULT_SIZE_EXCEPTIONS_LIST = 2;
|
||||
private static final int DEFAULT_CONSTRUCTOR_CHAIN_LIST_SIZE = 4;
|
||||
private IASTNode mostRelevantScopeNode;
|
||||
|
||||
/**
|
||||
* This is the standard cosntructor that we expect the Parser to be
|
||||
* instantiated with.
|
||||
|
@ -4806,8 +4806,32 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
.getArrayExpression() instanceof IASTFieldReference))
|
||||
return true;
|
||||
}
|
||||
//A & B = C;
|
||||
if (expressionStatement.getExpression() instanceof IASTBinaryExpression) {
|
||||
IASTBinaryExpression exp = (IASTBinaryExpression) expressionStatement
|
||||
.getExpression();
|
||||
if (exp.getOperator() == IASTBinaryExpression.op_assign) {
|
||||
IASTExpression lhs = exp.getOperand1();
|
||||
if (lhs instanceof IASTBinaryExpression
|
||||
&& ((IASTBinaryExpression) lhs).getOperator() == IASTBinaryExpression.op_binaryAnd) {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super
|
||||
.resolveOtherAmbiguitiesAsDeclaration(ds, expressionStatement);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser#queryIsTypeName(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||
*/
|
||||
protected boolean queryIsTypeName(IASTName name) {
|
||||
IBinding b = CPPSemantics.findTypeBinding( mostRelevantScopeNode, name );
|
||||
if( b == null ) return false;
|
||||
if( b instanceof IType ) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue