From e430e7f6b4dd381ca271f89880b166412fd52948 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 20 Aug 2012 19:48:20 -0700 Subject: [PATCH 01/28] Code streamlining. --- .../parser/cpp/CPPASTTypeIdExpression.java | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java index 934fd0f8d29..5e0c71d7bff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java @@ -1,13 +1,13 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2012 IBM Corporation 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: - * John Camelon (IBM) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * John Camelon (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -40,16 +40,12 @@ public class CPPASTTypeIdExpression extends ASTNode implements ICPPASTTypeIdExpr public CPPASTTypeIdExpression copy() { return copy(CopyStyle.withoutLocations); } - + @Override public CPPASTTypeIdExpression copy(CopyStyle style) { - CPPASTTypeIdExpression copy = new CPPASTTypeIdExpression(op, typeId == null ? null - : typeId.copy(style)); - copy.setOffsetAndLength(this); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + CPPASTTypeIdExpression copy = + new CPPASTTypeIdExpression(op, typeId == null ? null : typeId.copy(style)); + return copy(copy, style); } @Override @@ -66,11 +62,11 @@ public class CPPASTTypeIdExpression extends ASTNode implements ICPPASTTypeIdExpr @Override public void setTypeId(IASTTypeId typeId) { assertNotFrozen(); - this.typeId = typeId; - if (typeId != null) { - typeId.setParent(this); - typeId.setPropertyInParent(TYPE_ID); - } + this.typeId = typeId; + if (typeId != null) { + typeId.setParent(this); + typeId.setPropertyInParent(TYPE_ID); + } } @Override @@ -87,9 +83,9 @@ public class CPPASTTypeIdExpression extends ASTNode implements ICPPASTTypeIdExpr default: break; } } - + if (typeId != null && !typeId.accept(action)) return false; - + if (action.shouldVisitExpressions) { switch (action.leave(this)) { case ASTVisitor.PROCESS_ABORT: return false; @@ -99,7 +95,7 @@ public class CPPASTTypeIdExpression extends ASTNode implements ICPPASTTypeIdExpr } return true; } - + @Override public ICPPEvaluation getEvaluation() { if (fEvaluation == null) { @@ -112,7 +108,7 @@ public class CPPASTTypeIdExpression extends ASTNode implements ICPPASTTypeIdExpr } return fEvaluation; } - + @Override public IType getExpressionType() { return getEvaluation().getTypeOrFunctionSet(this); From 9587961176c0446f7aa429352824603bc413256c Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 21 Aug 2012 18:56:35 -0700 Subject: [PATCH 02/28] Cosmetics. --- .../tests/IndexCPPBindingResolutionBugs.java | 228 +++++++++--------- 1 file changed, 112 insertions(+), 116 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java index de0b1a2065f..57f2c350297 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java @@ -75,25 +75,24 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas public ProjectWithDepProj() {setStrategy(new ReferencedProject(true));} public static TestSuite suite() {return suite(ProjectWithDepProj.class);} } - - public static void addTests(TestSuite suite) { + + public static void addTests(TestSuite suite) { suite.addTest(IndexCPPBindingResolutionBugsSingleProjectFirstAST.suite()); suite.addTest(SingleProject.suite()); suite.addTest(ProjectWithDepProj.suite()); } - + public static TestSuite suite() { return suite(IndexCPPBindingResolutionBugs.class); } - + public IndexCPPBindingResolutionBugs() { setStrategy(new SinglePDOMTestStrategy(true)); } - + // #define OBJ void foo() // #define FUNC() void bar() // #define FUNC2(A) void baz() - // #include "header.h" // @@ -102,43 +101,43 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // FUNC2(1) {} public void testBug208558() throws CoreException { IIndex index= getIndex(); - + IIndexMacro[] macrosA= index.findMacros("OBJ".toCharArray(), IndexFilter.ALL, npm()); IIndexMacro[] macrosB= index.findMacros("FUNC".toCharArray(), IndexFilter.ALL, npm()); IIndexMacro[] macrosC= index.findMacros("FUNC2".toCharArray(), IndexFilter.ALL, npm()); - + assertEquals(1, macrosA.length); assertEquals(1, macrosB.length); assertEquals(1, macrosC.length); IIndexMacro obj= macrosA[0]; IIndexMacro func= macrosB[0]; IIndexMacro func2= macrosC[0]; - + assertEquals("OBJ", new String(obj.getName())); assertEquals("FUNC", new String(func.getName())); assertEquals("FUNC2", new String(func2.getName())); - + assertEquals("void foo()", new String(obj.getExpansionImage())); assertEquals("void bar()", new String(func.getExpansionImage())); assertEquals("void baz()", new String(func2.getExpansionImage())); - + assertEquals("OBJ", new String(obj.getName())); assertNull(obj.getParameterList()); - + assertEquals("FUNC", new String(func.getName())); assertEquals(0, func.getParameterList().length); assertEquals("FUNC2", new String(func2.getName())); assertEquals(1, func2.getParameterList().length); assertEquals("A", new String(func2.getParameterList()[0])); - + IIndexBinding[] bindings= index.findBindings(Pattern.compile(".*"), false, IndexFilter.ALL, npm()); assertEquals(3, bindings.length); - + IIndexBinding foo= index.findBindings("foo".toCharArray(), IndexFilter.ALL, npm())[0]; IIndexBinding bar= index.findBindings("bar".toCharArray(), IndexFilter.ALL, npm())[0]; IIndexBinding baz= index.findBindings("baz".toCharArray(), IndexFilter.ALL, npm())[0]; - + assertEquals("foo", foo.getName()); assertEquals("bar", bar.getName()); assertEquals("baz", baz.getName()); @@ -146,7 +145,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertInstance(bar, ICPPFunction.class); assertInstance(baz, ICPPFunction.class); } - + // template // inline void testTemplate(T& aRef); // @@ -162,7 +161,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertInstance(b0, ICPPFunction.class); assertInstance(b0, ICPPTemplateInstance.class); } - + // class testdef{ // // public: @@ -175,7 +174,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // // testdef* global_cBase; // testdef*& global_cBaseRef = global_cBase; - + // #include "typedefHeader.h" // // @@ -183,7 +182,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // { // testdef* local_cBase; // testdef*& local_cBaseRef = local_cBase; - // + // // testCall( /*1*/ (void *) local_cBase); // testCall( /*2*/ local_cBase); // @@ -206,18 +205,17 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas IBinding b7= getBindingFromASTName("testCall( /*7*/", 8); IBinding b8= getBindingFromASTName("testCall( /*8*/", 8); } - - + // template // class A {}; - // + // // template // class B : public A {}; - // + // // class C {}; // // B b; - + // void foo() {C c; B b;} public void testBug188274() throws Exception { IBinding b0= getBindingFromASTName("C", 1); @@ -226,7 +224,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertInstance(b1, ICPPClassType.class); assertInstance(b1, ICPPClassTemplate.class); assertInstance(b1, ICPPInstanceCache.class); - + ICPPInstanceCache ct= (ICPPInstanceCache) b1; ICPPSpecialization inst= ct.getInstance(new ICPPTemplateArgument[]{new CPPTemplateTypeArgument((IType)b0)}); assertInstance(inst, ICPPClassType.class); @@ -235,9 +233,9 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertEquals(1, bases.length); assertInstance(bases[0].getBaseClass(), ICPPClassType.class); } - + // namespace ns {class A{};} - + // ns::A a; // class B {}; public void testBug188324() throws Exception { @@ -247,41 +245,41 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas ICPPNamespace ns= (ICPPNamespace) b0; assertEquals(0, ns.getNamespaceScope().getBindings(name, false, false).length); } - + // template // class C : public C {}; - + // void foo() { // C::unresolvable(); // }; public void testBug185828() throws Exception { // Bug 185828 reports a StackOverflowException is thrown before we get here. // That the SOE is thrown is detected in BaseTestCase via an Error IStatus - + IBinding b0= getBindingFromASTName("C", 1); IBinding b1= getBindingFromASTName("C", 6); IBinding b2= getProblemFromASTName("unresolvable", 12); - + assertInstance(b0, ICPPClassType.class); assertInstance(b0, ICPPClassTemplate.class); - + assertInstance(b1, ICPPClassType.class); assertInstance(b1, ICPPSpecialization.class); } - + // class MyClass { // public: // template - // T* MopGetObject(T*& aPtr) + // T* MopGetObject(T*& aPtr) // { return 0; } - // - // - // template + // + // + // template // T* MopGetObjectNoChaining(T*& aPtr) // { return 0; } // // }; - + // int main() { // MyClass* cls= new MyClass(); // } @@ -294,12 +292,12 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertInstance(ms[0], ICPPTemplateDefinition.class); assertInstance(ms[1], ICPPTemplateDefinition.class); } - + // // header file // class cl; // typedef cl* t1; // typedef t1 t2; - + //// referencing content // void func(t2 a); // void func(int b); @@ -310,10 +308,10 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas public void testBug166954() { IBinding b0 = getBindingFromASTName("func(a)", 4); } - + // // header - // class Base { - // public: + // class Base { + // public: // void foo(int i); // int fooint(); // char* fooovr(); @@ -351,10 +349,9 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas getBindingFromASTName("fooovr('", 6); } - // // header - // class Base { - // public: + // class Base { + // public: // void foo(int i); // int foo2(int i); // }; @@ -382,9 +379,9 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas getBindingFromASTName("k=2", 1); getBindingFromASTName("l=2", 1); } - + // namespace X {} - + // namespace Y { // class Ambiguity {}; // enum Ambiguity {A1,A2,A3}; @@ -400,9 +397,9 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertNotNull(name); IBinding binding2= adapted.getNamespaceScope().getBinding(name, true); } - + // namespace X {int i;} - + // // references // #include "header.h" // int a= X::i; @@ -411,10 +408,10 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertTrue(binding instanceof ICPPVariable); IScope scope= binding.getScope(); } - + // template // class A {}; - + // template<> // class A {}; public void testBug180784() throws Exception { @@ -432,7 +429,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertNotNull(map.get(ps[1])); assertNotNull(map.get(ps[2])); } - + // class A{}; // // template @@ -442,7 +439,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // A id (A a) {return a;} // // int id(int x) {return x;} - + // void foo() { // id(*new A()); // id(6); @@ -453,10 +450,9 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas IBinding b0= getBindingFromASTName("id(*", 2); IBinding b1= getBindingFromASTName("id(6", 2); } - - + // void func1(void); - + // #include "header.h" // // int main(void) @@ -467,7 +463,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas IBinding b0 = getBindingFromASTName("func1;", 5); assertTrue(b0 instanceof IFunction); } - + // class B { // public: // class BB { @@ -477,9 +473,9 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // }; // // class A : public B::BB {}; - + // #include "header.h" - // + // // void foo() { // A c; // c.field;//comment @@ -488,7 +484,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas IBinding b0 = getBindingFromASTName("field;//", 5); assertTrue(b0 instanceof ICPPField); } - + // typedef struct { // int utm; // } usertype; @@ -532,9 +528,9 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas type= ((ITypedef) type).getType(); assertTrue(type instanceof IEnumeration); } - + // // no header needed - + // typedef class { // int member; // } t_class; @@ -570,7 +566,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertTrue(tdIndex instanceof IIndexBinding); assertTrue(tdAST instanceof ITypedef); assertTrue(tdIndex instanceof ITypedef); - + tAST= ((ITypedef) tdAST).getType(); tIndex= ((ITypedef) tdIndex).getType(); assertTrue(tAST instanceof ICompositeType); @@ -585,7 +581,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertTrue(tdIndex instanceof IIndexBinding); assertTrue(tdAST instanceof ITypedef); assertTrue(tdIndex instanceof ITypedef); - + tAST= ((ITypedef) tdAST).getType(); tIndex= ((ITypedef) tdIndex).getType(); assertTrue(tAST instanceof ICompositeType); @@ -600,7 +596,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertTrue(tdIndex instanceof IIndexBinding); assertTrue(tdAST instanceof ITypedef); assertTrue(tdIndex instanceof ITypedef); - + tAST= ((ITypedef) tdAST).getType(); tIndex= ((ITypedef) tdIndex).getType(); assertTrue(tAST instanceof IEnumeration); @@ -610,7 +606,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas } // // no header needed - + // namespace ns { // typedef class { // int member; @@ -648,7 +644,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertTrue(tdIndex instanceof IIndexBinding); assertTrue(tdAST instanceof ITypedef); assertTrue(tdIndex instanceof ITypedef); - + tAST= ((ITypedef) tdAST).getType(); tIndex= ((ITypedef) tdIndex).getType(); assertTrue(tAST instanceof ICompositeType); @@ -663,7 +659,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertTrue(tdIndex instanceof IIndexBinding); assertTrue(tdAST instanceof ITypedef); assertTrue(tdIndex instanceof ITypedef); - + tAST= ((ITypedef) tdAST).getType(); tIndex= ((ITypedef) tdIndex).getType(); assertTrue(tAST instanceof ICompositeType); @@ -678,7 +674,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertTrue(tdIndex instanceof IIndexBinding); assertTrue(tdAST instanceof ITypedef); assertTrue(tdIndex instanceof ITypedef); - + tAST= ((ITypedef) tdAST).getType(); tIndex= ((ITypedef) tdIndex).getType(); assertTrue(tAST instanceof IEnumeration); @@ -686,7 +682,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertTrue(tAST.isSameType(tIndex)); assertTrue(tIndex.isSameType(tAST)); } - + // namespace FOO { // namespace BAR { // class Bar; @@ -699,7 +695,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // #include "header.h" // namespace FOO { // using BAR::Bar; - // + // // Bar* Foo::Test(Bar* pBar) { // return pBar; // } @@ -716,13 +712,13 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertTrue(cl instanceof ICPPClassType); assertEquals("BAR", cl.getScope().getScopeName().toString()); } - + // struct outer { // union { // int var1; // }; // }; - + // #include "header.h" // void test() { // struct outer x; @@ -746,7 +742,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // int var2; // } hide; // }; - + // #include "header.h" // void test() { // union outer x; @@ -761,15 +757,15 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas IScope outer= f.getCompositeTypeOwner().getScope(); assertTrue(outer instanceof ICPPClassScope); assertEquals("outer", outer.getScopeName().toString()); - + getProblemFromASTName("var2=", 4); } - + // namespace ns { // int v; // }; // using namespace ns; - + // #include "header.h" // void test() { // v=1; @@ -781,8 +777,8 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas IScope scope= v.getScope(); assertTrue(scope instanceof ICPPNamespaceScope); assertEquals("ns", scope.getScopeName().toString()); - } - + } + // namespace NSA { // int a; // } @@ -813,7 +809,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertTrue(scope instanceof ICPPNamespaceScope); assertEquals("NSB", scope.getScopeName().toString()); } - + // namespace N { namespace M {}} // namespace N {using namespace N::M;} @@ -822,9 +818,9 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas public void testEndlessLoopWithUsingDeclaration_Bug209813() throws DOMException { getProblemFromASTName("x;", 1); } - + // class MyClass {}; - + // void test(MyClass* ptr); // class MyClass; public void testClassRedeclarationAfterReference_Bug229571() throws Exception { @@ -835,7 +831,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas type= ((IPointerType) type).getType(); assertSame(type, cl); } - + // class A { // public: // void foo() const volatile; @@ -847,7 +843,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // void bar() const; // void bar(); // }; - + // void A::foo() const volatile { bar();/*1*/ } // void A::foo() volatile { bar();/*2*/ } // void A::foo() const { bar();/*3*/ } @@ -871,12 +867,12 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas 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()); assertTrue(!bar_ft.isConst()); assertTrue(!bar_ft.isVolatile()); - + bar_cv= getBindingFromASTName("bar();/*5*/", 3, ICPPMethod.class); bar_v= getBindingFromASTName("bar();/*6*/", 3, ICPPMethod.class); bar_c= getBindingFromASTName("bar();/*7*/", 3, ICPPMethod.class); @@ -885,18 +881,18 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas 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()); } - + // typedef char t[12]; // void test1(char *); // void test2(char []); // void test3(t); - + // void xx() { // char* x= 0; // test1(x); @@ -908,7 +904,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas getBindingFromASTName("test2(x)", 5, ICPPFunction.class); getBindingFromASTName("test3(x)", 5, ICPPFunction.class); } - + // class A { // A(); // void l(); @@ -965,7 +961,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // int h; // class P {}; // }; - + // C c; // CT ct; // CT ctinst; @@ -1044,7 +1040,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertBindings(new String[] {"f", "g"}, ClassTypeHelper.getFields(ct, null)); assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); assertBindings(new String[] {"O"}, ClassTypeHelper.getNestedClasses(ct, null)); - + // explicit class specialization ct= getBindingFromASTName("C espec", 1); assertInstance(ct, ICPPClassSpecialization.class); @@ -1071,7 +1067,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas } // void func(const int* x) {} - + // void func(int* p) { // const int* q = p; // func(q); @@ -1124,12 +1120,12 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas String[] actual= new String[binding.length]; for (int i = 0; i < actual.length; i++) { actual[i]= binding[i].getName(); - } + } Arrays.sort(actual); Arrays.sort(expected); assertEquals(toString(expected), toString(actual)); } - + private String toString(String[] actual) { StringBuilder buf= new StringBuilder(); buf.append('{'); @@ -1144,14 +1140,14 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas buf.append('}'); return buf.toString(); } - + // class Derived; // class X { // Derived* d; // }; // class Base {}; // void useBase(Base* b); - + // class Derived: Base {}; // void test() { // X x; @@ -1160,7 +1156,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas public void testLateDefinitionOfInheritance_Bug292749() throws Exception { getBindingFromASTName("useBase(x.d", 7, ICPPFunction.class); } - + // namespace one { // void fx(); // void fx(int); @@ -1169,7 +1165,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // namespace two { // using one::fx; // } - + // #include "header.h" // void test() { // two::fx(); @@ -1181,7 +1177,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas getBindingFromASTName("fx(1);", 2, ICPPFunction.class); getBindingFromASTName("fx(1,1);", 2, ICPPFunction.class); } - + // struct YetAnotherTest { // void test(); // friend class InnerClass3; @@ -1201,10 +1197,10 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas public void testElaboratedTypeSpecifier_Bug303739() throws Exception { getBindingFromASTName("member=0", -2, ICPPField.class); } - + // typedef int xxx::* MBR_PTR; - - // void test() { + + // void test() { // MBR_PTR x; // } public void testProblemInIndexBinding_Bug317146() throws Exception { @@ -1248,8 +1244,8 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, // int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, // int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); - - // void test() { + + // void test() { // f255( // 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -1272,11 +1268,11 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas public void testFunctionsWithManyParameters_Bug319186() throws Exception { getBindingFromASTName("f255", 0); getBindingFromASTName("f256", 0); - } - + } + // void f(char16_t x); // void f(char32_t x); - + // void test() { // char16_t c16; // char32_t c32; @@ -1285,11 +1281,11 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas public void testChar16_Bug319186() throws Exception { IFunction f= getBindingFromASTName("f(c16)", 1); assertEquals("char16_t", ASTTypeUtil.getType(f.getType().getParameterTypes()[0])); - + f= getBindingFromASTName("f(c32)", 1); assertEquals("char32_t", ASTTypeUtil.getType(f.getType().getParameterTypes()[0])); } - + // namespace ns { // extern int* var; // void fun(); @@ -1298,7 +1294,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // using ns::var; // using ns::fun; // using ns::Type; - + // #include "header.h" // using namespace ::ns; // void sabel() { @@ -1311,12 +1307,12 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas IFunction f= getBindingFromASTName("fun", 0); ITypedef t= getBindingFromASTName("Type", 0); } - + // struct base { // virtual void operator+(base const &) { } // virtual void operator-(base const &) { } // }; - + // #include "header.h" // struct inter : public base { // virtual void operator+(base const &){} @@ -1326,14 +1322,14 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // base *left, *right; // // *left + *right; - // *left - *right; + // *left - *right; // } // }; public void test_Bug356982() throws Exception { IASTName name= findName("+ ", 1); assertTrue(name instanceof IASTImplicitName); assertEquals("base", name.resolveBinding().getOwner().getName()); - + name= findName("- ", 1); assertTrue(name instanceof IASTImplicitName); assertEquals("base", name.resolveBinding().getOwner().getName()); From 3b7da721b60c53f8f3e5baedeb41542f9d28d0d8 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 22 Aug 2012 10:18:46 -0700 Subject: [PATCH 03/28] Bug 367993 - Error due to CDT not recognizing compiler built-ins like __is_pod. --- .../core/parser/tests/ast2/AST2BaseTest.java | 2 +- .../parser/tests/ast2/AST2TemplateTests.java | 25 +- .../tests/ast2/ClassTypeHelperTests.java | 122 ------ .../parser/tests/ast2/DOMParserTestSuite.java | 2 +- .../ast2/GCCCompleteParseExtensionsTest.java | 2 +- .../parser/tests/ast2/TypeTraitsTests.java | 239 +++++++++++ .../cdt/core/dom/rewrite/TypeHelper.java | 6 +- .../core/dom/parser/SizeofCalculator.java | 15 + .../cdt/internal/core/dom/parser/Value.java | 152 ++++++- .../core/dom/parser/cpp/ClassTypeHelper.java | 381 ++++++------------ .../parser/cpp/semantics/CPPEvaluation.java | 10 - .../semantics/CPPVariableReadWriteFlags.java | 3 +- .../dom/parser/cpp/semantics/Conversions.java | 2 +- .../cpp/semantics/EvalBinaryTypeId.java | 10 +- .../dom/parser/cpp/semantics/EvalUnary.java | 5 +- .../parser/cpp/semantics/EvalUnaryTypeID.java | 53 +-- .../dom/parser/cpp/semantics/TypeTraits.java | 328 +++++++++++++++ .../LRGCCCompleteParseExtensionsTest.java | 2 +- 18 files changed, 866 insertions(+), 493 deletions(-) delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ClassTypeHelperTests.java create mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TypeTraitsTests.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeTraits.java 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 3cdbabd1573..dbebb3faec8 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 @@ -105,7 +105,7 @@ public class AST2BaseTest extends BaseTestCase { private static Map getGnuMap() { Map map= new HashMap(); map.put("__GNUC__", "4"); - map.put("__GNUC_MINOR__", "5"); + map.put("__GNUC_MINOR__", "7"); map.put("__SIZEOF_INT__", "4"); map.put("__SIZEOF_LONG__", "8"); return map; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index a35448d8d20..2f54ed2d440 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -1330,7 +1330,7 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPClassType sc0= assertInstance(b0.getSpecializedBinding(), ICPPClassType.class); ICPPClassType sc1= assertInstance(b1.getSpecializedBinding(), ICPPClassType.class); assertTrue(sc0.isSameType(sc1)); - + assertInstance(b0, ICPPSpecialization.class); assertInstance(b1, ICPPTemplateInstance.class); @@ -5988,4 +5988,27 @@ public class AST2TemplateTests extends AST2BaseTest { public void testSFINAE_b() throws Exception { parseAndCheckBindings(); } + + // template + // struct is_pod { + // static const bool value = __is_pod(T); + // }; + // + // template + // struct enable_if {}; + // + // template + // struct enable_if { + // typedef T type; + // }; + // + // template + // void f(typename enable_if::value>::type* = 0); + // + // void test() { + // f(); + // } + public void testIsPOD_367993() throws Exception { + parseAndCheckBindings(getAboveComment(), CPP, true); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ClassTypeHelperTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ClassTypeHelperTests.java deleted file mode 100644 index aadfeac5678..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ClassTypeHelperTests.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc 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: - * Sergey Prigogin (Google) - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests.ast2; - -import java.io.IOException; - -import junit.framework.TestSuite; - -import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; -import org.eclipse.cdt.internal.core.parser.ParserException; - -/** - * Tests for ClassTypeHelper class. - */ -public class ClassTypeHelperTests extends AST2BaseTest { - - public ClassTypeHelperTests() { - } - - public ClassTypeHelperTests(String name) { - super(name); - } - - public static TestSuite suite() { - return suite(ClassTypeHelperTests.class); - } - - protected BindingAssertionHelper getAssertionHelper() throws ParserException, IOException { - String code= getAboveComment(); - return new BindingAssertionHelper(code, true); - } - - // struct A { - // A(const A& a); - // }; - // - // class B { - // public: - // B(); - // int x; - // A* y; - // const A& z; - // static A s; - // }; - // - // class C { - // public: - // A a; - // }; - public void testHasTrivialCopyCtor() throws Exception { - BindingAssertionHelper helper = getAssertionHelper(); - ICPPClassType classA = helper.assertNonProblem("A {", 1, ICPPClassType.class); - assertFalse(ClassTypeHelper.hasTrivialCopyCtor(classA, null)); - ICPPClassType classB = helper.assertNonProblem("B {", 1, ICPPClassType.class); - assertTrue(ClassTypeHelper.hasTrivialCopyCtor(classB, null)); - ICPPClassType classC = helper.assertNonProblem("C {", 1, ICPPClassType.class); - assertFalse(ClassTypeHelper.hasTrivialCopyCtor(classC, null)); - } - - // struct A { - // ~A(); - // }; - // - // class B { - // public: - // B(); - // B(const B& a); - // int x; - // B* y; - // const B& z; - // static A s; - // }; - // - // class C { - // public: - // A a; - // }; - public void testHasTrivialDestructor() throws Exception { - BindingAssertionHelper helper = getAssertionHelper(); - ICPPClassType classA = helper.assertNonProblem("A {", 1, ICPPClassType.class); - assertFalse(ClassTypeHelper.hasTrivialDestructor(classA, null)); - ICPPClassType classB = helper.assertNonProblem("B {", 1, ICPPClassType.class); - assertTrue(ClassTypeHelper.hasTrivialDestructor(classB, null)); - ICPPClassType classC = helper.assertNonProblem("C {", 1, ICPPClassType.class); - assertFalse(ClassTypeHelper.hasTrivialDestructor(classC, null)); - } - - // struct A { - // virtual void m(); - // }; - // - // class B { - // public: - // B(); - // B(const B& a); - // void m(); - // int x; - // B* y; - // const B& z; - // }; - // - // class C : public A { - // }; - public void testIsPolymorphic() throws Exception { - BindingAssertionHelper helper = getAssertionHelper(); - ICPPClassType classA = helper.assertNonProblem("A {", 1, ICPPClassType.class); - assertTrue(ClassTypeHelper.isPolymorphic(classA)); - ICPPClassType classB = helper.assertNonProblem("B {", 1, ICPPClassType.class); - assertFalse(ClassTypeHelper.isPolymorphic(classB)); - ICPPClassType classC = helper.assertNonProblem("C", 1, ICPPClassType.class); - assertTrue(ClassTypeHelper.isPolymorphic(classC)); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMParserTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMParserTestSuite.java index aff28ece1a5..6b46417c965 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMParserTestSuite.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMParserTestSuite.java @@ -30,7 +30,7 @@ public class DOMParserTestSuite extends TestCase { suite.addTest(ASTCPPSpecDefectTests.suite()); suite.addTest(AST2CPPImplicitNameTests.suite()); suite.addTest(AST2TemplateTests.suite()); - suite.addTest(ClassTypeHelperTests.suite()); + suite.addTest(TypeTraitsTests.suite()); suite.addTestSuite(QuickParser2Tests.class); suite.addTest(CompleteParser2Tests.suite()); suite.addTest(DOMLocationTests.suite()); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCCompleteParseExtensionsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCCompleteParseExtensionsTest.java index be16c393abe..48f4e1a6c1a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCCompleteParseExtensionsTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCCompleteParseExtensionsTest.java @@ -426,7 +426,7 @@ public class GCCCompleteParseExtensionsTest extends AST2BaseTest { // b= __is_polymorphic (int); // b= __is_union (int); // } - public void testTypetraits_Bug342683() throws Exception { + public void testTypeTraits_Bug342683() throws Exception { parseGPP(getAboveComment()); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TypeTraitsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TypeTraitsTests.java new file mode 100644 index 00000000000..7fff28bb67d --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TypeTraitsTests.java @@ -0,0 +1,239 @@ +/******************************************************************************* + * Copyright (c) 2011, 2012 Google, Inc 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: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.parser.tests.ast2; + +import java.io.IOException; + +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.TypeTraits; +import org.eclipse.cdt.internal.core.parser.ParserException; + +/** + * Tests for ClassTypeHelper class. + */ +public class TypeTraitsTests extends AST2BaseTest { + + public TypeTraitsTests() { + } + + public TypeTraitsTests(String name) { + super(name); + } + + public static TestSuite suite() { + return suite(TypeTraitsTests.class); + } + + protected BindingAssertionHelper getAssertionHelper() throws ParserException, IOException { + String code= getAboveComment(); + return new BindingAssertionHelper(code, true); + } + + // struct A { + // A(const A& a); + // }; + // + // class B { + // public: + // B(); + // int x; + // A* y; + // const A& z; + // static A s; + // }; + // + // class C { + // public: + // A a; + // }; + public void testHasTrivialCopyCtor() throws Exception { + BindingAssertionHelper helper = getAssertionHelper(); + ICPPClassType classA = helper.assertNonProblem("A {", 1, ICPPClassType.class); + assertFalse(TypeTraits.hasTrivialCopyCtor(classA, null)); + ICPPClassType classB = helper.assertNonProblem("B {", 1, ICPPClassType.class); + assertTrue(TypeTraits.hasTrivialCopyCtor(classB, null)); + ICPPClassType classC = helper.assertNonProblem("C {", 1, ICPPClassType.class); + assertFalse(TypeTraits.hasTrivialCopyCtor(classC, null)); + } + + // struct A { + // ~A(); + // }; + // + // class B { + // public: + // B(); + // B(const B& a); + // int x; + // B* y; + // const B& z; + // static A s; + // }; + // + // class C { + // public: + // A a; + // }; + public void testHasTrivialDestructor() throws Exception { + BindingAssertionHelper helper = getAssertionHelper(); + ICPPClassType classA = helper.assertNonProblem("A {", 1, ICPPClassType.class); + assertFalse(TypeTraits.hasTrivialDestructor(classA, null)); + ICPPClassType classB = helper.assertNonProblem("B {", 1, ICPPClassType.class); + assertTrue(TypeTraits.hasTrivialDestructor(classB, null)); + ICPPClassType classC = helper.assertNonProblem("C {", 1, ICPPClassType.class); + assertFalse(TypeTraits.hasTrivialDestructor(classC, null)); + } + + // struct A { + // virtual void m(); + // }; + // + // class B { + // public: + // B(); + // B(const B& a); + // void m(); + // int x; + // B* y; + // const B& z; + // }; + // + // class C : public A { + // }; + public void testIsPolymorphic() throws Exception { + BindingAssertionHelper helper = getAssertionHelper(); + ICPPClassType classA = helper.assertNonProblem("A {", 1, ICPPClassType.class); + assertTrue(TypeTraits.isPolymorphic(classA, null)); + ICPPClassType classB = helper.assertNonProblem("B {", 1, ICPPClassType.class); + assertFalse(TypeTraits.isPolymorphic(classB, null)); + ICPPClassType classC = helper.assertNonProblem("C", 1, ICPPClassType.class); + assertTrue(TypeTraits.isPolymorphic(classC, null)); + } + + // struct A { + // A* a; + // int b; + // A(A* a, int b); + // A(A& a); + // ~A(); + // }; + // + // class B : public A { + // static int c; + // void m(A* a); + // }; + // + // class C : public A { + // int c; + // }; + // + // struct D { + // C c; + // }; + // + // struct E : public C { + // }; + // + // struct F : public B { + // virtual ~F(); + // }; + // + // struct G { + // int a; + // private: + // int b; + // }; + // + // struct H { + // int& a; + // }; + public void testIsStandardLayout() throws Exception { + BindingAssertionHelper helper = getAssertionHelper(); + ICPPClassType classA = helper.assertNonProblem("A {", 1, ICPPClassType.class); + assertTrue(TypeTraits.isStandardLayout(classA, null)); + ICPPClassType classB = helper.assertNonProblem("B {", 1, ICPPClassType.class); + assertTrue(TypeTraits.isStandardLayout(classB, null)); + ICPPClassType classC = helper.assertNonProblem("C :", 1, ICPPClassType.class); + assertFalse(TypeTraits.isStandardLayout(classC, null)); + ICPPClassType classD = helper.assertNonProblem("D {", 1, ICPPClassType.class); + assertFalse(TypeTraits.isStandardLayout(classD, null)); + ICPPClassType classE = helper.assertNonProblem("E :", 1, ICPPClassType.class); + assertFalse(TypeTraits.isStandardLayout(classE, null)); + ICPPClassType classF = helper.assertNonProblem("F :", 1, ICPPClassType.class); + assertFalse(TypeTraits.isStandardLayout(classF, null)); + ICPPClassType classG = helper.assertNonProblem("G {", 1, ICPPClassType.class); + assertFalse(TypeTraits.isStandardLayout(classG, null)); + ICPPClassType classH = helper.assertNonProblem("H {", 1, ICPPClassType.class); + assertFalse(TypeTraits.isStandardLayout(classH, null)); + } + + // struct A { + // A* a; + // int b; + // A(char* s); + // A(const A& a, int b); + // A& operator =(const A& a, A* b); + // }; + // + // class B : public A { + // A a; + // }; + // + // struct C { + // C(char* s = 0); + // }; + // + // struct D { + // D(const D& a, int b = 1); + // }; + // + // struct E { + // E& operator =(const E& a, E* b = nullptr); + // }; + // + // struct F { + // ~F(); + // }; + // + // struct G { + // C c; + // }; + // + // struct H : public C { + // }; + // + // struct I { + // virtual void m(); + // }; + public void testIsTrivial() throws Exception { + BindingAssertionHelper helper = getAssertionHelper(); + ICPPClassType classA = helper.assertNonProblem("A {", 1, ICPPClassType.class); + assertTrue(TypeTraits.isTrivial(classA, null)); + ICPPClassType classB = helper.assertNonProblem("B :", 1, ICPPClassType.class); + assertTrue(TypeTraits.isTrivial(classB, null)); + ICPPClassType classC = helper.assertNonProblem("C {", 1, ICPPClassType.class); + assertFalse(TypeTraits.isTrivial(classC, null)); + ICPPClassType classD = helper.assertNonProblem("D {", 1, ICPPClassType.class); + assertFalse(TypeTraits.isTrivial(classD, null)); + ICPPClassType classE = helper.assertNonProblem("E {", 1, ICPPClassType.class); + assertFalse(TypeTraits.isTrivial(classE, null)); + ICPPClassType classF = helper.assertNonProblem("F {", 1, ICPPClassType.class); + assertFalse(TypeTraits.isTrivial(classF, null)); + ICPPClassType classG = helper.assertNonProblem("G {", 1, ICPPClassType.class); + assertFalse(TypeTraits.isTrivial(classG, null)); + ICPPClassType classH = helper.assertNonProblem("H :", 1, ICPPClassType.class); + assertFalse(TypeTraits.isTrivial(classH, null)); + ICPPClassType classI = helper.assertNonProblem("I {", 1, ICPPClassType.class); + assertFalse(TypeTraits.isTrivial(classI, null)); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/rewrite/TypeHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/rewrite/TypeHelper.java index 6283e41a767..64d073363f3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/rewrite/TypeHelper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/rewrite/TypeHelper.java @@ -20,9 +20,9 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.TypeTraits; /** * A collection of static methods related to types. @@ -48,8 +48,8 @@ public class TypeHelper { if (type instanceof ICompositeType) { if (type instanceof ICPPClassType) { ICPPClassType classType = ((ICPPClassType) type); - if (!ClassTypeHelper.hasTrivialCopyCtor(classType, ast) || - !ClassTypeHelper.hasTrivialDestructor(classType, ast)) { + if (!TypeTraits.hasTrivialCopyCtor(classType, ast) || + !TypeTraits.hasTrivialDestructor(classType, ast)) { return true; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java index cdc024cd703..b8d7de011e3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser; import java.util.HashMap; import java.util.Map; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IArrayType; @@ -73,6 +74,20 @@ public class SizeofCalculator { private final IASTTranslationUnit ast; + /** + * Calculates size and alignment for the given type. + * + * @param type the type to get size and alignment for. + * @param point a node belonging to the AST of the translation unit defining context for + * the size calculation. + * @return size and alignment, or null if could not be calculated. + */ + public static SizeAndAlignment getSizeAndAlignment(IType type, IASTNode point) { + SizeofCalculator calc = point == null ? + getDefault() : ((ASTTranslationUnit) point.getTranslationUnit()).getSizeofCalculator(); + return calc.sizeAndAlignment(type); + } + /** * Returns the default instance of sizeof calculator. The default instance is not aware * of the parser configuration and can only calculate sizes that are the same across all diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java index 44e298d51fb..a3bc301dad0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java @@ -11,29 +11,58 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_alignof; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_nothrow_constructor; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_nothrow_copy; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_assign; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_constructor; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_copy; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_destructor; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_virtual_destructor; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_abstract; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_class; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_empty; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_enum; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_literal_type; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_pod; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_polymorphic; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_standard_layout; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_trivial; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_union; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_sizeof; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_typeid; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_typeof; + import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTBinaryTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTCastExpression; import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalBinding; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.TypeTraits; import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator; import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator.EvalException; import org.eclipse.cdt.internal.core.pdom.db.TypeMarshalBuffer; @@ -201,7 +230,7 @@ public class Value implements IValue { public static IValue evaluateBinaryExpression(final int op, final long v1, final long v2) { try { - return create(combineBinary(op, v1, v2)); + return create(applyBinaryOperator(op, v1, v2)); } catch (UnknownValueException e) { } return UNKNOWN; @@ -209,12 +238,101 @@ public class Value implements IValue { public static IValue evaluateUnaryExpression(final int unaryOp, final long value) { try { - return create(combineUnary(unaryOp, value)); + return create(applyUnaryOperator(unaryOp, value)); } catch (UnknownValueException e) { } return UNKNOWN; } + public static IValue evaluateUnaryTypeIdExpression(int operator, IType type, IASTNode point) { + try { + return create(applyUnaryTypeIdOperator(operator, type, point)); + } catch (UnknownValueException e) { + } + return UNKNOWN; + } + + public static IValue evaluateBinaryTypeIdExpression(IASTBinaryTypeIdExpression.Operator operator, + IType type1, IType type2, IASTNode point) { + try { + return create(applyBinaryTypeIdOperator(operator, type1, type2, point)); + } catch (UnknownValueException e) { + } + return UNKNOWN; + } + + private static long applyUnaryTypeIdOperator(int operator, IType type, IASTNode point) throws UnknownValueException{ + switch (operator) { + case op_sizeof: + return getSizeAndAlignment(type, point).size; + case op_alignof: + return getSizeAndAlignment(type, point).alignment; + case op_typeid: + break; // TODO(sprigogin): Implement + case op_has_nothrow_copy: + break; // TODO(sprigogin): Implement + case op_has_nothrow_constructor: + break; // TODO(sprigogin): Implement + case op_has_trivial_assign: + break; // TODO(sprigogin): Implement + case op_has_trivial_constructor: + break; // TODO(sprigogin): Implement + case op_has_trivial_copy: + return !(type instanceof ICPPClassType) || + TypeTraits.hasTrivialCopyCtor((ICPPClassType) type, point) ? 1 : 0; + case op_has_trivial_destructor: + break; // TODO(sprigogin): Implement + case op_has_virtual_destructor: + break; // TODO(sprigogin): Implement + case op_is_abstract: + return type instanceof ICPPClassType && + TypeTraits.isAbstract((ICPPClassType) type, point) ? 1 : 0; + case op_is_class: + return type instanceof ICompositeType && + ((ICompositeType) type).getKey() != ICompositeType.k_union ? 1 : 0; + case op_is_empty: + break; // TODO(sprigogin): Implement + case op_is_enum: + return type instanceof IEnumeration ? 1 : 0; + case op_is_literal_type: + break; // TODO(sprigogin): Implement + case op_is_pod: + return TypeTraits.isPOD(type, point) ? 1 : 0; + case op_is_polymorphic: + return type instanceof ICPPClassType && + TypeTraits.isPolymorphic((ICPPClassType) type, point) ? 1 : 0; + case op_is_standard_layout: + return TypeTraits.isStandardLayout(type, point) ? 1 : 0; + case op_is_trivial: + return type instanceof ICPPClassType && + TypeTraits.isTrivial((ICPPClassType) type, point) ? 1 : 0; + case op_is_union: + return type instanceof ICompositeType && + ((ICompositeType) type).getKey() == ICompositeType.k_union ? 1 : 0; + case op_typeof: + break; // TODO(sprigogin): Implement + } + throw UNKNOWN_EX; + } + + public static long applyBinaryTypeIdOperator(IASTBinaryTypeIdExpression.Operator operator, + IType type1, IType type2, IASTNode point) throws UnknownValueException { + switch (operator) { + case __is_base_of: + if (type1 instanceof ICPPClassType && type1 instanceof ICPPClassType) { + return ClassTypeHelper.isSubclass((ICPPClassType) type2, (ICPPClassType) type1) ? 1 : 0; + } + } + throw UNKNOWN_EX; + } + + private static SizeAndAlignment getSizeAndAlignment(IType type, IASTNode point) throws UnknownValueException { + SizeAndAlignment sizeAndAlignment = SizeofCalculator.getSizeAndAlignment(type, point); + if (sizeAndAlignment == null) + throw UNKNOWN_EX; + return sizeAndAlignment; + } + /** * Tests whether the value is a template parameter (or a parameter pack). * @@ -348,19 +466,15 @@ public class Value implements IValue { } } if (exp instanceof IASTTypeIdExpression) { - IASTTypeIdExpression typeIdEx = (IASTTypeIdExpression) exp; - switch (typeIdEx.getOperator()) { - case IASTTypeIdExpression.op_sizeof: - ASTTranslationUnit ast = (ASTTranslationUnit) typeIdEx.getTranslationUnit(); - final IType type = ast.createType(typeIdEx.getTypeId()); - if (type instanceof ICPPUnknownType) - return null; - SizeofCalculator calculator = ast.getSizeofCalculator(); - SizeAndAlignment info = calculator.sizeAndAlignment(type); - if (info == null) - throw UNKNOWN_EX; - return info.size; - } + ASTTranslationUnit ast = (ASTTranslationUnit) exp.getTranslationUnit(); + final IType type = ast.createType(((IASTTypeIdExpression) exp).getTypeId()); + if (type instanceof ICPPUnknownType) + return null; + return applyUnaryTypeIdOperator(((IASTTypeIdExpression) exp).getOperator(), type, exp); + } + + if (exp instanceof IASTBinaryTypeIdExpression) { + } throw UNKNOWN_EX; } @@ -422,10 +536,10 @@ public class Value implements IValue { final Long value= evaluate(exp.getOperand(), maxdepth); if (value == null) return null; - return combineUnary(unaryOp, value); + return applyUnaryOperator(unaryOp, value); } - private static long combineUnary(final int unaryOp, final long value) throws UnknownValueException { + private static long applyUnaryOperator(final int unaryOp, final long value) throws UnknownValueException { switch (unaryOp) { case IASTUnaryExpression.op_bracketedPrimary: case IASTUnaryExpression.op_plus: @@ -470,10 +584,10 @@ public class Value implements IValue { if (o2 == null) return null; - return combineBinary(op, o1, o2); + return applyBinaryOperator(op, o1, o2); } - private static long combineBinary(final int op, final long v1, final long v2) + private static long applyBinaryOperator(final int op, final long v1, final long v2) throws UnknownValueException { switch (op) { case IASTBinaryExpression.op_multiply: diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java index 3ddeba3b2fb..615bb1a3eb8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java @@ -15,9 +15,6 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.ARRAY; -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.TDEF; import java.util.ArrayList; import java.util.Collections; @@ -39,7 +36,6 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IField; -import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IScope; @@ -60,8 +56,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; 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.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.index.IIndex; @@ -78,8 +74,8 @@ import org.eclipse.core.runtime.CoreException; /** * Holds common implementation of methods for ICPPClassType implementations that have - * a corresponding textual definition in the source code. - * + * a corresponding textual definition in the source code. + * * @see CPPClassType * @see CPPClassTemplate */ @@ -101,8 +97,9 @@ public class ClassTypeHelper { ObjectSet resultSet = new ObjectSet(2); IASTDeclaration[] members = host.getCompositeTypeSpecifier().getMembers(); for (IASTDeclaration decl : members) { - while (decl instanceof ICPPASTTemplateDeclaration) + while (decl instanceof ICPPASTTemplateDeclaration) { decl = ((ICPPASTTemplateDeclaration) decl).getDeclaration(); + } if (decl instanceof IASTSimpleDeclaration) { ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) decl).getDeclSpecifier(); @@ -115,7 +112,7 @@ public class ClassTypeHelper { if (dtor == null) break; dtor= ASTQueries.findInnermostDeclarator(dtor); resultSet.put(dtor.getName().resolveBinding()); - } + } } } } else if (decl instanceof IASTFunctionDefinition) { @@ -134,7 +131,7 @@ public class ClassTypeHelper { /** * Checks if a binding is a friend of a class. Only classes and functions can be friends of a class. * A class is considered a friend of itself. - * @param binding a binding. + * @param binding a binding. * @param classType a class. * @return true if binding is a friend of classType. */ @@ -198,7 +195,7 @@ public class ClassTypeHelper { bindings[i] = new CPPBaseClause(bases[i]); } - return bindings; + return bindings; } public static ICPPField[] getDeclaredFields(ICPPInternalClassTypeMixinHost host) { @@ -278,7 +275,7 @@ public class ClassTypeHelper { } /** - * Returns all direct and indirect base classes. + * Returns all direct and indirect base classes. * @param classType a class * @return An array of visible base classes in arbitrary order. */ @@ -296,7 +293,7 @@ public class ClassTypeHelper { IBinding b= base.getBaseClass(); if (b instanceof ICPPClassType) { final ICPPClassType baseClass = (ICPPClassType) b; - if (result.add(baseClass)) { + if (result.add(baseClass)) { getAllBases(baseClass, result, point); } } @@ -346,7 +343,7 @@ public class ClassTypeHelper { /** * Returns methods either declared by the given class or generated by the compiler. Does not - * include methods declared in base classes. + * include methods declared in base classes. */ private static ObjectSet getOwnMethods(ICPPClassType classType, IASTNode point) { ObjectSet set= new ObjectSet(4); @@ -460,7 +457,7 @@ public class ClassTypeHelper { } if (binding instanceof ICPPClassType) result = ArrayUtil.append(ICPPClassType.class, result, (ICPPClassType) binding); - } + } } return ArrayUtil.trim(ICPPClassType.class, result); } @@ -498,7 +495,7 @@ public class ClassTypeHelper { public static boolean isVirtual(ICPPMethod m) { if (m instanceof ICPPConstructor) return false; - if (m.isVirtual()) + if (m.isVirtual()) return true; final char[] mname= m.getNameCharArray(); @@ -528,7 +525,7 @@ public class ClassTypeHelper { IType[] paramsA = a.getParameterTypes(); IType[] paramsB = b.getParameterTypes(); - + if (paramsA.length == 1 && paramsB.length == 0) { if (!SemanticUtil.isVoidType(paramsA[0])) return false; @@ -550,9 +547,9 @@ public class ClassTypeHelper { * Returns {@code true} if {@code source} overrides {@code target}. */ public static boolean isOverrider(ICPPMethod source, ICPPMethod target) { - if (source instanceof ICPPConstructor || target instanceof ICPPConstructor) + if (source instanceof ICPPConstructor || target instanceof ICPPConstructor) return false; - if (!isVirtual(target)) + if (!isVirtual(target)) return false; if (!functionTypesAllowOverride(source.getType(), target.getType())) return false; @@ -580,7 +577,7 @@ public class ClassTypeHelper { final char[] mname= method.getNameCharArray(); final ICPPClassType mcl= method.getClassOwner(); - if (mcl == null) + if (mcl == null) return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; final ArrayList result= new ArrayList(); @@ -646,14 +643,14 @@ public class ClassTypeHelper { /** * Returns all methods found in the index, that override the given {@code method}. - * @throws CoreException + * @throws CoreException */ public static ICPPMethod[] findOverriders(IIndex index, ICPPMethod method) throws CoreException { if (!isVirtual(method)) return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; final ICPPClassType mcl= method.getClassOwner(); - if (mcl == null) + if (mcl == null) return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; ICPPClassType[] subclasses= getSubClasses(index, mcl); @@ -714,24 +711,76 @@ public class ClassTypeHelper { } } - private static final int KIND_DEFAULT_CTOR= 0; - private static final int KIND_COPY_CTOR= 1; - private static final int KIND_ASSIGNMENT_OP= 2; - private static final int KIND_DTOR= 3; - private static final int KIND_OTHER= 4; + public enum MethodKind { + DEFAULT_CTOR, + COPY_CTOR, + MOVE_CTOR, + COPY_ASSIGNMENT_OP, + MOVE_ASSIGNMENT_OP, + DTOR, + OTHER + } + + public static MethodKind getMethodKind(ICPPClassType classType, ICPPMethod method) { + if (method instanceof ICPPConstructor) { + final List params= getTypesOfRequiredParameters(method); + if (params.isEmpty()) + return MethodKind.DEFAULT_CTOR; + if (params.size() == 1) { + IType t= SemanticUtil.getNestedType(params.get(0), SemanticUtil.TDEF); + if (SemanticUtil.isVoidType(t)) + return MethodKind.DEFAULT_CTOR; + + ICPPReferenceType refToClass = getRefToClass(classType, t); + if (refToClass != null) + return refToClass.isRValueReference() ? MethodKind.MOVE_CTOR : MethodKind.COPY_CTOR; + } + return MethodKind.OTHER; + } + + if (method.isDestructor()) + return MethodKind.DTOR; + + if (CharArrayUtils.equals(method.getNameCharArray(), OverloadableOperator.ASSIGN.toCharArray())) { + final List params= getTypesOfRequiredParameters(method); + if (params.size() == 1) { + IType t= params.get(0); + ICPPReferenceType refToClass = getRefToClass(classType, t); + if (refToClass != null) + return refToClass.isRValueReference() ? MethodKind.MOVE_ASSIGNMENT_OP : MethodKind.COPY_ASSIGNMENT_OP; + } + return MethodKind.OTHER; + } + return MethodKind.OTHER; + } /** - * For implicit methods the exception specification is inherited, search it + * Returns types of method parameters that don't have defaults. + */ + private static List getTypesOfRequiredParameters(ICPPMethod method) { + ICPPParameter[] parameters = method.getParameters(); + if (parameters.length == 0) + return Collections.emptyList(); + List types = new ArrayList(parameters.length); + for (ICPPParameter parameter : parameters) { + if (!parameter.hasDefaultValue() && !parameter.isParameterPack()) + types.add(parameter.getType()); + } + return types; + } + + /** + * For implicit methods the exception specification is inherited, search it. */ public static IType[] getInheritedExceptionSpecification(ICPPMethod implicitMethod, IASTNode point) { // See 15.4.13 ICPPClassType owner= implicitMethod.getClassOwner(); - if (owner == null || ClassTypeHelper.getBases(owner, point).length == 0) + if (owner == null || ClassTypeHelper.getBases(owner, point).length == 0) return null; - // we use a list as types aren't comparable, and can have duplicates (15.4.6) - int kind= getImplicitMethodKind(owner, implicitMethod); - if (kind == KIND_OTHER) + // We use a list as types aren't comparable, and can have duplicates (15.4.6) + MethodKind kind= getMethodKind(owner, implicitMethod); + if (kind == MethodKind.OTHER) return null; List inheritedTypeids = new ArrayList(); @@ -741,7 +790,7 @@ public class ClassTypeHelper { ICPPMethod baseMethod= getMethodInClass(base, kind, point); if (baseMethod != null) { IType[] baseExceptionSpec= baseMethod.getExceptionSpecification(); - if (baseExceptionSpec == null) + if (baseExceptionSpec == null) return null; for (IType baseTypeId : baseMethod.getExceptionSpecification()) { inheritedTypeids.add(baseTypeId); @@ -752,275 +801,71 @@ public class ClassTypeHelper { return inheritedTypeids.toArray(new IType[inheritedTypeids.size()]); } - private static int getImplicitMethodKind(ICPPClassType ct, ICPPMethod method) { - if (method instanceof ICPPConstructor) { - final IFunctionType type= method.getType(); - final IType[] params= type.getParameterTypes(); - if (params.length == 0) - return KIND_DEFAULT_CTOR; - if (params.length == 1) { - IType t= SemanticUtil.getNestedType(params[0], SemanticUtil.TDEF); - if (SemanticUtil.isVoidType(t)) - return KIND_DEFAULT_CTOR; - - if (isRefToConstClass(ct, t)) - return KIND_COPY_CTOR; - } - return KIND_OTHER; + /** + * If {@code type} is a, possibly qualified, reference type referring to {@code classType}, + * returns that reference type. Otherwise returns {@code null}. + */ + private static ICPPReferenceType getRefToClass(ICPPClassType classType, IType type) { + while (type instanceof ITypedef) { + type= ((ITypedef) type).getType(); } - if (method.isDestructor()) - return KIND_DTOR; - - if (CharArrayUtils.equals(method.getNameCharArray(), OverloadableOperator.ASSIGN.toCharArray())) { - final IFunctionType type= method.getType(); - final IType[] params= type.getParameterTypes(); - if (params.length == 1) { - IType t= params[0]; - if (isRefToConstClass(ct, t)) - return KIND_ASSIGNMENT_OP; + if (type instanceof ICPPReferenceType) { + ICPPReferenceType refType = (ICPPReferenceType) type; + type= refType.getType(); + while (type instanceof ITypedef) { + type= ((ITypedef) type).getType(); + } + if (type instanceof IQualifierType) { + type= ((IQualifierType) type).getType(); + if (classType.isSameType(type)) + return refType; } - return KIND_OTHER; } - return KIND_OTHER; + return null; } - private static boolean isRefToConstClass(ICPPClassType ct, IType t) { - while (t instanceof ITypedef) - t= ((ITypedef) t).getType(); - - if (t instanceof ICPPReferenceType) { - t= ((ICPPReferenceType) t).getType(); - while (t instanceof ITypedef) - t= ((ITypedef) t).getType(); - if (t instanceof IQualifierType) { - t= ((IQualifierType) t).getType(); - return ct.isSameType(t); - } - } - return false; - } - - private static ICPPMethod getMethodInClass(ICPPClassType ct, int kind, IASTNode point) { + private static ICPPMethod getMethodInClass(ICPPClassType ct, MethodKind kind, IASTNode point) { switch (kind) { - case KIND_DEFAULT_CTOR: - case KIND_COPY_CTOR: + case DEFAULT_CTOR: + case COPY_CTOR: + case MOVE_CTOR: for (ICPPConstructor ctor : getConstructors(ct, point)) { - if (!ctor.isImplicit() && getImplicitMethodKind(ct, ctor) == kind) + if (!ctor.isImplicit() && getMethodKind(ct, ctor) == kind) return ctor; } return null; - case KIND_ASSIGNMENT_OP: + case COPY_ASSIGNMENT_OP: + case MOVE_ASSIGNMENT_OP: for (ICPPMethod method : getDeclaredMethods(ct, point)) { if (method instanceof ICPPConstructor) continue; - if (getImplicitMethodKind(ct, method) == kind) + if (getMethodKind(ct, method) == kind) return method; } return null; - case KIND_DTOR: + case DTOR: for (ICPPMethod method : getDeclaredMethods(ct, point)) { if (method.isDestructor()) return method; } return null; + case OTHER: + break; } return null; } - /** - * 8.5.1 Aggregates [dcl.init.aggr] - * An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), - * no private or protected non-static data members (Clause 11), - * no base classes (Clause 10), and no virtual functions (10.3). - */ - public static boolean isAggregateClass(ICPPClassType classTarget, IASTNode point) { - if (ClassTypeHelper.getBases(classTarget, point).length > 0) - return false; - ICPPMethod[] methods = ClassTypeHelper.getDeclaredMethods(classTarget, point); - for (ICPPMethod m : methods) { - if (m instanceof ICPPConstructor) - return false; - if (m.isVirtual()) { - return false; - } - } - ICPPField[] fields = ClassTypeHelper.getDeclaredFields(classTarget, point); - for (ICPPField field : fields) { - if (!(field.getVisibility() == ICPPMember.v_public || field.isStatic())) { - return false; - } - } - return true; - } - - /** - * Returns true if and only if the given class has a trivial copy constructor. - * A copy constructor is trivial if: - *
    - *
  • it is implicitly defined by the compiler, and
  • - *
  • isPolymorphic(classTarget) == false, and
  • - *
  • the class has no virtual base classes, and
  • - *
  • every direct base class has trivial copy constructor, and
  • - *
  • for every nonstatic data member that has class type or array of class type, that type - * has trivial copy constructor.
  • - *
- * Similar to std::tr1::has_trivial_copy. - * - * @param classTarget the class to check - * @return true if the class has a trivial copy constructor - */ - public static boolean hasTrivialCopyCtor(ICPPClassType classTarget, IASTNode point) { - if (getImplicitCopyCtor(classTarget) == null) - return false; - if (isPolymorphic(classTarget)) - return false; - for (ICPPBase base : classTarget.getBases()) { - if (base.isVirtual()) - return false; - } - for (ICPPClassType baseClass : getAllBases(classTarget, point)) { - if (!classTarget.isSameType(baseClass) && !hasTrivialCopyCtor(baseClass, point)) - return false; - } - for (ICPPField field : classTarget.getDeclaredFields()) { - if (!field.isStatic()) { - IType type = field.getType(); - type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY); - if (type instanceof ICPPClassType && !classTarget.isSameType(type) && - !hasTrivialCopyCtor((ICPPClassType) type, point)) { - return false; - } - } - } - return true; - } - - /** - * Returns the compiler-generated copy constructor for the given class, or null - * if the class doesn't have a compiler-generated copy constructor. - * - * @param classTarget the class to get the copy ctor for. - * @return the compiler-generated copy constructor, or null if the class doesn't - * have a compiler-generated copy constructor. - */ - private static ICPPConstructor getImplicitCopyCtor(ICPPClassType classTarget) { - for (ICPPConstructor ctor : classTarget.getConstructors()) { - if (ctor.isImplicit() && getImplicitMethodKind(classTarget, ctor) == KIND_COPY_CTOR) - return ctor; - } - return null; - } - - /** - * Returns true if and only if the given class has a trivial default constructor. - * A default constructor is trivial if: - *
    - *
  • it is implicitly defined by the compiler, and
  • - *
  • every direct base class has trivial default constructor, and
  • - *
  • for every nonstatic data member that has class type or array of class type, that type - * has trivial default constructor.
  • - *
- * Similar to std::tr1::has_trivial_default_constructor. - * - * @param classTarget the class to check - * @param point - * @return true if the class has a trivial default constructor - */ - public static boolean hasTrivialDefaultConstructor(ICPPClassType classTarget, IASTNode point) { - for (ICPPConstructor ctor : getConstructors(classTarget, point)) { - if (!ctor.isImplicit() && ctor.getParameters().length == 0) - return false; - } - for (ICPPClassType baseClass : getAllBases(classTarget, null)) { - if (!classTarget.isSameType(baseClass) && !hasTrivialDefaultConstructor(baseClass, point)) - return false; - } - for (ICPPField field : getDeclaredFields(classTarget, point)) { - if (!field.isStatic()) { - IType type = field.getType(); - type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY); - if (type instanceof ICPPClassType && !classTarget.isSameType(type) && - !hasTrivialDefaultConstructor((ICPPClassType) type, point)) { - return false; - } - } - } - return true; - } - - /** - * Returns true if and only if the given class has a trivial destructor. - * A destructor is trivial if: - *
    - *
  • it is implicitly defined by the compiler, and
  • - *
  • every direct base class has trivial destructor, and
  • - *
  • for every nonstatic data member that has class type or array of class type, that type - * has trivial destructor.
  • - *
- * Similar to std::tr1::has_trivial_destructor. - * - * @param classTarget the class to check - * @return true if the class has a trivial destructor - */ - public static boolean hasTrivialDestructor(ICPPClassType classTarget, IASTNode point) { - for (ICPPMethod method : getDeclaredMethods(classTarget, point)) { - if (method.isDestructor()) - return false; - } - for (ICPPClassType baseClass : getAllBases(classTarget, null)) { - if (!classTarget.isSameType(baseClass) && !hasTrivialDestructor(baseClass, point)) - return false; - } - for (ICPPField field : getDeclaredFields(classTarget, point)) { - if (!field.isStatic()) { - IType type = field.getType(); - type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY); - if (type instanceof ICPPClassType && !classTarget.isSameType(type) && - !hasTrivialDestructor((ICPPClassType) type, point)) { - return false; - } - } - } - return true; - } - - /** - * Returns true if and only if the given class declares or inherits a virtual - * function. Similar to std::tr1::is_polymorphic. - * - * @param classTarget the class to check - * @return true if the class declares or inherits a virtual function. - */ - public static boolean isPolymorphic(ICPPClassType classTarget) { - if (hasDeclaredVirtualMethod(classTarget)) - return true; - for (ICPPClassType baseClass : getAllBases(classTarget, null)) { - if (hasDeclaredVirtualMethod(baseClass)) - return true; - } - return false; - } - - private static boolean hasDeclaredVirtualMethod(ICPPClassType classTarget) { - for (ICPPMethod method : classTarget.getDeclaredMethods()) { - if (method.isVirtual()) { - return true; - } - } - return false; - } - /** * Checks whether class is abstract, i.e. has pure virtual functions that were * not implemented in base after declaration. - * + * * NOTE: The method produces complete results for template instantiations * but doesn't take into account base classes and methods dependent on unspecified * template parameters. */ public static ICPPMethod[] getPureVirtualMethods(ICPPClassType classType, IASTNode point) { - Map> result= collectPureVirtualMethods(classType, + Map> result= collectPureVirtualMethods(classType, new HashMap>>(), point); int resultArraySize = 0; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index 53b6ff28028..8c2d30ed54c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -23,12 +23,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; -import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; -import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; @@ -250,11 +247,4 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } return args; } - - protected static SizeAndAlignment getSizeAndAlignment(IType type, IASTNode point) { - SizeofCalculator calc = point == null ? - SizeofCalculator.getDefault() : - ((ASTTranslationUnit) point.getTranslationUnit()).getSizeofCalculator(); - return calc.sizeAndAlignment(type); - } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVariableReadWriteFlags.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVariableReadWriteFlags.java index 4086f1bd98c..5a07c5e916f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVariableReadWriteFlags.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVariableReadWriteFlags.java @@ -32,7 +32,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.VariableReadWriteFlags; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType; /** @@ -61,7 +60,7 @@ public final class CPPVariableReadWriteFlags extends VariableReadWriteFlags { IType type = CPPVisitor.createType(parent); if (type instanceof ICPPUnknownType || type instanceof ICPPClassType && - !ClassTypeHelper.hasTrivialDefaultConstructor((ICPPClassType) type, parent)) { + !TypeTraits.hasTrivialDefaultConstructor((ICPPClassType) type, parent)) { return WRITE; } return super.rwInDeclarator(parent, indirection); 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 ccf06ec82a4..267b5c018dd 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 @@ -368,7 +368,7 @@ public class Conversions { return Cost.NO_CONVERSION; ICPPClassType classTarget= (ICPPClassType) noCVTarget; - if (ClassTypeHelper.isAggregateClass(classTarget, point)) { + if (TypeTraits.isAggregateClass(classTarget, point)) { Cost cost= new Cost(arg.getTypeOrFunctionSet(point), target, Rank.IDENTITY); cost.setUserDefinedConversion(null); return cost; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java index 707e19f45e3..abdbd08a752 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java @@ -20,14 +20,12 @@ import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.core.runtime.CoreException; @@ -83,13 +81,7 @@ public class EvalBinaryTypeId extends CPPEvaluation { if (isValueDependent()) return Value.create(this); - switch (fOperator) { - case __is_base_of: - if (!(fType1 instanceof ICPPClassType) || !(fType1 instanceof ICPPClassType)) - return Value.UNKNOWN; - return Value.create(ClassTypeHelper.isSubclass((ICPPClassType) fType2, (ICPPClassType) fType1)); - } - return Value.create(this); + return Value.evaluateBinaryTypeIdExpression(fOperator, fType1, fType2, point); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java index 7a74dc34041..97632357044 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java @@ -49,6 +49,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; +import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArithmeticConversion; @@ -219,11 +220,11 @@ public class EvalUnary extends CPPEvaluation { switch (fOperator) { case op_sizeof: { - SizeAndAlignment info = getSizeAndAlignment(fArgument.getTypeOrFunctionSet(point), point); + SizeAndAlignment info = SizeofCalculator.getSizeAndAlignment(fArgument.getTypeOrFunctionSet(point), point); return info == null ? Value.UNKNOWN : Value.create(info.size); } case op_alignOf: { - SizeAndAlignment info = getSizeAndAlignment(fArgument.getTypeOrFunctionSet(point), point); + SizeAndAlignment info = SizeofCalculator.getSizeAndAlignment(fArgument.getTypeOrFunctionSet(point), point); return info == null ? Value.UNKNOWN : Value.create(info.alignment); } case op_noexcept: diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java index 241fb626f72..06eb32de63f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java @@ -37,8 +37,6 @@ import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_typeof; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.ICompositeType; -import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; @@ -46,7 +44,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; -import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; @@ -163,55 +160,7 @@ public class EvalUnaryTypeID extends CPPEvaluation { if (isValueDependent()) return Value.create(this); - switch (fOperator) { - case op_sizeof: { - SizeAndAlignment info = getSizeAndAlignment(fOrigType, point); - return info == null ? Value.UNKNOWN : Value.create(info.size); - } - case op_alignof: { - SizeAndAlignment info = getSizeAndAlignment(fOrigType, point); - return info == null ? Value.UNKNOWN : Value.create(info.alignment); - } - case op_typeid: - return Value.UNKNOWN; // TODO(sprigogin): Implement - case op_has_nothrow_copy: - return Value.UNKNOWN; // TODO(sprigogin): Implement - case op_has_nothrow_constructor: - return Value.UNKNOWN; // TODO(sprigogin): Implement - case op_has_trivial_assign: - return Value.UNKNOWN; // TODO(sprigogin): Implement - case op_has_trivial_constructor: - return Value.UNKNOWN; // TODO(sprigogin): Implement - case op_has_trivial_copy: - return Value.UNKNOWN; // TODO(sprigogin): Implement - case op_has_trivial_destructor: - return Value.UNKNOWN; // TODO(sprigogin): Implement - case op_has_virtual_destructor: - return Value.UNKNOWN; // TODO(sprigogin): Implement - case op_is_abstract: - return Value.UNKNOWN; // TODO(sprigogin): Implement - case op_is_class: - return Value.create(fOrigType instanceof ICompositeType && ((ICompositeType) fOrigType).getKey() != ICompositeType.k_union); - case op_is_empty: - return Value.UNKNOWN; // TODO(sprigogin): Implement - case op_is_enum: - return Value.create(fOrigType instanceof IEnumeration); - case op_is_literal_type: - return Value.UNKNOWN; // TODO(sprigogin): Implement - case op_is_pod: - return Value.UNKNOWN; // TODO(sprigogin): Implement - case op_is_polymorphic: - return Value.UNKNOWN; // TODO(sprigogin): Implement - case op_is_standard_layout: - return Value.UNKNOWN; // TODO(sprigogin): Implement - case op_is_trivial: - return Value.UNKNOWN; // TODO(sprigogin): Implement - case op_is_union: - return Value.create(fOrigType instanceof ICompositeType && ((ICompositeType) fOrigType).getKey() == ICompositeType.k_union); - case op_typeof: - return Value.UNKNOWN; // TODO(sprigogin): Implement - } - return Value.create(this); + return Value.evaluateUnaryTypeIdExpression(fOperator, fOrigType, point); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeTraits.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeTraits.java new file mode 100644 index 00000000000..71454ab5d6e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeTraits.java @@ -0,0 +1,328 @@ +/******************************************************************************* + * Copyright (c) 2012 Google, Inc 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: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; + +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.ARRAY; +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.TDEF; + +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper.MethodKind; + +/** + * A collection of static methods for determining type traits. + */ +public class TypeTraits { + private TypeTraits() {} + + /** + * C++11: 9-6 + */ + public static boolean isTrivial(ICPPClassType classType, IASTNode point) { + for (ICPPMethod method : ClassTypeHelper.getDeclaredMethods(classType, point)) { + if (method.isVirtual()) + return false; + switch (ClassTypeHelper.getMethodKind(classType, method)) { + case DEFAULT_CTOR: + case COPY_CTOR: + case MOVE_CTOR: + case COPY_ASSIGNMENT_OP: + case MOVE_ASSIGNMENT_OP: + case DTOR: + return false; + default: + break; + } + } + ICPPField[] fields = ClassTypeHelper.getDeclaredFields(classType, point); + for (ICPPField field : fields) { + if (!field.isStatic()) { + IType fieldType = SemanticUtil.getNestedType(field.getType(), TDEF); + if (fieldType instanceof ICPPClassType && !isTrivial((ICPPClassType) fieldType, point)) + return false; + } + } + for (ICPPBase base : ClassTypeHelper.getBases(classType, point)) { + if (base.isVirtual()) + return false; + } + ICPPClassType[] baseClasses = ClassTypeHelper.getAllBases(classType, point); + for (ICPPClassType baseClass : baseClasses) { + if (!isTrivial(baseClass, point)) + return false; + } + return true; + } + + /** + * C++11: 9-7 + */ + public static boolean isStandardLayout(IType type, IASTNode point) { + type = SemanticUtil.getNestedType(type, ARRAY | CVTYPE | TDEF); + if (type instanceof ICPPReferenceType) + return false; + if (!(type instanceof ICPPClassType)) + return true; + ICPPClassType classType = (ICPPClassType) type; + int visibility = 0; + ICPPField firstNonStaticField = null; + ICPPField[] fields = ClassTypeHelper.getDeclaredFields(classType, point); + for (ICPPField field : fields) { + if (!field.isStatic()) { + if (!isStandardLayout(field.getType(), point)) + return false; + int vis = field.getVisibility(); + if (visibility == 0) { + visibility = vis; + } else if (vis != visibility) { + return false; + } + if (firstNonStaticField == null) + firstNonStaticField = field; + } + } + if (hasDeclaredVirtualMethod(classType, point)) + return false; + for (ICPPBase base : ClassTypeHelper.getBases(classType, point)) { + if (base.isVirtual()) + return false; + } + ICPPClassType[] baseClasses = ClassTypeHelper.getAllBases(classType, point); + for (ICPPClassType baseClass : baseClasses) { + if (!isStandardLayout(baseClass, point)) + return false; + if (firstNonStaticField != null) { + if (TypeTraits.hasNonStaticFields(baseClass, point)) + return false; + if (firstNonStaticField.getType().isSameType(baseClass)) + return false; + } + } + return true; + } + + /** + * C++11: 9-10 + */ + public static boolean isPOD(IType type, IASTNode point) { + if (!isStandardLayout(type, point)) + return false; + type = SemanticUtil.getNestedType(type, ARRAY | CVTYPE | TDEF); + if (!(type instanceof ICPPClassType)) + return true; + return isTrivial((ICPPClassType) type, point); + } + + /** + * 8.5.1 Aggregates [dcl.init.aggr] + * An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), + * no private or protected non-static data members (Clause 11), + * no base classes (Clause 10), and no virtual functions (10.3). + */ + public static boolean isAggregateClass(ICPPClassType classType, IASTNode point) { + if (ClassTypeHelper.getBases(classType, point).length > 0) + return false; + ICPPMethod[] methods = ClassTypeHelper.getDeclaredMethods(classType, point); + for (ICPPMethod m : methods) { + if (m instanceof ICPPConstructor) + return false; + if (m.isVirtual()) { + return false; + } + } + ICPPField[] fields = ClassTypeHelper.getDeclaredFields(classType, point); + for (ICPPField field : fields) { + if (!(field.getVisibility() == ICPPMember.v_public || field.isStatic())) { + return false; + } + } + return true; + } + + /** + * Returns true if and only if the given class has a trivial copy constructor. + * A copy constructor is trivial if: + *
    + *
  • it is implicitly defined by the compiler, and
  • + *
  • isPolymorphic(classType) is false, and
  • + *
  • the class has no virtual base classes, and
  • + *
  • every direct base class has trivial copy constructor, and
  • + *
  • for every nonstatic data member that has class type or array of class type, that type + * has trivial copy constructor.
  • + *
+ * Similar to std::tr1::has_trivial_copy. + * + * @param classType the class to check + * @return true if the class has a trivial copy constructor + */ + public static boolean hasTrivialCopyCtor(ICPPClassType classType, IASTNode point) { + if (getImplicitCopyCtor(classType, point) == null) + return false; + if (isPolymorphic(classType, point)) + return false; + for (ICPPBase base : ClassTypeHelper.getBases(classType, point)) { + if (base.isVirtual()) + return false; + } + for (ICPPClassType baseClass : ClassTypeHelper.getAllBases(classType, point)) { + if (!classType.isSameType(baseClass) && !hasTrivialCopyCtor(baseClass, point)) + return false; + } + for (ICPPField field : classType.getDeclaredFields()) { + if (!field.isStatic()) { + IType type = field.getType(); + type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY); + if (type instanceof ICPPClassType && !classType.isSameType(type) && + !hasTrivialCopyCtor((ICPPClassType) type, point)) { + return false; + } + } + } + return true; + } + + /** + * Returns true if and only if the given class has a trivial default constructor. + * A default constructor is trivial if: + *
    + *
  • it is implicitly defined by the compiler, and
  • + *
  • every direct base class has trivial default constructor, and
  • + *
  • for every nonstatic data member that has class type or array of class type, that type + * has trivial default constructor.
  • + *
+ * Similar to std::tr1::has_trivial_default_constructor. + * + * @param classType the class to check + * @param point + * @return true if the class has a trivial default constructor + */ + public static boolean hasTrivialDefaultConstructor(ICPPClassType classType, IASTNode point) { + for (ICPPConstructor ctor : ClassTypeHelper.getConstructors(classType, point)) { + if (!ctor.isImplicit() && ctor.getParameters().length == 0) + return false; + } + for (ICPPClassType baseClass : ClassTypeHelper.getAllBases(classType, null)) { + if (!classType.isSameType(baseClass) && !hasTrivialDefaultConstructor(baseClass, point)) + return false; + } + for (ICPPField field : ClassTypeHelper.getDeclaredFields(classType, point)) { + if (!field.isStatic()) { + IType type = field.getType(); + type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY); + if (type instanceof ICPPClassType && !classType.isSameType(type) && + !hasTrivialDefaultConstructor((ICPPClassType) type, point)) { + return false; + } + } + } + return true; + } + + /** + * Returns true if and only if the given class has a trivial destructor. + * A destructor is trivial if: + *
    + *
  • it is implicitly defined by the compiler, and
  • + *
  • every direct base class has trivial destructor, and
  • + *
  • for every nonstatic data member that has class type or array of class type, that type + * has trivial destructor.
  • + *
+ * Similar to std::tr1::has_trivial_destructor. + * + * @param classType the class to check + * @return true if the class has a trivial destructor + */ + public static boolean hasTrivialDestructor(ICPPClassType classType, IASTNode point) { + for (ICPPMethod method : ClassTypeHelper.getDeclaredMethods(classType, point)) { + if (method.isDestructor()) + return false; + } + for (ICPPClassType baseClass : ClassTypeHelper.getAllBases(classType, null)) { + if (!classType.isSameType(baseClass) && !hasTrivialDestructor(baseClass, point)) + return false; + } + for (ICPPField field : ClassTypeHelper.getDeclaredFields(classType, point)) { + if (!field.isStatic()) { + IType type = field.getType(); + type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY); + if (type instanceof ICPPClassType && !classType.isSameType(type) && + !hasTrivialDestructor((ICPPClassType) type, point)) { + return false; + } + } + } + return true; + } + + /** + * Returns true if and only if the given class declares or inherits a virtual + * function. Similar to std::tr1::is_polymorphic. + * + * @param classType the class to check + * @return true if the class declares or inherits a virtual function. + */ + public static boolean isPolymorphic(ICPPClassType classType, IASTNode point) { + if (hasDeclaredVirtualMethod(classType, point)) + return true; + for (ICPPClassType baseClass : ClassTypeHelper.getAllBases(classType, point)) { + if (hasDeclaredVirtualMethod(baseClass, point)) + return true; + } + return false; + } + + private static boolean hasNonStaticFields(ICPPClassType classType, IASTNode point) { + ICPPField[] fields = ClassTypeHelper.getDeclaredFields(classType, point); + for (ICPPField field : fields) { + if (!field.isStatic()) + return true; + } + return false; + } + + public static boolean isAbstract(ICPPClassType classType, IASTNode point) { + return ClassTypeHelper.getPureVirtualMethods(classType, point).length != 0; + } + + /** + * Returns the compiler-generated copy constructor for the given class, or null + * if the class doesn't have a compiler-generated copy constructor. + * + * @param classType the class to get the copy ctor for. + * @return the compiler-generated copy constructor, or null if the class doesn't + * have a compiler-generated copy constructor. + */ + private static ICPPConstructor getImplicitCopyCtor(ICPPClassType classType, IASTNode point) { + for (ICPPConstructor ctor : ClassTypeHelper.getConstructors(classType, point)) { + if (ctor.isImplicit() && ClassTypeHelper.getMethodKind(classType, ctor) == MethodKind.COPY_CTOR) + return ctor; + } + return null; + } + + private static boolean hasDeclaredVirtualMethod(ICPPClassType classType, IASTNode point) { + for (ICPPMethod method : ClassTypeHelper.getDeclaredMethods(classType, point)) { + if (method.isVirtual()) { + return true; + } + } + return false; + } +} diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRGCCCompleteParseExtensionsTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRGCCCompleteParseExtensionsTest.java index e689324df99..bb6b3535015 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRGCCCompleteParseExtensionsTest.java +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRGCCCompleteParseExtensionsTest.java @@ -32,7 +32,7 @@ public class LRGCCCompleteParseExtensionsTest extends GCCCompleteParseExtensions //override the test failed case for 342683 @Override - public void testTypetraits_Bug342683() throws Exception {} + public void testTypeTraits_Bug342683() throws Exception {} @Override From ab22bbda2d44ebd51f0ea5e66d21a66f1d0e5738 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 22 Aug 2012 12:13:04 -0700 Subject: [PATCH 04/28] Cosmetics. --- .../eclipse/cdt/ui/tests/BaseUITestCase.java | 61 ++++++++----------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java index d8b237b69dc..7618b5e913c 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java @@ -7,7 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation - *******************************************************************************/ + *******************************************************************************/ package org.eclipse.cdt.ui.tests; import java.io.IOException; @@ -57,18 +57,15 @@ import org.eclipse.cdt.ui.testplugin.CTestPlugin; import org.eclipse.cdt.ui.testplugin.util.StringAsserts; public class BaseUITestCase extends BaseTestCase { - + public BaseUITestCase() { super(); } - + public BaseUITestCase(String name) { super(name); } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.testplugin.util.BaseTestCase#setUp() - */ + @Override protected void setUp() throws Exception { super.setUp(); @@ -79,9 +76,6 @@ public class BaseUITestCase extends BaseTestCase { } } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.testplugin.util.BaseTestCase#tearDown() - */ @Override protected void tearDown() throws Exception { runEventQueue(0); @@ -89,14 +83,14 @@ public class BaseUITestCase extends BaseTestCase { } /** - * Reads a section in comments form the source of the given class. Fully + * Reads a section in comments form the source of the given class. Fully * equivalent to readTaggedComment(getClass(), tag) * @since 4.0 */ protected String readTaggedComment(final String tag) throws IOException { return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "ui", getClass(), tag); } - + /** * Reads multiple sections in comments from the source of the given class. * @since 4.0 @@ -105,15 +99,15 @@ public class BaseUITestCase extends BaseTestCase { return TestSourceReader.getContentsForTest(CTestPlugin.getDefault().getBundle(), "ui", getClass(), getName(), sections); } - + public String getAboveComment() throws IOException { return getContentsForTest(1)[0].toString(); } - + protected IFile createFile(IContainer container, String fileName, String contents) throws Exception { return TestSourceReader.createFile(container, new Path(fileName), contents); } - + protected IASTTranslationUnit createIndexBasedAST(IIndex index, ICProject project, IFile file) throws CModelException, CoreException { return TestSourceReader.createIndexBasedAST(index, project, file); } @@ -128,7 +122,7 @@ public class BaseUITestCase extends BaseTestCase { sleep= Math.min(250, sleep * 2); } firstTime= false; - + if (CCorePlugin.getIndexManager().isIndexerSetupPostponed(CoreModel.getDefault().create(file.getProject()))) continue; index.acquireReadLock(); @@ -149,7 +143,7 @@ public class BaseUITestCase extends BaseTestCase { } throw new Exception("Indexer did not complete in time!"); } - + protected void runEventQueue(int time) { final long endTime= System.currentTimeMillis() + time; while (true) { @@ -185,11 +179,11 @@ public class BaseUITestCase extends BaseTestCase { expandTreeItem(item); } } - + protected void expandTreeItem(TreeItem item) { Event event = new Event(); event.item = item; - item.getParent().notifyListeners(SWT.Expand, event); + item.getParent().notifyListeners(SWT.Expand, event); item.setExpanded(true); runEventQueue(0); } @@ -212,7 +206,7 @@ public class BaseUITestCase extends BaseTestCase { tree.setSelection(item); Event event = new Event(); event.item = item; - item.getParent().notifyListeners(SWT.Selection, event); + item.getParent().notifyListeners(SWT.Selection, event); runEventQueue(0); } @@ -223,7 +217,7 @@ public class BaseUITestCase extends BaseTestCase { page.closeEditor(editor, false); } } - + protected void closeAllEditors() { IWorkbenchWindow[] windows= PlatformUI.getWorkbench().getWorkbenchWindows(); for (IWorkbenchWindow window : windows) { @@ -233,7 +227,7 @@ public class BaseUITestCase extends BaseTestCase { } } } - + protected void restoreAllParts() throws WorkbenchException { IWorkbenchPage page= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); page.zoomOut(); @@ -249,14 +243,14 @@ public class BaseUITestCase extends BaseTestCase { } runEventQueue(0); } - + protected IViewPart activateView(String id) throws PartInitException { IViewPart view= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(id); assertNotNull(view); runEventQueue(0); return view; } - + protected void executeCommand(IViewPart viewPart, String commandID) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException { IHandlerService hs= (IHandlerService)viewPart.getSite().getService(IHandlerService.class); assertNotNull(hs); @@ -268,8 +262,8 @@ public class BaseUITestCase extends BaseTestCase { findControls(w, clazz, result); return result.toArray(new Control[result.size()]); } - - private void findControls(Control w, Class clazz, List result) { + + private void findControls(Control w, Class clazz, List result) { if (clazz.isInstance(w)) { result.add(w); } @@ -285,8 +279,8 @@ public class BaseUITestCase extends BaseTestCase { final protected TreeItem checkTreeNode(IViewPart part, int i0, String label) { assertNotNull(label); // we don't handle testing for a base node to not appear; can be added if/when needed IViewReference viewRef = part.getViewSite().getPage().findViewReference(part.getViewSite().getId()); - Control viewControl = ((WorkbenchPartReference)viewRef).getPane().getControl(); - + Control viewControl = ((WorkbenchPartReference) viewRef).getPane().getControl(); + Tree tree= null; TreeItem root= null; StringBuilder cands= new StringBuilder(); @@ -337,17 +331,17 @@ public class BaseUITestCase extends BaseTestCase { fail("Tree node " + label + "{" + i0 + "} does not exist!"); return null; } - + /** * Pass label=null to test that the {i0,i1} node doesn't exist */ final protected TreeItem checkTreeNode(Tree tree, int i0, int i1, String label) { String firstItemText= null; int timeout = (label == null) ? 1000 : 5000; // see footnote[0] - + // If {i0,i1} exists, whether or not it matches label (when label != null) boolean nodePresent = false; - + for (int millis= 0; millis < timeout; millis= millis == 0 ? 1 : millis * 2) { nodePresent = false; runEventQueue(millis); @@ -374,13 +368,12 @@ public class BaseUITestCase extends BaseTestCase { if (label == null) { assertFalse("Tree node {" + i0 + "," + i1 + "} exists but shouldn't!", nodePresent); - } - else { + } else { fail("Tree node " + label + "{" + i0 + "," + i1 + "} does not exist!"); } return null; } - + public static void assertEqualString(String actual, String expected) { StringAsserts.assertEqualString(actual, expected); } From 82a89c35edc6a6680dfdbcf62cd5b2306a8188cd Mon Sep 17 00:00:00 2001 From: John Cortell Date: Wed, 22 Aug 2012 15:08:31 -0500 Subject: [PATCH 05/28] BaseUITestCase.waitForIndexer() intermittently throws exception --- .../eclipse/cdt/ui/tests/BaseUITestCase.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java index 7618b5e913c..04e6abcb899 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java @@ -125,20 +125,25 @@ public class BaseUITestCase extends BaseTestCase { if (CCorePlugin.getIndexManager().isIndexerSetupPostponed(CoreModel.getDefault().create(file.getProject()))) continue; - index.acquireReadLock(); try { - IIndexFile[] indexFiles= index.getFiles(IndexLocationFactory.getWorkspaceIFL(file)); - for (IIndexFile indexFile : indexFiles) { - if (indexFile != null && indexFile.getTimestamp() >= file.getLocalTimeStamp()) { - return; + index.acquireReadLock(); + try { + IIndexFile[] indexFiles= index.getFiles(IndexLocationFactory.getWorkspaceIFL(file)); + for (IIndexFile indexFile : indexFiles) { + if (indexFile != null && indexFile.getTimestamp() >= file.getLocalTimeStamp()) { + return; + } + } + } finally { + index.releaseReadLock(); + int time= (int) (endTime - System.currentTimeMillis()); + if (time > 0) { + CCorePlugin.getIndexManager().joinIndexer(time, npm()); } } - } finally { - index.releaseReadLock(); - int time= (int) (endTime - System.currentTimeMillis()); - if (time > 0) { - CCorePlugin.getIndexManager().joinIndexer(time, npm()); - } + } + catch (InterruptedException e) { + // index.acquireReadLock() can be interrupted } } throw new Exception("Indexer did not complete in time!"); From 4f739bda84329872fb4d34c33861121bb7a77aae Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 22 Aug 2012 15:04:44 -0700 Subject: [PATCH 06/28] Pushed INDEXER_TIMEOUT_SEC constant up the test class hierarchy. --- .../internal/index/tests/IndexBugsTests.java | 1 - .../index/tests/IndexCompositeTests.java | 2 +- .../pdom/tests/PDOMProviderTests.java | 27 +++++++++---------- .../cdt/internal/pdom/tests/PDOMTestBase.java | 2 +- .../core/testplugin/util/BaseTestCase.java | 5 ++-- .../refactoring/RefactoringTestBase.java | 1 - .../selection/BaseSelectionTestsIndexer.java | 1 - .../selection/CSelectionTestsAnyIndexer.java | 19 +++++++------ 8 files changed, 26 insertions(+), 32 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java index e4d0bdfdb64..e4558287e40 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java @@ -108,7 +108,6 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; public class IndexBugsTests extends BaseTestCase { - private static final int INDEXER_TIMEOUT_SEC = 20; private ICProject fCProject; protected IIndex fIndex; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCompositeTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCompositeTests.java index b9c855ea516..b1ba0f5c4e4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCompositeTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCompositeTests.java @@ -468,7 +468,7 @@ public class IndexCompositeTests extends BaseTestCase { * Convenience class for setting up projects. */ class ProjectBuilder { - private static final int INDEXER_TIMEOUT_SEC = 5; + private static final int INDEXER_TIMEOUT_SEC = 10; private final String name; private final boolean cpp; private List dependencies = new ArrayList(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java index d3fe6fa95c2..cc5047d5bac 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java @@ -57,7 +57,7 @@ public class PDOMProviderTests extends PDOMTestBase { { ICProject cproject= CProjectHelper.createCCProject("foo"+System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); TestSourceReader.createFile(cproject.getProject(), new Path("/this.h"), "class A {};\n\n"); - CCorePlugin.getIndexManager().joinIndexer(3000, npm()); + CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()); IIndex index= CCorePlugin.getIndexManager().getIndex(cproject, A_FRAGMENT_OPTIONS); index.acquireReadLock(); @@ -78,7 +78,7 @@ public class PDOMProviderTests extends PDOMTestBase { final URI baseURI= new File("c:/ExternalSDK/").toURI(); final ICProject cproject2= CProjectHelper.createCCProject("bar"+System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); TestSourceReader.createFile(cproject2.getProject(), new Path("/source.cpp"), "namespace X { class A {}; }\n\n"); - CCorePlugin.getIndexManager().joinIndexer(3000, npm()); + CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()); IndexProviderManager ipm= CCoreInternals.getPDOMManager().getIndexProviderManager(); ipm.addIndexProvider(new ReadOnlyPDOMProviderBridge( @@ -129,7 +129,7 @@ public class PDOMProviderTests extends PDOMTestBase { { ICProject cproject= CProjectHelper.createCCProject("foo"+System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); TestSourceReader.createFile(cproject.getProject(), new Path("/this.h"), "class A {};\n\n"); - CCorePlugin.getIndexManager().joinIndexer(3000, npm()); + CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()); IIndex index= CCorePlugin.getIndexManager().getIndex(cproject, A_FRAGMENT_OPTIONS); index.acquireReadLock(); @@ -149,12 +149,12 @@ public class PDOMProviderTests extends PDOMTestBase { final ICProject cproject3= CProjectHelper.createCCProject("bar"+System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); TestSourceReader.createFile(cproject3.getProject(), new Path("/source.cpp"), "namespace Y { class A {}; }\n\n"); - CCorePlugin.getIndexManager().joinIndexer(3000, npm()); + CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()); final URI baseURI= new File("c:/ExternalSDK/").toURI(); final ICProject cproject2= CProjectHelper.createCCProject("baz"+System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); TestSourceReader.createFile(cproject2.getProject(), new Path("/source.cpp"), "namespace X { class A {}; }\n\n"); - CCorePlugin.getIndexManager().joinIndexer(3000, npm()); + CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()); IndexProviderManager ipm= CCoreInternals.getPDOMManager().getIndexProviderManager(); ipm.addIndexProvider(new ReadOnlyPDOMProviderBridge( @@ -241,21 +241,18 @@ public class PDOMProviderTests extends PDOMTestBase { } } - /* - * see bugzilla 178998 - */ - public void testVersionMismatchOfExternalPDOM() throws Exception { + public void testVersionMismatchOfExternalPDOM_178998() throws Exception { final File tempPDOM= File.createTempFile("foo", "bar"); { - ICProject cproject= CProjectHelper.createCCProject("foo"+System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); + ICProject cproject= CProjectHelper.createCCProject("foo" + System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); TestSourceReader.createFile(cproject.getProject(), new Path("/this.h"), "class A {};\n\n"); - CCorePlugin.getIndexManager().joinIndexer(3000, npm()); + CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()); ResourceContainerRelativeLocationConverter cvr= new ResourceContainerRelativeLocationConverter(cproject.getProject()); CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, tempPDOM, cvr); CProjectHelper.delete(cproject); - // mimic a pdom with superceded version + // Mimic a PDOM with superseded version. WritablePDOM wpdom= new WritablePDOM(tempPDOM, cvr, LanguageManager.getInstance().getPDOMLinkageFactoryMappings()); wpdom.acquireWriteLock(); try { @@ -267,9 +264,9 @@ public class PDOMProviderTests extends PDOMTestBase { } final URI baseURI= new File("c:/ExternalSDK/").toURI(); - final ICProject cproject2= CProjectHelper.createCCProject("baz"+System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); + final ICProject cproject2= CProjectHelper.createCCProject("baz" + System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); TestSourceReader.createFile(cproject2.getProject(), new Path("/source.cpp"), "namespace X { class A {}; }\n\n"); - CCorePlugin.getIndexManager().joinIndexer(3000, npm()); + CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()); IndexProviderManager ipm= CCoreInternals.getPDOMManager().getIndexProviderManager(); ipm.addIndexProvider(new ReadOnlyPDOMProviderBridge( @@ -302,7 +299,7 @@ public class PDOMProviderTests extends PDOMTestBase { setExpectedNumberOfLoggedNonOKStatusObjects(1); // (this applies to the entire test duration) for (int i= 0; i < 3; i++) { - // try several times in order to test the status is logged only once + // Try several times in order to test the status is logged only once. ICProjectDescription pd= CCorePlugin.getDefault().getProjectDescription(cproject2.getProject(), false); assertEquals(0, ipm.getProvidedIndexFragments(pd.getActiveConfiguration(), -1).length); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java index 101d538cf53..26cce84ea6c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java @@ -57,7 +57,7 @@ import org.eclipse.ui.wizards.datatransfer.ImportOperation; public class PDOMTestBase extends BaseTestCase { protected static final IProgressMonitor PROGRESS = new NullProgressMonitor(); static IPath rootPath = new Path("resources/pdomtests"); - private String projectName= null; + private String projectName; protected ICProject createProject(String folderName) throws CoreException { return createProject(folderName, false); diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java index a6e9a5ad1f9..3053135b962 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java @@ -45,6 +45,7 @@ import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.NullProgressMonitor; public class BaseTestCase extends TestCase { + protected static final int INDEXER_TIMEOUT_SEC = 10; private boolean fExpectFailure; private int fBugNumber; private int fExpectedLoggedNonOK; @@ -290,12 +291,12 @@ public class BaseTestCase extends TestCase { public static void waitForIndexer(ICProject project) throws InterruptedException { final PDOMManager indexManager = CCoreInternals.getPDOMManager(); - assertTrue(indexManager.joinIndexer(10000, npm())); + assertTrue(indexManager.joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm())); long waitms= 1; while (waitms < 2000 && !indexManager.isProjectRegistered(project)) { Thread.sleep(waitms); waitms *= 2; } - assertTrue(indexManager.joinIndexer(10000, npm())); + assertTrue(indexManager.joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm())); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java index f3af0034516..a461896c7df 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java @@ -56,7 +56,6 @@ import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext; * Common base for refactoring tests. */ public abstract class RefactoringTestBase extends BaseTestCase { - private static final int INDEXER_TIMEOUT_SEC = 300; protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor(); /** Allows empty files to be created during test setup. */ diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java index a61d122a55c..d38ec492a87 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java @@ -70,7 +70,6 @@ import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction; * @author dsteffle */ public class BaseSelectionTestsIndexer extends BaseUITestCase { - protected static final int INDEXER_TIMEOUT_SEC = 20; protected ICProject fCProject; static FileManager fileManager = new FileManager(); IProgressMonitor monitor = new NullProgressMonitor(); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsAnyIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsAnyIndexer.java index 42ebecbc222..fcad138f1a7 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsAnyIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsAnyIndexer.java @@ -100,8 +100,8 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe int hoffset= hcode.indexOf("MyInt"); int soffset = scode.indexOf("MyInt"); - IASTNode decl = testF3(file, soffset+2); - IASTNode def = testF3(hfile, hoffset+2); + IASTNode decl = testF3(file, soffset + 2); + IASTNode def = testF3(hfile, hoffset + 2); assertTrue(def instanceof IASTName); assertTrue(decl instanceof IASTName); assertEquals("MyInt", ((IASTName) decl).toString()); //$NON-NLS-1$ @@ -113,8 +113,8 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe hoffset= hcode.indexOf("MyConst"); soffset = scode.indexOf("MyConst"); - decl = testF3(file, soffset+2); - def = testF3(hfile, hoffset+2); + decl = testF3(file, soffset + 2); + def = testF3(hfile, hoffset + 2); assertTrue(def instanceof IASTName); assertTrue(decl instanceof IASTName); assertEquals("MyConst", ((IASTName) decl).toString()); //$NON-NLS-1$ @@ -126,8 +126,8 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe hoffset= hcode.indexOf("MyFunc"); soffset = scode.indexOf("MyFunc"); - decl = testF3(file, soffset+2); - def = testF3(hfile, hoffset+2); + decl = testF3(file, soffset + 2); + def = testF3(hfile, hoffset + 2); assertTrue(def instanceof IASTName); assertTrue(decl instanceof IASTName); assertEquals("MyFunc", ((IASTName) decl).toString()); //$NON-NLS-1$ @@ -139,8 +139,8 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe hoffset= hcode.indexOf("MyStruct"); soffset = scode.indexOf("MyStruct"); - decl = testF3(file, soffset+2); - def = testF3(hfile, hoffset+2); + decl = testF3(file, soffset + 2); + def = testF3(hfile, hoffset + 2); assertTrue(def instanceof IASTName); assertTrue(decl instanceof IASTName); assertEquals("MyStruct", ((IASTName) decl).toString()); //$NON-NLS-1$ @@ -150,8 +150,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe assertEquals(hoffset, def.getFileLocation().getNodeOffset()); assertEquals(8, ((ASTNode) def).getLength()); } - - + // // the header // extern int a; // declares // extern const int c = 1; // defines From 6b3627d0f4090bfb97cfb8eb77148625132d5f4c Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 22 Aug 2012 15:12:48 -0700 Subject: [PATCH 07/28] Added synchronization on fTaskQueue to PDOMManager.isIndexerIdle() --- .../org/eclipse/cdt/internal/core/pdom/PDOMManager.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java index 609d2d334bf..13dbeb38268 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java @@ -720,7 +720,9 @@ public class PDOMManager implements IWritableIndexManager, IListener { @Override public boolean isIndexerIdle() { - return Job.getJobManager().find(this).length == 0; + synchronized (fTaskQueue) { + return Job.getJobManager().find(this).length == 0; + } } void addProject(final ICProject cproject) { @@ -1097,7 +1099,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { @Override public void done(IJobChangeEvent event) { synchronized (idleCondition) { - if (Job.getJobManager().find(PDOMManager.this).length == 0) { + if (isIndexerIdle()) { idleCondition[0] = true; idleCondition.notifyAll(); } @@ -1106,7 +1108,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { }; Job.getJobManager().addJobChangeListener(listener); try { - if (Job.getJobManager().find(this).length == 0) { + if (isIndexerIdle()) { return true; } synchronized (idleCondition) { From 8cf9278d6fb1c286101aff45573e8172ec2a3cd9 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 22 Aug 2012 16:23:06 -0700 Subject: [PATCH 08/28] Cosmetics. --- .../cdt/internal/pdom/tests/PDOMLocationTests.java | 8 ++++---- .../cdt/internal/pdom/tests/PDOMProviderTests.java | 10 +++++----- .../eclipse/cdt/internal/pdom/tests/PDOMTests.java | 13 +++++-------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMLocationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMLocationTests.java index fd3d21f10ee..2f61446fb3f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMLocationTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMLocationTests.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Ferguson (Symbian) - Initial implementation + * Andrew Ferguson (Symbian) - Initial implementation *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; @@ -39,7 +39,7 @@ public class PDOMLocationTests extends BaseTestCase { @Override protected void setUp() throws Exception { - cproject= CProjectHelper.createCCProject("PDOMLocationTests"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); + cproject= CProjectHelper.createCCProject("PDOMLocationTests" + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); super.setUp(); } @@ -66,11 +66,11 @@ public class PDOMLocationTests extends BaseTestCase { Set externals= new HashSet(); externals.addAll(Arrays.asList(linuxExternals)); - if(Platform.getOS().equals("win32")) { + if (Platform.getOS().equals("win32")) { externals.addAll(Arrays.asList(winExternals)); } - for(String ext : externals) { + for (String ext : externals) { IIndexFileLocation loc = IndexLocationFactory.getExternalIFL(ext); String raw = converter.toInternalFormat(loc); IIndexFileLocation roundtrip = converter.fromInternalFormat(raw); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java index cc5047d5bac..f5a8ce9598b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java @@ -55,7 +55,7 @@ public class PDOMProviderTests extends PDOMTestBase { final File tempPDOM= File.createTempFile("foo", "bar"); { - ICProject cproject= CProjectHelper.createCCProject("foo"+System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); + ICProject cproject= CProjectHelper.createCCProject("foo" + System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); TestSourceReader.createFile(cproject.getProject(), new Path("/this.h"), "class A {};\n\n"); CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()); @@ -76,7 +76,7 @@ public class PDOMProviderTests extends PDOMTestBase { } final URI baseURI= new File("c:/ExternalSDK/").toURI(); - final ICProject cproject2= CProjectHelper.createCCProject("bar"+System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); + final ICProject cproject2= CProjectHelper.createCCProject("bar" + System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); TestSourceReader.createFile(cproject2.getProject(), new Path("/source.cpp"), "namespace X { class A {}; }\n\n"); CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()); @@ -127,7 +127,7 @@ public class PDOMProviderTests extends PDOMTestBase { final File tempPDOM= File.createTempFile("foo", "bar"); { - ICProject cproject= CProjectHelper.createCCProject("foo"+System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); + ICProject cproject= CProjectHelper.createCCProject("foo" + System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); TestSourceReader.createFile(cproject.getProject(), new Path("/this.h"), "class A {};\n\n"); CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()); @@ -147,12 +147,12 @@ public class PDOMProviderTests extends PDOMTestBase { CProjectHelper.delete(cproject); } - final ICProject cproject3= CProjectHelper.createCCProject("bar"+System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); + final ICProject cproject3= CProjectHelper.createCCProject("bar" + System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); TestSourceReader.createFile(cproject3.getProject(), new Path("/source.cpp"), "namespace Y { class A {}; }\n\n"); CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()); final URI baseURI= new File("c:/ExternalSDK/").toURI(); - final ICProject cproject2= CProjectHelper.createCCProject("baz"+System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); + final ICProject cproject2= CProjectHelper.createCCProject("baz" + System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER); TestSourceReader.createFile(cproject2.getProject(), new Path("/source.cpp"), "namespace X { class A {}; }\n\n"); CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java index fd92b1d2965..f244ec3925c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java @@ -18,14 +18,12 @@ import junit.framework.TestSuite; /** * @author Doug Schaefer - * */ public class PDOMTests extends TestSuite { public static Test suite() { TestSuite suite = new PDOMTests(); - - + suite.addTest(DBTest.suite()); suite.addTest(DBPropertiesTests.suite()); suite.addTest(PDOMCBugsTest.suite()); @@ -42,7 +40,7 @@ public class PDOMTests extends TestSuite { suite.addTest(BTreeTests.suite()); suite.addTest(FilesOnReindexTests.suite()); suite.addTest(GeneratePDOMApplicationTest.suite()); - + suite.addTest(CPPFieldTests.suite()); suite.addTest(CPPFunctionTests.suite()); suite.addTest(CPPVariableTests.suite()); @@ -50,16 +48,15 @@ public class PDOMTests extends TestSuite { suite.addTest(CPPFunctionTemplateTests.suite()); suite.addTest(MethodTests.suite()); suite.addTest(NamespaceTests.suite()); - + suite.addTest(CFunctionTests.suite()); suite.addTest(CVariableTests.suite()); suite.addTest(CCompositeTypeTests.suite()); - + suite.addTest(DefDeclTests.suite()); suite.addTest(RaceCondition157992Test.suite()); suite.addTest(ChangeConfigurationTests.suite()); - + return suite; } - } From c7abf5ab173a06ad2065a2ed83737de01e2acd89 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 22 Aug 2012 16:49:47 -0700 Subject: [PATCH 09/28] Delete the created project as part of test tear down. --- .../cdt/internal/pdom/tests/PDOMSearchTest.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java index d9cc6b78319..4d200c290b8 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java @@ -33,6 +33,7 @@ import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; @@ -49,7 +50,7 @@ public class PDOMSearchTest extends PDOMTestBase { return o1.getName().compareTo(o2.getName()); }}; - protected ICProject project; + protected ICProject project; protected PDOM pdom; protected IProgressMonitor NULL_MONITOR = new NullProgressMonitor(); protected IndexFilter INDEX_FILTER = IndexFilter.ALL_DECLARED; @@ -60,16 +61,17 @@ public class PDOMSearchTest extends PDOMTestBase { @Override protected void setUp() throws Exception { - if (pdom == null) { - ICProject project = createProject("searchTests", true); - pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(project); - } + project = createProject("searchTests", true); + pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); pdom.acquireReadLock(); } @Override protected void tearDown() throws Exception { pdom.releaseReadLock(); + if (project != null) { + project.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor()); + } } /** From 737b5c69491262c4d5c2bb96addbc88ee1e25b2f Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Thu, 23 Aug 2012 10:23:44 -0700 Subject: [PATCH 10/28] Removed public visibility from the Messages class. --- .../org.eclipse.cdt.ui/.settings/.api_filters | 11 ++++++++++ .../cdt/ui/refactoring/actions/Messages.java | 22 +++++-------------- ...essages.properties => Messages.properties} | 3 ++- 3 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 core/org.eclipse.cdt.ui/.settings/.api_filters rename core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/{messages.properties => Messages.properties} (90%) diff --git a/core/org.eclipse.cdt.ui/.settings/.api_filters b/core/org.eclipse.cdt.ui/.settings/.api_filters new file mode 100644 index 00000000000..6d77fc00926 --- /dev/null +++ b/core/org.eclipse.cdt.ui/.settings/.api_filters @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/Messages.java index fb089c82729..f9a0a1c908d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/Messages.java @@ -1,45 +1,33 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2012 Wind River Systems, Inc. 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: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.ui.refactoring.actions; import org.eclipse.osgi.util.NLS; -/** - * @noextend This class is not intended to be subclassed by clients. - * @noinstantiate This class is not intended to be instantiated by clients. - */ -public class Messages extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.cdt.ui.refactoring.actions.messages"; //$NON-NLS-1$ - +class Messages extends NLS { public static String CRefactoringActionGroup_menu; public static String CRenameAction_label; public static String ExtractConstantAction_label; - /** - * @since 5.1 - */ public static String ExtractLocalVariableAction_label; public static String ExtractFunctionAction_label; public static String HideMethodAction_label; public static String ImplementMethodAction_label; public static String GettersAndSetters_label; - /** - * @since 5.3 - */ public static String ToggleFunctionAction_label; static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); + NLS.initializeMessages(Messages.class.getName(), Messages.class); } + // Do not instantiate private Messages() { } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/Messages.properties similarity index 90% rename from core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/messages.properties rename to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/Messages.properties index 251ae6ccb5e..e773cef4301 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/messages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/Messages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2008 Wind River Systems, Inc. and others. +# Copyright (c) 2008, 2012 Wind River Systems, Inc. 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 @@ -7,6 +7,7 @@ # # Contributors: # Markus Schorn (Wind River Systems) +# Sergey Prigogin (Google) ############################################################################### CRefactoringActionGroup_menu=Refactor CRenameAction_label=Rename... From b038dd16cf4aad8509773f82432af324937c2fc2 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Thu, 23 Aug 2012 10:24:25 -0700 Subject: [PATCH 11/28] Code cleanup. --- .../extractfunction/ExtractFunctionRefactoring.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java index 7b1b8a0e8e9..66dfd2882b0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java @@ -128,10 +128,9 @@ public class ExtractFunctionRefactoring extends CRefactoring { "org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"; //$NON-NLS-1$ static final Integer NULL_INTEGER = Integer.valueOf(0); - static final char[] ZERO= "0".toCharArray(); //$NON-NLS-1$ private NodeContainer container; - final ExtractFunctionInformation info; + private final ExtractFunctionInformation info; final Map names; final Container namesCounter; @@ -142,7 +141,7 @@ public class ExtractFunctionRefactoring extends CRefactoring { private FunctionExtractor extractor; private INodeFactory nodeFactory; - DefaultCodeFormatterOptions formattingOptions; + private DefaultCodeFormatterOptions formattingOptions; private IIndex index; private IASTTranslationUnit ast; From 7f6c8f1f3e4a4b7da067afebbf730f02426edc52 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Thu, 23 Aug 2012 10:51:18 -0700 Subject: [PATCH 12/28] Changed Message classes to have package visibility --- .../src/org/eclipse/cdt/internal/ui/refactoring/Messages.java | 2 +- .../eclipse/cdt/internal/ui/refactoring/dialogs/Messages.java | 2 +- .../cdt/internal/ui/refactoring/extractconstant/Messages.java | 2 +- .../cdt/internal/ui/refactoring/extractfunction/Messages.java | 2 +- .../internal/ui/refactoring/extractlocalvariable/Messages.java | 2 +- .../cdt/internal/ui/refactoring/gettersandsetters/Messages.java | 2 +- .../cdt/internal/ui/refactoring/hidemethod/Messages.java | 2 +- .../cdt/internal/ui/refactoring/implementmethod/Messages.java | 2 +- .../cdt/internal/ui/refactoring/rename/RenameMessages.java | 2 +- .../cdt/internal/ui/refactoring/togglefunction/Messages.java | 2 +- .../org/eclipse/cdt/internal/ui/refactoring/utils/Messages.java | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java index c6b11ecb7d2..1b483e2b563 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.internal.ui.refactoring; import org.eclipse.osgi.util.NLS; -public final class Messages extends NLS { +final class Messages extends NLS { public static String DeleteFileChange_0; public static String DeleteFileChange_1; public static String Refactoring_name; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/Messages.java index 93fa308bf26..dedf2c22392 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/Messages.java @@ -13,7 +13,7 @@ package org.eclipse.cdt.internal.ui.refactoring.dialogs; import org.eclipse.osgi.util.NLS; -public final class Messages extends NLS { +final class Messages extends NLS { public static String CTextEditChangePreviewViewer_OrgSource; public static String CTextEditChangePreviewViewer_RefactoredSource; public static String ExtractInputPage_ReplaceInSubclass; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/Messages.java index e718304c464..fcfbb94c3c7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/Messages.java @@ -13,7 +13,7 @@ package org.eclipse.cdt.internal.ui.refactoring.extractconstant; import org.eclipse.osgi.util.NLS; -public final class Messages extends NLS { +final class Messages extends NLS { public static String InputPage_ConstName; public static String InputPage_EnterConstName; public static String InputPage_NameAlreadyDefined; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/Messages.java index 74fa49567fb..f0a1cf6ae40 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/Messages.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.internal.ui.refactoring.extractfunction; import org.eclipse.osgi.util.NLS; -public final class Messages extends NLS { +final class Messages extends NLS { public static String ExtractFunctionRefactoring_ExtractFunction; public static String ExtractFunctionRefactoring_NoStmtSelected; public static String ExtractFunctionRefactoring_TooManySelected; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/Messages.java index aff2babbb88..a2f43981f91 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractlocalvariable/Messages.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable; import org.eclipse.osgi.util.NLS; -public final class Messages extends NLS { +final class Messages extends NLS { public static String CreateLocalVariable; public static String EnterVariableName; public static String ExpressionMustBeSelected; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.java index f6cac1f695d..e6f8d99b440 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.java @@ -13,7 +13,7 @@ package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters; import org.eclipse.osgi.util.NLS; -public final class Messages extends NLS { +final class Messages extends NLS { public static String GenerateGettersAndSettersInputPage_DeselectAll; public static String GenerateGettersAndSettersInputPage_Header; public static String GenerateGettersAndSettersInputPage_LinkDescription; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/Messages.java index f5b09d92dc1..4fb72e6d7b3 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/Messages.java @@ -13,7 +13,7 @@ package org.eclipse.cdt.internal.ui.refactoring.hidemethod; import org.eclipse.osgi.util.NLS; -public final class Messages extends NLS { +final class Messages extends NLS { public static String HideMethodRefactoring_HasExternalReferences; public static String HideMethodRefactoring_HIDE_METHOD; public static String HideMethodRefactoring_NoNameSelected; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/Messages.java index c3ded7f342a..ba0996380b7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/Messages.java @@ -12,7 +12,7 @@ package org.eclipse.cdt.internal.ui.refactoring.implementmethod; import org.eclipse.osgi.util.NLS; -public final class Messages extends NLS { +final class Messages extends NLS { public static String ParameterNamesInputPage_Title; public static String ParameterNamesInputPage_CompleteMissingMails; public static String ImplementMethodInputPage_PageTitle; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameMessages.java index e570db8fcb4..07482025cda 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameMessages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameMessages.java @@ -13,7 +13,7 @@ package org.eclipse.cdt.internal.ui.refactoring.rename; import org.eclipse.osgi.util.NLS; -public class RenameMessages extends NLS { +class RenameMessages extends NLS { public static String ASTManager_error_macro_name_conflict; public static String ASTManager_subtask_analyzing; public static String ASTManager_task_analyze; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/Messages.java index 859204977be..53bcbe35253 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/Messages.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.internal.ui.refactoring.togglefunction; import org.eclipse.osgi.util.NLS; -public class Messages extends NLS { +class Messages extends NLS { public static String DeclaratorFinder_NestedFunction; public static String DeclaratorFinder_NoDeclarator; public static String DeclaratorFinder_MultipleDeclarators; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/Messages.java index 34754225f14..ea26995b51b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/Messages.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.internal.ui.refactoring.utils; import org.eclipse.osgi.util.NLS; -public final class Messages extends NLS { +final class Messages extends NLS { public static String IdentifierHelper_isKeyword; public static String IdentifierHelper_isValid; public static String IdentifierHelper_leadingDigit; From 266447957f26b712b1e950a4a535a51cf55a0384 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 23 Aug 2012 16:04:28 -0400 Subject: [PATCH 13/28] bug 387729: GCCScannerInfoConsoleParserTests fails consistently for me --- .../GCCScannerInfoConsoleParserTests.java | 13 +++++-------- .../gnu/AbstractGCCBOPConsoleParser.java | 3 +-- .../scannerconfig/AbstractXLCBuildOutputParser.java | 3 +-- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCScannerInfoConsoleParserTests.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCScannerInfoConsoleParserTests.java index 8db35da4fa5..2697061d7f0 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCScannerInfoConsoleParserTests.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCScannerInfoConsoleParserTests.java @@ -21,11 +21,11 @@ import org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCScannerInfoConsol /** * Scanner configuration console parser tests - * + * * @author vhirsl */ public class GCCScannerInfoConsoleParserTests extends BaseBOPConsoleParserTests { - + public static TestSuite suite() { return suite(GCCScannerInfoConsoleParserTests.class); } @@ -46,10 +46,10 @@ public class GCCScannerInfoConsoleParserTests extends BaseBOPConsoleParserTests super.tearDown(); fOutputParser.shutdown(); } - + /* * Tests GCCScannerInfoConsoleParser. Utility object not provided. - * Only tests parsing of the input (make build output) + * Only tests parsing of the input (make build output) */ public void testParsingIncludePaths() { fOutputParser.processLine("gcc -I /dir/include -I c:\\dir\\include -ID:/dir/include -c test.c"); // absolute paths //$NON-NLS-1$ @@ -68,7 +68,7 @@ public class GCCScannerInfoConsoleParserTests extends BaseBOPConsoleParserTests fOutputParser.processLine("gcc -Imultiline2 \\"); //$NON-NLS-1$ fOutputParser.processLine("-Imultiline3\\"); //$NON-NLS-1$ fOutputParser.processLine(" -DAA=\"BB\" test.c"); //$NON-NLS-1$ - + @SuppressWarnings("unchecked") List sumIncludes = fCollector.getCollectedScannerInfo(null, ScannerInfoTypes.INCLUDE_PATHS); assertTrue(sumIncludes.contains("/dir/include")); //$NON-NLS-1$ @@ -96,10 +96,7 @@ public class GCCScannerInfoConsoleParserTests extends BaseBOPConsoleParserTests assertTrue(sumIncludes.contains("//server6/include")); //$NON-NLS-1$ assertTrue(sumIncludes.contains("/multiline/dir")); //$NON-NLS-1$ assertTrue(sumIncludes.contains("multiline2")); //$NON-NLS-1$ - // Fails consistently - if (System.getProperty("cdt.skip.known.test.failures") == null) { assertTrue(sumIncludes.contains("multiline3")); //$NON-NLS-1$ - } assertTrue(sumIncludes.size() == 26); } } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/AbstractGCCBOPConsoleParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/AbstractGCCBOPConsoleParser.java index 32b9a9edc81..0d6a5067c8e 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/AbstractGCCBOPConsoleParser.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/AbstractGCCBOPConsoleParser.java @@ -94,8 +94,7 @@ public abstract class AbstractGCCBOPConsoleParser implements IScannerInfoConsole */ @Override public boolean processLine(String line) { - line= line.trim(); - if (line.length() == 0) { + if (line.trim().length() == 0) { return false; } boolean rc = false; diff --git a/xlc/org.eclipse.cdt.make.xlc.core/src/org/eclipse/cdt/make/xlc/core/scannerconfig/AbstractXLCBuildOutputParser.java b/xlc/org.eclipse.cdt.make.xlc.core/src/org/eclipse/cdt/make/xlc/core/scannerconfig/AbstractXLCBuildOutputParser.java index 64ed3c4c08e..fc33db47104 100644 --- a/xlc/org.eclipse.cdt.make.xlc.core/src/org/eclipse/cdt/make/xlc/core/scannerconfig/AbstractXLCBuildOutputParser.java +++ b/xlc/org.eclipse.cdt.make.xlc.core/src/org/eclipse/cdt/make/xlc/core/scannerconfig/AbstractXLCBuildOutputParser.java @@ -110,8 +110,7 @@ public abstract class AbstractXLCBuildOutputParser implements IScannerInfoConsol */ @Override public boolean processLine(String line) { - line= line.trim(); - if (line.length() == 0) { + if (line.trim().length() == 0) { return false; } From dd605da4955dccf6f5ee193c0598c90ab07f2ffc Mon Sep 17 00:00:00 2001 From: John Cortell Date: Thu, 23 Aug 2012 19:42:46 -0500 Subject: [PATCH 14/28] Problem with cygwin test was due to incomplete cygwin install --- .../errorparsers/tests/ErrorParserFileMatchingTest.java | 5 ----- 1 file changed, 5 deletions(-) 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 67927625397..a209c2cad9b 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 @@ -938,11 +938,6 @@ public class ErrorParserFileMatchingTest extends TestCase { return; } - // Consistently fails, and, yes, I do have Cygwin in my PATH - if (System.getProperty("cdt.skip.known.test.failures") != null) { //$NON-NLS-1$ - return; - } - assertTrue("usrIncludeWindowsPath=["+usrIncludeWindowsPath+"]", usrIncludeWindowsPath.charAt(1)==IPath.DEVICE_SEPARATOR); From 50cbcd2c210d5ceda22dc63b3e5e376706d49f3f Mon Sep 17 00:00:00 2001 From: John Cortell Date: Thu, 23 Aug 2012 22:16:52 -0500 Subject: [PATCH 15/28] correct comment and add the UPCParser test suite to the unreliable bucket. --- .../org/eclipse/cdt/autotools/tests/AllAutotoolsTests.java | 1 + .../src/org/eclipse/cdt/alltests/AllTests.java | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AllAutotoolsTests.java b/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AllAutotoolsTests.java index f75d1b51066..57823b5ddc0 100644 --- a/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AllAutotoolsTests.java +++ b/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AllAutotoolsTests.java @@ -16,6 +16,7 @@ import org.eclipse.cdt.autotools.tests.editors.EditorTests; import junit.framework.Test; import junit.framework.TestSuite; +/** On Windows requires either Cygwin or MinGW to be in PATH */ public class AllAutotoolsTests { public static Test suite() { diff --git a/core/org.eclipse.cdt.alltests/src/org/eclipse/cdt/alltests/AllTests.java b/core/org.eclipse.cdt.alltests/src/org/eclipse/cdt/alltests/AllTests.java index 9ad243b9256..2594f0d248f 100644 --- a/core/org.eclipse.cdt.alltests/src/org/eclipse/cdt/alltests/AllTests.java +++ b/core/org.eclipse.cdt.alltests/src/org/eclipse/cdt/alltests/AllTests.java @@ -12,15 +12,14 @@ import junit.framework.TestSuite; public class AllTests extends TestSuite { public static Test suite() throws Exception { final AllTests suite = new AllTests(); - suite.addTest(org.eclipse.cdt.autotools.tests.AllAutotoolsTests.suite()); // Works with MinGW but not Cygwin + suite.addTest(org.eclipse.cdt.autotools.tests.AllAutotoolsTests.suite()); // // There are intermittent failures in these tests. No pattern to failures. Seems like indexer is interrupted if (System.getProperty("cdt.skip.known.test.failures") == null) { //$NON-NLS-1$ suite.addTest(org.eclipse.cdt.codan.core.test.AutomatedIntegrationSuite.suite()); suite.addTest(org.eclipse.cdt.core.lrparser.tests.LRParserTestSuite.suite()); suite.addTest(org.eclipse.cdt.core.parser.xlc.tests.suite.XlcTestSuite.suite()); - } - suite.addTest(org.eclipse.cdt.core.parser.upc.tests.UPCParserTestSuite.suite()); + } suite.addTest(org.eclipse.cdt.core.suite.AutomatedIntegrationSuite.suite()); // These tests fail intermittently due to gdb not shutting down and thus From cb6f2c29474d68dfdb9d06e78bea90dfcbfe3551 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 24 Aug 2012 11:55:52 -0400 Subject: [PATCH 16/28] bug 387730: Better failure message in the unit test --- .../errorparsers/tests/ErrorParserFileMatchingTest.java | 5 ++++- .../org/eclipse/cdt/core/testplugin/ResourceHelper.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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 a209c2cad9b..75c7b5f5995 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 @@ -937,10 +937,13 @@ public class ErrorParserFileMatchingTest extends TestCase { // Skip the test if Cygwin is not available. return; } - + assertTrue("usrIncludeWindowsPath=["+usrIncludeWindowsPath+"]", usrIncludeWindowsPath.charAt(1)==IPath.DEVICE_SEPARATOR); + java.io.File file = new java.io.File(usrIncludeWindowsPath + "\\" + fileName); + assertTrue("File " + file + " does not exist, check your cygwin installation", file.exists()); + ResourceHelper.createLinkedFolder(fProject, "include", usrIncludeWindowsPath); parseOutput(cygwinFolder+fileName+":1:error"); diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/ResourceHelper.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/ResourceHelper.java index 696dae3fbf2..5db7cc5ca2c 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/ResourceHelper.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/ResourceHelper.java @@ -457,7 +457,7 @@ public class ResourceHelper { */ public static IFolder createLinkedFolder(IProject project, String folderLink, IPath realFolder) throws CoreException { IFolder folder = project.getFolder(folderLink); - folder.createLink(realFolder, IResource.REPLACE, null); + folder.createLink(realFolder, IResource.REPLACE | IResource.ALLOW_MISSING_LOCAL, null); Assert.assertTrue(folder.exists()); resourcesCreated.add(folder); return folder; From c4e80e62a2f2c5bae36dffa6fea5f28a32136bcf Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Thu, 23 Aug 2012 14:58:51 -0700 Subject: [PATCH 17/28] Revert "Allow unreliable tests to be avoided" This reverts commit 1bd247ce3d8825b76623166a89b111884ae1b195. --- .../src/org/eclipse/cdt/alltests/AllTests.java | 15 +++++++-------- .../tests/ErrorParserFileMatchingTest.java | 1 - .../cdt/core/suite/AutomatedIntegrationSuite.java | 12 +----------- .../org/eclipse/cdt/ui/tests/AutomatedSuite.java | 11 +---------- 4 files changed, 9 insertions(+), 30 deletions(-) diff --git a/core/org.eclipse.cdt.alltests/src/org/eclipse/cdt/alltests/AllTests.java b/core/org.eclipse.cdt.alltests/src/org/eclipse/cdt/alltests/AllTests.java index 2594f0d248f..b04bc09c6cc 100644 --- a/core/org.eclipse.cdt.alltests/src/org/eclipse/cdt/alltests/AllTests.java +++ b/core/org.eclipse.cdt.alltests/src/org/eclipse/cdt/alltests/AllTests.java @@ -12,21 +12,20 @@ import junit.framework.TestSuite; public class AllTests extends TestSuite { public static Test suite() throws Exception { final AllTests suite = new AllTests(); - suite.addTest(org.eclipse.cdt.autotools.tests.AllAutotoolsTests.suite()); -// // There are intermittent failures in these tests. No pattern to failures. Seems like indexer is interrupted - if (System.getProperty("cdt.skip.known.test.failures") == null) { //$NON-NLS-1$ + suite.addTest(org.eclipse.cdt.autotools.tests.AllAutotoolsTests.suite()); // Works with MinGW but not Cygwin + + // There are intermittent failures in these tests. No pattern to failures. Seems like indexer is interrupted suite.addTest(org.eclipse.cdt.codan.core.test.AutomatedIntegrationSuite.suite()); suite.addTest(org.eclipse.cdt.core.lrparser.tests.LRParserTestSuite.suite()); suite.addTest(org.eclipse.cdt.core.parser.xlc.tests.suite.XlcTestSuite.suite()); + suite.addTest(org.eclipse.cdt.core.parser.upc.tests.UPCParserTestSuite.suite()); - } suite.addTest(org.eclipse.cdt.core.suite.AutomatedIntegrationSuite.suite()); - // These tests fail intermittently due to gdb not shutting down and thus - // not being able to delete the project (exe locked) - if (System.getProperty("cdt.skip.known.test.failures") == null) { //$NON-NLS-1$ + // These tests fail intermittently due to gdb not shutting down and thus + // not being able to delete the project (exe locked) suite.addTest(org.eclipse.cdt.debug.core.tests.AllDebugTests.suite()); - } + suite.addTest(org.eclipse.cdt.errorparsers.xlc.tests.AllXlcErrorParserTests.suite()); suite.addTest(org.eclipse.cdt.make.core.tests.AutomatedIntegrationSuite.suite()); suite.addTest(org.eclipse.cdt.managedbuilder.tests.suite.AllManagedBuildTests.suite()); 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 75c7b5f5995..a9252570244 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 @@ -937,7 +937,6 @@ public class ErrorParserFileMatchingTest extends TestCase { // Skip the test if Cygwin is not available. return; } - assertTrue("usrIncludeWindowsPath=["+usrIncludeWindowsPath+"]", usrIncludeWindowsPath.charAt(1)==IPath.DEVICE_SEPARATOR); diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java index 3e999a48886..5e7b2090906 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java @@ -62,19 +62,12 @@ public class AutomatedIntegrationSuite extends TestSuite { public static Test suite() throws Exception { final AutomatedIntegrationSuite suite = new AutomatedIntegrationSuite(); - // Add all success tests - - // Has intermittent failures - if (System.getProperty("cdt.skip.known.test.failures") == null) { + // Add all success tests suite.addTest(CDescriptorTests.suite()); - } suite.addTest(CDescriptorOldTests.suite()); suite.addTest(IEnvironmentVariableManagerTests.suite()); suite.addTest(ErrorParserTests.suite()); - // Has intermittent failures - if (System.getProperty("cdt.skip.known.test.failures") == null) { suite.addTest(ParserTestSuite.suite()); - } suite.addTest(AllCoreTests.suite()); suite.addTest(ElementDeltaTests.suite()); suite.addTest(WorkingCopyTests.suite()); @@ -91,12 +84,9 @@ public class AutomatedIntegrationSuite extends TestSuite { suite.addTest(EFSExtensionTests.suite()); suite.addTest(ByteUtilsTest.suite()); - // Has intermittent failures - if (System.getProperty("cdt.skip.known.test.failures") == null) { //$NON-NLS-1$ // Add in PDOM tests suite.addTest(PDOMTests.suite()); suite.addTest(IndexTests.suite()); - } suite.addTest(RefreshScopeTests.suite()); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java index cb45f1e99c3..7b5affd6f35 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java @@ -61,11 +61,8 @@ public class AutomatedSuite extends TestSuite { // tests for package org.eclipse.cdt.ui.tests.viewsupport addTest(ViewSupportTestSuite.suite()); - // Has intermittent failures - if (System.getProperty("cdt.skip.known.test.failures") == null) { //$NON-NLS-1$ // tests for package org.eclipse.cdt.ui.tests.callhierarchy addTest(CallHierarchyTestSuite.suite()); - } // tests for package org.eclipse.cdt.ui.tests.typehierarchy addTest(TypeHierarchyTestSuite.suite()); @@ -78,12 +75,9 @@ public class AutomatedSuite extends TestSuite { // tests from package org.eclipse.cdt.ui.tests.text.contentAssist2 addTest(ContentAssist2TestSuite.suite()); - - // Has intermittent failures - if (System.getProperty("cdt.skip.known.test.failures") == null) { //$NON-NLS-1$ + // tests from package org.eclipse.cdt.ui.tests.text.selection addTest(SelectionTestSuite.suite()); - } // tests from package org.eclipse.cdt.ui.tests.quickfix addTest(AssistQuickFixTest.suite()); @@ -94,11 +88,8 @@ public class AutomatedSuite extends TestSuite { // tests from package org.eclipse.cdt.ui.tests.search addTest(SearchTestSuite.suite()); - // Has intermittent failures - if (System.getProperty("cdt.skip.known.test.failures") == null) { //$NON-NLS-1$ // tests from package org.eclipse.cdt.ui.tests.refactoring addTest(RefactoringTestSuite.suite()); - } // tests from package org.eclipse.cdt.ui.tests.chelp addTest(CHelpTest.suite()); From 7e16142beb7dddf981162b15417cdc763981c9fa Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Fri, 24 Aug 2012 09:48:04 -0700 Subject: [PATCH 18/28] Bug 387985 - Type at refactoringHideMethod.label in org.eclipse.cdt.ui/plugin.properties --- core/org.eclipse.cdt.ui/plugin.properties | 6 +++--- core/org.eclipse.cdt.ui/plugin.xml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index 783a6f95038..1c01c13a043 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -147,7 +147,7 @@ category.refactoring.description= C/C++ Refactorings category.refactoring.name = Refactor - C++ refactoringExtractConstant.label = Extract Constant... refactoringExtractLocalVariable.label = Extract Local Variable... -refactoringHideMethod.label = Hide Memeber Function... +refactoringHideMethod.label = Hide Member Function... ActionDefinition.renameElement.name= Rename - Refactoring @@ -544,7 +544,7 @@ toggleMarkOccurrences.description= Toggles mark occurrences in C/C++ editors OccurrenceAnnotation.label= C/C++ Occurrences WriteOccurrenceAnnotation.label= C/C++ Write Occurrences -DocCommentOwner.name = DocCommentOwner +DocCommentOwnerExtensionPoint = Doc Comment Owner Doxygen.name = Doxygen # Hyperlinking @@ -633,7 +633,7 @@ transfer.EditorBehavior.description = Preference related to how the editor proce # Refresh Exclusion Contributors RefreshExclusionContributor.name = Resources -extension-point.name = Refresh Exclusion Contributor +RefreshExclusionContributorExtensionPoint = Refresh Exclusion Contributor # New New Project Wizard newProjectWizard.name = C/C++ Project (prototype) diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 900b5032008..f60bb501625 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -24,10 +24,10 @@ - + - + Date: Fri, 24 Aug 2012 09:49:56 -0700 Subject: [PATCH 19/28] Normalized extension point labels. --- .../OSGI-INF/l10n/bundle.properties | 3 ++- codan/org.eclipse.cdt.codan.core/plugin.xml | 4 ++-- .../org.eclipse.cdt.codan.ui/OSGI-INF/l10n/bundle.properties | 4 ++-- codan/org.eclipse.cdt.codan.ui/plugin.xml | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/codan/org.eclipse.cdt.codan.core/OSGI-INF/l10n/bundle.properties b/codan/org.eclipse.cdt.codan.core/OSGI-INF/l10n/bundle.properties index ad252dc6852..6a6c77d109b 100644 --- a/codan/org.eclipse.cdt.codan.core/OSGI-INF/l10n/bundle.properties +++ b/codan/org.eclipse.cdt.codan.core/OSGI-INF/l10n/bundle.properties @@ -17,7 +17,8 @@ extension.name.Marker = Code Analysis Problem category.name.ProgrammingErrors = Potential Programming Problems category.name.CodeStyle = Coding Style category.name.CompilerErrors = Syntax and Semantic Errors -extension-point.name.CodeAnalysis = Code Analysis Checkers +codeAnalysisCheckersExtensionPoint = Code Analysis Checkers +checkerEnablementExtensionPoint = Verification of Checker Enablement marker.semanticError = Semantic Error category.name.Security = Security Vulnerabilities \ No newline at end of file diff --git a/codan/org.eclipse.cdt.codan.core/plugin.xml b/codan/org.eclipse.cdt.codan.core/plugin.xml index 11d7fa82852..4d43413061d 100644 --- a/codan/org.eclipse.cdt.codan.core/plugin.xml +++ b/codan/org.eclipse.cdt.codan.core/plugin.xml @@ -1,8 +1,8 @@ - - + + - - + +