mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixed Bug 81739 - [GNUCSourceParser] Lookahead problem w/nested declarators
This commit is contained in:
parent
55f4eca137
commit
78f1bf9054
9 changed files with 615 additions and 514 deletions
|
@ -290,81 +290,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 11.3-2):
|
||||
class A {
|
||||
public:
|
||||
int z;
|
||||
int z1;
|
||||
};
|
||||
class B : public A {
|
||||
int a;
|
||||
public:
|
||||
int b, c;
|
||||
int bf();
|
||||
protected:
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
class D : private B {
|
||||
int d;
|
||||
public:
|
||||
B::c; //adjust access to B::c
|
||||
B::z; //adjust access to A::z
|
||||
A::z1; //adjust access to A::z1
|
||||
int e;
|
||||
int df();
|
||||
protected:
|
||||
B::x; //adjust access to B::x
|
||||
int g;
|
||||
};
|
||||
class X : public D {
|
||||
int xf();
|
||||
};
|
||||
int ef(D&);
|
||||
int ff(X&);
|
||||
--End Example]
|
||||
*/
|
||||
public void test11_3s2() throws Exception { //bug 92793
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("class A {\n"); //$NON-NLS-1$
|
||||
buffer.append("public:\n"); //$NON-NLS-1$
|
||||
buffer.append("int z;\n"); //$NON-NLS-1$
|
||||
buffer.append("int z1;\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("class B : public A {\n"); //$NON-NLS-1$
|
||||
buffer.append("int a;\n"); //$NON-NLS-1$
|
||||
buffer.append("public:\n"); //$NON-NLS-1$
|
||||
buffer.append("int b, c;\n"); //$NON-NLS-1$
|
||||
buffer.append("int bf();\n"); //$NON-NLS-1$
|
||||
buffer.append("protected:\n"); //$NON-NLS-1$
|
||||
buffer.append("int x;\n"); //$NON-NLS-1$
|
||||
buffer.append("int y;\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("class D : private B {\n"); //$NON-NLS-1$
|
||||
buffer.append("int d;\n"); //$NON-NLS-1$
|
||||
buffer.append("public:\n"); //$NON-NLS-1$
|
||||
buffer.append("B::c; //adjust access to B::c\n"); //$NON-NLS-1$
|
||||
buffer.append("B::z; //adjust access to A::z\n"); //$NON-NLS-1$
|
||||
buffer.append("A::z1; //adjust access to A::z1\n"); //$NON-NLS-1$
|
||||
buffer.append("int e;\n"); //$NON-NLS-1$
|
||||
buffer.append("int df();\n"); //$NON-NLS-1$
|
||||
buffer.append("protected:\n"); //$NON-NLS-1$
|
||||
buffer.append("B::x; //adjust access to B::x\n"); //$NON-NLS-1$
|
||||
buffer.append("int g;\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("class X : public D {\n"); //$NON-NLS-1$
|
||||
buffer.append("int xf();\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("int ef(D&);\n"); //$NON-NLS-1$
|
||||
buffer.append("int ff(X&);\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 14.3-2):
|
||||
template<class T> void f();
|
||||
|
|
|
@ -6095,7 +6095,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("friend class X;\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("class X : A::B { // illformed:\n"); //$NON-NLS-1$
|
||||
buffer.append("A::B cannot be accessed\n"); //$NON-NLS-1$
|
||||
buffer.append("//A::B cannot be accessed\n"); //$NON-NLS-1$
|
||||
buffer.append("// in the baseclause for X\n"); //$NON-NLS-1$
|
||||
buffer.append("A::B mx; // OK: A::B used to declare member of X\n"); //$NON-NLS-1$
|
||||
buffer.append("class Y : A::B { // OK: A::B used to declare member of X\n"); //$NON-NLS-1$
|
||||
|
@ -9981,7 +9981,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("void f() {\n"); //$NON-NLS-1$
|
||||
buffer.append("g(1); //calls g(double)\n"); //$NON-NLS-1$
|
||||
buffer.append("h++; //illformed:\n"); //$NON-NLS-1$
|
||||
buffer.append("cannot increment function;\n"); //$NON-NLS-1$
|
||||
buffer.append("// cannot increment function;\n"); //$NON-NLS-1$
|
||||
buffer.append("// this could be diagnosed either here or\n"); //$NON-NLS-1$
|
||||
buffer.append("// at the point of instantiation\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
|
@ -12442,5 +12442,74 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
parse(buffer.toString(), ParserLanguage.CPP, false, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 11.3-2):
|
||||
class A {
|
||||
public:
|
||||
int z;
|
||||
int z1;
|
||||
};
|
||||
class B : public A {
|
||||
int a;
|
||||
public:
|
||||
int b, c;
|
||||
int bf();
|
||||
protected:
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
class D : private B {
|
||||
int d;
|
||||
public:
|
||||
B::c; //adjust access to B::c
|
||||
B::z; //adjust access to A::z
|
||||
A::z1; //adjust access to A::z1
|
||||
int e;
|
||||
int df();
|
||||
protected:
|
||||
B::x; //adjust access to B::x
|
||||
int g;
|
||||
};
|
||||
class X : public D {
|
||||
int xf();
|
||||
};
|
||||
int ef(D&);
|
||||
int ff(X&);
|
||||
--End Example]
|
||||
*/
|
||||
public void test11_3s2() throws Exception { //bug 92793
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("class A {\n"); //$NON-NLS-1$
|
||||
buffer.append("public:\n"); //$NON-NLS-1$
|
||||
buffer.append("int z;\n"); //$NON-NLS-1$
|
||||
buffer.append("int z1;\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("class B : public A {\n"); //$NON-NLS-1$
|
||||
buffer.append("int a;\n"); //$NON-NLS-1$
|
||||
buffer.append("public:\n"); //$NON-NLS-1$
|
||||
buffer.append("int b, c;\n"); //$NON-NLS-1$
|
||||
buffer.append("int bf();\n"); //$NON-NLS-1$
|
||||
buffer.append("protected:\n"); //$NON-NLS-1$
|
||||
buffer.append("int x;\n"); //$NON-NLS-1$
|
||||
buffer.append("int y;\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("class D : private B {\n"); //$NON-NLS-1$
|
||||
buffer.append("int d;\n"); //$NON-NLS-1$
|
||||
buffer.append("public:\n"); //$NON-NLS-1$
|
||||
buffer.append("B::c; //adjust access to B::c\n"); //$NON-NLS-1$
|
||||
buffer.append("B::z; //adjust access to A::z\n"); //$NON-NLS-1$
|
||||
buffer.append("A::z1; //adjust access to A::z1\n"); //$NON-NLS-1$
|
||||
buffer.append("int e;\n"); //$NON-NLS-1$
|
||||
buffer.append("int df();\n"); //$NON-NLS-1$
|
||||
buffer.append("protected:\n"); //$NON-NLS-1$
|
||||
buffer.append("B::x; //adjust access to B::x\n"); //$NON-NLS-1$
|
||||
buffer.append("int g;\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("class X : public D {\n"); //$NON-NLS-1$
|
||||
buffer.append("int xf();\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("int ef(D&);\n"); //$NON-NLS-1$
|
||||
buffer.append("int ff(X&);\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
|||
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.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
|
@ -58,6 +59,7 @@ import org.eclipse.cdt.core.dom.ast.IScope;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
|
||||
|
@ -3487,7 +3489,7 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
buffer.append(" const C& operator+=(const C&);\n"); //$NON-NLS-1$
|
||||
buffer.append(" const C& operator -= (const C&);\n"); //$NON-NLS-1$
|
||||
buffer.append(" const C& operator *= (const C&);\n"); //$NON-NLS-1$
|
||||
buffer.append(" cosnt C& operator /= (const C&);\n"); //$NON-NLS-1$
|
||||
buffer.append(" const C& operator /= (const C&);\n"); //$NON-NLS-1$
|
||||
buffer.append(" const C& operator %= (const C&);\n"); //$NON-NLS-1$
|
||||
buffer.append(" const C& operator^=(const C&);\n"); //$NON-NLS-1$
|
||||
buffer.append(" const C& operator&= (const C&);\n"); //$NON-NLS-1$
|
||||
|
@ -4085,6 +4087,124 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertSame( f1, col.getName(4).resolveBinding() );
|
||||
}
|
||||
|
||||
public void testAmbiguity() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("class A { };\n"); //$NON-NLS-1$
|
||||
buffer.append("int f() { \n"); //$NON-NLS-1$
|
||||
buffer.append(" A * b = 0;\n"); //$NON-NLS-1$
|
||||
buffer.append(" A & c = 0;\n"); //$NON-NLS-1$
|
||||
buffer.append("}"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
IASTSimpleDeclaration A = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTFunctionDefinition f = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[1];
|
||||
IASTCompoundStatement body = (IASTCompoundStatement) f.getBody();
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
IASTDeclarationStatement ds = (IASTDeclarationStatement) body
|
||||
.getStatements()[i];
|
||||
String s1 = ((IASTNamedTypeSpecifier) ((IASTSimpleDeclaration) ds
|
||||
.getDeclaration()).getDeclSpecifier()).getName().toString();
|
||||
String s2 = ((IASTCompositeTypeSpecifier) A.getDeclSpecifier())
|
||||
.getName().toString();
|
||||
assertEquals(s1, s2);
|
||||
}
|
||||
}
|
||||
|
||||
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$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept(col);
|
||||
|
||||
assertEquals(col.size(), 26);
|
||||
|
||||
ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding();
|
||||
ICPPClassType B = (ICPPClassType) col.getName(2).resolveBinding();
|
||||
|
||||
assertNotNull(A);
|
||||
assertNotNull(B);
|
||||
|
||||
assertInstances(col, A, 4);
|
||||
assertInstances(col, B, 4);
|
||||
}
|
||||
|
||||
public void testBasicPointerToMember() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer("class X {\n"); //$NON-NLS-1$
|
||||
buffer.append(" public:\n"); //$NON-NLS-1$
|
||||
buffer.append(" void f(int);\n"); //$NON-NLS-1$
|
||||
buffer.append(" int a;\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("int X:: * pmi = &X::a;\n"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
assertEquals(tu.getDeclarations().length, 2);
|
||||
IASTSimpleDeclaration p2m = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[1];
|
||||
IASTDeclarator d = p2m.getDeclarators()[0];
|
||||
ICPPASTPointerToMember po = (ICPPASTPointerToMember) d
|
||||
.getPointerOperators()[0];
|
||||
assertEquals(po.getName().toString(), "X::"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
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$
|
||||
|
||||
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();
|
||||
|
||||
assertEquals(dynamic_cast.getOperator(),
|
||||
ICPPASTCastExpression.op_dynamic_cast);
|
||||
}
|
||||
|
||||
public void testBug88338_CPP() throws Exception {
|
||||
IASTTranslationUnit tu = parse(
|
||||
"struct A; struct A* a;", ParserLanguage.CPP); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept(col);
|
||||
|
||||
assertTrue(col.getName(0).isDeclaration());
|
||||
assertFalse(col.getName(0).isReference());
|
||||
assertTrue(col.getName(1).isReference());
|
||||
assertFalse(col.getName(1).isDeclaration());
|
||||
|
||||
tu = parse("struct A* a;", ParserLanguage.CPP); //$NON-NLS-1$
|
||||
col = new CPPNameCollector();
|
||||
tu.accept(col);
|
||||
|
||||
assertTrue(col.getName(0).isDeclaration());
|
||||
assertFalse(col.getName(0).isReference());
|
||||
}
|
||||
|
||||
public void testPointerToFunction_CPP() throws Exception
|
||||
{
|
||||
IASTTranslationUnit tu = parse("int (*pfi)();", ParserLanguage.CPP); //$NON-NLS-1$
|
||||
assertEquals(tu.getDeclarations().length, 1);
|
||||
IASTSimpleDeclaration d = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
assertEquals(d.getDeclarators().length, 1);
|
||||
IASTStandardFunctionDeclarator f = (IASTStandardFunctionDeclarator) d.getDeclarators()[0];
|
||||
assertEquals(f.getName().toString(), "");
|
||||
assertNotNull(f.getNestedDeclarator());
|
||||
assertEquals(f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testBug95484() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("class X { public: int bar; }; \n"); //$NON-NLS-1$
|
||||
|
|
|
@ -75,9 +75,6 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
|
|||
import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CFunction;
|
||||
|
@ -160,7 +157,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTName name_ref_y = ref_y.getName();
|
||||
assertEquals("y", name_ref_y.toString()); //$NON-NLS-1$
|
||||
|
||||
//BINDINGS
|
||||
// BINDINGS
|
||||
// resolve the binding to get the variable object
|
||||
IVariable var_x = (IVariable) name_x.resolveBinding();
|
||||
assertEquals(globalScope, var_x.getScope());
|
||||
|
@ -203,24 +200,32 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(decls.length, 1);
|
||||
assertEquals(decls[0], name_y);
|
||||
|
||||
// // test clearBindings
|
||||
// assertNotNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
|
||||
// assertNotNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
|
||||
// assertNotNull(((ICScope) body_f.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("z").toCharArray())); //$NON-NLS-1$
|
||||
// assertNotNull(((ICScope) body_f.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray())); //$NON-NLS-1$
|
||||
// CVisitor.clearBindings(tu);
|
||||
// assertNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
|
||||
// assertNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
|
||||
// assertNull(((ICScope) body_f.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("z").toCharArray())); //$NON-NLS-1$
|
||||
// assertNull(((ICScope) body_f.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray())); //$NON-NLS-1$
|
||||
// // test clearBindings
|
||||
// assertNotNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
// assertNotNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
// assertNotNull(((ICScope) body_f.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("z").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
// assertNotNull(((ICScope) body_f.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
// CVisitor.clearBindings(tu);
|
||||
// assertNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
// assertNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
// assertNull(((ICScope) body_f.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("z").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
// assertNull(((ICScope) body_f.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testSimpleStruct() throws Exception {
|
||||
|
@ -244,8 +249,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(IASTDeclSpecifier.sc_typedef, type.getStorageClass());
|
||||
// this an anonymous struct
|
||||
IASTName name_struct = type.getName();
|
||||
assertTrue( name_struct.isDeclaration() );
|
||||
assertFalse( name_struct.isReference() );
|
||||
assertTrue(name_struct.isDeclaration());
|
||||
assertFalse(name_struct.isReference());
|
||||
assertEquals("", name_struct.toString()); //$NON-NLS-1$
|
||||
// member - x
|
||||
IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) type
|
||||
|
@ -298,7 +303,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
.getOperand2();
|
||||
assertEquals("5", lit_5.toString()); //$NON-NLS-1$
|
||||
|
||||
//Logical Bindings In Test
|
||||
// Logical Bindings In Test
|
||||
ICompositeType type_struct = (ICompositeType) name_struct
|
||||
.resolveBinding();
|
||||
ITypedef typedef_S = (ITypedef) name_S.resolveBinding();
|
||||
|
@ -453,7 +458,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
|
||||
//struct A;
|
||||
// struct A;
|
||||
IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
IASTElaboratedTypeSpecifier compTypeSpec = (IASTElaboratedTypeSpecifier) decl1
|
||||
|
@ -461,7 +466,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(0, decl1.getDeclarators().length);
|
||||
IASTName nameA1 = compTypeSpec.getName();
|
||||
|
||||
//void f() {
|
||||
// void f() {
|
||||
IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[1];
|
||||
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef
|
||||
|
@ -489,7 +494,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(1, dtor.getPointerOperators().length);
|
||||
assertTrue(dtor.getPointerOperators()[0] instanceof ICASTPointer);
|
||||
|
||||
//bindings
|
||||
// bindings
|
||||
ICompositeType str1 = (ICompositeType) nameA1.resolveBinding();
|
||||
ICompositeType str2 = (ICompositeType) nameA2.resolveBinding();
|
||||
IVariable var = (IVariable) namea.resolveBinding();
|
||||
|
@ -536,7 +541,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
|
||||
//struct A;
|
||||
// struct A;
|
||||
IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
IASTElaboratedTypeSpecifier compTypeSpec = (IASTElaboratedTypeSpecifier) decl1
|
||||
|
@ -544,7 +549,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(0, decl1.getDeclarators().length);
|
||||
IASTName nameA1 = compTypeSpec.getName();
|
||||
|
||||
//void f() {
|
||||
// void f() {
|
||||
IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[1];
|
||||
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef
|
||||
|
@ -563,7 +568,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(1, dtor.getPointerOperators().length);
|
||||
assertTrue(dtor.getPointerOperators()[0] instanceof ICASTPointer);
|
||||
|
||||
//bindings
|
||||
// bindings
|
||||
ICompositeType str1 = (ICompositeType) nameA1.resolveBinding();
|
||||
ICompositeType str2 = (ICompositeType) nameA2.resolveBinding();
|
||||
IVariable var = (IVariable) namea.resolveBinding();
|
||||
|
@ -603,7 +608,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
|
||||
//struct A;
|
||||
// struct A;
|
||||
IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) decl1
|
||||
|
@ -611,7 +616,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(0, decl1.getDeclarators().length);
|
||||
IASTName name_A1 = elabTypeSpec.getName();
|
||||
|
||||
//struct A * a;
|
||||
// struct A * a;
|
||||
IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[1];
|
||||
elabTypeSpec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier();
|
||||
|
@ -621,7 +626,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(1, dtor.getPointerOperators().length);
|
||||
assertTrue(dtor.getPointerOperators()[0] instanceof ICASTPointer);
|
||||
|
||||
//struct A {
|
||||
// struct A {
|
||||
IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[2];
|
||||
ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) decl3
|
||||
|
@ -634,7 +639,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
dtor = decl4.getDeclarators()[0];
|
||||
IASTName name_i = dtor.getName();
|
||||
|
||||
//void f() {
|
||||
// void f() {
|
||||
IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[3];
|
||||
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef
|
||||
|
@ -650,7 +655,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTName name_aref = id_a.getName();
|
||||
IASTName name_iref = fieldref.getFieldName();
|
||||
|
||||
//bindings
|
||||
// bindings
|
||||
IVariable var_a1 = (IVariable) name_aref.resolveBinding();
|
||||
IVariable var_i1 = (IVariable) name_iref.resolveBinding();
|
||||
IPointerType structA_1pointer = (IPointerType) var_a1.getType();
|
||||
|
@ -772,23 +777,31 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(decls.length, 1);
|
||||
assertEquals(decls[0], declaration2.getDeclarators()[0].getName());
|
||||
|
||||
// assertNotNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_TAG, new String("x").toCharArray())); //$NON-NLS-1$
|
||||
// assertNotNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
|
||||
// assertNotNull(((ICScope) compound.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
|
||||
// assertNotNull(((ICScope) compound.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("i").toCharArray())); //$NON-NLS-1$
|
||||
// CVisitor.clearBindings(tu);
|
||||
// assertNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_TAG, new String("x").toCharArray())); //$NON-NLS-1$
|
||||
// assertNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
|
||||
// assertNull(((ICScope) compound.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
|
||||
// assertNull(((ICScope) compound.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("i").toCharArray())); //$NON-NLS-1$
|
||||
// assertNotNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_TAG, new String("x").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
// assertNotNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
// assertNotNull(((ICScope) compound.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
// assertNotNull(((ICScope) compound.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("i").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
// CVisitor.clearBindings(tu);
|
||||
// assertNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_TAG, new String("x").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
// assertNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
// assertNull(((ICScope) compound.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
// assertNull(((ICScope) compound.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("i").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testFunctionParameters() throws Exception {
|
||||
|
@ -800,7 +813,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
|
||||
//void f(
|
||||
// void f(
|
||||
IASTSimpleDeclaration f_decl = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
IASTStandardFunctionDeclarator dtor = (IASTStandardFunctionDeclarator) f_decl
|
||||
|
@ -811,7 +824,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTDeclarator paramDtor = param1.getDeclarator();
|
||||
IASTName name_param1 = paramDtor.getName();
|
||||
|
||||
//void f(
|
||||
// void f(
|
||||
IASTFunctionDefinition f_defn = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[1];
|
||||
assertTrue(f_defn.getDeclarator() instanceof IASTStandardFunctionDeclarator);
|
||||
|
@ -831,7 +844,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
.getExpression();
|
||||
IASTName name_param3 = idexp.getName();
|
||||
|
||||
//bindings
|
||||
// bindings
|
||||
IParameter param_1 = (IParameter) name_param3.resolveBinding();
|
||||
IParameter param_2 = (IParameter) name_param2.resolveBinding();
|
||||
IParameter param_3 = (IParameter) name_param1.resolveBinding();
|
||||
|
@ -932,14 +945,14 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
|
||||
//void f();
|
||||
// void f();
|
||||
IASTSimpleDeclaration fdecl = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) fdecl
|
||||
.getDeclarators()[0];
|
||||
IASTName name_f = fdtor.getName();
|
||||
|
||||
//void g() {
|
||||
// void g() {
|
||||
IASTFunctionDefinition gdef = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[1];
|
||||
|
||||
|
@ -954,14 +967,14 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTName name_fcall = fcall_id.getName();
|
||||
assertNull(fcall.getParameterExpression());
|
||||
|
||||
//void f() {}
|
||||
// void f() {}
|
||||
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[2];
|
||||
assertTrue(fdef.getDeclarator() instanceof IASTStandardFunctionDeclarator);
|
||||
fdtor = (IASTStandardFunctionDeclarator) fdef.getDeclarator();
|
||||
IASTName name_fdef = fdtor.getName();
|
||||
|
||||
//bindings
|
||||
// bindings
|
||||
IFunction function_1 = (IFunction) name_fcall.resolveBinding();
|
||||
IFunction function_2 = (IFunction) name_f.resolveBinding();
|
||||
IFunction function_3 = (IFunction) name_fdef.resolveBinding();
|
||||
|
@ -1002,7 +1015,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
|
||||
//void f() {
|
||||
// void f() {
|
||||
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[0];
|
||||
IASTCompoundStatement compound = (IASTCompoundStatement) fdef.getBody();
|
||||
|
@ -1036,7 +1049,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTIdExpression id_i3 = (IASTIdExpression) exprSt.getExpression();
|
||||
IASTName name_i4 = id_i3.getName();
|
||||
|
||||
//bindings
|
||||
// bindings
|
||||
IVariable var_1 = (IVariable) name_i4.resolveBinding();
|
||||
IVariable var_2 = (IVariable) name_i.resolveBinding();
|
||||
IVariable var_3 = (IVariable) name_i2.resolveBinding();
|
||||
|
@ -1142,7 +1155,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
|
||||
CNameCollector collector = new CNameCollector();
|
||||
tu.accept( collector);
|
||||
tu.accept(collector);
|
||||
|
||||
assertEquals(collector.size(), 3);
|
||||
IFunction function = (IFunction) collector.getName(0).resolveBinding();
|
||||
|
@ -1388,56 +1401,6 @@ public class AST2Tests extends AST2BaseTest {
|
|||
.resolveBinding());
|
||||
assertEquals(decls.length, 1);
|
||||
assertEquals(decls[0], f.getNestedDeclarator().getName());
|
||||
|
||||
tu = parse("int (*pfi)();", ParserLanguage.CPP); //$NON-NLS-1$
|
||||
assertEquals(tu.getDeclarations().length, 1);
|
||||
d = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
assertEquals(d.getDeclarators().length, 1);
|
||||
f = (IASTStandardFunctionDeclarator) d.getDeclarators()[0];
|
||||
assertEquals(f.getName().toString(), "");
|
||||
assertNotNull(f.getNestedDeclarator());
|
||||
assertEquals(f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testBasicPointerToMember() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer("class X {\n"); //$NON-NLS-1$
|
||||
buffer.append(" public:\n"); //$NON-NLS-1$
|
||||
buffer.append(" void f(int);\n"); //$NON-NLS-1$
|
||||
buffer.append(" int a;\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("int X:: * pmi = &X::a;\n"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
assertEquals(tu.getDeclarations().length, 2);
|
||||
IASTSimpleDeclaration p2m = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[1];
|
||||
IASTDeclarator d = p2m.getDeclarators()[0];
|
||||
ICPPASTPointerToMember po = (ICPPASTPointerToMember) d
|
||||
.getPointerOperators()[0];
|
||||
assertEquals(po.getName().toString(), "X::"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testAmbiguity() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("class A { };\n"); //$NON-NLS-1$
|
||||
buffer.append("int f() { \n"); //$NON-NLS-1$
|
||||
buffer.append(" A * b = 0;\n"); //$NON-NLS-1$
|
||||
buffer.append(" A & c = 0;\n"); //$NON-NLS-1$
|
||||
buffer.append("}"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
IASTSimpleDeclaration A = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTFunctionDefinition f = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[1];
|
||||
IASTCompoundStatement body = (IASTCompoundStatement) f.getBody();
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
IASTDeclarationStatement ds = (IASTDeclarationStatement) body
|
||||
.getStatements()[i];
|
||||
String s1 = ((IASTNamedTypeSpecifier) ((IASTSimpleDeclaration) ds
|
||||
.getDeclaration()).getDeclSpecifier()).getName().toString();
|
||||
String s2 = ((IASTCompositeTypeSpecifier) A.getDeclSpecifier())
|
||||
.getName().toString();
|
||||
assertEquals(s1, s2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testBasicTypes() throws Exception {
|
||||
|
@ -1712,7 +1675,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
.getDeclSpecifier();
|
||||
ICompositeType A = (ICompositeType) elabSpec.getName().resolveBinding();
|
||||
IASTName name_A1 = elabSpec.getName();
|
||||
assertTrue( name_A1.isDeclaration() );
|
||||
assertTrue(name_A1.isDeclaration());
|
||||
|
||||
decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
|
||||
IFunction f = (IFunction) decl.getDeclarators()[0].getName()
|
||||
|
@ -1756,7 +1719,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertTrue(t_f_params[0] instanceof IBasicType);
|
||||
assertTrue(t_f_params[1] instanceof IBasicType);
|
||||
|
||||
//g is a pointer to a function that returns void and has 1 parameter
|
||||
// g is a pointer to a function that returns void and has 1 parameter
|
||||
// struct A *
|
||||
IType t_g = g.getType();
|
||||
assertTrue(t_g instanceof IPointerType);
|
||||
|
@ -1770,8 +1733,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertTrue(t_g_func_p1 instanceof IPointerType);
|
||||
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
|
||||
// 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 *h function takes 1 parameter struct A**
|
||||
IType t_h = h.getType();
|
||||
|
@ -1881,7 +1844,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
.getDesignators()[0]).getName();
|
||||
|
||||
// test bug 87649
|
||||
assertEquals(((ASTNode)(ICASTDesignatedInitializer) initializers1[0]).getLength(), 7);
|
||||
assertEquals(((ASTNode) (ICASTDesignatedInitializer) initializers1[0])
|
||||
.getLength(), 7);
|
||||
|
||||
IASTName name_x2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers1[1])
|
||||
.getDesignators()[0]).getName();
|
||||
|
@ -2513,7 +2477,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col);
|
||||
tu.accept(col);
|
||||
|
||||
IVariable a = (IVariable) col.getName(1).resolveBinding();
|
||||
assertNotNull(a);
|
||||
|
@ -2534,7 +2498,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col);
|
||||
tu.accept(col);
|
||||
|
||||
IVariable a = (IVariable) col.getName(1).resolveBinding();
|
||||
IFunction g = (IFunction) col.getName(2).resolveBinding();
|
||||
|
@ -2557,7 +2521,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col);
|
||||
tu.accept(col);
|
||||
|
||||
assertEquals(col.size(), 9);
|
||||
IField x = (IField) col.getName(1).resolveBinding();
|
||||
|
@ -2579,7 +2543,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col);
|
||||
tu.accept(col);
|
||||
|
||||
assertEquals(col.size(), 6);
|
||||
IEnumerator one = (IEnumerator) col.getName(1).resolveBinding();
|
||||
|
@ -2602,17 +2566,19 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
IASTIfStatement if_statement = (IASTIfStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) tu
|
||||
.getDeclarations()[0]).getBody()).getStatements()[0];
|
||||
assertEquals(((IASTBinaryExpression) if_statement.getConditionExpression())
|
||||
.getOperator(), IASTBinaryExpression.op_equals);
|
||||
assertEquals(((IASTBinaryExpression) if_statement
|
||||
.getConditionExpression()).getOperator(),
|
||||
IASTBinaryExpression.op_equals);
|
||||
IASTIfStatement second_if_statement = (IASTIfStatement) if_statement
|
||||
.getElseClause();
|
||||
assertEquals(
|
||||
((IASTBinaryExpression) second_if_statement.getConditionExpression())
|
||||
.getOperator(), IASTBinaryExpression.op_lessThan);
|
||||
assertEquals(((IASTBinaryExpression) second_if_statement
|
||||
.getConditionExpression()).getOperator(),
|
||||
IASTBinaryExpression.op_lessThan);
|
||||
IASTIfStatement third_if_statement = (IASTIfStatement) second_if_statement
|
||||
.getElseClause();
|
||||
assertEquals(((IASTBinaryExpression) third_if_statement.getConditionExpression())
|
||||
.getOperator(), IASTBinaryExpression.op_greaterThan);
|
||||
assertEquals(((IASTBinaryExpression) third_if_statement
|
||||
.getConditionExpression()).getOperator(),
|
||||
IASTBinaryExpression.op_greaterThan);
|
||||
}
|
||||
|
||||
public void testBug84090_LabelReferences() throws Exception {
|
||||
|
@ -2626,7 +2592,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col);
|
||||
tu.accept(col);
|
||||
|
||||
assertEquals(col.size(), 3);
|
||||
ILabel end = (ILabel) col.getName(1).resolveBinding();
|
||||
|
@ -2643,7 +2609,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector collector = new CNameCollector();
|
||||
tu.accept( collector);
|
||||
tu.accept(collector);
|
||||
|
||||
assertEquals(collector.size(), 5);
|
||||
IEnumeration col = (IEnumeration) collector.getName(0).resolveBinding();
|
||||
|
@ -2657,7 +2623,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTTranslationUnit tu = parse(
|
||||
"struct s { int a; } ss = { .a = 1 }; \n", ParserLanguage.C); //$NON-NLS-1$
|
||||
CNameCollector collector = new CNameCollector();
|
||||
tu.accept( collector);
|
||||
tu.accept(collector);
|
||||
|
||||
assertEquals(collector.size(), 4);
|
||||
IField a = (IField) collector.getName(1).resolveBinding();
|
||||
|
@ -2683,7 +2649,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col);
|
||||
tu.accept(col);
|
||||
|
||||
assertEquals(col.size(), 3);
|
||||
IEnumeration e = (IEnumeration) col.getName(0).resolveBinding();
|
||||
|
@ -2703,7 +2669,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col);
|
||||
tu.accept(col);
|
||||
|
||||
assertEquals(col.size(), 3);
|
||||
IVariable p = (IVariable) col.getName(1).resolveBinding();
|
||||
|
@ -2724,7 +2690,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col);
|
||||
tu.accept(col);
|
||||
|
||||
assertEquals(col.size(), 3);
|
||||
|
||||
|
@ -2755,7 +2721,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col);
|
||||
tu.accept(col);
|
||||
|
||||
assertEquals(col.size(), 7);
|
||||
|
||||
|
@ -2775,7 +2741,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
public void testBug84266_2() throws Exception {
|
||||
IASTTranslationUnit tu = parse("struct s f(void);", ParserLanguage.C); //$NON-NLS-1$
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col);
|
||||
tu.accept(col);
|
||||
|
||||
assertEquals(col.size(), 3);
|
||||
|
||||
|
@ -2784,7 +2750,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
tu = parse("struct s f(void){}", ParserLanguage.C); //$NON-NLS-1$
|
||||
col = new CNameCollector();
|
||||
tu.accept( col);
|
||||
tu.accept(col);
|
||||
|
||||
assertEquals(col.size(), 3);
|
||||
|
||||
|
@ -2804,7 +2770,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col);
|
||||
tu.accept(col);
|
||||
|
||||
assertEquals(col.size(), 6);
|
||||
|
||||
|
@ -2831,7 +2797,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col);
|
||||
tu.accept(col);
|
||||
|
||||
assertEquals(col.size(), 11);
|
||||
|
||||
|
@ -2860,7 +2826,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col);
|
||||
tu.accept(col);
|
||||
|
||||
assertEquals(col.size(), 13);
|
||||
|
||||
|
@ -2894,135 +2860,79 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
}
|
||||
|
||||
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$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col);
|
||||
|
||||
assertEquals(col.size(), 26);
|
||||
|
||||
ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding();
|
||||
ICPPClassType B = (ICPPClassType) col.getName(2).resolveBinding();
|
||||
|
||||
assertNotNull(A);
|
||||
assertNotNull(B);
|
||||
|
||||
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 );
|
||||
IASTTranslationUnit t = parse(buffer.toString(), ParserLanguage.C);
|
||||
IASTFunctionDefinition g = (IASTFunctionDefinition) t.getDeclarations()[1];
|
||||
IASTCompoundStatement body = (IASTCompoundStatement) g.getBody();
|
||||
final IASTStatement statement = body.getStatements()[0];
|
||||
assertTrue(statement instanceof IASTDeclarationStatement);
|
||||
IASTSimpleDeclaration bp = (IASTSimpleDeclaration) ((IASTDeclarationStatement)statement).getDeclaration();
|
||||
assertTrue( bp.getDeclarators()[0].getName().resolveBinding() instanceof IVariable );
|
||||
IASTSimpleDeclaration bp = (IASTSimpleDeclaration) ((IASTDeclarationStatement) statement)
|
||||
.getDeclaration();
|
||||
assertTrue(bp.getDeclarators()[0].getName().resolveBinding() instanceof IVariable);
|
||||
|
||||
}
|
||||
|
||||
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$
|
||||
|
||||
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();
|
||||
|
||||
assertEquals(dynamic_cast.getOperator(),
|
||||
ICPPASTCastExpression.op_dynamic_cast);
|
||||
|
||||
}
|
||||
|
||||
public void testBug86766() throws Exception {
|
||||
IASTTranslationUnit tu = parse("char foo; void foo(){}", ParserLanguage.C); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(
|
||||
"char foo; void foo(){}", ParserLanguage.C); //$NON-NLS-1$
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col);
|
||||
tu.accept(col);
|
||||
|
||||
IVariable foo = (IVariable) col.getName(0).resolveBinding();
|
||||
IProblemBinding prob = (IProblemBinding) col.getName(1).resolveBinding();
|
||||
assertEquals( prob.getID(), IProblemBinding.SEMANTIC_INVALID_OVERLOAD );
|
||||
assertNotNull( foo );
|
||||
IProblemBinding prob = (IProblemBinding) col.getName(1)
|
||||
.resolveBinding();
|
||||
assertEquals(prob.getID(), IProblemBinding.SEMANTIC_INVALID_OVERLOAD);
|
||||
assertNotNull(foo);
|
||||
}
|
||||
|
||||
public void testBug88338_CPP() throws Exception {
|
||||
IASTTranslationUnit tu = parse( "struct A; struct A* a;", ParserLanguage.CPP ); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
assertTrue( col.getName(0).isDeclaration() );
|
||||
assertFalse( col.getName(0).isReference() );
|
||||
assertTrue( col.getName(1).isReference() );
|
||||
assertFalse( col.getName(1).isDeclaration() );
|
||||
|
||||
tu = parse( "struct A* a;", ParserLanguage.CPP ); //$NON-NLS-1$
|
||||
col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
assertTrue( col.getName(0).isDeclaration() );
|
||||
assertFalse( col.getName(0).isReference() );
|
||||
|
||||
}
|
||||
|
||||
public void testBug88338_C() throws Exception {
|
||||
IASTTranslationUnit tu = parse( "struct A; struct A* a;", ParserLanguage.C ); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(
|
||||
"struct A; struct A* a;", ParserLanguage.C); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
tu.accept(col);
|
||||
|
||||
assertTrue( col.getName(0).isDeclaration() );
|
||||
assertFalse( col.getName(0).isReference() );
|
||||
assertTrue( col.getName(1).isReference() );
|
||||
assertFalse( col.getName(1).isDeclaration() );
|
||||
assertTrue(col.getName(0).isDeclaration());
|
||||
assertFalse(col.getName(0).isReference());
|
||||
assertTrue(col.getName(1).isReference());
|
||||
assertFalse(col.getName(1).isDeclaration());
|
||||
|
||||
tu = parse( "struct A* a; struct A;", ParserLanguage.C ); //$NON-NLS-1$
|
||||
tu = parse("struct A* a; struct A;", ParserLanguage.C); //$NON-NLS-1$
|
||||
col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
tu.accept(col);
|
||||
|
||||
col.getName(2).resolveBinding();
|
||||
|
||||
assertTrue( col.getName(0).isDeclaration() );
|
||||
assertFalse( col.getName(0).isReference() );
|
||||
assertTrue(col.getName(0).isDeclaration());
|
||||
assertFalse(col.getName(0).isReference());
|
||||
|
||||
assertTrue( col.getName(2).isDeclaration() );
|
||||
assertFalse( col.getName(2).isReference() );
|
||||
assertTrue(col.getName(2).isDeclaration());
|
||||
assertFalse(col.getName(2).isReference());
|
||||
}
|
||||
|
||||
public void test88460() throws Exception {
|
||||
IASTTranslationUnit tu = parse( "void f();", ParserLanguage.C ); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse("void f();", ParserLanguage.C); //$NON-NLS-1$
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col );
|
||||
tu.accept(col);
|
||||
|
||||
IFunction f = (IFunction) col.getName(0).resolveBinding();
|
||||
assertFalse( f.isStatic() );
|
||||
assertFalse(f.isStatic());
|
||||
}
|
||||
|
||||
public void testBug90253() throws Exception {
|
||||
IASTTranslationUnit tu = parse( "void f(int par) { int v1; };", ParserLanguage.C ); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(
|
||||
"void f(int par) { int v1; };", ParserLanguage.C); //$NON-NLS-1$
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col );
|
||||
tu.accept(col);
|
||||
|
||||
IFunction f = (IFunction) col.getName(0).resolveBinding();
|
||||
IParameter p = (IParameter) col.getName(1).resolveBinding();
|
||||
|
@ -3030,29 +2940,29 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IScope scope = f.getFunctionScope();
|
||||
|
||||
IBinding [] bs = scope.find( "par" ); //$NON-NLS-1$
|
||||
assertEquals( bs.length, 1 );
|
||||
assertSame( bs[0], p );
|
||||
IBinding[] bs = scope.find("par"); //$NON-NLS-1$
|
||||
assertEquals(bs.length, 1);
|
||||
assertSame(bs[0], p);
|
||||
|
||||
bs = scope.find( "v1" ); //$NON-NLS-1$
|
||||
assertEquals( bs.length, 1 );
|
||||
assertSame( bs[0], v1 );
|
||||
bs = scope.find("v1"); //$NON-NLS-1$
|
||||
assertEquals(bs.length, 1);
|
||||
assertSame(bs[0], v1);
|
||||
}
|
||||
|
||||
public void testFind() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "struct S {}; \n"); //$NON-NLS-1$
|
||||
buffer.append( "int S; \n"); //$NON-NLS-1$
|
||||
buffer.append( "void f( ) { \n"); //$NON-NLS-1$
|
||||
buffer.append( " int S; \n"); //$NON-NLS-1$
|
||||
buffer.append( " { \n"); //$NON-NLS-1$
|
||||
buffer.append( " S : ; \n"); //$NON-NLS-1$
|
||||
buffer.append( " } \n"); //$NON-NLS-1$
|
||||
buffer.append( "} \n"); //$NON-NLS-1$
|
||||
buffer.append("struct S {}; \n"); //$NON-NLS-1$
|
||||
buffer.append("int S; \n"); //$NON-NLS-1$
|
||||
buffer.append("void f( ) { \n"); //$NON-NLS-1$
|
||||
buffer.append(" int S; \n"); //$NON-NLS-1$
|
||||
buffer.append(" { \n"); //$NON-NLS-1$
|
||||
buffer.append(" S : ; \n"); //$NON-NLS-1$
|
||||
buffer.append(" } \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col );
|
||||
tu.accept(col);
|
||||
|
||||
ICompositeType S1 = (ICompositeType) col.getName(0).resolveBinding();
|
||||
IVariable S2 = (IVariable) col.getName(1).resolveBinding();
|
||||
|
@ -3062,73 +2972,73 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IScope scope = f.getFunctionScope();
|
||||
|
||||
IBinding [] bs = scope.find( "S" ); //$NON-NLS-1$
|
||||
IBinding[] bs = scope.find("S"); //$NON-NLS-1$
|
||||
|
||||
assertNotNull( S2 );
|
||||
assertEquals( bs.length, 3 );
|
||||
assertSame( bs[0], S3 );
|
||||
assertSame( bs[1], S1 );
|
||||
assertSame( bs[2], S4 );
|
||||
assertNotNull(S2);
|
||||
assertEquals(bs.length, 3);
|
||||
assertSame(bs[0], S3);
|
||||
assertSame(bs[1], S1);
|
||||
assertSame(bs[2], S4);
|
||||
}
|
||||
|
||||
public void test92791() throws Exception {
|
||||
IASTTranslationUnit tu = parse( "void f() { int x, y; x * y; }", ParserLanguage.C ); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(
|
||||
"void f() { int x, y; x * y; }", ParserLanguage.C); //$NON-NLS-1$
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept( col );
|
||||
for( int i = 0; i < col.size(); ++i )
|
||||
assertFalse( col.getName( i ).resolveBinding() instanceof IProblemBinding );
|
||||
tu.accept(col);
|
||||
for (int i = 0; i < col.size(); ++i)
|
||||
assertFalse(col.getName(i).resolveBinding() instanceof IProblemBinding);
|
||||
|
||||
tu = parse( "void f() { typedef int x; int y; x * y; }", ParserLanguage.C ); //$NON-NLS-1$
|
||||
tu = parse(
|
||||
"void f() { typedef int x; int y; x * y; }", ParserLanguage.C); //$NON-NLS-1$
|
||||
col = new CNameCollector();
|
||||
tu.accept( col );
|
||||
for( int i = 0; i < col.size(); ++i )
|
||||
assertFalse( col.getName( i ).resolveBinding() instanceof IProblemBinding );
|
||||
tu.accept(col);
|
||||
for (int i = 0; i < col.size(); ++i)
|
||||
assertFalse(col.getName(i).resolveBinding() instanceof IProblemBinding);
|
||||
|
||||
}
|
||||
|
||||
public void testBug85786() throws Exception {
|
||||
IASTTranslationUnit tu = parse( "void f( int ); void foo () { void * p = &f; ( (void (*) (int)) p ) ( 1 ); }", ParserLanguage.C ); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(
|
||||
"void f( int ); void foo () { void * p = &f; ( (void (*) (int)) p ) ( 1 ); }", ParserLanguage.C); //$NON-NLS-1$
|
||||
CNameCollector nameResolver = new CNameCollector();
|
||||
tu.accept( nameResolver );
|
||||
assertNoProblemBindings( nameResolver );
|
||||
tu.accept(nameResolver);
|
||||
assertNoProblemBindings(nameResolver);
|
||||
}
|
||||
|
||||
protected void assertNoProblemBindings(CNameCollector col) {
|
||||
Iterator i = col.nameList.iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
while (i.hasNext()) {
|
||||
IASTName n = (IASTName) i.next();
|
||||
assertFalse( n.resolveBinding() instanceof IProblemBinding );
|
||||
assertFalse(n.resolveBinding() instanceof IProblemBinding);
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertProblemBindings(CNameCollector col, int count ) {
|
||||
protected void assertProblemBindings(CNameCollector col, int count) {
|
||||
Iterator i = col.nameList.iterator();
|
||||
int sum = 0;
|
||||
while( i.hasNext() )
|
||||
{
|
||||
while (i.hasNext()) {
|
||||
IASTName n = (IASTName) i.next();
|
||||
if( n.getBinding() instanceof IProblemBinding )
|
||||
if (n.getBinding() instanceof IProblemBinding)
|
||||
++sum;
|
||||
}
|
||||
assertEquals( count, sum );
|
||||
assertEquals(count, sum);
|
||||
}
|
||||
|
||||
public void testBug94365() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "#define ONE(a, ...) int x\n"); //$NON-NLS-1$
|
||||
buffer.append( "#define TWO(b, args...) int y\n"); //$NON-NLS-1$
|
||||
buffer.append( "int main()\n"); //$NON-NLS-1$
|
||||
buffer.append( "{\n"); //$NON-NLS-1$
|
||||
buffer.append( "ONE(\"string\"); /* err */\n"); //$NON-NLS-1$
|
||||
buffer.append( "TWO(\"string\"); /* err */\n"); //$NON-NLS-1$
|
||||
buffer.append( "return 0; \n"); //$NON-NLS-1$
|
||||
buffer.append( "}\n"); //$NON-NLS-1$
|
||||
buffer.append("#define ONE(a, ...) int x\n"); //$NON-NLS-1$
|
||||
buffer.append("#define TWO(b, args...) int y\n"); //$NON-NLS-1$
|
||||
buffer.append("int main()\n"); //$NON-NLS-1$
|
||||
buffer.append("{\n"); //$NON-NLS-1$
|
||||
buffer.append("ONE(\"string\"); /* err */\n"); //$NON-NLS-1$
|
||||
buffer.append("TWO(\"string\"); /* err */\n"); //$NON-NLS-1$
|
||||
buffer.append("return 0; \n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
|
||||
parse( buffer.toString(), ParserLanguage.C );
|
||||
parse(buffer.toString(), ParserLanguage.C);
|
||||
}
|
||||
|
||||
|
||||
public void testBug95119() throws Exception {
|
||||
StringBuffer buff = new StringBuffer();
|
||||
buff.append("#define MACRO(a)\n"); //$NON-NLS-1$
|
||||
|
@ -3138,11 +3048,13 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IASTTranslationUnit tu = parse(buff.toString(), ParserLanguage.C);
|
||||
IASTDeclaration[] declarations = tu.getDeclarations();
|
||||
assertEquals( declarations.length, 1 );
|
||||
assertNotNull( declarations[0] );
|
||||
assertTrue( declarations[0] instanceof IASTFunctionDefinition );
|
||||
assertEquals( ((IASTFunctionDefinition)declarations[0]).getDeclarator().getName().toString(), "main");
|
||||
assertTrue( ((IASTCompoundStatement)((IASTFunctionDefinition)declarations[0]).getBody()).getStatements()[0] instanceof IASTNullStatement );
|
||||
assertEquals(declarations.length, 1);
|
||||
assertNotNull(declarations[0]);
|
||||
assertTrue(declarations[0] instanceof IASTFunctionDefinition);
|
||||
assertEquals(((IASTFunctionDefinition) declarations[0]).getDeclarator()
|
||||
.getName().toString(), "main");
|
||||
assertTrue(((IASTCompoundStatement) ((IASTFunctionDefinition) declarations[0])
|
||||
.getBody()).getStatements()[0] instanceof IASTNullStatement);
|
||||
|
||||
buff = new StringBuffer();
|
||||
buff.append("#define MACRO(a)\n"); //$NON-NLS-1$
|
||||
|
@ -3152,11 +3064,19 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
tu = parse(buff.toString(), ParserLanguage.C);
|
||||
declarations = tu.getDeclarations();
|
||||
assertEquals( declarations.length, 1 );
|
||||
assertNotNull( declarations[0] );
|
||||
assertTrue( declarations[0] instanceof IASTFunctionDefinition );
|
||||
assertEquals( ((IASTFunctionDefinition)declarations[0]).getDeclarator().getName().toString(), "main");
|
||||
assertTrue( ((IASTCompoundStatement)((IASTFunctionDefinition)declarations[0]).getBody()).getStatements()[0] instanceof IASTNullStatement );
|
||||
assertEquals(declarations.length, 1);
|
||||
assertNotNull(declarations[0]);
|
||||
assertTrue(declarations[0] instanceof IASTFunctionDefinition);
|
||||
assertEquals(((IASTFunctionDefinition) declarations[0]).getDeclarator()
|
||||
.getName().toString(), "main");
|
||||
assertTrue(((IASTCompoundStatement) ((IASTFunctionDefinition) declarations[0])
|
||||
.getBody()).getStatements()[0] instanceof IASTNullStatement);
|
||||
}
|
||||
|
||||
public void testBug81739() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer("typedef long _TYPE;\n"); //$NON-NLS-1$
|
||||
buffer.append("typedef _TYPE TYPE;\n"); //$NON-NLS-1$
|
||||
buffer.append("int function(TYPE (* pfv)(int parm));\n"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
}
|
||||
}
|
|
@ -868,16 +868,16 @@ public class QuickParser2Tests extends TestCase {
|
|||
parse(code.toString(), false);
|
||||
}
|
||||
|
||||
public void testBug36247() throws Exception {
|
||||
Writer code = new StringWriter();
|
||||
code.write("class A {\n"); //$NON-NLS-1$
|
||||
code.write("INLINE_DEF int f ();\n"); //$NON-NLS-1$
|
||||
code.write("INLINE_DEF A g ();"); //$NON-NLS-1$
|
||||
code.write("INLINE_DEF A * h ();"); //$NON-NLS-1$
|
||||
code.write("INLINE_DEF A & unlock( void );"); //$NON-NLS-1$
|
||||
code.write("};"); //$NON-NLS-1$
|
||||
parse(code.toString());
|
||||
}
|
||||
// public void testBug36247() throws Exception {
|
||||
// Writer code = new StringWriter();
|
||||
// code.write("class A {\n"); //$NON-NLS-1$
|
||||
// code.write("INLINE_DEF int f ();\n"); //$NON-NLS-1$
|
||||
// code.write("INLINE_DEF A g ();"); //$NON-NLS-1$
|
||||
// code.write("INLINE_DEF A * h ();"); //$NON-NLS-1$
|
||||
// code.write("INLINE_DEF A & unlock( void );"); //$NON-NLS-1$
|
||||
// code.write("};"); //$NON-NLS-1$
|
||||
// parse(code.toString());
|
||||
// }
|
||||
|
||||
public void testStruct() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
|
|
|
@ -42,7 +42,7 @@ public class BasicCompletionTest extends CompletionTestBase {
|
|||
ASTCompletionNode node = getGPPCompletionNode(code.toString());
|
||||
IASTName[] names = node.getNames();
|
||||
// There are three names, one as an expression, one that isn't connected, one as a declaration
|
||||
assertEquals(3, names.length);
|
||||
assertEquals(4, names.length);
|
||||
// The expression points to our functions
|
||||
IBinding[] bindings = names[0].resolvePrefix();
|
||||
// There should be two since they both start with fu
|
||||
|
@ -79,9 +79,9 @@ public class BasicCompletionTest extends CompletionTestBase {
|
|||
// C++
|
||||
ASTCompletionNode node = getGPPCompletionNode(code.toString());
|
||||
IASTName[] names = node.getNames();
|
||||
assertEquals(2, names.length);
|
||||
assertEquals(3, names.length);
|
||||
assertNull(names[0].getTranslationUnit());
|
||||
IBinding[] bindings = names[1].resolvePrefix();
|
||||
IBinding[] bindings = names[2].resolvePrefix();
|
||||
assertEquals(1, bindings.length);
|
||||
assertEquals("blah", ((ITypedef)bindings[0]).getName());
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
|
@ -1037,18 +1038,83 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
return compoundStatement();
|
||||
}
|
||||
|
||||
protected abstract IASTDeclarator initDeclarator() throws EndOfFileException,
|
||||
BacktrackException;
|
||||
/**
|
||||
* @param flags
|
||||
* input flags that are used to make our decision
|
||||
* @return whether or not this looks like a a declarator follows
|
||||
* @throws
|
||||
* @throws EndOfFileException
|
||||
* we could encounter EOF while looking ahead
|
||||
*/
|
||||
protected boolean lookAheadForDeclarator(Flags flags)
|
||||
throws EndOfFileException {
|
||||
return flags.haveEncounteredTypename()
|
||||
&& ((LT(2) != IToken.tIDENTIFIER || (LT(3) != IToken.tLPAREN && LT(3) != IToken.tASSIGN)) && !LA(
|
||||
2).isPointer());
|
||||
{
|
||||
if( flags.typeId ) return false;
|
||||
IToken mark = null;
|
||||
try
|
||||
{
|
||||
mark = mark();
|
||||
}
|
||||
catch( EndOfFileException eof )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
IASTDeclarator d = initDeclarator();
|
||||
IToken la = LA(1);
|
||||
backup( mark );
|
||||
if( la == null || la.getType() == IToken.tEOC )
|
||||
return false;
|
||||
final ASTNode n = ((ASTNode)d);
|
||||
final int length = n.getLength();
|
||||
final int offset = n.getOffset();
|
||||
if( length == 0 )
|
||||
return false;
|
||||
if( flags.parm )
|
||||
{
|
||||
ASTNode name = (ASTNode)d.getName();
|
||||
if( name.getOffset() == offset && name.getLength() == length )
|
||||
return false;
|
||||
if( d.getInitializer() != null )
|
||||
{
|
||||
ASTNode init = (ASTNode) d.getInitializer();
|
||||
if( name.getOffset() == offset && n.getOffset() + n.getLength() == init.getOffset() + init.getLength() )
|
||||
return false;
|
||||
}
|
||||
|
||||
switch( la.getType() )
|
||||
{
|
||||
case IToken.tCOMMA:
|
||||
case IToken.tRPAREN:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
switch( la.getType() )
|
||||
{
|
||||
case IToken.tCOMMA:
|
||||
case IToken.tLBRACE:
|
||||
return true;
|
||||
case IToken.tSEMI:
|
||||
if( d instanceof IASTFieldDeclarator )
|
||||
return false;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch( BacktrackException bte )
|
||||
{
|
||||
backup( mark );
|
||||
return false;
|
||||
} catch (EndOfFileException e) {
|
||||
backup( mark );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Flags {
|
||||
|
@ -1058,19 +1124,21 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
private boolean encounteredRawType = false;
|
||||
|
||||
// have we encountered a raw type yet?
|
||||
private final boolean parm;
|
||||
boolean parm = false;
|
||||
|
||||
// is this for a simpleDeclaration or parameterDeclaration?
|
||||
private final boolean constructor;
|
||||
boolean constructor = false;
|
||||
boolean typeId = false;
|
||||
|
||||
// are we attempting the constructor strategy?
|
||||
public Flags(boolean parm, boolean c) {
|
||||
public Flags(boolean parm, boolean c, boolean t) {
|
||||
this.parm = parm;
|
||||
constructor = c;
|
||||
typeId =t;
|
||||
}
|
||||
|
||||
public Flags(boolean parm) {
|
||||
this(parm, false);
|
||||
public Flags(boolean parm, boolean typeId ) {
|
||||
this(parm, false, typeId );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -442,7 +442,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
firstToken = null; // necessary for scalability
|
||||
|
||||
IASTDeclSpecifier declSpec = declSpecifierSeq(false);
|
||||
IASTDeclSpecifier declSpec = declSpecifierSeq(false, false);
|
||||
|
||||
IASTDeclarator [] declarators = new IASTDeclarator[2];
|
||||
if (LT(1) != IToken.tSEMI) {
|
||||
|
@ -1203,7 +1203,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
IASTDeclarator declarator = null;
|
||||
|
||||
try {
|
||||
declSpecifier = declSpecifierSeq(false);
|
||||
declSpecifier = declSpecifierSeq(false, true);
|
||||
declarator = declarator();
|
||||
} catch (BacktrackException bt) {
|
||||
backup(mark);
|
||||
|
@ -1304,9 +1304,9 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return new CASTPointer();
|
||||
}
|
||||
|
||||
protected IASTDeclSpecifier declSpecifierSeq(boolean parm)
|
||||
protected IASTDeclSpecifier declSpecifierSeq(boolean parm, boolean forTypeId)
|
||||
throws BacktrackException, EndOfFileException {
|
||||
Flags flags = new Flags(parm);
|
||||
Flags flags = new Flags(parm,forTypeId);
|
||||
|
||||
int startingOffset = LA(1).getOffset();
|
||||
int storageClass = IASTDeclSpecifier.sc_unspecified;
|
||||
|
@ -1319,7 +1319,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
IASTElaboratedTypeSpecifier elabSpec = null;
|
||||
IASTEnumerationSpecifier enumSpec = null;
|
||||
IASTExpression typeofExpression = null;
|
||||
boolean isTypedef = false;
|
||||
IToken last = null;
|
||||
|
||||
declSpecifiers: for (;;) {
|
||||
|
@ -1342,7 +1341,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
last = consume();
|
||||
break;
|
||||
case IToken.t_typedef:
|
||||
isTypedef = true;
|
||||
storageClass = IASTDeclSpecifier.sc_typedef;
|
||||
last = consume();
|
||||
break;
|
||||
|
@ -1438,21 +1436,12 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
if (flags.haveEncounteredRawType()) {
|
||||
break declSpecifiers;
|
||||
}
|
||||
if (parm && flags.haveEncounteredTypename()) {
|
||||
if (flags.haveEncounteredTypename()) {
|
||||
break declSpecifiers;
|
||||
}
|
||||
if (lookAheadForDeclarator(flags)) {
|
||||
break declSpecifiers;
|
||||
}
|
||||
switch (LT(2)) {
|
||||
case IToken.tLPAREN:
|
||||
if (isTypedef)
|
||||
break;
|
||||
case IToken.tSEMI:
|
||||
case IToken.tASSIGN:
|
||||
// TODO more
|
||||
break declSpecifiers;
|
||||
}
|
||||
|
||||
identifier = identifier();
|
||||
last = identifier;
|
||||
|
@ -1930,10 +1919,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
break;
|
||||
}
|
||||
if (LA(1).getType() != IToken.tIDENTIFIER)
|
||||
break;
|
||||
|
||||
} while (true);
|
||||
} while (false);
|
||||
|
||||
IASTDeclarator d = null;
|
||||
if (numKnRCParms > 0) {
|
||||
|
@ -2165,7 +2152,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
throws BacktrackException, EndOfFileException {
|
||||
IToken current = LA(1);
|
||||
int startingOffset = current.getOffset();
|
||||
IASTDeclSpecifier declSpec = declSpecifierSeq(true);
|
||||
IASTDeclSpecifier declSpec = declSpecifierSeq(true, false);
|
||||
|
||||
IASTDeclarator declarator = null;
|
||||
if (LT(1) != IToken.tSEMI)
|
||||
|
|
|
@ -540,6 +540,16 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON) {
|
||||
try {
|
||||
nameDuple = name();
|
||||
if( nameDuple.length() == 1 )
|
||||
{
|
||||
backup(mark);
|
||||
return;
|
||||
}
|
||||
if( nameDuple.getLastToken().getType() != IToken.tCOLONCOLON )
|
||||
{
|
||||
backup(mark);
|
||||
return;
|
||||
}
|
||||
last = nameDuple.getLastToken();
|
||||
} catch (BacktrackException bt) {
|
||||
backup(mark);
|
||||
|
@ -931,7 +941,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
IASTDeclarator declarator = null;
|
||||
|
||||
try {
|
||||
declSpecifier = declSpecifierSeq(true, true);
|
||||
declSpecifier = declSpecifierSeq(true, true, true);
|
||||
if (LT(1) != IToken.tEOC)
|
||||
declarator = declarator(
|
||||
SimpleDeclarationStrategy.TRY_CONSTRUCTOR, forNewExpression);
|
||||
|
@ -2744,7 +2754,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
firstToken = null; // necessary for scalability
|
||||
|
||||
ICPPASTDeclSpecifier declSpec = declSpecifierSeq(false,
|
||||
strategy == SimpleDeclarationStrategy.TRY_CONSTRUCTOR);
|
||||
strategy == SimpleDeclarationStrategy.TRY_CONSTRUCTOR, false);
|
||||
IASTDeclarator[] declarators = new IASTDeclarator[2];
|
||||
if (LT(1) != IToken.tSEMI && LT(1) != IToken.tEOC) {
|
||||
declarators = (IASTDeclarator[]) ArrayUtil
|
||||
|
@ -3008,7 +3018,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
protected ICPPASTParameterDeclaration parameterDeclaration()
|
||||
throws BacktrackException, EndOfFileException {
|
||||
IToken current = LA(1);
|
||||
IASTDeclSpecifier declSpec = declSpecifierSeq(true, false);
|
||||
IASTDeclSpecifier declSpec = declSpecifierSeq(true, false, false);
|
||||
IASTDeclarator declarator = null;
|
||||
if (LT(1) != IToken.tSEMI)
|
||||
declarator = initDeclarator(SimpleDeclarationStrategy.TRY_FUNCTION);
|
||||
|
@ -3126,21 +3136,22 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
* enumSpecifier Notes: - folded in storageClassSpecifier, typeSpecifier,
|
||||
* functionSpecifier - folded elaboratedTypeSpecifier into classSpecifier
|
||||
* and enumSpecifier - find template names in name
|
||||
*
|
||||
* @param parm
|
||||
* Is this for a parameter declaration (true) or simple
|
||||
* declaration (false)
|
||||
* @param tryConstructor
|
||||
* true for constructor, false for pointer to function strategy
|
||||
* @param forTypeId TODO
|
||||
*
|
||||
* @return TODO
|
||||
* @throws BacktrackException
|
||||
* request a backtrack
|
||||
*/
|
||||
protected ICPPASTDeclSpecifier declSpecifierSeq(boolean parm,
|
||||
boolean tryConstructor) throws BacktrackException,
|
||||
boolean tryConstructor, boolean forTypeId) throws BacktrackException,
|
||||
EndOfFileException {
|
||||
IToken firstToken = LA(1);
|
||||
Flags flags = new Flags(parm, tryConstructor);
|
||||
Flags flags = new Flags(parm, tryConstructor, forTypeId );
|
||||
IToken last = null;
|
||||
|
||||
boolean isInline = false, isVirtual = false, isExplicit = false, isFriend = false;
|
||||
|
@ -3306,7 +3317,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
if (flags.haveEncounteredRawType())
|
||||
break declSpecifiers;
|
||||
|
||||
if (parm && flags.haveEncounteredTypename())
|
||||
if (flags.haveEncounteredTypename())
|
||||
break declSpecifiers;
|
||||
|
||||
if (lookAheadForConstructorOrOperator(flags))
|
||||
|
@ -3532,6 +3543,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return new CPPASTElaboratedTypeSpecifier();
|
||||
}
|
||||
|
||||
protected IASTDeclarator initDeclarator() throws EndOfFileException, BacktrackException {
|
||||
return initDeclarator( SimpleDeclarationStrategy.TRY_FUNCTION );
|
||||
}
|
||||
/**
|
||||
* Parses the initDeclarator construct of the ANSI C++ spec. initDeclarator :
|
||||
* declarator ("=" initializerClause | "(" expressionList ")")?
|
||||
|
@ -3920,10 +3934,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
break;
|
||||
}
|
||||
if (LA(1).getType() != IToken.tIDENTIFIER)
|
||||
break;
|
||||
|
||||
} while (true);
|
||||
} while (false);
|
||||
|
||||
IASTDeclarator d = null;
|
||||
if (isFunction) {
|
||||
|
|
Loading…
Add table
Reference in a new issue