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;
|
||||
|
@ -205,22 +202,30 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
// // test clearBindings
|
||||
// assertNotNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
|
||||
// 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$
|
||||
// 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$
|
||||
// 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$
|
||||
// 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$
|
||||
// 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$
|
||||
// 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$
|
||||
// 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$
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testSimpleStruct() throws Exception {
|
||||
|
@ -773,22 +778,30 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(decls[0], declaration2.getDeclarators()[0].getName());
|
||||
|
||||
// assertNotNull(((ICScope) tu.getScope()).getBinding(
|
||||
// ICScope.NAMESPACE_TYPE_TAG, new String("x").toCharArray())); //$NON-NLS-1$
|
||||
// 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$
|
||||
// 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$
|
||||
// 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$
|
||||
// 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$
|
||||
// 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$
|
||||
// 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$
|
||||
// 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$
|
||||
// ICScope.NAMESPACE_TYPE_OTHER, new String("i").toCharArray()));
|
||||
// //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testFunctionParameters() throws Exception {
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
|
@ -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 {
|
||||
|
@ -2894,35 +2860,7 @@ 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$
|
||||
|
@ -2934,61 +2872,32 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTCompoundStatement body = (IASTCompoundStatement) g.getBody();
|
||||
final IASTStatement statement = body.getStatements()[0];
|
||||
assertTrue(statement instanceof IASTDeclarationStatement);
|
||||
IASTSimpleDeclaration bp = (IASTSimpleDeclaration) ((IASTDeclarationStatement)statement).getDeclaration();
|
||||
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);
|
||||
|
||||
IVariable foo = (IVariable) col.getName(0).resolveBinding();
|
||||
IProblemBinding prob = (IProblemBinding) col.getName(1).resolveBinding();
|
||||
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);
|
||||
|
||||
|
@ -3020,7 +2929,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
|
@ -3072,13 +2982,15 @@ public class AST2Tests extends AST2BaseTest {
|
|||
}
|
||||
|
||||
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 = 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)
|
||||
|
@ -3087,7 +2999,8 @@ public class AST2Tests extends AST2BaseTest {
|
|||
}
|
||||
|
||||
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);
|
||||
|
@ -3095,8 +3008,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
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);
|
||||
}
|
||||
|
@ -3105,8 +3017,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
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)
|
||||
++sum;
|
||||
|
@ -3128,7 +3039,6 @@ public class AST2Tests extends AST2BaseTest {
|
|||
parse(buffer.toString(), ParserLanguage.C);
|
||||
}
|
||||
|
||||
|
||||
public void testBug95119() throws Exception {
|
||||
StringBuffer buff = new StringBuffer();
|
||||
buff.append("#define MACRO(a)\n"); //$NON-NLS-1$
|
||||
|
@ -3141,8 +3051,10 @@ public class AST2Tests extends AST2BaseTest {
|
|||
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(((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$
|
||||
|
@ -3155,8 +3067,16 @@ public class AST2Tests extends AST2BaseTest {
|
|||
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(((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