1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Added some more tests.

This commit is contained in:
John Camelon 2005-05-04 19:55:14 +00:00
parent 39e465b9a8
commit 037b93c764

View file

@ -13,6 +13,8 @@
*/
package org.eclipse.cdt.core.parser.tests.ast2;
import java.util.Iterator;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
@ -868,7 +870,8 @@ public class AST2CPPTests extends AST2BaseTest {
IFunction g = (IFunction) collector.getName(2).resolveBinding();
ICPPNamespace X = (ICPPNamespace) collector.getName(3).resolveBinding();
ICPPUsingDeclaration using = (ICPPUsingDeclaration) collector.getName(5).resolveBinding();
ICPPUsingDeclaration using = (ICPPUsingDeclaration) collector
.getName(5).resolveBinding();
ICPPDelegate[] delegates = using.getDelegates();
assertEquals(delegates.length, 1);
assertSame(delegates[0].getBinding(), f);
@ -876,7 +879,8 @@ public class AST2CPPTests extends AST2BaseTest {
assertInstances(collector, A, 2);
assertInstances(collector, X, 3);
ICPPUsingDeclaration using_g = (ICPPUsingDeclaration) collector.getName(8).resolveBinding();
ICPPUsingDeclaration using_g = (ICPPUsingDeclaration) collector
.getName(8).resolveBinding();
assertSame(using_g.getDelegates()[0].getBinding(), g);
assertInstances(collector, using_g.getDelegates()[0], 2);
}
@ -1261,7 +1265,8 @@ public class AST2CPPTests extends AST2BaseTest {
buffer.append(" AB::f(`c`); \n"); //$NON-NLS-1$ use of ` ` deliberate!
buffer.append("} \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP, false, false );
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP,
false, false);
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
@ -1626,7 +1631,8 @@ public class AST2CPPTests extends AST2BaseTest {
// IASTTranslationUnit tu = parse(
// "int x = 5; int y(x);", ParserLanguage.CPP); //$NON-NLS-1$
//
// IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) ((IASTSimpleDeclaration) tu
// IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator)
// ((IASTSimpleDeclaration) tu
// .getDeclarations()[1]).getDeclarators()[0];
// IASTName name = fdtor.getParameters()[0].getDeclarator().getName();
// IBinding binding = CPPSemantics.findTypeBinding(tu, name);
@ -1646,11 +1652,15 @@ 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
// IASTCompoundStatement compound = (IASTCompoundStatement)
// ((IASTFunctionDefinition) tu
// .getDeclarations()[1]).getBody();
// IASTBinaryExpression b = (IASTBinaryExpression) ((IASTExpressionStatement)compound.getStatements()[0]).getExpression();
// IBinding binding = ((IASTIdExpression)b.getOperand1()).getName().resolveBinding();
//// IASTSimpleDeclaration decl = (IASTSimpleDeclaration) ((IASTDeclarationStatement) compound
// IASTBinaryExpression b = (IASTBinaryExpression)
// ((IASTExpressionStatement)compound.getStatements()[0]).getExpression();
// IBinding binding =
// ((IASTIdExpression)b.getOperand1()).getName().resolveBinding();
// // IASTSimpleDeclaration decl = (IASTSimpleDeclaration)
// ((IASTDeclarationStatement) compound
// // .getStatements()[0]).getDeclaration();
// // IBinding binding = CPPSemantics.findTypeBinding(compound,
// // ((ICPPASTNamedTypeSpecifier)decl.getDeclSpecifier()).getName());
@ -1669,7 +1679,6 @@ public class AST2CPPTests extends AST2BaseTest {
assertTrue(body.getStatements()[0] instanceof IASTDeclarationStatement);
}
public void testPMConversions() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("class A { public: int i; }; \n"); //$NON-NLS-1$
@ -1799,6 +1808,7 @@ public class AST2CPPTests extends AST2BaseTest {
assertEquals(friends.length, 1);
assertSame(friends[0], B);
}
public void testBug59302() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("class A { \n"); //$NON-NLS-1$
@ -1915,6 +1925,7 @@ public class AST2CPPTests extends AST2BaseTest {
assertInstances(col, f1, 2);
assertInstances(col, f2, 1);
}
public void _testBug45763_4() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("void f( int ); \n"); //$NON-NLS-1$
@ -1993,13 +2004,15 @@ public class AST2CPPTests extends AST2BaseTest {
// StringBuffer buffer = new StringBuffer( "void f() {" ); //$NON-NLS-1$
// buffer.append( " if (__io.flags() & ios_base::showbase" ); //$NON-NLS-1$
// buffer.append( " || __i < 2 || __sign.size() > 1" ); //$NON-NLS-1$
// buffer.append( " || ((static_cast<part>(__p.field[3]) != money_base::none)" ); //$NON-NLS-1$
// buffer.append( " || ((static_cast<part>(__p.field[3]) !=
// money_base::none)" ); //$NON-NLS-1$
// buffer.append( " && __i == 2)) " ); //$NON-NLS-1$
// buffer.append( " return;" ); //$NON-NLS-1$
// buffer.append( "}"); //$NON-NLS-1$
// String code = buffer.toString();
// IASTTranslationUnit tu = parse( code, ParserLanguage.CPP );
// IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
// IASTFunctionDefinition f = (IASTFunctionDefinition)
// tu.getDeclarations()[0];
// IASTCompoundStatement body = (IASTCompoundStatement) f.getBody();
// IASTIfStatement if_stmt = (IASTIfStatement) body.getStatements()[0];
// assertNotNull( if_stmt.getCondition() );
@ -2110,16 +2123,15 @@ public class AST2CPPTests extends AST2BaseTest {
assertInstances(col, g, 2);
}
public void testBug86288() throws Exception
{
public void testBug86288() throws Exception {
String code = "int *foo( int *b ) { return (int *)(b); }"; //$NON-NLS-1$
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
IASTReturnStatement r = (IASTReturnStatement) ((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[0]).getBody()).getStatements()[0];
IASTReturnStatement r = (IASTReturnStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) tu
.getDeclarations()[0]).getBody()).getStatements()[0];
assertTrue(r.getReturnValue() instanceof IASTCastExpression);
}
public void testBug84476() throws Exception
{
public void testBug84476() throws Exception {
StringBuffer buffer = new StringBuffer();
// buffer.append( "struct B { int f();};\n"); //$NON-NLS-1$
// buffer.append( "int (B::*pb)() = &B::f; \n"); //$NON-NLS-1$
@ -2130,9 +2142,12 @@ public class AST2CPPTests extends AST2BaseTest {
buffer.append("int (B::*pb)() = &B::f;\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
String code = buffer.toString();
IASTFunctionDefinition foo = (IASTFunctionDefinition) parse( code, ParserLanguage.CPP ).getDeclarations()[0];
IASTDeclarationStatement decl = (IASTDeclarationStatement) ((IASTCompoundStatement)foo.getBody()).getStatements()[1];
IASTSimpleDeclaration pb = (IASTSimpleDeclaration) decl.getDeclaration();
IASTFunctionDefinition foo = (IASTFunctionDefinition) parse(code,
ParserLanguage.CPP).getDeclarations()[0];
IASTDeclarationStatement decl = (IASTDeclarationStatement) ((IASTCompoundStatement) foo
.getBody()).getStatements()[1];
IASTSimpleDeclaration pb = (IASTSimpleDeclaration) decl
.getDeclaration();
IASTDeclarator d = pb.getDeclarators()[0];
assertEquals(d.getNestedDeclarator().getPointerOperators().length, 1);
assertEquals(d.getNestedDeclarator().getName().toString(), "pb"); //$NON-NLS-1$
@ -2152,7 +2167,8 @@ public class AST2CPPTests extends AST2BaseTest {
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
ICPPConstructor T1_ctor = (ICPPConstructor) col.getName(6).resolveBinding();
ICPPConstructor T1_ctor = (ICPPConstructor) col.getName(6)
.resolveBinding();
ICPPClassType T1 = (ICPPClassType) col.getName(0).resolveBinding();
assertInstances(col, T1_ctor, 2);
@ -2245,6 +2261,7 @@ public class AST2CPPTests extends AST2BaseTest {
assertInstances(col, j, 3);
assertInstances(col, x, 5);
}
public void testBug84478() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("void foo() {\n"); //$NON-NLS-1$
@ -2259,8 +2276,10 @@ public class AST2CPPTests extends AST2BaseTest {
buffer.append(" i = 0;\n"); //$NON-NLS-1$
buffer.append(" }\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
IASTFunctionDefinition foo = (IASTFunctionDefinition) parse( buffer.toString(), ParserLanguage.CPP ).getDeclarations()[0];
ICPPASTWhileStatement whileStatement = (ICPPASTWhileStatement) ((IASTCompoundStatement)foo.getBody()).getStatements()[2];
IASTFunctionDefinition foo = (IASTFunctionDefinition) parse(
buffer.toString(), ParserLanguage.CPP).getDeclarations()[0];
ICPPASTWhileStatement whileStatement = (ICPPASTWhileStatement) ((IASTCompoundStatement) foo
.getBody()).getStatements()[2];
assertNull(whileStatement.getCondition());
assertNotNull(whileStatement.getConditionDeclaration());
}
@ -2487,7 +2506,8 @@ public class AST2CPPTests extends AST2BaseTest {
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
ICPPUsingDeclaration u = (ICPPUsingDeclaration) col.getName(7).resolveBinding();
ICPPUsingDeclaration u = (ICPPUsingDeclaration) col.getName(7)
.resolveBinding();
IASTName[] decls = tu.getDeclarations(u);
assertEquals(decls.length, 2);
@ -2555,13 +2575,15 @@ public class AST2CPPTests extends AST2BaseTest {
assertTrue(ref1 instanceof ICPPDelegate);
assertTrue(ref2 instanceof ICPPDelegate);
ICPPClassType g_struct = (ICPPClassType) col.getName(1).resolveBinding();
ICPPClassType g_struct = (ICPPClassType) col.getName(1)
.resolveBinding();
IFunction g_func = (IFunction) col.getName(2).resolveBinding();
assertSame(g_struct, ((ICPPDelegate) ref2).getBinding());
assertSame(g_func, ((ICPPDelegate) ref1).getBinding());
ICPPUsingDeclaration comp = (ICPPUsingDeclaration) col.getName(7).resolveBinding();
ICPPUsingDeclaration comp = (ICPPUsingDeclaration) col.getName(7)
.resolveBinding();
IASTName[] decls = tu.getDeclarations(comp);
assertEquals(decls.length, 2);
assertSame(decls[0], col.getName(1));
@ -2590,7 +2612,8 @@ public class AST2CPPTests extends AST2BaseTest {
ICPPBinding ref1 = (ICPPBinding) col.getName(11).resolveBinding();
ICPPBinding ref2 = (ICPPBinding) col.getName(12).resolveBinding();
ICPPClassType x_struct = (ICPPClassType) col.getName(3).resolveBinding();
ICPPClassType x_struct = (ICPPClassType) col.getName(3)
.resolveBinding();
IVariable x_var = (IVariable) col.getName(1).resolveBinding();
assertTrue(ref1 instanceof ICPPDelegate);
@ -2838,6 +2861,7 @@ public class AST2CPPTests extends AST2BaseTest {
assertEquals(bs.length, 1);
assertSame(bs[0], v1);
}
public void testFind_2() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("class A { int a; }; \n"); //$NON-NLS-1$
@ -2869,6 +2893,7 @@ public class AST2CPPTests extends AST2BaseTest {
assertEquals(bs.length, 1);
assertSame(bs[0], A);
}
public void testFind_3() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("namespace A { \n"); //$NON-NLS-1$
@ -2888,7 +2913,8 @@ public class AST2CPPTests extends AST2BaseTest {
IFunction f2 = (IFunction) col.getName(3).resolveBinding();
IFunction f3 = (IFunction) col.getName(6).resolveBinding();
IASTFunctionDefinition def = (IASTFunctionDefinition) col.getName(5).getParent().getParent();
IASTFunctionDefinition def = (IASTFunctionDefinition) col.getName(5)
.getParent().getParent();
IScope scope = ((IASTCompoundStatement) def.getBody()).getScope();
IBinding[] bs = scope.find("f"); //$NON-NLS-1$
assertEquals(bs.length, 3);
@ -2901,11 +2927,13 @@ public class AST2CPPTests extends AST2BaseTest {
assertEquals(s[0], "f"); //$NON-NLS-1$
assertFalse(((ICPPDelegate) bs[1]).isGloballyQualified());
s = ((ICPPBinding) ((ICPPDelegate)bs[1]).getBinding()).getQualifiedName();
s = ((ICPPBinding) ((ICPPDelegate) bs[1]).getBinding())
.getQualifiedName();
assertEquals(s.length, 2);
assertEquals(s[0], "A"); //$NON-NLS-1$
assertEquals(s[1], "f"); //$NON-NLS-1$
assertTrue( ((ICPPBinding) ((ICPPDelegate)bs[1]).getBinding()).isGloballyQualified() );
assertTrue(((ICPPBinding) ((ICPPDelegate) bs[1]).getBinding())
.isGloballyQualified());
}
@ -2934,7 +2962,8 @@ public class AST2CPPTests extends AST2BaseTest {
IFunction f1 = (IFunction) col.getName(2).resolveBinding();
IFunction f2 = (IFunction) col.getName(4).resolveBinding();
IASTFunctionDefinition def = (IASTFunctionDefinition) col.getName(8).getParent().getParent();
IASTFunctionDefinition def = (IASTFunctionDefinition) col.getName(8)
.getParent().getParent();
IScope scope = ((IASTCompoundStatement) def.getBody()).getScope();
IBinding[] bs = scope.find("f"); //$NON-NLS-1$
assertEquals(bs.length, 3);
@ -2983,14 +3012,16 @@ public class AST2CPPTests extends AST2BaseTest {
assertSame(result[0], fb);
assertSame(result[1], fa);
ICPPMethod [] B_implicit = ((ICPPClassScope)B.getCompositeScope()).getImplicitMethods();
ICPPMethod[] B_implicit = ((ICPPClassScope) B.getCompositeScope())
.getImplicitMethods();
assertEquals(B_implicit.length, 4);
assertTrue(B_implicit[0].getName().equals("B")); //$NON-NLS-1$
assertTrue(B_implicit[1].getName().equals("B")); //$NON-NLS-1$
assertTrue(B_implicit[2].getName().equals("operator =")); //$NON-NLS-1$
assertTrue(B_implicit[3].getName().equals("~B")); //$NON-NLS-1$
ICPPMethod [] A_implicit = ((ICPPClassScope)A.getCompositeScope()).getImplicitMethods();
ICPPMethod[] A_implicit = ((ICPPClassScope) A.getCompositeScope())
.getImplicitMethods();
assertEquals(A_implicit.length, 4);
assertTrue(A_implicit[0].getName().equals("A")); //$NON-NLS-1$
assertTrue(A_implicit[1].getName().equals("A")); //$NON-NLS-1$
@ -3012,7 +3043,8 @@ public class AST2CPPTests extends AST2BaseTest {
}
public void testBug87424() throws Exception {
IASTTranslationUnit tu = parse( "int * restrict x;", ParserLanguage.CPP, true ); //$NON-NLS-1$
IASTTranslationUnit tu = parse(
"int * restrict x;", ParserLanguage.CPP, true); //$NON-NLS-1$
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
@ -3032,7 +3064,8 @@ public class AST2CPPTests extends AST2BaseTest {
}
public void testBug87705() throws Exception {
IASTTranslationUnit tu = parse( "class A { friend class B::C; };", ParserLanguage.CPP, true ); //$NON-NLS-1$
IASTTranslationUnit tu = parse(
"class A { friend class B::C; };", ParserLanguage.CPP, true); //$NON-NLS-1$
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
@ -3052,7 +3085,8 @@ public class AST2CPPTests extends AST2BaseTest {
}
public void testBug88501_1() throws Exception {
IASTTranslationUnit tu = parse( "void f(); void f( int ); struct f;", ParserLanguage.CPP ); //$NON-NLS-1$
IASTTranslationUnit tu = parse(
"void f(); void f( int ); struct f;", ParserLanguage.CPP); //$NON-NLS-1$
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
@ -3062,7 +3096,8 @@ public class AST2CPPTests extends AST2BaseTest {
}
// public void testBug8342_1() throws Exception {
// IASTTranslationUnit tu = parse( "int a; int a;", ParserLanguage.CPP ); //$NON-NLS-1$
// IASTTranslationUnit tu = parse( "int a; int a;", ParserLanguage.CPP );
// //$NON-NLS-1$
// CPPNameCollector col = new CPPNameCollector();
// tu.accept(col);
//
@ -3072,7 +3107,8 @@ public class AST2CPPTests extends AST2BaseTest {
// }
public void testBug8342_2() throws Exception {
IASTTranslationUnit tu = parse( "extern int a; extern char a;", ParserLanguage.CPP ); //$NON-NLS-1$
IASTTranslationUnit tu = parse(
"extern int a; extern char a;", ParserLanguage.CPP); //$NON-NLS-1$
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
@ -3094,7 +3130,8 @@ public class AST2CPPTests extends AST2BaseTest {
tu.accept(col);
ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding();
ICPPNamespaceAlias alias = (ICPPNamespaceAlias) col.getName(6).resolveBinding();
ICPPNamespaceAlias alias = (ICPPNamespaceAlias) col.getName(6)
.resolveBinding();
ICPPVariable i = (ICPPVariable) col.getName(7).resolveBinding();
assertInstances(col, A, 2);
@ -3155,7 +3192,8 @@ public class AST2CPPTests extends AST2BaseTest {
}
public void testBug89828() throws Exception {
IASTTranslationUnit tu = parse( "class B * b; void f(); void f( int );", ParserLanguage.CPP ); //$NON-NLS-1$
IASTTranslationUnit tu = parse(
"class B * b; void f(); void f( int );", ParserLanguage.CPP); //$NON-NLS-1$
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
@ -3210,7 +3248,6 @@ public class AST2CPPTests extends AST2BaseTest {
assertSame(one.getType(), e);
}
public void testOperatorConversionNames() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("class Foo {\n"); //$NON-NLS-1$
@ -3234,7 +3271,8 @@ public class AST2CPPTests extends AST2BaseTest {
IASTTypeId typeId = ((ICPPASTConversionName) name1).getTypeId();
assertNotNull(typeId);
assertEquals( ((IASTSimpleDeclSpecifier)typeId.getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_int );
assertEquals(((IASTSimpleDeclSpecifier) typeId.getDeclSpecifier())
.getType(), IASTSimpleDeclSpecifier.t_int);
}
@ -3242,7 +3280,8 @@ public class AST2CPPTests extends AST2BaseTest {
StringBuffer buffer = new StringBuffer();
buffer.append("class X { operator int(); }; \n"); //$NON-NLS-1$
buffer.append("X::operator int() { } \n"); //$NON-NLS-1$
buffer.append("template <class A,B> class X<A,C> { operator int(); }; \n"); //$NON-NLS-1$
buffer
.append("template <class A,B> class X<A,C> { operator int(); }; \n"); //$NON-NLS-1$
buffer.append("template <class A,B> X<A,C>::operator int() { } \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); //$NON-NLS-1$
@ -3274,27 +3313,34 @@ public class AST2CPPTests extends AST2BaseTest {
// ensure qualified name isConversionOrOperator
assertTrue(col.getName(2) instanceof ICPPASTQualifiedName);
assertTrue(col.getName(16) instanceof ICPPASTQualifiedName);
assertTrue(((ICPPASTQualifiedName)col.getName(2)).isConversionOrOperator());
assertTrue(((ICPPASTQualifiedName)col.getName(16)).isConversionOrOperator());
assertTrue(((ICPPASTQualifiedName) col.getName(2))
.isConversionOrOperator());
assertTrue(((ICPPASTQualifiedName) col.getName(16))
.isConversionOrOperator());
}
public void testBug88662() throws Exception {
IASTTranslationUnit tu = parse( "int foo() { return int();}", ParserLanguage.CPP ); //$NON-NLS-1$
IASTReturnStatement returnStatement = (IASTReturnStatement) ((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[0]).getBody()).getStatements()[0];
ICPPASTSimpleTypeConstructorExpression expression = (ICPPASTSimpleTypeConstructorExpression) returnStatement.getReturnValue();
IASTTranslationUnit tu = parse(
"int foo() { return int();}", ParserLanguage.CPP); //$NON-NLS-1$
IASTReturnStatement returnStatement = (IASTReturnStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) tu
.getDeclarations()[0]).getBody()).getStatements()[0];
ICPPASTSimpleTypeConstructorExpression expression = (ICPPASTSimpleTypeConstructorExpression) returnStatement
.getReturnValue();
assertEquals(expression.getInitialValue(), null);
assertEquals( expression.getSimpleType(), ICPPASTSimpleTypeConstructorExpression.t_int );
assertEquals(expression.getSimpleType(),
ICPPASTSimpleTypeConstructorExpression.t_int);
}
public void testBug90498_1() throws Exception {
IASTTranslationUnit tu = parse( "typedef INT ( FOO ) (INT);", ParserLanguage.CPP ); //$NON-NLS-1$
IASTTranslationUnit tu = parse(
"typedef INT ( FOO ) (INT);", ParserLanguage.CPP); //$NON-NLS-1$
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu
.getDeclarations()[0];
IASTDeclSpecifier declSpec = decl.getDeclSpecifier();
assertTrue(declSpec instanceof ICPPASTNamedTypeSpecifier);
assertEquals( ((ICPPASTNamedTypeSpecifier)declSpec).getName().toString(), "INT" ); //$NON-NLS-1$
assertEquals(((ICPPASTNamedTypeSpecifier) declSpec).getName()
.toString(), "INT"); //$NON-NLS-1$
IASTDeclarator dtor = decl.getDeclarators()[0];
assertTrue(dtor instanceof IASTFunctionDeclarator);
@ -3304,9 +3350,11 @@ public class AST2CPPTests extends AST2BaseTest {
}
public void testBug90498_2() throws Exception {
IASTTranslationUnit tu = parse( "int (* foo) (int) (0);", ParserLanguage.CPP ); //$NON-NLS-1$
IASTTranslationUnit tu = parse(
"int (* foo) (int) (0);", ParserLanguage.CPP); //$NON-NLS-1$
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu
.getDeclarations()[0];
IASTDeclSpecifier declSpec = decl.getDeclSpecifier();
assertTrue(declSpec instanceof IASTSimpleDeclSpecifier);
@ -3319,7 +3367,6 @@ public class AST2CPPTests extends AST2BaseTest {
assertNotNull(dtor.getInitializer());
}
public void testBug866274() throws Exception {
StringBuffer buffer = new StringBuffer("class D { /* ... */ };\n"); //$NON-NLS-1$
buffer.append("D d1;\n"); //$NON-NLS-1$
@ -3329,34 +3376,38 @@ public class AST2CPPTests extends AST2BaseTest {
buffer.append(" typeid(D) == typeid(d2);\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
IASTFunctionDefinition foo = (IASTFunctionDefinition) tu.getDeclarations()[3];
IASTFunctionDefinition foo = (IASTFunctionDefinition) tu
.getDeclarations()[3];
IASTCompoundStatement cs = (IASTCompoundStatement) foo.getBody();
IASTStatement[] subs = cs.getStatements();
for( int i = 0; i < subs.length; ++i )
{
IASTBinaryExpression be = (IASTBinaryExpression) ((IASTExpressionStatement)subs[i]).getExpression();
if( i == 1 )
{
IASTTypeIdExpression expression = (IASTTypeIdExpression) be.getOperand1();
for (int i = 0; i < subs.length; ++i) {
IASTBinaryExpression be = (IASTBinaryExpression) ((IASTExpressionStatement) subs[i])
.getExpression();
if (i == 1) {
IASTTypeIdExpression expression = (IASTTypeIdExpression) be
.getOperand1();
IASTTypeId typeId = expression.getTypeId();
assertTrue( ((IASTNamedTypeSpecifier)typeId.getDeclSpecifier()).getName().resolveBinding() instanceof IType );
}
else
{
IASTUnaryExpression expression = (IASTUnaryExpression) be.getOperand1();
IASTIdExpression idExpression = (IASTIdExpression) expression.getOperand();
assertTrue(((IASTNamedTypeSpecifier) typeId.getDeclSpecifier())
.getName().resolveBinding() instanceof IType);
} else {
IASTUnaryExpression expression = (IASTUnaryExpression) be
.getOperand1();
IASTIdExpression idExpression = (IASTIdExpression) expression
.getOperand();
assertTrue(idExpression.getName().resolveBinding() instanceof IVariable);
}
IASTUnaryExpression expression = (IASTUnaryExpression) be.getOperand2();
IASTIdExpression idExpression = (IASTIdExpression) expression.getOperand();
IASTUnaryExpression expression = (IASTUnaryExpression) be
.getOperand2();
IASTIdExpression idExpression = (IASTIdExpression) expression
.getOperand();
assertTrue(idExpression.getName().resolveBinding() instanceof IVariable);
}
}
public void testTypedefFunction() throws Exception {
IASTTranslationUnit tu = parse( "typedef int foo (int);", ParserLanguage.CPP ); //$NON-NLS-1$
IASTTranslationUnit tu = parse(
"typedef int foo (int);", ParserLanguage.CPP); //$NON-NLS-1$
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
@ -3382,7 +3433,8 @@ public class AST2CPPTests extends AST2BaseTest {
}
public void testBug90603() throws Exception {
IASTTranslationUnit tu = parse( "class X { void f(){} };", ParserLanguage.CPP ); //$NON-NLS-1$
IASTTranslationUnit tu = parse(
"class X { void f(){} };", ParserLanguage.CPP); //$NON-NLS-1$
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
@ -3413,9 +3465,11 @@ public class AST2CPPTests extends AST2BaseTest {
ICPPClassType X = (ICPPClassType) col.getName(0).resolveBinding();
IVariable x = (IVariable) col.getName(2).resolveBinding();
IProblemBinding problem = (IProblemBinding) col.getName(3).resolveBinding();
IProblemBinding problem = (IProblemBinding) col.getName(3)
.resolveBinding();
assertSame(x.getType(), X);
assertEquals( problem.getID(), IProblemBinding.SEMANTIC_INVALID_REDEFINITION );
assertEquals(problem.getID(),
IProblemBinding.SEMANTIC_INVALID_REDEFINITION);
}
public void testOperatorNames() throws Exception {
@ -3583,10 +3637,13 @@ public class AST2CPPTests extends AST2BaseTest {
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
ICPPConstructor ctor1 = (ICPPConstructor) col.getName(1).resolveBinding();
ICPPConstructor ctor = (ICPPConstructor) col.getName(11).resolveBinding();
ICPPConstructor ctor1 = (ICPPConstructor) col.getName(1)
.resolveBinding();
ICPPConstructor ctor = (ICPPConstructor) col.getName(11)
.resolveBinding();
assertSame(ctor, ctor1);
}
public void testBug90654_2() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("struct A { \n"); //$NON-NLS-1$
@ -3669,8 +3726,7 @@ public class AST2CPPTests extends AST2BaseTest {
assertSame(g1, g2);
}
public void testAmbiguousStatements() throws Exception
{
public void testAmbiguousStatements() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("class ABC { \n"); //$NON-NLS-1$
buffer.append(" class DEF { };\n"); //$NON-NLS-1$
@ -3686,7 +3742,8 @@ public class AST2CPPTests extends AST2BaseTest {
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
IASTDeclaration[] declarations = tu.getDeclarations();
assertEquals(3, declarations.length);
IASTCompoundStatement cs = (IASTCompoundStatement) ((IASTFunctionDefinition)declarations[2]).getBody();
IASTCompoundStatement cs = (IASTCompoundStatement) ((IASTFunctionDefinition) declarations[2])
.getBody();
assertTrue(cs.getStatements()[1] instanceof IASTDeclarationStatement);
assertTrue(cs.getStatements()[2] instanceof IASTExpressionStatement);
@ -3779,14 +3836,18 @@ public class AST2CPPTests extends AST2BaseTest {
assertSame(x, x2);
}
public void testBug90648() throws ParserException
{
IASTTranslationUnit tu = parse( "int f() { int (&ra)[3] = a; }", ParserLanguage.CPP ); //$NON-NLS-1$
IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
public void testBug90648() throws ParserException {
IASTTranslationUnit tu = parse(
"int f() { int (&ra)[3] = a; }", ParserLanguage.CPP); //$NON-NLS-1$
IASTFunctionDefinition f = (IASTFunctionDefinition) tu
.getDeclarations()[0];
IASTCompoundStatement body = (IASTCompoundStatement) f.getBody();
final IASTDeclarationStatement statement = (IASTDeclarationStatement) body.getStatements()[0];
IASTSimpleDeclaration d = (IASTSimpleDeclaration) statement.getDeclaration();
IASTSimpleDeclSpecifier declSpec = (IASTSimpleDeclSpecifier) d.getDeclSpecifier();
final IASTDeclarationStatement statement = (IASTDeclarationStatement) body
.getStatements()[0];
IASTSimpleDeclaration d = (IASTSimpleDeclaration) statement
.getDeclaration();
IASTSimpleDeclSpecifier declSpec = (IASTSimpleDeclSpecifier) d
.getDeclSpecifier();
assertEquals(IASTSimpleDeclSpecifier.t_int, declSpec.getType());
final IASTDeclarator[] declarators = d.getDeclarators();
assertEquals(declarators.length, 1);
@ -3832,7 +3893,73 @@ public class AST2CPPTests extends AST2BaseTest {
}
public void testBug90647() throws Exception {
parse( "char msg[] = \"Syntax error on line %s\\n\";", ParserLanguage.CPP ); //$NON-NLS-1$
parse(
"char msg[] = \"Syntax error on line %s\\n\";", ParserLanguage.CPP); //$NON-NLS-1$
}
public void testBug82766() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("int main(int argc, char **argv)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("int sum=0;\n"); //$NON-NLS-1$
buffer.append("int i;\n"); //$NON-NLS-1$
buffer.append("for (i = 0; i < 10; ++i)\n"); //$NON-NLS-1$
buffer.append("for (int j = 0; j < 3; ++j)\n"); //$NON-NLS-1$
buffer.append("sum += j;\n"); //$NON-NLS-1$
buffer.append("for (i = 0; i < 10; ++i)\n"); //$NON-NLS-1$
buffer.append("for (int j = 0; j < 3; ++j) // line X\n"); //$NON-NLS-1$
buffer.append("sum += j; // line Y\n"); //$NON-NLS-1$
buffer.append("int k;\n"); //$NON-NLS-1$
buffer.append("k = sum;\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
assertNoProblemBindings( col );
}
public void testBug77385() throws Exception {
StringBuffer buffer = new StringBuffer( "int main(int argc, char *argv[])\n" ); //$NON-NLS-1$
buffer.append( "{\n" ); //$NON-NLS-1$
buffer.append( " unsigned long l = 0;\n" ); //$NON-NLS-1$
buffer.append( "char *c;\n" ); //$NON-NLS-1$
buffer.append( "l |= ((unsigned long)(*((c)++)))<<24;\n" ); //$NON-NLS-1$
buffer.append( "}\n" ); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
assertNoProblemBindings( col );
}
public void testBug83997() throws Exception {
IASTTranslationUnit tu = parse( "namespace { int x; }", ParserLanguage.CPP ); //$NON-NLS-1$
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
assertNoProblemBindings( col );
}
protected void assertNoProblemBindings(CPPNameCollector col) {
Iterator i = col.nameList.iterator();
while( i.hasNext() )
{
IASTName n = (IASTName) i.next();
assertNotNull( n.resolveBinding());
assertFalse( n.resolveBinding() instanceof IProblemBinding );
}
}
protected void assertProblemBindings(CPPNameCollector col, int count ) {
Iterator i = col.nameList.iterator();
int sum = 0;
while( i.hasNext() )
{
IASTName n = (IASTName) i.next();
assertNotNull( n.resolveBinding());
if( n.getBinding() instanceof IProblemBinding )
++sum;
}
assertEquals( count, sum );
}
}