diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java index 7d1cc7b638a..8aca7558fa4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java @@ -73,31 +73,20 @@ public class AST2SelectionParseBaseTest extends FileBasePluginTest { return tu.getNodeSelector(null).findNode(offset, length); } - /** - * @param string - * @param c - * @return - * @throws ParserException - */ - protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException { + protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems) throws ParserException { FileContent codeReader = FileContent.create("", code.toCharArray()); ScannerInfo scannerInfo = new ScannerInfo(); IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); ISourceCodeParser parser2 = null; - if( lang == ParserLanguage.CPP ) - { + if (lang == ParserLanguage.CPP) { ICPPParserExtensionConfiguration config = null; if (useGNUExtensions) config = new GPPParserExtensionConfiguration(); else config = new ANSICPPParserExtensionConfiguration(); - parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, - NULL_LOG, - config ); - } - else - { + parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config); + } else { ICParserExtensionConfiguration config = null; if (useGNUExtensions) @@ -105,56 +94,45 @@ public class AST2SelectionParseBaseTest extends FileBasePluginTest { else config = new ANSICParserExtensionConfiguration(); - parser2 = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, - NULL_LOG, config ); + parser2 = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config); } IASTTranslationUnit tu = parser2.parse(); - if( parser2.encounteredError() && expectNoProblems ) - throw new ParserException( "FAILURE"); //$NON-NLS-1$ + if (parser2.encounteredError() && expectNoProblems) + throw new ParserException("FAILURE"); //$NON-NLS-1$ - if( lang == ParserLanguage.C && expectNoProblems ) - { - assertEquals( CVisitor.getProblems(tu).length, 0 ); - assertEquals( tu.getPreprocessorProblems().length, 0 ); + if (lang == ParserLanguage.C && expectNoProblems) { + assertEquals(CVisitor.getProblems(tu).length, 0); + assertEquals(tu.getPreprocessorProblems().length, 0); + } else if (lang == ParserLanguage.CPP && expectNoProblems) { + assertEquals(CPPVisitor.getProblems(tu).length, 0); + assertEquals(tu.getPreprocessorProblems().length, 0); } - else if ( lang == ParserLanguage.CPP && expectNoProblems ) - { - assertEquals( CPPVisitor.getProblems(tu).length, 0 ); - assertEquals( tu.getPreprocessorProblems().length, 0 ); - } - if( expectNoProblems ) - assertEquals( 0, tu.getPreprocessorProblems().length ); - + if (expectNoProblems) + assertEquals(0, tu.getPreprocessorProblems().length); return tu; } - protected IASTTranslationUnit parse( IFile file, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException { - - IASTTranslationUnit tu=null; + protected IASTTranslationUnit parse(IFile file, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems) throws ParserException { + IASTTranslationUnit tu= null; try { tu = CDOM.getInstance().getASTService().getTranslationUnit(file); } catch (UnsupportedDialectException e) { assertFalse(true); // shouldn't happen } - if( lang == ParserLanguage.C && expectNoProblems ) - { - assertEquals( CVisitor.getProblems(tu).length, 0 ); - assertEquals( tu.getPreprocessorProblems().length, 0 ); + if (lang == ParserLanguage.C && expectNoProblems) { + assertEquals(CVisitor.getProblems(tu).length, 0); + assertEquals(tu.getPreprocessorProblems().length, 0); + } else if (lang == ParserLanguage.CPP && expectNoProblems) { + assertEquals(CPPVisitor.getProblems(tu).length, 0); + assertEquals(tu.getPreprocessorProblems().length, 0); } - else if ( lang == ParserLanguage.CPP && expectNoProblems ) - { - assertEquals( CPPVisitor.getProblems(tu).length, 0 ); - assertEquals( tu.getPreprocessorProblems().length, 0 ); - } - if( expectNoProblems ) - assertEquals( 0, tu.getPreprocessorProblems().length ); - + if (expectNoProblems) + assertEquals(0, tu.getPreprocessorProblems().length); return tu; } - } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index d6fb38c2367..5c993b4ada3 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -6327,11 +6327,6 @@ public class AST2Tests extends AST2BaseTest { return false; } - /** - * @param declarations - * @param index - * @return - */ private IBasicType getTypeForDeclaration(IASTDeclaration[] declarations, int index) { IASTInitializer init = ((IASTSimpleDeclaration) declarations[index]).getDeclarators()[0].getInitializer(); return (IBasicType)((IASTExpression)((IASTEqualsInitializer) init).getInitializerClause()).getExpressionType(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java index 5e0277075f3..d2c052b0c22 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java @@ -90,7 +90,7 @@ import org.eclipse.core.runtime.Platform; public class CompleteParser2Tests extends BaseTestCase { private static final NullLogService NULL_LOG = new NullLogService(); - + public CompleteParser2Tests() { } public CompleteParser2Tests(String name) { @@ -107,16 +107,16 @@ public class CompleteParser2Tests extends BaseTestCase { } public List nameList = new ArrayList(); @Override - public int visit( IASTName name ){ - nameList.add( name ); + public int visit(IASTName name){ + nameList.add(name); return PROCESS_CONTINUE; } - public IASTName getName( int idx ){ - if( idx < 0 || idx >= nameList.size() ) + public IASTName getName(int idx){ + if (idx < 0 || idx >= nameList.size()) return null; - return (IASTName) nameList.get( idx ); + return (IASTName) nameList.get(idx); } - public int size() { return nameList.size(); } + public int size() { return nameList.size(); } } static protected class CNameCollector extends ASTVisitor { { @@ -124,32 +124,32 @@ public class CompleteParser2Tests extends BaseTestCase { } public List nameList = new ArrayList(); @Override - public int visit( IASTName name ){ - nameList.add( name ); + public int visit(IASTName name){ + nameList.add(name); return PROCESS_CONTINUE; } - public IASTName getName( int idx ){ - if( idx < 0 || idx >= nameList.size() ) + public IASTName getName(int idx){ + if (idx < 0 || idx >= nameList.size()) return null; - return (IASTName) nameList.get( idx ); + return (IASTName) nameList.get(idx); } - public int size() { return nameList.size(); } + public int size() { return nameList.size(); } } - protected void assertInstances( CPPNameCollector nameCollector, IBinding binding, int num ) throws Exception { + protected void assertInstances(CPPNameCollector nameCollector, IBinding binding, int num) throws Exception { int count = 0; - for( int i = 0; i < nameCollector.size(); i++ ) - if( nameCollector.getName( i ).resolveBinding() == binding ) + for (int i = 0; i < nameCollector.size(); i++) + if (nameCollector.getName(i).resolveBinding() == binding) count++; - - assertEquals( count, num ); + + assertEquals(count, num); } - protected void assertInstances( CNameCollector nameCollector, IBinding binding, int num ) throws Exception { + protected void assertInstances(CNameCollector nameCollector, IBinding binding, int num) throws Exception { int count = 0; - for( int i = 0; i < nameCollector.size(); i++ ) - if( nameCollector.getName( i ).resolveBinding() == binding ) + for (int i = 0; i < nameCollector.size(); i++) + if (nameCollector.getName(i).resolveBinding() == binding) count++; - - assertEquals( count, num ); + + assertEquals(count, num); } protected IASTTranslationUnit parse(String code, boolean expectedToPass, ParserLanguage lang) throws Exception { @@ -166,17 +166,9 @@ public class CompleteParser2Tests extends BaseTestCase { protected IASTTranslationUnit parse(String code) throws Exception { return parse(code, true, ParserLanguage.CPP); } - - /** - * @param string - * @param b - * @param c - * @param d - */ + protected IASTTranslationUnit parse(String code, boolean expectedToPass, ParserLanguage lang, boolean gcc) throws Exception { - - FileContent codeReader = FileContent.create("", code.toCharArray()); ScannerInfo scannerInfo = new ScannerInfo(); ISourceCodeParser parser2 = null; @@ -201,365 +193,339 @@ public class CompleteParser2Tests extends BaseTestCase { } IASTTranslationUnit tu = parser2.parse(); if (parser2.encounteredError() && expectedToPass) - throw new ParserException("FAILURE"); //$NON-NLS-1$ - if (expectedToPass) - { - if( lang == ParserLanguage.C ) - { - IASTProblem [] problems = CVisitor.getProblems(tu); - assertEquals( problems.length, 0 ); - } - else if ( lang == ParserLanguage.CPP ) - { - IASTProblem [] problems = CPPVisitor.getProblems(tu); - assertEquals( problems.length, 0 ); + throw new ParserException("FAILURE"); + if (expectedToPass) { + if (lang == ParserLanguage.C) { + IASTProblem[] problems = CVisitor.getProblems(tu); + assertEquals(problems.length, 0); + } else if (lang == ParserLanguage.CPP) { + IASTProblem[] problems = CPPVisitor.getProblems(tu); + assertEquals(problems.length, 0); } } return tu; } - - public void testEmptyCompilationUnit() throws Exception - { - parse( "// no real code "); //$NON-NLS-1$ - } - - public void testSimpleNamespace() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { }"); //$NON-NLS-1$ - CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 1 ); - assertTrue( col.getName(0).resolveBinding() instanceof ICPPNamespace ); + + public void testEmptyCompilationUnit() throws Exception { + parse("// no real code "); } - public void testMultipleNamespaceDefinitions() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { } namespace A { }"); //$NON-NLS-1$ + public void testSimpleNamespace() throws Exception { + IASTTranslationUnit tu = parse("namespace A { }"); + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertEquals(col.size(), 1); + assertTrue(col.getName(0).resolveBinding() instanceof ICPPNamespace); + } + + public void testMultipleNamespaceDefinitions() throws Exception { + IASTTranslationUnit tu = parse("namespace A { } namespace A { }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 2 ); + tu.accept(col); + + assertEquals(col.size(), 2); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); - assertInstances( col, A, 2 ); + assertInstances(col, A, 2); } - public void testNestedNamespaceDefinitions() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { namespace B { } }"); //$NON-NLS-1$ + public void testNestedNamespaceDefinitions() throws Exception { + IASTTranslationUnit tu = parse("namespace A { namespace B { } }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 2 ); + tu.accept(col); + + assertEquals(col.size(), 2); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPNamespace B = (ICPPNamespace) col.getName(1).resolveBinding(); - - assertSame( A.getNamespaceScope(), B.getNamespaceScope().getParent() ); + + assertSame(A.getNamespaceScope(), B.getNamespaceScope().getParent()); } - - public void testEmptyClassDeclaration() throws Exception - { - IASTTranslationUnit tu = parse( "class A { };"); //$NON-NLS-1$ + + public void testEmptyClassDeclaration() throws Exception { + IASTTranslationUnit tu = parse("class A { };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 1 ); - assertTrue( col.getName(0).resolveBinding() instanceof ICPPClassType ); + tu.accept(col); + + assertEquals(col.size(), 1); + assertTrue(col.getName(0).resolveBinding() instanceof ICPPClassType); } - - public void testSimpleSubclass() throws Exception - { - IASTTranslationUnit tu = parse( "class A { }; class B : public A { };"); //$NON-NLS-1$ + + public void testSimpleSubclass() throws Exception { + IASTTranslationUnit tu = parse("class A { }; class B : public A { };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(1).resolveBinding(); - - assertInstances( col, A, 2 ); - - assertEquals( B.getBases().length, 1 ); + + assertInstances(col, A, 2); + + assertEquals(B.getBases().length, 1); ICPPBase base = B.getBases()[0]; - assertSame( base.getBaseClass(), A ); - assertEquals( base.getVisibility(), ICPPBase.v_public ); - assertFalse( base.isVirtual() ); + assertSame(base.getBaseClass(), A); + assertEquals(base.getVisibility(), ICPPBase.v_public); + assertFalse(base.isVirtual()); } - - public void testNestedSubclass() throws Exception - { - IASTTranslationUnit tu = parse( "namespace N { class A { }; } class B : protected virtual N::A { };"); //$NON-NLS-1$ + + public void testNestedSubclass() throws Exception { + IASTTranslationUnit tu = parse("namespace N { class A { }; } class B : protected virtual N::A { };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 6 ); + tu.accept(col); + + assertEquals(col.size(), 6); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(1).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(2).resolveBinding(); - - assertInstances( col, N, 2 ); - assertInstances( col, A, 3 ); - assertInstances( col, B, 1 ); - - assertSame( A.getScope(), N.getNamespaceScope() ); - + + assertInstances(col, N, 2); + assertInstances(col, A, 3); + assertInstances(col, B, 1); + + assertSame(A.getScope(), N.getNamespaceScope()); + ICPPBase base = B.getBases()[0]; - assertSame( base.getBaseClass(), A ); - assertTrue( base.isVirtual() ); - assertEquals( base.getVisibility(), ICPPBase.v_protected ); + assertSame(base.getBaseClass(), A); + assertTrue(base.isVirtual()); + assertEquals(base.getVisibility(), ICPPBase.v_protected); } - - public void testSimpleVariable() throws Exception - { - IASTTranslationUnit tu = parse( "int x;"); //$NON-NLS-1$ + + public void testSimpleVariable() throws Exception { + IASTTranslationUnit tu = parse("int x;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 1 ); + tu.accept(col); + + assertEquals(col.size(), 1); IVariable x = (IVariable) col.getName(0).resolveBinding(); - - assertTrue( x.getType() instanceof IBasicType ); + + assertTrue(x.getType() instanceof IBasicType); IBasicType t = (IBasicType) x.getType(); - assertEquals( t.getType(), IBasicType.t_int ); + assertEquals(t.getType(), IBasicType.t_int); } - - public void testSimpleClassReferenceVariable() throws Exception - { - IASTTranslationUnit tu = parse( "class A { }; A x;"); //$NON-NLS-1$ + + public void testSimpleClassReferenceVariable() throws Exception { + IASTTranslationUnit tu = parse("class A { }; A x;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); IVariable x = (IVariable) col.getName(2).resolveBinding(); - - assertInstances( col, A, 2 ); - assertSame( x.getType(), A ); + + assertInstances(col, A, 2); + assertSame(x.getType(), A); } - - public void testNestedClassReferenceVariable() throws Exception - { - IASTTranslationUnit tu = parse( "namespace N { class A { }; } N::A x;"); //$NON-NLS-1$ + + public void testNestedClassReferenceVariable() throws Exception { + IASTTranslationUnit tu = parse("namespace N { class A { }; } N::A x;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 6 ); + tu.accept(col); + + assertEquals(col.size(), 6); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(1).resolveBinding(); IVariable x = (IVariable) col.getName(5).resolveBinding(); - - assertInstances( col, N, 2 ); - assertInstances( col, A, 3 ); - assertSame( x.getType(), A ); - assertSame( A.getScope(), N.getNamespaceScope() ); + + assertInstances(col, N, 2); + assertInstances(col, A, 3); + assertSame(x.getType(), A); + assertSame(A.getScope(), N.getNamespaceScope()); } - - public void testMultipleDeclaratorsVariable() throws Exception - { - IASTTranslationUnit tu = parse( "class A { }; A x, y, z;"); //$NON-NLS-1$ + + public void testMultipleDeclaratorsVariable() throws Exception { + IASTTranslationUnit tu = parse("class A { }; A x, y, z;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); IVariable x = (IVariable) col.getName(2).resolveBinding(); IVariable y = (IVariable) col.getName(3).resolveBinding(); IVariable z = (IVariable) col.getName(4).resolveBinding(); - - assertInstances( col, A, 2 ); - assertSame( A, x.getType() ); - assertSame( x.getType(), y.getType() ); - assertSame( y.getType(), z.getType() ); + + assertInstances(col, A, 2); + assertSame(A, x.getType()); + assertSame(x.getType(), y.getType()); + assertSame(y.getType(), z.getType()); } - - public void testSimpleField() throws Exception - { - IASTTranslationUnit tu = parse( "class A { double x; };"); //$NON-NLS-1$ + + public void testSimpleField() throws Exception { + IASTTranslationUnit tu = parse("class A { double x; };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 2 ); + tu.accept(col); + + assertEquals(col.size(), 2); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPField x = (ICPPField) col.getName(1).resolveBinding(); - - assertSame( x.getScope(), A.getCompositeScope() ); - IField [] fields = A.getFields(); - assertEquals( fields.length, 1 ); - assertSame( fields[0], x ); + + assertSame(x.getScope(), A.getCompositeScope()); + IField[] fields = A.getFields(); + assertEquals(fields.length, 1); + assertSame(fields[0], x); } - - public void testUsingClauses() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { namespace B { int x; class C { static int y = 5; }; } } \n " + //$NON-NLS-1$ - "using namespace A::B;\n " + //$NON-NLS-1$ - "using A::B::x;" + //$NON-NLS-1$ - "using A::B::C;" + //$NON-NLS-1$ - "using A::B::C::y;"); //$NON-NLS-1$ + + public void testUsingClauses() throws Exception { + IASTTranslationUnit tu = parse("namespace A { namespace B { int x; class C { static int y = 5; }; } } \n " + + "using namespace A::B;\n " + + "using A::B::x;" + + "using A::B::C;" + + "using A::B::C::y;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 21 ); + tu.accept(col); + + assertEquals(col.size(), 21); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPNamespace B = (ICPPNamespace) col.getName(1).resolveBinding(); IVariable x = (IVariable) col.getName(2).resolveBinding(); ICPPClassType C = (ICPPClassType) col.getName(3).resolveBinding(); ICPPField y = (ICPPField) col.getName(4).resolveBinding(); - + ICPPUsingDeclaration using_x = (ICPPUsingDeclaration) col.getName(11).resolveBinding(); ICPPUsingDeclaration using_C = (ICPPUsingDeclaration) col.getName(15).resolveBinding(); ICPPUsingDeclaration using_y = (ICPPUsingDeclaration) col.getName(20).resolveBinding(); - - assertInstances( col, A, 5 ); - assertInstances( col, B, 6 ); - assertInstances( col, x, 1 ); - assertInstances( col, C, 2 ); - assertInstances( col, y, 1 ); - - IBinding [] ds = using_x.getDelegates(); - assertSame( ds[0], x ); - assertSame( using_C.getDelegates()[0], C ); - assertSame( using_y.getDelegates()[0], y ); + + assertInstances(col, A, 5); + assertInstances(col, B, 6); + assertInstances(col, x, 1); + assertInstances(col, C, 2); + assertInstances(col, y, 1); + + IBinding[] ds = using_x.getDelegates(); + assertSame(ds[0], x); + assertSame(using_C.getDelegates()[0], C); + assertSame(using_y.getDelegates()[0], y); } - - public void testEnumerations() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { enum E { e1, e2, e3 }; E varE;}"); //$NON-NLS-1$ + + public void testEnumerations() throws Exception { + IASTTranslationUnit tu = parse("namespace A { enum E { e1, e2, e3 }; E varE;}"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 7 ); + tu.accept(col); + + assertEquals(col.size(), 7); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); IEnumeration E = (IEnumeration) col.getName(1).resolveBinding(); IEnumerator e1 = (IEnumerator) col.getName(2).resolveBinding(); IEnumerator e2 = (IEnumerator) col.getName(3).resolveBinding(); IEnumerator e3 = (IEnumerator) col.getName(4).resolveBinding(); IVariable varE = (IVariable) col.getName(6).resolveBinding(); - - assertInstances( col, E, 2 ); - assertSame( E.getScope(), A.getNamespaceScope() ); - assertSame( e1.getScope(), A.getNamespaceScope() ); - assertNotNull( e2 ); - assertNotNull( e3 ); - assertNotNull( varE ); + + assertInstances(col, E, 2); + assertSame(E.getScope(), A.getNamespaceScope()); + assertSame(e1.getScope(), A.getNamespaceScope()); + assertNotNull(e2); + assertNotNull(e3); + assertNotNull(varE); } - - public void testSimpleFunction() throws Exception - { - IASTTranslationUnit tu = parse( "void foo( void );"); //$NON-NLS-1$ + + public void testSimpleFunction() throws Exception { + IASTTranslationUnit tu = parse("void foo(void);"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 2 ); + tu.accept(col); + + assertEquals(col.size(), 2); IFunction foo = (IFunction) col.getName(0).resolveBinding(); IParameter p = (IParameter) col.getName(1).resolveBinding(); - - assertEquals( foo.getParameters().length, 1 ); - assertSame( foo.getParameters()[0], p ); - assertSame( p.getScope(), foo.getFunctionScope() ); + + assertEquals(foo.getParameters().length, 1); + assertSame(foo.getParameters()[0], p); + assertSame(p.getScope(), foo.getFunctionScope()); } - - public void testSimpleFunctionWithTypes() throws Exception - { - IASTTranslationUnit tu = parse( "class A { public: \n class B { }; }; const A::B & foo( A * myParam );"); //$NON-NLS-1$ + + public void testSimpleFunctionWithTypes() throws Exception { + IASTTranslationUnit tu = parse("class A { public: \n class B { }; }; const A::B & foo(A * myParam);"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 8 ); + tu.accept(col); + + assertEquals(col.size(), 8); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(1).resolveBinding(); IFunction foo = (IFunction) col.getName(5).resolveBinding(); IParameter p = (IParameter) col.getName(7).resolveBinding(); - - assertInstances( col, A, 3 ); - assertInstances( col, B, 3 ); - + + assertInstances(col, A, 3); + assertInstances(col, B, 3); + IFunctionType ftype = foo.getType(); - assertTrue( ftype.getReturnType() instanceof ICPPReferenceType ); + assertTrue(ftype.getReturnType() instanceof ICPPReferenceType); ICPPReferenceType rt = (ICPPReferenceType) ftype.getReturnType(); - assertTrue( rt.getType() instanceof IQualifierType ); - assertSame( ((IQualifierType)rt.getType()).getType(), B ); - + assertTrue(rt.getType() instanceof IQualifierType); + assertSame(((IQualifierType)rt.getType()).getType(), B); + IType pt = ftype.getParameterTypes()[0]; - assertTrue( p.getType().isSameType( pt ) ); - assertTrue( pt instanceof IPointerType ); - assertSame( ((IPointerType) pt).getType(), A ); + assertTrue(p.getType().isSameType(pt)); + assertTrue(pt instanceof IPointerType); + assertSame(((IPointerType) pt).getType(), A); } - - public void testSimpleMethod() throws Exception - { - IASTTranslationUnit tu = parse( "class A { void foo(); };"); //$NON-NLS-1$ + + public void testSimpleMethod() throws Exception { + IASTTranslationUnit tu = parse("class A { void foo(); };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 2 ); + tu.accept(col); + + assertEquals(col.size(), 2); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod foo = (ICPPMethod) col.getName(1).resolveBinding(); - - assertSame( foo.getScope(), A.getCompositeScope() ); + + assertSame(foo.getScope(), A.getCompositeScope()); } - - public void testSimpleMethodWithTypes() throws Exception - { - IASTTranslationUnit tu = parse( "class U { }; class A { U foo( U areDumb ); };"); //$NON-NLS-1$ + + public void testSimpleMethodWithTypes() throws Exception { + IASTTranslationUnit tu = parse("class U { }; class A { U foo(U areDumb); };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 6 ); + tu.accept(col); + + assertEquals(col.size(), 6); ICPPClassType U = (ICPPClassType) col.getName(0).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(1).resolveBinding(); ICPPMethod foo = (ICPPMethod) col.getName(3).resolveBinding(); IParameter p = (IParameter) col.getName(5).resolveBinding(); - - assertInstances( col, U, 3 ); - assertSame( foo.getScope(), A.getCompositeScope() ); + + assertInstances(col, U, 3); + assertSame(foo.getScope(), A.getCompositeScope()); IFunctionType ft = foo.getType(); - assertSame( ft.getReturnType(), U ); - assertSame( p.getType(), U ); + assertSame(ft.getReturnType(), U); + assertSame(p.getType(), U); } - - public void testUsingDeclarationWithFunctionsAndMethods() throws Exception - { - IASTTranslationUnit tu = parse( "namespace N { int foo(void); } class A { static int bar(void); }; using N::foo; using ::A::bar;" ); //$NON-NLS-1$ + + public void testUsingDeclarationWithFunctionsAndMethods() throws Exception { + IASTTranslationUnit tu = parse("namespace N { int foo(void); } class A { static int bar(void); }; using N::foo; using ::A::bar;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 12 ); + tu.accept(col); + + assertEquals(col.size(), 12); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); IFunction foo = (IFunction) col.getName(1).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(3).resolveBinding(); ICPPMethod bar = (ICPPMethod) col.getName(4).resolveBinding(); - + ICPPUsingDeclaration using_foo = (ICPPUsingDeclaration) col.getName(8).resolveBinding(); ICPPUsingDeclaration using_bar = (ICPPUsingDeclaration) col.getName(11).resolveBinding(); - - assertInstances( col, N, 2 ); - assertInstances( col, foo, 1 ); - assertInstances( col, A, 2 ); - assertInstances( col, bar, 1 ); - - assertSame( using_foo.getDelegates()[0], foo ); - assertSame( using_bar.getDelegates()[0], bar ); - } - - public void testLinkageSpec() throws Exception - { - IASTTranslationUnit tu = parse( "extern \"C\" { int foo(); }"); //$NON-NLS-1$ - CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 1 ); - IFunction foo = (IFunction) col.getName(0).resolveBinding(); - assertNotNull( foo ); - } - - public void testBogdansExample() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { namespace B { enum e1{e_1,e_2}; int x; class C { static int y = 5; }; }} "); //$NON-NLS-1$ + assertInstances(col, N, 2); + assertInstances(col, foo, 1); + assertInstances(col, A, 2); + assertInstances(col, bar, 1); + + assertSame(using_foo.getDelegates()[0], foo); + assertSame(using_bar.getDelegates()[0], bar); + } + + public void testLinkageSpec() throws Exception { + IASTTranslationUnit tu = parse("extern \"C\" { int foo(); }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 8 ); + tu.accept(col); + + assertEquals(col.size(), 1); + IFunction foo = (IFunction) col.getName(0).resolveBinding(); + assertNotNull(foo); + } + + public void testBogdansExample() throws Exception { + IASTTranslationUnit tu = parse("namespace A { namespace B { enum e1{e_1,e_2}; int x; class C { static int y = 5; }; }} "); + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertEquals(col.size(), 8); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPNamespace B = (ICPPNamespace) col.getName(1).resolveBinding(); IEnumeration e1 = (IEnumeration) col.getName(2).resolveBinding(); @@ -568,550 +534,513 @@ public class CompleteParser2Tests extends BaseTestCase { IVariable x = (IVariable) col.getName(5).resolveBinding(); ICPPClassType C = (ICPPClassType) col.getName(6).resolveBinding(); ICPPField y = (ICPPField) col.getName(7).resolveBinding(); - - assertSame( B.getScope(), A.getNamespaceScope() ); - assertSame( e1.getScope(), B.getNamespaceScope() ); - assertSame( e_1.getScope(), B.getNamespaceScope() ); - assertSame( e_2.getType(), e1 ); - assertNotNull( x ); - assertNotNull( C ); - assertNotNull( y ); + + assertSame(B.getScope(), A.getNamespaceScope()); + assertSame(e1.getScope(), B.getNamespaceScope()); + assertSame(e_1.getScope(), B.getNamespaceScope()); + assertSame(e_2.getType(), e1); + assertNotNull(x); + assertNotNull(C); + assertNotNull(y); } - - public void testAndrewsExample() throws Exception - { - IASTTranslationUnit tu = parse( "namespace N{ class A {}; } using namespace N; class B: public A{};"); //$NON-NLS-1$ + + public void testAndrewsExample() throws Exception { + IASTTranslationUnit tu = parse("namespace N{ class A {}; } using namespace N; class B: public A{};"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(1).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(3).resolveBinding(); - - assertInstances( col, N, 2 ); - assertInstances( col, A, 2 ); - + + assertInstances(col, N, 2); + assertInstances(col, A, 2); + ICPPBase base = B.getBases()[0]; - assertSame( base.getBaseClass(), A ); + assertSame(base.getBaseClass(), A); } - - public void testSimpleTypedef() throws Exception - { - IASTTranslationUnit tu = parse( "typedef int myInt;\n myInt var;"); //$NON-NLS-1$ + + public void testSimpleTypedef() throws Exception { + IASTTranslationUnit tu = parse("typedef int myInt;\n myInt var;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); ITypedef myInt = (ITypedef) col.getName(0).resolveBinding(); IVariable var = (IVariable) col.getName(2).resolveBinding(); - - assertInstances( col, myInt, 2 ); - assertTrue( myInt.getType() instanceof IBasicType ); - assertSame( var.getType(), myInt ); + + assertInstances(col, myInt, 2); + assertTrue(myInt.getType() instanceof IBasicType); + assertSame(var.getType(), myInt); } - - public void testComplexTypedef() throws Exception - { - IASTTranslationUnit tu = parse( "class A{ }; typedef A ** A_DOUBLEPTR;"); //$NON-NLS-1$ + + public void testComplexTypedef() throws Exception { + IASTTranslationUnit tu = parse("class A{ }; typedef A ** A_DOUBLEPTR;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ITypedef APTR = (ITypedef) col.getName(2).resolveBinding(); - - assertInstances( col, A, 2 ); - assertTrue( APTR.getType() instanceof IPointerType ); + + assertInstances(col, A, 2); + assertTrue(APTR.getType() instanceof IPointerType); IPointerType pt = (IPointerType) APTR.getType(); - assertTrue( pt.getType() instanceof IPointerType ); + assertTrue(pt.getType() instanceof IPointerType); pt = (IPointerType) pt.getType(); - assertSame( pt.getType(), A ); + assertSame(pt.getType(), A); } - - - protected void assertQualifiedName(String [] fromAST, String [] theTruth) + + protected void assertQualifiedName(String[] fromAST, String[] theTruth) { - assertNotNull( fromAST ); - assertNotNull( theTruth ); - assertEquals( fromAST.length, theTruth.length ); - for( int i = 0; i < fromAST.length; ++i ) + assertNotNull(fromAST); + assertNotNull(theTruth); + assertEquals(fromAST.length, theTruth.length); + for (int i = 0; i < fromAST.length; ++i) { - assertEquals( fromAST[i], theTruth[i]); + assertEquals(fromAST[i], theTruth[i]); } } - public void testBug40842() throws Exception{ - Writer code = new StringWriter(); - code.write("class A {} a;\n"); //$NON-NLS-1$ + public void testBug40842() throws Exception { + Writer code = new StringWriter(); + code.write("class A {} a;\n"); IASTTranslationUnit tu = parse(code.toString()); IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTCompositeTypeSpecifier comp = (IASTCompositeTypeSpecifier) decl.getDeclSpecifier(); ICPPClassType A = (ICPPClassType) comp.getName().resolveBinding(); IVariable a = (IVariable) decl.getDeclarators()[0].getName().resolveBinding(); - assertSame( a.getType(), A ); + assertSame(a.getType(), A); } - - public void testNestedClassname() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { \n class A::B { };}"); //$NON-NLS-1$ + + public void testNestedClassname() throws Exception { + IASTTranslationUnit tu = parse("namespace A { \n class A::B { };}"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - + tu.accept(col); + ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(1).resolveBinding(); - assertInstances( col, A, 2 ); - assertEquals( B.getScope(), A.getNamespaceScope() ); + assertInstances(col, A, 2); + assertEquals(B.getScope(), A.getNamespaceScope()); } - - public void testForwardDeclaration() throws Exception - { - IASTTranslationUnit tu = parse( "class forward;"); //$NON-NLS-1$ + + public void testForwardDeclaration() throws Exception { + IASTTranslationUnit tu = parse("class forward;"); IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; - assertEquals( decl.getDeclarators().length, 0 ); - + assertEquals(decl.getDeclarators().length, 0); + IASTElaboratedTypeSpecifier spec = (IASTElaboratedTypeSpecifier) decl.getDeclSpecifier(); ICPPClassType forward = (ICPPClassType) spec.getName().resolveBinding(); - assertNotNull( forward ); + assertNotNull(forward); } - - public void testElaboratedType() throws Exception - { - IASTTranslationUnit tu = parse( "class A; class A * a;"); //$NON-NLS-1$ + + public void testElaboratedType() throws Exception { + IASTTranslationUnit tu = parse("class A; class A * a;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); IVariable a = (IVariable) col.getName(2).resolveBinding(); IPointerType ptr = (IPointerType) a.getType(); - assertInstances( col, A, 2 ); - assertSame( ptr.getType(), A ); + assertInstances(col, A, 2); + assertSame(ptr.getType(), A); } - - public void testForewardDeclarationWithUsage() throws Exception - { - IASTTranslationUnit tu = parse( "class A; A * anA;class A { };"); //$NON-NLS-1$ + + public void testForewardDeclarationWithUsage() throws Exception { + IASTTranslationUnit tu = parse("class A; A * anA;class A { };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); + tu.accept(col); + + assertEquals(col.size(), 4); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); IVariable anA = (IVariable) col.getName(2).resolveBinding(); - assertInstances( col, A, 3 ); + assertInstances(col, A, 3); IPointerType ptr = (IPointerType) anA.getType(); - assertSame( ptr.getType(), A ); - } - - - public void testASM() throws Exception - { - parse( "asm ( \"blah blah blah\" );" ); //$NON-NLS-1$ + assertSame(ptr.getType(), A); } - - /** + public void testASM() throws Exception { + parse("asm (\"blah blah blah\");"); + } + + /** * Tests GNU extensions to asm * e.g. asm volatile ("stuff"); - * asm ("addl %%ebx,%%eax" : "=a"(foo) : "a"(foo),"b"(bar) ); + * asm ("addl %%ebx,%%eax" : "=a"(foo) : "a"(foo),"b"(bar)); */ - public void testGNUASMExtension() throws Exception - { + public void testGNUASMExtension() throws Exception { // volatile keyword - parse( "asm volatile( \"blah blah blah\" );", true, ParserLanguage.C, true ); //$NON-NLS-1$ - parse( "asm volatile( \"blah blah blah\" );", true, ParserLanguage.CPP, true ); //$NON-NLS-1$ - + parse("asm volatile(\"blah blah blah\");", true, ParserLanguage.C, true); + parse("asm volatile(\"blah blah blah\");", true, ParserLanguage.CPP, true); + // Use of operands - parse( "asm (\"addl %%ebx,%%eax\" : \"=a\"(foo) :\"a\"(foo), \"b\"(bar) );", true, ParserLanguage.C, true );//$NON-NLS-1$ - parse( "asm (\"addl %%ebx,%%eax\" : \"=a\"(foo) :\"a\"(foo), \"b\"(bar) );", true, ParserLanguage.CPP, true );//$NON-NLS-1$ - + parse("asm (\"addl %%ebx,%%eax\" : \"=a\"(foo) :\"a\"(foo), \"b\"(bar));", true, ParserLanguage.C, true);//$NON-NLS-1$ + parse("asm (\"addl %%ebx,%%eax\" : \"=a\"(foo) :\"a\"(foo), \"b\"(bar));", true, ParserLanguage.CPP, true);//$NON-NLS-1$ + // Invalid use of operands - parse( "asm (\"addl %%ebx,%%eax\" \"=a\"(foo) :\"a\"(foo) : \"b\"(bar) );", false, ParserLanguage.C, true );//$NON-NLS-1$ - parse( "asm (\"addl %%ebx,%%eax\" \"=a\"(foo) :\"a\"(foo) : \"b\"(bar) );", false, ParserLanguage.CPP, true );//$NON-NLS-1$ + parse("asm (\"addl %%ebx,%%eax\" \"=a\"(foo) :\"a\"(foo) : \"b\"(bar));", false, ParserLanguage.C, true);//$NON-NLS-1$ + parse("asm (\"addl %%ebx,%%eax\" \"=a\"(foo) :\"a\"(foo) : \"b\"(bar));", false, ParserLanguage.CPP, true);//$NON-NLS-1$ // Code from bug 145389. - parse("#define mb() __asm__ __volatile__ (\"sync\" : : : \"memory\")\r\n" + - "\r\n" + - "int main(int argc, char **argv) {\r\n" + - " mb();\r\n" + + parse("#define mb() __asm__ __volatile__ (\"sync\" : : : \"memory\")\r\n" + + "\r\n" + + "int main(int argc, char **argv) {\r\n" + + " mb();\r\n" + "}"); // Code from bug 117001 - parse("static inline long\r\n" + - "div_ll_X_l_rem(long long divs, long div, long *rem)\r\n" + - "{\r\n" + - " long dum2;\r\n" + - " __asm__(\"divl %2\":\"=a\"(dum2), \"=d\"(*rem) // syntax error indicated at \":\"\r\n" + - " : \"rm\"(div), \"A\"(divs));\r\n" + - "\r\n" + - " return dum2;\r\n" + - "\r\n" + + parse("static inline long\r\n" + + "div_ll_X_l_rem(long long divs, long div, long *rem)\r\n" + + "{\r\n" + + " long dum2;\r\n" + + " __asm__(\"divl %2\":\"=a\"(dum2), \"=d\"(*rem) // syntax error indicated at \":\"\r\n" + + " : \"rm\"(div), \"A\"(divs));\r\n" + + "\r\n" + + " return dum2;\r\n" + + "\r\n" + "}"); } - public void testOverride() throws Exception - { - IASTTranslationUnit tu = parse( "void foo();\n void foo( int );\n"); //$NON-NLS-1$ + public void testOverride() throws Exception { + IASTTranslationUnit tu = parse("void foo();\n void foo(int);\n"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); IFunction foo1 = (IFunction) col.getName(0).resolveBinding(); IFunction foo2 = (IFunction) col.getName(1).resolveBinding(); - - assertNotSame( foo1, foo2 ); - } - - public void testSimpleExpression() throws Exception - { - IASTTranslationUnit tu = parse( "int x; int y = x;"); //$NON-NLS-1$ + + assertNotSame(foo1, foo2); + } + + public void testSimpleExpression() throws Exception { + IASTTranslationUnit tu = parse("int x; int y = x;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); IVariable x = (IVariable) col.getName(0).resolveBinding(); IVariable y = (IVariable) col.getName(1).resolveBinding(); - assertInstances( col, x, 2 ); - assertNotNull( y ); + assertInstances(col, x, 2); + assertNotNull(y); } - - public void testParameterExpressions() throws Exception - { - IASTTranslationUnit tu = parse( "int x = 5; void foo( int sub = x ) { }"); //$NON-NLS-1$ + + public void testParameterExpressions() throws Exception { + IASTTranslationUnit tu = parse("int x = 5; void foo(int sub = x) { }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); + tu.accept(col); + + assertEquals(col.size(), 4); IVariable x = (IVariable) col.getName(0).resolveBinding(); - assertInstances( col, x, 2 ); + assertInstances(col, x, 2); } - - public void testNestedNamespaceExpression() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { int x = 666; } int y = A::x;"); //$NON-NLS-1$ + + public void testNestedNamespaceExpression() throws Exception { + IASTTranslationUnit tu = parse("namespace A { int x = 666; } int y = A::x;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 6 ); + tu.accept(col); + + assertEquals(col.size(), 6); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); IVariable x = (IVariable) col.getName(1).resolveBinding(); - assertInstances( col, A, 2 ); - assertInstances( col, x, 3 ); + assertInstances(col, A, 2); + assertInstances(col, x, 3); } - - public void testConstructorChain() throws Exception - { - IASTTranslationUnit tu = parse( "int x = 5;\n class A \n{ public : \n int a; \n A() : a( x ) { } };"); //$NON-NLS-1$ + + public void testConstructorChain() throws Exception { + IASTTranslationUnit tu = parse("int x = 5;\n class A \n{ public : \n int a; \n A() : a(x) { } };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 6 ); + tu.accept(col); + + assertEquals(col.size(), 6); IVariable x = (IVariable) col.getName(0).resolveBinding(); ICPPField a = (ICPPField) col.getName(2).resolveBinding(); ICPPConstructor A = (ICPPConstructor) col.getName(3).resolveBinding(); - assertNotNull( A ); - assertInstances( col, x, 2 ); - assertInstances( col, a, 2 ); + assertNotNull(A); + assertInstances(col, x, 2); + assertInstances(col, a, 2); } - - public void testArrayModExpression() throws Exception - { - IASTTranslationUnit tu = parse( "const int x = 5; int y [ x ]; "); //$NON-NLS-1$ + + public void testArrayModExpression() throws Exception { + IASTTranslationUnit tu = parse("const int x = 5; int y[ x ]; "); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); IVariable x = (IVariable) col.getName(0).resolveBinding(); IVariable y = (IVariable) col.getName(1).resolveBinding(); - assertInstances( col, x, 2 ); - assertTrue( y.getType() instanceof IArrayType ); - assertTrue( ((IArrayType)y.getType()).getType() instanceof IBasicType ); + assertInstances(col, x, 2); + assertTrue(y.getType() instanceof IArrayType); + assertTrue(((IArrayType)y.getType()).getType() instanceof IBasicType); } - - public void testPointerVariable() throws Exception - { - IASTTranslationUnit tu = parse( "class A { }; A * anA;"); //$NON-NLS-1$ + public void testPointerVariable() throws Exception { + IASTTranslationUnit tu = parse("class A { }; A * anA;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); IVariable anA = (IVariable) col.getName(2).resolveBinding(); - assertInstances( col, A, 2 ); - assertTrue( anA.getType() instanceof IPointerType ); - assertSame( ((IPointerType) anA.getType()).getType(), A ); - } - - public void testExceptionSpecification() throws Exception - { - IASTTranslationUnit tu = parse( "class A { }; void foo( void ) throw ( A );"); //$NON-NLS-1$ - CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); - ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); - assertInstances( col, A, 2 ); + assertInstances(col, A, 2); + assertTrue(anA.getType() instanceof IPointerType); + assertSame(((IPointerType) anA.getType()).getType(), A); } - - public void testNewExpressions() throws Exception { - IASTTranslationUnit tu = parse( "typedef int A; int B; int C; int D; int P; int*p = new (P) (A[B][C][D]);" ); //$NON-NLS-1$ + + public void testExceptionSpecification() throws Exception { + IASTTranslationUnit tu = parse("class A { }; void foo(void) throw (A);"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 11 ); + tu.accept(col); + + assertEquals(col.size(), 4); + ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); + assertInstances(col, A, 2); + } + + public void testNewExpressions() throws Exception { + IASTTranslationUnit tu = parse("typedef int A; int B; int C; int D; int P; int*p = new (P) (A[B][C][D]);"); + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertEquals(col.size(), 11); ITypedef A = (ITypedef) col.getName(0).resolveBinding(); IVariable B = (IVariable) col.getName(1).resolveBinding(); IVariable C = (IVariable) col.getName(2).resolveBinding(); IVariable D = (IVariable) col.getName(3).resolveBinding(); IVariable P = (IVariable) col.getName(4).resolveBinding(); IVariable p = (IVariable) col.getName(5).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, B, 2 ); - assertInstances( col, C, 2 ); - assertInstances( col, D, 2 ); - assertInstances( col, P, 2 ); - - assertTrue( p.getType() instanceof IPointerType ); + + assertInstances(col, A, 2); + assertInstances(col, B, 2); + assertInstances(col, C, 2); + assertInstances(col, D, 2); + assertInstances(col, P, 2); + + assertTrue(p.getType() instanceof IPointerType); } - public void testBug41520() throws Exception - { - IASTTranslationUnit tu = parse( "int f() { const int x = 666; const int y( x ); }"); //$NON-NLS-1$ + public void testBug41520() throws Exception { + IASTTranslationUnit tu = parse("int f() { const int x = 666; const int y(x); }"); IASTCompoundStatement s = (IASTCompoundStatement) ((IASTFunctionDefinition)tu.getDeclarations()[0]).getBody(); IASTDeclarationStatement ds = (IASTDeclarationStatement) s.getStatements()[1]; - + IASTSimpleDeclaration decl = (IASTSimpleDeclaration) ds.getDeclaration(); IASTDeclarator dtor = decl.getDeclarators()[0]; - assertFalse( dtor instanceof IASTFunctionDeclarator ); - assertNotNull( dtor.getInitializer() ); - + assertFalse(dtor instanceof IASTFunctionDeclarator); + assertNotNull(dtor.getInitializer()); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); + tu.accept(col); + + assertEquals(col.size(), 4); IVariable x = (IVariable) col.getName(1).resolveBinding(); IVariable y = (IVariable) col.getName(2).resolveBinding(); assertNotNull(y); - assertInstances( col, x, 2 ); + assertInstances(col, x, 2); } - - public void testNewXReferences() throws Exception - { - IASTTranslationUnit tu = parse( "const int max = 5;\n int * x = new int[max];"); //$NON-NLS-1$ + + public void testNewXReferences() throws Exception { + IASTTranslationUnit tu = parse("const int max = 5;\n int * x = new int[max];"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); IVariable max = (IVariable) col.getName(0).resolveBinding(); - assertInstances( col, max, 2 ); + assertInstances(col, max, 2); } - - public void testQualifiedNameReferences() throws Exception - { + + public void testQualifiedNameReferences() throws Exception { // Used to cause AST Semantic exception - IASTTranslationUnit tu = parse( "class A{ class B{ class C { public: int cMethod(); }; }; }; \n int A::B::C::cMethod() {}; \n" ); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("class A{ class B{ class C { public: int cMethod(); }; }; }; \n int A::B::C::cMethod() {}; \n"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 9 ); + tu.accept(col); + + assertEquals(col.size(), 9); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(1).resolveBinding(); ICPPClassType C = (ICPPClassType) col.getName(2).resolveBinding(); ICPPMethod cMethod = (ICPPMethod) col.getName(3).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, B, 2 ); - assertInstances( col, C, 2 ); - assertInstances( col, cMethod, 3 ); - assertEquals( cMethod.getVisibility(), ICPPMember.v_public ); - assertSame( cMethod.getScope(), C.getCompositeScope() ); - assertSame( C.getScope(), B.getCompositeScope() ); - assertSame( B.getScope(), A.getCompositeScope() ); + + assertInstances(col, A, 2); + assertInstances(col, B, 2); + assertInstances(col, C, 2); + assertInstances(col, cMethod, 3); + assertEquals(cMethod.getVisibility(), ICPPMember.v_public); + assertSame(cMethod.getScope(), C.getCompositeScope()); + assertSame(C.getScope(), B.getCompositeScope()); + assertSame(B.getScope(), A.getCompositeScope()); } - public void testIsConstructor() throws Exception - { - IASTTranslationUnit tu = parse( "class A{ public: A(); }; \n A::A() {}; \n" ); //$NON-NLS-1$ + public void testIsConstructor() throws Exception { + IASTTranslationUnit tu = parse("class A{ public: A(); }; \n A::A() {}; \n"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPConstructor ctor = (ICPPConstructor) col.getName(1).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, ctor, 3 ); + + assertInstances(col, A, 2); + assertInstances(col, ctor, 3); } - public void testIsDestructor() throws Exception - { - IASTTranslationUnit tu = parse( "class A{ public: ~A(); }; \n A::~A() {}; \n" ); //$NON-NLS-1$ + public void testIsDestructor() throws Exception { + IASTTranslationUnit tu = parse("class A{ public: ~A(); }; \n A::~A() {}; \n"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod dtor = (ICPPMethod) col.getName(1).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, dtor, 3 ); + + assertInstances(col, A, 2); + assertInstances(col, dtor, 3); } - - public void testBug41445() throws Exception - { - IASTTranslationUnit tu = parse( "class A { }; namespace N { class B : public A { struct A {}; }; }"); //$NON-NLS-1$ + + public void testBug41445() throws Exception { + IASTTranslationUnit tu = parse("class A { }; namespace N { class B : public A { struct A {}; }; }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPNamespace N = (ICPPNamespace) col.getName(1).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(2).resolveBinding(); ICPPClassType A2 = (ICPPClassType) col.getName(4).resolveBinding(); - - assertInstances( col, A, 2 ); - assertNotSame( A, A2 ); - assertSame( A2.getScope(), B.getCompositeScope() ); - assertSame( B.getScope(), N.getNamespaceScope() ); - assertSame( B.getBases()[0].getBaseClass(), A ); - + + assertInstances(col, A, 2); + assertNotSame(A, A2); + assertSame(A2.getScope(), B.getCompositeScope()); + assertSame(B.getScope(), N.getNamespaceScope()); + assertSame(B.getBases()[0].getBaseClass(), A); + } - - public void testSimpleFunctionBody() throws Exception - { - IASTTranslationUnit tu = parse( "class A { int f1(); }; const int x = 4; int f() { return x; } int A::f1() { return x; }"); //$NON-NLS-1$ + + public void testSimpleFunctionBody() throws Exception { + IASTTranslationUnit tu = parse("class A { int f1(); }; const int x = 4; int f() { return x; } int A::f1() { return x; }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 9 ); + tu.accept(col); + + assertEquals(col.size(), 9); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod f1 = (ICPPMethod) col.getName(1).resolveBinding(); IVariable x = (IVariable) col.getName(2).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, f1, 3 ); - assertInstances( col, x, 3 ); + + assertInstances(col, A, 2); + assertInstances(col, f1, 3); + assertInstances(col, x, 3); } - - public void testSimpleForLoop() throws Exception - { - IASTTranslationUnit tu = parse( "const int FIVE = 5; void f() { int x = 0; for( int i = 0; i < FIVE; ++i ) { x += i; } }"); //$NON-NLS-1$ + public void testSimpleForLoop() throws Exception { + IASTTranslationUnit tu = parse("const int FIVE = 5; void f() { int x = 0; for (int i = 0; i < FIVE; ++i) { x += i; } }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 9 ); + tu.accept(col); + + assertEquals(col.size(), 9); IVariable FIVE = (IVariable) col.getName(0).resolveBinding(); IVariable x = (IVariable) col.getName(2).resolveBinding(); IVariable i = (IVariable) col.getName(3).resolveBinding(); - - assertInstances( col, FIVE, 2 ); - assertInstances( col, x, 2 ); - assertInstances( col, i, 4 ); + + assertInstances(col, FIVE, 2); + assertInstances(col, x, 2); + assertInstances(col, i, 4); } - public void testBug42541() throws Exception - { - IASTTranslationUnit tu = parse( "union{ int v; char a; } id;" ); //$NON-NLS-1$ + public void testBug42541() throws Exception { + IASTTranslationUnit tu = parse("union{ int v; char a; } id;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); - + tu.accept(col); + + assertEquals(col.size(), 4); + ICPPClassType unnamed = (ICPPClassType) col.getName(0).resolveBinding(); ICPPField v = (ICPPField) col.getName(1).resolveBinding(); ICPPField a = (ICPPField) col.getName(2).resolveBinding(); IVariable id = (IVariable) col.getName(3).resolveBinding(); - - assertEquals( unnamed.getKey(), ICompositeType.k_union ); - assertSame( v.getScope(), unnamed.getCompositeScope() ); - assertSame( a.getScope(), unnamed.getCompositeScope() ); - assertSame( id.getType(), unnamed ); + + assertEquals(unnamed.getKey(), ICompositeType.k_union); + assertSame(v.getScope(), unnamed.getCompositeScope()); + assertSame(a.getScope(), unnamed.getCompositeScope()); + assertSame(id.getType(), unnamed); } - - - - public void testSimpleIfStatement() throws Exception - { - IASTTranslationUnit tu =parse( "const bool T = true; int foo() { if( T ) { return 5; } else if( ! T ) return 20; else { return 10; } }"); //$NON-NLS-1$ - + + public void testSimpleIfStatement() throws Exception { + IASTTranslationUnit tu =parse("const bool T = true; int foo() { if (T) { return 5; } else if (! T) return 20; else { return 10; } }"); + IASTFunctionDefinition foo = (IASTFunctionDefinition) tu.getDeclarations()[1]; IASTCompoundStatement compound = (IASTCompoundStatement) foo.getBody(); IASTIfStatement ifstmt = (IASTIfStatement) compound.getStatements()[0]; - assertTrue( ifstmt.getConditionExpression() instanceof IASTIdExpression ); - assertTrue( ifstmt.getThenClause() instanceof IASTCompoundStatement ); - assertTrue( ifstmt.getElseClause() instanceof IASTIfStatement ); + assertTrue(ifstmt.getConditionExpression() instanceof IASTIdExpression); + assertTrue(ifstmt.getThenClause() instanceof IASTCompoundStatement); + assertTrue(ifstmt.getElseClause() instanceof IASTIfStatement); ifstmt = (IASTIfStatement) ifstmt.getElseClause(); - assertTrue( ifstmt.getConditionExpression() instanceof IASTUnaryExpression ); - assertTrue( ifstmt.getThenClause() instanceof IASTReturnStatement ); - assertTrue( ifstmt.getElseClause() instanceof IASTCompoundStatement ); - + assertTrue(ifstmt.getConditionExpression() instanceof IASTUnaryExpression); + assertTrue(ifstmt.getThenClause() instanceof IASTReturnStatement); + assertTrue(ifstmt.getElseClause() instanceof IASTCompoundStatement); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); - + tu.accept(col); + + assertEquals(col.size(), 4); + IVariable T = (IVariable) col.getName(0).resolveBinding(); - assertInstances( col, T, 3 ); + assertInstances(col, T, 3); } - - public void testSimpleWhileStatement() throws Exception - { - IASTTranslationUnit tu = parse( "const bool T = true; void foo() { int x = 0; while( T ) { ++x; if( x == 100 ) break; } }"); //$NON-NLS-1$ + + public void testSimpleWhileStatement() throws Exception { + IASTTranslationUnit tu = parse("const bool T = true; void foo() { int x = 0; while(T) { ++x; if (x == 100) break; } }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 6 ); + tu.accept(col); + + assertEquals(col.size(), 6); IVariable T = (IVariable) col.getName(0).resolveBinding(); IVariable x = (IVariable) col.getName(2).resolveBinding(); - assertInstances( col, T, 2 ); - assertInstances( col, x, 3 ); + assertInstances(col, T, 2); + assertInstances(col, x, 3); } - - public void testSimpleSwitchStatement() throws Exception - { - IASTTranslationUnit tu = parse( "const int x = 5; const int y = 10; " + //$NON-NLS-1$ - "void foo() { " + //$NON-NLS-1$ - " while( true ) { " + //$NON-NLS-1$ - " switch( x ) { " + //$NON-NLS-1$ - " case 1: break; " + //$NON-NLS-1$ - " case 2: goto blah; " + //$NON-NLS-1$ - " case y: continue; " + //$NON-NLS-1$ - " default: break; " + //$NON-NLS-1$ - " } " + //$NON-NLS-1$ - " } " + //$NON-NLS-1$ - " blah : ; " + //$NON-NLS-1$ - "} "); //$NON-NLS-1$ + + public void testSimpleSwitchStatement() throws Exception { + IASTTranslationUnit tu = parse("const int x = 5; const int y = 10; " + + "void foo() { " + + " while(true) { " + + " switch(x) { " + + " case 1: break; " + + " case 2: goto blah; " + + " case y: continue; " + + " default: break; " + + " } " + + " } " + + " blah : ; " + + "} "); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 7 ); + tu.accept(col); + + assertEquals(col.size(), 7); IVariable x = (IVariable) col.getName(0).resolveBinding(); IVariable y = (IVariable) col.getName(1).resolveBinding(); ILabel blah = (ILabel) col.getName(4).resolveBinding(); - assertNotNull( blah ); - assertInstances( col, x, 2 ); - assertInstances( col, y, 2 ); - assertInstances( col, blah, 2 ); + assertNotNull(blah); + assertInstances(col, x, 2); + assertInstances(col, y, 2); + assertInstances(col, blah, 2); } - - public void testSimpleDoStatement() throws Exception - { - IASTTranslationUnit tu = parse( "const int x = 3; int counter = 0; void foo() { do { ++counter; } while( counter != x ); } "); //$NON-NLS-1$ + + public void testSimpleDoStatement() throws Exception { + IASTTranslationUnit tu = parse("const int x = 3; int counter = 0; void foo() { do { ++counter; } while(counter != x); } "); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 6 ); + tu.accept(col); + + assertEquals(col.size(), 6); IVariable x = (IVariable) col.getName(0).resolveBinding(); IVariable counter = (IVariable) col.getName(1).resolveBinding(); - assertInstances( col, x, 2 ); - assertInstances( col, counter, 3 ); + assertInstances(col, x, 2); + assertInstances(col, counter, 3); } - + public void testThrowStatement() throws Exception { - IASTTranslationUnit tu = parse("class A { }; void foo() throw ( A ) { A a; throw a; throw; } "); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("class A { }; void foo() throw (A) { A a; throw a; throw; } "); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1122,430 +1051,405 @@ public class CompleteParser2Tests extends BaseTestCase { IVariable a = (IVariable) col.getName(4).resolveBinding(); assertInstances(col, a, 2); } - - public void testScoping() throws Exception - { - IASTTranslationUnit tu = parse( "void foo() { int x = 3; if( x == 1 ) { int x = 4; } else int x = 2; }"); //$NON-NLS-1$ + + public void testScoping() throws Exception { + IASTTranslationUnit tu = parse("void foo() { int x = 3; if (x == 1) { int x = 4; } else int x = 2; }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); IVariable x1 = (IVariable) col.getName(1).resolveBinding(); IVariable x2 = (IVariable) col.getName(3).resolveBinding(); IVariable x3 = (IVariable) col.getName(4).resolveBinding(); - - assertInstances( col, x1, 2 ); - assertInstances( col, x2, 1 ); - assertInstances( col, x3, 1 ); + + assertInstances(col, x1, 2); + assertInstances(col, x2, 1); + assertInstances(col, x3, 1); } - - public void testEnumeratorReferences() throws Exception - { - IASTTranslationUnit tu = parse( "enum E { e1, e2, e3 }; E anE = e1;"); //$NON-NLS-1$ + + public void testEnumeratorReferences() throws Exception { + IASTTranslationUnit tu = parse("enum E { e1, e2, e3 }; E anE = e1;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 7 ); + tu.accept(col); + + assertEquals(col.size(), 7); IEnumeration E = (IEnumeration) col.getName(0).resolveBinding(); IEnumerator e1 = (IEnumerator) col.getName(1).resolveBinding(); IEnumerator e2 = (IEnumerator) col.getName(2).resolveBinding(); IEnumerator e3 = (IEnumerator) col.getName(3).resolveBinding(); IVariable anE = (IVariable) col.getName(5).resolveBinding(); - - assertInstances( col, E, 2 ); - assertInstances( col, e1, 2 ); - assertInstances( col, e2, 1 ); - assertInstances( col, e3, 1 ); - assertInstances( col, anE, 1 ); + + assertInstances(col, E, 2); + assertInstances(col, e1, 2); + assertInstances(col, e2, 1); + assertInstances(col, e3, 1); + assertInstances(col, anE, 1); } - - public void testBug42840() throws Exception - { - IASTTranslationUnit tu = parse( "void foo(); void foo() { } class SearchMe { };"); //$NON-NLS-1$ + + public void testBug42840() throws Exception { + IASTTranslationUnit tu = parse("void foo(); void foo() { } class SearchMe { };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); IFunction foo = (IFunction) col.getName(0).resolveBinding(); - - assertInstances( col, foo, 2 ); + + assertInstances(col, foo, 2); } - - public void testBug42872() throws Exception - { - IASTTranslationUnit tu = parse( "struct B {}; struct D : B {}; void foo(D* dp) { B* bp = dynamic_cast(dp); }" ); //$NON-NLS-1$ + + public void testBug42872() throws Exception { + IASTTranslationUnit tu = parse("struct B {}; struct D : B {}; void foo(D* dp) { B* bp = dynamic_cast(dp); }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 10 ); + tu.accept(col); + + assertEquals(col.size(), 10); ICompositeType B = (ICompositeType) col.getName(0).resolveBinding(); ICompositeType D = (ICompositeType) col.getName(1).resolveBinding(); - - assertInstances( col, B, 4 ); - assertInstances( col, D, 2 ); + + assertInstances(col, B, 4); + assertInstances(col, D, 2); } - + public void testBug43503A() throws Exception { - IASTTranslationUnit tu = parse("class SD_01 { void f_SD_01() {}}; int main(){ SD_01 * a = new SD_01(); a->f_SD_01(); } "); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("class SD_01 { void f_SD_01() {}}; int main(){ SD_01 * a = new SD_01(); a->f_SD_01(); } "); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 8 ); + tu.accept(col); + + assertEquals(col.size(), 8); ICPPClassType SD_01 = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod f_SD_01 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPConstructor ctor = SD_01.getConstructors()[0]; - assertInstances( col, SD_01, 2 ); - assertInstances( col, ctor, 1 ); - assertInstances( col, f_SD_01, 2 ); - } - - - public void testBug42979() throws Exception - { - Writer code = new StringWriter(); - code.write( "class OperatorOverload{\n" ); //$NON-NLS-1$ - code.write( "public:\n" ); //$NON-NLS-1$ - code.write( " bool operator==( const class OperatorOverload& that )\n" ); //$NON-NLS-1$ - code.write( " { return true; }\n" ); //$NON-NLS-1$ - code.write( " bool operator!=( const class OperatorOverload& that );\n" ); //$NON-NLS-1$ - code.write( "}; \n" ); //$NON-NLS-1$ - - code.write( "bool OperatorOverload::operator!=( const class OperatorOverload& that )\n" ); //$NON-NLS-1$ - code.write( "{ return false; }\n" ); //$NON-NLS-1$ + assertInstances(col, SD_01, 2); + assertInstances(col, ctor, 1); + assertInstances(col, f_SD_01, 2); + } - IASTTranslationUnit tu = parse( code.toString() ); + public void testBug42979() throws Exception { + Writer code = new StringWriter(); + code.write("class OperatorOverload{\n"); + code.write("public:\n"); + code.write(" bool operator==(const class OperatorOverload& that)\n"); + code.write(" { return true; }\n"); + code.write(" bool operator!=(const class OperatorOverload& that);\n"); + code.write("}; \n"); + + code.write("bool OperatorOverload::operator!=(const class OperatorOverload& that)\n"); + code.write("{ return false; }\n"); + + IASTTranslationUnit tu = parse(code.toString()); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 12 ); + tu.accept(col); + + assertEquals(col.size(), 12); ICompositeType OperatorOverload = (ICompositeType) col.getName(0).resolveBinding(); ICPPMethod op1 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPMethod op2 = (ICPPMethod) col.getName(4).resolveBinding(); - - assertInstances( col, OperatorOverload, 5 ); - assertInstances( col, op1, 1 ); - assertInstances( col, op2, 3 ); + + assertInstances(col, OperatorOverload, 5); + assertInstances(col, op1, 1); + assertInstances(col, op2, 3); } - /** + /** * class A { static int x; } int A::x = 5; */ - public void testBug43373() throws Exception - { - IASTTranslationUnit tu = parse( "class A { static int x; }; int A::x = 5;" ); //$NON-NLS-1$ + public void testBug43373() throws Exception { + IASTTranslationUnit tu = parse("class A { static int x; }; int A::x = 5;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); ICompositeType A = (ICompositeType) col.getName(0).resolveBinding(); ICPPField x = (ICPPField) col.getName(1).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, x, 3 ); - } - - public void testBug39504() throws Exception - { - IASTTranslationUnit tu = parse( "const int w = 2; int x[ 5 ]; int y = sizeof ( x[w] );" ); //$NON-NLS-1$ - CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); - IVariable w = (IVariable) col.getName(0).resolveBinding(); - IVariable x = (IVariable) col.getName(1).resolveBinding(); - - assertInstances( col, w, 2 ); - assertInstances( col, x, 2 ); - } - - public void testBug43375() throws Exception - { - parse( "extern int x;"); //$NON-NLS-1$ + + assertInstances(col, A, 2); + assertInstances(col, x, 3); } - public void testBug43503() throws Exception - { - StringBuffer buff = new StringBuffer(); - - buff.append( "class SD_02 { "); //$NON-NLS-1$ - buff.append( " public: "); //$NON-NLS-1$ - buff.append( " void f_SD_02(); "); //$NON-NLS-1$ - buff.append( " }; "); //$NON-NLS-1$ - buff.append( "class SD_01 { \n"); //$NON-NLS-1$ - buff.append( " public: \n"); //$NON-NLS-1$ - buff.append( " SD_02 *next; \n"); //$NON-NLS-1$ // REFERENCE SD_02 - buff.append( " void f_SD_01(); \n"); //$NON-NLS-1$ - buff.append( "}; \n"); //$NON-NLS-1$ - buff.append( "int main(){ \n"); //$NON-NLS-1$ - buff.append( " SD_01* a = new SD_01(); \n"); //$NON-NLS-1$ // REFERENCE SD_01 * 2 - buff.append( " a->f_SD_01(); \n"); //$NON-NLS-1$ // REFERENCE a && REFERENCE f_SD_01 - buff.append( "} \n"); //$NON-NLS-1$ - buff.append( "void SD_01::f_SD_01() \n"); //$NON-NLS-1$ // REFERENCE SD_01 - buff.append( "{ \n"); //$NON-NLS-1$ - buff.append( " next->f_SD_02(); \n"); //$NON-NLS-1$ // REFERENCE next && reference f_SD_02 - buff.append( "} \n"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( buff.toString() ); - + public void testBug39504() throws Exception { + IASTTranslationUnit tu = parse("const int w = 2; int x[ 5 ]; int y = sizeof (x[w]);"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 17 ); + tu.accept(col); + + assertEquals(col.size(), 5); + IVariable w = (IVariable) col.getName(0).resolveBinding(); + IVariable x = (IVariable) col.getName(1).resolveBinding(); + + assertInstances(col, w, 2); + assertInstances(col, x, 2); + } + + public void testBug43375() throws Exception { + parse("extern int x;"); + } + + public void testBug43503() throws Exception { + StringBuffer buff = new StringBuffer(); + + buff.append("class SD_02 { "); + buff.append(" public: "); + buff.append(" void f_SD_02(); "); + buff.append(" }; "); + buff.append("class SD_01 { \n"); + buff.append(" public: \n"); + buff.append(" SD_02 *next; \n"); // REFERENCE SD_02 + buff.append(" void f_SD_01(); \n"); + buff.append("}; \n"); + buff.append("int main(){ \n"); + buff.append(" SD_01* a = new SD_01(); \n"); // REFERENCE SD_01 * 2 + buff.append(" a->f_SD_01(); \n"); // REFERENCE a && REFERENCE f_SD_01 + buff.append("} \n"); + buff.append("void SD_01::f_SD_01() \n"); // REFERENCE SD_01 + buff.append("{ \n"); + buff.append(" next->f_SD_02(); \n"); // REFERENCE next && reference f_SD_02 + buff.append("} \n"); + IASTTranslationUnit tu = parse(buff.toString()); + + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertEquals(col.size(), 17); ICompositeType SD_02 = (ICompositeType) col.getName(0).resolveBinding(); ICPPMethod f_SD_02 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPClassType SD_01 = (ICPPClassType) col.getName(2).resolveBinding(); ICPPField next = (ICPPField) col.getName(4).resolveBinding(); ICPPMethod f_SD_01 = (ICPPMethod) col.getName(5).resolveBinding(); ICPPConstructor ctor = SD_01.getConstructors()[0]; - - assertInstances( col, SD_02, 2 ); - assertInstances( col, f_SD_02, 2 ); - assertInstances( col, SD_01, 3 ); - assertInstances( col, ctor, 1 ); - assertInstances( col, next, 2 ); - assertInstances( col, f_SD_01, 4 ); + + assertInstances(col, SD_02, 2); + assertInstances(col, f_SD_02, 2); + assertInstances(col, SD_01, 3); + assertInstances(col, ctor, 1); + assertInstances(col, next, 2); + assertInstances(col, f_SD_01, 4); } - - public void testBug43679_A () throws Exception - { - IASTTranslationUnit tu = parse( "struct Sample { int size() const; }; extern const Sample * getSample(); int trouble() { return getSample()->size(); } " ); //$NON-NLS-1$ + + public void testBug43679_A () throws Exception { + IASTTranslationUnit tu = parse("struct Sample { int size() const; }; extern const Sample * getSample(); int trouble() { return getSample()->size(); } "); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 7 ); + tu.accept(col); + + assertEquals(col.size(), 7); ICompositeType sample = (ICompositeType) col.getName(0).resolveBinding(); ICPPMethod size = (ICPPMethod) col.getName(1).resolveBinding(); IFunction getSample = (IFunction) col.getName(3).resolveBinding(); - assertInstances( col, sample, 2 ); - assertInstances( col, size, 2 ); - assertInstances( col, getSample, 2 ); + assertInstances(col, sample, 2); + assertInstances(col, size, 2); + assertInstances(col, getSample, 2); } - public void testBug43679_B () throws Exception - { - IASTTranslationUnit tu = parse( "struct Sample{int size() const; }; struct Sample; " ); //$NON-NLS-1$ + public void testBug43679_B () throws Exception { + IASTTranslationUnit tu = parse("struct Sample{int size() const; }; struct Sample; "); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); ICompositeType sample = (ICompositeType) col.getName(0).resolveBinding(); ICPPMethod size = (ICPPMethod) col.getName(1).resolveBinding(); - - assertInstances( col, sample, 2 ); - assertInstances( col, size, 1 ); + + assertInstances(col, sample, 2); + assertInstances(col, size, 1); } - - public void testBug43951() throws Exception - { - IASTTranslationUnit tu = parse( "class B{ B(); ~B(); }; B::B(){} B::~B(){}" ); //$NON-NLS-1$ + + public void testBug43951() throws Exception { + IASTTranslationUnit tu = parse("class B{ B(); ~B(); }; B::B(){} B::~B(){}"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 9 ); + tu.accept(col); + + assertEquals(col.size(), 9); ICPPClassType B = (ICPPClassType) col.getName(0).resolveBinding(); ICPPConstructor constructor = (ICPPConstructor) col.getName(1).resolveBinding(); ICPPMethod destructor = (ICPPMethod) col.getName(2).resolveBinding(); - - assertInstances( col, B, 3 ); - assertInstances( col, constructor, 3 ); - assertInstances( col, destructor, 3 ); - } + + assertInstances(col, B, 3); + assertInstances(col, constructor, 3); + assertInstances(col, destructor, 3); + } public void testBug44342() throws Exception { - IASTTranslationUnit tu = parse("class A { void f(){} void f(int){} }; int main(){ A * a = new A(); a->f();} "); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("class A { void f(){} void f(int){} }; int main(){ A * a = new A(); a->f();} "); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 10 ); + tu.accept(col); + + assertEquals(col.size(), 10); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod f1 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPMethod f2 = (ICPPMethod) col.getName(2).resolveBinding(); - + ICPPConstructor ctor = A.getConstructors()[0]; - IVariable a = (IVariable) col.getName( 6 ).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, f1, 2 ); - assertInstances( col, f2, 1 ); - assertInstances( col, ctor, 1 ); - assertInstances( col, a, 2 ); - } + IVariable a = (IVariable) col.getName(6).resolveBinding(); - - public void testCDesignatedInitializers() throws Exception - { + assertInstances(col, A, 2); + assertInstances(col, f1, 2); + assertInstances(col, f2, 1); + assertInstances(col, ctor, 1); + assertInstances(col, a, 2); + } + + public void testCDesignatedInitializers() throws Exception { StringBuffer buffer = new StringBuffer(); - buffer.append( "struct Inner { int a,b,c; };"); //$NON-NLS-1$ - buffer.append( "struct A { int x; int y[]; struct Inner innerArray[]; int z []; };"); //$NON-NLS-1$ - buffer.append( "struct A myA = { .x = 4, .y[3] = 4, .y[4] = 3, .innerArray[0].a = 3, .innerArray[1].b = 5, .innerArray[2].c=6, .z = { 1,4,5} };"); //$NON-NLS-1$ - parse( buffer.toString(), true, ParserLanguage.C ); - } - - public void testBug39551A() throws Exception - { - parse("extern float _Complex conjf (float _Complex);", true, ParserLanguage.C); //$NON-NLS-1$ + buffer.append("struct Inner { int a,b,c; };"); + buffer.append("struct A { int x; int y[]; struct Inner innerArray[]; int z[]; };"); + buffer.append("struct A myA = { .x = 4, .y[3] = 4, .y[4] = 3, .innerArray[0].a = 3, .innerArray[1].b = 5, .innerArray[2].c=6, .z = { 1,4,5} };"); + parse(buffer.toString(), true, ParserLanguage.C); } - public void testBug39551B() throws Exception - { + public void testBug39551A() throws Exception { + parse("extern float _Complex conjf (float _Complex);", true, ParserLanguage.C); + } + + public void testBug39551B() throws Exception { //this used to be 99.99 * __I__, but I don't know where the __I__ came from, its not in C99, nor in GCC - parse("_Imaginary double id = 99.99 * 1i;", true, ParserLanguage.C); //$NON-NLS-1$ + parse("_Imaginary double id = 99.99 * 1i;", true, ParserLanguage.C); } - - public void testCBool() throws Exception - { - parse( "_Bool x;", true, ParserLanguage.C ); //$NON-NLS-1$ + + public void testCBool() throws Exception { + parse("_Bool x;", true, ParserLanguage.C); } - - public void testCBoolAsParameter() throws Exception - { - parse( "void f( _Bool b ) {} " + //$NON-NLS-1$ - "_Bool g( _Bool b ) {} " + //$NON-NLS-1$ - "void main(){" + //$NON-NLS-1$ - " _Bool b; " + //$NON-NLS-1$ - " f(b);" + //$NON-NLS-1$ - " f( g( (_Bool) 1 ) );" + //$NON-NLS-1$ - "}", //$NON-NLS-1$ - true, ParserLanguage.C ); + + public void testCBoolAsParameter() throws Exception { + parse("void f(_Bool b) {} " + + "_Bool g(_Bool b) {} " + + "void main(){" + + " _Bool b; " + + " f(b);" + + " f(g((_Bool) 1) );" + + "}", + true, ParserLanguage.C); } - - public void testBug44510() throws Exception - { - IASTTranslationUnit tu = parse( "int initialize(); " + //$NON-NLS-1$ - "int initialize( char ){} " + //$NON-NLS-1$ - "int initialize(){ return 1; } " + //$NON-NLS-1$ - "void main(){ int i = initialize(); }" ); //$NON-NLS-1$ - + + public void testBug44510() throws Exception { + IASTTranslationUnit tu = parse("int initialize(); " + + "int initialize(char){} " + + "int initialize(){ return 1; } " + + "void main(){ int i = initialize(); }"); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 7 ); + tu.accept(col); + + assertEquals(col.size(), 7); IFunction init1 = (IFunction) col.getName(0).resolveBinding(); IFunction init2 = (IFunction) col.getName(1).resolveBinding(); - - assertInstances( col, init1, 3 ); - assertInstances( col, init2, 1 ); - } - - public void testBug44925() throws Exception - { + + assertInstances(col, init1, 3); + assertInstances(col, init2, 1); + } + + public void testBug44925() throws Exception { StringBuffer buffer = new StringBuffer(); - buffer.append( "class MyClass { };"); //$NON-NLS-1$ - buffer.append( "class MyClass myObj1;"); //$NON-NLS-1$ - buffer.append( "enum MyEnum { Item1 };"); //$NON-NLS-1$ - buffer.append( "enum MyEnum myObj2;"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( buffer.toString() ); - + buffer.append("class MyClass { };"); + buffer.append("class MyClass myObj1;"); + buffer.append("enum MyEnum { Item1 };"); + buffer.append("enum MyEnum myObj2;"); + IASTTranslationUnit tu = parse(buffer.toString()); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 7 ); + tu.accept(col); + + assertEquals(col.size(), 7); ICPPClassType myClass = (ICPPClassType) col.getName(0).resolveBinding(); IVariable obj1 = (IVariable) col.getName(2).resolveBinding(); IEnumeration myEnum = (IEnumeration) col.getName(3).resolveBinding(); IEnumerator item = (IEnumerator) col.getName(4).resolveBinding(); IVariable obj2 = (IVariable)col.getName(6).resolveBinding(); - - assertInstances( col, myClass, 2 ); - assertInstances( col, myEnum, 2 ); - assertSame( obj1.getType(), myClass ); - assertSame( obj2.getType(), myEnum ); - assertSame( item.getType(), myEnum ); + + assertInstances(col, myClass, 2); + assertInstances(col, myEnum, 2); + assertSame(obj1.getType(), myClass); + assertSame(obj2.getType(), myEnum); + assertSame(item.getType(), myEnum); } - - public void testBug44838() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "class A { int myX; A( int x ); };\n"); //$NON-NLS-1$ - buffer.append( "A::A( int x ) : myX( x ) { if( x == 5 ) myX++; }\n"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( buffer.toString() ); - + + public void testBug44838() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("class A { int myX; A(int x); };\n"); + buffer.append("A::A(int x) : myX(x) { if (x == 5) myX++; }\n"); + IASTTranslationUnit tu = parse(buffer.toString()); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 12 ); + tu.accept(col); + + assertEquals(col.size(), 12); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPField myX = (ICPPField) col.getName(1).resolveBinding(); ICPPConstructor ctor = (ICPPConstructor) col.getName(2).resolveBinding(); IParameter x = (IParameter) col.getName(3).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, myX, 3 ); - assertInstances( col, ctor, 3 ); - assertInstances( col, x, 4 ); - } - - public void testBug46165() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "class A { int myX; A( int x ); };\n"); //$NON-NLS-1$ - buffer.append( "A::A( int x ) : myX( x ) { if( x == 5 ) myX++; }\n"); //$NON-NLS-1$ - parse( buffer.toString() ); + + assertInstances(col, A, 2); + assertInstances(col, myX, 3); + assertInstances(col, ctor, 3); + assertInstances(col, x, 4); } - public void testBug47624() throws Exception - { + public void testBug46165() throws Exception { StringBuffer buffer = new StringBuffer(); - buffer.append( "struct s { }; \n" ); //$NON-NLS-1$ - buffer.append( "void f ( int s ) { \n" ); //$NON-NLS-1$ - buffer.append( " struct s sInstance; \n" ); //$NON-NLS-1$ - buffer.append( "}\n"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( buffer.toString() ); - + buffer.append("class A { int myX; A(int x); };\n"); + buffer.append("A::A(int x) : myX(x) { if (x == 5) myX++; }\n"); + parse(buffer.toString()); + } + + public void testBug47624() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("struct s { }; \n"); + buffer.append("void f (int s) { \n"); + buffer.append(" struct s sInstance; \n"); + buffer.append("}\n"); + IASTTranslationUnit tu = parse(buffer.toString()); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); ICPPClassType s = (ICPPClassType) col.getName(0).resolveBinding(); IParameter s2 = (IParameter) col.getName(2).resolveBinding(); IVariable instance = (IVariable) col.getName(4).resolveBinding(); - assertInstances( col, s, 2 ); - assertInstances( col, s2, 1 ); - assertSame( instance.getType(), s ); + assertInstances(col, s, 2); + assertInstances(col, s2, 1); + assertSame(instance.getType(), s); } - - public void testQualifiedLookup() throws Exception{ + + public void testQualifiedLookup() throws Exception { //this is meant to test that on a->f, the lookup for f is qualified //the namespace is necessary because of bug 47926 StringBuffer buffer = new StringBuffer(); - buffer.append( "namespace N {" ); //$NON-NLS-1$ - buffer.append( " void f () {} \n" ); //$NON-NLS-1$ - buffer.append( " class A { }; \n" ); //$NON-NLS-1$ - buffer.append( "}" ); //$NON-NLS-1$ - buffer.append( "void main() { N::A * a = new N::A(); a->f(); } "); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( buffer.toString() ); - + buffer.append("namespace N {"); + buffer.append(" void f () {} \n"); + buffer.append(" class A { }; \n"); + buffer.append("}"); + buffer.append("void main() { N::A * a = new N::A(); a->f(); } "); + IASTTranslationUnit tu = parse(buffer.toString()); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 13 ); + tu.accept(col); + + assertEquals(col.size(), 13); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); IFunction f = (IFunction) col.getName(1).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(2).resolveBinding(); - + ICPPConstructor ctor = A.getConstructors()[0]; - + IProblemBinding fp = (IProblemBinding) col.getName(12).resolveBinding(); - assertEquals( fp.getID(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND ); - - assertInstances( col, N, 3 ); - assertInstances( col, f, 1 ); - assertInstances( col, A, 3 ); - assertInstances( col, ctor, 2 ); + assertEquals(fp.getID(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND); + + assertInstances(col, N, 3); + assertInstances(col, f, 1); + assertInstances(col, A, 3); + assertInstances(col, ctor, 2); } - - public void testBug43110() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append("void x( int y, ... );\n"); //$NON-NLS-1$ - buffer.append("void y( int x... );\n"); //$NON-NLS-1$ - buffer.append("void z(...);"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( buffer.toString() ); - + + public void testBug43110() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("void x(int y, ...);\n"); + buffer.append("void y(int x...);\n"); + buffer.append("void z(...);"); + IASTTranslationUnit tu = parse(buffer.toString()); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); IFunction x = (IFunction) col.getName(0).resolveBinding(); IFunction y = (IFunction) col.getName(2).resolveBinding(); IFunction z = (IFunction) col.getName(4).resolveBinding(); @@ -1553,1088 +1457,1023 @@ public class CompleteParser2Tests extends BaseTestCase { assertNotNull(y); assertNotNull(z); } - - public void testBug43110_XRef() throws Exception - { + + public void testBug43110_XRef() throws Exception { StringBuffer buffer = new StringBuffer(); - buffer.append( "void foo( ... ) {}\n" ); //$NON-NLS-1$ - buffer.append( "void main( ){ foo( 1 ); }\n" ); //$NON-NLS-1$ - - IASTTranslationUnit tu = parse( buffer.toString() ); - + buffer.append("void foo(...) {}\n"); + buffer.append("void main(){ foo(1); }\n"); + + IASTTranslationUnit tu = parse(buffer.toString()); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); IFunction foo = (IFunction) col.getName(0).resolveBinding(); - assertInstances( col, foo, 2 ); + assertInstances(col, foo, 2); } - + public void testErrorHandling_1() throws Exception { - IASTTranslationUnit tu = parse( "A anA; int x = c; class A {}; A * anotherA = &anA; int b;", false ); //$NON-NLS-1$ - + IASTTranslationUnit tu = parse("A anA; int x = c; class A {}; A * anotherA = &anA; int b;", false); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 9 ); + tu.accept(col); + + assertEquals(col.size(), 9); IProblemBinding p = (IProblemBinding) col.getName(0).resolveBinding(); IVariable anA = (IVariable) col.getName(1).resolveBinding(); - assertNotNull( col.getName(2).resolveBinding() ); + assertNotNull(col.getName(2).resolveBinding()); IProblemBinding p2 = (IProblemBinding) col.getName(3).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(4).resolveBinding(); - - assertInstances( col, anA, 2 ); - assertInstances( col, A, 2 ); - - assertNotNull( p ); - assertNotNull( p2 ); - + + assertInstances(col, anA, 2); + assertInstances(col, A, 2); + + assertNotNull(p); + assertNotNull(p2); + IProblemType pt= (IProblemType) anA.getType(); assertEquals(ISemanticProblem.TYPE_UNRESOLVED_NAME, pt.getID()); } - + public void testBug44340() throws Exception { - // inline function with reference to variables declared after them - IASTTranslationUnit tu = parse ("class A{ int getX() {return x[1];} int x[10];};"); //$NON-NLS-1$ - + // Inline function with reference to variables declared after them + IASTTranslationUnit tu = parse ("class A{ int getX() {return x[1];} int x[10];};"); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); - + tu.accept(col); + + assertEquals(col.size(), 4); + ICPPField x = (ICPPField) col.getName(2).resolveBinding(); - assertInstances( col, x, 2 ); - } - - public void testBug47628() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void h(char) { }\n"); //$NON-NLS-1$ - writer.write( "void h(unsigned char) { }\n"); //$NON-NLS-1$ - writer.write( "void h(signed char) { } // not shown in outline, parsed as char\n"); //$NON-NLS-1$ - - parse( writer.toString() ); - } - - public void testBug47636() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void f( char [] ); \n" ); //$NON-NLS-1$ - writer.write( "void f( char * ){} \n" ); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( writer.toString() ); - CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); - IFunction f1 = (IFunction) col.getName(0).resolveBinding(); - IParameter p1 = (IParameter)col.getName(1).resolveBinding(); - IFunction f2 = (IFunction) col.getName(2).resolveBinding(); - IParameter p2 = (IParameter)col.getName(3).resolveBinding(); - assertSame( f1, f2 ); - assertSame( p1, p2 ); - } - - public void testBug45697() throws Exception - { - Writer writer = new StringWriter(); - writer.write( " int f( bool ); \n"); //$NON-NLS-1$ - writer.write( " int f( char ){ } "); //$NON-NLS-1$ - - IASTTranslationUnit tu = parse( writer.toString() ); - CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); - IFunction f1 = (IFunction) col.getName(0).resolveBinding(); - IParameter p1 = (IParameter)col.getName(1).resolveBinding(); - IFunction f2 = (IFunction) col.getName(2).resolveBinding(); - IParameter p2 = (IParameter)col.getName(3).resolveBinding(); - - assertNotSame( f1, f2 ); - assertNotSame( p1, p2 ); + assertInstances(col, x, 2); } - public void testBug54639() throws Exception - { + public void testBug47628() throws Exception { Writer writer = new StringWriter(); - writer.write( "typedef enum _A { } A, *pA; " ); //$NON-NLS-1$ - - IASTTranslationUnit tu = parse( writer.toString() ); + writer.write("void h(char) { }\n"); + writer.write("void h(unsigned char) { }\n"); + writer.write("void h(signed char) { } // not shown in outline, parsed as char\n"); + + parse(writer.toString()); + } + + public void testBug47636() throws Exception { + Writer writer = new StringWriter(); + writer.write("void f(char[]); \n"); + writer.write("void f(char *){} \n"); + IASTTranslationUnit tu = parse(writer.toString()); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); - + tu.accept(col); + + assertEquals(col.size(), 4); + IFunction f1 = (IFunction) col.getName(0).resolveBinding(); + IParameter p1 = (IParameter)col.getName(1).resolveBinding(); + IFunction f2 = (IFunction) col.getName(2).resolveBinding(); + IParameter p2 = (IParameter)col.getName(3).resolveBinding(); + assertSame(f1, f2); + assertSame(p1, p2); + } + + public void testBug45697() throws Exception { + Writer writer = new StringWriter(); + writer.write(" int f(bool); \n"); + writer.write(" int f(char){ } "); + + IASTTranslationUnit tu = parse(writer.toString()); + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertEquals(col.size(), 4); + IFunction f1 = (IFunction) col.getName(0).resolveBinding(); + IParameter p1 = (IParameter)col.getName(1).resolveBinding(); + IFunction f2 = (IFunction) col.getName(2).resolveBinding(); + IParameter p2 = (IParameter)col.getName(3).resolveBinding(); + + assertNotSame(f1, f2); + assertNotSame(p1, p2); + } + + public void testBug54639() throws Exception { + Writer writer = new StringWriter(); + writer.write("typedef enum _A { } A, *pA; "); + + IASTTranslationUnit tu = parse(writer.toString()); + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertEquals(col.size(), 3); + IEnumeration _A = (IEnumeration) col.getName(0).resolveBinding(); ITypedef A = (ITypedef) col.getName(1).resolveBinding(); ITypedef pA = (ITypedef)col.getName(2).resolveBinding(); - - assertNotNull( _A ); - assertSame( A.getType(), _A ); - assertTrue( pA.getType() instanceof IPointerType ); - assertSame( ((IPointerType)pA.getType()).getType(), _A ); + + assertNotNull(_A); + assertSame(A.getType(), _A); + assertTrue(pA.getType() instanceof IPointerType); + assertSame(((IPointerType)pA.getType()).getType(), _A); } - - public void testBug55163() throws Exception - { + + public void testBug55163() throws Exception { Writer writer = new StringWriter(); - writer.write( "void foo() { \n"); //$NON-NLS-1$ - writer.write( " int i, n; \n"); //$NON-NLS-1$ - writer.write( " double di; \n"); //$NON-NLS-1$ - writer.write( " for( i = n - 1, di = (double)( i + i ); i > 0; i-- ){ } \n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - - IASTTranslationUnit tu = parse( writer.toString() ); + writer.write("void foo() { \n"); + writer.write(" int i, n; \n"); + writer.write(" double di; \n"); + writer.write(" for (i = n - 1, di = (double)(i + i); i > 0; i--){ } \n"); + writer.write("}\n"); + + IASTTranslationUnit tu = parse(writer.toString()); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 11 ); + tu.accept(col); + + assertEquals(col.size(), 11); IVariable i = (IVariable)col.getName(1).resolveBinding(); IVariable n = (IVariable)col.getName(2).resolveBinding(); IVariable di = (IVariable)col.getName(3).resolveBinding(); - - assertInstances( col, i, 6 ); - assertInstances( col, n, 2 ); - assertInstances( col, di, 2 ); + + assertInstances(col, i, 6); + assertInstances(col, n, 2); + assertInstances(col, di, 2); } - public void testBug55673() throws Exception{ + public void testBug55673() throws Exception { Writer writer = new StringWriter(); - writer.write( "struct Example { int i; int ( * pfi ) ( int ); }; "); //$NON-NLS-1$ - - parse( writer.toString() ); - IASTTranslationUnit tu = parse( writer.toString() ); + writer.write("struct Example { int i; int (* pfi) (int); }; "); + + parse(writer.toString()); + IASTTranslationUnit tu = parse(writer.toString()); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); + tu.accept(col); + + assertEquals(col.size(), 4); ICPPField pfi = (ICPPField)col.getName(2).resolveBinding(); - - assertNotNull( pfi ); - assertTrue( pfi.getType() instanceof IPointerType ); - assertTrue( ((IPointerType)pfi.getType()).getType() instanceof IFunctionType ); + + assertNotNull(pfi); + assertTrue(pfi.getType() instanceof IPointerType); + assertTrue(((IPointerType)pfi.getType()).getType() instanceof IFunctionType); } - - public void testBug54531() throws Exception - { - parse( "typedef enum _A {} A, *pA;" ); //$NON-NLS-1$ + + public void testBug54531() throws Exception { + parse("typedef enum _A {} A, *pA;"); } - - public void testBug56516() throws Exception - { - IASTTranslationUnit tu = parse( "typedef struct blah sb;"); //$NON-NLS-1$ + + public void testBug56516() throws Exception { + IASTTranslationUnit tu = parse("typedef struct blah sb;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 2 ); - + tu.accept(col); + + assertEquals(col.size(), 2); + ICPPClassType blah = (ICPPClassType) col.getName(0).resolveBinding(); ITypedef sb = (ITypedef) col.getName(1).resolveBinding(); - assertSame( sb.getType(), blah ); - } - - public void testBug53786() throws Exception - { - parse( "struct Example { struct Data * data; };"); //$NON-NLS-1$ - } - - public void testBug54029() throws Exception - { - parse( "typedef int T; T i;" ); //$NON-NLS-1$ + assertSame(sb.getType(), blah); } - public void testBug47625() throws Exception - { + public void testBug53786() throws Exception { + parse("struct Example { struct Data * data; };"); + } + + public void testBug54029() throws Exception { + parse("typedef int T; T i;"); + } + + public void testBug47625() throws Exception { Writer writer = new StringWriter(); - writer.write("struct s { int num; }; "); //$NON-NLS-1$ - writer.write("namespace ns{ "); //$NON-NLS-1$ - writer.write(" struct s { double num; };"); //$NON-NLS-1$ - writer.write(" s inner = { 3.14 };"); //$NON-NLS-1$ - writer.write(" ::s outer = { 42 };"); //$NON-NLS-1$ - writer.write("}"); //$NON-NLS-1$ - - IASTTranslationUnit tu = parse( writer.toString() ); - - CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); + writer.write("struct s { int num; }; "); + writer.write("namespace ns{ "); + writer.write(" struct s { double num; };"); + writer.write(" s inner = { 3.14 };"); + writer.write(" ::s outer = { 42 };"); + writer.write("}"); + + IASTTranslationUnit tu = parse(writer.toString()); + + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertEquals(col.size(), 10); - assertEquals( col.size(), 10 ); - ICPPClassType s = (ICPPClassType) col.getName(0).resolveBinding(); ICPPClassType s2 = (ICPPClassType) col.getName(3).resolveBinding(); - + ICPPClassType ref1 = (ICPPClassType) col.getName(5).resolveBinding(); - ICPPClassType ref2 = (ICPPClassType) col.getName( 8 ).resolveBinding(); - - assertSame( s, ref2 ); - assertSame( s2, ref1 ); + ICPPClassType ref2 = (ICPPClassType) col.getName(8).resolveBinding(); + + assertSame(s, ref2); + assertSame(s2, ref1); } - - public void testBug57754() throws Exception - { + + public void testBug57754() throws Exception { Writer writer = new StringWriter(); - writer.write( "struct X { " ); //$NON-NLS-1$ - writer.write( " typedef int T; " ); //$NON-NLS-1$ - writer.write( " void f( T ); " ); //$NON-NLS-1$ - writer.write( "}; " ); //$NON-NLS-1$ - writer.write( "void X::f( T ) { } " ); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( writer.toString() ); + writer.write("struct X { "); + writer.write(" typedef int T; "); + writer.write(" void f(T); "); + writer.write("}; "); + writer.write("void X::f(T) { } "); + IASTTranslationUnit tu = parse(writer.toString()); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 10 ); + tu.accept(col); + + assertEquals(col.size(), 10); ICPPClassType X = (ICPPClassType) col.getName(0).resolveBinding(); ITypedef T = (ITypedef) col.getName(1).resolveBinding(); ICPPMethod f = (ICPPMethod) col.getName(2).resolveBinding(); - - assertInstances( col, X, 2 ); - assertInstances( col, T, 3 ); - assertInstances( col, f, 3 ); - } - - public void testBug57800() throws Exception - { + + assertInstances(col, X, 2); + assertInstances(col, T, 3); + assertInstances(col, f, 3); + } + + public void testBug57800() throws Exception { Writer writer= new StringWriter(); - writer.write( "class G2 { int j; };"); //$NON-NLS-1$ - writer.write( "typedef G2 AltG2;"); //$NON-NLS-1$ - writer.write( "class AltG3 : AltG2 { int x;};"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( writer.toString() ); + writer.write("class G2 { int j; };"); + writer.write("typedef G2 AltG2;"); + writer.write("class AltG3 : AltG2 { int x;};"); + IASTTranslationUnit tu = parse(writer.toString()); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 7 ); + tu.accept(col); + + assertEquals(col.size(), 7); ICPPClassType G2 = (ICPPClassType) col.getName(0).resolveBinding(); ITypedef alt = (ITypedef) col.getName(3).resolveBinding(); - - assertInstances( col, G2, 2 ); - assertInstances( col, alt, 2 ); + + assertInstances(col, G2, 2); + assertInstances(col, alt, 2); } - - public void testBug46246() throws Exception - { + + public void testBug46246() throws Exception { Writer writer = new StringWriter(); - writer.write( "struct A { "); //$NON-NLS-1$ - writer.write( " struct B { int ab; } b; "); //$NON-NLS-1$ - writer.write( " int a; "); //$NON-NLS-1$ - writer.write( "}; "); //$NON-NLS-1$ - writer.write( "struct A a1; "); //$NON-NLS-1$ - writer.write( "struct B b1; "); //$NON-NLS-1$ - - IASTTranslationUnit tu = parse( writer.toString(), true, ParserLanguage.C ); + writer.write("struct A { "); + writer.write(" struct B { int ab; } b; "); + writer.write(" int a; "); + writer.write("}; "); + writer.write("struct A a1; "); + writer.write("struct B b1; "); + + IASTTranslationUnit tu = parse(writer.toString(), true, ParserLanguage.C); CNameCollector col = new CNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 9 ); + tu.accept(col); + + assertEquals(col.size(), 9); ICompositeType A = (ICompositeType) col.getName(0).resolveBinding(); ICompositeType B = (ICompositeType) col.getName(1).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, B, 2 ); + + assertInstances(col, A, 2); + assertInstances(col, B, 2); } - - public void testBug45235() throws Exception - { - parse( "class A { friend class B; friend void f(); }; " ); //$NON-NLS-1$ + + public void testBug45235() throws Exception { + parse("class A { friend class B; friend void f(); }; "); } - - public void testBug57791() throws Exception - { + + public void testBug57791() throws Exception { Writer writer = new StringWriter(); - writer.write(" void f() { "); //$NON-NLS-1$ - writer.write(" struct astruct astruct; "); //$NON-NLS-1$ - writer.write(" astruct.foo++; "); //$NON-NLS-1$ - writer.write(" }"); //$NON-NLS-1$ - - parse( writer.toString(), true, ParserLanguage.C ); - } - - public void testBug44249() throws Exception - { + writer.write(" void f() { "); + writer.write(" struct astruct astruct; "); + writer.write(" astruct.foo++; "); + writer.write(" }"); - parse( "class SD_01 { public:\n void SD_01::f_SD_01();};" ); //$NON-NLS-1$ + parse(writer.toString(), true, ParserLanguage.C); } - - public void testBug59149() throws Exception - { + + public void testBug44249() throws Exception { + + parse("class SD_01 { public:\n void SD_01::f_SD_01();};"); + } + + public void testBug59149() throws Exception { Writer writer = new StringWriter(); - writer.write( "class A{ friend class B; friend class B; };" ); //$NON-NLS-1$ - writer.write( "class B{ };" ); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug59302() throws Exception - { - Writer writer = new StringWriter(); - writer.write("class A { class N{}; }; "); //$NON-NLS-1$ - writer.write("class B { friend class A::N; }; "); //$NON-NLS-1$ - parse( writer.toString() ); - } - - - - public void testULong() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#ifndef ASMINCLUDE\n"); //$NON-NLS-1$ - writer.write( "typedef unsigned short ushort;\n"); //$NON-NLS-1$ - writer.write( "typedef volatile unsigned long semaphore;\n"); //$NON-NLS-1$ - writer.write( "typedef unsigned long ulong;\n"); //$NON-NLS-1$ - writer.write( "#ifndef _NO_LONGLONG\n"); //$NON-NLS-1$ - writer.write( "typedef long long longlong;\n"); //$NON-NLS-1$ - writer.write( "typedef unsigned long long ulonglong;\n"); //$NON-NLS-1$ - writer.write( "#endif /* _NO_LONGLONG */\n"); //$NON-NLS-1$ - writer.write( "#endif /* ASMINCLUDE */\n"); //$NON-NLS-1$ - writer.write( "typedef struct section_type_ {\n"); //$NON-NLS-1$ - writer.write( "ulong source;\n"); //$NON-NLS-1$ - writer.write( "ulong dest;\n"); //$NON-NLS-1$ - writer.write( "ulong bytes;\n"); //$NON-NLS-1$ - writer.write( "} section_type;\n"); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug47926() throws Exception - { - parse( "void f() {} class A {}; void main() { A * a = new A(); a->f(); }", false ); //$NON-NLS-1$ - } - - public void testBug50984_ASTMethod_getOwnerClassSpecifier_ClassCastException() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < typename _OutIter > " ); //$NON-NLS-1$ - writer.write( "class num_put { " ); //$NON-NLS-1$ - writer.write( " typedef _OutIter iter_type; " ); //$NON-NLS-1$ - writer.write( " template< typename _ValueT > " ); //$NON-NLS-1$ - writer.write( " iter_type _M_convert_float( iter_type ); " ); //$NON-NLS-1$ - writer.write( "}; " ); //$NON-NLS-1$ - writer.write( "template < typename _OutIter > " ); //$NON-NLS-1$ - writer.write( "template < typename _ValueT > " ); //$NON-NLS-1$ - writer.write( "_OutIter num_put<_OutIter>::_M_convert_float( _OutIter ) { } " ); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testGloballyQualifiedUsingDeclaration() throws Exception - { - parse( "int iii; namespace N { using ::iii; }" ); //$NON-NLS-1$ - } - - public void test57513_new() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class A{ A(); A( int ); }; \n" ); //$NON-NLS-1$ - writer.write( " void f() { \n" ); //$NON-NLS-1$ - writer.write( " A * a1 = new A; \n" ); //$NON-NLS-1$ - writer.write( " A * a2 = new(1)A(); \n" ); //$NON-NLS-1$ - writer.write( " A * a3 = new A( 1 ); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("class A{ friend class B; friend class B; };"); + writer.write("class B{ };"); + parse(writer.toString()); } - public void test57513_NoConstructor() throws Exception - { + public void testBug59302() throws Exception { Writer writer = new StringWriter(); - writer.write( "class A{ }; \n" ); //$NON-NLS-1$ - writer.write( " void f() { \n" ); //$NON-NLS-1$ - writer.write( " A * a1 = new A; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("class A { class N{}; }; "); + writer.write("class B { friend class A::N; }; "); + parse(writer.toString()); } - - public void test57513_ctorinit() throws Exception - { + + public void testULong() throws Exception { Writer writer = new StringWriter(); - writer.write( "class A{ A(); A( A * ); }; \n" ); //$NON-NLS-1$ - writer.write( "class B : public A { B(); }; \n" ); //$NON-NLS-1$ - writer.write( "B::B():A( new A ){} \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("#ifndef ASMINCLUDE\n"); + writer.write("typedef unsigned short ushort;\n"); + writer.write("typedef volatile unsigned long semaphore;\n"); + writer.write("typedef unsigned long ulong;\n"); + writer.write("#ifndef _NO_LONGLONG\n"); + writer.write("typedef long long longlong;\n"); + writer.write("typedef unsigned long long ulonglong;\n"); + writer.write("#endif /* _NO_LONGLONG */\n"); + writer.write("#endif /* ASMINCLUDE */\n"); + writer.write("typedef struct section_type_ {\n"); + writer.write("ulong source;\n"); + writer.write("ulong dest;\n"); + writer.write("ulong bytes;\n"); + writer.write("} section_type;\n"); + parse(writer.toString()); + } + + public void testBug47926() throws Exception { + parse("void f() {} class A {}; void main() { A * a = new A(); a->f(); }", false); + } + + public void testBug50984_ASTMethod_getOwnerClassSpecifier_ClassCastException() throws Exception { + Writer writer = new StringWriter(); + writer.write("template < typename _OutIter > "); + writer.write("class num_put { "); + writer.write(" typedef _OutIter iter_type; "); + writer.write(" template< typename _ValueT > "); + writer.write(" iter_type _M_convert_float(iter_type); "); + writer.write("}; "); + writer.write("template < typename _OutIter > "); + writer.write("template < typename _ValueT > "); + writer.write("_OutIter num_put<_OutIter>::_M_convert_float(_OutIter) { } "); + parse(writer.toString()); } - - public void test575513_qualified() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "namespace Foo{ " ); //$NON-NLS-1$ - writer.write( " class Bar{ public : Bar(); }; " ); //$NON-NLS-1$ - writer.write( "} " ); //$NON-NLS-1$ - writer.write( "void main(){ " ); //$NON-NLS-1$ - writer.write( " Foo::Bar * bar = new Foo::Bar(); " ); //$NON-NLS-1$ - writer.write( "} " ); //$NON-NLS-1$ - - parse( writer.toString() ); + + public void testGloballyQualifiedUsingDeclaration() throws Exception { + parse("int iii; namespace N { using ::iii; }"); } - - public void testBug60944() throws Exception - { + + public void test57513_new() throws Exception { Writer writer = new StringWriter(); - writer.write( "typedef int OurInt;\n"); //$NON-NLS-1$ - writer.write( "class A { int x; };\n"); //$NON-NLS-1$ - writer.write( "typedef A AnotherA;\n"); //$NON-NLS-1$ - writer.write( "typedef AnotherA SecondA;\n"); //$NON-NLS-1$ - writer.write( "typedef OurInt AnotherInt;\n" ); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("class A{ A(); A(int); }; \n"); + writer.write(" void f() { \n"); + writer.write(" A * a1 = new A; \n"); + writer.write(" A * a2 = new(1)A(); \n"); + writer.write(" A * a3 = new A(1); \n"); + writer.write("} \n"); + + parse(writer.toString()); } - - public void testDestructorReference() throws Exception - { + + public void test57513_NoConstructor() throws Exception { Writer writer = new StringWriter(); - writer.write( "class ABC {\n"); //$NON-NLS-1$ - writer.write( " public:\n"); //$NON-NLS-1$ - writer.write( " ~ABC(){ }\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "int main() { ABC * abc = new ABC();\n"); //$NON-NLS-1$ - writer.write( "abc->~ABC();\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("class A{ }; \n"); + writer.write(" void f() { \n"); + writer.write(" A * a1 = new A; \n"); + writer.write("} \n"); + + parse(writer.toString()); + } + + public void test57513_ctorinit() throws Exception { + Writer writer = new StringWriter(); + writer.write("class A{ A(); A(A *); }; \n"); + writer.write("class B : public A { B(); }; \n"); + writer.write("B::B():A(new A){} \n"); + + parse(writer.toString()); + } + + public void test575513_qualified() throws Exception { + Writer writer = new StringWriter(); + writer.write("namespace Foo{ "); + writer.write(" class Bar{ public : Bar(); }; "); + writer.write("} "); + writer.write("void main(){ "); + writer.write(" Foo::Bar * bar = new Foo::Bar(); "); + writer.write("} "); + + parse(writer.toString()); + } + + public void testBug60944() throws Exception { + Writer writer = new StringWriter(); + writer.write("typedef int OurInt;\n"); + writer.write("class A { int x; };\n"); + writer.write("typedef A AnotherA;\n"); + writer.write("typedef AnotherA SecondA;\n"); + writer.write("typedef OurInt AnotherInt;\n"); + parse(writer.toString()); + } + + public void testDestructorReference() throws Exception { + Writer writer = new StringWriter(); + writer.write("class ABC {\n"); + writer.write(" public:\n"); + writer.write(" ~ABC(){ }\n"); + writer.write("};\n"); + writer.write("int main() { ABC * abc = new ABC();\n"); + writer.write("abc->~ABC();\n"); + writer.write("}\n"); + + parse(writer.toString()); } - - public void testBug39676_tough() throws Exception - { - parse( "int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };", true, ParserLanguage.C, true ); //$NON-NLS-1$ + + public void testBug39676_tough() throws Exception { + parse("int widths[] = {[0 ... 9] = 1,[10 ... 99] = 2,[100] = 3 };", true, ParserLanguage.C, true); } - - public void testBug60939() throws Exception - { - for( int i = 0; i < 2; ++i ) + + public void testBug60939() throws Exception { + for (int i = 0; i < 2; ++i) { Writer writer = new StringWriter(); - writer.write( "namespace ABC { class DEF { }; }\n"); //$NON-NLS-1$ - if( i == 0 ) - writer.write( "using namespace ABC;\n"); //$NON-NLS-1$ + writer.write("namespace ABC { class DEF { }; }\n"); + if (i == 0) + writer.write("using namespace ABC;\n"); else - writer.write( "using ABC::DEF;\n"); //$NON-NLS-1$ - writer.write( "class GHI : public DEF { };"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("using ABC::DEF;\n"); + writer.write("class GHI : public DEF { };"); + parse(writer.toString()); } - + } - } - - public void testBug64010() throws Exception - { + public void testBug64010() throws Exception { Writer writer = new StringWriter(); - writer.write( " #define ONE else if (0) { } \n"); //$NON-NLS-1$ - writer.write( " #define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE \n "); //$NON-NLS-1$ - writer.write( " #define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN \n "); //$NON-NLS-1$ - writer.write( " #define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN \n"); //$NON-NLS-1$ - writer.write("void foo() "); //$NON-NLS-1$ - writer.write("{ "); //$NON-NLS-1$ - writer.write(" if (0) { } "); //$NON-NLS-1$ - writer.write(" /* 2,500 else if's. */ "); //$NON-NLS-1$ - writer.write(" THOU THOU HUN HUN HUN HUN HUN "); //$NON-NLS-1$ - writer.write("} "); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write(" #define ONE else if (0) { } \n"); + writer.write(" #define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE \n "); + writer.write(" #define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN \n "); + writer.write(" #define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN \n"); + writer.write("void foo() "); + writer.write("{ "); + writer.write(" if (0) { } "); + writer.write(" /* 2,500 else if's. */ "); + writer.write(" THOU THOU HUN HUN HUN HUN HUN "); + writer.write("} "); + + parse(writer.toString()); } - - public void testBug64271() throws Exception - { + + public void testBug64271() throws Exception { Writer writer = new StringWriter(); - writer.write( "typedef int DWORD;\n" ); //$NON-NLS-1$ - writer.write( "typedef char BYTE;\n"); //$NON-NLS-1$ - writer.write( "#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\\n"); //$NON-NLS-1$ - writer.write( "((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\\n"); //$NON-NLS-1$ - writer.write( "((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))\n"); //$NON-NLS-1$ - writer.write( "enum e {\n"); //$NON-NLS-1$ - writer.write( "blah1 = 5,\n"); //$NON-NLS-1$ - writer.write( "blah2 = MAKEFOURCC('a', 'b', 'c', 'd'),\n"); //$NON-NLS-1$ - writer.write( "blah3\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "e mye = blah;\n"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("typedef int DWORD;\n"); + writer.write("typedef char BYTE;\n"); + writer.write("#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\\n"); + writer.write("((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\\n"); + writer.write("((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24))\n"); + writer.write("enum e {\n"); + writer.write("blah1 = 5,\n"); + writer.write("blah2 = MAKEFOURCC('a', 'b', 'c', 'd'),\n"); + writer.write("blah3\n"); + writer.write("};\n"); + writer.write("e mye = blah;\n"); + parse(writer.toString()); } - - public void testBug47752() throws Exception - { + + public void testBug47752() throws Exception { Writer writer = new StringWriter(); - writer.write( "class BBC\n"); //$NON-NLS-1$ - writer.write( "{\n"); //$NON-NLS-1$ - writer.write( "int x;\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "void func( BBC bar )\n"); //$NON-NLS-1$ - writer.write( "try\n"); //$NON-NLS-1$ - writer.write( "{\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - writer.write( "catch ( BBC error )\n"); //$NON-NLS-1$ - writer.write( "{\n"); //$NON-NLS-1$ - writer.write( " //... error handling code ...\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("class BBC\n"); + writer.write("{\n"); + writer.write("int x;\n"); + writer.write("};\n"); + writer.write("void func(BBC bar)\n"); + writer.write("try\n"); + writer.write("{\n"); + writer.write("}\n"); + writer.write("catch (BBC error)\n"); + writer.write("{\n"); + writer.write(" //... error handling code ...\n"); + writer.write("}\n"); + parse(writer.toString()); } - public void testBug61972() throws Exception - { - parse( "#define DEF1(A1) A1\n#define DEF2 DEF1(DEF2)\nDEF2;", false ); //$NON-NLS-1$ + public void testBug61972() throws Exception { + parse("#define DEF1(A1) A1\n#define DEF2 DEF1(DEF2)\nDEF2;", false); } - - public void testBug65569() throws Exception - { - parse( "class Sample;\nstruct Sample { /* ... */ };" ); //$NON-NLS-1$ + + public void testBug65569() throws Exception { + parse("class Sample;\nstruct Sample { /* ... */ };"); } - - public void testBug64268() throws Exception - { + + public void testBug64268() throws Exception { Writer writer = new StringWriter(); - writer.write("#define BODY \\\n"); //$NON-NLS-1$ - writer.write("for (;;) { \\\n"); //$NON-NLS-1$ - writer.write("/* this multi-line comment messes \\\n"); //$NON-NLS-1$ - writer.write("up the parser. */ }\n"); //$NON-NLS-1$ - writer.write(" void abc() {\n"); //$NON-NLS-1$ - writer.write("BODY\n"); //$NON-NLS-1$ - writer.write("}\n"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("#define BODY \\\n"); + writer.write("for (;;) { \\\n"); + writer.write("/* this multi-line comment messes \\\n"); + writer.write("up the parser. */ }\n"); + writer.write(" void abc() {\n"); + writer.write("BODY\n"); + writer.write("}\n"); + parse(writer.toString()); } - - public void testBug67622() throws Exception - { - parse( "const char * x = __FILE__;"); //$NON-NLS-1$ + + public void testBug67622() throws Exception { + parse("const char * x = __FILE__;"); } - - public void testBug67680() throws Exception - { + + public void testBug67680() throws Exception { Writer writer = new StringWriter(); - writer.write( "template < class T> class Base {}; \n" ); //$NON-NLS-1$ - writer.write( "class Derived : public Base, Base, foo {}; \n" ); //$NON-NLS-1$ - - parse( writer.toString(), false ); + writer.write("template < class T> class Base {}; \n"); + writer.write("class Derived : public Base, Base, foo {}; \n"); + + parse(writer.toString(), false); } - - public void testTypeIDSignature() throws Exception - { - parse( "int * v = (int*)0;");//$NON-NLS-1$ + + public void testTypeIDSignature() throws Exception { + parse("int * v = (int*)0;");//$NON-NLS-1$ } - - public void testUnaryAmperCast() throws Exception{ + + public void testUnaryAmperCast() throws Exception { Writer writer = new StringWriter(); - writer.write( "void f( char * ); \r\n "); //$NON-NLS-1$ - writer.write( "void f( char ); \n "); //$NON-NLS-1$ - writer.write( "void main() { \n "); //$NON-NLS-1$ - writer.write( " char * t = new char [ 5 ]; \n "); //$NON-NLS-1$ - writer.write( " f( &t[1] ); \n "); //$NON-NLS-1$ - writer.write( "} \n "); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("void f(char *); \r\n "); + writer.write("void f(char ); \n "); + writer.write("void main() { \n "); + writer.write(" char * t = new char[ 5 ]; \n "); + writer.write(" f(&t[1]); \n "); + writer.write("} \n "); + + parse(writer.toString()); } - - public void testBug68235() throws Exception{ + + public void testBug68235() throws Exception { Writer writer = new StringWriter(); - writer.write( " struct xTag { int x; }; "); //$NON-NLS-1$ - writer.write( " typedef xTag xType; "); //$NON-NLS-1$ - writer.write( " typedef struct yTag { int x; } yType; "); //$NON-NLS-1$ - writer.write( " class C1 { xType x; yType y; }; "); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write(" struct xTag { int x; }; "); + writer.write(" typedef xTag xType; "); + writer.write(" typedef struct yTag { int x; } yType; "); + writer.write(" class C1 { xType x; yType y; }; "); + + parse(writer.toString()); } - - public void testBug60407() throws Exception - { + + public void testBug60407() throws Exception { Writer writer = new StringWriter(); - writer.write( "struct ZZZ { int x, y, z; };\r\n" ); //$NON-NLS-1$ - writer.write( "typedef struct ZZZ _FILE;\n" ); //$NON-NLS-1$ - writer.write( "typedef _FILE FILE;\n" ); //$NON-NLS-1$ - writer.write( "static void static_function(FILE * lcd){}\n" ); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$ - writer.write( "FILE * file = 0;\n" ); //$NON-NLS-1$ - writer.write( "static_function( file );\n" ); //$NON-NLS-1$ - writer.write( "return 0;\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("struct ZZZ { int x, y, z; };\r\n"); + writer.write("typedef struct ZZZ _FILE;\n"); + writer.write("typedef _FILE FILE;\n"); + writer.write("static void static_function(FILE * lcd){}\n"); + writer.write("int main(int argc, char **argv) {\n"); + writer.write("FILE * file = 0;\n"); + writer.write("static_function(file);\n"); + writer.write("return 0;\n"); + writer.write("}\n"); + parse(writer.toString()); } - - public void testBug68623() throws Exception{ + + public void testBug68623() throws Exception { Writer writer = new StringWriter(); - writer.write( "class A { \n" ); //$NON-NLS-1$ - writer.write( " A(); \n" ); //$NON-NLS-1$ - writer.write( " class sub{}; \n" ); //$NON-NLS-1$ - writer.write( " sub * x; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "A::A() : x( (sub *) 0 ) {} \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); - + writer.write("class A { \n"); + writer.write(" A(); \n"); + writer.write(" class sub{}; \n"); + writer.write(" sub * x; \n"); + writer.write("}; \n"); + writer.write("A::A() : x((sub *) 0) {} \n"); + + parse(writer.toString()); + writer = new StringWriter(); - writer.write( "class A { \n" ); //$NON-NLS-1$ - writer.write( " A() : x (0) {} \n" ); //$NON-NLS-1$ - writer.write( " int x; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("class A { \n"); + writer.write(" A() : x (0) {} \n"); + writer.write(" int x; \n"); + writer.write("}; \n"); + + parse(writer.toString()); } - - public void testBug69798() throws Exception{ + + public void testBug69798() throws Exception { Writer writer = new StringWriter(); - writer.write( "enum Flags { FLAG1, FLAG2 }; \n" ); //$NON-NLS-1$ - writer.write( "int f() { int a, b; b = ( a ? FLAG1 : 0 ) | FLAG2; } \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("enum Flags { FLAG1, FLAG2 }; \n"); + writer.write("int f() { int a, b; b = (a ? FLAG1 : 0) | FLAG2; } \n"); + + parse(writer.toString()); } - - public void testBug69662() throws Exception{ + + public void testBug69662() throws Exception { Writer writer = new StringWriter(); - writer.write( "class A { operator float * (); }; \n" ); //$NON-NLS-1$ - writer.write( "A::operator float * () { } \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("class A { operator float * (); }; \n"); + writer.write("A::operator float * () { } \n"); + + parse(writer.toString()); } - - - public void testBug68528() throws Exception - { + + public void testBug68528() throws Exception { Writer writer = new StringWriter(); - writer.write( "namespace N526026\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "template \n" ); //$NON-NLS-1$ - writer.write( "class T526026\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "typedef int diff;\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( "\n" ); //$NON-NLS-1$ - writer.write( "template\n" ); //$NON-NLS-1$ - writer.write( "inline T526026< T >\n" ); //$NON-NLS-1$ - writer.write( "operator+(typename T526026::diff d, const T526026 & x )\n" ); //$NON-NLS-1$ - writer.write( "{ return T526026< T >(); }\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - parse( writer.toString(), false ); + writer.write("namespace N526026\n"); + writer.write("{\n"); + writer.write("template \n"); + writer.write("class T526026\n"); + writer.write("{\n"); + writer.write("typedef int diff;\n"); + writer.write("};\n"); + writer.write("\n"); + writer.write("template\n"); + writer.write("inline T526026< T >\n"); + writer.write("operator+(typename T526026::diff d, const T526026 & x)\n"); + writer.write("{ return T526026< T >(); }\n"); + writer.write("}\n"); + parse(writer.toString(), false); } - - public void testBug71094() throws Exception - { + + public void testBug71094() throws Exception { Writer writer = new StringWriter(); - writer.write( "using namespace DOESNOTEXIST;\n" ); //$NON-NLS-1$ - writer.write( "class A { int x; };\n" ); //$NON-NLS-1$ - parse( writer.toString(), false ); + writer.write("using namespace DOESNOTEXIST;\n"); + writer.write("class A { int x; };\n"); + parse(writer.toString(), false); } - + public void testPredefinedSymbol_bug70928() throws Exception { - // GNU builtin storage class type __cdecl preceded by a custom return type + // GNU built-in storage class type __cdecl preceded by a custom return type Writer writer = new StringWriter(); - writer.write( "#define __cdecl __attribute__ ((__cdecl__))\n" ); //$NON-NLS-1$ - writer.write( "typedef int size_t; \n int __cdecl foo(); \n" ); //$NON-NLS-1$ + writer.write("#define __cdecl __attribute__ ((__cdecl__))\n"); + writer.write("typedef int size_t; \n int __cdecl foo(); \n"); parse(writer.toString(), true, ParserLanguage.CPP, true); } - + public void testPredefinedSymbol_bug70928_infinite_loop_test1() throws Exception { - // GNU builtin storage class type __cdecl preceded by a custom return type + // GNU builtin storage class type __cdecl preceded by a custom return type Writer writer = new StringWriter(); - writer.write( "#define __cdecl __attribute__ ((__cdecl__))\n" ); //$NON-NLS-1$ - writer.write( "typedef int size_t; \n int __cdecl foo(); \n" ); //$NON-NLS-1$ + writer.write("#define __cdecl __attribute__ ((__cdecl__))\n"); + writer.write("typedef int size_t; \n int __cdecl foo(); \n"); parse(writer.toString(), false, ParserLanguage.CPP, false);// test for an infinite loop if the GCC extensions aren't supported parse(writer.toString(), false, ParserLanguage.C, false);// test for an infinite loop if the GCC extensions aren't supported } - + public void testPredefinedSymbol_bug70928_infinite_loop_test2() throws Exception { - // GNU builtin storage class type __cdecl preceded by a custom return type + // GNU builtin storage class type __cdecl preceded by a custom return type Writer writer = new StringWriter(); - writer.write( "int x __attribute__ ((aligned (16))) = 0;\n" ); //$NON-NLS-1$ + writer.write("int x __attribute__ ((aligned (16))) = 0;\n"); parse(writer.toString(), false, ParserLanguage.CPP, false);// test for an infinite loop if the GCC extensions aren't supported parse(writer.toString(), false, ParserLanguage.C, false);// test for an infinite loop if the GCC extensions aren't supported } - + public void testBug102376() throws Exception { Writer writer = new StringWriter(); - writer.write( "int func1 (void) __attribute__((,id2,id (,,),,,));\n" ); //$NON-NLS-1$ - writer.write( "int func2 (void) __attribute__((id,id (id)));\n" ); //$NON-NLS-1$ - writer.write( "int func3 (void) __attribute__((id,id (3)));\n" ); //$NON-NLS-1$ - writer.write( "int func4 (void) __attribute__((id,id (1+2)));\n" ); //$NON-NLS-1$ - writer.write( "void (****f1)(void) __attribute__((noreturn));\n" ); //$NON-NLS-1$ - writer.write( "void (__attribute__((noreturn)) ****f2) (void);\n" ); //$NON-NLS-1$ - writer.write( "char *__attribute__((aligned(8))) *f3;\n" ); //$NON-NLS-1$ - writer.write( "char * __attribute__((aligned(8))) * f3;\n" ); //$NON-NLS-1$ - writer.write( "void fatal1 () __attribute__ ((noreturn));\n" ); //$NON-NLS-1$ - writer.write( "int square1 (int) __attribute__ ((pure));\n" ); //$NON-NLS-1$ - writer.write( "extern int\n" ); //$NON-NLS-1$ - writer.write( "my_printf1 (void *my_object, const char *my_format, ...)\n" ); //$NON-NLS-1$ - writer.write( "__attribute__ ((format (printf, 2, 3)));\n" ); //$NON-NLS-1$ - writer.write( "extern char *\n" ); //$NON-NLS-1$ - writer.write( "my_dgettext1 (char *my_domain, const char *my_format)\n" ); //$NON-NLS-1$ - writer.write( "__attribute__ ((format_arg (2)));\n" ); //$NON-NLS-1$ - writer.write( "extern void *\n" ); //$NON-NLS-1$ - writer.write( "my_memcpy1 (void *dest, const void *src, size_t len)\n" ); //$NON-NLS-1$ - writer.write( "__attribute__((nonnull (1, 2)));\n" ); //$NON-NLS-1$ - writer.write( "extern void *\n" ); //$NON-NLS-1$ - writer.write( "my_memcpy2 (void *dest, const void *src, size_t len)\n" ); //$NON-NLS-1$ - writer.write( "__attribute__((nonnull));\n" ); //$NON-NLS-1$ - writer.write( "extern void foobar3 (void) __attribute__ ((section (\"bar\")));\n" ); //$NON-NLS-1$ - writer.write( "int old_fn () __attribute__ ((deprecated));\n" ); //$NON-NLS-1$ - writer.write( "void f5 () __attribute__ ((weak, alias (\"__f\")));\n" ); //$NON-NLS-1$ - writer.write( "void __attribute__ ((visibility (\"protected\")))\n" ); //$NON-NLS-1$ - writer.write( "f6 () { /* Do something. */; }\n" ); //$NON-NLS-1$ - writer.write( "int i2 __attribute__ ((visibility (\"hidden\")));\n" ); //$NON-NLS-1$ - writer.write( "void f7 () __attribute__ ((interrupt (\"IRQ\")));\n" ); //$NON-NLS-1$ - writer.write( "void *alt_stack9;\n" ); //$NON-NLS-1$ - writer.write( "void f8 () __attribute__ ((interrupt_handler,\n" ); //$NON-NLS-1$ - writer.write( "sp_switch (\"alt_stack\")));\n" ); //$NON-NLS-1$ - writer.write( "int x1 __attribute__ ((aligned (16))) = 0;\n" ); //$NON-NLS-1$ - writer.write( "struct foo11 { int x[2] __attribute__ ((aligned (8))); };\n" ); //$NON-NLS-1$ - writer.write( "short array12[3] __attribute__ ((aligned));\n" ); //$NON-NLS-1$ - writer.write( "extern int old_var14 __attribute__ ((deprecated));\n" ); //$NON-NLS-1$ - writer.write( "struct foo13\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "char a15;\n" ); //$NON-NLS-1$ - writer.write( "int x16[2] __attribute__ ((packed));\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( "struct duart15 a16 __attribute__ ((section (\"DUART_A\"))) = { 0 };\n" ); //$NON-NLS-1$ - writer.write( "struct duart15 b17 __attribute__ ((section (\"DUART_B\"))) = { 0 };\n" ); //$NON-NLS-1$ - writer.write( "char stack18[10000] __attribute__ ((section (\"STACK\"))) = { 0 };\n" ); //$NON-NLS-1$ - writer.write( "int init_data19 __attribute__ ((section (\"INITDATA\"))) = 0;\n" ); //$NON-NLS-1$ - writer.write( "int foo20 __attribute__((section (\"shared\"), shared)) = 0;\n" ); //$NON-NLS-1$ - writer.write( "int foo21 __attribute__ ((vector_size (16)));\n" ); //$NON-NLS-1$ - writer.write( "struct S22 { int a23; };\n" ); //$NON-NLS-1$ - writer.write( "struct S24 __attribute__ ((vector_size (16))) foo;\n" ); //$NON-NLS-1$ - writer.write( "struct S25 { short f27[3]; } __attribute__ ((aligned (8)));\n" ); //$NON-NLS-1$ - writer.write( "typedef int more_aligned_int __attribute__ ((aligned (8)));\n" ); //$NON-NLS-1$ - writer.write( "struct S26 { short f28[3]; } __attribute__ ((aligned));\n" ); //$NON-NLS-1$ - writer.write( "\n" ); //$NON-NLS-1$ - writer.write( "struct my_unpacked_struct29\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "char c;\n" ); //$NON-NLS-1$ - writer.write( "int i;\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( " \n" ); //$NON-NLS-1$ - writer.write( "struct my_packed_struct __attribute__ ((__packed__))\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "char c;\n" ); //$NON-NLS-1$ - writer.write( "int i;\n" ); //$NON-NLS-1$ - writer.write( "struct my_unpacked_struct29 s;\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( "\n" ); //$NON-NLS-1$ - writer.write( "typedef union\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "int *__ip;\n" ); //$NON-NLS-1$ - writer.write( "union wait *__up;\n" ); //$NON-NLS-1$ - writer.write( "} wait_status_ptr_t __attribute__ ((__transparent_union__));\n" ); //$NON-NLS-1$ - writer.write( "\n" ); //$NON-NLS-1$ - writer.write( "typedef int T1 __attribute__ ((deprecated));\n" ); //$NON-NLS-1$ - writer.write( "typedef short __attribute__((__may_alias__)) short_a;\n" ); //$NON-NLS-1$ - writer.write( "extern const unsigned short int ** __ctype_b_loc (void) __attribute__ ((__const));" ); //$NON-NLS-1$ - parse( writer.toString(), true, ParserLanguage.C, true ); - parse( writer.toString(), true, ParserLanguage.CPP, true ); + writer.write("int func1 (void) __attribute__((,id2,id (,,),,,));\n"); + writer.write("int func2 (void) __attribute__((id,id (id)));\n"); + writer.write("int func3 (void) __attribute__((id,id (3)));\n"); + writer.write("int func4 (void) __attribute__((id,id (1+2)));\n"); + writer.write("void (****f1)(void) __attribute__((noreturn));\n"); + writer.write("void (__attribute__((noreturn)) ****f2) (void);\n"); + writer.write("char *__attribute__((aligned(8))) *f3;\n"); + writer.write("char * __attribute__((aligned(8))) * f3;\n"); + writer.write("void fatal1 () __attribute__ ((noreturn));\n"); + writer.write("int square1 (int) __attribute__ ((pure));\n"); + writer.write("extern int\n"); + writer.write("my_printf1 (void *my_object, const char *my_format, ...)\n"); + writer.write("__attribute__ ((format (printf, 2, 3)));\n"); + writer.write("extern char *\n"); + writer.write("my_dgettext1 (char *my_domain, const char *my_format)\n"); + writer.write("__attribute__ ((format_arg (2)));\n"); + writer.write("extern void *\n"); + writer.write("my_memcpy1 (void *dest, const void *src, size_t len)\n"); + writer.write("__attribute__((nonnull (1, 2)));\n"); + writer.write("extern void *\n"); + writer.write("my_memcpy2 (void *dest, const void *src, size_t len)\n"); + writer.write("__attribute__((nonnull));\n"); + writer.write("extern void foobar3 (void) __attribute__ ((section (\"bar\")));\n"); + writer.write("int old_fn () __attribute__ ((deprecated));\n"); + writer.write("void f5 () __attribute__ ((weak, alias (\"__f\")));\n"); + writer.write("void __attribute__ ((visibility (\"protected\")))\n"); + writer.write("f6 () { /* Do something. */; }\n"); + writer.write("int i2 __attribute__ ((visibility (\"hidden\")));\n"); + writer.write("void f7 () __attribute__ ((interrupt (\"IRQ\")));\n"); + writer.write("void *alt_stack9;\n"); + writer.write("void f8 () __attribute__ ((interrupt_handler,\n"); + writer.write("sp_switch (\"alt_stack\")));\n"); + writer.write("int x1 __attribute__ ((aligned (16))) = 0;\n"); + writer.write("struct foo11 { int x[2] __attribute__ ((aligned (8))); };\n"); + writer.write("short array12[3] __attribute__ ((aligned));\n"); + writer.write("extern int old_var14 __attribute__ ((deprecated));\n"); + writer.write("struct foo13\n"); + writer.write("{\n"); + writer.write("char a15;\n"); + writer.write("int x16[2] __attribute__ ((packed));\n"); + writer.write("};\n"); + writer.write("struct duart15 a16 __attribute__ ((section (\"DUART_A\"))) = { 0 };\n"); + writer.write("struct duart15 b17 __attribute__ ((section (\"DUART_B\"))) = { 0 };\n"); + writer.write("char stack18[10000] __attribute__ ((section (\"STACK\"))) = { 0 };\n"); + writer.write("int init_data19 __attribute__ ((section (\"INITDATA\"))) = 0;\n"); + writer.write("int foo20 __attribute__((section (\"shared\"), shared)) = 0;\n"); + writer.write("int foo21 __attribute__ ((vector_size (16)));\n"); + writer.write("struct S22 { int a23; };\n"); + writer.write("struct S24 __attribute__ ((vector_size (16))) foo;\n"); + writer.write("struct S25 { short f27[3]; } __attribute__ ((aligned (8)));\n"); + writer.write("typedef int more_aligned_int __attribute__ ((aligned (8)));\n"); + writer.write("struct S26 { short f28[3]; } __attribute__ ((aligned));\n"); + writer.write("\n"); + writer.write("struct my_unpacked_struct29\n"); + writer.write("{\n"); + writer.write("char c;\n"); + writer.write("int i;\n"); + writer.write("};\n"); + writer.write(" \n"); + writer.write("struct my_packed_struct __attribute__ ((__packed__))\n"); + writer.write("{\n"); + writer.write("char c;\n"); + writer.write("int i;\n"); + writer.write("struct my_unpacked_struct29 s;\n"); + writer.write("};\n"); + writer.write("\n"); + writer.write("typedef union\n"); + writer.write("{\n"); + writer.write("int *__ip;\n"); + writer.write("union wait *__up;\n"); + writer.write("} wait_status_ptr_t __attribute__ ((__transparent_union__));\n"); + writer.write("\n"); + writer.write("typedef int T1 __attribute__ ((deprecated));\n"); + writer.write("typedef short __attribute__((__may_alias__)) short_a;\n"); + writer.write("extern const unsigned short int ** __ctype_b_loc (void) __attribute__ ((__const));"); + parse(writer.toString(), true, ParserLanguage.C, true); + parse(writer.toString(), true, ParserLanguage.CPP, true); } - public void testBug73652() throws Exception - { + public void testBug73652() throws Exception { StringWriter writer = new StringWriter(); - writer.write( "#define DoSuperMethodA IDoSuperMethodA\n" ); //$NON-NLS-1$ - writer.write( "#define IDoSuperMethodA(a,b,c) IIntuition->IDoSuperMethodA(a,b,c)\n" ); //$NON-NLS-1$ - writer.write( "void hang(void)\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "DoSuperMethodA(0,0,0);\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - parse( writer.toString() , false ); + writer.write("#define DoSuperMethodA IDoSuperMethodA\n"); + writer.write("#define IDoSuperMethodA(a,b,c) IIntuition->IDoSuperMethodA(a,b,c)\n"); + writer.write("void hang(void)\n"); + writer.write("{\n"); + writer.write("DoSuperMethodA(0,0,0);\n"); + writer.write("}\n"); + parse(writer.toString() , false); } - - public void testBug73428() throws Exception - { - parse( "namespace { }");//$NON-NLS-1$ - parse( "namespace { };");//$NON-NLS-1$ - parse( "namespace { int abc; };");//$NON-NLS-1$ - parse( "namespace { int abc; }");//$NON-NLS-1$ + + public void testBug73428() throws Exception { + parse("namespace { }");//$NON-NLS-1$ + parse("namespace { };");//$NON-NLS-1$ + parse("namespace { int abc; };");//$NON-NLS-1$ + parse("namespace { int abc; }");//$NON-NLS-1$ } - - public void testBug73615() throws Exception - { - for( int i = 0; i < 2; ++i ) - { + + public void testBug73615() throws Exception { + for (int i = 0; i < 2; ++i) { StringWriter writer = new StringWriter(); - if( i == 0 ) - writer.write( "class B;\n"); //$NON-NLS-1$ - writer.write( "class A { A( B * ); };\n"); //$NON-NLS-1$ - if( i == 0 ) - parse( writer.toString() ); + if (i == 0) + writer.write("class B;\n"); + writer.write("class A { A(B *); };\n"); + if (i == 0) + parse(writer.toString()); else - parse( writer.toString(), false ); + parse(writer.toString(), false); } } - - public void testBug74180() throws Exception - { - parse( "enum DHCPFOBoolean { false, true } additionalHB, more_payload; \n", true, ParserLanguage.C ); //$NON-NLS-1$ + + public void testBug74180() throws Exception { + parse("enum DHCPFOBoolean { false, true } additionalHB, more_payload; \n", true, + ParserLanguage.C); } - - public void testBug72691() throws Exception{ + + public void testBug72691() throws Exception { StringWriter writer = new StringWriter(); - writer.write( "typedef int * PINT; \n" ); //$NON-NLS-1$ - writer.write( "typedef int * PINT; \n" ); //$NON-NLS-1$ - writer.write( "PINT pint; \n" ); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("typedef int * PINT; \n"); + writer.write("typedef int * PINT; \n"); + writer.write("PINT pint; \n"); + parse(writer.toString()); } - - public void testBug72691_2() throws Exception{ + + public void testBug72691_2() throws Exception { StringWriter writer = new StringWriter(); - writer.write( "typedef int * PINT; \n" ); //$NON-NLS-1$ - writer.write( "namespace N { \n" ); //$NON-NLS-1$ - writer.write( " typedef int * PINT; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - writer.write( "using namespace N; \n" ); //$NON-NLS-1$ - writer.write( "PINT pint; \n" ); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("typedef int * PINT; \n"); + writer.write("namespace N { \n"); + writer.write(" typedef int * PINT; \n"); + writer.write("} \n"); + writer.write("using namespace N; \n"); + writer.write("PINT pint; \n"); + parse(writer.toString()); } - - public void testBug74328() throws Exception - { + + public void testBug74328() throws Exception { Writer writer = new StringWriter(); - writer.write( "int\n" ); //$NON-NLS-1$ - writer.write( "main(int argc, char **argv) {\n" ); //$NON-NLS-1$ - writer.write( " char *sign;\n" ); //$NON-NLS-1$ - writer.write( "sign = \"\"; // IProblem generated here, syntax error\n" ); //$NON-NLS-1$ - writer.write( "return argc;\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("int\n"); + writer.write("main(int argc, char **argv) {\n"); + writer.write(" char *sign;\n"); + writer.write("sign = \"\"; // IProblem generated here, syntax error\n"); + writer.write("return argc;\n"); + writer.write("}\n"); + parse(writer.toString()); } - - public void testBug71733() throws Exception - { + + public void testBug71733() throws Exception { Writer writer = new StringWriter(); - writer.write( "void foo( int );\n"); //$NON-NLS-1$ - writer.write( "#define BLAH() \\\n"); //$NON-NLS-1$ - writer.write( " foo ( /* slash / is misinterpreted as end of comment */ \\\n"); //$NON-NLS-1$ - writer.write( " 4 );\n"); //$NON-NLS-1$ - writer.write( "int f() { BLAH() }\n"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("void foo(int);\n"); + writer.write("#define BLAH() \\\n"); + writer.write(" foo (/* slash / is misinterpreted as end of comment */ \\\n"); + writer.write(" 4);\n"); + writer.write("int f() { BLAH() }\n"); + parse(writer.toString()); } - - public void testBug69526() throws Exception - { + + public void testBug69526() throws Exception { Writer writer = new StringWriter(); - writer.write( "unsigned inkernel;\n" ); //$NON-NLS-1$ - writer.write( "#define lock_kernel() (inkernel |= 0x01)" ); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) {" ); //$NON-NLS-1$ - writer.write( "lock_kernel();" ); //$NON-NLS-1$ - writer.write( "}" ); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("unsigned inkernel;\n"); + writer.write("#define lock_kernel() (inkernel |= 0x01)"); + writer.write("int main(int argc, char **argv) {"); + writer.write("lock_kernel();"); + writer.write("}"); + parse(writer.toString()); } - - public void testBug69454() throws Exception - { + + public void testBug69454() throws Exception { Writer writer = new StringWriter(); - writer.write( "#define CATCH_ALL_EXCEPTIONS() \\\n" ); //$NON-NLS-1$ - writer.write( " catch( Exception &ex ) { handleException( ex ); } \\\n" ); //$NON-NLS-1$ - writer.write( " catch( ... ) { handleException(); } \n" ); //$NON-NLS-1$ - writer.write( "class Exception; \n" ); //$NON-NLS-1$ - writer.write( "void handleException( Exception & ex ) {} \n" ); //$NON-NLS-1$ - writer.write( "void handleException() {} \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " try { int i; } \n" ); //$NON-NLS-1$ - writer.write( " CATCH_ALL_EXCEPTIONS(); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ + writer.write("#define CATCH_ALL_EXCEPTIONS() \\\n"); + writer.write(" catch(Exception &ex) { handleException(ex); } \\\n"); + writer.write(" catch(...) { handleException(); } \n"); + writer.write("class Exception; \n"); + writer.write("void handleException(Exception & ex) {} \n"); + writer.write("void handleException() {} \n"); + writer.write("void f() { \n"); + writer.write(" try { int i; } \n"); + writer.write(" CATCH_ALL_EXCEPTIONS(); \n"); + writer.write("} \n"); - parse( writer.toString() ); + parse(writer.toString()); } - - public void testBug72692A() throws Exception - { + public void testBug72692A() throws Exception { Writer writer = new StringWriter(); - writer.write( "extern double pow(double, double);\n"); //$NON-NLS-1$ - writer.write( "extern double pow2(double, double){}\n"); //$NON-NLS-1$ - writer.write( "namespace DS {\n"); //$NON-NLS-1$ - writer.write( "using ::pow;\n"); //$NON-NLS-1$ - writer.write( "using ::pow2;\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - writer.write( "using DS::pow;\n"); //$NON-NLS-1$ - writer.write( "using DS::pow2;\n"); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug72692B() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "extern double pow(double, double);\n"); //$NON-NLS-1$ - writer.write( "namespace DS {\n"); //$NON-NLS-1$ - writer.write( "using ::pow;\n"); //$NON-NLS-1$ - writer.write( "inline float pow(float __x, float __y)\n" ); //$NON-NLS-1$ - writer.write( "{ return ::pow(static_cast(__x), static_cast(__y)); }\n" ); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - writer.write( "using namespace DS;\n"); //$NON-NLS-1$ - writer.write( "float foo() { double d1 = 3.0, d2 = 4.0; return pow(d1, d2); }"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("extern double pow(double, double);\n"); + writer.write("extern double pow2(double, double){}\n"); + writer.write("namespace DS {\n"); + writer.write("using ::pow;\n"); + writer.write("using ::pow2;\n"); + writer.write("}\n"); + writer.write("using DS::pow;\n"); + writer.write("using DS::pow2;\n"); + parse(writer.toString()); } - public void testBug72692C() throws Exception - { + public void testBug72692B() throws Exception { Writer writer = new StringWriter(); - writer.write( "extern double pow(double, double){}\n"); //$NON-NLS-1$ - writer.write( "namespace DS {\n"); //$NON-NLS-1$ - writer.write( "using ::pow;\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - writer.write( "using DS::pow;\n"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("extern double pow(double, double);\n"); + writer.write("namespace DS {\n"); + writer.write("using ::pow;\n"); + writer.write("inline float pow(float __x, float __y)\n"); + writer.write("{ return ::pow(static_cast(__x), static_cast(__y)); }\n"); + writer.write("}\n"); + writer.write("using namespace DS;\n"); + writer.write("float foo() { double d1 = 3.0, d2 = 4.0; return pow(d1, d2); }"); + parse(writer.toString()); } - - public void testBug74575A() throws Exception - { + public void testBug72692C() throws Exception { Writer writer = new StringWriter(); - writer.write( "double pow(double, double);\n"); //$NON-NLS-1$ - writer.write( "float pow(float __x, float __y)\n" ); //$NON-NLS-1$ - writer.write( "{ return 0; }\n"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("extern double pow(double, double){}\n"); + writer.write("namespace DS {\n"); + writer.write("using ::pow;\n"); + writer.write("}\n"); + writer.write("using DS::pow;\n"); + parse(writer.toString()); } - - public void testBug75338() throws Exception - { + + public void testBug74575A() throws Exception { Writer writer = new StringWriter(); - writer.write( "class Thrown { };\n"); //$NON-NLS-1$ - writer.write( "void foo() throw( Thrown );"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("double pow(double, double);\n"); + writer.write("float pow(float __x, float __y)\n"); + writer.write("{ return 0; }\n"); + parse(writer.toString()); } - + + public void testBug75338() throws Exception { + Writer writer = new StringWriter(); + writer.write("class Thrown { };\n"); + writer.write("void foo() throw(Thrown);"); + parse(writer.toString()); + } + public void testBug74847() throws Exception { - String code = "class A : public FOO {};"; //$NON-NLS-1$ - parse( code, false ); + String code = "class A : public FOO {};"; + parse(code, false); } - - public void testBug76696() throws Exception{ + + public void testBug76696() throws Exception { Writer writer = new StringWriter(); - writer.write(" void f(){ \n"); //$NON-NLS-1$ - writer.write(" if( A a) { \n"); //$NON-NLS-1$ - writer.write(" } else { \n"); //$NON-NLS-1$ - writer.write(" } \n"); //$NON-NLS-1$ - writer.write(" } \n"); //$NON-NLS-1$ - - parse( writer.toString(), false ); + writer.write(" void f(){ \n"); + writer.write(" if (A a) { \n"); + writer.write(" } else { \n"); + writer.write(" } \n"); + writer.write(" } \n"); + + parse(writer.toString(), false); } - - public void testBug74069() throws Exception{ + + public void testBug74069() throws Exception { Writer writer = new StringWriter(); - writer.write( "int f() { \n"); //$NON-NLS-1$ - writer.write( " int a, b, c; \n"); //$NON-NLS-1$ - writer.write( " if( a < b ) \n"); //$NON-NLS-1$ - writer.write( " if( b < c ) \n"); //$NON-NLS-1$ - writer.write( " return b; \n"); //$NON-NLS-1$ - writer.write( " else if ( a < c ) \n"); //$NON-NLS-1$ - writer.write( " return c; \n"); //$NON-NLS-1$ - writer.write( " else \n"); //$NON-NLS-1$ - writer.write( " return a; \n"); //$NON-NLS-1$ - writer.write( " else if( a < c ) \n"); //$NON-NLS-1$ - writer.write( " return a; \n"); //$NON-NLS-1$ - writer.write( " else if( b < c ) \n"); //$NON-NLS-1$ - writer.write( " return c; \n"); //$NON-NLS-1$ - writer.write( " else \n"); //$NON-NLS-1$ - writer.write( " return b; \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("int f() { \n"); + writer.write(" int a, b, c; \n"); + writer.write(" if (a < b) \n"); + writer.write(" if (b < c) \n"); + writer.write(" return b; \n"); + writer.write(" else if (a < c) \n"); + writer.write(" return c; \n"); + writer.write(" else \n"); + writer.write(" return a; \n"); + writer.write(" else if (a < c) \n"); + writer.write(" return a; \n"); + writer.write(" else if (b < c) \n"); + writer.write(" return c; \n"); + writer.write(" else \n"); + writer.write(" return b; \n"); + writer.write("} \n"); + + parse(writer.toString()); } + public void testBug77805() throws Exception { Writer writer = new StringWriter(); - writer.write("#if X // Do something only if X is true\n"); //$NON-NLS-1$ - writer.write("/* some statements */\n"); //$NON-NLS-1$ - writer.write("#endif\n"); //$NON-NLS-1$ + writer.write("#if X // Do something only if X is true\n"); + writer.write("/* some statements */\n"); + writer.write("#endif\n"); parse(writer.toString()); } - + public void testBug77821() throws Exception { Writer writer = new StringWriter(); - writer.write("typedef struct { /* ... */ }TYPE;\n"); //$NON-NLS-1$ - writer.write("void ptrArith(const TYPE* pType) {\n"); //$NON-NLS-1$ - writer.write("TYPE *temp = 0;\n"); //$NON-NLS-1$ - writer.write("temp = (TYPE*)(pType + 1); /* Parser error is here */\n}\n"); //$NON-NLS-1$ + writer.write("typedef struct { /* ... */ }TYPE;\n"); + writer.write("void ptrArith(const TYPE* pType) {\n"); + writer.write("TYPE *temp = 0;\n"); + writer.write("temp = (TYPE*)(pType + 1); /* Parser error is here */\n}\n"); parse(writer.toString()); } - - public void testBug77009() throws Exception - { - parse("int foo(volatile int &);\n"); //$NON-NLS-1$ + + public void testBug77009() throws Exception { + parse("int foo(volatile int &);\n"); } - - + public void testBug77281() throws Exception { Writer writer = new StringWriter(); - writer.write("void fun2(float a, float b) {}\n"); //$NON-NLS-1$ - writer.write("int main() { fun2(0.24f, 0.25f); }\n"); //$NON-NLS-1$ + writer.write("void fun2(float a, float b) {}\n"); + writer.write("int main() { fun2(0.24f, 0.25f); }\n"); parse(writer.toString()); } - + public void testBug77921() throws Exception { Writer writer = new StringWriter(); - writer.write("void f()\n{\n"); //$NON-NLS-1$ - writer.write("static float v0[] = { -1.0f, -1.0f, 1.0f };\n}\n"); //$NON-NLS-1$ + writer.write("void f()\n{\n"); + writer.write("static float v0[] = { -1.0f, -1.0f, 1.0f };\n}\n"); parse(writer.toString()); } - - + public void testBug71317A() throws Exception { Writer writer = new StringWriter(); - writer.write("void f();\n"); //$NON-NLS-1$ - writer.write("namespace NS {\n"); //$NON-NLS-1$ - writer.write("using ::f;\n"); //$NON-NLS-1$ - writer.write("using ::f;\n}"); //$NON-NLS-1$ + writer.write("void f();\n"); + writer.write("namespace NS {\n"); + writer.write("using ::f;\n"); + writer.write("using ::f;\n}"); parse(writer.toString()); } public void testBug71317B() throws Exception { Writer writer = new StringWriter(); - writer.write("void f();\n"); //$NON-NLS-1$ - writer.write("namespace NS {\n"); //$NON-NLS-1$ - writer.write("void f();\n"); //$NON-NLS-1$ - writer.write("using ::f;\n}"); //$NON-NLS-1$ + writer.write("void f();\n"); + writer.write("namespace NS {\n"); + writer.write("void f();\n"); + writer.write("using ::f;\n}"); parse(writer.toString()); } - + public void testBug77097() throws Exception { Writer writer = new StringWriter(); - writer.write("#define SOME_MACRO() { \\\r\n"); //$NON-NLS-1$ - writer.write("printf(\"Hello World\"); \\\r\n"); //$NON-NLS-1$ - writer.write("printf(\"Good morning\"); \\\r\n"); //$NON-NLS-1$ + writer.write("#define SOME_MACRO() { \\\r\n"); + writer.write("printf(\"Hello World\"); \\\r\n"); + writer.write("printf(\"Good morning\"); \\\r\n"); parse(writer.toString()); } - + public void testBug77276() throws Exception { Writer writer = new StringWriter(); - writer.write("#if (!defined(OS_LIBMODE_R) && !defined(OS_LIBMODE_RP) && \\\r\n"); //$NON-NLS-1$ - writer.write("!defined(OS_LIBMODE_T))\r\n"); //$NON-NLS-1$ - writer.write("#define OS_LIBMODE_DP\r\n"); //$NON-NLS-1$ - writer.write("#endif\r\n"); //$NON-NLS-1$ + writer.write("#if (!defined(OS_LIBMODE_R) && !defined(OS_LIBMODE_RP) && \\\r\n"); + writer.write("!defined(OS_LIBMODE_T))\r\n"); + writer.write("#define OS_LIBMODE_DP\r\n"); + writer.write("#endif\r\n"); parse(writer.toString()); } - + public void testBug78165() throws Exception { Writer writer = new StringWriter(); - writer.write("struct Node {\n"); //$NON-NLS-1$ - writer.write("struct Node* Next; // OK: Refers to Node at global scope\n"); //$NON-NLS-1$ - writer.write("struct Data* Data; // OK: Declares type Data at global scope and member Data\n"); //$NON-NLS-1$ - writer.write("};\n"); //$NON-NLS-1$ - writer.write("struct Data {\n"); //$NON-NLS-1$ - writer.write("struct Node* Node; // OK: Refers to Node at global scope\n"); //$NON-NLS-1$ - writer.write("friend struct Glob; // OK: Refers to (as yet) undeclared Glob at global scope.\n"); //$NON-NLS-1$ - writer.write("};\n"); //$NON-NLS-1$ - writer.write("struct Base {\n"); //$NON-NLS-1$ - writer.write("struct Data; // OK: Declares nested Data\n"); //$NON-NLS-1$ - writer.write("struct ::Data* thatData; // OK: Refers to ::Data\n"); //$NON-NLS-1$ - writer.write("struct Base::Data* thisData; // OK: Refers to nested Data\n"); //$NON-NLS-1$ - writer.write("friend class ::Data; // OK: global Data is a friend\n"); //$NON-NLS-1$ - writer.write("friend class Data; // OK: nested Data is a friend\n"); //$NON-NLS-1$ - writer.write("struct Data { /* ... */ }; // Defines nested Data\n"); //$NON-NLS-1$ - writer.write("struct Data; // OK: Redeclares nested Data\n"); //$NON-NLS-1$ - writer.write("};\n"); //$NON-NLS-1$ - writer.write("struct Data; // OK: Redeclares Data at global scope\n"); //$NON-NLS-1$ - writer.write("struct Base::Data* pBase; // OK: refers to nested Data\n"); //$NON-NLS-1$ + writer.write("struct Node {\n"); + writer.write("struct Node* Next; // OK: Refers to Node at global scope\n"); + writer.write("struct Data* Data; // OK: Declares type Data at global scope and member Data\n"); + writer.write("};\n"); + writer.write("struct Data {\n"); + writer.write("struct Node* Node; // OK: Refers to Node at global scope\n"); + writer.write("friend struct Glob; // OK: Refers to (as yet) undeclared Glob at global scope.\n"); + writer.write("};\n"); + writer.write("struct Base {\n"); + writer.write("struct Data; // OK: Declares nested Data\n"); + writer.write("struct ::Data* thatData; // OK: Refers to ::Data\n"); + writer.write("struct Base::Data* thisData; // OK: Refers to nested Data\n"); + writer.write("friend class ::Data; // OK: global Data is a friend\n"); + writer.write("friend class Data; // OK: nested Data is a friend\n"); + writer.write("struct Data { /* ... */ }; // Defines nested Data\n"); + writer.write("struct Data; // OK: Redeclares nested Data\n"); + writer.write("};\n"); + writer.write("struct Data; // OK: Redeclares Data at global scope\n"); + writer.write("struct Base::Data* pBase; // OK: refers to nested Data\n"); - parse( writer.toString() ); + parse(writer.toString()); } public void testBug103560() throws Exception { Writer writer = new StringWriter(); - writer.write("#define A( a, b ) a ## b \n"); //$NON-NLS-1$ - writer.write("#define FOOBAR 1 \n"); //$NON-NLS-1$ - writer.write("int i = A( FOO, BAR ); \n"); //$NON-NLS-1$ - parse( writer.toString(), true, ParserLanguage.CPP ); + writer.write("#define A(a, b) a ## b \n"); + writer.write("#define FOOBAR 1 \n"); + writer.write("int i = A(FOO, BAR); \n"); + parse(writer.toString(), true, ParserLanguage.CPP); } - + public void test158192_declspec_on_class() throws Exception { - if(!Platform.getOS().equals(Platform.OS_WIN32)) + if (!Platform.getOS().equals(Platform.OS_WIN32)) return; // XXX: see GPPParserExtensionConfiguration.supportDeclspecSpecifiers() - + Writer writer = new StringWriter(); writer.write("class __declspec(foobar) Foo1 {};\n"); writer.write("union __declspec(foobar) Foo2 {};\n"); writer.write("struct __declspec(foobar) Foo3 {};\n"); - IASTTranslationUnit tu = parse( writer.toString(), true, ParserLanguage.CPP, true ); + IASTTranslationUnit tu = parse(writer.toString(), true, ParserLanguage.CPP, true); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); + tu.accept(col); - assertEquals( 3, col.size()); + assertEquals(3, col.size()); ICompositeType fooClass = (ICompositeType) col.getName(0).resolveBinding(); ICompositeType fooUnion = (ICompositeType) col.getName(1).resolveBinding(); ICompositeType fooStruct = (ICompositeType) col.getName(2).resolveBinding(); @@ -2649,17 +2488,17 @@ public class CompleteParser2Tests extends BaseTestCase { } public void test158192_declspec_on_variable() throws Exception { - if(!Platform.getOS().equals(Platform.OS_WIN32)) + if (!Platform.getOS().equals(Platform.OS_WIN32)) return; // XXX: see GPPParserExtensionConfiguration.supportDeclspecSpecifiers() - + Writer writer = new StringWriter(); writer.write("__declspec(foobar) class Foo {} bar;\n"); - IASTTranslationUnit tu = parse( writer.toString(), true, ParserLanguage.CPP, true); + IASTTranslationUnit tu = parse(writer.toString(), true, ParserLanguage.CPP, true); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); + tu.accept(col); - assertEquals( 2, col.size()); + assertEquals(2, col.size()); ICompositeType fooClass = (ICompositeType) col.getName(0).resolveBinding(); ICPPVariable bar = (ICPPVariable) col.getName(1).resolveBinding(); @@ -2670,33 +2509,33 @@ public class CompleteParser2Tests extends BaseTestCase { // MSVC does not allow declspec in this position, GCC does so we test for this // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=158192 public void test158192_declspec_in_declarator() throws Exception { - if(!Platform.getOS().equals(Platform.OS_WIN32)) + if (!Platform.getOS().equals(Platform.OS_WIN32)) return; // XXX: see GPPParserExtensionConfiguration.supportDeclspecSpecifiers() - + Writer writer = new StringWriter(); writer.write("int * __declspec(foo) bar = 0;\n"); - IASTTranslationUnit tu = parse( writer.toString(), true, ParserLanguage.CPP, true); + IASTTranslationUnit tu = parse(writer.toString(), true, ParserLanguage.CPP, true); - IASTProblem [] problems = CPPVisitor.getProblems(tu); - assertFalse("__declspec rejected inside declarator", problems.length>0 ); + IASTProblem[] problems = CPPVisitor.getProblems(tu); + assertFalse("__declspec rejected inside declarator", problems.length>0); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); + tu.accept(col); - assertEquals( 1, col.size()); + assertEquals(1, col.size()); ICPPVariable bar = (ICPPVariable) col.getName(0).resolveBinding(); assertInstances(col, bar, 1); } - + public void test173874_nestedClasses() throws Exception { String code = "class aClass { class bClass; int x; };"; IASTTranslationUnit tu = parse(code, true, ParserLanguage.CPP, true); - + CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + ICPPClassType cls = (ICPPClassType)col.getName(0).resolveBinding(); ICPPClassType[] nested = cls.getNestedClasses(); assertEquals(1, nested.length); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java index 8fea36b2b9a..7c7b93a3234 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -151,15 +151,10 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest { public String getParserDialect() { return dialect; } - } private static final String[] EMPTY_STRING_ARRAY = new String[0]; - /** - * @param name - * @param className - */ public DOMLocationInclusionTests(String name) { super(name, DOMLocationInclusionTests.class); } @@ -178,13 +173,6 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest { new ParserConfiguration(s, code)); } - /** - * @param pathEndsWith - * TODO - * @param offset - * @param length - * @param declarator - */ protected void assertSoleFileLocation(IASTNode n, String pathEndsWith, int offset, int length) { IASTNodeLocation[] locations = n.getNodeLocations(); assertEquals(locations.length, 1); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java index 34dd6256ac4..80ec78f9b37 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -178,11 +178,6 @@ public class DOMLocationTests extends AST2BaseTest { } - /** - * @param declarator - * @param offset - * @param length - */ private void assertSoleLocation(IASTNode n, int offset, int length) { assertEquals(length, ((ASTNode)n).getLength()); IASTNodeLocation[] locations = n.getNodeLocations(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSearchUtil.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSearchUtil.java index eb7eb48b99c..10fc1e5a816 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSearchUtil.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSearchUtil.java @@ -35,8 +35,8 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.content.IContentType; /** - * Utility class to have commonly used algorithms in one place for searching with the DOM. - * + * Utility class to have commonly used algorithms in one place for searching with the DOM. + * * @author dsteffle */ public class DOMSearchUtil { @@ -48,28 +48,26 @@ public class DOMSearchUtil { public static final int DECLARATIONS_DEFINITIONS = 3; public static final int REFERENCES = 4; public static final int ALL_OCCURRENCES = 5; + /** - * This retrieves the ParserLanguage from an IFile. - * - * @param file - * @return - */ + * Retrieves the ParserLanguage from an file. + */ public static ParserLanguage getLanguageFromFile(IFile file) { IProject project = file.getProject(); IContentType contentType = CCorePlugin.getContentType(project, file.getFullPath().lastSegment()); if (contentType != null) { String lid = contentType.getId(); - if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(lid) || + if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(lid) || CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(lid)) { return ParserLanguage.CPP; } - } + } return ParserLanguage.C; } /** * The CPPNameCollector used to get IASTNames from an IASTNode. - * + * * @author dsteffle */ static public class CPPNameCollector extends ASTVisitor { @@ -78,21 +76,21 @@ public class DOMSearchUtil { } public List nameList = new ArrayList(); @Override - public int visit( IASTName name ){ - nameList.add( name ); + public int visit(IASTName name) { + nameList.add(name); return PROCESS_CONTINUE; } - public IASTName getName( int idx ){ - if( idx < 0 || idx >= nameList.size() ) + public IASTName getName(int idx) { + if (idx < 0 || idx >= nameList.size()) return null; - return (IASTName) nameList.get( idx ); + return (IASTName) nameList.get(idx); } - public int size() { return nameList.size(); } + public int size() { return nameList.size(); } } /** * The CNameCollector used to get IASTNames from an IASTNode. - * + * * @author dsteffle */ static public class CNameCollector extends ASTVisitor { @@ -101,27 +99,22 @@ public class DOMSearchUtil { } public List nameList = new ArrayList(); @Override - public int visit( IASTName name ){ - nameList.add( name ); + public int visit(IASTName name) { + nameList.add(name); return PROCESS_CONTINUE; } - public IASTName getName( int idx ){ - if( idx < 0 || idx >= nameList.size() ) + public IASTName getName(int idx) { + if (idx < 0 || idx >= nameList.size()) return null; - return (IASTName) nameList.get( idx ); + return (IASTName) nameList.get(idx); } - public int size() { return nameList.size(); } + public int size() { return nameList.size(); } } - + /** * Returns the ParserLanguage corresponding to the IPath and IProject. Returns ParserLanguage.CPP if the file type is a header. - * - * @param path - * @param project - * @return */ - public static ParserLanguage getLanguage( IPath path, IProject project ) - { + public static ParserLanguage getLanguage(IPath path, IProject project) { //FIXME: ALAIN, for headers should we assume CPP ?? // The problem is that it really depends on how the header was included. String id = null; @@ -135,7 +128,7 @@ public class DOMSearchUtil { } else if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id)) { return ParserLanguage.CPP; } else if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(id)) { - return ParserLanguage.C; + return ParserLanguage.C; } else if (CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)) { return ParserLanguage.C; } else if (CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)) { @@ -148,24 +141,24 @@ public class DOMSearchUtil { /** * This is used to get the names from the TU that the IASTName searchName belongs to. - * - * @param searchName the IASTName whose references/delcarations are to be retrieved - * @param limitTo used to specify whether to get declarations, references, or both, one of: - * ( CSearchPattern.DECLARATION | CSearchPattern.REFERENCES | CSearchPattern.ALL_OCCURRENCES ) + * + * @param searchName the IASTName whose references/declarations are to be retrieved + * @param limitTo used to specify whether to get declarations, references, or both, one of: + * (CSearchPattern.DECLARATION | CSearchPattern.REFERENCES | CSearchPattern.ALL_OCCURRENCES) * @return IASTName[] declarations, references, or both depending on limitTo that correspond to the IASTName searchName searched for */ public static IName[] getNamesFromDOM(IASTName searchName, int limitTo) { IName[] names = null; IASTTranslationUnit tu = searchName.getTranslationUnit(); - + if (tu == null) { return BLANK_NAME_ARRAY; } - + IBinding binding = searchName.resolveBinding(); if (binding instanceof IIndexBinding) { Assert.fail("Not implemented"); -// try { +// try { // ArrayList pdomNames = new ArrayList(); // IPDOMResolver pdom= ((PDOMBinding) binding).getPDOM(); // // First decls @@ -180,22 +173,23 @@ public class DOMSearchUtil { // } } else { names = getNames(tu, binding, limitTo); - - if (names == null || names.length == 0) { // try alternate strategies + + if (names == null || names.length == 0) { // try alternate strategies try { // fix for 86829, 95224 - if ((binding instanceof ICPPConstructor || (binding instanceof ICPPMethod && ((ICPPMethod)binding).isDestructor())) + if ((binding instanceof ICPPConstructor || (binding instanceof ICPPMethod && ((ICPPMethod)binding).isDestructor())) && binding.getScope() instanceof ICPPClassScope) { binding = ((ICPPClassScope)binding.getScope()).getClassType(); names = getNames(tu, binding, limitTo); } - } catch (DOMException e) {} + } catch (DOMException e) { + } } } return names; } - + private static IASTName[] getNames(IASTTranslationUnit tu, IBinding binding, int limitTo) { IASTName[] names = null; if (limitTo == DECLARATIONS || @@ -205,15 +199,14 @@ public class DOMSearchUtil { names = tu.getReferences(binding); } else if (limitTo == DEFINITIONS) { names = tu.getDefinitionsInAST(binding); - } else if (limitTo == ALL_OCCURRENCES){ + } else if (limitTo == ALL_OCCURRENCES) { names = tu.getDeclarationsInAST(binding); names = ArrayUtil.addAll(IASTName.class, names, tu.getReferences(binding)); } else { // assume ALL names = tu.getDeclarationsInAST(binding); names = ArrayUtil.addAll(IASTName.class, names, tu.getReferences(binding)); } - + return names; } - } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java index 56570492300..33cc1a0d043 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -44,23 +44,15 @@ import org.eclipse.cdt.internal.core.parser.ParserException; * @author jcamelon */ public class QuickParser2Tests extends TestCase { - private static final NullLogService NULL_LOG = new NullLogService(); - /** - * - */ public QuickParser2Tests() { super(); } - /** - * @param name - */ public QuickParser2Tests(String name) { super(name); } - @Override protected void setUp() throws Exception { @@ -69,7 +61,7 @@ public class QuickParser2Tests extends TestCase { } /** - * Test code: int x = 5; Purpose: to test the simple decaration in it's + * Test code: int x = 5; Purpose: to test the simple declaration in it's * simplest form. */ public void testIntGlobal() throws Exception { @@ -160,30 +152,29 @@ public class QuickParser2Tests extends TestCase { 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; };"); + code.write("class A : public B, private C, virtual protected D { public: int x, y; float a,b,c; };"); parse(code.toString()); } /** - * Test code: int myFunction( void ); + * 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 );"); + code.write("void myFunction(void);"); parse(code.toString()); } /** - * Test code: bool myFunction( int parm1 = 3 * 4, double parm2 ); + * 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 );"); + code.write("bool myFunction(int parm1 = 3 * 4, double parm2);"); parse(code.toString()); } @@ -208,8 +199,8 @@ public class QuickParser2Tests extends TestCase { } public void testBug36290() throws Exception { - parse("typedef void ( A:: * pMethod ) ( void ); "); - parse("typedef void (boo) ( void ); "); + parse("typedef void (A:: * pMethod) (void); "); + parse("typedef void (boo) (void); "); parse("typedef void boo (void); "); } @@ -245,113 +236,113 @@ public class QuickParser2Tests extends TestCase { // failing, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=236856 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 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 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 (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 (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) 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) 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) (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) (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) 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) 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) (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) (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 { @@ -372,7 +363,7 @@ public class QuickParser2Tests extends TestCase { } public void testBug37019() throws Exception { - parse("static const A a( 1, 0 );"); + parse("static const A a(1, 0);"); } public void testBug36766and36769A() throws Exception { @@ -414,7 +405,7 @@ public class QuickParser2Tests extends TestCase { } public void testBug36932A() throws Exception { - parse("A::A( ) : var( new char [ (unsigned)bufSize ] ) {}"); + parse("A::A() : var(new char[ (unsigned)bufSize ]) {}"); } // failing, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=236856 @@ -529,7 +520,6 @@ public class QuickParser2Tests extends TestCase { } public void testBug36769A() throws Exception { - parse("template cls::operator otherType() const {}\n"); parse("template cls::cls() {}\n"); parse("template cls::~cls() {}\n"); @@ -539,7 +529,6 @@ public class QuickParser2Tests extends TestCase { Writer code = new StringWriter(); code.write("unsigned long a = 0UL;\n"); code.write("unsigned long a2 = 0L; \n"); - parse(code.toString()); } @@ -548,11 +537,11 @@ public class QuickParser2Tests extends TestCase { "class Functor {"+ "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 ) {}"); + parse("A::A(): b(new int(5)), b(new B), c(new int) {}"); } public void testBug36704() throws Exception { @@ -590,8 +579,7 @@ public class QuickParser2Tests extends TestCase { 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 *, 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"); @@ -605,16 +593,13 @@ public class QuickParser2Tests extends TestCase { 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"); + 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()); } @@ -623,14 +608,12 @@ public class QuickParser2Tests extends TestCase { code.write("template\n"); code.write("<\n"); code.write("class AbstractFact,\n"); - code - .write("template class Creator = OpNewFactoryUnit,\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("typename TL::Reverse::Result, Creator, AbstractFact>\n"); code.write("{\n"); code.write("public:\n"); code.write("typedef typename AbstractFact::ProductList ProductList;\n"); @@ -688,23 +671,23 @@ public class QuickParser2Tests extends TestCase { } /** - * Test code: "class A { int floor( double input ), someInt; };" + * Test code: "class A { int floor(double input), someInt; };" */ public void testMultipleDeclarators() throws Exception { - // Parse and get the translaton unit - parse("class A { int floor( double input ), someInt; };"); + // Parse and get the translation unit + parse("class A { int floor(double input), someInt; };"); } public void testFunctionModifiers() throws Exception { - parse("class A {virtual void foo( void ) const throw ( yay, nay, we::dont::care ) = 0;};"); + parse("class A {virtual void foo(void) const throw (yay, nay, we::dont::care) = 0;};"); } public void testArrays() throws Exception { - parse("int x [5][];"); + parse("int x[5][];"); } public void testElaboratedParms() throws Exception { - parse("int x( struct A myA ) { /* junk */ }"); + parse("int x(struct A myA) { /* junk */ }"); } public void testMemberDeclarations() throws Exception { @@ -733,16 +716,16 @@ public class QuickParser2Tests extends TestCase { } public void testASMDefinition() throws Exception { - parse("asm( \"mov ep1 ds2\");"); + parse("asm(\"mov ep1 ds2\");"); } public void testConstructorChain() throws Exception { //TODO - requires CPPVisitor in order to reduce ambiguities - parse("TrafficLight_Actor::TrafficLight_Actor( RTController * rtg_rts, RTActorRef * rtg_ref ) : RTActor( rtg_rts, rtg_ref ), myId( 0 ) {}"); + parse("TrafficLight_Actor::TrafficLight_Actor(RTController * rtg_rts, RTActorRef * rtg_ref) : RTActor(rtg_rts, rtg_ref), myId(0) {}"); } public void testBug36237() throws Exception { - parse("A::A():B( (char *)0 ){}"); + parse("A::A():B((char *)0){}"); } public void testBug36532() throws Exception { @@ -760,7 +743,7 @@ public class QuickParser2Tests extends TestCase { } public void testTemplateDeclarationOfFunction() throws Exception { - parse("template A aTemplatedFunction( B bInstance );"); + parse("template A aTemplatedFunction(B bInstance);"); } public void testTemplateDeclarationOfClass() throws Exception { @@ -779,15 +762,15 @@ public class QuickParser2Tests extends TestCase { } public void testBug36250() throws Exception { - parse("int f( int = 0 );"); + parse("int f(int = 0);"); } public void testBug36240() throws Exception { - parse("A & A::operator=( A ){}"); + parse("A & A::operator=(A){}"); } public void testBug36254() throws Exception { - parse("unsigned i;\nvoid f( unsigned p1 = 0 );"); + parse("unsigned i;\nvoid f(unsigned p1 = 0);"); } public void testBug36432() throws Exception { @@ -868,8 +851,7 @@ public class QuickParser2Tests extends TestCase { 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("void SetLongevity(T* pDynObject, unsigned int longevity,\n"); code.write("Destroyer d = Private::Deleter::Delete){}\n"); parse(code.toString()); } @@ -888,7 +870,7 @@ public class QuickParser2Tests extends TestCase { // 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("INLINE_DEF A & unlock(void);"); // code.write("};"); // parse(code.toString()); // } @@ -911,7 +893,7 @@ public class QuickParser2Tests extends TestCase { public void testPointersToFunctions() throws Exception { Writer code = new StringWriter(); - code.write("void (*name)( void );\n"); + code.write("void (*name)(void);\n"); code .write("static void * (* const orig_malloc_hook)(const char *file, int line, size_t size);\n"); @@ -924,8 +906,8 @@ public class QuickParser2Tests extends TestCase { public void testBug36713() throws Exception { Writer code = new StringWriter(); - code.write("A ( * const fPtr) (void *); \n"); - code.write("A (* const fPtr2) ( A * ); \n"); + code.write("A (* const fPtr) (void *); \n"); + code.write("A (* const fPtr2) (A *); \n"); parse(code.toString()); } @@ -935,7 +917,7 @@ public class QuickParser2Tests extends TestCase { // { // // Parse and get the translaton unit // Writer code = new StringWriter(); - // code.write("bool myFunction( parm1, parm2, parm3 )\n"); + // code.write("bool myFunction(parm1, parm2, parm3)\n"); // code.write("const char* parm1;\n"); // code.write("int (*parm2)(float);\n"); // code.write("{}"); @@ -946,82 +928,82 @@ public class QuickParser2Tests extends TestCase { // assertEquals(1, declarations.size()); // SimpleDeclaration simpleDeclaration = // (SimpleDeclaration)declarations.get(0); - // assertEquals( simpleDeclaration.getDeclSpecifier().getType(), - // DeclSpecifier.t_bool ); + // 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" ); + // assertEquals(1, declarators.size()); + // Declarator functionDeclarator = (Declarator)declarators.get(0); + // assertEquals(functionDeclarator.getName().toString(), "myFunction"); // // ParameterDeclarationClause pdc = functionDeclarator.getParms(); - // assertNotNull( pdc ); + // 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() ); + // 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() ); + // assertEquals(1, parm1Decls.size()); // - // ParameterDeclaration parm2 = (ParameterDeclaration)parameterDecls.get( 1 - // ); - // assertNotNull( parm2.getDeclSpecifier().getName() ); - // assertEquals( "parm2", parm2.getDeclSpecifier().getName().toString() ); + // ParameterDeclaration parm2 = (ParameterDeclaration)parameterDecls.get(1 + //); + // assertNotNull(parm2.getDeclSpecifier().getName()); + // assertEquals("parm2", parm2.getDeclSpecifier().getName().toString()); // List parm2Decls = parm2.getDeclarators(); - // assertEquals( 1, parm2Decls.size() ); + // assertEquals(1, parm2Decls.size()); // - // ParameterDeclaration parm3 = (ParameterDeclaration)parameterDecls.get( 2 - // ); - // assertNotNull( parm3.getDeclSpecifier().getName() ); - // assertEquals( "parm3", parm3.getDeclSpecifier().getName().toString() ); + // ParameterDeclaration parm3 = (ParameterDeclaration)parameterDecls.get(2 + //); + // assertNotNull(parm3.getDeclSpecifier().getName()); + // assertEquals("parm3", parm3.getDeclSpecifier().getName().toString()); // List parm3Decls = parm3.getDeclarators(); - // assertEquals( 1, parm3Decls.size() ); + // assertEquals(1, parm3Decls.size()); // // OldKRParameterDeclarationClause clause = pdc.getOldKRParms(); - // assertNotNull( clause ); - // assertEquals( clause.getDeclarations().size(), 2 ); + // assertNotNull(clause); + // assertEquals(clause.getDeclarations().size(), 2); // SimpleDeclaration decl1 = // (SimpleDeclaration)clause.getDeclarations().get(0); - // assertEquals( decl1.getDeclarators().size(), 1 ); + // 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" ); + // 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() ); + // 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 ); + // 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() - // ); + // 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() ); + // ((Declarator)declaration.getDeclarators().get(0)).getDeclarator()); // assertEquals( // ((Declarator)declaration.getDeclarators().get(0)).getDeclarator().getName().toString(), - // "parm2" ); + // "parm2"); // ParameterDeclarationClause clause2 = // ((Declarator)declaration.getDeclarators().get(0)).getParms(); - // assertEquals( clause2.getDeclarations().size(), 1 ); + // assertEquals(clause2.getDeclarations().size(), 1); // assertEquals( // ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().size(), - // 1 ); + // 1); // assertNull( // ((Declarator)((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().get(0)).getName() - // ); + //); // assertEquals( // ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclSpecifier().getType(), - // DeclSpecifier.t_float ); + // DeclSpecifier.t_float); // } public void testPointersToMemberFunctions() throws Exception { @@ -1038,10 +1020,8 @@ public class QuickParser2Tests extends TestCase { 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("#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"); @@ -1063,17 +1043,14 @@ public class QuickParser2Tests extends TestCase { 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(" /* 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"); @@ -1098,7 +1075,7 @@ public class QuickParser2Tests extends TestCase { } public void testIndirectDeclarators() throws Exception { - parse("void (*x)( int );"); + parse("void (*x)(int);"); } public void testBug39532() throws Exception { @@ -1143,7 +1120,7 @@ public class QuickParser2Tests extends TestCase { code.write("template struct SuperSubclass {\n"); code.write("enum { value = (::Loki::Conversion::exists && \n"); code.write("!::Loki::Conversion::sameType) }; };"); - } catch (IOException ioe) { + } catch (IOException e) { } parse(code.toString()); } @@ -1210,7 +1187,7 @@ public class QuickParser2Tests extends TestCase { code.write(" catch (...)\n"); code.write(" { if (c != 3) r |= 1; }\n"); code.write("};\n"); - } catch (IOException ioe) { + } catch (IOException e) { } parse(code.toString()); } @@ -1266,64 +1243,64 @@ public class QuickParser2Tests extends TestCase { } public void testBug43110() throws Exception { - parse("void x( int y, ... );"); + parse("void x(int y, ...);"); } // public void testBug44370() throws Exception // { - // parse( "#define SWAP(x,y) {x|=y;y|=x;x|=y;}\n"); + // parse("#define SWAP(x,y) {x|=y;y|=x;x|=y;}\n"); // Iterator macros = quickParseCallback.getMacros(); // assertNotNull(macros); - // assertTrue( macros.hasNext()); + // assertTrue(macros.hasNext()); // IASTMacro swap = (IASTMacro) macros.next(); - // assertFalse( macros.hasNext() ); - // assertEquals( swap.getName(), "SWAP"); - // assertEquals( swap.getMacroType(), - // IMacroDescriptor.MacroType.FUNCTION_LIKE ); - // String [] params = swap.getParameters(); - // assertEquals( params.length, 2 ); - // assertEquals( params[0], "x"); - // assertEquals( params[1], "y"); + // assertFalse(macros.hasNext()); + // assertEquals(swap.getName(), "SWAP"); + // assertEquals(swap.getMacroType(), + // IMacroDescriptor.MacroType.FUNCTION_LIKE); + // String[] params = swap.getParameters(); + // assertEquals(params.length, 2); + // assertEquals(params[0], "x"); + // assertEquals(params[1], "y"); // String completeSignature = swap.getCompleteSignature().trim(); - // assertEquals( completeSignature, "#define SWAP(x,y) {x|=y;y|=x;x|=y;}"); + // assertEquals(completeSignature, "#define SWAP(x,y) {x|=y;y|=x;x|=y;}"); // - // assertEquals( swap.getExpansionSignature().trim(),"{x|=y;y|=x;x|=y;}"); + // assertEquals(swap.getExpansionSignature().trim(),"{x|=y;y|=x;x|=y;}"); // - // IToken [] tokens = swap.getTokenizedExpansion(); - // validateToken( tokens[0], IToken.tLBRACE); - // validateIdentifier( tokens[1], "x"); - // validateToken( tokens[2], IToken.tBITORASSIGN ); - // validateIdentifier( tokens[3], "y"); - // validateToken( tokens[4], IToken.tSEMI ); - // validateIdentifier( tokens[5], "y"); - // validateToken( tokens[6], IToken.tBITORASSIGN ); - // validateIdentifier( tokens[7], "x"); - // validateToken( tokens[8], IToken.tSEMI ); - // validateIdentifier( tokens[9], "x"); - // validateToken( tokens[10], IToken.tBITORASSIGN ); - // validateIdentifier( tokens[11], "y"); - // validateToken( tokens[12], IToken.tSEMI ); - // validateToken( tokens[13], IToken.tRBRACE ); + // IToken[] tokens = swap.getTokenizedExpansion(); + // validateToken(tokens[0], IToken.tLBRACE); + // validateIdentifier(tokens[1], "x"); + // validateToken(tokens[2], IToken.tBITORASSIGN); + // validateIdentifier(tokens[3], "y"); + // validateToken(tokens[4], IToken.tSEMI); + // validateIdentifier(tokens[5], "y"); + // validateToken(tokens[6], IToken.tBITORASSIGN); + // validateIdentifier(tokens[7], "x"); + // validateToken(tokens[8], IToken.tSEMI); + // validateIdentifier(tokens[9], "x"); + // validateToken(tokens[10], IToken.tBITORASSIGN); + // validateIdentifier(tokens[11], "y"); + // validateToken(tokens[12], IToken.tSEMI); + // validateToken(tokens[13], IToken.tRBRACE); // } // /** // * @param token // * @param string // */ - // private void validateIdentifier(IToken token, String identifierName ) { - // validateToken( token, IToken.tIDENTIFIER); - // assertEquals( token.getImage(), identifierName ); + // private void validateIdentifier(IToken token, String identifierName) { + // validateToken(token, IToken.tIDENTIFIER); + // assertEquals(token.getImage(), identifierName); // } // /** // * @param token // * @param i // */ // private void validateToken(IToken token, int signal) { - // assertEquals( token.getType(), signal ); + // assertEquals(token.getType(), signal); // } public void testBug47752() throws Exception { //TODO requires CPPVisitor - parse("void func( cFoo bar ) try { } catch ( const char * error ){ }"); + parse("void func(cFoo bar) try { } catch (const char * error){ }"); } public void testBug47628() throws Exception { @@ -1354,15 +1331,8 @@ public class QuickParser2Tests extends TestCase { parse("struct file_operations driver_fops = { open: device_open, release: device_release };", true, ParserLanguage.C, true); } - /** - * @param string - * @param b - * @param c - * @param d - */ protected void parse(String code, boolean expectedToPass, ParserLanguage lang, boolean gcc) throws Exception { - FileContent codeReader = FileContent.create("", code.toCharArray()); IScannerInfo scannerInfo = new ScannerInfo(); IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); @@ -1373,8 +1343,7 @@ public class QuickParser2Tests extends TestCase { config = new GPPParserExtensionConfiguration(); else config = new ANSICPPParserExtensionConfiguration(); - parser2 = new GNUCPPSourceParser(scanner, ParserMode.QUICK_PARSE, - NULL_LOG, config); + parser2 = new GNUCPPSourceParser(scanner, ParserMode.QUICK_PARSE, NULL_LOG, config); } else { ICParserExtensionConfiguration config = null; if (gcc) @@ -1382,23 +1351,18 @@ public class QuickParser2Tests extends TestCase { else config = new ANSICParserExtensionConfiguration(); - parser2 = new GNUCSourceParser(scanner, ParserMode.QUICK_PARSE, - NULL_LOG, config); + parser2 = new GNUCSourceParser(scanner, ParserMode.QUICK_PARSE, NULL_LOG, config); } IASTTranslationUnit tu = parser2.parse(); if (parser2.encounteredError() && expectedToPass) throw new ParserException("FAILURE"); - if (expectedToPass) - { - if( lang == ParserLanguage.C ) - { - IASTProblem [] problems = CVisitor.getProblems(tu); - assertEquals( problems.length, 0 ); - } - else if ( lang == ParserLanguage.CPP ) - { - IASTProblem [] problems = CPPVisitor.getProblems(tu); - assertEquals( problems.length, 0 ); + if (expectedToPass) { + if (lang == ParserLanguage.C) { + IASTProblem[] problems = CVisitor.getProblems(tu); + assertEquals(problems.length, 0); + } else if (lang == ParserLanguage.CPP) { + IASTProblem[] problems = CPPVisitor.getProblems(tu); + assertEquals(problems.length, 0); } } } @@ -1409,8 +1373,7 @@ public class QuickParser2Tests extends TestCase { public void testBug61431() throws Exception { for (int i = 0; i < 2; ++i) { - ParserLanguage language = (i == 0) ? ParserLanguage.C - : ParserLanguage.CPP; + ParserLanguage language = (i == 0) ? ParserLanguage.C : ParserLanguage.CPP; parse("int k[][] = { {0, {1}, {2,3}};", false, language); } } @@ -1458,14 +1421,14 @@ public class QuickParser2Tests extends TestCase { StringWriter writer = new StringWriter(); writer.write("#define __declspec(x) __attribute__((x))"); writer.write("__declspec (dllimport) int foo;"); - parse( writer.toString() ); + parse(writer.toString()); } public void testBug39704D() throws Exception { StringWriter writer = new StringWriter(); writer.write("#define __declspec(x) __attribute__((x))"); writer.write("__declspec(dllexport) int func1 (int a) {}"); - parse( writer.toString() ); + parse(writer.toString()); } public void testBug39695() throws Exception { @@ -1510,8 +1473,7 @@ public class QuickParser2Tests extends TestCase { Writer code = new StringWriter(); code.write("__complex__ double x; // complex double\n"); code.write("__complex__ short int a; // complex short int\n"); - code - .write("__complex__ float y = 2.5fi; // 2.5 imaginary float literal\n"); + code.write("__complex__ float y = 2.5fi; // 2.5 imaginary float literal\n"); code.write("__complex__ int a = 3i; // imaginary intege r literal\n"); code.write("double v = __real__ x; // real part of expression\n"); code.write("double w = __imag__ x; // imaginary part of expression\n"); @@ -1532,7 +1494,7 @@ public class QuickParser2Tests extends TestCase { public void testBug39677() throws Exception { parse("B::B() : a(({ 1; })) {}", true, ParserLanguage.CPP, true); Writer writer = new StringWriter(); - writer.write("B::B() : a(( { int y = foo (); int z;\n"); + writer.write("B::B() : a(({ int y = foo (); int z;\n"); writer.write("if (y > 0) z = y;\n"); writer.write("else z = - y;\n"); writer.write("z; })) {}\n"); @@ -1562,5 +1524,4 @@ public class QuickParser2Tests extends TestCase { public void testBug39701C() throws Exception { parse("static template class Foo;", true, ParserLanguage.CPP, true); } - }