diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java index 7947093b6b5..4cd57b67d42 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java @@ -596,7 +596,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti // with UTF-8 encoding since GNU compilers can handle only UTF-8 characters. // Include paths with locale characters will be handled properly regardless // of the language as long as the encoding is set to UTF-8. - // Default language is set for parser because it relies on English messages + // English language is set for parser because it relies on English messages // in the output of the 'gcc -v' command. List envp = new ArrayList(Arrays.asList(BuildRunnerHelper.getEnvp(currentCfgDescription))); @@ -606,7 +606,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti iterator.remove(); } } - envp.add(ENV_LANGUAGE + "=C"); // override for GNU gettext //$NON-NLS-1$ + envp.add(ENV_LANGUAGE + "=en"); // override for GNU gettext //$NON-NLS-1$ envp.add(ENV_LC_ALL + "=C.UTF-8"); // for other parts of the system libraries //$NON-NLS-1$ return envp.toArray(new String[envp.size()]); diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserFileMatchingTest.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserFileMatchingTest.java index d5475bdd7b7..894a16ef159 100644 --- a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserFileMatchingTest.java +++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserFileMatchingTest.java @@ -1206,7 +1206,7 @@ public class ErrorParserFileMatchingTest extends TestCase { } /** - * Checks if output of '-n'/'--just-print' or '-w'/'--print-directory' options of make can be recognized. + * Checks if output of -w or --print-directory options of make can be recognized. * * @throws Exception... */ diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java index 9f68e1f51ee..ed3edc18d69 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java @@ -10,6 +10,7 @@ * Markus Schorn (Wind River Systems) * Andrew Ferguson (Symbian) * Mike Kucera (IBM) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -366,19 +367,20 @@ public class AST2BaseTest extends BaseTestCase { public int size() { return nameList.size(); } public void dump() { - for (int i=0; i T assertInstance(Object o, Class clazz, Class... cs) { - assertNotNull("Expected object of "+clazz.getName()+" but got a null value", o); + assertNotNull("Expected object of " + clazz.getName() + " but got a null value", o); assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), clazz.isInstance(o)); for (Class c : cs) { - assertNotNull("Expected object of "+c.getName()+" but got a null value", o); - assertTrue("Expected "+c.getName()+" but got "+o.getClass().getName(), c.isInstance(o)); + assertNotNull("Expected object of " + c.getName() + " but got a null value", o); + assertTrue("Expected " + c.getName() + " but got " + o.getClass().getName(), c.isInstance(o)); } return clazz.cast(o); } @@ -516,14 +518,14 @@ public class AST2BaseTest extends BaseTestCase { this.isCPP= isCPP; this.tu= parse(contents, isCPP ? ParserLanguage.CPP : ParserLanguage.C, true, false); } - + public IASTTranslationUnit getTranslationUnit() { return tu; } - - public IProblemBinding assertProblem(String section, int len) { + + public IProblemBinding assertProblem(String section, int len) { if (len <= 0) - len= section.length()+len; + len= section.length() + len; IBinding binding= binding(section, len); assertTrue("Non-ProblemBinding for name: " + section.substring(0, len), binding instanceof IProblemBinding); @@ -532,11 +534,11 @@ public class AST2BaseTest extends BaseTestCase { public T assertNonProblem(String section, int len) { if (len <= 0) - len= section.length()+len; + len= section.length() + len; IBinding binding= binding(section, len); if (binding instanceof IProblemBinding) { IProblemBinding problem= (IProblemBinding) binding; - fail("ProblemBinding for name: " + section.substring(0, len) + " (" + renderProblemID(problem.getID())+")"); + fail("ProblemBinding for name: " + section.substring(0, len) + " (" + renderProblemID(problem.getID()) + ")"); } if (binding == null) { fail("Null binding resolved for name: " + section.substring(0, len)); @@ -548,7 +550,7 @@ public class AST2BaseTest extends BaseTestCase { IASTName name= findName(section, len); if (name != null) { String selection = section.substring(0, len); - fail("Found unexpected \""+selection+"\": " + name.resolveBinding()); + fail("Found unexpected \"" + selection + "\": " + name.resolveBinding()); } } @@ -559,7 +561,7 @@ public class AST2BaseTest extends BaseTestCase { public IASTImplicitName assertImplicitName(String section, int len, Class bindingClass) { IASTName name = findImplicitName(section, len); final String selection = section.substring(0, len); - assertNotNull("did not find \""+selection+"\"", name); + assertNotNull("did not find \"" + selection + "\"", name); assertInstance(name, IASTImplicitName.class); IASTImplicitNameOwner owner = (IASTImplicitNameOwner) name.getParent(); @@ -587,7 +589,7 @@ public class AST2BaseTest extends BaseTestCase { public void assertNoImplicitName(String section, int len) { IASTName name = findImplicitName(section, len); final String selection = section.substring(0, len); - assertNull("found name \""+selection+"\"", name); + assertNull("found name \"" + selection + "\"", name); } public IASTImplicitName[] getImplicitNames(String section, int len) { @@ -627,6 +629,23 @@ public class AST2BaseTest extends BaseTestCase { return selector.findImplicitName(offset, len); } + public T assertNode(String context, String nodeText, Class type, Class... cs) { + if (context == null) { + context = contents; + } + int offset = contents.indexOf(context); + assertTrue("Context \"" + context + "\" not found", offset >= 0); + int nodeOffset = context.indexOf(nodeText); + assertTrue("Node \"" + nodeText + "\" not found", nodeOffset >= 0); + IASTNodeSelector selector = tu.getNodeSelector(null); + IASTNode node = selector.findNode(offset + nodeOffset, nodeText.length()); + return assertType(node, type, cs); + } + + public T assertNode(String nodeText, Class type, Class... cs) { + return assertNode(contents, nodeText, type, cs); + } + private String renderProblemID(int i) { try { for (Field field : IProblemBinding.class.getDeclaredFields()) { @@ -647,29 +666,53 @@ public class AST2BaseTest extends BaseTestCase { public T assertNonProblem(String section, int len, Class type, Class... cs) { if (len <= 0) - len+= section.length(); + len += section.length(); IBinding binding= binding(section, len); assertTrue("ProblemBinding for name: " + section.substring(0, len), !(binding instanceof IProblemBinding)); - assertInstance(binding, type); - for (Class c : cs) { - assertInstance(binding, c); - } - return type.cast(binding); + return assertType(binding, type, cs); } - + + public T assertNonProblem(String section, Class type, Class... cs) { + return assertNonProblem(section, section.length(), type, cs); + } + + public T assertNonProblem(String context, String name, Class type, Class... cs) { + IBinding binding= binding(context, name); + assertTrue("ProblemBinding for name: " + name, !(binding instanceof IProblemBinding)); + return assertType(binding, type, cs); + } + + public U assertType(T obj, Class type, Class... cs) { + assertInstance(obj, type); + for (Class c : cs) { + assertInstance(obj, c); + } + return type.cast(obj); + } + private IBinding binding(String section, int len) { IASTName name = findName(section, len); final String selection = section.substring(0, len); - assertNotNull("did not find \""+selection+"\"", name); + assertNotNull("Did not find \"" + selection + "\"", name); assertEquals(selection, name.getRawSignature()); IBinding binding = name.resolveBinding(); - assertNotNull("No binding for "+name.getRawSignature(), binding); + assertNotNull("No binding for " + name.getRawSignature(), binding); return name.resolveBinding(); } - } + + private IBinding binding(String context, String name) { + IASTName astName = findName(context, name); + assertEquals(name, astName.getRawSignature()); + + IBinding binding = astName.resolveBinding(); + assertNotNull("No binding for " + astName.getRawSignature(), binding); + + return astName.resolveBinding(); + } + } final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang) throws Exception { return parseAndCheckBindings(code, lang, false); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index ceb452abbd8..a2773522dc5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -149,7 +149,7 @@ public class AST2CPPTests extends AST2BaseTest { } protected IASTTranslationUnit parseAndCheckBindings(String code) throws Exception { - IASTTranslationUnit tu = parse(code, ParserLanguage.CPP); + IASTTranslationUnit tu = parse(code, ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); assertNoProblemBindings(col); @@ -231,7 +231,7 @@ public class AST2CPPTests extends AST2BaseTest { } private void checkDeclDef(String[] declNames, String[] defNames, IASTDeclaration[] decls) { - int i= 0, j= 0; + int i= 0, j= 0; for (IASTDeclaration decl : decls) { if (decl instanceof ICPPASTLinkageSpecification) { decl= ((ICPPASTLinkageSpecification) decl).getDeclarations()[0]; @@ -282,9 +282,9 @@ public class AST2CPPTests extends AST2BaseTest { // enum type {A}; // enum type a, b; - // type c; + // type c; // enum type2 {A, B}; - // enum type2 d, e; + // enum type2 d, e; public void testBug77967() throws Exception { parseAndCheckBindings(getAboveComment()); } @@ -353,10 +353,10 @@ public class AST2CPPTests extends AST2BaseTest { } // class A { int m(int); }; - // A a; + // A a; // int (A::*pm)(int) = &A::m; - // int f(){} - // int f(int); + // int f(){} + // int f(int); // int x = f((a.*pm)(5)); public void testBug43242() throws Exception { parseAndCheckBindings(getAboveComment()); @@ -367,11 +367,11 @@ public class AST2CPPTests extends AST2BaseTest { } // int *zzz1 (char); - // int (*zzz2) (char); - // int ((*zzz3)) (char); - // int (*(zzz4)) (char); + // int (*zzz2) (char); + // int ((*zzz3)) (char); + // int (*(zzz4)) (char); public void testBug40768() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); assertNoProblemBindings(col); @@ -540,8 +540,8 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(f.getScope(), A.getCompositeScope()); } - // class A { void f(); }; - // void A::f() { } + // class A { void f(); }; + // void A::f() { } public void testMethodDefinition() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); @@ -577,8 +577,8 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(A, A2); } - // class A { void f(); int i; }; - // void A::f() { i; } + // class A { void f(); int i; }; + // void A::f() { i; } public void testMemberReference() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); @@ -627,9 +627,9 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(i1, i2); } - // class A { int i; }; - // class B : public A { void f(); }; - // void B::f() { i; } + // class A { int i; }; + // class B : public A { void f(); }; + // void B::f() { i; } public void testBasicInheritance() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); @@ -682,24 +682,24 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(f2, f3); } - // namespace A{ - // int a; - // } - // namespace B{ - // using namespace A; - // } - // namespace C{ - // using namespace A; - // } - // - // namespace BC{ - // using namespace B; - // using namespace C; - // } - // - // void f(){ - // BC::a++; //ok - // } + // namespace A{ + // int a; + // } + // namespace B{ + // using namespace A; + // } + // namespace C{ + // using namespace A; + // } + // + // namespace BC{ + // using namespace B; + // using namespace C; + // } + // + // void f(){ + // BC::a++; //ok + // } public void testNamespaces() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); @@ -721,12 +721,12 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, f, 1); } - // int A; - // class A {}; - // void f() { - // A++; - // class A a; - // } + // int A; + // class A {}; + // void f() { + // A++; + // class A a; + // } public void testNameHiding() throws Exception { String content= getAboveComment(); IASTTranslationUnit tu = parse(content, ParserLanguage.CPP); @@ -753,12 +753,12 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(vA, A); } - // class A { void f(); }; - // class B; - // void A::f() { - // B b; - // } - // int B; + // class A { void f(); }; + // class B; + // void A::f() { + // B b; + // } + // int B; public void testBlockTraversal() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -779,12 +779,12 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, B2, 1); } - // void f(int i); - // void f(char c); - // void main() { - // f(1); //calls f(int); - // f('b'); - // } + // void f(int i); + // void f(char c); + // void main() { + // f(1); //calls f(int); + // f('b'); + // } public void testFunctionResolution() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -796,13 +796,13 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, f2, 2); } - // typedef struct { - // int x; - // } S; - // void f() { - // S myS; - // myS.x = 5; - // } + // typedef struct { + // int x; + // } S; + // void f() { + // S myS; + // myS.x = 5; + // } public void testSimpleStruct() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -820,11 +820,11 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, myS, 2); } - // struct A; - // void f(){ - // struct A; - // struct A * a; - // } + // struct A; + // void f(){ + // struct A; + // struct A * a; + // } public void testStructureTags_1() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -842,10 +842,10 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, A2, 2); } - // struct A; - // void f(){ - // struct A * a; - // } + // struct A; + // void f(){ + // struct A * a; + // } public void testStructureTags_2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -862,12 +862,12 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, A1, 2); } - // struct A; - // struct A * a; - // struct A { int i; }; - // void f() { - // a->i; - // } + // struct A; + // struct A * a; + // struct A { int i; }; + // void f() { + // a->i; + // } public void testStructureDef() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -882,10 +882,10 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, i, 2); } - // struct x {}; - // void f(int x) { - // struct x i; - // } + // struct x {}; + // void f(int x) { + // struct x i; + // } public void testStructureNamespace() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -896,10 +896,10 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, x, 2); } - // void f(int a); - // void f(int b){ - // b; - // } + // void f(int a); + // void f(int b){ + // b; + // } public void testFunctionDef() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -916,11 +916,11 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(scope.getParent(), f.getScope()); } - // void f(); - // void g() { - // f(); - // } - // void f(){ } + // void f(); + // void g() { + // f(); + // } + // void f(){ } public void testSimpleFunctionCall() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -933,11 +933,11 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, g, 1); } - // void f() { - // for(int i = 0; i < 5; i++) { - // i; - // } - // } + // void f() { + // for(int i = 0; i < 5; i++) { + // i; + // } + // } public void testForLoop() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -948,10 +948,10 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, i, 4); } - // struct A { int x; }; - // void f(){ - // ((struct A *) 1)->x; - // } + // struct A { int x; }; + // void f(){ + // ((struct A *) 1)->x; + // } public void testExpressionFieldReference() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -964,14 +964,14 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, x, 2); } - // enum hue { red, blue, green }; - // enum hue col, *cp; - // void f() { - // col = blue; - // cp = &col; - // if (*cp != red) - // return; - // } + // enum hue { red, blue, green }; + // enum hue col, *cp; + // void f() { + // col = blue; + // cp = &col; + // if (*cp != red) + // return; + // } public void testEnumerations() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -1020,10 +1020,10 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(pt.getType(), A); } - // struct A; - // int * f(int i, char c); - // void (*g) (A *); - // void (* (*h)(A**)) (int); + // struct A; + // int * f(int i, char c); + // void (*g) (A *); + // void (* (*h)(A**)) (int); public void testFunctionTypes() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); @@ -1104,18 +1104,18 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(ft.getParameterTypes().length, 1); } - // void f(); - // namespace A { - // void g(); - // } - // namespace X { - // using ::f; - // using A::g; - // } - // void h() { - // X::f(); - // X::g(); - // } + // void f(); + // namespace A { + // void g(); + // } + // namespace X { + // using ::f; + // using A::g; + // } + // void h() { + // X::f(); + // X::g(); + // } public void testUsingDeclaration_1() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -1139,14 +1139,14 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, using_g.getDelegates()[0], 3); // decl + using-decl + ref } - // typedef int Int; - // void f(int i); - // void f(const int); - // void f(Int i); - // void g(char *); - // void g(char []); - // void h(int(a)()); - // void h(int (*) ()); + // typedef int Int; + // void f(int i); + // void f(const int); + // void f(Int i); + // void g(char *); + // void g(char []); + // void h(int(a)()); + // void h(int (*) ()); public void testFunctionDeclarations() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -1164,13 +1164,13 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, h, 2); } - // class P1 { public: int x; }; - // class P2 { public: int x; }; - // class B : public P1, public P2 {}; - // void main() { - // B * b = new B(); - // b->x; - // } + // class P1 { public: int x; }; + // class P2 { public: int x; }; + // class B : public P1, public P2 {}; + // void main() { + // B * b = new B(); + // b->x; + // } public void testProblem_AmbiguousInParent() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -1180,14 +1180,14 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(x.getID(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP); } - // class D { public: int x; }; - // class C : public virtual D {}; - // class B : public virtual D {}; - // class A : public B, public C {}; - // void main() { - // A * a = new A(); - // a->x; - // } + // class D { public: int x; }; + // class C : public virtual D {}; + // class B : public virtual D {}; + // class A : public B, public C {}; + // void main() { + // A * a = new A(); + // a->x; + // } public void testVirtualParentLookup() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -1209,14 +1209,14 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, x, 2); } - // class D { public: int x; }; - // class C : public D {}; - // class B : public D {}; - // class A : public B, public C {}; - // void main() { - // A * a = new A(); - // a->x; - // } + // class D { public: int x; }; + // class C : public D {}; + // class B : public D {}; + // class A : public B, public C {}; + // void main() { + // A * a = new A(); + // a->x; + // } public void testAmbiguousVirtualParentLookup() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -1241,13 +1241,13 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, x1, 1); } - // namespace A { - // int x; - // } - // int x; - // namespace A { - // void f() { x; } - // } + // namespace A { + // int x; + // } + // int x; + // namespace A { + // void f() { x; } + // } public void testExtendedNamespaces() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector collector = new CPPNameCollector(); @@ -1442,7 +1442,7 @@ public class AST2CPPTests extends AST2BaseTest { assertNotNull(ctors); // one copy constructor, no implicit default constructor - assertEquals(1, ctors.length); + assertEquals(1, ctors.length); } } @@ -1461,7 +1461,7 @@ public class AST2CPPTests extends AST2BaseTest { assertNotNull(ctors); // one copy constructor, one user declared constructor (not a copy constructor) - assertEquals(2, ctors.length); + assertEquals(2, ctors.length); } } @@ -1501,7 +1501,7 @@ public class AST2CPPTests extends AST2BaseTest { // class A {public: void operator=(A &); }; // class B {protected: void operator=(const B &); }; // class C {private: void operator=(volatile C &) {} }; - // class D {D& operator=(volatile const D &); }; + // class D {D& operator=(volatile const D &); }; public void testExplicitCopyAssignmentOperator_183160() throws Exception { BufferedReader br= new BufferedReader(new StringReader(getAboveComment())); for(String line= br.readLine(); line!=null; line= br.readLine()) { @@ -1531,9 +1531,9 @@ public class AST2CPPTests extends AST2BaseTest { } } - // namespace A { int x; } - // namespace B = A; - // int f(){ B::x; } + // namespace A { int x; } + // namespace B = A; + // int f(){ B::x; } public void testNamespaceAlias() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -1559,10 +1559,10 @@ public class AST2CPPTests extends AST2BaseTest { // instanceof IASTSimpleDeclaration); //$NON-NLS-1$ // } - // void f() { - // int (*p) [2]; - // (&p)[0] = 1; - // } + // void f() { + // int (*p) [2]; + // (&p)[0] = 1; + // } public void testBug84250() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -1578,10 +1578,10 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, p, 2); } - // void f() { - // int (*p) [2]; - // (&p)[0] = 1; - // } + // void f() { + // int (*p) [2]; + // (&p)[0] = 1; + // } public void testBug84250_2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -1595,8 +1595,8 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(p_ref, p_decl); } - // struct s { double i; } f(void); - // struct s f(void){} + // struct s { double i; } f(void); + // struct s f(void){} public void testBug84266() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -1630,11 +1630,11 @@ public class AST2CPPTests extends AST2BaseTest { assertNotNull(s); } - // void f(int m, int c[m][m]); - // void f(int m, int c[m][m]){ - // int x; - // { int x = x; } - // } + // void f(int m, int c[m][m]); + // void f(int m, int c[m][m]){ + // int x; + // { int x = x; } + // } public void testBug84228() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -1655,12 +1655,12 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, x2, 2); } - // class A { public : static int n; }; - // int main() { - // int A; - // A::n = 42; - // A b; - // } + // class A { public : static int n; }; + // int main() { + // int A; + // A::n = 42; + // A b; + // } public void testBug84615() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -1693,14 +1693,14 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(name.getNames()[2].toString(), "ghi"); //$NON-NLS-1$ } - // namespace Y { void f(float); } - // namespace A { using namespace Y; void f(int); } - // namespace B { void f(char); } - // namespace AB { using namespace A; using namespace B; } - // void h(){ - // AB::f(1); - // AB::f(`c`); - // } + // namespace Y { void f(float); } + // namespace A { using namespace Y; void f(int); } + // namespace B { void f(char); } + // namespace AB { using namespace A; using namespace B; } + // void h(){ + // AB::f(1); + // AB::f(`c`); + // } public void testBug84679() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, false, false); @@ -1723,14 +1723,14 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, AB, 3); } - // struct Node { - // struct Node* Next; - // struct Data* Data; - // }; - // struct Data { - // struct Node * node; - // friend struct Glob; - // }; + // struct Node { + // struct Node* Next; + // struct Data* Data; + // }; + // struct Data { + // struct Node * node; + // friend struct Glob; + // }; public void testBug84692() throws Exception { // also tests bug 234042. CPPASTNameBase.sAllowRecursionBindings= false; @@ -1749,10 +1749,10 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, Data, 2); } - // namespace B { int b; } - // namespace A { using namespace B; int a; } - // namespace B { using namespace A; } - // void f() { B::a++; } + // namespace B { int b; } + // namespace A { using namespace B; int a; } + // namespace B { using namespace A; } + // void f() { B::a++; } public void testBug84686() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -1765,18 +1765,18 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(a1, a2); } - // struct C { - // void f(); - // const C& operator=(const C&); - // }; - // const C& C::operator=(const C& other) { - // if (this != &other) { - // this->~C(); - // new (this) C(other); - // f(); - // } - // return *this; - // } + // struct C { + // void f(); + // const C& operator=(const C&); + // }; + // const C& C::operator=(const C& other) { + // if (this != &other) { + // this->~C(); + // new (this) C(other); + // f(); + // } + // return *this; + // } public void testBug84705() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -1801,9 +1801,9 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, other, 4); } - // class A { void f(); void g() const; }; - // void A::f(){ this; } - // void A::g() const { *this; } + // class A { void f(); void g() const; }; + // void A::f(){ this; } + // void A::g() const { *this; } public void testThis() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); @@ -1841,16 +1841,16 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(T.getName(), "T"); //$NON-NLS-1$ } - // namespace NS { - // class T {}; - // void f(T); - // } - // NS::T parm; - // int main() { - // f(parm); - // } + // namespace NS { + // class T {}; + // void f(T); + // } + // NS::T parm; + // int main() { + // f(parm); + // } public void testArgumentDependantLookup() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1865,18 +1865,18 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, parm, 2); } - // namespace NS1{ - // void f(void *); - // } - // namespace NS2{ - // using namespace NS1; - // class B {}; - // void f(void *); - // } - // class A : public NS2::B {} *a; - // int main() { - // f(a); - // } + // namespace NS1{ + // void f(void *); + // } + // namespace NS2{ + // using namespace NS1; + // class B {}; + // void f(void *); + // } + // class A : public NS2::B {} *a; + // int main() { + // f(a); + // } public void testArgumentDependantLookup_2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -1892,20 +1892,20 @@ public class AST2CPPTests extends AST2BaseTest { } // namespace { int i; } //1 - // void f(){ i; } - // namespace A { - // namespace { - // int i; //2 - // int j; - // } - // void g(){ i; } - // } - // using namespace A; - // void h() { - // i; //ambiguous - // A::i; //i2 - // j; - // } + // void f(){ i; } + // namespace A { + // namespace { + // int i; //2 + // int j; + // } + // void g(){ i; } + // } + // using namespace A; + // void h() { + // i; //ambiguous + // A::i; //i2 + // j; + // } public void testBug84610() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -1925,13 +1925,13 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, problem.getID()); } - // struct B { - // void mutate(); - // }; - // void g() { - // B* pb = new B(); - // pb->mutate(); - // } + // struct B { + // void mutate(); + // }; + // void g() { + // B* pb = new B(); + // pb->mutate(); + // } public void testBug84703() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -1948,10 +1948,10 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, B, 2); } - // struct S { int i; }; - // void f() { ; - // int S::* pm = &S::i; - // } + // struct S { int i; }; + // void f() { ; + // int S::* pm = &S::i; + // } public void testBug84469() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -1979,11 +1979,11 @@ public class AST2CPPTests extends AST2BaseTest { assertTrue(((ICPPPointerToMemberType) t).getType() instanceof IBasicType); } - // struct S { int i ; } *s; - // int S::* pm = &S::i; - // void f() { - // s->*pm = 1; - // } + // struct S { int i ; } *s; + // int S::* pm = &S::i; + // void f() { + // s->*pm = 1; + // } public void testBug_PM_() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -1995,14 +1995,14 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(pm, ref); } - // struct S { - // int i; - // S* f(); - // } *s; - // S* (S::* pm) () = &S::f; - // void foo() { - // (s->*pm)()->i; - // } + // struct S { + // int i; + // S* f(); + // } *s; + // S* (S::* pm) () = &S::f; + // void foo() { + // (s->*pm)()->i; + // } public void testBug_PM_2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2080,13 +2080,13 @@ public class AST2CPPTests extends AST2BaseTest { assertTrue(body.getStatements()[0] instanceof IASTDeclarationStatement); } - // class A { public: int i; }; - // class B : public A {}; - // void f(int B::*); - // void g() { - // int A::* pm = &A::i; - // f(pm); - // } + // class A { public: int i; }; + // class B : public A {}; + // void f(int B::*); + // void g() { + // int A::* pm = &A::i; + // f(pm); + // } public void testPMConversions() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2105,14 +2105,14 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, pm, 2); } - // namespace N { - // class A { public: int i; }; - // void f(int A::*); - // } - // int N::A::* pm = &N::A::i; - // void g() { - // f(pm); - // } + // namespace N { + // class A { public: int i; }; + // void f(int A::*); + // } + // int N::A::* pm = &N::A::i; + // void g() { + // f(pm); + // } public void testPMKoenig() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2127,18 +2127,18 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, A, 4); } - // namespace M { - // class B { }; - // void f(B*); - // } - // namespace N { - // class A { public: M::B * b; }; - // } - // M::B* N::A::* pm = &N::A::b; - // void g() { - // N::A * a; - // f(a->*pm); - // } + // namespace M { + // class B { }; + // void f(B*); + // } + // namespace N { + // class A { public: M::B * b; }; + // } + // M::B* N::A::* pm = &N::A::b; + // void g() { + // N::A * a; + // f(a->*pm); + // } public void testPMKoenig_2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2159,12 +2159,12 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, pm, 2); } - // class A { - // friend void set(); - // friend class B; - // }; - // void set(); - // class B{}; + // class A { + // friend void set(); + // friend class B; + // }; + // void set(); + // class B{}; public void testFriend_1() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2185,10 +2185,10 @@ public class AST2CPPTests extends AST2BaseTest { // class Other { // void m(); }; - // class A { - // friend void set(); - // friend void Other::m(); - // }; + // class A { + // friend void set(); + // friend void Other::m(); + // }; public void testFriend_Bug275358() throws Exception { final String code = getAboveComment(); BindingAssertionHelper bh= new BindingAssertionHelper(code, true); @@ -2207,8 +2207,8 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(0, declaredMethods.length); } - // class A { friend class B; friend class B; }; - // class B{}; + // class A { friend class B; friend class B; }; + // class B{}; public void testBug59149() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2224,12 +2224,12 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(friends[0], B); } - // class A { - // public: class N {}; - // }; - // class B { - // friend class A::N; - // }; + // class A { + // public: class N {}; + // }; + // class B { + // friend class A::N; + // }; public void testBug59302() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2248,9 +2248,9 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(N.getFriends().length, 0); } - // class A { - // friend class B *helper(); - // }; + // class A { + // friend class B *helper(); + // }; public void testBug75482() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2268,12 +2268,12 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(friends[0], helper); } - // void f(int); - // void f(char); - // void (*pf) (int) = &f; - // void foo() { - // pf = &f; - // } + // void f(int); + // void f(char); + // void (*pf) (int) = &f; + // void foo() { + // pf = &f; + // } public void testBug45763_1() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2288,14 +2288,14 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, f2, 1); } - // void f(char); - // void f(int); - // void g(void (*)(int)) {} - // void (*pg)(void(*)(int)); - // void foo() { - // g(&f); - // (*pg)(&f); - // } + // void f(char); + // void f(int); + // void g(void (*)(int)) {} + // void (*pg)(void(*)(int)); + // void foo() { + // g(&f); + // (*pg)(&f); + // } public void testBug45763_2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2312,11 +2312,11 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, pg, 2); } - // void f(int); - // void f(char); - // void (* bar ()) (int) { - // return &f; - // } + // void f(int); + // void f(char); + // void (* bar ()) (int) { + // return &f; + // } public void testBug45763_3() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2331,11 +2331,11 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, f2, 1); } - // void f(int); - // void f(char); - // void foo () { - // (void (*)(int)) &f; - // } + // void f(int); + // void f(char); + // void foo () { + // (void (*)(int)) &f; + // } public void testBug45763_4() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2350,8 +2350,8 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, f2, 1); } - // extern int g; - // int g; + // extern int g; + // int g; // void f() { g = 1; } public void testBug85824() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); @@ -2362,18 +2362,18 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, g, 3); } - // struct A { - // int a2; - // }; - // struct B : public A { - // int a1; - // void f(); - // }; - // int a3; - // void B::f(){ - // int a4; - // a; - // } + // struct A { + // int a2; + // }; + // struct B : public A { + // int a1; + // void f(); + // }; + // int a3; + // void B::f(){ + // int a4; + // a; + // } public void testPrefixLookup() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2404,7 +2404,7 @@ public class AST2CPPTests extends AST2BaseTest { // } // void test(){ // v_; - // } + // } public void testAdditionalNamespaceLookup() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2423,8 +2423,8 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(1, bs.length); // the bindings above } - // static void f(); - // void f() {} + // static void f(); + // void f() {} public void testIsStatic() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2440,7 +2440,7 @@ public class AST2CPPTests extends AST2BaseTest { // // || __i < 2 || __sign.size() > 1 // // || ((static_cast(__p.field[3]) != // // money_base::none) - // // && __i == 2)) + // // && __i == 2)) // // return; // // } // public void testBug85310() throws Exception { @@ -2452,15 +2452,15 @@ public class AST2CPPTests extends AST2BaseTest { // assertNotNull(if_stmt.getCondition()); // } - // struct B { void mutate(); }; - // struct D1 : B {}; - // struct D2 : B {}; - // void B::mutate() { - // new (this) D2; - // } - // void g() { - // B* pb = new (p) D1; - // } + // struct B { void mutate(); }; + // struct D1 : B {}; + // struct D2 : B {}; + // void B::mutate() { + // new (this) D2; + // } + // void g() { + // B* pb = new (p) D1; + // } public void testBug86267() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2479,18 +2479,18 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, d2_ctor, 1); } - // struct C { - // void f(); - // const C& operator =(const C&); - // }; - // const C& C::operator = (const C& other) { - // if (this != &other) { - // this->~C(); - // new (this) C(other); - // f(); - // } - // return *this; - // } + // struct C { + // void f(); + // const C& operator =(const C&); + // }; + // const C& C::operator = (const C& other) { + // if (this != &other) { + // this->~C(); + // new (this) C(other); + // f(); + // } + // return *this; + // } public void testBug86269() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2509,15 +2509,15 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(other.getName(), "other"); //$NON-NLS-1$ } - // extern "C" { - // void printf(const char *); - // void sprintf(const char *); - // } - // void foo(){ - // char *p; - // printf(p); - // printf("abc"); - // } + // extern "C" { + // void printf(const char *); + // void sprintf(const char *); + // } + // void foo(){ + // char *p; + // printf(p); + // printf("abc"); + // } public void testBug86279() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2531,12 +2531,12 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(printf, r2); } - // struct S; - // extern S a; - // void g(S); - // void h() { - // g(a); - // } + // struct S; + // extern S a; + // void g(S); + // void h() { + // g(a); + // } public void testBug86346() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2561,7 +2561,7 @@ public class AST2CPPTests extends AST2BaseTest { // void foo() { // struct B { // int f(); - // }; + // }; // int (B::*pb)() = &B::f; // } public void testBug84476() throws Exception { @@ -2577,12 +2577,12 @@ public class AST2CPPTests extends AST2BaseTest { assertTrue(d.getNestedDeclarator().getPointerOperators()[0] instanceof ICPPASTPointerToMember); } - // struct T1 { - // T1 operator() (int x) { - // return T1(x); - // } - // T1(int) {} - // }; + // struct T1 { + // T1 operator() (int x) { + // return T1(x); + // } + // T1(int) {} + // }; public void testBug86336() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2598,10 +2598,10 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(T1_ctor, ctor2); } - // struct S { int i; }; - // void foo() { - // int S::* pm = &S::i; - // } + // struct S { int i; }; + // void foo() { + // int S::* pm = &S::i; + // } public void testBug86306() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2617,29 +2617,29 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(refs[1], col.getName(7)); } - // class A { - // public: - // template void f(T); - // template struct X { }; - // }; - // class B : public A { - // public: - // using A::f; // illformed - // using A::X; // illformed - // }; + // class A { + // public: + // template void f(T); + // template struct X { }; + // }; + // class B : public A { + // public: + // using A::f; // illformed + // using A::X; // illformed + // }; public void testBug86372() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); } - // void foo() { - // int i = 42; - // int a[10]; + // void foo() { + // int i = 42; + // int a[10]; // for(int i = 0; i < 10; i++) - // a[i] = 1; - // int j = i; - // } + // a[i] = 1; + // int j = i; + // } public void testBug86319() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2653,16 +2653,16 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, i2, 4); } - // class X { int i, j; }; - // class Y { X x; }; - // void foo() { - // const Y y; - // y.x.i++; - // y.x.j++; - // Y* p = const_cast(&y); - // p->x.i; - // p->x.j; - // } + // class X { int i, j; }; + // class Y { X x; }; + // void foo() { + // const Y y; + // y.x.i++; + // y.x.j++; + // Y* p = const_cast(&y); + // p->x.i; + // p->x.j; + // } public void testBug86350() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2698,11 +2698,11 @@ public class AST2CPPTests extends AST2BaseTest { assertNotNull(whileStatement.getConditionDeclaration()); } - // void foo() { - // const int x = 12; - // { enum { x = x }; } - // } - // enum { RED }; + // void foo() { + // const int x = 12; + // { enum { x = x }; } + // } + // enum { RED }; public void testBug86353() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2729,13 +2729,13 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(decls[0], col.getName(6)); } - // class D {}; - // D d1; - // const D d2; - // void foo() { - // typeid(d1) == typeid(d2); - // typeid(D) == typeid(d2); - // } + // class D {}; + // D d1; + // const D d2; + // void foo() { + // typeid(d1) == typeid(d2); + // typeid(D) == typeid(d2); + // } public void testBug86274() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2751,12 +2751,12 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, d2, 3); } - // void point (int = 3, int = 4); - // void foo() { - // point(1, 2); - // point(1); - // point(); - // } + // void point (int = 3, int = 4); + // void foo() { + // point(1, 2); + // point(1); + // point(); + // } public void testBug86546() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2767,14 +2767,14 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, point, 4); } - // namespace Outer{ - // int i; - // namespace Inner { - // void f() { i++; } - // int i; - // void g() { i++; } - // } - // } + // namespace Outer{ + // int i; + // namespace Inner { + // void f() { i++; } + // int i; + // void g() { i++; } + // } + // } public void testBug86358_1() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2787,14 +2787,14 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, i2, 2); } - // namespace Q { - // namespace V { - // void f(); - // } - // void V::f() {} - // namespace V { - // } - // } + // namespace Q { + // namespace V { + // void f(); + // } + // void V::f() {} + // namespace V { + // } + // } public void testBug86358_2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2816,15 +2816,15 @@ public class AST2CPPTests extends AST2BaseTest { assertTrue(f2.isGloballyQualified()); } - // struct B { - // void f (char); - // void g (char); - // }; - // struct D : B { - // using B::f; - // void f(int) { f('c'); } - // void g(int) { g('c'); } - // }; + // struct B { + // void f (char); + // void g (char); + // }; + // struct D : B { + // using B::f; + // void f(int) { f('c'); } + // void g(int) { g('c'); } + // }; public void test86371() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2853,10 +2853,10 @@ public class AST2CPPTests extends AST2BaseTest { assertTrue(f.isGloballyQualified()); } - // namespace Company_with_veryblahblah {} - // namespace CWVLN = Company_with_veryblahblah; - // namespace CWVLN = Company_with_veryblahblah; - // namespace CWVLN = CWVLN; + // namespace Company_with_veryblahblah {} + // namespace CWVLN = Company_with_veryblahblah; + // namespace CWVLN = Company_with_veryblahblah; + // namespace CWVLN = CWVLN; public void testBug86369() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2893,11 +2893,11 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(decls[2], col.getName(5)); } - // namespace A { - // void f(char); - // void f(int); - // } - // using A::f; + // namespace A { + // void f(char); + // void f(int); + // } + // using A::f; public void testBug86470_1() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2923,20 +2923,20 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(decls[0], col.getName(1)); } - // namespace A { - // void f(int); - // void f(double); - // } - // namespace B { - // void f(int); - // void f(double); - // void f(char); - // } - // void g() { - // using A::f; - // using B::f; - // f('c'); - // } + // namespace A { + // void f(int); + // void f(double); + // } + // namespace B { + // void f(int); + // void f(double); + // void f(char); + // } + // void g() { + // using A::f; + // using B::f; + // f('c'); + // } public void testBug86470_2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2947,15 +2947,15 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(f_decl, f_ref); } - // namespace A { - // struct g {}; - // void g (char); - // } - // void f() { - // using A::g; - // g('a'); - // struct g gg; - // } + // namespace A { + // struct g {}; + // void g (char); + // } + // void f() { + // using A::g; + // g('a'); + // struct g gg; + // } public void testBug86470_3() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -2978,18 +2978,18 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(decls[2], col.getName(7)); } - // namespace A { - // int x; - // } - // namespace B { - // struct x {}; - // } - // void f() { - // using A::x; - // using B::x; - // x = 1; - // struct x xx; - // } + // namespace A { + // int x; + // } + // namespace B { + // struct x {}; + // } + // void f() { + // using A::x; + // using B::x; + // x = 1; + // struct x xx; + // } public void testBug86470_4() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3020,15 +3020,15 @@ public class AST2CPPTests extends AST2BaseTest { assertTrue(x_struct.isGloballyQualified()); } - // namespace A { - // void f(int); - // void f(double); - // } - // void g() { - // void f(char); - // using A::f; - // f(3.5); - // } + // namespace A { + // void f(int); + // void f(double); + // } + // void g() { + // void f(char); + // using A::f; + // f(3.5); + // } public void testBug86470_5() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3050,15 +3050,15 @@ public class AST2CPPTests extends AST2BaseTest { assertTrue(f.isGloballyQualified()); } - // class B; - // class A { - // int i; - // friend void f(B *); - // }; - // class B : public A {}; - // void f(B* p) { - // p->i = 1; - // } + // class B; + // class A { + // int i; + // friend void f(B *); + // }; + // class B : public A {}; + // void f(B* p) { + // p->i = 1; + // } public void testBug86678() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3073,12 +3073,12 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, p, 3); } - // int printf(const char *, ...); - // void foo(){ - // int a, b; - // printf("hello"); - // printf("a=%d b=%d", a, b); - // } + // int printf(const char *, ...); + // void foo(){ + // int a, b; + // printf("hello"); + // printf("a=%d b=%d", a, b); + // } public void testBug86543() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3088,10 +3088,10 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, printf, 3); } - // int max(int a, int b, int c) { - // int m = (a > b) ? a : b; - // return (m > c) ? m : c; - // } + // int max(int a, int b, int c) { + // int m = (a > b) ? a : b; + // return (m > c) ? m : c; + // } public void testBug86554() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3112,10 +3112,10 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, c, 3); } - // int g(); - // struct X { static int g(); }; - // struct Y : X { static int i ; }; - // int Y::i = g(); + // int g(); + // struct X { static int g(); }; + // struct Y : X { static int i ; }; + // int Y::i = g(); public void testBug86621() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3137,22 +3137,22 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, g2, 2); } - // class V { int f(); int x; }; - // class W { int g(); int y; }; - // class B : public virtual V, public W { - // int f(); int x; - // int g(); int y; - // }; - // class C : public virtual V, public W {}; - // class D : public B, public C { - // void foo(); - // }; - // void D::foo(){ - // x++; - // f(); - // y++; - // g(); - // } + // class V { int f(); int x; }; + // class W { int g(); int y; }; + // class B : public virtual V, public W { + // int f(); int x; + // int g(); int y; + // }; + // class C : public virtual V, public W {}; + // class D : public B, public C { + // void foo(); + // }; + // void D::foo(){ + // x++; + // f(); + // y++; + // g(); + // } public void testBug86649() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3181,10 +3181,10 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, f, 2); } - // struct C { - // int c; - // C() : c(0) { } - // }; + // struct C { + // int c; + // C() : c(0) { } + // }; public void testBug86827() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3203,12 +3203,12 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(refs[0], col.getName(3)); } - // void f(int par) { - // int v1; - // { - // int v2; - // } - // } + // void f(int par) { + // int v1; + // { + // int v2; + // } + // } public void testFind_1() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3231,12 +3231,12 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(bs[0], v1); } - // class A { int a; }; - // class B : public A { - // void f(); - // }; - // void B::f() { - // } + // class A { int a; }; + // class B : public A { + // void f(); + // }; + // void B::f() { + // } public void testFind_2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3261,14 +3261,14 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(bs[0], A); } - // namespace A { - // void f(int); - // void f(double); - // } - // void g() { - // void f(char); - // using A::f; - // } + // namespace A { + // void f(int); + // void f(double); + // } + // void g() { + // void f(char); + // using A::f; + // } public void testFind_3() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3293,20 +3293,20 @@ public class AST2CPPTests extends AST2BaseTest { assertTrue(((ICPPBinding) bs[1]).isGloballyQualified()); } - // namespace A { - // struct f; - // void f(); - // } - // namespace B { - // void f(int); - // } - // namespace C { - // using namespace B; - // } - // void g(){ - // using namespace A; - // using namespace C; - // } + // namespace A { + // struct f; + // void f(); + // } + // namespace B { + // void f(int); + // } + // namespace C { + // using namespace B; + // } + // void g(){ + // using namespace A; + // using namespace C; + // } public void testFind_4() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3360,14 +3360,14 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(classType.getQualifiedName()[0], "A"); } - // class A { - // int a; - // void fa(); - // }; - // class B : public A { - // int b; - // void fb(); - // }; + // class A { + // int a; + // void fa(); + // }; + // class B : public A { + // int b; + // void fb(); + // }; public void testGets() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3484,7 +3484,7 @@ public class AST2CPPTests extends AST2BaseTest { // //$NON-NLS-1$ // CPPNameCollector col = new CPPNameCollector(); // tu.accept(col); - // + // // assertTrue(col.getName(0).resolveBinding() instanceof IVariable); // IProblemBinding p = (IProblemBinding) col.getName(1).resolveBinding(); // assertEquals(p.getID(), IProblemBinding.SEMANTIC_INVALID_REDEFINITION); @@ -3501,13 +3501,13 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(p.getID(), IProblemBinding.SEMANTIC_INVALID_REDECLARATION); } - // namespace A { int i; } - // namespace B = A; - // void f() { - // B::i; - // } + // namespace A { int i; } + // namespace B = A; + // void f() { + // B::i; + // } public void testNamespaceAlias_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -3529,13 +3529,13 @@ public class AST2CPPTests extends AST2BaseTest { assertTrue(alias.isGloballyQualified()); } - // class A{}; - // class B : public A { - // B () : A() {} - // }; + // class A{}; + // class B : public A { + // B () : A() {} + // }; public void testBug89539() throws Exception { String content= getAboveComment(); - IASTTranslationUnit tu = parse(content, ParserLanguage.CPP); + IASTTranslationUnit tu = parse(content, ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -3546,20 +3546,20 @@ public class AST2CPPTests extends AST2BaseTest { ICPPConstructor A3 = (ICPPConstructor) col.getName(4).resolveBinding(); assertSame(A3.getScope(), A1.getCompositeScope()); - tu = parse(content, ParserLanguage.CPP); + tu = parse(content, ParserLanguage.CPP); col = new CPPNameCollector(); tu.accept(col); assertTrue(col.getName(4).resolveBinding() instanceof ICPPConstructor); } - // class B * b; - // class A { - // A * a; - // }; - // class A; + // class B * b; + // class A { + // A * a; + // }; + // class A; public void testBug89851() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -3587,15 +3587,15 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(bs[1], f2); } - // class A { - // enum type { t1, t2 }; - // void f(type t); - // }; - // class B : public A { - // void g() { - // f(A::t1); - // } - // }; + // class A { + // enum type { t1, t2 }; + // void f(type t); + // }; + // class B : public A { + // void g() { + // f(A::t1); + // } + // }; public void testBug90039() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3608,9 +3608,9 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, t1, 3); } - // void f(void) { - // enum { one }; - // } + // void f(void) { + // enum { one }; + // } public void testBug90039_2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3628,7 +3628,7 @@ public class AST2CPPTests extends AST2BaseTest { // char& operator[](unsigned int); // }; public void testOperatorConversionNames() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -3648,12 +3648,12 @@ public class AST2CPPTests extends AST2BaseTest { } - // class X { operator int(); }; - // X::operator int() { } - // template class X { operator int(); }; - // template X::operator int() { } + // class X { operator int(); }; + // X::operator int() { } + // template class X { operator int(); }; + // template X::operator int() { } public void testBug36769B() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -3779,12 +3779,12 @@ public class AST2CPPTests extends AST2BaseTest { assertTrue(((ITypedef) binding).getType() instanceof IFunctionType); } - // void f(int); - // void foo(){ - // f((1, 2)); - // } + // void f(int); + // void foo(){ + // f((1, 2)); + // } public void testBug90616() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -3814,11 +3814,11 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(f1.getScope(), X.getCompositeScope()); } - // class X { }; - // X x; - // class X { }; + // class X { }; + // X x; + // class X { }; public void testBug90662() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -3830,10 +3830,10 @@ public class AST2CPPTests extends AST2BaseTest { IProblemBinding.SEMANTIC_INVALID_REDEFINITION); } - // struct C { + // struct C { // void* operator new [ ] (unsigned int); // void* operator new (unsigned int); - // void operator delete [ ] (void *); + // void operator delete [ ] (void *); // void operator delete (void *); // const C& operator+=(const C&); // const C& operator -= (const C&); @@ -3871,11 +3871,11 @@ public class AST2CPPTests extends AST2BaseTest { // const C& operator &(const C&); // const C& operator |(const C&); // const C& operator ~ (const C&); - // const C& operator + // const C& operator // ! /**/ (const C&); // const C& operator <(const C&); // const C& operator>(const C&); - // }; + // }; public void testOperatorNames() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -3926,16 +3926,16 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(col.getName(158).toString(), "operator >"); //$NON-NLS-1$ } - // typedef int I; - // typedef int I; - // typedef I I; - // class A { - // typedef char I; - // typedef char I; - // typedef I I; - // }; + // typedef int I; + // typedef int I; + // typedef I I; + // class A { + // typedef char I; + // typedef char I; + // typedef I I; + // }; public void testBug90623() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -3964,11 +3964,11 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(((IBasicType) I8.getType()).getType(), IBasicType.t_char); } - // typedef int I; - // void f11(I i); - // void main(){ f a; } + // typedef int I; + // void f11(I i); + // void main(){ f a; } public void testBug90623_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -3976,16 +3976,16 @@ public class AST2CPPTests extends AST2BaseTest { f.getCompletionContext().findBindings(f, true); } - // class X { - // X(const X &); - // }; - // class Y { - // operator X (); - // }; - // Y y; - // X x = new X(y); + // class X { + // X(const X &); + // }; + // class Y { + // operator X (); + // }; + // Y y; + // X x = new X(y); public void testBug90654_1() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -3994,14 +3994,14 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(ctor, ctor1); } - // struct A { - // operator short(); - // } a; - // int f(int); - // int f(float); - // int x = f(a); + // struct A { + // operator short(); + // } a; + // int f(int); + // int f(float); + // int x = f(a); public void testBug90654_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -4010,16 +4010,16 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(f1, f2); } - // struct A {}; - // struct B : public A { - // B& operator = (const B &); - // }; - // B& B::operator = (const B & s){ - // this->A::operator=(s); - // return *this; - // } + // struct A {}; + // struct B : public A { + // B& operator = (const B &); + // }; + // B& B::operator = (const B & s){ + // this->A::operator=(s); + // return *this; + // } public void testBug90653() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -4035,12 +4035,12 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(op, implicit); } - // void f(char *); - // void foo() { - // f("test"); - // } + // void f(char *); + // void foo() { + // f("test"); + // } public void testBug86618() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -4048,13 +4048,13 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, f, 2); } - // void f(int (*pf) (char)); - // int g(char); - // void foo () { - // f(g) ; - // } + // void f(int (*pf) (char)); + // int g(char); + // void foo () { + // f(g) ; + // } public void testBug45129() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -4068,12 +4068,12 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(g1, g2); } - // class ABC { + // class ABC { // class DEF { }; // static int GHI; - // }; + // }; // int ABC::GHI = 77; // ray bourque - // int f() { + // int f() { // int value; // ABC::DEF * var; // ABC::GHI * value; @@ -4088,12 +4088,12 @@ public class AST2CPPTests extends AST2BaseTest { } - // void f(){ - // union { int a; char* p; }; - // a = 1; - // } + // void f(){ + // union { int a; char* p; }; + // a = 1; + // } public void testBug86639() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -4102,12 +4102,12 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(a, a2); } - // void f () { - // int aa1, aa2; - // a; - // } + // void f () { + // int aa1, aa2; + // a; + // } public void testBug80940() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -4121,18 +4121,18 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(bs[1], a2); } - // struct Ex { - // int d(); - // int d() const; - // }; - // int Ex::d() {} - // int Ex::d() const {} - // void f() { - // const Ex * e; - // e->d(); - // } + // struct Ex { + // int d(); + // int d() const; + // }; + // int Ex::d() {} + // int Ex::d() const {} + // void f() { + // const Ex * e; + // e->d(); + // } public void testBug77024() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -4154,12 +4154,12 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(d2, r); } - // class Point { - // Point() : xCoord(0) {} - // int xCoord; - // }; + // class Point { + // Point() : xCoord(0) {} + // int xCoord; + // }; public void testBug91773() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -4187,10 +4187,10 @@ public class AST2CPPTests extends AST2BaseTest { parse(code, ParserLanguage.CPP, true, false); } - // class Dummy { int v(); int d; }; - // void Dummy::v(int){ d++; } + // class Dummy { int v(); int d; }; + // void Dummy::v(int){ d++; } public void testBug92882() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -4200,15 +4200,15 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(d1, d2); } - // void f(int, int); - // void f(int, int = 3); - // void f(int = 2, int); - // void g() { - // f(3); - // f(); - // } + // void f(int, int); + // void f(int, int = 3); + // void f(int = 2, int); + // void g() { + // f(3); + // f(); + // } public void testBug86547() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -4270,11 +4270,11 @@ public class AST2CPPTests extends AST2BaseTest { assertNoProblemBindings(nameResolver); } - // class C { - // static const int n = 1; - // static int arr[ n ]; - // }; - // int C::arr[n]; + // class C { + // static const int n = 1; + // static int arr[ n ]; + // }; + // int C::arr[n]; public void testBug90610() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4286,20 +4286,20 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, n, 3); } - // int a; - // extern int b; - // extern int c = 1; - // int f(); - // int f(int p){} - // struct S; - // struct S { int d; }; - // struct X { - // static int y; - // }; - // namespace N {} - // int X::y = 1; - // int (*g(int))(int); - // int (*pf)(int); + // int a; + // extern int b; + // extern int c = 1; + // int f(); + // int f(int p){} + // struct S; + // struct S { int d; }; + // struct X { + // static int y; + // }; + // namespace N {} + // int X::y = 1; + // int (*g(int))(int); + // int (*pf)(int); public void testDeclDefn() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4322,10 +4322,10 @@ public class AST2CPPTests extends AST2BaseTest { assertTrue(col.getName(18).isDefinition()); // pf } - // int f(double); - // int f(int); - // int (&rfi)(int) = f; - // int (&rfd)(double) = f; + // int f(double); + // int f(int); + // int (&rfi)(int) = f; + // int (&rfd)(double) = f; public void testBug95200() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4362,11 +4362,11 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(ctor, ctors[1]); } - // void f(char *); - // void g(){ - // char x[100]; - // f(x); - // } + // void f(char *); + // void g(){ + // char x[100]; + // f(x); + // } public void testBug95461() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4377,7 +4377,7 @@ public class AST2CPPTests extends AST2BaseTest { } // class A { }; - // int f() { + // int f() { // A * b = 0; // A & c = 0; // } @@ -4396,7 +4396,7 @@ public class AST2CPPTests extends AST2BaseTest { } // struct A { - // int a; + // int a; // }; // struct B: virtual A { }; // struct C: B { }; @@ -4489,11 +4489,11 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$ } - // class X { public: int bar; }; - // void f(){ - // X a[10]; - // a[0].bar; - // } + // class X { public: int bar; }; + // void f(){ + // X a[10]; + // a[0].bar; + // } public void testBug95484() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4503,10 +4503,10 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(bar, col.getName(6).resolveBinding()); } - // int strcmp(const char *); - // void f(const char * const * argv){ - // strcmp(*argv); - // } + // int strcmp(const char *); + // void f(const char * const * argv){ + // strcmp(*argv); + // } public void testBug95419() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4516,14 +4516,14 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(strcmp, col.getName(4).resolveBinding()); } - // class Other; - // class Base { - // public: Base(Other *); - // }; - // class Sub : public Base { - // public: Sub(Other *); - // }; - // Sub::Sub(Other * b) : Base(b) {} + // class Other; + // class Base { + // public: Base(Other *); + // }; + // class Sub : public Base { + // public: Sub(Other *); + // }; + // Sub::Sub(Other * b) : Base(b) {} public void testBug95673() throws Exception { BindingAssertionHelper ba= getAssertionHelper(); @@ -4532,12 +4532,12 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(ctor, ctor2); } - // void mem(void *, const void *); - // void f() { - // char *x; int offset; - // mem(x, "FUNC"); - // mem(x + offset, "FUNC2"); - // } + // void mem(void *, const void *); + // void f() { + // char *x; int offset; + // mem(x, "FUNC"); + // mem(x + offset, "FUNC2"); + // } public void testBug95768() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4548,13 +4548,13 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(mem, col.getName(8).resolveBinding()); } - // void trace(const void *); - // class Foo { - // public: int import(); - // }; - // int Foo::import(){ - // trace(this); - // } + // void trace(const void *); + // class Foo { + // public: int import(); + // }; + // int Foo::import(){ + // trace(this); + // } public void testBug95741() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4564,13 +4564,13 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(trace, col.getName(7).resolveBinding()); } - // class RTCharacter { - // char value; - // public: operator char (void) const; - // }; - // RTCharacter::operator char(void)const { - // return value; - // } + // class RTCharacter { + // char value; + // public: operator char (void) const; + // }; + // RTCharacter::operator char(void)const { + // return value; + // } public void testBug95692() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4580,11 +4580,11 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(op, col.getName(6).resolveBinding()); } - // int str(const char *); - // void f(){ - // str(0); - // str(00); str(0x0); - // } + // int str(const char *); + // void f(){ + // str(0); + // str(00); str(0x0); + // } public void testBug95734() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4596,12 +4596,12 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(str, col.getName(5).resolveBinding()); } - // int str(bool); - // enum { ONE }; - // void f(char * p){ - // str(1.2); - // str(ONE); str(p); - // } + // int str(bool); + // enum { ONE }; + // void f(char * p){ + // str(1.2); + // str(ONE); str(p); + // } public void testBug95734_2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4660,13 +4660,13 @@ public class AST2CPPTests extends AST2BaseTest { assertTrue(d.getName().resolveBinding() instanceof IVariable); } - // typedef struct xs { - // int state; - // } xs; - // void f(xs *ci) { - // ci->state; - // (ci - 1)->state; - // } + // typedef struct xs { + // int state; + // } xs; + // void f(xs *ci) { + // ci->state; + // (ci - 1)->state; + // } public void testBug95714() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4689,13 +4689,13 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(((IASTSimpleDeclSpecifier) ((IASTSimpleDeclaration)decls[1]).getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_double); } - // class _A { - // static int i; - // }; - // typedef _A A; - // void f(){ - // A::i++; - // } + // class _A { + // static int i; + // }; + // typedef _A A; + // void f(){ + // A::i++; + // } public void testTypedefQualified() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4705,6 +4705,33 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(i, col.getName(7).resolveBinding()); } + // template + // class basic_string { + // basic_string& operator+=(const T* s); + // }; + // + // template + // basic_string operator+(const T* cs, const basic_string& s); + // + // template + // basic_string operator+(const basic_string& s, const T* cs); + // + // typedef basic_string string; + // + // void test(const string& s) { + // auto s1 = "" + s + ""; + // auto s2 = s1 += ""; + // } + public void testTypedefPreservation_380498() throws Exception { + BindingAssertionHelper ba= getAssertionHelper(); + ICPPVariable s1 = ba.assertNonProblem("s1", ICPPVariable.class); + assertTrue(s1.getType() instanceof ITypedef); + assertEquals("string", ((ITypedef) s1.getType()).getName()); + ICPPVariable s2 = ba.assertNonProblem("s2", ICPPVariable.class); + assertTrue(s2.getType() instanceof ITypedef); + assertEquals("string", ((ITypedef) s2.getType()).getName()); + } + // int f() { // return 5; // } @@ -4720,11 +4747,11 @@ public class AST2CPPTests extends AST2BaseTest { assertNoProblemBindings(col); } - // void copy(void *); - // typedef struct {} A; - // void f(A * a) { - // copy(a); - // } + // void copy(void *); + // typedef struct {} A; + // void f(A * a) { + // copy(a); + // } public void testBug96655() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4738,11 +4765,11 @@ public class AST2CPPTests extends AST2BaseTest { parse("int x; // comment \r\n", ParserLanguage.CPP, false, true); //$NON-NLS-1$ } - // struct A {}; - // void copy(A *); - // void f() { - // copy(new A()); - // } + // struct A {}; + // void copy(A *); + // void f() { + // copy(new A()); + // } public void testNewExpressionType() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4752,9 +4779,9 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(copy, col.getName(5).resolveBinding()); } - // class A { - // A(int i = 0); - // }; + // class A { + // A(int i = 0); + // }; public void testDefaultConstructor() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4768,20 +4795,20 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(cs[1], ctor); } - // class C { public: int foo; }; - // class B { - // C* operator ->(); - // C& operator [] (int); - // }; - // void f(){ - // B b; - // b->foo; - // b[0].foo; - // } + // class C { public: int foo; }; + // class B { + // C* operator ->(); + // C& operator [] (int); + // }; + // void f(){ + // B b; + // b->foo; + // b[0].foo; + // } public void testBug91707() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.accept(col); + tu.accept(col); ICPPField foo = (ICPPField) col.getName(1).resolveBinding(); @@ -4789,16 +4816,16 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(foo, col.getName(14).resolveBinding()); } - // class A; - // class A { - // class B; - // class C {}; - // }; - // class A::B{}; + // class A; + // class A { + // class B; + // class C {}; + // }; + // class A::B{}; public void testBug92425() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.accept(col); + tu.accept(col); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(2).resolveBinding(); @@ -4810,14 +4837,14 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(classes[1], C); } - // namespace A { - // struct F {} f; - // void f(int a) {} - // } + // namespace A { + // struct F {} f; + // void f(int a) {} + // } public void testBug92425_2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); - tu.accept(col); + tu.accept(col); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); IBinding [] bindings = A.getMemberBindings(); @@ -4827,14 +4854,14 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(bindings[2], col.getName(3).resolveBinding()); } - // A< B< C< D< E< F< G< H > > > > > > > a; - // int A::B::* b; + // A< B< C< D< E< F< G< H > > > > > > > a; + // int A::B::* b; public void testBug98704() throws Exception { parse(getAboveComment(), ParserLanguage.CPP); } - // void f(); - // void f(void) {} + // void f(); + // void f(void) {} public void testBug_AIOOBE() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4846,9 +4873,9 @@ public class AST2CPPTests extends AST2BaseTest { assertNotNull(p); } - // void f(const int); - // void f(int); - // void g() { f(1); } + // void f(const int); + // void f(int); + // void g() { f(1); } public void testRankingQualificationConversions_a() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4917,21 +4944,21 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(i1, ref); } - // namespace n { - // namespace m { - // class A; - // } - // } - // namespace n { - // namespace m { - // class A { void f(); }; - // } - // } - // namespace n { - // namespace m { - // void A::f(){} - // } - // } + // namespace n { + // namespace m { + // class A; + // } + // } + // namespace n { + // namespace m { + // class A { void f(); }; + // } + // } + // namespace n { + // namespace m { + // void A::f(){} + // } + // } public void testBug98818() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4944,21 +4971,21 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(m, col.getName(4).resolveBinding()); assertSame(m, col.getName(8).resolveBinding()); - ICPPClassType A = (ICPPClassType) col.getName(2).resolveBinding(); + ICPPClassType A = (ICPPClassType) col.getName(2).resolveBinding(); assertSame(A, col.getName(5).resolveBinding()); ICPPMethod f = (ICPPMethod) col.getName(9).resolveBinding(); assertSame(f, col.getName(11).resolveBinding()); } - // struct A { - // struct { int i; } B; - // struct { int j; } C; - // }; - // void f(){ - // A a; - // a.B.i; a.C.j; - // } + // struct A { + // struct { int i; } B; + // struct { int j; } C; + // }; + // void f(){ + // A a; + // a.B.i; a.C.j; + // } public void testAnonymousStructures() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); @@ -4979,7 +5006,7 @@ public class AST2CPPTests extends AST2BaseTest { // void f2() { // f1(__null); // } - public void testBug240567() throws Exception { + public void testBug240567() throws Exception { BindingAssertionHelper bh= getAssertionHelper(); bh.assertNonProblem("f1(__null", 2, ICPPFunction.class); } @@ -5002,24 +5029,24 @@ public class AST2CPPTests extends AST2BaseTest { IASTTranslationUnit tu = parse("void foo() { for(int i = 0; int j = 0; ++i) {} }", ParserLanguage.CPP); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - assertNoProblemBindings(col); + assertNoProblemBindings(col); } - // void f(){ - // if (int x = 1) x++; - // else x--; - // while(int y = 2) - // y++; - // for(int a = 1; int b = 2; b++){ - // a++; b++; - // } - // } + // void f(){ + // if (int x = 1) x++; + // else x--; + // while(int y = 2) + // y++; + // for(int a = 1; int b = 2; b++){ + // a++; b++; + // } + // } public void testBug84478_2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - assertNoProblemBindings(col); + assertNoProblemBindings(col); IVariable x = (IVariable) col.getName(1).resolveBinding(); assertSame(x, col.getName(2).resolveBinding()); assertSame(x, col.getName(3).resolveBinding()); @@ -5034,10 +5061,10 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(b, col.getName(10).resolveBinding()); } - // void free(void*); - // void f(char** p) { + // void free(void*); + // void f(char** p) { // free(p); - // } + // } public void testBug100415() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); CPPNameCollector col = new CPPNameCollector(); @@ -5047,17 +5074,17 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(free, col.getName(4).resolveBinding()); } - // class X; - // void f() { - // class A { - // friend class X; - // }; - // } - // namespace B { - // class A { - // friend class X; - // }; - // } + // class X; + // void f() { + // class A { + // friend class X; + // }; + // } + // namespace B { + // class A { + // friend class X; + // }; + // } public void testBug86688() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); CPPNameCollector col = new CPPNameCollector(); @@ -5069,10 +5096,10 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(X, col.getName(6).resolveBinding()); } - // class m { - // int m::f(); - // }; - // int m::f(){} + // class m { + // int m::f(); + // }; + // int m::f(){} public void testBug100403() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); CPPNameCollector col = new CPPNameCollector(); @@ -5082,16 +5109,16 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(f, col.getName(6).resolveBinding()); } - // struct A { - // typedef int AT; - // void f1(AT); - // void f2(float); - // }; - // struct B { - // typedef float BT; - // friend void A::f1(AT); - // friend void A::f2(BT); - // }; + // struct A { + // typedef int AT; + // void f1(AT); + // void f2(float); + // }; + // struct B { + // typedef float BT; + // friend void A::f1(AT); + // friend void A::f2(BT); + // }; public void testBug90609() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); CPPNameCollector col = new CPPNameCollector(); @@ -5108,13 +5135,13 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(BT, col.getName(17).resolveBinding()); } - // struct Except { int blah; }; - // void f() { - // try { } - // catch (Except * e) { - // e->blah; - // } - // } + // struct Except { int blah; }; + // void f() { + // try { } + // catch (Except * e) { + // e->blah; + // } + // } public void testBug103281() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); CPPNameCollector col = new CPPNameCollector(); @@ -5131,13 +5158,13 @@ public class AST2CPPTests extends AST2BaseTest { parseAndCheckBindings("class Matrix { public: Matrix & operator *(Matrix &); }; Matrix rotate, translate; Matrix transform = rotate * translate;"); //$NON-NLS-1$ } - // struct U { static int i; }; - // struct V : U { }; - // struct W : U { using U::i; }; - // struct X : V, W { void foo(); }; - // void X::foo() { - // i; - // } + // struct U { static int i; }; + // struct V : U { }; + // struct W : U { using U::i; }; + // struct X : V, W { void foo(); }; + // void X::foo() { + // i; + // } public void test10_2s3b() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); CPPNameCollector col = new CPPNameCollector(); @@ -5166,7 +5193,7 @@ public class AST2CPPTests extends AST2BaseTest { assertTrue(es.getExpression() instanceof IASTUnaryExpression); } - // int f() { + // int f() { // int i; // do { ++i; } while(i < 10); // return 0; @@ -5190,7 +5217,7 @@ public class AST2CPPTests extends AST2BaseTest { buffer.append("}\r\n"); //$NON-NLS-1$ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); - + buffer = new StringBuffer(); buffer.append("#define FUNC_PROTOTYPE_PARAMS(list) list\n"); //$NON-NLS-1$ buffer.append("int func1 FUNC_PROTOTYPE_PARAMS((int arg1)){\n"); //$NON-NLS-1$ @@ -5216,7 +5243,7 @@ public class AST2CPPTests extends AST2BaseTest { } - // // Test redundant class specifiers + // // Test redundant class specifiers // class MyClass { // int MyClass::field; // static int MyClass::static_field; @@ -5280,20 +5307,20 @@ public class AST2CPPTests extends AST2BaseTest { parse(getAboveComment(), ParserLanguage.CPP, true, true); } - // class A { - // double operator*(const A&); - // }; - // class B : public A { - // double operator*(double); - // using A::operator*; - // }; + // class A { + // double operator*(const A&); + // }; + // class B : public A { + // double operator*(double); + // using A::operator*; + // }; public void testBug178059() throws Exception { parse(getAboveComment(), ParserLanguage.CPP, true, true); } - // void foo (void *p) throw () ; - // void bar (void *p) __attribute__ ((__nonnull__(1))); - // void zot (void *p) throw () __attribute__ ((__nonnull__(1))); + // void foo (void *p) throw () ; + // void bar (void *p) __attribute__ ((__nonnull__(1))); + // void zot (void *p) throw () __attribute__ ((__nonnull__(1))); public void testBug179712() throws Exception { parse(getAboveComment(), ParserLanguage.CPP, true, true); } @@ -5475,8 +5502,8 @@ public class AST2CPPTests extends AST2BaseTest { // int * pBar = &bar; // Test foo1 (bar, &bar); // Test foo2 (bar, pBar); - // Test foo3 (&bar); - // } + // Test foo3 (&bar); + // } public void testCastAmbiguity_Bug211756() throws Exception { BindingAssertionHelper bh= getAssertionHelper(); @@ -5641,7 +5668,7 @@ public class AST2CPPTests extends AST2BaseTest { bh.assertProblem("ns::", 2); } - // void func() { + // void func() { // int a, b; // a < b || (a==b && a < b); // if (a > b) { @@ -5683,7 +5710,7 @@ public class AST2CPPTests extends AST2BaseTest { // foo/*b3*/(0x010U); // // /*c*/ /*d*/ - // + // // foo/*e1*/(1L); // foo/*e2*/(010L); // foo/*e3*/(0x010L); @@ -5785,24 +5812,24 @@ public class AST2CPPTests extends AST2BaseTest { // void* operator new (unsigned int, int[100]); // typedef int T; - // int p[100]; + // int p[100]; // void test(int f) { - // new T; + // new T; // new T(); // new T(f); - // new (p) T; + // new (p) T; // new (p) T(); // new (p) T(f); - // new (T); + // new (T); // new (T)(); // new (T)(f); - // new (p) (T); + // new (p) (T); // new (p) (T)(); // new (p) (T)(f); - // new T[f][f]; - // new (p) T[f][f]; - // new (T[f][f]); - // new (p) (T[f][f]); + // new T[f][f]; + // new (p) T[f][f]; + // new (T[f][f]); + // new (p) (T[f][f]); // }; public void testNewPlacement() throws Exception { IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment()); @@ -5852,7 +5879,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTProblemDeclaration pdecl= getDeclaration(ls, 1); assertEquals("+", pdecl.getRawSignature()); } - + // class C; // void func(void (C::*m)(int) const); public void test233889_a() throws Exception { @@ -5864,11 +5891,11 @@ public class AST2CPPTests extends AST2BaseTest { ICPPFunctionType t= ((ICPPFunctionType)ptm.getType()); assertTrue(t.isConst()); } - + // struct C { // int m1(int a); // int m2(int a) const; - // }; + // }; // // C* func(int (C::*m)(int) const); // C* func(int (C::*m)(int)); @@ -5883,7 +5910,7 @@ public class AST2CPPTests extends AST2BaseTest { ICPPFunction fn2= bh.assertNonProblem("func(&C::m2", 4, ICPPFunction.class); assertNotSame(fn1, fn2); } - + // class A; // // void foo(A* a) {} @@ -6035,7 +6062,7 @@ public class AST2CPPTests extends AST2BaseTest { // typedef char t2[8]; // typedef char* charp; // void test(charp x) {} - // int main(void) { + // int main(void) { // char x[12]; // t1 y; // t2 z; @@ -6069,7 +6096,7 @@ public class AST2CPPTests extends AST2BaseTest { // void test(char c) { // void (A::* ptr2mem)(char); // ptr2mem= reinterpret_cast(&A::m); - // ptr2mem= (void (A::*)(int))(0); + // ptr2mem= (void (A::*)(int))(0); // } public void testTypeIdForPtrToMember_Bug242197() throws Exception { parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); @@ -6303,7 +6330,7 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(decl, func); } } - + // class MyClass{ // public: // int v; @@ -6324,7 +6351,7 @@ public class AST2CPPTests extends AST2BaseTest { exstmt= getStatement(fdef, 1); assertInstance(exstmt.getExpression(), IASTBinaryExpression.class); } - + // template class A; // class A {}; // class A; @@ -6369,7 +6396,7 @@ public class AST2CPPTests extends AST2BaseTest { public void testVoidParamInDefinition_257376() throws Exception { parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); } - + // namespace ns { // struct C { // C(C* c){} @@ -6392,14 +6419,14 @@ public class AST2CPPTests extends AST2BaseTest { // void donothing(VOID){} // void donothing(VOID); // void test() { - // donothing(); + // donothing(); // } public void testVoidViaTypedef_Bug258694() throws Exception { parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); } // struct A { - // B method(B p, int& a = y) { // B is not defined + // B method(B p, int& a = y) { // B is not defined // B b; // int x = y + 1; // return b; @@ -6524,8 +6551,8 @@ public class AST2CPPTests extends AST2BaseTest { ba.assertNonProblem("a; //5", 1, ICPPField.class); ba.assertProblem("a; //6", 1); } - - + + // struct A { // int x; // }; @@ -6544,8 +6571,8 @@ public class AST2CPPTests extends AST2BaseTest { ba.assertNonProblem("x; //1", 1, ICPPField.class); ba.assertNonProblem("x; //2", 1, ICPPField.class); } - - + + // struct A { // int x; // }; @@ -6562,7 +6589,7 @@ public class AST2CPPTests extends AST2BaseTest { ba.assertNonProblem("x; //1", 1, ICPPField.class); ba.assertNonProblem("x; //2", 1, ICPPField.class); } - + // struct A { // int xx; @@ -6593,7 +6620,7 @@ public class AST2CPPTests extends AST2BaseTest { for(int i = 1; i <=6; i++) ba.assertNonProblem("xx; // "+i, 2, ICPPField.class); } - + // struct A { // int xx; // }; @@ -6624,9 +6651,9 @@ public class AST2CPPTests extends AST2BaseTest { for(int i = 1; i <=6; i++) ba.assertNonProblem("xx; // "+i, 2, ICPPField.class); } - - - + + + // int a,b,c,d ; // class X { // void m() { @@ -6663,10 +6690,10 @@ public class AST2CPPTests extends AST2BaseTest { // friend void g(int); // }; // }; - // void test() { + // void test() { // f(1); // g(1); - // } + // } // } public void testFriendFunctionResolution_86368_1() throws Exception { final String code= getAboveComment(); @@ -6723,7 +6750,7 @@ public class AST2CPPTests extends AST2BaseTest { g1= bh.assertNonProblem("f(char)", 1); assertSame(g1, g2); } - + // class A { // public: // void foo() const volatile; @@ -6761,7 +6788,7 @@ public class AST2CPPTests extends AST2BaseTest { ICPPFunctionType bar_v_ft= bar_v.getType(); ICPPFunctionType bar_c_ft= bar_c.getType(); ICPPFunctionType bar_ft= bar.getType(); - + assertTrue(bar_cv_ft.isConst()); assertTrue(bar_cv_ft.isVolatile()); assertTrue(!bar_v_ft.isConst()); assertTrue(bar_v_ft.isVolatile()); assertTrue(bar_c_ft.isConst()); assertTrue(!bar_c_ft.isVolatile()); @@ -6775,13 +6802,13 @@ public class AST2CPPTests extends AST2BaseTest { bar_v_ft= bar_v.getType(); bar_c_ft= bar_c.getType(); bar_ft= bar.getType(); - + assertTrue(bar_cv_ft.isConst()); assertTrue(bar_cv_ft.isVolatile()); assertTrue(!bar_v_ft.isConst()); assertTrue(bar_v_ft.isVolatile()); assertTrue(bar_c_ft.isConst()); assertTrue(!bar_c_ft.isVolatile()); assertTrue(!bar_ft.isConst()); assertTrue(!bar_ft.isVolatile()); } - + // void test1(float f); // void test1(void); // void blabla() { @@ -6803,11 +6830,11 @@ public class AST2CPPTests extends AST2BaseTest { // typedef int TInt; // void select(int); // void test() { - // int a= TInt(1); + // int a= TInt(1); // E e= E(0); // void* h; // select (int (h) + 1); - // } + // } public void testSimpleTypeConstructorExpressions() throws Exception { final String code= getAboveComment(); parseAndCheckBindings(code); @@ -7199,7 +7226,7 @@ public class AST2CPPTests extends AST2BaseTest { // foo(L'a'); // } public void testWideCharacterLiteralTypes_Bug270892() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -7483,9 +7510,9 @@ public class AST2CPPTests extends AST2BaseTest { } // class X { - // struct S* m1; + // struct S* m1; // struct T; - // struct T* m2; + // struct T* m2; // }; public void testStructOwner_290693() throws Exception { final String code = getAboveComment(); @@ -7503,8 +7530,8 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(X, T.getOwner()); } - // class ULONGLONG { - // public : + // class ULONGLONG { + // public : // ULONGLONG (unsigned long long val) {} // friend ULONGLONG operator ~ (const ULONGLONG &) { return 0; } // }; @@ -7666,7 +7693,7 @@ public class AST2CPPTests extends AST2BaseTest { // void f(ns::E e) {} // void test() { // f(ns::e1); - // f(ns::e1 | ns::e2); // the operator| needs to be looked up in the + // f(ns::e1 | ns::e2); // the operator| needs to be looked up in the // // associated namespace. // } public void testAssociatedScopesForOverloadedOperators_293589() throws Exception { @@ -7689,7 +7716,7 @@ public class AST2CPPTests extends AST2BaseTest { ICPPFunctionTemplate template= bh.assertNonProblem("functionTemplate", 16); assertNotNull(template.getType()); assertEquals(1, template.getParameters().length); - + ICPPMethod method= bh.assertNonProblem("method", 6); assertNotNull(method.getType()); assertEquals(1, method.getParameters().length); @@ -7715,7 +7742,7 @@ public class AST2CPPTests extends AST2BaseTest { // x(""); // Array a; // xx(&a); - // f(""); + // f(""); // } public void testCVQualifiersWithArrays_293982() throws Exception { final String code = getAboveComment(); @@ -7800,18 +7827,18 @@ public class AST2CPPTests extends AST2BaseTest { } // struct A {}; - // + // // void foo(const A&); // #1 // void foo(A&&); // #2 - // + // // A source_rvalue(); // A& source_ref(); // A&& source_rvalue_ref(); - // + // // const A source_const_rvalue(); // const A& source_const_ref(); // const A&& source_const_rvalue_ref(); - // + // // int main() { // A a; // A& ra = a; @@ -7819,7 +7846,7 @@ public class AST2CPPTests extends AST2BaseTest { // const A ca; // const A& rca = ca; // const A&& rrca = ca; - // + // // foo(a); // #1 // foo(ra); // #1 // foo(rra); // #1 @@ -7907,7 +7934,7 @@ public class AST2CPPTests extends AST2BaseTest { // double d = 2.0; // const volatile double cvd = 1; // int i = 2; - // dref(d); + // dref(d); // cdref(d); // aref(b); // caref(b); @@ -8278,7 +8305,7 @@ public class AST2CPPTests extends AST2BaseTest { // h({'a'}); // OK: same conversion as char to int // h({1.0}); // error: narrowing // h({ }); // OK: identity conversion - // } + // } public void testListInitialization_302412e() throws Exception { String code= getAboveComment(); BindingAssertionHelper bh= new BindingAssertionHelper(code, true); @@ -8461,9 +8488,9 @@ public class AST2CPPTests extends AST2BaseTest { } // enum class E { a, b }; - // enum E x1 = E::a; // OK + // enum E x1 = E::a; // OK // enum F { a, b }; - // enum F y1 = a; // OK + // enum F y1 = a; // OK // enum E1 : int; // OK: E1 is un-scoped, underlying type is int // enum class F1; // OK: F1 is scoped, underlying type is int public void testScopedEnums_305975b() throws Exception { @@ -8472,7 +8499,7 @@ public class AST2CPPTests extends AST2BaseTest { } // enum class E x2 = E::a; // illegal (elaborated type specifier) - // enum class F y2 = a; // illegal + // enum class F y2 = a; // illegal // enum E; // illegal public void testScopedEnums_305975c() throws Exception { String code= getAboveComment(); @@ -8484,11 +8511,11 @@ public class AST2CPPTests extends AST2BaseTest { assertInstance(decls[2], IASTProblemDeclaration.class); } - // enum class Col { red, yellow, green }; + // enum class Col { red, yellow, green }; // void fint(int); // void fbool(bool); // void fCol(Col); - // + // // void test() { // fCol(Col::red); // fint(Col::red); // error: no conversion to int @@ -8510,29 +8537,29 @@ public class AST2CPPTests extends AST2BaseTest { // d = direction::right; // OK // } // - // enum class altitude { high=1, low=2 }; + // enum class altitude { high=1, low=2 }; // void h() { // altitude a; // OK // a = altitude::low; // OK // } // // struct X { - // enum xdir { xl=1, xr=2 }; + // enum xdir { xl=1, xr=2 }; // int f(int i) { return i==xl ? 0 : i==xr ? 1 : 2; } // }; // void g(X* p) { // int i; - // i = p->f(X::xr); // OK - // i = p->f(p->xl); // OK + // i = p->f(X::xr); // OK + // i = p->f(p->xl); // OK // } public void testScopedEnums_305975e() throws Exception { String code= getAboveComment(); parseAndCheckBindings(code); } - // enum class altitude { high=1, low=2 }; + // enum class altitude { high=1, low=2 }; // struct X { - // enum xdir { xl=1, xr=2 }; + // enum xdir { xl=1, xr=2 }; // int f(int i) { return i==xl ? 0 : i==xr ? 1 : 2; } // }; // void g(X* p) { @@ -8983,7 +9010,7 @@ public class AST2CPPTests extends AST2BaseTest { // void test() { // f(); // xvalue // f().m; // xvalue - // static_cast(a); // xvalue + // static_cast(a); // xvalue // a+a; // xvalue // ar; // rvalue // } @@ -9080,7 +9107,7 @@ public class AST2CPPTests extends AST2BaseTest { // } // int i; // } - // int j = A::i; + // int j = A::i; public void testInlineNamespaceLookup_324096() throws Exception { parseAndCheckBindings(); } @@ -9117,7 +9144,7 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(fc, ref); ref= bh.assertNonProblem("f(0 ? p : \"\")", 1); // "" converted to char* assertSame(fc, ref); - bh.assertNonProblem("g(0 ? p : \"\")", 1); // + bh.assertNonProblem("g(0 ? p : \"\")", 1); // } // struct C { @@ -9303,7 +9330,7 @@ public class AST2CPPTests extends AST2BaseTest { // S arr[5]; // std::pair p{arr, arr + 5}; // for (const auto& r : p) - // r.x; + // r.x; // } public void testAutoTypeInRangeBasedFor_332883c() throws Exception { parseAndCheckBindings(); @@ -9485,8 +9512,8 @@ public class AST2CPPTests extends AST2BaseTest { // void (g)(int); //2 public void testFunctionRedeclarations() throws Exception { BindingAssertionHelper bh= getAssertionHelper(); - IFunction g1= bh.assertNonProblem("g)(char)", 1); - IFunction g2= bh.assertNonProblem("g)(int); //1", 1); + IFunction g1= bh.assertNonProblem("g)(char)", 1); + IFunction g2= bh.assertNonProblem("g)(int); //1", 1); IFunction g3= bh.assertNonProblem("g)(int); //2", 1); assertNotSame(g1, g2); assertSame(g2, g3); @@ -9579,7 +9606,7 @@ public class AST2CPPTests extends AST2BaseTest { // } public void testModeAttribute_330635() throws Exception { BindingAssertionHelper bh= getAssertionHelper(); - String[] calls = { "f(i8)", "f(i16)", "f(i32)", "f(i64)", "f(word)" }; + String[] calls = { "f(i8)", "f(i16)", "f(i32)", "f(i64)", "f(word)" }; ICPPFunction[] functions = new ICPPFunction[calls.length]; for (int i = 0; i < calls.length; i++) { functions[i] = bh.assertNonProblem(calls[i], 1, ICPPFunction.class); @@ -9593,7 +9620,7 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(calls[calls.length - 1] + " and " + calls[calls.length - 2] + " resolve to different functions", functions[calls.length - 1], functions[calls.length - 2]); } - + // void f(int x) try { // } catch(...) { // (void)x; @@ -9601,7 +9628,7 @@ public class AST2CPPTests extends AST2BaseTest { public void testParentScopeOfCatchHandler_376246() throws Exception { parseAndCheckBindings(); } - + // struct MyClass { // struct MyException {}; // void doSomething() throw(MyException); @@ -9649,7 +9676,7 @@ public class AST2CPPTests extends AST2BaseTest { public void testNullptr_327298a() throws Exception { parseAndCheckBindings(); } - + // namespace std { // typedef decltype(nullptr) nullptr_t; // } @@ -9670,7 +9697,7 @@ public class AST2CPPTests extends AST2BaseTest { bh.assertProblem("checklvalue(nullptr)", 11); bh.assertProblem("g( nullptr )", 1); } - + // void f( char* ); // void f( int ); // void test2() { @@ -9684,7 +9711,7 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals("void (char *)", ASTTypeUtil.getType(f.getType())); f= bh.assertNonProblem("f( 0 )", 1); assertEquals("void (int)", ASTTypeUtil.getType(f.getType())); - } + } // void foo(struct S s); public void testParameterForwardDeclaration_379511() throws Exception { 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 6d25bb28016..d76d3e9fbdf 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 @@ -6,9 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Doug Schaefer (IBM) - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Andrew Ferguson (Symbian) + * Doug Schaefer (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -127,17 +128,16 @@ import org.eclipse.cdt.internal.core.parser.ParserException; * Testcases on the AST. */ public class AST2Tests extends AST2BaseTest { - private static final int NUM_TESTS = 3; - + public static TestSuite suite() { return suite(AST2Tests.class); } - + public AST2Tests() { super(); } - + public AST2Tests(String name) { super(name); } @@ -151,18 +151,18 @@ public class AST2Tests extends AST2BaseTest { protected IASTTranslationUnit parseAndCheckBindings(String code) throws Exception { return parseAndCheckBindings(code, ParserLanguage.C); } - + public void testBug75189() throws Exception { parseAndCheckBindings("struct A{};\n typedef int (*F) (struct A*);"); //$NON-NLS-1$ parseAndCheckBindings("struct A{};\n typedef int (*F) (A*);", ParserLanguage.CPP); //$NON-NLS-1$ } - + public void testBug75340() throws Exception { IASTTranslationUnit tu = parseAndCheckBindings("void f(int i = 0, int * p = 0);", ParserLanguage.CPP); //$NON-NLS-1$ IASTSimpleDeclaration sd = (IASTSimpleDeclaration) tu.getDeclarations()[0]; isParameterSignatureEqual(sd.getDeclarators()[0], "(int=0, int*=0)"); //$NON-NLS-1$ } - + // int *p1; int *p2; // union { // struct {int a; int b;} A; @@ -176,7 +176,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug78103() throws Exception { parseAndCheckBindings(getAboveComment()); } - + // int m(int); // int (*pm)(int) = &m; // int f(int); @@ -184,18 +184,18 @@ public class AST2Tests extends AST2BaseTest { public void testBug43241() throws Exception { parseAndCheckBindings(getAboveComment()); } - + // int *zzz1 (char); - // int (*zzz2) (char); - // int ((*zzz3)) (char); - // int (*(zzz4)) (char); + // int (*zzz2) (char); + // int ((*zzz3)) (char); + // int (*(zzz4)) (char); public void testBug40768() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); CNameCollector col = new CNameCollector(); tu.accept(col); assertNoProblemBindings(col); } - + // int x; // void f(int y) { // int z = x + y; @@ -205,9 +205,9 @@ public class AST2Tests extends AST2BaseTest { assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IScope globalScope = tu.getScope(); - + IASTDeclaration[] declarations = tu.getDeclarations(); - + // int x IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) declarations[0]; IASTSimpleDeclSpecifier declspec_x = (IASTSimpleDeclSpecifier) decl_x.getDeclSpecifier(); @@ -215,7 +215,7 @@ public class AST2Tests extends AST2BaseTest { IASTDeclarator declor_x = decl_x.getDeclarators()[0]; IASTName name_x = declor_x.getName(); assertEquals("x", name_x.toString()); //$NON-NLS-1$ - + // function - void f() IASTFunctionDefinition funcdef_f = (IASTFunctionDefinition) declarations[1]; IASTSimpleDeclSpecifier declspec_f = (IASTSimpleDeclSpecifier) funcdef_f @@ -224,7 +224,7 @@ public class AST2Tests extends AST2BaseTest { IASTFunctionDeclarator declor_f = funcdef_f.getDeclarator(); IASTName name_f = declor_f.getName(); assertEquals("f", name_f.toString()); //$NON-NLS-1$ - + // parameter - int y assertTrue(declor_f instanceof IASTStandardFunctionDeclarator); IASTParameterDeclaration decl_y = ((IASTStandardFunctionDeclarator) declor_f) @@ -235,7 +235,7 @@ public class AST2Tests extends AST2BaseTest { IASTDeclarator declor_y = decl_y.getDeclarator(); IASTName name_y = declor_y.getName(); assertEquals("y", name_y.toString()); //$NON-NLS-1$ - + // int z IASTCompoundStatement body_f = (IASTCompoundStatement) funcdef_f .getBody(); @@ -249,7 +249,7 @@ public class AST2Tests extends AST2BaseTest { IASTDeclarator declor_z = decl_z.getDeclarators()[0]; IASTName name_z = declor_z.getName(); assertEquals("z", name_z.toString()); //$NON-NLS-1$ - + // = x + y IASTEqualsInitializer initializer = (IASTEqualsInitializer) declor_z.getInitializer(); IASTBinaryExpression init_z = (IASTBinaryExpression) initializer.getInitializerClause(); @@ -257,11 +257,11 @@ public class AST2Tests extends AST2BaseTest { IASTIdExpression ref_x = (IASTIdExpression) init_z.getOperand1(); IASTName name_ref_x = ref_x.getName(); assertEquals("x", name_ref_x.toString()); //$NON-NLS-1$ - + IASTIdExpression ref_y = (IASTIdExpression) init_z.getOperand2(); IASTName name_ref_y = ref_y.getName(); assertEquals("y", name_ref_y.toString()); //$NON-NLS-1$ - + // BINDINGS // resolve the binding to get the variable object IVariable var_x = (IVariable) name_x.resolveBinding(); @@ -271,39 +271,39 @@ public class AST2Tests extends AST2BaseTest { IParameter var_y = (IParameter) name_y.resolveBinding(); assertEquals(((IASTCompoundStatement) funcdef_f.getBody()).getScope(), var_y.getScope()); - + IVariable var_z = (IVariable) name_z.resolveBinding(); assertEquals(((ICFunctionScope) func_f.getFunctionScope()).getBodyScope(), var_z.getScope()); - + // make sure the variable referenced is the same one we declared above assertEquals(var_x, name_ref_x.resolveBinding()); assertEquals(var_y, name_ref_y.resolveBinding()); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(name_x.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_x); - + decls = tu.getDeclarationsInAST(name_f.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_f); - + decls = tu.getDeclarationsInAST(name_y.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_y); - + decls = tu.getDeclarationsInAST(name_z.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_z); - + decls = tu.getDeclarationsInAST(name_ref_x.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_x); - + decls = tu.getDeclarationsInAST(name_ref_y.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_y); - + // // test clearBindings // assertNotNull(((ICScope) tu.getScope()).getBinding( // ICScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); @@ -330,11 +330,11 @@ public class AST2Tests extends AST2BaseTest { // assertNull(((ICScope) body_f.getScope()).getBinding( // ICScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray())); // //$NON-NLS-1$ - + tu = validateCopy(tu); } } - + // typedef struct { // int x; // } S; @@ -351,7 +351,7 @@ public class AST2Tests extends AST2BaseTest { .getDeclarations()[0]; IASTCompositeTypeSpecifier type = (IASTCompositeTypeSpecifier) decl .getDeclSpecifier(); - + // it's a typedef assertEquals(IASTDeclSpecifier.sc_typedef, type.getStorageClass()); // this an anonymous struct @@ -369,12 +369,12 @@ public class AST2Tests extends AST2BaseTest { IASTDeclarator tor_x = decl_x.getDeclarators()[0]; IASTName name_x = tor_x.getName(); assertEquals("x", name_x.toString()); //$NON-NLS-1$ - + // declarator S IASTDeclarator tor_S = decl.getDeclarators()[0]; IASTName name_S = tor_S.getName(); assertEquals("S", name_S.toString()); //$NON-NLS-1$ - + // function f IASTFunctionDefinition def_f = (IASTFunctionDefinition) tu .getDeclarations()[1]; @@ -408,7 +408,7 @@ public class AST2Tests extends AST2BaseTest { IASTIdExpression ref_myS = (IASTIdExpression) fieldref.getFieldOwner(); IASTLiteralExpression lit_5 = (IASTLiteralExpression) assexpr.getOperand2(); assertEquals("5", lit_5.toString()); //$NON-NLS-1$ - + // Logical Bindings In Test ICompositeType type_struct = (ICompositeType) name_struct.resolveBinding(); ITypedef typedef_S = (ITypedef) name_S.resolveBinding(); @@ -426,40 +426,40 @@ public class AST2Tests extends AST2BaseTest { assertEquals(var_myS, ref_myS.getName().resolveBinding()); IField field_x = (IField) name_x.resolveBinding(); assertEquals(field_x, fieldref.getFieldName().resolveBinding()); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(name_struct.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_struct); - + decls = tu.getDeclarationsInAST(name_x.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_x); - + decls = tu.getDeclarationsInAST(def_f.getDeclarator().getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], def_f.getDeclarator().getName()); - + decls = tu.getDeclarationsInAST(name_S.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_S); - + decls = tu.getDeclarationsInAST(name_myS.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_myS); - + decls = tu.getDeclarationsInAST(ref_myS.getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_myS); - + decls = tu.getDeclarationsInAST(fieldref.getFieldName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_x); - + tu = validateCopy(tu); } } - + public void testCExpressions() throws ParserException { validateSimpleUnaryExpressionC("++x", IASTUnaryExpression.op_prefixIncr); //$NON-NLS-1$ validateSimpleUnaryExpressionC("--x", IASTUnaryExpression.op_prefixDecr); //$NON-NLS-1$ @@ -528,7 +528,7 @@ public class AST2Tests extends AST2BaseTest { "x||y", IASTBinaryExpression.op_logicalOr); //$NON-NLS-1$ validateConditionalExpressionC("x ? y : x"); //$NON-NLS-1$ } - + public void testMultipleDeclarators() throws Exception { IASTTranslationUnit tu = parse("int r, s;", ParserLanguage.C); //$NON-NLS-1$ assertTrue(tu.isFrozen()); @@ -536,30 +536,30 @@ public class AST2Tests extends AST2BaseTest { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTDeclarator[] declarators = decl.getDeclarators(); assertEquals(2, declarators.length); - + IASTDeclarator dtor1 = declarators[0]; IASTDeclarator dtor2 = declarators[1]; - + IASTName name1 = dtor1.getName(); IASTName name2 = dtor2.getName(); - + assertEquals(name1.resolveBinding().getName(), "r"); //$NON-NLS-1$ assertEquals(name2.resolveBinding().getName(), "s"); //$NON-NLS-1$ - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(name1.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name1); - + decls = tu.getDeclarationsInAST(name2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name2); - + tu = validateCopy(tu); } } - - + + public void testStructureTagScoping_1() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("struct A; \n"); //$NON-NLS-1$ @@ -567,9 +567,9 @@ public class AST2Tests extends AST2BaseTest { buffer.append(" struct A; \n"); //$NON-NLS-1$ buffer.append(" struct A * a; \n"); //$NON-NLS-1$ buffer.append("} \n"); //$NON-NLS-1$ - + IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); - + assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { // struct A; @@ -578,19 +578,19 @@ public class AST2Tests extends AST2BaseTest { IASTElaboratedTypeSpecifier compTypeSpec = (IASTElaboratedTypeSpecifier) decl1.getDeclSpecifier(); assertEquals(0, decl1.getDeclarators().length); IASTName nameA1 = compTypeSpec.getName(); - + // void f() { IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations()[1]; IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody(); assertEquals(2, compoundStatement.getStatements().length); - + // struct A; IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compoundStatement.getStatements()[0]; IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) declStatement.getDeclaration(); compTypeSpec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier(); assertEquals(0, decl2.getDeclarators().length); IASTName nameA2 = compTypeSpec.getName(); - + // struct A * a; declStatement = (IASTDeclarationStatement) compoundStatement.getStatements()[1]; IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) declStatement.getDeclaration(); @@ -600,7 +600,7 @@ public class AST2Tests extends AST2BaseTest { IASTName namea = dtor.getName(); assertEquals(1, dtor.getPointerOperators().length); assertTrue(dtor.getPointerOperators()[0] instanceof ICASTPointer); - + // bindings ICompositeType str1 = (ICompositeType) nameA1.resolveBinding(); ICompositeType str2 = (ICompositeType) nameA2.resolveBinding(); @@ -614,41 +614,41 @@ public class AST2Tests extends AST2BaseTest { assertNotSame(str1, str2); assertSame(str2, str3); assertSame(str3, str4); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(nameA1.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], nameA1); - + decls = tu.getDeclarationsInAST(fndef.getDeclarator().getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], fndef.getDeclarator().getName()); - + decls = tu.getDeclarationsInAST(nameA2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], nameA2); - + decls = tu.getDeclarationsInAST(nameA3.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], nameA2); - + decls = tu.getDeclarationsInAST(namea.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], namea); - + tu = validateCopy(tu); } } - + public void testStructureTagScoping_2() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("struct A; \n"); //$NON-NLS-1$ buffer.append("void f() { \n"); //$NON-NLS-1$ buffer.append(" struct A * a; \n"); //$NON-NLS-1$ buffer.append("} \r\n"); //$NON-NLS-1$ - + IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); - + assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { // struct A; @@ -656,12 +656,12 @@ public class AST2Tests extends AST2BaseTest { IASTElaboratedTypeSpecifier compTypeSpec = (IASTElaboratedTypeSpecifier) decl1.getDeclSpecifier(); assertEquals(0, decl1.getDeclarators().length); IASTName nameA1 = compTypeSpec.getName(); - + // void f() { IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations()[1]; IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody(); assertEquals(1, compoundStatement.getStatements().length); - + // struct A * a; IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compoundStatement.getStatements()[0]; IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) declStatement.getDeclaration(); @@ -671,7 +671,7 @@ public class AST2Tests extends AST2BaseTest { IASTName namea = dtor.getName(); assertEquals(1, dtor.getPointerOperators().length); assertTrue(dtor.getPointerOperators()[0] instanceof ICASTPointer); - + // bindings ICompositeType str1 = (ICompositeType) nameA1.resolveBinding(); ICompositeType str2 = (ICompositeType) nameA2.resolveBinding(); @@ -681,28 +681,28 @@ public class AST2Tests extends AST2BaseTest { assertNotNull(str1); assertSame(str1, str2); assertSame(str2, str3); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(nameA1.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], nameA1); - + decls = tu.getDeclarationsInAST(fndef.getDeclarator().getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], fndef.getDeclarator().getName()); - + decls = tu.getDeclarationsInAST(nameA2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], nameA1); - + decls = tu.getDeclarationsInAST(namea.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], namea); - + tu = validateCopy(tu); } } - + public void testStructureDef() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("struct A; \r\n"); //$NON-NLS-1$ @@ -711,9 +711,9 @@ public class AST2Tests extends AST2BaseTest { buffer.append("void f() { \n"); //$NON-NLS-1$ buffer.append(" a->i; \n"); //$NON-NLS-1$ buffer.append("} \n"); //$NON-NLS-1$ - + IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); - + assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { // struct A; @@ -721,7 +721,7 @@ public class AST2Tests extends AST2BaseTest { IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) decl1.getDeclSpecifier(); assertEquals(0, decl1.getDeclarators().length); IASTName name_A1 = elabTypeSpec.getName(); - + // struct A * a; IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu.getDeclarations()[1]; elabTypeSpec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier(); @@ -730,30 +730,30 @@ public class AST2Tests extends AST2BaseTest { IASTName name_a = dtor.getName(); assertEquals(1, dtor.getPointerOperators().length); assertTrue(dtor.getPointerOperators()[0] instanceof ICASTPointer); - + // struct A { IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) tu.getDeclarations()[2]; ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) decl3.getDeclSpecifier(); IASTName name_Adef = compTypeSpec.getName(); - + // int i; IASTSimpleDeclaration decl4 = (IASTSimpleDeclaration) compTypeSpec .getMembers()[0]; dtor = decl4.getDeclarators()[0]; IASTName name_i = dtor.getName(); - + // void f() { IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations()[3]; IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody(); assertEquals(1, compoundStatement.getStatements().length); - + // a->i; IASTExpressionStatement exprstmt = (IASTExpressionStatement) compoundStatement.getStatements()[0]; IASTFieldReference fieldref = (IASTFieldReference) exprstmt.getExpression(); IASTIdExpression id_a = (IASTIdExpression) fieldref.getFieldOwner(); IASTName name_aref = id_a.getName(); IASTName name_iref = fieldref.getFieldName(); - + // bindings IVariable var_a1 = (IVariable) name_aref.resolveBinding(); IVariable var_i1 = (IVariable) name_iref.resolveBinding(); @@ -762,114 +762,114 @@ public class AST2Tests extends AST2BaseTest { ICompositeType structA_2 = (ICompositeType) name_A1.resolveBinding(); ICompositeType structA_3 = (ICompositeType) name_A2.resolveBinding(); ICompositeType structA_4 = (ICompositeType) name_Adef.resolveBinding(); - + IVariable var_a2 = (IVariable) name_a.resolveBinding(); IVariable var_i2 = (IVariable) name_i.resolveBinding(); - + assertSame(var_a1, var_a2); assertSame(var_i1, var_i2); assertSame(structA_1, structA_2); assertSame(structA_2, structA_3); assertSame(structA_3, structA_4); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(name_A1.resolveBinding()); assertEquals(decls.length, 2); assertEquals(decls[0], name_A1); assertEquals(decls[1], name_Adef); - + decls = tu.getDeclarationsInAST(name_A2.resolveBinding()); assertEquals(decls.length, 2); assertEquals(decls[0], name_A1); assertEquals(decls[1], name_Adef); - + decls = tu.getDeclarationsInAST(name_a.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_a); - + decls = tu.getDeclarationsInAST(name_Adef.resolveBinding()); assertEquals(decls.length, 2); assertEquals(decls[0], name_A1); assertEquals(decls[1], name_Adef); - + decls = tu.getDeclarationsInAST(name_i.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_i); - + decls = tu.getDeclarationsInAST(fndef.getDeclarator().getName() .resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], fndef.getDeclarator().getName()); - + decls = tu.getDeclarationsInAST(name_aref.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_a); - + decls = tu.getDeclarationsInAST(name_iref.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_i); - + tu = validateCopy(tu); } } - - // struct x {}; - // void f(int x) { - // struct x i; - // } + + // struct x {}; + // void f(int x) { + // struct x i; + // } public void testStructureNamespace() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); - + assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration declaration1 = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTCompositeTypeSpecifier typeSpec = (IASTCompositeTypeSpecifier) declaration1.getDeclSpecifier(); IASTName x_1 = typeSpec.getName(); - + IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[1]; assertTrue(fdef.getDeclarator() instanceof IASTStandardFunctionDeclarator); IASTParameterDeclaration param = ((IASTStandardFunctionDeclarator) fdef.getDeclarator()).getParameters()[0]; IASTName x_2 = param.getDeclarator().getName(); - + IASTCompoundStatement compound = (IASTCompoundStatement) fdef.getBody(); IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compound.getStatements()[0]; IASTSimpleDeclaration declaration2 = (IASTSimpleDeclaration) declStatement.getDeclaration(); IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier) declaration2.getDeclSpecifier(); IASTName x_3 = elab.getName(); - + ICompositeType x1 = (ICompositeType) x_1.resolveBinding(); IVariable x2 = (IVariable) x_2.resolveBinding(); ICompositeType x3 = (ICompositeType) x_3.resolveBinding(); - + assertNotNull(x1); assertNotNull(x2); assertSame(x1, x3); assertNotSame(x2, x3); - + IASTDeclarator decl_i = declaration2.getDeclarators()[0]; decl_i.getName().resolveBinding(); // add i's binding to the scope - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(x_1.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], x_1); - + decls = tu.getDeclarationsInAST(fdef.getDeclarator().getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], fdef.getDeclarator().getName()); - + decls = tu.getDeclarationsInAST(x_2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], x_2); - + decls = tu.getDeclarationsInAST(x_3.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], x_1); - + decls = tu.getDeclarationsInAST(declaration2.getDeclarators()[0].getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], declaration2.getDeclarators()[0].getName()); - + // assertNotNull(((ICScope) tu.getScope()).getBinding( // ICScope.NAMESPACE_TYPE_TAG, new String("x").toCharArray())); // //$NON-NLS-1$ @@ -895,19 +895,19 @@ public class AST2Tests extends AST2BaseTest { // assertNull(((ICScope) compound.getScope()).getBinding( // ICScope.NAMESPACE_TYPE_OTHER, new String("i").toCharArray())); // //$NON-NLS-1$ - + tu = validateCopy(tu); } } - - // void f(int a); - // void f(int b) { - // b; - // } + + // void f(int a); + // void f(int b) { + // b; + // } public void testFunctionParameters() throws Exception { final String code = getAboveComment(); IASTTranslationUnit tu = parse(code, ParserLanguage.C); - + assertTrue(tu.isFrozen()); // void f( IASTSimpleDeclaration f_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -1008,7 +1008,7 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } - + // void f(int a, int b) { } public void testSimpleFunction() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); @@ -1018,61 +1018,61 @@ public class AST2Tests extends AST2BaseTest { assertTrue(fDef.getDeclarator() instanceof IASTStandardFunctionDeclarator); IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) fDef.getDeclarator(); IASTName fName = fDtor.getName(); - + IASTParameterDeclaration a = fDtor.getParameters()[0]; IASTName name_a = a.getDeclarator().getName(); - + IASTParameterDeclaration b = fDtor.getParameters()[1]; IASTName name_b = b.getDeclarator().getName(); - + IFunction function = (IFunction) fName.resolveBinding(); IParameter param_a = (IParameter) name_a.resolveBinding(); IParameter param_b = (IParameter) name_b.resolveBinding(); - + assertEquals("f", function.getName()); //$NON-NLS-1$ assertEquals("a", param_a.getName()); //$NON-NLS-1$ assertEquals("b", param_b.getName()); //$NON-NLS-1$ - + IParameter[] params = function.getParameters(); assertEquals(2, params.length); assertSame(params[0], param_a); assertSame(params[1], param_b); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(fName.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], fName); - + decls = tu.getDeclarationsInAST(name_a.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_a); - + decls = tu.getDeclarationsInAST(name_b.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_b); - + tu = validateCopy(tu); } } - - // void f(); - // void g() { - // f(); - // } - // void f() { } + + // void f(); + // void g() { + // f(); + // } + // void f() { } public void testSimpleFunctionCall() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); - + assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { // void f(); IASTSimpleDeclaration fdecl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) fdecl.getDeclarators()[0]; IASTName name_f = fdtor.getName(); - + // void g() { IASTFunctionDefinition gdef = (IASTFunctionDefinition) tu.getDeclarations()[1]; - + // f(); IASTCompoundStatement compound = (IASTCompoundStatement) gdef.getBody(); IASTExpressionStatement expStatement = (IASTExpressionStatement) compound @@ -1083,38 +1083,38 @@ public class AST2Tests extends AST2BaseTest { .getFunctionNameExpression(); IASTName name_fcall = fcall_id.getName(); assertNull(fcall.getParameterExpression()); - + // void f() {} IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[2]; assertTrue(fdef.getDeclarator() instanceof IASTStandardFunctionDeclarator); fdtor = (IASTStandardFunctionDeclarator) fdef.getDeclarator(); IASTName name_fdef = fdtor.getName(); - + // bindings IFunction function_1 = (IFunction) name_fcall.resolveBinding(); IFunction function_2 = (IFunction) name_f.resolveBinding(); IFunction function_3 = (IFunction) name_fdef.resolveBinding(); - + assertNotNull(function_1); assertSame(function_1, function_2); assertSame(function_2, function_3); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(name_f.resolveBinding()); assertEquals(decls.length, 2); assertEquals(decls[0], name_f); assertEquals(decls[1], name_fdef); - + decls = tu.getDeclarationsInAST(gdef.getDeclarator().getName() .resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], gdef.getDeclarator().getName()); - + decls = tu.getDeclarationsInAST(name_fcall.resolveBinding()); assertEquals(decls.length, 2); assertEquals(decls[0], name_f); assertEquals(decls[1], name_fdef); - + decls = tu.getDeclarationsInAST(name_fdef.resolveBinding()); assertEquals(decls.length, 2); assertEquals(decls[0], name_f); @@ -1123,12 +1123,12 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - - // void f() { - // for (int i = 0; i < 5; i++) { - // i; - // } - // } + + // void f() { + // for (int i = 0; i < 5; i++) { + // i; + // } + // } public void testForLoop() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); assertTrue(tu.isFrozen()); @@ -1136,11 +1136,11 @@ public class AST2Tests extends AST2BaseTest { // void f() { IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations()[0]; IASTCompoundStatement compound = (IASTCompoundStatement) fdef.getBody(); - + // for( IASTForStatement for_stmt = (IASTForStatement) compound.getStatements()[0]; // int i = 0; - + IASTSimpleDeclaration initDecl = (IASTSimpleDeclaration) ((IASTDeclarationStatement) for_stmt .getInitializerStatement()).getDeclaration(); IASTDeclarator dtor = initDecl.getDeclarators()[0]; @@ -1156,41 +1156,41 @@ public class AST2Tests extends AST2BaseTest { IASTIdExpression id_i2 = (IASTIdExpression) un.getOperand(); IASTName name_i3 = id_i2.getName(); assertEquals(IASTUnaryExpression.op_postFixIncr, un.getOperator()); - + // i; compound = (IASTCompoundStatement) for_stmt.getBody(); IASTExpressionStatement exprSt = (IASTExpressionStatement) compound.getStatements()[0]; IASTIdExpression id_i3 = (IASTIdExpression) exprSt.getExpression(); IASTName name_i4 = id_i3.getName(); - + // bindings IVariable var_1 = (IVariable) name_i4.resolveBinding(); IVariable var_2 = (IVariable) name_i.resolveBinding(); IVariable var_3 = (IVariable) name_i2.resolveBinding(); IVariable var_4 = (IVariable) name_i3.resolveBinding(); - + assertSame(var_1, var_2); assertSame(var_2, var_3); assertSame(var_3, var_4); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(fdef.getDeclarator().getName() .resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], fdef.getDeclarator().getName()); - + decls = tu.getDeclarationsInAST(name_i.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_i); - + decls = tu.getDeclarationsInAST(name_i2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_i); - + decls = tu.getDeclarationsInAST(name_i3.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_i); - + decls = tu.getDeclarationsInAST(name_i4.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_i); @@ -1198,11 +1198,11 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - - // struct A { int x; }; - // void f() { - // ((struct A *) 1)->x; - // } + + // struct A { int x; }; + // void f() { + // ((struct A *) 1)->x; + // } public void testExpressionFieldReference() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); assertTrue(tu.isFrozen()); @@ -1250,21 +1250,21 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - - // void f() { - // while (1) { - // if (1) - // goto end; - // } - // end: ; - // } + + // void f() { + // while (1) { + // if (1) + // goto end; + // } + // end: ; + // } public void testLabels() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector collector = new CNameCollector(); tu.accept(collector); - + assertEquals(collector.size(), 3); IFunction function = (IFunction) collector.getName(0).resolveBinding(); ILabel label_1 = (ILabel) collector.getName(1).resolveBinding(); @@ -1272,25 +1272,25 @@ public class AST2Tests extends AST2BaseTest { assertNotNull(function); assertNotNull(label_1); assertEquals(label_1, label_2); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(collector.getName(0) .resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], collector.getName(0)); - + decls = tu.getDeclarationsInAST(collector.getName(1).resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], collector.getName(2)); - + decls = tu.getDeclarationsInAST(collector.getName(2).resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], collector.getName(2)); - + tu = validateCopy(tu); } } - + // typedef struct { } X; // int f(X x); public void testAnonStruct() throws Exception { @@ -1306,49 +1306,49 @@ public class AST2Tests extends AST2BaseTest { .getDeclarators()[0]).getParameters()[0].getDeclSpecifier()).getName(); IASTName name_x = ((IASTStandardFunctionDeclarator) decl2 .getDeclarators()[0]).getParameters()[0].getDeclarator().getName(); - + IASTName[] decls = tu.getDeclarationsInAST(name_X1.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_X1); - + decls = tu.getDeclarationsInAST(name_f.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_f); - + decls = tu.getDeclarationsInAST(name_X2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_X1); - + decls = tu.getDeclarationsInAST(name_x.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_x); - + tu = validateCopy(tu); } - + } - + public void testLongLong() throws ParserException { IASTTranslationUnit tu = parse("long long x;\n", ParserLanguage.C); //$NON-NLS-1$ - + // test tu.getDeclarationsInAST(IBinding) IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu .getDeclarations()[0]; IASTName name_x = decl1.getDeclarators()[0].getName(); - + IASTName[] decls = tu.getDeclarationsInAST(name_x.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_x); } - - // enum hue { red, blue, green }; - // enum hue col, *cp; - // void f() { - // col = blue; - // cp = &col; - // if (*cp != red) - // return; - // } + + // enum hue { red, blue, green }; + // enum hue col, *cp; + // void f() { + // col = blue; + // cp = &col; + // if (*cp != red) + // return; + // } public void testEnumerations() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); assertTrue(tu.isFrozen()); @@ -1360,7 +1360,7 @@ public class AST2Tests extends AST2BaseTest { IASTEnumerator e2 = enumSpec.getEnumerators()[1]; IASTEnumerator e3 = enumSpec.getEnumerators()[2]; IASTName name_hue = enumSpec.getName(); - + IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu.getDeclarations()[1]; IASTDeclarator dtor = decl2.getDeclarators()[0]; IASTName name_col = dtor.getName(); @@ -1369,7 +1369,7 @@ public class AST2Tests extends AST2BaseTest { IASTElaboratedTypeSpecifier spec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier(); assertEquals(spec.getKind(), IASTElaboratedTypeSpecifier.k_enum); IASTName name_hue2 = spec.getName(); - + IASTFunctionDefinition fn = (IASTFunctionDefinition) tu.getDeclarations()[2]; IASTCompoundStatement compound = (IASTCompoundStatement) fn.getBody(); IASTExpressionStatement expStatement1 = (IASTExpressionStatement) compound.getStatements()[0]; @@ -1379,7 +1379,7 @@ public class AST2Tests extends AST2BaseTest { IASTIdExpression id2 = (IASTIdExpression) exp.getOperand2(); IASTName r_col = id1.getName(); IASTName r_blue = id2.getName(); - + IASTExpressionStatement expStatement2 = (IASTExpressionStatement) compound.getStatements()[1]; exp = (IASTBinaryExpression) expStatement2.getExpression(); assertEquals(exp.getOperator(), IASTBinaryExpression.op_assign); @@ -1388,16 +1388,16 @@ public class AST2Tests extends AST2BaseTest { id2 = (IASTIdExpression) ue.getOperand(); IASTName r_cp = id1.getName(); IASTName r_col2 = id2.getName(); - + IASTIfStatement ifStatement = (IASTIfStatement) compound.getStatements()[2]; exp = (IASTBinaryExpression) ifStatement.getConditionExpression(); ue = (IASTUnaryExpression) exp.getOperand1(); id1 = (IASTIdExpression) ue.getOperand(); id2 = (IASTIdExpression) exp.getOperand2(); - + IASTName r_cp2 = id1.getName(); IASTName r_red = id2.getName(); - + IEnumeration hue = (IEnumeration) name_hue.resolveBinding(); IEnumerator red = (IEnumerator) e1.getName().resolveBinding(); IEnumerator blue = (IEnumerator) e2.getName().resolveBinding(); @@ -1411,7 +1411,7 @@ public class AST2Tests extends AST2BaseTest { IVariable col3 = (IVariable) r_col2.resolveBinding(); IVariable cp3 = (IVariable) r_cp2.resolveBinding(); IEnumerator red2 = (IEnumerator) r_red.resolveBinding(); - + assertNotNull(hue); assertSame(hue, hue_2); assertNotNull(red); @@ -1425,61 +1425,61 @@ public class AST2Tests extends AST2BaseTest { assertSame(col, col3); assertSame(cp, cp3); assertSame(red, red2); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(name_hue.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_hue); - + decls = tu.getDeclarationsInAST(e1.getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], e1.getName()); - + decls = tu.getDeclarationsInAST(e2.getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], e2.getName()); - + decls = tu.getDeclarationsInAST(e3.getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], e3.getName()); - + decls = tu.getDeclarationsInAST(name_hue2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_hue); - + decls = tu.getDeclarationsInAST(name_col.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_col); - + decls = tu.getDeclarationsInAST(name_cp.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_cp); - + decls = tu.getDeclarationsInAST(fn.getDeclarator().getName() .resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], fn.getDeclarator().getName()); - + decls = tu.getDeclarationsInAST(r_col.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_col); - + decls = tu.getDeclarationsInAST(r_blue.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], e2.getName()); - + decls = tu.getDeclarationsInAST(r_cp.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_cp); - + decls = tu.getDeclarationsInAST(r_col2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_col); - + decls = tu.getDeclarationsInAST(r_cp2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_cp); - + decls = tu.getDeclarationsInAST(r_red.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], e1.getName()); @@ -1487,7 +1487,7 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - + public void testPointerToFunction() throws Exception { IASTTranslationUnit tu = parse("int (*pfi)();", ParserLanguage.C); //$NON-NLS-1$ assertTrue(tu.isFrozen()); @@ -1502,7 +1502,7 @@ public class AST2Tests extends AST2BaseTest { assertEquals(f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$ assertTrue(f.getPointerOperators().length == 0); assertFalse(f.getNestedDeclarator().getPointerOperators().length == 0); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(f.getNestedDeclarator().getName() .resolveBinding()); @@ -1512,13 +1512,13 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - - // int a; - // char * b; - // const int c; - // const char * const d; - // const char ** e; - // const char * const * const volatile ** const * f; + + // int a; + // char * b; + // const int c; + // const char * const d; + // const char ** e; + // const char * const * const volatile ** const * f; public void testBasicTypes() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); assertTrue(tu.isFrozen()); @@ -1542,7 +1542,7 @@ public class AST2Tests extends AST2BaseTest { decl = (IASTSimpleDeclaration) tu.getDeclarations()[5]; IVariable f = (IVariable) decl.getDeclarators()[0].getName() .resolveBinding(); - + IType t_a_1 = a.getType(); assertTrue(t_a_1 instanceof IBasicType); assertFalse(((IBasicType) t_a_1).isLong()); @@ -1550,20 +1550,20 @@ public class AST2Tests extends AST2BaseTest { assertFalse(((IBasicType) t_a_1).isSigned()); assertFalse(((IBasicType) t_a_1).isUnsigned()); assertEquals(((IBasicType) t_a_1).getType(), IBasicType.t_int); - + IType t_b_1 = b.getType(); assertTrue(t_b_1 instanceof IPointerType); IType t_b_2 = ((IPointerType) t_b_1).getType(); assertTrue(t_b_2 instanceof IBasicType); assertEquals(((IBasicType) t_b_2).getType(), IBasicType.t_char); - + IType t_c_1 = c.getType(); assertTrue(t_c_1 instanceof IQualifierType); assertTrue(((IQualifierType) t_c_1).isConst()); IType t_c_2 = ((IQualifierType) t_c_1).getType(); assertTrue(t_c_2 instanceof IBasicType); assertEquals(((IBasicType) t_c_2).getType(), IBasicType.t_int); - + IType t_d_1 = d.getType(); assertTrue(t_d_1 instanceof IPointerType); assertTrue(((IPointerType) t_d_1).isConst()); @@ -1573,7 +1573,7 @@ public class AST2Tests extends AST2BaseTest { IType t_d_3 = ((IQualifierType) t_d_2).getType(); assertTrue(t_d_3 instanceof IBasicType); assertEquals(((IBasicType) t_d_3).getType(), IBasicType.t_char); - + IType t_e_1 = e.getType(); assertTrue(t_e_1 instanceof IPointerType); assertFalse(((IPointerType) t_e_1).isConst()); @@ -1586,7 +1586,7 @@ public class AST2Tests extends AST2BaseTest { IType t_e_4 = ((IQualifierType) t_e_3).getType(); assertTrue(t_e_4 instanceof IBasicType); assertEquals(((IBasicType) t_e_4).getType(), IBasicType.t_char); - + IType t_f_1 = f.getType(); assertTrue(t_f_1 instanceof IPointerType); assertFalse(((IPointerType) t_f_1).isConst()); @@ -1617,7 +1617,7 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - + // int plainInt = 7; // signed int signedInt = -2; // unsigned int unsignedInt = 99; @@ -1625,20 +1625,20 @@ public class AST2Tests extends AST2BaseTest { public void testBug270275_int_is_equivalent_to_signed_int() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); IASTDeclaration[] declarations = tu.getDeclarations(); - IType plainInt = ((IVariable)((IASTSimpleDeclaration)declarations[0]).getDeclarators()[0].getName().resolveBinding()).getType(); - IType signedInt = ((IVariable)((IASTSimpleDeclaration)declarations[1]).getDeclarators()[0].getName().resolveBinding()).getType(); - IType unsignedInt = ((IVariable)((IASTSimpleDeclaration)declarations[2]).getDeclarators()[0].getName().resolveBinding()).getType(); - IType noSpec = ((IVariable)((IASTSimpleDeclaration)declarations[3]).getDeclarators()[0].getName().resolveBinding()).getType(); + IType plainInt = ((IVariable)((IASTSimpleDeclaration) declarations[0]).getDeclarators()[0].getName().resolveBinding()).getType(); + IType signedInt = ((IVariable)((IASTSimpleDeclaration) declarations[1]).getDeclarators()[0].getName().resolveBinding()).getType(); + IType unsignedInt = ((IVariable)((IASTSimpleDeclaration) declarations[2]).getDeclarators()[0].getName().resolveBinding()).getType(); + IType noSpec = ((IVariable)((IASTSimpleDeclaration) declarations[3]).getDeclarators()[0].getName().resolveBinding()).getType(); assertTrue(plainInt.isSameType(signedInt)); assertFalse(plainInt.isSameType(unsignedInt)); assertFalse(signedInt.isSameType(unsignedInt)); assertTrue(plainInt.isSameType(noSpec)); } - - // struct A {} a1; - // typedef struct A * AP; - // struct A * const a2; - // AP a3; + + // struct A {} a1; + // typedef struct A * AP; + // struct A * const a2; + // AP a3; public void testCompositeTypes() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); assertTrue(tu.isFrozen()); @@ -1660,50 +1660,50 @@ public class AST2Tests extends AST2BaseTest { IVariable a3 = (IVariable) decl.getDeclarators()[0].getName().resolveBinding(); IASTName name_a3 = decl.getDeclarators()[0].getName(); IASTName name_AP2 = ((IASTNamedTypeSpecifier) decl.getDeclSpecifier()).getName(); - + IType t_a1 = a1.getType(); assertSame(t_a1, A); - + IType t_a2 = a2.getType(); assertTrue(t_a2 instanceof IPointerType); assertTrue(((IPointerType) t_a2).isConst()); assertSame(((IPointerType) t_a2).getType(), A); - + IType t_a3 = a3.getType(); assertSame(t_a3, AP); IType t_AP = AP.getType(); assertTrue(t_AP instanceof IPointerType); assertSame(((IPointerType) t_AP).getType(), A); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(compSpec.getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], compSpec.getName()); - + decls = tu.getDeclarationsInAST(name_a1.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_a1); - + decls = tu.getDeclarationsInAST(name_A2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], compSpec.getName()); - + decls = tu.getDeclarationsInAST(name_AP.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_AP); - + decls = tu.getDeclarationsInAST(name_A3.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], compSpec.getName()); - + decls = tu.getDeclarationsInAST(name_a2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_a2); - + decls = tu.getDeclarationsInAST(name_AP2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_AP); - + decls = tu.getDeclarationsInAST(name_a3.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_a3); @@ -1711,10 +1711,10 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - - // int a[restrict]; - // char * b[][]; - // const char * const c[][][]; + + // int a[restrict]; + // char * b[][]; + // const char * const c[][][]; // char* d[const][]; public void testArrayTypes() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); @@ -1732,14 +1732,14 @@ public class AST2Tests extends AST2BaseTest { decl = (IASTSimpleDeclaration) tu.getDeclarations()[3]; IASTName name_d = decl.getDeclarators()[0].getName(); IVariable d = (IVariable) decl.getDeclarators()[0].getName().resolveBinding(); - + IType t_a_1 = a.getType(); assertTrue(t_a_1 instanceof ICArrayType); assertTrue(((ICArrayType) t_a_1).isRestrict()); IType t_a_2 = ((IArrayType) t_a_1).getType(); assertTrue(t_a_2 instanceof IBasicType); assertEquals(((IBasicType) t_a_2).getType(), IBasicType.t_int); - + IType t_b_1 = b.getType(); assertTrue(t_b_1 instanceof IArrayType); IType t_b_2 = ((IArrayType) t_b_1).getType(); @@ -1749,7 +1749,7 @@ public class AST2Tests extends AST2BaseTest { IType t_b_4 = ((IPointerType) t_b_3).getType(); assertTrue(t_b_4 instanceof IBasicType); assertEquals(((IBasicType) t_b_4).getType(), IBasicType.t_char); - + t_b_1 = d.getType(); assertTrue(t_b_1 instanceof IArrayType); t_b_2 = ((IArrayType) t_b_1).getType(); @@ -1759,7 +1759,7 @@ public class AST2Tests extends AST2BaseTest { t_b_4 = ((IPointerType) t_b_3).getType(); assertTrue(t_b_4 instanceof IBasicType); assertEquals(((IBasicType) t_b_4).getType(), IBasicType.t_char); - + IType t_c_1 = c.getType(); assertTrue(t_c_1 instanceof IArrayType); IType t_c_2 = ((IArrayType) t_c_1).getType(); @@ -1775,16 +1775,16 @@ public class AST2Tests extends AST2BaseTest { IType t_c_6 = ((IQualifierType) t_c_5).getType(); assertTrue(t_c_6 instanceof IBasicType); assertEquals(((IBasicType) t_c_6).getType(), IBasicType.t_char); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(name_a.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_a); - + decls = tu.getDeclarationsInAST(name_b.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_b); - + decls = tu.getDeclarationsInAST(name_c.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_c); @@ -1792,11 +1792,11 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - - // struct A; - // int * f(int i, char c); - // void (*g) (struct A *); - // void (* (*h)(struct A**)) (int d); + + // struct A; + // int * f(int i, char c); + // void (*g) (struct A *); + // void (* (*h)(struct A**)) (int d); public void testFunctionTypes() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); assertTrue(tu.isFrozen()); @@ -1806,7 +1806,7 @@ public class AST2Tests extends AST2BaseTest { ICompositeType A = (ICompositeType) elabSpec.getName().resolveBinding(); IASTName name_A1 = elabSpec.getName(); assertTrue(name_A1.isDeclaration()); - + decl = (IASTSimpleDeclaration) tu.getDeclarations()[1]; IFunction f = (IFunction) decl.getDeclarators()[0].getName().resolveBinding(); IASTName name_f = decl.getDeclarators()[0].getName(); @@ -1814,14 +1814,14 @@ public class AST2Tests extends AST2BaseTest { .getDeclarators()[0]).getParameters()[0].getDeclarator().getName(); IASTName name_c = ((IASTStandardFunctionDeclarator) decl .getDeclarators()[0]).getParameters()[1].getDeclarator().getName(); - + decl = (IASTSimpleDeclaration) tu.getDeclarations()[2]; IVariable g = (IVariable) decl.getDeclarators()[0] .getNestedDeclarator().getName().resolveBinding(); IASTName name_g = decl.getDeclarators()[0].getNestedDeclarator().getName(); IASTName name_A2 = ((IASTElaboratedTypeSpecifier) ((IASTStandardFunctionDeclarator) decl .getDeclarators()[0]).getParameters()[0].getDeclSpecifier()).getName(); - + decl = (IASTSimpleDeclaration) tu.getDeclarations()[3]; IVariable h = (IVariable) decl.getDeclarators()[0] .getNestedDeclarator().getNestedDeclarator().getName().resolveBinding(); @@ -1832,7 +1832,7 @@ public class AST2Tests extends AST2BaseTest { .getDeclSpecifier()).getName(); IASTName name_d = ((IASTStandardFunctionDeclarator) decl .getDeclarators()[0]).getParameters()[0].getDeclarator().getName(); - + IFunctionType t_f = f.getType(); IType t_f_return = t_f.getReturnType(); assertTrue(t_f_return instanceof IPointerType); @@ -1841,7 +1841,7 @@ public class AST2Tests extends AST2BaseTest { assertEquals(t_f_params.length, 2); assertTrue(t_f_params[0] instanceof IBasicType); assertTrue(t_f_params[1] instanceof IBasicType); - + // g is a pointer to a function that returns void and has 1 parameter // struct A * IType t_g = g.getType(); @@ -1855,7 +1855,7 @@ public class AST2Tests extends AST2BaseTest { IType t_g_func_p1 = t_g_func_params[0]; assertTrue(t_g_func_p1 instanceof IPointerType); assertSame(((IPointerType) t_g_func_p1).getType(), A); - + // h is a pointer to a function that returns a pointer to a function // the returned pointer to function returns void and takes 1 parameter // int @@ -1872,7 +1872,7 @@ public class AST2Tests extends AST2BaseTest { assertTrue(((IPointerType) t_h_func_p1).getType() instanceof IPointerType); assertSame(((IPointerType) ((IPointerType) t_h_func_p1).getType()) .getType(), A); - + assertTrue(t_h_func_return instanceof IPointerType); IFunctionType h_return = (IFunctionType) ((IPointerType) t_h_func_return) .getType(); @@ -1881,46 +1881,46 @@ public class AST2Tests extends AST2BaseTest { assertTrue(h_r instanceof IBasicType); assertEquals(h_ps.length, 1); assertTrue(h_ps[0] instanceof IBasicType); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(name_A1.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_A1); - + decls = tu.getDeclarationsInAST(name_f.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_f); - + decls = tu.getDeclarationsInAST(name_i.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_i); - + decls = tu.getDeclarationsInAST(name_c.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_c); - + decls = tu.getDeclarationsInAST(name_g.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_g); - + decls = tu.getDeclarationsInAST(name_A2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_A1); - + decls = tu.getDeclarationsInAST(name_h.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_h); - + decls = tu.getDeclarationsInAST(name_A3.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_A1); - + assertNull("Expected null, got "+name_d.resolveBinding(), name_d.resolveBinding()); tu = validateCopy(tu); } } - + // typedef struct { // int x; // int y; @@ -1952,7 +1952,7 @@ public class AST2Tests extends AST2BaseTest { .getDeclSpecifier()).getMembers()[1]).getDeclarators()[0].getName(); IASTFunctionDefinition main = (IASTFunctionDefinition) declarations[2]; IASTStatement[] statements = ((IASTCompoundStatement) main.getBody()).getStatements(); - + IASTSimpleDeclaration xy = (IASTSimpleDeclaration) ((IASTDeclarationStatement) statements[0]).getDeclaration(); IASTName name_Coord2 = ((IASTNamedTypeSpecifier) xy.getDeclSpecifier()).getName(); IASTName name_xy = xy.getDeclarators()[0].getName(); @@ -1961,14 +1961,14 @@ public class AST2Tests extends AST2BaseTest { .getInitializerClause()).getInitializers(); IASTName name_y2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers1[0]) .getDesignators()[0]).getName(); - + // test bug 87649 assertEquals(((ASTNode) (ICASTDesignatedInitializer) initializers1[0]) .getLength(), 7); - + IASTName name_x2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers1[1]) .getDesignators()[0]).getName(); - + IASTSimpleDeclaration point = (IASTSimpleDeclaration) ((IASTDeclarationStatement) statements[1]) .getDeclaration(); IASTName name_Point2 = ((IASTNamedTypeSpecifier) point @@ -1984,47 +1984,47 @@ public class AST2Tests extends AST2BaseTest { IASTName name_xy2 = ((IASTIdExpression) ((IASTUnaryExpression) ((IASTEqualsInitializer) ((ICASTDesignatedInitializer) initializers2[1]) .getOperandInitializer()).getInitializerClause()).getOperand()) .getName(); - + for (int j = 0; j < 2; ++j) { ICASTDesignatedInitializer designatedInitializer = (ICASTDesignatedInitializer) initializers1[j]; assertEquals(designatedInitializer.getDesignators().length, 1); ICASTFieldDesignator fieldDesignator = (ICASTFieldDesignator) designatedInitializer.getDesignators()[0]; assertNotNull(fieldDesignator.getName().toString()); } - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(name_Coord2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_Coord); - + decls = tu.getDeclarationsInAST(name_xy.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_xy); - + decls = tu.getDeclarationsInAST(name_y2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_y); - + decls = tu.getDeclarationsInAST(name_x2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_x); - + decls = tu.getDeclarationsInAST(name_Point2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_Point); - + decls = tu.getDeclarationsInAST(name_point.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_point); - + decls = tu.getDeclarationsInAST(name_width2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_width); - + decls = tu.getDeclarationsInAST(name_pos2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_pos); - + decls = tu.getDeclarationsInAST(name_xy2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_xy); @@ -2032,7 +2032,7 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - + // struct S { // int a; // int b; @@ -2046,7 +2046,7 @@ public class AST2Tests extends AST2BaseTest { for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration S_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTFunctionDefinition f_def = (IASTFunctionDefinition) tu.getDeclarations()[1]; - + IASTName a1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl .getDeclSpecifier()).getMembers()[0]).getDeclarators()[0] .getName(); @@ -2055,19 +2055,19 @@ public class AST2Tests extends AST2BaseTest { .getName(); final IASTDeclarator dtor = ((IASTSimpleDeclaration) ((IASTDeclarationStatement) ((IASTCompoundStatement) f_def .getBody()).getStatements()[0]).getDeclaration()).getDeclarators()[0]; - final IASTInitializerList initializerList = (IASTInitializerList) ((IASTEqualsInitializer)dtor.getInitializer()).getInitializerClause(); + final IASTInitializerList initializerList = (IASTInitializerList) ((IASTEqualsInitializer) dtor.getInitializer()).getInitializerClause(); IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializerList.getInitializers()[0]) .getDesignators()[0]).getName(); IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializerList.getInitializers()[1]) .getDesignators()[0]).getName(); - + assertEquals(a1.resolveBinding(), a2.resolveBinding()); assertEquals(b1.resolveBinding(), b2.resolveBinding()); - + IASTName[] decls = tu.getDeclarationsInAST(a1.resolveBinding()); assertEquals(decls.length, 1); assertEquals(a1, decls[0]); - + decls = tu.getDeclarationsInAST(b1.resolveBinding()); assertEquals(decls.length, 1); assertEquals(b1, decls[0]); @@ -2075,17 +2075,17 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - - // struct S { - // int a; - // int b; + + // struct S { + // int a; + // int b; // } s = {.a=1,.b=2}; public void testMoregetDeclarationsInAST2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration S_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; - + IASTName a1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl .getDeclSpecifier()).getMembers()[0]).getDeclarators()[0] .getName(); @@ -2098,25 +2098,25 @@ public class AST2Tests extends AST2BaseTest { .getDesignators()[0]).getName(); IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers[1]) .getDesignators()[0]).getName(); - + assertEquals(a1.resolveBinding(), a2.resolveBinding()); assertEquals(b1.resolveBinding(), b2.resolveBinding()); - + IASTName[] decls = tu.getDeclarationsInAST(a1.resolveBinding()); assertEquals(decls.length, 1); assertEquals(a1, decls[0]); - + decls = tu.getDeclarationsInAST(b1.resolveBinding()); assertEquals(decls.length, 1); assertEquals(b1, decls[0]); - + tu = validateCopy(tu); } } - - // typedef struct S { - // int a; - // int b; + + // typedef struct S { + // int a; + // int b; // } s; // typedef s t; // typedef t y; @@ -2127,7 +2127,7 @@ public class AST2Tests extends AST2BaseTest { for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration S_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTSimpleDeclaration x_decl = (IASTSimpleDeclaration) tu.getDeclarations()[3]; - + IASTName a1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl .getDeclSpecifier()).getMembers()[0]).getDeclarators()[0] .getName(); @@ -2140,14 +2140,14 @@ public class AST2Tests extends AST2BaseTest { .getDesignators()[0]).getName(); IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) initializer).getInitializers()[1]) .getDesignators()[0]).getName(); - + assertEquals(a1.resolveBinding(), a2.resolveBinding()); assertEquals(b1.resolveBinding(), b2.resolveBinding()); - + IASTName[] decls = tu.getDeclarationsInAST(a1.resolveBinding()); assertEquals(decls.length, 1); assertEquals(a1, decls[0]); - + decls = tu.getDeclarationsInAST(b1.resolveBinding()); assertEquals(decls.length, 1); assertEquals(b1, decls[0]); @@ -2155,7 +2155,7 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - + public void testFnReturningPtrToFn() throws Exception { IASTTranslationUnit tu = parse( "void (* f(int))() {}", ParserLanguage.C); //$NON-NLS-1$ @@ -2164,12 +2164,12 @@ public class AST2Tests extends AST2BaseTest { IASTFunctionDefinition def = (IASTFunctionDefinition) tu.getDeclarations()[0]; final IASTName fname = def.getDeclarator().getName(); IFunction f = (IFunction) fname.resolveBinding(); - + IFunctionType ft = f.getType(); assertTrue(ft.getReturnType() instanceof IPointerType); assertTrue(((IPointerType) ft.getReturnType()).getType() instanceof IFunctionType); assertEquals(ft.getParameterTypes().length, 1); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(f); assertEquals(decls.length, 1); @@ -2178,7 +2178,7 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - + // test C99: 6.7.5.3-7 A declaration of a parameter as ''array of type'' // shall be adjusted to ''qualified pointer to // type'', where the type qualifiers (if any) are those specified within the @@ -2191,11 +2191,11 @@ public class AST2Tests extends AST2BaseTest { for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration def = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IFunction f = (IFunction) def.getDeclarators()[0].getName().resolveBinding(); - + IFunctionType ft = f.getType(); assertTrue(ft.getParameterTypes()[0] instanceof IPointerType); assertTrue(((IPointerType) ft.getParameterTypes()[0]).isConst()); - + // test tu.getDeclarationsInAST(IBinding) IASTName name_parm = ((IASTStandardFunctionDeclarator) def .getDeclarators()[0]).getParameters()[0].getDeclarator() @@ -2225,46 +2225,38 @@ public class AST2Tests extends AST2BaseTest { // int *f2() {} // int (* f3())() {} public void testFunctionDefTypes() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); - + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { - IASTFunctionDefinition def1 = (IASTFunctionDefinition) tu - .getDeclarations()[0]; - IFunction f = (IFunction) def1.getDeclarator().getName() - .resolveBinding(); - IASTFunctionDefinition def2 = (IASTFunctionDefinition) tu - .getDeclarations()[1]; - IFunction f2 = (IFunction) def2.getDeclarator().getName() - .resolveBinding(); - IASTFunctionDefinition def3 = (IASTFunctionDefinition) tu - .getDeclarations()[2]; - IFunction f3 = (IFunction) def3.getDeclarator().getName() - .resolveBinding(); - + IASTFunctionDefinition def1 = (IASTFunctionDefinition) tu.getDeclarations()[0]; + IFunction f = (IFunction) def1.getDeclarator().getName().resolveBinding(); + IASTFunctionDefinition def2 = (IASTFunctionDefinition) tu.getDeclarations()[1]; + IFunction f2 = (IFunction) def2.getDeclarator().getName().resolveBinding(); + IASTFunctionDefinition def3 = (IASTFunctionDefinition) tu.getDeclarations()[2]; + IFunction f3 = (IFunction) def3.getDeclarator().getName().resolveBinding(); + IFunctionType ft = f.getType(); IFunctionType ft2 = f2.getType(); IFunctionType ft3 = f3.getType(); - + assertTrue(ft.getReturnType() instanceof IBasicType); assertTrue(ft2.getReturnType() instanceof IPointerType); assertTrue(((IPointerType) ft2.getReturnType()).getType() instanceof IBasicType); assertTrue(ft3.getReturnType() instanceof IPointerType); assertTrue(((IPointerType) ft3.getReturnType()).getType() instanceof IFunctionType); - assertTrue(((IFunctionType) ((IPointerType) ft3.getReturnType()) - .getType()).getReturnType() instanceof IBasicType); - + assertTrue(((IFunctionType) ((IPointerType) ft3.getReturnType()).getType()).getReturnType() + instanceof IBasicType); + // test tu.getDeclarationsInAST(IBinding) - IASTName[] decls = tu.getDeclarationsInAST(def1.getDeclarator().getName() - .resolveBinding()); + IASTName[] decls = tu.getDeclarationsInAST(def1.getDeclarator().getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], def1.getDeclarator().getName()); - - decls = tu.getDeclarationsInAST(def2.getDeclarator().getName() - .resolveBinding()); + + decls = tu.getDeclarationsInAST(def2.getDeclarator().getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], def2.getDeclarator().getName()); - + decls = tu.getDeclarationsInAST(def3.getDeclarator().getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], def3.getDeclarator().getName()); @@ -2272,17 +2264,16 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - + // any parameter to type function returning T is adjusted to be pointer to // function returning T public void testParmToFunction() throws Exception { - IASTTranslationUnit tu = parse( - "int f(int g(void)) { return g();}", ParserLanguage.C); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("int f(int g(void)) { return g();}", ParserLanguage.C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTFunctionDefinition def = (IASTFunctionDefinition) tu.getDeclarations()[0]; IFunction f = (IFunction) def.getDeclarator().getName().resolveBinding(); - + IType ft = ((CFunction) f).getType(); assertTrue(ft instanceof IFunctionType); IType gt_1 = ((IFunctionType) ft).getParameterTypes()[0]; @@ -2295,12 +2286,13 @@ public class AST2Tests extends AST2BaseTest { IType gt_parm = ((IFunctionType) gt_2).getParameterTypes()[0]; assertTrue(gt_parm instanceof IBasicType); assertEquals(((IBasicType) gt_parm).getType(), IBasicType.t_void); - + // test tu.getDeclarationsInAST(IBinding) assertTrue(def.getDeclarator() instanceof IASTStandardFunctionDeclarator); IASTName name_g = ((IASTStandardFunctionDeclarator) def.getDeclarator()) .getParameters()[0].getDeclarator().getName(); - IASTName name_g_call = ((IASTIdExpression) ((IASTFunctionCallExpression) ((IASTReturnStatement) ((IASTCompoundStatement) def + IASTName name_g_call = + ((IASTIdExpression) ((IASTFunctionCallExpression) ((IASTReturnStatement) ((IASTCompoundStatement) def .getBody()).getStatements()[0]).getReturnValue()) .getFunctionNameExpression()).getName(); IASTName[] decls = tu.getDeclarationsInAST(name_g_call.resolveBinding()); @@ -2310,18 +2302,16 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - + public void testArrayPointerFunction() throws Exception { - IASTTranslationUnit tu = parse( - "int (*v[])(int *x, int *y);", ParserLanguage.C); //$NON-NLS-1$ - + IASTTranslationUnit tu = parse("int (*v[])(int *x, int *y);", ParserLanguage.C); + assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; - IVariable v = (IVariable) ((IASTStandardFunctionDeclarator) decl - .getDeclarators()[0]).getNestedDeclarator().getName() - .resolveBinding(); - + IVariable v = (IVariable) ((IASTStandardFunctionDeclarator) decl.getDeclarators()[0]) + .getNestedDeclarator().getName().resolveBinding(); + IType vt_1 = v.getType(); assertTrue(vt_1 instanceof IArrayType); IType vt_2 = ((IArrayType) vt_1).getType(); @@ -2342,25 +2332,25 @@ public class AST2Tests extends AST2BaseTest { IType vpt_2_2 = ((IPointerType) vpt_1).getType(); assertTrue(vpt_2_2 instanceof IBasicType); assertEquals(((IBasicType) vpt_2_2).getType(), IBasicType.t_int); - + // test tu.getDeclarationsInAST(IBinding) IASTName[] decls = tu.getDeclarationsInAST(((IASTStandardFunctionDeclarator) decl .getDeclarators()[0]).getNestedDeclarator().getName() .resolveBinding()); assertEquals(decls.length, 1); - assertEquals(decls[0], ((IASTStandardFunctionDeclarator) decl - .getDeclarators()[0]).getNestedDeclarator().getName()); + assertEquals(decls[0], ((IASTStandardFunctionDeclarator) decl.getDeclarators()[0]) + .getNestedDeclarator().getName()); tu = validateCopy(tu); } } - + // typedef void DWORD; // typedef DWORD v; // v signal(int); public void testTypedefExample4a() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); - + assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -2368,7 +2358,7 @@ public class AST2Tests extends AST2BaseTest { IType dword_t = dword.getType(); assertTrue(dword_t instanceof IBasicType); assertEquals(((IBasicType) dword_t).getType(), IBasicType.t_void); - + IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu.getDeclarations()[1]; ITypedef v = (ITypedef) decl2.getDeclarators()[0].getName().resolveBinding(); IType v_t_1 = v.getType(); @@ -2376,7 +2366,7 @@ public class AST2Tests extends AST2BaseTest { IType v_t_2 = ((ITypedef) v_t_1).getType(); assertTrue(v_t_2 instanceof IBasicType); assertEquals(((IBasicType) v_t_2).getType(), IBasicType.t_void); - + IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) tu.getDeclarations()[2]; IFunction signal = (IFunction) decl3.getDeclarators()[0].getName().resolveBinding(); IFunctionType signal_t = signal.getType(); @@ -2387,20 +2377,20 @@ public class AST2Tests extends AST2BaseTest { IType signal_ret3 = ((ITypedef) signal_ret2).getType(); assertTrue(signal_ret3 instanceof IBasicType); assertEquals(((IBasicType) signal_ret3).getType(), IBasicType.t_void); - + // test tu.getDeclarationsInAST(IBinding) IASTName name_DWORD = decl1.getDeclarators()[0].getName(); IASTName name_v = decl2.getDeclarators()[0].getName(); - + IASTName[] decls = tu.getDeclarationsInAST(name_DWORD.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_DWORD); - - decls = tu.getDeclarationsInAST(((IASTNamedTypeSpecifier) decl2 - .getDeclSpecifier()).getName().resolveBinding()); + + decls = tu.getDeclarationsInAST(((IASTNamedTypeSpecifier) decl2.getDeclSpecifier()) + .getName().resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_DWORD); - + decls = tu.getDeclarationsInAST(((IASTNamedTypeSpecifier) decl3 .getDeclSpecifier()).getName().resolveBinding()); assertEquals(decls.length, 1); @@ -2409,7 +2399,7 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - + // typedef void DWORD; // typedef DWORD (*pfv)(int); // pfv signal(int, pfv); @@ -2422,7 +2412,7 @@ public class AST2Tests extends AST2BaseTest { IType dword_t = dword.getType(); assertTrue(dword_t instanceof IBasicType); assertEquals(((IBasicType) dword_t).getType(), IBasicType.t_void); - + IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) tu.getDeclarations()[1]; ITypedef pfv = (ITypedef) decl2.getDeclarators()[0].getNestedDeclarator().getName().resolveBinding(); IType pfv_t_1 = pfv.getType(); @@ -2438,7 +2428,7 @@ public class AST2Tests extends AST2BaseTest { IType pfv_t_2_parm = ((IFunctionType) pfv_t_2).getParameterTypes()[0]; assertTrue(pfv_t_2_parm instanceof IBasicType); assertEquals(((IBasicType) pfv_t_2_parm).getType(), IBasicType.t_int); - + IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) tu.getDeclarations()[2]; IFunction signal = (IFunction) decl3.getDeclarators()[0].getName().resolveBinding(); IFunctionType signal_t = signal.getType(); @@ -2455,7 +2445,7 @@ public class AST2Tests extends AST2BaseTest { assertEquals(((IBasicType) signal_ret_ret_2).getType(), IBasicType.t_void); assertTrue(((ITypedef) signal_ret_ret_1).getName().equals("DWORD")); //$NON-NLS-1$ - + IType signal_parm_t1 = signal_t.getParameterTypes()[0]; assertTrue(signal_parm_t1 instanceof IBasicType); assertEquals(((IBasicType) signal_parm_t1).getType(), IBasicType.t_int); @@ -2472,65 +2462,65 @@ public class AST2Tests extends AST2BaseTest { assertEquals(((IBasicType) signal_parm_t2_ret_2).getType(), IBasicType.t_void); assertTrue(((ITypedef) signal_parm_t2_ret_1).getName().equals("DWORD")); //$NON-NLS-1$ - + // test tu.getDeclarationsInAST(IBinding) IASTName name_pfv = decl2.getDeclarators()[0].getNestedDeclarator().getName(); IASTName name_pfv1 = ((IASTNamedTypeSpecifier) decl3.getDeclSpecifier()).getName(); IASTName name_pfv2 = ((IASTNamedTypeSpecifier) ((IASTStandardFunctionDeclarator) decl3 .getDeclarators()[0]).getParameters()[1].getDeclSpecifier()).getName(); - + IASTName[] decls = tu.getDeclarationsInAST(name_pfv1.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_pfv); - + decls = tu.getDeclarationsInAST(name_pfv2.resolveBinding()); assertEquals(decls.length, 1); assertEquals(decls[0], name_pfv); - + tu = validateCopy(tu); } } - + // typedef void fv(int), (*pfv)(int); // void (*signal1(int, void (*)(int)))(int); // fv *signal2(int, fv *); // pfv signal3(int, pfv); public void testTypedefExample4c() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); - + assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; ITypedef fv = (ITypedef) decl.getDeclarators()[0].getName().resolveBinding(); ITypedef pfv = (ITypedef) decl.getDeclarators()[1].getNestedDeclarator().getName().resolveBinding(); - + IType fv_t = fv.getType(); assertEquals(((IBasicType) ((IFunctionType) fv_t).getReturnType()) .getType(), IBasicType.t_void); assertEquals( ((IBasicType) ((IFunctionType) fv_t).getParameterTypes()[0]) .getType(), IBasicType.t_int); - + IType pfv_t = pfv.getType(); assertEquals(((IBasicType) ((IFunctionType) ((IPointerType) pfv_t) .getType()).getReturnType()).getType(), IBasicType.t_void); assertEquals(((IBasicType) ((IFunctionType) ((IPointerType) pfv .getType()).getType()).getParameterTypes()[0]).getType(), IBasicType.t_int); - + decl = (IASTSimpleDeclaration) tu.getDeclarations()[1]; IFunction signal1 = (IFunction) decl.getDeclarators()[0] .getNestedDeclarator().getName().resolveBinding(); IType signal1_t = signal1.getType(); - + decl = (IASTSimpleDeclaration) tu.getDeclarations()[2]; IFunction signal2 = (IFunction) decl.getDeclarators()[0].getName().resolveBinding(); IType signal2_t = signal2.getType(); - + decl = (IASTSimpleDeclaration) tu.getDeclarations()[3]; IFunction signal3 = (IFunction) decl.getDeclarators()[0].getName().resolveBinding(); IType signal3_t = signal3.getType(); - + assertEquals( ((IBasicType) ((IFunctionType) ((IPointerType) ((IFunctionType) signal1_t) .getReturnType()).getType()).getReturnType()).getType(), @@ -2545,7 +2535,7 @@ public class AST2Tests extends AST2BaseTest { ((IBasicType) ((IFunctionType) ((IPointerType) ((IFunctionType) signal1_t) .getParameterTypes()[1]).getType()).getParameterTypes()[0]) .getType(), IBasicType.t_int); - + assertEquals( ((IBasicType) ((IFunctionType) ((ITypedef) ((IPointerType) ((IFunctionType) signal2_t) .getReturnType()).getType()).getType()).getReturnType()) @@ -2560,7 +2550,7 @@ public class AST2Tests extends AST2BaseTest { ((IBasicType) ((IFunctionType) ((ITypedef) ((IPointerType) ((IFunctionType) signal2_t) .getParameterTypes()[1]).getType()).getType()) .getParameterTypes()[0]).getType(), IBasicType.t_int); - + assertEquals( ((IBasicType) ((IFunctionType) ((IPointerType) ((ITypedef) ((IFunctionType) signal3_t) .getReturnType()).getType()).getType()).getReturnType()) @@ -2578,9 +2568,9 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } - + } - + // const int x = 10; // int y [ const static x ]; public void testBug80992() throws Exception { @@ -2593,8 +2583,8 @@ public class AST2Tests extends AST2BaseTest { assertFalse(mod.isVolatile()); assertFalse(mod.isVariableSized()); } - - + + // int y (int [ const *]); public void testBug80978() throws Exception { ICASTArrayModifier mod = (ICASTArrayModifier) ((IASTArrayDeclarator) ((IASTStandardFunctionDeclarator) ((IASTSimpleDeclaration) parse( @@ -2607,12 +2597,12 @@ public class AST2Tests extends AST2BaseTest { assertFalse(mod.isRestrict()); assertFalse(mod.isVolatile()); } - - //AJN: bug 77383 don't do external variables - // // void f() { - // // if (a == 0) - // // a = a + 3; - // // } + + //AJN: bug 77383 don't do external variables + // // void f() { + // // if (a == 0) + // // a = a + 3; + // // } // public void testExternalVariable() throws Exception { // IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); // CNameCollector col = new CNameCollector(); @@ -2623,53 +2613,53 @@ public class AST2Tests extends AST2BaseTest { // assertTrue(a instanceof ICExternalBinding); // assertInstances(col, a, 3); // } - - // void f() { - // int a = 1; - // if (a == 0) - // g(a); - // if (a < 0) - // g(a >> 1); - // if (a > 0) - // g(*(&a + 2)); - // } + + // void f() { + // int a = 1; + // if (a == 0) + // g(a); + // if (a < 0) + // g(a >> 1); + // if (a > 0) + // g(*(&a + 2)); + // } public void testExternalDefs() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); tu.accept(col); - + IVariable a = (IVariable) col.getName(1).resolveBinding(); IFunction g = (IFunction) col.getName(3).resolveBinding(); assertNotNull(a); assertNotNull(g); assertTrue(g instanceof ICExternalBinding); - + assertEquals(col.size(), 11); assertInstances(col, a, 7); assertInstances(col, g, 3); - + tu = validateCopy(tu); } } - - // typedef struct { int x; int y; } Coord; - // int f() { - // Coord xy = { .x = 10, .y = 11 }; - // } + + // typedef struct { int x; int y; } Coord; + // int f() { + // Coord xy = { .x = 10, .y = 11 }; + // } public void testFieldDesignators() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); tu.accept(col); - + assertEquals(col.size(), 9); IField x = (IField) col.getName(1).resolveBinding(); IField y = (IField) col.getName(2).resolveBinding(); ITypedef Coord = (ITypedef) col.getName(3).resolveBinding(); - + assertInstances(col, x, 2); assertInstances(col, y, 2); assertInstances(col, Coord, 2); @@ -2677,7 +2667,7 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - + // enum { member_one, member_two }; // const char *nm[] = { // [member_one] = "one", @@ -2689,18 +2679,18 @@ public class AST2Tests extends AST2BaseTest { for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); tu.accept(col); - + assertEquals(col.size(), 6); IEnumerator one = (IEnumerator) col.getName(1).resolveBinding(); IEnumerator two = (IEnumerator) col.getName(2).resolveBinding(); - + assertInstances(col, one, 2); assertInstances(col, two, 2); tu = validateCopy(tu); } } - + // void f() { // if (a == 0) // g(a); @@ -2732,23 +2722,23 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - - // void f() { - // while (1) { - // if (1) goto end; - // } - // end: ; - // } + + // void f() { + // while (1) { + // if (1) goto end; + // } + // end: ; + // } public void testBug84090_LabelReferences() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); tu.accept(col); - + assertEquals(col.size(), 3); ILabel end = (ILabel) col.getName(1).resolveBinding(); - + IASTName[] refs = tu.getReferences(end); assertEquals(refs.length, 1); assertSame(refs[0].resolveBinding(), end); @@ -2756,7 +2746,7 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - + // enum col { red, blue }; // enum col c; public void testBug84092_EnumReferences() throws Exception { @@ -2765,10 +2755,10 @@ public class AST2Tests extends AST2BaseTest { for (int i = 0; i < NUM_TESTS; i++) { CNameCollector collector = new CNameCollector(); tu.accept(collector); - + assertEquals(collector.size(), 5); IEnumeration col = (IEnumeration) collector.getName(0).resolveBinding(); - + IASTName[] refs = tu.getReferences(col); assertEquals(refs.length, 1); assertSame(refs[0].resolveBinding(), col); @@ -2776,7 +2766,7 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - + public void testBug84096_FieldDesignatorRef() throws Exception { IASTTranslationUnit tu = parse( "struct s { int a; } ss = { .a = 1 }; \n", ParserLanguage.C); //$NON-NLS-1$ @@ -2784,10 +2774,10 @@ public class AST2Tests extends AST2BaseTest { for (int i = 0; i < NUM_TESTS; i++) { CNameCollector collector = new CNameCollector(); tu.accept(collector); - + assertEquals(collector.size(), 4); IField a = (IField) collector.getName(1).resolveBinding(); - + IASTName[] refs = tu.getReferences(a); assertEquals(refs.length, 1); assertSame(refs[0].resolveBinding(), a); @@ -2795,16 +2785,16 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - + public void testProblems() throws Exception { - + IASTTranslationUnit tu = parse( " a += ;", ParserLanguage.C, true, false); //$NON-NLS-1$ IASTProblem[] ps = CVisitor.getProblems(tu); assertEquals(ps.length, 1); ps[0].getMessage(); } - + // enum e; // enum e{ one }; public void testEnumerationForwards() throws Exception { @@ -2813,55 +2803,55 @@ public class AST2Tests extends AST2BaseTest { for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); tu.accept(col); - + assertEquals(col.size(), 3); IEnumeration e = (IEnumeration) col.getName(0).resolveBinding(); IEnumerator[] etors = e.getEnumerators(); assertTrue(etors.length == 1); assertFalse(etors[0] instanceof IProblemBinding); - + assertInstances(col, e, 2); tu = validateCopy(tu); } } - - // void f() { - // int (*p) [2]; - // (&p)[0] = 1; - // } + + // void f() { + // int (*p) [2]; + // (&p)[0] = 1; + // } public void testBug84185() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); CNameCollector col = new CNameCollector(); tu.accept(col); - + assertEquals(col.size(), 3); IVariable p = (IVariable) col.getName(1).resolveBinding(); assertTrue(p.getType() instanceof IPointerType); assertTrue(((IPointerType) p.getType()).getType() instanceof IArrayType); IArrayType at = (IArrayType) ((IPointerType) p.getType()).getType(); assertTrue(at.getType() instanceof IBasicType); - + assertInstances(col, p, 2); } - - // void f() { - // int (*p) [2]; - // (&p)[0] = 1; - // } + + // void f() { + // int (*p) [2]; + // (&p)[0] = 1; + // } public void testBug84185_2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); CNameCollector col = new CNameCollector(); tu.accept(col); - + assertEquals(col.size(), 3); - + IVariable p_ref = (IVariable) col.getName(2).resolveBinding(); IVariable p_decl = (IVariable) col.getName(1).resolveBinding(); - + assertSame(p_ref, p_decl); } - + // // example from: C99 6.5.2.5-16 // struct s { int i; }; // void f (void) @@ -2869,14 +2859,14 @@ public class AST2Tests extends AST2BaseTest { // struct s *p = 0, *q; // int j = 0; // q = p; - // p = &((struct s) { j++ }); + // p = &((struct s) { j++ }); // } public void testBug84176() throws Exception { parse(getAboveComment(), ParserLanguage.C, false, true); } - - // struct s { double i; } f(void); - // struct s f(void) {} + + // struct s { double i; } f(void); + // struct s f(void) {} public void testBug84266() throws Exception { final String code = getAboveComment(); IASTTranslationUnit tu = parse(code, ParserLanguage.C); @@ -2897,34 +2887,34 @@ public class AST2Tests extends AST2BaseTest { s_ref = (ICompositeType) col.getName(4).resolveBinding(); assertSame(s_ref, s_decl); } - + public void testBug84266_2() throws Exception { IASTTranslationUnit tu = parse("struct s f(void);", ParserLanguage.C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); - + assertEquals(col.size(), 3); - + ICompositeType s = (ICompositeType) col.getName(0).resolveBinding(); assertNotNull(s); - + tu = parse("struct s f(void) {}", ParserLanguage.C); //$NON-NLS-1$ col = new CNameCollector(); tu.accept(col); - + assertEquals(col.size(), 3); - + s = (ICompositeType) col.getName(0).resolveBinding(); assertNotNull(s); } - + public void testBug84250() throws Exception { assertTrue(((IASTDeclarationStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) parse( "void f() { int (*p) [2]; }", ParserLanguage.C).getDeclarations()[0]).getBody()).getStatements()[0]).getDeclaration() instanceof IASTSimpleDeclaration); //$NON-NLS-1$ } - - // struct s1 { struct s2 *s2p; /* ... */ }; // D1 - // struct s2 { struct s1 *s1p; /* ... */ }; // D2 + + // struct s1 { struct s2 *s2p; /* ... */ }; // D1 + // struct s2 { struct s1 *s1p; /* ... */ }; // D2 public void testBug84186() throws Exception { for (ParserLanguage lang : ParserLanguage.values()) { final String code = getAboveComment(); @@ -2948,26 +2938,26 @@ public class AST2Tests extends AST2BaseTest { assertSame(s_ref, s_decl); } } - - // typedef struct { int a; } S; - // void g(S* (*funcp) (void)) { - // (*funcp)()->a; - // funcp()->a; - // } + + // typedef struct { int a; } S; + // void g(S* (*funcp) (void)) { + // (*funcp)()->a; + // funcp()->a; + // } public void testBug84267() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); CNameCollector col = new CNameCollector(); tu.accept(col); - + assertEquals(col.size(), 11); - + ITypedef S = (ITypedef) col.getName(2).resolveBinding(); IField a = (IField) col.getName(10).resolveBinding(); IParameter funcp = (IParameter) col.getName(7).resolveBinding(); assertNotNull(funcp); assertInstances(col, funcp, 3); assertInstances(col, a, 3); - + assertTrue(funcp.getType() instanceof IPointerType); IType t = ((IPointerType) funcp.getType()).getType(); assertTrue(t instanceof IFunctionType); @@ -2975,36 +2965,36 @@ public class AST2Tests extends AST2BaseTest { assertTrue(ft.getReturnType() instanceof IPointerType); assertSame(((IPointerType) ft.getReturnType()).getType(), S); } - - // void f(int m, int c[m][m]); - // void f(int m, int c[m][m]) { - // int x; - // { int x = x; } - // } + + // void f(int m, int c[m][m]); + // void f(int m, int c[m][m]) { + // int x; + // { int x = x; } + // } public void testBug84228() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); CNameCollector col = new CNameCollector(); tu.accept(col); - + assertEquals(col.size(), 13); - + IParameter m = (IParameter) col.getName(3).resolveBinding(); IVariable x3 = (IVariable) col.getName(12).resolveBinding(); IVariable x2 = (IVariable) col.getName(11).resolveBinding(); IVariable x1 = (IVariable) col.getName(10).resolveBinding(); - + assertSame(x2, x3); assertNotSame(x1, x2); - + assertInstances(col, m, 6); assertInstances(col, x1, 1); assertInstances(col, x2, 2); - + IASTName[] ds = tu.getDeclarationsInAST(x2); assertEquals(ds.length, 1); assertSame(ds[0], col.getName(11)); } - + public void testBug84236() throws Exception { String code = "double maximum(double a[ ][*]);"; //$NON-NLS-1$ IASTSimpleDeclaration d = (IASTSimpleDeclaration) parse(code, @@ -3015,9 +3005,9 @@ public class AST2Tests extends AST2BaseTest { IASTArrayDeclarator a = (IASTArrayDeclarator) p.getDeclarator(); ICASTArrayModifier star = (ICASTArrayModifier) a.getArrayModifiers()[1]; assertTrue(star.isVariableSized()); - + } - + // typedef int B; // void g() { // B * bp; //1 @@ -3031,108 +3021,108 @@ public class AST2Tests extends AST2BaseTest { IASTSimpleDeclaration bp = (IASTSimpleDeclaration) ((IASTDeclarationStatement) statement) .getDeclaration(); assertTrue(bp.getDeclarators()[0].getName().resolveBinding() instanceof IVariable); - + } - + public void testBug86766() throws Exception { IASTTranslationUnit tu = parse( "char foo; void foo() {}", ParserLanguage.C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); - + IVariable foo = (IVariable) col.getName(0).resolveBinding(); IProblemBinding prob = (IProblemBinding) col.getName(1) .resolveBinding(); assertEquals(prob.getID(), IProblemBinding.SEMANTIC_INVALID_OVERLOAD); assertNotNull(foo); } - + public void testBug88338_C() throws Exception { IASTTranslationUnit tu = parse( "struct A; struct A* a;", ParserLanguage.C); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + assertTrue(col.getName(0).isDeclaration()); assertFalse(col.getName(0).isReference()); assertTrue(col.getName(1).isReference()); assertFalse(col.getName(1).isDeclaration()); - + tu = parse("struct A* a; struct A;", ParserLanguage.C); //$NON-NLS-1$ col = new CPPNameCollector(); tu.accept(col); - + col.getName(2).resolveBinding(); - + assertTrue(col.getName(0).isDeclaration()); assertFalse(col.getName(0).isReference()); - + assertTrue(col.getName(2).isDeclaration()); assertFalse(col.getName(2).isReference()); } - + public void test88460() throws Exception { IASTTranslationUnit tu = parse("void f();", ParserLanguage.C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); - + IFunction f = (IFunction) col.getName(0).resolveBinding(); assertFalse(f.isStatic()); } - + public void testBug90253() throws Exception { IASTTranslationUnit tu = parse( "void f(int par) { int v1; };", ParserLanguage.C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); - + IFunction f = (IFunction) col.getName(0).resolveBinding(); IParameter p = (IParameter) col.getName(1).resolveBinding(); IVariable v1 = (IVariable) col.getName(2).resolveBinding(); - + IASTFunctionDefinition fdef= getDeclaration(tu, 0); IScope scope = ((IASTCompoundStatement) fdef.getBody()).getScope(); - + IBinding[] bs = scope.find("par"); //$NON-NLS-1$ assertEquals(1, bs.length); assertSame(bs[0], p); - + bs = scope.find("v1"); //$NON-NLS-1$ assertEquals(bs.length, 1); assertSame(bs[0], v1); } - - // struct S {}; - // int S; - // void f() { - // int S; - // { - // S : ; - // } - // } + + // struct S {}; + // int S; + // void f() { + // int S; + // { + // S : ; + // } + // } public void testFind() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); CNameCollector col = new CNameCollector(); tu.accept(col); - + ICompositeType S1 = (ICompositeType) col.getName(0).resolveBinding(); IVariable S2 = (IVariable) col.getName(1).resolveBinding(); IFunction f = (IFunction) col.getName(2).resolveBinding(); IVariable S3 = (IVariable) col.getName(3).resolveBinding(); ILabel S4 = (ILabel) col.getName(4).resolveBinding(); - + IASTFunctionDefinition fdef= getDeclaration(tu, 2); IScope scope = ((IASTCompoundStatement) fdef.getBody()).getScope(); - + IBinding[] bs = scope.find("S"); //$NON-NLS-1$ - + assertNotNull(S2); assertEquals(bs.length, 3); assertSame(bs[0], S3); assertSame(bs[1], S1); assertSame(bs[2], S4); } - + public void test92791() throws Exception { IASTTranslationUnit tu = parse( "void f() { int x, y; x * y; }", ParserLanguage.C); //$NON-NLS-1$ @@ -3140,7 +3130,7 @@ public class AST2Tests extends AST2BaseTest { tu.accept(col); for (int i = 0; i < col.size(); ++i) assertFalse(col.getName(i).resolveBinding() instanceof IProblemBinding); - + tu = parse( "int y; void f() { typedef int x; x * y; }", ParserLanguage.C); //$NON-NLS-1$ col = new CNameCollector(); @@ -3148,7 +3138,7 @@ public class AST2Tests extends AST2BaseTest { for (int i = 0; i < col.size(); ++i) assertFalse(col.getName(i).resolveBinding() instanceof IProblemBinding); } - + public void testBug85786() throws Exception { IASTTranslationUnit tu = parse( "void f(int); void foo () { void * p = &f; ((void (*) (int)) p) (1); }", ParserLanguage.C); //$NON-NLS-1$ @@ -3156,7 +3146,7 @@ public class AST2Tests extends AST2BaseTest { tu.accept(nameResolver); assertNoProblemBindings(nameResolver); } - + // void func() { // int i=0; // i= i&0x00ff; @@ -3166,21 +3156,21 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); CNameCollector nameResolver = new CNameCollector(); tu.accept(nameResolver); - assertNoProblemBindings(nameResolver); + assertNoProblemBindings(nameResolver); } - + // #define ONE(a, ...) int x // #define TWO(b, args...) int y // int main() // { // ONE("string"); /* err */ // TWO("string"); /* err */ - // return 0; + // return 0; // } public void testBug94365() throws Exception { parse(getAboveComment(), ParserLanguage.C); } - + // #define MACRO(a) // void main() { // MACRO('"'); @@ -3196,7 +3186,7 @@ public class AST2Tests extends AST2BaseTest { assertTrue(((IASTCompoundStatement) ((IASTFunctionDefinition) declarations[0]) .getBody()).getStatements()[0] instanceof IASTNullStatement); } - + // #define MACRO(a) // void main() { // MACRO('X'); @@ -3212,150 +3202,150 @@ public class AST2Tests extends AST2BaseTest { assertTrue(((IASTCompoundStatement) ((IASTFunctionDefinition) declarations[0]) .getBody()).getStatements()[0] instanceof IASTNullStatement); } - + // typedef long _TYPE; // typedef _TYPE TYPE; // int function(TYPE (* pfv)(int parm)); public void testBug81739() throws Exception { parse(getAboveComment(), ParserLanguage.C); } - + // float _Complex x; // double _Complex y; public void testBug95757() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true, true); IASTDeclaration[] decls = tu.getDeclarations(); - - assertTrue(((ICASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[0]).getDeclSpecifier()).isComplex()); - assertEquals(((ICASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[0]).getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_float); - assertTrue(((ICASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[1]).getDeclSpecifier()).isComplex()); - assertEquals(((ICASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[1]).getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_double); + + assertTrue(((ICASTSimpleDeclSpecifier)((IASTSimpleDeclaration) decls[0]).getDeclSpecifier()).isComplex()); + assertEquals(((ICASTSimpleDeclSpecifier)((IASTSimpleDeclaration) decls[0]).getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_float); + assertTrue(((ICASTSimpleDeclSpecifier)((IASTSimpleDeclaration) decls[1]).getDeclSpecifier()).isComplex()); + assertEquals(((ICASTSimpleDeclSpecifier)((IASTSimpleDeclaration) decls[1]).getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_double); } - - // int foo(); - // typeof({ int x = foo(); - // x; }) zoot; + + // int foo(); + // typeof({ int x = foo(); + // x; }) zoot; public void testBug93980() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true); CNameCollector col = new CNameCollector(); tu.accept(col); - + IFunction foo = (IFunction) col.getName(0).resolveBinding(); assertSame(foo, col.getName(2).resolveBinding()); - + IVariable zoot = (IVariable) col.getName(4).resolveBinding(); IType t = zoot.getType(); assertTrue(t instanceof IBasicType); - assertEquals(((IBasicType)t).getType(), IBasicType.t_int); + assertEquals(((IBasicType) t).getType(), IBasicType.t_int); } - + public void testBug95866() throws Exception { IASTTranslationUnit tu = parse("int test[10] = { [0 ... 9] = 2 };", ParserLanguage.C, true, true); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); assertNoProblemBindings(col); } - + public void testBug98502() throws Exception { IASTTranslationUnit tu = parse("typedef enum { ONE } e;", ParserLanguage.C, true, true); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); - + IEnumeration etion = (IEnumeration) col.getName(0).resolveBinding(); ITypedef e = (ITypedef) col.getName(2).resolveBinding(); assertSame(e.getType(), etion); } - - // typedef struct _loop_data { - // enum { PIPERR } pipe_err; - // } loop_data; - // void f() { - // PIPERR; - // } + + // typedef struct _loop_data { + // enum { PIPERR } pipe_err; + // } loop_data; + // void f() { + // PIPERR; + // } public void testBug98365() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true); CNameCollector col = new CNameCollector(); tu.accept(col); - + IEnumerator etor = (IEnumerator) col.getName(2).resolveBinding(); assertSame(etor, col.getName(6).resolveBinding()); } - + public void testBug99262() throws Exception { parse("void foo() {void *f; f=__null;}", ParserLanguage.C, true, true); //$NON-NLS-1$ } - + // void f1(int*) { // } // void f2() { // f1(__null); // } - public void testBug240567() throws Exception { + public void testBug240567() throws Exception { BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), false); bh.assertNonProblem("f1(__null", 2, IFunction.class); } - - // void f() { - // int a; - // { a; int a; } - // } + + // void f() { + // int a; + // { a; int a; } + // } public void testBug98960() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true); CNameCollector col = new CNameCollector(); tu.accept(col); - + IVariable a1 = (IVariable) col.getName(1).resolveBinding(); IVariable a2 = (IVariable) col.getName(2).resolveBinding(); IVariable a3 = (IVariable) col.getName(3).resolveBinding(); - + assertSame(a1, a2); assertNotSame(a2, a3); } - + public void testBug100408() throws Exception { IASTTranslationUnit tu = parse("int foo() { int x=1; (x)*3; }", ParserLanguage.C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); assertNoProblemBindings(col); } - - // struct nfa; - // void f() { - // struct nfa * n; - // freenfa(n); - // } - // static void freenfa(nfa) - // struct nfa * nfa; - // { - // } + + // struct nfa; + // void f() { + // struct nfa * n; + // freenfa(n); + // } + // static void freenfa(nfa) + // struct nfa * nfa; + // { + // } public void testBug98760() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true); CNameCollector col = new CNameCollector(); tu.accept(col); - + IFunction free = (IFunction) col.getName(4).resolveBinding(); IParameter [] ps = free.getParameters(); assertEquals(ps.length, 1); - + assertSame(free, col.getName(6).resolveBinding()); } - + // void testCasting() { // typedef struct { // int employee_id; // int dept_id; // } Employee; // #define MY_DETAILS { 20, 30 } - // Employee e = (Employee)MY_DETAILS; + // Employee e = (Employee)MY_DETAILS; // } public void testBug79650() throws Exception { parseAndCheckBindings(getAboveComment()); } - + public void testBug80171() throws Exception { parseAndCheckBindings("static var;"); //$NON-NLS-1$ } - + // enum E_OPTIONCODE { // red = 1, // black = 2, @@ -3371,7 +3361,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug79067() throws Exception { parseAndCheckBindings(getAboveComment()); } - + // enum COLOR { // RED=1 // }; @@ -3383,41 +3373,41 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment()); IASTFunctionDefinition fd = (IASTFunctionDefinition) tu.getDeclarations()[1]; assertEquals(fd.getDeclSpecifier().getRawSignature(), "enum COLOR"); //$NON-NLS-1$ - + } - + // int f() { // int x = 4; while (x < 10) blah: ++x; // } public void test1043290() throws Exception { IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment()); IASTFunctionDefinition fd = (IASTFunctionDefinition) tu.getDeclarations()[0]; - IASTStatement [] statements = ((IASTCompoundStatement)fd.getBody()).getStatements(); + IASTStatement [] statements = ((IASTCompoundStatement) fd.getBody()).getStatements(); IASTWhileStatement whileStmt = (IASTWhileStatement) statements[1]; IASTLabelStatement labelStmt = (IASTLabelStatement) whileStmt.getBody(); assertTrue(labelStmt.getNestedStatement() instanceof IASTExpressionStatement); IASTExpressionStatement es = (IASTExpressionStatement) labelStmt.getNestedStatement(); assertTrue(es.getExpression() instanceof IASTUnaryExpression); } - - // void f() { - // int x; - // for (int x; ;) - // blah: x; - // } + + // void f() { + // int x; + // for (int x; ;) + // blah: x; + // } public void testBug104390_2() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true); CNameCollector col = new CNameCollector(); tu.accept(col); - + IVariable x = (IVariable) col.getName(1).resolveBinding(); IVariable x2 = (IVariable) col.getName(2).resolveBinding(); assertNotSame(x, x2); assertSame(x2, col.getName(4).resolveBinding()); assertTrue(col.getName(3).resolveBinding() instanceof ILabel); } - - // int f() { + + // int f() { // int i; // do { ++i; } while (i < 10); // return 0; @@ -3428,7 +3418,7 @@ public class AST2Tests extends AST2BaseTest { IASTCompoundStatement body = (IASTCompoundStatement) f.getBody(); assertEquals(body.getStatements().length, 3); } - + public void testBug107150() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("#define FUNC_PROTOTYPE_PARAMS(list) list\r\n"); //$NON-NLS-1$ @@ -3443,7 +3433,7 @@ public class AST2Tests extends AST2BaseTest { assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); tu = parse(buffer.toString(), ParserLanguage.CPP); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); - + buffer = new StringBuffer(); buffer.append("#define FUNC_PROTOTYPE_PARAMS(list) list\n"); //$NON-NLS-1$ buffer.append("int func1 FUNC_PROTOTYPE_PARAMS((int arg1)) {\n"); //$NON-NLS-1$ @@ -3458,7 +3448,7 @@ public class AST2Tests extends AST2BaseTest { tu= parse(buffer.toString(), ParserLanguage.CPP); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); } - + public void testBug107150b() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("#define FUNC_PROTOTYPE_PARAMS(list) list\r\n"); //$NON-NLS-1$ @@ -3471,10 +3461,10 @@ public class AST2Tests extends AST2BaseTest { buffer.append("}\r\n"); //$NON-NLS-1$ IASTTranslationUnit tu= parse(buffer.toString(), ParserLanguage.C); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); - + tu = parse(buffer.toString(), ParserLanguage.CPP); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); - + buffer = new StringBuffer(); buffer.append("#define FUNC_PROTOTYPE_PARAMS(list) list\n"); //$NON-NLS-1$ buffer.append("int func1 FUNC_PROTOTYPE_PARAMS((int arg1)) {\n"); //$NON-NLS-1$ @@ -3489,7 +3479,7 @@ public class AST2Tests extends AST2BaseTest { tu = parse(buffer.toString(), ParserLanguage.CPP); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); } - + // NWindow NewWindowDuplicate(NWindow theWindow, bool insert)\n"); // { // NWindow newWindow; @@ -3534,7 +3524,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug143502() throws Exception { parse(getAboveComment(), ParserLanguage.C, true, false); } - + // void func(int a) { // int z=0; // z= (a)+z; @@ -3552,14 +3542,14 @@ public class AST2Tests extends AST2BaseTest { IASTParameterDeclaration[] params= ((IASTStandardFunctionDeclarator) func.getDeclarator()).getParameters(); IBinding binding= params[0].getDeclarator().getName().resolveBinding(); assertEquals(7, tu.getReferences(binding).length); - + tu= parse(content, ParserLanguage.CPP, true, true); func= (IASTFunctionDefinition) tu.getDeclarations()[0]; params= ((IASTStandardFunctionDeclarator) func.getDeclarator()).getParameters(); binding= params[0].getDeclarator().getName().resolveBinding(); assertEquals(7, tu.getReferences(binding).length); } - + // #define MAC(x) x // void func() { // MAC("); @@ -3567,45 +3557,45 @@ public class AST2Tests extends AST2BaseTest { public void testBug179383() throws ParserException, IOException { parse(getAboveComment(), ParserLanguage.C, false, false); } - + /** * Bug in not removing single-line comments from macros. * @throws Exception */ public void testMacroCommentsBug_177154() throws Exception { // simple case - String simple = - "#define LIT 1 // my value\r\n" + - "int func(int x) {\r\n" + - "}\r\n" + - "int main() {\r\n" + - " return func(LIT); // fails to parse\r\n" + - "}\r\n"; - + String simple = + "#define LIT 1 // my value\r\n" + + "int func(int x) {\r\n" + + "}\r\n" + + "int main() {\r\n" + + " return func(LIT); // fails to parse\r\n" + + "}\r\n"; + IASTTranslationUnit tu = parse(simple, ParserLanguage.CPP, true, true); - + // actual reduced test case, plus extra cases String text = - "#define KBOOT 1 //0x00000002\r\n" + - "#define KBOOT2 /* value */ 1 /* another */ //0x00000002\r\n" + + "#define KBOOT 1 //0x00000002\r\n" + + "#define KBOOT2 /* value */ 1 /* another */ //0x00000002\r\n" + "#define KBOOT3 /* value \r\n" + " multi line\r\n"+ " comment */ 1 \\\r\n"+ "/* another */ + \\\r\n"+ - "2 //0x00000002\r\n" + - "#define DEBUGNUM(x) (KDebugNum(x))\r\n" + - "bool KDebugNum(int aBitNum);\r\n" + + "2 //0x00000002\r\n" + + "#define DEBUGNUM(x) (KDebugNum(x))\r\n" + + "bool KDebugNum(int aBitNum);\r\n" + "#define __KTRACE_OPT(a,p) {if ((DEBUGNUM(a)))p;}\r\n" + "void fail();\r\n"+ "void test() {\r\n"+ - "__KTRACE_OPT(KBOOT,fail());\r\n" + - "__KTRACE_OPT(KBOOT2,fail());\r\n" + + "__KTRACE_OPT(KBOOT,fail());\r\n" + + "__KTRACE_OPT(KBOOT2,fail());\r\n" + "}\r\n" ; - + // essential test: this code should be parseable tu = parse(text, ParserLanguage.CPP, true, true); - + // verify macros IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions(); assertEquals(5, macroDefinitions.length); @@ -3616,10 +3606,10 @@ public class AST2Tests extends AST2BaseTest { assertEquals(expectExpansion, macroDefinitions[2].getExpansion()); assertEquals("(KDebugNum(x))", macroDefinitions[3].getExpansion()); assertEquals("{if ((DEBUGNUM(a)))p;}", macroDefinitions[4].getExpansion()); - + // TODO: exhaustive macro testing } - + // void (decl)(char); // void foo() { // decl('a'); @@ -3627,7 +3617,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug181305_1() throws Exception { for (ParserLanguage lang : ParserLanguage.values()) { IASTTranslationUnit tu = parse(getAboveComment(), lang, true, true); - + // check class IASTFunctionDefinition fd = (IASTFunctionDefinition) tu.getDeclarations()[1]; IASTCompoundStatement comp_stmt= (IASTCompoundStatement) fd.getBody(); @@ -3640,7 +3630,7 @@ public class AST2Tests extends AST2BaseTest { assertEquals(binding.getName(), "decl"); } } - + // void (*decl)(char); // void foo() { // decl('a'); @@ -3648,7 +3638,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug181305_2() throws Exception { for (ParserLanguage lang : ParserLanguage.values()) { IASTTranslationUnit tu = parse(getAboveComment(), lang, true, true); - + // check class IASTFunctionDefinition fd = (IASTFunctionDefinition) tu.getDeclarations()[1]; IASTCompoundStatement comp_stmt= (IASTCompoundStatement) fd.getBody(); @@ -3660,64 +3650,64 @@ public class AST2Tests extends AST2BaseTest { assertFalse(lang.toString(), binding instanceof IProblemBinding); } } - + public void testBug181735() throws Exception { String code= "int (*f)(int);\n" + "int g(int n) {return n;}\n" + "int g(int n, int m) {return n;}\n" + "void foo() { f=g; }"; - + for (ParserLanguage lang : ParserLanguage.values()) parseAndCheckBindings(code, lang); } - + // void test() { // char d= *"b"; // } public void testBug181942() throws Exception { - for (ParserLanguage lang : ParserLanguage.values()) + for (ParserLanguage lang : ParserLanguage.values()) parse(getAboveComment(), lang, true, true); } - + public void testMacroCommentsBug_177154_2() throws Exception { String noCommentMacro = - "#define Sonar16G(x) ((Sonr16G(x)<<16)|0xff000000L)\r\n"; - String commentMacro = - "#define Sonar16G(x) ((Sonr16G(x)<<16)|0xff000000L) // add the varf value\r\n"; - - String textTail = "\r\n" + - "const int snd16SonarR[32] = {\r\n" + - " 0xFF000000L, Sonar16G(0x01), Sonar16G(0x02), Sonar16G(0x03),\r\n" + - " Sonar16G(0x04), Sonar16G(0x05), Sonar16G(0x06), Sonar16G(0x07),\r\n" + - " Sonar16G(0x08), Sonar16G(0x09), Sonar16G(0x0A), Sonar16G(0x0B),\r\n" + - " Sonar16G(0x0C), Sonar16G(0x0D), Sonar16G(0x0E), Sonar16G(0x0F),\r\n" + - " Sonar16G(0x10), Sonar16G(0x11), Sonar16G(0x12), Sonar16G(0x13),\r\n" + - " Sonar16G(0x14), Sonar16G(0x15), Sonar16G(0x16), Sonar16G(0x17),\r\n" + - " Sonar16G(0x18), Sonar16G(0x19), Sonar16G(0x1A), Sonar16G(0x1B),\r\n" + - " Sonar16G(0x1C), Sonar16G(0x1D), Sonar16G(0x1E), Sonar16G(0x1F),\r\n" + - " };\r\n" + - "\r\n" + + "#define Sonar16G(x) ((Sonr16G(x)<<16)|0xff000000L)\r\n"; + String commentMacro = + "#define Sonar16G(x) ((Sonr16G(x)<<16)|0xff000000L) // add the varf value\r\n"; + + String textTail = "\r\n" + + "const int snd16SonarR[32] = {\r\n" + + " 0xFF000000L, Sonar16G(0x01), Sonar16G(0x02), Sonar16G(0x03),\r\n" + + " Sonar16G(0x04), Sonar16G(0x05), Sonar16G(0x06), Sonar16G(0x07),\r\n" + + " Sonar16G(0x08), Sonar16G(0x09), Sonar16G(0x0A), Sonar16G(0x0B),\r\n" + + " Sonar16G(0x0C), Sonar16G(0x0D), Sonar16G(0x0E), Sonar16G(0x0F),\r\n" + + " Sonar16G(0x10), Sonar16G(0x11), Sonar16G(0x12), Sonar16G(0x13),\r\n" + + " Sonar16G(0x14), Sonar16G(0x15), Sonar16G(0x16), Sonar16G(0x17),\r\n" + + " Sonar16G(0x18), Sonar16G(0x19), Sonar16G(0x1A), Sonar16G(0x1B),\r\n" + + " Sonar16G(0x1C), Sonar16G(0x1D), Sonar16G(0x1E), Sonar16G(0x1F),\r\n" + + " };\r\n" + + "\r\n" + ""; - + // this should work String textNoComment = noCommentMacro + textTail; IASTTranslationUnit tu = parse(textNoComment, ParserLanguage.CPP, true, true); - + // this fails String textComment = commentMacro + textTail; tu = parse(textComment, ParserLanguage.CPP, true, true); - + } - + // int __builtin_sin; public void testBug182464() throws Exception { for (ParserLanguage lang : ParserLanguage.values()) parseAndCheckBindings(getAboveComment(), lang, true); } - + public void testBug186018() throws Exception { - String code = + String code = "int main() { \n" + " switch(1) { \n" + " case 1 : \n" + @@ -3725,10 +3715,10 @@ public class AST2Tests extends AST2BaseTest { " printf(\"pantera rules\"); \n" + " } \n" + "}\n"; - + parseAndCheckBindings(code, ParserLanguage.C); } - + // template // class auto_ptr { // private: @@ -3765,13 +3755,13 @@ public class AST2Tests extends AST2BaseTest { assertEquals("method", methodc.getName()); assertInstance(methodb, ICPPMethod.class); assertInstance(methodc, ICPPMethod.class); - assertEquals("A", ((ICPPMethod)methodb).getClassOwner().getName()); - assertEquals("A", ((ICPPMethod)methodc).getClassOwner().getName()); - + assertEquals("A", ((ICPPMethod) methodb).getClassOwner().getName()); + assertEquals("A", ((ICPPMethod) methodc).getClassOwner().getName()); + tu = validateCopy(tu); } } - + // template // class odd_pair { // private: @@ -3817,13 +3807,13 @@ public class AST2Tests extends AST2BaseTest { assertEquals("method", methodAA.getName()); assertInstance(methodA, ICPPMethod.class); assertInstance(methodAA, ICPPMethod.class); - assertEquals("A", ((ICPPMethod)methodA).getClassOwner().getName()); - assertEquals("AA", ((ICPPMethod)methodAA).getClassOwner().getName()); + assertEquals("A", ((ICPPMethod) methodA).getClassOwner().getName()); + assertEquals("AA", ((ICPPMethod) methodAA).getClassOwner().getName()); tu = validateCopy(tu); } } - + // class B { // public: // void bar() {} @@ -3847,7 +3837,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); validateCopy(tu); } - + // typedef int int32; // int32 f(int32 (*p)) { // return *p; @@ -3855,17 +3845,17 @@ public class AST2Tests extends AST2BaseTest { public void test167833() throws Exception { parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); parseAndCheckBindings(getAboveComment(), ParserLanguage.C); - } - + } + // // this is a \ - // single line comment + // single line comment // char str[] = " multi \ // line \ // string"; public void testBug188707_backslashNewline() throws Exception { parseAndCheckBindings(getAboveComment()); } - + // typedef A B; // typedef C D; // typedef E E; @@ -3890,7 +3880,7 @@ public class AST2Tests extends AST2BaseTest { assertInstance(col.getName(9).resolveBinding(), ITypedef.class); assertInstance(col.getName(10).resolveBinding(), IProblemBinding.class); assertInstance(col.getName(11).resolveBinding(), ITypedef.class); - + // function ptr final IBinding typedef = col.getName(12).resolveBinding(); final IBinding secondJ = col.getName(13).resolveBinding(); @@ -3898,23 +3888,23 @@ public class AST2Tests extends AST2BaseTest { if (lang == ParserLanguage.CPP) { assertInstance(secondJ, IProblemBinding.class); } else { - // for plain C this is actually not a problem, the second J has to be interpreted as a (useless) + // for plain C this is actually not a problem, the second J has to be interpreted as a (useless) // parameter name. assertInstance(typedef, ITypedef.class); isTypeEqual(((ITypedef) typedef).getType(), "int (*)(int)"); } } } - + // /* a comment */ // #define INVALID(a, b) ## a ## b // INVALID(1, 2) // public void test192639() throws Exception { - parse(getAboveComment(), ParserLanguage.CPP, false, false); - parse(getAboveComment(), ParserLanguage.C, false, false); + parse(getAboveComment(), ParserLanguage.CPP, false, false); + parse(getAboveComment(), ParserLanguage.C, false, false); } - + public void test195943() throws Exception { final int depth= 100; StringBuffer buffer = new StringBuffer(); @@ -3924,16 +3914,16 @@ public class AST2Tests extends AST2BaseTest { } buffer.append("int a= M" + (depth-1) + ";\n"); long time= System.currentTimeMillis(); - parse(buffer.toString(), ParserLanguage.CPP); + parse(buffer.toString(), ParserLanguage.CPP); parse(buffer.toString(), ParserLanguage.C); assertTrue(System.currentTimeMillis()-time < 2000); } - + // int array[12]= {}; public void testBug196468_emptyArrayInitializer() throws Exception { final String content = getAboveComment(); - parse(content, ParserLanguage.CPP, false); - parse(content, ParserLanguage.CPP, true); + parse(content, ParserLanguage.CPP, false); + parse(content, ParserLanguage.CPP, true); parse(content, ParserLanguage.C, true); try { parse(content, ParserLanguage.C, false); @@ -3942,7 +3932,7 @@ public class AST2Tests extends AST2BaseTest { catch (ParserException e) { } } - + // #define foo(f,...) // void bar(void) {} // int main(int argc, char **argv) { @@ -3955,10 +3945,10 @@ public class AST2Tests extends AST2BaseTest { // } public void testBug197633_parenthesisInVarargMacros() throws Exception { final String content = getAboveComment(); - parse(content, ParserLanguage.CPP); - parse(content, ParserLanguage.C); + parse(content, ParserLanguage.CPP); + parse(content, ParserLanguage.C); } - + // void (__attribute__((__stdcall__))* foo1) (int); // void (* __attribute__((__stdcall__)) foo2) (int); // void (* __attribute__((__stdcall__))* foo3) (int); @@ -3966,11 +3956,11 @@ public class AST2Tests extends AST2BaseTest { parse(getAboveComment(), ParserLanguage.CPP, true, true); parse(getAboveComment(), ParserLanguage.C, true, true); } - - // class NameClash {}; + + // class NameClash {}; // namespace NameClash {}; // namespace NameClash2 {}; - // class NameClash2 {}; + // class NameClash2 {}; public void testBug202271_nameClash() throws Exception { IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, true); assertTrue(tu.isFrozen()); @@ -3985,7 +3975,7 @@ public class AST2Tests extends AST2BaseTest { tu = validateCopy(tu); } } - + // #define WRAP(var) var // #define MACRO 1 // int a= MACRO; @@ -4007,7 +3997,7 @@ public class AST2Tests extends AST2BaseTest { IASTImageLocation iloc= refs[1].getImageLocation(); assertEquals(idx+5, iloc.getNodeOffset()); } - + // void OSi_Panic(const char *file, int line) {}; // void OSi_Panic(const char *file, int line, const char *fmt, ...) {}; // @@ -4027,7 +4017,7 @@ public class AST2Tests extends AST2BaseTest { // ASSERT(a > b, "Error!");// marked with error also // ASSERT(false);// fine // } - + // void OSi_Panic(const char *file, int line) {}; // void OSi_Panic(const char *file, int line, const char *fmt, ...) {}; // @@ -4051,45 +4041,45 @@ public class AST2Tests extends AST2BaseTest { CharSequence[] buffer = getContents(2); final String content1 = buffer[0].toString(); final String content2 = buffer[1].toString(); - parse(content1, ParserLanguage.CPP); - parse(content1, ParserLanguage.C); - parse(content2, ParserLanguage.CPP); - parse(content2, ParserLanguage.C); + parse(content1, ParserLanguage.CPP); + parse(content1, ParserLanguage.C); + parse(content2, ParserLanguage.CPP); + parse(content2, ParserLanguage.C); } - - + + // typedef struct Point { // int x; // int y; // } Point ; - // + // // typedef struct Tag { // int tag; // } Tag ; - // + // // typedef struct Line { // Point p1; // Point p2; // Tag t; // } Line ; - // + // // int foo() { - // Point p1 = {.x = 1, .y = 2}; - // - // Line l1 = {.p1 = {.x = 1, .y = 2}, {.x = 1, .y = 2}, {.tag = 5}}; - // Line l2 = {.t.tag = 9, .p1.x = 1, .p2.x = 3, .p1.y = 4, .p2.y = 9}; + // Point p1 = {.x = 1, .y = 2}; // + // Line l1 = {.p1 = {.x = 1, .y = 2}, {.x = 1, .y = 2}, {.tag = 5}}; + // Line l2 = {.t.tag = 9, .p1.x = 1, .p2.x = 3, .p1.y = 4, .p2.y = 9}; + // // Point points[] = {{.x=1, .y=1}, {.x=2, .y=2}}; - // } + // } public void _testBug210019_nestedDesignatedInitializers() throws Exception { IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.C); CNameCollector col = new CNameCollector(); tu.accept(col); - - // Point p1 + + // Point p1 assertField(col.getName(18).resolveBinding(), "x", "Point"); assertField(col.getName(19).resolveBinding(), "y", "Point"); - + // Line l1 assertField(col.getName(22).resolveBinding(), "p1", "Line"); assertField(col.getName(23).resolveBinding(), "x", "Point"); @@ -4097,7 +4087,7 @@ public class AST2Tests extends AST2BaseTest { assertField(col.getName(25).resolveBinding(), "x", "Point"); assertField(col.getName(26).resolveBinding(), "y", "Point"); assertField(col.getName(27).resolveBinding(), "tag", "Tag"); - + // Line l2 assertField(col.getName(30).resolveBinding(), "t", "Line"); assertField(col.getName(31).resolveBinding(), "tag", "Tag"); @@ -4109,50 +4099,50 @@ public class AST2Tests extends AST2BaseTest { assertField(col.getName(37).resolveBinding(), "y", "Point"); assertField(col.getName(38).resolveBinding(), "p2", "Line"); assertField(col.getName(39).resolveBinding(), "y", "Point"); - + // Point points[] assertField(col.getName(42).resolveBinding(), "x", "Point"); assertField(col.getName(43).resolveBinding(), "y", "Point"); assertField(col.getName(44).resolveBinding(), "x", "Point"); assertField(col.getName(45).resolveBinding(), "y", "Point"); } - - - // struct S1 { - // int i; + + + // struct S1 { + // int i; // float f; // int a[2]; // }; - // + // // struct S1 x = { - // .f=3.1, + // .f=3.1, // .i=2, // .a[1]=9 // }; - // + // // struct S2 { // int x, y; // }; - // + // // struct S2 a1[3] = {1, 2, 3, 4, 5, 6}; - // + // // struct S2 a2[3] = // {{1, 2},{3, 4}, 5, 6}; - // + // // struct S2 a3[3] = // { // [2].y=6, [2].x=5, // [1].y=4, [1].x=3, // [0].y=2, [0].x=1 // }; - // + // // struct S2 a4[3] = // { // [0].x=1, [0].y=2, // {.x=3, .y=4}, // 5, [2].y=6 // }; - // + // // struct S2 a5[3] = // { // [2].x=5, 6, @@ -4165,31 +4155,31 @@ public class AST2Tests extends AST2BaseTest { for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); tu.accept(col); - + assertField(col.getName(6).resolveBinding(), "f", "S1"); assertField(col.getName(7).resolveBinding(), "i", "S1"); assertField(col.getName(8).resolveBinding(), "a", "S1"); - + assertField(col.getName(18).resolveBinding(), "y", "S2"); assertField(col.getName(19).resolveBinding(), "x", "S2"); assertField(col.getName(20).resolveBinding(), "y", "S2"); assertField(col.getName(21).resolveBinding(), "x", "S2"); assertField(col.getName(22).resolveBinding(), "y", "S2"); assertField(col.getName(23).resolveBinding(), "x", "S2"); - + assertField(col.getName(26).resolveBinding(), "x", "S2"); assertField(col.getName(27).resolveBinding(), "y", "S2"); assertField(col.getName(28).resolveBinding(), "x", "S2"); assertField(col.getName(29).resolveBinding(), "y", "S2"); assertField(col.getName(30).resolveBinding(), "y", "S2"); - + assertField(col.getName(33).resolveBinding(), "x", "S2"); assertField(col.getName(34).resolveBinding(), "x", "S2"); tu = validateCopy(tu); } } - + // extern "C" { // extern "C" { // void externFunc(); @@ -4201,7 +4191,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug183126_nestedLinkageSpecs() throws Exception { parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); } - + // int* i= 0; // void f1(const int**); // void f2(int *const*); @@ -4213,18 +4203,18 @@ public class AST2Tests extends AST2BaseTest { // f3(&i); // ok // } public void testBug213029_cvConversion() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, false); + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, false); CNameCollector col = new CNameCollector(); tu.accept(col); for (Object o : col.nameList) { - IASTName n = (IASTName)o; + IASTName n = (IASTName) o; if (n.isReference() && "f1".equals(n.toString())) assertTrue(n.resolveBinding() instanceof IProblemBinding); else assertFalse(n.resolveBinding() instanceof IProblemBinding); } } - + // void isTrue(int field, int bit) { // return ((field) & (bit)); // } @@ -4242,7 +4232,7 @@ public class AST2Tests extends AST2BaseTest { cpp= !cpp; } while (cpp); } - + // void f1(int& r) {} // void f2(const int& r) {} // void f3(volatile int& r) {} @@ -4253,23 +4243,23 @@ public class AST2Tests extends AST2BaseTest { // const int ci= 1; // volatile int vi= 2; // const volatile int cvi = 3; - // + // // f1(i); // f1(ci); // should be an error // f1(vi); // should be an error // f1(cvi); // should be an error - // + // // f2(i); // f2(ci); // f2(vi); // should be an error // f2(cvi); // should be an error - // + // // f3(i); // f3(ci); // should be an error // f3(vi); // f3(cvi); // should be an error - // - // f4(i); + // + // f4(i); // f4(ci); // f4(vi); // f4(cvi); @@ -4280,25 +4270,25 @@ public class AST2Tests extends AST2BaseTest { ba.assertProblem("f1(ci)", 2); ba.assertProblem("f1(vi)", 2); ba.assertProblem("f1(cvi)", 2); - + ba.assertNonProblem("f2(i)", 2); ba.assertNonProblem("f2(ci)",2); ba.assertProblem("f2(vi)", 2); ba.assertProblem("f2(cvi)", 2); - + ba.assertNonProblem("f3(i)", 2); ba.assertProblem("f3(ci)", 2); ba.assertNonProblem("f3(vi)",2); ba.assertProblem("f3(cvi)", 2); - + ba.assertNonProblem("f4(i)", 2); ba.assertNonProblem("f4(ci)", 2); ba.assertNonProblem("f4(vi)", 2); ba.assertNonProblem("f4(cvi)",2); } - + // void f1(int& r) {} // 1 - // void f1(const int& r) {} // 2 + // void f1(const int& r) {} // 2 // void f1(volatile int& r) {} // 3 // void f1(const volatile int& r) {} // 4 // @@ -4307,38 +4297,38 @@ public class AST2Tests extends AST2BaseTest { // const int ci= 1; // volatile int vi= 2; // const volatile int cvi = 3; - // + // // f1(i); // (1) - // f1(ci); // (2) + // f1(ci); // (2) // f1(vi); // (3) // f1(cvi); // (4) // } public void testBug222418_b() throws Exception { BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); - + ICPPFunction f1_1= ba.assertNonProblem("f1(i)", 2, ICPPFunction.class); ICPPFunction f1_2= ba.assertNonProblem("f1(ci)", 2, ICPPFunction.class); ICPPFunction f1_3= ba.assertNonProblem("f1(vi)", 2, ICPPFunction.class); ICPPFunction f1_4= ba.assertNonProblem("f1(cvi)",2, ICPPFunction.class); - + assertEquals(ASTTypeUtil.getParameterTypeString(f1_1.getType()), "(int &)"); assertEquals(ASTTypeUtil.getParameterTypeString(f1_2.getType()), "(const int &)"); assertEquals(ASTTypeUtil.getParameterTypeString(f1_3.getType()), "(volatile int &)"); assertEquals(ASTTypeUtil.getParameterTypeString(f1_4.getType()), "(const volatile int &)"); } - + // void f1(int r) {} // 1 - // void f1(const int r) {} // 2 + // void f1(const int r) {} // 2 // void f1(volatile int r) {} // 3 // void f1(const volatile int r) {} // 4 public void testBug222418_b_regression() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); ba.assertNonProblem("f1(int", 2, ICPPFunction.class); ba.assertProblem("f1(const i", 2); ba.assertProblem("f1(vol", 2); ba.assertProblem("f1(const v",2); } - + // void fa(int& r) {} // void fb(const int& r) {} // void fc(volatile int& r) {} @@ -4348,35 +4338,35 @@ public class AST2Tests extends AST2BaseTest { // // void ref() { // fa(5); // should be an error - // fb(5); // ok + // fb(5); // ok // fc(5); // should be an error // fd(5); // should be an error // // fb(five()); // ok - // fa(five()); // should be an error + // fa(five()); // should be an error // fc(five()); // should be an error // fd(five()); // should be an error // } public void testBug222418_c() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); - + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + ICPPFunction fn= ba.assertNonProblem("five() {", 4, ICPPFunction.class); assertFalse(fn.getType().getReturnType() instanceof IProblemBinding); - + ba.assertProblem("fa(5", 2); ICPPFunction fb= ba.assertNonProblem("fb(5", 2, ICPPFunction.class); ba.assertProblem("fc(5", 2); ba.assertProblem("fd(5",2); - + ICPPFunction fb2= ba.assertNonProblem("fb(f", 2, ICPPFunction.class); ba.assertProblem("fa(f",2); ba.assertProblem("fc(f",2); ba.assertProblem("fd(f",2); - + assertEquals(ASTTypeUtil.getParameterTypeString(fb.getType()), "(const int &)"); assertEquals(ASTTypeUtil.getParameterTypeString(fb2.getType()), "(const int &)"); } - + // class X { // public: // X(int x) {} @@ -4390,11 +4380,11 @@ public class AST2Tests extends AST2BaseTest { // f_nonconst(2); // should be an error // } public void testBug222418_d() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); ba.assertNonProblem("f_const(2", 7, ICPPFunction.class); ba.assertProblem("f_nonconst(2", 10); } - + // class A {}; // // void f1(A& r) {} @@ -4423,7 +4413,7 @@ public class AST2Tests extends AST2BaseTest { // f3(vi); // f3(cvi); // should be an error // - // f4(i); + // f4(i); // f4(ci); // f4(vi); // f4(cvi); @@ -4434,23 +4424,23 @@ public class AST2Tests extends AST2BaseTest { ba.assertProblem("f1(ci)", 2); ba.assertProblem("f1(vi)", 2); ba.assertProblem("f1(cvi)", 2); - + ba.assertNonProblem("f2(i)", 2); ba.assertNonProblem("f2(ci)",2); ba.assertProblem("f2(vi)", 2); ba.assertProblem("f2(cvi)", 2); - + ba.assertNonProblem("f3(i)", 2); ba.assertProblem("f3(ci)", 2); ba.assertNonProblem("f3(vi)",2); ba.assertProblem("f3(cvi)", 2); - + ba.assertNonProblem("f4(i)", 2); ba.assertNonProblem("f4(ci)", 2); ba.assertNonProblem("f4(vi)", 2); ba.assertNonProblem("f4(cvi)",2); } - + // class B {}; // // class A { @@ -4483,10 +4473,10 @@ public class AST2Tests extends AST2BaseTest { // C c; // D d; // - // foo1(a); + // foo1(a); // foo2(a); // not copied // - // foo1(3); + // foo1(3); // foo2(4); // should be an error (222418) // // foo1(A(5)); @@ -4498,13 +4488,13 @@ public class AST2Tests extends AST2BaseTest { // foo1(d); // foo2(d); // should be an error // - // foo1(b); + // foo1(b); // foo2(b); // should be an error // // return 0; // } public void testBug222418_f() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); ba.assertNonProblem("foo1(a)", 4); ba.assertNonProblem("foo2(a)", 4); ba.assertNonProblem("foo1(3)", 4); @@ -4518,8 +4508,8 @@ public class AST2Tests extends AST2BaseTest { ba.assertNonProblem("foo1(b)", 4); ba.assertProblem("foo2(b)", 4); } - - + + // class A {}; // class B : public A {}; // @@ -4533,7 +4523,7 @@ public class AST2Tests extends AST2BaseTest { BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); ba.assertNonProblem("f(b2)", 1); } - + // void f(int &i) {} // void ref() { // int a=3; @@ -4544,7 +4534,7 @@ public class AST2Tests extends AST2BaseTest { BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); ba.assertNonProblem("f(r)", 1); } - + // class A {}; // class B : public A {}; // void f(A &a) {} @@ -4557,11 +4547,11 @@ public class AST2Tests extends AST2BaseTest { BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); ba.assertNonProblem("f(b2)", 1); } - + // // test adapted from IndexNamesTests.testReadWriteFlagsCpp() - // + // // int ri, wi, rwi, ridebug; - // int* rp; int* wp; int* rwp; + // int* rp; int* wp; int* rwp; // int* const rpc= 0; // const int * const rcpc= 0; // void fi(int); @@ -4579,49 +4569,49 @@ public class AST2Tests extends AST2BaseTest { // void fcpcr(int const *const&); // // int test() { - // fi(ri); fp(&rwi); fcp(&ri); - // fi(*rp); fp(rp); fcp(rp); fpp(&rwp); fpcp(&rpc); fcpcp(&rcpc); + // fi(ri); fp(&rwi); fcp(&ri); + // fi(*rp); fp(rp); fcp(rp); fpp(&rwp); fpcp(&rpc); fcpcp(&rcpc); // fr(rwi); fcr(ri); // fpcr(&rwi); fcpcr(&ri); // fpr(rwp); fpcr(rp); fcpcr(rp); - // - // fcpp(&rwp); // should be error + // + // fcpp(&rwp); // should be error // fpr(&rwi); // should be error // fcpr(&ridebug); // should be error // fcpr(rwp); // should be error - // + // // return ri; // } public void testBug222418_j() throws Exception { BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); - + ba.assertNonProblem("fi(ri)", 2); ba.assertNonProblem("fp(&rwi)", 2); ba.assertNonProblem("fcp(&ri)", 3); - + ba.assertNonProblem("fi(*rp)", 2); ba.assertNonProblem("fp(rp)", 2); ba.assertNonProblem("fcp(rp)", 3); ba.assertNonProblem("fpp(&rwp)", 3); ba.assertNonProblem("fpcp(&rpc)", 4); ba.assertNonProblem("fcpcp(&rcpc)", 5); - + ba.assertNonProblem("fr(rwi)", 2); ba.assertNonProblem("fcr(ri)", 3); - + ba.assertNonProblem("fpcr(&rwi)", 4); ba.assertNonProblem("fcpcr(&ri)", 5); - + ba.assertNonProblem("fpr(rwp)", 3); ba.assertNonProblem("fpcr(rp)", 4); ba.assertNonProblem("fcpcr(rp)", 5); - + ba.assertProblem("fcpp(&rwp)", 4); ba.assertProblem("fpr(&rwi)", 3); ba.assertProblem("fcpr(&ridebug)", 4); ba.assertProblem("fcpr(rwp)", 4); } - + // class A { // public: // void foo() {} @@ -4635,13 +4625,13 @@ public class AST2Tests extends AST2BaseTest { BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); ba.assertNonProblem("foo();", 3); } - + // class B {}; // - // class C { - // public: + // class C { + // public: // operator const B() const { return *new B();} - // }; + // }; // // void foo(B b) {} // @@ -4649,28 +4639,28 @@ public class AST2Tests extends AST2BaseTest { // const C c= *new C(); // const B b= *new B(); // - // foo(b); - // foo(c); + // foo(b); + // foo(c); // } public void testBug222444_a() throws Exception { BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); ICPPFunction foo1= ba.assertNonProblem("foo(b", 3, ICPPFunction.class); ICPPFunction foo2= ba.assertNonProblem("foo(c", 3, ICPPFunction.class); } - + // class A {}; // class B : public A {}; - // - // class C { - // public: + // + // class C { + // public: // operator const B() { return *new B();} - // }; + // }; // // void foo(A a) {} // // void refs() { // C c= *new C(); - // + // // foo(c); // } public void testBug222444_b() throws Exception { @@ -4680,24 +4670,24 @@ public class AST2Tests extends AST2BaseTest { // class A {}; // class B : public A {}; - // - // class C { - // public: + // + // class C { + // public: // operator const B&() { return *new B();} - // }; + // }; // // void foo(A a) {} // // void refs() { // C c= *new C(); - // + // // foo(c); // } public void testBug222444_c() throws Exception { BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); ICPPFunction foo2= ba.assertNonProblem("foo(c", 3, ICPPFunction.class); } - + // int a, b, c; // void test() { // a= b ? : c; @@ -4707,7 +4697,7 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(code, ParserLanguage.C); parseAndCheckBindings(code, ParserLanguage.CPP); } - + // #define __inline__ __inline__ __attribute__((always_inline)) // typedef int __u32; // static __inline__ __u32 f(int x) { @@ -4718,15 +4708,15 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(code, ParserLanguage.C, true); parseAndCheckBindings(code, ParserLanguage.CPP, true); } - + // int foo asm ("myfoo") __attribute__((__used__)), ff asm("ss") = 2; - // extern void func () asm ("FUNC") __attribute__((__used__)); + // extern void func () asm ("FUNC") __attribute__((__used__)); public void testASMLabels_Bug226121() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code, ParserLanguage.C, true); parseAndCheckBindings(code, ParserLanguage.CPP, true); } - + // void test() { // ({1;}) != 0; // } @@ -4734,8 +4724,8 @@ public class AST2Tests extends AST2BaseTest { final String code = getAboveComment(); parseAndCheckBindings(code, ParserLanguage.C, true); parseAndCheckBindings(code, ParserLanguage.CPP, true); - } - + } + // void test(int count) { // __typeof__(count) a= 1; // int ret0 = ((__typeof__(count)) 1); @@ -4745,7 +4735,7 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(code, ParserLanguage.C, true); parseAndCheckBindings(code, ParserLanguage.CPP, true); } - + // void test(int count) { // typeof(count==1) a= 1; // } @@ -4754,16 +4744,16 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(code, ParserLanguage.C, true); parseAndCheckBindings(code, ParserLanguage.CPP, true); } - + // void func() { // typeof(__attribute__((regparm(3)))void (*)(int *)) a; - // } + // } public void testTypeofExpressionWithAttribute_Bug226492() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code, ParserLanguage.C, true); parseAndCheckBindings(code, ParserLanguage.CPP, true); } - + // void test(int count) { // switch(count) { // case 1 ... 3: break; @@ -4773,26 +4763,26 @@ public class AST2Tests extends AST2BaseTest { final String code = getAboveComment(); { IASTTranslationUnit tu = parseAndCheckBindings(code, ParserLanguage.C, true); - IASTCompoundStatement body = (IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[0]).getBody(); - IASTSwitchStatement switchStmt = (IASTSwitchStatement)body.getStatements()[0]; - IASTCaseStatement caseStmt = (IASTCaseStatement)((IASTCompoundStatement)switchStmt.getBody()).getStatements()[0]; - IASTBinaryExpression binExpr = (IASTBinaryExpression)caseStmt.getExpression(); + IASTCompoundStatement body = (IASTCompoundStatement)((IASTFunctionDefinition) tu.getDeclarations()[0]).getBody(); + IASTSwitchStatement switchStmt = (IASTSwitchStatement) body.getStatements()[0]; + IASTCaseStatement caseStmt = (IASTCaseStatement)((IASTCompoundStatement) switchStmt.getBody()).getStatements()[0]; + IASTBinaryExpression binExpr = (IASTBinaryExpression) caseStmt.getExpression(); assertTrue(binExpr.getOperator() == IASTBinaryExpression.op_ellipses); assertTrue(binExpr.getOperand1() instanceof IASTLiteralExpression); assertTrue(binExpr.getOperand2() instanceof IASTLiteralExpression); } { IASTTranslationUnit tu = parseAndCheckBindings(code, ParserLanguage.CPP, true); - IASTCompoundStatement body = (IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[0]).getBody(); - IASTSwitchStatement switchStmt = (IASTSwitchStatement)body.getStatements()[0]; - IASTCaseStatement caseStmt = (IASTCaseStatement)((IASTCompoundStatement)switchStmt.getBody()).getStatements()[0]; - IASTBinaryExpression binExpr = (IASTBinaryExpression)caseStmt.getExpression(); + IASTCompoundStatement body = (IASTCompoundStatement)((IASTFunctionDefinition) tu.getDeclarations()[0]).getBody(); + IASTSwitchStatement switchStmt = (IASTSwitchStatement) body.getStatements()[0]; + IASTCaseStatement caseStmt = (IASTCaseStatement)((IASTCompoundStatement) switchStmt.getBody()).getStatements()[0]; + IASTBinaryExpression binExpr = (IASTBinaryExpression) caseStmt.getExpression(); assertTrue(binExpr.getOperator() == IASTBinaryExpression.op_ellipses); assertTrue(binExpr.getOperand1() instanceof IASTLiteralExpression); assertTrue(binExpr.getOperand2() instanceof IASTLiteralExpression); } } - + // typedef int* TIntPtr; // int x(int (int * a)); // int x(int(TIntPtr)); @@ -4801,7 +4791,7 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(code, ParserLanguage.C, true); parseAndCheckBindings(code, ParserLanguage.CPP, true); } - + // template class X { // typename T::t func() { // return typename T::t(); @@ -4811,29 +4801,29 @@ public class AST2Tests extends AST2BaseTest { final String code = getAboveComment(); parseAndCheckBindings(code, ParserLanguage.CPP); } - + // struct __attribute__((declspec)) bla; public void testAttributeInElaboratedTypeSpecifier_Bug227085() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code, ParserLanguage.C, true); parseAndCheckBindings(code, ParserLanguage.CPP, true); } - + // struct X; // void test(struct X* __restrict result); public void testRestrictReference_Bug227110() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code, ParserLanguage.CPP, true); } - + // char buf[256]; // int x= sizeof(buf)[0]; public void testSizeofUnaryWithParenthesis_Bug227122() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code, ParserLanguage.C); parseAndCheckBindings(code, ParserLanguage.CPP); - } - + } + // class X { // public: // void* operator new(unsigned int sz, char* buf) {return buf;} @@ -4846,8 +4836,8 @@ public class AST2Tests extends AST2BaseTest { public void testPlacementNewInConditionalExpression_Bug227104() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code, ParserLanguage.CPP); - } - + } + // int f(x) { // return 0; // } @@ -4855,7 +4845,7 @@ public class AST2Tests extends AST2BaseTest { CharSequence buffer = getContents(1)[0]; parse(buffer.toString(), ParserLanguage.C, false); } - + // struct { // char foo; // } myStruct, *myStructPointer; @@ -4874,7 +4864,7 @@ public class AST2Tests extends AST2BaseTest { // myStructPointer->bar=2; // myUnion.bar=3; // myUnionPointer->bar=4; - // } + // } public void testBug228504_nonExistingMembers() throws Exception { boolean[] isCpps= {true, false}; for (boolean isCpp : isCpps) { @@ -4885,13 +4875,13 @@ public class AST2Tests extends AST2BaseTest { } } } - + // struct S { - // int value; + // int value; // }; - // typedef struct S *PtrS; + // typedef struct S *PtrS; // struct T { - // PtrS ptrS; + // PtrS ptrS; // }; // // void testint(int x); @@ -4904,18 +4894,18 @@ public class AST2Tests extends AST2BaseTest { // testptr(t-0); // testint(t-t); // testint(0-t); - // } + // } public void testTypeOfPointerOperations() throws Exception { String code= getAboveComment(); parseAndCheckBindings(code, ParserLanguage.C); parseAndCheckBindings(code, ParserLanguage.CPP); } - + // int globalArray[4] = {1,2,3,4}; // void function1(); // decl // // void function1() { - // getArray()[0] = 1; + // getArray()[0] = 1; // } // // void function2() { @@ -4933,7 +4923,7 @@ public class AST2Tests extends AST2BaseTest { assertSame(b2, b3); } } - + // #define foo __typeof__((int*)0 - (int*)0) // typedef foo ptrdiff_t; public void testRedefinePtrdiff_Bug230895() throws Exception { @@ -4946,9 +4936,9 @@ public class AST2Tests extends AST2BaseTest { ITypedef td= (ITypedef) b1; IType t= td.getType(); assertFalse(t instanceof ITypedef); - } + } } - + // int a; // int b= a; // ref // struct S; @@ -4965,9 +4955,9 @@ public class AST2Tests extends AST2BaseTest { IType t= td.getType(); assertFalse(t instanceof IProblemBinding); assertSame(t, ct); - } + } } - + // void checkLong(long); // void test() { // checkLong(__builtin_expect(1, 1)); @@ -4977,19 +4967,19 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(code, ParserLanguage.C, true); parseAndCheckBindings(code, ParserLanguage.CPP, true); } - + // typedef void VOID; // VOID func(VOID) { // } public void testTypedefVoid_Bug221567() throws Exception { - final boolean[] isCpps= {false, true}; + final boolean[] isCpps= { false, true }; String code= getAboveComment(); for (boolean isCpp : isCpps) { BindingAssertionHelper ba= new BindingAssertionHelper(code, isCpp); ITypedef td= ba.assertNonProblem("VOID;", 4, ITypedef.class); IBinding ref= ba.assertNonProblem("VOID)", 4); assertSame(td, ref); - + IFunction func= ba.assertNonProblem("func", 4, IFunction.class); IFunctionType ft= func.getType(); IType rt= ft.getReturnType(); @@ -4998,37 +4988,37 @@ public class AST2Tests extends AST2BaseTest { IType pt = pts[0]; assertInstance(rt, ITypedef.class); assertInstance(pt, ITypedef.class); - rt= ((ITypedef)rt).getType(); - pt= ((ITypedef)pt).getType(); + rt= ((ITypedef) rt).getType(); + pt= ((ITypedef) pt).getType(); assertTrue(rt instanceof IBasicType); - assertEquals(IBasicType.t_void, ((IBasicType)rt).getType()); + assertEquals(IBasicType.t_void, ((IBasicType) rt).getType()); assertTrue(pt instanceof IBasicType); - assertEquals(IBasicType.t_void, ((IBasicType)pt).getType()); + assertEquals(IBasicType.t_void, ((IBasicType) pt).getType()); } } - + // #define str(s) # s // // void foo() { // printf(str(this is a // this should go away - // string)); + // string)); // } public void testCommentInExpansion_Bug84276() throws Exception { IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment()); IASTFunctionDefinition func= (IASTFunctionDefinition) tu.getDeclarations()[0]; - + IASTFunctionCallExpression fcall= (IASTFunctionCallExpression) ((IASTExpressionStatement)((IASTCompoundStatement) func.getBody()).getStatements()[0]).getExpression(); IASTLiteralExpression lit= (IASTLiteralExpression) fcall.getParameterExpression(); assertEquals("\"this is a string\"", lit.toString()); } - + // typedef int tint; // tint f1(tint (tint)); // int f2(int (int)); // int f3(int (tint)); // int f4(int (identifier)); - // int f5(int *(tint[10])); + // int f5(int *(tint[10])); public void testParamWithFunctionType_Bug84242() throws Exception { final String comment= getAboveComment(); final boolean[] isCpps= {false, true}; @@ -5046,14 +5036,14 @@ public class AST2Tests extends AST2BaseTest { f= ba.assertNonProblem("f4", 2, IFunction.class); isTypeEqual(f.getType(), "int (int)"); - + f= ba.assertNonProblem("f5", 2, IFunction.class); isTypeEqual(f.getType(), "int (int * (*)(int *))"); } } // class C { }; - // void f1(int(C)) { } + // void f1(int(C)) { } public void testParamWithFunctionTypeCpp_Bug84242() throws Exception { BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); @@ -5071,12 +5061,12 @@ public class AST2Tests extends AST2BaseTest { IFunction f= ba.assertNonProblem("f1", 2, IFunction.class); isTypeEqual(f.getType(), "int (* (int))[5]"); - + f= ba.assertNonProblem("f1 ", 2, IFunction.class); isTypeEqual(f.getType(), "int (* (int))[5]"); } } - + // void f1() {} // void (f2)() {} // void (f3()) {} @@ -5118,7 +5108,7 @@ public class AST2Tests extends AST2BaseTest { IBinding binding= sdef.getDeclarators()[0].getName().resolveBinding(); assertInstance(binding, IFunction.class); assertEquals(2, tu.getDeclarationsInAST(binding).length); - + sdef= getDeclaration(tu, 5); binding= sdef.getDeclarators()[0].getNestedDeclarator().getName().resolveBinding(); assertInstance(binding, IFunction.class); @@ -5136,9 +5126,9 @@ public class AST2Tests extends AST2BaseTest { } } - // void f() { - // int a,b; - // { b; a; int a; } + // void f() { + // int a,b; + // { b; a; int a; } // } public void testLocalVariableResolution_Bug235831() throws Exception { final String comment= getAboveComment(); @@ -5154,7 +5144,7 @@ public class AST2Tests extends AST2BaseTest { assertNotSame(v2, v3); } } - + // int foo(int (*ptr) (int, int)); public void testComplexParameterBinding_Bug214482() throws Exception { final String comment= getAboveComment(); @@ -5165,7 +5155,7 @@ public class AST2Tests extends AST2BaseTest { assertEquals("ptr", p.getName()); } } - + // void test() {} // + public void testTrailingSyntaxErrorInTU() throws Exception { @@ -5192,7 +5182,7 @@ public class AST2Tests extends AST2BaseTest { assertEquals("+", pdecl.getRawSignature()); } } - + // void func() { // { // int test; @@ -5210,7 +5200,7 @@ public class AST2Tests extends AST2BaseTest { assertEquals("+", pstmt.getRawSignature()); } } - + // struct X { // ; // }; @@ -5226,7 +5216,7 @@ public class AST2Tests extends AST2BaseTest { assertEquals(";", empty.getRawSignature()); } } - + // void test() { // int foux = 3; // switch(foux) // no brace! @@ -5245,11 +5235,11 @@ public class AST2Tests extends AST2BaseTest { assertEquals("foux= 1;", stmt.getRawSignature()); } } - + // typedef int t; // int a,b; // void test() { - + // b* (t)+a *b // b,t,a,unary+,cast,*,b,* // b*(a) + a*b // b,a,*,a,b,*,+ // b* (t)-a *b // b,t,a,unary-,cast,*,b,* @@ -5293,7 +5283,7 @@ public class AST2Tests extends AST2BaseTest { // struct s* a; // struct s* f(struct s*); // void test() { - + // (t)(a) // t,a,cast // (f)(a) // f,a,() // (t)(t)(a) // t,t,a,cast,cast @@ -5330,7 +5320,7 @@ public class AST2Tests extends AST2BaseTest { // int a,b; // void test() { - + // 1+2+3 // 1,2,+,3,+ // a=b=1 // a,b,1,=,= // 0, a= 1 ? 2,3 : b= 4, 5 // 0,a,1,2,3,,,b,4,=,?,=,5,, @@ -5355,7 +5345,7 @@ public class AST2Tests extends AST2BaseTest { // int a,b; // void test(int a= - + // 1+2+3 // 1,2,+,3,+ // a=b=1 // a,b,1,=,= // 1 ? 2,3 : b= 4 // 1,2,3,,,b,4,=,? @@ -5413,7 +5403,7 @@ public class AST2Tests extends AST2BaseTest { assertEquals("in expr: " + exprStr, endOffset(unaryExpr), endOffset(unaryExpr.getOperand())); break; } - } + } } private int offset(IASTNode expr) { @@ -5502,25 +5492,25 @@ public class AST2Tests extends AST2BaseTest { buf.append(expr.getRawSignature()); } } - + // typedef struct { // int x; // } spinlock_t; - // spinlock_t _lock = (spinlock_t) { }; + // spinlock_t _lock = (spinlock_t) { }; public void testCompoundInitializer_bug145387() throws Exception { // valid in C99, not in C++. parseAndCheckBindings(getAboveComment(), ParserLanguage.C, true); } - + // enum __declspec(uuid("uuid")) bla { a, b}; public void testDeclspecInEnumSpecifier_bug241203() throws Exception { for (ParserLanguage lang : ParserLanguage.values()) { parseAndCheckBindings(getAboveComment(), lang, true); } } - + // struct Outer { - // struct {int a1;}; + // struct {int a1;}; // struct {int a2;} a3; // }; // void test() { @@ -5536,7 +5526,7 @@ public class AST2Tests extends AST2BaseTest { bh.assertNonProblem("a3=", 2); } } - + // void test() { // char* p; // if (__builtin_types_compatible_p(typeof(p), char[])) { @@ -5547,10 +5537,10 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(getAboveComment(), lang, true); } } - + // void alloc(const char * id) {} // void test() { - // alloc(__func__); + // alloc(__func__); // } public void testPredefinedFunctionName_Bug247747() throws Exception { parseAndCheckBindings(getAboveComment(), ParserLanguage.C, false); @@ -5559,15 +5549,15 @@ public class AST2Tests extends AST2BaseTest { // void alloc(const char * id) {} // void test() { - // alloc(__func__); - // alloc(__FUNCTION__); - // alloc(__PRETTY_FUNCTION__); + // alloc(__func__); + // alloc(__FUNCTION__); + // alloc(__PRETTY_FUNCTION__); // } public void testPredefinedFunctionNameGcc_Bug247747() throws Exception { parseAndCheckBindings(getAboveComment(), ParserLanguage.C, true); parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, true); } - + // int foo = 42; // typedef char StupidType; // StupidType const *bar = (StupidType const*)&foo; @@ -5575,11 +5565,11 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(getAboveComment(), ParserLanguage.C, true); parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, true); } - + // #define IF if // #define IF_P if ( // #define IF_P_T if (1 - // #define SEMI_IF ; if + // #define SEMI_IF ; if // #define IF_COND if (1) // void test() { public void testLeadingSyntax_Bug250251() throws Exception { @@ -5658,14 +5648,14 @@ public class AST2Tests extends AST2BaseTest { IToken syntax= x.getTrailingSyntax(); checkToken(syntax, ")", 0); syntax= syntax.getNext(); assertNull(syntax); - + tu= parseAndCheckBindings(code + "do {} while(1 );}"); f= getDeclaration(tu, 0); IASTDoStatement dstmt= getStatement(f, 0); x= dstmt.getCondition(); syntax= x.getTrailingSyntax(); checkToken(syntax, ")", 1); syntax= syntax.getNext(); checkToken(syntax, ";", 2); syntax= syntax.getNext(); assertNull(syntax); - + tu= parseAndCheckBindings(code + "if(1 ) BLOCK()}"); f= getDeclaration(tu, 0); i= getStatement(f, 0); x= i.getConditionExpression(); @@ -5705,11 +5695,11 @@ public class AST2Tests extends AST2BaseTest { } catch (ExpansionOverlapsBoundaryException e) { } } - + // #define IF if // #define IF_P if ( // #define IF_P_T if (1 - // #define SEMI_IF ; if + // #define SEMI_IF ; if // #define IF_COND if (1) // void test() { public void testSyntax_Bug250251() throws Exception { @@ -5728,7 +5718,7 @@ public class AST2Tests extends AST2BaseTest { assertNull(syntax); tu= parseAndCheckBindings(code + "if( 1) {}}"); - f= getDeclaration(tu, 0); x= getStatement(f, 0); + f= getDeclaration(tu, 0); x= getStatement(f, 0); syntax= x.getSyntax(); checkToken(syntax, "if", 0); syntax= syntax.getNext(); checkToken(syntax, "(", 2); syntax= syntax.getNext(); @@ -5761,13 +5751,13 @@ public class AST2Tests extends AST2BaseTest { private void checkToken(IToken token, String image, int offset) { assertEquals(image, token.getImage()); assertEquals(offset, token.getOffset()); - assertEquals(image.length(), token.getLength()); + assertEquals(image.length(), token.getLength()); } - + // void test() { // int x,y; // x - // << + // << // y; // } public void testSyntaxWithNL_Bug280175() throws Exception { @@ -5775,14 +5765,14 @@ public class AST2Tests extends AST2BaseTest { int offsetX= code.indexOf('x', code.indexOf('x')+1); int offsetShift= code.indexOf('<'); int offsetY= code.indexOf('y', offsetX); - + IASTTranslationUnit tu= parseAndCheckBindings(code); IASTFunctionDefinition f= getDeclaration(tu, 0); IASTExpressionStatement i = getStatement(f, 1); final IASTBinaryExpression expr = (IASTBinaryExpression) i.getExpression(); IASTExpression x= expr.getOperand1(); IASTExpression y= expr.getOperand2(); - + IToken syntax= x.getTrailingSyntax(); checkToken(syntax, "<<", offsetShift-offsetX-1); syntax= syntax.getNext(); assertNull(syntax); @@ -5834,7 +5824,7 @@ public class AST2Tests extends AST2BaseTest { assertNotNull(numericalValue); assertEquals(i, numericalValue.intValue()); } - + // void myfunc(char *arg) {} // void (*funcVar2)(char *) = myfunc; // void caller() { @@ -5859,11 +5849,11 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(code, lang); } } - + // int a[]= { - - // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - + + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // }; public void testScalabilityOfLargeTrivialInitializer_Bug253690() throws Exception { sValidateCopy= false; @@ -5882,20 +5872,20 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu= parse(code, lang, false, true, true); long diff= memoryUsed()-mem; // allow a copy of the buffer + less than 2 bytes per initializer - final int expected = code.length()*2 + AMOUNT + AMOUNT/2; + final int expected = code.length()*2 + AMOUNT + AMOUNT/2; assertTrue(String.valueOf(diff) + " expected < " + expected, diff < expected); assertTrue(tu.isFrozen()); } } - + // struct MyStrcutType {}; // MyStructType Data [1000000] = { // {1,2,3}, // 1.2, - // { - - // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - + // { + + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // } // }; public void testLargeTrivialAggregateInitializer_Bug253690() throws Exception { @@ -5915,7 +5905,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu= parse(code, lang, false, true, true); long diff= memoryUsed()-mem; // allow a copy of the buffer + not even 1 byte per initializer - final int expected = code.length()*2 + AMOUNT + AMOUNT/2; + final int expected = code.length()*2 + AMOUNT + AMOUNT/2; assertTrue(String.valueOf(diff) + " expected < " + expected, diff < expected); assertTrue(tu.isFrozen()); } @@ -5929,7 +5919,7 @@ public class AST2Tests extends AST2BaseTest { do { Thread.sleep(50); System.gc(); - mem= newMem; + mem= newMem; newMem= runtime.totalMemory()-runtime.freeMemory(); } while (newMem < mem && ++i<5); return mem; @@ -5955,17 +5945,17 @@ public class AST2Tests extends AST2BaseTest { final String code = getAboveComment(); for (ParserLanguage lang : ParserLanguage.values()) { IASTNode node= parseAndCheckBindings(code, lang); - + IASTNode[] children= node.getChildren(); assertEquals(1, children.length); assertInstance(children[0], IASTFunctionDefinition.class); - + children= children[0].getChildren(); assertEquals(3, children.length); assertInstance(children[0], IASTDeclSpecifier.class); assertInstance(children[1], IASTDeclarator.class); assertInstance(children[2], IASTCompoundStatement.class); - + children= children[2].getChildren(); assertEquals(1, children.length); assertInstance(children[0], IASTDeclarationStatement.class); @@ -5975,21 +5965,21 @@ public class AST2Tests extends AST2BaseTest { assertInstance(children[0], IASTDeclSpecifier.class); assertInstance(children[1], IASTDeclarator.class); - children= children[1].getChildren(); + children= children[1].getChildren(); assertEquals(3, children.length); assertInstance(children[0], IASTPointerOperator.class); assertInstance(children[1], IASTName.class); assertInstance(children[2], IASTInitializer.class); - children= children[2].getChildren()[0].getChildren(); // skip binary expression + children= children[2].getChildren()[0].getChildren(); // skip binary expression assertEquals(2, children.length); assertInstance(children[0], IASTLiteralExpression.class); assertInstance(children[1], IASTLiteralExpression.class); - + assertEquals(0, children[0].getChildren().length); } } - + // struct s { // int (mem); // }; @@ -6002,7 +5992,7 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(code, ParserLanguage.C); parseAndCheckBindings(code, ParserLanguage.CPP); } - + // typedef struct { // float a; // int b; @@ -6025,7 +6015,7 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(code, ParserLanguage.C, true); parseAndCheckBindings(code, ParserLanguage.CPP, true); } - + // void test() { // int a,b; // if ((a)+b); @@ -6040,7 +6030,7 @@ public class AST2Tests extends AST2BaseTest { assertInstance(expr, IASTBinaryExpression.class); } } - + // typedef int TInt; // struct X { // const TInt; // declaration without name @@ -6053,7 +6043,7 @@ public class AST2Tests extends AST2BaseTest { ITypedef td= bh.assertNonProblem("TInt; //", 4); IField f= bh.assertNonProblem("a;", 1); } - + // struct beta { // int glob; // }; @@ -6074,7 +6064,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu= parseAndCheckBindings(code, lang, true); } } - + // typedef struct A A; // struct A; // struct // struct A* a; @@ -6082,7 +6072,7 @@ public class AST2Tests extends AST2BaseTest { final String code= getAboveComment(); for (ParserLanguage lang : ParserLanguage.values()) { IASTTranslationUnit tu= parseAndCheckBindings(code, lang, true); - + BindingAssertionHelper ba= new BindingAssertionHelper(code, lang == ParserLanguage.CPP); ITypedef t= ba.assertNonProblem("A;", 1); ICompositeType s1= ba.assertNonProblem("A; // struct", 1); @@ -6091,9 +6081,32 @@ public class AST2Tests extends AST2BaseTest { assertSame(s1, t.getType()); } } - + + // typedef long unsigned int size_t; + // + // size_t a = 0; + // size_t x = a + 5; + // size_t y = 2 + a; + // size_t y = a * 2; + public void testTypeOfExpressionWithTypedef_380498() throws Exception { + final boolean[] isCpps= { false, true }; + String code= getAboveComment(); + for (boolean isCpp : isCpps) { + BindingAssertionHelper ba= new BindingAssertionHelper(code, isCpp); + IASTExpression exp = ba.assertNode("a + 5", IASTExpression.class); + assertTrue(exp.getExpressionType() instanceof ITypedef); + assertEquals("size_t", ((ITypedef) exp.getExpressionType()).getName()); + exp = ba.assertNode("2 + a", IASTExpression.class); + assertTrue(exp.getExpressionType() instanceof ITypedef); + assertEquals("size_t", ((ITypedef) exp.getExpressionType()).getName()); + exp = ba.assertNode("a * 2", IASTExpression.class); + assertTrue(exp.getExpressionType() instanceof ITypedef); + assertEquals("size_t", ((ITypedef) exp.getExpressionType()).getName()); + } + } + // typedef int TInt; - // int a= TInt; //ref + // int a= TInt; //ref public void testTypeAsExpressionIsProblem_261175() throws Exception { final String code= getAboveComment(); BindingAssertionHelper bh= new BindingAssertionHelper(code, true); @@ -6102,7 +6115,7 @@ public class AST2Tests extends AST2BaseTest { bh= new BindingAssertionHelper(code, false); bh.assertProblem("TInt; //ref", 4); } - + // typedef int x, y; // void func(int c) { // c= sizeof(x(y)); @@ -6116,7 +6129,7 @@ public class AST2Tests extends AST2BaseTest { IVariable v= ba.assertNonProblem("y);", 1); } } - + // int* v; public void testPointerOperatorsAsChildren_260461() throws Exception { final String code= getAboveComment(); @@ -6141,13 +6154,13 @@ public class AST2Tests extends AST2BaseTest { // int i = 8888uL; public void testBug269705_int_literal() throws Exception { final String code= getAboveComment(); - + for (ParserLanguage lang : ParserLanguage.values()) { IASTTranslationUnit tu = parseAndCheckBindings(code, lang); IASTDeclaration[] declarations = tu.getDeclarations(); - + // int a = -142; - { + { IBasicType t = getTypeForDeclaration(declarations, 0); assertTrue(t.getType() == IBasicType.t_int); assertFalse(t.isUnsigned()); @@ -6155,7 +6168,7 @@ public class AST2Tests extends AST2BaseTest { assertFalse(t.isLong()); assertFalse(isLongLong(t)); } - + // int b = 456L; { IBasicType t = getTypeForDeclaration(declarations, 1); @@ -6165,7 +6178,7 @@ public class AST2Tests extends AST2BaseTest { assertTrue(t.isLong()); assertFalse(isLongLong(t)); } - + // int c = 100000LL; { IBasicType t = getTypeForDeclaration(declarations, 2); @@ -6175,7 +6188,7 @@ public class AST2Tests extends AST2BaseTest { assertFalse(t.isLong()); assertTrue(isLongLong(t)); } - + // int d = 0U; { IBasicType t = getTypeForDeclaration(declarations, 3); @@ -6186,7 +6199,7 @@ public class AST2Tests extends AST2BaseTest { assertFalse(t.isLong()); } - + // int e = 1UL; { IBasicType t = getTypeForDeclaration(declarations, 4); @@ -6196,7 +6209,7 @@ public class AST2Tests extends AST2BaseTest { assertTrue(t.isLong()); assertFalse(isLongLong(t)); } - + // int f = 9u; { IBasicType t = getTypeForDeclaration(declarations, 5); @@ -6207,7 +6220,7 @@ public class AST2Tests extends AST2BaseTest { assertFalse(t.isLong()); } - + // int g = 1234l; { IBasicType t = getTypeForDeclaration(declarations, 6); @@ -6217,7 +6230,7 @@ public class AST2Tests extends AST2BaseTest { assertTrue(t.isLong()); assertFalse(isLongLong(t)); } - + // int h = -123ll; { IBasicType t = getTypeForDeclaration(declarations, 7); @@ -6227,7 +6240,7 @@ public class AST2Tests extends AST2BaseTest { assertFalse(t.isLong()); assertTrue(isLongLong(t)); } - + // int i = 8888uL; { IBasicType t = getTypeForDeclaration(declarations, 8); @@ -6310,15 +6323,15 @@ 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(); + IASTInitializer init = ((IASTSimpleDeclaration) declarations[index]).getDeclarators()[0].getInitializer(); + return (IBasicType)((IASTExpression)((IASTEqualsInitializer) init).getInitializerClause()).getExpressionType(); } // void test() { @@ -6332,7 +6345,7 @@ public class AST2Tests extends AST2BaseTest { public void testPredefinedMacroNamesC() throws Exception { parseAndCheckBindings(getAboveComment(), ParserLanguage.C); } - + // long double longDouble = 1.0; // double _double = 1.0; // float _float= 1.0; @@ -6387,7 +6400,7 @@ public class AST2Tests extends AST2BaseTest { } } } - + // double _double = 1.0; // float _float= 1.0; // long long int longLongInt = 1; @@ -6439,7 +6452,7 @@ public class AST2Tests extends AST2BaseTest { } } } - + // float _float= 1.0; // long long int longLongInt = 1; // long int longInt = 1; @@ -6486,7 +6499,7 @@ public class AST2Tests extends AST2BaseTest { } } } - + // long long int longLongInt = 1; // long int longInt = 1; // int _int = 1; @@ -6534,7 +6547,7 @@ public class AST2Tests extends AST2BaseTest { } } } - + // long long int longLongInt = 1; // long int longInt = 1; // int _int = 1; @@ -6578,7 +6591,7 @@ public class AST2Tests extends AST2BaseTest { } } } - + // int _int = 1; // short int shortInt = 1; // char _char = 1; @@ -6619,7 +6632,7 @@ public class AST2Tests extends AST2BaseTest { } } } - + // short int shortInt = 1; // char _char = 1; // @@ -6658,7 +6671,7 @@ public class AST2Tests extends AST2BaseTest { } } } - + // char _char = 1; // // float var; @@ -6692,7 +6705,7 @@ public class AST2Tests extends AST2BaseTest { } } } - + // // char _char = 1; // signed char signedChar = 1; @@ -6716,7 +6729,7 @@ public class AST2Tests extends AST2BaseTest { // // /* (3) Should be an unsigned int*/ // var = unsignedInt + signedChar; - // + // // /* (4) Should be a signed long int */ // var = signedLongInt + unsignedInt; // @@ -6724,7 +6737,7 @@ public class AST2Tests extends AST2BaseTest { // var = signedLongInt + unsignedLongInt; // // /* (6) Should be an unsigned long int*/ - // var = unsignedLongInt + signedLongInt; + // var = unsignedLongInt + signedLongInt; // } public void testTypePromotion_signedAndUnsignedInts() throws Exception { for (ParserLanguage lang : ParserLanguage.values()) { @@ -6830,8 +6843,8 @@ public class AST2Tests extends AST2BaseTest { assertFalse(type1.isLongLong()); } } - } - + } + // char c; // void func() { // c; @@ -6847,7 +6860,7 @@ public class AST2Tests extends AST2BaseTest { IBasicType t= (IBasicType) expr.getExpressionType(); assertEquals(Kind.eChar, t.getKind()); assertEquals(0, t.getModifiers()); - + for (int i = 1; i < 4; i++) { expr= getExpressionOfStatement(fdef, i); t= (IBasicType) expr.getExpressionType(); @@ -6856,16 +6869,16 @@ public class AST2Tests extends AST2BaseTest { } } } - + // // int MyGlobal[10]; // public void testBug273797() throws Exception { IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.C); - IASTName n = ((IASTSimpleDeclaration)tu.getDeclarations()[0]).getDeclarators()[0].getName(); + IASTName n = ((IASTSimpleDeclaration) tu.getDeclarations()[0]).getDeclarators()[0].getName(); IVariable v = (IVariable) n.resolveBinding(); - - ICArrayType t = (ICArrayType)v.getType(); + + ICArrayType t = (ICArrayType) v.getType(); assertFalse(t.isConst()); assertFalse(t.isRestrict()); assertFalse(t.isVolatile()); @@ -6884,9 +6897,9 @@ public class AST2Tests extends AST2BaseTest { // } public void testBug278797() throws Exception { IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.C); - IASTFunctionDefinition func = (IASTFunctionDefinition)tu.getDeclarations()[1]; - IASTExpressionStatement stmt = ((IASTExpressionStatement)((IASTCompoundStatement)func.getBody()).getStatements()[0]); - IType t = ((IASTCastExpression)stmt.getExpression()).getOperand().getExpressionType(); + IASTFunctionDefinition func = (IASTFunctionDefinition) tu.getDeclarations()[1]; + IASTExpressionStatement stmt = ((IASTExpressionStatement)((IASTCompoundStatement) func.getBody()).getStatements()[0]); + IType t = ((IASTCastExpression) stmt.getExpression()).getOperand().getExpressionType(); assertNotNull(t); assertTrue(t instanceof IEnumeration); } @@ -6902,39 +6915,39 @@ public class AST2Tests extends AST2BaseTest { //int a[2][3] = {{1,2,3},{4,5,6}}; { IASTDeclaration d = tu.getDeclarations()[0]; - IBinding b = ((IASTSimpleDeclaration)d).getDeclarators()[0].getName().resolveBinding(); - IType t = ((IVariable)b).getType(); + IBinding b = ((IASTSimpleDeclaration) d).getDeclarators()[0].getName().resolveBinding(); + IType t = ((IVariable) b).getType(); assertTrue(t instanceof IArrayType); - IArrayType at1 = (IArrayType)t; + IArrayType at1 = (IArrayType) t; IASTExpression size1 = at1.getArraySizeExpression(); assertTrue(at1.getType() instanceof IArrayType); IArrayType at2 = (IArrayType) at1.getType(); IASTExpression size2 = at2.getArraySizeExpression(); assertTrue(size1 instanceof IASTLiteralExpression); - assertEquals(((IASTLiteralExpression)size1).getValue()[0], '2'); + assertEquals(((IASTLiteralExpression) size1).getValue()[0], '2'); assertTrue(size2 instanceof IASTLiteralExpression); - assertEquals(((IASTLiteralExpression)size2).getValue()[0], '3'); + assertEquals(((IASTLiteralExpression) size2).getValue()[0], '3'); } //int b[3][2] = {{1,2},{3,4},{5,6}}; { IASTDeclaration d = tu.getDeclarations()[1]; - IBinding b = ((IASTSimpleDeclaration)d).getDeclarators()[0].getName().resolveBinding(); - IType t = ((IVariable)b).getType(); + IBinding b = ((IASTSimpleDeclaration) d).getDeclarators()[0].getName().resolveBinding(); + IType t = ((IVariable) b).getType(); assertTrue(t instanceof IArrayType); - IArrayType at1 = (IArrayType)t; + IArrayType at1 = (IArrayType) t; IASTExpression size1 = at1.getArraySizeExpression(); assertTrue(at1.getType() instanceof IArrayType); IArrayType at2 = (IArrayType) at1.getType(); IASTExpression size2 = at2.getArraySizeExpression(); assertTrue(size1 instanceof IASTLiteralExpression); - assertEquals(((IASTLiteralExpression)size1).getValue()[0], '3'); + assertEquals(((IASTLiteralExpression) size1).getValue()[0], '3'); assertTrue(size2 instanceof IASTLiteralExpression); - assertEquals(((IASTLiteralExpression)size2).getValue()[0], '2'); + assertEquals(((IASTLiteralExpression) size2).getValue()[0], '2'); } } } - // /* Check that a parameter declared as a typedef'd array + // /* Check that a parameter declared as a typedef'd array // * is treated as a pointer // */ //typedef int my_buf[16]; @@ -6948,7 +6961,7 @@ public class AST2Tests extends AST2BaseTest { assertTrue(((IFunction) n.resolveBinding()).getType().getParameterTypes()[0] instanceof IPointerType); } } - + // // /* check that enumerator values are evaluated correctly for // * conditional expressions */ @@ -6962,7 +6975,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug295851() throws Exception { for (ParserLanguage lang : ParserLanguage.values()) { IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), lang); - IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier)((IASTSimpleDeclaration)tu.getDeclarations()[0]).getDeclSpecifier(); + IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier)((IASTSimpleDeclaration) tu.getDeclarations()[0]).getDeclSpecifier(); IEnumerator enumeratorBinding = (IEnumerator) enumSpec.getEnumerators()[0].getName().resolveBinding(); IValue value = enumeratorBinding.getValue(); assertEquals(2, value.numericalValue().longValue()); @@ -6984,30 +6997,30 @@ public class AST2Tests extends AST2BaseTest { // } public void testBindingsOnFields() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, false); - IASTCompoundStatement bodyStmt = (IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[2]).getBody(); + IASTCompoundStatement bodyStmt = (IASTCompoundStatement)((IASTFunctionDefinition) tu.getDeclarations()[2]).getBody(); // Get the IFields bindings from the type used in the declaration of structure - IASTName n = ((IASTSimpleDeclaration)((IASTDeclarationStatement)bodyStmt.getStatements()[0]).getDeclaration()).getDeclarators()[0].getName(); - ICompositeType t = (ICompositeType)((IVariable)n.resolveBinding()).getType(); + IASTName n = ((IASTSimpleDeclaration)((IASTDeclarationStatement) bodyStmt.getStatements()[0]).getDeclaration()).getDeclarators()[0].getName(); + ICompositeType t = (ICompositeType)((IVariable) n.resolveBinding()).getType(); IField[] fields = t.getFields(); assertTrue(fields.length == 2); // Get the IField for the first assignment - IASTFieldReference ref1 = (IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement)bodyStmt.getStatements()[1]).getExpression()).getOperand1(); + IASTFieldReference ref1 = (IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement) bodyStmt.getStatements()[1]).getExpression()).getOperand1(); IBinding field1 = ref1.getFieldName().resolveBinding(); - + // Get the IField for the second assignment - IASTFieldReference ref2 = (IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement)bodyStmt.getStatements()[2]).getExpression()).getOperand1(); + IASTFieldReference ref2 = (IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement) bodyStmt.getStatements()[2]).getExpression()).getOperand1(); IBinding field2 = ref2.getFieldName().resolveBinding(); // Compare the IField from the type and the assignments assertEquals(fields[0], field1); assertEquals(fields[1], field2); // fails - + assertEquals(1, ((ICInternalBinding) field1).getDeclarations().length); assertEquals(1, ((ICInternalBinding) field2).getDeclarations().length); } - + // /* // * Check that the type returned by CASTArraySubscriptExpression // * handles typedefs correctly. @@ -7025,7 +7038,7 @@ public class AST2Tests extends AST2BaseTest { // newArray var5; // // void foo() { - // /* The type of the arraysubscript expression should be struct s + // /* The type of the arraysubscript expression should be struct s // * each of the following statements // */ // var1[1].a = 1; @@ -7045,13 +7058,13 @@ public class AST2Tests extends AST2BaseTest { IASTExpression owner = ((IASTFieldReference) op1).getFieldOwner(); IType t = owner.getExpressionType(); assertTrue(t instanceof ICompositeType); - assertEquals("s",((ICompositeType)t).getName()); + assertEquals("s", ((ICompositeType) t).getName()); } } } } } - + // char array[10]; // char* ptr; // @@ -7076,7 +7089,7 @@ public class AST2Tests extends AST2BaseTest { } } } - + // extern int a[]; // int a[1]; public void testIncompleteArrays_269926() throws Exception { @@ -7084,7 +7097,7 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(code, ParserLanguage.C); parseAndCheckBindings(code, ParserLanguage.CPP); } - + // void f1(const int* p); // void f2(const int* p) {} public void testDroppingOfStorageDecl_293322() throws Exception { @@ -7095,7 +7108,7 @@ public class AST2Tests extends AST2BaseTest { f= bh.assertNonProblem("f2", 2); assertEquals("const int *", ASTTypeUtil.getType(f.getParameters()[0].getType())); } - + // typedef int f(int); // f ff; public void testFunctionDeclViaTypedef_86495() throws Exception { @@ -7108,9 +7121,9 @@ public class AST2Tests extends AST2BaseTest { assertEquals(1, ff.getParameters().length); } } - + // void f() { - // int a= + // int a= public void testLargeExpression_294029() throws Exception { // when running the test in a suite, it cannot handle more than 160 parenthesis. // run as a single test it does > 500. @@ -7131,13 +7144,13 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parseAndCheckBindings(code, lang); } } - + // static a[2]= {0,0}; public void testSkipAggregateInitializer_297550() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code, ParserLanguage.C, false, true); } - + // typeof(b(1)) b(int); public void testRecursiveFunctionType_321856() throws Exception { final String code = getAboveComment(); @@ -7146,7 +7159,7 @@ public class AST2Tests extends AST2BaseTest { f= bh.assertNonProblem("b(int)", 1); f.getType(); } - + public void testDeepBinaryExpression_294969() throws Exception { sValidateCopy= false; StringBuilder buf= new StringBuilder("void f() {0"); @@ -7159,7 +7172,7 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parseAndCheckBindings(code, lang); } } - + public void testDeepElseif_298455() throws Exception { sValidateCopy= false; StringBuilder buf= new StringBuilder("void f() {if (0) {}"); @@ -7179,7 +7192,7 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(code, ParserLanguage.C, true); parseAndCheckBindings(code, ParserLanguage.CPP, true); } - + // void func(int* obj) { // int* obj = 0; // } @@ -7192,7 +7205,7 @@ public class AST2Tests extends AST2BaseTest { bh.assertNonProblem("obj", 3, IParameter.class); bh.assertProblem("obj =", 3); } - + // #define ONCE() PRAGMA(once) // #define PRAGMA(x) _Pragma(#x) // #pragma once @@ -7216,7 +7229,7 @@ public class AST2Tests extends AST2BaseTest { assertEquals(i>2, ((IASTPreprocessorPragmaStatement) stmt).isPragmaOperator()); } } - + // int min(int,int); // void test() { // int a= (min)(1, 2); @@ -7226,7 +7239,7 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(code, ParserLanguage.C, true); parseAndCheckBindings(code, ParserLanguage.CPP, true); } - + // #define MACRO // void funca(){ // } @@ -7243,20 +7256,20 @@ public class AST2Tests extends AST2BaseTest { assertEquals("MACRO", t.getImage()); } } - + // typedef __builtin_va_list va_list; // #define va_arg(v,l) __builtin_va_arg(v,l) // void test(int c, ...) { // int (*x)[3]; // va_list list; - // x = va_arg(list, int(*)[3]); + // x = va_arg(list, int(*)[3]); // } public void testVaArgWithFunctionPtr_311030() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code, ParserLanguage.C, true); parseAndCheckBindings(code, ParserLanguage.CPP, true); } - + // void test() { // __builtin_va_list result; // } @@ -7272,7 +7285,7 @@ public class AST2Tests extends AST2BaseTest { assertInstance(var, IVariable.class); assertTrue(var.getScope().getKind() == EScopeKind.eLocal); } - + // void foo(int i); // void foo(int j) { } public void testParameterBindings_316931() throws Exception { @@ -7283,15 +7296,15 @@ public class AST2Tests extends AST2BaseTest { IParameter i= bh.assertNonProblem("i)", 1); IParameter j= bh.assertNonProblem("j)", 1); assertSame(i, j); - + IASTTranslationUnit tu= bh.getTranslationUnit(); IASTName[] decls = tu.getDeclarationsInAST(i); assertEquals(2, decls.length); decls = tu.getDeclarationsInAST(j); assertEquals(2, decls.length); } - } - + } + // typedef __typeof__((int*)0-(int*)0) ptrdiff_t; // typedef __typeof__(sizeof(int)) size_t; public void testPtrDiffRecursion_317004() throws Exception { @@ -7312,14 +7325,14 @@ public class AST2Tests extends AST2BaseTest { td= bh.assertNonProblem("size_t", 0); assertEquals("unsigned long int", ASTTypeUtil.getType(td.getType())); } - + // void f(int a) { // int tmp = a; // } // void f(int); public void testParameterResolution() throws Exception { final String code = getAboveComment(); - + BindingAssertionHelper bh= new BindingAssertionHelper(code, true); bh.assertNonProblem("f(int a)", 1); bh.assertNonProblem("f(int)", 1); @@ -7342,12 +7355,11 @@ public class AST2Tests extends AST2BaseTest { assertFalse(stmts[1].isActive()); assertFalse(stmts[2].isActive()); assertTrue(stmts[3].isActive()); - + assertFalse(((IASTPreprocessorIfdefStatement) stmts[0]).taken()); assertFalse(((IASTPreprocessorIfdefStatement) stmts[1]).taken()); - } - - + } + // void a() { // typedef float size_t; // sizeof(10); // wrong - getExpressionType returns float @@ -7369,15 +7381,15 @@ public class AST2Tests extends AST2BaseTest { es= getStatement(a, 2); assertEquals("unsigned long int", ASTTypeUtil.getType(es.getExpression().getExpressionType())); } - + // void foo(){ // typedef int foobar_t; // foobar_t *a = 0, *b = a; // } public void testAmbiguousStatement_Bug360541() throws Exception { parseAndCheckBindings(); - } - + } + // typedef int T[sizeof(int)]; public void testSizeofExpression_Bug362464() throws Exception { String code= getAboveComment(); @@ -7389,8 +7401,8 @@ public class AST2Tests extends AST2BaseTest { IValue v= at.getSize(); assertTrue(v.numericalValue() == 4); } - } - + } + // #define NULL_STATEMENT_MACRO ;; // void macro_test() { // NULL_STATEMENT_MACRO //comment diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/extension/CLanguageData.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/extension/CLanguageData.java index b8ed907138d..55c90586e8d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/extension/CLanguageData.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/extension/CLanguageData.java @@ -6,15 +6,15 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Intel Corporation - Initial API and implementation + * Intel Corporation - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.settings.model.extension; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; public abstract class CLanguageData extends CDataObject { + protected CLanguageData() { - } // public abstract CDataObject[] getChildrenOfKind(int kind); @@ -52,7 +52,7 @@ public abstract class CLanguageData extends CDataObject { public abstract void setSourceExtensions(String exts[]); - public boolean containsDiscoveredScannerInfo(){ + public boolean containsDiscoveredScannerInfo() { return true; } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescription.java index e140e2f0bc0..bab280e25f4 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescription.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Intel Corporation - Initial API and implementation - * James Blackburn (Broadcom Corp.) - * Baltasar Belyavsky (Texas Instruments) - bug 340219: Project metadata files are saved unnecessarily + * Intel Corporation - Initial API and implementation + * James Blackburn (Broadcom Corp.) + * Baltasar Belyavsky (Texas Instruments) - bug 340219: Project metadata files are saved unnecessarily *******************************************************************************/ package org.eclipse.cdt.internal.core.settings.model; @@ -62,21 +62,21 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon private boolean fNeedsPersistance; private boolean fIsCfgModified; - CfgIdPair(CfgIdPair base){ + CfgIdPair(CfgIdPair base) { fId = base.fId; fPersistanceName = base.fPersistanceName; } - CfgIdPair(QualifiedName persistanceName){ + CfgIdPair(QualifiedName persistanceName) { fPersistanceName = persistanceName; } - public String getId(){ - if(fId == null){ + public String getId() { + if (fId == null) { fId = load(); - if(fId == null){ + if (fId == null) { fId = getFirstCfgId(); - if(fId != null){ + if (fId != null) { fNeedsPersistance = true; } } @@ -85,13 +85,13 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon } public ICConfigurationDescription getConfiguration() { - if(fCfg == null){ + if (fCfg == null) { String id = getId(); - if(id != null){ + if (id != null) { fCfg = getConfigurationById(id); - if(fCfg == null){ + if (fCfg == null) { fId = getFirstCfgId(); - if(fId != null){ + if (fId != null) { fCfg = getConfigurationById(fId); fNeedsPersistance = true; } @@ -101,11 +101,11 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon return fCfg; } - public void setConfiguration(ICConfigurationDescription cfg){ - if(cfg.getProjectDescription() != CProjectDescription.this) + public void setConfiguration(ICConfigurationDescription cfg) { + if (cfg.getProjectDescription() != CProjectDescription.this) throw new IllegalArgumentException(); - if(cfg.getId().equals(getId())) + if (cfg.getId().equals(getId())) return; fCfg = cfg; @@ -114,11 +114,11 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon fNeedsPersistance = true; } - public void configurationRemoved(ICConfigurationDescription cfg){ - if(cfg.getProjectDescription() != CProjectDescription.this) + public void configurationRemoved(ICConfigurationDescription cfg) { + if (cfg.getProjectDescription() != CProjectDescription.this) throw new IllegalArgumentException(); - if(!cfg.getId().equals(getId())) + if (!cfg.getId().equals(getId())) return; fIsCfgModified = true; @@ -126,7 +126,7 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon getConfiguration(); } - private String load(){ + private String load() { try { return getProject().getPersistentProperty(fPersistanceName); } catch (CoreException e) { @@ -135,8 +135,8 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon return null; } - private boolean store(String oldId, boolean force){ - if(force || fIsCfgModified || fNeedsPersistance || oldId == null || !oldId.equals(fId)){ + private boolean store(String oldId, boolean force) { + if (force || fIsCfgModified || fNeedsPersistance || oldId == null || !oldId.equals(fId)) { try { getProject().setPersistentProperty(fPersistanceName, fId); fIsCfgModified = false; @@ -162,7 +162,7 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon fIsCreating = isCreating; ICStorageElement el = null; CProjectDescriptionManager mngr = CProjectDescriptionManager.getInstance(); - if(loading){ + if (loading) { Map cfgStorMap = mngr.createCfgStorages(this); for (ICStorageElement sel : cfgStorMap.values()) { @@ -174,22 +174,22 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon } fPrefs = new CProjectDescriptionPreferences(el, - (CProjectDescriptionPreferences)mngr.getProjectDescriptionWorkspacePreferences(false), + (CProjectDescriptionPreferences) mngr.getProjectDescriptionWorkspacePreferences(false), false); fPropertiesMap = new HashMap(); } - public void updateProject(IProject project){ + public void updateProject(IProject project) { fProject = project; } - public void loadDatas(){ - if(!fIsReadOnly || !fIsLoading) + public void loadDatas() { + if (!fIsReadOnly || !fIsLoading) return; - for(Iterator iter = fCfgMap.values().iterator(); iter.hasNext();){ - CConfigurationDescriptionCache cache = (CConfigurationDescriptionCache)iter.next(); + for (Iterator iter = fCfgMap.values().iterator(); iter.hasNext();) { + CConfigurationDescriptionCache cache = (CConfigurationDescriptionCache) iter.next(); try { cache.loadData(); } catch (CoreException e) { @@ -203,15 +203,15 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon // fIsLoading = false; } - public boolean applyDatas(SettingsContext context){ - if(!fIsReadOnly || !fIsApplying) + public boolean applyDatas(SettingsContext context) { + if (!fIsReadOnly || !fIsApplying) return false; boolean modified = false; for (Iterator iter = fCfgMap.values().iterator(); iter.hasNext();) { - CConfigurationDescriptionCache cache = (CConfigurationDescriptionCache)iter.next(); + CConfigurationDescriptionCache cache = (CConfigurationDescriptionCache) iter.next(); try { - if(cache.applyData(context)) + if (cache.applyData(context)) modified = true; } catch (CoreException e) { CCorePlugin.log(e); @@ -233,7 +233,7 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon * setModified (false) * set the ICSettingsStorage to readonly */ - public void doneApplying(){ + public void doneApplying() { doneInitializing(); fIsApplying = false; @@ -246,31 +246,31 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon setModified(false); } - public void doneLoading(){ + public void doneLoading() { doneInitializing(); fIsLoading = false; } - public void setLoading(boolean loading){ + public void setLoading(boolean loading) { fIsLoading = loading; } - private void doneInitializing(){ + private void doneInitializing() { for (ICConfigurationDescription cfg : fCfgMap.values()) { // FIXME How and why are we down casting to a CConfigurationDescriptionCache. Comments, please! - CConfigurationDescriptionCache cache = (CConfigurationDescriptionCache)cfg; + CConfigurationDescriptionCache cache = (CConfigurationDescriptionCache) cfg; cache.doneInitialization(); } - if(fIsReadOnly) + if (fIsReadOnly) fPrefs.setReadOnly(true); } - public boolean isLoading(){ + public boolean isLoading() { return fIsLoading; } - public boolean isApplying(){ + public boolean isApplying() { return fIsApplying; } @@ -296,30 +296,30 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon fPrefs = new CProjectDescriptionPreferences(base.fPrefs, (CProjectDescriptionPreferences)CProjectDescriptionManager.getInstance().getProjectDescriptionWorkspacePreferences(false), false); - for(Iterator iter = base.fCfgMap.values().iterator(); iter.hasNext();){ + for (Iterator iter = base.fCfgMap.values().iterator(); iter.hasNext();) { try { - IInternalCCfgInfo cfgDes = (IInternalCCfgInfo)iter.next(); - if(fIsReadOnly){ + IInternalCCfgInfo cfgDes = (IInternalCCfgInfo) iter.next(); + if (fIsReadOnly) { CConfigurationData baseData = cfgDes.getConfigurationData(false); CConfigurationDescriptionCache baseCache = null; - if(baseData instanceof CConfigurationDescriptionCache){ - baseCache = (CConfigurationDescriptionCache)baseData; + if (baseData instanceof CConfigurationDescriptionCache) { + baseCache = (CConfigurationDescriptionCache) baseData; baseData = baseCache.getConfigurationData(); } - CConfigurationDescriptionCache cache = new CConfigurationDescriptionCache((ICConfigurationDescription)cfgDes, baseData, baseCache, cfgDes.getSpecSettings(), this, null); + CConfigurationDescriptionCache cache = new CConfigurationDescriptionCache((ICConfigurationDescription) cfgDes, baseData, baseCache, cfgDes.getSpecSettings(), this, null); configurationCreated(cache); } else { CConfigurationData baseData = cfgDes.getConfigurationData(false); CConfigurationDescription cfg = new CConfigurationDescription(baseData, this); configurationCreated(cfg); } - } catch (CoreException e){ + } catch (CoreException e) { CCorePlugin.log(e); } } @SuppressWarnings("unchecked") - HashMap cloneMap = (HashMap)base.fPropertiesMap.clone(); + HashMap cloneMap = (HashMap) base.fPropertiesMap.clone(); fPropertiesMap = cloneMap; } @@ -328,14 +328,13 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon * This occurs during the SetCProjectDescription Operation */ void switchToCachedConfigurationDescriptions() throws CoreException { - for (Map.Entry e : fCfgMap.entrySet()) { if (e.getValue() instanceof CConfigurationDescription) { - CConfigurationDescription cfgDes = (CConfigurationDescription)e.getValue(); - CConfigurationData baseData = ((IInternalCCfgInfo)cfgDes).getConfigurationData(false); + CConfigurationDescription cfgDes = (CConfigurationDescription) e.getValue(); + CConfigurationData baseData = ((IInternalCCfgInfo) cfgDes).getConfigurationData(false); CConfigurationDescriptionCache baseCache = null; - if(baseData instanceof CConfigurationDescriptionCache){ - baseCache = (CConfigurationDescriptionCache)baseData; + if (baseData instanceof CConfigurationDescriptionCache) { + baseCache = (CConfigurationDescriptionCache) baseData; baseData = baseCache.getConfigurationData(); } CConfigurationDescriptionCache cache = new CConfigurationDescriptionCache(cfgDes, baseData, baseCache, @@ -345,14 +344,14 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon } } - void configurationCreated(ICConfigurationDescription des){ + void configurationCreated(ICConfigurationDescription des) { fCfgMap.put(des.getId(), des); } @Override public ICConfigurationDescription createConfiguration(String id, String name, ICConfigurationDescription base) throws CoreException{ - if(fIsReadOnly) + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); CConfigurationDescription cfg = new CConfigurationDescription(id, name, base, this); configurationCreated(cfg); @@ -364,8 +363,8 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon return fActiveCfgInfo.getConfiguration(); } - private String getFirstCfgId(){ - if(!fCfgMap.isEmpty()){ + private String getFirstCfgId() { + if (!fCfgMap.isEmpty()) { return fCfgMap.keySet().iterator().next(); } return null; @@ -378,9 +377,9 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon @Override public ICConfigurationDescription getConfigurationByName(String name) { - for(Iterator iter = fCfgMap.values().iterator(); iter.hasNext();){ + for (Iterator iter = fCfgMap.values().iterator(); iter.hasNext();) { ICConfigurationDescription cfg = iter.next(); - if(name.equals(cfg.getName())) + if (name.equals(cfg.getName())) return cfg; } return null; @@ -393,18 +392,17 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon @Override public void removeConfiguration(String name) throws WriteAccessException { - if(fIsReadOnly) + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); - CConfigurationDescription cfgDes = (CConfigurationDescription)getConfigurationByName(name); - if(cfgDes != null){ + CConfigurationDescription cfgDes = (CConfigurationDescription) getConfigurationByName(name); + if (cfgDes != null) { cfgDes.removeConfiguration(); } - } - void configurationRemoved(CConfigurationDescription des){ + void configurationRemoved(CConfigurationDescription des) { fCfgMap.remove(des.getId()); fIsModified = true; @@ -414,25 +412,24 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon @Override public void removeConfiguration(ICConfigurationDescription cfg) throws WriteAccessException { - if(fIsReadOnly) + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); - ((CConfigurationDescription)cfg).removeConfiguration(); + ((CConfigurationDescription) cfg).removeConfiguration(); } @Override public void setActiveConfiguration( ICConfigurationDescription cfg) throws WriteAccessException { - if(fIsReadOnly) + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); - if(cfg == null) + if (cfg == null) throw new NullPointerException(); fActiveCfgInfo.setConfiguration(cfg); - if(getConfigurationRelations() == CONFIGS_LINK_SETTINGS_AND_ACTIVE) + if (getConfigurationRelations() == CONFIGS_LINK_SETTINGS_AND_ACTIVE) fSettingCfgInfo.setConfiguration(cfg); - } @Override @@ -492,10 +489,10 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon @Override public void updateChild(CDataProxy child, boolean write) { - if(write){ + if (write) { try { String oldId = child.getId(); - CConfigurationDescription cfgDes = ((CConfigurationDescription)child); + CConfigurationDescription cfgDes = ((CConfigurationDescription) child); cfgDes.doWritable(); updateMap(cfgDes, oldId); } catch (CoreException e) { @@ -504,8 +501,8 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon } } - void updateMap(CConfigurationDescription des, String oldId){ - if(!oldId.equals(des.getId())){ + void updateMap(CConfigurationDescription des, String oldId) { + if (!oldId.equals(des.getId())) { fCfgMap.remove(oldId); fCfgMap.put(des.getId(), des); } @@ -515,26 +512,26 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon if (fRootStorageElement == null) throw ExceptionFactory.createCoreException("CProjectDescription ICStorageElement == null"); //$NON-NLS-1$ -// if(fRootStorageElement == null){ +// if (fRootStorageElement == null) { // fRootStorageElement = CProjectDescriptionManager.getInstance().createStorage(fProject, true, true, isReadOnly()); // } return fRootStorageElement; } -// ICStorageElement doGetCachedRootStorageElement(){ +// ICStorageElement doGetCachedRootStorageElement() { // return fRootStorageElement; // } ICSettingsStorage getStorageBase() throws CoreException{ - if(fStorage == null) -// fStorage = new CStorage((InternalXmlStorageElement)getRootStorageElement()); + if (fStorage == null) +// fStorage = new CStorage((InternalXmlStorageElement) getRootStorageElement()); throw ExceptionFactory.createCoreException("CProjectDescription ICSettingsStorage == null"); //$NON-NLS-1$ return fStorage; } @Override public ICConfigurationDescription createConfiguration(String buildSystemId, CConfigurationData data) throws CoreException { - if(fIsReadOnly) + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); CConfigurationDescription cfg = new CConfigurationDescription(data, buildSystemId, this); configurationCreated(cfg); @@ -542,7 +539,7 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon } public CConfigurationDescription createConvertedConfiguration(String id, String name, ICStorageElement el) throws CoreException{ - if(fIsReadOnly) + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); CConfigurationDescription cfg = new CConfigurationDescription(id, name, el, this); configurationCreated(cfg); @@ -550,47 +547,48 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon } boolean needsDescriptionPersistence() { - if(fIsModified) + if (fIsModified) return true; - if(fPrefs.isModified()) + if (fPrefs.isModified()) return true; - if(fStorage.isModified()) + if (fStorage.isModified()) return true; - for(ICConfigurationDescription cfgDes : fCfgMap.values()) - if(cfgDes.isModified()) + for (ICConfigurationDescription cfgDes : fCfgMap.values()) { + if (cfgDes.isModified()) return true; + } return false; } @Override public boolean isModified() { - if(needsDescriptionPersistence()) + if (needsDescriptionPersistence()) return true; - if(needsActiveCfgPersistence()) + if (needsActiveCfgPersistence()) return true; - if(needsSettingCfgPersistence()) + if (needsSettingCfgPersistence()) return true; return false; } - private void setModified(boolean modified){ + private void setModified(boolean modified) { fIsModified = modified; - if(!modified){ + if (!modified) { fActiveCfgInfo.fIsCfgModified = false; fSettingCfgInfo.fIsCfgModified = false; fPrefs.setModified(false); - //no need to do that for config cache since they always maintain the "isModified == false" + // no need to do that for config cache since they always maintain the "isModified == false" } } @@ -614,8 +612,8 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon } @Override - public ICConfigurationDescription getDefaultSettingConfiguration(){ - if(getConfigurationRelations() == CONFIGS_LINK_SETTINGS_AND_ACTIVE) + public ICConfigurationDescription getDefaultSettingConfiguration() { + if (getConfigurationRelations() == CONFIGS_LINK_SETTINGS_AND_ACTIVE) return getActiveConfiguration(); return fSettingCfgInfo.getConfiguration(); @@ -623,14 +621,14 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon @Override public void setDefaultSettingConfiguration(ICConfigurationDescription cfg) throws WriteAccessException { - if(fIsReadOnly) + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); - if(cfg == null) + if (cfg == null) throw new NullPointerException(); fSettingCfgInfo.setConfiguration(cfg); - if(getConfigurationRelations() == CONFIGS_LINK_SETTINGS_AND_ACTIVE) + if (getConfigurationRelations() == CONFIGS_LINK_SETTINGS_AND_ACTIVE) fActiveCfgInfo.setConfiguration(cfg); } @@ -641,10 +639,11 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon @Override public void setSessionProperty(QualifiedName name, Object value) { - if(value != null) + if (value != null) { fPropertiesMap.put(name, value); - else + } else { fPropertiesMap.remove(name); + } fIsModified = true; } @@ -654,41 +653,41 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon getStorageBase().removeStorage(id); } - void switchToCachedAppliedData(CProjectDescription appliedCache){ - if(fIsReadOnly) + void switchToCachedAppliedData(CProjectDescription appliedCache) { + if (fIsReadOnly) return; ICConfigurationDescription[] cfgs = appliedCache.getConfigurations(); - for(int i = 0; i < cfgs.length; i++){ - CConfigurationDescriptionCache cfgCache = (CConfigurationDescriptionCache)cfgs[i]; - CConfigurationDescription des = (CConfigurationDescription)getChildSettingById(cfgCache.getId()); - if(des != null){ + for (int i = 0; i < cfgs.length; i++) { + CConfigurationDescriptionCache cfgCache = (CConfigurationDescriptionCache) cfgs[i]; + CConfigurationDescription des = (CConfigurationDescription) getChildSettingById(cfgCache.getId()); + if (des != null) { des.setData(cfgCache); // ICResourceDescription rcDes = des.getResourceDescription(new Path("dd"), false); // rcDes = des.getResourceDescription(new Path("dd"), false); // ICBuildSetting bs = des.getBuildSetting(); -// ICLanguageSetting lss[] = ((ICFolderDescription)rcDes).getLanguageSettings(); +// ICLanguageSetting lss[] = ((ICFolderDescription) rcDes).getLanguageSettings(); } } } - boolean checkPersistActiveCfg(String oldId, boolean force){ + boolean checkPersistActiveCfg(String oldId, boolean force) { return fActiveCfgInfo.store(oldId, force); } - boolean checkPersistSettingCfg(String oldId, boolean force){ + boolean checkPersistSettingCfg(String oldId, boolean force) { return fSettingCfgInfo.store(oldId, force); } - boolean needsActiveCfgPersistence(){ + boolean needsActiveCfgPersistence() { return fActiveCfgInfo.fIsCfgModified; } - boolean needsSettingCfgPersistence(){ + boolean needsSettingCfgPersistence() { return fSettingCfgInfo.fIsCfgModified; } - CProjectDescriptionPreferences getPreferences(){ + CProjectDescriptionPreferences getPreferences() { return fPrefs; } @@ -719,10 +718,10 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon @Override public void setCdtProjectCreated() { - if(!fIsCreating) + if (!fIsCreating) return; - if(fIsReadOnly) + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); fIsCreating = false; @@ -730,11 +729,9 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon } public void touch() throws WriteAccessException { - if(fIsReadOnly) + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); fIsModified = true; } - - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java index 6bceaa29dca..ee0d6e2fb11 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java @@ -45,8 +45,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; /** - * This is a utility class to help convert AST elements to Strings corresponding to the - * AST element's type. + * This is a utility class to help convert AST elements to Strings corresponding to + * the AST element's type. * * @noextend This class is not intended to be subclassed by clients. * @noinstantiate This class is not intended to be instantiated by clients. @@ -58,9 +58,9 @@ public class ASTTypeUtil { private static final int DEAULT_ITYPE_SIZE = 2; /** - * Returns a string representation for the parameters of the given function type. The - * representation contains the comma-separated list of the normalized parameter type - * representations wrapped in parentheses. + * Returns a string representation for the parameters of the given function type. + * The representation contains the comma-separated list of the normalized parameter + * type representations wrapped in parentheses. */ public static String getParameterTypeString(IFunctionType type) { StringBuilder result = new StringBuilder(); @@ -493,7 +493,7 @@ public class ASTTypeUtil { } else { if (type instanceof ICPPReferenceType) { // reference types ignore cv-qualifiers - cvq=null; + cvq= null; // lvalue references win over rvalue references if (ref == null || ref.isRValueReference()) { // delay reference to see if there are more @@ -599,23 +599,24 @@ public class ASTTypeUtil { * * @noreference This method is not intended to be referenced by clients. */ - public static String getType(IASTDeclarator decltor) { + public static String getType(IASTDeclarator declarator) { // get the most nested declarator - while (decltor.getNestedDeclarator() != null) - decltor = decltor.getNestedDeclarator(); + while (declarator.getNestedDeclarator() != null) { + declarator = declarator.getNestedDeclarator(); + } - IBinding binding = decltor.getName().resolveBinding(); + IBinding binding = declarator.getName().resolveBinding(); IType type = null; try { if (binding instanceof IEnumerator) { - type = ((IEnumerator)binding).getType(); + type = ((IEnumerator) binding).getType(); } else if (binding instanceof IFunction) { - type = ((IFunction)binding).getType(); + type = ((IFunction) binding).getType(); } else if (binding instanceof ITypedef) { - type = ((ITypedef)binding).getType(); + type = ((ITypedef) binding).getType(); } else if (binding instanceof IVariable) { - type = ((IVariable)binding).getType(); + type = ((IVariable) binding).getType(); } } catch (DOMException e) { return EMPTY_STRING; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNodeSelector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNodeSelector.java index fea86d7c702..e418d73e41f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNodeSelector.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNodeSelector.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; @@ -20,7 +20,6 @@ package org.eclipse.cdt.core.dom.ast; * @since 5.0 */ public interface IASTNodeSelector { - /** * Returns the name for the exact given range, or null if there is no such node. * Will not return an implicit name. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java index 767b376941d..13fc8a000c9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java @@ -21,15 +21,15 @@ public interface IASTTypeId extends IASTNode { public static final IASTTypeId[] EMPTY_TYPEID_ARRAY = new IASTTypeId[0]; /** - * DECL_SPECIFIER represents the relationship between an IASTTypeId and - * it's nested IASTDeclSpecifier. + * DECL_SPECIFIER represents the relationship between an IASTTypeId + * and it's nested IASTDeclSpecifier. */ public static final ASTNodeProperty DECL_SPECIFIER = new ASTNodeProperty( "IASTTypeId.DECL_SPECIFIER - IASTDeclSpecifier for IASTTypeId"); //$NON-NLS-1$ /** - * ABSTRACT_DECLARATOR represents the relationship between an IASTTypeId and - * it's nested IASTDeclarator. + * ABSTRACT_DECLARATOR represents the relationship between an IASTTypeId + * and it's nested IASTDeclarator. */ public static final ASTNodeProperty ABSTRACT_DECLARATOR = new ASTNodeProperty( "IASTTypeId.ABSTRACT_DECLARATOR - IASTDeclarator for IASTTypeId"); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemType.java index facc9fa48c8..abc92782df0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemType.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; @@ -22,5 +22,4 @@ package org.eclipse.cdt.core.dom.ast; * @noimplement This interface is not intended to be implemented by clients. */ public interface IProblemType extends IType, ISemanticProblem { - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IType.java index e3f13bc2bfd..e661796ec86 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IType.java @@ -22,7 +22,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; * @noimplement This interface is not intended to be implemented by clients. */ public interface IType extends Cloneable { - public static final IType[] EMPTY_TYPE_ARRAY = new IType[0]; + public static final IType[] EMPTY_TYPE_ARRAY = {}; public static final ASTTypeMatcher TYPE_MATCHER = new ASTTypeMatcher(); public Object clone(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ITypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ITypedef.java index 011381d1cb4..00f34adeb60 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ITypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ITypedef.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Doug Schaefer (IBM) - Initial API and implementation + * Doug Schaefer (IBM) - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; @@ -15,7 +15,6 @@ package org.eclipse.cdt.core.dom.ast; * @noimplement This interface is not intended to be implemented by clients. */ public interface ITypedef extends IBinding, IType { - /** * Returns the type that this thing is a typedef of */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTypeId.java index 5f7dad418f4..cab1df9c5ef 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTypeId.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPPointerToMemberType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPPointerToMemberType.java index 9d53659ed25..aa13028531e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPPointerToMemberType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPPointerToMemberType.java @@ -19,9 +19,8 @@ import org.eclipse.cdt.core.dom.ast.IType; * @noimplement This interface is not intended to be implemented by clients. */ public interface ICPPPointerToMemberType extends IPointerType { - /** - * Get the class to whose members this points to. + * Returns the class to whose members this points to. * @return Either ICPPClassType or ICPPTeplateTypeParameter. */ public IType getMemberOfClass(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ArithmeticConversion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ArithmeticConversion.java index 8bdc3abcf97..70e5fe1dcbd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ArithmeticConversion.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ArithmeticConversion.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; @@ -85,7 +85,7 @@ public abstract class ArithmeticConversion { private boolean isArithmeticOrUnscopedEnum(IType op1) { if (op1 instanceof IBasicType) { - final Kind kind = ((IBasicType)op1).getKind(); + final Kind kind = ((IBasicType) op1).getKind(); switch (kind) { case eUnspecified: case eVoid: @@ -190,7 +190,8 @@ public abstract class ArithmeticConversion { return signedType; } - return createBasicType(signedType.getKind(), changeModifier(signedType.getModifiers(), IBasicType.IS_SIGNED, IBasicType.IS_UNSIGNED)); + return createBasicType(signedType.getKind(), + changeModifier(signedType.getModifiers(), IBasicType.IS_SIGNED, IBasicType.IS_UNSIGNED)); } private IBasicType promote(IType type, Domain domain) { @@ -331,21 +332,21 @@ public abstract class ArithmeticConversion { return false; if (basicTarget.isShort()) { - return n < (Short.MAX_VALUE + 1L)*2; + return n < (Short.MAX_VALUE + 1L) * 2; } // Can't represent long longs with java longs. if (basicTarget.isLong() || basicTarget.isLongLong()) { return true; } - return n < (Integer.MAX_VALUE + 1L)*2; + return n < (Integer.MAX_VALUE + 1L) * 2; case eFloat: float f= n; - return (long)f == n; + return (long) f == n; case eDouble: double d= n; - return (long)d == n; + return (long) d == n; default: return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java index d433dcdb11d..bab886728ae 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java @@ -9,9 +9,12 @@ * John Camelon (IBM Rational Software) - Initial API and implementation * Yuan Zhang / Beth Tibbitts (IBM Research) * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.restoreTypedefs; + import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; @@ -54,11 +57,7 @@ public class CASTBinaryExpression extends ASTNode copy.op = op; copy.setOperand1(operand1 == null ? null : operand1.copy(style)); copy.setOperand2(operand2 == null ? null : operand2.copy(style)); - copy.setOffsetAndLength(this); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + return copy(copy, style); } @Override @@ -118,9 +117,9 @@ public class CASTBinaryExpression extends ASTNode if (action.shouldVisitExpressions) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } @@ -147,7 +146,7 @@ public class CASTBinaryExpression extends ASTNode public static boolean acceptWithoutRecursion(IASTBinaryExpression bexpr, ASTVisitor action) { N stack= new N(bexpr); - while(stack != null) { + while (stack != null) { IASTBinaryExpression expr= stack.fExpression; if (stack.fState == 0) { if (action.shouldVisitExpressions) { @@ -211,11 +210,13 @@ public class CASTBinaryExpression extends ASTNode @Override public IType getExpressionType() { final int op = getOperator(); - final IType t1= CVisitor.unwrapTypedefs(getOperand1().getExpressionType()); - final IType t2= CVisitor.unwrapTypedefs(getOperand2().getExpressionType()); - IType type= CArithmeticConversion.convertCOperandTypes(op, t1, t2); + IType originalType1 = getOperand1().getExpressionType(); + IType originalType2 = getOperand2().getExpressionType(); + final IType type1= CVisitor.unwrapTypedefs(originalType1); + final IType type2= CVisitor.unwrapTypedefs(originalType2); + IType type= CArithmeticConversion.convertCOperandTypes(op, type1, type2); if (type != null) { - return type; + return restoreTypedefs(type, originalType1, originalType2); } switch (op) { @@ -230,25 +231,25 @@ public class CASTBinaryExpression extends ASTNode return new CBasicType(Kind.eInt, 0, this); case IASTBinaryExpression.op_plus: - if (t1 instanceof IArrayType) { - return arrayTypeToPointerType((ICArrayType) t1); - } else if (t2 instanceof IPointerType) { - return t2; - } else if (t2 instanceof IArrayType) { - return arrayTypeToPointerType((ICArrayType) t2); + if (type1 instanceof IArrayType) { + return arrayTypeToPointerType((ICArrayType) type1); + } else if (type2 instanceof IPointerType) { + return restoreTypedefs(type2, originalType2); + } else if (type2 instanceof IArrayType) { + return arrayTypeToPointerType((ICArrayType) type2); } break; case IASTBinaryExpression.op_minus: - if (t2 instanceof IPointerType || t2 instanceof IArrayType) { - if (t1 instanceof IPointerType || t1 instanceof IArrayType) { + if (type2 instanceof IPointerType || type2 instanceof IArrayType) { + if (type1 instanceof IPointerType || type1 instanceof IArrayType) { return CVisitor.getPtrDiffType(this); } - return t1; + return restoreTypedefs(type1, originalType1); } break; } - return t1; + return restoreTypedefs(type1, originalType1); } private IType arrayTypeToPointerType(ICArrayType type) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java index bed10b3ca86..7d06b0dd0c1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java @@ -6,12 +6,15 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * John Camelon (IBM Rational Software) - Initial API and implementation - * Yuan Zhang / Beth Tibbitts (IBM Research) - * Markus Schorn (Wind River Systems) + * John Camelon (IBM Rational Software) - Initial API and implementation + * Yuan Zhang / Beth Tibbitts (IBM Research) + * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.restoreTypedefs; + import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTNode; @@ -29,7 +32,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; public class CASTUnaryExpression extends ASTNode implements IASTUnaryExpression, IASTAmbiguityParent { private int operator; private IASTExpression operand; - public CASTUnaryExpression() { } @@ -46,13 +48,9 @@ public class CASTUnaryExpression extends ASTNode implements IASTUnaryExpression, @Override public CASTUnaryExpression copy(CopyStyle style) { - CASTUnaryExpression copy = new CASTUnaryExpression(operator, operand == null ? null - : operand.copy(style)); - copy.setOffsetAndLength(this); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + CASTUnaryExpression copy = + new CASTUnaryExpression(operator, operand == null ? null : operand.copy(style)); + return copy(copy, style); } @Override @@ -82,22 +80,22 @@ public class CASTUnaryExpression extends ASTNode implements IASTUnaryExpression, } @Override - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitExpressions ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - if( operand != null ) if( !operand.accept( action ) ) return false; + if (operand != null && !operand.accept(action)) return false; - if( action.shouldVisitExpressions ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } return true; @@ -105,10 +103,9 @@ public class CASTUnaryExpression extends ASTNode implements IASTUnaryExpression, @Override public void replace(IASTNode child, IASTNode other) { - if( child == operand ) - { - other.setPropertyInParent( child.getPropertyInParent() ); - other.setParent( child.getParent() ); + if (child == operand) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); operand = (IASTExpression) other; } } @@ -121,24 +118,24 @@ public class CASTUnaryExpression extends ASTNode implements IASTUnaryExpression, } final IType exprType = getOperand().getExpressionType(); IType type = CVisitor.unwrapTypedefs(exprType); - switch(op) { + switch (op) { case op_star: if (type instanceof IPointerType || type instanceof IArrayType) { return ((ITypeContainer) type).getType(); } break; case op_amper: - return new CPointerType(type, 0); + return new CPointerType(exprType, 0); case op_minus: case op_plus: case op_tilde: IType t= CArithmeticConversion.promoteCType(type); if (t != null) { - return t; + return restoreTypedefs(t, exprType); } break; } - return exprType; // return the original + return exprType; // Return the original. } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java index 8b04d2b0929..a6a29f4401c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java @@ -9,12 +9,17 @@ * John Camelon (IBM) - Initial API and implementation * Mike Kucera (IBM) * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.restoreTypedefs; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromFunctionCall; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromFunctionCall; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; @@ -37,14 +42,13 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemType; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; - public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpression, IASTAmbiguityParent { private int op; private IASTExpression operand1; private IASTInitializerClause operand2; private IType type; private ICPPFunction overload= UNINITIALIZED_FUNCTION; - private IASTImplicitName[] implicitNames = null; + private IASTImplicitName[] implicitNames; public CPPASTBinaryExpression() { } @@ -66,11 +70,7 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr copy.op = op; copy.setOperand1(operand1 == null ? null : operand1.copy(style)); copy.setInitOperand2(operand2 == null ? null : operand2.copy(style)); - copy.setOffsetAndLength(this); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + return copy(copy, style); } @Override @@ -314,21 +314,26 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr } private IType createExpressionType() { + IType originalType1 = operand1.getExpressionType(); + IType originalType2 = operand2 instanceof IASTExpression ? + ((IASTExpression) operand2).getExpressionType() : null; + // Check for overloaded operator. ICPPFunction o= getOverload(); if (o != null) { - return typeFromFunctionCall(o); + IType type = typeFromFunctionCall(o); + return restoreTypedefs(type, originalType1, originalType2); } final int op = getOperator(); - IType type1 = prvalueType(operand1.getExpressionType()); + IType type1 = prvalueType(originalType1); if (type1 instanceof ISemanticProblem) { return type1; } - + IType type2 = null; - if (operand2 instanceof IASTExpression) { - type2= prvalueType(((IASTExpression) operand2).getExpressionType()); + if (originalType2 != null) { + type2= prvalueType(originalType2); if (type2 instanceof ISemanticProblem) { return type2; } @@ -336,7 +341,7 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr IType type= CPPArithmeticConversion.convertCppOperandTypes(op, type1, type2); if (type != null) { - return type; + return restoreTypedefs(type, originalType1, originalType2); } switch (op) { @@ -352,10 +357,10 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr case IASTBinaryExpression.op_plus: if (type1 instanceof IPointerType) { - return type1; + return restoreTypedefs(type1, originalType1); } if (type2 instanceof IPointerType) { - return type2; + return restoreTypedefs(type2, originalType2); } break; @@ -364,7 +369,7 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr if (type2 instanceof IPointerType) { return CPPVisitor.getPointerDiffType(this); } - return type1; + return restoreTypedefs(type1, originalType1); } break; @@ -381,6 +386,6 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr } return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION); } - return type1; + return restoreTypedefs(type1, originalType1); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeId.java index 0e0c4f67f92..ebbca66cef9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeId.java @@ -43,12 +43,8 @@ public class CPPASTTypeId extends ASTNode implements ICPPASTTypeId { CPPASTTypeId copy = new CPPASTTypeId(); copy.setDeclSpecifier(declSpec == null ? null : declSpec.copy(style)); copy.setAbstractDeclarator(absDecl == null ? null : absDecl.copy(style)); - copy.setOffsetAndLength(this); copy.isPackExpansion = isPackExpansion; - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + return copy(copy, style); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java index 1b732bb14d0..e80a54287ac 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java @@ -72,13 +72,9 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres @Override public CPPASTUnaryExpression copy(CopyStyle style) { - CPPASTUnaryExpression copy = new CPPASTUnaryExpression(op, operand == null ? null - : operand.copy(style)); - copy.setOffsetAndLength(this); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + CPPASTUnaryExpression copy = + new CPPASTUnaryExpression(op, operand == null ? null : operand.copy(style)); + return copy(copy, style); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArithmeticConversion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArithmeticConversion.java index f1749cd8b2a..58c15d59ff9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArithmeticConversion.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArithmeticConversion.java @@ -6,13 +6,13 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.IBasicType; -import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; +import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.internal.core.dom.parser.ArithmeticConversion; public class CPPArithmeticConversion extends ArithmeticConversion { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitTypedef.java index e81e3416b41..863b3dbd6c1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitTypedef.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Devin Steffler (IBM) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * Devin Steffler (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -23,9 +23,9 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; * An example is the GCC built-in typedef: typedef char * __builtin_va_list; */ public class CPPImplicitTypedef extends CPPTypedef { - private IType type=null; - private char[] name=null; - private IScope scope=null; + private IType type; + private char[] name; + private IScope scope; public CPPImplicitTypedef(IType type, char[] name, IScope scope) { super(null); @@ -135,5 +135,4 @@ public class CPPImplicitTypedef extends CPPTypedef { public boolean isGloballyQualified() { return true; } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java index 50032369a36..e49137afdc1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java @@ -38,20 +38,20 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.core.runtime.PlatformObject; /** - * Binding for a c++ function parameter + * Binding for a c++ function parameter. */ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPInternalBinding, ICPPTwoPhaseBinding { + public static class CPPParameterProblem extends ProblemBinding implements ICPPParameter { public CPPParameterProblem(IASTNode node, int id, char[] arg) { super(node, id, arg); } } - private IType fType = null; - private IASTName[] fDeclarations = null; + private IType fType; + private IASTName[] fDeclarations; private int fPosition; - - + public CPPParameter(IASTName name, int pos) { this.fDeclarations = new IASTName[] { name }; fPosition= pos; @@ -61,23 +61,17 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI this.fType = type; fPosition= pos; } - + @Override public boolean isParameterPack() { return getType() instanceof ICPPParameterPackType; } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDeclarations() - */ @Override public IASTNode[] getDeclarations() { return fDeclarations; } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition() - */ @Override public IASTNode getDefinition() { return null; @@ -121,17 +115,12 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI } return null; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() - */ + @Override public String getName() { return new String(getNameCharArray()); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray() - */ @Override public char[] getNameCharArray() { IASTName name = getPrimaryDeclaration(); @@ -140,26 +129,17 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI return CharArrayUtils.EMPTY; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() - */ @Override public IScope getScope() { return CPPVisitor.getContainingScope(getPrimaryDeclaration()); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode() - */ public IASTNode getPhysicalNode() { if (fDeclarations != null) return fDeclarations[0]; return null; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IVariable#getType() - */ @Override public IType getType() { if (fType == null && fDeclarations != null) { @@ -175,75 +155,48 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI return fType; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IVariable#isStatic() - */ @Override public boolean isStatic() { return false; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedName() - */ @Override public String[] getQualifiedName() { return new String[] { getName() }; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedNameCharArray() - */ @Override public char[][] getQualifiedNameCharArray() { return new char[][] { getNameCharArray() }; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#isGloballyQualified() - */ @Override public boolean isGloballyQualified() { return false; } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode) - */ @Override public void addDefinition(IASTNode node) { addDeclaration(node); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern() - */ @Override public boolean isExtern() { - //7.1.1-5 extern can not be used in the declaration of a parameter + // 7.1.1-5 extern can not be used in the declaration of a parameter return false; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable#isMutable() - */ @Override public boolean isMutable() { - //7.1.1-8 mutable can only apply to class members + // 7.1.1-8 mutable can only apply to class members return false; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto() - */ @Override public boolean isAuto() { return hasStorageClass(IASTDeclSpecifier.sc_auto); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister() - */ @Override public boolean isRegister() { return hasStorageClass(IASTDeclSpecifier.sc_register); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java index 6974a726823..01c64516bbc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java @@ -35,7 +35,7 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain private IType type; public CPPTypedef(IASTName name) { - // bug 223020 even though qualified names are not legal, we need to deal with them. + // Bug 223020 even though qualified names are not legal, we need to deal with them. if (name != null && name.getParent() instanceof ICPPASTQualifiedName) { name= (IASTName) name.getParent(); } @@ -61,7 +61,7 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain if (o instanceof ITypedef) { IType t = getType(); if (t != null) - return t.isSameType(((ITypedef)o).getType()); + return t.isSameType(((ITypedef) o).getType()); return false; } @@ -105,7 +105,7 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain try { t = (IType) super.clone(); } catch (CloneNotSupportedException e) { - //not going to happen + // Not going to happen } return t; } @@ -123,7 +123,7 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain @Override public boolean isGloballyQualified() throws DOMException { IScope scope = getScope(); - while(scope != null) { + while (scope != null) { if (scope instanceof ICPPBlockScope) return false; scope = scope.getParent(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index 7b13aa7ef33..2d1347274a9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -1762,10 +1762,9 @@ public class CPPVisitor extends ASTQueries { * Creates the type for a parameter declaration. */ public static IType createType(final ICPPASTParameterDeclaration pdecl, boolean forFuncType) { - IType pt; IASTDeclSpecifier pDeclSpec = pdecl.getDeclSpecifier(); ICPPASTDeclarator pDtor = pdecl.getDeclarator(); - pt = createType(pDeclSpec); + IType pt = createType(pDeclSpec); if (pDtor != null) { pt = createType(pt, pDtor); } @@ -2017,7 +2016,8 @@ public class CPPVisitor extends ASTQueries { return createAutoType(autoInitClause, declSpec, declarator); } - private static IType createAutoType(IASTInitializerClause initClause, IASTDeclSpecifier declSpec, IASTDeclarator declarator) { + private static IType createAutoType(IASTInitializerClause initClause, IASTDeclSpecifier declSpec, + IASTDeclarator declarator) { // C++0x: 7.1.6.4 if (initClause == null || !autoTypeDeclSpecs.get().add(declSpec)) { // Detected a self referring auto type, e.g.: auto x = x; @@ -2064,6 +2064,9 @@ public class CPPVisitor extends ASTQueries { return new ProblemType(ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE); } type = argument.getTypeValue(); + IType t = SemanticUtil.substituteTypedef(type, initType); + if (t != null) + type = t; if (initClause instanceof ICPPASTInitializerList) { type = (IType) CPPTemplates.instantiate(initializer_list_template, new ICPPTemplateArgument[] { new CPPTemplateArgument(type) }); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java index 66431d14421..6ae940c814c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java @@ -16,7 +16,16 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromReturnType; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.ALLCVQ; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.COND_TDEF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.addQualifiers; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.calculateInheritanceDepth; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getCVQualifier; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getNestedType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.isVoidType; import java.util.Collections; @@ -179,7 +188,7 @@ public class Conversions { return cost; } } - // — otherwise, the program is ill-formed. + // � otherwise, the program is ill-formed. return Cost.NO_CONVERSION; } @@ -1147,18 +1156,18 @@ public class Conversions { * 4.1, 4.2, 4.3 */ public static IType lvalue_to_rvalue(IType type) { - type= SemanticUtil.getNestedType(type, TDEF | REF); - if (type instanceof IArrayType) { - return new CPPPointerType(((IArrayType) type).getType()); + IType t= SemanticUtil.getNestedType(type, TDEF | REF); + if (t instanceof IArrayType) { + return new CPPPointerType(((IArrayType) t).getType()); } - if (type instanceof IFunctionType) { - return new CPPPointerType(type); + if (t instanceof IFunctionType) { + return new CPPPointerType(t); } - IType uqType= SemanticUtil.getNestedType(type, TDEF | REF | ALLCVQ); + IType uqType= SemanticUtil.getNestedType(t, TDEF | REF | ALLCVQ); if (uqType instanceof ICPPClassType) { - return type; + return SemanticUtil.getNestedType(type, COND_TDEF | REF); } - return uqType; + return SemanticUtil.getNestedType(t, COND_TDEF | REF | ALLCVQ); } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExpressionTypes.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExpressionTypes.java index 70e059bea65..0f4be05ea7f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExpressionTypes.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExpressionTypes.java @@ -6,10 +6,12 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.COND_TDEF; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; @@ -26,22 +28,20 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; - /** - * Methods for computing the type of an expression + * Methods for computing the type of an expression. */ public class ExpressionTypes { public static IType glvalueType(IType type) { // Reference types are removed. - return SemanticUtil.getNestedType(type, TDEF | REF); + return SemanticUtil.getNestedType(type, COND_TDEF | REF); } public static IType prvalueType(IType type) { return Conversions.lvalue_to_rvalue(type); } - public static ValueCategory valueCategoryFromFunctionCall(ICPPFunction function) { final ICPPFunctionType ft = function.getType(); return valueCategoryFromReturnType(ft.getReturnType()); @@ -67,46 +67,46 @@ public class ExpressionTypes { return typeFromReturnType(ft.getReturnType()); } - public static IType typeFromReturnType(IType r) { - r= SemanticUtil.getNestedType(r, TDEF); - if (r instanceof ICPPReferenceType) { - return glvalueType(r); + public static IType typeFromReturnType(IType type) { + IType t= SemanticUtil.getNestedType(type, TDEF); + if (t instanceof ICPPReferenceType) { + return glvalueType(type); } - return prvalueType(r); + return prvalueType(type); } - public static IType typeOrFunctionSet(IASTExpression e) { - FunctionSetType fs= getFunctionSetType(e); + public static IType typeOrFunctionSet(IASTExpression exp) { + FunctionSetType fs= getFunctionSetType(exp); if (fs != null) { return fs; } - return e.getExpressionType(); + return exp.getExpressionType(); } - public static ValueCategory valueCat(IASTExpression e) { - FunctionSetType fs= getFunctionSetType(e); + public static ValueCategory valueCat(IASTExpression exp) { + FunctionSetType fs= getFunctionSetType(exp); if (fs != null) return fs.getValueCategory(); - return e.getValueCategory(); + return exp.getValueCategory(); } - private static FunctionSetType getFunctionSetType(IASTExpression e) { + private static FunctionSetType getFunctionSetType(IASTExpression exp) { boolean addressOf= false; - while (e instanceof IASTUnaryExpression) { - final IASTUnaryExpression unary = (IASTUnaryExpression) e; + while (exp instanceof IASTUnaryExpression) { + final IASTUnaryExpression unary = (IASTUnaryExpression) exp; final int op= unary.getOperator(); if (op == IASTUnaryExpression.op_bracketedPrimary) { - e= unary.getOperand(); + exp= unary.getOperand(); } else if (!addressOf && op == IASTUnaryExpression.op_amper) { addressOf= true; - e= unary.getOperand(); + exp= unary.getOperand(); } else { break; } } - if (e instanceof IASTIdExpression) { - IASTIdExpression idexpr= (IASTIdExpression) e; + if (exp instanceof IASTIdExpression) { + IASTIdExpression idexpr= (IASTIdExpression) exp; final IASTName name = idexpr.getName(); IBinding b= name.resolvePreBinding(); if (b instanceof CPPFunctionSet) { @@ -115,4 +115,23 @@ public class ExpressionTypes { } return null; } + + public static IType restoreTypedefs(IType type, IType originalType) { + IType t = SemanticUtil.substituteTypedef(type, originalType); + if (t != null) + return t; + return type; + } + + public static IType restoreTypedefs(IType type, IType originalType1, IType originalType2) { + IType t = SemanticUtil.substituteTypedef(type, originalType1); + if (t != null) + return t; + if (originalType2 != null) { + t = SemanticUtil.substituteTypedef(type, originalType2); + if (t != null) + return t; + } + return type; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java index 7513e44aec7..fea27bfaa2e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java @@ -14,7 +14,14 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CVQualifier.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CVQualifier.CONST; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CVQualifier.CONST_RESTRICT; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CVQualifier.CONST_VOLATILE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CVQualifier.CONST_VOLATILE_RESTRICT; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CVQualifier.NONE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CVQualifier.RESTRICT; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CVQualifier.VOLATILE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CVQualifier.VOLATILE_RESTRICT; import java.util.HashSet; import java.util.Set; @@ -60,20 +67,23 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator; /** - * + * Collection of static methods operating on C++ bindings. */ public class SemanticUtil { private static final char[] OPERATOR_CHARS = Keywords.OPERATOR.toCharArray(); // Cache of overloadable operator names for fast lookup. Used by isConversionOperator. private static final CharArraySet cas= new CharArraySet(OverloadableOperator.values().length); - - public static final int TDEF = 0x01; - public static final int REF = 0x02; - public static final int CVTYPE = 0x04; - public static final int ALLCVQ= 0x08; - public static final int PTR= 0x10; - public static final int MPTR= 0x20; - public static final int ARRAY= 0x40; + + // Resolve typedefs. + public static final int TDEF = 0x01; + // Resolve typedefs, but only if necessary for a nested type transformation. + public static final int COND_TDEF = 0x02; + public static final int REF = 0x04; + public static final int CVTYPE = 0x08; + public static final int ALLCVQ = 0x10; + public static final int PTR = 0x20; + public static final int MPTR = 0x40; + public static final int ARRAY = 0x80; static { final int OPERATOR_SPC= OPERATOR_CHARS.length + 1; @@ -221,14 +231,25 @@ public class SemanticUtil { */ public static IType getNestedType(IType type, int options) { final boolean tdef= (options & TDEF) != 0; + final boolean cond_tdef= (options & COND_TDEF) != 0; final boolean ptr= (options & PTR) != 0; final boolean mptr= (options & MPTR) != 0; final boolean allcvq= (options & ALLCVQ) != 0; final boolean cvtype = (options & CVTYPE) != 0; + IType beforeTypedefs = null; + while (true) { IType t= null; - if (type instanceof IPointerType) { + if (type instanceof ITypedef) { + if (tdef || cond_tdef) { + if (beforeTypedefs == null && cond_tdef) { + beforeTypedefs = type; + } + t= ((ITypedef) type).getType(); + } + } else if (type instanceof IPointerType) { + beforeTypedefs = null; final boolean isMbrPtr = type instanceof ICPPPointerToMemberType; if ((ptr && !isMbrPtr) || (mptr && isMbrPtr)) { t= ((IPointerType) type).getType(); @@ -244,20 +265,20 @@ public class SemanticUtil { } return pt; } - } else if (tdef && type instanceof ITypedef) { - t= ((ITypedef) type).getType(); } else if (type instanceof IQualifierType) { + beforeTypedefs = null; final IQualifierType qt = (IQualifierType) type; final IType qttgt = qt.getType(); if (allcvq || cvtype) { t= qttgt; - } else if (tdef) { + } else if (tdef || cond_tdef) { t= getNestedType(qttgt, options); if (t == qttgt) return qt; return addQualifiers(t, qt.isConst(), qt.isVolatile(), false); } } else if (type instanceof IArrayType) { + beforeTypedefs = null; final IArrayType atype= (IArrayType) type; if ((options & ARRAY) != 0) { t= atype.getType(); @@ -269,11 +290,12 @@ public class SemanticUtil { return replaceNestedType((ITypeContainer) atype, newNested); } } else if (type instanceof ICPPReferenceType) { + beforeTypedefs = null; final ICPPReferenceType rt = (ICPPReferenceType) type; if ((options & REF) != 0) { t= rt.getType(); } else if (tdef) { - // a typedef within the reference type can influence whether the reference is lvalue or rvalue + // A typedef within the reference type can influence whether the reference is lvalue or rvalue IType nested= rt.getType(); IType newNested = getNestedType(nested, TDEF); if (nested == newNested) @@ -282,8 +304,12 @@ public class SemanticUtil { } } // Pack expansion types are dependent types, there is no need to descend into those. - if (t == null) + if (t == null) { + if (beforeTypedefs != null) { + return beforeTypedefs; + } return type; + } type= t; } @@ -354,7 +380,7 @@ public class SemanticUtil { if (newNestedType == null) return type; - // bug 249085 make sure not to add unnecessary qualifications + // Bug 249085 make sure not to add unnecessary qualifications if (type instanceof IQualifierType) { IQualifierType qt= (IQualifierType) type; return addQualifiers(newNestedType, qt.isConst(), qt.isVolatile(), false); @@ -364,7 +390,41 @@ public class SemanticUtil { type.setType(newNestedType); return type; } - + + /** + * Replaces the given type or its nested type with a typedef if that type is the same as + * the type the typedef resolves to. + * + * @param type the type subject to substitution + * @param typedefType the type possibly containing the typedef as its nested type. + * @return the given type with the nested type replaced by the typedef, or {@code null} if + * the typedefType doesn't contain a typedef or the nested type doesn't match the typedef. + */ + public static IType substituteTypedef(IType type, IType typedefType) { + typedefType = getNestedType(typedefType, REF | ALLCVQ | PTR | ARRAY); + if (!(typedefType instanceof ITypedef)) + return null; + IType nestedType = getNestedType(type, REF | ALLCVQ | PTR | ARRAY); + if (!nestedType.isSameType(((ITypedef) typedefType).getType())) + return null; + + IType result = null; + ITypeContainer containerType = null; + for (IType t = type; ; t = containerType.getType()) { + IType newType = t == nestedType ? typedefType : (IType) t.clone(); + if (result == null) + result = newType; + if (containerType != null) { + containerType.setType(newType); + } + if (t == nestedType) + return result; + if (!(t instanceof ITypeContainer)) + return null; + containerType = (ITypeContainer) t; + } + } + public static IType mapToAST(IType type, IASTNode node) { if (type instanceof IFunctionType) { final ICPPFunctionType ft = (ICPPFunctionType) type; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/CWDLocator.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/CWDLocator.java index ce6125841c4..62d0618a71b 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/CWDLocator.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/CWDLocator.java @@ -76,7 +76,7 @@ public class CWDLocator extends AbstractErrorParser { return true; } }, - // This is emitted by GNU make using options -n, --just-print or -w, --print-directory. + // This is emitted by GNU make using options -w or --print-directory. new ErrorPattern("make: Entering directory `(.*)'", 0, 0) { //$NON-NLS-1$ @Override protected boolean recordError(Matcher matcher, ErrorParserManager eoParser) { diff --git a/core/org.eclipse.cdt.ui/icons/ovr16/edited_ovr.gif b/core/org.eclipse.cdt.ui/icons/ovr16/edited_ovr.gif index 48526ac8b38..f272e8c7321 100644 Binary files a/core/org.eclipse.cdt.ui/icons/ovr16/edited_ovr.gif and b/core/org.eclipse.cdt.ui/icons/ovr16/edited_ovr.gif differ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoring.java index 37fd2cb8c18..61a77465292 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/ExtractLocalVariableRefactoring.java @@ -100,7 +100,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { @Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { - SubMonitor sm = SubMonitor.convert(pm, 9); + SubMonitor sm = SubMonitor.convert(pm, 10); RefactoringStatus status = super.checkInitialConditions(sm.newChild(6)); if (status.hasError()) { @@ -128,11 +128,6 @@ public class ExtractLocalVariableRefactoring extends CRefactoring { if (isProgressMonitorCanceled(sm, initStatus)) return initStatus; - sm.worked(1); - - container.getNames(); //XXX Is this needed? - sm.worked(1); - info.addNamesToUsedNames(findAllDeclaredNames()); sm.worked(1); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties index 4deb6dd58e0..86d85b60e80 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties @@ -110,4 +110,4 @@ OccurrencesFinder_label_singular=''{0}'' - 1 occurrence in ''{1}'' # The first argument will be replaced by the element name, the second by the count and the last by the file name OccurrencesFinder_label_plural=''{0}'' - {1} occurrences in ''{2}'' OccurrencesFinder_occurrence_description=Occurrence of ''{0}'' -OccurrencesFinder_occurrence_write_description=Write Occurrence of ''{0}'' \ No newline at end of file +OccurrencesFinder_occurrence_write_description=Write occurrence of ''{0}'' \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/AbstractCEditorTextHover.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/AbstractCEditorTextHover.java index 81696fb5953..016f663fb95 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/AbstractCEditorTextHover.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/AbstractCEditorTextHover.java @@ -10,7 +10,6 @@ * IBM Corporation * Anton Leherbauer (Wind River Systems) *******************************************************************************/ - package org.eclipse.cdt.internal.ui.text.c.hover; import org.eclipse.jface.text.DefaultInformationControl; @@ -32,12 +31,10 @@ import org.eclipse.cdt.ui.text.c.hover.ICEditorTextHover; import org.eclipse.cdt.internal.ui.text.CWordFinder; /** - * Abstract class for providing hover information for C - * elements. - * + * Abstract class for providing hover information for C elements. */ -public abstract class AbstractCEditorTextHover implements ICEditorTextHover, ITextHoverExtension, ITextHoverExtension2, IInformationProviderExtension2 { - +public abstract class AbstractCEditorTextHover implements ICEditorTextHover, ITextHoverExtension, + ITextHoverExtension2, IInformationProviderExtension2 { private IEditorPart fEditor; /* @@ -102,7 +99,7 @@ public abstract class AbstractCEditorTextHover implements ICEditorTextHover, ITe } /* - * @see org.eclipse.jface.text.ITextHoverExtension2#getInformationPresenterControlCreator() + * @see ITextHoverExtension2#getInformationPresenterControlCreator() * @since 5.0 */ @Override diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/BestMatchHover.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/BestMatchHover.java index e2722749571..98a3ffb5bab 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/BestMatchHover.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/BestMatchHover.java @@ -10,7 +10,6 @@ * Anton Leherbauer (Wind River Systems) * Ericsson - Fix improper hover order (Bug 294812) *******************************************************************************/ - package org.eclipse.cdt.internal.ui.text.c.hover; import java.util.ArrayList; @@ -39,10 +38,8 @@ import org.eclipse.cdt.ui.text.c.hover.ICEditorTextHover; * hovers being placed before less specific ones. */ public class BestMatchHover extends AbstractCEditorTextHover { - /* - * Note that hover ordering is very important to be preserved by this - * class. (Bug 294812) + * Note that hover ordering is very important to be preserved by this class (bug 294812). */ private List fTextHoverSpecifications; private List fInstantiatedTextHovers; @@ -63,16 +60,16 @@ public class BestMatchHover extends AbstractCEditorTextHover { private void installTextHovers() { CEditorTextHoverDescriptor[] hoverDescs= CUIPlugin.getDefault().getCEditorTextHoverDescriptors(); - // initialize lists - indicates that the initialization happened + // Initialize lists - indicates that the initialization happened fTextHoverSpecifications= new ArrayList(hoverDescs.length-1); fInstantiatedTextHovers= new ArrayList(hoverDescs.length-1); - // populate list + // Populate list for (int i= 0; i < hoverDescs.length; i++) { - // ensure that we don't add ourselves to the list + // Ensure that we don't add ourselves to the list if (!PreferenceConstants.ID_BESTMATCH_HOVER.equals(hoverDescs[i].getId())) { fTextHoverSpecifications.add(hoverDescs[i]); - // add place-holder for hover instance + // Add place-holder for hover instance fInstantiatedTextHovers.add(null); } } @@ -90,7 +87,7 @@ public class BestMatchHover extends AbstractCEditorTextHover { ICEditorTextHover hover= spec.createTextHover(); if (hover != null) { hover.setEditor(getEditor()); - // remember instance and mark as created + // Remember instance and mark as created fInstantiatedTextHovers.set(i, hover); fTextHoverSpecifications.set(i, null); } else { @@ -109,7 +106,6 @@ public class BestMatchHover extends AbstractCEditorTextHover { @SuppressWarnings("deprecation") @Override public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { - checkTextHovers(); fBestHover= null; @@ -130,12 +126,11 @@ public class BestMatchHover extends AbstractCEditorTextHover { } /* - * @see org.eclipse.jface.text.ITextHoverExtension2#getHoverInfo2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) + * @see ITextHoverExtension2#getHoverInfo2(ITextViewer, IRegion) */ @SuppressWarnings("deprecation") @Override public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) { - checkTextHovers(); fBestHover= null; @@ -164,7 +159,7 @@ public class BestMatchHover extends AbstractCEditorTextHover { } /* - * @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator() + * @see ITextHoverExtension#getHoverControlCreator() * @since 3.0 */ @Override @@ -176,16 +171,15 @@ public class BestMatchHover extends AbstractCEditorTextHover { } /* - * @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator() + * @see IInformationProviderExtension2#getInformationPresenterControlCreator() * @since 3.0 */ @Override public IInformationControlCreator getInformationPresenterControlCreator() { - // this is wrong, but left here for backwards compatibility + // This is wrong, but left here for backwards compatibility if (fBestHover instanceof IInformationProviderExtension2) - return ((IInformationProviderExtension2)fBestHover).getInformationPresenterControlCreator(); + return ((IInformationProviderExtension2) fBestHover).getInformationPresenterControlCreator(); return null; } - } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CDocHover.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CDocHover.java index f0a89dee4f2..2361fb9ea21 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CDocHover.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CDocHover.java @@ -11,7 +11,6 @@ *******************************************************************************/ package org.eclipse.cdt.internal.ui.text.c.hover; - import org.eclipse.core.resources.IProject; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextViewer; @@ -22,8 +21,8 @@ import org.eclipse.ui.IEditorInput; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.IFunctionSummary; -import org.eclipse.cdt.ui.IRequiredInclude; import org.eclipse.cdt.ui.IFunctionSummary.IFunctionPrototypeSummary; +import org.eclipse.cdt.ui.IRequiredInclude; import org.eclipse.cdt.ui.text.ICHelpInvocationContext; import org.eclipse.cdt.ui.text.IHoverHelpInvocationContext; @@ -33,15 +32,12 @@ import org.eclipse.cdt.internal.ui.text.CWordFinder; import org.eclipse.cdt.internal.ui.text.HTMLPrinter; public class CDocHover extends AbstractCEditorTextHover { - - /** - * Constructor for DefaultCEditorTextHover - */ + public CDocHover() { } /* (non-Javadoc) - * @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) + * @see ITextHover#getHoverInfo(ITextViewer, IRegion) */ @Override public String getHoverInfo(ITextViewer viewer, IRegion region) { @@ -61,7 +57,6 @@ public class CDocHover extends AbstractCEditorTextHover { // call the Help to get info ICHelpInvocationContext context = new IHoverHelpInvocationContext() { - @Override public IProject getProject() { ITranslationUnit unit = getTranslationUnit(); @@ -81,7 +76,6 @@ public class CDocHover extends AbstractCEditorTextHover { public IRegion getHoverRegion() { return hoverRegion; } - }; IFunctionSummary fs = CHelpProviderManager.getDefault().getFunctionInfo(context, expression); @@ -93,7 +87,7 @@ public class CDocHover extends AbstractCEditorTextHover { buffer.append(CEditorMessages.DefaultCEditorTextHover_html_prototype); buffer.append(HTMLPrinter.convertToHTMLContent(prototype.getPrototypeString(false))); } - if(fs.getDescription() != null) { + if (fs.getDescription() != null) { buffer.append(CEditorMessages.DefaultCEditorTextHover_html_description); //Don't convert this description since it could already be formatted buffer.append(fs.getDescription()); @@ -117,7 +111,7 @@ public class CDocHover extends AbstractCEditorTextHover { HTMLPrinter.addPageEpilog(buffer); return buffer.toString(); } - } catch(Exception ex) { + } catch (Exception e) { /* Ignore */ } @@ -125,7 +119,7 @@ public class CDocHover extends AbstractCEditorTextHover { } /* (non-Javadoc) - * @see org.eclipse.jface.text.ITextHover#getHoverRegion(org.eclipse.jface.text.ITextViewer, int) + * @see ITextHover#getHoverRegion(ITextViewer, int) */ @Override public IRegion getHoverRegion(ITextViewer viewer, int offset) { @@ -134,12 +128,12 @@ public class CDocHover extends AbstractCEditorTextHover { if (selectedRange.x >= 0 && selectedRange.y > 0 && offset >= selectedRange.x && - offset <= selectedRange.x + selectedRange.y) - return new Region( selectedRange.x, selectedRange.y ); + offset <= selectedRange.x + selectedRange.y) { + return new Region(selectedRange.x, selectedRange.y); + } return CWordFinder.findWord(viewer.getDocument(), offset); } return null; } - } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CEditorTextHoverProxy.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CEditorTextHoverProxy.java index b76604737b9..e899b216e64 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CEditorTextHoverProxy.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CEditorTextHoverProxy.java @@ -9,7 +9,6 @@ * QNX Software Systems - Initial API and implementation * Anton Leherbauer (Wind River Systems) *******************************************************************************/ - package org.eclipse.cdt.internal.ui.text.c.hover; import org.eclipse.jface.text.IInformationControlCreator; @@ -26,7 +25,6 @@ import org.eclipse.cdt.ui.text.c.hover.ICEditorTextHover; * CEditorTexHoverProxy */ public class CEditorTextHoverProxy extends AbstractCEditorTextHover { - private CEditorTextHoverDescriptor fHoverDescriptor; private ICEditorTextHover fHover; @@ -132,5 +130,4 @@ public class CEditorTextHoverProxy extends AbstractCEditorTextHover { } return null; } - } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionHover.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionHover.java index ea67639e15f..a2497c22726 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionHover.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionHover.java @@ -25,7 +25,6 @@ import org.eclipse.ui.part.IWorkbenchPartOrientation; * @since 5.0 */ public class CMacroExpansionHover extends AbstractCEditorTextHover { - @Override public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { Object hoverInfo= getHoverInfo2(textViewer, hoverRegion); @@ -33,7 +32,7 @@ public class CMacroExpansionHover extends AbstractCEditorTextHover { } /* - * @see org.eclipse.cdt.internal.ui.text.c.hover.AbstractCEditorTextHover#getHoverInfo2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) + * @see AbstractCEditorTextHover#getHoverInfo2(ITextViewer, IRegion) */ @Override public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) { @@ -55,7 +54,7 @@ public class CMacroExpansionHover extends AbstractCEditorTextHover { } /* - * @see org.eclipse.cdt.internal.ui.text.c.hover.AbstractCEditorTextHover#getInformationPresenterControlCreator() + * @see AbstractCEditorTextHover#getInformationPresenterControlCreator() */ @Override public IInformationControlCreator getInformationPresenterControlCreator() { @@ -70,5 +69,4 @@ public class CMacroExpansionHover extends AbstractCEditorTextHover { } }; } - } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java index 5e59cd00407..abcc4421aa3 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java @@ -1,13 +1,14 @@ /******************************************************************************* - * Copyright (c) 2002, 2011 QNX Software Systems and others. + * Copyright (c) 2002, 2012 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX Software Systems - Initial API and implementation - * Anton Leherbauer (Wind River Systems) + * QNX Software Systems - Initial API and implementation + * Anton Leherbauer (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.text.c.hover; @@ -47,12 +48,20 @@ import org.eclipse.ui.part.IWorkbenchPartOrientation; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.IPositionConverter; import org.eclipse.cdt.core.dom.IName; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTNodeSelector; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; @@ -62,9 +71,14 @@ import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IProblemBinding; +import org.eclipse.cdt.core.dom.ast.IProblemType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IVariable; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; @@ -77,12 +91,14 @@ import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.parser.KeywordSetKey; +import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.IWorkingCopyManager; import org.eclipse.cdt.ui.text.ICPartitions; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable; import org.eclipse.cdt.internal.corext.util.Strings; @@ -95,15 +111,16 @@ import org.eclipse.cdt.internal.ui.util.EditorUtility; * A text hover presenting the source of the element under the cursor. */ public class CSourceHover extends AbstractCEditorTextHover { - private static final boolean DEBUG = false; protected static class SingletonRule implements ISchedulingRule { public static final ISchedulingRule INSTANCE = new SingletonRule(); + @Override public boolean contains(ISchedulingRule rule) { return rule == this; } + @Override public boolean isConflicting(ISchedulingRule rule) { return rule == this; @@ -114,69 +131,100 @@ public class CSourceHover extends AbstractCEditorTextHover { * Computes the source location for a given identifier. */ protected static class ComputeSourceRunnable implements ASTRunnable { - private final ITranslationUnit fTU; private final IRegion fTextRegion; + private final String fSelection; private final IProgressMonitor fMonitor; private String fSource; /** - * @param tUnit - * @param textRegion + * @param tUnit the translation unit + * @param textRegion the selected region + * @param selection the text of the selected region without */ - public ComputeSourceRunnable(ITranslationUnit tUnit, IRegion textRegion) { + public ComputeSourceRunnable(ITranslationUnit tUnit, IRegion textRegion, String selection) { fTU= tUnit; fTextRegion= textRegion; + fSelection = selection; fMonitor= new NullProgressMonitor(); fSource= null; } /* - * @see org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable#runOnAST(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit) + * @see org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable#runOnAST(IASTTranslationUnit) */ @Override public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) { if (ast != null) { try { - IASTName name= ast.getNodeSelector(null).findEnclosingName(fTextRegion.getOffset(), fTextRegion.getLength()); - if (name != null) { - IBinding binding= name.resolveBinding(); - if (binding != null) { - - // Check for implicit names first, could be an implicit constructor call - if(name.getParent() instanceof IASTImplicitNameOwner) { - IASTImplicitNameOwner iastImplicitNameOwner = (IASTImplicitNameOwner) name.getParent(); - IASTName [] implicitNames = iastImplicitNameOwner.getImplicitNames(); - if(implicitNames.length == 1) { - IBinding implicitNameBinding = implicitNames[0].resolveBinding(); - if(implicitNameBinding instanceof ICPPConstructor) { - binding = implicitNameBinding; + IASTNodeSelector nodeSelector = ast.getNodeSelector(null); + if (fSelection.equals(Keywords.AUTO)) { + IASTNode node = nodeSelector.findEnclosingNode(fTextRegion.getOffset(), fTextRegion.getLength()); + if (node instanceof ICPPASTDeclSpecifier) { + ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) node; + IASTNode parent = declSpec.getParent(); + IASTDeclarator[] declarators = IASTDeclarator.EMPTY_DECLARATOR_ARRAY; + if (parent instanceof IASTSimpleDeclaration) { + declarators = ((IASTSimpleDeclaration) parent).getDeclarators(); + } else if (parent instanceof IASTParameterDeclaration) { + declarators = new IASTDeclarator[] { ((IASTParameterDeclaration) parent).getDeclarator() }; + } else if (parent instanceof ICPPASTTypeId) { + declarators = new IASTDeclarator[] { ((ICPPASTTypeId) parent).getAbstractDeclarator() }; + } + IType type = null; + for (IASTDeclarator declarator : declarators) { + IType t = CPPVisitor.createType(declarator); + if (type == null) { + type = t; + } else if (!type.isSameType(t)) { + // Type varies between declarators - don't display anything. + type = null; + break; + } + } + if (type != null && !(type instanceof IProblemType)) + fSource = ASTTypeUtil.getType(type, false); + } + } else { + IASTName name= nodeSelector.findEnclosingName(fTextRegion.getOffset(), fTextRegion.getLength()); + if (name != null) { + IBinding binding= name.resolveBinding(); + if (binding != null) { + // Check for implicit names first, could be an implicit constructor call. + if (name.getParent() instanceof IASTImplicitNameOwner) { + IASTImplicitNameOwner implicitNameOwner = (IASTImplicitNameOwner) name.getParent(); + IASTName[] implicitNames = implicitNameOwner.getImplicitNames(); + if (implicitNames.length == 1) { + IBinding implicitNameBinding = implicitNames[0].resolveBinding(); + if (implicitNameBinding instanceof ICPPConstructor) { + binding = implicitNameBinding; + } } } - } - - if (binding instanceof IProblemBinding) { - // report problem as source comment - if (DEBUG) { - IProblemBinding problem= (IProblemBinding) binding; - fSource= "/* Indexer Problem!\n" + //$NON-NLS-1$ - " * " + problem.getMessage() + //$NON-NLS-1$ - "\n */"; //$NON-NLS-1$ + + if (binding instanceof IProblemBinding) { + // Report problem as source comment. + if (DEBUG) { + IProblemBinding problem= (IProblemBinding) binding; + fSource= "/* Problem:\n" + //$NON-NLS-1$ + " * " + problem.getMessage() + //$NON-NLS-1$ + "\n */"; //$NON-NLS-1$ + } + } else if (binding instanceof IMacroBinding) { + fSource= computeSourceForMacro(ast, name, binding); + } else { + fSource= computeSourceForBinding(ast, binding); } - } else if (binding instanceof IMacroBinding) { - fSource= computeSourceForMacro(ast, name, binding); - } else { - fSource= computeSourceForBinding(ast, binding); - } - if (fSource != null) { - return Status.OK_STATUS; } } } - } catch (CoreException exc) { - return exc.getStatus(); - } catch (DOMException exc) { - return new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Internal Error", exc); //$NON-NLS-1$ + if (fSource != null) { + return Status.OK_STATUS; + } + } catch (CoreException e) { + return e.getStatus(); + } catch (DOMException e) { + return new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Internal Error", e); //$NON-NLS-1$ } } return Status.CANCEL_STATUS; @@ -219,8 +267,8 @@ public class CSourceHover extends AbstractCEditorTextHover { private String computeSourceForBinding(IASTTranslationUnit ast, IBinding binding) throws CoreException, DOMException { IName[] names = findDefsOrDecls(ast, binding); - // in case the binding is a non-explicit specialization we need - // to consider the original binding (bug 281396) + // In case the binding is a non-explicit specialization we need + // to consider the original binding (bug 281396). while (names.length == 0 && binding instanceof ICPPSpecialization) { IBinding specializedBinding = ((ICPPSpecialization) binding).getSpecializedBinding(); if (specializedBinding == null || specializedBinding instanceof IProblemBinding) { @@ -270,29 +318,29 @@ public class CSourceHover extends AbstractCEditorTextHover { IPath location= Path.fromOSString(fileName); LocationKind locationKind= LocationKind.LOCATION; if (name instanceof IASTName && !name.isReference()) { - IASTName astName= (IASTName)name; + IASTName astName= (IASTName) name; if (astName.getTranslationUnit().getFilePath().equals(fileName)) { int hoverOffset = fTextRegion.getOffset(); if (hoverOffset <= nodeOffset && nodeOffset < hoverOffset + fTextRegion.getLength() || hoverOffset >= nodeOffset && hoverOffset < nodeOffset + nodeLength) { - // bug 359352 - don't show source if its the same we are hovering on - return null; + // Bug 359352 - don't show source if its the same we are hovering on. + return computeHoverForDeclaration(astName); } if (fTU.getResource() != null) { - // reuse editor buffer for names local to the translation unit + // Reuse editor buffer for names local to the translation unit location= fTU.getResource().getFullPath(); locationKind= LocationKind.IFILE; } } } else { - // try to resolve path to a resource for proper encoding (bug 221029) + // Try to resolve path to a resource for proper encoding (bug 221029) IFile file= EditorUtility.getWorkspaceFileAtLocation(location, fTU); if (file != null) { location= file.getFullPath(); locationKind= LocationKind.IFILE; if (name instanceof IIndexName) { - // need to adjust index offsets to current offsets - // in case file has been modified since last index time + // Need to adjust index offsets to current offsets + // in case file has been modified since last index time. IIndexName indexName= (IIndexName) name; long timestamp= indexName.getFile().getTimestamp(); IPositionConverter converter= CCorePlugin.getPositionTrackerManager().findPositionConverter(file, timestamp); @@ -331,7 +379,7 @@ public class CSourceHover extends AbstractCEditorTextHover { return null; } } else { - // expand source range to include preceding comment, if any + // Expand source range to include preceding comment, if any boolean isKnR= isKnRSource(name); sourceStart= computeSourceStart(doc, nameOffset, binding, isKnR); if (sourceStart == CHeuristicScanner.NOT_FOUND) { @@ -342,15 +390,46 @@ public class CSourceHover extends AbstractCEditorTextHover { String source= buffer.getDocument().get(sourceStart, sourceEnd - sourceStart); return source; - } catch (BadLocationException exc) { - // ignore - should not happen anyway - if (DEBUG) exc.printStackTrace(); + } catch (BadLocationException e) { + // Ignore - should not happen anyway + if (DEBUG) e.printStackTrace(); } finally { mgr.disconnect(location, LocationKind.LOCATION, fMonitor); } return null; } + /** + * Computes the hover containing the deduced type for a declaration based on {@code auto} + * keyword. + * + * @param name the name of the declarator + * @return the hover text, if the declaration is based on {@code auto} keyword, + * otherwise {@code null}. + */ + private String computeHoverForDeclaration(IASTName name) { + ICPPASTDeclarator declarator = + CPPVisitor.findAncestorWithType(name, ICPPASTDeclarator.class); + if (declarator == null) + return null; + IASTDeclaration declaration = + CPPVisitor.findAncestorWithType(declarator, IASTDeclaration.class); + IASTDeclSpecifier declSpec = null; + if (declaration instanceof IASTSimpleDeclaration) { + declSpec = ((IASTSimpleDeclaration) declaration).getDeclSpecifier(); + } else if (declaration instanceof IASTParameterDeclaration) { + declSpec = ((IASTParameterDeclaration) declaration).getDeclSpecifier(); + } + if (!(declSpec instanceof ICPPASTSimpleDeclSpecifier) || + ((ICPPASTSimpleDeclSpecifier) declSpec).getType() != IASTSimpleDeclSpecifier.t_auto) { + return null; + } + IType type = CPPVisitor.createType(declarator); + if (type instanceof IProblemType) + return null; + return ASTTypeUtil.getType(type, false) + " " + name.getRawSignature(); //$NON-NLS-1$ + } + /** * Determine if the name is part of a KnR function definition. * @param name @@ -455,7 +534,7 @@ public class CSourceHover extends AbstractCEditorTextHover { if (nextNonWS != CHeuristicScanner.NOT_FOUND) { int nextNonWSLine= doc.getLineOfOffset(nextNonWS); int lineOffset= doc.getLineOffset(nextNonWSLine); - if (doc.get(lineOffset, nextNonWS - lineOffset).trim().length() == 0) { + if (doc.get(lineOffset, nextNonWS - lineOffset).trim().isEmpty()) { sourceStart= doc.getLineOffset(nextNonWSLine); } } @@ -467,7 +546,7 @@ public class CSourceHover extends AbstractCEditorTextHover { private int computeSourceEnd(IDocument doc, int start, IBinding binding, boolean isDefinition, boolean isKnR) throws BadLocationException { int sourceEnd= start; CHeuristicScanner scanner= new CHeuristicScanner(doc); - // expand forward to the end of the definition/declaration + // Expand forward to the end of the definition/declaration boolean searchBrace= false; boolean searchSemi= false; boolean searchComma= false; @@ -498,7 +577,7 @@ public class CSourceHover extends AbstractCEditorTextHover { sourceEnd= doc.getLength(); } } - // expand region to include whole line + // Expand region to include whole line IRegion lineRegion= doc.getLineInformationOfOffset(sourceEnd); sourceEnd= lineRegion.getOffset() + lineRegion.getLength(); } else if (searchSemi) { @@ -506,7 +585,7 @@ public class CSourceHover extends AbstractCEditorTextHover { if (semi != CHeuristicScanner.NOT_FOUND) { sourceEnd= semi+1; } - // expand region to include whole line + // Expand region to include whole line IRegion lineRegion= doc.getLineInformationOfOffset(sourceEnd); sourceEnd= lineRegion.getOffset() + lineRegion.getLength(); } else if (searchComma) { @@ -552,8 +631,7 @@ public class CSourceHover extends AbstractCEditorTextHover { * @return an array of definitions, never null * @throws CoreException */ - private IName[] findDefinitions(IASTTranslationUnit ast, - IBinding binding) throws CoreException { + private IName[] findDefinitions(IASTTranslationUnit ast, IBinding binding) throws CoreException { IName[] declNames= ast.getDefinitionsInAST(binding); if (declNames.length == 0 && ast.getIndex() != null) { // search definitions in index @@ -570,8 +648,7 @@ public class CSourceHover extends AbstractCEditorTextHover { * @return an array of declarations, never null * @throws CoreException */ - private IName[] findDeclarations(IASTTranslationUnit ast, - IBinding binding) throws CoreException { + private IName[] findDeclarations(IASTTranslationUnit ast, IBinding binding) throws CoreException { IName[] declNames= ast.getDeclarationsInAST(binding); if (declNames.length == 0 && ast.getIndex() != null) { // search declarations in index @@ -586,7 +663,6 @@ public class CSourceHover extends AbstractCEditorTextHover { public String getSource() { return fSource; } - } /** @@ -605,12 +681,12 @@ public class CSourceHover extends AbstractCEditorTextHover { if (editor != null) { IEditorInput input= editor.getEditorInput(); IWorkingCopyManager manager= CUIPlugin.getDefault().getWorkingCopyManager(); - IWorkingCopy copy = manager.getWorkingCopy(input); + IWorkingCopy workingCopy = manager.getWorkingCopy(input); try { - if (copy == null || !copy.isConsistent()) { + if (workingCopy == null || !workingCopy.isConsistent()) { return null; } - } catch (CModelException exc) { + } catch (CModelException e) { return null; } @@ -618,22 +694,21 @@ public class CSourceHover extends AbstractCEditorTextHover { try { expression = textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength()); expression = expression.trim(); - if (expression.length() == 0) + if (expression.isEmpty()) return null; - //Before trying a search lets make sure that the user is not hovering over a keyword - if (selectionIsKeyword(expression)) + // Before trying a search lets make sure that the user is not hovering + // over a keyword other than 'auto'. + if (selectionIsKeyword(expression) && !expression.equals(Keywords.AUTO)) return null; - String source= null; + // Try with the indexer. + String source= searchInIndex(workingCopy, hoverRegion, expression); - // Try with the indexer - source= searchInIndex(copy, hoverRegion); - - if (source == null || source.trim().length() == 0) + if (source == null || source.trim().isEmpty()) return null; - // we are actually interested in the comments, too. + // We are actually interested in the comments, too. // source= removeLeadingComments(source); String delim= System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -645,7 +720,6 @@ public class CSourceHover extends AbstractCEditorTextHover { source = Strings.concatenate(sourceLines, delim); return source; - } catch (BadLocationException e) { } } @@ -680,7 +754,7 @@ public class CSourceHover extends AbstractCEditorTextHover { final int startLine= doc.getLineOfOffset(partitionOffset); final int lineOffset= doc.getLineOffset(startLine); if (partitionOffset == lineOffset || - doc.get(lineOffset, partitionOffset - lineOffset).trim().length() == 0) { + doc.get(lineOffset, partitionOffset - lineOffset).trim().isEmpty()) { return lineOffset; } return commentOffset; @@ -690,13 +764,13 @@ public class CSourceHover extends AbstractCEditorTextHover { final int startLine= doc.getLineOfOffset(partitionOffset); final int lineOffset= doc.getLineOffset(startLine); if (partitionOffset == lineOffset || - doc.get(lineOffset, partitionOffset - lineOffset).trim().length() == 0) { + doc.get(lineOffset, partitionOffset - lineOffset).trim().isEmpty()) { commentOffset= lineOffset; continue; } return commentOffset; } else if (IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())) { - if (doc.get(partition.getOffset(), partition.getLength()).trim().length() == 0) { + if (doc.get(partition.getOffset(), partition.getLength()).trim().isEmpty()) { continue; } if (commentOffset >= 0) { @@ -713,7 +787,6 @@ public class CSourceHover extends AbstractCEditorTextHover { return 4; } - /** * Strip the leading comment from the given source string. * @@ -732,13 +805,13 @@ public class CSourceHover extends AbstractCEditorTextHover { } i= reader.getOffset(); reader.close(); - } catch (IOException ex) { + } catch (IOException e) { i= 0; } finally { try { reader.close(); - } catch (IOException ex) { - CUIPlugin.log(ex); + } catch (IOException e) { + CUIPlugin.log(e); } } @@ -747,13 +820,14 @@ public class CSourceHover extends AbstractCEditorTextHover { return source.substring(i); } - protected String searchInIndex(final ITranslationUnit tUnit, IRegion textRegion) { - final ComputeSourceRunnable computer= new ComputeSourceRunnable(tUnit, textRegion); + protected String searchInIndex(final ITranslationUnit tUnit, IRegion textRegion, String selection) { + final ComputeSourceRunnable computer= new ComputeSourceRunnable(tUnit, textRegion, selection); Job job= new Job(CHoverMessages.CSourceHover_jobTitle) { @Override protected IStatus run(IProgressMonitor monitor) { try { - return ASTProvider.getASTProvider().runOnAST(tUnit, ASTProvider.WAIT_ACTIVE_ONLY, monitor, computer); + return ASTProvider.getASTProvider().runOnAST(tUnit, ASTProvider.WAIT_ACTIVE_ONLY, + monitor, computer); } catch (Throwable t) { CUIPlugin.log(t); } @@ -769,16 +843,15 @@ public class CSourceHover extends AbstractCEditorTextHover { job.schedule(); try { job.join(); - } catch (InterruptedException exc) { + } catch (InterruptedException e) { job.cancel(); return null; } return computer.getSource(); } - /** - * Test whether the given name is a known keyword. + * Checks whether the given name is a known keyword. * * @param name * @return true if the name is a known keyword or false if the @@ -802,7 +875,8 @@ public class CSourceHover extends AbstractCEditorTextHover { int orientation= SWT.NONE; if (editor instanceof IWorkbenchPartOrientation) orientation= ((IWorkbenchPartOrientation) editor).getOrientation(); - return new SourceViewerInformationControl(parent, false, orientation, getTooltipAffordanceString()); + return new SourceViewerInformationControl(parent, false, orientation, + getTooltipAffordanceString()); } }; }