From e6b07afaf6e6ef100cbc5d09fa8442a0718c3c96 Mon Sep 17 00:00:00 2001 From: tmadan Date: Sun, 17 Jul 2011 12:12:57 +0300 Subject: [PATCH 1/5] Bug 345151 - Executable View should create virtual folders when importing executables --- .../internal/core/executables/StandardExecutableImporter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/executables/StandardExecutableImporter.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/executables/StandardExecutableImporter.java index b1761fa209c..056689e36ea 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/executables/StandardExecutableImporter.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/executables/StandardExecutableImporter.java @@ -31,6 +31,7 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -143,7 +144,7 @@ public class StandardExecutableImporter implements IExecutableImporter { for (int i = 0; i < segmentCount; i++) { currentFolder = currentFolder.getFolder(new Path(path.segment(i))); if (!currentFolder.exists()) { - ((IFolder) currentFolder).create(false, true, new NullProgressMonitor()); + ((IFolder) currentFolder).create(IResource.VIRTUAL | IResource.DERIVED, true, new NullProgressMonitor()); } } From 21e056c85659a76f88f4a26de0e0704c9ed1756a Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 17 Jul 2011 17:20:16 -0700 Subject: [PATCH 2/5] Bug 315528 - [fp] Non-virtual destructor diagnostics doesn't take superclass into account. Fix and additional tests including the ones contributed by Tomasz Wesolowski. --- .../checkers/NonVirtualDestructor.java | 230 +++++------------- .../NonVirtualDestructorCheckerTest.java | 59 ++++- 2 files changed, 122 insertions(+), 167 deletions(-) diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java index 076e2e1878c..f4e365cd037 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java @@ -11,10 +11,8 @@ *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers; -import org.eclipse.cdt.codan.checkers.CodanCheckersActivator; import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker; import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; @@ -33,183 +31,89 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; * @author Alena Laskavaia */ public class NonVirtualDestructor extends AbstractIndexAstChecker { - public static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem"; //$NON-NLS-1$ + public static final String PROBLEM_ID = "org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem"; //$NON-NLS-1$ public void processAst(IASTTranslationUnit ast) { // Traverse the AST using the visitor pattern. ast.accept(new OnEachClass()); } - class OnEachClass extends ASTVisitor { - private IASTName className; - private IBinding virtualMethod; - private IBinding destructor; - private IASTDeclSpecifier warningLocation; + private static ICPPMethod getDestructor(ICPPClassType classType) { + for (ICPPMethod method : classType.getDeclaredMethods()) { + if (method.isDestructor()) { + return method; + } + } + return null; + } + private static boolean hasVirtualDestructor(ICPPClassType classType) { + ICPPMethod destructor = getDestructor(classType); + if (destructor != null && destructor.isVirtual()) { + return true; + } + ICPPBase[] bases = classType.getBases(); + for (ICPPBase base : bases) { + IBinding baseClass = base.getBaseClass(); + if (baseClass instanceof ICPPClassType) { + if (hasVirtualDestructor((ICPPClassType) baseClass)) { + return true; + } + } + } + return false; + } + + private class OnEachClass extends ASTVisitor { OnEachClass() { shouldVisitDeclSpecifiers = true; } public int visit(IASTDeclSpecifier decl) { - if (isClassDecl(decl)) { - try { - boolean err = hasErrorCondition(decl); - if (err) { - String clazz = className.toString(); - String method = virtualMethod.getName(); - IASTNode node = decl; - if (destructor != null) { - if (destructor instanceof ICPPInternalBinding) { - IASTNode[] decls = ((ICPPInternalBinding) destructor).getDeclarations(); - if (warningLocation == null) { - if (decls != null && decls.length > 0) - node = decls[0]; - } else { - node = warningLocation; - } - } - } - reportProblem(ER_ID, node, clazz, method); - } - } catch (DOMException e) { - // Ignore, not an error. - } catch (Exception e) { - CodanCheckersActivator.log(e); + if (decl instanceof ICPPASTCompositeTypeSpecifier) { + ICPPASTCompositeTypeSpecifier spec = (ICPPASTCompositeTypeSpecifier) decl; + IASTName className = spec.getName(); + IBinding binding = className.resolveBinding(); + if (!(binding instanceof ICPPClassType)) { + return PROCESS_SKIP; } + ICPPClassType classType = (ICPPClassType) binding; + if (hasVirtualDestructor(classType)) { + return PROCESS_SKIP; + } + ICPPMethod virtualMethod = null; + for (ICPPMethod method : classType.getAllDeclaredMethods()) { + if (method.isPureVirtual()) { + // Class has at least one pure virtual method, it is abstract + // and cannot be instantiated. + return PROCESS_SKIP; + } else if (method.isVirtual() && !method.isDestructor()) { + virtualMethod = method; + } + } + if (virtualMethod == null) { + return PROCESS_SKIP; + } + ICPPMethod destructor = getDestructor(classType); + if (destructor != null && + destructor.getVisibility() != ICPPASTVisibilityLabel.v_public && + classType.getFriends().length == 0) { + // No error if the destructor is protected or private and there are no friends. + return PROCESS_SKIP; + } + + IASTNode node = decl; + if (destructor instanceof ICPPInternalBinding) { + IASTNode[] decls = ((ICPPInternalBinding) destructor).getDeclarations(); + if (decls != null && decls.length > 0) { + node = decls[0]; + } + } + reportProblem(PROBLEM_ID, node, className.getSimpleID().toString(), + virtualMethod.getName()); return PROCESS_SKIP; } return PROCESS_CONTINUE; } - - /** - * @param decl - * @throws DOMException - */ - private boolean hasErrorCondition(IASTDeclSpecifier decl) throws DOMException { - ICPPASTCompositeTypeSpecifier spec = (ICPPASTCompositeTypeSpecifier) decl; - className = spec.getName(); - IBinding binding = className.resolveBinding(); - if ((binding instanceof ICPPClassType) == false) { - return false; - } - ICPPClassType classType = (ICPPClassType) binding; - virtualMethod = null; - destructor = null; - warningLocation = null; - // Check for the following conditions: - // class has own virtual method and own non-virtual destructor - // class has own virtual method and base non-virtual destructor - // class has base virtual method and own non-virtual destructor - ICPPMethod[] declaredMethods = classType.getDeclaredMethods(); - boolean hasOwnVirtualMethod = false; - boolean hasOwnNonVirtualDestructor = false; // implicit destructor - boolean hasDestructor = false; - boolean hasVirtualMethod = false; - for (ICPPMethod method : declaredMethods) { - if (method.isPureVirtual()) { - // Class has at least one pure virtual method, it is abstract and cannot be instantiated. - return false; - } else if (method.isVirtual() && !method.isDestructor()) { - hasOwnVirtualMethod = true; - virtualMethod = method; - } - if (method.isDestructor()) { - hasDestructor = true; - if (!method.isVirtual()) { - hasOwnNonVirtualDestructor = true; - destructor = method; - } - } - } - boolean hasVirtualDestructor = false; - // Class has own virtual method and own non-virtual destructor. - if (hasOwnVirtualMethod && hasOwnNonVirtualDestructor) { - if (classType.getFriends().length == 0) { - if (destructor instanceof ICPPMethod) { - // Check visibility of dtor. No error if it is protected or private. - if (((ICPPMethod) destructor).getVisibility() != ICPPASTVisibilityLabel.v_public) { - return false; - } - } - // Check if one of its base classes has a virtual destructor. - return !hasVirtualDtorInBaseClass(classType); - } - // Destructor can be called from a class declared as friend. - return true; - } - // Class has virtual methods and implicit public destructor. - if (hasOwnVirtualMethod && !hasDestructor && classType.getBases().length == 0) { - return true; - } - // Class does not have virtual methods but has virtual destructor - // - not an error - if (!hasOwnVirtualMethod && hasDestructor && !hasOwnNonVirtualDestructor) { - return false; - } - // Check inherited methods - ICPPMethod[] allDeclaredMethods = classType.getAllDeclaredMethods(); - for (ICPPMethod method : allDeclaredMethods) { - if (method.isVirtual() && !method.isDestructor()) { - hasVirtualMethod = true; - if (virtualMethod == null) - virtualMethod = method; - } - if (method.isDestructor()) { - hasDestructor = true; - if (method.isVirtual()) { - hasVirtualDestructor = true; - } else if (destructor == null) { - destructor = method; - } - } - } - if (hasOwnVirtualMethod) { - // Class has own virtual method and base non-virtual destructor. - if (hasDestructor && !hasVirtualDestructor) { - boolean noVirtualDtorInBase = !hasVirtualDtorInBaseClass(classType); - if (noVirtualDtorInBase) { - warningLocation = decl; - } - return noVirtualDtorInBase; - } - } else if (hasVirtualMethod) { - // Class has base virtual method and own non-virtual destructor. - if (hasOwnNonVirtualDestructor) { - return true; - } - boolean noVirtualDtorInBase = !hasVirtualDtorInBaseClass(classType); - if (noVirtualDtorInBase) { - warningLocation = decl; - } - return noVirtualDtorInBase; - } - return false; - } - - private boolean hasVirtualDtorInBaseClass(ICPPClassType classType) { - ICPPBase[] bases = classType.getBases(); - for (ICPPBase base : bases) { - if (!(base.getBaseClass() instanceof ICPPClassType)) { - continue; - } - ICPPClassType testedBaseClass = (ICPPClassType) base.getBaseClass(); - ICPPMethod[] declaredBaseMethods = testedBaseClass.getDeclaredMethods(); - for (ICPPMethod method : declaredBaseMethods) { - if (method.isPureVirtual()) { - return false; - } - if (method.isDestructor() && method.isVirtual()) { - return true; - } - } - if (hasVirtualDtorInBaseClass(testedBaseClass)) - return true; - } - return false; - } - - private boolean isClassDecl(IASTDeclSpecifier decl) { - return decl instanceof ICPPASTCompositeTypeSpecifier; - } } } diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java index a86b87dafb2..4a587027b88 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java @@ -14,7 +14,7 @@ import org.eclipse.cdt.codan.core.test.CheckerTestCase; import org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructor; /** - * Test for {@see NonVirtualDestructor} class. + * Test for {@link NonVirtualDestructor} class. */ public class NonVirtualDestructorCheckerTest extends CheckerTestCase { @Override @@ -25,7 +25,7 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase { @Override public void setUp() throws Exception { super.setUp(); - enableProblems(NonVirtualDestructor.ER_ID); + enableProblems(NonVirtualDestructor.PROBLEM_ID); } // struct A { @@ -86,7 +86,7 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase { // struct B { // ~B(); // ok. // }; - public void testVirtualDtorInBaseClass() { + public void testVirtualDtorInBaseClass1() { loadCodeAndRun(getAboveComment()); checkNoErrors(); } @@ -108,6 +108,22 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase { checkNoErrors(); } + // class A { + // public: + // virtual ~A(); + // }; + // + // class B : public A { + // public: + // ~B(); + // virtual void m(); + // friend class C; + // }; + public void testVirtualDtorInBaseClass3() { + loadCodeAndRun(getAboveComment()); + checkNoErrors(); + } + // struct A { // virtual void f() { }; // ~A(); // warn! public non-virtual dtor. @@ -122,7 +138,7 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase { // // struct E : public D { // }; - public void testNonVirtualDtorInBaseClass2() { + public void testNonVirtualDtorInBaseClass() { loadCodeAndRun(getAboveComment()); checkErrorLines(3, 7, 11, 13); } @@ -143,4 +159,39 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase { loadCodeAndRun(getAboveComment()); checkNoErrors(); } + + // struct Base { + // }; + // struct Derived : Base { + // virtual void bar(); + // }; + public void testImplicitDtorInBaseClass() { + loadCodeAndRun(getAboveComment()); + checkErrorLines(3); + } + + // struct Base { + // ~Base(); + // }; + // struct Derived : Base { + // virtual void bar(); + // }; + public void testExplicitDtorInBaseClass() { + loadCodeAndRun(getAboveComment()); + checkErrorLines(4); + } + + // struct IBase { + // virtual void foo() = 0; + // }; + // struct IDerived : IBase { + // }; + // struct ADerived : IDerived { + // void foo(); + // virtual void bar() = 0; + // }; + public void testInheritedAbstractClasses() { + loadCodeAndRun(getAboveComment()); + checkNoErrors(); + } } From d3264a74180ab0306d5dd217da409bf309031ff5 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 17 Jul 2011 19:02:26 -0700 Subject: [PATCH 3/5] Removed an invalid exemption for abstract classes. --- .../checkers/NonVirtualDestructor.java | 7 ++---- .../NonVirtualDestructorCheckerTest.java | 23 ++++--------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java index f4e365cd037..24fb21b8a42 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java @@ -8,6 +8,7 @@ * Contributors: * Alena Laskavaia - initial API and implementation * Patrick Hofer [bug 315528] + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers; @@ -83,11 +84,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker { } ICPPMethod virtualMethod = null; for (ICPPMethod method : classType.getAllDeclaredMethods()) { - if (method.isPureVirtual()) { - // Class has at least one pure virtual method, it is abstract - // and cannot be instantiated. - return PROCESS_SKIP; - } else if (method.isVirtual() && !method.isDestructor()) { + if (!method.isDestructor() && method.isVirtual()) { virtualMethod = method; } } diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java index 4a587027b88..2e5c88d8993 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java @@ -7,6 +7,8 @@ * * Contributors: * Patrick Hofer - Initial API and implementation + * Tomasz Wesolowski + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.codan.core.internal.checkers; @@ -143,9 +145,7 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase { checkErrorLines(3, 7, 11, 13); } - // class A { // OK. Do _not_ warn here. - // // A is an abstract class because it has one pure virtual method. - // // A cannot be instantiated. + // class A { // virtual void f1() { }; // virtual void f2() = 0; // }; @@ -157,7 +157,8 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase { // }; public void testAbstractBaseClass() { loadCodeAndRun(getAboveComment()); - checkNoErrors(); + // It doesn't matter if the class is abstract or not - dtor can be called polymorphically. + checkErrorLines(1); } // struct Base { @@ -180,18 +181,4 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase { loadCodeAndRun(getAboveComment()); checkErrorLines(4); } - - // struct IBase { - // virtual void foo() = 0; - // }; - // struct IDerived : IBase { - // }; - // struct ADerived : IDerived { - // void foo(); - // virtual void bar() = 0; - // }; - public void testInheritedAbstractClasses() { - loadCodeAndRun(getAboveComment()); - checkNoErrors(); - } } From 72b60757333e37599ae117c9472ac821c4ebbca7 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 17 Jul 2011 19:38:57 -0700 Subject: [PATCH 4/5] Cosmetics. --- .../core/dom/parser/cpp/CPPMethod.java | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java index b4d0bd3301f..7067ca1b3e6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java @@ -40,7 +40,7 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { public CPPMethod(IASTDeclarator declarator) { super(declarator); } - + public IASTDeclaration getPrimaryDeclaration() { //first check if we already know it if (declarations != null) { @@ -60,7 +60,7 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { if (decl.getParent() instanceof ICPPASTCompositeTypeSpecifier) return decl; } - + final char[] myName = getASTName().getLookupKey(); ICPPClassScope scope = (ICPPClassScope) getScope(); ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(scope); @@ -91,33 +91,34 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { */ public int getVisibility() { IASTDeclaration decl = getPrimaryDeclaration(); - if( decl == null ){ + if (decl == null) { IScope scope = getScope(); - if( scope instanceof ICPPClassScope ){ + if (scope instanceof ICPPClassScope) { ICPPClassType cls = ((ICPPClassScope)scope).getClassType(); - if( cls != null ) - return ( cls.getKey() == ICPPClassType.k_class ) ? ICPPASTVisibilityLabel.v_private : ICPPASTVisibilityLabel.v_public; + if (cls != null) + return (cls.getKey() == ICPPClassType.k_class) ? ICPPASTVisibilityLabel.v_private : ICPPASTVisibilityLabel.v_public; } return ICPPASTVisibilityLabel.v_private; } - + IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent(); IASTDeclaration [] members = cls.getMembers(); ICPPASTVisibilityLabel vis = null; for (IASTDeclaration member : members) { - if( member instanceof ICPPASTVisibilityLabel ) + if (member instanceof ICPPASTVisibilityLabel) { vis = (ICPPASTVisibilityLabel) member; - else if( member == decl ) + } else if (member == decl) { break; + } } - if( vis != null ){ + if (vis != null) { return vis.getVisibility(); - } else if( cls.getKey() == ICPPASTCompositeTypeSpecifier.k_class ){ + } else if (cls.getKey() == ICPPASTCompositeTypeSpecifier.k_class) { return ICPPASTVisibilityLabel.v_private; - } + } return ICPPASTVisibilityLabel.v_public; } - + public ICPPClassType getClassOwner() { ICPPClassScope scope = (ICPPClassScope)getScope(); return scope.getClassType(); @@ -139,15 +140,15 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { public IScope getScope() { return CPPVisitor.getContainingScope(getASTName()); } - + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isVirtual() */ public boolean isVirtual() { IASTDeclaration decl = getPrimaryDeclaration(); - if( decl != null ){ + if (decl != null) { ICPPASTDeclSpecifier declSpec = getDeclSpec(decl); - if( declSpec != null ){ + if (declSpec != null) { return declSpec.isVirtual(); } } @@ -156,10 +157,11 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { protected ICPPASTDeclSpecifier getDeclSpec(IASTDeclaration decl) { ICPPASTDeclSpecifier declSpec = null; - if( decl instanceof IASTSimpleDeclaration ) + if (decl instanceof IASTSimpleDeclaration) { declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)decl).getDeclSpecifier(); - else if( decl instanceof IASTFunctionDefinition ) + } else if (decl instanceof IASTFunctionDefinition) { declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)decl).getDeclSpecifier(); + } return declSpec; } @@ -169,11 +171,11 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { @Override public boolean isInline() { IASTDeclaration decl = getPrimaryDeclaration(); - if( decl instanceof IASTFunctionDefinition ) + if (decl instanceof IASTFunctionDefinition) return true; - if( decl == null ) + if (decl == null) return false; - + IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)decl).getDeclSpecifier(); return declSpec.isInline(); } @@ -183,9 +185,9 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { */ @Override public boolean isMutable() { - return hasStorageClass( this, IASTDeclSpecifier.sc_mutable ); + return hasStorageClass(this, IASTDeclSpecifier.sc_mutable); } - + @Override public boolean isStatic(boolean resolveAll) { IASTDeclaration decl = getPrimaryDeclaration(); @@ -205,21 +207,21 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { char[] name = getNameCharArray(); if (name.length > 1 && name[0] == '~') return true; - + return false; } public boolean isImplicit() { return false; } - + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isPureVirtual() */ public boolean isPureVirtual() { if (declarations != null) { for (IASTDeclarator dtor : declarations) { - if (dtor == null) + if (dtor == null) break; dtor = ASTQueries.findOutermostDeclarator(dtor); From 114952f64a850260f9d4043d5d31fd690d8ca99d Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 18 Jul 2011 00:45:48 -0400 Subject: [PATCH 5/5] bug 352301: [performance] Intern strings used for creation of ICLanguageSettingsEntry objects --- .../org/eclipse/cdt/core/settings/model/ACSettingEntry.java | 3 ++- .../org/eclipse/cdt/core/settings/model/CMacroEntry.java | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACSettingEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACSettingEntry.java index ff509a828d9..37420be10a1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACSettingEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ACSettingEntry.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.core.settings.model; import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer; +import org.eclipse.cdt.internal.core.SafeStringInterner; @@ -19,7 +20,7 @@ public abstract class ACSettingEntry implements ICSettingEntry { String fName; ACSettingEntry(String name, int flags){ - fName = name; + fName = SafeStringInterner.safeIntern(name); fFlags = flags; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CMacroEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CMacroEntry.java index 34e9a8b3818..451efd313d8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CMacroEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CMacroEntry.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.cdt.core.settings.model; +import org.eclipse.cdt.internal.core.SafeStringInterner; + public final class CMacroEntry extends ACSettingEntry implements ICMacroEntry{ @@ -17,7 +19,7 @@ public final class CMacroEntry extends ACSettingEntry implements ICMacroEntry{ public CMacroEntry(String name, String value, int flags) { super(name, flags); - fValue = value; + fValue = SafeStringInterner.safeIntern(value); if(fValue == null) fValue = ""; //$NON-NLS-1$ }