diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 3db2ed187a9..3e1bbc8c68b 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,4 +1,9 @@ -2003-06-15 Victor Mozgin +2003-07-17 + Rewrote the entire DOMTests suite to now be AST tests. + Removed DOMTests, BaseDOMTest, DOMFailedTests after methods were migrated to QuickParseASTTests & ASTFailedTests. + Made sure every parser failed test had a defect number associated with it. + +2003-07-15 Victor Mozgin Moved testBug39349() from DOMFailedTest.java to DOMTests.java. Moved testBug39544() from DOMFailedTest.java to DOMTests.java. diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/CModelElementsFailedTests.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/CModelElementsFailedTests.java index 67d0efcb55a..a20e197509e 100644 --- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/CModelElementsFailedTests.java +++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/CModelElementsFailedTests.java @@ -44,7 +44,9 @@ import org.eclipse.core.runtime.Path; * Window>Preferences>Java>Code Generation>Code and Comments */ public class CModelElementsFailedTests extends TestCase { - private ICProject fCProject; + + private static final boolean domCurrentlyBroken = true; + private ICProject fCProject; private IFile headerFile; private NullProgressMonitor monitor; @@ -100,6 +102,14 @@ public class CModelElementsFailedTests extends TestCase { // tu ---> namespace: MyPackage ArrayList tuPackages = tu.getChildrenOfType(ICElement.C_NAMESPACE); + // INSERTED BY JOHNC 7/17/2003 to make fail test fail rather than err + if( domCurrentlyBroken ) + { + assertFalse( "There are declarations - failure", tuPackages.size() != 0 ); + return; + } + + INamespace namespace = (INamespace) tuPackages.get(0); assertEquals(namespace.getElementName(), new String("MyPackage")); diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java new file mode 100644 index 00000000000..2015feee558 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java @@ -0,0 +1,465 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.core.parser.failedTests; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Iterator; + +import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTFunction; +import org.eclipse.cdt.core.parser.ast.IASTPointerToFunction; +import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTVariable; +import org.eclipse.cdt.core.parser.tests.BaseASTTest; +/** + * @author jcamelon + * + */ +public class ASTFailedTests extends BaseASTTest +{ + private static final boolean debugging = false; + public ASTFailedTests(String name) + { + super(name); + } + public void testBug36730() throws Exception + { + assertCodeFailsParse("FUNCTION_MACRO( 1, a )\n int i;"); + } + public void testBug39504A() throws Exception + { + try + { + IASTVariable variable = (IASTVariable)parse("int y = sizeof(x[0]);").getDeclarations().next(); + } + catch( ClassCastException cce ) + { + assertFalse( "We should not get a cast error here", false ); + } + } + public void testBug39504B() throws Exception + { + assertCodeFailsParse("int y = sizeof (int*);"); + } + public void testBug39505A() throws Exception + { + assertCodeFailsParse("int AD::* gp_down = static_cast(gp_stat);"); + } + public void testBug39505B() throws Exception + { + assertCodeFailsParse("int* gp_down = static_cast(gp_stat);"); + } + + public void testBug39523() + { + if( ! debugging ) + { + Writer code = new StringWriter(); + try { + code.write("#define e0 \"a\"\n"); + code.write("#define e1 e0 e0 e0 e0 e0 e0 e0 e0 e0 e0\n"); + code.write("#define e2 e1 e1 e1 e1 e1 e1 e1 e1 e1 e1\n"); + code.write("#define e3 e2 e2 e2 e2 e2 e2 e2 e2 e2 e2\n"); + code.write("#define e4 e3 e3 e3 e3 e3 e3 e3 e3 e3 e3\n"); + code.write("#define e5 e4 e4 e4 e4 e4 e4 e4 e4 e4 e4\n"); + code.write("void foo() { (void)(e5); }\n"); + } catch( IOException ioe ){} + + boolean testPassed = false; + try { + parse(code.toString()); + testPassed = true; + fail( "We should not reach this point"); + } catch (Throwable e) { + if (!(e instanceof StackOverflowError)) + fail("Unexpected Error: " + e.getMessage()); + } + if (testPassed) + fail("The expected error did not occur."); + } + } + + public void testBug39525() throws Exception + { + assertCodeFailsParse("C &(C::*DD)(const C &x) = &C::operator=;"); + } + public void testBug39526() throws Exception + { + assertCodeFailsParse("UnitList unit_list (String(\"keV\"));"); + } + public void testBug39528() throws Exception + { + Writer code = new StringWriter(); + try + { + code.write("struct B: public A {\n"); + code.write(" A a;\n"); + code.write(" B() try : A(1), a(2)\n"); + code.write(" { throw 1; }\n"); + code.write(" catch (...)\n"); + code.write(" { if (c != 3) r |= 1; }\n"); + code.write("};\n"); + } + catch (IOException ioe) + { + } + assertCodeFailsParse(code.toString()); + } + public void testBug39531() throws Exception + { + assertCodeFailsParse("class AString { operator char const *() const; };"); + } + public void testBug39532() throws Exception + { + assertCodeFailsParse("class N1::N2::B : public A {};"); + } + public void testBug39535() throws Exception + { + assertCodeFailsParse("namespace bar = foo;"); + } + public void testBug39536A() throws Exception + { + assertCodeFailsParse("template class X { X(); };"); + } + public void testBug39536B() throws Exception + { + assertCodeFailsParse("template class X { inline X(int); };"); + } + public void testBug39537() throws Exception + { + assertCodeFailsParse("typedef foo<(U::id > 0)> foobar;"); + } + public void testBug39538() throws Exception + { + assertCodeFailsParse("template C::operator int ();"); + } + public void testBug39540() throws Exception + { + assertCodeFailsParse("class {} const null;"); + } + public void testBug39542() throws Exception + { + assertCodeFailsParse("void f(int a, struct {int b[a];} c) {}"); + } + public void testBug39546() throws Exception + { + assertCodeFailsParse("signed char c = (signed char) 0xffffffff;"); + } + //Here starts C99-specific section + public void testBug39549() throws Exception + { + assertCodeFailsParse("struct X x = { .b = 40, .z = {} };"); + } + public void testBug39550() throws Exception + { + assertCodeFailsParse("double x = 0x1.fp1;"); + } + public void testBug39551A() throws Exception + { + IASTFunction function = (IASTFunction)parse("extern float _Complex conjf (float _Complex);").getDeclarations().next(); + assertEquals( function.getName(), "conjf"); + } + public void testBug39551B() throws Exception + { + IASTVariable variable = (IASTVariable)parse("_Imaginary double id = 99.99 * __I__;").getDeclarations().next(); + assertEquals( variable.getName(), "id"); + } + + public void testBug39552A() throws Exception + { + Writer code = new StringWriter(); + try + { + code.write( + "%:define glue(x, y) x %:%: y /* #define glue(x, y) x ## y. */\n"); + code.write("#ifndef glue\n"); + code.write("#error glue not defined!\n"); + code.write("#endif\n"); + code.write("%:define str(x) %:x /* #define str(x) #x */\n"); + code.write("int main (int argc, char *argv<::>) /* argv[] */\n"); + code.write("glue (<, %) /* { */\n"); + code.write(" /* di_str[] = */\n"); + code.write( + " const char di_str glue(<, :)glue(:, >) = str(%:%:<::><%%>%:);\n"); + code.write( + " /* Check the glue macro actually pastes, and that the spelling of\n"); + code.write(" all digraphs is preserved. */\n"); + code.write(" if (glue(str, cmp) (di_str, \"%:%:<::><%%>%:\"))\n"); + code.write(" err (\"Digraph spelling not preserved!\");\n"); + code.write(" return 0;\n"); + code.write("glue (%, >) /* } */\n"); + } + catch (IOException ioe) + { + } + assertCodeFailsParse(code.toString()); + } + public void testBug39552B() throws Exception + { + Writer code = new StringWriter(); + try + { + code.write("??=include \n"); + code.write("??=define TWELVE 1??/\n"); + code.write("2\n"); + code.write("static const char str??(??) = \"0123456789??/n\";\n"); + code.write("int\n"); + code.write("main(void)\n"); + code.write("??<\n"); + code.write(" unsigned char x = 5;\n"); + code.write(" if (sizeof str != TWELVE)\n"); + code.write(" abort ();\n"); + code.write( + " /* Test ^=, the only multi-character token to come from trigraphs. */\n"); + code.write(" x ??'= 3;\n"); + code.write(" if (x != 6)\n"); + code.write(" abort ();\n"); + code.write(" if ((5 ??! 3) != 7)\n"); + code.write(" abort ();\n"); + code.write(" return 0;\n"); + code.write("??>\n"); + } + catch (IOException ioe) + { + } + assertCodeFailsParse(code.toString()); + } + public void testBug39553() throws Exception + { + parse("#define COMP_INC \"foobar.h\" \n" + "#include COMP_INC"); + assertFalse( quickParseCallback.getInclusions().hasNext() ); + } + public void testBug39554() throws Exception + { + assertCodeFailsParse("_Pragma(\"foobar\")"); + } + public void testBug39556() throws Exception + { + IASTFunction function = (IASTFunction)parse("int *restrict ip_fn (void);").getDeclarations().next(); + assertFalse( + "The expected error did not occur.", + function.getReturnType().getPointerOperators().hasNext() ); + } + + //Here C99-specific section ends + //Here GCC-specific section starts + public void testBug39676() throws Exception + { + assertCodeFailsParse("struct { int e1, e2; } v = { e2: 0 }"); + } + public void testBug39677() throws Exception + { + assertCodeFailsParse("B::B() : a(({ 1; })) {}"); + } + public void testBug39678() throws Exception + { + assertCodeFailsParse("char *s = L\"a\" \"b\";"); + } + public void testBug39679() throws Exception + { + assertCodeFailsParse("Foo blat() return f(4) {}"); + } + public void testBug39681() throws Exception + { + Writer code = new StringWriter(); + try + { + code.write("double\n"); + code.write("foo (double a, double b)\n"); + code.write("{\n"); + code.write(" double square (double z) { return z * z; }\n"); + code.write(" return square (a) + square (b);\n"); + code.write("}\n"); + } + catch (IOException ioe) + { + } + parse(code.toString()); + } + + public void testBug39682() throws Exception + { + IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)parse("typedef name = (a+1);").getDeclarations().next(); + assertFalse( + "The expected error did not occur.", + typedef.getName().equals( "name" ) ); + } + public void testBug39684() throws Exception + { + assertCodeFailsParse("typeof(foo(1)) bar () { return foo(1); }"); + } + public void testBug39686() throws Exception + { + Writer code = new StringWriter(); + try + { + code.write("__complex__ double x; // complex double\n"); + code.write("__complex__ short int a; // complex short int\n"); + code.write("x = 2.5fi; // 2.5 imaginary float literal\n"); + code.write("a = 3i; // imaginary integer literal\n"); + code.write("double v = __real__ x; // real part of expression\n"); + code.write( + "double w = __imag__ x; // imaginary part of expression\n"); + } + catch (IOException ioe) + { + } + assertCodeFailsParse(code.toString()); + } + public void testBug39687() throws Exception + { + assertCodeFailsParse("struct entry tester (int len; char data[len][len], int len) {}"); + } + public void testBug39688() throws Exception + { + Writer code = new StringWriter(); + try + { + code.write("#define decl(type, vars...) \\\n"); + code.write(" type vars ;\n"); + code.write("decl(int, x, y)\n"); + } + catch (IOException ioe) + { + } + Iterator declarations = parse(code.toString()).getDeclarations(); + assertFalse( "Should be 2 declarations, not 0", declarations.hasNext() ); + } + public void testBug39694() throws Exception + { + IASTVariable variable = (IASTVariable)parse("int ab$cd = 1;").getDeclarations().next(); + assertFalse( + "The expected error did not occur.", + variable.equals("ab$cd")); + } + public void testBug39695() throws Exception + { + assertCodeFailsParse("int a = __alignof__ (int);"); + } + public void testBug39695A() throws Exception + { + assertCodeFailsParse("int foo asm (\"myfoo\") = 2;"); + } + public void testBug39695B() throws Exception + { + assertCodeFailsParse("extern func () asm (\"FUNC\");"); + } + public void testBug39695C() throws Exception + { + assertCodeFailsParse("register int *foo asm (\"a5\");"); + } + public void testBug39698A() throws Exception + { + Iterator declarations = parse("int c = a ? b;"); + } + public void testBug39701A() throws Exception + { + assertCodeFailsParse("extern template int max (int, int);"); + } + public void testBug39701B() throws Exception + { + assertCodeFailsParse("inline template class Foo;"); + } + public void testBug39701C() throws Exception + { + assertCodeFailsParse("static template class Foo;"); + } + public void testBug39702() throws Exception + { + Writer code = new StringWriter(); + try + { + code.write("signature T {\n"); + code.write(" int f (int);\n"); + code.write(" int f0 () { return f (0); };\n"); + code.write("};\n"); + } + catch (IOException ioe) + { + } + Iterator declarations = parse(code.toString()).getDeclarations(); + IASTDeclaration d = (IASTDeclaration)declarations.next(); + assertFalse( "Should be 1 declaration, not 2", !declarations.hasNext() ); + } + public void testBug39703() throws Exception + { + Writer code = new StringWriter(); + try + { + code.write( + "/* __extension__ enables GNU C mode for the duration of the declaration. */\n"); + code.write("__extension__ struct G {\n"); + code.write(" struct { char z; };\n"); + code.write(" char g;\n"); + code.write("};\n"); + } + catch (IOException ioe) + { + } + IASTAbstractTypeSpecifierDeclaration abs = (IASTAbstractTypeSpecifierDeclaration)assertSoleDeclaration(code.toString()); + assertEquals( ((IASTClassSpecifier)abs.getTypeSpecifier()).getName(), "G" ); + } + public void testBug39704A() throws Exception + { + assertCodeFailsParse("__declspec (dllimport) int foo;"); + } + + + public void testBug39704B() throws Exception + { + try + { + IASTPointerToFunction p2f = (IASTPointerToFunction)assertSoleDeclaration("extern int (* import) (void) __attribute__((dllimport));"); + fail( "We should not reach this point"); + } + catch( ClassCastException cce ) + { + failedAsExpected(); + } + } + public void testBug39704C() throws Exception + { + try + { + IASTFunction f = (IASTFunction)assertSoleDeclaration("int func2 (void) __attribute__((dllexport));"); + assertNotReached(); + } catch( ClassCastException cce ) + { + } + } + public void testBug39704D() throws Exception + { + assertCodeFailsParse("__declspec(dllexport) int func1 (int a) {}"); + } + public void testBug39705() throws Exception + { + assertCodeFailsParse("#ident \"@(#)filename.c 1.3 90/02/12\""); + } + //Here GCC-specific section ends + public void testBug40007() throws Exception + { + parse("int y = #;"); + } + + public void testBug40422() throws Exception { + // Parse and get the translaton unit + parse("int A::* x = 0;").getDeclarations().next(); + } + +} diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/DOMFailedTest.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/DOMFailedTest.java deleted file mode 100644 index fafd3a029ac..00000000000 --- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/DOMFailedTest.java +++ /dev/null @@ -1,468 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -package org.eclipse.cdt.core.parser.failedTests; - -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; - -import org.eclipse.cdt.core.parser.tests.BaseDOMTest; - -import org.eclipse.cdt.internal.core.dom.ClassSpecifier; -import org.eclipse.cdt.internal.core.dom.Declarator; -import org.eclipse.cdt.internal.core.dom.ParameterDeclaration; -import org.eclipse.cdt.internal.core.dom.SimpleDeclaration; -import org.eclipse.cdt.internal.core.dom.TemplateDeclaration; -import org.eclipse.cdt.internal.core.dom.TranslationUnit; - -/** - * @author jcamelon - */ -public class DOMFailedTest extends BaseDOMTest { - - public DOMFailedTest(String name) { - super(name); - } - - public void testBug36730()throws Exception { - failTest("FUNCTION_MACRO( 1, a )\n int i;"); - } - - public void testBug39504A() throws Exception { - TranslationUnit tu = parse("int y = sizeof(x[0]);"); - - assertEquals(tu.getDeclarations().size(), 1); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertFalse("The expected error did not occur.", declaration.getDeclarators().size() == 1 ); - } - - public void testBug39504B() throws Exception { - failTest("int y = sizeof (int*);"); - } - - public void testBug39505A() throws Exception { - failTest("int AD::* gp_down = static_cast(gp_stat);"); - } - - public void testBug39505B() throws Exception { - failTest("int* gp_down = static_cast(gp_stat);"); - } - - public void testBug39523() { - Writer code = new StringWriter(); - try { - code.write("#define e0 \"a\"\n"); - code.write("#define e1 e0 e0 e0 e0 e0 e0 e0 e0 e0 e0\n"); - code.write("#define e2 e1 e1 e1 e1 e1 e1 e1 e1 e1 e1\n"); - code.write("#define e3 e2 e2 e2 e2 e2 e2 e2 e2 e2 e2\n"); - code.write("#define e4 e3 e3 e3 e3 e3 e3 e3 e3 e3 e3\n"); - code.write("#define e5 e4 e4 e4 e4 e4 e4 e4 e4 e4 e4\n"); - code.write("void foo() { (void)(e5); }\n"); - } catch( IOException ioe ){} - - boolean testPassed = false; - try { - parse(code.toString()); - testPassed = true; - fail( "We should not reach this point"); - } catch (Throwable e) { - if (!(e instanceof StackOverflowError)) - fail("Unexpected Error: " + e.getMessage()); - } - if (testPassed) - fail("The expected error did not occur."); - } - - public void testBug39525() throws Exception { - failTest("C &(C::*DD)(const C &x) = &C::operator=;"); - } - - public void testBug39526() throws Exception { - failTest("UnitList unit_list (String(\"keV\"));"); - } - - public void testBug39528() throws Exception { - Writer code = new StringWriter(); - try { - code.write("struct B: public A {\n"); - code.write(" A a;\n"); - code.write(" B() try : A(1), a(2)\n"); - code.write(" { throw 1; }\n"); - code.write(" catch (...)\n"); - code.write(" { if (c != 3) r |= 1; }\n"); - code.write("};\n"); - } catch( IOException ioe ){} - - failTest(code.toString()); - } - - public void testBug39531() throws Exception { - failTest("class AString { operator char const *() const; };"); - } - - public void testBug39532() throws Exception { - failTest("class N1::N2::B : public A {};"); - } - - public void testBug39535() throws Exception { - failTest("namespace bar = foo;"); - } - - public void testBug39536A() throws Exception { - TranslationUnit tu = parse("template class X { X(); };"); - - assertEquals(tu.getDeclarations().size(), 1); - TemplateDeclaration tDeclaration = (TemplateDeclaration)tu.getDeclarations().get(0); - assertEquals(tDeclaration.getDeclarations().size(), 1); - SimpleDeclaration declaration = (SimpleDeclaration)tDeclaration.getDeclarations().get(0); - ClassSpecifier cs = (ClassSpecifier)declaration.getTypeSpecifier(); - assertEquals(cs.getDeclarations().size(), 1); - SimpleDeclaration declaration2 = (SimpleDeclaration)cs.getDeclarations().get(0); - assertEquals(declaration2.getDeclarators().size(), 1); - Declarator declarator = (Declarator)declaration2.getDeclarators().get(0); - assertFalse("The expected error did not occur.", declarator.getName() != null); - } - - public void testBug39536B() throws Exception { - failTest("template class X { inline X(int); };"); - } - - public void testBug39537() throws Exception { - failTest("typedef foo<(U::id > 0)> foobar;"); - } - - public void testBug39538() throws Exception { - failTest("template C::operator int ();"); - } - - public void testBug39540() throws Exception { - failTest("class {} const null;"); - } - - public void testBug39542() throws Exception { - failTest("void f(int a, struct {int b[a];} c) {}"); - } - - public void testBug39546() throws Exception { - failTest("signed char c = (signed char) 0xffffffff;"); - } - - -// Here starts C99-specific section - - public void testBug39549() throws Exception { - failTest("struct X x = { .b = 40, .z = {} };"); - } - - public void testBug39550() throws Exception { - failTest("double x = 0x1.fp1;"); - } - - public void testBug39551A() throws Exception { - TranslationUnit tu = parse("extern float _Complex conjf (float _Complex);"); - - assertEquals(tu.getDeclarations().size(), 1); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals(declaration.getDeclarators().size(), 1); - Declarator declarator = (Declarator)declaration.getDeclarators().get(0); - assertEquals(declarator.getParms().getDeclarations().size(), 1); - ParameterDeclaration declaration2 = (ParameterDeclaration)declarator.getParms().getDeclarations().get(0); - assertEquals(declaration2.getDeclarators().size(), 1); - Declarator declarator2 = (Declarator)declaration2.getDeclarators().get(0); - assertFalse("The expected error did not occur.", declarator2.getName() == null ); - } - - public void testBug39551B() throws Exception { - TranslationUnit tu = parse("_Imaginary double id = 99.99 * __I__;"); - - assertEquals(tu.getDeclarations().size(), 1); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0); - String s = declaration.getDeclSpecifier().getTypeName(); - assertFalse("The expected error did not occur.", !declaration.getDeclSpecifier().getTypeName().equals("double") ); - } - - public void testBug39552A() throws Exception { - Writer code = new StringWriter(); - try { - code.write("%:define glue(x, y) x %:%: y /* #define glue(x, y) x ## y. */\n"); - code.write("#ifndef glue\n"); - code.write("#error glue not defined!\n"); - code.write("#endif\n"); - code.write("%:define str(x) %:x /* #define str(x) #x */\n"); - - code.write("int main (int argc, char *argv<::>) /* argv[] */\n"); - code.write("glue (<, %) /* { */\n"); - code.write(" /* di_str[] = */\n"); - code.write(" const char di_str glue(<, :)glue(:, >) = str(%:%:<::><%%>%:);\n"); - - code.write(" /* Check the glue macro actually pastes, and that the spelling of\n"); - code.write(" all digraphs is preserved. */\n"); - code.write(" if (glue(str, cmp) (di_str, \"%:%:<::><%%>%:\"))\n"); - code.write(" err (\"Digraph spelling not preserved!\");\n"); - - code.write(" return 0;\n"); - code.write("glue (%, >) /* } */\n"); - } catch( IOException ioe ){} - - failTest(code.toString()); - } - - public void testBug39552B() throws Exception { - Writer code = new StringWriter(); - try { - code.write("??=include \n"); - - code.write("??=define TWELVE 1??/\n"); - code.write("2\n"); - - code.write("static const char str??(??) = \"0123456789??/n\";\n"); - - code.write("int\n"); - code.write("main(void)\n"); - code.write("??<\n"); - code.write(" unsigned char x = 5;\n"); - - code.write(" if (sizeof str != TWELVE)\n"); - code.write(" abort ();\n"); - - code.write(" /* Test ^=, the only multi-character token to come from trigraphs. */\n"); - code.write(" x ??'= 3;\n"); - code.write(" if (x != 6)\n"); - code.write(" abort ();\n"); - - code.write(" if ((5 ??! 3) != 7)\n"); - code.write(" abort ();\n"); - - code.write(" return 0;\n"); - code.write("??>\n"); - } catch( IOException ioe ){} - - failTest(code.toString()); - } - - public void testBug39553() throws Exception { - TranslationUnit tu = parse( - "#define COMP_INC \"foobar.h\" \n" + - "#include COMP_INC"); - assertFalse("The expected error did not occur.", tu.getInclusions().size() == 1 ); - } - - public void testBug39554() throws Exception { - failTest("_Pragma(\"foobar\")"); - } - - public void testBug39556() throws Exception { - TranslationUnit tu = parse("int *restrict ip_fn (void);"); - - assertEquals(tu.getDeclarations().size(), 1); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals(declaration.getDeclarators().size(), 1); - Declarator declarator = (Declarator)declaration.getDeclarators().get(0); - assertFalse("The expected error did not occur.", declarator.getPointerOperators().size() == 1 ); - } - -// Here C99-specific section ends - -// Here GCC-specific section starts - - public void testBug39676() throws Exception { - failTest("struct { int e1, e2; } v = { e2: 0 }"); - } - - public void testBug39677() throws Exception { - failTest("B::B() : a(({ 1; })) {}"); - } - - public void testBug39678() throws Exception { - failTest("char *s = L\"a\" \"b\";"); - } - - public void testBug39679() throws Exception { - failTest("Foo blat() return f(4) {}"); - } - - public void testBug39681() throws Exception { - Writer code = new StringWriter(); - try { - code.write("double\n"); - code.write("foo (double a, double b)\n"); - code.write("{\n"); - code.write(" double square (double z) { return z * z; }\n"); - - code.write(" return square (a) + square (b);\n"); - code.write("}\n"); - } catch( IOException ioe ){} - - TranslationUnit tu = parse(code.toString()); - // Internal structure for functions is not supported, so actual test - // needs to be added later - } - - public void testBug39682() throws Exception { - TranslationUnit tu = parse("typedef name = (a+1);"); - - assertEquals(tu.getDeclarations().size(), 1); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals(declaration.getDeclarators().size(), 1); - Declarator declarator = (Declarator)declaration.getDeclarators().get(0); - assertFalse("The expected error did not occur.", declarator.getName() != null ); - } - - public void testBug39684() throws Exception { - failTest("typeof(foo(1)) bar () { return foo(1); }"); - } - - public void testBug39686() throws Exception { - Writer code = new StringWriter(); - try { - code.write("__complex__ double x; // complex double\n"); - code.write("__complex__ short int a; // complex short int\n"); - code.write("x = 2.5fi; // 2.5 imaginary float literal\n"); - code.write("a = 3i; // imaginary integer literal\n"); - code.write("double v = __real__ x; // real part of expression\n"); - code.write("double w = __imag__ x; // imaginary part of expression\n"); - } catch( IOException ioe ){} - - failTest(code.toString()); - } - - public void testBug39687() throws Exception { - failTest("struct entry tester (int len; char data[len][len], int len) {}"); - } - - public void testBug39688() throws Exception { - Writer code = new StringWriter(); - try { - code.write("#define decl(type, vars...) \\\n"); - code.write(" type vars ;\n"); - - code.write("decl(int, x, y)\n"); - } catch( IOException ioe ){} - - TranslationUnit tu = parse(code.toString()); - assertFalse("The expected error did not occur.", tu.getDeclarations().size() == 1 ); - } - - public void testBug39694() throws Exception { - TranslationUnit tu = parse("int ab$cd = 1;"); - - assertEquals(tu.getDeclarations().size(), 1); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals(declaration.getDeclarators().size(), 1); - Declarator declarator = (Declarator)declaration.getDeclarators().get(0); - assertFalse("The expected error did not occur.", declarator.getName().equals("ab$cd") ); - } - - public void testBug39695() throws Exception { - failTest("int a = __alignof__ (int);"); - } - - public void testBug39695A() throws Exception { - failTest("int foo asm (\"myfoo\") = 2;"); - } - - public void testBug39695B() throws Exception { - failTest("extern func () asm (\"FUNC\");"); - } - - public void testBug39695C() throws Exception { - failTest("register int *foo asm (\"a5\");"); - } - - public void testBug39698A() throws Exception { - TranslationUnit tu = parse("int c = a ? b;"); - } - - public void testBug39701A() throws Exception { - failTest("extern template int max (int, int);"); - } - - public void testBug39701B() throws Exception { - failTest("inline template class Foo;"); - } - - public void testBug39701C() throws Exception { - failTest("static template class Foo;"); - } - - public void testBug39702() throws Exception { - Writer code = new StringWriter(); - try { - code.write("signature T {\n"); - code.write(" int f (int);\n"); - code.write(" int f0 () { return f (0); };\n"); - code.write("};\n"); - } catch( IOException ioe ){} - - TranslationUnit tu = parse(code.toString()); - assertFalse("The expected error did not occur.", tu.getDeclarations().size() == 1 ); - } - - public void testBug39703() throws Exception { - Writer code = new StringWriter(); - try { - code.write("/* __extension__ enables GNU C mode for the duration of the declaration. */\n"); - code.write("__extension__ struct G {\n"); - code.write(" struct { char z; };\n"); - code.write(" char g;\n"); - code.write("};\n"); - } catch( IOException ioe ){} - - TranslationUnit tu = parse(code.toString()); - assertEquals(tu.getDeclarations().size(), 1); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertFalse("The expected error did not occur.", declaration.getDeclSpecifier().getName() == null ); - } - - public void testBug39704A() throws Exception { - failTest("__declspec (dllimport) int foo;"); - } - - public void testBug39704B() throws Exception { - TranslationUnit tu = parse("extern int (* import) (void) __attribute__((dllimport));"); - - assertEquals(tu.getDeclarations().size(), 1); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals(declaration.getDeclarators().size(), 1); - Declarator declarator = (Declarator)declaration.getDeclarators().get(0); - assertFalse("The expected error did not occur.", !declarator.getName().toString().equals("__attribute__")); - } - - public void testBug39704C() throws Exception { - TranslationUnit tu = parse("int func2 (void) __attribute__((dllexport));"); - - assertEquals(tu.getDeclarations().size(), 1); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals(declaration.getDeclarators().size(), 1); - Declarator declarator = (Declarator)declaration.getDeclarators().get(0); - assertFalse("The expected error did not occur.", !declarator.getName().toString().equals("__attribute__")); - } - - public void testBug39704D() throws Exception { - failTest("__declspec(dllexport) int func1 (int a) {}"); - } - - public void testBug39705() throws Exception { - failTest("#ident \"@(#)filename.c 1.3 90/02/12\""); - } - -// Here GCC-specific section ends - - public void testBug40007() throws Exception { - parse("int y = #;"); - } -} diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/LokiFailures.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/LokiFailures.java index 22a0e21718a..762a5373539 100644 --- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/LokiFailures.java +++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/LokiFailures.java @@ -14,18 +14,18 @@ import java.io.IOException; import java.io.StringWriter; import java.io.Writer; -import org.eclipse.cdt.core.parser.tests.BaseDOMTest; +import org.eclipse.cdt.core.parser.tests.BaseASTTest; /** * @author jcamelon */ -public class LokiFailures extends BaseDOMTest { +public class LokiFailures extends BaseASTTest { public LokiFailures(String name) { super(name); } - public void testBugTypeManip151() + public void testBug40419() { Writer code = new StringWriter(); try @@ -34,7 +34,7 @@ public class LokiFailures extends BaseDOMTest { code.write( "enum { value = (::Loki::Conversion::exists && \n" ); code.write( "!::Loki::Conversion::sameType) }; };" ); } catch( IOException ioe ){} - failTest( code.toString() ); + assertCodeFailsParse( code.toString() ); } } diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/STLFailedTests.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/STLFailedTests.java index 9997d3cce10..0dabc232458 100644 --- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/STLFailedTests.java +++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/STLFailedTests.java @@ -12,12 +12,12 @@ package org.eclipse.cdt.core.parser.failedTests; import java.io.StringWriter; import java.io.Writer; -import org.eclipse.cdt.core.parser.tests.BaseDOMTest; +import org.eclipse.cdt.core.parser.tests.BaseASTTest; /** * @author hamer */ -public class STLFailedTests extends BaseDOMTest { +public class STLFailedTests extends BaseASTTest { public STLFailedTests(String name) { super(name); @@ -29,7 +29,7 @@ public class STLFailedTests extends BaseDOMTest { code.write("template class char_traits\n"); code.write(": public __char_traits_base<_CharT, _CharT>\n"); code.write("{};\n"); - failTest(code.toString()); + assertCodeFailsParse(code.toString()); } } diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java index 3b88673b633..1b6d45b7a9c 100644 --- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java @@ -17,7 +17,6 @@ import junit.framework.TestCase; import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.internal.core.index.IEntryResult; import org.eclipse.cdt.internal.core.index.IIndex; import org.eclipse.cdt.internal.core.index.IQueryResult; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedFramework.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedFramework.java index 30dcd0c49d0..4dd5dddc79d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedFramework.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedFramework.java @@ -24,7 +24,7 @@ import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; -import org.eclipse.cdt.core.parser.IParserCallback; +import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.internal.core.parser.NullSourceElementRequestor; /** @@ -157,7 +157,7 @@ public abstract class AutomatedFramework extends TestCase { return suite; } - protected static IParserCallback nullCallback = new NullSourceElementRequestor(); + protected static ISourceElementRequestor nullCallback = new NullSourceElementRequestor(); protected static Properties properties = new Properties(); protected static String defaultNature; protected static String outputFile = null; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseASTTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseASTTest.java new file mode 100644 index 00000000000..4722f2edb7f --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseASTTest.java @@ -0,0 +1,107 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.core.parser.tests; + +import java.io.StringReader; +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.eclipse.cdt.core.parser.IParser; +import org.eclipse.cdt.core.parser.IQuickParseCallback; +import org.eclipse.cdt.core.parser.ParserFactory; +import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; +import org.eclipse.cdt.core.parser.ast.IASTDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTFunction; +import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTVariable; +import org.eclipse.cdt.internal.core.parser.ParserException; +import org.eclipse.cdt.internal.core.parser.ScannerInfo; + +/** + * @author jcamelon + * + */ +public class BaseASTTest extends TestCase +{ + public BaseASTTest( String a ) + { + super( a ); + } + + protected IQuickParseCallback quickParseCallback; + protected IParser parser; + protected IASTCompilationUnit parse( String code, boolean quick, boolean throwExceptionOnError ) throws ParserException + { + ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE; + quickParseCallback = ParserFactory.createQuickParseCallback(); + parser = ParserFactory.createParser( ParserFactory.createScanner( new StringReader( code ), "code", new ScannerInfo(), mode), quickParseCallback, mode ); + if( ! parser.parse() && throwExceptionOnError ) + throw new ParserException("Parse failure"); + return quickParseCallback.getCompilationUnit(); + } + + protected IASTCompilationUnit parse( String code )throws ParserException + { + return parse( code, true, true ); + } + + protected IASTDeclaration assertSoleDeclaration( String code ) throws ParserException + { + Iterator declarationIter = parse( code ).getDeclarations(); + assertTrue( declarationIter.hasNext() ); + IASTDeclaration returnValue = (IASTDeclaration)declarationIter.next(); + assertFalse( declarationIter.hasNext() ); + return returnValue; + } + + public void assertCodeFailsParse(String code) { + boolean testPassed = false; + try { + IASTCompilationUnit tu = parse(code); + testPassed = true; + fail( "We should not reach this point"); + } catch (Throwable e) { + if (!(e instanceof ParserException)) + fail("Unexpected Error: " + e.getMessage()); + } + if (testPassed) + fail("The expected error did not occur."); + } + + protected void assertSimpleReturnType(IASTFunction function, IASTSimpleTypeSpecifier.Type type) + { + assertEquals( ((IASTSimpleTypeSpecifier)function.getReturnType().getTypeSpecifier()).getType(), type ); + } + + protected void assertSimpleType(IASTVariable variable, IASTSimpleTypeSpecifier.Type type) + { + assertEquals( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).getType(), type ); + } + + protected void assertParameterSimpleType(IASTParameterDeclaration variable, IASTSimpleTypeSpecifier.Type type) + { + assertEquals( ((IASTSimpleTypeSpecifier)variable.getTypeSpecifier()).getType(), type ); + } + + protected void failedAsExpected() + { + assertFalse( "The expected error did not occur.", false ); + } + + protected void assertNotReached() + { + fail( "We should not reach this point"); + } + +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java deleted file mode 100644 index 44a594d228d..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - ******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.io.StringReader; - -import junit.framework.TestCase; - -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.internal.core.dom.DOMBuilder; -import org.eclipse.cdt.internal.core.dom.TranslationUnit; -import org.eclipse.cdt.internal.core.parser.ParserException; -import org.eclipse.cdt.internal.core.parser.ScannerInfo; - -/** - * @author jcamelon - * - */ -public class BaseDOMTest extends TestCase { - - public BaseDOMTest( String arg ) - { - super( arg ); - } - - public TranslationUnit parse( String code ) throws Exception - { - return parse( code, true, true ); - } - - public TranslationUnit parse(String code, boolean quickParse, boolean throwOnError ) throws Exception { - DOMBuilder domBuilder = new DOMBuilder(); - ParserMode mode = quickParse ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE; - IParser parser = ParserFactory.createParser(ParserFactory.createScanner( new StringReader( code ), null, new ScannerInfo(), mode ), domBuilder, mode ); - if( ! parser.parse() ) - if( throwOnError ) throw new ParserException( "Parse failure" ); - else domBuilder.getTranslationUnit().setParseSuccessful( false ); - - return domBuilder.getTranslationUnit(); - } - - public void failTest(String code) { - boolean testPassed = false; - try { - TranslationUnit tu = parse(code); - testPassed = true; - fail( "We should not reach this point"); - } catch (Throwable e) { - if (!(e instanceof ParserException)) - fail("Unexpected Error: " + e.getMessage()); - } - if (testPassed) - fail("The expected error did not occur."); - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/DOMTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/DOMTests.java deleted file mode 100644 index 28f344febea..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/DOMTests.java +++ /dev/null @@ -1,2211 +0,0 @@ -package org.eclipse.cdt.core.parser.tests; - -import java.io.StringWriter; -import java.io.Writer; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.internal.core.dom.ASMDefinition; -import org.eclipse.cdt.internal.core.dom.AccessSpecifier; -import org.eclipse.cdt.internal.core.dom.ArrayQualifier; -import org.eclipse.cdt.internal.core.dom.BaseSpecifier; -import org.eclipse.cdt.internal.core.dom.ClassKey; -import org.eclipse.cdt.internal.core.dom.ClassSpecifier; -import org.eclipse.cdt.internal.core.dom.ConstructorChain; -import org.eclipse.cdt.internal.core.dom.ConstructorChainElement; -import org.eclipse.cdt.internal.core.dom.DeclSpecifier; -import org.eclipse.cdt.internal.core.dom.Declaration; -import org.eclipse.cdt.internal.core.dom.Declarator; -import org.eclipse.cdt.internal.core.dom.ElaboratedTypeSpecifier; -import org.eclipse.cdt.internal.core.dom.EnumerationSpecifier; -import org.eclipse.cdt.internal.core.dom.EnumeratorDefinition; -import org.eclipse.cdt.internal.core.dom.ExceptionSpecifier; -import org.eclipse.cdt.internal.core.dom.ExplicitTemplateDeclaration; -import org.eclipse.cdt.internal.core.dom.Expression; -import org.eclipse.cdt.internal.core.dom.Inclusion; -import org.eclipse.cdt.internal.core.dom.LinkageSpecification; -import org.eclipse.cdt.internal.core.dom.Macro; -import org.eclipse.cdt.internal.core.dom.NamespaceDefinition; -import org.eclipse.cdt.internal.core.dom.OldKRParameterDeclarationClause; -import org.eclipse.cdt.internal.core.dom.ParameterDeclaration; -import org.eclipse.cdt.internal.core.dom.ParameterDeclarationClause; -import org.eclipse.cdt.internal.core.dom.PointerOperator; -import org.eclipse.cdt.internal.core.dom.SimpleDeclaration; -import org.eclipse.cdt.internal.core.dom.TemplateDeclaration; -import org.eclipse.cdt.internal.core.dom.TemplateParameter; -import org.eclipse.cdt.internal.core.dom.TemplateParameterList; -import org.eclipse.cdt.internal.core.dom.TranslationUnit; -import org.eclipse.cdt.internal.core.dom.UsingDeclaration; -import org.eclipse.cdt.internal.core.dom.UsingDirective; -import org.eclipse.cdt.internal.core.parser.Name; -import org.eclipse.cdt.internal.core.parser.ParserException; -import org.eclipse.cdt.internal.core.parser.Token; - -public class DOMTests extends BaseDOMTest { - - public DOMTests( String arg ) - { - super( arg ); - } - - public void testNamespaceDefinition() throws Exception - { - for( int i = 0; i < 2; ++i ) - { - TranslationUnit translationUnit; - if( i == 0 ) - translationUnit = parse("namespace KingJohn { int x; }"); - else - translationUnit = parse("namespace { int x; }"); - - List declarations = translationUnit.getDeclarations(); - assertEquals( declarations.size(), 1 ); - NamespaceDefinition namespace = (NamespaceDefinition)declarations.get(0); - - if( i == 0 ) - assertEquals( namespace.getName().toString(), "KingJohn" ); - else - assertEquals( namespace.getName(), "" ); - List namespaceDeclarations = namespace.getDeclarations(); - assertEquals( namespaceDeclarations.size(), 1 ); - SimpleDeclaration simpleDec = (SimpleDeclaration)namespaceDeclarations.get(0); - assertEquals( simpleDec.getDeclSpecifier().getType(), DeclSpecifier.t_int ); - List declarators = simpleDec.getDeclarators(); - assertEquals( declarators.size(), 1 ); - Declarator declarator = (Declarator)declarators.get(0); - assertEquals( declarator.getName().toString(), "x"); - } - } - - public void testLinkageSpecification() throws Exception - { - for( int i = 0; i < 2; ++i ) - { - TranslationUnit translationUnit; - if( i == 0 ) - translationUnit = parse("extern \"C\" { int x(void); }"); - else - translationUnit = parse("extern \"ADA\" int x(void);"); - - List declarations = translationUnit.getDeclarations(); - assertEquals( declarations.size(), 1 ); - LinkageSpecification linkage = (LinkageSpecification)declarations.get(0); - if( i == 0 ) - assertEquals( "C", linkage.getLanguageLinkage() ); - else - assertEquals( "ADA", linkage.getLanguageLinkage() ); - - List subDeclarations = linkage.getDeclarations(); - assertEquals( subDeclarations.size(), 1 ); - - SimpleDeclaration simpleDec = (SimpleDeclaration)subDeclarations.get(0); - assertEquals( simpleDec.getDeclSpecifier().getType(), DeclSpecifier.t_int ); - List declarators = simpleDec.getDeclarators(); - assertEquals( declarators.size(), 1 ); - Declarator declarator = (Declarator)declarators.get(0); - assertEquals( declarator.getName().toString(), "x" ); - assertNotNull( declarator.getParms() ); - } - - } - - public void testTemplateSpecialization() throws Exception - { - TranslationUnit tu = parse( "template<> class stream { /* ... */ };"); - assertEquals( tu.getDeclarations().size(), 1 ); - ExplicitTemplateDeclaration explicit = (ExplicitTemplateDeclaration)tu.getDeclarations().get( 0 ); - assertNotNull( explicit ); - assertEquals( explicit.getKind(), ExplicitTemplateDeclaration.k_specialization ); - assertEquals( explicit.getDeclarations().size(), 1 ); - SimpleDeclaration declaration = (SimpleDeclaration)explicit.getDeclarations().get(0); - assertNotNull( declaration ); - ClassSpecifier classSpec = (ClassSpecifier)declaration.getTypeSpecifier(); - assertNotNull( classSpec ); - assertEquals( classSpec.getClassKey(), ClassKey.t_class ); - assertEquals( classSpec.getName().toString(), "stream" ); - assertEquals( declaration.getDeclarators().size(), 0 ); - assertEquals( classSpec.getDeclarations().size(), 0 ); - - } - - public void testTemplateInstantiation() throws Exception - { - TranslationUnit tu = parse( "template class Array;"); - assertEquals( tu.getDeclarations().size(), 1 ); - ExplicitTemplateDeclaration explicit = (ExplicitTemplateDeclaration)tu.getDeclarations().get( 0 ); - assertNotNull( explicit ); - assertEquals( explicit.getKind(), ExplicitTemplateDeclaration.k_instantiation ); - assertEquals( explicit.getDeclarations().size(), 1 ); - SimpleDeclaration declaration = (SimpleDeclaration)explicit.getDeclarations().get(0); - assertNotNull( declaration ); - ElaboratedTypeSpecifier classSpec = (ElaboratedTypeSpecifier)declaration.getTypeSpecifier(); - assertNotNull( classSpec ); - assertEquals( classSpec.getClassKey(), ClassKey.t_class ); - assertEquals( classSpec.getName().toString(), "Array"); - } - - public void testEnumSpecifier() throws Exception - { - Writer code = new StringWriter(); - code.write( "enum { yo, go = 3, away };\n"); - code.write( "enum hasAName { last = 666 };"); - TranslationUnit translationUnit = parse( code.toString() ); - List declarations = translationUnit.getDeclarations(); - assertEquals( declarations.size(), 2 ); - - SimpleDeclaration declaration1 = (SimpleDeclaration)declarations.get(0); - EnumerationSpecifier enumSpecifier = (EnumerationSpecifier)declaration1.getTypeSpecifier(); - assertNull( enumSpecifier.getName() ); - List firstEnumItems = enumSpecifier.getEnumeratorDefinitions(); - assertEquals( 3, firstEnumItems.size()); - EnumeratorDefinition enumDef1_1 = (EnumeratorDefinition)firstEnumItems.get(0); - assertEquals( enumDef1_1.getName().toString(), "yo" ); - assertNull( enumDef1_1.getExpression() ); - - EnumeratorDefinition enumDef1_2 = (EnumeratorDefinition)firstEnumItems.get(1); - assertEquals( enumDef1_2.getName().toString(), "go" ); - assertNotNull( enumDef1_2.getExpression() ); - - EnumeratorDefinition enumDef1_3 = (EnumeratorDefinition)firstEnumItems.get(2); - assertEquals( enumDef1_3.getName().toString(), "away" ); - assertNull( enumDef1_3.getExpression() ); - - SimpleDeclaration declaration2 = (SimpleDeclaration)declarations.get(1); - EnumerationSpecifier enumSpecifier2 = (EnumerationSpecifier)declaration2.getTypeSpecifier(); - assertEquals( enumSpecifier2.getName().toString(), "hasAName" ); - - } - - public void testTypedef() throws Exception - { - TranslationUnit tu = parse( "typedef const struct A * const cpStructA;"); - assertEquals( tu.getDeclarations().size(), 1 ); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertTrue( declaration.getDeclSpecifier().isTypedef() ); - assertTrue( declaration.getDeclSpecifier().isConst() ); - ElaboratedTypeSpecifier elab = (ElaboratedTypeSpecifier) declaration.getTypeSpecifier(); - assertEquals( elab.getClassKey(), ClassKey.t_struct ); - assertEquals( elab.getName().toString(), "A" ); - List declarators = declaration.getDeclarators(); - assertEquals( declarators.size(), 1 ); - Declarator declarator = (Declarator)declarators.get(0); - assertEquals( declarator.getName().toString(), "cpStructA"); - assertEquals( declarator.getPointerOperators().size(), 1 ); - PointerOperator po = (PointerOperator)declarator.getPointerOperators().get(0); - assertEquals( po.getType(), PointerOperator.t_pointer); - assertTrue( po.isConst() ); - assertFalse( po.isVolatile()); - - } - public void testUsingClauses() throws Exception - { - Writer code = new StringWriter(); - - code.write("using namespace A::B::C;\n"); - code.write("using namespace C;\n"); - code.write("using B::f;\n"); - code.write("using ::f;\n"); - code.write("using typename crap::de::crap;"); - TranslationUnit translationUnit = parse(code.toString()); - - List declarations = translationUnit.getDeclarations(); - assertEquals( declarations.size(), 5 ); - - UsingDirective first, second; - UsingDeclaration third, fourth, fifth; - - first = (UsingDirective) declarations.get(0); - assertEquals( first.getNamespaceName().toString(), "A::B::C" ); - - second = (UsingDirective) declarations.get(1); - assertEquals( second.getNamespaceName().toString(), "C" ); - - third = (UsingDeclaration) declarations.get(2); - assertEquals( third.getMappedName(), "B::f" ); - assertFalse( third.isTypename() ); - - fourth = (UsingDeclaration) declarations.get(3); - assertEquals( fourth.getMappedName(), "::f" ); - assertFalse( fourth.isTypename() ); - - fifth = (UsingDeclaration) declarations.get(4); - assertTrue( fifth.isTypename() ); - assertEquals( fifth.getMappedName(), "crap::de::crap" ); - } - - public void testDeclSpecifier() throws Exception - { - DeclSpecifier d = new DeclSpecifier(); - d.setTypedef( true ); - assertTrue( d.isTypedef() ); - d.setTypedef( false ); - assertFalse( d.isTypedef() ); - d.setAuto(true); - assertTrue( d.isAuto() ); - d.setAuto(false); - assertFalse( d.isAuto()); - d.setRegister(true); - assertTrue( d.isRegister() ); - d.setRegister(false); - assertFalse( d.isRegister() ); - d.setStatic(true); - assertTrue( d.isStatic() ); - d.setStatic(false); - assertFalse( d.isStatic() ); - - d.setExtern(true); - assertTrue( d.isExtern() ); - d.setExtern(false); - assertFalse( d.isExtern() ); - - d.setMutable(true); - assertTrue( d.isMutable() ); - d.setMutable(false); - assertFalse( d.isMutable() ); - - d.setInline(true); - assertTrue( d.isInline() ); - d.setInline(false); - assertFalse( d.isInline() ); - - d.setVirtual(true); - assertTrue( d.isVirtual() ); - d.setVirtual(false); - assertFalse( d.isVirtual() ); - - d.setExplicit(true); - assertTrue( d.isExplicit() ); - d.setExplicit(false); - assertFalse( d.isExplicit() ); - - d.setTypedef(true); - assertTrue( d.isTypedef() ); - d.setTypedef(false); - assertFalse( d.isTypedef() ); - - d.setFriend(true); - assertTrue( d.isFriend()); - d.setFriend(false); - assertFalse( d.isFriend()); - - d.setConst(true); - assertTrue( d.isConst() ); - d.setConst(false); - assertFalse( d.isConst() ); - - d.setVolatile(true); - assertTrue( d.isVolatile() ); - d.setVolatile(false); - assertFalse( d.isVolatile() ); - - d.setUnsigned(true); - assertTrue( d.isUnsigned()); - d.setUnsigned(false); - assertFalse( d.isUnsigned()); - - d.setShort(true); - assertTrue( d.isShort()); - d.setShort(false); - assertFalse( d.isShort()); - - d.setLong(true); - assertTrue( d.isLong() ); - d.setLong(false); - assertFalse( d.isLong() ); - - for( int i = 0; i <= 7; ++i ) - { - d.setType( i ); - for( int j = 0; j <= 7; ++j ) - { - if( j == i ) - assertTrue( d.getType() == j ); - else - assertFalse( d.getType() == j ); - } - } - - } - - /** - * Test code: int x = 5; - * Purpose: to test the simple decaration in it's simplest form. - */ - public void testIntGlobal() throws Exception { - // Parse and get the translation Unit - TranslationUnit translationUnit = parse("int x = 5;"); - - // Get the simple declaration - List declarations = translationUnit.getDeclarations(); - assertEquals(1, declarations.size()); - SimpleDeclaration declaration = (SimpleDeclaration)declarations.get(0); - - // Make sure it is only an int - assertEquals(DeclSpecifier.t_int, declaration.getDeclSpecifier().getDeclSpecifierSeq()); - - // Get the declarator and check its name - List declarators = declaration.getDeclarators(); - assertEquals(1, declarators.size()); - Declarator declarator = (Declarator)declarators.get(0); - Name name = declarator.getName(); - assertEquals("x", name.toString()); - - Expression exp = declarator.getExpression(); - assertNotNull( exp ); - assertEquals( 1, exp.elements().size() ); - Token t = (Token)exp.elements().get(0); - assertEquals( t.getImage(), "5" ); - assertEquals( t.getType(), IToken.tINTEGER); - } - - /** - * Test code: class A { } a; - * Purpose: tests the use of a classSpecifier in - */ - public void testEmptyClass() throws Exception { - // Parse and get the translation unit - Writer code = new StringWriter(); - code.write("class A { } a;"); - TranslationUnit translationUnit = parse(code.toString()); - - // Get the simple declaration - List declarations = translationUnit.getDeclarations(); - assertEquals(1, declarations.size()); - SimpleDeclaration declaration = (SimpleDeclaration)declarations.get(0); - - // Make sure it is a type specifier - assertEquals(0, declaration.getDeclSpecifier().getDeclSpecifierSeq()); - - // Get the class specifier and check its name - ClassSpecifier classSpecifier = (ClassSpecifier)declaration.getTypeSpecifier(); - Name className = classSpecifier.getName(); - assertEquals("A", className.toString()); - - // Get the declarator and check it's name - List declarators = declaration.getDeclarators(); - assertEquals(1, declarators.size()); - Declarator declarator = (Declarator)declarators.get(0); - Name name = declarator.getName(); - assertEquals("a", name.toString()); - } - - /** - * Test code: class A { public: int x; }; - * Purpose: tests a declaration in a class scope. - */ - public void testSimpleClassMember() throws Exception { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("class A { public: int x; };"); - TranslationUnit translationUnit = parse(code.toString()); - - // Get the declaration - List declarations = translationUnit.getDeclarations(); - assertEquals(1, declarations.size()); - SimpleDeclaration declaration = (SimpleDeclaration)declarations.get(0); - - // Make sure there is no declarator - assertEquals(0, declaration.getDeclarators().size()); - - // Make sure it's a type specifier - assertEquals(0, declaration.getDeclSpecifier().getDeclSpecifierSeq()); - - // Get the class specifier and check its name - ClassSpecifier classSpecifier = (ClassSpecifier)declaration.getTypeSpecifier(); - Name className = classSpecifier.getName(); - assertEquals("A", className.toString()); - - // Get the member declaration - declarations = classSpecifier.getDeclarations(); - assertEquals(1, declarations.size()); - declaration = (SimpleDeclaration)declarations.get(0); - - // Make sure it's an int - assertEquals(DeclSpecifier.t_int, declaration.getDeclSpecifier().getDeclSpecifierSeq()); - - // Get the declarator and check it's name - List declarators = declaration.getDeclarators(); - assertEquals(1, declarators.size()); - Declarator declarator = (Declarator)declarators.get(0); - Name name = declarator.getName(); - assertEquals("x", name.toString()); - } - /** - * Test code: class A : public B, private C, virtual protected D { public: int x, y; float a,b,c; } - * Purpose: tests a declaration in a class scope. - */ - public void testSimpleClassMembers() throws Exception { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("class A : public B, private C, virtual protected D { public: int x, y; float a,b,c; };"); - TranslationUnit translationUnit = parse(code.toString()); - - // Get the declaration - List declarations = translationUnit.getDeclarations(); - assertEquals(1, declarations.size()); - SimpleDeclaration declaration = (SimpleDeclaration)declarations.get(0); - - // Make sure there is no declarator - assertEquals(0, declaration.getDeclarators().size()); - - // Make sure it's a type specifier - assertEquals(0, declaration.getDeclSpecifier().getDeclSpecifierSeq()); - - // Get the class specifier and check its name - ClassSpecifier classSpecifier = (ClassSpecifier)declaration.getTypeSpecifier(); - Name className = classSpecifier.getName(); - assertEquals("A", className.toString()); - - List baseClasses = classSpecifier.getBaseSpecifiers(); - assertEquals( 3, baseClasses.size() ); - BaseSpecifier bs = (BaseSpecifier)baseClasses.get( 0 ); - assertEquals( bs.getAccess(), AccessSpecifier.v_public ); - assertEquals( bs.isVirtual(), false ); - assertEquals( bs.getName().toString(), "B" ); - - bs = (BaseSpecifier)baseClasses.get( 1 ); - assertEquals( bs.getAccess(), AccessSpecifier.v_private ); - assertEquals( bs.isVirtual(), false ); - assertEquals( bs.getName().toString(), "C" ); - - bs = (BaseSpecifier)baseClasses.get( 2 ); - assertEquals( bs.getAccess(), AccessSpecifier.v_protected ); - assertEquals( bs.isVirtual(), true ); - assertEquals( bs.getName().toString(), "D" ); - - - // Get the member declaration - declarations = classSpecifier.getDeclarations(); - assertEquals(2, declarations.size()); - declaration = (SimpleDeclaration)declarations.get(0); - - // Make sure it's an int - assertEquals(DeclSpecifier.t_int, declaration.getDeclSpecifier().getDeclSpecifierSeq()); - - // Get the declarator and check it's name - List declarators = declaration.getDeclarators(); - assertEquals(2, declarators.size()); - Declarator declarator = (Declarator)declarators.get(0); - Name name = declarator.getName(); - assertEquals("x", name.toString()); - declarator = (Declarator)declarators.get(1); - name = declarator.getName(); - assertEquals("y", name.toString()); - - declaration = (SimpleDeclaration)declarations.get(1); - // Make sure it's an float - assertEquals(DeclSpecifier.t_float, declaration.getDeclSpecifier().getDeclSpecifierSeq()); - declarators = declaration.getDeclarators(); - assertEquals( 3, declarators.size() ); - name = ((Declarator)declarators.get(0)).getName(); - assertEquals( "a", name.toString() ); - name = ((Declarator)declarators.get(1)).getName(); - assertEquals( "b", name.toString() ); - name = ((Declarator)declarators.get(2)).getName(); - assertEquals( "c", name.toString() ); - - } - - - /** - * Test code: int myFunction( void ); - */ - public void testSimpleFunctionDeclaration() throws Exception - { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("void myFunction( void );"); - TranslationUnit translationUnit = parse(code.toString()); - - // Get the declaration - List declarations = translationUnit.getDeclarations(); - assertEquals(1, declarations.size()); - SimpleDeclaration simpleDeclaration = (SimpleDeclaration)declarations.get(0); - assertEquals( simpleDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_void ); - List declarators = simpleDeclaration.getDeclarators(); - assertEquals( 1, declarators.size() ); - Declarator functionDeclarator = (Declarator)declarators.get( 0 ); - assertEquals( functionDeclarator.getName().toString(), "myFunction" ); - ParameterDeclarationClause pdc = functionDeclarator.getParms(); - assertNotNull( pdc ); - List parameterDecls = pdc.getDeclarations(); - assertEquals( 1, parameterDecls.size() ); - ParameterDeclaration parm1 = (ParameterDeclaration)parameterDecls.get( 0 ); - assertEquals( DeclSpecifier.t_void, parm1.getDeclSpecifier().getType() ); - List parm1Decls = parm1.getDeclarators(); - assertEquals( 1, parm1Decls.size() ); - Declarator parm1Declarator = (Declarator) parm1Decls.get(0); - assertNull( parm1Declarator.getName() ); - } - - /** - * Test code: bool myFunction( int parm1 = 3 * 4, double parm2 ); - * @throws Exception - */ - public void testFunctionDeclarationWithParameters() throws Exception - { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("bool myFunction( int parm1 = 3 * 4, double parm2 );"); - TranslationUnit translationUnit = parse(code.toString()); - - // Get the declaration - List declarations = translationUnit.getDeclarations(); - assertEquals(1, declarations.size()); - SimpleDeclaration simpleDeclaration = (SimpleDeclaration)declarations.get(0); - assertEquals( simpleDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_bool ); - List declarators = simpleDeclaration.getDeclarators(); - assertEquals( 1, declarators.size() ); - Declarator functionDeclarator = (Declarator)declarators.get( 0 ); - assertEquals( functionDeclarator.getName().toString(), "myFunction" ); - ParameterDeclarationClause pdc = functionDeclarator.getParms(); - assertNotNull( pdc ); - List parameterDecls = pdc.getDeclarations(); - assertEquals( 2, parameterDecls.size() ); - ParameterDeclaration parm1 = (ParameterDeclaration)parameterDecls.get( 0 ); - assertEquals( DeclSpecifier.t_int, parm1.getDeclSpecifier().getType() ); - List parm1Decls = parm1.getDeclarators(); - assertEquals( 1, parm1Decls.size() ); - Declarator parm1Declarator = (Declarator) parm1Decls.get(0); - assertEquals( "parm1", parm1Declarator.getName().toString() ); - Expression initialValueParm1 = parm1Declarator.getExpression(); - assertEquals( initialValueParm1.elements().size(), 3 ); - Token t1 = (Token)initialValueParm1.elements().get( 0 ); - Token t2 = (Token)initialValueParm1.elements().get( 1 ); - Token t3 = (Token)initialValueParm1.elements().get( 2 ); - assertEquals( t1.getType(), IToken.tINTEGER ); - assertEquals( t1.getImage(), "3" ); - assertEquals( t3.getType(), IToken.tSTAR ); - assertEquals( t2.getType(), IToken.tINTEGER ); - assertEquals( t2.getImage(), "4" ); - - ParameterDeclaration parm2 = (ParameterDeclaration)parameterDecls.get( 1 ); - assertEquals( DeclSpecifier.t_double, parm2.getDeclSpecifier().getType() ); - List parm2Decls = parm2.getDeclarators(); - assertEquals( 1, parm2Decls.size() ); - Declarator parm2Declarator = (Declarator) parm2Decls.get(0); - assertEquals( "parm2", parm2Declarator.getName().toString() ); - - } - - - /** - * Test code: "class A { int floor( double input ), someInt; };" - */ - public void testMultipleDeclarators() throws Exception - { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("class A { int floor( double input ), someInt; };"); - TranslationUnit translationUnit = parse(code.toString()); - - List tudeclarations = translationUnit.getDeclarations(); - assertEquals( 1, tudeclarations.size() ); - SimpleDeclaration classDecl = (SimpleDeclaration)tudeclarations.get(0); - assertEquals( 0, classDecl.getDeclarators().size() ); - ClassSpecifier classSpec = (ClassSpecifier)classDecl.getTypeSpecifier(); - - List classDeclarations = classSpec.getDeclarations(); - assertEquals( classDeclarations.size(), 1 ); - SimpleDeclaration simpleDeclaration = (SimpleDeclaration)classDeclarations.get(0); - assertEquals( simpleDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_int ); - List simpleDeclarators = simpleDeclaration.getDeclarators(); - assertEquals( simpleDeclarators.size(), 2 ); - Declarator methodDeclarator = (Declarator)simpleDeclarators.get(0); - assertEquals( methodDeclarator.getName().toString(), "floor" ); - ParameterDeclarationClause pdc = methodDeclarator.getParms(); - assertNotNull( pdc ); - List parameterDeclarations = pdc.getDeclarations(); - assertEquals( 1, parameterDeclarations.size() ); - ParameterDeclaration parm1Declaration = (ParameterDeclaration)parameterDeclarations.get(0); - assertEquals( DeclSpecifier.t_double, parm1Declaration.getDeclSpecifier().getType() ); - List parm1Declarators = parm1Declaration.getDeclarators(); - assertEquals( parm1Declarators.size(), 1 ); - Declarator parm1Declarator = (Declarator)parm1Declarators.get(0); - assertEquals( parm1Declarator.getName().toString(), "input" ); - Declarator integerDeclarator = (Declarator)simpleDeclarators.get(1); - assertEquals( integerDeclarator.getName().toString(), "someInt" ); - assertNull( integerDeclarator.getParms() ); - } - - public void testFunctionModifiers() throws Exception - { - Writer code = new StringWriter(); - code.write( "virtual void foo( void ) const throw ( yay, nay, we::dont::care ) = 0;"); - TranslationUnit translationUnit = parse( code.toString() ); - List tudeclarations = translationUnit.getDeclarations(); - assertEquals( 1, tudeclarations.size() ); - SimpleDeclaration decl1 = (SimpleDeclaration)tudeclarations.get(0); - assertEquals( decl1.getDeclSpecifier().getType(), DeclSpecifier.t_void); - assertTrue( decl1.getDeclSpecifier().isVirtual() ); - assertEquals( decl1.getDeclarators().size(), 1 ); - Declarator declarator = (Declarator)decl1.getDeclarators().get(0); - assertEquals( declarator.getName().toString(), "foo"); - assertTrue( declarator.isConst() ); - assertFalse( declarator.isVolatile() ); - ExceptionSpecifier exceptions = declarator.getExceptionSpecifier(); - List typenames = exceptions.getTypeNames(); - assertEquals( typenames.size(), 3 ); - Name n = (Name)typenames.get(0); - assertEquals( n.toString(), "yay"); - n = (Name)typenames.get(1); - assertEquals( n.toString(), "nay"); - n = (Name)typenames.get(2); - assertEquals( n.toString(), "we::dont::care"); - assertTrue( declarator.isPureVirtual() ); - } - - - public void testArrays() throws Exception - { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("int x [5][];"); - TranslationUnit translationUnit = parse( code.toString() ); - List tudeclarations = translationUnit.getDeclarations(); - assertEquals( 1, tudeclarations.size() ); - SimpleDeclaration decl1 = (SimpleDeclaration)tudeclarations.get(0); - assertEquals( decl1.getDeclSpecifier().getType(), DeclSpecifier.t_int); - assertEquals( decl1.getDeclarators().size(), 1 ); - Declarator declarator = (Declarator)decl1.getDeclarators().get(0); - assertEquals( declarator.getName().toString(), "x"); - List arrayQualifiers = declarator.getArrayQualifiers(); - assertEquals( 2, arrayQualifiers.size() ); - ArrayQualifier q1 =(ArrayQualifier)arrayQualifiers.get(0); - assertNotNull( q1.getExpression() ); - List tokens = q1.getExpression().elements(); - assertEquals( tokens.size(), 1 ); - ArrayQualifier q2 =(ArrayQualifier)arrayQualifiers.get(1); - assertNull( q2.getExpression() ); - } - - public void testElaboratedParms() throws Exception - { - TranslationUnit tu = parse( "int x( struct A myA ) { /* junk */ }", true, true); - assertEquals( tu.getDeclarations().size(), 1 ); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals( declaration.getDeclSpecifier().getType(), DeclSpecifier.t_int ); - assertEquals( declaration.getDeclarators().size(), 1 ); - Declarator declarator = (Declarator)declaration.getDeclarators().get(0); - assertEquals( declarator.getName().toString(), "x" ); - assertTrue( declaration.isFunctionDefinition() ); - assertEquals( declarator.getParms().getDeclarations().size(), 1 ); - ParameterDeclaration parm = (ParameterDeclaration)declarator.getParms().getDeclarations().get(0); - ElaboratedTypeSpecifier typeSpec = (ElaboratedTypeSpecifier)parm.getTypeSpecifier(); - assertEquals( typeSpec.getClassKey(), ClassKey.t_struct ); - assertEquals( typeSpec.getName().toString(), "A" ); - assertEquals( parm.getDeclarators().size(), 1 ); - Declarator subDeclarator = (Declarator)parm.getDeclarators().get(0); - assertEquals( subDeclarator.getName().toString(), "myA" ); - - } - - public void testPreprocessor() throws Exception - { - Writer code = new StringWriter(); - code.write( "#include \n#define DEF VALUE\n"); - TranslationUnit tu = parse( code.toString(), true, true ); - assertEquals( tu.getInclusions().size(), 1 ); - Inclusion i = (Inclusion)tu.getInclusions().get(0); - assertEquals( i.getName(), "stdio.h"); - assertEquals( i.getStartingOffset(), 0 ); - assertEquals( i.getNameLength(), 7 ); - assertEquals( i.getNameOffset(), 10 ); - assertEquals( i.getTotalLength(), 18 ); - - assertEquals( tu.getMacros().size(), 1 ); - Macro m = (Macro)tu.getMacros().get(0); - assertEquals( m.getName(), "DEF" ); - assertEquals( m.getStartingOffset(), 19 ); - assertEquals( m.getNameLength(), 3 ); - assertEquals( m.getNameOffset(), 27 ); - assertEquals( m.getTotalLength(), 18 ); - } - - public void testMemberDeclarations() throws Exception - { - Writer code = new StringWriter(); - code.write( "class A {\n" ); - code.write( "public:\n"); - code.write( " int isPublic;\n" ); - code.write( "private:\n"); - code.write( " int isPrivate;\n" ); - code.write( "protected:\n"); - code.write( " int isProtected;\n" ); - code.write( "};"); - TranslationUnit translationUnit = parse( code.toString() ); - assertEquals( translationUnit.getDeclarations().size(), 1 ); - SimpleDeclaration classDeclaration = (SimpleDeclaration) - translationUnit.getDeclarations().get(0); - assertEquals( classDeclaration.getDeclarators().size(), 0 ); - ClassSpecifier classSpec = (ClassSpecifier)classDeclaration.getTypeSpecifier(); - assertEquals( "A", classSpec.getName().toString() ); - assertEquals( 3, classSpec.getDeclarations().size()); - for( int i = 0; i < 3; ++i ) - { - SimpleDeclaration subDecl = (SimpleDeclaration)classSpec.getDeclarations().get( i ); - int visibility = AccessSpecifier.v_unknown; - - switch( i ) - { - case 0: - visibility = AccessSpecifier.v_public; - break; - case 1: - visibility = AccessSpecifier.v_private; - break; - case 2: - visibility = AccessSpecifier.v_protected; - break; - default: - break; - } - - assertEquals( visibility, subDecl.getAccessSpecifier().getAccess() ); - } - - } - - public void testPointerOperators() throws Exception - { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("int * x = 0, & y, * const * const volatile * z;"); - TranslationUnit translationUnit = parse(code.toString()); - - List tudeclarations = translationUnit.getDeclarations(); - assertEquals( 1, tudeclarations.size() ); - SimpleDeclaration decl1 = (SimpleDeclaration)tudeclarations.get(0); - assertEquals( decl1.getDeclSpecifier().getType(), DeclSpecifier.t_int); - - assertEquals( 3, decl1.getDeclarators().size() ); - - Declarator declarator1 = (Declarator)decl1.getDeclarators().get( 0 ); - assertEquals( declarator1.getName().toString(), "x" ); - Expression initValue1 = declarator1.getExpression(); - assertEquals( initValue1.elements().size(), 1 ); - List ptrOps1 = declarator1.getPointerOperators(); - assertNotNull( ptrOps1 ); - assertEquals( 1, ptrOps1.size() ); - PointerOperator po1 = (PointerOperator)ptrOps1.get(0); - assertNotNull( po1 ); - assertFalse( po1.isConst() ); - assertFalse( po1.isVolatile() ); - assertEquals( po1.getType(), PointerOperator.t_pointer ); - Token t1 = (Token)initValue1.elements().get(0); - assertEquals( t1.getType(), IToken.tINTEGER ); - assertEquals( t1.getImage(), "0"); - - Declarator declarator2 = (Declarator)decl1.getDeclarators().get( 1 ); - assertEquals( declarator2.getName().toString(), "y" ); - assertNull( declarator2.getExpression() ); - List ptrOps2 = declarator2.getPointerOperators(); - assertNotNull( ptrOps2 ); - assertEquals( 1, ptrOps2.size() ); - PointerOperator po2 = (PointerOperator)ptrOps2.get(0); - assertNotNull( po2 ); - assertFalse( po2.isConst() ); - assertFalse( po2.isVolatile() ); - assertEquals( po2.getType(), PointerOperator.t_reference ); - - Declarator declarator3 = (Declarator)decl1.getDeclarators().get( 2 ); - assertEquals( "z", declarator3.getName().toString() ); - List ptrOps3 = declarator3.getPointerOperators(); - assertNotNull( ptrOps3 ); - assertEquals( 3, ptrOps3.size() ); - - //* const - PointerOperator po3 = (PointerOperator)ptrOps3.get(0); - assertNotNull( po3 ); - assertTrue( po3.isConst() ); - assertFalse( po3.isVolatile() ); - assertEquals( po3.getType(), PointerOperator.t_pointer ); - // * const volatile - PointerOperator po4 = (PointerOperator)ptrOps3.get(1); - assertNotNull( po4 ); - assertEquals( po4.getType(), PointerOperator.t_pointer ); - assertTrue( po4.isConst() ); - assertTrue( po4.isVolatile() ); - // * - PointerOperator po5 = (PointerOperator)ptrOps3.get(2); - assertNotNull( po5 ); - assertFalse( po5.isConst() ); - assertFalse( po5.isVolatile() ); - assertEquals( po5.getType(), PointerOperator.t_pointer ); - } - - public void testBug26467() throws Exception - { - StringWriter code = new StringWriter(); - code.write( "struct foo { int fooInt; char fooChar; };\n" ); - code.write( "typedef struct foo fooStruct;\n" ); - code.write( "typedef struct { int anonInt; char anonChar; } anonStruct;\n" ); - - TranslationUnit tu = parse( code.toString() ); - List tuDeclarations = tu.getDeclarations(); - assertEquals( tuDeclarations.size(), 3 ); - - SimpleDeclaration declaration = (SimpleDeclaration)tuDeclarations.get(0); - ClassSpecifier classSpec = (ClassSpecifier)declaration.getTypeSpecifier(); - assertEquals( declaration.getDeclarators().size(), 0 ); - assertEquals( classSpec.getClassKey(), ClassKey.t_struct); - assertEquals( classSpec.getName().toString(), "foo"); - List subDeclarations = classSpec.getDeclarations(); - assertEquals( subDeclarations.size(), 2 ); - SimpleDeclaration subDeclaration = (SimpleDeclaration)subDeclarations.get(0); - assertEquals( subDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_int); - assertEquals( subDeclaration.getDeclarators().size(), 1 ); - assertEquals( ((Declarator)subDeclaration.getDeclarators().get(0)).getName().toString(), "fooInt" ); - subDeclaration = (SimpleDeclaration)subDeclarations.get(1); - assertEquals( subDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_char); - assertEquals( subDeclaration.getDeclarators().size(), 1 ); - assertEquals( ((Declarator)subDeclaration.getDeclarators().get(0)).getName().toString(), "fooChar" ); - - declaration = (SimpleDeclaration)tuDeclarations.get(1); - assertEquals( declaration.getDeclSpecifier().isTypedef(), true ); - ElaboratedTypeSpecifier elab = (ElaboratedTypeSpecifier)declaration.getTypeSpecifier(); - assertEquals( elab.getClassKey(), ClassKey.t_struct); - assertEquals( elab.getName().toString(), "foo" ); - assertEquals( declaration.getDeclarators().size(), 1 ); - assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getName().toString(), "fooStruct" ); - - declaration = (SimpleDeclaration)tuDeclarations.get(2); - assertEquals( declaration.getDeclSpecifier().isTypedef(), true ); - classSpec = (ClassSpecifier) declaration.getTypeSpecifier(); - assertEquals( classSpec.getClassKey(), ClassKey.t_struct ); - assertNull( classSpec.getName() ); - subDeclarations = classSpec.getDeclarations(); - assertEquals( subDeclarations.size(), 2 ); - subDeclaration = (SimpleDeclaration)subDeclarations.get(0); - assertEquals( subDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_int); - assertEquals( subDeclaration.getDeclarators().size(), 1 ); - assertEquals( ((Declarator)subDeclaration.getDeclarators().get(0)).getName().toString(), "anonInt" ); - subDeclaration = (SimpleDeclaration)subDeclarations.get(1); - assertEquals( subDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_char); - assertEquals( subDeclaration.getDeclarators().size(), 1 ); - assertEquals( ((Declarator)subDeclaration.getDeclarators().get(0)).getName().toString(), "anonChar" ); - assertEquals( declaration.getDeclarators().size(), 1 ); - assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getName().toString(), "anonStruct" ); - } - - public void testASMDefinition() throws Exception - { - TranslationUnit tu = parse( "asm( \"mov ep1 ds2\");" ); - assertEquals( tu.getDeclarations().size(), 1 ); - ASMDefinition asm = (ASMDefinition)tu.getDeclarations().get(0); - assertEquals( asm.getAssemblyCode(), "mov ep1 ds2" ); - } - - public void testConstructorChain() throws Exception - { - TranslationUnit tu = parse( "TrafficLight_Actor::TrafficLight_Actor( RTController * rtg_rts, RTActorRef * rtg_ref ) : RTActor( rtg_rts, rtg_ref ), myId( 0 ) {}", true, true); - List tuDeclarations = tu.getDeclarations(); - assertEquals( tuDeclarations.size(), 1 ); - SimpleDeclaration decl1 = (SimpleDeclaration)tuDeclarations.get(0); - List declarators1 = decl1.getDeclarators(); - assertEquals( declarators1.size(), 1 ); - Declarator declarator1 = (Declarator)declarators1.get(0); - assertEquals( declarator1.getName().toString(), "TrafficLight_Actor::TrafficLight_Actor"); - ConstructorChain chain1 = declarator1.getCtorChain(); - List chainElements1 = chain1.getChainElements(); - assertEquals( chainElements1.size(), 2 ); - ConstructorChainElement element1_1 = (ConstructorChainElement) chainElements1.get(0); - assertEquals( element1_1.getName().toString(), "RTActor"); - - } - - public void testTemplateDeclarationOfMethod() throws Exception - { - TranslationUnit tu = parse( "template A aTemplatedFunction( B bInstance );"); - assertEquals( tu.getDeclarations().size(), 1 ); - TemplateDeclaration templateDeclaration = (TemplateDeclaration)tu.getDeclarations().get(0); - assertEquals( templateDeclaration.getTemplateParms().getDeclarations().size(), 2 ); - TemplateParameter templateParameter = (TemplateParameter)templateDeclaration.getTemplateParms().getDeclarations().get(0); - assertEquals( templateParameter.getKind(), TemplateParameter.k_class ); - assertEquals( templateParameter.getName().toString(), "A"); - templateParameter = (TemplateParameter)templateDeclaration.getTemplateParms().getDeclarations().get(1); - assertEquals( templateParameter.getKind(), TemplateParameter.k_typename ); - assertEquals( templateParameter.getName().toString(), "B"); - assertEquals( templateParameter.getTypeId().toString(), "C"); - assertEquals( templateDeclaration.getDeclarations().size(), 1 ); - SimpleDeclaration methodDeclaration = (SimpleDeclaration) templateDeclaration.getDeclarations().get(0); - assertEquals( methodDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_type ); - assertEquals( methodDeclaration.getDeclSpecifier().getTypeName(), "A"); - assertEquals( methodDeclaration.getDeclarators().size(), 1 ); - Declarator declarator = (Declarator)methodDeclaration.getDeclarators().get(0); - assertEquals( declarator.getName().toString(), "aTemplatedFunction" ); - assertEquals( declarator.getParms().getDeclarations().size(), 1 ); - ParameterDeclaration parameterDeclaration = (ParameterDeclaration)declarator.getParms().getDeclarations().get(0); - assertEquals( parameterDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_type ); - assertEquals( parameterDeclaration.getDeclSpecifier().getTypeName(), "B" ); - assertEquals( parameterDeclaration.getDeclarators().size(), 1 ); - assertEquals( ((Declarator)parameterDeclaration.getDeclarators().get(0)).getName().toString(), "bInstance"); - } - - public void testTemplateDeclarationOfClass() throws Exception { - TranslationUnit tu = parse( "template class, template class AClass> class myarray { /* ... */ };"); - assertEquals( tu.getDeclarations().size(), 1 ); - TemplateDeclaration declaration = (TemplateDeclaration)tu.getDeclarations().get(0); - assertEquals( declaration.getTemplateParms().getDeclarations().size(), 8 ); - TemplateParameter parameter = (TemplateParameter)declaration.getTemplateParms().getDeclarations().get(0); - assertEquals( parameter.getKind(), TemplateParameter.k_class); - assertEquals( parameter.getName().toString(), "T" ); - assertNull( parameter.getTypeId()); - parameter = (TemplateParameter)declaration.getTemplateParms().getDeclarations().get(1); - assertEquals( parameter.getKind(), TemplateParameter.k_typename); - assertEquals( parameter.getName().toString(), "Tibor" ); - assertEquals( parameter.getTypeId().toString(), "junk"); - parameter = (TemplateParameter)declaration.getTemplateParms().getDeclarations().get(2); - assertEquals( parameter.getKind(), TemplateParameter.k_class); - assertNull( parameter.getName() ); - assertNull( parameter.getTypeId()); - parameter = (TemplateParameter)declaration.getTemplateParms().getDeclarations().get(3); - assertEquals( parameter.getKind(), TemplateParameter.k_typename); - assertNull( parameter.getName() ); - assertNull( parameter.getTypeId()); - ParameterDeclaration decl = (ParameterDeclaration)declaration.getTemplateParms().getDeclarations().get(4); - assertEquals( decl.getDeclSpecifier().getType(), DeclSpecifier.t_int ); - assertEquals( 1, decl.getDeclarators().size() ); - assertEquals( "x", ((Declarator)decl.getDeclarators().get(0)).getName().toString() ); - - decl = (ParameterDeclaration)declaration.getTemplateParms().getDeclarations().get(5); - assertEquals( decl.getDeclSpecifier().getType(), DeclSpecifier.t_float ); - assertEquals( 1, decl.getDeclarators().size() ); - assertEquals( "y", ((Declarator)decl.getDeclarators().get(0)).getName().toString() ); - - parameter = (TemplateParameter)declaration.getTemplateParms().getDeclarations().get(6); - assertEquals( parameter.getKind(), TemplateParameter.k_template ); - assertEquals( parameter.getTemplateParms().getDeclarations().size(), 1 ); - assertNull( parameter.getName() ); - TemplateParameter subParameter = (TemplateParameter)parameter.getTemplateParms().getDeclarations().get(0); - assertEquals( subParameter.getKind(), TemplateParameter.k_class ); - assertEquals( subParameter.getName().toString(), "Y" ); - assertNull( subParameter.getTypeId() ); - - parameter = (TemplateParameter)declaration.getTemplateParms().getDeclarations().get(7); - assertEquals( parameter.getKind(), TemplateParameter.k_template ); - assertEquals( parameter.getTemplateParms().getDeclarations().size(), 1 ); - subParameter = (TemplateParameter)parameter.getTemplateParms().getDeclarations().get(0); - assertEquals( subParameter.getKind(), TemplateParameter.k_class ); - assertEquals( subParameter.getName().toString(), "A" ); - assertNull( subParameter.getTypeId() ); - assertEquals( parameter.getName().toString(), "AClass" ); - assertEquals( declaration.getDeclarations().size(), 1 ); - SimpleDeclaration myArray = (SimpleDeclaration)declaration.getDeclarations().get(0); - ClassSpecifier classSpec = (ClassSpecifier)myArray.getTypeSpecifier(); - assertEquals( classSpec.getClassKey(), ClassKey.t_class ); - assertEquals( classSpec.getName().toString(), "myarray"); - assertEquals( 0, classSpec.getDeclarations().size() ); - } - - public void testStruct() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "struct mad_bitptr { unsigned char const *byte;\n" ); writer.write( "unsigned short cache;\n unsigned short left;};" ); - TranslationUnit tu = parse( writer.toString() ); - assertEquals( tu.getDeclarations().size(), 1 ); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get( 0 ); - ClassSpecifier classSpec = (ClassSpecifier)declaration.getTypeSpecifier(); - DeclSpecifier declSpec = declaration.getDeclSpecifier(); - assertEquals( classSpec.getClassKey(), ClassKey.t_struct ); - assertEquals( classSpec.getName().toString(), "mad_bitptr" ); - assertEquals( declaration.getDeclarators().size(), 0 ); - List subDeclarations = classSpec.getDeclarations(); - assertEquals( 3, subDeclarations.size() ); - declaration = (SimpleDeclaration)subDeclarations.get(0); - declSpec = declaration.getDeclSpecifier(); - assertTrue( declSpec.isUnsigned() ); - assertTrue( declSpec.isConst() ); - assertEquals( declSpec.getType(), DeclSpecifier.t_char ); - assertEquals( declaration.getDeclarators().size(), 1 ); - Declarator d = (Declarator)declaration.getDeclarators().get(0); - assertEquals( d.getPointerOperators().size(), 1 ); - PointerOperator po = (PointerOperator)d.getPointerOperators().get(0); - assertEquals( po.getType(), PointerOperator.t_pointer ); - assertFalse( po.isConst() ); - assertFalse(po.isVolatile() ); - assertEquals( d.getName().toString(), "byte" ); - - declaration = (SimpleDeclaration)subDeclarations.get(1); - declSpec = declaration.getDeclSpecifier(); - assertTrue( declSpec.isUnsigned()); - assertTrue( declSpec.isShort()); - assertEquals( declaration.getDeclarators().size(), 1 ); - d = (Declarator)declaration.getDeclarators().get(0); - assertEquals( d.getPointerOperators().size(), 0 ); - assertEquals( d.getName().toString(), "cache" ); - - - declaration = (SimpleDeclaration)subDeclarations.get(2); - declSpec = declaration.getDeclSpecifier(); - assertTrue( declSpec.isUnsigned()); - assertTrue( declSpec.isShort()); - assertEquals( declaration.getDeclarators().size(), 1 ); - d = (Declarator)declaration.getDeclarators().get(0); - assertEquals( d.getPointerOperators().size(), 0 ); - assertEquals( d.getName().toString(), "left" ); - } - - - public void testBug35906() throws Exception - { - StringWriter code = new StringWriter(); - code.write( "void TTest::MTest() {}\n" ); - code.write( "struct TTest::STest *TTest::FTest (int i) {}\n" ); - TranslationUnit tu = parse( code.toString() ); - assertEquals( tu.getDeclarations().size(), 2 ); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals( declaration.getDeclSpecifier().getType(), DeclSpecifier.t_void ); - assertEquals( declaration.getDeclarators().size(), 1 ); - Declarator d = (Declarator)declaration.getDeclarators().get(0); - assertEquals( d.getName().toString(), "TTest::MTest"); - - declaration = (SimpleDeclaration)tu.getDeclarations().get(1); - ElaboratedTypeSpecifier spec = (ElaboratedTypeSpecifier)declaration.getTypeSpecifier(); - assertEquals( spec.getClassKey(), ClassKey.t_struct ); - assertEquals( spec.getName().toString(), "TTest::STest" ); - } - - public void testBug36073() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "class A{\n" ); - writer.write( "int x;\n" ); - writer.write( "public:\n" ); - writer.write( "A(const A&);\n" ); - writer.write( "};\n" ); - writer.write( "A::A(const A&v) : x(v.x) { }\n" ); - } - - public void testBug36288() throws Exception - { - TranslationUnit tu = parse( "int foo() {}\nlong foo2(){}", true, true); - assertEquals( tu.getDeclarations().size(), 2 ); - for( int i = 0; i < 2; ++i ) - { - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(i); - assertEquals( declaration.getDeclarators().size(), 1 ); - Declarator d = (Declarator)declaration.getDeclarators().get(0); - assertEquals( d.getName().toString(), ( i == 0 ) ? "foo" : "foo2"); - assertEquals( declaration.getDeclSpecifier().getType(), (i == 0 ) ? DeclSpecifier.t_int : DeclSpecifier.t_type ); - assertEquals( declaration.getDeclSpecifier().isLong(), ( i == 0 ) ? false : true ); - } - } - - public void testBug36250() throws Exception - { - TranslationUnit tu = parse( "int f( int = 0 );"); - assertEquals( tu.getDeclarations().size(), 1 ); - SimpleDeclaration functionDeclaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals( functionDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_int ); - assertEquals( functionDeclaration.getDeclarators().size(), 1 ); - Declarator functionDeclarator = (Declarator)functionDeclaration.getDeclarators().get(0); - assertEquals( functionDeclarator.getName().toString(), "f" ); - assertEquals( functionDeclarator.getParms().getDeclarations().size(), 1 ); - ParameterDeclaration parameterDeclaration = (ParameterDeclaration)functionDeclarator.getParms().getDeclarations().get(0); - assertEquals( parameterDeclaration .getDeclSpecifier().getType(), DeclSpecifier.t_int ); - assertEquals( parameterDeclaration .getDeclarators().size(), 1 ); - Declarator parameterDeclarator = (Declarator)parameterDeclaration.getDeclarators().get(0); - assertNull( parameterDeclarator.getName() ); - assertNotNull( parameterDeclarator.getExpression()); - - } - - public void testBug36240() throws Exception - { - TranslationUnit tu = parse( "A & A::operator=( A ){}"); - assertEquals( tu.getDeclarations().size(), 1 ); - SimpleDeclaration functionDeclaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals( functionDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_type ); - assertEquals( functionDeclaration.getDeclSpecifier().getTypeName(), "A" ); - assertEquals( functionDeclaration.getDeclarators().size(), 1 ); - Declarator functionDeclarator = (Declarator)functionDeclaration.getDeclarators().get(0); - assertEquals( functionDeclarator.getPointerOperators().size(), 1 ); - PointerOperator po = (PointerOperator)functionDeclarator.getPointerOperators().get(0); - assertEquals( po.getType(), PointerOperator.t_reference ); - assertFalse( po.isConst() || po.isVolatile() ); - assertEquals( functionDeclarator.getName().toString(), "A::operator ="); - assertEquals( functionDeclarator.getParms().getDeclarations().size(), 1 ); - ParameterDeclaration parameterDeclaration = (ParameterDeclaration)functionDeclarator.getParms().getDeclarations().get(0); - assertEquals( parameterDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_type ); - assertEquals( parameterDeclaration.getDeclSpecifier().getTypeName(), "A"); - assertEquals( parameterDeclaration .getDeclarators().size(), 1 ); - Declarator parameterDeclarator = (Declarator)parameterDeclaration.getDeclarators().get(0); - assertNull( parameterDeclarator.getName() ); - } - - public void testBug36254() throws Exception - { - TranslationUnit tu = parse( "unsigned i;\nvoid f( unsigned p1 = 0 );"); - assertEquals( tu.getDeclarations().size(), 2 ); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertTrue( declaration.getDeclSpecifier().isUnsigned()); - assertEquals( 1, declaration.getDeclarators().size() ); - assertEquals( "i", ((Declarator)declaration.getDeclarators().get(0)).getName().toString() ); - declaration = (SimpleDeclaration)tu.getDeclarations().get(1); - assertEquals( declaration.getDeclSpecifier().getType(), DeclSpecifier.t_void ); - assertEquals( 1, declaration.getDeclarators().size() ); - Declarator declarator = (Declarator)declaration.getDeclarators().get(0); - assertEquals( declarator.getName().toString(), "f" ); - assertEquals( declarator.getParms().getDeclarations().size(), 1 ); - ParameterDeclaration parmDecl = (ParameterDeclaration)declarator.getParms().getDeclarations().get(0); - assertTrue( parmDecl.getDeclSpecifier().isUnsigned()); - assertEquals( parmDecl.getDeclarators().size(), 1 ); - Declarator parmDeclarator = (Declarator) parmDecl.getDeclarators().get(0); - assertEquals( parmDeclarator.getName().toString(), "p1"); - assertNotNull( parmDeclarator.getExpression()); - } - - public void testBug36237() throws Exception - { - TranslationUnit tu = parse( "A::A():B( (char *)0 ){}", true, true ); - assertEquals( tu.getDeclarations().size(), 1 ); - } - - public void testPointersToFunctions() throws Exception - { - Writer code = new StringWriter(); - code.write( "void (*name)( void );\n"); - code.write( "static void * (*orig_malloc_hook)(const char *file, int line, size_t size);\n"); - - TranslationUnit tu = parse( code.toString() ); - assertEquals( tu.getDeclarations().size(), 2 ); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals( declaration.getDeclSpecifier().getType(), DeclSpecifier.t_void ); - assertEquals( declaration.getDeclarators().size(), 1); - assertNull( ((Declarator)declaration.getDeclarators().get(0)).getName() ); - assertNotNull( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator() ); - assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator().getName().toString(), "name" ); - ParameterDeclarationClause clause = ((Declarator)declaration.getDeclarators().get(0)).getParms(); - assertEquals( clause.getDeclarations().size(), 1 ); - assertEquals( ((ParameterDeclaration)clause.getDeclarations().get(0)).getDeclarators().size(), 1 ); - assertNull( ((Declarator)((ParameterDeclaration)clause.getDeclarations().get(0)).getDeclarators().get(0)).getName() ); - assertEquals( ((ParameterDeclaration)clause.getDeclarations().get(0)).getDeclSpecifier().getType(), DeclSpecifier.t_void ); - - declaration = (SimpleDeclaration)tu.getDeclarations().get(1); - assertEquals( declaration.getDeclSpecifier().getType(), DeclSpecifier.t_void ); - assertTrue( declaration.getDeclSpecifier().isStatic() ); - assertEquals( declaration.getDeclarators().size(), 1); - assertNull( ((Declarator)declaration.getDeclarators().get(0)).getName() ); - assertNotNull( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator() ); - assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator().getName().toString(), "orig_malloc_hook" ); - clause = ((Declarator)declaration.getDeclarators().get(0)).getParms(); - assertEquals( clause.getDeclarations().size(), 3 ); - } - - public void testBug36532() throws Exception - { - try - { - TranslationUnit tu = parse( "template class B {};\n" ); - code.write( "template<> class B {};\n" ); - code.write( "}\n" ); - TranslationUnit tu = parse( code.toString() ); - assertEquals( tu.getDeclarations().size(),1); - NamespaceDefinition definition = (NamespaceDefinition)tu.getDeclarations().get(0); - assertEquals( definition.getName().toString(), "myNameSpace"); - assertEquals( definition.getDeclarations().size(), 2 ); - TemplateDeclaration templateDeclaration = (TemplateDeclaration)definition.getDeclarations().get(0); - assertFalse( templateDeclaration.isExported()); - assertEquals( templateDeclaration.getTemplateParms().getDeclarations().size(), 1 ); - TemplateParameter parm = (TemplateParameter)templateDeclaration.getTemplateParms().getDeclarations().get(0); - assertEquals( parm.getKind(), TemplateParameter.k_typename ); - assertEquals( parm.getName().toString(), "T"); - assertEquals( parm.getTypeId().toString(), "short"); - assertEquals( templateDeclaration.getDeclarations().size(), 1 ); - SimpleDeclaration classB = (SimpleDeclaration)templateDeclaration.getDeclarations().get(0); - assertEquals( classB.getDeclarators().size(), 0 ); - assertEquals( ((ClassSpecifier)classB.getTypeSpecifier()).getName().toString(), "B" ); - assertEquals( ((ClassSpecifier)classB.getTypeSpecifier()).getClassKey(), ClassKey.t_class ); - assertEquals( ((ClassSpecifier)classB.getTypeSpecifier()).getDeclarations().size(), 0 ); - - ExplicitTemplateDeclaration etd = (ExplicitTemplateDeclaration)definition.getDeclarations().get(1); - assertEquals( etd.getKind(), ExplicitTemplateDeclaration.k_specialization ); - assertEquals( etd.getDeclarations().size(), 1 ); - classB = (SimpleDeclaration)etd.getDeclarations().get(0); - assertEquals( classB.getDeclarators().size(), 0 ); - assertEquals( ((ClassSpecifier)classB.getTypeSpecifier()).getName().toString(), "B" ); - assertEquals( ((ClassSpecifier)classB.getTypeSpecifier()).getClassKey(), ClassKey.t_class ); - assertEquals( ((ClassSpecifier)classB.getTypeSpecifier()).getDeclarations().size(), 0 ); - - } - - public void testBug36551() throws Exception - { - Writer code = new StringWriter(); - code.write( "class TextFrame {\n" ); - code.write( "BAD_MACRO()\n"); - code.write( "};"); - TranslationUnit tu = parse( code.toString(), true, false ); - assertFalse( tu.isParseSuccessful() ); - assertEquals( tu.getDeclarations().size(), 1 ); - SimpleDeclaration d = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals( d.getDeclarators().size(), 0 ); - ClassSpecifier classSpec = (ClassSpecifier)d.getTypeSpecifier(); - assertEquals( classSpec.getClassKey(), ClassKey.t_class ); - assertEquals( classSpec.getName().toString(), "TextFrame"); - assertEquals( classSpec.getDeclarations().size(), 0 ); - - code = new StringWriter(); - code.write( "namespace X { class A }"); - tu = parse( code.toString(), true, false ); - assertFalse( tu.isParseSuccessful() ); - assertEquals( tu.getDeclarations().size(), 1 ); - NamespaceDefinition nd = (NamespaceDefinition)tu.getDeclarations().get(0); - assertEquals( nd.getDeclarations().size(), 0 ); - assertEquals( nd.getName().toString(), "X"); - - code = new StringWriter(); - code.write( "extern \"C\" { JUNK }" ); - tu = parse( code.toString(), true, false ); - assertFalse( tu.isParseSuccessful() ); - assertEquals( tu.getDeclarations().size(), 1 ); - LinkageSpecification ls = (LinkageSpecification)tu.getDeclarations().get(0); - assertEquals( ls.getDeclarations().size(), 0); - assertEquals( ls.getLanguageLinkage(), "C" ); - } - - public void testBug36692() throws Exception { - Writer code = new StringWriter(); - code.write("template \n"); - code.write("void SetLongevity(T* pDynObject, unsigned int longevity,\n"); - code.write("Destroyer d = Private::Deleter::Delete){}\n"); - - TranslationUnit tu = parse(code.toString()); - assertEquals( tu.getDeclarations().size(), 1 ); - TemplateDeclaration template = (TemplateDeclaration)tu.getDeclarations().get(0); - assertFalse( template.isExported() ); - TemplateParameterList list = template.getTemplateParms(); - assertEquals( list.getDeclarations().size(), 2 ); - for( int i = 0; i < 2; ++i ) - { - TemplateParameter parameter = (TemplateParameter)list.getDeclarations().get(i); - assertEquals( parameter.getName().toString(), i == 0 ? "T": "Destroyer"); - assertEquals( parameter.getKind(), TemplateParameter.k_typename ); - } - assertEquals( template.getDeclarations().size(), 1 ); - SimpleDeclaration method = (SimpleDeclaration)template.getDeclarations().get(0); - assertEquals( method.getDeclSpecifier().getType(), DeclSpecifier.t_void ); - assertEquals( method.getDeclarators().size(), 1 ); - assertEquals( method.isFunctionDefinition(), true ); - Declarator declarator = (Declarator)method.getDeclarators().get(0); - assertEquals( declarator.getName().toString(), "SetLongevity"); - ParameterDeclarationClause pdc = declarator.getParms(); - assertEquals( pdc.getDeclarations().size(), 3 ); - for( int i = 0; i < 3; ++i ) - { - ParameterDeclaration parameter = (ParameterDeclaration)pdc.getDeclarations().get(i); - assertEquals( parameter.getDeclarators().size(), 1 ); - Declarator parameterDeclarator = (Declarator)parameter.getDeclarators().get(0); - List pointers = parameterDeclarator.getPointerOperators(); - PointerOperator op = null; - Expression exp = parameterDeclarator.getExpression(); - switch( i ) - { - case 0: - assertEquals( parameterDeclarator.getName().toString(), "pDynObject"); - assertEquals( pointers.size(), 1 ); - op = (PointerOperator)pointers.get(0); - assertFalse( op.isConst()); - assertFalse( op.isVolatile()); - assertEquals( op.getType(), PointerOperator.t_pointer); - assertNull( exp ); - break; - case 1: - assertEquals( parameterDeclarator.getName().toString(), "longevity"); - assertEquals( pointers.size(), 0 ); - assertEquals( parameter.getDeclSpecifier().getType(), DeclSpecifier.t_int ); - assertTrue( parameter.getDeclSpecifier().isUnsigned() ); - assertNull( exp ); - break; - case 2: - assertEquals( parameterDeclarator.getName().toString(), "d"); - assertEquals( pointers.size(), 0 ); - assertNotNull( exp ); - break; - default: - break; - } - } - - } - - public void testBug36708() throws Exception { - TranslationUnit tu = parse("enum { isPointer = PointerTraits::result };"); - assertEquals( tu.getDeclarations().size(), 1 ); - SimpleDeclaration simple = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals( simple.getDeclarators().size(), 0 ); - EnumerationSpecifier enum = (EnumerationSpecifier)simple.getTypeSpecifier(); - assertNull( enum.getName() ); - List enumerators = enum.getEnumeratorDefinitions(); - assertEquals( enumerators.size(), 1 ); - EnumeratorDefinition enumerator = (EnumeratorDefinition )enumerators.get(0); - assertEquals( enumerator.getName().toString(), "isPointer"); - assertNotNull( enumerator.getExpression() ); - } - - public void testWeirdExpression() throws Exception - { - parse( "int x = rhs.spImpl_.get();"); - } - - public void testBug36690() throws Exception { - TranslationUnit tu = parse("Functor(const Functor& rhs) : spImpl_(Impl::Clone(rhs.spImpl_.get())){}"); - assertEquals( tu.getDeclarations().size(), 1 ); - SimpleDeclaration simple = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals( simple.getDeclarators().size(), 1 ); - Declarator declarator = (Declarator)simple.getDeclarators().get(0); - ParameterDeclarationClause pdc = declarator.getParms(); - assertEquals( pdc.getDeclarations().size(), 1 ); - ConstructorChain chain = declarator.getCtorChain(); - assertEquals( chain.getChainElements().size(), 1 ); - } - - public void testBug36703() throws Exception { - TranslationUnit tu = parse("const std::type_info& Get() const;"); - assertEquals( tu.getDeclarations().size(), 1 ); - SimpleDeclaration simple = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals( simple.getDeclSpecifier().isConst(), true ); - assertEquals( simple.getDeclSpecifier().getType(), DeclSpecifier.t_type); - assertEquals( simple.getDeclSpecifier().getTypeName(), "std::type_info"); - assertEquals( simple.getDeclarators().size(), 1 ); - Declarator declarator = (Declarator)simple.getDeclarators().get(0); - ParameterDeclarationClause pdc = declarator.getParms(); - assertTrue( declarator.isConst() ); - assertEquals( pdc.getDeclarations().size(), 0 ); - assertEquals( declarator.getName().toString(), "Get"); - assertEquals( declarator.getPointerOperators().size(), 1 ); - PointerOperator pointerOperator = (PointerOperator)declarator.getPointerOperators().get(0); - assertFalse( pointerOperator.isConst()); - assertFalse( pointerOperator.isVolatile()); - assertEquals( pointerOperator.getType(), PointerOperator.t_reference); - } - - public void testBug36689() throws Exception { - Writer code = new StringWriter(); - code.write("template\n"); - code.write("<\n"); - code.write("class AbstractFact,\n"); - code.write( - "template class Creator = OpNewFactoryUnit,\n"); - code.write("class TList = typename AbstractFact::ProductList\n"); - code.write(">\n"); - code.write("class ConcreteFactory\n"); - code.write(": public GenLinearHierarchy<\n"); - code.write( - "typename TL::Reverse::Result, Creator, AbstractFact>\n"); - code.write("{\n"); - code.write("public:\n"); - code.write( - "typedef typename AbstractFact::ProductList ProductList;\n"); - code.write("typedef TList ConcreteProductList;\n"); - code.write("};\n"); - TranslationUnit tu = parse(code.toString()); - } - - public void testBug36707() throws Exception { - TranslationUnit tu = - parse("enum { exists = sizeof(typename H::Small) == sizeof((H::Test(H::MakeT()))) };"); - } - - public void testBug36717() throws Exception { - TranslationUnit tu = parse("enum { eA = A::b };"); - } - - public void testBug36693() throws Exception { - TranslationUnit tu = - parse("FixedAllocator::Chunk* FixedAllocator::VicinityFind(void* p){}"); - } - - public void testBug36696() throws Exception { - Writer code = new StringWriter(); - code.write( - "template RefCounted(const RefCounted& rhs)\n"); - code.write( - ": pCount_(reinterpret_cast(rhs).pCount_) {}\n"); - TranslationUnit tu = parse(code.toString()); - } - - public void testBug36713() throws Exception { - Writer code = new StringWriter(); - code.write("A ( * const fPtr) (void *); \n"); - code.write("A (* const fPtr2) ( A * ); \n"); - TranslationUnit tu = parse(code.toString()); - assertEquals( tu.getDeclarations().size(), 2 ); - SimpleDeclaration simple = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals( simple.getDeclarators().size(), 1) ; - Declarator top = (Declarator)simple.getDeclarators().get(0); - assertEquals( top.getPointerOperators().size(), 0 ); - assertNotNull( top.getDeclarator() ); - assertEquals( top.getDeclarator().getPointerOperators().size(), 1 ); - PointerOperator po = (PointerOperator)top.getDeclarator().getPointerOperators().get(0); - assertTrue( po.isConst()); - assertFalse( po.isVolatile()); - assertEquals( po.getType(), PointerOperator.t_pointer); - } - - public void testBug36794() throws Exception - { - TranslationUnit tu = parse( "template<> class allocator {};"); - Iterator i = tu.iterateOffsetableElements(); - while( i.hasNext() ) - assertNotNull( i.next() ); - } - - public void testBug36811() throws Exception - { - Writer code = new StringWriter(); - code.write( "using namespace std;\n" ); - code.write( "class Test {};" ); - TranslationUnit tu = parse( code.toString() ); - assertEquals( tu.getDeclarations().size(), 2 ); - Iterator i = tu.iterateOffsetableElements(); - while( i.hasNext() ) - assertNotNull( i.next() ); - } - - public void testBug36799() throws Exception - { - TranslationUnit tu = parse( "static const int __WORD_BIT = int(CHAR_BIT*sizeof(unsigned int));"); - assertEquals( tu.getDeclarations().size(), 1 ); - } - - public void testBug36852() throws Exception - { - Writer code = new StringWriter(); - code.write( "int CBT::senseToAllRect( double id_standardQuot = DOSE, double id_minToleranz =15.0,\n" ); - code.write( "double id_maxToleranz = 15.0, unsigned int iui_minY = 0, \n" ); - code.write( "unsigned int iui_maxY = HEIGHT );\n" ); - TranslationUnit tu = parse( code.toString() ); - } - - public void testBug36764() throws Exception - { - TranslationUnit tu = parse( "struct{ int x : 4; int y : 8; };" ); - assertEquals( tu.getDeclarations().size(), 1 ); - assertEquals( ((ClassSpecifier)((SimpleDeclaration)tu.getDeclarations().get(0)).getTypeSpecifier()).getDeclarations().size(), 2 ); - } - - public void testBug36702() throws Exception - { - Writer code = new StringWriter(); - code.write( "void mad_decoder_init(struct mad_decoder *, void *,\n" ); - code.write( " enum mad_flow (*)(void *, struct mad_stream *),\n" ); - code.write( " enum mad_flow (*)(void *, struct mad_header const *),\n" ); - code.write( " enum mad_flow (*)(void *,\n" ); - code.write( " struct mad_stream const *,\n" ); - code.write( " struct mad_frame *),\n" ); - code.write( " enum mad_flow (*)(void *,\n" ); - code.write( " struct mad_header const *,\n" ); - code.write( " struct mad_pcm *),\n" ); - code.write( " enum mad_flow (*)(void *,\n" ); - code.write( " struct mad_stream *,\n" ); - code.write( " struct mad_frame *),\n" ); - code.write( " enum mad_flow (*)(void *, void *, unsigned int *)\n" ); - code.write( ");\n" ); - - TranslationUnit tu = parse( code.toString() ); - - } - - public void testBug36771() throws Exception { - Writer code = new StringWriter(); - code.write("#include /**/ \"foo.h\"\n"); - - TranslationUnit tu = parse( code.toString(), true, true ); - - List includes = tu.getInclusions(); - - assertEquals( includes.size(), 1 ); - Inclusion include = (Inclusion)includes.get(0); - assertTrue( include.getName().equals("foo.h") ); - } - - public void testBug36714() throws Exception { - Writer code = new StringWriter(); - code.write("unsigned long a = 0UL;\n"); - code.write("unsigned long a2 = 0L; \n"); - - TranslationUnit tu = parse( code.toString() ); - } - - public void testBugFunctor758() throws Exception { - TranslationUnit tu = parse( "template Functor(Fun fun) : spImpl_(new FunctorHandler(fun)){}" ); - } - - public void testBug36932() throws Exception - { - TranslationUnit tu = parse( "A::A(): b( new int( 5 ) ), b( new B ), c( new int ) {}" ); - } - - public void testBug36704() throws Exception { - Writer code = new StringWriter(); - code.write( "template \n" ); - code.write( "struct Length< Typelist >\n" ); - code.write( "{\n" ); - code.write( "enum { value = 1 + Length::value };\n" ); - code.write( "};\n" ); - parse(code.toString()); - } - - public void testBug36699() throws Exception { - Writer code = new StringWriter(); - code.write( - "template < template class ThreadingModel = DEFAULT_THREADING,\n"); - code.write("std::size_t chunkSize = DEFAULT_CHUNK_SIZE,\n"); - code.write( - "std::size_t maxSmallObjectSize = MAX_SMALL_OBJECT_SIZE >\n"); - code.write("class SmallObject : public ThreadingModel<\n"); - code.write( - "SmallObject >\n"); - code.write("{};\n"); - parse(code.toString()); - } - - public void testBug36691() throws Exception { - Writer code = new StringWriter(); - code.write("template \n"); - code.write( - "typename H::template Rebind::Result& Field(H& obj)\n"); - code.write("{ return obj; }\n"); - parse(code.toString()); - } - - public void testOrder() throws Exception - { - Writer code = new StringWriter(); - code.write( "#define __SGI_STL_INTERNAL_ALGOBASE_H\n" ); - code.write( "#include \n" ); - code.write( "template \n" ); - code.write( "inline void swap(_Tp& __a, _Tp& __b) {\n" ); - code.write( "__STL_REQUIRES(_Tp, _Assignable);\n" ); - code.write( "_Tp __tmp = __a;\n" ); - code.write( "__a = __b;\n" ); - code.write( "__b = __tmp;\n" ); - code.write( "}\n" ); - - Iterator i = parse( code.toString(), true, true ).iterateOffsetableElements(); - assertTrue( i.hasNext() ); - assertTrue( i.next() instanceof Macro ); - assertTrue( i.hasNext() ); - assertTrue( i.next() instanceof Inclusion ); - assertTrue( i.hasNext() ); - assertTrue( i.next() instanceof Declaration ); - assertFalse( i.hasNext() ); - } - - public void testBug37019() throws Exception { - parse("static const A a( 1, 0 );"); - } - - public void testBug36766and36769A() throws Exception { - Writer code = new StringWriter(); - code.write("template \n"); - code.write("rope<_CharT, _Alloc>::rope(size_t __n, _CharT __c,\n"); - code.write("const allocator_type& __a): _Base(__a)\n"); - code.write("{}\n"); - parse(code.toString()); - } - - public void testBug36766and36769B() throws Exception { - Writer code = new StringWriter(); - code.write("template\n"); - code.write("bool _Rope_insert_char_consumer<_CharT>::operator()\n"); - code.write("(const _CharT* __leaf, size_t __n)\n"); - code.write("{}\n"); - parse(code.toString()); - } - - public void testBug36766and36769C() throws Exception { - Writer code = new StringWriter(); - code.write("template \n"); - code.write("_Rope_char_ref_proxy<_CharT, _Alloc>&\n"); - code.write( - "_Rope_char_ref_proxy<_CharT, _Alloc>::operator= (_CharT __c)\n"); - code.write("{}\n"); - parse(code.toString()); - } - - public void testBug36766and36769D() throws Exception { - Writer code = new StringWriter(); - code.write("template \n"); - code.write("rope<_CharT, _Alloc>::~rope()\n"); - code.write("{}\n"); - parse(code.toString()); - } - - public void testBug36932A() throws Exception { - parse("A::A( ) : var( new char [ (unsigned)bufSize ] ) {}"); - } - - public void testBug36932B() throws Exception { - parse(" p = new int; "); - parse(" p = new int(5); "); - parse(" p = new int(B); "); - parse(" p = new int(B,C); "); - parse(" p = new int[5]; "); - parse(" p = new int[5][10]; "); - parse(" p = new int[B]; "); - parse(" p = new int[B][C][D]; "); - - parse(" p = new A; "); - parse(" p = new A(5); "); - parse(" p = new A(B); "); - parse(" p = new A(B,C); "); - parse(" p = new A[5]; "); - parse(" p = new A[5][10]; "); - parse(" p = new A[B]; "); - parse(" p = new A[B][C][D]; "); - - parse(" p = new (int); "); - parse(" p = new (int)(5); "); - parse(" p = new (int)(B); "); - parse(" p = new (int)(B,C); "); - parse(" p = new (int)[5]; "); - parse(" p = new (int)[5][10]; "); - parse(" p = new (int)[B]; "); - parse(" p = new (int)[B][C][D]; "); - - parse(" p = new (A); "); - parse(" p = new (A)(5); "); - parse(" p = new (A)(B); "); - parse(" p = new (A)(B,C); "); - parse(" p = new (A)[5]; "); - parse(" p = new (A)[5][10]; "); - parse(" p = new (A)[B]; "); - parse(" p = new (A)[B][C][D]; "); - - parse(" p = new (0) int; "); - parse(" p = new (0) int(5); "); - parse(" p = new (0) int(B); "); - parse(" p = new (0) int(B,C); "); - parse(" p = new (0) int[5]; "); - parse(" p = new (0) int[5][10]; "); - parse(" p = new (0) int[B]; "); - parse(" p = new (0) int[B][C][D]; "); - - parse(" p = new (0) A; "); - parse(" p = new (0) A(5); "); - parse(" p = new (0) A(B); "); - parse(" p = new (0) A(B,C); "); - parse(" p = new (0) A[5]; "); - parse(" p = new (0) A[5][10]; "); - parse(" p = new (0) A[B]; "); - parse(" p = new (0) A[B][C][D]; "); - - parse(" p = new (0) (int); "); - parse(" p = new (0) (int)(5); "); - parse(" p = new (0) (int)(B); "); - parse(" p = new (0) (int)(B,C); "); - parse(" p = new (0) (int)[5]; "); - parse(" p = new (0) (int)[5][10]; "); - parse(" p = new (0) (int)[B]; "); - parse(" p = new (0) (int)[B][C][D]; "); - - parse(" p = new (0) (A); "); - parse(" p = new (0) (A)(5); "); - parse(" p = new (0) (A)(B); "); - parse(" p = new (0) (A)(B,C); "); - parse(" p = new (0) (A)[5]; "); - parse(" p = new (0) (A)[5][10]; "); - parse(" p = new (0) (A)[B]; "); - parse(" p = new (0) (A)[B][C][D]; "); - - parse(" p = new (P) int; "); - parse(" p = new (P) int(5); "); - parse(" p = new (P) int(B); "); - parse(" p = new (P) int(B,C); "); - parse(" p = new (P) int[5]; "); - parse(" p = new (P) int[5][10]; "); - parse(" p = new (P) int[B]; "); - parse(" p = new (P) int[B][C][D]; "); - - parse(" p = new (P) A; "); - parse(" p = new (P) A(5); "); - parse(" p = new (P) A(B); "); - parse(" p = new (P) A(B,C); "); - parse(" p = new (P) A[5]; "); - parse(" p = new (P) A[5][10]; "); - parse(" p = new (P) A[B]; "); - parse(" p = new (P) A[B][C][D]; "); - - parse(" p = new (P) (int); "); - parse(" p = new (P) (int)(5); "); - parse(" p = new (P) (int)(B); "); - parse(" p = new (P) (int)(B,C); "); - parse(" p = new (P) (int)[5]; "); - parse(" p = new (P) (int)[5][10]; "); - parse(" p = new (P) (int)[B]; "); - parse(" p = new (P) (int)[B][C][D]; "); - - parse(" p = new (P) (A); "); - parse(" p = new (P) (A)(5); "); - parse(" p = new (P) (A)(B); "); - parse(" p = new (P) (A)(B,C); "); - parse(" p = new (P) (A)[5]; "); - parse(" p = new (P) (A)[5][10]; "); - parse(" p = new (P) (A)[B]; "); - parse(" p = new (P) (A)[B][C][D]; "); - } - - public void testBug36932C() throws Exception { - parse("X::X( ) : var( new int ) {}"); - parse("X::X( ) : var( new int(5) ) {}"); - parse("X::X( ) : var( new int(B) ) {}"); - parse("X::X( ) : var( new int(B,C) ) {}"); - parse("X::X( ) : var( new int[5] ) {}"); - parse("X::X( ) : var( new int[5][10] ) {}"); - parse("X::X( ) : var( new int[B] ) {}"); - parse("X::X( ) : var( new int[B][C][D] ) {}"); - - parse("X::X( ) : var( new A ) {}"); - parse("X::X( ) : var( new A(5) ) {}"); - parse("X::X( ) : var( new A(B) ) {}"); - parse("X::X( ) : var( new A(B,C) ) {}"); - parse("X::X( ) : var( new A[5] ) {}"); - parse("X::X( ) : var( new A[5][10] ) {}"); - parse("X::X( ) : var( new A[B] ) {}"); - parse("X::X( ) : var( new A[B][C][D] ) {}"); - - parse("X::X( ) : var( new (int) ) {}"); - parse("X::X( ) : var( new (int)(5) ) {}"); - parse("X::X( ) : var( new (int)(B) ) {}"); - parse("X::X( ) : var( new (int)(B,C) ) {}"); - parse("X::X( ) : var( new (int)[5] ) {}"); - parse("X::X( ) : var( new (int)[5][10] ) {}"); - parse("X::X( ) : var( new (int)[B] ) {}"); - parse("X::X( ) : var( new (int)[B][C][D] ) {}"); - - parse("X::X( ) : var( new (A) ) {}"); - parse("X::X( ) : var( new (A)(5) ) {}"); - parse("X::X( ) : var( new (A)(B) ) {}"); - parse("X::X( ) : var( new (A)(B,C) ) {}"); - parse("X::X( ) : var( new (A)[5] ) {}"); - parse("X::X( ) : var( new (A)[5][10] ) {}"); - parse("X::X( ) : var( new (A)[B] ) {}"); - parse("X::X( ) : var( new (A)[B][C][D] ) {}"); - - parse("X::X( ) : var( new (0) int ) {}"); - parse("X::X( ) : var( new (0) int(5) ) {}"); - parse("X::X( ) : var( new (0) int(B) ) {}"); - parse("X::X( ) : var( new (0) int(B,C) ) {}"); - parse("X::X( ) : var( new (0) int[5] ) {}"); - parse("X::X( ) : var( new (0) int[5][10] ) {}"); - parse("X::X( ) : var( new (0) int[B] ) {}"); - parse("X::X( ) : var( new (0) int[B][C][D] ) {}"); - - parse("X::X( ) : var( new (0) A ) {}"); - parse("X::X( ) : var( new (0) A(5) ) {}"); - parse("X::X( ) : var( new (0) A(B) ) {}"); - parse("X::X( ) : var( new (0) A(B,C) ) {}"); - parse("X::X( ) : var( new (0) A[5] ) {}"); - parse("X::X( ) : var( new (0) A[5][10] ) {}"); - parse("X::X( ) : var( new (0) A[B] ) {}"); - parse("X::X( ) : var( new (0) A[B][C][D] ) {}"); - - parse("X::X( ) : var( new (0) (int) ) {}"); - parse("X::X( ) : var( new (0) (int)(5) ) {}"); - parse("X::X( ) : var( new (0) (int)(B) ) {}"); - parse("X::X( ) : var( new (0) (int)(B,C) ) {}"); - parse("X::X( ) : var( new (0) (int)[5] ) {}"); - parse("X::X( ) : var( new (0) (int)[5][10] ) {}"); - parse("X::X( ) : var( new (0) (int)[B] ) {}"); - parse("X::X( ) : var( new (0) (int)[B][C][D] ) {}"); - - parse("X::X( ) : var( new (0) (A) ) {}"); - parse("X::X( ) : var( new (0) (A)(5) ) {}"); - parse("X::X( ) : var( new (0) (A)(B) ) {}"); - parse("X::X( ) : var( new (0) (A)(B,C) ) {}"); - parse("X::X( ) : var( new (0) (A)[5] ) {}"); - parse("X::X( ) : var( new (0) (A)[5][10] ) {}"); - parse("X::X( ) : var( new (0) (A)[B] ) {}"); - parse("X::X( ) : var( new (0) (A)[B][C][D] ) {}"); - - parse("X::X( ) : var( new (P) int ) {}"); - parse("X::X( ) : var( new (P) int(5) ) {}"); - parse("X::X( ) : var( new (P) int(B) ) {}"); - parse("X::X( ) : var( new (P) int(B,C) ) {}"); - parse("X::X( ) : var( new (P) int[5] ) {}"); - parse("X::X( ) : var( new (P) int[5][10] ) {}"); - parse("X::X( ) : var( new (P) int[B] ) {}"); - parse("X::X( ) : var( new (P) int[B][C][D] ) {}"); - - parse("X::X( ) : var( new (P) A ) {}"); - parse("X::X( ) : var( new (P) A(5) ) {}"); - parse("X::X( ) : var( new (P) A(B) ) {}"); - parse("X::X( ) : var( new (P) A(B,C) ) {}"); - parse("X::X( ) : var( new (P) A[5] ) {}"); - parse("X::X( ) : var( new (P) A[5][10] ) {}"); - parse("X::X( ) : var( new (P) A[B] ) {}"); - parse("X::X( ) : var( new (P) A[B][C][D] ) {}"); - - parse("X::X( ) : var( new (P) (int) ) {}"); - parse("X::X( ) : var( new (P) (int)(5) ) {}"); - parse("X::X( ) : var( new (P) (int)(B) ) {}"); - parse("X::X( ) : var( new (P) (int)(B,C) ) {}"); - parse("X::X( ) : var( new (P) (int)[5] ) {}"); - parse("X::X( ) : var( new (P) (int)[5][10] ) {}"); - parse("X::X( ) : var( new (P) (int)[B] ) {}"); - parse("X::X( ) : var( new (P) (int)[B][C][D] ) {}"); - - parse("X::X( ) : var( new (P) (A) ) {}"); - parse("X::X( ) : var( new (P) (A)(5) ) {}"); - parse("X::X( ) : var( new (P) (A)(B) ) {}"); - parse("X::X( ) : var( new (P) (A)(B,C) ) {}"); - parse("X::X( ) : var( new (P) (A)[5] ) {}"); - parse("X::X( ) : var( new (P) (A)[5][10] ) {}"); - parse("X::X( ) : var( new (P) (A)[B] ) {}"); - parse("X::X( ) : var( new (P) (A)[B][C][D] ) {}"); - } - - public void testBug36769A() throws Exception { - Writer code = new StringWriter(); - code.write("template cls::operator op &() const {}\n"); - code.write("template cls::cls() {}\n"); - code.write("template cls::~cls() {}\n"); - - parse( code.toString()); - } - - public void testBug36769B() throws Exception { - parse("class X { operator int(); } \n"); - parse("class X { operator int*(); } \n"); - parse("class X { operator int&(); } \n"); - parse("class X { operator A(); } \n"); - parse("class X { operator A*(); } \n"); - parse("class X { operator A&(); } \n"); - - parse("X::operator int() { } \n"); - parse("X::operator int*() { } \n"); - parse("X::operator int&() { } \n"); - parse("X::operator A() { } \n"); - parse("X::operator A*() { } \n"); - parse("X::operator A&() { } \n"); - - parse("template class X { operator int(); } \n"); - parse("template class X { operator int*(); } \n"); - parse("template class X { operator int&(); } \n"); - parse("template class X { operator A(); } \n"); - parse("template class X { operator A*(); } \n"); - parse("template class X { operator A&(); } \n"); - - parse("template X::operator int() { } \n"); - parse("template X::operator int*() { } \n"); - parse("template X::operator int&() { } \n"); - parse("template X::operator A() { } \n"); - parse("template X::operator A*() { } \n"); - parse("template X::operator A&() { } \n"); - } - - public void testBugSingleton192() throws Exception { - parse("int Test::* pMember_;" ); - } - - public void testPointersToMembers() throws Exception { - // Parse and get the translaton unit - TranslationUnit translationUnit = parse("int A::* x = 0;"); - - List tudeclarations = translationUnit.getDeclarations(); - assertEquals(1, tudeclarations.size()); - SimpleDeclaration decl1 = (SimpleDeclaration) tudeclarations.get(0); - assertEquals(decl1.getDeclSpecifier().getType(), DeclSpecifier.t_int); - - assertEquals(1, decl1.getDeclarators().size()); - - Declarator declarator1 = (Declarator) decl1.getDeclarators().get(0); - assertEquals(declarator1.getName().toString(), "x"); - Expression initValue1 = declarator1.getExpression(); - assertEquals(initValue1.elements().size(), 1); - List ptrOps1 = declarator1.getPointerOperators(); - assertNotNull(ptrOps1); - assertEquals(1, ptrOps1.size()); - PointerOperator po1 = (PointerOperator) ptrOps1.get(0); - assertNotNull(po1); - assertFalse(po1.isConst()); - assertFalse(po1.isVolatile()); - assertEquals(po1.getType(), PointerOperator.t_pointer_to_member); - assertEquals(po1.getNameSpecifier().toString(), "A::"); - } - - public void testPointersToMemberFunctions() throws Exception - { - TranslationUnit tu = parse("void (A::*name)(void);"); - assertEquals( tu.getDeclarations().size(), 1 ); - SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0); - assertEquals( declaration.getDeclSpecifier().getType(), DeclSpecifier.t_void ); - assertEquals( declaration.getDeclarators().size(), 1); - assertNull( ((Declarator)declaration.getDeclarators().get(0)).getName() ); - assertNotNull( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator() ); - assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator().getName().toString(), "name" ); - ParameterDeclarationClause clause = ((Declarator)declaration.getDeclarators().get(0)).getParms(); - assertEquals( clause.getDeclarations().size(), 1 ); - assertEquals( ((ParameterDeclaration)clause.getDeclarations().get(0)).getDeclarators().size(), 1 ); - assertNull( ((Declarator)((ParameterDeclaration)clause.getDeclarations().get(0)).getDeclarators().get(0)).getName() ); - assertEquals( ((ParameterDeclaration)clause.getDeclarations().get(0)).getDeclSpecifier().getType(), DeclSpecifier.t_void ); - - List ptrOps1 = ((Declarator)declaration.getDeclarators().get(0)).getDeclarator().getPointerOperators(); - assertNotNull(ptrOps1); - assertEquals(1, ptrOps1.size()); - PointerOperator po1 = (PointerOperator) ptrOps1.get(0); - assertNotNull(po1); - assertFalse(po1.isConst()); - assertFalse(po1.isVolatile()); - assertEquals(po1.getType(), PointerOperator.t_pointer_to_member); - assertEquals(po1.getNameSpecifier().toString(), "A::"); - } - - public void testBug36290() throws Exception { - parse("typedef void ( A:: * pFunction ) ( void ); "); - parse("typedef void (boo) ( void ); "); - parse("typedef void boo (void); "); - } - - public void testBug36931() throws Exception { - parse("A::nested::nested(){}; "); - parse("int A::nested::foo() {} "); - parse("int A::nested::operator+() {} "); - parse("A::nested::operator int() {} "); - parse("static const int A::nested::i = 1; "); - - parse("template A::nested::nested(){}; "); - parse("template int A::nested::foo() {} "); - parse("template int A::nested::operator+() {} "); - parse("template A::nested::operator int() {} "); - } - - public void testOldKRFunctionDeclarations() throws Exception - { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("bool myFunction( parm1, parm2, parm3 )\n"); - code.write("const char* parm1;\n"); - code.write("int (*parm2)(float);\n"); - code.write("{}"); - TranslationUnit translationUnit = parse(code.toString()); - - // Get the declaration - List declarations = translationUnit.getDeclarations(); - assertEquals(1, declarations.size()); - SimpleDeclaration simpleDeclaration = (SimpleDeclaration)declarations.get(0); - assertEquals( simpleDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_bool ); - List declarators = simpleDeclaration.getDeclarators(); - assertEquals( 1, declarators.size() ); - Declarator functionDeclarator = (Declarator)declarators.get( 0 ); - assertEquals( functionDeclarator.getName().toString(), "myFunction" ); - - ParameterDeclarationClause pdc = functionDeclarator.getParms(); - assertNotNull( pdc ); - List parameterDecls = pdc.getDeclarations(); - assertEquals( 3, parameterDecls.size() ); - ParameterDeclaration parm1 = (ParameterDeclaration)parameterDecls.get( 0 ); - assertNotNull( parm1.getDeclSpecifier().getName() ); - assertEquals( "parm1", parm1.getDeclSpecifier().getName().toString() ); - List parm1Decls = parm1.getDeclarators(); - assertEquals( 1, parm1Decls.size() ); - - ParameterDeclaration parm2 = (ParameterDeclaration)parameterDecls.get( 1 ); - assertNotNull( parm2.getDeclSpecifier().getName() ); - assertEquals( "parm2", parm2.getDeclSpecifier().getName().toString() ); - List parm2Decls = parm2.getDeclarators(); - assertEquals( 1, parm2Decls.size() ); - - ParameterDeclaration parm3 = (ParameterDeclaration)parameterDecls.get( 2 ); - assertNotNull( parm3.getDeclSpecifier().getName() ); - assertEquals( "parm3", parm3.getDeclSpecifier().getName().toString() ); - List parm3Decls = parm3.getDeclarators(); - assertEquals( 1, parm3Decls.size() ); - - OldKRParameterDeclarationClause clause = pdc.getOldKRParms(); - assertNotNull( clause ); - assertEquals( clause.getDeclarations().size(), 2 ); - SimpleDeclaration decl1 = (SimpleDeclaration)clause.getDeclarations().get(0); - assertEquals( decl1.getDeclarators().size(), 1 ); - assertTrue(decl1.getDeclSpecifier().isConst()); - assertFalse(decl1.getDeclSpecifier().isVolatile()); - assertEquals( decl1.getDeclSpecifier().getType(), DeclSpecifier.t_char); - Declarator declarator1 = (Declarator)decl1.getDeclarators().get( 0 ); - assertEquals( declarator1.getName().toString(), "parm1" ); - Expression initValue1 = declarator1.getExpression(); - List ptrOps1 = declarator1.getPointerOperators(); - assertNotNull( ptrOps1 ); - assertEquals( 1, ptrOps1.size() ); - PointerOperator po1 = (PointerOperator)ptrOps1.get(0); - assertNotNull( po1 ); - assertFalse( po1.isConst() ); - assertFalse( po1.isVolatile() ); - assertEquals( po1.getType(), PointerOperator.t_pointer ); - - SimpleDeclaration declaration = (SimpleDeclaration)clause.getDeclarations().get(1); - assertEquals( declaration.getDeclSpecifier().getType(), DeclSpecifier.t_int ); - assertEquals( declaration.getDeclarators().size(), 1); - assertNull( ((Declarator)declaration.getDeclarators().get(0)).getName() ); - assertNotNull( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator() ); - assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator().getName().toString(), "parm2" ); - ParameterDeclarationClause clause2 = ((Declarator)declaration.getDeclarators().get(0)).getParms(); - assertEquals( clause2.getDeclarations().size(), 1 ); - assertEquals( ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().size(), 1 ); - assertNull( ((Declarator)((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().get(0)).getName() ); - assertEquals( ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclSpecifier().getType(), DeclSpecifier.t_float ); - } - - public void testAssignmentExpressions() throws Exception - { - parse( "int x = y = z = 5;"); - } - - public void testBug39348() throws Exception - { - parse("unsigned char a[sizeof (struct sss)];"); - } - - public void testBug39501() throws Exception - { - parse("struct A { A() throw (int); };"); - } - - public void testBug39349() throws Exception - { - parse( "enum foo { foo1 = 0, foo2 = 0xffffffffffffffffULL, foo3 = 0xf0fffffffffffffeLLU };" ); - } - - public void testBug39544() throws Exception { - parse("wchar_t wc = L'X';"); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java index 290d4f5c9ba..7dfbf0601e9 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java @@ -26,7 +26,7 @@ public class ExprEvalTest extends TestCase { public void runTest(String code, int expectedValue) throws Exception { IParser parser = ParserFactory.createParser(ParserFactory.createScanner( new StringReader( code ), null, new ScannerInfo(), null ), new NullSourceElementRequestor(), ParserMode.QUICK_PARSE); - IASTExpression expression = parser.expression(null); + IASTExpression expression = parser.expression(); assertEquals(expectedValue, expression.evaluateExpression()); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java index 868599d29f3..6e3bf312fc1 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java @@ -26,7 +26,6 @@ import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol; import org.eclipse.cdt.internal.core.parser.pst.ISymbol; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Declaration; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Mark; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TemplateInstance; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TypeInfo; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java index 0836d24db2b..c1e120ecdd5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java @@ -29,7 +29,7 @@ public class ParserTestSuite extends TestCase { suite.addTestSuite(BranchTrackerTest.class); suite.addTestSuite(ScannerTestCase.class); suite.addTestSuite(ExprEvalTest.class); - suite.addTestSuite(DOMTests.class); + suite.addTestSuite(QuickParseASTTests.class); suite.addTestSuite(ParserSymbolTableTest.class); suite.addTestSuite(CModelElementsTests.class); suite.addTestSuite(MacroTests.class); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java new file mode 100644 index 00000000000..8ab4e83e789 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java @@ -0,0 +1,1651 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.core.parser.tests; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Iterator; + +import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; +import org.eclipse.cdt.core.parser.ast.ASTClassKind; +import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; +import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; +import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; +import org.eclipse.cdt.core.parser.ast.IASTDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTEnumerator; +import org.eclipse.cdt.core.parser.ast.IASTExpression; +import org.eclipse.cdt.core.parser.ast.IASTField; +import org.eclipse.cdt.core.parser.ast.IASTFunction; +import org.eclipse.cdt.core.parser.ast.IASTInclusion; +import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; +import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; +import org.eclipse.cdt.core.parser.ast.IASTMacro; +import org.eclipse.cdt.core.parser.ast.IASTMethod; +import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; +import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTPointerToFunction; +import org.eclipse.cdt.core.parser.ast.IASTPointerToMethod; +import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; +import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; +import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; +import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; +import org.eclipse.cdt.core.parser.ast.IASTVariable; +import org.eclipse.cdt.internal.core.parser.ParserException; +import org.eclipse.cdt.internal.core.parser.ast.IASTArrayModifier; +/** + * @author jcamelon + * + */ +public class QuickParseASTTests extends BaseASTTest +{ + public QuickParseASTTests(String a) + { + super(a); + } + /** + * Test code: int x = 5; + * Purpose: to test the simple decaration in it's simplest form. + */ + public void testIntGlobal() throws Exception + { + // Parse and get the translation Unit + IASTCompilationUnit translationUnit = parse("int x = 5;"); + Iterator i = translationUnit.getDeclarations(); + assertTrue(i.hasNext()); + IASTVariable var = (IASTVariable)i.next(); + assertTrue( + var.getAbstractDeclaration().getTypeSpecifier() + instanceof IASTSimpleTypeSpecifier); + assertTrue( + ((IASTSimpleTypeSpecifier)var + .getAbstractDeclaration() + .getTypeSpecifier()) + .getType() + == IASTSimpleTypeSpecifier.Type.INT); + assertEquals(var.getName(), "x"); + assertNotNull(var.getInitializerClause()); + assertNotNull(var.getInitializerClause().getAssigmentExpression()); + assertFalse(i.hasNext()); + } + /** + * Test code: class A { } a; + * Purpose: tests the use of a classSpecifier in + */ + public void testEmptyClass() throws Exception + { + // Parse and get the translation unit + Writer code = new StringWriter(); + code.write("class A { } a;"); + IASTCompilationUnit translationUnit = parse(code.toString()); + Iterator i = translationUnit.getDeclarations(); + assertTrue(i.hasNext()); + IASTVariable var = (IASTVariable)i.next(); + assertEquals(var.getName(), "a"); + assertTrue( + var.getAbstractDeclaration().getTypeSpecifier() + instanceof IASTClassSpecifier); + IASTClassSpecifier classSpec = + (IASTClassSpecifier)var.getAbstractDeclaration().getTypeSpecifier(); + assertEquals(classSpec.getName(), "A"); + assertFalse(classSpec.getDeclarations().hasNext()); + assertFalse(i.hasNext()); + } + /** + * Test code: class A { public: int x; }; + * Purpose: tests a declaration in a class scope. + */ + public void testSimpleClassMember() throws Exception + { + // Parse and get the translaton unit + Writer code = new StringWriter(); + code.write("class A { public: int x; };"); + IASTCompilationUnit cu = parse(code.toString()); + Iterator i = cu.getDeclarations(); + assertTrue(i.hasNext()); + IASTAbstractTypeSpecifierDeclaration declaration = + (IASTAbstractTypeSpecifierDeclaration)i.next(); + assertFalse(i.hasNext()); + assertTrue( + declaration.getTypeSpecifier() instanceof IASTClassSpecifier); + assertTrue( + ((IASTClassSpecifier)declaration.getTypeSpecifier()).getClassKind() + == ASTClassKind.CLASS); + Iterator j = + ((IASTClassSpecifier)declaration.getTypeSpecifier()) + .getDeclarations(); + assertTrue(j.hasNext()); + IASTField field = (IASTField)j.next(); + assertFalse(j.hasNext()); + assertTrue(field.getName().equals("x")); + assertTrue( + field.getAbstractDeclaration().getTypeSpecifier() + instanceof IASTSimpleTypeSpecifier); + assertTrue( + ((IASTSimpleTypeSpecifier)field + .getAbstractDeclaration() + .getTypeSpecifier()) + .getType() + == IASTSimpleTypeSpecifier.Type.INT); + } + public void testNamespaceDefinition() throws Exception + { + for (int i = 0; i < 2; ++i) + { + IASTCompilationUnit translationUnit; + if (i == 0) + translationUnit = parse("namespace KingJohn { int x; }"); + else + translationUnit = parse("namespace { int x; }"); + Iterator iter = translationUnit.getDeclarations(); + assertTrue(iter.hasNext()); + IASTNamespaceDefinition namespaceDefinition = + (IASTNamespaceDefinition)iter.next(); + assertFalse(iter.hasNext()); + if (i == 0) + assertTrue(namespaceDefinition.getName().equals("KingJohn")); + else + assertEquals(namespaceDefinition.getName(), ""); + Iterator j = namespaceDefinition.getDeclarations(); + assertTrue(j.hasNext()); + IASTVariable var = (IASTVariable)j.next(); + assertFalse(j.hasNext()); + assertTrue( + var.getAbstractDeclaration().getTypeSpecifier() + instanceof IASTSimpleTypeSpecifier); + assertTrue( + ((IASTSimpleTypeSpecifier)var + .getAbstractDeclaration() + .getTypeSpecifier()) + .getType() + == IASTSimpleTypeSpecifier.Type.INT); + assertEquals(var.getName(), "x"); + } + } + + public void testLinkageSpecification() throws Exception + { + for( int i = 0; i < 2; ++i ) + { + IASTCompilationUnit compilationUnit; + if( i == 0 ) + compilationUnit = parse("extern \"C\" { int x(void); }"); + else + compilationUnit = parse("extern \"ADA\" int x(void);"); + + Iterator declarations = compilationUnit.getDeclarations(); + assertTrue( declarations.hasNext() ); + IASTLinkageSpecification linkage = (IASTLinkageSpecification)declarations.next(); + assertFalse( declarations.hasNext() ); + + if( i == 0 ) + assertEquals( "C", linkage.getLinkageString() ); + else + assertEquals( "ADA", linkage.getLinkageString() ); + + Iterator subDeclarations = linkage.getDeclarations(); + assertTrue( subDeclarations.hasNext() ); + IASTFunction function = (IASTFunction)subDeclarations.next(); + assertFalse( subDeclarations.hasNext()); + + assertEquals( ((IASTSimpleTypeSpecifier)function.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); + assertEquals( function.getName(), "x"); + + Iterator parameters = function.getParameters(); + assertTrue( parameters.hasNext() ); + IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); + assertFalse( parameters.hasNext() ); + assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.VOID ); + assertEquals( parm.getName(), "" ); + } + } + + public void testEnumSpecifier() throws Exception + { + Writer code = new StringWriter(); + code.write( "enum { yo, go = 3, away };\n"); + code.write( "enum hasAString { last = 666 };"); + IASTCompilationUnit translationUnit = parse( code.toString() ); + Iterator declarations = translationUnit.getDeclarations(); + + for( int i = 0; i < 2; ++i ) + { + assertTrue( declarations.hasNext() ); + IASTAbstractTypeSpecifierDeclaration abstractDeclaration = (IASTAbstractTypeSpecifierDeclaration)declarations.next(); + IASTEnumerationSpecifier enumerationSpec = (IASTEnumerationSpecifier)abstractDeclaration.getTypeSpecifier(); + if( i == 0 ) + assertEquals( enumerationSpec.getName(), "" ); + else + assertEquals( enumerationSpec.getName(), "hasAString" ); + Iterator j = enumerationSpec.getEnumerators(); + + if( i == 0 ) + { + IASTEnumerator enumerator1 = (IASTEnumerator)j.next(); + assertEquals( enumerator1.getName(), "yo"); + assertNull( enumerator1.getInitialValue() ); + IASTEnumerator enumerator2 = (IASTEnumerator)j.next(); + assertNotNull( enumerator2.getInitialValue() ); + assertEquals( enumerator2.getInitialValue().getLiteralString(), "3"); + assertEquals( enumerator2.getInitialValue().getExpressionKind(), IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ); + assertEquals( enumerator2.getName(), "go"); + IASTEnumerator enumerator3 = (IASTEnumerator)j.next(); + assertEquals( enumerator3.getName(), "away"); + assertNull( enumerator3.getInitialValue() ); + assertFalse( j.hasNext() ); + } + else + { + IASTEnumerator enumerator2 = (IASTEnumerator)j.next(); + assertNotNull( enumerator2.getInitialValue() ); + assertEquals( enumerator2.getInitialValue().getLiteralString(), "666"); + assertEquals( enumerator2.getInitialValue().getExpressionKind(), IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ); + assertEquals( enumerator2.getName(), "last"); + assertFalse( j.hasNext() ); + } + } + } + + public void testTypedef() throws Exception + { + Iterator i = parse( "typedef const struct A * const cpStructA;").getDeclarations(); + IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)i.next(); + assertFalse( i.hasNext() ); + assertTrue( typedef.getAbstractDeclarator().isConst() ); + assertTrue( typedef.getAbstractDeclarator().getTypeSpecifier() instanceof IASTElaboratedTypeSpecifier ); + IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier)typedef.getAbstractDeclarator().getTypeSpecifier(); + assertEquals( elab.getName(), "A"); + assertEquals( elab.getClassKind(), ASTClassKind.STRUCT ); + assertTrue( typedef.getAbstractDeclarator().getPointerOperators().hasNext() ); + Iterator pIter = (Iterator)typedef.getAbstractDeclarator().getPointerOperators(); + ASTPointerOperator po =(ASTPointerOperator)pIter.next(); + assertEquals( po, ASTPointerOperator.CONST_POINTER ); + assertFalse( pIter.hasNext() ); + assertEquals( typedef.getName(), "cpStructA"); + + } + + public void testUsingClauses() throws Exception + { + Writer code = new StringWriter(); + + code.write("using namespace A::B::C;\n"); + code.write("using namespace C;\n"); + code.write("using B::f;\n"); + code.write("using ::f;\n"); + code.write("using typename crap::de::crap;"); + Iterator declarations = parse(code.toString()).getDeclarations(); + + IASTUsingDirective usingDirective = (IASTUsingDirective)declarations.next(); + assertEquals( usingDirective.getNamespaceName(), "A::B::C" ); + + usingDirective = (IASTUsingDirective)declarations.next(); + assertEquals( usingDirective.getNamespaceName(), "C" ); + + IASTUsingDeclaration usingDeclaration = (IASTUsingDeclaration)declarations.next(); + assertEquals( usingDeclaration.usingTypeName(), "B::f" ); + + usingDeclaration = (IASTUsingDeclaration)declarations.next(); + assertEquals( usingDeclaration.usingTypeName(), "::f" ); + usingDeclaration = (IASTUsingDeclaration)declarations.next(); + assertEquals( usingDeclaration.usingTypeName(), "crap::de::crap" ); + assertTrue( usingDeclaration.isTypename() ); + + assertFalse( declarations.hasNext()); + } + + /** + * Test code: class A : public B, private C, virtual protected D { public: int x, y; float a,b,c; } + * Purpose: tests a declaration in a class scope. + */ + public void testSimpleClassMembers() throws Exception { + // Parse and get the translaton unit + Writer code = new StringWriter(); + code.write("class A : public B, private C, virtual protected D { public: int x, y; float a,b,c; };"); + Iterator declarations = parse( code.toString() ).getDeclarations(); + IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); + assertFalse( declarations.hasNext() ); + Iterator baseClauses = classSpec.getBaseClauses(); + IASTBaseSpecifier baseSpec = (IASTBaseSpecifier)baseClauses.next(); + assertEquals( baseSpec.getParentClassName(), "B" ); + assertEquals( baseSpec.getAccess(), ASTAccessVisibility.PUBLIC ); + baseSpec = (IASTBaseSpecifier)baseClauses.next(); + assertEquals( baseSpec.getParentClassName(), "C" ); + assertEquals( baseSpec.getAccess(), ASTAccessVisibility.PRIVATE); + baseSpec = (IASTBaseSpecifier)baseClauses.next(); + assertEquals( baseSpec.getAccess(), ASTAccessVisibility.PROTECTED ); + assertTrue( baseSpec.isVirtual() ); + assertEquals( baseSpec.getParentClassName(), "D" ); + assertFalse( baseClauses.hasNext() ); + + Iterator members = classSpec.getDeclarations(); + IASTField field = (IASTField)members.next(); + assertEquals( ((IASTSimpleTypeSpecifier)field.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); + assertEquals( field.getName(), "x" ); + + field = (IASTField)members.next(); + assertEquals( ((IASTSimpleTypeSpecifier)field.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); + assertEquals( field.getName(), "y" ); + + field = (IASTField)members.next(); + assertEquals( ((IASTSimpleTypeSpecifier)field.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.FLOAT ); + assertEquals( field.getName(), "a" ); + field = (IASTField)members.next(); + assertEquals( ((IASTSimpleTypeSpecifier)field.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.FLOAT ); + assertEquals( field.getName(), "b" ); + field = (IASTField)members.next(); + assertEquals( ((IASTSimpleTypeSpecifier)field.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.FLOAT ); + assertEquals( field.getName(), "c" ); + assertFalse( members.hasNext() ); + + } + + /** + * Test code: int myFunction( void ); + */ + public void testSimpleFunctionDeclaration() throws Exception + { + // Parse and get the translaton unit + Writer code = new StringWriter(); + code.write("void myFunction( void );"); + Iterator declarations = parse( code.toString()).getDeclarations(); + IASTFunction f1 = (IASTFunction)declarations.next(); + assertFalse( declarations.hasNext() ); + assertEquals( f1.getName(), "myFunction"); + assertEquals( ((IASTSimpleTypeSpecifier)f1.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.VOID ); + Iterator parameters = f1.getParameters(); + IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); + assertFalse( parameters.hasNext() ); + assertEquals( parm.getName(), "" ); + assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.VOID ); + + } + + /** + * Test code: bool myFunction( int parm1 = 3 * 4, double parm2 ); + * @throws Exception + */ + public void testFunctionDeclarationWithParameters() throws Exception + { + // Parse and get the translaton unit + Writer code = new StringWriter(); + code.write("bool myFunction( int parm1 = 3 * 4, double parm2 );"); + Iterator declarations = parse(code.toString()).getDeclarations(); + IASTFunction f1 = (IASTFunction)declarations.next(); + assertFalse( declarations.hasNext() ); + assertEquals( f1.getName(), "myFunction"); + assertEquals( ((IASTSimpleTypeSpecifier)f1.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.BOOL ); + Iterator parameters = f1.getParameters(); + IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); + assertEquals( parm.getName(), "parm1" ); + assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); + assertEquals( parm.getDefaultValue().getAssigmentExpression().getExpressionKind(), IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY ); + + parm = (IASTParameterDeclaration)parameters.next(); + assertEquals( parm.getName(), "parm2" ); + assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.DOUBLE ); + assertNull( parm.getDefaultValue() ); + assertFalse( parameters.hasNext()); + + } + + public void testAssignmentExpressions() throws Exception + { + parse( "int x = y = z = 5;"); + } + + public void testBug39348() throws Exception + { + parse("unsigned char a[sizeof (struct sss)];"); + } + + public void testBug39501() throws Exception + { + parse("struct A { A() throw (int); };"); + } + + public void testBug39349() throws Exception + { + parse( "enum foo { foo1 = 0, foo2 = 0xffffffffffffffffULL, foo3 = 0xf0fffffffffffffeLLU };" ); + } + + public void testBug39544() throws Exception { + parse("wchar_t wc = L'X';"); + } + + public void testBug36290() throws Exception { + parse("typedef void ( A:: * pFunction ) ( void ); "); + parse("typedef void (boo) ( void ); "); + parse("typedef void boo (void); "); + } + public void testBug36769B() throws Exception { + parse("class X { operator int(); } \n"); + parse("class X { operator int*(); } \n"); + parse("class X { operator int&(); } \n"); + parse("class X { operator A(); } \n"); + parse("class X { operator A*(); } \n"); + parse("class X { operator A&(); } \n"); + + parse("X::operator int() { } \n"); + parse("X::operator int*() { } \n"); + parse("X::operator int&() { } \n"); + parse("X::operator A() { } \n"); + parse("X::operator A*() { } \n"); + parse("X::operator A&() { } \n"); + + parse("template class X { operator int(); } \n"); + parse("template class X { operator int*(); } \n"); + parse("template class X { operator int&(); } \n"); + parse("template class X { operator A(); } \n"); + parse("template class X { operator A*(); } \n"); + parse("template class X { operator A&(); } \n"); + + parse("template X::operator int() { } \n"); + parse("template X::operator int*() { } \n"); + parse("template X::operator int&() { } \n"); + parse("template X::operator A() { } \n"); + parse("template X::operator A*() { } \n"); + parse("template X::operator A&() { } \n"); + } + public void testBug36932C() throws Exception { + parse("X::X( ) : var( new int ) {}"); + parse("X::X( ) : var( new int(5) ) {}"); + parse("X::X( ) : var( new int(B) ) {}"); + parse("X::X( ) : var( new int(B,C) ) {}"); + parse("X::X( ) : var( new int[5] ) {}"); + parse("X::X( ) : var( new int[5][10] ) {}"); + parse("X::X( ) : var( new int[B] ) {}"); + parse("X::X( ) : var( new int[B][C][D] ) {}"); + + parse("X::X( ) : var( new A ) {}"); + parse("X::X( ) : var( new A(5) ) {}"); + parse("X::X( ) : var( new A(B) ) {}"); + parse("X::X( ) : var( new A(B,C) ) {}"); + parse("X::X( ) : var( new A[5] ) {}"); + parse("X::X( ) : var( new A[5][10] ) {}"); + parse("X::X( ) : var( new A[B] ) {}"); + parse("X::X( ) : var( new A[B][C][D] ) {}"); + + parse("X::X( ) : var( new (int) ) {}"); + parse("X::X( ) : var( new (int)(5) ) {}"); + parse("X::X( ) : var( new (int)(B) ) {}"); + parse("X::X( ) : var( new (int)(B,C) ) {}"); + parse("X::X( ) : var( new (int)[5] ) {}"); + parse("X::X( ) : var( new (int)[5][10] ) {}"); + parse("X::X( ) : var( new (int)[B] ) {}"); + parse("X::X( ) : var( new (int)[B][C][D] ) {}"); + + parse("X::X( ) : var( new (A) ) {}"); + parse("X::X( ) : var( new (A)(5) ) {}"); + parse("X::X( ) : var( new (A)(B) ) {}"); + parse("X::X( ) : var( new (A)(B,C) ) {}"); + parse("X::X( ) : var( new (A)[5] ) {}"); + parse("X::X( ) : var( new (A)[5][10] ) {}"); + parse("X::X( ) : var( new (A)[B] ) {}"); + parse("X::X( ) : var( new (A)[B][C][D] ) {}"); + + parse("X::X( ) : var( new (0) int ) {}"); + parse("X::X( ) : var( new (0) int(5) ) {}"); + parse("X::X( ) : var( new (0) int(B) ) {}"); + parse("X::X( ) : var( new (0) int(B,C) ) {}"); + parse("X::X( ) : var( new (0) int[5] ) {}"); + parse("X::X( ) : var( new (0) int[5][10] ) {}"); + parse("X::X( ) : var( new (0) int[B] ) {}"); + parse("X::X( ) : var( new (0) int[B][C][D] ) {}"); + + parse("X::X( ) : var( new (0) A ) {}"); + parse("X::X( ) : var( new (0) A(5) ) {}"); + parse("X::X( ) : var( new (0) A(B) ) {}"); + parse("X::X( ) : var( new (0) A(B,C) ) {}"); + parse("X::X( ) : var( new (0) A[5] ) {}"); + parse("X::X( ) : var( new (0) A[5][10] ) {}"); + parse("X::X( ) : var( new (0) A[B] ) {}"); + parse("X::X( ) : var( new (0) A[B][C][D] ) {}"); + + parse("X::X( ) : var( new (0) (int) ) {}"); + parse("X::X( ) : var( new (0) (int)(5) ) {}"); + parse("X::X( ) : var( new (0) (int)(B) ) {}"); + parse("X::X( ) : var( new (0) (int)(B,C) ) {}"); + parse("X::X( ) : var( new (0) (int)[5] ) {}"); + parse("X::X( ) : var( new (0) (int)[5][10] ) {}"); + parse("X::X( ) : var( new (0) (int)[B] ) {}"); + parse("X::X( ) : var( new (0) (int)[B][C][D] ) {}"); + + parse("X::X( ) : var( new (0) (A) ) {}"); + parse("X::X( ) : var( new (0) (A)(5) ) {}"); + parse("X::X( ) : var( new (0) (A)(B) ) {}"); + parse("X::X( ) : var( new (0) (A)(B,C) ) {}"); + parse("X::X( ) : var( new (0) (A)[5] ) {}"); + parse("X::X( ) : var( new (0) (A)[5][10] ) {}"); + parse("X::X( ) : var( new (0) (A)[B] ) {}"); + parse("X::X( ) : var( new (0) (A)[B][C][D] ) {}"); + + parse("X::X( ) : var( new (P) int ) {}"); + parse("X::X( ) : var( new (P) int(5) ) {}"); + parse("X::X( ) : var( new (P) int(B) ) {}"); + parse("X::X( ) : var( new (P) int(B,C) ) {}"); + parse("X::X( ) : var( new (P) int[5] ) {}"); + parse("X::X( ) : var( new (P) int[5][10] ) {}"); + parse("X::X( ) : var( new (P) int[B] ) {}"); + parse("X::X( ) : var( new (P) int[B][C][D] ) {}"); + + parse("X::X( ) : var( new (P) A ) {}"); + parse("X::X( ) : var( new (P) A(5) ) {}"); + parse("X::X( ) : var( new (P) A(B) ) {}"); + parse("X::X( ) : var( new (P) A(B,C) ) {}"); + parse("X::X( ) : var( new (P) A[5] ) {}"); + parse("X::X( ) : var( new (P) A[5][10] ) {}"); + parse("X::X( ) : var( new (P) A[B] ) {}"); + parse("X::X( ) : var( new (P) A[B][C][D] ) {}"); + + parse("X::X( ) : var( new (P) (int) ) {}"); + parse("X::X( ) : var( new (P) (int)(5) ) {}"); + parse("X::X( ) : var( new (P) (int)(B) ) {}"); + parse("X::X( ) : var( new (P) (int)(B,C) ) {}"); + parse("X::X( ) : var( new (P) (int)[5] ) {}"); + parse("X::X( ) : var( new (P) (int)[5][10] ) {}"); + parse("X::X( ) : var( new (P) (int)[B] ) {}"); + parse("X::X( ) : var( new (P) (int)[B][C][D] ) {}"); + + parse("X::X( ) : var( new (P) (A) ) {}"); + parse("X::X( ) : var( new (P) (A)(5) ) {}"); + parse("X::X( ) : var( new (P) (A)(B) ) {}"); + parse("X::X( ) : var( new (P) (A)(B,C) ) {}"); + parse("X::X( ) : var( new (P) (A)[5] ) {}"); + parse("X::X( ) : var( new (P) (A)[5][10] ) {}"); + parse("X::X( ) : var( new (P) (A)[B] ) {}"); + parse("X::X( ) : var( new (P) (A)[B][C][D] ) {}"); + } + + + public void testBugSingleton192() throws Exception { + parse("int Test::* pMember_;" ); + } + public void testBug36931() throws Exception { + parse("A::nested::nested(){}; "); + parse("int A::nested::foo() {} "); + parse("int A::nested::operator+() {} "); + parse("A::nested::operator int() {} "); + parse("static const int A::nested::i = 1; "); + + parse("template A::nested::nested(){}; "); + parse("template int A::nested::foo() {} "); + parse("template int A::nested::operator+() {} "); + parse("template A::nested::operator int() {} "); + } + + public void testBug37019() throws Exception { + parse("static const A a( 1, 0 );"); + } + + public void testBug36766and36769A() throws Exception { + Writer code = new StringWriter(); + code.write("template \n"); + code.write("rope<_CharT, _Alloc>::rope(size_t __n, _CharT __c,\n"); + code.write("const allocator_type& __a): _Base(__a)\n"); + code.write("{}\n"); + parse(code.toString()); + } + + public void testBug36766and36769B() throws Exception { + Writer code = new StringWriter(); + code.write("template\n"); + code.write("bool _Rope_insert_char_consumer<_CharT>::operator()\n"); + code.write("(const _CharT* __leaf, size_t __n)\n"); + code.write("{}\n"); + parse(code.toString()); + } + + public void testBug36766and36769C() throws Exception { + Writer code = new StringWriter(); + code.write("template \n"); + code.write("_Rope_char_ref_proxy<_CharT, _Alloc>&\n"); + code.write( + "_Rope_char_ref_proxy<_CharT, _Alloc>::operator= (_CharT __c)\n"); + code.write("{}\n"); + parse(code.toString()); + } + + public void testBug36766and36769D() throws Exception { + Writer code = new StringWriter(); + code.write("template \n"); + code.write("rope<_CharT, _Alloc>::~rope()\n"); + code.write("{}\n"); + parse(code.toString()); + } + + public void testBug36932A() throws Exception { + parse("A::A( ) : var( new char [ (unsigned)bufSize ] ) {}"); + } + + public void testBug36932B() throws Exception { + parse(" p = new int; "); + parse(" p = new int(5); "); + parse(" p = new int(B); "); + parse(" p = new int(B,C); "); + parse(" p = new int[5]; "); + parse(" p = new int[5][10]; "); + parse(" p = new int[B]; "); + parse(" p = new int[B][C][D]; "); + + parse(" p = new A; "); + parse(" p = new A(5); "); + parse(" p = new A(B); "); + parse(" p = new A(B,C); "); + parse(" p = new A[5]; "); + parse(" p = new A[5][10]; "); + parse(" p = new A[B]; "); + parse(" p = new A[B][C][D]; "); + + parse(" p = new (int); "); + parse(" p = new (int)(5); "); + parse(" p = new (int)(B); "); + parse(" p = new (int)(B,C); "); + parse(" p = new (int)[5]; "); + parse(" p = new (int)[5][10]; "); + parse(" p = new (int)[B]; "); + parse(" p = new (int)[B][C][D]; "); + + parse(" p = new (A); "); + parse(" p = new (A)(5); "); + parse(" p = new (A)(B); "); + parse(" p = new (A)(B,C); "); + parse(" p = new (A)[5]; "); + parse(" p = new (A)[5][10]; "); + parse(" p = new (A)[B]; "); + parse(" p = new (A)[B][C][D]; "); + + parse(" p = new (0) int; "); + parse(" p = new (0) int(5); "); + parse(" p = new (0) int(B); "); + parse(" p = new (0) int(B,C); "); + parse(" p = new (0) int[5]; "); + parse(" p = new (0) int[5][10]; "); + parse(" p = new (0) int[B]; "); + parse(" p = new (0) int[B][C][D]; "); + + parse(" p = new (0) A; "); + parse(" p = new (0) A(5); "); + parse(" p = new (0) A(B); "); + parse(" p = new (0) A(B,C); "); + parse(" p = new (0) A[5]; "); + parse(" p = new (0) A[5][10]; "); + parse(" p = new (0) A[B]; "); + parse(" p = new (0) A[B][C][D]; "); + + parse(" p = new (0) (int); "); + parse(" p = new (0) (int)(5); "); + parse(" p = new (0) (int)(B); "); + parse(" p = new (0) (int)(B,C); "); + parse(" p = new (0) (int)[5]; "); + parse(" p = new (0) (int)[5][10]; "); + parse(" p = new (0) (int)[B]; "); + parse(" p = new (0) (int)[B][C][D]; "); + + parse(" p = new (0) (A); "); + parse(" p = new (0) (A)(5); "); + parse(" p = new (0) (A)(B); "); + parse(" p = new (0) (A)(B,C); "); + parse(" p = new (0) (A)[5]; "); + parse(" p = new (0) (A)[5][10]; "); + parse(" p = new (0) (A)[B]; "); + parse(" p = new (0) (A)[B][C][D]; "); + + parse(" p = new (P) int; "); + parse(" p = new (P) int(5); "); + parse(" p = new (P) int(B); "); + parse(" p = new (P) int(B,C); "); + parse(" p = new (P) int[5]; "); + parse(" p = new (P) int[5][10]; "); + parse(" p = new (P) int[B]; "); + parse(" p = new (P) int[B][C][D]; "); + + parse(" p = new (P) A; "); + parse(" p = new (P) A(5); "); + parse(" p = new (P) A(B); "); + parse(" p = new (P) A(B,C); "); + parse(" p = new (P) A[5]; "); + parse(" p = new (P) A[5][10]; "); + parse(" p = new (P) A[B]; "); + parse(" p = new (P) A[B][C][D]; "); + + parse(" p = new (P) (int); "); + parse(" p = new (P) (int)(5); "); + parse(" p = new (P) (int)(B); "); + parse(" p = new (P) (int)(B,C); "); + parse(" p = new (P) (int)[5]; "); + parse(" p = new (P) (int)[5][10]; "); + parse(" p = new (P) (int)[B]; "); + parse(" p = new (P) (int)[B][C][D]; "); + + parse(" p = new (P) (A); "); + parse(" p = new (P) (A)(5); "); + parse(" p = new (P) (A)(B); "); + parse(" p = new (P) (A)(B,C); "); + parse(" p = new (P) (A)[5]; "); + parse(" p = new (P) (A)[5][10]; "); + parse(" p = new (P) (A)[B]; "); + parse(" p = new (P) (A)[B][C][D]; "); + } + + public void testBug36769A() throws Exception { + Writer code = new StringWriter(); + code.write("template cls::operator op &() const {}\n"); + code.write("template cls::cls() {}\n"); + code.write("template cls::~cls() {}\n"); + + parse( code.toString()); + } + + public void testBug36714() throws Exception { + Writer code = new StringWriter(); + code.write("unsigned long a = 0UL;\n"); + code.write("unsigned long a2 = 0L; \n"); + + parse( code.toString() ); + } + + public void testBugFunctor758() throws Exception { + parse( "template Functor(Fun fun) : spImpl_(new FunctorHandler(fun)){}" ); + } + + public void testBug36932() throws Exception + { + parse( "A::A(): b( new int( 5 ) ), b( new B ), c( new int ) {}" ); + } + + public void testBug36704() throws Exception { + Writer code = new StringWriter(); + code.write( "template \n" ); + code.write( "struct Length< Typelist >\n" ); + code.write( "{\n" ); + code.write( "enum { value = 1 + Length::value };\n" ); + code.write( "};\n" ); + parse(code.toString()); + } + + public void testBug36699() throws Exception { + Writer code = new StringWriter(); + code.write( + "template < template class ThreadingModel = DEFAULT_THREADING,\n"); + code.write("std::size_t chunkSize = DEFAULT_CHUNK_SIZE,\n"); + code.write( + "std::size_t maxSmallObjectSize = MAX_SMALL_OBJECT_SIZE >\n"); + code.write("class SmallObject : public ThreadingModel<\n"); + code.write( + "SmallObject >\n"); + code.write("{};\n"); + parse(code.toString()); + } + + public void testBug36691() throws Exception { + Writer code = new StringWriter(); + code.write("template \n"); + code.write( + "typename H::template Rebind::Result& Field(H& obj)\n"); + code.write("{ return obj; }\n"); + parse(code.toString()); + } + + public void testBug36702() throws Exception + { + Writer code = new StringWriter(); + code.write( "void mad_decoder_init(struct mad_decoder *, void *,\n" ); + code.write( " enum mad_flow (*)(void *, struct mad_stream *),\n" ); + code.write( " enum mad_flow (*)(void *, struct mad_header const *),\n" ); + code.write( " enum mad_flow (*)(void *,\n" ); + code.write( " struct mad_stream const *,\n" ); + code.write( " struct mad_frame *),\n" ); + code.write( " enum mad_flow (*)(void *,\n" ); + code.write( " struct mad_header const *,\n" ); + code.write( " struct mad_pcm *),\n" ); + code.write( " enum mad_flow (*)(void *,\n" ); + code.write( " struct mad_stream *,\n" ); + code.write( " struct mad_frame *),\n" ); + code.write( " enum mad_flow (*)(void *, void *, unsigned int *)\n" ); + code.write( ");\n" ); + + parse( code.toString() ); + + } + + public void testBug36852() throws Exception + { + Writer code = new StringWriter(); + code.write( "int CBT::senseToAllRect( double id_standardQuot = DOSE, double id_minToleranz =15.0,\n" ); + code.write( "double id_maxToleranz = 15.0, unsigned int iui_minY = 0, \n" ); + code.write( "unsigned int iui_maxY = HEIGHT );\n" ); + parse( code.toString() ); + } + + public void testBug36689() throws Exception { + Writer code = new StringWriter(); + code.write("template\n"); + code.write("<\n"); + code.write("class AbstractFact,\n"); + code.write( + "template class Creator = OpNewFactoryUnit,\n"); + code.write("class TList = typename AbstractFact::ProductList\n"); + code.write(">\n"); + code.write("class ConcreteFactory\n"); + code.write(": public GenLinearHierarchy<\n"); + code.write( + "typename TL::Reverse::Result, Creator, AbstractFact>\n"); + code.write("{\n"); + code.write("public:\n"); + code.write( + "typedef typename AbstractFact::ProductList ProductList;\n"); + code.write("typedef TList ConcreteProductList;\n"); + code.write("};\n"); + parse(code.toString()); + } + + public void testBug36707() throws Exception { + parse("enum { exists = sizeof(typename H::Small) == sizeof((H::Test(H::MakeT()))) };"); + } + + public void testBug36717() throws Exception { + parse("enum { eA = A::b };"); + } + + public void testBug36693() throws Exception { + parse("FixedAllocator::Chunk* FixedAllocator::VicinityFind(void* p){}"); + } + + public void testWeirdExpression() throws Exception + { + parse( "int x = rhs.spImpl_.get();"); + } + + public void testBug36696() throws Exception { + Writer code = new StringWriter(); + code.write( + "template RefCounted(const RefCounted& rhs)\n"); + code.write( + ": pCount_(reinterpret_cast(rhs).pCount_) {}\n"); + parse(code.toString()); + } + + public void testArrayOfPointerToFunctions() throws Exception + { + parse( "unsigned char (*main_data)[MAD_BUFFER_MDLEN];"); + } + + public void testBug36073() throws Exception + { + StringWriter writer = new StringWriter(); + writer.write( "class A{\n" ); + writer.write( "int x;\n" ); + writer.write( "public:\n" ); + writer.write( "A(const A&);\n" ); + writer.write( "};\n" ); + writer.write( "A::A(const A&v) : x(v.x) { }\n" ); + parse( writer.toString() ); + } + + + public void testTemplateSpecialization() throws Exception + { + Iterator declarations = parse( "template<> class stream { /* ... */ };").getDeclarations(); + IASTClassSpecifier specifier = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)((IASTTemplateSpecialization)declarations.next()).getOwnedDeclaration()).getTypeSpecifier(); + assertFalse( declarations.hasNext()); + assertEquals( specifier.getName(), "stream"); + assertFalse( specifier.getDeclarations().hasNext() ); + } + + public void testTemplateInstantiation() throws Exception + { + Iterator declarations = parse( "template class Array;").getDeclarations(); + IASTElaboratedTypeSpecifier specifier = (IASTElaboratedTypeSpecifier)((IASTAbstractTypeSpecifierDeclaration)((IASTTemplateInstantiation)declarations.next()).getOwnedDeclaration()).getTypeSpecifier(); + assertFalse( declarations.hasNext() ); + assertEquals( specifier.getName(), "Array"); + assertEquals( specifier.getClassKind(), ASTClassKind.CLASS ); + } + + /** + * Test code: "class A { int floor( double input ), someInt; };" + */ + public void testMultipleDeclarators() throws Exception + { + // Parse and get the translaton unit + Iterator declarations = parse("class A { int floor( double input ), someInt; };").getDeclarations(); + Iterator members = ((IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier()).getDeclarations(); + assertFalse( declarations.hasNext() ); + IASTMethod decl1 = (IASTMethod)members.next(); + assertEquals( ((IASTSimpleTypeSpecifier)decl1.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); + Iterator parameters = decl1.getParameters(); + IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); + assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.DOUBLE ); + assertFalse( parameters.hasNext()); + assertEquals( parm.getName(), "input"); + + IASTField decl2 = (IASTField)members.next(); + assertEquals( decl2.getName(), "someInt"); + assertEquals( ((IASTSimpleTypeSpecifier)decl2.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); + assertFalse( members.hasNext()); + } + + public void testFunctionModifiers() throws Exception + { + Iterator declarations = parse( "class A {virtual void foo( void ) const throw ( yay, nay, we::dont::care ) = 0;};").getDeclarations(); + IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); + assertFalse( declarations.hasNext()); + Iterator members = classSpec.getDeclarations(); + IASTMethod method = (IASTMethod)members.next(); + assertFalse( members.hasNext() ); + assertTrue( method.isVirtual()); + assertEquals( method.getName(), "foo"); + assertEquals( ((IASTSimpleTypeSpecifier)method.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.VOID ); + Iterator parameters = method.getParameters(); + IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); + assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.VOID ); + assertFalse( parameters.hasNext()); + assertEquals( parm.getName(), ""); + assertTrue( method.isConst() ); + assertTrue( method.isPureVirtual() ); + assertNotNull( method.getExceptionSpec() ); + Iterator exceptions = method.getExceptionSpec().getTypeIds(); + assertEquals( (String)exceptions.next(), "yay"); + assertEquals( (String)exceptions.next(), "nay"); + assertEquals( (String)exceptions.next(), "we::dont::care"); + assertFalse( exceptions.hasNext() ); + } + + + public void testArrays() throws Exception + { + Iterator declarations = parse("int x [5][];").getDeclarations(); + IASTVariable x = (IASTVariable)declarations.next(); + assertFalse( declarations.hasNext() ); + assertEquals( ((IASTSimpleTypeSpecifier)x.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); + assertEquals( x.getName(), "x"); + Iterator arrayMods = x.getAbstractDeclaration().getArrayModifiers(); + IASTArrayModifier mod = (IASTArrayModifier)arrayMods.next(); + assertEquals( mod.getExpression().getExpressionKind(), IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ); + assertEquals( mod.getExpression().getLiteralString(), "5" ); + mod = (IASTArrayModifier)arrayMods.next(); + assertNull( mod.getExpression()); + assertFalse( arrayMods.hasNext() ); + } + + public void testElaboratedParms() throws Exception + { + Iterator declarations = parse( "int x( struct A myA ) { /* junk */ }" ).getDeclarations(); + IASTFunction f = (IASTFunction)declarations.next(); + assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.INT ); + Iterator parms = f.getParameters(); + IASTParameterDeclaration parm = (IASTParameterDeclaration)parms.next(); + assertFalse( parms.hasNext()); + assertEquals( parm.getName(), "myA"); + assertEquals( ((IASTElaboratedTypeSpecifier)parm.getTypeSpecifier()).getName(), "A" ); + assertEquals( ((IASTElaboratedTypeSpecifier)parm.getTypeSpecifier()).getClassKind(), ASTClassKind.STRUCT ); + assertFalse( declarations.hasNext()); + } + + public void testMemberDeclarations() throws Exception + { + Writer code = new StringWriter(); + code.write( "class A {\n" ); + code.write( "public:\n"); + code.write( " int is0;\n" ); + code.write( "private:\n"); + code.write( " int is1;\n" ); + code.write( "protected:\n"); + code.write( " int is2;\n" ); + code.write( "};"); + Iterator declarations = parse( code.toString()).getDeclarations(); + IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); + assertFalse(declarations.hasNext()); + Iterator members = classSpec.getDeclarations(); + for( int i = 0; i < 3; ++i ) + { + IASTField field = (IASTField)members.next(); + assertEquals( field.getName(), "is"+ new Integer( i ).toString()); + ASTAccessVisibility visibility = null; + switch( i ) + { + case 0: + visibility = ASTAccessVisibility.PUBLIC; + break; + + case 1: + visibility = ASTAccessVisibility.PRIVATE; + break; + + default: + visibility = ASTAccessVisibility.PROTECTED; + break; + } + assertEquals( field.getVisiblity(), visibility ); + } + assertFalse( members.hasNext()); + } + + public void testPointerOperators() throws Exception + { + Iterator declarations = parse("int * x = 0, & y, * const * volatile * z;").getDeclarations(); + for( int i = 0; i < 3; ++i ) + { + IASTVariable v = (IASTVariable)declarations.next(); + assertSimpleType( v, IASTSimpleTypeSpecifier.Type.INT ); + Iterator pointerOperators = v.getAbstractDeclaration().getPointerOperators(); + ASTPointerOperator pointerOp = (ASTPointerOperator)pointerOperators.next(); + + switch( i ) + { + case 0: + assertEquals( v.getName(), "x"); + assertEquals( pointerOp, ASTPointerOperator.POINTER ); + assertFalse( pointerOperators.hasNext()); + break; + case 1: + assertEquals( v.getName(), "y"); + assertEquals( pointerOp, ASTPointerOperator.REFERENCE); + assertFalse( pointerOperators.hasNext()); + break; + case 2: + assertEquals( v.getName(), "z"); + assertEquals( pointerOp, ASTPointerOperator.CONST_POINTER ); + assertEquals( pointerOperators.next(), ASTPointerOperator.VOLATILE_POINTER ); + assertEquals( pointerOperators.next(), ASTPointerOperator.POINTER ); + assertFalse( pointerOperators.hasNext()); + break; + } + } + assertFalse( declarations.hasNext() ); + } + + public void testBug26467() throws Exception + { + StringWriter code = new StringWriter(); + code.write( "struct foo { int fooInt; char fooChar; };\n" ); + code.write( "typedef struct foo fooStruct;\n" ); + code.write( "typedef struct { int anonInt; char anonChar; } anonStruct;\n" ); + Iterator declarations = parse( code.toString()).getDeclarations(); + IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); + assertEquals( classSpec.getClassKind(), ASTClassKind.STRUCT); + assertEquals( classSpec.getName(), "foo" ); + Iterator members = classSpec.getDeclarations(); + IASTField field = (IASTField)members.next(); + assertSimpleType(field, IASTSimpleTypeSpecifier.Type.INT ); + assertEquals( field.getName(), "fooInt"); + field = (IASTField)members.next(); + assertSimpleType(field, IASTSimpleTypeSpecifier.Type.CHAR ); + assertEquals( field.getName(), "fooChar"); + assertFalse( members.hasNext()); + IASTTypedefDeclaration firstTypeDef = (IASTTypedefDeclaration)declarations.next(); + assertEquals( ((IASTElaboratedTypeSpecifier)firstTypeDef.getAbstractDeclarator().getTypeSpecifier()).getClassKind(), ASTClassKind.STRUCT ); + assertEquals( ((IASTElaboratedTypeSpecifier)firstTypeDef.getAbstractDeclarator().getTypeSpecifier()).getName(), "foo"); + assertEquals( firstTypeDef.getName(), "fooStruct"); + IASTTypedefDeclaration secondTypeDef = (IASTTypedefDeclaration)declarations.next(); + classSpec = (IASTClassSpecifier)secondTypeDef.getAbstractDeclarator().getTypeSpecifier(); + assertEquals( classSpec.getClassKind(), ASTClassKind.STRUCT); + assertEquals( classSpec.getName(), "" ); + members = classSpec.getDeclarations(); + field = (IASTField)members.next(); + assertSimpleType(field, IASTSimpleTypeSpecifier.Type.INT ); + assertEquals( field.getName(), "anonInt"); + field = (IASTField)members.next(); + assertSimpleType(field, IASTSimpleTypeSpecifier.Type.CHAR ); + assertEquals( field.getName(), "anonChar"); + assertFalse( members.hasNext()); + assertEquals( secondTypeDef.getName(), "anonStruct"); + + } + + public void testASMDefinition() throws Exception + { + Iterator declarations = parse( "asm( \"mov ep1 ds2\");" ).getDeclarations(); + IASTASMDefinition asm = (IASTASMDefinition)declarations.next(); + assertFalse( declarations.hasNext()); + assertEquals( asm.getBody(), "mov ep1 ds2"); + } + + public void testConstructorChain() throws Exception + { + Iterator declarations = parse( "TrafficLight_Actor::TrafficLight_Actor( RTController * rtg_rts, RTActorRef * rtg_ref ) : RTActor( rtg_rts, rtg_ref ), myId( 0 ) {}" ).getDeclarations(); + IASTDeclaration d = (IASTDeclaration)declarations.next(); // cannot properly do this test now with new callback structure in quickparse mode + } + + public void testBug36237() throws Exception + { + parse( "A::A():B( (char *)0 ){}" ); + } + + public void testBug36532() throws Exception + { + try + { + parse( "template\n#define DEF VALUE\n"); + IASTCompilationUnit tu = parse( code.toString() ); + assertFalse( tu.getDeclarations().hasNext()); + Iterator inclusions = quickParseCallback.getInclusions(); + Iterator macros = quickParseCallback.getMacros(); + + IASTInclusion i = (IASTInclusion)inclusions.next(); + assertFalse( inclusions.hasNext()); + + assertEquals( i.getName(), "stdio.h"); + assertEquals( i.getElementStartingOffset(), 0 ); + assertEquals( i.getElementNameOffset(), 10 ); + assertEquals( i.getElementEndingOffset(), 18 ); + + + IASTMacro m = (IASTMacro)macros.next(); + assertEquals( m.getName(), "DEF" ); + assertEquals( m.getElementStartingOffset(), 19 ); + assertEquals( m.getElementNameOffset(), 27 ); + assertEquals( m.getElementEndingOffset(), 18 + 19); + } + + public void testTemplateDeclarationOfFunction() throws Exception + { + Iterator declarations = parse( "template A aTemplatedFunction( B bInstance );").getDeclarations(); + IASTTemplateDeclaration templateDeclaration = (IASTTemplateDeclaration)declarations.next(); + assertFalse( declarations.hasNext()); + Iterator templateParms = templateDeclaration.getTemplateParameters(); + IASTTemplateParameter parm = (IASTTemplateParameter)templateParms.next(); + assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.CLASS ); + assertEquals( parm.getIdentifier(), "A"); + parm = (IASTTemplateParameter)templateParms.next(); + assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.TYPENAME ); + assertEquals( parm.getIdentifier(), "B"); + assertEquals( parm.getDefaultValueIdExpression(), "C" ); + IASTFunction f = (IASTFunction)templateDeclaration.getOwnedDeclaration(); + assertEquals( f.getName(), "aTemplatedFunction" ); + assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); + assertEquals( ((IASTSimpleTypeSpecifier)f.getReturnType().getTypeSpecifier()).getTypename(), "A" ); + Iterator parameters = f.getParameters(); + IASTParameterDeclaration parmDeclaration = (IASTParameterDeclaration)parameters.next(); + assertFalse( parameters.hasNext() ); + assertEquals( parmDeclaration.getName(), "bInstance"); + assertEquals( ((IASTSimpleTypeSpecifier)parmDeclaration.getTypeSpecifier()).getType(),IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); + assertEquals( ((IASTSimpleTypeSpecifier)parmDeclaration.getTypeSpecifier()).getTypename(), "B" ); + } + + public void testTemplateDeclarationOfClass() throws Exception { + Iterator declarations = parse( "template class, template class AClass> class myarray { /* ... */ };").getDeclarations(); + IASTTemplateDeclaration templateDeclaration = (IASTTemplateDeclaration)declarations.next(); + assertFalse( declarations.hasNext()); + Iterator templateParms = templateDeclaration.getTemplateParameters(); + IASTTemplateParameter parm = (IASTTemplateParameter)templateParms.next(); + assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.CLASS ); + assertEquals( parm.getIdentifier(), "T"); + parm = (IASTTemplateParameter)templateParms.next(); + assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.TYPENAME ); + assertEquals( parm.getIdentifier(), "Tibor"); + assertEquals( parm.getDefaultValueIdExpression(), "junk"); + parm = (IASTTemplateParameter)templateParms.next(); + assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.CLASS ); + assertEquals( parm.getIdentifier(), ""); + parm = (IASTTemplateParameter)templateParms.next(); + assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.TYPENAME ); + assertEquals( parm.getIdentifier(), ""); + parm = (IASTTemplateParameter)templateParms.next(); + assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.PARAMETER ); + assertEquals( parm.getParameterDeclaration().getName(), "x"); + assertEquals( ((IASTSimpleTypeSpecifier)parm.getParameterDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); + parm = (IASTTemplateParameter)templateParms.next(); + assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.PARAMETER ); + assertEquals( parm.getParameterDeclaration().getName(), "y"); + assertEquals( ((IASTSimpleTypeSpecifier)parm.getParameterDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.FLOAT ); + parm = (IASTTemplateParameter)templateParms.next(); + assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.TEMPLATE_LIST); + assertEquals( parm.getIdentifier(), ""); + Iterator subParms = parm.getTemplateParameters(); + parm = (IASTTemplateParameter)subParms.next(); + assertFalse( subParms.hasNext() ); + assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.CLASS ); + assertEquals( parm.getIdentifier(), "Y" ); + parm = (IASTTemplateParameter)templateParms.next(); + assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.TEMPLATE_LIST); + assertEquals( parm.getIdentifier(), "AClass"); + subParms = parm.getTemplateParameters(); + parm = (IASTTemplateParameter)subParms.next(); + assertFalse( subParms.hasNext() ); + assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.CLASS ); + assertEquals( parm.getIdentifier(), "A" ); + assertFalse( templateParms.hasNext() ); + IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)templateDeclaration.getOwnedDeclaration()).getTypeSpecifier(); + assertEquals( classSpec.getName(), "myarray"); + assertFalse( classSpec.getDeclarations().hasNext() ); + } + + public void testBug35906() throws Exception + { + StringWriter code = new StringWriter(); + code.write( "void TTest::MTest() {}\n" ); + code.write( "struct TTest::STest *TTest::FTest (int i) {}\n" ); + Iterator declarations = parse( code.toString() ).getDeclarations(); + IASTFunction f = (IASTFunction)declarations.next(); + assertEquals( f.getName(), "TTest::MTest"); + assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.VOID ); + f = (IASTFunction)declarations.next(); + assertFalse( declarations.hasNext()); + assertEquals( f.getName(), "TTest::FTest"); + assertEquals( ((IASTElaboratedTypeSpecifier)f.getReturnType().getTypeSpecifier()).getClassKind(), ASTClassKind.STRUCT ); + assertEquals( ((IASTElaboratedTypeSpecifier)f.getReturnType().getTypeSpecifier()).getName(), "TTest::STest"); + Iterator pointerOperators = f.getReturnType().getPointerOperators(); + assertEquals( pointerOperators.next(), ASTPointerOperator.POINTER ); + assertFalse( pointerOperators.hasNext() ); + Iterator parameters = f.getParameters(); + IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); + assertFalse( parameters.hasNext() ); + assertEquals( parm.getName(), "i"); + assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.INT ); + } + + public void testBug36288() throws Exception + { + Iterator declarations = parse( "int foo() {}\nlong foo2(){}" ).getDeclarations(); + IASTFunction f = (IASTFunction)declarations.next(); + assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.INT ); + assertEquals( f.getName(), "foo"); + f = (IASTFunction)declarations.next(); + assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.INT ); + assertTrue( ((IASTSimpleTypeSpecifier)f.getReturnType().getTypeSpecifier()).isLong() ); + assertEquals( f.getName(), "foo2"); + assertFalse( declarations.hasNext() ); + } + + public void testBug36250() throws Exception + { + Iterator declarations = parse( "int f( int = 0 );").getDeclarations(); + IASTFunction f = (IASTFunction)declarations.next(); + assertFalse( declarations.hasNext() ); + assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.INT ); + assertEquals( f.getName(), "f"); + Iterator parameters = f.getParameters(); + IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); + assertFalse( parameters.hasNext() ); + assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.INT ); + assertEquals( parm.getName(), "" ); + assertEquals( parm.getDefaultValue().getKind(), IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION ); + assertEquals( parm.getDefaultValue().getAssigmentExpression().getExpressionKind(), IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ); + assertEquals( parm.getDefaultValue().getAssigmentExpression().getLiteralString(), "0" ); + } + + public void testBug36240() throws Exception + { + Iterator declarations = parse( "A & A::operator=( A ){}").getDeclarations(); + IASTFunction f = (IASTFunction)declarations.next(); + IASTSimpleTypeSpecifier typeSpec = (IASTSimpleTypeSpecifier)f.getReturnType().getTypeSpecifier(); + assertEquals( typeSpec.getType(), IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); + assertEquals( typeSpec.getTypename(), "A"); + Iterator pointerOps = f.getReturnType().getPointerOperators(); + assertEquals( (ASTPointerOperator)pointerOps.next(), ASTPointerOperator.REFERENCE ); + assertFalse( pointerOps.hasNext() ); + assertEquals( f.getName(), "A::operator="); + Iterator parms = f.getParameters(); + IASTParameterDeclaration parm = (IASTParameterDeclaration)parms.next(); + assertEquals( parm.getName(), "" ); + typeSpec = (IASTSimpleTypeSpecifier)parm.getTypeSpecifier(); + assertEquals( typeSpec.getType(), IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); + assertEquals( typeSpec.getTypename(), "A" ); + } + + public void testBug36254() throws Exception + { + Iterator declarations = parse( "unsigned i;\nvoid f( unsigned p1 = 0 );").getDeclarations(); + IASTVariable v = (IASTVariable)declarations.next(); + assertSimpleType( v, IASTSimpleTypeSpecifier.Type.INT); + assertTrue( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).isUnsigned() ); + IASTFunction f = (IASTFunction)declarations.next(); + assertSimpleReturnType(f, IASTSimpleTypeSpecifier.Type.VOID ); + assertEquals( f.getName(), "f"); + Iterator parms = f.getParameters(); + IASTParameterDeclaration parm = (IASTParameterDeclaration)parms.next(); + assertEquals( parm.getName(), "p1"); + assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.INT ); + assertTrue( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).isUnsigned() ); + assertEquals( parm.getDefaultValue().getKind(), IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION ); + assertEquals( parm.getDefaultValue().getAssigmentExpression().getExpressionKind(), IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ); + assertEquals( parm.getDefaultValue().getAssigmentExpression().getLiteralString(), "0" ); + assertFalse( declarations.hasNext()); + } + + public void testBug36432() throws Exception + { + Writer code = new StringWriter(); + code.write( "#define CMD_GET \"g\"\n" ); + code.write( "#define CMD_ACTION \"a\"\n" ); + code.write( "#define CMD_QUIT \"q\"\n" ); + code.write( "static const memevent_cmd_func memevent_cmd_funcs[sizeof memevent_cmds - 1] = {\n"); + code.write( "memevent_get,\n"); + code.write( "memevent_action,\n"); + code.write( "memevent_quit,\n"); + code.write( "};\n"); + parse( code.toString() ); + } + + public void testBug36594() throws Exception + { + parse( "const int n = sizeof(A) / sizeof(B);"); + } + + public void testBug36794() throws Exception + { + parse( "template<> class allocator {};"); + Iterator i = quickParseCallback.iterateOffsetableElements(); + while( i.hasNext() ) + assertNotNull( i.next() ); + } + + public void testBug36799() throws Exception + { + parse( "static const int __WORD_BIT = int(CHAR_BIT*sizeof(unsigned int));"); + } + + + public void testBug36764() throws Exception + { + parse( "struct{ int x : 4; int y : 8; };" ); + } + + public void testOrder() throws Exception + { + Writer code = new StringWriter(); + code.write( "#define __SGI_STL_INTERNAL_ALGOBASE_H\n" ); + code.write( "#include \n" ); + code.write( "template \n" ); + code.write( "inline void swap(_Tp& __a, _Tp& __b) {\n" ); + code.write( "__STL_REQUIRES(_Tp, _Assignable);\n" ); + code.write( "_Tp __tmp = __a;\n" ); + code.write( "__a = __b;\n" ); + code.write( "__b = __tmp;\n" ); + code.write( "}\n" ); + + parse( code.toString() ); + Iterator i = quickParseCallback.iterateOffsetableElements(); + assertTrue( i.hasNext() ); + assertTrue( i.next() instanceof IASTMacro ); + assertTrue( i.hasNext() ); + assertTrue( i.next() instanceof IASTInclusion ); + assertTrue( i.hasNext() ); + assertTrue( i.next() instanceof IASTDeclaration ); + assertFalse( i.hasNext() ); + } + + public void testBug36771() throws Exception { + Writer code = new StringWriter(); + code.write("#include /**/ \"foo.h\"\n"); + + parse( code.toString() ); + + Iterator includes = quickParseCallback.getInclusions(); + + IASTInclusion include = (IASTInclusion)includes.next(); + assertTrue( include.getName().equals("foo.h") ); + assertFalse( includes.hasNext() ); + } + + + public void testBug36811() throws Exception + { + Writer code = new StringWriter(); + code.write( "using namespace std;\n" ); + code.write( "class Test {};" ); + parse( code.toString() ); + Iterator i = quickParseCallback.iterateOffsetableElements(); + while( i.hasNext() ) + assertNotNull( i.next() ); + } + + public void testBug36708() throws Exception { + Iterator declarations = parse("enum { isPointer = PointerTraits::result };").getDeclarations(); + IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); + assertFalse( declarations.hasNext() ); + Iterator enumerators = enumSpec.getEnumerators(); + IASTEnumerator enumerator = (IASTEnumerator)enumerators.next(); + assertFalse( enumerators.hasNext() ); + assertEquals( enumerator.getName(), "isPointer"); + assertEquals( enumerator.getInitialValue().getExpressionKind(), IASTExpression.Kind.ID_EXPRESSION ); + assertEquals( enumerator.getInitialValue().getLiteralString(), "PointerTraits::result"); + } + + public void testBug36690() throws Exception { + parse("Functor(const Functor& rhs) : spImpl_(Impl::Clone(rhs.spImpl_.get())){}").getDeclarations(); + } + + public void testBug36703() throws Exception { + parse("const std::type_info& Get() const;"); + } + + public void testBug36692() throws Exception { + Writer code = new StringWriter(); + code.write("template \n"); + code.write("void SetLongevity(T* pDynObject, unsigned int longevity,\n"); + code.write("Destroyer d = Private::Deleter::Delete){}\n"); + parse(code.toString()); + } + + public void testBug36551() throws Exception + { + Writer code = new StringWriter(); + code.write( "class TextFrame {\n" ); + code.write( "BAD_MACRO()\n"); + code.write( "};"); + parse( code.toString(), true, false ); + } + + public void testBug36247() throws Exception + { + Writer code = new StringWriter(); + code.write( "class A {\n" ); + code.write( "INLINE_DEF int f ();\n" ); + code.write( "INLINE_DEF A g ();" ); + code.write( "INLINE_DEF A * h ();" ); + code.write( "INLINE_DEF A & unlock( void );"); + code.write( "};" ); + parse(code.toString()); + } + + public void testStruct() throws Exception + { + StringWriter writer = new StringWriter(); + writer.write( "struct mad_bitptr { unsigned char const *byte;\n" ); + writer.write( "unsigned short cache;\n unsigned short left;};" ); + parse( writer.toString() ); + } + + public void testBug36559() throws Exception + { + Writer code = new StringWriter(); + code.write( "namespace myNameSpace {\n" ); + code.write( "template class B {};\n" ); + code.write( "template<> class B {};\n" ); + code.write( "}\n" ); + parse( code.toString() ); + } + + public void testPointersToFunctions() throws Exception + { + Writer code = new StringWriter(); + code.write( "void (*name)( void );\n"); + code.write( "static void * (* const orig_malloc_hook)(const char *file, int line, size_t size);\n"); + + Iterator declarations = parse( code.toString() ).getDeclarations(); + IASTPointerToFunction p2f = (IASTPointerToFunction)declarations.next(); + assertSimpleReturnType( p2f, IASTSimpleTypeSpecifier.Type.VOID ); + assertEquals( p2f.getName(), "name"); + assertEquals( p2f.getPointerOperator(), ASTPointerOperator.POINTER); + Iterator parameters = p2f.getParameters(); + IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); + assertFalse( parameters.hasNext() ); + assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.VOID ); + assertEquals( parm.getName(), "" ); + + p2f = (IASTPointerToFunction)declarations.next(); + assertSimpleReturnType( p2f, IASTSimpleTypeSpecifier.Type.VOID ); + assertTrue( p2f.isStatic() ); + Iterator rtPo = p2f.getReturnType().getPointerOperators(); + assertEquals( rtPo.next(), ASTPointerOperator.POINTER ); + assertFalse( rtPo.hasNext() ); + assertEquals( p2f.getPointerOperator(), ASTPointerOperator.CONST_POINTER); + parameters = p2f.getParameters(); + parm = (IASTParameterDeclaration)parameters.next(); + assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.CHAR ); + assertEquals( parm.getName(), "file" ); + assertTrue( parm.isConst() ); + assertTrue( parm.getPointerOperators().hasNext() ); + parm = (IASTParameterDeclaration)parameters.next(); + assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.INT ); + assertEquals( parm.getName(), "line" ); + parm = (IASTParameterDeclaration)parameters.next(); + assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); + assertEquals( parm.getName(), "size" ); + assertFalse( parameters.hasNext() ); + } + + public void testBug36600() throws Exception + { + IASTPointerToFunction p2f = (IASTPointerToFunction)parse( "enum mad_flow (*input_func)(void *, struct mad_stream *);").getDeclarations().next(); + IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier)p2f.getReturnType().getTypeSpecifier(); + assertEquals( elab.getName(), "mad_flow"); + assertEquals( elab.getClassKind(), ASTClassKind.ENUM ); + assertEquals( p2f.getPointerOperator(), ASTPointerOperator.POINTER ); + assertEquals( p2f.getName(), "input_func"); + Iterator parms = p2f.getParameters(); + IASTParameterDeclaration parm = (IASTParameterDeclaration)parms.next(); + assertEquals( parm.getName(), "" ); + assertEquals( parm.getPointerOperators().next(), ASTPointerOperator.POINTER); + assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.VOID); + parm = (IASTParameterDeclaration)parms.next(); + assertEquals( parm.getName(), "" ); + assertEquals( parm.getPointerOperators().next(), ASTPointerOperator.POINTER); + elab = (IASTElaboratedTypeSpecifier)parm.getTypeSpecifier(); + assertEquals( elab.getName(), "mad_stream"); + assertEquals( elab.getClassKind(), ASTClassKind.STRUCT ); + + + } + + public void testBug36713() throws Exception { + Writer code = new StringWriter(); + code.write("A ( * const fPtr) (void *); \n"); + code.write("A (* const fPtr2) ( A * ); \n"); + Iterator declarations = parse(code.toString()).getDeclarations(); + } + + // K&R Test hasn't been ported from DOMTests + // still need to figure out how to represent these in the AST +// public void testOldKRFunctionDeclarations() throws Exception +// { +// // Parse and get the translaton unit +// Writer code = new StringWriter(); +// code.write("bool myFunction( parm1, parm2, parm3 )\n"); +// code.write("const char* parm1;\n"); +// code.write("int (*parm2)(float);\n"); +// code.write("{}"); +// TranslationUnit translationUnit = parse(code.toString()); +// +// // Get the declaration +// List declarations = translationUnit.getDeclarations(); +// assertEquals(1, declarations.size()); +// SimpleDeclaration simpleDeclaration = (SimpleDeclaration)declarations.get(0); +// assertEquals( simpleDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_bool ); +// List declarators = simpleDeclaration.getDeclarators(); +// assertEquals( 1, declarators.size() ); +// Declarator functionDeclarator = (Declarator)declarators.get( 0 ); +// assertEquals( functionDeclarator.getName().toString(), "myFunction" ); +// +// ParameterDeclarationClause pdc = functionDeclarator.getParms(); +// assertNotNull( pdc ); +// List parameterDecls = pdc.getDeclarations(); +// assertEquals( 3, parameterDecls.size() ); +// ParameterDeclaration parm1 = (ParameterDeclaration)parameterDecls.get( 0 ); +// assertNotNull( parm1.getDeclSpecifier().getName() ); +// assertEquals( "parm1", parm1.getDeclSpecifier().getName().toString() ); +// List parm1Decls = parm1.getDeclarators(); +// assertEquals( 1, parm1Decls.size() ); +// +// ParameterDeclaration parm2 = (ParameterDeclaration)parameterDecls.get( 1 ); +// assertNotNull( parm2.getDeclSpecifier().getName() ); +// assertEquals( "parm2", parm2.getDeclSpecifier().getName().toString() ); +// List parm2Decls = parm2.getDeclarators(); +// assertEquals( 1, parm2Decls.size() ); +// +// ParameterDeclaration parm3 = (ParameterDeclaration)parameterDecls.get( 2 ); +// assertNotNull( parm3.getDeclSpecifier().getName() ); +// assertEquals( "parm3", parm3.getDeclSpecifier().getName().toString() ); +// List parm3Decls = parm3.getDeclarators(); +// assertEquals( 1, parm3Decls.size() ); +// +// OldKRParameterDeclarationClause clause = pdc.getOldKRParms(); +// assertNotNull( clause ); +// assertEquals( clause.getDeclarations().size(), 2 ); +// SimpleDeclaration decl1 = (SimpleDeclaration)clause.getDeclarations().get(0); +// assertEquals( decl1.getDeclarators().size(), 1 ); +// assertTrue(decl1.getDeclSpecifier().isConst()); +// assertFalse(decl1.getDeclSpecifier().isVolatile()); +// assertEquals( decl1.getDeclSpecifier().getType(), DeclSpecifier.t_char); +// Declarator declarator1 = (Declarator)decl1.getDeclarators().get( 0 ); +// assertEquals( declarator1.getName().toString(), "parm1" ); +// List ptrOps1 = declarator1.getPointerOperators(); +// assertNotNull( ptrOps1 ); +// assertEquals( 1, ptrOps1.size() ); +// PointerOperator po1 = (PointerOperator)ptrOps1.get(0); +// assertNotNull( po1 ); +// assertFalse( po1.isConst() ); +// assertFalse( po1.isVolatile() ); +// assertEquals( po1.getType(), PointerOperator.t_pointer ); +// +// SimpleDeclaration declaration = (SimpleDeclaration)clause.getDeclarations().get(1); +// assertEquals( declaration.getDeclSpecifier().getType(), DeclSpecifier.t_int ); +// assertEquals( declaration.getDeclarators().size(), 1); +// assertNull( ((Declarator)declaration.getDeclarators().get(0)).getName() ); +// assertNotNull( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator() ); +// assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator().getName().toString(), "parm2" ); +// ParameterDeclarationClause clause2 = ((Declarator)declaration.getDeclarators().get(0)).getParms(); +// assertEquals( clause2.getDeclarations().size(), 1 ); +// assertEquals( ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().size(), 1 ); +// assertNull( ((Declarator)((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().get(0)).getName() ); +// assertEquals( ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclSpecifier().getType(), DeclSpecifier.t_float ); +// } + + public void testPointersToMemberFunctions() throws Exception + { + IASTPointerToMethod p2m = (IASTPointerToMethod)parse("void (A::*name)(void);").getDeclarations().next(); + assertSimpleReturnType( p2m, IASTSimpleTypeSpecifier.Type.VOID ); + assertEquals( p2m.getName(), "A::name"); + assertEquals( p2m.getPointerOperator(), ASTPointerOperator.POINTER); + Iterator parameters = p2m.getParameters(); + IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); + assertFalse( parameters.hasNext() ); + assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.VOID ); + assertEquals( parm.getName(), "" ); + } + + + +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java index d09c734bd06..c483322cb15 100644 --- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java +++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java @@ -20,7 +20,6 @@ import org.eclipse.cdt.core.search.ICSearchConstants; import org.eclipse.cdt.core.search.ICSearchPattern; import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.internal.core.search.CharOperation; -import org.eclipse.cdt.internal.core.search.matching.CSearchPattern; import org.eclipse.cdt.internal.core.search.matching.ClassDeclarationPattern; import org.eclipse.cdt.internal.core.search.matching.MatchLocator; import org.eclipse.cdt.internal.ui.search.CSearchResultCollector; diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassSpecifierSearchTests.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassSpecifierSearchTests.java index 61fe6f96ace..371714f92f0 100644 --- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassSpecifierSearchTests.java +++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassSpecifierSearchTests.java @@ -5,18 +5,15 @@ package org.eclipse.cdt.core.search.tests; import java.io.FileInputStream; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CProjectNature; -import org.eclipse.cdt.core.search.ICSearchConstants; import org.eclipse.cdt.core.search.ICSearchPattern; import org.eclipse.cdt.core.search.ICSearchResultCollector; -import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.internal.core.index.impl.IFileDocument; -import org.eclipse.cdt.internal.core.model.CModelManager; -import org.eclipse.cdt.internal.core.search.PathCollector; -import org.eclipse.cdt.internal.core.search.PatternSearchJob; -import org.eclipse.cdt.internal.core.search.indexing.IndexManager; -import org.eclipse.cdt.internal.ui.search.CSearchResultCollector; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; @@ -31,10 +28,6 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - /** * @author bgheorgh */ diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java index de2fd4004b6..be19815a1b4 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.core.model.tests.AllCoreTests; import org.eclipse.cdt.core.model.tests.BinaryTests; import org.eclipse.cdt.core.model.tests.ElementDeltaTests; import org.eclipse.cdt.core.model.tests.WorkingCopyTests; -import org.eclipse.cdt.core.parser.failedTests.DOMFailedTest; +import org.eclipse.cdt.core.parser.failedTests.ASTFailedTests; import org.eclipse.cdt.core.parser.failedTests.LokiFailures; import org.eclipse.cdt.core.parser.failedTests.STLFailedTests; import org.eclipse.cdt.core.parser.tests.ParserTestSuite; @@ -87,7 +87,7 @@ public class AutomatedIntegrationSuite extends TestSuite suite.addTest(suite.new GenerateReport("startFailedTests")); // Add all failed tests - suite.addTestSuite(DOMFailedTest.class); + suite.addTestSuite(ASTFailedTests.class); suite.addTestSuite(LokiFailures.class); suite.addTestSuite(STLFailedTests.class); suite.addTestSuite(CModelElementsFailedTests.class); diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ArrayQualifier.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ArrayQualifier.java index 16029e0db6b..9512a5106bd 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ArrayQualifier.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ArrayQualifier.java @@ -16,23 +16,7 @@ package org.eclipse.cdt.internal.core.dom; * @author jcamelon * */ -public class ArrayQualifier implements IExpressionOwner { - - private Expression constantExpression; - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.IExpressionOwner#getExpression() - */ - public Expression getExpression() { - return constantExpression; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.IExpressionOwner#setExpression(org.eclipse.cdt.internal.core.dom.Expression) - */ - public void setExpression(Expression exp) { - constantExpression = exp; - } +public class ArrayQualifier { public ArrayQualifier( Declarator owner ) { diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/BaseSpecifier.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/BaseSpecifier.java index 55ecbad5c4c..4b471011dc4 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/BaseSpecifier.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/BaseSpecifier.java @@ -1,6 +1,5 @@ package org.eclipse.cdt.internal.core.dom; -import org.eclipse.cdt.internal.core.parser.Name; /** @@ -40,7 +39,7 @@ public class BaseSpecifier { public void setAccess(int access) { this.access.setAccess(access); } public int getAccess() { return access.getAccess(); } - private Name name; - public void setName(Name name) { this.name = name; } - public Name getName() { return name; } + private String name; + public void setName(String name) { this.name = name; } + public String getName() { return name; } } diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/BitField.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/BitField.java index d53cabe2c7c..4037ec48da2 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/BitField.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/BitField.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.internal.core.dom; * @author jcamelon * */ -public class BitField implements IExpressionOwner { +public class BitField { public BitField( Declarator owner ) @@ -22,21 +22,7 @@ public class BitField implements IExpressionOwner { ownerDeclarator= owner; } private final Declarator ownerDeclarator; - private Expression expression = null; - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.IExpressionOwner#getExpression() - */ - public Expression getExpression() { - return expression; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.IExpressionOwner#setExpression(org.eclipse.cdt.internal.core.dom.Expression) - */ - public void setExpression(Expression exp) { - expression = exp; - } - + /** * @return */ diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ClassSpecifier.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ClassSpecifier.java index 943ed6adc28..d276114a9d2 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ClassSpecifier.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ClassSpecifier.java @@ -4,27 +4,30 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.internal.core.parser.Name; - public class ClassSpecifier extends TypeSpecifier implements IScope, IOffsetable, IAccessable { - private AccessSpecifier access = new AccessSpecifier( AccessSpecifier.v_private ); + private String classKeyImage = null; + private AccessSpecifier access = new AccessSpecifier( AccessSpecifier.v_private ); private ClassKey key = new ClassKey(); - private int startingOffset = 0, totalLength = 0; + private int startingOffset = 0, totalLength = 0, nameOffset = 0; private int topLine = 0, bottomLine = 0; - private IToken classKeyToken = null; public int getClassKey() { return key.getClassKey(); } public ClassSpecifier(int classKey, TypeSpecifier.IOwner declaration) { super(declaration); this.key.setClassKey(classKey); + if( classKey == ClassKey.t_class ) + classKeyImage = "class"; + else if( classKey == ClassKey.t_struct ) + classKeyImage = "struct"; + else if( classKey == ClassKey.t_union ) + classKeyImage = "union"; } - private Name name; - public void setName(Name n) { name = n; } - public Name getName() { return name; } + private String name; + public void setName(String n) { name = n; } + public String getName() { return name; } private List baseSpecifiers = new LinkedList(); public void addBaseSpecifier(BaseSpecifier baseSpecifier) { @@ -63,6 +66,10 @@ public class ClassSpecifier extends TypeSpecifier implements IScope, IOffsetable return startingOffset; } + public int getClassKeyEndOffset() + { + return startingOffset + classKeyImage.length(); + } /** * @return */ @@ -84,22 +91,6 @@ public class ClassSpecifier extends TypeSpecifier implements IScope, IOffsetable totalLength = i; } - /** - * Returns the classKeyToken. - * @return Token - */ - public IToken getClassKeyToken() { - return classKeyToken; - } - - /** - * Sets the classKeyToken. - * @param classKeyToken The classKeyToken to set - */ - public void setClassKeyToken(IToken classKeyToken) { - this.classKeyToken = classKeyToken; - } - /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.IOffsetable#setTopLine(int) */ @@ -128,4 +119,28 @@ public class ClassSpecifier extends TypeSpecifier implements IScope, IOffsetable return bottomLine; } + /** + * @return + */ + public String getClassKeyImage() + { + return classKeyImage; + } + + /** + * @return + */ + public int getNameOffset() + { + return nameOffset; + } + + /** + * @param i + */ + public void setNameOffset(int i) + { + nameOffset = i; + } + } diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ConstructorChainElement.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ConstructorChainElement.java index aa4d9530bd3..8dacc88d58e 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ConstructorChainElement.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ConstructorChainElement.java @@ -12,16 +12,15 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.dom; -import org.eclipse.cdt.internal.core.parser.Name; /** * @author jcamelon * */ -public class ConstructorChainElement implements IExpressionOwner { +public class ConstructorChainElement { - private Name name; + private String name; private final ConstructorChain ownerChain; ConstructorChainElement( ConstructorChain chain ) @@ -32,7 +31,7 @@ public class ConstructorChainElement implements IExpressionOwner { /** * @return Name */ - public Name getName() { + public String getName() { return name; } @@ -40,7 +39,7 @@ public class ConstructorChainElement implements IExpressionOwner { * Sets the name. * @param name The name to set */ - public void setName(Name name) { + public void setName(String name) { this.name = name; } @@ -53,21 +52,4 @@ public class ConstructorChainElement implements IExpressionOwner { } - private Expression exp = null; - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.IExpressionOwner#getExpression() - */ - public Expression getExpression() - { - return exp; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.IExpressionOwner#setExpression(org.eclipse.cdt.internal.core.dom.Expression) - */ - public void setExpression(Expression exp) - { - this.exp = exp; - } - } diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java index 1dbde3b4e0c..b69e006ca35 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java @@ -1,17 +1,21 @@ package org.eclipse.cdt.internal.core.dom; - - -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.IParserCallback; +import java.util.Iterator; +import java.util.List; import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.IToken; +import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; +import org.eclipse.cdt.core.parser.ast.ASTClassKind; +import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; +import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; import org.eclipse.cdt.core.parser.ast.IASTClassReference; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTEnumerator; +import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTField; import org.eclipse.cdt.core.parser.ast.IASTFunction; import org.eclipse.cdt.core.parser.ast.IASTInclusion; @@ -19,1256 +23,901 @@ import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; import org.eclipse.cdt.core.parser.ast.IASTMacro; import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; +import org.eclipse.cdt.core.parser.ast.IASTPointerToFunction; +import org.eclipse.cdt.core.parser.ast.IASTPointerToMethod; +import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypedef; +import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.Name; - +import org.eclipse.cdt.internal.core.parser.ast.IASTArrayModifier; /** * This is the parser callback that creates objects in the DOM. */ -public class DOMBuilder implements IParserCallback, ISourceElementRequestor +public class DOMBuilder implements ISourceElementRequestor { - public DOMBuilder() - { - } - - public TranslationUnit getTranslationUnit() { - return translationUnit; - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#argumentsBegin() - */ - public Object argumentsBegin( Object declarator ) { - Declarator decl = ((Declarator)declarator); - ParameterDeclarationClause clause = new ParameterDeclarationClause( decl ); - return clause; - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#argumentsEnd() - */ - public void argumentsEnd(Object parameterDeclarationClause) { - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#oldKRParametersBegin() - */ - public Object oldKRParametersBegin( Object parameterDeclarationClause ) { - ParameterDeclarationClause clause = ((ParameterDeclarationClause)parameterDeclarationClause); - OldKRParameterDeclarationClause KRclause = new OldKRParameterDeclarationClause( clause ); - domScopes.push(KRclause); - return KRclause; + public DOMBuilder() + { } + protected TranslationUnit translationUnit = new TranslationUnit(); + public TranslationUnit getTranslationUnit() + { + return translationUnit; + } + public SimpleDeclaration getTypeSpecOwner( + IScope scope, + int startingOffset) + { + List declarations = scope.getDeclarations(); + for (int i = 0; i < declarations.size(); ++i) + { + if (declarations.get(i) instanceof SimpleDeclaration ) + { + SimpleDeclaration s = (SimpleDeclaration)declarations.get(i); + if (s.getStartingOffset() == startingOffset) + return s; + } + } + return null; + } + protected void createPDC(Declarator decl) + { + ParameterDeclarationClause clause = + new ParameterDeclarationClause(decl); + } + // /** + // * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#oldKRParametersBegin() + // */ + // public Object oldKRParametersBegin( Object parameterDeclarationClause ) { + // ParameterDeclarationClause clause = ((ParameterDeclarationClause)parameterDeclarationClause); + // OldKRParameterDeclarationClause KRclause = new OldKRParameterDeclarationClause( clause ); + // domScopes.push(KRclause); + // return KRclause; + // } + // + // /** + // * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#oldKRParametersEnd() + // */ + // public void oldKRParametersEnd(Object oldKRParameterDeclarationClause) { + // domScopes.pop(); + // } + // + // + // /** + // * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declaratorBegin() + // */ + // public Object declaratorBegin(Object container) { + // if( container instanceof DeclSpecifier.IContainer ) + // { + // DeclSpecifier.IContainer decl = (DeclSpecifier.IContainer )container; + // Declarator declarator = new Declarator(decl); + // return declarator; + // } + // else if( container instanceof IDeclaratorOwner ) + // { + // IDeclaratorOwner owner = (IDeclaratorOwner)container; + // Declarator declarator = new Declarator(owner); + // return declarator; + // } + // return null; + // } + // + // /** + // * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declaratorEnd() + // */ + // public void declaratorEnd(Object declarator) { + // Declarator d = (Declarator)declarator; + // if( d.getDeclaration() != null ) + // d.getDeclaration().addDeclarator(d); + // else if( d.getOwnerDeclarator() != null ) + // d.getOwnerDeclarator().setDeclarator(d); + // } + // + // /** + // * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declaratorId(org.eclipse.cdt.internal.core.newparser.Token) + // */ + // public void declaratorId(Object declarator) { + // ((Declarator)declarator).setName(currName); + // } + // + // /** + // * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declSpecifier(org.eclipse.cdt.internal.core.newparser.Token) + // */ + // public void simpleDeclSpecifier(Object Container, IToken specifier) { + // DeclSpecifier.IContainer decl = (DeclSpecifier.IContainer)Container; + // DeclSpecifier declSpec = decl.getDeclSpecifier(); + // declSpec.setType( specifier ); + // } + // + // /** + // * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#functionBodyBegin() + // */ + // public Object functionBodyBegin(Object declaration) { + // SimpleDeclaration simpleDec = (SimpleDeclaration)declaration; + // simpleDec.setFunctionDefinition(true); + // return null; + // } + // + // /** + // * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#simpleDeclarationBegin(org.eclipse.cdt.internal.core.newparser.Token) + // */ + // public Object simpleDeclarationBegin(Object container, IToken firstToken) { + // SimpleDeclaration decl = new SimpleDeclaration( getCurrentDOMScope() ); + // if( getCurrentDOMScope() instanceof IAccessable ) + // decl.setAccessSpecifier(new AccessSpecifier( ((IAccessable)getCurrentDOMScope()).getVisibility() )); + // ((IOffsetable)decl).setStartingOffset( firstToken.getOffset() ); + // } + // + // /** + // * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#simpleDeclarationEnd(org.eclipse.cdt.internal.core.newparser.Token) + // */ + // public void simpleDeclarationEnd(Object declaration, IToken lastToken) { + // SimpleDeclaration decl = (SimpleDeclaration)declaration; + // IOffsetable offsetable = (IOffsetable)decl; + // offsetable.setTotalLength( lastToken.getOffset() + lastToken.getLength() - offsetable.getStartingOffset()); + // getCurrentDOMScope().addDeclaration(decl); + // } + // + // + // + protected void createBaseSpecifier(ClassSpecifier cs, IASTBaseSpecifier bs) + { + BaseSpecifier baseSpec = new BaseSpecifier(cs); + baseSpec.setVirtual(bs.isVirtual()); + int access = AccessSpecifier.v_public; + if (bs.getAccess() == ASTAccessVisibility.PUBLIC) + access = AccessSpecifier.v_public; + else if (bs.getAccess() == ASTAccessVisibility.PROTECTED) + access = AccessSpecifier.v_protected; + else if (bs.getAccess() == ASTAccessVisibility.PRIVATE) + access = AccessSpecifier.v_private; + baseSpec.setAccess(access); + baseSpec.setName(bs.getParentClassName()); + } + // + // public Object parameterDeclarationBegin( Object container ) + // { + // IScope clause = (IScope)container; + // ParameterDeclaration pd = new ParameterDeclaration(clause); + // return pd; + // } + // + // public void parameterDeclarationEnd( Object declaration ){ + // ParameterDeclaration d = (ParameterDeclaration)declaration; + // d.getOwnerScope().addDeclaration(d); + // } + // + - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#oldKRParametersEnd() + // + // /** + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierName(java.lang.Object) + // */ + // public void simpleDeclSpecifierName(Object declaration) { + // DeclSpecifier.IContainer decl = (DeclSpecifier.IContainer)declaration; + // DeclSpecifier declSpec = decl.getDeclSpecifier(); + // declSpec.setName( currName ); + // } + // + // + protected void addPointerOperator( + Declarator d, + ASTPointerOperator pointerOp, + String name) + { + PointerOperator ptrOp = new PointerOperator(d); + if (pointerOp == ASTPointerOperator.REFERENCE) + { + ptrOp.setType(PointerOperator.t_reference); + } + else if (pointerOp == ASTPointerOperator.POINTER) + { + ptrOp.setType(PointerOperator.t_pointer); + } + else if (pointerOp == ASTPointerOperator.CONST_POINTER) + { + ptrOp.setType(PointerOperator.t_pointer); + ptrOp.setConst(true); + } + else if (pointerOp == ASTPointerOperator.VOLATILE_POINTER) + { + ptrOp.setType(PointerOperator.t_pointer); + ptrOp.setVolatile(true); + } + if (d != null) + d.addPointerOperator(ptrOp); + } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorCVModifier(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) + // */ + // public void declaratorCVModifier(Object declarator, IToken modifier) { + // Declarator decl = (Declarator)declarator; + // switch( modifier.getType() ) + // { + // case IToken.t_const: + // decl.setConst(true); + // break; + // case IToken.t_volatile: + // decl.setVolatile( true ); + // break; + // default: + // break; + // } + // + // } + protected void addArrayDeclarator( + Declarator decl, + IASTArrayModifier arrayModifier) + { + ArrayQualifier qual = new ArrayQualifier(decl); + decl.addArrayQualifier(qual); + } + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#exceptionSpecificationTypename(java.lang.Object) + // */ + // public void declaratorThrowExceptionName(Object declarator ) + // { + // Declarator decl = (Declarator)declarator; + // decl.getExceptionSpecifier().addTypeName( currName ); + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorThrowsException(java.lang.Object) + // */ + // public void declaratorThrowsException(Object declarator) { + // Declarator decl = (Declarator)declarator; + // decl.getExceptionSpecifier().setThrowsException(true); + // } + // + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainBegin(java.lang.Object) + // */ + // public Object constructorChainBegin(Object declarator) { + // Declarator d = (Declarator)declarator; + // ConstructorChain chain = new ConstructorChain(d); + // return chain; + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainEnd(java.lang.Object) + // */ + // public void constructorChainEnd(Object ctor) { + // ConstructorChain chain = (ConstructorChain)ctor; + // chain.getOwnerDeclarator().setCtorChain(chain); + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementBegin(java.lang.Object) + // */ + // public Object constructorChainElementBegin(Object ctor) { + // return new ConstructorChainElement( (ConstructorChain)ctor ); + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementEnd(java.lang.Object) + // */ + // public void constructorChainElementEnd(Object element) { + // ConstructorChainElement ele = (ConstructorChainElement)element; + // ele.getOwnerChain().addChainElement( ele ); + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainId(java.lang.Object) + // */ + // public void constructorChainElementId(Object element) { + // ConstructorChainElement ele = (ConstructorChainElement)element; + // ele.setName(currName); + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitInstantiationBegin(java.lang.Object) + // */ + // public Object explicitInstantiationBegin(Object container) { + // ExplicitTemplateDeclaration etd = new ExplicitTemplateDeclaration( getCurrentDOMScope(), ExplicitTemplateDeclaration.k_instantiation ); + // domScopes.push( etd ); + // return etd; + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitInstantiationEnd(java.lang.Object) + // */ + // public void explicitInstantiationEnd(Object instantiation) { + // ExplicitTemplateDeclaration declaration = (ExplicitTemplateDeclaration)domScopes.pop(); + // declaration.getOwnerScope().addDeclaration(declaration); + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitSpecializationBegin(java.lang.Object) + // */ + // public Object explicitSpecializationBegin(Object container) { + // ExplicitTemplateDeclaration etd = new ExplicitTemplateDeclaration( getCurrentDOMScope(), ExplicitTemplateDeclaration.k_specialization); + // domScopes.push( etd ); + // return etd; + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitSpecializationEnd(java.lang.Object) + // */ + // public void explicitSpecializationEnd(Object instantiation) { + // ExplicitTemplateDeclaration etd = (ExplicitTemplateDeclaration)domScopes.pop(); + // etd.getOwnerScope().addDeclaration(etd); + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorPureVirtual(java.lang.Object) + // */ + // public void declaratorPureVirtual(Object declarator) { + // Declarator d = (Declarator)declarator; + // d.setPureVirtual(true); + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationBegin(java.lang.Object, boolean) + // */ + // public Object templateDeclarationBegin(Object container, IToken exported) { + // TemplateDeclaration d = new TemplateDeclaration( (IScope)getCurrentDOMScope(), exported ); + // if( getCurrentDOMScope() instanceof IAccessable ) + // d.setVisibility( ((IAccessable)container).getVisibility() ); + // d.setStartingOffset( exported.getOffset() ); + // domScopes.push( d ); + // return d; + // } + // + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationEnd(java.lang.Object) + // */ + // public void templateDeclarationEnd(Object templateDecl, IToken lastToken) { + // TemplateDeclaration decl = (TemplateDeclaration)domScopes.pop(); + // decl.setLastToken(lastToken); + // decl.getOwnerScope().addDeclaration(decl); + // decl.setTotalLength(lastToken.getOffset() + lastToken.getLength() - decl.getStartingOffset() ); + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterBegin(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) + // */ + // public Object templateTypeParameterBegin(Object templDecl, IToken kind) { + // TemplateParameterList list = (TemplateParameterList)templDecl; + // int k; + // switch( kind.getType() ) + // { + // case IToken.t_class: + // k = TemplateParameter.k_class; + // break; + // case IToken.t_typename: + // k= TemplateParameter.k_typename; + // break; + // case IToken.t_template: + // k= TemplateParameter.k_template; + // break; + // default: + // k = 0; + // } + // TemplateParameter p = new TemplateParameter( list, k ); + // return p; + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterName(java.lang.Object) + // */ + // public void templateTypeParameterName(Object typeParm) { + // ((TemplateParameter)typeParm).setName( currName ); + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeInitialTypeId(java.lang.Object) + // */ + // public void templateTypeParameterInitialTypeId(Object typeParm) { + // ((TemplateParameter)typeParm).setTypeId( currName ); + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterEnd(java.lang.Object) + // */ + // public void templateTypeParameterEnd(Object typeParm) { + // TemplateParameter parameter = (TemplateParameter)typeParm; + // parameter.getOwnerScope().addDeclaration( parameter ); + // } + // + // + // + // + // /* (non-Javadoc) + // * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateParameterListBegin(java.lang.Object) + // */ + // public Object templateParameterListBegin(Object declaration) { + // ITemplateParameterListOwner d = (ITemplateParameterListOwner)declaration; + // TemplateParameterList list = new TemplateParameterList(); + // d.setTemplateParms(list); + // return list; + // } + protected void addBitfield( + Declarator declarator, + IASTExpression bitfieldExpression) + { + declarator.setBitField(new BitField(declarator)); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem) */ - public void oldKRParametersEnd(Object oldKRParameterDeclarationClause) { + public void acceptProblem(IProblem problem) + { + // ignore + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMacro(org.eclipse.cdt.core.parser.ast.IASTMacro) + */ + public void acceptMacro(IASTMacro macro) + { + Macro m = + new Macro( + macro.getName(), + macro.getElementNameOffset(), + macro.getElementStartingOffset(), + macro.getElementEndingOffset() + - macro.getElementStartingOffset()); + translationUnit.addMacro(m); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariable(org.eclipse.cdt.core.parser.ast.IASTVariable) + */ + public void acceptVariable(IASTVariable variable) + { + SimpleDeclaration declaration = + createStructuralSimpleDeclaration(variable); + Declarator d = new Declarator(declaration); + d.setName(variable.getName()); + declaration.addDeclarator(d); + } + protected SimpleDeclaration createStructuralSimpleDeclaration(IASTVariable variable) + { + SimpleDeclaration declaration = + getTypeSpecOwner( + getCurrentDOMScope(), + variable.getElementStartingOffset()); + if (declaration == null) + { + declaration = + startSimpleDeclaration(variable.getElementStartingOffset()); + declaration.getDeclSpecifier().setConst( + variable.getAbstractDeclaration().isConst()); + declaration.getDeclSpecifier().setExtern(variable.isExtern()); + declaration.getDeclSpecifier().setAuto(variable.isAuto()); + declaration.getDeclSpecifier().setRegister(variable.isRegister()); + declaration.getDeclSpecifier().setStatic(variable.isStatic()); + IASTTypeSpecifier typeSpec = + variable.getAbstractDeclaration().getTypeSpecifier(); + if (typeSpec == null) + { + // what to do here? + } + else if (typeSpec instanceof IASTSimpleTypeSpecifier) + { + IASTSimpleTypeSpecifier simpleTypeSpec = + (IASTSimpleTypeSpecifier)typeSpec; + declaration.getDeclSpecifier().setLong(simpleTypeSpec.isLong()); + declaration.getDeclSpecifier().setShort( + simpleTypeSpec.isShort()); + declaration.getDeclSpecifier().setUnsigned( + simpleTypeSpec.isUnsigned()); + if (simpleTypeSpec.getType() + == IASTSimpleTypeSpecifier.Type.BOOL) + declaration.getDeclSpecifier().setType( + DeclSpecifier.t_bool); + else if ( + simpleTypeSpec.getType() + == IASTSimpleTypeSpecifier.Type.CHAR) + declaration.getDeclSpecifier().setType( + DeclSpecifier.t_char); + else if ( + simpleTypeSpec.getType() + == IASTSimpleTypeSpecifier.Type.DOUBLE) + declaration.getDeclSpecifier().setType( + DeclSpecifier.t_double); + else if ( + simpleTypeSpec.getType() + == IASTSimpleTypeSpecifier.Type.FLOAT) + declaration.getDeclSpecifier().setType( + DeclSpecifier.t_float); + else if ( + simpleTypeSpec.getType() + == IASTSimpleTypeSpecifier.Type.INT) + declaration.getDeclSpecifier().setType(DeclSpecifier.t_int); + else if ( + simpleTypeSpec.getType() + == IASTSimpleTypeSpecifier.Type.TEMPLATE) + declaration.getDeclSpecifier().setType( + DeclSpecifier.t_type); + else if ( + simpleTypeSpec.getType() + == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME) + declaration.getDeclSpecifier().setType( + DeclSpecifier.t_type); + else if ( + simpleTypeSpec.getType() + == IASTSimpleTypeSpecifier.Type.VOID) + declaration.getDeclSpecifier().setType( + DeclSpecifier.t_void); + else if ( + simpleTypeSpec.getType() + == IASTSimpleTypeSpecifier.Type.WCHAR_T) + declaration.getDeclSpecifier().setType( + DeclSpecifier.t_wchar_t); + } + else if (typeSpec instanceof IASTClassSpecifier) + { + } + else if (typeSpec instanceof IASTEnumerationSpecifier) + { + } + else if (typeSpec instanceof IASTElaboratedTypeSpecifier) + { + } + getCurrentDOMScope().addDeclaration(declaration); + } + return declaration; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionDeclaration(org.eclipse.cdt.core.parser.ast.IASTFunction) + */ + public void acceptFunctionDeclaration(IASTFunction function) + { + SimpleDeclaration simpleDeclaration = + getTypeSpecOwner( + getCurrentDOMScope(), + function.getElementStartingOffset()); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsageDirective(org.eclipse.cdt.core.parser.ast.IASTUsageDirective) + */ + public void acceptUsingDirective(IASTUsingDirective usageDirective) + { + UsingDirective directive = new UsingDirective(getCurrentDOMScope()); + directive.setNamespaceName(usageDirective.getNamespaceName()); + directive.getOwnerScope().addDeclaration(directive); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsageDeclaration(org.eclipse.cdt.core.parser.ast.IASTUsageDeclaration) + */ + public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration) + { + UsingDeclaration declaration = + new UsingDeclaration(getCurrentDOMScope()); + declaration.setTypename(usageDeclaration.isTypename()); + declaration.setMappedName(usageDeclaration.usingTypeName()); + declaration.getOwnerScope().addDeclaration(declaration); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptASMDefinition(org.eclipse.cdt.core.parser.ast.IASTASMDefinition) + */ + public void acceptASMDefinition(IASTASMDefinition asmDefinition) + { + IScope scope = getCurrentDOMScope(); + ASMDefinition definition = + new ASMDefinition(scope, asmDefinition.getBody()); + scope.addDeclaration(definition); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedef(org.eclipse.cdt.core.parser.ast.IASTTypedef) + */ + public void acceptTypedef(IASTTypedefDeclaration typedef) + { + // TODO Auto-generated method stub + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) + */ + public void enterFunctionBody(IASTFunction function) + { + // ignore + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) + */ + public void exitFunctionBody(IASTFunction function) + { + //ignore + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) + */ + public void enterCompilationUnit(IASTCompilationUnit compilationUnit) + { + domScopes.push(translationUnit); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) + */ + public void enterInclusion(IASTInclusion inclusion) + { + Inclusion i = + new Inclusion( + inclusion.getName(), + inclusion.getElementNameOffset(), + inclusion.getElementStartingOffset(), + inclusion.getElementEndingOffset(), + inclusion.isLocal()); + translationUnit.addInclusion(i); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) + */ + public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) + { + NamespaceDefinition namespaceDef = + new NamespaceDefinition(getCurrentDOMScope()); + namespaceDef.setName(namespaceDefinition.getName()); + ((IOffsetable)namespaceDef).setStartingOffset( + namespaceDefinition.getElementStartingOffset()); + if (!namespaceDefinition.getName().equals("")) + namespaceDef.setNameOffset( + namespaceDefinition.getElementNameOffset()); + this.domScopes.push(namespaceDef); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecification) + */ + public void enterClassSpecifier(IASTClassSpecifier classSpecification) + { + SimpleDeclaration decl = + startSimpleDeclaration( + classSpecification.getElementStartingOffset()); + int kind = ClassKey.t_struct; + int visibility = AccessSpecifier.v_public; + if (classSpecification.getClassKind() == ASTClassKind.CLASS) + { + kind = ClassKey.t_class; + visibility = AccessSpecifier.v_private; + } + else if (classSpecification.getClassKind() == ASTClassKind.STRUCT) + { + kind = ClassKey.t_struct; + } + else if (classSpecification.getClassKind() == ASTClassKind.UNION) + { + kind = ClassKey.t_union; + } + ClassSpecifier classSpecifier = new ClassSpecifier(kind, decl); + classSpecifier.setVisibility(visibility); + classSpecifier.setStartingOffset( + classSpecification.getElementStartingOffset()); + decl.setTypeSpecifier(classSpecifier); + classSpecifier.setName(classSpecification.getName()); + classSpecifier.setNameOffset(classSpecification.getElementNameOffset()); + domScopes.push(classSpecifier); + } + protected SimpleDeclaration startSimpleDeclaration(int startingOffset) + { + SimpleDeclaration decl = new SimpleDeclaration(getCurrentDOMScope()); + if (getCurrentDOMScope() instanceof IAccessable) + decl.setAccessSpecifier( + new AccessSpecifier( + ((IAccessable)getCurrentDOMScope()).getVisibility())); + ((IOffsetable)decl).setStartingOffset(startingOffset); + return decl; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) + */ + public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) + { + LinkageSpecification linkage = + new LinkageSpecification( + getCurrentDOMScope(), + linkageSpec.getLinkageString()); + domScopes.push(linkage); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) + */ + public void enterTemplateDeclaration(IASTTemplateDeclaration declaration) + { + // TODO Auto-generated method stub + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization) + */ + public void enterTemplateSpecialization(IASTTemplateSpecialization specialization) + { + // TODO Auto-generated method stub + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation) + */ + public void enterTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) + { + // TODO Auto-generated method stub + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodDeclaration(org.eclipse.cdt.core.parser.ast.IASTMethod) + */ + public void acceptMethodDeclaration(IASTMethod method) + { + // TODO Auto-generated method stub + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) + */ + public void enterMethodBody(IASTMethod method) + { + // ignore + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) + */ + public void exitMethodBody(IASTMethod method) + { + // ignore + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptField(org.eclipse.cdt.core.parser.ast.IASTField) + */ + public void acceptField(IASTField field) + { + SimpleDeclaration declaration = + createStructuralSimpleDeclaration(field); + Declarator d = new Declarator(declaration); + d.setName(field.getName()); + declaration.addDeclarator(d); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) + */ + public void exitTemplateDeclaration(IASTTemplateDeclaration declaration) + { + // TODO Auto-generated method stub + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization) + */ + public void exitTemplateSpecialization(IASTTemplateSpecialization specialization) + { + // TODO Auto-generated method stub + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation) + */ + public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) + { + // TODO Auto-generated method stub + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) + */ + public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) + { + LinkageSpecification linkage = (LinkageSpecification)domScopes.pop(); + getCurrentDOMScope().addDeclaration(linkage); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecification) + */ + public void exitClassSpecifier(IASTClassSpecifier classSpecification) + { + ClassSpecifier c = (ClassSpecifier)getCurrentDOMScope(); + c.setTotalLength( + classSpecification.getElementEndingOffset() + + 1 + - classSpecification.getElementStartingOffset()); domScopes.pop(); } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#classBegin(java.lang.String, org.eclipse.cdt.internal.core.newparser.Token) - */ - public Object classSpecifierBegin(Object container, IToken classKey) { - TypeSpecifier.IOwner decl = (TypeSpecifier.IOwner)container; - - int kind = ClassKey.t_struct; - int visibility = AccessSpecifier.v_public; - - switch (classKey.getType()) { - case IToken.t_class: - kind = ClassKey.t_class; - visibility = AccessSpecifier.v_private; - break; - case IToken.t_struct: - kind = ClassKey.t_struct; - break; - case IToken.t_union: - kind = ClassKey.t_union; - break; - } - - ClassSpecifier classSpecifier = new ClassSpecifier(kind, decl); - classSpecifier.setVisibility( visibility ); - classSpecifier.setStartingOffset( classKey.getOffset() ); - - classSpecifier.setClassKeyToken( classKey ); - decl.setTypeSpecifier(classSpecifier); - domScopes.push( classSpecifier ); - return classSpecifier; - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#classSpecifierName() - */ - public void classSpecifierName(Object classSpecifier) { - ((ClassSpecifier)classSpecifier).setName(currName); - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#classEnd() - */ - public void classSpecifierEnd(Object classSpecifier, IToken closingBrace) { - ClassSpecifier c = (ClassSpecifier)classSpecifier; - c.setTotalLength( closingBrace.getOffset() + closingBrace.getLength() - c.getStartingOffset() ); - domScopes.pop(); - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declaratorBegin() - */ - public Object declaratorBegin(Object container) { - if( container instanceof DeclSpecifier.IContainer ) - { - DeclSpecifier.IContainer decl = (DeclSpecifier.IContainer )container; - Declarator declarator = new Declarator(decl); - return declarator; - } - else if( container instanceof IDeclaratorOwner ) - { - IDeclaratorOwner owner = (IDeclaratorOwner)container; - Declarator declarator = new Declarator(owner); - return declarator; - } - return null; - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declaratorEnd() - */ - public void declaratorEnd(Object declarator) { - Declarator d = (Declarator)declarator; - if( d.getDeclaration() != null ) - d.getDeclaration().addDeclarator(d); - else if( d.getOwnerDeclarator() != null ) - d.getOwnerDeclarator().setDeclarator(d); - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declaratorId(org.eclipse.cdt.internal.core.newparser.Token) - */ - public void declaratorId(Object declarator) { - ((Declarator)declarator).setName(currName); - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declSpecifier(org.eclipse.cdt.internal.core.newparser.Token) - */ - public void simpleDeclSpecifier(Object Container, IToken specifier) { - DeclSpecifier.IContainer decl = (DeclSpecifier.IContainer)Container; - DeclSpecifier declSpec = decl.getDeclSpecifier(); - declSpec.setType( specifier ); - } - - - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#expressionOperator(org.eclipse.cdt.internal.core.newparser.Token) - */ - public void expressionOperator(Object expression, IToken operator){ - Expression e = (Expression)expression; - e.add( operator ); - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#expressionTerminal(org.eclipse.cdt.internal.core.newparser.Token) - */ - public void expressionTerminal(Object expression, IToken terminal){ - Expression e = (Expression)expression; - e.add( terminal ); - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#functionBodyBegin() - */ - public Object functionBodyBegin(Object declaration) { - SimpleDeclaration simpleDec = (SimpleDeclaration)declaration; - simpleDec.setFunctionDefinition(true); - return null; - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#functionBodyEnd() - */ - public void functionBodyEnd(Object functionBody ) { - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#inclusionBegin(java.lang.String) - */ - public Object inclusionBegin(String includeFile, int offset, int inclusionBeginOffset, boolean local) { -// Inclusion inclusion = new Inclusion( -// includeFile, -// offset, -// inclusionBeginOffset, -// offset - inclusionBeginOffset + includeFile.length() + 1, -// local ); -// translationUnit.addInclusion( inclusion ); -// return inclusion; - return null; - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#inclusionEnd() - */ - public void inclusionEnd(Object inclusion) { - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#macro(java.lang.String) - */ - public Object macro(String macroName, int offset, int macroBeginOffset, int macroEndOffset) { -// Macro macro = new Macro( macroName, offset, macroBeginOffset, macroEndOffset - macroBeginOffset); -// translationUnit.addMacro( macro ); - return null; - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#simpleDeclarationBegin(org.eclipse.cdt.internal.core.newparser.Token) - */ - public Object simpleDeclarationBegin(Object container, IToken firstToken) { - SimpleDeclaration decl = new SimpleDeclaration( getCurrentDOMScope() ); - if( getCurrentDOMScope() instanceof IAccessable ) - decl.setAccessSpecifier(new AccessSpecifier( ((IAccessable)getCurrentDOMScope()).getVisibility() )); - ((IOffsetable)decl).setStartingOffset( firstToken.getOffset() ); - return decl; - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#simpleDeclarationEnd(org.eclipse.cdt.internal.core.newparser.Token) - */ - public void simpleDeclarationEnd(Object declaration, IToken lastToken) { - SimpleDeclaration decl = (SimpleDeclaration)declaration; - IOffsetable offsetable = (IOffsetable)decl; - offsetable.setTotalLength( lastToken.getOffset() + lastToken.getLength() - offsetable.getStartingOffset()); - getCurrentDOMScope().addDeclaration(decl); - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#translationUnitBegin() - */ - public Object translationUnitBegin() { - translationUnit = new TranslationUnit(); - return translationUnit; - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#translationUnitEnd() - */ - public void translationUnitEnd(Object unit) { - } - - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#nameBegin(org.eclipse.cdt.internal.core.newparser.Token) - */ - public void nameBegin(IToken firstToken) { - currName = new Name(firstToken); - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#nameEnd(org.eclipse.cdt.internal.core.newparser.Token) - */ - public void nameEnd(IToken lastToken) { - currName.setEnd(lastToken); - } - - public Object baseSpecifierBegin( Object classSpecifier ) - { - ClassSpecifier cs =(ClassSpecifier)classSpecifier; - BaseSpecifier baseSpec = new BaseSpecifier( cs ); - return baseSpec; - } - - public void baseSpecifierEnd( Object baseSpecifier ) - { - - } - - public void baseSpecifierVirtual( Object baseSpecifier, boolean virtual ) - { - BaseSpecifier bs = (BaseSpecifier)baseSpecifier; - bs.setVirtual( virtual ); - } - - public void baseSpecifierVisibility( Object baseSpecifier, IToken visibility ) - { - int access = AccessSpecifier.v_public; - switch( visibility.getType() ) - { - case IToken.t_public: - access = AccessSpecifier.v_public; - break; - case IToken.t_protected: - access = AccessSpecifier.v_protected; - break; - case IToken.t_private: - access = AccessSpecifier.v_private; - break; - default: - break; - } - - ((BaseSpecifier)baseSpecifier).setAccess(access); - } - - - public void baseSpecifierName( Object baseSpecifier ) - { - ((BaseSpecifier)baseSpecifier).setName(currName); - } - - public Object parameterDeclarationBegin( Object container ) - { - IScope clause = (IScope)container; - ParameterDeclaration pd = new ParameterDeclaration(clause); - return pd; - } - - public void parameterDeclarationEnd( Object declaration ){ - ParameterDeclaration d = (ParameterDeclaration)declaration; - d.getOwnerScope().addDeclaration(d); - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declaratorAbort(java.lang.Object, java.lang.Object) - */ - public void declaratorAbort(Object declarator) { - currName = null; - } - - /** - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionBegin(java.lang.Object) - */ - public Object expressionBegin(Object container) { - IExpressionOwner owner = (IExpressionOwner)container; - Expression expression = new Expression(); - owner.setExpression(expression); - return expression; - } - /** - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionEnd(java.lang.Object) - */ - public void expressionEnd(Object expression) { - } - - /** - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierAbort(java.lang.Object) - */ - public void classSpecifierAbort(Object classSpecifier) { - ClassSpecifier cs = (ClassSpecifier)classSpecifier; - cs.getOwner().setTypeSpecifier(null); - domScopes.pop(); - } - - /** - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierBegin(java.lang.Object) - */ - public Object elaboratedTypeSpecifierBegin(Object container, IToken classKey) { - int kind = ClassKey.t_struct; - - switch (classKey.getType()) { - case IToken.t_class: - kind = ClassKey.t_class; - break; - case IToken.t_struct: - kind = ClassKey.t_struct; - break; - case IToken.t_union: - kind = ClassKey.t_union; - break; - case IToken.t_enum: - kind = ClassKey.t_enum; - break; - } - - ElaboratedTypeSpecifier elab = null; - TypeSpecifier.IOwner declaration = (TypeSpecifier.IOwner)container; - elab = new ElaboratedTypeSpecifier( kind, declaration ); - declaration.setTypeSpecifier( elab ); - return elab; - } - - /** - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierEnd(java.lang.Object) - */ - public void elaboratedTypeSpecifierEnd(Object elab) { - } - - /** - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierName(java.lang.Object) - */ - public void elaboratedTypeSpecifierName(Object elab) { - ((ElaboratedTypeSpecifier)elab).setName( currName ); - } - - /** - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierName(java.lang.Object) - */ - public void simpleDeclSpecifierName(Object declaration) { - DeclSpecifier.IContainer decl = (DeclSpecifier.IContainer)declaration; - DeclSpecifier declSpec = decl.getDeclSpecifier(); - declSpec.setName( currName ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionAbort(java.lang.Object) - */ - public void expressionAbort(Object expression) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#classMemberVisibility(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public void classMemberVisibility(Object classSpecifier, IToken visibility) { - ClassSpecifier spec = (ClassSpecifier)classSpecifier; - switch( visibility.getType() ) - { - case IToken.t_public: - spec.setVisibility( AccessSpecifier.v_public ); - break; - case IToken.t_protected: - spec.setVisibility( AccessSpecifier.v_protected ); - break; - case IToken.t_private: - spec.setVisibility( AccessSpecifier.v_private ); - break; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#pointerOperatorBegin(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public Object pointerOperatorBegin(Object container) { - Declarator declarator = (Declarator)container; - PointerOperator ptrOp = new PointerOperator(declarator); - return ptrOp; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#pointerOperatorEnd(java.lang.Object) - */ - public void pointerOperatorEnd(Object ptrOperator) { - PointerOperator ptrOp = (PointerOperator)ptrOperator; - Declarator owner = ptrOp.getOwnerDeclarator(); - if( owner != null ) // can be since operator * - owner.addPointerOperator( ptrOp ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#pointerOperatorName(java.lang.Object) - */ - public void pointerOperatorName(Object ptrOperator) { - ((PointerOperator)ptrOperator).setNameSpecifier(currName); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#pointerOperatorType(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public void pointerOperatorType(Object ptrOperator, IToken type) { - PointerOperator ptrOp = (PointerOperator)ptrOperator; - switch( type.getType() ) - { - case IToken.tSTAR: - ptrOp.setType( PointerOperator.t_pointer ); - break; - case IToken.tAMPER: - ptrOp.setType( PointerOperator.t_reference ); - break; - case IToken.tCOLONCOLON: - case IToken.tIDENTIFIER: - ptrOp.setType( PointerOperator.t_pointer_to_member ); - break; - default: - break; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#pointerOperatorCVModifier(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public void pointerOperatorCVModifier(Object ptrOperator, IToken modifier) { - PointerOperator ptrOp = (PointerOperator)ptrOperator; - switch( modifier.getType() ) - { - case IToken.t_const: - ptrOp.setConst(true); - break; - case IToken.t_volatile: - ptrOp.setVolatile( true ); - break; - default: - break; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorCVModifier(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public void declaratorCVModifier(Object declarator, IToken modifier) { - Declarator decl = (Declarator)declarator; - switch( modifier.getType() ) - { - case IToken.t_const: - decl.setConst(true); - break; - case IToken.t_volatile: - decl.setVolatile( true ); - break; - default: - break; - } - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#arrayBegin(java.lang.Object) - */ - public Object arrayDeclaratorBegin(Object declarator) { - Declarator decl = (Declarator)declarator; - ArrayQualifier qual = new ArrayQualifier( decl ); - return qual; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#arrayEnd(java.lang.Object) - */ - public void arrayDeclaratorEnd(Object arrayQualifier ) { - ArrayQualifier qual = (ArrayQualifier)arrayQualifier; - Declarator parent = qual.getOwnerDeclarator(); - parent.addArrayQualifier(qual); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#exceptionSpecificationTypename(java.lang.Object) - */ - public void declaratorThrowExceptionName(Object declarator ) - { - Declarator decl = (Declarator)declarator; - decl.getExceptionSpecifier().addTypeName( currName ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorThrowsException(java.lang.Object) - */ - public void declaratorThrowsException(Object declarator) { - Declarator decl = (Declarator)declarator; - decl.getExceptionSpecifier().setThrowsException(true); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#namespaceDeclarationBegin(java.lang.Object) - */ - public Object namespaceDefinitionBegin(Object container, IToken namespace) { -// IScope ownerScope = (IScope)container; -// NamespaceDefinition namespaceDef = new NamespaceDefinition(ownerScope); -// namespaceDef.setStartToken(namespace); -// ((IOffsetable)namespaceDef).setStartingOffset( namespace.getOffset() ); -// return namespaceDef; - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#namespaceDeclarationId(java.lang.Object) - */ - public void namespaceDefinitionId(Object namespace) { -// NamespaceDefinition ns = (NamespaceDefinition)namespace; -// ns.setName( currName ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#namespaceDeclarationAbort(java.lang.Object) - */ - public void namespaceDefinitionAbort(Object namespace) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#namespaceDeclarationEnd(java.lang.Object) - */ - public void namespaceDefinitionEnd(Object namespace, IToken closingBrace) { -// NamespaceDefinition ns = (NamespaceDefinition)namespace; -// ns.setTotalLength( closingBrace.getOffset() + closingBrace.getLength() - ns.getStartingOffset() ); -// ns.getOwnerScope().addDeclaration(ns); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#linkageSpecificationBegin(java.lang.Object, java.lang.String) - */ - public Object linkageSpecificationBegin(Object container, String literal) { -// IScope scope = (IScope)container; -// LinkageSpecification linkage = new LinkageSpecification( scope, literal ); -// domScopes.push( linkage ); - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#linkageSpecificationEnd(java.lang.Object) - */ - public void linkageSpecificationEnd(Object linkageSpec) { -// LinkageSpecification linkage = (LinkageSpecification)domScopes.pop(); -// linkage.getOwnerScope().addDeclaration(linkage ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDirectiveBegin(java.lang.Object) - */ - public Object usingDirectiveBegin(Object container) { -// IScope scope = (IScope)container; -// UsingDirective directive = new UsingDirective( scope ); -// return directive; - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDirectiveNamespaceId(java.lang.Object) - */ - public void usingDirectiveNamespaceId(Object dir) { -// UsingDirective directive = (UsingDirective)dir; -// directive.setNamespaceName( currName ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDirectiveEnd(java.lang.Object) - */ - public void usingDirectiveEnd(Object dir) { -// UsingDirective directive = (UsingDirective)dir; -// directive.getOwnerScope().addDeclaration( directive ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDeclarationBegin(java.lang.Object) - */ - public Object usingDeclarationBegin(Object container) { -// IScope scope = (IScope)container; -// UsingDeclaration declaration = new UsingDeclaration( scope ); -// return declaration; - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDeclarationMapping(java.lang.Object) - */ - public void usingDeclarationMapping(Object decl, boolean isTypename) { -// UsingDeclaration declaration = (UsingDeclaration)decl; -// declaration.setMappedName( currName ); -// declaration.setTypename( isTypename ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDeclarationEnd(java.lang.Object) - */ - public void usingDeclarationEnd(Object decl) { -// UsingDeclaration declaration = (UsingDeclaration)decl; -// declaration.getOwnerScope().addDeclaration( declaration ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDirectiveAbort(java.lang.Object) - */ - public void usingDirectiveAbort(Object directive) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDeclarationAbort(java.lang.Object) - */ - public void usingDeclarationAbort(Object declaration) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumSpecifierBegin(java.lang.Object) - */ - public Object enumSpecifierBegin(Object container, IToken enumKey) { - TypeSpecifier.IOwner decl = (TypeSpecifier.IOwner)container; - EnumerationSpecifier es = new EnumerationSpecifier( decl ); - es.setStartToken(enumKey); - decl.setTypeSpecifier(es); - ((IOffsetable)es).setStartingOffset( enumKey.getOffset() ); - return es; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumSpecifierId(java.lang.Object) - */ - public void enumSpecifierId(Object enumSpec) { - EnumerationSpecifier es = (EnumerationSpecifier)enumSpec; - es.setName( currName ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumSpecifierAbort(java.lang.Object) - */ - public void enumSpecifierAbort(Object enumSpec) { - EnumerationSpecifier es = (EnumerationSpecifier)enumSpec; - es.getOwner().setTypeSpecifier(null); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumSpecifierEnd(java.lang.Object) - */ - public void enumSpecifierEnd(Object enumSpec, IToken closingBrace) { - IOffsetable offsetable = (IOffsetable)enumSpec; - offsetable.setTotalLength( closingBrace.getOffset() + closingBrace.getLength() - offsetable.getStartingOffset()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumDefinitionBegin(java.lang.Object) - */ - public Object enumeratorBegin(Object enumSpec) { - EnumerationSpecifier es = (EnumerationSpecifier)enumSpec; - EnumeratorDefinition definition = new EnumeratorDefinition(); - es.addEnumeratorDefinition(definition); - return definition; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumDefinitionId(java.lang.Object) - */ - public void enumeratorId(Object enumDefn) { - EnumeratorDefinition definition = (EnumeratorDefinition)enumDefn; - definition.setName( currName ); - ((IOffsetable)enumDefn).setStartingOffset( currName.getStartOffset() ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumDefinitionEnd(java.lang.Object) - */ - public void enumeratorEnd(Object enumDefn, IToken lastToken) { - IOffsetable offsetable = (IOffsetable)enumDefn; - offsetable.setTotalLength( lastToken.getOffset() + lastToken.getLength() - offsetable.getStartingOffset()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#asmDefinition(java.lang.String) - */ - public void asmDefinition(Object container, String assemblyCode) { -// IScope scope = (IScope)container; -// ASMDefinition definition = new ASMDefinition( scope, assemblyCode ); -// scope.addDeclaration( definition ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainBegin(java.lang.Object) - */ - public Object constructorChainBegin(Object declarator) { - Declarator d = (Declarator)declarator; - ConstructorChain chain = new ConstructorChain(d); - return chain; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainAbort(java.lang.Object) - */ - public void constructorChainAbort(Object ctor) { - ctor = null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainEnd(java.lang.Object) - */ - public void constructorChainEnd(Object ctor) { - ConstructorChain chain = (ConstructorChain)ctor; - chain.getOwnerDeclarator().setCtorChain(chain); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementBegin(java.lang.Object) - */ - public Object constructorChainElementBegin(Object ctor) { - return new ConstructorChainElement( (ConstructorChain)ctor ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementEnd(java.lang.Object) - */ - public void constructorChainElementEnd(Object element) { - ConstructorChainElement ele = (ConstructorChainElement)element; - ele.getOwnerChain().addChainElement( ele ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainId(java.lang.Object) - */ - public void constructorChainElementId(Object element) { - ConstructorChainElement ele = (ConstructorChainElement)element; - ele.setName(currName); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitInstantiationBegin(java.lang.Object) - */ - public Object explicitInstantiationBegin(Object container) { - ExplicitTemplateDeclaration etd = new ExplicitTemplateDeclaration( getCurrentDOMScope(), ExplicitTemplateDeclaration.k_instantiation ); - domScopes.push( etd ); - return etd; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitInstantiationEnd(java.lang.Object) - */ - public void explicitInstantiationEnd(Object instantiation) { - ExplicitTemplateDeclaration declaration = (ExplicitTemplateDeclaration)domScopes.pop(); - declaration.getOwnerScope().addDeclaration(declaration); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitSpecializationBegin(java.lang.Object) - */ - public Object explicitSpecializationBegin(Object container) { - ExplicitTemplateDeclaration etd = new ExplicitTemplateDeclaration( getCurrentDOMScope(), ExplicitTemplateDeclaration.k_specialization); - domScopes.push( etd ); - return etd; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitSpecializationEnd(java.lang.Object) - */ - public void explicitSpecializationEnd(Object instantiation) { - ExplicitTemplateDeclaration etd = (ExplicitTemplateDeclaration)domScopes.pop(); - etd.getOwnerScope().addDeclaration(etd); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorPureVirtual(java.lang.Object) - */ - public void declaratorPureVirtual(Object declarator) { - Declarator d = (Declarator)declarator; - d.setPureVirtual(true); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationBegin(java.lang.Object, boolean) - */ - public Object templateDeclarationBegin(Object container, IToken exported) { - TemplateDeclaration d = new TemplateDeclaration( (IScope)getCurrentDOMScope(), exported ); - if( getCurrentDOMScope() instanceof IAccessable ) - d.setVisibility( ((IAccessable)container).getVisibility() ); - d.setStartingOffset( exported.getOffset() ); - domScopes.push( d ); - return d; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationAbort(java.lang.Object) - */ - public void templateDeclarationAbort(Object templateDecl) { - domScopes.pop(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationEnd(java.lang.Object) - */ - public void templateDeclarationEnd(Object templateDecl, IToken lastToken) { - TemplateDeclaration decl = (TemplateDeclaration)domScopes.pop(); - decl.setLastToken(lastToken); - decl.getOwnerScope().addDeclaration(decl); - decl.setTotalLength(lastToken.getOffset() + lastToken.getLength() - decl.getStartingOffset() ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterBegin(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public Object templateTypeParameterBegin(Object templDecl, IToken kind) { - TemplateParameterList list = (TemplateParameterList)templDecl; - int k; - switch( kind.getType() ) - { - case IToken.t_class: - k = TemplateParameter.k_class; - break; - case IToken.t_typename: - k= TemplateParameter.k_typename; - break; - case IToken.t_template: - k= TemplateParameter.k_template; - break; - default: - k = 0; - } - TemplateParameter p = new TemplateParameter( list, k ); - return p; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterName(java.lang.Object) - */ - public void templateTypeParameterName(Object typeParm) { - ((TemplateParameter)typeParm).setName( currName ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeInitialTypeId(java.lang.Object) - */ - public void templateTypeParameterInitialTypeId(Object typeParm) { - ((TemplateParameter)typeParm).setTypeId( currName ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterEnd(java.lang.Object) - */ - public void templateTypeParameterEnd(Object typeParm) { - TemplateParameter parameter = (TemplateParameter)typeParm; - parameter.getOwnerScope().addDeclaration( parameter ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterAbort(java.lang.Object) - */ - public void templateTypeParameterAbort(Object typeParm) { - typeParm = null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#pointerOperatorAbort(java.lang.Object) - */ - public void pointerOperatorAbort(Object ptrOperator) { - ptrOperator = null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateParameterListBegin(java.lang.Object) - */ - public Object templateParameterListBegin(Object declaration) { - ITemplateParameterListOwner d = (ITemplateParameterListOwner)declaration; - TemplateParameterList list = new TemplateParameterList(); - d.setTemplateParms(list); - return list; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateParameterListEnd(java.lang.Object) - */ - public void templateParameterListEnd(Object parameterList) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#setParser(org.eclipse.cdt.internal.core.parser.IParser) - */ - public void setParser(IParser parser) { - this.parser = parser; - } - - protected Name currName; - protected IParser parser = null; - protected TranslationUnit translationUnit; - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionName(java.lang.Object) - */ - public void expressionName(Object expression) { - Expression e = (Expression)expression; - e.add( currName ); } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#startBitfield(java.lang.Object) - */ - public Object startBitfield(Object declarator) { - return new BitField((Declarator)declarator); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#endBitfield(java.lang.Object) - */ - public void endBitfield(Object bitfield) { - BitField b = (BitField)bitfield; - b.getOwnerDeclarator().setBitField( b ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierType(java.lang.Object, java.lang.Object) - */ - public void simpleDeclSpecifierType(Object declaration, Object type) { -// if( type instanceof TypeSpecifier ) -// { -// System.out.println( "Told you so!"); -// } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem) - */ - public void acceptProblem(IProblem problem) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMacro(org.eclipse.cdt.core.parser.ast.IASTMacro) - */ - public void acceptMacro(IASTMacro macro) { - Macro m = new Macro( macro.getName(), macro.getElementNameOffset(), macro.getElementStartingOffset(), - macro.getElementEndingOffset() - macro.getElementStartingOffset()); - translationUnit.addMacro( m ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariable(org.eclipse.cdt.core.parser.ast.IASTVariable) - */ - public void acceptVariable(IASTVariable variable) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionDeclaration(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void acceptFunctionDeclaration(IASTFunction function) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsageDirective(org.eclipse.cdt.core.parser.ast.IASTUsageDirective) - */ - public void acceptUsingDirective(IASTUsingDirective usageDirective) { - UsingDirective directive = new UsingDirective( getCurrentDOMScope() ); - directive.setNamespaceName( usageDirective.getNamespaceName() ); - directive.getOwnerScope().addDeclaration( directive ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsageDeclaration(org.eclipse.cdt.core.parser.ast.IASTUsageDeclaration) - */ - public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration) { - UsingDeclaration declaration = new UsingDeclaration( getCurrentDOMScope() ); - declaration.setTypename( usageDeclaration.isTypename()); - declaration.setMappedName(usageDeclaration.usingTypeName()); - declaration.getOwnerScope().addDeclaration( declaration ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptASMDefinition(org.eclipse.cdt.core.parser.ast.IASTASMDefinition) - */ - public void acceptASMDefinition(IASTASMDefinition asmDefinition) { - IScope scope = getCurrentDOMScope(); - ASMDefinition definition = new ASMDefinition( scope, asmDefinition.getBody() ); - scope.addDeclaration( definition ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedef(org.eclipse.cdt.core.parser.ast.IASTTypedef) - */ - public void acceptTypedef(IASTTypedef typedef) { - // TODO Auto-generated method stub - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void enterFunctionBody(IASTFunction function) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void exitFunctionBody(IASTFunction function) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) - */ - public void enterCompilationUnit(IASTCompilationUnit compilationUnit) { - domScopes.push( translationUnit ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) - */ - public void enterInclusion(IASTInclusion inclusion) { - Inclusion i = new Inclusion( - inclusion.getName(), - inclusion.getElementNameOffset(), - inclusion.getElementStartingOffset(), - inclusion.getElementEndingOffset(), - inclusion.isLocal() ); - translationUnit.addInclusion( i ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) - */ - public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) { - NamespaceDefinition namespaceDef = new NamespaceDefinition(getCurrentDOMScope()); - namespaceDef.setName( namespaceDefinition.getName() ); - ((IOffsetable)namespaceDef).setStartingOffset( namespaceDefinition.getElementStartingOffset() ); - if( ! namespaceDefinition.getName().equals( "" )) - namespaceDef.setNameOffset( namespaceDefinition.getElementNameOffset() ); - this.domScopes.push( namespaceDef ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecification) - */ - public void enterClassSpecifier(IASTClassSpecifier classSpecification) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) - */ - public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) { - LinkageSpecification linkage = new LinkageSpecification( getCurrentDOMScope(), linkageSpec.getLinkageString() ); - domScopes.push( linkage ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) - */ - public void enterTemplateDeclaration(IASTTemplateDeclaration declaration) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization) - */ - public void enterTemplateSpecialization(IASTTemplateSpecialization specialization) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation) - */ - public void enterTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodDeclaration(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void acceptMethodDeclaration(IASTMethod method) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void enterMethodBody(IASTMethod method) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void exitMethodBody(IASTMethod method) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptField(org.eclipse.cdt.core.parser.ast.IASTField) - */ - public void acceptField(IASTField field) { - // TODO Auto-generated method stub - - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) - */ - public void exitTemplateDeclaration(IASTTemplateDeclaration declaration) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization) - */ - public void exitTemplateSpecialization(IASTTemplateSpecialization specialization) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation) - */ - public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) - */ - public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) { - LinkageSpecification linkage = (LinkageSpecification)domScopes.pop(); - getCurrentDOMScope().addDeclaration(linkage ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecification) - */ - public void exitClassSpecifier(IASTClassSpecifier classSpecification) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) - */ - public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) { - NamespaceDefinition definition = (NamespaceDefinition)domScopes.pop(); - definition.setTotalLength( namespaceDefinition.getElementEndingOffset() - namespaceDefinition.getElementStartingOffset()); - getCurrentDOMScope().addDeclaration( definition ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) - */ - public void exitInclusion(IASTInclusion inclusion) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) - */ - public void exitCompilationUnit(IASTCompilationUnit compilationUnit) { - domScopes.pop(); - } - - private ScopeStack domScopes = new ScopeStack(); - - private IScope getCurrentDOMScope() - { - return domScopes.peek(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier) - */ - public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration) { - // TODO Auto-generated method stub - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptClassReference(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier, int) - */ - public void acceptClassReference(IASTClassReference reference) { - // TODO Auto-generated method stub - - } - + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) + */ + public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) + { + NamespaceDefinition definition = (NamespaceDefinition)domScopes.pop(); + definition.setTotalLength( + namespaceDefinition.getElementEndingOffset() + - namespaceDefinition.getElementStartingOffset()); + getCurrentDOMScope().addDeclaration(definition); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) + */ + public void exitInclusion(IASTInclusion inclusion) + { + // ignore + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) + */ + public void exitCompilationUnit(IASTCompilationUnit compilationUnit) + { + domScopes.pop(); + } + private ScopeStack domScopes = new ScopeStack(); + private IScope getCurrentDOMScope() + { + return domScopes.peek(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier) + */ + public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration) + { + SimpleDeclaration decl = + startSimpleDeclaration(enumeration.getElementStartingOffset()); + EnumerationSpecifier es = new EnumerationSpecifier(decl); + es.setStartingOffset(enumeration.getElementStartingOffset()); + es.setStartImage("enum"); + decl.setTypeSpecifier(es); + es.setName(enumeration.getName()); + es.setTotalLength( + enumeration.getElementEndingOffset() + + 1 + - enumeration.getElementStartingOffset()); + Iterator i = enumeration.getEnumerators(); + while (i.hasNext()) + { + IASTEnumerator enumerator = (IASTEnumerator)i.next(); + EnumeratorDefinition definition = new EnumeratorDefinition(); + es.addEnumeratorDefinition(definition); + definition.setName(enumerator.getName()); + ((IOffsetable)definition).setStartingOffset( + enumerator.getElementNameOffset()); + definition.setTotalLength( + enumerator.getElementEndingOffset() + + 1 + - enumerator.getElementStartingOffset()); + } + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptClassReference(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier, int) + */ + public void acceptClassReference(IASTClassReference reference) + { + // ignore + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier) */ public void acceptElaboratedTypeSpecifier(IASTElaboratedTypeSpecifier elaboratedTypeSpec) + { + int kind = ClassKey.t_struct; + + if( elaboratedTypeSpec.getClassKind() == ASTClassKind.CLASS ) + kind = ClassKey.t_class; + else if( elaboratedTypeSpec.getClassKind() == ASTClassKind.STRUCT ) + kind = ClassKey.t_struct; + else if( elaboratedTypeSpec.getClassKind() == ASTClassKind.UNION ) + kind = ClassKey.t_union; + else if( elaboratedTypeSpec.getClassKind() == ASTClassKind.ENUM ) + kind = ClassKey.t_enum; + + SimpleDeclaration declaration = getTypeSpecOwner( getCurrentDOMScope(), elaboratedTypeSpec.getElementStartingOffset() ); + ElaboratedTypeSpecifier elab = null; + elab = new ElaboratedTypeSpecifier( kind, declaration ); + declaration.setTypeSpecifier( elab ); + ((ElaboratedTypeSpecifier)elab).setName( elaboratedTypeSpec.getName() ); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptAbstractTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration) + */ + public void acceptAbstractTypeSpecDeclaration(IASTAbstractTypeSpecifierDeclaration abstractDeclaration) + { + // TODO Auto-generated method stub + + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptPointerToFunction(org.eclipse.cdt.core.parser.ast.IASTPointerToFunction) + */ + public void acceptPointerToFunction(IASTPointerToFunction function) + { + // TODO Auto-generated method stub + + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptPointerToMethod(org.eclipse.cdt.core.parser.ast.IASTPointerToMethod) + */ + public void acceptPointerToMethod(IASTPointerToMethod method) { // TODO Auto-generated method stub diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DeclSpecifier.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DeclSpecifier.java index 703bd0aac1c..773ffbf99d2 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DeclSpecifier.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DeclSpecifier.java @@ -2,8 +2,6 @@ package org.eclipse.cdt.internal.core.dom; import java.util.List; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.internal.core.parser.Name; /** * @author jcamelon @@ -168,86 +166,7 @@ public class DeclSpecifier { public static final int t_double = 6; public static final int t_void = 7; - public void setType(IToken token) { - switch (token.getType()) { - case IToken.t_typename: - setTypename(true); - break; - case IToken.t_auto : - setAuto(true); - break; - case IToken.t_register : - setRegister(true); - break; - case IToken.t_static : - setStatic(true); - break; - case IToken.t_extern : - setExtern(true); - break; - case IToken.t_mutable : - setMutable(true); - break; - case IToken.t_inline : - setInline(true); - break; - case IToken.t_virtual : - setVirtual(true); - break; - case IToken.t_explicit : - setExplicit(true); - break; - case IToken.t_typedef : - setTypedef(true); - break; - case IToken.t_friend : - setFriend(true); - break; - case IToken.t_const : - setConst(true); - break; - case IToken.t_volatile : - setVolatile(true); - break; - case IToken.t_char : - setType(DeclSpecifier.t_char); - break; - case IToken.t_wchar_t : - setType(DeclSpecifier.t_wchar_t); - break; - case IToken.t_bool : - setType(DeclSpecifier.t_bool); - break; - case IToken.t_short : - setShort(true); - break; - case IToken.t_int : - setType(DeclSpecifier.t_int); - break; - case IToken.t_long : - setLong(true); - break; - case IToken.t_signed : - setUnsigned(false); - break; - case IToken.t_unsigned : - setUnsigned(true); - break; - case IToken.t_float : - setType(DeclSpecifier.t_float); - break; - case IToken.t_double : - setType(DeclSpecifier.t_double); - break; - case IToken.t_void : - setType(DeclSpecifier.t_void); - break; - case IToken.tIDENTIFIER : - setType(DeclSpecifier.t_type); - break; - } - } public void setType(int t) { declSpecifierSeq = declSpecifierSeq & ~typeMask | t; @@ -265,13 +184,13 @@ public class DeclSpecifier { }; - Name name = null; + String name = null; /** * Returns the name. * @return Name */ - public Name getName() { + public String getName() { return name; } @@ -279,7 +198,7 @@ public class DeclSpecifier { * Sets the name. * @param name The name to set */ - public void setName(Name name) { + public void setName(String name) { this.name = name; } diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Declarator.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Declarator.java index 245c43361fa..d365937c93f 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Declarator.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Declarator.java @@ -4,11 +4,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.eclipse.cdt.internal.core.parser.Name; -public class Declarator implements IExpressionOwner, IDeclaratorOwner { +public class Declarator implements IDeclaratorOwner { public Declarator(DeclSpecifier.IContainer declaration) { this.declaration = declaration; @@ -23,6 +22,7 @@ public class Declarator implements IExpressionOwner, IDeclaratorOwner { private final DeclSpecifier.IContainer declaration; private final IDeclaratorOwner ownerDeclarator; + private int nameOffset; /** * Returns the declaration. @@ -40,13 +40,13 @@ public class Declarator implements IExpressionOwner, IDeclaratorOwner { } - private Name name; + private String name; /** * Returns the name. * @return Name */ - public Name getName() { + public String getName() { return name; } @@ -54,7 +54,7 @@ public class Declarator implements IExpressionOwner, IDeclaratorOwner { * Sets the name. * @param name The name to set */ - public void setName(Name name) { + public void setName(String name) { this.name = name; } @@ -72,22 +72,6 @@ public class Declarator implements IExpressionOwner, IDeclaratorOwner { public ParameterDeclarationClause getParms() { return parms; } - - private Expression initialExpression = null; - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.IExpressionOwner#getExpression() - */ - public Expression getExpression() { - return initialExpression; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.IExpressionOwner#setExpression(org.eclipse.cdt.internal.core.dom.Expression) - */ - public void setExpression(Expression exp) { - initialExpression = exp; - } List pointerOperators = new ArrayList(); List arrayQualifiers = new ArrayList(); @@ -226,4 +210,20 @@ public class Declarator implements IExpressionOwner, IDeclaratorOwner { bitField = field; } + /** + * @return + */ + public int getNameOffset() + { + return nameOffset; + } + + /** + * @param i + */ + public void setNameOffset(int i) + { + nameOffset = i; + } + } diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ElaboratedTypeSpecifier.java index 27b3807b95a..9b129a648b5 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ElaboratedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ElaboratedTypeSpecifier.java @@ -1,6 +1,5 @@ package org.eclipse.cdt.internal.core.dom; -import org.eclipse.cdt.internal.core.parser.Name; /** @@ -27,9 +26,9 @@ public class ElaboratedTypeSpecifier extends TypeSpecifier { this.classKey.setClassKey( classKey ); } - private Name name; - public void setName(Name n) { name = n; } - public Name getName() { return name; } + private String name; + public void setName(String n) { name = n; } + public String getName() { return name; } private ClassSpecifier classSpec = null; diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/EnumerationSpecifier.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/EnumerationSpecifier.java index 5923a0f90c4..886024d033b 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/EnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/EnumerationSpecifier.java @@ -16,9 +16,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.internal.core.parser.Name; - /** * @author jcamelon * @@ -29,10 +26,11 @@ public class EnumerationSpecifier extends TypeSpecifier implements IOffsetable { super(declaration); } - private Name name = null; + private String name = null; private List enumeratorDefinitions = new ArrayList(); private int startingOffset = 0, totalLength = 0; - private IToken startToken = null; + private int nameOffset = 0; + private String startImage = null; public void addEnumeratorDefinition( EnumeratorDefinition def ) { @@ -50,7 +48,7 @@ public class EnumerationSpecifier extends TypeSpecifier implements IOffsetable { /** * @return Name */ - public Name getName() { + public String getName() { return name; } @@ -58,7 +56,7 @@ public class EnumerationSpecifier extends TypeSpecifier implements IOffsetable { * Sets the name. * @param name The name to set */ - public void setName(Name name) { + public void setName(String name) { this.name = name; } @@ -94,16 +92,16 @@ public class EnumerationSpecifier extends TypeSpecifier implements IOffsetable { * Returns the startToken. * @return Token */ - public IToken getStartToken() { - return startToken; + public String getStartImage() { + return startImage; } /** * Sets the startToken. * @param startToken The startToken to set */ - public void setStartToken(IToken startToken) { - this.startToken = startToken; + public void setStartImage(String startImage) { + this.startImage= startImage; } private int topLine = 0, bottomLine = 0; @@ -138,4 +136,20 @@ public class EnumerationSpecifier extends TypeSpecifier implements IOffsetable { return bottomLine; } + /** + * @return + */ + public int getNameOffset() + { + return nameOffset; + } + + /** + * @param i + */ + public void setNameOffset(int i) + { + nameOffset = i; + } + } diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/EnumeratorDefinition.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/EnumeratorDefinition.java index 3c6e39c4b69..6ea8a0f2747 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/EnumeratorDefinition.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/EnumeratorDefinition.java @@ -12,37 +12,21 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.dom; -import org.eclipse.cdt.internal.core.parser.Name; /** * @author jcamelon * */ -public class EnumeratorDefinition implements IExpressionOwner, IOffsetable { +public class EnumeratorDefinition implements IOffsetable { - private Expression initialValue = null; - private Name name = null; + private String name = null; private int startingOffset = 0, totalLength = 0; - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.IExpressionOwner#getExpression() - */ - public Expression getExpression() { - return initialValue; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.IExpressionOwner#setExpression(org.eclipse.cdt.internal.core.dom.Expression) - */ - public void setExpression(Expression exp) { - initialValue = exp; - } - /** * @return Name */ - public Name getName() { + public String getName() { return name; } @@ -50,7 +34,7 @@ public class EnumeratorDefinition implements IExpressionOwner, IOffsetable { * Sets the name. * @param name The name to set */ - public void setName(Name name) { + public void setName(String name) { this.name = name; } diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ExceptionSpecifier.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ExceptionSpecifier.java index 3437236a596..252e0c596dd 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ExceptionSpecifier.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ExceptionSpecifier.java @@ -16,8 +16,6 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; -import org.eclipse.cdt.internal.core.parser.Name; - /** * @author jcamelon @@ -35,7 +33,7 @@ public class ExceptionSpecifier { return Collections.unmodifiableList( typeNames ); } - public void addTypeName( Name name ) + public void addTypeName( String name ) { typeNames.add( name ); } diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Expression.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Expression.java deleted file mode 100644 index 11aec1d6319..00000000000 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Expression.java +++ /dev/null @@ -1,44 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: John Camelon - * Rational Software - Initial API and implementation -***********************************************************************/ - -package org.eclipse.cdt.internal.core.dom; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.internal.core.parser.Name; - -/** - * @author jcamelon - * - */ -public class Expression { - - private List tokens = new ArrayList(); - - public void add( IToken t ) - { - tokens.add( t ); - } - - public void add( Name t ) - { - tokens.add( t ); - } - - public List elements() - { - return Collections.unmodifiableList( tokens ); - } - -} diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Name.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Name.java deleted file mode 100644 index 0fd726d5f3c..00000000000 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Name.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.eclipse.cdt.internal.core.dom; - -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.internal.core.parser.Token; - - -/** - * @author dschaefe - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class Name { - - private Token nameStart, nameEnd; - - public Name(Token nameStart) { - this.nameStart = nameStart; - } - - public void setEnd(Token nameEnd) { - this.nameEnd = nameEnd; - } - - public int getStartOffset() - { - return nameStart.getOffset(); - } - - public int getEndOffset() - { - return nameEnd.getOffset(); - } - - public String toString() { - IToken t = nameStart; - StringBuffer buffer = new StringBuffer(); - buffer.append( t.getImage() ); - if( t.getType() == IToken.t_operator ) - buffer.append( " " ); - - while (t != nameEnd) { - t = t.getNext(); - - buffer.append( t.getImage() ); - if (t.getType() == IToken.t_operator) buffer.append( " " ); - } - - return buffer.toString(); - } - - public int length() - { - return getEndOffset() - getStartOffset() + nameEnd.getLength(); - } - /** - * @return - */ - public IToken getNameStart() { - return nameStart; - } - -} diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/PointerOperator.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/PointerOperator.java index 2392d3e0aab..89d705e403d 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/PointerOperator.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/PointerOperator.java @@ -12,8 +12,6 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.dom; -import org.eclipse.cdt.internal.core.parser.Name; - /** * @author jcamelon * @@ -89,12 +87,12 @@ public class PointerOperator { // This is not a complete name, it is something like A::B::, i.e. ends with :: - private Name nameSpecifier = null; + private String nameSpecifier = null; /** * @return Class name specifier for pointers to members */ - public Name getNameSpecifier() { + public String getNameSpecifier() { return nameSpecifier; } @@ -102,7 +100,7 @@ public class PointerOperator { * Sets the class name specifier for pointers to members. * @param name The name specifier to set */ - public void setNameSpecifier(Name name) { + public void setNameSpecifier(String name) { this.nameSpecifier = name; } } diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/SimpleDeclaration.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/SimpleDeclaration.java index 8174523bff4..cda769596e3 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/SimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/SimpleDeclaration.java @@ -10,6 +10,7 @@ public class SimpleDeclaration extends Declaration implements DeclSpecifier.ICon private AccessSpecifier accessSpecifier = null; private DeclSpecifier declSpec = null; private boolean isFunctionDefinition = false; + private int nameOffset; public SimpleDeclaration(IScope owner ) @@ -84,4 +85,20 @@ public class SimpleDeclaration extends Declaration implements DeclSpecifier.ICon public void setFunctionDefinition(boolean b) { isFunctionDefinition = b; } + /** + * @return + */ + public int getNameOffset() + { + return nameOffset; + } + + /** + * @param i + */ + public void setNameOffset(int i) + { + nameOffset = i; + } + } diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TemplateDeclaration.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TemplateDeclaration.java index b03eb12e77a..df6abb87342 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TemplateDeclaration.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TemplateDeclaration.java @@ -16,9 +16,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.internal.core.parser.Token; - /** * @author jcamelon * @@ -27,15 +24,14 @@ public class TemplateDeclaration extends Declaration implements IScope, IAccessa private final boolean exported; private AccessSpecifier visibility = null; - private IToken firstToken, lastToken; + private List declarations = new ArrayList(); private TemplateParameterList templateParms = null; - public TemplateDeclaration( IScope ownerScope, IToken exported ) + public TemplateDeclaration( IScope ownerScope, boolean exported ) { super( ownerScope ); - this.firstToken = exported; - this.exported = exported.getType() == IToken.t_export ? true : false; + this.exported = exported; } /* (non-Javadoc) @@ -73,34 +69,19 @@ public class TemplateDeclaration extends Declaration implements IScope, IAccessa templateParms = list; } - /** - * @return - */ - public IToken getFirstToken() { - return firstToken; - } /** - * @return + * @param token */ - public IToken getLastToken() { - return lastToken; + public void setFirstOffset(int startingOffset) { + setStartingOffset( startingOffset ); } /** * @param token */ - public void setFirstToken(Token token) { - firstToken = token; - setStartingOffset( getFirstToken().getOffset() ); - } - - /** - * @param token - */ - public void setLastToken(IToken token) { - lastToken = token; - setTotalLength( getLastToken().getOffset() + getLastToken().getLength() - getStartingOffset() ); + public void setLastOffset(int lastOffset) { + setTotalLength( lastOffset - getStartingOffset() ); } /** diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TemplateParameter.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TemplateParameter.java index d73cba6c2ba..d6fe7fa1b6d 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TemplateParameter.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TemplateParameter.java @@ -12,7 +12,6 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.dom; -import org.eclipse.cdt.internal.core.parser.Name; /** @@ -34,8 +33,8 @@ public class TemplateParameter extends Declaration implements ITemplateParameter this.kind = kind; } - private Name name = null; - private Name typeId = null; + private String name = null; + private String typeId = null; /** @@ -48,14 +47,14 @@ public class TemplateParameter extends Declaration implements ITemplateParameter /** * @return Name */ - public Name getName() { + public String getName() { return name; } /** * @return Name */ - public Name getTypeId() { + public String getTypeId() { return typeId; } @@ -63,7 +62,7 @@ public class TemplateParameter extends Declaration implements ITemplateParameter * Sets the name. * @param name The name to set */ - public void setName(Name name) { + public void setName(String name) { this.name = name; } @@ -71,7 +70,7 @@ public class TemplateParameter extends Declaration implements ITemplateParameter * Sets the typeId. * @param typeId The typeId to set */ - public void setTypeId(Name typeId) { + public void setTypeId(String typeId) { this.typeId = typeId; } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java index fe7c7a977ea..2f3ef9ce995 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java @@ -16,11 +16,11 @@ package org.eclipse.cdt.internal.core.search.indexing; */ import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.IParserCallback; import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; +import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; import org.eclipse.cdt.core.parser.ast.IASTClassReference; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; @@ -33,10 +33,12 @@ import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; import org.eclipse.cdt.core.parser.ast.IASTMacro; import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; +import org.eclipse.cdt.core.parser.ast.IASTPointerToFunction; +import org.eclipse.cdt.core.parser.ast.IASTPointerToMethod; import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypedef; +import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTVariable; @@ -48,7 +50,7 @@ import org.eclipse.cdt.internal.core.index.IDocument; * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ -public class SourceIndexerRequestor implements IParserCallback,ISourceElementRequestor, IIndexConstants { +public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexConstants { SourceIndexer indexer; IDocument document; @@ -122,7 +124,7 @@ public class SourceIndexerRequestor implements IParserCallback,ISourceElementReq /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedef(org.eclipse.cdt.core.parser.ast.IASTTypedef) */ - public void acceptTypedef(IASTTypedef typedef) { + public void acceptTypedef(IASTTypedefDeclaration typedef) { // TODO Auto-generated method stub //System.out.println("acceptTypedef"); } @@ -1050,6 +1052,30 @@ public class SourceIndexerRequestor implements IParserCallback,ISourceElementReq // TODO Auto-generated method stub } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptAbstractTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration) + */ + public void acceptAbstractTypeSpecDeclaration(IASTAbstractTypeSpecifierDeclaration abstractDeclaration) + { + // TODO Auto-generated method stub + + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptPointerToFunction(org.eclipse.cdt.core.parser.ast.IASTPointerToFunction) + */ + public void acceptPointerToFunction(IASTPointerToFunction function) + { + // TODO Auto-generated method stub + + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptPointerToMethod(org.eclipse.cdt.core.parser.ast.IASTPointerToMethod) + */ + public void acceptPointerToMethod(IASTPointerToMethod method) + { + // TODO Auto-generated method stub + + } //TODO: Get rid of these IParserCallbacks once the parser cleans up diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java index 0f20a1f8d73..4fdd70a0cd2 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java @@ -55,7 +55,6 @@ import org.eclipse.cdt.internal.core.dom.TemplateDeclaration; import org.eclipse.cdt.internal.core.dom.TemplateParameter; import org.eclipse.cdt.internal.core.dom.TranslationUnit; import org.eclipse.cdt.internal.core.dom.TypeSpecifier; -import org.eclipse.cdt.internal.core.parser.Name; import org.eclipse.cdt.internal.core.parser.ScannerInfo; import org.eclipse.core.resources.IProject; @@ -341,12 +340,12 @@ public class CModelBuilder { } // set enumeration position if(enumSpecifier.getName() != null ){ - element.setIdPos(enumSpecifier.getName().getStartOffset(), enumSpecifier.getName().length()); + element.setIdPos(enumSpecifier.getStartingOffset(), enumSpecifier.getName().length()); }else { - element.setIdPos(enumSpecifier.getStartToken().getOffset(), enumSpecifier.getStartToken().getLength()); + element.setIdPos(enumSpecifier.getStartingOffset(), enumSpecifier.getStartImage().length()); } element.setPos(enumSpecifier.getStartingOffset(), enumSpecifier.getTotalLength()); - element.setTypeName(enumSpecifier.getStartToken().getImage()); + element.setTypeName(enumSpecifier.getStartImage()); // set the element lines element.setLines(enumSpecifier.getTopLine(), enumSpecifier.getBottomLine()); @@ -359,7 +358,7 @@ public class CModelBuilder { // add to parent enum.addChild(element); // set enumerator position - element.setIdPos(enumDef.getName().getStartOffset(), enumDef.getName().length()); + element.setIdPos(enumDef.getStartingOffset(), enumDef.getName().length()); element.setPos(enumDef.getStartingOffset(), enumDef.getTotalLength()); // set the element lines element.setLines(enumDef.getTopLine(), enumDef.getBottomLine()); @@ -411,12 +410,12 @@ public class CModelBuilder { if( classSpecifier.getName() != null ) { type = simpleDeclaration.getDeclSpecifier().getTypeName(); - element.setIdPos( classSpecifier.getName().getStartOffset(), classSpecifier.getName().length() ); + element.setIdPos( classSpecifier.getNameOffset(), classSpecifier.getName().length() ); } else { - type = classSpecifier.getClassKeyToken().getImage(); - element.setIdPos(classSpecifier.getClassKeyToken().getOffset(), classSpecifier.getClassKeyToken().getLength()); + type = classSpecifier.getClassKeyImage(); + element.setIdPos(classSpecifier.getStartingOffset(), classSpecifier.getClassKeyImage().length()); } element.setTypeName( type ); @@ -433,7 +432,7 @@ public class CModelBuilder { protected TypeDef createTypeDef(Parent parent, Declarator declarator, SimpleDeclaration simpleDeclaration){ // create the element - Name domName = getDOMName(declarator); + String domName = getDOMName(declarator); if (domName == null) { // Something is wrong, skip this element return null; @@ -450,7 +449,7 @@ public class CModelBuilder { parent.addChild((CElement)element); // set positions - element.setIdPos(domName.getStartOffset(), domName.length()); + element.setIdPos(declarator.getNameOffset(), domName.length()); element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength()); // set the element lines element.setLines(simpleDeclaration.getTopLine(), simpleDeclaration.getBottomLine()); @@ -461,7 +460,7 @@ public class CModelBuilder { protected VariableDeclaration createVariableSpecification(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator, boolean isTemplate) { - Name domName = getDOMName(declarator); + String domName = getDOMName(declarator); if (domName == null) { // TODO : improve errorhandling // When parsing syntactically incorrect code, we might @@ -516,7 +515,7 @@ public class CModelBuilder { parent.addChild( element ); // set position - element.setIdPos( domName.getStartOffset(), domName.length() ); + element.setIdPos( declarator.getNameOffset(), domName.length() ); if(!isTemplate){ // set element position element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength()); @@ -530,7 +529,7 @@ public class CModelBuilder { protected FunctionDeclaration createFunctionSpecification(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator, boolean isTemplate) { - Name domName = getDOMName(declarator); + String domName = getDOMName(declarator); if (domName == null) { // Something is wrong, skip this element return null; @@ -614,7 +613,7 @@ public class CModelBuilder { parent.addChild( element ); // hook up the offsets - element.setIdPos( domName.getStartOffset(), domName.length() ); + element.setIdPos( declarator.getNameOffset(), domName.length() ); if(!isTemplate){ // set the element position element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength()); @@ -986,7 +985,7 @@ public class CModelBuilder { while (d.hasNext()) { Declarator decl = (Declarator) d.next(); - Name oldKRparamName = getDOMName(decl); + String oldKRparamName = getDOMName(decl); String oldKRparamType = getType(declKR, decl); if ( (oldKRparamType != null) @@ -1028,10 +1027,10 @@ public class CModelBuilder { return getParametersString(getParameterTypes(declarator)); } - private Name getDOMName(Declarator declarator) + private String getDOMName(Declarator declarator) { Declarator currentDeclarator = declarator; - Name name = null; + String name = null; if (currentDeclarator != null) { while (currentDeclarator.getDeclarator() != null) { diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index f8d978b9410..cf79b68472f 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,11 @@ +2003-07-17 John Camelon + Removed IParserCallback. + Partially converted DOM to ISourceElementRequestor (requires refactoring of CModelBuilder & StuctureComparator modules in near future). + Completely finished ISourceElementRequestor/IASTFactory work for QuickParse mode. + Added pointer to methods/functions into AST callback structure. + Restructured AST class hierarchy. + Removed the old IParserCallback return Objects from every Parser method. + 2003-07-15 Victor Mozgin Fixed PR 39349 : Scanner fails on long long literals. Fixed PR 39544 : Scanner fails on wide char literals. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java index 8d3dc2d4065..bdd04d936f8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java @@ -40,7 +40,7 @@ public interface IParser { * @throws Backtrack thrown if the Scanner/Stream provided does not yield a valid * expression */ - public IASTExpression expression(Object expression) throws Backtrack; + public IASTExpression expression() throws Backtrack; /** * Is the parser configured for ANSI C or ANSI C++? diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParserCallback.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParserCallback.java deleted file mode 100644 index 31efa291d51..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParserCallback.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001 Rational Software Corp. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - initial implementation - ******************************************************************************/ -package org.eclipse.cdt.core.parser; - - -public interface IParserCallback { - - public void setParser( IParser parser ); - - public Object translationUnitBegin(); - public void translationUnitEnd(Object unit); - - public Object inclusionBegin(String includeFile, int nameBeginOffset, int inclusionBeginOffset, boolean local); - public void inclusionEnd(Object inclusion); - public Object macro(String macroName, int macroNameOffset, int macroBeginOffset, int macroEndOffset); - - public Object simpleDeclarationBegin(Object Container, IToken firstToken); - public void simpleDeclSpecifier(Object Container, IToken specifier); - public void simpleDeclSpecifierName( Object declaration ); - public void simpleDeclSpecifierType( Object declaration, Object type ); - public void simpleDeclarationEnd(Object declaration, IToken lastToken); - - public Object parameterDeclarationBegin( Object Container ); - public void parameterDeclarationEnd( Object declaration ); - - public void nameBegin(IToken firstToken); - public void nameEnd(IToken lastToken); - - public Object declaratorBegin(Object container); - public void declaratorId(Object declarator); - public void declaratorAbort( Object declarator ); - public void declaratorPureVirtual( Object declarator ); - public void declaratorCVModifier( Object declarator, IToken modifier ); - public void declaratorThrowsException( Object declarator ); - public void declaratorThrowExceptionName( Object declarator ); - public void declaratorEnd(Object declarator); - - public Object arrayDeclaratorBegin( Object declarator ); - public void arrayDeclaratorEnd( Object arrayQualifier ); - - public Object pointerOperatorBegin( Object container ); - public void pointerOperatorType( Object ptrOperator, IToken type ); - public void pointerOperatorName( Object ptrOperator ); - public void pointerOperatorCVModifier( Object ptrOperator, IToken modifier ); - public void pointerOperatorAbort( Object ptrOperator ); - public void pointerOperatorEnd( Object ptrOperator ); - - public Object argumentsBegin( Object declarator ); - public void argumentsEnd(Object parameterDeclarationClause); - - public Object oldKRParametersBegin( Object parameterDeclarationClause ); - public void oldKRParametersEnd(Object oldKRParameterDeclarationClause); - - public Object functionBodyBegin(Object declaration); - public void functionBodyEnd(Object functionBody); - - public Object classSpecifierBegin(Object container, IToken classKey); - public void classSpecifierName(Object classSpecifier); - public void classSpecifierAbort( Object classSpecifier ); - public void classMemberVisibility( Object classSpecifier, IToken visibility ); - public void classSpecifierEnd(Object classSpecifier, IToken closingBrace ); - - public Object baseSpecifierBegin( Object containingClassSpec ); - public void baseSpecifierName( Object baseSpecifier ); - public void baseSpecifierVisibility( Object baseSpecifier, IToken visibility ); - public void baseSpecifierVirtual( Object baseSpecifier, boolean virtual ); - public void baseSpecifierEnd( Object baseSpecifier ); - - public Object expressionBegin( Object container ); - public void expressionOperator(Object expression, IToken operator); - public void expressionTerminal(Object expression, IToken terminal); - public void expressionName( Object expression ); - public void expressionAbort( Object expression ); - public void expressionEnd(Object expression ); - - public Object elaboratedTypeSpecifierBegin( Object container, IToken classKey ); - public void elaboratedTypeSpecifierName( Object elab ); - public void elaboratedTypeSpecifierEnd( Object elab ); - - public Object namespaceDefinitionBegin( Object container, IToken namespace ); - public void namespaceDefinitionId( Object namespace ); - public void namespaceDefinitionAbort( Object namespace ); - public void namespaceDefinitionEnd( Object namespace, IToken closingBrace ); - - public Object linkageSpecificationBegin( Object container, String literal ); - public void linkageSpecificationEnd( Object linkageSpec ); - - public Object usingDirectiveBegin( Object container ); - public void usingDirectiveNamespaceId( Object directive ); - public void usingDirectiveAbort( Object directive ); - public void usingDirectiveEnd( Object directive ); - - public Object usingDeclarationBegin( Object container ); - public void usingDeclarationMapping( Object declaration, boolean isTypeName ); - public void usingDeclarationAbort( Object declaration ); - public void usingDeclarationEnd( Object declaration ); - - public Object enumSpecifierBegin( Object container, IToken enumKey ); - public void enumSpecifierId( Object enumSpec ); - public void enumSpecifierAbort( Object enumSpec ); - public void enumSpecifierEnd( Object enumSpec, IToken closingBrace ); - - public Object enumeratorBegin( Object enumSpec ); - public void enumeratorId( Object enumDefn ); - public void enumeratorEnd( Object enumDefn, IToken lastToken ); - - public void asmDefinition( Object container, String assemblyCode ); - - public Object constructorChainBegin( Object declarator ); - public void constructorChainAbort( Object ctor ); - public void constructorChainEnd( Object ctor ); - - public Object constructorChainElementBegin( Object ctor ); - public void constructorChainElementId( Object element ); - public void constructorChainElementEnd( Object element ); - - public Object explicitInstantiationBegin( Object container); - public void explicitInstantiationEnd( Object instantiation ); - - public Object explicitSpecializationBegin( Object container ); - public void explicitSpecializationEnd( Object instantiation ); - - public Object templateDeclarationBegin( Object container, IToken firstToken ); - public void templateDeclarationAbort( Object templateDecl ); - public void templateDeclarationEnd( Object templateDecl, IToken lastToken ); - - public Object templateParameterListBegin( Object declaration ); - public void templateParameterListEnd( Object parameterList ); - - public Object templateTypeParameterBegin( Object templDecl, IToken kind ); - public void templateTypeParameterName( Object typeParm ); - public void templateTypeParameterAbort( Object typeParm ); - public void templateTypeParameterInitialTypeId( Object typeParm ); - public void templateTypeParameterEnd( Object typeParm ); - - public Object startBitfield(Object declarator); - public void endBitfield(Object bitfield); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IQuickParseCallback.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IQuickParseCallback.java new file mode 100644 index 00000000000..fd045654ee4 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IQuickParseCallback.java @@ -0,0 +1,27 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.core.parser; +import java.util.Iterator; +import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; +/** + * @author jcamelon + * + */ +public interface IQuickParseCallback extends ISourceElementRequestor +{ + public abstract Iterator getInclusions(); + public abstract Iterator getMacros(); + /** + * @return + */ + public abstract IASTCompilationUnit getCompilationUnit(); + public abstract Iterator iterateOffsetableElements(); +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java index a448f7ac3af..de62858de70 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java @@ -27,7 +27,6 @@ public interface IScanner { public void setCppNature( boolean value ); public void setMode(ParserMode mode); - public void setCallback(IParserCallback c); public int getCount(); public int getDepth(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementRequestor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementRequestor.java index 6af5b3dbfd6..dbd6c88ae66 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementRequestor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementRequestor.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.core.parser; import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; +import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; import org.eclipse.cdt.core.parser.ast.IASTClassReference; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; @@ -23,10 +24,12 @@ import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; import org.eclipse.cdt.core.parser.ast.IASTMacro; import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; +import org.eclipse.cdt.core.parser.ast.IASTPointerToFunction; +import org.eclipse.cdt.core.parser.ast.IASTPointerToMethod; import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypedef; +import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTVariable; @@ -45,8 +48,9 @@ public interface ISourceElementRequestor { public void acceptUsingDirective( IASTUsingDirective usageDirective ); public void acceptUsingDeclaration( IASTUsingDeclaration usageDeclaration ); public void acceptASMDefinition( IASTASMDefinition asmDefinition ); - public void acceptTypedef( IASTTypedef typedef ); + public void acceptTypedef( IASTTypedefDeclaration typedef ); public void acceptEnumerationSpecifier( IASTEnumerationSpecifier enumeration ); + public void acceptAbstractTypeSpecDeclaration( IASTAbstractTypeSpecifierDeclaration abstractDeclaration ); public void enterFunctionBody( IASTFunction function ); public void exitFunctionBody( IASTFunction function ); @@ -79,4 +83,14 @@ public interface ISourceElementRequestor { public void exitCompilationUnit( IASTCompilationUnit compilationUnit ); public void acceptElaboratedTypeSpecifier(IASTElaboratedTypeSpecifier elaboratedTypeSpec); + + /** + * @param function + */ + public void acceptPointerToFunction(IASTPointerToFunction function); + + /** + * @param method + */ + public void acceptPointerToMethod(IASTPointerToMethod method); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITokenDuple.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITokenDuple.java index cecf731fdcc..67fafbe40f9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITokenDuple.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITokenDuple.java @@ -28,4 +28,5 @@ public interface ITokenDuple { public abstract Iterator iterator(); public abstract String toString(); public abstract boolean isIdentifier(); + public abstract int length(); } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java index 1be296ae9c9..fc0a0c2b685 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java @@ -19,6 +19,7 @@ import org.eclipse.cdt.internal.core.parser.LineOffsetReconciler; import org.eclipse.cdt.internal.core.parser.NullSourceElementRequestor; import org.eclipse.cdt.internal.core.parser.Parser; import org.eclipse.cdt.internal.core.parser.Preprocessor; +import org.eclipse.cdt.internal.core.parser.QuickParseCallback; import org.eclipse.cdt.internal.core.parser.Scanner; import org.eclipse.cdt.internal.core.parser.TranslationOptions; import org.eclipse.cdt.internal.core.parser.TranslationResult; @@ -42,15 +43,15 @@ public class ParserFactory { return new FullParseASTFactory(); } - public static IParser createParser( IScanner scanner, IParserCallback callback, ParserMode mode ) + public static IParser createParser( IScanner scanner, ISourceElementRequestor callback, ParserMode mode ) { return createParser(scanner, callback, mode, null, null); } - public static IParser createParser( IScanner scanner, IParserCallback callback, ParserMode mode, IProblemReporter problemReporter, ITranslationResult unitResult ) + public static IParser createParser( IScanner scanner, ISourceElementRequestor callback, ParserMode mode, IProblemReporter problemReporter, ITranslationResult unitResult ) { ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode ); - IParserCallback ourCallback = (( callback == null) ? new NullSourceElementRequestor() : callback ); + ISourceElementRequestor ourCallback = (( callback == null) ? new NullSourceElementRequestor() : callback ); return new Parser( scanner, ourCallback, ourMode, problemReporter, unitResult ); } @@ -101,4 +102,9 @@ public class ParserFactory { { return new TranslationResult( fileName /* tu */ ); } + + public static IQuickParseCallback createQuickParseCallback() + { + return new QuickParseCallback(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserMode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserMode.java index ed5e6668753..4e2c1418f86 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserMode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserMode.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.core.parser; * @author jcamelon * */ -public class ParserMode { +public class ParserMode extends Enum { // follow inclusions, parse function/method bodies public static final ParserMode COMPLETE_PARSE = new ParserMode( 1 ); @@ -25,10 +25,9 @@ public class ParserMode { // do not follow inclusions, do not parse function/method bodies public static final ParserMode QUICK_PARSE = new ParserMode( 3 ); - private ParserMode( int value ) + protected ParserMode( int value ) { - this.value = value; + super( value ); } - - private final int value; + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTNotImplementedException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTNotImplementedException.java index 5094f68e0bd..e17b3bc3796 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTNotImplementedException.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTNotImplementedException.java @@ -14,6 +14,6 @@ package org.eclipse.cdt.core.parser.ast; * @author jcamelon * */ -public class ASTNotImplementedException +public class ASTNotImplementedException extends Exception { } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTPointerOperator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTPointerOperator.java index 5dde84d2a37..3fccbcc92e7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTPointerOperator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTPointerOperator.java @@ -22,9 +22,6 @@ public class ASTPointerOperator extends Enum public static final ASTPointerOperator POINTER = new ASTPointerOperator( 1 ); public static final ASTPointerOperator CONST_POINTER = new ASTPointerOperator( 2 ); public static final ASTPointerOperator VOLATILE_POINTER = new ASTPointerOperator( 3 ); - public static final ASTPointerOperator POINTER_TO_FUNCTION = new ASTPointerOperator( 4 ); - public static final ASTPointerOperator CONST_POINTER_TO_FUNCTION = new ASTPointerOperator( 5 ); - public static final ASTPointerOperator VOLATILE_POINTER_TO_FUNCTION = new ASTPointerOperator( 6 ); /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTAbstractDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTAbstractDeclaration.java index ba3a94fecfe..196658951fb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTAbstractDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTAbstractDeclaration.java @@ -16,12 +16,10 @@ import java.util.Iterator; * @author jcamelon * */ -public interface IASTAbstractDeclaration +public interface IASTAbstractDeclaration extends IASTTypeSpecifierOwner { public boolean isConst(); - public IASTTypeSpecifier getTypeSpecifier(); - public Iterator getPointerOperators(); public Iterator getArrayModifiers(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTAbstractTypeSpecifierDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTAbstractTypeSpecifierDeclaration.java new file mode 100644 index 00000000000..23eb9fac48f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTAbstractTypeSpecifierDeclaration.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.core.parser.ast; + +/** + * @author jcamelon + * + */ +public interface IASTAbstractTypeSpecifierDeclaration + extends IASTDeclaration, IASTTypeSpecifierOwner, IASTTemplatedDeclaration, IASTOffsetableElement +{ +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTBaseSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTBaseSpecifier.java index 36d555b87c2..07a4b80438a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTBaseSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTBaseSpecifier.java @@ -19,6 +19,7 @@ public interface IASTBaseSpecifier { public ASTAccessVisibility getAccess(); public boolean isVirtual(); - public IASTClassSpecifier getParent(); + public String getParentClassName(); + public IASTClassSpecifier getParentClassSpecifier() throws ASTNotImplementedException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java index fbdad5e8e2c..98443eba84e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java @@ -18,7 +18,7 @@ import org.eclipse.cdt.core.parser.Enum; * @author jcamelon * */ -public interface IASTClassSpecifier extends IASTTypeSpecifier, IASTScope, IASTOffsetableNamedElement, IASTTemplatedDeclaration, IASTQualifiedNameElement { +public interface IASTClassSpecifier extends IASTTypeSpecifier, IASTScope, IASTScopedElement, IASTOffsetableNamedElement, IASTQualifiedNameElement { public class ClassNameType extends Enum { @@ -30,7 +30,7 @@ public interface IASTClassSpecifier extends IASTTypeSpecifier, IASTScope, IASTOf super( t ); } } - + public ClassNameType getClassNameType(); public ASTClassKind getClassKind(); @@ -38,5 +38,6 @@ public interface IASTClassSpecifier extends IASTTypeSpecifier, IASTScope, IASTOf public Iterator getBaseClauses(); public ASTAccessVisibility getCurrentVisibilityMode(); + public void setCurrentVisibility( ASTAccessVisibility visibility ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTDeclaration.java index 569b6b1da11..9c4d57c55ba 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTDeclaration.java @@ -14,8 +14,7 @@ package org.eclipse.cdt.core.parser.ast; * @author jcamelon * */ -public interface IASTDeclaration { +public interface IASTDeclaration extends IASTScopedElement { - IASTScope getOwnerScope(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTElaboratedTypeSpecifier.java index a13ad9ad15c..a3fc5db4b09 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTElaboratedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTElaboratedTypeSpecifier.java @@ -17,7 +17,6 @@ package org.eclipse.cdt.core.parser.ast; */ public interface IASTElaboratedTypeSpecifier extends IASTTypeSpecifier, IASTOffsetableElement { - public String getTypeName(); + public String getName(); public ASTClassKind getClassKind(); - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java index fb0cccf9f26..1c1f36f06a8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java @@ -36,12 +36,12 @@ public interface IASTFactory int nameOffset); public IASTUsingDirective createUsingDirective( IASTScope scope, - ITokenDuple duple) + ITokenDuple duple, int startingOffset, int endingOffset) throws Backtrack; public IASTUsingDeclaration createUsingDeclaration( IASTScope scope, boolean isTypeName, - ITokenDuple name); + ITokenDuple name, int startingOffset, int endingOffset); public IASTASMDefinition createASMDefinition( IASTScope scope, String assembly, @@ -55,7 +55,7 @@ public interface IASTFactory public IASTCompilationUnit createCompilationUnit(); public IASTLinkageSpecification createLinkageSpecification( IASTScope scope, - String spec); + String spec, int startingOffset); public IASTClassSpecifier createClassSpecifier( IASTScope scope, String name, @@ -118,7 +118,7 @@ public interface IASTFactory ITokenDuple duple, IASTExpression expressionList); public IASTSimpleTypeSpecifier createSimpleTypeSpecifier( - IASTSimpleTypeSpecifier.SimpleType kind, + IASTSimpleTypeSpecifier.Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, @@ -172,12 +172,47 @@ public interface IASTFactory public IASTTemplateDeclaration createTemplateDeclaration( IASTScope scope, List templateParameters, boolean exported, int startingOffset ); - public IASTTemplateParameter createTemplateParameter( IASTTemplateParameter.ParameterKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List parms ); + public IASTTemplateParameter createTemplateParameter( IASTTemplateParameter.ParamKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List parms ); public IASTTemplateInstantiation createTemplateInstantiation(IASTScope scope, int startingOffset); public IASTTemplateSpecialization createTemplateSpecialization(IASTScope scope, int startingOffset); - public IASTTypedef createTypedef( IASTScope scope, String name, IASTAbstractDeclaration mapping, int startingOffset, int nameOffset ); + public IASTTypedefDeclaration createTypedef( IASTScope scope, String name, IASTAbstractDeclaration mapping, int startingOffset, int nameOffset ); + public IASTAbstractTypeSpecifierDeclaration createTypeSpecDeclaration( IASTScope scope, IASTTypeSpecifier typeSpecifier, IASTTemplate template, int startingOffset, int endingOffset); + + public IASTPointerToFunction createPointerToFunction( + IASTScope scope, + String name, + List parameters, + IASTAbstractDeclaration returnType, + IASTExceptionSpecification exception, + boolean isInline, + boolean isFriend, + boolean isStatic, + int startOffset, + int nameOffset, + IASTTemplate ownerTemplate, ASTPointerOperator pointerOperator); + + public IASTPointerToMethod createPointerToMethod( + IASTScope scope, + String name, + List parameters, + IASTAbstractDeclaration returnType, + IASTExceptionSpecification exception, + boolean isInline, + boolean isFriend, + boolean isStatic, + int startOffset, + int nameOffset, + IASTTemplate ownerTemplate, + boolean isConst, + boolean isVolatile, + boolean isConstructor, + boolean isDestructor, + boolean isVirtual, + boolean isExplicit, + boolean isPureVirtual, + ASTAccessVisibility visibility, ASTPointerOperator pointerOperator); } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTLinkageSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTLinkageSpecification.java index 72eb090ffa2..85ff5471c26 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTLinkageSpecification.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTLinkageSpecification.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.core.parser.ast; * @author jcamelon * */ -public interface IASTLinkageSpecification extends IASTScope, IASTDeclaration { +public interface IASTLinkageSpecification extends IASTScope, IASTDeclaration, IASTOffsetableElement { public String getLinkageString(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableNamedElement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableNamedElement.java index 6b554da5595..ec51ae2d69b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableNamedElement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableNamedElement.java @@ -19,5 +19,5 @@ public interface IASTOffsetableNamedElement extends IASTOffsetableElement { public String getName(); public int getElementNameOffset(); - public void setNameOffset( int o ); + public void setElementNameOffset( int o ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTPointerOperatorOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTPointerOperatorOwner.java new file mode 100644 index 00000000000..aefe8bf6df5 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTPointerOperatorOwner.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.core.parser.ast; + +/** + * @author jcamelon + * + */ +public interface IASTPointerOperatorOwner +{ + public ASTPointerOperator getPointerOperator(); +} diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/IExpressionOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTPointerToFunction.java similarity index 58% rename from core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/IExpressionOwner.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTPointerToFunction.java index 39f1f6e58db..bb6e16e2302 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/IExpressionOwner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTPointerToFunction.java @@ -6,13 +6,14 @@ * http://www.eclipse.org/legal/cpl-v05.html * * Contributors: - * Rational Software - Initial API and implementation - ***********************************************************************/ + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.core.parser.ast; -package org.eclipse.cdt.internal.core.dom; - -public interface IExpressionOwner { - - public Expression getExpression(); - public void setExpression( Expression exp ); +/** + * @author jcamelon + * + */ +public interface IASTPointerToFunction extends IASTFunction, IASTPointerOperatorOwner +{ } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTPointerToMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTPointerToMethod.java new file mode 100644 index 00000000000..bd529205aa2 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTPointerToMethod.java @@ -0,0 +1,19 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.core.parser.ast; + +/** + * @author jcamelon + * + */ +public interface IASTPointerToMethod extends IASTMethod, IASTPointerOperatorOwner +{ +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScopedElement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScopedElement.java new file mode 100644 index 00000000000..8fa153c6805 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScopedElement.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.core.parser.ast; + +/** + * @author jcamelon + * + */ +public interface IASTScopedElement +{ + IASTScope getOwnerScope(); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTSimpleTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTSimpleTypeSpecifier.java index 17c999a9319..496a620045c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTSimpleTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTSimpleTypeSpecifier.java @@ -18,23 +18,23 @@ import org.eclipse.cdt.core.parser.Enum; */ public interface IASTSimpleTypeSpecifier extends IASTTypeSpecifier { - public static class SimpleType extends Enum + public static class Type extends Enum { - public static final SimpleType UNSPECIFIED = new SimpleType( 1 ); - public static final SimpleType CHAR = new SimpleType( 1 ); - public static final SimpleType WCHAR_T = new SimpleType( 2 ); - public static final SimpleType BOOL = new SimpleType( 3 ); - public static final SimpleType INT = new SimpleType( 4 ); - public static final SimpleType FLOAT = new SimpleType( 5 ); - public static final SimpleType DOUBLE = new SimpleType( 6 ); - public static final SimpleType VOID = new SimpleType( 7 ); - public static final SimpleType TYPENAME = new SimpleType( 8 ); - public static final SimpleType TEMPLATE = new SimpleType( 9 ); + public static final Type UNSPECIFIED = new Type( 1 ); + public static final Type CHAR = new Type( 1 ); + public static final Type WCHAR_T = new Type( 2 ); + public static final Type BOOL = new Type( 3 ); + public static final Type INT = new Type( 4 ); + public static final Type FLOAT = new Type( 5 ); + public static final Type DOUBLE = new Type( 6 ); + public static final Type VOID = new Type( 7 ); + public static final Type CLASS_OR_TYPENAME = new Type( 8 ); + public static final Type TEMPLATE = new Type( 9 ); /** * @param enumValue */ - protected SimpleType(int enumValue) + protected Type(int enumValue) { super(enumValue); } @@ -42,7 +42,7 @@ public interface IASTSimpleTypeSpecifier extends IASTTypeSpecifier } - public SimpleType getType(); + public Type getType(); public String getTypename(); public boolean isLong(); public boolean isShort(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameter.java index e6766c3fe1f..893356d2965 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameter.java @@ -18,24 +18,25 @@ import org.eclipse.cdt.core.parser.Enum; */ public interface IASTTemplateParameter extends IASTTemplateParameterList { - public class ParameterKind extends Enum + public class ParamKind extends Enum { - public static final ParameterKind CLASS = new ParameterKind( 1 ); - public static final ParameterKind TYPENAME = new ParameterKind( 2 ); - public static final ParameterKind TEMPLATE_LIST = new ParameterKind( 3 ); - public static final ParameterKind PARAMETER = new ParameterKind( 4 ); + public static final ParamKind CLASS = new ParamKind( 1 ); + public static final ParamKind TYPENAME = new ParamKind( 2 ); + public static final ParamKind TEMPLATE_LIST = new ParamKind( 3 ); + public static final ParamKind PARAMETER = new ParamKind( 4 ); /** * @param enumValue */ - protected ParameterKind(int enumValue) + protected ParamKind(int enumValue) { super(enumValue); } } - public ParameterKind getTemplateParameterKind(); + public ParamKind getTemplateParameterKind(); public String getIdentifier(); public String getDefaultValueIdExpression(); + public IASTParameterDeclaration getParameterDeclaration(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypeSpecifierOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypeSpecifierOwner.java new file mode 100644 index 00000000000..491cd35260b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypeSpecifierOwner.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.core.parser.ast; + +/** + * @author jcamelon + * + */ +public interface IASTTypeSpecifierOwner +{ + public IASTTypeSpecifier getTypeSpecifier(); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypedefDeclaration.java similarity index 88% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypedef.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypedefDeclaration.java index d921b095b92..63d03ce4f5c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypedefDeclaration.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.core.parser.ast; * @author jcamelon * */ -public interface IASTTypedef extends IASTDeclaration, IASTOffsetableNamedElement { +public interface IASTTypedefDeclaration extends IASTDeclaration, IASTOffsetableNamedElement { public String getName(); public IASTAbstractDeclaration getAbstractDeclarator(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDeclaration.java index c33146a44ab..45632bdd1a0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDeclaration.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.core.parser.ast; * @author jcamelon * */ -public interface IASTUsingDeclaration extends IASTDeclaration { +public interface IASTUsingDeclaration extends IASTDeclaration, IASTOffsetableElement { public boolean isTypename(); public String usingTypeName(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDirective.java index afe1639e623..ed2f8a75d35 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDirective.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDirective.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.core.parser.ast; * @author jcamelon * */ -public interface IASTUsingDirective extends IASTDeclaration { +public interface IASTUsingDirective extends IASTDeclaration, IASTOffsetableElement { public String getNamespaceName(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java index 4c4d4feb736..ea0a0353cc5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java @@ -13,20 +13,26 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; + +import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; +import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; +import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTDeclaration; import org.eclipse.cdt.core.parser.ast.IASTFactory; import org.eclipse.cdt.core.parser.ast.IASTField; import org.eclipse.cdt.core.parser.ast.IASTFunction; import org.eclipse.cdt.core.parser.ast.IASTMethod; +import org.eclipse.cdt.core.parser.ast.IASTPointerToFunction; +import org.eclipse.cdt.core.parser.ast.IASTPointerToMethod; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTTemplate; import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypedef; +import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.SimpleType; +import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type; /** * @author jcamelon * @@ -34,8 +40,8 @@ import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.SimpleType; public class DeclarationWrapper implements IDeclaratorOwner { private ITokenDuple name; - private SimpleType simpleType = - IASTSimpleTypeSpecifier.SimpleType.UNSPECIFIED; + private Type simpleType = + IASTSimpleTypeSpecifier.Type.UNSPECIFIED; private boolean isSigned; private boolean isLong; private boolean isShort; @@ -308,24 +314,40 @@ public class DeclarationWrapper implements IDeclaratorOwner { boolean isWithinClass = (getScope() instanceof IASTClassSpecifier); boolean isFunction = declarator.isFunction(); + boolean hasInnerDeclarator = ( declarator.getOwnedDeclarator() != null ); + + if( hasInnerDeclarator ) + { + ITokenDuple innerPointerName = declarator.getOwnedDeclarator().getPointerOperatorNameDuple(); + if( innerPointerName != null && innerPointerName.getLastToken().getType() == IToken.tCOLONCOLON ) + return createP2MethodASTNode(declarator); + else + return createP2FunctionASTNode( declarator ); + } + if (isTypedef()) return createTypedef(declarator); - if (isWithinClass && isFunction) - return createMethodASTNode(declarator); - else if (isWithinClass && !isFunction) - return createFieldASTNode(declarator); - else if ((!isWithinClass) && isFunction) - return createFunctionASTNode(declarator); - else if (!isFunction && !isWithinClass) - return createVariableASTNode(declarator); - else - throw new Error("WTF"); //return IProblem? + + if (isWithinClass ) + { + if( isFunction) + return createMethodASTNode(declarator); + else + return createFieldASTNode(declarator); + } + else + { + if (isFunction) + return createFunctionASTNode(declarator); + else + return createVariableASTNode(declarator); + } } /** * @param declarator * @return */ - private IASTTypedef createTypedef(Declarator declarator) + private IASTTypedefDeclaration createTypedef(Declarator declarator) { return astFactory.createTypedef( scope, @@ -466,6 +488,68 @@ public class DeclarationWrapper implements IDeclaratorOwner getStartingOffset(), declarator.getNameEndOffset()); } + + /** + * @param declarator + * @return + */ + private IASTPointerToMethod createP2MethodASTNode(Declarator declarator) + { + + return astFactory + .createPointerToMethod( + scope, + declarator.getOwnedDeclarator().getPointerOperatorNameDuple().toString().trim() + + declarator.getOwnedDeclarator().getName().trim(), + createParameterList(declarator.getParameters()), + astFactory.createAbstractDeclaration( + constt, + getTypeSpecifier(), + declarator.getPtrOps(), + declarator.getArrayModifiers()), + declarator.getExceptionSpecification(), + inline, + friend, + staticc, + startingOffset, + declarator.getNameStartOffset(), + templateDeclaration, + declarator.isConst(), + declarator.isVolatile(), + false, + // isConstructor + false, // isDestructor + virtual, + explicit, + declarator.isPureVirtual(), + ((scope instanceof IASTClassSpecifier )? ((IASTClassSpecifier)scope).getCurrentVisibilityMode() : ASTAccessVisibility.PUBLIC ) + , (ASTPointerOperator)declarator.getOwnedDeclarator().getPtrOps().get(0)); + } + /** + * @param declarator + * @return + */ + private IASTPointerToFunction createP2FunctionASTNode(Declarator declarator) + { + return astFactory.createPointerToFunction( + scope, + declarator.getOwnedDeclarator().getName(), + createParameterList(declarator.getParameters()), + astFactory.createAbstractDeclaration( + constt, + getTypeSpecifier(), + declarator.getPtrOps(), + declarator.getArrayModifiers()), + declarator.getExceptionSpecification(), + inline, + friend, + staticc, + startingOffset, + declarator.getNameStartOffset(), + templateDeclaration, (ASTPointerOperator)declarator.getOwnedDeclarator().getPtrOps().get(0)); + } + + /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IDeclaratorOwner#getDeclarationWrapper() */ @@ -532,14 +616,14 @@ public class DeclarationWrapper implements IDeclaratorOwner /** * @return */ - public SimpleType getSimpleType() + public Type getSimpleType() { return simpleType; } /** * @param type */ - public void setSimpleType(SimpleType type) + public void setSimpleType(Type type) { simpleType = type; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declarator.java index e00494d04ee..88b89909402 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declarator.java @@ -29,7 +29,9 @@ import org.eclipse.cdt.internal.core.parser.ast.IASTArrayModifier; */ public class Declarator implements IParameterCollection, IDeclaratorOwner { - private boolean isFunction; + private ITokenDuple pointerOperatorNameDuple; + private ITokenDuple namedDuple; + private boolean isFunction; private boolean hasFunctionBody; private IASTExpression constructorExpression; private boolean pureVirtual = false; @@ -172,6 +174,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner setName( duple.toString() ); setNameStartOffset( duple.getFirstToken().getOffset()); setNameEndOffset( duple.getLastToken().getEndOffset()); + namedDuple = duple; } /** @@ -365,4 +368,28 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner } + /** + * @return + */ + public ITokenDuple getNamedDuple() + { + return namedDuple; + } + + /** + * @param nameDuple + */ + public void setPointerOperatorName(ITokenDuple nameDuple) + { + pointerOperatorNameDuple = nameDuple; + } + + /** + * @return + */ + public ITokenDuple getPointerOperatorNameDuple() + { + return pointerOperatorNameDuple; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclaratorDuple.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclaratorDuple.java index d6cf2552595..b4467fea017 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclaratorDuple.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclaratorDuple.java @@ -15,26 +15,16 @@ package org.eclipse.cdt.internal.core.parser; */ public class DeclaratorDuple { - public DeclaratorDuple( Object o, Declarator d ) + public DeclaratorDuple( Declarator d ) { - object = o; declarator = d; } - private final Declarator declarator; - private final Object object; + private final Declarator declarator; /** * @return */ public Declarator getDeclarator() { return declarator; } - - /** - * @return - */ - public Object getObject() { - return object; - } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Name.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Name.java deleted file mode 100644 index 9d061ae41cc..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Name.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.eclipse.cdt.internal.core.parser; - -import org.eclipse.cdt.core.parser.IToken; - - - -/** - * @author dschaefe - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class Name { - - private IToken nameStart, nameEnd; - - public Name(IToken nameStart) { - this.nameStart = nameStart; - } - - public Name(IToken nameStart, IToken nameEnd) { - this( nameStart ); - setEnd( nameEnd ); - } - - - public void setEnd(IToken nameEnd) { - this.nameEnd = nameEnd; - } - - public int getStartOffset() - { - return nameStart.getOffset(); - } - - public int getEndOffset() - { - return nameEnd.getOffset(); - } - - public String toString() { - IToken t = nameStart; - StringBuffer buffer = new StringBuffer(); - buffer.append( t.getImage() ); - if( t.getType() == IToken.t_operator ) - buffer.append( " " ); - - while (t != nameEnd) { - t = t.getNext(); - - buffer.append( t.getImage() ); - if (t.getType() == IToken.t_operator) buffer.append( " " ); - } - - return buffer.toString(); - } - - public int length() - { - return getEndOffset() - getStartOffset() + nameEnd.getLength(); - } - /** - * @return - */ - public IToken getNameStart() { - return nameStart; - } - - public static String tokensToString( Token first, Token last ) - { - Name n = new Name( first, last ); - return n.toString(); - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullSourceElementRequestor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullSourceElementRequestor.java index 9f19de49a19..022c16f7cf1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullSourceElementRequestor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullSourceElementRequestor.java @@ -1,11 +1,9 @@ package org.eclipse.cdt.internal.core.parser; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.IParserCallback; import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; +import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; import org.eclipse.cdt.core.parser.ast.IASTClassReference; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; @@ -18,870 +16,308 @@ import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; import org.eclipse.cdt.core.parser.ast.IASTMacro; import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; +import org.eclipse.cdt.core.parser.ast.IASTPointerToFunction; +import org.eclipse.cdt.core.parser.ast.IASTPointerToMethod; import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypedef; +import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTVariable; -public class NullSourceElementRequestor implements ISourceElementRequestor, IParserCallback { - -// Here goes ISourceElementRequestor interface +public class NullSourceElementRequestor implements ISourceElementRequestor +{ /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem) */ - public void acceptProblem(IProblem problem) { + public void acceptProblem(IProblem problem) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMacro(org.eclipse.cdt.core.parser.ast.IASTMacro) */ - public void acceptMacro(IASTMacro macro) { + public void acceptMacro(IASTMacro macro) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariable(org.eclipse.cdt.core.parser.ast.IASTVariable) */ - public void acceptVariable(IASTVariable variable) { + public void acceptVariable(IASTVariable variable) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionDeclaration(org.eclipse.cdt.core.parser.ast.IASTFunction) */ - public void acceptFunctionDeclaration(IASTFunction function) { + public void acceptFunctionDeclaration(IASTFunction function) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsageDirective(org.eclipse.cdt.core.parser.ast.IASTUsageDirective) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDirective(org.eclipse.cdt.core.parser.ast.IASTUsingDirective) */ - public void acceptUsingDirective(IASTUsingDirective usageDirective) { + public void acceptUsingDirective(IASTUsingDirective usageDirective) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsageDeclaration(org.eclipse.cdt.core.parser.ast.IASTUsageDeclaration) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration) */ - public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration) { + public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptASMDefinition(org.eclipse.cdt.core.parser.ast.IASTASMDefinition) */ - public void acceptASMDefinition(IASTASMDefinition asmDefinition) { + public void acceptASMDefinition(IASTASMDefinition asmDefinition) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedef(org.eclipse.cdt.core.parser.ast.IASTTypedef) */ - public void acceptTypedef(IASTTypedef typedef) { + public void acceptTypedef(IASTTypedefDeclaration typedef) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier) + */ + public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) */ - public void enterFunctionBody(IASTFunction function) { + public void enterFunctionBody(IASTFunction function) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) */ - public void exitFunctionBody(IASTFunction function) { + public void exitFunctionBody(IASTFunction function) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) */ - public void enterCompilationUnit(IASTCompilationUnit compilationUnit) { + public void enterCompilationUnit(IASTCompilationUnit compilationUnit) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) */ - public void enterInclusion(IASTInclusion inclusion) { + public void enterInclusion(IASTInclusion inclusion) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) */ - public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) { + public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecification) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) */ - public void enterClassSpecifier(IASTClassSpecifier classSpecification) { + public void enterClassSpecifier(IASTClassSpecifier classSpecification) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) */ - public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) { + public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) */ - public void enterTemplateDeclaration(IASTTemplateDeclaration declaration) { + public void enterTemplateDeclaration(IASTTemplateDeclaration declaration) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization) */ - public void enterTemplateSpecialization(IASTTemplateSpecialization specialization) { + public void enterTemplateSpecialization(IASTTemplateSpecialization specialization) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation) */ - public void enterTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) { + public void enterTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodDeclaration(org.eclipse.cdt.core.parser.ast.IASTMethod) */ - public void acceptMethodDeclaration(IASTMethod method) { + public void acceptMethodDeclaration(IASTMethod method) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) */ - public void enterMethodBody(IASTMethod method) { + public void enterMethodBody(IASTMethod method) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) */ - public void exitMethodBody(IASTMethod method) { + public void exitMethodBody(IASTMethod method) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptField(org.eclipse.cdt.core.parser.ast.IASTField) */ - public void acceptField(IASTField field) { + public void acceptField(IASTField field) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptClassReference(org.eclipse.cdt.core.parser.ast.IASTClassReference) + */ + public void acceptClassReference(IASTClassReference reference) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) */ - public void exitTemplateDeclaration(IASTTemplateDeclaration declaration) { + public void exitTemplateDeclaration(IASTTemplateDeclaration declaration) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization) */ - public void exitTemplateSpecialization(IASTTemplateSpecialization specialization) { + public void exitTemplateSpecialization(IASTTemplateSpecialization specialization) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation) */ - public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) { + public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) */ - public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) { + public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecification) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) */ - public void exitClassSpecifier(IASTClassSpecifier classSpecification) { + public void exitClassSpecifier(IASTClassSpecifier classSpecification) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) */ - public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) { + public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) */ - public void exitInclusion(IASTInclusion inclusion) { + public void exitInclusion(IASTInclusion inclusion) + { + // TODO Auto-generated method stub + } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) */ - public void exitCompilationUnit(IASTCompilationUnit compilationUnit) { + public void exitCompilationUnit(IASTCompilationUnit compilationUnit) + { + // TODO Auto-generated method stub + } - -// Here goes IParserCallback interface - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#translationUnitBegin() - */ - public Object translationUnitBegin() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#translationUnitEnd(java.lang.Object) - */ - public void translationUnitEnd(Object unit) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#inclusionBegin(java.lang.String, int) - */ - public Object inclusionBegin(String includeFile, int offset, int inclusionBeginOffset, boolean local) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#inclusionEnd() - */ - public void inclusionEnd(Object inclusion) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#macro(java.lang.String, int) - */ - public Object macro(String macroName, int offset, int macroBeginOffset, int macroEndOffset) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclarationBegin(java.lang.Object) - */ - public Object simpleDeclarationBegin(Object Container, IToken firstToken) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifier(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public void simpleDeclSpecifier(Object Container, IToken specifier) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierName(java.lang.Object) - */ - public void simpleDeclSpecifierName(Object declaration) { - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclarationEnd(java.lang.Object) - */ - public void simpleDeclarationEnd(Object declaration, IToken lastToken) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#parameterDeclarationBegin(java.lang.Object) - */ - public Object parameterDeclarationBegin(Object Container) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#parameterDeclarationEnd(java.lang.Object) - */ - public void parameterDeclarationEnd(Object declaration) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#nameBegin(org.eclipse.cdt.internal.core.parser.Token) - */ - public void nameBegin(IToken firstToken) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#nameEnd(org.eclipse.cdt.internal.core.parser.Token) - */ - public void nameEnd(IToken lastToken) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorBegin(java.lang.Object) - */ - public Object declaratorBegin(Object container) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorId(java.lang.Object) - */ - public void declaratorId(Object declarator) { - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorAbort(java.lang.Object, java.lang.Object) - */ - public void declaratorAbort(Object declarator) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorCVModifier(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public void declaratorCVModifier(Object declarator, IToken modifier) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorThrowExceptionName(java.lang.Object) - */ - public void declaratorThrowExceptionName(Object exceptionSpec) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorEnd(java.lang.Object) - */ - public void declaratorEnd(Object declarator) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#arrayDeclaratorBegin(java.lang.Object) - */ - public Object arrayDeclaratorBegin(Object declarator) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#arrayDeclaratorEnd(java.lang.Object) - */ - public void arrayDeclaratorEnd(Object arrayQualifier) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#pointerOperatorBegin(java.lang.Object) - */ - public Object pointerOperatorBegin(Object container) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#pointerOperatorType(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public void pointerOperatorType(Object ptrOperator, IToken type) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#pointerOperatorName(java.lang.Object) - */ - public void pointerOperatorName(Object ptrOperator) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#pointerOperatorCVModifier(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public void pointerOperatorCVModifier(Object ptrOperator, IToken modifier) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#pointerOperatorEnd(java.lang.Object) - */ - public void pointerOperatorEnd(Object ptrOperator) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#argumentsBegin(java.lang.Object) - */ - public Object argumentsBegin(Object declarator) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#argumentsEnd(java.lang.Object) - */ - public void argumentsEnd(Object parameterDeclarationClause) { - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#oldKRParametersBegin() - */ - public Object oldKRParametersBegin( Object parameterDeclarationClause ) { - return null; - } - - /** - * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#oldKRParametersEnd() - */ - public void oldKRParametersEnd(Object oldKRParameterDeclarationClause) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#functionBodyBegin(java.lang.Object) - */ - public Object functionBodyBegin(Object declaration) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#functionBodyEnd(java.lang.Object) - */ - public void functionBodyEnd(Object functionBody) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierBegin(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public Object classSpecifierBegin(Object container, IToken classKey) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierName(java.lang.Object) - */ - public void classSpecifierName(Object classSpecifier) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierAbort(java.lang.Object) - */ - public void classSpecifierAbort(Object classSpecifier) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#classMemberVisibility(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public void classMemberVisibility(Object classSpecifier, IToken visibility) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierEnd(java.lang.Object) - */ - public void classSpecifierEnd(Object classSpecifier, IToken closingBrace) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#baseSpecifierBegin(java.lang.Object) - */ - public Object baseSpecifierBegin(Object containingClassSpec) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#baseSpecifierName(java.lang.Object) - */ - public void baseSpecifierName(Object baseSpecifier) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#baseSpecifierVisibility(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public void baseSpecifierVisibility(Object baseSpecifier, IToken visibility) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#baseSpecifierVirtual(java.lang.Object, boolean) - */ - public void baseSpecifierVirtual(Object baseSpecifier, boolean virtual) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#baseSpecifierEnd(java.lang.Object) - */ - public void baseSpecifierEnd(Object baseSpecifier) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionBegin(java.lang.Object) - */ - public Object expressionBegin(Object container) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionOperator(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public void expressionOperator(Object expression, IToken operator) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionTerminal(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public void expressionTerminal(Object expression, IToken terminal) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionAbort(java.lang.Object) - */ - public void expressionAbort(Object expression) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionEnd(java.lang.Object) - */ - public void expressionEnd(Object expression) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierBegin(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public Object elaboratedTypeSpecifierBegin(Object container, IToken classKey) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierName(java.lang.Object) - */ - public void elaboratedTypeSpecifierName(Object elab) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierEnd(java.lang.Object) - */ - public void elaboratedTypeSpecifierEnd(Object elab) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorThrowsException(java.lang.Object) - */ - public void declaratorThrowsException(Object declarator) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#namespaceDeclarationBegin(java.lang.Object) - */ - public Object namespaceDefinitionBegin(Object container, IToken namespace) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#namespaceDeclarationId(java.lang.Object) - */ - public void namespaceDefinitionId(Object namespace) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#namespaceDeclarationAbort(java.lang.Object) - */ - public void namespaceDefinitionAbort(Object namespace) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#namespaceDeclarationEnd(java.lang.Object) - */ - public void namespaceDefinitionEnd(Object namespace, IToken closingBrace) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#linkageSpecificationBegin(java.lang.Object, java.lang.String) - */ - public Object linkageSpecificationBegin(Object container, String literal) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#linkageSpecificationEnd(java.lang.Object) - */ - public void linkageSpecificationEnd(Object linkageSpec) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDirectiveBegin(java.lang.Object) - */ - public Object usingDirectiveBegin(Object container) { - - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDirectiveNamespaceId(java.lang.Object) - */ - public void usingDirectiveNamespaceId(Object container) { - - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDirectiveEnd(java.lang.Object) - */ - public void usingDirectiveEnd(Object directive) { - - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDeclarationBegin(java.lang.Object) - */ - public Object usingDeclarationBegin(Object container) { - - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDeclarationMapping(java.lang.Object) - */ - public void usingDeclarationMapping(Object container, boolean isTypename) { - - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDeclarationEnd(java.lang.Object) - */ - public void usingDeclarationEnd(Object directive) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDirectiveAbort(java.lang.Object) - */ - public void usingDirectiveAbort(Object directive) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#usingDeclarationAbort(java.lang.Object) - */ - public void usingDeclarationAbort(Object declaration) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumSpecifierBegin(java.lang.Object) - */ - public Object enumSpecifierBegin(Object container, IToken enumKey) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumSpecifierId(java.lang.Object) - */ - public void enumSpecifierId(Object enumSpec) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumSpecifierAbort(java.lang.Object) - */ - public void enumSpecifierAbort(Object enumSpec) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumSpecifierEnd(java.lang.Object) - */ - public void enumSpecifierEnd(Object enumSpec, IToken closingBrace) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumDefinitionBegin(java.lang.Object) - */ - public Object enumeratorBegin(Object enumSpec) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumDefinitionId(java.lang.Object) - */ - public void enumeratorId(Object enumDefn) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumDefinitionEnd(java.lang.Object) - */ - public void enumeratorEnd(Object enumDefn, IToken lastToken) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#asmDefinition(java.lang.String) - */ - public void asmDefinition(Object container, String assemblyCode) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainBegin(java.lang.Object) - */ - public Object constructorChainBegin(Object declarator) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainAbort(java.lang.Object) - */ - public void constructorChainAbort(Object ctor) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainEnd(java.lang.Object) - */ - public void constructorChainEnd(Object ctor) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementBegin(java.lang.Object) - */ - public Object constructorChainElementBegin(Object ctor) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementEnd(java.lang.Object) - */ - public void constructorChainElementEnd(Object element) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainId(java.lang.Object) - */ - public void constructorChainElementId(Object ctor) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementExpressionListElementBegin(java.lang.Object) - */ - public Object constructorChainElementExpressionListElementBegin(Object element) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementExpressionListElementEnd(java.lang.Object) - */ - public void constructorChainElementExpressionListElementEnd(Object expression) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitInstantiationBegin(java.lang.Object) - */ - public Object explicitInstantiationBegin(Object container) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitInstantiationEnd(java.lang.Object) - */ - public void explicitInstantiationEnd(Object instantiation) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitSpecializationBegin(java.lang.Object) - */ - public Object explicitSpecializationBegin(Object container) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitSpecializationEnd(java.lang.Object) - */ - public void explicitSpecializationEnd(Object instantiation) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorPureVirtual(java.lang.Object) - */ - public void declaratorPureVirtual(Object declarator) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationBegin(java.lang.Object, boolean) - */ - public Object templateDeclarationBegin(Object container, IToken exported) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationAbort(java.lang.Object) - */ - public void templateDeclarationAbort(Object templateDecl) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationEnd(java.lang.Object) - */ - public void templateDeclarationEnd(Object templateDecl, IToken lastToken) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterBegin(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token) - */ - public Object templateTypeParameterBegin(Object templDecl, IToken kind) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterName(java.lang.Object) - */ - public void templateTypeParameterName(Object typeParm) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeInitialTypeId(java.lang.Object) - */ - public void templateTypeParameterInitialTypeId(Object typeParm) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterEnd(java.lang.Object) - */ - public void templateTypeParameterEnd(Object typeParm) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterAbort(java.lang.Object) - */ - public void templateTypeParameterAbort(Object typeParm) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#pointerOperatorAbort(java.lang.Object) - */ - public void pointerOperatorAbort(Object ptrOperator) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateParameterListBegin(java.lang.Object) - */ - public Object templateParameterListBegin(Object declaration) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateParameterListEnd(java.lang.Object) - */ - public void templateParameterListEnd(Object parameterList) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#setParser(org.eclipse.cdt.internal.core.parser.IParser) - */ - public void setParser(IParser parser) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#expressionName(java.lang.Object) - */ - public void expressionName(Object expression) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#startBitfield(java.lang.Object) - */ - public Object startBitfield(Object declarator) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#endBitfield(java.lang.Object) - */ - public void endBitfield(Object bitfield) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierType(java.lang.Object, java.lang.Object) - */ - public void simpleDeclSpecifierType(Object declaration, Object type) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier) - */ - public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptClassReference(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier, int) - */ - public void acceptClassReference(IASTClassReference reference) { - // TODO Auto-generated method stub - - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier) */ @@ -890,4 +326,31 @@ public class NullSourceElementRequestor implements ISourceElementRequestor, IPar // TODO Auto-generated method stub } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptAbstractTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration) + */ + public void acceptAbstractTypeSpecDeclaration(IASTAbstractTypeSpecifierDeclaration abstractDeclaration) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptPointerToFunction(org.eclipse.cdt.core.parser.ast.IASTPointerToFunction) + */ + public void acceptPointerToFunction(IASTPointerToFunction function) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptPointerToMethod(org.eclipse.cdt.core.parser.ast.IASTPointerToMethod) + */ + public void acceptPointerToMethod(IASTPointerToMethod method) + { + // TODO Auto-generated method stub + + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParameterCollection.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParameterCollection.java new file mode 100644 index 00000000000..9c34ad8a44f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParameterCollection.java @@ -0,0 +1,37 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.internal.core.parser; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author jcamelon + * + */ +public class ParameterCollection implements IParameterCollection +{ + private List list = new ArrayList(); + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.IParameterCollection#getParameters() + */ + public List getParameters() + { + return list; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.IParameterCollection#addParameter(org.eclipse.cdt.internal.core.parser.DeclarationWrapper) + */ + public void addParameter(DeclarationWrapper param) + { + list.add( param ); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java index 27287d04030..10ecd8c594e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java @@ -16,7 +16,6 @@ import java.util.List; import org.eclipse.cdt.core.parser.Backtrack; import org.eclipse.cdt.core.parser.EndOfFile; import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.IParserCallback; import org.eclipse.cdt.core.parser.IProblemReporter; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.ISourceElementRequestor; @@ -44,12 +43,16 @@ import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement; +import org.eclipse.cdt.core.parser.ast.IASTPointerToFunction; +import org.eclipse.cdt.core.parser.ast.IASTPointerToMethod; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTTemplate; +import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; +import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypedef; +import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTVariable; @@ -57,8 +60,6 @@ import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType; import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; import org.eclipse.cdt.internal.core.model.Util; import org.eclipse.cdt.internal.core.parser.ast.IASTArrayModifier; - - /** * This is our first implementation of the IParser interface, serving as a parser for * ANSI C and C++. @@ -74,8 +75,7 @@ public class Parser implements IParser // sentinel initial value for offsets private int firstErrorOffset = DEFAULT_OFFSET; // offset where the first parse error occurred - private IParserCallback callback; - // the parser callback that was registered with us + private ParserMode mode = ParserMode.COMPLETE_PARSE; // are we doing the high-level parse, or an in depth parse? private boolean parsePassed = true; // did the parse pass? @@ -83,9 +83,8 @@ public class Parser implements IParser private ISourceElementRequestor requestor = null; // new callback mechanism private IASTFactory astFactory = null; // ast factory - private IProblemReporter problemReporter = null; - private ITranslationResult unitResult = null; + private ITranslationResult unitResult = null; /** * This is the single entry point for setting parsePassed to * false, and also making note what token offset we failed upon. @@ -106,25 +105,25 @@ public class Parser implements IParser * @param c IParserCallback instance that will receive callbacks as we parse * @param quick Are we asking for a high level parse or not? */ - public Parser(IScanner s, IParserCallback c, ParserMode m, IProblemReporter problemReporter, ITranslationResult unitResult) + public Parser( + IScanner scanner, + ISourceElementRequestor callback, + ParserMode mode, + IProblemReporter problemReporter, + ITranslationResult unitResult) { - callback = c; - scanner = s; + this.scanner = scanner; this.problemReporter = problemReporter; this.unitResult = unitResult; - if (c instanceof ISourceElementRequestor) - setRequestor((ISourceElementRequestor)c); - mode = m; - astFactory = ParserFactory.createASTFactory(m); - scanner.setMode(m); - scanner.setCallback(c); + if (callback instanceof ISourceElementRequestor) + setRequestor((ISourceElementRequestor)callback); + this.mode = mode; + astFactory = ParserFactory.createASTFactory(mode); + scanner.setMode(mode); scanner.setASTFactory(astFactory); } - - // counter that keeps track of the number of times Parser.parse() is called + // counter that keeps track of the number of times Parser.parse() is called private static int parseCount = 0; - - /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IParser#parse() */ @@ -145,11 +144,10 @@ public class Parser implements IParser + (parsePassed ? "" : " - parse failure")); return parsePassed; } - - public void onParseEnd() { + public void onParseEnd() + { scanner.onParseEnd(); } - /** * This is the top-level entry point into the ANSI C++ grammar. * @@ -157,23 +155,9 @@ public class Parser implements IParser */ protected void translationUnit() { - try - { - callback.setParser(this); - } - catch (Exception e) - { - } - Object translationUnit = null; - try - { - translationUnit = callback.translationUnitBegin(); - } - catch (Exception e) - { - } IASTCompilationUnit compilationUnit = astFactory.createCompilationUnit(); + requestor.enterCompilationUnit(compilationUnit); IToken lastBacktrack = null; IToken checkToken; @@ -182,7 +166,7 @@ public class Parser implements IParser try { checkToken = LA(1); - declaration(translationUnit, compilationUnit, null); + declaration(compilationUnit, null); if (LA(1) == checkToken) errorHandling(); } @@ -219,13 +203,6 @@ public class Parser implements IParser // we've done the best we can } } - try - { - callback.translationUnitEnd(translationUnit); - } - catch (Exception e) - { - } requestor.exitCompilationUnit(compilationUnit); } /** @@ -268,83 +245,35 @@ public class Parser implements IParser * @param container Callback object representing the scope these definitions fall into. * @throws Backtrack request for a backtrack */ - protected void usingClause(Object container, IASTScope scope) + protected void usingClause(IASTScope scope) throws Backtrack { IToken firstToken = consume(IToken.t_using); if (LT(1) == IToken.t_namespace) { - Object directive = null; - try - { - directive = callback.usingDirectiveBegin(container); - } - catch (Exception e) - { - } // using-directive consume(IToken.t_namespace); // optional :: and nested classes handled in name TokenDuple duple = null; if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON) - { duple = name(); - try - { - callback.usingDirectiveNamespaceId(directive); - } - catch (Exception e) - { - } - } else - { - try - { - callback.usingDirectiveAbort(directive); - } - catch (Exception e) - { - } throw backtrack; - } if (LT(1) == IToken.tSEMI) { - consume(IToken.tSEMI); - try - { - callback.usingDirectiveEnd(directive); - } - catch (Exception e) - { - } + IToken last = consume(IToken.tSEMI); IASTUsingDirective astUD = - astFactory.createUsingDirective(scope, duple); + astFactory.createUsingDirective(scope, duple, firstToken.getOffset(), last.getEndOffset()); requestor.acceptUsingDirective(astUD); return; } else { - try - { - callback.usingDirectiveAbort(directive); - } - catch (Exception e) - { - } throw backtrack; } } else { - Object usingDeclaration = null; - try - { - usingDeclaration = callback.usingDeclarationBegin(container); - } - catch (Exception e) - { - } boolean typeName = false; if (LT(1) == IToken.t_typename) { @@ -356,50 +285,20 @@ public class Parser implements IParser { // optional :: and nested classes handled in name name = name(); - try - { - callback.usingDeclarationMapping( - usingDeclaration, - typeName); - } - catch (Exception e) - { - } } else { - try - { - callback.usingDeclarationAbort(usingDeclaration); - } - catch (Exception e) - { - } throw backtrack; } if (LT(1) == IToken.tSEMI) { - consume(IToken.tSEMI); - try - { - callback.usingDeclarationEnd(usingDeclaration); - } - catch (Exception e) - { - } + IToken last = consume(IToken.tSEMI); IASTUsingDeclaration declaration = - astFactory.createUsingDeclaration(scope, typeName, name); + astFactory.createUsingDeclaration(scope, typeName, name, firstToken.getOffset(), last.getEndOffset()); requestor.acceptUsingDeclaration(declaration); } else { - try - { - callback.usingDeclarationAbort(usingDeclaration); - } - catch (Exception e) - { - } throw backtrack; } } @@ -414,27 +313,19 @@ public class Parser implements IParser * @param container Callback object representing the scope these definitions fall into. * @throws Backtrack request for a backtrack */ - protected void linkageSpecification(Object container, IASTScope scope) + protected void linkageSpecification(IASTScope scope) throws Backtrack { - consume(IToken.t_extern); + IToken firstToken = consume(IToken.t_extern); if (LT(1) != IToken.tSTRING) throw backtrack; - Object linkageSpec = null; IToken spec = consume(IToken.tSTRING); - try - { - linkageSpec = - callback.linkageSpecificationBegin(container, spec.getImage()); - } - catch (Exception e) - { - } + if (LT(1) == IToken.tLBRACE) { consume(IToken.tLBRACE); IASTLinkageSpecification linkage = - astFactory.createLinkageSpecification(scope, spec.getImage()); + astFactory.createLinkageSpecification(scope, spec.getImage(), firstToken.getOffset()); requestor.enterLinkageSpecification(linkage); linkageDeclarationLoop : while (LT(1) != IToken.tRBRACE) { @@ -447,7 +338,7 @@ public class Parser implements IParser default : try { - declaration(linkageSpec, linkage, null); + declaration(linkage, null); } catch (Backtrack bt) { @@ -460,29 +351,16 @@ public class Parser implements IParser errorHandling(); } // consume the } - consume(); - try - { - callback.linkageSpecificationEnd(linkageSpec); - } - catch (Exception e) - { - } + IToken lastToken = consume(); + linkage.setEndingOffset(lastToken.getEndOffset()); requestor.exitLinkageSpecification(linkage); } else // single declaration { IASTLinkageSpecification linkage = - astFactory.createLinkageSpecification(scope, spec.getImage()); + astFactory.createLinkageSpecification(scope, spec.getImage(), firstToken.getOffset()); requestor.enterLinkageSpecification(linkage); - declaration(linkageSpec, linkage, null); - try - { - callback.linkageSpecificationEnd(linkageSpec); - } - catch (Exception e) - { - } + declaration(linkage, null); requestor.exitLinkageSpecification(linkage); } } @@ -498,11 +376,14 @@ public class Parser implements IParser * @param container Callback object representing the scope these definitions fall into. * @throws Backtrack request for a backtrack */ - protected void templateDeclaration(Object container, IASTScope scope) throws Backtrack + protected void templateDeclaration(IASTScope scope) + throws Backtrack { IToken firstToken = null; + boolean exported = false; if (LT(1) == IToken.t_export) { + exported = true; firstToken = consume(IToken.t_export); consume(IToken.t_template); } @@ -511,28 +392,15 @@ public class Parser implements IParser if (LT(1) != IToken.tLT) { // explicit-instantiation - Object instantiation = null; - try - { - instantiation = callback.explicitInstantiationBegin(container); - } - catch (Exception e) - { - } - - IASTTemplateInstantiation templateInstantiation = astFactory.createTemplateInstantiation( scope, firstToken.getOffset() ); - requestor.enterTemplateExplicitInstantiation( templateInstantiation ); - declaration(instantiation, scope, templateInstantiation ); - templateInstantiation.setEndingOffset( lastToken.getEndOffset() ); - requestor.exitTemplateExplicitInstantiation( templateInstantiation ); - - try - { - callback.explicitInstantiationEnd(instantiation); - } - catch (Exception e) - { - } + IASTTemplateInstantiation templateInstantiation = + astFactory.createTemplateInstantiation( + scope, + firstToken.getOffset()); + requestor.enterTemplateExplicitInstantiation(templateInstantiation); + declaration(scope, templateInstantiation); + templateInstantiation.setEndingOffset(lastToken.getEndOffset()); + requestor.exitTemplateExplicitInstantiation(templateInstantiation); + return; } else @@ -542,65 +410,33 @@ public class Parser implements IParser { consume(IToken.tGT); // explicit-specialization - Object specialization = null; - try - { - specialization = - callback.explicitSpecializationBegin(container); - } - catch (Exception e) - { - } - IASTTemplateSpecialization templateSpecialization = astFactory.createTemplateSpecialization( scope, firstToken.getOffset() ); - requestor.enterTemplateSpecialization( templateSpecialization ); - declaration(specialization, scope, templateSpecialization ); - templateSpecialization.setEndingOffset( lastToken.getEndOffset() ); - requestor.exitTemplateSpecialization( templateSpecialization ); - - try - { - callback.explicitSpecializationEnd(specialization); - } - catch (Exception e) - { - } + IASTTemplateSpecialization templateSpecialization = + astFactory.createTemplateSpecialization( + scope, + firstToken.getOffset()); + requestor.enterTemplateSpecialization(templateSpecialization); + declaration(scope, templateSpecialization); + templateSpecialization.setEndingOffset( + lastToken.getEndOffset()); + requestor.exitTemplateSpecialization(templateSpecialization); return; } } - Object templateDeclaration = null; + try { - try - { - templateDeclaration = - callback.templateDeclarationBegin(container, firstToken); - } - catch (Exception e) - { - } - templateParameterList(templateDeclaration); + List parms = templateParameterList(); consume(IToken.tGT); - declaration(templateDeclaration, scope, null); - try - { - callback.templateDeclarationEnd( - templateDeclaration, - (Token)lastToken); - } - catch (Exception e) - { - } + IASTTemplateDeclaration templateDecl = astFactory.createTemplateDeclaration( scope, parms, exported, firstToken.getOffset() ); + requestor.enterTemplateDeclaration( templateDecl ); + declaration(scope, templateDecl ); + templateDecl.setEndingOffset( lastToken.getEndOffset() ); + requestor.exitTemplateDeclaration( templateDecl ); + } catch (Backtrack bt) { - try - { - callback.templateDeclarationAbort(templateDeclaration); - } - catch (Exception e) - { - } throw bt; } } @@ -629,134 +465,82 @@ public class Parser implements IParser * @param templateDeclaration Callback's templateDeclaration which serves as a scope to this list. * @throws Backtrack request for a backtrack */ - protected void templateParameterList(Object templateDeclaration) + protected List templateParameterList() throws Backtrack { // if we have gotten this far then we have a true template-declaration // iterate through the template parameter list - Object templateParameterList = null; - try - { - templateParameterList = - callback.templateParameterListBegin(templateDeclaration); - } - catch (Exception e) - { - } + List returnValue = new ArrayList(); + for (;;) { if (LT(1) == IToken.tGT) - return; + return returnValue; if (LT(1) == IToken.t_class || LT(1) == IToken.t_typename) { - Object currentTemplateParm = null; + IASTTemplateParameter.ParamKind kind = + (consume().getType() == IToken.t_class) + ? IASTTemplateParameter.ParamKind.CLASS + : IASTTemplateParameter.ParamKind.TYPENAME; + + IToken id = null; + ITokenDuple typeId = null; try { - try - { - currentTemplateParm = - callback.templateTypeParameterBegin( - templateParameterList, - consume()); - } - catch (Exception e) - { - } if (LT(1) == IToken.tIDENTIFIER) // optional identifier { - identifier(); - try - { - callback.templateTypeParameterName( - currentTemplateParm); - } - catch (Exception e) - { - } + id = identifier(); + if (LT(1) == IToken.tASSIGN) // optional = type-id { consume(IToken.tASSIGN); - typeId(); // type-id - try - { - callback.templateTypeParameterInitialTypeId( - currentTemplateParm); - } - catch (Exception e) - { - } + typeId = typeId(); // type-id } } - try - { - callback.templateTypeParameterEnd(currentTemplateParm); - } - catch (Exception e) - { - } + } catch (Backtrack bt) { - try - { - callback.templateTypeParameterAbort( - currentTemplateParm); - } - catch (Exception e) - { - } throw bt; } + returnValue.add( + astFactory.createTemplateParameter( + kind, + ( id == null )? "" : id.getImage(), + (typeId == null) ? null : typeId.toString(), + null, + null)); + } else if (LT(1) == IToken.t_template) { IToken kind = consume(IToken.t_template); consume(IToken.tLT); - Object newTemplateParm = null; - try - { - newTemplateParm = - callback.templateTypeParameterBegin( - templateParameterList, - kind); - } - catch (Exception e) - { - } - templateParameterList(newTemplateParm); + + List subResult = templateParameterList(); consume(IToken.tGT); consume(IToken.t_class); + IToken optionalId = null; + ITokenDuple optionalTypeId = null; if (LT(1) == IToken.tIDENTIFIER) // optional identifier { - identifier(); - try - { - callback.templateTypeParameterName(newTemplateParm); - } - catch (Exception e) - { - } + optionalId = identifier(); + if (LT(1) == IToken.tASSIGN) // optional = type-id { consume(IToken.tASSIGN); - typeId(); - try - { - callback.templateTypeParameterInitialTypeId( - newTemplateParm); - } - catch (Exception e) - { - } + optionalTypeId = typeId(); + } } - try - { - callback.templateTypeParameterEnd(newTemplateParm); - } - catch (Exception e) - { - } + + returnValue.add( + astFactory.createTemplateParameter( + IASTTemplateParameter.ParamKind.TEMPLATE_LIST, + ( optionalId == null )? "" : optionalId.getImage(), + ( optionalTypeId == null ) ? "" : optionalTypeId.toString(), + null, + subResult)); } else if (LT(1) == IToken.tCOMMA) { @@ -765,11 +549,30 @@ public class Parser implements IParser } else { - parameterDeclaration(templateParameterList, null); // this should be something real + ParameterCollection c = new ParameterCollection(); + parameterDeclaration(c); + DeclarationWrapper wrapper = + (DeclarationWrapper)c.getParameters().get(0); + Declarator declarator = + (Declarator)wrapper.getDeclarators().next(); + returnValue.add( + astFactory.createTemplateParameter( + IASTTemplateParameter.ParamKind.PARAMETER, + null, + null, + astFactory.createParameterDeclaration( + wrapper.isConst(), + wrapper.getTypeSpecifier(), + declarator.getPtrOps(), + declarator.getArrayModifiers(), + declarator.getName() == null + ? "" + : declarator.getName(), + declarator.getInitializerClause()), + null)); } } } - /** * The most abstract construct within a translationUnit : a declaration. * @@ -793,7 +596,9 @@ public class Parser implements IParser * @param container IParserCallback object which serves as the owner scope for this declaration. * @throws Backtrack request a backtrack */ - protected void declaration(Object container, IASTScope scope, IASTTemplate ownerTemplate) + protected void declaration( + IASTScope scope, + IASTTemplate ownerTemplate) throws Backtrack { switch (LT(1)) @@ -812,43 +617,45 @@ public class Parser implements IParser last.getEndOffset()); // if we made it this far, then we have all we need // do the callback - try - { - callback.asmDefinition(container, assembly); - } - catch (Exception e) - { - } + requestor.acceptASMDefinition(asmDefinition); return; case IToken.t_namespace : - namespaceDefinition(container, scope); + namespaceDefinition(scope); return; case IToken.t_using : - usingClause(container, scope); + usingClause(scope); return; case IToken.t_export : case IToken.t_template : - templateDeclaration(container, scope); + templateDeclaration(scope); return; case IToken.t_extern : if (LT(2) == IToken.tSTRING) { - linkageSpecification(container, scope); + linkageSpecification(scope); return; } default : IToken mark = mark(); try { - simpleDeclaration(container, true, false, scope, ownerTemplate); + simpleDeclaration( + true, + false, + scope, + ownerTemplate); // try it first with the original strategy } catch (Backtrack bt) { // did not work backup(mark); - simpleDeclaration(container, false, false, scope, ownerTemplate); + simpleDeclaration( + false, + false, + scope, + ownerTemplate); // try it again with the second strategy } } @@ -864,31 +671,16 @@ public class Parser implements IParser * @throws Backtrack request a backtrack */ - protected void namespaceDefinition(Object container, IASTScope scope) + protected void namespaceDefinition(IASTScope scope) throws Backtrack { - Object namespace = null; IToken first = consume(IToken.t_namespace); - try - { - namespace = callback.namespaceDefinitionBegin(container, first); - } - catch (Exception e) - { - } + IToken identifier = null; // optional name if (LT(1) == IToken.tIDENTIFIER) - { identifier = identifier(); - try - { - callback.namespaceDefinitionId(namespace); - } - catch (Exception e) - { - } - } + if (LT(1) == IToken.tLBRACE) { consume(); @@ -910,7 +702,7 @@ public class Parser implements IParser default : try { - declaration(namespace, namespaceDefinition, null); + declaration(namespaceDefinition, null); } catch (Backtrack bt) { @@ -924,26 +716,13 @@ public class Parser implements IParser } // consume the } IToken last = consume(IToken.tRBRACE); - try - { - callback.namespaceDefinitionEnd(namespace, (Token)last); - } - catch (Exception e) - { - } + namespaceDefinition.setEndingOffset( last.getOffset() + last.getLength()); requestor.exitNamespaceDefinition(namespaceDefinition); } else { - try - { - callback.namespaceDefinitionAbort(namespace); - } - catch (Exception e) - { - } throw backtrack; } } @@ -966,38 +745,39 @@ public class Parser implements IParser * @throws Backtrack request a backtrack */ protected void simpleDeclaration( - Object container, boolean tryConstructor, boolean forKR, - IASTScope scope, IASTTemplate ownerTemplate) + IASTScope scope, + IASTTemplate ownerTemplate) throws Backtrack { - Object simpleDecl = null; - DeclarationWrapper sdw = new DeclarationWrapper(scope, LA(1).getOffset(), ownerTemplate); - try - { - simpleDecl = callback.simpleDeclarationBegin(container, LA(1)); - } - catch (Exception e) - { - } - declSpecifierSeq(simpleDecl, false, tryConstructor, sdw); - if( sdw.getTypeSpecifier() == null && sdw.getSimpleType() != IASTSimpleTypeSpecifier.SimpleType.UNSPECIFIED ) - sdw.setTypeSpecifier( astFactory.createSimpleTypeSpecifier( sdw.getSimpleType(), sdw.getName(), sdw.isShort(), sdw.isLong(), sdw.isSigned(), sdw.isUnsigned(), sdw.isTypeNamed() ) ); + DeclarationWrapper sdw = + new DeclarationWrapper(scope, LA(1).getOffset(), ownerTemplate); + + declSpecifierSeq(false, tryConstructor, sdw); + if (sdw.getTypeSpecifier() == null ) + sdw.setTypeSpecifier( + astFactory.createSimpleTypeSpecifier( + sdw.getSimpleType(), + sdw.getName(), + sdw.isShort(), + sdw.isLong(), + sdw.isSigned(), + sdw.isUnsigned(), + sdw.isTypeNamed())); - Object declarator = null; - DeclaratorDuple d = null; + DeclaratorDuple d = null; if (LT(1) != IToken.tSEMI) try { - d = initDeclarator(simpleDecl, sdw); - declarator = d.getObject(); + d = initDeclarator(sdw); + while (LT(1) == IToken.tCOMMA) { consume(); try { - d = initDeclarator(simpleDecl, sdw); + d = initDeclarator(sdw); } catch (Backtrack b) { @@ -1009,143 +789,125 @@ public class Parser implements IParser { // allowed to be empty } - - boolean done = false; - boolean hasFunctionBody = false; + boolean done = false; + boolean hasFunctionBody = false; switch (LT(1)) { case IToken.tSEMI : consume(IToken.tSEMI); - done = true; + done = true; break; case IToken.tCOLON : if (forKR) throw backtrack; - ctorInitializer(declarator, d.getDeclarator()); + ctorInitializer(d.getDeclarator()); // Falling through on purpose case IToken.tLBRACE : if (forKR) throw backtrack; - - d.getDeclarator().hasFunctionBody( true ); - hasFunctionBody = true; + d.getDeclarator().hasFunctionBody(true); + hasFunctionBody = true; break; default : throw backtrack; } - List l = sdw.createASTNodes(astFactory); - Iterator i = l.iterator(); - if( hasFunctionBody && l.size() != 1 ) - { - failParse(); - throw backtrack; //TODO Should be an IProblem - } - - if( i.hasNext() ) // no need to do this unless we have a declarator - { - if( ! hasFunctionBody ) - { - - while( i.hasNext() ) - { - IASTDeclaration declaration = (IASTDeclaration)i.next(); - ((IASTOffsetableElement)declaration).setEndingOffset( lastToken.getEndOffset() ); - if( declaration instanceof IASTField ) - requestor.acceptField( (IASTField)declaration ); - else if( declaration instanceof IASTVariable ) - requestor.acceptVariable( (IASTVariable)declaration ); - else if( declaration instanceof IASTMethod ) - requestor.acceptMethodDeclaration( (IASTMethod)declaration ); - else if( declaration instanceof IASTFunction ) - requestor.acceptFunctionDeclaration( (IASTFunction)declaration ); - else if( declaration instanceof IASTTypedef ) - requestor.acceptTypedef( (IASTTypedef)declaration); - else - { - if( hasFunctionBody && l.size() != 1 ) - { - failParse(); - throw backtrack; //TODO Should be an IProblem - } - } - } - } - else - { - IASTDeclaration declaration = (IASTDeclaration)i.next(); - if( declaration instanceof IASTMethod ) - requestor.enterMethodBody( (IASTMethod)declaration ); - else if( declaration instanceof IASTFunction ) - requestor.enterFunctionBody( (IASTFunction)declaration ); - else - { - if( hasFunctionBody && l.size() != 1 ) - { - failParse(); - throw backtrack; //TODO Should be an IProblem - } - } - - Object function = null; - try - { - function = callback.functionBodyBegin(simpleDecl); - } - catch (Exception e) - { - } - handleFunctionBody(d.getDeclarator()); - try - { - callback.functionBodyEnd(function); - } - catch (Exception e) - { - } - - if( declaration instanceof IASTMethod ) - requestor.exitMethodBody( (IASTMethod)declaration ); - else if( declaration instanceof IASTFunction ) - requestor.exitFunctionBody( (IASTFunction)declaration ); - } - } - + if( forKR ) return; - try + List l = sdw.createASTNodes(astFactory); + Iterator i = l.iterator(); + if (hasFunctionBody && l.size() != 1) { - callback.simpleDeclarationEnd(simpleDecl, (Token)lastToken); + failParse(); + throw backtrack; //TODO Should be an IProblem } - catch (Exception e) + if (i.hasNext()) // no need to do this unless we have a declarator { + if (!hasFunctionBody) + { + while (i.hasNext()) + { + IASTDeclaration declaration = (IASTDeclaration)i.next(); + ((IASTOffsetableElement)declaration).setEndingOffset( + lastToken.getEndOffset()); + if (declaration instanceof IASTField) + requestor.acceptField((IASTField)declaration); + else if (declaration instanceof IASTVariable) + requestor.acceptVariable((IASTVariable)declaration); + else if (declaration instanceof IASTMethod) + requestor.acceptMethodDeclaration( + (IASTMethod)declaration); + else if (declaration instanceof IASTFunction) + requestor.acceptFunctionDeclaration( + (IASTFunction)declaration); + else if (declaration instanceof IASTTypedefDeclaration) + requestor.acceptTypedef((IASTTypedefDeclaration)declaration); + else if (declaration instanceof IASTPointerToFunction ) + requestor.acceptPointerToFunction( (IASTPointerToFunction)declaration ); + else if (declaration instanceof IASTPointerToMethod ) + requestor.acceptPointerToMethod( (IASTPointerToMethod)declaration ); + else + { + failParse(); + throw backtrack; //TODO Should be an IProblem + } + } + } + else + { + IASTDeclaration declaration = (IASTDeclaration)i.next(); + if (declaration instanceof IASTMethod) + requestor.enterMethodBody((IASTMethod)declaration); + else if (declaration instanceof IASTFunction) + requestor.enterFunctionBody((IASTFunction)declaration); + else + { + if (hasFunctionBody && l.size() != 1) + { + failParse(); + throw backtrack; //TODO Should be an IProblem + } + } + + handleFunctionBody(d.getDeclarator()); + + if (declaration instanceof IASTMethod) + requestor.exitMethodBody((IASTMethod)declaration); + else if (declaration instanceof IASTFunction) + requestor.exitFunctionBody((IASTFunction)declaration); + } + } + else + requestor.acceptAbstractTypeSpecDeclaration( astFactory.createTypeSpecDeclaration( + sdw.getScope(), sdw.getTypeSpecifier(), ownerTemplate, sdw.getStartingOffset(), lastToken.getEndOffset()) ); + + } + protected void handleFunctionBody(Declarator d) throws Backtrack, EndOfFile + { + if (mode == ParserMode.QUICK_PARSE) + { + // speed up the parser by skiping the body + // simply look for matching brace and return + consume(IToken.tLBRACE); + int depth = 1; + while (depth > 0) + { + switch (consume().getType()) + { + case IToken.tRBRACE : + --depth; + break; + case IToken.tLBRACE : + ++depth; + break; + } + } + } + else + { + functionBody(); } } - - protected void handleFunctionBody(Declarator d) throws Backtrack, EndOfFile { - if (mode == ParserMode.QUICK_PARSE) - { - // speed up the parser by skiping the body - // simply look for matching brace and return - consume(IToken.tLBRACE); - int depth = 1; - while (depth > 0) - { - switch (consume().getType()) - { - case IToken.tRBRACE : - --depth; - break; - case IToken.tLBRACE : - ++depth; - break; - } - } - } - else - { - functionBody(); - } - } /** * This method parses a constructor chain * ctorinitializer: : meminitializerlist @@ -1157,72 +919,32 @@ public class Parser implements IParser * @param declarator IParserCallback object that represents the declarator (constructor) that owns this initializer * @throws Backtrack request a backtrack */ - protected void ctorInitializer(Object declarator, Declarator d) throws Backtrack + protected void ctorInitializer(Declarator d) + throws Backtrack { consume(IToken.tCOLON); - Object constructorChain = null; - try - { - constructorChain = callback.constructorChainBegin(declarator); - } - catch (Exception e) - { - } + try { for (;;) { if (LT(1) == IToken.tLBRACE) break; - Object constructorChainElement = null; - try - { - constructorChainElement = - callback.constructorChainElementBegin(constructorChain); - } - catch (Exception e) - { - } + + ITokenDuple duple = name(); - try - { - callback.constructorChainElementId(constructorChainElement); - } - catch (Exception e) - { - } + consume(IToken.tLPAREN); - IASTExpression expressionList = null; - Object expression = null; - try - { - expression = callback.expressionBegin(constructorChainElement); - } - catch (Exception e) - { - } - expressionList = expression(expression); - try - { - callback.expressionEnd(expressionList); - } - catch (Exception e) - { - } - + IASTExpression expressionList = null; + + expressionList = expression(); + consume(IToken.tRPAREN); - - try - { - callback.constructorChainElementEnd( - constructorChainElement); - } - catch (Exception e) - { - } - - d.addConstructorMemberInitializer( astFactory.createConstructorMemberInitializer( duple, expressionList ) ); - + + d.addConstructorMemberInitializer( + astFactory.createConstructorMemberInitializer( + duple, + expressionList)); if (LT(1) == IToken.tLBRACE) break; consume(IToken.tCOMMA); @@ -1230,22 +952,10 @@ public class Parser implements IParser } catch (Backtrack bt) { - try - { - callback.constructorChainAbort(constructorChain); - } - catch (Exception e) - { - } + throw backtrack; } - try - { - callback.constructorChainEnd(constructorChain); - } - catch (Exception e) - { - } + } /** * This routine parses a parameter declaration @@ -1253,35 +963,31 @@ public class Parser implements IParser * @param containerObject The IParserCallback object representing the parameterDeclarationClause owning the parm. * @throws Backtrack request a backtrack */ - protected void parameterDeclaration(Object containerObject, IParameterCollection collection) + protected void parameterDeclaration( + IParameterCollection collection) throws Backtrack { IToken current = LA(1); - Object parameterDecl = null; - try - { - parameterDecl = callback.parameterDeclarationBegin(containerObject); - } - catch (Exception e) - { - } - - DeclarationWrapper sdw = new DeclarationWrapper( null, current.getOffset(), null ); - declSpecifierSeq( - parameterDecl, - true, - false, - sdw - ); - if( sdw.getTypeSpecifier() == null && sdw.getSimpleType() != IASTSimpleTypeSpecifier.SimpleType.UNSPECIFIED ) - sdw.setTypeSpecifier( astFactory.createSimpleTypeSpecifier( sdw.getSimpleType(), sdw.getName(), sdw.isShort(), sdw.isLong(), sdw.isSigned(), sdw.isUnsigned(), sdw.isTypeNamed() ) ); - - + + DeclarationWrapper sdw = + new DeclarationWrapper(null, current.getOffset(), null); + declSpecifierSeq(true, false, sdw); + if (sdw.getTypeSpecifier() == null + && sdw.getSimpleType() + != IASTSimpleTypeSpecifier.Type.UNSPECIFIED) + sdw.setTypeSpecifier( + astFactory.createSimpleTypeSpecifier( + sdw.getSimpleType(), + sdw.getName(), + sdw.isShort(), + sdw.isLong(), + sdw.isSigned(), + sdw.isUnsigned(), + sdw.isTypeNamed())); if (LT(1) != IToken.tSEMI) try { - DeclaratorDuple d = initDeclarator(parameterDecl, sdw ); - Object declarator = d.getObject(); + DeclaratorDuple d = initDeclarator(sdw); } catch (Backtrack b) { @@ -1289,17 +995,7 @@ public class Parser implements IParser } if (current == LA(1)) throw backtrack; - - if ( collection != null ) - collection.addParameter( sdw ); - - try - { - callback.parameterDeclarationEnd(parameterDecl); - } - catch (Exception e) - { - } + collection.addParameter(sdw); } /** * This class represents the state and strategy for parsing declarationSpecifierSequences @@ -1444,18 +1140,10 @@ public class Parser implements IParser || (LT(3) != IToken.tLPAREN && LT(3) != IToken.tASSIGN)) && !LA(2).isPointer()); } - - private void callbackSimpleDeclToken( Object decl, Flags flags ) + private void callbackSimpleDeclToken(Flags flags) throws Backtrack { - flags.setEncounteredRawType(true); - try - { - callback.simpleDeclSpecifier(decl, consume()); - } - catch (Exception e) - { - } - + flags.setEncounteredRawType(true); + consume(); } /** * This function parses a declaration specifier sequence, as according to the ANSI C++ spec. @@ -1482,242 +1170,152 @@ public class Parser implements IParser * @throws Backtrack request a backtrack */ protected void declSpecifierSeq( - Object decl, boolean parm, boolean tryConstructor, DeclarationWrapper sdw) throws Backtrack { Flags flags = new Flags(parm, tryConstructor); - IToken typeNameBegin = null; - IToken typeNameEnd = null; + IToken typeNameBegin = null; + IToken typeNameEnd = null; declSpecifiers : for (;;) { switch (LT(1)) { case IToken.t_inline : - try - { - callback.simpleDeclSpecifier(decl, consume()); - } - catch (Exception e) - { - } + consume(); sdw.setInline(true); break; case IToken.t_auto : - try - { - callback.simpleDeclSpecifier(decl, consume()); - } - catch (Exception e) - { - } + consume(); sdw.setAuto(true); break; case IToken.t_register : sdw.setRegister(true); - try - { - callback.simpleDeclSpecifier(decl, consume()); - } - catch (Exception e) - { - } - break; + consume(); + break; case IToken.t_static : sdw.setStatic(true); - try - { - callback.simpleDeclSpecifier(decl, consume()); - } - catch (Exception e) - { - } - break; + consume(); + break; case IToken.t_extern : sdw.setExtern(true); - try - { - callback.simpleDeclSpecifier(decl, consume()); - } - catch (Exception e) - { - } + consume(); break; case IToken.t_mutable : sdw.setMutable(true); - try - { - callback.simpleDeclSpecifier(decl, consume()); - } - catch (Exception e) - { - } + consume(); break; case IToken.t_virtual : sdw.setVirtual(true); - try - { - callback.simpleDeclSpecifier(decl, consume()); - } - catch (Exception e) - { - } + consume(); break; case IToken.t_explicit : sdw.setExplicit(true); - try - { - callback.simpleDeclSpecifier(decl, consume()); - } - catch (Exception e) - { - } + consume(); break; case IToken.t_typedef : sdw.setTypedef(true); - try - { - callback.simpleDeclSpecifier(decl, consume()); - } - catch (Exception e) - { - } + consume(); break; case IToken.t_friend : sdw.setFriend(true); - try - { - callback.simpleDeclSpecifier(decl, consume()); - } - catch (Exception e) - { - } + consume(); break; case IToken.t_const : sdw.setConst(true); - try - { - callback.simpleDeclSpecifier(decl, consume()); - } - catch (Exception e) - { - } + consume(); break; case IToken.t_volatile : sdw.setVolatile(true); - try - { - callback.simpleDeclSpecifier(decl, consume()); - } - catch (Exception e) - { - } + consume(); break; case IToken.t_signed : - sdw.setSigned(true); - if( typeNameBegin == null ) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - callbackSimpleDeclToken(decl, flags); - break; + sdw.setSigned(true); + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + callbackSimpleDeclToken(flags); + sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.INT); + break; case IToken.t_unsigned : - sdw.setUnsigned( true ); - if( typeNameBegin == null ) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - callbackSimpleDeclToken(decl, flags); - break; + sdw.setUnsigned(true); + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + callbackSimpleDeclToken(flags); + sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.INT); + break; case IToken.t_short : - sdw.setShort( true ); - if( typeNameBegin == null ) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - callbackSimpleDeclToken(decl, flags); - break; - case IToken.t_long : - if( typeNameBegin == null ) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - - callbackSimpleDeclToken(decl, flags); - sdw.setLong( true ); - break; - + sdw.setShort(true); + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + callbackSimpleDeclToken(flags); + sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.INT); + break; + case IToken.t_long : + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + callbackSimpleDeclToken(flags); + sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.INT); + sdw.setLong(true); + break; case IToken.t_char : - if( typeNameBegin == null ) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - - callbackSimpleDeclToken(decl, flags); - sdw.setSimpleType( IASTSimpleTypeSpecifier.SimpleType.CHAR ); - break; + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + callbackSimpleDeclToken(flags); + sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.CHAR); + break; case IToken.t_wchar_t : - if( typeNameBegin == null ) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - - callbackSimpleDeclToken(decl, flags); - sdw.setSimpleType( IASTSimpleTypeSpecifier.SimpleType.WCHAR_T); - break; - + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + callbackSimpleDeclToken(flags); + sdw.setSimpleType( + IASTSimpleTypeSpecifier.Type.WCHAR_T); + break; case IToken.t_bool : - if( typeNameBegin == null ) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - - callbackSimpleDeclToken(decl, flags); - sdw.setSimpleType( IASTSimpleTypeSpecifier.SimpleType.BOOL); - break; - + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + callbackSimpleDeclToken(flags); + sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.BOOL); + break; case IToken.t_int : - if( typeNameBegin == null ) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - - callbackSimpleDeclToken(decl, flags); - sdw.setSimpleType( IASTSimpleTypeSpecifier.SimpleType.INT); - break; - + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + callbackSimpleDeclToken(flags); + sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.INT); + break; case IToken.t_float : - if( typeNameBegin == null ) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - - callbackSimpleDeclToken(decl, flags); - sdw.setSimpleType( IASTSimpleTypeSpecifier.SimpleType.FLOAT); - break; - + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + callbackSimpleDeclToken(flags); + sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.FLOAT); + break; case IToken.t_double : - if( typeNameBegin == null ) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - - callbackSimpleDeclToken(decl, flags); - sdw.setSimpleType( IASTSimpleTypeSpecifier.SimpleType.DOUBLE ); - break; - + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + callbackSimpleDeclToken(flags); + sdw.setSimpleType( + IASTSimpleTypeSpecifier.Type.DOUBLE); + break; case IToken.t_void : - if( typeNameBegin == null ) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - - callbackSimpleDeclToken(decl, flags); - sdw.setSimpleType( IASTSimpleTypeSpecifier.SimpleType.VOID ); - break; - + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + callbackSimpleDeclToken(flags); + sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.VOID); + break; case IToken.t_typename : sdw.setTypenamed(true); - try - { - callback.simpleDeclSpecifier( - decl, - consume(IToken.t_typename)); - } - catch (Exception e) - { - } + consume(IToken.t_typename ); IToken first = LA(1); IToken last = null; last = name().getLastToken(); @@ -1725,24 +1323,10 @@ public class Parser implements IParser { consume(IToken.t_template); last = templateId(); - try - { - callback.nameBegin(first); - callback.nameEnd(last); - } - catch (Exception e) - { - } } ITokenDuple duple = new TokenDuple(first, last); sdw.setTypeName(duple); - try - { - callback.simpleDeclSpecifierName(decl); - } - catch (Exception e) - { - } + return; case IToken.tCOLONCOLON : consume(IToken.tCOLONCOLON); @@ -1752,44 +1336,36 @@ public class Parser implements IParser // handle nested later: if (flags.haveEncounteredRawType()) { - if( typeNameBegin != null ) - sdw.setTypeName( new TokenDuple( typeNameBegin, typeNameEnd )); + if (typeNameBegin != null) + sdw.setTypeName( + new TokenDuple(typeNameBegin, typeNameEnd)); return; } if (parm && flags.haveEncounteredTypename()) - { - if( typeNameBegin != null ) - sdw.setTypeName( new TokenDuple( typeNameBegin, typeNameEnd )); - return; - } + { + if (typeNameBegin != null) + sdw.setTypeName( + new TokenDuple(typeNameBegin, typeNameEnd)); + return; + } if (lookAheadForConstructorOrConversion(flags)) - { - if( typeNameBegin != null ) - sdw.setTypeName( new TokenDuple( typeNameBegin, typeNameEnd )); - return; - } + { + if (typeNameBegin != null) + sdw.setTypeName( + new TokenDuple(typeNameBegin, typeNameEnd)); + return; + } if (lookAheadForDeclarator(flags)) - { - if( typeNameBegin != null ) - sdw.setTypeName( new TokenDuple( typeNameBegin, typeNameEnd )); - return; - } - try - { - callback.simpleDeclSpecifier(decl, LA(1)); - } - catch (Exception e) { + if (typeNameBegin != null) + sdw.setTypeName( + new TokenDuple(typeNameBegin, typeNameEnd)); + return; } + ITokenDuple d = name(); sdw.setTypeName(d); - try - { - callback.simpleDeclSpecifierName(decl); - } - catch (Exception e) - { - } + sdw.setSimpleType( IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); flags.setEncounteredTypename(true); break; case IToken.t_class : @@ -1799,19 +1375,19 @@ public class Parser implements IParser { try { - classSpecifier(decl, sdw ); + classSpecifier(sdw); return; } catch (Backtrack bt) { - elaboratedTypeSpecifier(decl, sdw); + elaboratedTypeSpecifier(sdw); flags.setEncounteredTypename(true); break; } } else { - elaboratedTypeSpecifier(decl, sdw); + elaboratedTypeSpecifier(sdw); flags.setEncounteredTypename(true); break; } @@ -1820,20 +1396,20 @@ public class Parser implements IParser { try { - enumSpecifier(decl, sdw); + enumSpecifier(sdw); break; } catch (Backtrack bt) { // this is an elaborated class specifier - elaboratedTypeSpecifier(decl, sdw); + elaboratedTypeSpecifier(sdw); flags.setEncounteredTypename(true); break; } } else { - elaboratedTypeSpecifier(decl, sdw); + elaboratedTypeSpecifier(sdw); flags.setEncounteredTypename(true); break; } @@ -1841,9 +1417,8 @@ public class Parser implements IParser break declSpecifiers; } } - if( typeNameBegin != null ) - sdw.setTypeName( new TokenDuple( typeNameBegin, typeNameEnd )); - + if (typeNameBegin != null) + sdw.setTypeName(new TokenDuple(typeNameBegin, typeNameEnd)); } /** * Parse an elaborated type specifier. @@ -1851,55 +1426,40 @@ public class Parser implements IParser * @param decl Declaration which owns the elaborated type * @throws Backtrack request a backtrack */ - protected void elaboratedTypeSpecifier(Object decl, DeclarationWrapper sdw) throws Backtrack + protected void elaboratedTypeSpecifier(DeclarationWrapper sdw) + throws Backtrack { // this is an elaborated class specifier - Object elab = null; IToken t = consume(); - ASTClassKind eck = null; - - switch( t.getType() ) + ASTClassKind eck = null; + switch (t.getType()) { - case Token.t_class: - eck = ASTClassKind.CLASS; - break; - case Token.t_struct: - eck = ASTClassKind.STRUCT; - break; - case Token.t_union: - eck = ASTClassKind.UNION; - break; - case Token.t_enum: - eck = ASTClassKind.ENUM; - break; - default: - break; + case Token.t_class : + eck = ASTClassKind.CLASS; + break; + case Token.t_struct : + eck = ASTClassKind.STRUCT; + break; + case Token.t_union : + eck = ASTClassKind.UNION; + break; + case Token.t_enum : + eck = ASTClassKind.ENUM; + break; + default : + break; } - try - { - elab = callback.elaboratedTypeSpecifierBegin(decl, t ); - } - catch (Exception e) - { - } - + ITokenDuple d = name(); - - IASTElaboratedTypeSpecifier elaboratedTypeSpec = astFactory.createElaboratedTypeSpecifier( eck, d.toString(), t.getOffset(), - d.getLastToken().getEndOffset() ); - - sdw.setTypeSpecifier( elaboratedTypeSpec ); - - requestor.acceptElaboratedTypeSpecifier( elaboratedTypeSpec ); - - try - { - callback.elaboratedTypeSpecifierName(elab); - callback.elaboratedTypeSpecifierEnd(elab); - } - catch (Exception e) - { - } + IASTElaboratedTypeSpecifier elaboratedTypeSpec = + astFactory.createElaboratedTypeSpecifier( + eck, + d.toString(), + t.getOffset(), + d.getLastToken().getEndOffset()); + sdw.setTypeSpecifier(elaboratedTypeSpec); + requestor.acceptElaboratedTypeSpecifier(elaboratedTypeSpec); + } /** * Consumes template parameters. @@ -1940,16 +1500,7 @@ public class Parser implements IParser */ protected IToken identifier() throws Backtrack { - IToken first = consume(IToken.tIDENTIFIER); - // throws backtrack if its not that - try - { - callback.nameBegin(first); - callback.nameEnd(first); - } - catch (Exception e) - { - } + IToken first = consume(IToken.tIDENTIFIER); // throws backtrack if its not that return first; } /** @@ -1990,8 +1541,6 @@ public class Parser implements IParser { IToken first = consume(IToken.tIDENTIFIER); IToken last = consumeTemplateParameters(first); - callback.nameBegin(first); - callback.nameEnd(last); return last; } /** @@ -2010,13 +1559,7 @@ public class Parser implements IParser IToken first = LA(1); IToken last = null; IToken mark = mark(); - try - { - callback.nameBegin(first); - } - catch (Exception e) - { - } + if (LT(1) == IToken.tCOLONCOLON) last = consume(); // TODO - whacky way to deal with destructors, please revisit @@ -2049,13 +1592,7 @@ public class Parser implements IParser last = consumeTemplateParameters(last); } } - try - { - callback.nameEnd(last); - } - catch (Exception e) - { - } + return new TokenDuple(first, last); } /** @@ -2069,38 +1606,20 @@ public class Parser implements IParser * @return Returns the same object sent in. * @throws Backtrack */ - protected Object cvQualifier(Object ptrOp, boolean hasName, Declarator declarator) throws Backtrack + protected void cvQualifier( + Declarator declarator) + throws Backtrack { switch (LT(1)) { case IToken.t_const : - try - { - callback.pointerOperatorCVModifier(ptrOp, consume()); - } - catch (Exception e) - { - } - - if( hasName ) - declarator.addPtrOp( ASTPointerOperator.CONST_POINTER_TO_FUNCTION ); - else - declarator.addPtrOp( ASTPointerOperator.CONST_POINTER ); - return ptrOp; - + consume( IToken.t_const ); + declarator.addPtrOp(ASTPointerOperator.CONST_POINTER); + return; case IToken.t_volatile : - try - { - callback.pointerOperatorCVModifier(ptrOp, consume()); - } - catch (Exception e) - { - } - if( hasName ) - declarator.addPtrOp( ASTPointerOperator.VOLATILE_POINTER_TO_FUNCTION ); - else - declarator.addPtrOp( ASTPointerOperator.VOLATILE_POINTER ); - return ptrOp; + consume( IToken.t_volatile ); + declarator.addPtrOp(ASTPointerOperator.VOLATILE_POINTER); + return; default : throw backtrack; } @@ -2114,143 +1633,85 @@ public class Parser implements IParser * @return declarator that this parsing produced. * @throws Backtrack request a backtrack */ - protected DeclaratorDuple initDeclarator(Object owner, DeclarationWrapper sdw) + protected DeclaratorDuple initDeclarator( + DeclarationWrapper sdw) throws Backtrack { - DeclaratorDuple duple = declarator(owner, sdw); - Object declarator = duple.getObject(); + DeclaratorDuple duple = declarator(sdw); Declarator d = duple.getDeclarator(); - // handle = initializerClause - if(LT(1) == IToken.tASSIGN ) + if (LT(1) == IToken.tASSIGN) { - consume( IToken.tASSIGN ); - d.setInitializerClause( initializerClause( declarator ) ); - } + consume(IToken.tASSIGN); + d.setInitializerClause(initializerClause()); + } else if (LT(1) == IToken.tLPAREN) { - // initializer in constructor + // initializer in constructor consume(IToken.tLPAREN); // EAT IT! - Object expression = null; - IASTExpression astExpression = null; - try - { - try - { - expression = callback.expressionBegin(declarator); - } - catch (Exception e) - { - } - astExpression = expression(expression); - consume(IToken.tRPAREN); - try - { - callback.expressionEnd(expression); - } - catch (Exception e) - { - } - d.setConstructorExpression( astExpression ); - } - catch (Backtrack b) - { - if (expression != null) - { - try - { - callback.expressionAbort(expression); - } - catch (Exception e) - { - } - throw b; - } - } + IASTExpression astExpression = null; + astExpression = expression(); + consume(IToken.tRPAREN); + d.setConstructorExpression(astExpression); } + sdw.addDeclarator(d); + return duple; + } + /** + * + */ + protected IASTInitializerClause initializerClause() + throws Backtrack + { + if (LT(1) == IToken.tLBRACE) + { + //TODO - parse this for real + consume(IToken.tLBRACE); + if (LT(1) == (IToken.tRBRACE)) + { + consume(IToken.tRBRACE); + return astFactory.createInitializerClause( + IASTInitializerClause.Kind.EMPTY, + null, + null); + } + // otherwise it is a list of initializers + List initializerClauses = new ArrayList(); + for (;;) + { + IASTInitializerClause clause = initializerClause(); + initializerClauses.add(clause); + if (LT(1) == IToken.tRBRACE) + break; + consume(IToken.tCOMMA); + } + consume(IToken.tRBRACE); + return astFactory.createInitializerClause( + IASTInitializerClause.Kind.INITIALIZER_LIST, + null, + initializerClauses); + } + // try this now instead + // assignmentExpression || { initializerList , } || { } try { - callback.declaratorEnd(declarator); + + IToken marked = mark(); + IASTExpression assignmentExpression = + assignmentExpression(); + + return astFactory.createInitializerClause( + IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION, + assignmentExpression, + null); } - catch (Exception e) + catch (Backtrack b) { + // who cares } - - sdw.addDeclarator(d); - return duple; + throw backtrack; } - /** - * - */ - protected IASTInitializerClause initializerClause(Object declarator) throws Backtrack - { - if (LT(1) == IToken.tLBRACE) - { - //TODO - parse this for real - consume(IToken.tLBRACE); - if( LT(1) == (IToken.tRBRACE ) ) - { - consume( IToken.tRBRACE ); - return astFactory.createInitializerClause( IASTInitializerClause.Kind.EMPTY, null, null ); - } - - // otherwise it is a list of initializers - List initializerClauses = new ArrayList(); - for( ; ; ) - { - IASTInitializerClause clause = initializerClause( declarator ); - initializerClauses.add( clause ); - if( LT(1) == IToken.tRBRACE ) break; - consume( IToken.tCOMMA ); - } - consume( IToken.tRBRACE ); - return astFactory.createInitializerClause( IASTInitializerClause.Kind.INITIALIZER_LIST, null, initializerClauses ); - } - // try this now instead - // assignmentExpression || { initializerList , } || { } - Object expression = null; - try - { - try - { - expression = callback.expressionBegin(declarator); - } - catch (Exception e) - { - } - - IToken marked = mark(); - IASTExpression assignmentExpression = assignmentExpression(expression); - - try - { - callback.expressionEnd(expression); - } - catch (Exception e) - { - } - - return astFactory.createInitializerClause( IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION, assignmentExpression, null ); - } - catch (Backtrack b) - { - if (expression != null) - try - { - callback.expressionAbort(expression); - } - catch (Exception e) - { - } - } - - - - throw backtrack; - } - - /** * Parse a declarator, as according to the ANSI C++ specification. * * declarator @@ -2271,30 +1732,21 @@ public class Parser implements IParser * @return declarator that this parsing produced. * @throws Backtrack request a backtrack */ - protected DeclaratorDuple declarator(Object container, IDeclaratorOwner owner) throws Backtrack + protected DeclaratorDuple declarator( + IDeclaratorOwner owner) + throws Backtrack { - Object declarator = null; - Declarator d = null; - DeclarationWrapper sdw = owner.getDeclarationWrapper(); - - overallLoop: - do - { - declarator = null; - d = new Declarator( owner ); - - try - { - declarator = callback.declaratorBegin(container); - } - catch (Exception e) - { - } + Declarator d = null; + DeclarationWrapper sdw = owner.getDeclarationWrapper(); + overallLoop : do + { + d = new Declarator(owner); + for (;;) { try { - ptrOperator(declarator, d); + ptrOperator(d); } catch (Backtrack b) { @@ -2304,37 +1756,23 @@ public class Parser implements IParser if (LT(1) == IToken.tLPAREN) { consume(); - DeclaratorDuple subDeclarator = declarator(declarator, d); + DeclaratorDuple subDeclarator = declarator(d); consume(IToken.tRPAREN); - try - { - callback.declaratorEnd(subDeclarator.getObject()); - } - catch (Exception e) - { - } } else if (LT(1) == IToken.t_operator) - operatorId(declarator, d, null); + operatorId(d, null); else { try { ITokenDuple duple = name(); - d.setName( duple ); - try - { - callback.declaratorId(declarator); - } - catch (Exception e) - { - } - + d.setName(duple); + } catch (Backtrack bt) { - IToken start = null; - IToken mark = mark(); + IToken start = null; + IToken mark = mark(); if (LT(1) == IToken.tCOLONCOLON || LT(1) == IToken.tIDENTIFIER) { @@ -2342,21 +1780,20 @@ public class Parser implements IParser IToken end = null; if (start.getType() == IToken.tIDENTIFIER) end = consumeTemplateParameters(end); - - while (LT(1) == IToken.tCOLONCOLON - || LT(1) == IToken.tIDENTIFIER) - { - end = consume(); + while (LT(1) == IToken.tCOLONCOLON + || LT(1) == IToken.tIDENTIFIER) + { + end = consume(); if (end.getType() == IToken.tIDENTIFIER) end = consumeTemplateParameters(end); - } + } if (LT(1) == IToken.t_operator) - operatorId( declarator, d, start ); - else - { - backup( mark ); - throw backtrack; - } + operatorId(d, start); + else + { + backup(mark); + throw backtrack; + } } } } @@ -2369,15 +1806,7 @@ public class Parser implements IParser if (!LA(2).looksLikeExpression()) { // parameterDeclarationClause - d.setIsFunction( true ); - Object clause = null; - try - { - clause = callback.argumentsBegin(declarator); - } - catch (Exception e) - { - } + d.setIsFunction(true); consume(); boolean seenParameter = false; parameterDeclarationLoop : for (;;) @@ -2397,20 +1826,14 @@ public class Parser implements IParser default : if (seenParameter) throw backtrack; - parameterDeclaration(clause, d); + parameterDeclaration(d); seenParameter = true; } } - try - { - callback.argumentsEnd(clause); - } - catch (Exception e) - { - } + if (LT(1) == IToken.tCOLON) { - break overallLoop; + break overallLoop; } IToken beforeCVModifier = mark(); IToken cvModifier = null; @@ -2427,22 +1850,14 @@ public class Parser implements IParser afterCVModifier = mark(); } //check for throws clause here - List exceptionSpecIds = null; + List exceptionSpecIds = null; if (LT(1) == IToken.t_throw) { - exceptionSpecIds = new ArrayList(); - try - { - callback.declaratorThrowsException( - declarator); - } - catch (Exception e) - { - } + exceptionSpecIds = new ArrayList(); consume(); // throw consume(IToken.tLPAREN); // ( boolean done = false; - ITokenDuple duple = null; + ITokenDuple duple = null; while (!done) { switch (LT(1)) @@ -2451,36 +1866,35 @@ public class Parser implements IParser consume(); done = true; break; - case IToken.tCOMMA : - consume(); - break; + case IToken.tCOMMA : + consume(); + break; default : - String image = LA(1).getImage(); - try { - duple = typeId(); - exceptionSpecIds.add( duple ); - } catch (Backtrack e) { - failParse(); - Util.debugLog( "Unexpected Token =" + image ); - consume(); // eat this token anyway - continue; - } - - try { - callback - .declaratorThrowExceptionName( - declarator); - } - catch (Exception e) + String image = LA(1).getImage(); + try { + duple = typeId(); + exceptionSpecIds.add(duple); + } + catch (Backtrack e) + { + failParse(); + Util.debugLog( + "Unexpected Token =" + + image); + consume(); + // eat this token anyway + continue; } break; } } - if( exceptionSpecIds != null ) - d.setExceptionSpecification( astFactory.createExceptionSpecification( exceptionSpecIds ) ); + if (exceptionSpecIds != null) + d.setExceptionSpecification( + astFactory + .createExceptionSpecification( + exceptionSpecIds)); } - // check for optional pure virtual if (LT(1) == IToken.tASSIGN && LT(2) == IToken.tINTEGER @@ -2488,69 +1902,45 @@ public class Parser implements IParser { consume(IToken.tASSIGN); consume(IToken.tINTEGER); - d.setPureVirtual( true ); - try - { - callback.declaratorPureVirtual(declarator); - } - catch (Exception e) - { - } + d.setPureVirtual(true); } - - if ( afterCVModifier != LA(1) || LT(1) == IToken.tSEMI ) + if (afterCVModifier != LA(1) + || LT(1) == IToken.tSEMI) { // There were C++-specific clauses after const/volatile modifier // Then it is a marker for the method - if ( cvModifier != null ) { - try - { - callback.declaratorCVModifier( - declarator, - cvModifier); - } - catch (Exception e) - { - } - - if( cvModifier.getType() == IToken.t_const ) - d.setConst( true ); - if( cvModifier.getType() == IToken.t_volatile ) - d.setVolatile( true ); + if (cvModifier != null) + { + + if (cvModifier.getType() == IToken.t_const) + d.setConst(true); + if (cvModifier.getType() + == IToken.t_volatile) + d.setVolatile(true); } - - afterCVModifier = mark(); - + afterCVModifier = mark(); // In this case (method) we can't expect K&R parameter declarations, // but we'll check anyway, for errorhandling } else { // let's try this modifier as part of K&R parameter declaration - if (cvModifier != null) backup(beforeCVModifier); + if (cvModifier != null) + backup(beforeCVModifier); } - if (LT(1) != IToken.tSEMI) { // try K&R-style parameter declarations - Object oldKRParameterDeclarationClause = null; - try - { - oldKRParameterDeclarationClause = - callback.oldKRParametersBegin(clause); - } - catch (Exception e) - { - } + try { do - { + { simpleDeclaration( - oldKRParameterDeclarationClause, false, true, - sdw.getScope(), sdw.getOwnerTemplate()); + sdw.getScope(), + sdw.getOwnerTemplate()); } while (LT(1) != IToken.tLBRACE); } @@ -2560,14 +1950,7 @@ public class Parser implements IParser // this is not a proper K&R declaration clause backup(afterCVModifier); } - try - { - callback.oldKRParametersEnd( - oldKRParameterDeclarationClause); - } - catch (Exception e) - { - } + } } break; @@ -2575,185 +1958,99 @@ public class Parser implements IParser while (LT(1) == IToken.tLBRACKET) { consume(); // eat the '[' - Object array = null; - try - { - array = - callback.arrayDeclaratorBegin(declarator); - } - catch (Exception e) - { - } - IASTExpression exp = null; + + IASTExpression exp = null; if (LT(1) != IToken.tRBRACKET) { - Object expression = null; - try - { - expression = - callback.expressionBegin(array); - } - catch (Exception e) - { - } - exp = constantExpression(expression); - try - { - callback.expressionEnd(expression); - } - catch (Exception e) - { - } + exp = constantExpression(); } consume(IToken.tRBRACKET); - IASTArrayModifier arrayMod = astFactory.createArrayModifier( exp ); - d.addArrayModifier( arrayMod ); + IASTArrayModifier arrayMod = + astFactory.createArrayModifier(exp); + d.addArrayModifier(arrayMod); - try - { - callback.arrayDeclaratorEnd(array); - } - catch (Exception e) - { - } } continue; case IToken.tCOLON : consume(IToken.tCOLON); - Object bitfield = null; - try - { - bitfield = callback.startBitfield(declarator); - } - catch (Exception e) - { - } - Object expression = null; - IASTExpression exp = null; - try - { - expression = callback.expressionBegin(bitfield); - } - catch (Exception e) - { - } - exp = constantExpression(expression); - try - { - callback.expressionEnd(expression); - } - catch (Exception e) - { - } - try - { - callback.endBitfield(bitfield); - } - catch (Exception e) - { - } - d.setBitFieldExpression( exp ); + IASTExpression exp = null; + exp = constantExpression(); + d.setBitFieldExpression(exp); default : break; } break; } - if (LA(1).getType() == IToken.tIDENTIFIER) - { - try - { - callback.declaratorAbort(declarator); - } - catch (Exception e) - { - } - declarator = null; - } - else - { - break; - } + if (LA(1).getType() != IToken.tIDENTIFIER) + break; + } while (true); - - if( d.getOwner() instanceof Declarator ) - ((Declarator)d.getOwner()).setOwnedDeclarator(d); - return new DeclaratorDuple( declarator, d ); - + if (d.getOwner() instanceof Declarator) + ((Declarator)d.getOwner()).setOwnedDeclarator(d); + return new DeclaratorDuple(d); } - - protected void operatorId(Object declarator, Declarator d, IToken originalToken) + protected void operatorId( + Declarator d, + IToken originalToken) throws Backtrack, EndOfFile { - // we know this is an operator - IToken operatorToken = consume(IToken.t_operator); - IToken toSend = null; - if (LA(1).isOperator() - || LT(1) == IToken.tLPAREN - || LT(1) == IToken.tLBRACKET) + // we know this is an operator + IToken operatorToken = consume(IToken.t_operator); + IToken toSend = null; + if (LA(1).isOperator() + || LT(1) == IToken.tLPAREN + || LT(1) == IToken.tLBRACKET) + { + if ((LT(1) == IToken.t_new || LT(1) == IToken.t_delete) + && LT(2) == IToken.tLBRACKET + && LT(3) == IToken.tRBRACKET) { - if ((LT(1) == IToken.t_new || LT(1) == IToken.t_delete) - && LT(2) == IToken.tLBRACKET - && LT(3) == IToken.tRBRACKET) - { - consume(); - consume(IToken.tLBRACKET); - toSend = consume(IToken.tRBRACKET); - // vector new and delete operators - } - else if ( - LT(1) == IToken.tLPAREN && LT(2) == IToken.tRPAREN) - { - // operator () - consume(IToken.tLPAREN); - toSend = consume(IToken.tRPAREN); - } - else if ( - LT(1) == IToken.tLBRACKET && LT(2) == IToken.tRBRACKET) - { - consume(IToken.tLBRACKET); - toSend = consume(IToken.tRBRACKET); - } - else if (LA(1).isOperator()) - toSend = consume(); - else - throw backtrack; + consume(); + consume(IToken.tLBRACKET); + toSend = consume(IToken.tRBRACKET); + // vector new and delete operators } + else if (LT(1) == IToken.tLPAREN && LT(2) == IToken.tRPAREN) + { + // operator () + consume(IToken.tLPAREN); + toSend = consume(IToken.tRPAREN); + } + else if (LT(1) == IToken.tLBRACKET && LT(2) == IToken.tRBRACKET) + { + consume(IToken.tLBRACKET); + toSend = consume(IToken.tRBRACKET); + } + else if (LA(1).isOperator()) + toSend = consume(); else + throw backtrack; + } + else + { + // must be a conversion function + typeId(); + toSend = lastToken; + try { - // must be a conversion function - typeId(); + // this ptrOp doesn't belong to the declarator, + // it's just a part of the name + ptrOperator(d); toSend = lastToken; - try - { - // this ptrOp doesn't belong to the declarator, - // it's just a part of the name - ptrOperator(null, d); - toSend = lastToken; - } - catch (Backtrack b) - { - } - // In case we'll need better error recovery - // while( LT(1) != Token.tLPAREN ) { toSend = consume(); } } - ITokenDuple duple = new TokenDuple( originalToken == null ? operatorToken : originalToken ,toSend ); - try - { - callback.nameBegin(originalToken == null ? operatorToken : originalToken ); - callback.nameEnd(toSend); - } - catch (Exception e) + catch (Backtrack b) { } - try - { - callback.declaratorId(declarator); - } - catch (Exception e) - { - } - d.setName( duple ); + // In case we'll need better error recovery + // while( LT(1) != Token.tLPAREN ) { toSend = consume(); } + } + ITokenDuple duple = + new TokenDuple( + originalToken == null ? operatorToken : originalToken, + toSend); + + d.setName(duple); } /** * Parse a Pointer Operator. @@ -2766,75 +2063,36 @@ public class Parser implements IParser * @param owner Declarator that this pointer operator corresponds to. * @throws Backtrack request a backtrack */ - protected void ptrOperator(Object owner, Declarator d) throws Backtrack + protected void ptrOperator(Declarator d) throws Backtrack { int t = LT(1); - Object ptrOp = null; - - try - { - ptrOp = callback.pointerOperatorBegin(owner); - } - catch (Exception e) - { - } if (t == IToken.tAMPER) { - try - { - callback.pointerOperatorType(ptrOp, consume(IToken.tAMPER)); - callback.pointerOperatorEnd(ptrOp); - } - catch (Exception e) - { - } - d.addPtrOp( ASTPointerOperator.REFERENCE ); + consume( IToken.tAMPER ); + d.addPtrOp(ASTPointerOperator.REFERENCE); return; } IToken mark = mark(); IToken tokenType = LA(1); - boolean hasName = false; ITokenDuple nameDuple = null; if (t == IToken.tIDENTIFIER || t == IToken.tCOLONCOLON) { - callback.nameBegin(tokenType); nameDuple = name(); - callback.nameEnd(lastToken); - hasName = true; t = LT(1); } - if (t == IToken.tSTAR) { - if (hasName) - { - try - { - - callback.pointerOperatorName(ptrOp); - } - catch (Exception e) - { - } - consume(Token.tSTAR); - } - else - { - tokenType = consume(Token.tSTAR); // tokenType = "*" - } - - try - { - callback.pointerOperatorType(ptrOp, tokenType); - } - catch (Exception e) - { - } + tokenType = consume(Token.tSTAR); // tokenType = "*" + + d.setPointerOperatorName(nameDuple); + + boolean successful = false; for (;;) { try { - ptrOp = cvQualifier(ptrOp, hasName, d); + cvQualifier(d); + successful = true; } catch (Backtrack b) { @@ -2842,23 +2100,12 @@ public class Parser implements IParser break; } } - try - { - callback.pointerOperatorEnd(ptrOp); - } - catch (Exception e) - { - } + if( !successful ) + d.addPtrOp( ASTPointerOperator.POINTER ); + return; } backup(mark); - try - { - callback.pointerOperatorAbort(ptrOp); - } - catch (Exception e) - { - } throw backtrack; } /** @@ -2877,135 +2124,70 @@ public class Parser implements IParser * @param owner IParserCallback object that represents the declaration that owns this type specifier. * @throws Backtrack request a backtrack */ - protected void enumSpecifier(Object owner, DeclarationWrapper sdw) throws Backtrack + protected void enumSpecifier(DeclarationWrapper sdw) + throws Backtrack { - Object enumSpecifier = null; IToken mark = mark(); - IToken identifier = null; - try - { - enumSpecifier = - callback.enumSpecifierBegin(owner, consume(IToken.t_enum)); - } - catch (Exception e) - { - } + IToken identifier = null; + consume( IToken.t_enum ); if (LT(1) == IToken.tIDENTIFIER) { identifier = identifier(); - try - { - callback.enumSpecifierId(enumSpecifier); - } - catch (Exception e) - { - } } if (LT(1) == IToken.tLBRACE) { - IASTEnumerationSpecifier enumeration = astFactory.createEnumerationSpecifier( - ( ( identifier == null ) ? "" : identifier.getImage()), - mark.getOffset(), - ( ( identifier == null ) ? mark.getOffset() : identifier.getOffset()) ); + IASTEnumerationSpecifier enumeration = + astFactory.createEnumerationSpecifier( + ((identifier == null) ? "" : identifier.getImage()), + mark.getOffset(), + ((identifier == null) + ? mark.getOffset() + : identifier.getOffset())); consume(IToken.tLBRACE); while (LT(1) != IToken.tRBRACE) { - Object defn; - IToken enumeratorIdentifier = null; + IToken enumeratorIdentifier = null; if (LT(1) == IToken.tIDENTIFIER) { - - defn = null; - try - { - defn = callback.enumeratorBegin(enumSpecifier); - } - catch (Exception e) - { - } - enumeratorIdentifier = identifier(); - try - { - callback.enumeratorId(defn); - } - catch (Exception e) - { - } + enumeratorIdentifier = identifier(); } else { - try - { - callback.enumSpecifierAbort(enumSpecifier); - } - catch (Exception e) - { - } throw backtrack; } IASTExpression initialValue = null; if (LT(1) == IToken.tASSIGN) { consume(IToken.tASSIGN); - Object expression = null; - try - { - expression = callback.expressionBegin(defn); - } - catch (Exception e) - { - } - initialValue = constantExpression(expression); - try - { - callback.expressionEnd(expression); - } - catch (Exception e) - { - } - - } - try - { - callback.enumeratorEnd(defn, lastToken); - } - catch (Exception e) - { + initialValue = constantExpression(); } + if (LT(1) == IToken.tRBRACE) { - astFactory.addEnumerator( enumeration, enumeratorIdentifier.toString(), enumeratorIdentifier.getOffset(), enumeratorIdentifier.getEndOffset(), initialValue); + astFactory.addEnumerator( + enumeration, + enumeratorIdentifier.getImage(), + enumeratorIdentifier.getOffset(), + enumeratorIdentifier.getEndOffset(), + initialValue); break; } if (LT(1) != IToken.tCOMMA) { - try - { - callback.enumSpecifierAbort(enumSpecifier); - } - catch (Exception e) - { - } throw backtrack; } - astFactory.addEnumerator( enumeration, enumeratorIdentifier.toString(), enumeratorIdentifier.getOffset(), enumeratorIdentifier.getEndOffset(), initialValue ); + astFactory.addEnumerator( + enumeration, + enumeratorIdentifier.getImage(), + enumeratorIdentifier.getOffset(), + enumeratorIdentifier.getEndOffset(), + initialValue); consume(IToken.tCOMMA); } - - IToken t = consume(IToken.tRBRACE); - try - { - - callback.enumSpecifierEnd( - enumSpecifier, - t ); - } - catch (Exception e) - { - } - enumeration.setEndingOffset( t.getEndOffset() ); - requestor.acceptEnumerationSpecifier( enumeration ); - sdw.setTypeSpecifier( enumeration ); + IToken t = consume(IToken.tRBRACE); + enumeration.setEndingOffset(t.getEndOffset()); + requestor.acceptEnumerationSpecifier(enumeration); + sdw.setTypeSpecifier(enumeration); } else { @@ -3023,7 +2205,7 @@ public class Parser implements IParser * @param owner IParserCallback object that represents the declaration that owns this classSpecifier * @throws Backtrack request a backtrack */ - protected void classSpecifier(Object owner, DeclarationWrapper sdw ) + protected void classSpecifier(DeclarationWrapper sdw) throws Backtrack { ClassNameType nameType = ClassNameType.IDENTIFIER; @@ -3050,40 +2232,15 @@ public class Parser implements IParser default : throw backtrack; } - Object classSpec = null; - try - { - classSpec = callback.classSpecifierBegin(owner, classKey); - } - catch (Exception e) - { - } + ITokenDuple duple = null; // class name if (LT(1) == IToken.tIDENTIFIER) - { duple = className(); - try - { - callback.classSpecifierName(classSpec); - } - catch (Exception e) - { - } - } if (duple != null && !duple.isIdentifier()) nameType = ClassNameType.TEMPLATE; if (LT(1) != IToken.tCOLON && LT(1) != IToken.tLBRACE) { - // this is not a classSpecification - try - { - callback.classSpecifierAbort(classSpec); - } - catch (Exception e) - { - } - classSpec = null; backup(mark); throw backtrack; } @@ -3096,13 +2253,13 @@ public class Parser implements IParser nameType, access, null, //TODO add TemplateDeclaration here - classKey.getOffset(), - duple == null ? 0 : duple.getFirstToken().getOffset()); - sdw.setTypeSpecifier(astClassSpecifier); + classKey.getOffset(), + duple == null ? 0 : duple.getFirstToken().getOffset()); + sdw.setTypeSpecifier(astClassSpecifier); // base clause if (LT(1) == IToken.tCOLON) { - baseSpecifier(classSpec, astClassSpecifier); + baseSpecifier(astClassSpecifier); } if (LT(1) == IToken.tLBRACE) { @@ -3114,18 +2271,20 @@ public class Parser implements IParser switch (LT(1)) { case IToken.t_public : + consume(); + consume(IToken.tCOLON); + astClassSpecifier.setCurrentVisibility( ASTAccessVisibility.PUBLIC ); + break; case IToken.t_protected : + consume(); + consume(IToken.tCOLON); + astClassSpecifier.setCurrentVisibility( ASTAccessVisibility.PROTECTED); + break; + case IToken.t_private : - try - { - callback.classMemberVisibility( - classSpec, - consume()); - } - catch (Exception e) - { - } + consume(); consume(IToken.tCOLON); + astClassSpecifier.setCurrentVisibility( ASTAccessVisibility.PRIVATE); break; case IToken.tRBRACE : consume(IToken.tRBRACE); @@ -3133,7 +2292,7 @@ public class Parser implements IParser default : try { - declaration(classSpec,astClassSpecifier, null); + declaration(astClassSpecifier, null); } catch (Backtrack bt) { @@ -3147,13 +2306,6 @@ public class Parser implements IParser } // consume the } IToken lastToken = consume(IToken.tRBRACE); - try - { - callback.classSpecifierEnd(classSpec, lastToken); - } - catch (Exception e) - { - } astClassSpecifier.setEndingOffset(lastToken.getEndOffset()); requestor.exitClassSpecifier(astClassSpecifier); } @@ -3172,19 +2324,10 @@ public class Parser implements IParser * @throws Backtrack */ protected void baseSpecifier( - Object classSpecOwner, IASTClassSpecifier astClassSpec) throws Backtrack { consume(IToken.tCOLON); - Object baseSpecifier = null; - try - { - baseSpecifier = callback.baseSpecifierBegin(classSpecOwner); - } - catch (Exception e) - { - } boolean isVirtual = false; ASTAccessVisibility visibility = ASTAccessVisibility.PUBLIC; ITokenDuple nameDuple = null; @@ -3195,91 +2338,38 @@ public class Parser implements IParser case IToken.t_virtual : consume(IToken.t_virtual); isVirtual = true; - try - { - callback.baseSpecifierVirtual(baseSpecifier, true); - } - catch (Exception e) - { - } break; case IToken.t_public : - try - { - callback.baseSpecifierVisibility( - baseSpecifier, - consume()); - } - catch (Exception e) - { - } + consume(); break; case IToken.t_protected : - try - { - callback.baseSpecifierVisibility( - baseSpecifier, - consume()); - } - catch (Exception e) - { - } - visibility = ASTAccessVisibility.PROTECTED; + consume(); + visibility = ASTAccessVisibility.PROTECTED; break; case IToken.t_private : visibility = ASTAccessVisibility.PRIVATE; - try - { - callback.baseSpecifierVisibility( - baseSpecifier, - consume()); - } - catch (Exception e) - { - } - break; + consume(); + break; case IToken.tCOLONCOLON : case IToken.tIDENTIFIER : nameDuple = name(); - try - { - callback.baseSpecifierName(baseSpecifier); - } - catch (Exception e) - { - } break; case IToken.tCOMMA : - try - { - astFactory.addBaseSpecifier( - astClassSpec, - isVirtual, - visibility, - nameDuple.toString()); - isVirtual = false; - visibility = ASTAccessVisibility.PUBLIC; - nameDuple = null; - callback.baseSpecifierEnd(baseSpecifier); - baseSpecifier = - callback.baseSpecifierBegin(classSpecOwner); - } - catch (Exception e) - { - } + astFactory.addBaseSpecifier( + astClassSpec, + isVirtual, + visibility, + nameDuple.toString()); + isVirtual = false; + visibility = ASTAccessVisibility.PUBLIC; + nameDuple = null; consume(); continue baseSpecifierLoop; default : break baseSpecifierLoop; } } - try - { - callback.baseSpecifierEnd(baseSpecifier); - } - catch (Exception e) - { - } + astFactory.addBaseSpecifier( astClassSpec, isVirtual, @@ -3302,27 +2392,12 @@ public class Parser implements IParser */ protected void statement() throws Backtrack { - Object expression = null; + switch (LT(1)) { case IToken.t_case : consume(); - // TODO regarding this null - try - { - expression = callback.expressionBegin(null); - } - catch (Exception e) - { - } - constantExpression(expression); - try - { - callback.expressionEnd(expression); - } - catch (Exception e) - { - } + constantExpression(); consume(IToken.tCOLON); statement(); return; @@ -3377,22 +2452,8 @@ public class Parser implements IParser consume(IToken.tSEMI); if (LT(1) != IToken.tRPAREN) { - try - { - expression = callback.expressionBegin(null); - } - catch (Exception e) - { - } //TODO get rid of NULL - expression(expression); - try - { - callback.expressionEnd(expression); - } - catch (Exception e) - { - } + expression(); } consume(IToken.tRPAREN); statement(); @@ -3409,22 +2470,8 @@ public class Parser implements IParser consume(); if (LT(1) != IToken.tSEMI) { - try - { - expression = callback.expressionBegin(null); - } - catch (Exception e) - { - } //TODO get rid of NULL - expression(expression); - try - { - callback.expressionEnd(expression); - } - catch (Exception e) - { - } + expression(); } consume(IToken.tSEMI); return; @@ -3440,7 +2487,7 @@ public class Parser implements IParser { consume(); consume(IToken.tLPAREN); - declaration(null, null, null); // was exceptionDeclaration + declaration(null, null); // was exceptionDeclaration consume(IToken.tRPAREN); compoundStatement(); } @@ -3463,22 +2510,7 @@ public class Parser implements IParser // Since it only happens when we are in a statement try { - try - { - expression = callback.expressionBegin(null); - } - catch (Exception e) - { - } - //TODO get rid of NULL - expression(expression); - try - { - callback.expressionEnd(expression); - } - catch (Exception e) - { - } + expression(); consume(IToken.tSEMI); return; } @@ -3486,7 +2518,7 @@ public class Parser implements IParser { } // declarationStatement - declaration(null,null, null); + declaration(null, null); } } /** @@ -3517,122 +2549,157 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression constantExpression(Object expression) throws Backtrack + protected IASTExpression constantExpression() + throws Backtrack { - return conditionalExpression(expression); + return conditionalExpression(); } - /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IParser#expression(java.lang.Object) */ - public IASTExpression expression(Object expression) throws Backtrack + public IASTExpression expression() throws Backtrack { - IASTExpression assignmentExpression = assignmentExpression(expression); + IASTExpression assignmentExpression = assignmentExpression(); while (LT(1) == IToken.tCOMMA) { IToken t = consume(); - IASTExpression secondExpression = assignmentExpression(expression); - - try - { - callback.expressionOperator(expression, t); - } - catch (Exception e) - { - } - assignmentExpression = astFactory.createExpression( IASTExpression.Kind.EXPRESSIONLIST, assignmentExpression, secondExpression, null, "", "", "", null ); + IASTExpression secondExpression = assignmentExpression(); + assignmentExpression = + astFactory.createExpression( + IASTExpression.Kind.EXPRESSIONLIST, + assignmentExpression, + secondExpression, + null, + "", + "", + "", + null); } - return assignmentExpression; + return assignmentExpression; } /** * @param expression * @throws Backtrack */ - protected IASTExpression assignmentExpression(Object expression) throws Backtrack + protected IASTExpression assignmentExpression() + throws Backtrack { if (LT(1) == IToken.t_throw) { - return throwExpression(expression); + return throwExpression(); } - IASTExpression conditionalExpression = conditionalExpression(expression); + IASTExpression conditionalExpression = + conditionalExpression(); // if the condition not taken, try assignment operators - if (conditionalExpression != null && conditionalExpression.getExpressionKind() == IASTExpression.Kind.CONDITIONALEXPRESSION_HARD ) - return conditionalExpression; - + if (conditionalExpression != null + && conditionalExpression.getExpressionKind() + == IASTExpression.Kind.CONDITIONALEXPRESSION_HARD) + return conditionalExpression; switch (LT(1)) { case IToken.tASSIGN : - return assignmentOperatorExpression(expression, IASTExpression.Kind.ASSIGNMENTEXPRESSION_NORMAL ); + return assignmentOperatorExpression( + IASTExpression.Kind.ASSIGNMENTEXPRESSION_NORMAL); case IToken.tSTARASSIGN : - return assignmentOperatorExpression(expression, IASTExpression.Kind.ASSIGNMENTEXPRESSION_MULT ); + return assignmentOperatorExpression( + IASTExpression.Kind.ASSIGNMENTEXPRESSION_MULT); case IToken.tDIVASSIGN : - return assignmentOperatorExpression(expression, IASTExpression.Kind.ASSIGNMENTEXPRESSION_DIV ); + return assignmentOperatorExpression( + IASTExpression.Kind.ASSIGNMENTEXPRESSION_DIV); case IToken.tMODASSIGN : - return assignmentOperatorExpression(expression, IASTExpression.Kind.ASSIGNMENTEXPRESSION_MOD ); + return assignmentOperatorExpression( + IASTExpression.Kind.ASSIGNMENTEXPRESSION_MOD); case IToken.tPLUSASSIGN : - return assignmentOperatorExpression(expression, IASTExpression.Kind.ASSIGNMENTEXPRESSION_PLUS ); + return assignmentOperatorExpression( + IASTExpression.Kind.ASSIGNMENTEXPRESSION_PLUS); case IToken.tMINUSASSIGN : - return assignmentOperatorExpression(expression, IASTExpression.Kind.ASSIGNMENTEXPRESSION_MINUS ); + return assignmentOperatorExpression( + IASTExpression.Kind.ASSIGNMENTEXPRESSION_MINUS); case IToken.tSHIFTRASSIGN : - return assignmentOperatorExpression(expression, IASTExpression.Kind.ASSIGNMENTEXPRESSION_RSHIFT ); + return assignmentOperatorExpression( + IASTExpression.Kind.ASSIGNMENTEXPRESSION_RSHIFT); case IToken.tSHIFTLASSIGN : - return assignmentOperatorExpression(expression, IASTExpression.Kind.ASSIGNMENTEXPRESSION_LSHIFT ); + return assignmentOperatorExpression( + IASTExpression.Kind.ASSIGNMENTEXPRESSION_LSHIFT); case IToken.tAMPERASSIGN : - return assignmentOperatorExpression(expression, IASTExpression.Kind.ASSIGNMENTEXPRESSION_AND ); + return assignmentOperatorExpression( + IASTExpression.Kind.ASSIGNMENTEXPRESSION_AND); case IToken.tXORASSIGN : - return assignmentOperatorExpression(expression, IASTExpression.Kind.ASSIGNMENTEXPRESSION_XOR ); + return assignmentOperatorExpression( + IASTExpression.Kind.ASSIGNMENTEXPRESSION_XOR); case IToken.tBITORASSIGN : - return assignmentOperatorExpression(expression, IASTExpression.Kind.ASSIGNMENTEXPRESSION_OR ); + return assignmentOperatorExpression( + IASTExpression.Kind.ASSIGNMENTEXPRESSION_OR); } - return conditionalExpression; - + return conditionalExpression; + } + protected IASTExpression assignmentOperatorExpression( + IASTExpression.Kind kind) + throws EndOfFile, Backtrack + { + IToken t = consume(); + IASTExpression assignmentExpression = assignmentExpression(); + + return astFactory.createExpression( + kind, + assignmentExpression, + null, + null, + "", + "", + "", + null); } - - protected IASTExpression assignmentOperatorExpression(Object expression, IASTExpression.Kind kind ) - throws EndOfFile, Backtrack { - IToken t = consume(); - IASTExpression assignmentExpression = assignmentExpression(expression); - try - { - callback.expressionOperator(expression, t); - } - catch (Exception e) - { - } - return astFactory.createExpression( kind, assignmentExpression, null, null, "", "", "", null ); - } /** * @param expression * @throws Backtrack */ - protected IASTExpression throwExpression(Object expression) throws Backtrack + protected IASTExpression throwExpression() + throws Backtrack { consume(IToken.t_throw); - IASTExpression throwExpression = null; + IASTExpression throwExpression = null; try { - throwExpression = expression(expression); + throwExpression = expression(); } catch (Backtrack b) { } - return astFactory.createExpression( IASTExpression.Kind.THROWEXPRESSION, throwExpression, null, null, "", "", "", null ); + return astFactory.createExpression( + IASTExpression.Kind.THROWEXPRESSION, + throwExpression, + null, + null, + "", + "", + "", + null); } /** * @param expression * @return * @throws Backtrack */ - protected IASTExpression conditionalExpression(Object expression) throws Backtrack + protected IASTExpression conditionalExpression() + throws Backtrack { - IASTExpression firstExpression = logicalOrExpression(expression); + IASTExpression firstExpression = logicalOrExpression(); if (LT(1) == IToken.tQUESTION) { consume(); - IASTExpression secondExpression = expression(expression); + IASTExpression secondExpression = expression(); consume(IToken.tCOLON); - IASTExpression thirdExpression = assignmentExpression(expression); - return astFactory.createExpression( IASTExpression.Kind.CONDITIONALEXPRESSION_HARD, firstExpression, secondExpression, thirdExpression, "","","",null); + IASTExpression thirdExpression = assignmentExpression(); + return astFactory.createExpression( + IASTExpression.Kind.CONDITIONALEXPRESSION_HARD, + firstExpression, + secondExpression, + thirdExpression, + "", + "", + "", + null); } else return firstExpression; @@ -3641,22 +2708,25 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression logicalOrExpression(Object expression) throws Backtrack + protected IASTExpression logicalOrExpression() + throws Backtrack { - IASTExpression firstExpression = logicalAndExpression(expression); - + IASTExpression firstExpression = logicalAndExpression(); while (LT(1) == IToken.tOR) { IToken t = consume(); - IASTExpression secondExpression = logicalAndExpression(expression); - try - { - callback.expressionOperator(expression, t); - } - catch (Exception e) - { - } - firstExpression = astFactory.createExpression( IASTExpression.Kind.LOGICALOREXPRESSION, firstExpression, secondExpression, null, "", "", "", null ); + IASTExpression secondExpression = logicalAndExpression(); + + firstExpression = + astFactory.createExpression( + IASTExpression.Kind.LOGICALOREXPRESSION, + firstExpression, + secondExpression, + null, + "", + "", + "", + null); } return firstExpression; } @@ -3664,21 +2734,24 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression logicalAndExpression(Object expression) throws Backtrack + protected IASTExpression logicalAndExpression() + throws Backtrack { - IASTExpression firstExpression = inclusiveOrExpression(expression); + IASTExpression firstExpression = inclusiveOrExpression(); while (LT(1) == IToken.tAND) { IToken t = consume(); - IASTExpression secondExpression = inclusiveOrExpression(expression); - try - { - callback.expressionOperator(expression, t); - } - catch (Exception e) - { - } - firstExpression = astFactory.createExpression( IASTExpression.Kind.LOGICALANDEXPRESSION, firstExpression, secondExpression, null, "", "", "", null ); + IASTExpression secondExpression = inclusiveOrExpression(); + firstExpression = + astFactory.createExpression( + IASTExpression.Kind.LOGICALANDEXPRESSION, + firstExpression, + secondExpression, + null, + "", + "", + "", + null); } return firstExpression; } @@ -3686,65 +2759,25 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression inclusiveOrExpression(Object expression) throws Backtrack + protected IASTExpression inclusiveOrExpression() + throws Backtrack { - IASTExpression firstExpression = exclusiveOrExpression(expression); + IASTExpression firstExpression = exclusiveOrExpression(); while (LT(1) == IToken.tBITOR) { IToken t = consume(); - IASTExpression secondExpression = exclusiveOrExpression(expression); - try - { - callback.expressionOperator(expression, t); - } - catch (Exception e) - { - } - firstExpression = astFactory.createExpression( IASTExpression.Kind.INCLUSIVEOREXPRESSION, firstExpression, secondExpression, null, "", "", "", null ); - } - return firstExpression; - } - /** - * @param expression - * @throws Backtrack - */ - protected IASTExpression exclusiveOrExpression(Object expression) throws Backtrack - { - IASTExpression firstExpression = andExpression(expression); - while (LT(1) == IToken.tXOR) - { - IToken t = consume(); - IASTExpression secondExpression = andExpression(expression); - try - { - callback.expressionOperator(expression, t); - } - catch (Exception e) - { - } - firstExpression = astFactory.createExpression( IASTExpression.Kind.EXCLUSIVEOREXPRESSION, firstExpression, secondExpression, null, "", "", "", null ); - } - return firstExpression; - } - /** - * @param expression - * @throws Backtrack - */ - protected IASTExpression andExpression(Object expression) throws Backtrack - { - IASTExpression firstExpression = equalityExpression(expression); - while (LT(1) == IToken.tAMPER) - { - IToken t = consume(); - IASTExpression secondExpression = equalityExpression(expression); - try - { - callback.expressionOperator(expression, t); - } - catch (Exception e) - { - } - firstExpression = astFactory.createExpression( IASTExpression.Kind.ANDEXPRESSION, firstExpression, secondExpression, null, "", "", "", null ); + IASTExpression secondExpression = exclusiveOrExpression(); + + firstExpression = + astFactory.createExpression( + IASTExpression.Kind.INCLUSIVEOREXPRESSION, + firstExpression, + secondExpression, + null, + "", + "", + "", + null); } return firstExpression; } @@ -3752,26 +2785,83 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression equalityExpression(Object expression) throws Backtrack + protected IASTExpression exclusiveOrExpression() + throws Backtrack { - IASTExpression firstExpression = relationalExpression(expression); + IASTExpression firstExpression = andExpression(); + while (LT(1) == IToken.tXOR) + { + IToken t = consume(); + IASTExpression secondExpression = andExpression(); + + firstExpression = + astFactory.createExpression( + IASTExpression.Kind.EXCLUSIVEOREXPRESSION, + firstExpression, + secondExpression, + null, + "", + "", + "", + null); + } + return firstExpression; + } + /** + * @param expression + * @throws Backtrack + */ + protected IASTExpression andExpression() throws Backtrack + { + IASTExpression firstExpression = equalityExpression(); + while (LT(1) == IToken.tAMPER) + { + IToken t = consume(); + IASTExpression secondExpression = equalityExpression(); + + firstExpression = + astFactory.createExpression( + IASTExpression.Kind.ANDEXPRESSION, + firstExpression, + secondExpression, + null, + "", + "", + "", + null); + } + return firstExpression; + } + /** + * @param expression + * @throws Backtrack + */ + protected IASTExpression equalityExpression() + throws Backtrack + { + IASTExpression firstExpression = relationalExpression(); for (;;) { switch (LT(1)) { case IToken.tEQUAL : - case IToken.tNOTEQUAL : + case IToken.tNOTEQUAL : IToken t = consume(); - IASTExpression secondExpression = relationalExpression(expression); - try - { - callback.expressionOperator(expression, t); - } - catch (Exception e) - { - } - firstExpression = astFactory.createExpression( ( t.getType() == IToken.tEQUAL ) ? IASTExpression.Kind.EQUALITY_EQUALS : IASTExpression.Kind.EQUALITY_NOTEQUALS, - firstExpression, secondExpression, null, "", "", "", null ); + IASTExpression secondExpression = + relationalExpression(); + + firstExpression = + astFactory.createExpression( + (t.getType() == IToken.tEQUAL) + ? IASTExpression.Kind.EQUALITY_EQUALS + : IASTExpression.Kind.EQUALITY_NOTEQUALS, + firstExpression, + secondExpression, + null, + "", + "", + "", + null); break; default : return firstExpression; @@ -3782,9 +2872,10 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression relationalExpression(Object expression) throws Backtrack + protected IASTExpression relationalExpression() + throws Backtrack { - IASTExpression firstExpression = shiftExpression(expression); + IASTExpression firstExpression = shiftExpression(); for (;;) { switch (LT(1)) @@ -3796,7 +2887,8 @@ public class Parser implements IParser IToken mark = mark(); IToken t = consume(); IToken next = LA(1); - IASTExpression secondExpression = shiftExpression(expression); + IASTExpression secondExpression = + shiftExpression(); if (next == LA(1)) { // we did not consume anything @@ -3806,36 +2898,39 @@ public class Parser implements IParser } else { - try + IASTExpression.Kind kind = null; + switch (t.getType()) { - callback.expressionOperator(expression, t); + case IToken.tGT : + kind = + IASTExpression.Kind.RELATIONAL_GREATERTHAN; + break; + case IToken.tLT : + kind = IASTExpression.Kind.RELATIONAL_LESSTHAN; + break; + case IToken.tLTEQUAL : + kind = + IASTExpression + .Kind + .RELATIONAL_LESSTHANEQUALTO; + break; + case IToken.tGTEQUAL : + kind = + IASTExpression + .Kind + .RELATIONAL_GREATERTHANEQUALTO; + break; } - catch (Exception e) - { - } - - IASTExpression.Kind kind = null; - switch( t.getType() ) - { - case IToken.tGT : - kind = IASTExpression.Kind.RELATIONAL_GREATERTHAN; - break; - - case IToken.tLT : - kind = IASTExpression.Kind.RELATIONAL_LESSTHAN; - break; - - case IToken.tLTEQUAL : - kind = IASTExpression.Kind.RELATIONAL_LESSTHANEQUALTO; - break; - - case IToken.tGTEQUAL : - kind = IASTExpression.Kind.RELATIONAL_GREATERTHANEQUALTO; - break; - - } - - firstExpression = astFactory.createExpression( kind, firstExpression, secondExpression, null, "", "", "", null ); + firstExpression = + astFactory.createExpression( + kind, + firstExpression, + secondExpression, + null, + "", + "", + "", + null); } break; default : @@ -3847,9 +2942,10 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression shiftExpression(Object expression) throws Backtrack + protected IASTExpression shiftExpression() + throws Backtrack { - IASTExpression firstExpression = additiveExpression(expression); + IASTExpression firstExpression = additiveExpression(); for (;;) { switch (LT(1)) @@ -3857,47 +2953,20 @@ public class Parser implements IParser case IToken.tSHIFTL : case IToken.tSHIFTR : IToken t = consume(); - IASTExpression secondExpression = additiveExpression(expression); - try - { - callback.expressionOperator(expression, t); - } - catch (Exception e) - { - } - firstExpression = astFactory.createExpression( ( ( t.getType() == IToken.tSHIFTL ) ? IASTExpression.Kind.SHIFT_LEFT : IASTExpression.Kind.SHIFT_RIGHT ), - firstExpression, secondExpression, null, "", "", "", null ); - break; - default : - return firstExpression ; - } - } - } - /** - * @param expression - * @throws Backtrack - */ - protected IASTExpression additiveExpression(Object expression) throws Backtrack - { - IASTExpression firstExpression = multiplicativeExpression(expression); - for (;;) - { - switch (LT(1)) - { - case IToken.tPLUS : - case IToken.tMINUS : - IToken t = consume(); - IASTExpression secondExpression = multiplicativeExpression(expression); - try - { - callback.expressionOperator(expression, t); - } - catch (Exception e) - { - } - firstExpression = astFactory.createExpression( ( ( t.getType() == IToken.tPLUS ) ? IASTExpression.Kind.ADDITIVE_PLUS : IASTExpression.Kind.ADDITIVE_MINUS), - firstExpression, secondExpression, null, "", "", "", null ); - + IASTExpression secondExpression = + additiveExpression(); + firstExpression = + astFactory.createExpression( + ((t.getType() == IToken.tSHIFTL) + ? IASTExpression.Kind.SHIFT_LEFT + : IASTExpression.Kind.SHIFT_RIGHT), + firstExpression, + secondExpression, + null, + "", + "", + "", + null); break; default : return firstExpression; @@ -3908,9 +2977,45 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression multiplicativeExpression(Object expression) throws Backtrack + protected IASTExpression additiveExpression() + throws Backtrack { - IASTExpression firstExpression = pmExpression(expression); + IASTExpression firstExpression = multiplicativeExpression(); + for (;;) + { + switch (LT(1)) + { + case IToken.tPLUS : + case IToken.tMINUS : + IToken t = consume(); + IASTExpression secondExpression = + multiplicativeExpression(); + firstExpression = + astFactory.createExpression( + ((t.getType() == IToken.tPLUS) + ? IASTExpression.Kind.ADDITIVE_PLUS + : IASTExpression.Kind.ADDITIVE_MINUS), + firstExpression, + secondExpression, + null, + "", + "", + "", + null); + break; + default : + return firstExpression; + } + } + } + /** + * @param expression + * @throws Backtrack + */ + protected IASTExpression multiplicativeExpression() + throws Backtrack + { + IASTExpression firstExpression = pmExpression(); for (;;) { switch (LT(1)) @@ -3919,36 +3024,31 @@ public class Parser implements IParser case IToken.tDIV : case IToken.tMOD : IToken t = consume(); - IASTExpression secondExpression = pmExpression(expression); - try + IASTExpression secondExpression = pmExpression(); + IASTExpression.Kind kind = null; + switch (t.getType()) { - callback.expressionOperator(expression, t); + case IToken.tSTAR : + kind = IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY; + break; + case IToken.tDIV : + kind = IASTExpression.Kind.MULTIPLICATIVE_DIVIDE; + break; + case IToken.tMOD : + kind = IASTExpression.Kind.MULTIPLICATIVE_MODULUS; + break; } - catch (Exception e) - { - } - - - IASTExpression.Kind kind = null; - switch( t.getType() ) - { - case IToken.tSTAR : - kind = IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY; - break; - - case IToken.tDIV : - kind = IASTExpression.Kind.MULTIPLICATIVE_DIVIDE; - break; - - case IToken.tMOD : - kind = IASTExpression.Kind.MULTIPLICATIVE_MODULUS; - break; - - } - - firstExpression = astFactory.createExpression( kind, firstExpression, secondExpression, null, "", "", "", null ); - break; - + firstExpression = + astFactory.createExpression( + kind, + firstExpression, + secondExpression, + null, + "", + "", + "", + null); + break; default : return firstExpression; } @@ -3958,9 +3058,9 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression pmExpression(Object expression) throws Backtrack + protected IASTExpression pmExpression() throws Backtrack { - IASTExpression firstExpression = castExpression(expression); + IASTExpression firstExpression = castExpression(); for (;;) { switch (LT(1)) @@ -3968,17 +3068,20 @@ public class Parser implements IParser case IToken.tDOTSTAR : case IToken.tARROWSTAR : IToken t = consume(); - IASTExpression secondExpression = castExpression(expression); - try - { - callback.expressionOperator(expression, t); - } - catch (Exception e) - { - } - firstExpression = astFactory.createExpression( ( ( t.getType() == IToken.tDOTSTAR ) ? IASTExpression.Kind.PM_DOTSTAR : IASTExpression.Kind.PM_ARROWSTAR), - firstExpression, secondExpression, null, "", "", "", null ); - + IASTExpression secondExpression = + castExpression(); + firstExpression = + astFactory.createExpression( + ((t.getType() == IToken.tDOTSTAR) + ? IASTExpression.Kind.PM_DOTSTAR + : IASTExpression.Kind.PM_ARROWSTAR), + firstExpression, + secondExpression, + null, + "", + "", + "", + null); break; default : return firstExpression; @@ -3990,14 +3093,14 @@ public class Parser implements IParser * : unaryExpression * | "(" typeId ")" castExpression */ - protected IASTExpression castExpression(Object expression) throws Backtrack + protected IASTExpression castExpression() throws Backtrack { // TO DO: we need proper symbol checkint to ensure type name if (LT(1) == IToken.tLPAREN) { IToken mark = mark(); consume(); - ITokenDuple duple = null; + ITokenDuple duple = null; // If this isn't a type name, then we shouldn't be here try { @@ -4011,24 +3114,31 @@ public class Parser implements IParser consume(); } consume(IToken.tRPAREN); - IASTExpression castExpression = castExpression(expression); - return astFactory.createExpression( IASTExpression.Kind.CASTEXPRESSION, castExpression, null, null, null, duple.toString(), "", null ); + IASTExpression castExpression = castExpression(); + return astFactory.createExpression( + IASTExpression.Kind.CASTEXPRESSION, + castExpression, + null, + null, + null, + duple.toString(), + "", + null); } catch (Backtrack b) { backup(mark); } } - return unaryExpression(expression); + return unaryExpression(); } /** * @throws Backtrack */ protected ITokenDuple typeId() throws Backtrack { - IToken begin = LA(1); - IToken end = null; - + IToken begin = LA(1); + IToken end = null; try { ITokenDuple d = name(); @@ -4067,21 +3177,18 @@ public class Parser implements IParser } if (end != null) { - try - { - callback.nameBegin(begin); - callback.nameEnd(end); - } - catch (Exception e) - { - } - return new TokenDuple( begin, end ); + return new TokenDuple(begin, end); } - else if (LT(1) == IToken.t_typename || LT(1) == IToken.t_struct || LT(1) == IToken.t_class || LT(1) == IToken.t_enum || LT(1) == IToken.t_union ) + else if ( + LT(1) == IToken.t_typename + || LT(1) == IToken.t_struct + || LT(1) == IToken.t_class + || LT(1) == IToken.t_enum + || LT(1) == IToken.t_union) { - consume(); - ITokenDuple d = name(); - return new TokenDuple( begin, d.getLastToken() ); + consume(); + ITokenDuple d = name(); + return new TokenDuple(begin, d.getLastToken()); } else throw backtrack; @@ -4091,7 +3198,8 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression deleteExpression(Object expression) throws Backtrack + protected IASTExpression deleteExpression() + throws Backtrack { if (LT(1) == IToken.tCOLONCOLON) { @@ -4099,7 +3207,7 @@ public class Parser implements IParser consume(); } consume(IToken.t_delete); - boolean vectored = false; + boolean vectored = false; if (LT(1) == IToken.tLBRACKET) { // array delete @@ -4107,9 +3215,18 @@ public class Parser implements IParser consume(IToken.tRBRACKET); vectored = true; } - IASTExpression castExpression = castExpression(expression); - return astFactory.createExpression( ( vectored ? IASTExpression.Kind.DELETE_VECTORCASTEXPRESSION : IASTExpression.Kind.DELETE_CASTEXPRESSION ), - castExpression, null, null, "", "", "", null ); + IASTExpression castExpression = castExpression(); + return astFactory.createExpression( + (vectored + ? IASTExpression.Kind.DELETE_VECTORCASTEXPRESSION + : IASTExpression.Kind.DELETE_CASTEXPRESSION), + castExpression, + null, + null, + "", + "", + "", + null); } /** * Pazse a new-expression. @@ -4127,7 +3244,7 @@ public class Parser implements IParser * directnewdeclarator [ constantexpression ] * newinitializer: ( expressionlist? ) */ - protected IASTExpression newExpression(Object expression) throws Backtrack + protected IASTExpression newExpression() throws Backtrack { if (LT(1) == IToken.tCOLONCOLON) { @@ -4135,13 +3252,10 @@ public class Parser implements IParser consume(); } consume(IToken.t_new); - boolean typeIdInParen = false; boolean placementParseFailure = true; - IToken beforeSecondParen = null; IToken backtrackMarker = null; - if (LT(1) == IToken.tLPAREN) { consume(IToken.tLPAREN); @@ -4150,7 +3264,7 @@ public class Parser implements IParser // Try to consume placement list // Note: since expressionList and expression are the same... backtrackMarker = mark(); - expression(expression); + expression(); consume(IToken.tRPAREN); placementParseFailure = false; if (LT(1) == IToken.tLPAREN) @@ -4228,7 +3342,7 @@ public class Parser implements IParser // Worst-case scenario - this cannot be resolved w/o more semantic information. // Luckily, we don't need to know what was that - we only know that // new-expression ends here. - return null; // TODO fix this + return null; // TODO fix this } } catch (Backtrack e) @@ -4251,7 +3365,7 @@ public class Parser implements IParser { // array new consume(); - assignmentExpression(expression); + assignmentExpression(); consume(IToken.tRBRACKET); } // newinitializer @@ -4259,55 +3373,73 @@ public class Parser implements IParser { consume(IToken.tLPAREN); if (LT(1) != IToken.tRPAREN) - expression(expression); + expression(); consume(IToken.tRPAREN); } return null; //TODO fix this } - - - protected IASTExpression unaryOperatorCastExpression( Object expression, IASTExpression.Kind kind, IToken consumed ) throws Backtrack + protected IASTExpression unaryOperatorCastExpression( + IASTExpression.Kind kind, + IToken consumed) + throws Backtrack { - IASTExpression castExpression = castExpression(expression); - try - { - callback.expressionOperator(expression, consumed); - } - catch (Exception e) - { - } - return astFactory.createExpression( kind, castExpression, null, null, "", "", "", null ); + IASTExpression castExpression = castExpression(); + return astFactory.createExpression( + kind, + castExpression, + null, + null, + "", + "", + "", + null); } /** * @param expression * @throws Backtrack */ - protected IASTExpression unaryExpression(Object expression) throws Backtrack + protected IASTExpression unaryExpression() + throws Backtrack { switch (LT(1)) { case IToken.tSTAR : - return unaryOperatorCastExpression( expression, IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION, consume() ); + return unaryOperatorCastExpression( + IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION, + consume()); case IToken.tAMPER : - return unaryOperatorCastExpression( expression, IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION, consume() ); + return unaryOperatorCastExpression( + IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION, + consume()); case IToken.tPLUS : - return unaryOperatorCastExpression( expression, IASTExpression.Kind.UNARY_PLUS_CASTEXPRESSION, consume() ); + return unaryOperatorCastExpression( + IASTExpression.Kind.UNARY_PLUS_CASTEXPRESSION, + consume()); case IToken.tMINUS : - return unaryOperatorCastExpression( expression, IASTExpression.Kind.UNARY_MINUS_CASTEXPRESSION, consume() ); + return unaryOperatorCastExpression( + IASTExpression.Kind.UNARY_MINUS_CASTEXPRESSION, + consume()); case IToken.tNOT : - return unaryOperatorCastExpression( expression, IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION, consume() ); + return unaryOperatorCastExpression( + IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION, + consume()); case IToken.tCOMPL : - return unaryOperatorCastExpression( expression, IASTExpression.Kind.UNARY_TILDE_CASTEXPRESSION, consume() ); + return unaryOperatorCastExpression( + IASTExpression.Kind.UNARY_TILDE_CASTEXPRESSION, + consume()); case IToken.tINCR : - return unaryOperatorCastExpression( expression, IASTExpression.Kind.UNARY_INCREMENT, consume() ); - case IToken.tDECR : - return unaryOperatorCastExpression( expression, IASTExpression.Kind.UNARY_DECREMENT, consume() ); - + return unaryOperatorCastExpression( + IASTExpression.Kind.UNARY_INCREMENT, + consume()); + case IToken.tDECR : + return unaryOperatorCastExpression( + IASTExpression.Kind.UNARY_DECREMENT, + consume()); case IToken.t_sizeof : consume(IToken.t_sizeof); IToken mark = LA(1); ITokenDuple d = null; - IASTExpression unaryExpression = null; + IASTExpression unaryExpression = null; if (LT(1) == IToken.tLPAREN) { try @@ -4319,295 +3451,439 @@ public class Parser implements IParser catch (Backtrack bt) { backup(mark); - unaryExpression = unaryExpression(expression); + unaryExpression = unaryExpression(); } } else { - unaryExpression = unaryExpression(expression); + unaryExpression = unaryExpression(); } - - if( d != null & unaryExpression == null ) - return astFactory.createExpression( IASTExpression.Kind.UNARY_SIZEOF_TYPEID, null, null, null, "", d.toString(), "", null ); - else if( unaryExpression != null && d == null ) - return astFactory.createExpression( IASTExpression.Kind.UNARY_SIZEOF_UNARYEXPRESSION, unaryExpression, null, null, "", "", "", null ); + if (d != null & unaryExpression == null) + return astFactory.createExpression( + IASTExpression.Kind.UNARY_SIZEOF_TYPEID, + null, + null, + null, + "", + d.toString(), + "", + null); + else if (unaryExpression != null && d == null) + return astFactory.createExpression( + IASTExpression.Kind.UNARY_SIZEOF_UNARYEXPRESSION, + unaryExpression, + null, + null, + "", + "", + "", + null); else - throw backtrack; - + throw backtrack; case IToken.t_new : - return newExpression(expression); + return newExpression(); case IToken.t_delete : - return deleteExpression(expression); + return deleteExpression(); case IToken.tCOLONCOLON : switch (LT(2)) { case IToken.t_new : - return newExpression(expression); + return newExpression(); case IToken.t_delete : - return deleteExpression(expression); + return deleteExpression(); default : - return postfixExpression(expression); + return postfixExpression(); } default : - return postfixExpression(expression); + return postfixExpression(); } } /** * @param expression * @throws Backtrack */ - protected IASTExpression postfixExpression(Object expression) throws Backtrack + protected IASTExpression postfixExpression() + throws Backtrack { - IASTExpression firstExpression = null; - boolean isTemplate = false; + IASTExpression firstExpression = null; + boolean isTemplate = false; switch (LT(1)) { case IToken.t_typename : consume(); //TODO: the rest of this break; - // simple-type-specifier ( assignment-expression , .. ) + // simple-type-specifier ( assignment-expression , .. ) case IToken.t_char : - firstExpression = simpleTypeConstructorExpression(expression, IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR ); - break; + firstExpression = + simpleTypeConstructorExpression( + IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR); + break; case IToken.t_wchar_t : - firstExpression = simpleTypeConstructorExpression(expression, IASTExpression.Kind.POSTFIX_SIMPLETYPE_WCHART ); - break; + firstExpression = + simpleTypeConstructorExpression( + IASTExpression.Kind.POSTFIX_SIMPLETYPE_WCHART); + break; case IToken.t_bool : - firstExpression = simpleTypeConstructorExpression(expression, IASTExpression.Kind.POSTFIX_SIMPLETYPE_BOOL); - break; + firstExpression = + simpleTypeConstructorExpression( + IASTExpression.Kind.POSTFIX_SIMPLETYPE_BOOL); + break; case IToken.t_short : - firstExpression = simpleTypeConstructorExpression(expression, IASTExpression.Kind.POSTFIX_SIMPLETYPE_SHORT); - break; + firstExpression = + simpleTypeConstructorExpression( + IASTExpression.Kind.POSTFIX_SIMPLETYPE_SHORT); + break; case IToken.t_int : - firstExpression = simpleTypeConstructorExpression(expression, IASTExpression.Kind.POSTFIX_SIMPLETYPE_INT); - break; + firstExpression = + simpleTypeConstructorExpression( + IASTExpression.Kind.POSTFIX_SIMPLETYPE_INT); + break; case IToken.t_long : - firstExpression = simpleTypeConstructorExpression(expression, IASTExpression.Kind.POSTFIX_SIMPLETYPE_LONG); - break; + firstExpression = + simpleTypeConstructorExpression( + IASTExpression.Kind.POSTFIX_SIMPLETYPE_LONG); + break; case IToken.t_signed : - firstExpression = simpleTypeConstructorExpression(expression, IASTExpression.Kind.POSTFIX_SIMPLETYPE_SIGNED); - break; + firstExpression = + simpleTypeConstructorExpression( + IASTExpression.Kind.POSTFIX_SIMPLETYPE_SIGNED); + break; case IToken.t_unsigned : - firstExpression = simpleTypeConstructorExpression(expression, IASTExpression.Kind.POSTFIX_SIMPLETYPE_UNSIGNED); - break; + firstExpression = + simpleTypeConstructorExpression( + IASTExpression.Kind.POSTFIX_SIMPLETYPE_UNSIGNED); + break; case IToken.t_float : - firstExpression = simpleTypeConstructorExpression(expression, IASTExpression.Kind.POSTFIX_SIMPLETYPE_FLOAT); - break; + firstExpression = + simpleTypeConstructorExpression( + IASTExpression.Kind.POSTFIX_SIMPLETYPE_FLOAT); + break; case IToken.t_double : - firstExpression = simpleTypeConstructorExpression(expression, IASTExpression.Kind.POSTFIX_SIMPLETYPE_DOUBLE); + firstExpression = + simpleTypeConstructorExpression( + IASTExpression.Kind.POSTFIX_SIMPLETYPE_DOUBLE); break; case IToken.t_dynamic_cast : - firstExpression = specialCastExpression(expression, IASTExpression.Kind.POSTFIX_DYNAMIC_CAST ); - break; + firstExpression = + specialCastExpression( + IASTExpression.Kind.POSTFIX_DYNAMIC_CAST); + break; case IToken.t_static_cast : - firstExpression = specialCastExpression(expression, IASTExpression.Kind.POSTFIX_STATIC_CAST ); - break; + firstExpression = + specialCastExpression( + IASTExpression.Kind.POSTFIX_STATIC_CAST); + break; case IToken.t_reinterpret_cast : - firstExpression = specialCastExpression(expression, IASTExpression.Kind.POSTFIX_REINTERPRET_CAST ); - break; + firstExpression = + specialCastExpression( + IASTExpression.Kind.POSTFIX_REINTERPRET_CAST); + break; case IToken.t_const_cast : - firstExpression = specialCastExpression(expression, IASTExpression.Kind.POSTFIX_CONST_CAST ); + firstExpression = + specialCastExpression( + IASTExpression.Kind.POSTFIX_CONST_CAST); break; case IToken.t_typeid : consume(); consume(IToken.tLPAREN); boolean isTypeId = true; - IASTExpression lhs = null; - ITokenDuple typeId = null; + IASTExpression lhs = null; + ITokenDuple typeId = null; try { typeId = typeId(); } catch (Backtrack b) { - isTypeId = false; - lhs = expression(expression); + isTypeId = false; + lhs = expression(); } consume(IToken.tRPAREN); - - firstExpression = astFactory.createExpression( ( isTypeId ? IASTExpression.Kind.POSTFIX_TYPEID_TYPEID : IASTExpression.Kind.POSTFIX_TYPEID_EXPRESSION ), - lhs, null, null, "", ( isTypeId ? typeId.toString() : "" ), "", null ); - + firstExpression = + astFactory.createExpression( + (isTypeId + ? IASTExpression.Kind.POSTFIX_TYPEID_TYPEID + : IASTExpression.Kind.POSTFIX_TYPEID_EXPRESSION), + lhs, + null, + null, + "", + (isTypeId ? typeId.toString() : ""), + "", + null); break; default : - firstExpression = primaryExpression(expression); + firstExpression = primaryExpression(); + } + IASTExpression secondExpression = null; + for (;;) + { + switch (LT(1)) + { + case IToken.tLBRACKET : + // array access + consume(); + secondExpression = expression(); + consume(IToken.tRBRACKET); + firstExpression = + astFactory.createExpression( + IASTExpression.Kind.POSTFIX_SUBSCRIPT, + firstExpression, + secondExpression, + null, + "", + "", + "", + null); + break; + case IToken.tLPAREN : + // function call + consume(); + secondExpression = expression(); + consume(IToken.tRPAREN); + firstExpression = + astFactory.createExpression( + IASTExpression.Kind.POSTFIX_FUNCTIONCALL, + firstExpression, + secondExpression, + null, + "", + "", + "", + null); + break; + case IToken.tINCR : + consume(); + firstExpression = + astFactory.createExpression( + IASTExpression.Kind.POSTFIX_INCREMENT, + firstExpression, + null, + null, + "", + "", + "", + null); + break; + case IToken.tDECR : + consume(); + firstExpression = + astFactory.createExpression( + IASTExpression.Kind.POSTFIX_DECREMENT, + firstExpression, + null, + null, + "", + "", + "", + null); + break; + case IToken.tDOT : + // member access + consume(IToken.tDOT); + if (LT(1) == IToken.t_template) + { + consume(IToken.t_template); + isTemplate = true; + } + secondExpression = primaryExpression(); + firstExpression = + astFactory.createExpression( + (isTemplate + ? IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS + : IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION), + firstExpression, + secondExpression, + null, + "", + "", + "", + null); + break; + case IToken.tARROW : + // member access + consume(IToken.tARROW); + if (LT(1) == IToken.t_template) + { + consume(IToken.t_template); + isTemplate = true; + } + secondExpression = primaryExpression(); + firstExpression = + astFactory.createExpression( + (isTemplate + ? IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP + : IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION), + firstExpression, + secondExpression, + null, + "", + "", + "", + null); + break; + default : + return firstExpression; + } } - - IASTExpression secondExpression = null; - - for( ; ; ) - { - switch (LT(1)) - { - case IToken.tLBRACKET : - // array access - consume(); - secondExpression = expression(expression); - consume(IToken.tRBRACKET); - firstExpression = astFactory.createExpression( IASTExpression.Kind.POSTFIX_SUBSCRIPT, firstExpression, secondExpression, null, "", "", "", null ); - break; - case IToken.tLPAREN : - // function call - consume(); - secondExpression = expression(expression); - consume(IToken.tRPAREN); - firstExpression = astFactory.createExpression( IASTExpression.Kind.POSTFIX_FUNCTIONCALL, firstExpression, secondExpression, null, "", "", "", null ); - break; - case IToken.tINCR : - consume(); - firstExpression = astFactory.createExpression( IASTExpression.Kind.POSTFIX_INCREMENT, firstExpression, null, null, "", "", "", null ); - break; - case IToken.tDECR : - consume(); - firstExpression = astFactory.createExpression( IASTExpression.Kind.POSTFIX_DECREMENT, firstExpression, null, null, "", "", "", null ); - break; - case IToken.tDOT : - // member access - consume( IToken.tDOT ); - - if( LT(1) == IToken.t_template ) - { - consume( IToken.t_template ); - isTemplate = true; - } - secondExpression = primaryExpression(expression); - firstExpression = astFactory.createExpression( ( isTemplate ? IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS : IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION), - firstExpression, secondExpression, null, "", "", "", null ); - break; - case IToken.tARROW : - // member access - consume( IToken.tARROW ); - if( LT(1) == IToken.t_template ) - { - consume( IToken.t_template ); - isTemplate = true; - } - secondExpression = primaryExpression(expression); - firstExpression = astFactory.createExpression( ( isTemplate ? IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP : IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION), - firstExpression, secondExpression, null, "", "", "", null ); - break; - default : - return firstExpression; - } - } - - } - protected IASTExpression specialCastExpression(Object expression, IASTExpression.Kind kind) - throws EndOfFile, Backtrack { - consume(); - consume(IToken.tLT); - ITokenDuple duple = typeId(); - consume(IToken.tGT); - consume(IToken.tLPAREN); - IASTExpression lhs = expression(expression); - consume(IToken.tRPAREN); - return astFactory.createExpression( kind, lhs, null, null, "", "", "", null ); - } - - protected IASTExpression simpleTypeConstructorExpression(Object expression, Kind type) throws EndOfFile, Backtrack { - consume(); - consume(IToken.tLPAREN); - IASTExpression inside = expression( expression ); - // while (true) - // { - // assignmentExpression(expression); - // if (LT(1) == IToken.tRPAREN) - // break; - // consume(IToken.tCOMMA); - // } - consume(IToken.tRPAREN); - return astFactory.createExpression( type, inside, null, null, "", "", "", null ); - } + protected IASTExpression specialCastExpression( + IASTExpression.Kind kind) + throws EndOfFile, Backtrack + { + consume(); + consume(IToken.tLT); + ITokenDuple duple = typeId(); + consume(IToken.tGT); + consume(IToken.tLPAREN); + IASTExpression lhs = expression(); + consume(IToken.tRPAREN); + return astFactory.createExpression( + kind, + lhs, + null, + null, + "", + "", + "", + null); + } + protected IASTExpression simpleTypeConstructorExpression( + Kind type) + throws EndOfFile, Backtrack + { + consume(); + consume(IToken.tLPAREN); + IASTExpression inside = expression(); + // while (true) + // { + // assignmentExpression(expression); + // if (LT(1) == IToken.tRPAREN) + // break; + // consume(IToken.tCOMMA); + // } + consume(IToken.tRPAREN); + return astFactory.createExpression( + type, + inside, + null, + null, + "", + "", + "", + null); + } /** * @param expression * @throws Backtrack */ - protected IASTExpression primaryExpression(Object expression) throws Backtrack + protected IASTExpression primaryExpression() + throws Backtrack { - IToken t = null; + IToken t = null; switch (LT(1)) { // TO DO: we need more literals... case IToken.tINTEGER : - t = consume(); - try - { - callback.expressionTerminal(expression, t ); - } - catch (Exception e) - { - } - return astFactory.createExpression( IASTExpression.Kind.PRIMARY_INTEGER_LITERAL, null, null, null, "", "", t.getImage(), null ); - + t = consume(); + return astFactory.createExpression( + IASTExpression.Kind.PRIMARY_INTEGER_LITERAL, + null, + null, + null, + "", + "", + t.getImage(), + null); case IToken.tFLOATINGPT : - t = consume(); - try - { - callback.expressionTerminal(expression, t ); - } - catch (Exception e) - { - } - return astFactory.createExpression( IASTExpression.Kind.PRIMARY_FLOAT_LITERAL, null, null, null, "", "", t.getImage(), null ); - + t = consume(); + return astFactory.createExpression( + IASTExpression.Kind.PRIMARY_FLOAT_LITERAL, + null, + null, + null, + "", + "", + t.getImage(), + null); case IToken.tSTRING : case IToken.tLSTRING : t = consume(); - try - { - callback.expressionTerminal(expression, t ); - } - catch (Exception e) - { - } return astFactory.createExpression( IASTExpression.Kind.PRIMARY_STRING_LITERAL, null, null, null, "", "", t.getImage(), null ); case IToken.t_false : case IToken.t_true : - t = consume(); - try - { - callback.expressionTerminal(expression, t ); - } - catch (Exception e) - { - } - return astFactory.createExpression( IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL, null, null, null, "", "", t.getImage(), null ); - + t = consume(); + return astFactory.createExpression( + IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL, + null, + null, + null, + "", + "", + t.getImage(), + null); + case IToken.tCHAR : case IToken.tLCHAR : - t = consume(); - try - { - callback.expressionTerminal(expression, t ); - } - catch (Exception e) - { - } - return astFactory.createExpression( IASTExpression.Kind.PRIMARY_CHAR_LITERAL, null, null, null, "", "", t.getImage(), null ); + + t = consume(); + return astFactory.createExpression( + IASTExpression.Kind.PRIMARY_CHAR_LITERAL, + null, + null, + null, + "", + "", + t.getImage(), + null); + case IToken.t_this : - consume( IToken.t_this ); - return astFactory.createExpression( IASTExpression.Kind.PRIMARY_THIS, null, null, null, "", "", "", null ); + consume(IToken.t_this); + return astFactory.createExpression( + IASTExpression.Kind.PRIMARY_THIS, + null, + null, + null, + "", + "", + "", + null); case IToken.tLPAREN : consume(); - IASTExpression lhs = expression(expression); + IASTExpression lhs = expression(); consume(IToken.tRPAREN); - return astFactory.createExpression( IASTExpression.Kind.PRIMARY_BRACKETED_EXPRESSION, lhs, null, null, "", "", "", null ); - - case IToken.tIDENTIFIER : - - ITokenDuple duple = name(); //TODO should be an ID Expression really - try - { - callback.expressionName(expression); - } - catch (Exception e) - { - } - return astFactory.createExpression( IASTExpression.Kind.ID_EXPRESSION, null, null, null, "", "", duple.toString(), null ); - default : - return astFactory.createExpression( IASTExpression.Kind.PRIMARY_EMPTY, null, null, null, "", "", "", null ); + return astFactory.createExpression( + IASTExpression.Kind.PRIMARY_BRACKETED_EXPRESSION, + lhs, + null, + null, + "", + "", + "", + null); + case IToken.tIDENTIFIER : + ITokenDuple duple = name(); + //TODO should be an ID Expression really + return astFactory.createExpression( + IASTExpression.Kind.ID_EXPRESSION, + null, + null, + null, + "", + "", + duple.toString(), + null); + default : + return astFactory.createExpression( + IASTExpression.Kind.PRIMARY_EMPTY, + null, + null, + null, + "", + "", + "", + null); } } /** @@ -4657,7 +3933,6 @@ public class Parser implements IParser } // the static instance we always use private static Backtrack backtrack = new Backtrack(); - // the static instance we always use public static EndOfFile endOfFile = new EndOfFile(); // Token management @@ -4695,7 +3970,7 @@ public class Parser implements IParser */ protected IToken LA(int i) throws EndOfFile { - if (i < 1) // can't go backwards + if (i < 1) // can't go backwards return null; if (currToken == null) currToken = fetchToken(); @@ -4787,7 +4062,6 @@ public class Parser implements IParser if (scanner != null) scanner.setCppNature(b); } - /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IParser#getLastErrorOffset() */ @@ -4795,7 +4069,6 @@ public class Parser implements IParser { return firstErrorOffset; } - /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.IParser#setRequestor(org.eclipse.cdt.core.parser.ISourceElementRequestor) */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParseCallback.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParseCallback.java new file mode 100644 index 00000000000..6cee5701e1e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParseCallback.java @@ -0,0 +1,169 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.internal.core.parser; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; + +import org.eclipse.cdt.core.parser.IQuickParseCallback; +import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; +import org.eclipse.cdt.core.parser.ast.IASTInclusion; +import org.eclipse.cdt.core.parser.ast.IASTMacro; +import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement; + + +public class QuickParseCallback extends NullSourceElementRequestor implements IQuickParseCallback +{ + private IASTCompilationUnit compilationUnit = null; + private List inclusions = new ArrayList(); + private List macros = new ArrayList(); + + public Iterator getInclusions() + { + return inclusions.iterator(); + } + + public Iterator getMacros() + { + return macros.iterator(); + } + + public void exitCompilationUnit( IASTCompilationUnit compilationUnit ) + { + this.compilationUnit = compilationUnit; + } + + public void exitInclusion( IASTInclusion inclusion ) + { + inclusions.add( inclusion ); + } + + public void acceptMacro( IASTMacro macro ) + { + macros.add( macro ); + } + + /** + * @return + */ + public IASTCompilationUnit getCompilationUnit() + { + return compilationUnit; + } + + public class OffsetableIterator implements Iterator + { + private final Iterator declarationIter; + private final Iterator inclusionIter; + private final Iterator macroIter; + + private IASTOffsetableElement currentMacro = null, currentInclusion= null, currentDeclaration= null; + + public OffsetableIterator() + { + declarationIter = compilationUnit.getDeclarations(); + inclusionIter = inclusions.iterator(); + macroIter = macros.iterator(); + updateInclusionIterator(); + updateDeclarationIterator(); + updateMacroIterator(); + } + + private Object updateDeclarationIterator() + { + Object offsetable = currentDeclaration; + currentDeclaration = ( declarationIter.hasNext() ) ? (IASTOffsetableElement)declarationIter.next() : null; + return offsetable; + } + + private Object updateMacroIterator() + { + Object offsetable = currentMacro; + currentMacro = ( macroIter.hasNext() ) ? (IASTOffsetableElement)macroIter.next() : null; + return offsetable; + } + + private Object updateInclusionIterator() + { + Object offsetable = currentInclusion; + currentInclusion = ( inclusionIter.hasNext() ) ? (IASTOffsetableElement)inclusionIter.next() : null; + return offsetable; + } + /* (non-Javadoc) + * @see java.util.Iterator#hasNext() + */ + public boolean hasNext() { + return (( currentMacro == null && currentInclusion == null && currentDeclaration == null ) ? + false : true); + } + + /* (non-Javadoc) + * @see java.util.Iterator#next() + */ + public Object next() { + // case 1: all are null + if( ! hasNext() ) + throw new NoSuchElementException(); + + // case 2: two of three are null + if( currentMacro == null && currentInclusion == null ) + return updateDeclarationIterator(); + if( currentDeclaration == null && currentInclusion == null ) + return updateMacroIterator(); + if( currentMacro == null && currentDeclaration == null ) + return updateInclusionIterator(); + + // case 3: 1 is null + if( currentMacro == null ) + if( currentDeclaration.getElementStartingOffset() < currentInclusion.getElementStartingOffset() ) + return updateDeclarationIterator(); + else + return updateInclusionIterator(); + + if( currentInclusion == null ) + if( currentDeclaration.getElementStartingOffset() < currentMacro.getElementStartingOffset() ) + return updateDeclarationIterator(); + else + return updateMacroIterator(); + + if( currentDeclaration == null ) + if( currentInclusion.getElementStartingOffset() < currentMacro.getElementStartingOffset() ) + return updateInclusionIterator(); + else + return updateMacroIterator(); + + // case 4: none are null + if( currentInclusion.getElementStartingOffset() < currentMacro.getElementStartingOffset() && + currentInclusion.getElementStartingOffset() < currentDeclaration.getElementStartingOffset() ) + return updateInclusionIterator(); + + if( currentMacro.getElementStartingOffset() < currentInclusion.getElementStartingOffset() && + currentMacro.getElementStartingOffset() < currentDeclaration.getElementStartingOffset() ) + return updateMacroIterator(); + // only remaining case + return updateDeclarationIterator(); + } + + /* (non-Javadoc) + * @see java.util.Iterator#remove() + */ + public void remove() { + throw new UnsupportedOperationException( "OffsetableIterator is a const iterator"); + } + } + + public Iterator iterateOffsetableElements() + { + return new OffsetableIterator(); + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java index d04714ccaf9..d2febad6cab 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java @@ -28,7 +28,6 @@ import org.eclipse.cdt.core.parser.Backtrack; import org.eclipse.cdt.core.parser.EndOfFile; import org.eclipse.cdt.core.parser.IMacroDescriptor; import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.IParserCallback; import org.eclipse.cdt.core.parser.IProblemReporter; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScannerInfo; @@ -388,11 +387,6 @@ public class Scanner implements IScanner { this.mode = mode; } - private IParserCallback callback; - public void setCallback(IParserCallback c) { - callback = c; - } - private int getChar() throws ScannerException { return getChar( false ); @@ -1671,7 +1665,7 @@ public class Scanner implements IScanner { IParser parser = ParserFactory.createParser(trial, new NullSourceElementRequestor(), ParserMode.QUICK_PARSE ); try { - IASTExpression exp = parser.expression(null); + IASTExpression exp = parser.expression(); if( exp.evaluateExpression() == 0 ) return false; } catch( Backtrack b ) @@ -1815,11 +1809,6 @@ public class Scanner implements IScanner { if( mode == ParserMode.QUICK_PARSE ) { - if( callback != null ) - { - callback.inclusionEnd(callback.inclusionBegin( f, offset, beginningOffset, !useIncludePath )); - } - if( requestor != null ) { IASTInclusion i = astFactory.createInclusion( f, "", !useIncludePath, beginningOffset, @@ -1986,13 +1975,6 @@ public class Scanner implements IScanner { if (throwExceptionOnBadPreprocessorSyntax) throw new ScannerException(BAD_PP + contextStack.getCurrentContext().getOffset()); } - - // call the callback accordingly - if( callback != null ) - { - // NOTE: return value is ignored! - callback.macro( key, offset, beginning, contextStack.getCurrentContext().getOffset() ); - } if( requestor != null ) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TokenDuple.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TokenDuple.java index 2b43955784a..30dc21ec0e1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TokenDuple.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TokenDuple.java @@ -92,5 +92,20 @@ public class TokenDuple implements ITokenDuple { { return ( firstToken == lastToken ); } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ITokenDuple#length() + */ + public int length() + { + int count = 0; + Iterator i = iterator(); + while( i.hasNext() ) + { + ++count; + i.next(); + } + return count; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTInclusion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTInclusion.java index 0b4ecff141e..eb2e4e46086 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTInclusion.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTInclusion.java @@ -90,7 +90,7 @@ public class ASTInclusion implements IASTInclusion { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.ast.IOffsetableElementRW#setNameOffset(int) */ - public void setNameOffset(int o) { + public void setElementNameOffset(int o) { nameOffset = o; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java index 695c48e5938..00411afe25e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java @@ -47,7 +47,7 @@ public class ASTMacro implements IASTMacro { /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IOffsetableElementRW#setNameOffset(int) */ - public void setNameOffset(int o) { + public void setElementNameOffset(int o) { nameOffset = o; } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java index 9ed2cc25f66..76727165b67 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java @@ -27,7 +27,7 @@ public class BaseASTFactory { IASTMacro m = new ASTMacro( name ); m.setStartingOffset( startingOffset ); m.setEndingOffset( endingOffset ); - m.setNameOffset( nameOffset ); + m.setElementNameOffset( nameOffset ); return m; } @@ -38,7 +38,7 @@ public class BaseASTFactory { IASTInclusion inclusion = new ASTInclusion( name, fileName, local ); inclusion.setStartingOffset( startingOffset ); inclusion.setEndingOffset( endingOffset ); - inclusion.setNameOffset( nameOffset ); + inclusion.setElementNameOffset( nameOffset ); return inclusion; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTBaseSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTBaseSpecifier.java similarity index 71% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTBaseSpecifier.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTBaseSpecifier.java index dc75d3ec985..f28bdaf0824 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTBaseSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTBaseSpecifier.java @@ -8,9 +8,10 @@ * Contributors: * IBM Rational Software - Initial API and implementation ***********************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast; +package org.eclipse.cdt.internal.core.parser.ast.full; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; +import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; @@ -24,10 +25,10 @@ public class ASTBaseSpecifier implements IASTBaseSpecifier { private final boolean isVirtual; private final ASTAccessVisibility visibility; - public ASTBaseSpecifier( IASTClassSpecifier c, ASTAccessVisibility a, boolean virtual ) + public ASTBaseSpecifier( IASTClassSpecifier classSpec, ASTAccessVisibility a, boolean virtual ) { isVirtual = virtual; - baseClass = c; + baseClass = classSpec; visibility = a; } @@ -48,8 +49,16 @@ public class ASTBaseSpecifier implements IASTBaseSpecifier { /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier#getParent() */ - public IASTClassSpecifier getParent() { - return baseClass; + public String getParentClassName() { + return baseClass.getName(); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier#getParentClassSpecifier() + */ + public IASTClassSpecifier getParentClassSpecifier() throws ASTNotImplementedException + { + return baseClass; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTClassSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTClassSpecifier.java index 08739b77777..5a1fd297c65 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTClassSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTClassSpecifier.java @@ -14,6 +14,7 @@ import java.util.Iterator; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTClassKind; +import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTTemplate; import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol; @@ -26,7 +27,7 @@ import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable; */ public class ASTClassSpecifier implements IASTFClassSpecifier, IPSTSymbolExtension { - private final IDerivableContainerSymbol symbol; + private final IDerivableContainerSymbol symbol; private final ASTClassKind classKind; private final ClassNameType type; private final String name; @@ -86,7 +87,7 @@ public class ASTClassSpecifier implements IASTFClassSpecifier, IPSTSymbolExtensi /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ - public void setNameOffset(int o) { + public void setElementNameOffset(int o) { nameOffset = o; } @@ -152,4 +153,22 @@ public class ASTClassSpecifier implements IASTFClassSpecifier, IPSTSymbolExtensi return null; } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#setCurrentVisibility(org.eclipse.cdt.core.parser.ast.ASTAccessVisibility) + */ + public void setCurrentVisibility(ASTAccessVisibility visibility) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope() + */ + public IASTScope getOwnerScope() + { + return null; + } + + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTLinkageSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTLinkageSpecification.java index 966c440a3fa..819cc775b55 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTLinkageSpecification.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTLinkageSpecification.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.parser.ast.full; import java.util.Iterator; import org.eclipse.cdt.core.parser.ast.IASTScope; +import org.eclipse.cdt.internal.core.parser.ast.Offsets; import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; import org.eclipse.cdt.internal.core.parser.pst.ISymbol; @@ -22,11 +23,12 @@ import org.eclipse.cdt.internal.core.parser.pst.ISymbol; */ public class ASTLinkageSpecification implements IASTFLinkageSpecification { - public ASTLinkageSpecification( IContainerSymbol symbol, String linkage ) + public ASTLinkageSpecification( IContainerSymbol symbol, String linkage, int startingOffset ) { this.symbol = symbol; symbol.setASTNode( this ); this.linkage = linkage; + setStartingOffset(startingOffset); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() @@ -65,4 +67,34 @@ public class ASTLinkageSpecification implements IASTFLinkageSpecification { return (IPSTContainerExtension)symbol.getContainingSymbol().getASTNode(); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) + */ + public void setStartingOffset(int o) + { + offsets.setStartingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) + */ + public void setEndingOffset(int o) + { + offsets.setEndingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() + */ + public int getElementStartingOffset() + { + return offsets.getElementStartingOffset(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() + */ + public int getElementEndingOffset() + { + return offsets.getElementEndingOffset(); + } + private Offsets offsets = new Offsets(); + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTNamespaceDefinition.java index 3006da0959c..47df52d8de1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTNamespaceDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTNamespaceDefinition.java @@ -64,7 +64,7 @@ public class ASTNamespaceDefinition implements IASTFNamespaceDefinition { /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ - public void setNameOffset(int o) { + public void setElementNameOffset(int o) { nameOffset = o; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTUsingDirective.java index d376106c115..3090e4a850a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTUsingDirective.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTUsingDirective.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.parser.ast.full; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; +import org.eclipse.cdt.internal.core.parser.ast.Offsets; /** * @author jcamelon @@ -19,11 +20,14 @@ import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; */ public class ASTUsingDirective implements IASTUsingDirective { - private final String namespaceName; + private final String namespaceName; + private Offsets offsets = new Offsets(); - public ASTUsingDirective( String namespace ) + public ASTUsingDirective( String namespace, int startingOffset, int endingOffset ) { namespaceName = namespace; + offsets.setStartingOffset(startingOffset); + offsets.setEndingOffset( endingOffset ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTUsingDirective#getNamespaceName() @@ -37,6 +41,34 @@ public class ASTUsingDirective implements IASTUsingDirective { public IASTScope getOwnerScope() { return null; //TODO } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) + */ + public void setStartingOffset(int o) + { + offsets.setStartingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) + */ + public void setEndingOffset(int o) + { + offsets.setEndingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() + */ + public int getElementStartingOffset() + { + return offsets.getElementStartingOffset(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() + */ + public int getElementEndingOffset() + { + return offsets.getElementEndingOffset(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/BaseIterator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/BaseIterator.java index 8c176e9054e..07bcffe7ee3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/BaseIterator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/BaseIterator.java @@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.core.parser.ast.full; import java.util.Iterator; import java.util.List; -import org.eclipse.cdt.internal.core.parser.ast.ASTBaseSpecifier; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable; /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/FullParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/FullParseASTFactory.java index d91953b9797..54956fa3c2d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/FullParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/FullParseASTFactory.java @@ -18,8 +18,10 @@ import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTClassKind; +import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; import org.eclipse.cdt.core.parser.ast.IASTConstructorMemberInitializer; @@ -35,6 +37,8 @@ import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTPointerToFunction; +import org.eclipse.cdt.core.parser.ast.IASTPointerToMethod; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTTemplate; @@ -43,15 +47,14 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypedef; +import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType; import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.SimpleType; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParameterKind; +import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type; import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory; import org.eclipse.cdt.internal.core.parser.ast.IASTArrayModifier; import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; @@ -69,7 +72,7 @@ public class FullParseASTFactory extends BaseASTFactory implements IASTFactory { public IASTUsingDirective createUsingDirective( IASTScope scope, - ITokenDuple duple) + ITokenDuple duple, int startingOffset, int endingOffset) throws Backtrack { Iterator iter = duple.iterator(); IToken t1 = (IToken)iter.next(); @@ -109,7 +112,7 @@ public class FullParseASTFactory extends BaseASTFactory implements IASTFactory { handlePSTException( pste ); } - IASTUsingDirective astUD = new ASTUsingDirective( duple.toString() ); + IASTUsingDirective astUD = new ASTUsingDirective( duple.toString(), startingOffset, endingOffset ); return astUD; } @@ -145,7 +148,7 @@ public class FullParseASTFactory extends BaseASTFactory implements IASTFactory { IASTFNamespaceDefinition namespaceDefinition = new ASTNamespaceDefinition( namespaceSymbol, identifier ); namespaceDefinition.setStartingOffset( first ); if( identifier != "" ) - namespaceDefinition.setNameOffset( nameOffset ); + namespaceDefinition.setElementNameOffset( nameOffset ); return namespaceDefinition; } @@ -154,9 +157,9 @@ public class FullParseASTFactory extends BaseASTFactory implements IASTFactory { return compilationUnit; } - public IASTLinkageSpecification createLinkageSpecification(IASTScope scope, String spec) { + public IASTLinkageSpecification createLinkageSpecification(IASTScope scope, String spec, int startingOffset) { IContainerSymbol symbol = pst.newContainerSymbol("", ParserSymbolTable.TypeInfo.t_linkage ); - IASTFLinkageSpecification linkage = new ASTLinkageSpecification( symbol, spec); + IASTFLinkageSpecification linkage = new ASTLinkageSpecification( symbol, spec, startingOffset); return linkage; } @@ -170,7 +173,7 @@ public class FullParseASTFactory extends BaseASTFactory implements IASTFactory { /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope, boolean, org.eclipse.cdt.internal.core.parser.TokenDuple) */ - public IASTUsingDeclaration createUsingDeclaration(IASTScope scope, boolean isTypeName, ITokenDuple name) { + public IASTUsingDeclaration createUsingDeclaration(IASTScope scope, boolean isTypeName, ITokenDuple name, int startingOffset, int endingOffset) { // TODO Auto-generated method stub return null; } @@ -273,7 +276,7 @@ public class FullParseASTFactory extends BaseASTFactory implements IASTFactory { /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createSimpleTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.SimpleType, org.eclipse.cdt.core.parser.ITokenDuple, boolean, boolean, boolean, boolean) */ - public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(SimpleType kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename) + public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename) { // TODO Auto-generated method stub return null; @@ -345,7 +348,7 @@ public class FullParseASTFactory extends BaseASTFactory implements IASTFactory { /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateParameter(org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParameterKind, org.eclipse.cdt.core.parser.IToken, java.lang.String, org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration) */ - public IASTTemplateParameter createTemplateParameter(ParameterKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List parms) + public IASTTemplateParameter createTemplateParameter(IASTTemplateParameter.ParamKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List parms) { // TODO Auto-generated method stub return null; @@ -372,7 +375,34 @@ public class FullParseASTFactory extends BaseASTFactory implements IASTFactory { /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTypedef(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration) */ - public IASTTypedef createTypedef(IASTScope scope, String name, IASTAbstractDeclaration mapping, int startingOffset, int nameOffset) + public IASTTypedefDeclaration createTypedef(IASTScope scope, String name, IASTAbstractDeclaration mapping, int startingOffset, int nameOffset) + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope, boolean, org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier, java.util.List, java.util.List) + */ + public IASTAbstractTypeSpecifierDeclaration createTypeSpecDeclaration(IASTScope scope, IASTTypeSpecifier typeSpecifier, IASTTemplate template, int startingOffset, int endingOffset) + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createPointerToFunction(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, java.util.List, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification, boolean, boolean, boolean, int, int, org.eclipse.cdt.core.parser.ast.IASTTemplate) + */ + public IASTPointerToFunction createPointerToFunction(IASTScope scope, String name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, IASTTemplate ownerTemplate, ASTPointerOperator pointerOperator) + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createPointerToMethod(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, java.util.List, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification, boolean, boolean, boolean, int, int, org.eclipse.cdt.core.parser.ast.IASTTemplate, boolean, boolean, boolean, boolean, boolean, boolean, boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility) + */ + public IASTPointerToMethod createPointerToMethod(IASTScope scope, String name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, IASTTemplate ownerTemplate, boolean isConst, boolean isVolatile, boolean isConstructor, boolean isDestructor, boolean isVirtual, boolean isExplicit, boolean isPureVirtual, ASTAccessVisibility visibility, ASTPointerOperator pointerOperator) { // TODO Auto-generated method stub return null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTAbstractDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTAbstractDeclaration.java index 8dec57e7a5d..856e870654d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTAbstractDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTAbstractDeclaration.java @@ -20,7 +20,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; * @author jcamelon * */ -public class ASTAbstractDeclaration implements IASTAbstractDeclaration +public class ASTAbstractDeclaration implements IASTAbstractDeclaration { private final boolean isConst; private final IASTTypeSpecifier typeSpecifier; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTAbstractTypeSpecifierDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTAbstractTypeSpecifierDeclaration.java new file mode 100644 index 00000000000..291c4e9e032 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTAbstractTypeSpecifierDeclaration.java @@ -0,0 +1,89 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.internal.core.parser.ast.quick; + +import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTScope; +import org.eclipse.cdt.core.parser.ast.IASTTemplate; +import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; +import org.eclipse.cdt.internal.core.parser.ast.Offsets; + +/** + * @author jcamelon + * + */ +public class ASTAbstractTypeSpecifierDeclaration + extends ASTDeclaration + implements IASTAbstractTypeSpecifierDeclaration +{ + private final IASTTemplate ownerTemplate; + private final IASTTypeSpecifier typeSpecifier; + /** + * @param scope + * @param typeSpecifier + */ + public ASTAbstractTypeSpecifierDeclaration(IASTScope scope, IASTTypeSpecifier typeSpecifier, IASTTemplate ownerTemplate, int startingOffset, int endingOffset) + { + super( ownerTemplate != null ? null : scope ); + this.typeSpecifier = typeSpecifier; + this.ownerTemplate = ownerTemplate; + if( ownerTemplate != null ) + ownerTemplate.setOwnedDeclaration( this ); + setStartingOffset(startingOffset); + setEndingOffset(endingOffset); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getTypeSpecifier() + */ + public IASTTypeSpecifier getTypeSpecifier() + { + return typeSpecifier; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTTemplatedDeclaration#getOwnerTemplateDeclaration() + */ + public IASTTemplate getOwnerTemplateDeclaration() + { + return ownerTemplate; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) + */ + public void setStartingOffset(int o) + { + offsets.setStartingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) + */ + public void setEndingOffset(int o) + { + offsets.setEndingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() + */ + public int getElementStartingOffset() + { + return offsets.getElementStartingOffset(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() + */ + public int getElementEndingOffset() + { + return offsets.getElementEndingOffset(); + } + private Offsets offsets = new Offsets(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTBaseSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTBaseSpecifier.java index b5f4176705e..adb1bc6debd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTBaseSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTBaseSpecifier.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.core.parser.ast.quick; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; +import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; @@ -22,11 +23,11 @@ public class ASTBaseSpecifier implements IASTBaseSpecifier { private final ASTAccessVisibility visibility; private final boolean isVirtual; - private final IASTClassSpecifier parentClass; + private final String parentClassName; - public ASTBaseSpecifier( IASTClassSpecifier classSpec, boolean v, ASTAccessVisibility a ) + public ASTBaseSpecifier( String className, boolean v, ASTAccessVisibility a ) { - parentClass = classSpec; + parentClassName = className; isVirtual = v; visibility = a; } @@ -47,8 +48,15 @@ public class ASTBaseSpecifier implements IASTBaseSpecifier { /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier#getParent() */ - public IASTClassSpecifier getParent() { - return parentClass; + public String getParentClassName() { + return parentClassName; } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier#getParentClassSpecifier() + */ + public IASTClassSpecifier getParentClassSpecifier() throws ASTNotImplementedException + { + throw new ASTNotImplementedException(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java index 0078d3e36e9..56b593358e8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java @@ -24,10 +24,10 @@ import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets; * @author jcamelon * */ -public class ASTClassSpecifier - extends ASTQualifiedNamedDeclaration - implements IASTQClassSpecifier, IASTQScope +public class ASTClassSpecifier implements IASTQClassSpecifier, IASTQScope { + + private final IASTScope scope; public ASTClassSpecifier( IASTScope scope, String name, @@ -36,15 +36,15 @@ public class ASTClassSpecifier ASTAccessVisibility access, IASTTemplate ownerTemplate) { - super(scope, name ); + this.scope = scope; + qualifiedNameElement = new ASTQualifiedNamedElement( scope, name ); classNameType = type; classKind = kind; this.access = access; this.name = name; - templateOwner = ownerTemplate; } - private IASTTemplate templateOwner = null; + private final ASTQualifiedNamedElement qualifiedNameElement; private final String name; private List declarations = new ArrayList(); private List baseClauses = new ArrayList(); @@ -104,17 +104,11 @@ public class ASTClassSpecifier /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ - public void setNameOffset(int o) + public void setElementNameOffset(int o) { offsets.setNameOffset(o); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplatedDeclaration#getOwnerTemplateDeclaration() - */ - public IASTTemplate getOwnerTemplateDeclaration() - { - return templateOwner; - } + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) */ @@ -157,4 +151,26 @@ public class ASTClassSpecifier { baseClauses.add(baseSpecifier); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() + */ + public String[] getFullyQualifiedName() + { + return qualifiedNameElement.getFullyQualifiedName(); + } + /** + * @return + */ + public IASTScope getOwnerScope() + { + return scope; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#setCurrentVisibility(org.eclipse.cdt.core.parser.ast.ASTAccessVisibility) + */ + public void setCurrentVisibility(ASTAccessVisibility visibility) + { + this.access = visibility; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTDeclaration.java index 4fb3635bcb3..94e99cae6ef 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTDeclaration.java @@ -23,6 +23,8 @@ public class ASTDeclaration implements IASTDeclaration { public ASTDeclaration( IASTScope scope ) { this.scope = scope; + if( scope != null && scope instanceof IASTQScope ) + ((IASTQScope)scope).addDeclaration(this); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTElaboratedTypeSpecifier.java index 9e9198bef57..ecf0423d8b4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTElaboratedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTElaboratedTypeSpecifier.java @@ -40,7 +40,7 @@ public class ASTElaboratedTypeSpecifier implements IASTElaboratedTypeSpecifier /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier#getTypeName() */ - public String getTypeName() + public String getName() { return typeName; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerationSpecifier.java index 25d546138da..5d4bccbc656 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerationSpecifier.java @@ -57,7 +57,7 @@ public class ASTEnumerationSpecifier /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ - public void setNameOffset(int o) + public void setElementNameOffset(int o) { offsets.setNameOffset(o); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerator.java index 83950602485..ee8f69ed4b6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerator.java @@ -61,7 +61,7 @@ public class ASTEnumerator /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ - public void setNameOffset(int o) + public void setElementNameOffset(int o) { offsets.setNameOffset(o); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTFunction.java index 9175a4dc201..fbd0214fb03 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTFunction.java @@ -33,7 +33,7 @@ public class ASTFunction extends ASTDeclaration implements IASTFunction public ASTFunction(IASTScope scope, String name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, IASTTemplate ownerTemplate ) { - super(scope); + super(ownerTemplate != null ? null : scope ); this.name = name; this.parms = parameters; this.returnType = returnType; @@ -42,6 +42,8 @@ public class ASTFunction extends ASTDeclaration implements IASTFunction this.isFriend = isFriend; this.isStatic = isStatic; this.ownerTemplateDeclaration = ownerTemplate; + if( ownerTemplate != null ) + ownerTemplate.setOwnedDeclaration( this ); offsets.setStartingOffset( startOffset ); offsets.setNameOffset( nameOffset ); } @@ -115,7 +117,7 @@ public class ASTFunction extends ASTDeclaration implements IASTFunction /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ - public void setNameOffset(int o) + public void setElementNameOffset(int o) { offsets.setNameOffset( o ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLinkageSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLinkageSpecification.java index 499695fc915..c657e38a8e7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLinkageSpecification.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLinkageSpecification.java @@ -17,6 +17,7 @@ import java.util.List; import org.eclipse.cdt.core.parser.ast.IASTDeclaration; import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; import org.eclipse.cdt.core.parser.ast.IASTScope; +import org.eclipse.cdt.internal.core.parser.ast.Offsets; /** * @author jcamelon @@ -28,10 +29,11 @@ public class ASTLinkageSpecification private final String linkage; - public ASTLinkageSpecification( IASTScope scope, String linkage ) + public ASTLinkageSpecification( IASTScope scope, String linkage, int startingOffset ) { super( scope ); this.linkage = linkage; + setStartingOffset(startingOffset); } /* (non-Javadoc) @@ -56,4 +58,34 @@ public class ASTLinkageSpecification declarations.add( declaration ); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) + */ + public void setStartingOffset(int o) + { + offsets.setStartingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) + */ + public void setEndingOffset(int o) + { + offsets.setEndingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() + */ + public int getElementStartingOffset() + { + return offsets.getElementStartingOffset(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() + */ + public int getElementEndingOffset() + { + return offsets.getElementEndingOffset(); + } + private Offsets offsets = new Offsets(); + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceDefinition.java index e908dc3dd0c..db353460338 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceDefinition.java @@ -23,14 +23,16 @@ import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets; * @author jcamelon * */ -public class ASTNamespaceDefinition extends ASTQualifiedNamedDeclaration implements IASTNamespaceDefinition, IASTQScope { +public class ASTNamespaceDefinition extends ASTDeclaration implements IASTNamespaceDefinition, IASTQScope { private final String name; - private NamedOffsets offsets = new NamedOffsets(); + private NamedOffsets offsets = new NamedOffsets(); + private final ASTQualifiedNamedElement qualifiedNameElement; public ASTNamespaceDefinition( IASTScope scope, String name ) { - super( scope, name ); + super( scope ); + qualifiedNameElement = new ASTQualifiedNamedElement( scope, name ); this.name = name; } /* (non-Javadoc) @@ -50,7 +52,7 @@ public class ASTNamespaceDefinition extends ASTQualifiedNamedDeclaration impleme /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ - public void setNameOffset(int o) { + public void setElementNameOffset(int o) { offsets.setNameOffset( o ); } @@ -96,4 +98,11 @@ public class ASTNamespaceDefinition extends ASTQualifiedNamedDeclaration impleme public void addDeclaration(IASTDeclaration declaration) { declarations.add( declaration ); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() + */ + public String[] getFullyQualifiedName() + { + return qualifiedNameElement.getFullyQualifiedName(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTPointerToFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTPointerToFunction.java new file mode 100644 index 00000000000..55e49bd2d32 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTPointerToFunction.java @@ -0,0 +1,72 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.internal.core.parser.ast.quick; + +import java.util.List; + +import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; +import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; +import org.eclipse.cdt.core.parser.ast.IASTPointerToFunction; +import org.eclipse.cdt.core.parser.ast.IASTScope; +import org.eclipse.cdt.core.parser.ast.IASTTemplate; + +/** + * @author jcamelon + * + */ +public class ASTPointerToFunction + extends ASTFunction + implements IASTPointerToFunction +{ + + private final ASTPointerOperator pointerOperator; + + /** + * @param scope + * @param name + * @param parameters + * @param returnType + * @param exception + * @param isInline + * @param isFriend + * @param isStatic + * @param startOffset + * @param nameOffset + * @param ownerTemplate + */ + public ASTPointerToFunction(IASTScope scope, String name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, IASTTemplate ownerTemplate, ASTPointerOperator pointerOperator) + { + super( + scope, + name, + parameters, + returnType, + exception, + isInline, + isFriend, + isStatic, + startOffset, + nameOffset, + ownerTemplate); + this.pointerOperator = pointerOperator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTPointerOperatorOwner#getPointerOperator() + */ + public ASTPointerOperator getPointerOperator() + { + return pointerOperator; + } + + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTPointerToMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTPointerToMethod.java new file mode 100644 index 00000000000..bd634495cc1 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTPointerToMethod.java @@ -0,0 +1,87 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.internal.core.parser.ast.quick; + +import java.util.List; + +import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; +import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; +import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; +import org.eclipse.cdt.core.parser.ast.IASTPointerToMethod; +import org.eclipse.cdt.core.parser.ast.IASTScope; +import org.eclipse.cdt.core.parser.ast.IASTTemplate; + +/** + * @author jcamelon + * + */ +public class ASTPointerToMethod + extends ASTMethod + implements IASTPointerToMethod +{ + + private final ASTPointerOperator pointerOperator; + + /** + * @param scope + * @param name + * @param parameters + * @param returnType + * @param exception + * @param isInline + * @param isFriend + * @param isStatic + * @param startOffset + * @param nameOffset + * @param ownerTemplate + * @param isConst + * @param isVolatile + * @param isConstructor + * @param isDestructor + * @param isVirtual + * @param isExplicit + * @param isPureVirtual + * @param visibility + */ + public ASTPointerToMethod(IASTScope scope, String name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, IASTTemplate ownerTemplate, boolean isConst, boolean isVolatile, boolean isConstructor, boolean isDestructor, boolean isVirtual, boolean isExplicit, boolean isPureVirtual, ASTAccessVisibility visibility, ASTPointerOperator pointerOperator) + { + super( + scope, + name, + parameters, + returnType, + exception, + isInline, + isFriend, + isStatic, + startOffset, + nameOffset, + ownerTemplate, + isConst, + isVolatile, + isConstructor, + isDestructor, + isVirtual, + isExplicit, + isPureVirtual, + visibility); + this.pointerOperator = pointerOperator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTPointerOperatorOwner#getPointerOperator() + */ + public ASTPointerOperator getPointerOperator() + { + return pointerOperator; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTQualifiedNamedDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTQualifiedNamedElement.java similarity index 82% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTQualifiedNamedDeclaration.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTQualifiedNamedElement.java index d1dc663702c..5c2b272cbee 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTQualifiedNamedDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTQualifiedNamedElement.java @@ -13,26 +13,25 @@ package org.eclipse.cdt.internal.core.parser.ast.quick; import java.util.Stack; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; import org.eclipse.cdt.core.parser.ast.IASTScope; +import org.eclipse.cdt.core.parser.ast.IASTScopedElement; /** * @author jcamelon * */ -public class ASTQualifiedNamedDeclaration extends ASTDeclaration +public class ASTQualifiedNamedElement { /** * @param scope */ - public ASTQualifiedNamedDeclaration(IASTScope scope, String name ) + public ASTQualifiedNamedElement(IASTScope scope, String name ) { - super(scope); - Stack names = new Stack(); - IASTScope parent = getOwnerScope(); + Stack names = new Stack(); + IASTScope parent = scope; names.push( name ); // push on our own name while (parent != null) @@ -41,7 +40,8 @@ public class ASTQualifiedNamedDeclaration extends ASTDeclaration || parent instanceof IASTClassSpecifier ) { names.push(((IASTOffsetableNamedElement)parent).getName()); - parent = ((IASTDeclaration)parent).getOwnerScope(); + if( parent instanceof IASTScopedElement ) + parent = ((IASTScopedElement)parent).getOwnerScope(); } else break; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTSimpleTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTSimpleTypeSpecifier.java index b73800fd273..49633e0dcb2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTSimpleTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTSimpleTypeSpecifier.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier { private final boolean isTypename; - private final SimpleType kind; + private final Type kind; private final String typeName; private final boolean isLong, isShort, isSigned, isUnsigned; @@ -31,19 +31,19 @@ public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier static { nameMap = new Hashtable(); - nameMap.put( SimpleType.BOOL, "bool"); - nameMap.put( SimpleType.CHAR, "char"); - nameMap.put( SimpleType.DOUBLE, "double"); - nameMap.put( SimpleType.FLOAT, "float"); - nameMap.put( SimpleType.INT, "int"); - nameMap.put( SimpleType.VOID, "void" ); - nameMap.put( SimpleType.WCHAR_T, "wchar_t" ); + nameMap.put( Type.BOOL, "bool"); + nameMap.put( Type.CHAR, "char"); + nameMap.put( Type.DOUBLE, "double"); + nameMap.put( Type.FLOAT, "float"); + nameMap.put( Type.INT, "int"); + nameMap.put( Type.VOID, "void" ); + nameMap.put( Type.WCHAR_T, "wchar_t" ); } /** * @param kind * @param typeName */ - public ASTSimpleTypeSpecifier(SimpleType kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename) + public ASTSimpleTypeSpecifier(Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename) { this.kind = kind; this.isLong = isLong; @@ -54,17 +54,17 @@ public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier StringBuffer type = new StringBuffer(); - if( this.kind == IASTSimpleTypeSpecifier.SimpleType.CHAR || this.kind == IASTSimpleTypeSpecifier.SimpleType.WCHAR_T ) + if( this.kind == IASTSimpleTypeSpecifier.Type.CHAR || this.kind == IASTSimpleTypeSpecifier.Type.WCHAR_T ) { if (isUnsigned()) type.append("unsigned "); type.append( (String)nameMap.get( this.kind )); } - else if( this.kind == SimpleType.BOOL || this.kind == SimpleType.FLOAT || this.kind == SimpleType.VOID ) + else if( this.kind == Type.BOOL || this.kind == Type.FLOAT || this.kind == Type.VOID ) { type.append( (String) nameMap.get( this.kind )); } - else if( this.kind == SimpleType.INT ) + else if( this.kind == Type.INT ) { if (isUnsigned()) type.append("unsigned "); @@ -74,19 +74,19 @@ public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier type.append("long "); type.append( (String)nameMap.get( this.kind )); } - else if( this.kind == SimpleType.DOUBLE ) + else if( this.kind == Type.DOUBLE ) { if (isLong()) type.append("long "); type.append( (String)nameMap.get( this.kind )); } - else if( this.kind == SimpleType.TYPENAME || this.kind == SimpleType.TEMPLATE ) + else if( this.kind == Type.CLASS_OR_TYPENAME || this.kind == Type.TEMPLATE ) { if (isTypename() ) type.append("typename "); type.append(typeName.toString()); } - else if( this.kind == SimpleType.UNSPECIFIED ) + else if( this.kind == Type.UNSPECIFIED ) { if (isUnsigned()) type.append("unsigned "); @@ -103,7 +103,7 @@ public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#getType() */ - public SimpleType getType() + public Type getType() { return kind; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateParameter.java index 981bdaf19a0..93886eefea0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateParameter.java @@ -24,7 +24,7 @@ public class ASTTemplateParameter implements IASTTemplateParameter { private final List templateParms; private final IASTParameterDeclaration parameter; - private final ParameterKind kind; + private final ParamKind kind; private final String identifier; private final String defaultValue; /** @@ -33,7 +33,7 @@ public class ASTTemplateParameter implements IASTTemplateParameter * @param defaultValue * @param parameter */ - public ASTTemplateParameter(ParameterKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List templateParms) + public ASTTemplateParameter(ParamKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List templateParms) { this.kind = kind; this.identifier = identifier; @@ -44,7 +44,7 @@ public class ASTTemplateParameter implements IASTTemplateParameter /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameter#getTemplateParameterKind() */ - public ParameterKind getTemplateParameterKind() + public ParamKind getTemplateParameterKind() { return kind; } @@ -67,7 +67,13 @@ public class ASTTemplateParameter implements IASTTemplateParameter */ public Iterator getTemplateParameters() { - // TODO Auto-generated method stub return templateParms.iterator(); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameter#getParameterDeclaration() + */ + public IASTParameterDeclaration getParameterDeclaration() + { + return parameter; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypedef.java index 76b50330794..f843e16d002 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypedef.java @@ -12,14 +12,14 @@ package org.eclipse.cdt.internal.core.parser.ast.quick; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTypedef; +import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets; /** * @author jcamelon * */ -public class ASTTypedef extends ASTDeclaration implements IASTTypedef +public class ASTTypedef extends ASTDeclaration implements IASTTypedefDeclaration { private final String name; private final IASTAbstractDeclaration mapping; @@ -60,7 +60,7 @@ public class ASTTypedef extends ASTDeclaration implements IASTTypedef /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) */ - public void setNameOffset(int o) + public void setElementNameOffset(int o) { // TODO Auto-generated method stub diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDeclaration.java index f08ff71205b..6c344767960 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDeclaration.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.parser.ast.quick; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; +import org.eclipse.cdt.internal.core.parser.ast.Offsets; /** * @author jcamelon @@ -24,11 +25,13 @@ public class ASTUsingDeclaration private final boolean isTypename; private final String mappingName; - public ASTUsingDeclaration( IASTScope scope, boolean isTypeName, String mappingName ) + public ASTUsingDeclaration( IASTScope scope, boolean isTypeName, String mappingName, int startingOffset, int endingOffset ) { super( scope ); isTypename = isTypeName; this.mappingName = mappingName; + setStartingOffset(startingOffset); + setEndingOffset(endingOffset); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration#isTypename() @@ -44,4 +47,33 @@ public class ASTUsingDeclaration return mappingName; } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) + */ + public void setStartingOffset(int o) + { + offsets.setStartingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) + */ + public void setEndingOffset(int o) + { + offsets.setEndingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() + */ + public int getElementStartingOffset() + { + return offsets.getElementStartingOffset(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() + */ + public int getElementEndingOffset() + { + return offsets.getElementEndingOffset(); + } + private Offsets offsets = new Offsets(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDirective.java index 16c8d464399..b36efa3a62f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDirective.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDirective.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.parser.ast.quick; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; +import org.eclipse.cdt.internal.core.parser.ast.Offsets; /** * @author jcamelon @@ -22,17 +23,49 @@ public class ASTUsingDirective implements IASTUsingDirective { - public ASTUsingDirective( IASTScope scope, String name ) + public ASTUsingDirective( IASTScope scope, String name, int startingOffset, int endingOffset ) { super( scope ); - this.namespaceName = name; + this.namespaceName = name; + setStartingOffset(startingOffset); + setEndingOffset(endingOffset); + } - private final String namespaceName; + private final String namespaceName; + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTUsingDirective#getNamespaceName() */ public String getNamespaceName() { return namespaceName; } - + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) + */ + public void setStartingOffset(int o) + { + offsets.setStartingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) + */ + public void setEndingOffset(int o) + { + offsets.setEndingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() + */ + public int getElementStartingOffset() + { + return offsets.getElementStartingOffset(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() + */ + public int getElementEndingOffset() + { + return offsets.getElementEndingOffset(); + } + private Offsets offsets = new Offsets(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTVariable.java index 3365ce1e789..30fbda0e194 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTVariable.java @@ -119,56 +119,50 @@ public class ASTVariable extends ASTDeclaration implements IASTVariable */ public IASTExpression getBitfieldExpression() { - // TODO Auto-generated method stub return bitfieldExpression; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public void setStartingOffset(int o) - { - // TODO Auto-generated method stub - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public void setEndingOffset(int o) - { - // TODO Auto-generated method stub - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() - */ - public int getElementStartingOffset() - { - // TODO Auto-generated method stub - return 0; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() - */ - public int getElementEndingOffset() - { - // TODO Auto-generated method stub - return 0; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getElementNameOffset() - */ - public int getElementNameOffset() - { - // TODO Auto-generated method stub - return 0; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) - { - // TODO Auto-generated method stub - - } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) + */ + public void setStartingOffset(int o) + { + offsets.setStartingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) + */ + public void setEndingOffset(int o) + { + offsets.setEndingOffset(o); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementStartingOffset() + */ + public int getElementStartingOffset() + { + return offsets.getElementStartingOffset(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getElementEndingOffset() + */ + public int getElementEndingOffset() + { + return offsets.getElementEndingOffset(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getElementNameOffset() + */ + public int getElementNameOffset() + { + return offsets.getElementNameOffset(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) + */ + public void setElementNameOffset(int o) + { + offsets.setNameOffset(o); + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java index 6edd4b7b070..8c543255d20 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java @@ -16,8 +16,10 @@ import org.eclipse.cdt.core.parser.Backtrack; import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTClassKind; +import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; @@ -35,6 +37,8 @@ import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTPointerToFunction; +import org.eclipse.cdt.core.parser.ast.IASTPointerToMethod; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTTemplate; @@ -43,15 +47,14 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypedef; +import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType; import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.SimpleType; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParameterKind; +import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type; import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory; import org.eclipse.cdt.internal.core.parser.ast.IASTArrayModifier; @@ -64,8 +67,8 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.ast.IASTFactory#createUsingDirective(org.eclipse.cdt.internal.core.parser.ast.IASTScope, org.eclipse.cdt.internal.core.parser.TokenDuple) */ - public IASTUsingDirective createUsingDirective(IASTScope scope, ITokenDuple duple) throws Backtrack { - return new ASTUsingDirective( scope, duple.toString() ); + public IASTUsingDirective createUsingDirective(IASTScope scope, ITokenDuple duple, int startingOffset, int endingOffset) throws Backtrack { + return new ASTUsingDirective( scope, duple.toString(), startingOffset, endingOffset ); } /* (non-Javadoc) @@ -84,7 +87,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory public IASTNamespaceDefinition createNamespaceDefinition(IASTScope scope, String identifier, int first, int nameOffset) { IASTNamespaceDefinition definition = new ASTNamespaceDefinition( scope, identifier ); definition.setStartingOffset( first ); - definition.setNameOffset( nameOffset ); + definition.setElementNameOffset( nameOffset ); return definition; } @@ -98,15 +101,15 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.ast.IASTFactory#createLinkageSpecification(java.lang.String) */ - public IASTLinkageSpecification createLinkageSpecification(IASTScope scope, String spec) { - return new ASTLinkageSpecification( scope, spec ); + public IASTLinkageSpecification createLinkageSpecification(IASTScope scope, String spec, int startingOffset) { + return new ASTLinkageSpecification( scope, spec, startingOffset ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope, boolean, org.eclipse.cdt.internal.core.parser.TokenDuple) */ - public IASTUsingDeclaration createUsingDeclaration(IASTScope scope, boolean isTypeName, ITokenDuple name) { - return new ASTUsingDeclaration( scope, isTypeName, name.toString() ); + public IASTUsingDeclaration createUsingDeclaration(IASTScope scope, boolean isTypeName, ITokenDuple name, int startingOffset, int endingOffset) { + return new ASTUsingDeclaration( scope, isTypeName, name.toString(), startingOffset, endingOffset ); } /* (non-Javadoc) @@ -115,7 +118,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory public IASTClassSpecifier createClassSpecifier(IASTScope scope, String name, ASTClassKind kind, ClassNameType type, ASTAccessVisibility access, IASTTemplate ownerTemplateDeclaration, int startingOffset, int nameOffset) { IASTClassSpecifier spec = new ASTClassSpecifier( scope, name, kind, type, access, ownerTemplateDeclaration ); spec.setStartingOffset( startingOffset ); - spec.setNameOffset( nameOffset ); + spec.setElementNameOffset( nameOffset ); return spec; } @@ -123,7 +126,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory * @see org.eclipse.cdt.core.parser.ast.IASTFactory#addBaseSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier, boolean, org.eclipse.cdt.core.parser.ast.AccessVisibility, java.lang.String) */ public void addBaseSpecifier(IASTClassSpecifier astClassSpec, boolean isVirtual, ASTAccessVisibility visibility, String string) { - IASTBaseSpecifier baseSpecifier = new ASTBaseSpecifier( astClassSpec, isVirtual, visibility ); + IASTBaseSpecifier baseSpecifier = new ASTBaseSpecifier( string, isVirtual, visibility ); ((IASTQClassSpecifier)astClassSpec).addBaseClass(baseSpecifier); } @@ -199,7 +202,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createSimpleTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.SimpleType, org.eclipse.cdt.core.parser.ITokenDuple) */ - public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(SimpleType kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename ) + public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename ) { return new ASTSimpleTypeSpecifier( kind, typeName, isShort, isLong, isSigned, isUnsigned, isTypename ); } @@ -263,7 +266,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateParameter(org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParameterKind, org.eclipse.cdt.core.parser.IToken, java.lang.String, org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration) */ - public IASTTemplateParameter createTemplateParameter(ParameterKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List parms) + public IASTTemplateParameter createTemplateParameter(IASTTemplateParameter.ParamKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List parms) { return new ASTTemplateParameter( kind, identifier, defaultValue, parameter, parms ); } @@ -287,10 +290,34 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTypedef(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration) */ - public IASTTypedef createTypedef(IASTScope scope, String name, IASTAbstractDeclaration mapping, int startingOffset, int nameOffset) + public IASTTypedefDeclaration createTypedef(IASTScope scope, String name, IASTAbstractDeclaration mapping, int startingOffset, int nameOffset) { return new ASTTypedef( scope, name, mapping, startingOffset, nameOffset ); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope, boolean, org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier, java.util.List, java.util.List) + */ + public IASTAbstractTypeSpecifierDeclaration createTypeSpecDeclaration(IASTScope scope, IASTTypeSpecifier typeSpecifier, IASTTemplate template, int startingOffset, int endingOffset) + { + return new ASTAbstractTypeSpecifierDeclaration( scope, typeSpecifier, template, startingOffset, endingOffset ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createPointerToFunction(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, java.util.List, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification, boolean, boolean, boolean, int, int, org.eclipse.cdt.core.parser.ast.IASTTemplate) + */ + public IASTPointerToFunction createPointerToFunction(IASTScope scope, String name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, IASTTemplate ownerTemplate, ASTPointerOperator pointerOperator) + { + return new ASTPointerToFunction( scope, name, parameters, returnType, exception, isInline, isFriend, isStatic, startOffset, nameOffset, ownerTemplate, pointerOperator); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createPointerToMethod(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, java.util.List, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification, boolean, boolean, boolean, int, int, org.eclipse.cdt.core.parser.ast.IASTTemplate, boolean, boolean, boolean, boolean, boolean, boolean, boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility) + */ + public IASTPointerToMethod createPointerToMethod(IASTScope scope, String name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, IASTTemplate ownerTemplate, boolean isConst, boolean isVolatile, boolean isConstructor, boolean isDestructor, boolean isVirtual, boolean isExplicit, boolean isPureVirtual, ASTAccessVisibility visibility, ASTPointerOperator pointerOperator) + { + return new ASTPointerToMethod(scope, name, parameters, returnType, exception, isInline, isFriend, isStatic, startOffset, nameOffset, ownerTemplate, isConst, isVolatile, isConstructor, isDestructor, isVirtual, isExplicit, isPureVirtual, visibility, pointerOperator); + } + } diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java index 8e46f6d1d21..9839568738c 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java @@ -29,6 +29,7 @@ import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ast.ASTClassKind; import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; +import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; import org.eclipse.cdt.core.parser.ast.IASTClassReference; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; @@ -43,11 +44,13 @@ import org.eclipse.cdt.core.parser.ast.IASTMacro; import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; +import org.eclipse.cdt.core.parser.ast.IASTPointerToFunction; +import org.eclipse.cdt.core.parser.ast.IASTPointerToMethod; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypedef; +import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTVariable; @@ -95,8 +98,11 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants public void acceptUsingDirective(IASTUsingDirective usageDirective) { } public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration) { } public void acceptASMDefinition(IASTASMDefinition asmDefinition) { } - public void acceptTypedef(IASTTypedef typedef) { } + public void acceptTypedef(IASTTypedefDeclaration typedef) { } public void acceptEnumerator(IASTEnumerator enumerator) { } + public void acceptAbstractTypeSpecDeclaration(IASTAbstractTypeSpecifierDeclaration abstractDeclaration) {} + public void acceptPointerToFunction(IASTPointerToFunction function) {} + public void acceptPointerToMethod(IASTPointerToMethod method) { } public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration){ if( searchPattern.getLimitTo() == DECLARATIONS || searchPattern.getLimitTo() == ALL_OCCURRENCES ){ @@ -356,4 +362,5 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants private IASTScope currentScope = null; private LinkedList scopeStack = new LinkedList(); + } diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 5924e6d4435..c1dfc98bf95 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,6 @@ +2003-07-17 John Camelon + Partially converted DOM to ISourceElementRequestor (requires refactoring of CModelBuilder & StuctureComparator modules in near future). + 2003-07-16 Alain Magloire Patch from Alex chapiro. diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index d357a7aa93b..3385bb5d120 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -501,7 +501,7 @@