1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Adds ICPPMethod.isPureVirtual(), bug 248865.

This commit is contained in:
Markus Schorn 2008-10-06 09:22:25 +00:00
parent 6b82deb626
commit 5a9b69c9ee
21 changed files with 133 additions and 22 deletions

View file

@ -8,7 +8,6 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.index.tests;
import java.util.Arrays;
@ -49,6 +48,7 @@ public class IndexUpdateTests extends IndexTestBase {
private static final String EXPLICIT = "explicit";
private static final String VIRTUAL = "virtual";
private static final String PURE_VIRTUAL= "pure-virtual";
private static final String PROTECTED = "protected";
private static final String PUBLIC = "public";
private static final String PRIVATE = "private";
@ -80,6 +80,7 @@ public class IndexUpdateTests extends IndexTestBase {
super(name);
}
@Override
public void setUp() throws Exception {
super.setUp();
if (fCppProject == null) {
@ -119,6 +120,7 @@ public class IndexUpdateTests extends IndexTestBase {
TestSourceReader.waitUntilFileIsIndexed(fIndex, fFile, INDEXER_WAIT_TIME);
}
@Override
public void tearDown() throws Exception {
fIndex= null;
if (fFile != null) {
@ -376,8 +378,10 @@ public class IndexUpdateTests extends IndexTestBase {
// class MyClass {int method(char a){};};
// class MyClass {virtual int method(char a) = 0;};
public void testCppMethod() throws Exception {
setupFile(9, true);
setupFile(10, true);
checkCppMethod("MyClass::method", new String[] {INT, INT, INT}, new String[]{PRIVATE});
updateFile();
checkCppMethod("MyClass::method", new String[] {SHORT, INT, INT}, new String[]{PRIVATE});
@ -395,6 +399,8 @@ public class IndexUpdateTests extends IndexTestBase {
checkCppMethod("MyClass::method", new String[] {INT, CHAR}, new String[]{PRIVATE});
updateFile();
checkCppMethod("MyClass::method", new String[] {INT, CHAR}, new String[]{PRIVATE, INLINE});
updateFile();
checkCppMethod("MyClass::method", new String[] {INT, CHAR}, new String[]{PRIVATE, VIRTUAL, PURE_VIRTUAL});
}
// class MyClass {protected: int method(int a, int b);};
@ -429,6 +435,7 @@ public class IndexUpdateTests extends IndexTestBase {
checkFunction(method, types, modifiers);
checkCppMember(method, modifiers);
checkModifier(modifiers, VIRTUAL, method.isVirtual());
checkModifier(modifiers, PURE_VIRTUAL, method.isPureVirtual());
checkModifier(modifiers, IMPLICIT, method.isImplicit());
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 IBM Corporation.
* Copyright (c) 2006, 2008 IBM Corporation.
* 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
@ -8,7 +8,6 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests;
import junit.framework.Test;
@ -38,12 +37,14 @@ public class MethodTests extends PDOMTestBase {
return suite(MethodTests.class);
}
@Override
protected void setUp() throws Exception {
project = createProject("methodTests");
pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project);
pdom.acquireReadLock();
}
@Override
protected void tearDown() throws Exception {
pdom.releaseReadLock();
if (project != null) {
@ -109,6 +110,7 @@ public class MethodTests extends PDOMTestBase {
assertEquals(1, bindings.length);
ICPPMethod method = (ICPPMethod) bindings[0];
assertTrue(method.isVirtual());
assertTrue(method.isPureVirtual());
}
public void testPureVirtualMethodType() throws Exception {

View file

@ -6,14 +6,16 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
* IBM - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
/**
* @author Doug Schaefer
* Base interface for methods, also used for constructors.
*
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface ICPPMethod extends ICPPFunction, ICPPMember {
public static final ICPPMethod [] EMPTY_CPPMETHOD_ARRAY = new ICPPMethod[0];
@ -36,4 +38,10 @@ public interface ICPPMethod extends ICPPFunction, ICPPMember {
* @since 4.0
*/
public boolean isImplicit();
/**
* Returns whether this is a pure abstract method
* @since 5.1
*/
public boolean isPureVirtual() throws DOMException;
}

View file

@ -171,8 +171,13 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
return true;
}
public boolean isPureVirtual() {
return false;
}
@Override
public IBinding getOwner() {
return getClassOwner();
}
}

View file

@ -60,6 +60,9 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
public boolean isVirtual() throws DOMException {
throw new DOMException( this );
}
public boolean isPureVirtual() throws DOMException {
throw new DOMException( this );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isDestructor()
@ -239,4 +242,27 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
public boolean isImplicit() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isPureVirtual()
*/
public boolean isPureVirtual() throws DOMException {
if (declarations != null) {
for (IASTDeclarator dtor : declarations) {
if (dtor == null)
break;
dtor = CPPVisitor.findOutermostDeclarator(dtor);
IASTDeclaration decl = (IASTDeclaration) dtor.getParent();
if (decl.getParent() instanceof ICPPASTCompositeTypeSpecifier) {
dtor= CPPVisitor.findTypeRelevantDeclarator(dtor);
if (dtor instanceof ICPPASTFunctionDeclarator) {
return ((ICPPASTFunctionDeclarator) dtor).isPureVirtual();
}
}
}
}
return false;
}
}

View file

@ -44,6 +44,13 @@ public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod
return ((ICPPMethod)getTemplateDefinition()).isVirtual();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isPureVirtual()
*/
public boolean isPureVirtual() throws DOMException {
return ((ICPPMethod)getTemplateDefinition()).isPureVirtual();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isDestructor()
*/

View file

@ -79,4 +79,12 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization
return false;
}
public boolean isPureVirtual() throws DOMException {
ICPPMethod f = (ICPPMethod) getSpecializedBinding();
if (f != null)
return f.isPureVirtual();
return false;
}
}

View file

@ -156,4 +156,8 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
return false;
}
public boolean isPureVirtual() throws DOMException {
return false;
}
}

View file

@ -57,4 +57,8 @@ public class CPPMethodTemplateSpecialization extends
return false;
}
public boolean isPureVirtual() throws DOMException {
return false;
}
}

View file

@ -43,4 +43,8 @@ class CompositeCPPMethod extends CompositeCPPFunction implements ICPPMethod {
public int getVisibility() throws DOMException {
return ((ICPPMethod)rbinding).getVisibility();
}
public boolean isPureVirtual() throws DOMException {
return ((ICPPMethod)rbinding).isPureVirtual();
}
}

View file

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others.
* Copyright (c) 2007, 2008 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
@ -42,4 +42,8 @@ public class CompositeCPPMethodInstance extends CompositeCPPFunctionInstance imp
public int getVisibility() throws DOMException {
return ((ICPPMethod)rbinding).getVisibility();
}
public boolean isPureVirtual() throws DOMException {
return ((ICPPMethod)rbinding).isPureVirtual();
}
}

View file

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others.
* Copyright (c) 2007, 2008 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
@ -43,4 +43,8 @@ implements ICPPMethod {
public int getVisibility() throws DOMException {
return ((ICPPMethod)rbinding).getVisibility();
}
public boolean isPureVirtual() throws DOMException {
return ((ICPPMethod)rbinding).isPureVirtual();
}
}

View file

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others.
* Copyright (c) 2007, 2008 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
@ -44,4 +44,8 @@ public class CompositeCPPMethodTemplate extends CompositeCPPFunctionTemplate imp
return ((ICPPMethod)rbinding).getVisibility();
}
public boolean isPureVirtual() throws DOMException {
return ((ICPPMethod)rbinding).isPureVirtual();
}
}

View file

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others.
* Copyright (c) 2007, 2008 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
@ -46,4 +46,8 @@ public class CompositeCPPMethodTemplateSpecialization
public int getVisibility() throws DOMException {
return ((ICPPMethod)rbinding).getVisibility();
}
public boolean isPureVirtual() throws DOMException {
return ((ICPPMethod)rbinding).isPureVirtual();
}
}

View file

@ -179,6 +179,7 @@ public class PDOM extends PlatformObject implements IPDOM {
* 70.0 - cleaned up templates, fixes bug 236197
* 71.0 - proper support for anonymous unions, bug 206450
* 72.0 - store project-relative paths for resources that belong to the project, bug 239472
* 72.1 - store flag for pure virtual methods.
*/
public static final int LINKAGES = Database.DATA_AREA;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 IBM Corporation.
* Copyright (c) 2006, 2008 IBM Corporation.
* 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
@ -9,7 +9,6 @@
* IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
@ -39,7 +38,8 @@ class PDOMCPPAnnotation {
public static final int DESTRUCTOR_OFFSET = 1;
public static final int IMPLICIT_METHOD_OFFSET = 2;
public static final int EXPLICIT_CONSTRUCTOR_OFFSET = 3;
public static final int MAX_EXTRA_OFFSET= EXPLICIT_CONSTRUCTOR_OFFSET;
public static final int PURE_VIRTUAL_OFFSET = 4;
public static final int MAX_EXTRA_OFFSET= PURE_VIRTUAL_OFFSET;
/**
* Encodes storage class specifiers and other annotation, including
@ -92,6 +92,7 @@ class PDOMCPPAnnotation {
modifiers |= (method.isVirtual() ? 1 : 0) << VIRTUAL_OFFSET;
modifiers |= (method.isDestructor() ? 1 : 0) << DESTRUCTOR_OFFSET;
modifiers |= (method.isImplicit() ? 1 : 0) << IMPLICIT_METHOD_OFFSET;
modifiers |= (method.isPureVirtual() ? 1 : 0) << PURE_VIRTUAL_OFFSET;
}
if (binding instanceof ICPPConstructor) {
ICPPConstructor constructor= (ICPPConstructor) binding;

View file

@ -11,7 +11,6 @@
* Andrew Ferguson (Symbian)
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
@ -104,6 +103,10 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.VIRTUAL_OFFSET);
}
public boolean isPureVirtual() throws DOMException {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.PURE_VIRTUAL_OFFSET);
}
public boolean isDestructor() throws DOMException {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.DESTRUCTOR_OFFSET);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 QNX Software Systems and others.
* Copyright (c) 2007, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -24,8 +24,7 @@ import org.eclipse.core.runtime.CoreException;
* @author Bryan Wilkinson
*
*/
class PDOMCPPMethodInstance extends PDOMCPPFunctionInstance implements
ICPPMethod {
class PDOMCPPMethodInstance extends PDOMCPPFunctionInstance implements ICPPMethod {
/**
* The size in bytes of a PDOMCPPMethodInstance record in the database.
@ -69,6 +68,10 @@ class PDOMCPPMethodInstance extends PDOMCPPFunctionInstance implements
return ((ICPPMethod)getTemplateDefinition()).isVirtual();
}
public boolean isPureVirtual() throws DOMException {
return ((ICPPMethod)getTemplateDefinition()).isPureVirtual();
}
public ICPPClassType getClassOwner() throws DOMException {
return (ICPPClassType) getOwner();
}

View file

@ -89,6 +89,10 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.VIRTUAL_OFFSET);
}
public boolean isPureVirtual() throws DOMException {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.PURE_VIRTUAL_OFFSET);
}
@Override
public boolean isExtern() throws DOMException {
// ISO/IEC 14882:2003 9.2.6

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 QNX Software Systems and others.
* Copyright (c) 2007, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -128,4 +128,8 @@ class PDOMCPPMethodTemplate extends PDOMCPPFunctionTemplate implements ICPPMetho
// ISO/IEC 14882:2003 9.2.6
return false;
}
public boolean isPureVirtual() throws DOMException {
return false;
}
}

View file

@ -83,4 +83,8 @@ class PDOMCPPMethodTemplateSpecialization extends
public boolean isExternC() {
return false;
}
public boolean isPureVirtual() throws DOMException {
return false;
}
}