mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Variable and function annotations in PDOM, by Jason Montojo, bug 159595.
This commit is contained in:
parent
08a632ecc7
commit
4c2b2120e4
36 changed files with 1867 additions and 81 deletions
|
@ -18,8 +18,9 @@ import java.util.Random;
|
|||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.BTree;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
|
||||
|
@ -32,7 +33,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
* @author aferguso
|
||||
*
|
||||
*/
|
||||
public class BTreeTests extends TestCase {
|
||||
public class BTreeTests extends BaseTestCase {
|
||||
protected File dbFile;
|
||||
protected Database db;
|
||||
protected BTree btree;
|
||||
|
@ -41,6 +42,10 @@ public class BTreeTests extends TestCase {
|
|||
|
||||
protected boolean debugMode = false;
|
||||
|
||||
public static Test suite() {
|
||||
return suite(BTreeTests.class);
|
||||
}
|
||||
|
||||
// setUp is not used since we need to parameterize this method,
|
||||
// and invoke it multiple times per Junit test
|
||||
protected void init(int degree) throws Exception {
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.pdom.tests;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
|
||||
/**
|
||||
* Tests for verifying whether the PDOM correctly stores information about
|
||||
* C functions.
|
||||
*/
|
||||
public class CFunctionTests extends PDOMTestBase {
|
||||
|
||||
protected ICProject project;
|
||||
protected PDOM pdom;
|
||||
|
||||
public static Test suite() {
|
||||
return suite(CFunctionTests.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
project = createProject("functionTests");
|
||||
pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
|
||||
pdom.acquireReadLock();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
pdom.releaseReadLock();
|
||||
}
|
||||
|
||||
public void testExternCFunction() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "externCFunction");
|
||||
assertEquals(1, bindings.length);
|
||||
assertTrue(((IFunction) bindings[0]).isExtern());
|
||||
}
|
||||
|
||||
public void testStaticCFunction() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "staticCFunction");
|
||||
assertEquals(1, bindings.length);
|
||||
assertTrue(((IFunction) bindings[0]).isStatic());
|
||||
}
|
||||
|
||||
public void testInlineCFunction() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "inlineCFunction");
|
||||
assertEquals(1, bindings.length);
|
||||
assertTrue(((IFunction) bindings[0]).isInline());
|
||||
}
|
||||
|
||||
public void testVarArgsCFunction() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "varArgsCFunction");
|
||||
assertEquals(1, bindings.length);
|
||||
assertTrue(((IFunction) bindings[0]).takesVarArgs());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,186 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.pdom.tests;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
|
||||
/**
|
||||
* Tests for verifying whether the PDOM correctly stores information about
|
||||
* C++ structs and unions.
|
||||
*/
|
||||
public class CPPCompositeTypeTests extends PDOMTestBase {
|
||||
|
||||
private ICProject project;
|
||||
private PDOM pdom;
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(CPPCompositeTypeTests.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
CPPCompositeTypeTests foo = null;
|
||||
|
||||
project = createProject("compositeTypeTests");
|
||||
pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
|
||||
pdom.acquireReadLock();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
pdom.releaseReadLock();
|
||||
}
|
||||
|
||||
public void testSimpleStructure() throws Exception {
|
||||
assertType(pdom, "SimpleStructure", ICompositeType.class);
|
||||
}
|
||||
|
||||
public void testSimpleStructureDeclarations() throws Exception {
|
||||
assertDeclarationCount(pdom, "SimpleStructure", 1);
|
||||
assertDeclarationCount(pdom, "SimpleStructure::ssa", 1);
|
||||
}
|
||||
|
||||
public void testSimpleStructureDefinitions() throws Exception {
|
||||
assertDefinitionCount(pdom, "SimpleStructure", 1);
|
||||
assertDefinitionCount(pdom, "SimpleStructure::ssa", 1);
|
||||
}
|
||||
|
||||
public void testSimpleStructureReferences() throws Exception {
|
||||
assertReferenceCount(pdom, "SimpleStructure", 2);
|
||||
assertReferenceCount(pdom, "SimpleStructure::ssa", 2);
|
||||
}
|
||||
|
||||
public void testDeepStructure() throws Exception {
|
||||
assertType(pdom, "Structure1", ICompositeType.class);
|
||||
assertType(pdom, "Structure1::Structure2", ICompositeType.class);
|
||||
assertType(pdom, "Structure1::Structure2::Structure3", ICompositeType.class);
|
||||
}
|
||||
|
||||
public void testDeepStructureDeclarations() throws Exception {
|
||||
assertDeclarationCount(pdom, "Structure1", 1);
|
||||
assertDeclarationCount(pdom, "Structure1::Structure2", 1);
|
||||
assertDeclarationCount(pdom, "Structure1::Structure2::Structure3", 1);
|
||||
}
|
||||
|
||||
public void testDeepStructureMemberDeclarations() throws Exception {
|
||||
assertDeclarationCount(pdom, "Structure1::s1a", 1);
|
||||
assertDeclarationCount(pdom, "Structure1::s1b", 1);
|
||||
assertDeclarationCount(pdom, "Structure1::s1c", 1);
|
||||
assertDeclarationCount(pdom, "Structure1::Structure2::s2b", 1);
|
||||
assertDeclarationCount(pdom, "Structure1::Structure2::Structure3::s3a", 1);
|
||||
}
|
||||
|
||||
public void testDeepStructureDefinitions() throws Exception {
|
||||
assertDefinitionCount(pdom, "Structure1", 1);
|
||||
assertDefinitionCount(pdom, "Structure1::Structure2", 1);
|
||||
assertDefinitionCount(pdom, "Structure1::Structure2::Structure3", 1);
|
||||
}
|
||||
|
||||
public void testDeepStructureMemberDefinitions() throws Exception {
|
||||
assertDefinitionCount(pdom, "Structure1::s1a", 1);
|
||||
assertDefinitionCount(pdom, "Structure1::s1b", 1);
|
||||
assertDefinitionCount(pdom, "Structure1::s1c", 1);
|
||||
assertDefinitionCount(pdom, "Structure1::Structure2::s2b", 1);
|
||||
assertDefinitionCount(pdom, "Structure1::Structure2::Structure3::s3a", 1);
|
||||
}
|
||||
|
||||
public void testDeepStructureReferences() throws Exception {
|
||||
assertReferenceCount(pdom, "Structure1", 6);
|
||||
assertReferenceCount(pdom, "Structure1::Structure2", 4);
|
||||
assertReferenceCount(pdom, "Structure1::Structure2::Structure3", 2);
|
||||
}
|
||||
|
||||
public void testDeepStructureMemberReferences() throws Exception {
|
||||
assertReferenceCount(pdom, "Structure1::s1a", 2);
|
||||
assertReferenceCount(pdom, "Structure1::s1b", 3);
|
||||
assertReferenceCount(pdom, "Structure1::s1c", 14);
|
||||
assertReferenceCount(pdom, "Structure1::Structure2::s2b", 12);
|
||||
assertReferenceCount(pdom, "Structure1::Structure2::Structure3::s3a", 8);
|
||||
}
|
||||
|
||||
public void testUnionDeclarations() throws Exception {
|
||||
assertDeclarationCount(pdom, "Union1", 1);
|
||||
assertDeclarationCount(pdom, "Union1::Union2", 1);
|
||||
}
|
||||
|
||||
public void testUnionDefinitions() throws Exception {
|
||||
assertDefinitionCount(pdom, "Union1", 1);
|
||||
assertDefinitionCount(pdom, "Union1::Union2", 1);
|
||||
}
|
||||
|
||||
public void testUnionReferences() throws Exception {
|
||||
assertReferenceCount(pdom, "Union1", 4);
|
||||
assertReferenceCount(pdom, "Union1::Union2", 2);
|
||||
}
|
||||
|
||||
public void testUnionMemberDeclarations() throws Exception {
|
||||
assertDeclarationCount(pdom, "Union1::u1a", 1);
|
||||
assertDeclarationCount(pdom, "Union1::u1d", 1);
|
||||
}
|
||||
|
||||
public void testUnionMemberDefinitions() throws Exception {
|
||||
assertDefinitionCount(pdom, "Union1::u1a", 1);
|
||||
assertDefinitionCount(pdom, "Union1::u1d", 1);
|
||||
}
|
||||
|
||||
public void testUnionMemberReferences() throws Exception {
|
||||
assertReferenceCount(pdom, "Union1::u1a", 2);
|
||||
assertReferenceCount(pdom, "Union1::u1d", 1);
|
||||
}
|
||||
|
||||
public void testMixedDeclarations() throws Exception {
|
||||
assertDeclarationCount(pdom, "MixedS1::MixedU1", 1);
|
||||
assertDeclarationCount(pdom, "MixedS1::MixedU1::MixedS2", 1);
|
||||
assertDeclarationCount(pdom, "MixedS1::MixedU1::MixedU2", 1);
|
||||
assertDeclarationCount(pdom, "MixedS1::MixedS3", 1);
|
||||
}
|
||||
|
||||
public void testMixedDefinitions() throws Exception {
|
||||
assertDefinitionCount(pdom, "MixedS1::MixedU1", 1);
|
||||
assertDefinitionCount(pdom, "MixedS1::MixedU1::MixedS2", 1);
|
||||
assertDefinitionCount(pdom, "MixedS1::MixedU1::MixedU2", 1);
|
||||
assertDefinitionCount(pdom, "MixedS1::MixedS3", 1);
|
||||
}
|
||||
|
||||
public void testMixedReferences() throws Exception {
|
||||
assertReferenceCount(pdom, "MixedS1::MixedU1", 6);
|
||||
assertReferenceCount(pdom, "MixedS1::MixedU1::MixedS2", 2);
|
||||
assertReferenceCount(pdom, "MixedS1::MixedU1::MixedU2", 2);
|
||||
assertReferenceCount(pdom, "MixedS1::MixedS3", 2);
|
||||
}
|
||||
|
||||
public void testMixedMemberDeclarations() throws Exception {
|
||||
assertDeclarationCount(pdom, "MixedS1::MixedU1::mu1a", 1);
|
||||
assertDeclarationCount(pdom, "MixedS1::MixedU1::MixedS2::ms2a", 1);
|
||||
assertDeclarationCount(pdom, "MixedS1::MixedU1::MixedU2::mu2a", 1);
|
||||
assertDeclarationCount(pdom, "MixedS1::MixedS3::ms3a", 1);
|
||||
}
|
||||
|
||||
public void testMixedMemberDefinitions() throws Exception {
|
||||
assertDefinitionCount(pdom, "MixedS1::MixedU1::mu1a", 1);
|
||||
assertDefinitionCount(pdom, "MixedS1::MixedU1::MixedS2::ms2a", 1);
|
||||
assertDefinitionCount(pdom, "MixedS1::MixedU1::MixedU2::mu2a", 1);
|
||||
assertDefinitionCount(pdom, "MixedS1::MixedS3::ms3a", 1);
|
||||
}
|
||||
|
||||
public void testMixedMemberReferences() throws Exception {
|
||||
assertReferenceCount(pdom, "MixedS1::MixedU1::mu1a", 2);
|
||||
assertReferenceCount(pdom, "MixedS1::MixedU1::MixedS2::ms2a", 2);
|
||||
assertReferenceCount(pdom, "MixedS1::MixedU1::MixedU2::mu2a", 2);
|
||||
assertReferenceCount(pdom, "MixedS1::MixedS3::ms3a", 2);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.pdom.tests;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Tests for verifying whether the PDOM correctly stores information about
|
||||
* C++ class data members.
|
||||
*/
|
||||
public class CPPFieldTests extends PDOMTestBase {
|
||||
|
||||
protected PDOM pdom;
|
||||
protected ICProject project;
|
||||
|
||||
public static Test suite() {
|
||||
return suite(CPPFieldTests.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
project = createProject("fieldTests");
|
||||
pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
|
||||
pdom.acquireReadLock();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
pdom.releaseReadLock();
|
||||
}
|
||||
|
||||
public void testFieldDeclarations() throws Exception {
|
||||
assertDeclarationCount(pdom, "Class1::c1a", 1);
|
||||
}
|
||||
|
||||
public void testFieldDefinitions() throws Exception {
|
||||
assertDefinitionCount(pdom, "Class1::c1a", 1);
|
||||
}
|
||||
|
||||
public void testFieldReferences() throws Exception {
|
||||
assertReferenceCount(pdom, "Class1::c1a", 4);
|
||||
}
|
||||
|
||||
public void testInheritedFieldDeclarations() throws Exception {
|
||||
assertDeclarationCount(pdom, "Class2::c1a", 0);
|
||||
}
|
||||
|
||||
public void testInheritedFieldDefinitions() throws Exception {
|
||||
assertDefinitionCount(pdom, "Class2::c1a", 0);
|
||||
}
|
||||
|
||||
public void testInheritedFieldReferences() throws Exception {
|
||||
assertReferenceCount(pdom, "Class2::c1a", 0);
|
||||
}
|
||||
|
||||
public void testDefaultPrivateField() throws Exception {
|
||||
assertVisibility(pdom, "Class1::defaultField", ICPPMember.v_private);
|
||||
}
|
||||
|
||||
public void testPrivateField() throws Exception {
|
||||
assertVisibility(pdom, "Class1::privateField", ICPPMember.v_private);
|
||||
}
|
||||
|
||||
public void testProtectedField() throws Exception {
|
||||
assertVisibility(pdom, "Class1::protectedField", ICPPMember.v_protected);
|
||||
}
|
||||
|
||||
public void testPublicField() throws Exception {
|
||||
assertVisibility(pdom, "Class1::publicField", ICPPMember.v_public);
|
||||
}
|
||||
|
||||
public void testMutableField() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "Class1::mutableField");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPField field = (ICPPField) bindings[0];
|
||||
assertTrue(field.isMutable());
|
||||
}
|
||||
|
||||
public void testStaticField() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "Class1::staticField");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPField field = (ICPPField) bindings[0];
|
||||
assertTrue(field.isStatic());
|
||||
}
|
||||
|
||||
public void _testIntField() throws Exception {
|
||||
// Type information not yet stored in PDOM.
|
||||
assertFieldType(pdom, "Class1::c1a", IBasicType.t_int);
|
||||
}
|
||||
|
||||
public void _testDoubleField() throws Exception {
|
||||
// Type information not yet stored in PDOM.
|
||||
assertFieldType(pdom, "Class1::c1b", IBasicType.t_double);
|
||||
}
|
||||
|
||||
public void _testCharField() throws Exception {
|
||||
// Type information not yet stored in PDOM.
|
||||
assertFieldType(pdom, "Class2::c2a", IBasicType.t_char);
|
||||
}
|
||||
|
||||
public void _testFloatField() throws Exception {
|
||||
// Type information not yet stored in PDOM.
|
||||
assertFieldType(pdom, "Class2::c2b", IBasicType.t_float);
|
||||
}
|
||||
|
||||
private void assertFieldType(PDOM pdom, String name, int type) throws CoreException {
|
||||
IBinding[] bindings = findQualifiedName(pdom, name);
|
||||
assertEquals(1, bindings.length);
|
||||
IField field = (IField) bindings[0];
|
||||
assertEquals(type, ((IBasicType) field.getType()).getType());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,187 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.pdom.tests;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Tests for verifying whether the PDOM correctly stores information about
|
||||
* C++ non-member functions.
|
||||
*/
|
||||
public class CPPFunctionTests extends PDOMTestBase {
|
||||
|
||||
protected ICProject project;
|
||||
|
||||
protected PDOM pdom;
|
||||
|
||||
public static Test suite() {
|
||||
return suite(CPPFunctionTests.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
project = createProject("functionTests");
|
||||
pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
|
||||
pdom.acquireReadLock();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
pdom.releaseReadLock();
|
||||
}
|
||||
|
||||
public void testFunctionType() throws Exception {
|
||||
assertType(pdom, "normalDeclaration1", ICPPFunction.class);
|
||||
assertType(pdom, "normalDeclaration2", ICPPFunction.class);
|
||||
}
|
||||
|
||||
public void testFunctionDeclarations() throws Exception {
|
||||
assertDeclarationCount(pdom, "normalDeclaration1", 1);
|
||||
assertDeclarationCount(pdom, "normalDeclaration2", 1);
|
||||
}
|
||||
|
||||
public void testFunctionDefinitions() throws Exception {
|
||||
assertDefinitionCount(pdom, "normalDeclaration1", 1);
|
||||
assertDefinitionCount(pdom, "normalDeclaration2", 1);
|
||||
}
|
||||
|
||||
public void testFunctionReferences() throws Exception {
|
||||
assertReferenceCount(pdom, "normalDeclaration1", 2);
|
||||
assertReferenceCount(pdom, "normalDeclaration2", 3);
|
||||
assertReferenceCount(pdom, "forwardDeclaration", 2);
|
||||
}
|
||||
|
||||
public void testParameters() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "normalCPPFunction");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPFunction function = (ICPPFunction) bindings[0];
|
||||
IParameter[] parameters = function.getParameters();
|
||||
assertEquals(IBasicType.t_int, ((ICPPBasicType) parameters[0].getType()).getType());
|
||||
assertEquals("p1", parameters[0].getName());
|
||||
assertEquals(IBasicType.t_char, ((ICPPBasicType) parameters[1].getType()).getType());
|
||||
assertEquals("p2", parameters[1].getName());
|
||||
assertEquals(IBasicType.t_float, ((ICPPBasicType) parameters[2].getType()).getType());
|
||||
assertEquals("p3", parameters[2].getName());
|
||||
}
|
||||
|
||||
public void testExternCPPFunction() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "externCPPFunction");
|
||||
assertEquals(1, bindings.length);
|
||||
assertTrue(((ICPPFunction) bindings[0]).isExtern());
|
||||
}
|
||||
|
||||
public void testStaticCPPFunction() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "staticCPPFunction");
|
||||
assertEquals(1, bindings.length);
|
||||
assertTrue(((ICPPFunction) bindings[0]).isStatic());
|
||||
}
|
||||
|
||||
public void testInlineCPPFunction() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "inlineCPPFunction");
|
||||
assertEquals(1, bindings.length);
|
||||
assertTrue(((ICPPFunction) bindings[0]).isInline());
|
||||
}
|
||||
|
||||
public void testVarArgsCPPFunction() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "varArgsCPPFunction");
|
||||
assertEquals(1, bindings.length);
|
||||
assertTrue(((ICPPFunction) bindings[0]).takesVarArgs());
|
||||
}
|
||||
|
||||
public void testForwardDeclarationType() throws Exception {
|
||||
assertType(pdom, "forwardDeclaration", ICPPFunction.class);
|
||||
}
|
||||
|
||||
public void testForwardDeclaration() throws Exception {
|
||||
assertDeclarationCount(pdom, "forwardDeclaration", 2);
|
||||
assertDefinitionCount(pdom, "forwardDeclaration", 1);
|
||||
}
|
||||
|
||||
public void _testVoidFunction() throws Exception {
|
||||
// Type information not yet stored in PDOM.
|
||||
assertReturnType(pdom, "voidCPPFunction", IBasicType.t_void);
|
||||
}
|
||||
|
||||
public void _testIntFunction() throws Exception {
|
||||
// Type information not yet stored in PDOM.
|
||||
assertReturnType(pdom, "intCPPFunction", IBasicType.t_int);
|
||||
}
|
||||
|
||||
public void _testDoubleFunction() throws Exception {
|
||||
// Type information not yet stored in PDOM.
|
||||
assertReturnType(pdom, "doubleCPPFunction", IBasicType.t_double);
|
||||
}
|
||||
|
||||
public void _testCharFunction() throws Exception {
|
||||
// Type information not yet stored in PDOM.
|
||||
assertReturnType(pdom, "charCPPFunction", IBasicType.t_char);
|
||||
}
|
||||
|
||||
public void _testFloatFunction() throws Exception {
|
||||
// Type information not yet stored in PDOM.
|
||||
assertReturnType(pdom, "floatCPPFunction", IBasicType.t_float);
|
||||
}
|
||||
|
||||
public void _testOverloadedFunction() throws Exception {
|
||||
// Right now, only one binding is showing up for overloaded functions.
|
||||
// There really should be one for each declaration.
|
||||
|
||||
IBinding[] bindings = findQualifiedName(pdom, "overloadedFunction");
|
||||
assertEquals(2, bindings.length);
|
||||
boolean[] seen = new boolean[2];
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
ICPPFunction function = (ICPPFunction) bindings[i];
|
||||
assertEquals(1, pdom.getDeclarations(function).length);
|
||||
assertEquals(1, pdom.getDefinitions(function).length);
|
||||
IParameter[] parameters = function.getParameters();
|
||||
switch (parameters.length) {
|
||||
case 0:
|
||||
assertFalse(seen[0]);
|
||||
assertEquals(1, pdom.getReferences(function).length);
|
||||
seen[0] = true;
|
||||
break;
|
||||
case 1:
|
||||
assertFalse(seen[1]);
|
||||
assertEquals(2, pdom.getReferences(function).length);
|
||||
assertEquals("p1", parameters[0].getName());
|
||||
assertEquals(IBasicType.t_int, ((ICPPBasicType) parameters[0].getType()).getType());
|
||||
seen[1] = true;
|
||||
break;
|
||||
default:
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < seen.length; i++) {
|
||||
assertTrue(seen[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertReturnType(PDOM pdom, String name, int type) throws CoreException {
|
||||
IBinding[] bindings = findQualifiedName(pdom, name);
|
||||
assertEquals(1, bindings.length);
|
||||
IFunction function = (IFunction) bindings[0];
|
||||
IFunctionType functionType = function.getType();
|
||||
assertEquals(type, ((ICPPBasicType) functionType.getReturnType()).getType());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.pdom.tests;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
|
||||
/**
|
||||
* Tests for verifying whether the PDOM correctly stores information about
|
||||
* C++ variable declarations.
|
||||
*/
|
||||
public class CPPVariableTests extends PDOMTestBase {
|
||||
|
||||
protected ICProject project;
|
||||
protected PDOM pdom;
|
||||
|
||||
public static Test suite() {
|
||||
return suite(CPPVariableTests.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
project = createProject("variableTests");
|
||||
pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
|
||||
pdom.acquireReadLock();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
pdom.releaseReadLock();
|
||||
}
|
||||
|
||||
public void testCPPAutoVariable() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "autoCPPVariable");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPVariable variable = (ICPPVariable) bindings[0];
|
||||
assertTrue(variable.isAuto());
|
||||
}
|
||||
|
||||
public void testCPPExternVariable() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "externCPPVariable");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPVariable variable = (ICPPVariable) bindings[0];
|
||||
assertTrue(variable.isExtern());
|
||||
}
|
||||
|
||||
public void testCPPRegisterVariable() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "registerCPPVariable");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPVariable variable = (ICPPVariable) bindings[0];
|
||||
assertTrue(variable.isRegister());
|
||||
}
|
||||
|
||||
public void testCPPStaticVariable() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "staticCPPVariable");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPVariable variable = (ICPPVariable) bindings[0];
|
||||
assertTrue(variable.isStatic());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.pdom.tests;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
|
||||
/**
|
||||
* Tests for verifying whether the PDOM correctly stores information about
|
||||
* C variable declarations.
|
||||
*/
|
||||
public class CVariableTests extends PDOMTestBase {
|
||||
|
||||
protected ICProject project;
|
||||
protected PDOM pdom;
|
||||
|
||||
public static Test suite() {
|
||||
return suite(CVariableTests.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
project = createProject("variableTests");
|
||||
pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
|
||||
pdom.acquireReadLock();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
pdom.releaseReadLock();
|
||||
}
|
||||
|
||||
public void testCAutoVariable() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "autoCVariable");
|
||||
assertEquals(1, bindings.length);
|
||||
IVariable variable = (IVariable) bindings[0];
|
||||
assertTrue(variable.isAuto());
|
||||
}
|
||||
|
||||
public void testCExternVariable() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "externCVariable");
|
||||
assertEquals(1, bindings.length);
|
||||
IVariable variable = (IVariable) bindings[0];
|
||||
assertTrue(variable.isExtern());
|
||||
}
|
||||
|
||||
public void testCRegisterVariable() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "registerCVariable");
|
||||
assertEquals(1, bindings.length);
|
||||
IVariable variable = (IVariable) bindings[0];
|
||||
assertTrue(variable.isRegister());
|
||||
}
|
||||
|
||||
public void testCStaticVariable() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "staticCVariable");
|
||||
assertEquals(1, bindings.length);
|
||||
IVariable variable = (IVariable) bindings[0];
|
||||
assertTrue(variable.isStatic());
|
||||
}
|
||||
|
||||
}
|
|
@ -13,6 +13,8 @@ package org.eclipse.cdt.internal.pdom.tests;
|
|||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
|
@ -36,6 +38,10 @@ public class ClassTests extends PDOMTestBase {
|
|||
|
||||
protected PDOM pdom;
|
||||
|
||||
public static Test suite() {
|
||||
return suite(ClassTests.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
if (pdom == null) {
|
||||
ICProject project = createProject("classTests");
|
||||
|
|
|
@ -13,6 +13,8 @@ package org.eclipse.cdt.internal.pdom.tests;
|
|||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
|
@ -33,6 +35,10 @@ public class EnumerationTests extends PDOMTestBase {
|
|||
|
||||
protected PDOM pdom;
|
||||
|
||||
public static Test suite() {
|
||||
return suite(EnumerationTests.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
if (pdom == null) {
|
||||
ICProject project = createProject("enumerationTests");
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.pdom.tests;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexFile;
|
||||
|
@ -26,6 +28,10 @@ public class IncludesTests extends PDOMTestBase {
|
|||
protected ICProject project;
|
||||
protected IIndex pdom;
|
||||
|
||||
public static Test suite() {
|
||||
return suite(IncludesTests.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
if (pdom == null) {
|
||||
project = createProject("includesTests");
|
||||
|
|
|
@ -0,0 +1,243 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.pdom.tests;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
||||
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.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
|
||||
/**
|
||||
* Tests for verifying whether the PDOM correctly stores information about
|
||||
* C++ class member functions.
|
||||
*/
|
||||
public class MethodTests extends PDOMTestBase {
|
||||
protected ICProject project;
|
||||
protected PDOM pdom;
|
||||
|
||||
public static Test suite() {
|
||||
return suite(MethodTests.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
project = createProject("methodTests");
|
||||
pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
|
||||
pdom.acquireReadLock();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
pdom.releaseReadLock();
|
||||
}
|
||||
|
||||
public void testMethodParameters() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "Class1::normalMethod");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPFunction function = (ICPPFunction) bindings[0];
|
||||
IParameter[] parameters = function.getParameters();
|
||||
assertEquals(IBasicType.t_int, ((ICPPBasicType) parameters[0].getType()).getType());
|
||||
assertEquals("p1", parameters[0].getName());
|
||||
assertEquals(IBasicType.t_char, ((ICPPBasicType) parameters[1].getType()).getType());
|
||||
assertEquals("p2", parameters[1].getName());
|
||||
assertEquals(IBasicType.t_float, ((ICPPBasicType) parameters[2].getType()).getType());
|
||||
assertEquals("p3", parameters[2].getName());
|
||||
}
|
||||
|
||||
public void testVirtualMethod() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "Class1::inheritedMethod");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPMethod method = (ICPPMethod) bindings[0];
|
||||
assertTrue(method.isVirtual());
|
||||
}
|
||||
|
||||
public void testVirtualMethodType() throws Exception {
|
||||
assertType(pdom, "Class1::inheritedMethod", ICPPFunction.class);
|
||||
}
|
||||
|
||||
public void testVirtualMethodDeclarations() throws Exception {
|
||||
assertDeclarationCount(pdom, "Class1::inheritedMethod", 2);
|
||||
}
|
||||
|
||||
public void testVirtualMethodDefinitions() throws Exception {
|
||||
assertDefinitionCount(pdom, "Class1::inheritedMethod", 1);
|
||||
}
|
||||
|
||||
public void testVirtualMethodReferences() throws Exception {
|
||||
assertReferenceCount(pdom, "Class1::inheritedMethod", 3);
|
||||
}
|
||||
|
||||
public void testInheritedMethodType() throws Exception {
|
||||
assertEquals(0, findQualifiedName(pdom, "Class2::inheritedMethod").length);
|
||||
}
|
||||
|
||||
public void testInheritedMethodDeclarations() throws Exception {
|
||||
assertDeclarationCount(pdom, "Class2::inheritedMethod", 0);
|
||||
}
|
||||
|
||||
public void testInheritedMethodDefinitions() throws Exception {
|
||||
assertDefinitionCount(pdom, "Class2::inheritedMethod", 0);
|
||||
}
|
||||
|
||||
public void testInheritedMethodReferences() throws Exception {
|
||||
assertReferenceCount(pdom, "Class2::inheritedMethod", 0);
|
||||
}
|
||||
|
||||
public void testPureVirtualMethod() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "Class1::pureVirtualMethod");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPMethod method = (ICPPMethod) bindings[0];
|
||||
assertTrue(method.isVirtual());
|
||||
}
|
||||
|
||||
public void testPureVirtualMethodType() throws Exception {
|
||||
assertType(pdom, "Class1::pureVirtualMethod", ICPPFunction.class);
|
||||
assertType(pdom, "Class2::pureVirtualMethod", ICPPFunction.class);
|
||||
}
|
||||
|
||||
public void testPureVirtualMethodDeclarations() throws Exception {
|
||||
assertDeclarationCount(pdom, "Class1::pureVirtualMethod", 1);
|
||||
assertDeclarationCount(pdom, "Class2::pureVirtualMethod", 2);
|
||||
}
|
||||
|
||||
public void testPureVirtualMethodDefinitions() throws Exception {
|
||||
assertDefinitionCount(pdom, "Class1::pureVirtualMethod", 0);
|
||||
assertDefinitionCount(pdom, "Class2::pureVirtualMethod", 1);
|
||||
}
|
||||
|
||||
public void testPureVirtualMethodReferences() throws Exception {
|
||||
assertReferenceCount(pdom, "Class1::pureVirtualMethod", 2);
|
||||
assertReferenceCount(pdom, "Class2::pureVirtualMethod", 3);
|
||||
}
|
||||
|
||||
public void testOverriddenMethodType() throws Exception {
|
||||
assertType(pdom, "Class1::overriddenMethod", ICPPFunction.class);
|
||||
assertType(pdom, "Class2::overriddenMethod", ICPPFunction.class);
|
||||
}
|
||||
|
||||
public void testOverriddenMethodDeclarations() throws Exception {
|
||||
assertDeclarationCount(pdom, "Class1::overriddenMethod", 2);
|
||||
assertDeclarationCount(pdom, "Class2::overriddenMethod", 2);
|
||||
}
|
||||
|
||||
public void testOverriddenMethodDefinitions() throws Exception {
|
||||
assertDefinitionCount(pdom, "Class1::overriddenMethod", 1);
|
||||
assertDefinitionCount(pdom, "Class2::overriddenMethod", 1);
|
||||
}
|
||||
|
||||
public void testOverriddenMethodReferences() throws Exception {
|
||||
assertReferenceCount(pdom, "Class1::overriddenMethod", 3);
|
||||
assertReferenceCount(pdom, "Class2::overriddenMethod", 4);
|
||||
}
|
||||
|
||||
public void testDestructor() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "Class1::~Class1");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPMethod method = (ICPPMethod) bindings[0];
|
||||
assertTrue(method.isDestructor());
|
||||
}
|
||||
|
||||
public void testDefaultPrivateMethod() throws Exception {
|
||||
assertVisibility(pdom, "Class3::defaultMethod", ICPPMember.v_private);
|
||||
}
|
||||
|
||||
public void testPrivateMethod() throws Exception {
|
||||
assertVisibility(pdom, "Class3::privateMethod", ICPPMember.v_private);
|
||||
}
|
||||
|
||||
public void testProtectedMethod() throws Exception {
|
||||
assertVisibility(pdom, "Class3::protectedMethod", ICPPMember.v_protected);
|
||||
}
|
||||
|
||||
public void testPublicMethod() throws Exception {
|
||||
assertVisibility(pdom, "Class3::publicMethod", ICPPMember.v_public);
|
||||
}
|
||||
|
||||
public void testInlineMethod() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "Class1::inlineMethod");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPMethod method = (ICPPMethod) bindings[0];
|
||||
assertTrue(method.isInline());
|
||||
}
|
||||
|
||||
public void testStaticMethod() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "Class1::staticMethod");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPMethod method = (ICPPMethod) bindings[0];
|
||||
assertTrue(method.isStatic());
|
||||
}
|
||||
|
||||
public void testVarArgsMethod() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "Class1::varArgsMethod");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPMethod method = (ICPPMethod) bindings[0];
|
||||
assertTrue(method.takesVarArgs());
|
||||
}
|
||||
|
||||
public void testConstMethod() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "Class1::constMethod");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPMethod method = (ICPPMethod) bindings[0];
|
||||
ICPPFunctionType type = (ICPPFunctionType) method.getType();
|
||||
assertTrue(type.isConst());
|
||||
}
|
||||
|
||||
public void testVolatileMethod() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "Class1::volatileMethod");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPMethod method = (ICPPMethod) bindings[0];
|
||||
ICPPFunctionType type = (ICPPFunctionType) method.getType();
|
||||
assertTrue(type.isVolatile());
|
||||
}
|
||||
|
||||
public void testConstVolatileMethod() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "Class1::constVolatileMethod");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPMethod method = (ICPPMethod) bindings[0];
|
||||
ICPPFunctionType type = (ICPPFunctionType) method.getType();
|
||||
assertTrue(type.isConst());
|
||||
assertTrue(type.isVolatile());
|
||||
}
|
||||
|
||||
public void testNotConstMethod() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "Class1::notConstMethod");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPMethod method = (ICPPMethod) bindings[0];
|
||||
ICPPFunctionType type = (ICPPFunctionType) method.getType();
|
||||
assertFalse(type.isConst());
|
||||
}
|
||||
|
||||
public void testNotVolatileMethod() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "Class1::notVolatileMethod");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPMethod method = (ICPPMethod) bindings[0];
|
||||
ICPPFunctionType type = (ICPPFunctionType) method.getType();
|
||||
assertFalse(type.isVolatile());
|
||||
}
|
||||
|
||||
public void testNotConstVolatileMethod() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "Class1::notConstVolatileMethod");
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPMethod method = (ICPPMethod) bindings[0];
|
||||
ICPPFunctionType type = (ICPPFunctionType) method.getType();
|
||||
assertFalse(type.isConst());
|
||||
assertFalse(type.isVolatile());
|
||||
}
|
||||
|
||||
}
|
|
@ -8,20 +8,29 @@
|
|||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM Corporation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.pdom.tests;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.CProjectNature;
|
||||
import org.eclipse.cdt.core.dom.IName;
|
||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.fast.PDOMFastIndexer;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.fast.PDOMFastReindex;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.nulli.PDOMNullIndexer;
|
||||
|
@ -34,6 +43,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
|
@ -44,8 +54,9 @@ import org.eclipse.ui.wizards.datatransfer.ImportOperation;
|
|||
/**
|
||||
* @author Doug Schaefer
|
||||
*/
|
||||
public class PDOMTestBase extends TestCase {
|
||||
public class PDOMTestBase extends BaseTestCase {
|
||||
|
||||
protected static final IProgressMonitor PROGRESS = new NullProgressMonitor();
|
||||
static IPath rootPath = new Path("resources/pdomtests");
|
||||
private String projectName= null;
|
||||
|
||||
|
@ -119,4 +130,76 @@ public class PDOMTestBase extends TestCase {
|
|||
Path path= new Path(projectName + "/" + projectRelativePath);
|
||||
return TestSourceReader.indexOfInFile(lookfor, path);
|
||||
}
|
||||
|
||||
protected IBinding[] findQualifiedName(PDOM pdom, String name) throws CoreException {
|
||||
String[] segments = name.split("::");
|
||||
Pattern[] pattern = new Pattern[segments.length];
|
||||
for (int i = 0; i < segments.length; i++) {
|
||||
pattern[i] = Pattern.compile(segments[i]);
|
||||
}
|
||||
return pdom.findBindings(pattern, true, new IndexFilter(), PROGRESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for checking the number of PDOM references for a
|
||||
* particular name.
|
||||
*/
|
||||
protected void assertReferenceCount(PDOM pdom, String name, int count) throws CoreException {
|
||||
assertNameCount(pdom, name, count, IIndexFragment.FIND_REFERENCES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for checking the number of PDOM declarations for a
|
||||
* particular name.
|
||||
*/
|
||||
protected void assertDeclarationCount(PDOM pdom, String name, int count) throws CoreException {
|
||||
assertNameCount(pdom, name, count, IIndexFragment.FIND_DECLARATIONS_DEFINITIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for checking the number of PDOM definitions for a
|
||||
* particular name.
|
||||
*/
|
||||
protected void assertDefinitionCount(PDOM pdom, String name, int count) throws CoreException {
|
||||
assertNameCount(pdom, name, count, IIndexFragment.FIND_DEFINITIONS);
|
||||
}
|
||||
|
||||
private void assertNameCount(PDOM pdom, String name, int count, int options) throws CoreException {
|
||||
IBinding[] bindings = findQualifiedName(pdom, name);
|
||||
if (count > 0) {
|
||||
assertEquals(1, bindings.length);
|
||||
}
|
||||
if (bindings.length > 0) {
|
||||
IName[] names = pdom.findNames(bindings[0], options);
|
||||
assertUniqueNameCount(names, count);
|
||||
} else {
|
||||
assertEquals(0, count);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for checking how many unique instances (i.e. same
|
||||
* offset within the same file) there are within an array of INames.
|
||||
*/
|
||||
private void assertUniqueNameCount(IName[] names, int count) {
|
||||
Set offsets = new HashSet();
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
offsets.add(names[i].getFileLocation());
|
||||
}
|
||||
assertEquals(count, offsets.size());
|
||||
}
|
||||
|
||||
protected void assertType(PDOM pdom, String name, Class c) throws CoreException {
|
||||
IBinding[] bindings = findQualifiedName(pdom, name);
|
||||
assertEquals(1, bindings.length);
|
||||
assertTrue(c.isAssignableFrom(bindings[0].getClass()));
|
||||
}
|
||||
|
||||
protected void assertVisibility(PDOM pdom, String name, int visibility) throws CoreException {
|
||||
IBinding[] bindings = findQualifiedName(pdom, name);
|
||||
assertEquals(1, bindings.length);
|
||||
ICPPMember member = (ICPPMember) bindings[0];
|
||||
assertEquals(visibility, member.getVisibility());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,12 +22,19 @@ public class PDOMTests extends TestSuite {
|
|||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
|
||||
suite.addTestSuite(EnumerationTests.class);
|
||||
suite.addTestSuite(ClassTests.class);
|
||||
suite.addTestSuite(TypesTests.class);
|
||||
suite.addTestSuite(IncludesTests.class);
|
||||
suite.addTestSuite(BTreeTests.class);
|
||||
|
||||
suite.addTest(EnumerationTests.suite());
|
||||
suite.addTest(ClassTests.suite());
|
||||
suite.addTest(TypesTests.suite());
|
||||
suite.addTest(IncludesTests.suite());
|
||||
suite.addTest(BTreeTests.suite());
|
||||
|
||||
suite.addTest(CPPFieldTests.suite());
|
||||
suite.addTest(CPPFunctionTests.suite());
|
||||
suite.addTest(CPPVariableTests.suite());
|
||||
suite.addTest(MethodTests.suite());
|
||||
|
||||
suite.addTest(CFunctionTests.suite());
|
||||
suite.addTest(CVariableTests.suite());
|
||||
return suite;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ package org.eclipse.cdt.internal.pdom.tests;
|
|||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
|
@ -36,6 +38,10 @@ public class TypesTests extends PDOMTestBase {
|
|||
|
||||
protected PDOM pdom;
|
||||
|
||||
public static Test suite() {
|
||||
return suite(TypesTests.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
if (pdom == null) {
|
||||
ICProject project = createProject("types");
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
struct SimpleStructure {
|
||||
char ssa;
|
||||
};
|
||||
|
||||
struct Structure1 {
|
||||
int s1a;
|
||||
double s1b;
|
||||
struct Structure2 {
|
||||
float s2a;
|
||||
struct Structure3 {
|
||||
char s3a;
|
||||
} s2b;
|
||||
} s1c;
|
||||
};
|
||||
|
||||
union Union1 {
|
||||
int u1a;
|
||||
double u1b;
|
||||
char u1c;
|
||||
union Union2 {
|
||||
int u2a;
|
||||
} u1d;
|
||||
};
|
||||
|
||||
struct MixedS1 {
|
||||
union MixedU1 {
|
||||
struct MixedS2 {
|
||||
double ms2a;
|
||||
} mu1a;
|
||||
union MixedU2 {
|
||||
int mu2a;
|
||||
} mu1b;
|
||||
float mu1c;
|
||||
} ms1a;
|
||||
struct MixedS3 {
|
||||
char ms3a;
|
||||
} ms1b;
|
||||
}
|
||||
|
||||
int main() {
|
||||
struct SimpleStructure ss;
|
||||
struct SimpleStructure *pss;
|
||||
|
||||
ss.ssa = 0;
|
||||
pss->ssa = 1;
|
||||
|
||||
struct Structure1 s1;
|
||||
struct Structure1 *ps1 = &s1;
|
||||
|
||||
s1.s1a = 0;
|
||||
ps1->s1a = 1;
|
||||
|
||||
s1.s1b = 2;
|
||||
s1.s1b = 3;
|
||||
ps1->s1b = 4;
|
||||
|
||||
struct Structure1::Structure2 s2;
|
||||
struct Structure1::Structure2 *ps2 = &s2;
|
||||
|
||||
s1.s1c = s2;
|
||||
s1.s1c = s2;
|
||||
s1.s1c = s2;
|
||||
ps1->s1c = s2;
|
||||
|
||||
struct Structure1::Structure2::Structure3 s3;
|
||||
struct Structure1::Structure2::Structure3 *ps3 = &s3;
|
||||
|
||||
s1.s1c.s2b = 9;
|
||||
s1.s1c.s2b = 10;
|
||||
s1.s1c.s2b = 11;
|
||||
ps1->s1c.s2b = 12;
|
||||
ps2->s2b = 13;
|
||||
|
||||
s1.s1c.s2b.s3a = 13;
|
||||
s1.s1c.s2b.s3a = 14;
|
||||
s1.s1c.s2b.s3a = 15;
|
||||
s1.s1c.s2b.s3a = 16;
|
||||
s1.s1c.s2b.s3a = 17;
|
||||
ps1->s1c.s2b.s3a = 18;
|
||||
ps2->s2b.s3a = 19;
|
||||
ps3->s3a = 19;
|
||||
|
||||
Union1 u1;
|
||||
Union1 *pu1 = &u1;
|
||||
|
||||
u1.u1a = 0;
|
||||
pu1->u1a = 1;
|
||||
|
||||
Union1::Union2 u2;
|
||||
Union1::Union2 *pu2 = &u1.u1d;
|
||||
|
||||
u2.u2a = 2;
|
||||
pu2->u2a = 3;
|
||||
|
||||
MixedS1::MixedU1 mu1;
|
||||
MixedS1::MixedU1 *pmu1 = &mu1;
|
||||
|
||||
mu1.mu1a;
|
||||
pmu1->mu1a;
|
||||
|
||||
MixedS1::MixedU1::MixedU2 mu2;
|
||||
MixedS1::MixedU1::MixedU2 *pmu2 = &mu2;
|
||||
|
||||
mu2.mu2a;
|
||||
pmu2->mu2a;
|
||||
|
||||
MixedS1::MixedU1::MixedS2 ms2;
|
||||
MixedS1::MixedU1::MixedS2 *pms2 = &ms2;
|
||||
|
||||
ms2.ms2a;
|
||||
pms2->ms2a;
|
||||
|
||||
MixedS1::MixedS3 ms3;
|
||||
MixedS1::MixedS3 *pms3 = &ms3;
|
||||
|
||||
ms3.ms3a;
|
||||
pms3->ms3a;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
class Class1 {
|
||||
int defaultField = 0;
|
||||
|
||||
mutable int mutableField;
|
||||
static int staticField;
|
||||
|
||||
private:
|
||||
double privateField = 4.5;
|
||||
protected:
|
||||
char protectedField = 'A';
|
||||
public:
|
||||
long publicField = 20;
|
||||
|
||||
int c1a;
|
||||
double c1b;
|
||||
|
||||
Class1();
|
||||
~Class1();
|
||||
};
|
||||
|
||||
class Class2 : public Class1 {
|
||||
public:
|
||||
char c2a;
|
||||
float c2b;
|
||||
|
||||
Class2();
|
||||
~Class2();
|
||||
};
|
||||
|
||||
Class1::Class1() {
|
||||
}
|
||||
|
||||
Class1::~Class1() {
|
||||
}
|
||||
|
||||
Class2::Class2() {
|
||||
}
|
||||
|
||||
Class2::~Class2() {
|
||||
}
|
||||
|
||||
int main() {
|
||||
Class1 c1;
|
||||
Class1 *pc1 = &c1;
|
||||
|
||||
Class2 c2;
|
||||
Class2 *pc2 = &c2;
|
||||
|
||||
c1.c1a = 0;
|
||||
pc1->c1a = 1;
|
||||
|
||||
c2.c1a = 2;
|
||||
pc2->c1a = 3;
|
||||
|
||||
c2.c2a = 4;
|
||||
c2.c2a = 5;
|
||||
pc2->c2a = 6;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
void forwardDeclaration();
|
||||
|
||||
void normalDeclaration1() {
|
||||
forwardDeclaration();
|
||||
}
|
||||
|
||||
void normalDeclaration2() {
|
||||
normalDeclaration1();
|
||||
}
|
||||
|
||||
void forwardDeclaration() {
|
||||
normalDeclaration2();
|
||||
}
|
||||
|
||||
void spin() {
|
||||
normalDeclaration1();
|
||||
normalDeclaration2();
|
||||
normalDeclaration2();
|
||||
forwardDeclaration();
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
double normalCFunction(int p1, char p2, float p3);
|
||||
static int staticCFunction(double p1);
|
||||
extern float externCFunction(int p1);
|
||||
inline void inlineCFunction(long p1);
|
||||
void varArgsCFunction(int p1, ...);
|
||||
const void constCFunction();
|
||||
volatile void volatileCFunction();
|
||||
|
||||
void voidCFunction();
|
||||
int intCFunction();
|
||||
double doubleCFunction();
|
||||
char charCFunction();
|
||||
float floatCFunction();
|
|
@ -0,0 +1,11 @@
|
|||
double normalCPPFunction(int p1, char p2, float p3);
|
||||
static int staticCPPFunction(double p1);
|
||||
extern float externCPPFunction(int p1);
|
||||
inline void inlineCPPFunction(long p1);
|
||||
void varArgsCPPFunction(int p1, ...);
|
||||
|
||||
void voidCPPFunction();
|
||||
int intCPPFunction();
|
||||
double doubleCPPFunction();
|
||||
char charCPPFunction();
|
||||
float floatCPPFunction();
|
|
@ -0,0 +1,13 @@
|
|||
void overloadedFunction() {
|
||||
}
|
||||
|
||||
void overloadedFunction(int p1) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
overloadedFunction();
|
||||
overloadedFunction(1);
|
||||
overloadedFunction(1);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
class Class1 {
|
||||
public:
|
||||
double normalMethod(int p1, char p2, float p3);
|
||||
virtual void inheritedMethod();
|
||||
virtual void pureVirtualMethod() = 0;
|
||||
virtual void overriddenMethod();
|
||||
|
||||
inline int inlineMethod();
|
||||
static int staticMethod();
|
||||
int varArgsMethod(...);
|
||||
int constMethod() const;
|
||||
int volatileMethod() volatile;
|
||||
int constVolatileMethod() const volatile;
|
||||
|
||||
// Here, const/volatile applies to the return value, not the method
|
||||
const int *notConstMethod();
|
||||
volatile int *notVolatileMethod();
|
||||
const volatile int *notConstVolatileMethod();
|
||||
|
||||
Class1();
|
||||
virtual ~Class1() = 0;
|
||||
};
|
||||
|
||||
class Class2 : public Class1 {
|
||||
public:
|
||||
void pureVirtualMethod();
|
||||
void overriddenMethod();
|
||||
void overloadedMethod();
|
||||
void overloadedMethod(int p1);
|
||||
|
||||
Class2();
|
||||
~Class2();
|
||||
};
|
||||
|
||||
double Class1::normalMethod(int p1, char p2, float p3) {
|
||||
}
|
||||
|
||||
void Class1::inheritedMethod() {
|
||||
}
|
||||
|
||||
void Class1::overriddenMethod() {
|
||||
}
|
||||
|
||||
void Class2::pureVirtualMethod() {
|
||||
}
|
||||
|
||||
void Class2::overriddenMethod() {
|
||||
}
|
||||
|
||||
void Class2::overloadedMethod() {
|
||||
}
|
||||
|
||||
void Class2::overloadedMethod(int p1) {
|
||||
}
|
||||
|
||||
Class1::Class1() {
|
||||
}
|
||||
|
||||
Class1::~Class1() {
|
||||
}
|
||||
|
||||
Class2::Class2() {
|
||||
}
|
||||
|
||||
Class2::~Class2() {
|
||||
}
|
||||
|
||||
class Class3 {
|
||||
int defaultMethod();
|
||||
private:
|
||||
void privateMethod();
|
||||
protected:
|
||||
char protectedMethod();
|
||||
public:
|
||||
double publicMethod();
|
||||
};
|
||||
|
||||
int main() {
|
||||
Class2 c2;
|
||||
|
||||
Class1 *pc1 = &c2;
|
||||
Class2 *pc2 = &c2;
|
||||
|
||||
pc1->inheritedMethod();
|
||||
|
||||
pc1->pureVirtualMethod();
|
||||
pc1->pureVirtualMethod();
|
||||
|
||||
pc1->overriddenMethod();
|
||||
pc1->overriddenMethod();
|
||||
pc1->overriddenMethod();
|
||||
|
||||
c2.inheritedMethod();
|
||||
pc2->inheritedMethod();
|
||||
|
||||
c2.pureVirtualMethod();
|
||||
c2.pureVirtualMethod();
|
||||
pc2->pureVirtualMethod();
|
||||
|
||||
c2.overriddenMethod();
|
||||
c2.overriddenMethod();
|
||||
c2.overriddenMethod();
|
||||
pc2->overriddenMethod();
|
||||
|
||||
c2.overloadedMethod();
|
||||
pc2->overloadedMethod();
|
||||
|
||||
c2.overloadedMethod(1);
|
||||
c2.overloadedMethod(1);
|
||||
pc2->overloadedMethod(1);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
auto int autoCVariable;
|
||||
extern int externCVariable;
|
||||
register int registerCVariable;
|
||||
static int staticCVariable;
|
|
@ -0,0 +1,4 @@
|
|||
auto int autoCPPVariable;
|
||||
extern int externCPPVariable;
|
||||
register int registerCPPVariable;
|
||||
static int staticCPPVariable;
|
|
@ -66,7 +66,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
|||
|
||||
private Database db;
|
||||
|
||||
public static final int VERSION = 12;
|
||||
public static final int VERSION = 13;
|
||||
// 0 - the beginning of it all
|
||||
// 1 - first change to kick off upgrades
|
||||
// 2 - added file inclusions
|
||||
|
@ -80,6 +80,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
|||
// 10 - typedefs, types on C++ variables
|
||||
// 11 - changed how members work
|
||||
// 12 - one more change for members (is-a list -> has-a list)
|
||||
// 13 - CV-qualifiers, storage class specifiers, function/method annotations
|
||||
|
||||
public static final int LINKAGES = Database.DATA_AREA;
|
||||
public static final int FILE_INDEX = Database.DATA_AREA + 4;
|
||||
|
|
|
@ -7,10 +7,12 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
* IBM Corporation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
|
||||
|
@ -23,9 +25,14 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*
|
||||
*/
|
||||
public abstract class PDOMNamedNode extends PDOMNode {
|
||||
|
||||
/**
|
||||
* Offset of pointer to node name (relative to the beginning of the record).
|
||||
*/
|
||||
private static final int NAME = PDOMNode.RECORD_SIZE + 0;
|
||||
|
||||
/**
|
||||
* The size in bytes of a PDOMNamedNode record in the database.
|
||||
*/
|
||||
protected static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 4;
|
||||
|
||||
public PDOMNamedNode(PDOM pdom, int record) {
|
||||
|
@ -72,6 +79,32 @@ public abstract class PDOMNamedNode extends PDOMNode {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for fetching a byte from the database.
|
||||
* @param offset Location of the byte.
|
||||
* @return a byte from the database.
|
||||
*/
|
||||
protected byte getByte(int offset) {
|
||||
try {
|
||||
return pdom.getDB().getByte(offset);
|
||||
}
|
||||
catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bit at the specified offset in a bit vector.
|
||||
* @param bitVector Bits.
|
||||
* @param offset The position of the desired bit.
|
||||
* @return the bit at the specified offset.
|
||||
*/
|
||||
protected boolean getBit(int bitVector, int offset) {
|
||||
int mask = 1 << offset;
|
||||
return (bitVector & mask) == mask;
|
||||
}
|
||||
|
||||
public abstract static class NodeFinder implements IBTreeVisitor {
|
||||
protected final PDOM pdom;
|
||||
protected final char[] name;
|
||||
|
|
|
@ -15,7 +15,6 @@ package org.eclipse.cdt.internal.core.pdom.dom;
|
|||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.IPDOMNode;
|
||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
import org.eclipse.cdt.core.index.IIndexLinkage;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
|
||||
/**
|
||||
* A utility class for packing various annotations into bit fields. This
|
||||
* includes storage class specifiers (auto, register, etc.), and CV qualifiers
|
||||
* (const, volatile).
|
||||
*/
|
||||
public class PDOMCAnnotation {
|
||||
|
||||
// Storage class specifiers and function annotations
|
||||
public static final int AUTO_OFFSET = 0;
|
||||
public static final int EXTERN_OFFSET = 1;
|
||||
public static final int INLINE_OFFSET = 2;
|
||||
public static final int REGISTER_OFFSET = 3;
|
||||
public static final int STATIC_OFFSET = 4;
|
||||
public static final int VARARGS_OFFSET = 5;
|
||||
|
||||
// CV qualifiers
|
||||
public static final int CONST_OFFSET = 0;
|
||||
public static final int VOLATILE_OFFSET = 1;
|
||||
|
||||
/**
|
||||
* Encodes storage class specifiers and other annotation from an IBinding
|
||||
* as a bit vector.
|
||||
*
|
||||
* @param binding the IBinding whose annotation will be encoded.
|
||||
* @return a bit vector of the annotation.
|
||||
* @throws DOMException
|
||||
*/
|
||||
public static byte encodeAnnotation(IBinding binding) throws DOMException {
|
||||
byte modifiers = 0;
|
||||
if (binding instanceof IVariable) {
|
||||
IVariable variable = (IVariable) binding;
|
||||
modifiers |= (variable.isAuto() ? 1 : 0) << PDOMCAnnotation.AUTO_OFFSET;
|
||||
modifiers |= (variable.isExtern() ? 1 : 0) << PDOMCAnnotation.EXTERN_OFFSET;
|
||||
modifiers |= (variable.isRegister() ? 1 : 0) << PDOMCAnnotation.REGISTER_OFFSET;
|
||||
modifiers |= (variable.isStatic() ? 1 : 0) << PDOMCAnnotation.STATIC_OFFSET;
|
||||
}
|
||||
if (binding instanceof IFunction) {
|
||||
IFunction function = (IFunction) binding;
|
||||
modifiers |= (function.isAuto() ? 1 : 0) << PDOMCAnnotation.AUTO_OFFSET;
|
||||
modifiers |= (function.isExtern() ? 1 : 0) << PDOMCAnnotation.EXTERN_OFFSET;
|
||||
modifiers |= (function.isRegister() ? 1 : 0) << PDOMCAnnotation.REGISTER_OFFSET;
|
||||
modifiers |= (function.isStatic() ? 1 : 0) << PDOMCAnnotation.STATIC_OFFSET;
|
||||
modifiers |= (function.isInline() ? 1 : 0) << PDOMCAnnotation.INLINE_OFFSET;
|
||||
modifiers |= (function.takesVarArgs() ? 1 : 0) << PDOMCAnnotation.VARARGS_OFFSET;
|
||||
}
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes CV qualifiers from a method declarator as a bit vector.
|
||||
* @param declarator Method declarator.
|
||||
* @return a bit vector of the CV qualifiers.
|
||||
*/
|
||||
public static byte encodeCVQualifiers(ICPPASTFunctionDeclarator declarator) {
|
||||
byte modifiers = 0;
|
||||
modifiers |= (declarator.isConst() ? 1 : 0) << CONST_OFFSET;
|
||||
modifiers |= (declarator.isVolatile() ? 1 : 0) << VOLATILE_OFFSET;
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
* IBM Corporation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.c;
|
||||
|
@ -19,7 +20,6 @@ import org.eclipse.cdt.internal.core.pdom.PDOM;
|
|||
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
|
@ -51,19 +51,23 @@ class PDOMCField extends PDOMBinding implements IField {
|
|||
}
|
||||
|
||||
public boolean isStatic() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 9899:TC1 6.7.2.1
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isExtern() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 9899:TC1 6.7.2.1
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAuto() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 9899:TC1 6.7.2.1
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isRegister() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 9899:TC1 6.7.2.1
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
* IBM Corporation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.c;
|
||||
|
@ -28,9 +29,20 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*
|
||||
*/
|
||||
class PDOMCFunction extends PDOMBinding implements IFunction {
|
||||
/**
|
||||
* Offset of annotation information (relative to the beginning of the
|
||||
* record).
|
||||
*/
|
||||
private static final int ANNOTATIONS = PDOMBinding.RECORD_SIZE + 0; // byte
|
||||
|
||||
/**
|
||||
* The size in bytes of a PDOMCFunction record in the database.
|
||||
*/
|
||||
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 1;
|
||||
|
||||
public PDOMCFunction(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name);
|
||||
pdom.getDB().putByte(record + ANNOTATIONS, PDOMCAnnotation.encodeAnnotation(name.resolveBinding()));
|
||||
}
|
||||
|
||||
public PDOMCFunction(PDOM pdom, int record) {
|
||||
|
@ -58,27 +70,29 @@ class PDOMCFunction extends PDOMBinding implements IFunction {
|
|||
}
|
||||
|
||||
public boolean isStatic() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.STATIC_OFFSET);
|
||||
}
|
||||
|
||||
public boolean isExtern() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.EXTERN_OFFSET);
|
||||
}
|
||||
|
||||
public boolean isAuto() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 9899:TC1 6.9.1.4
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isRegister() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 9899:TC1 6.9.1.4
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInline() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.INLINE_OFFSET);
|
||||
}
|
||||
|
||||
public boolean takesVarArgs() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.VARARGS_OFFSET);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
* IBM Corporation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.c;
|
||||
|
@ -18,7 +19,6 @@ import org.eclipse.cdt.core.dom.ast.IVariable;
|
|||
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.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
|
@ -27,12 +27,24 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*/
|
||||
class PDOMCVariable extends PDOMBinding implements IVariable {
|
||||
|
||||
/**
|
||||
* Offset of annotation information (relative to the beginning of the
|
||||
* record).
|
||||
*/
|
||||
private static final int ANNOTATIONS = PDOMBinding.RECORD_SIZE + 0;
|
||||
|
||||
/**
|
||||
* The size in bytes of a PDOMCVariable record in the database.
|
||||
*/
|
||||
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 1;
|
||||
|
||||
public PDOMCVariable(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name);
|
||||
IVariable binding = (IVariable)name.getBinding();
|
||||
if (binding != null) {
|
||||
IType type = binding.getType();
|
||||
}
|
||||
pdom.getDB().putByte(record + ANNOTATIONS, PDOMCAnnotation.encodeAnnotation(binding));
|
||||
}
|
||||
|
||||
public PDOMCVariable(PDOM pdom, int record) {
|
||||
|
@ -54,19 +66,19 @@ class PDOMCVariable extends PDOMBinding implements IVariable {
|
|||
}
|
||||
|
||||
public boolean isStatic() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.STATIC_OFFSET);
|
||||
}
|
||||
|
||||
public boolean isExtern() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.EXTERN_OFFSET);
|
||||
}
|
||||
|
||||
public boolean isAuto() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.AUTO_OFFSET);
|
||||
}
|
||||
|
||||
public boolean isRegister() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.REGISTER_OFFSET);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
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.internal.core.pdom.dom.c.PDOMCAnnotation;
|
||||
|
||||
public class PDOMCPPAnnotation {
|
||||
|
||||
// "Mutable" shares the same offset as "inline" because
|
||||
// only fields can be mutable and only functions can be inline.
|
||||
public static final int MUTABLE_OFFSET = 2;
|
||||
|
||||
public static final int VISIBILITY_OFFSET = 6;
|
||||
private static final int VISIBILITY_MASK = 0x03;
|
||||
|
||||
// Extra C++-specific annotations that don't fit on the first
|
||||
// byte of annotations.
|
||||
public static final int VIRTUAL_OFFSET = 0;
|
||||
public static final int DESTRUCTOR_OFFSET = 1;
|
||||
|
||||
/**
|
||||
* Encodes storage class specifiers and other annotation, including
|
||||
* C++-specific annotation, from an IBinding as a bit vector.
|
||||
*
|
||||
* @param binding the IBinding whose annotation will be encoded.
|
||||
* @return a bit vector of the annotation.
|
||||
* @throws DOMException
|
||||
*/
|
||||
public static byte encodeAnnotation(IBinding binding) throws DOMException {
|
||||
byte modifiers = PDOMCAnnotation.encodeAnnotation(binding);
|
||||
if (binding instanceof ICPPField) {
|
||||
ICPPField variable = (ICPPField) binding;
|
||||
modifiers |= (variable.isMutable() ? 1 : 0) << MUTABLE_OFFSET;
|
||||
}
|
||||
if (binding instanceof ICPPMember) {
|
||||
ICPPMember member = (ICPPMember) binding;
|
||||
int mask = ~(VISIBILITY_MASK << VISIBILITY_OFFSET);
|
||||
modifiers &= mask;
|
||||
modifiers |= (member.getVisibility() & VISIBILITY_MASK) << VISIBILITY_OFFSET;
|
||||
}
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes C++-specific annotation not already handled by
|
||||
* encodeAnnotation() as a bit vector.
|
||||
*
|
||||
* @param binding the IBinding whose annotation will be encoded.
|
||||
* @return a bit vector of the annotation.
|
||||
* @throws DOMException
|
||||
*/
|
||||
public static byte encodeExtraAnnotation(IBinding binding) throws DOMException {
|
||||
byte modifiers = 0;
|
||||
if (binding instanceof ICPPMethod) {
|
||||
ICPPMethod method = (ICPPMethod) binding;
|
||||
modifiers |= (method.isVirtual() ? 1 : 0) << VIRTUAL_OFFSET;
|
||||
modifiers |= (method.isDestructor() ? 1 : 0) << DESTRUCTOR_OFFSET;
|
||||
}
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpacks visibility information from a bit vector of annotation.
|
||||
* @param annotation Annotation containing visibility information.
|
||||
* @return The visibility component of the annotation.
|
||||
*/
|
||||
public static int getVisibility(byte annotation) {
|
||||
return (annotation >> VISIBILITY_OFFSET) & VISIBILITY_MASK;
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
* IBM Corporation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
@ -14,12 +15,15 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
|||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
|
@ -28,9 +32,23 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*/
|
||||
class PDOMCPPField extends PDOMCPPBinding implements ICPPField {
|
||||
|
||||
/**
|
||||
* Offset of annotation information (relative to the beginning of the
|
||||
* record).
|
||||
*/
|
||||
private static final int ANNOTATION = PDOMBinding.RECORD_SIZE + 0; // byte
|
||||
|
||||
/**
|
||||
* The size in bytes of a PDOMCPPField record in the database.
|
||||
*/
|
||||
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 1;
|
||||
|
||||
public PDOMCPPField(PDOM pdom, PDOMCPPClassType parent, IASTName name)
|
||||
throws CoreException {
|
||||
super(pdom, parent, name);
|
||||
IBinding binding = name.resolveBinding();
|
||||
Database db = pdom.getDB();
|
||||
db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(binding));
|
||||
}
|
||||
|
||||
public PDOMCPPField(PDOM pdom, int bindingRecord) {
|
||||
|
@ -59,11 +77,11 @@ class PDOMCPPField extends PDOMCPPBinding implements ICPPField {
|
|||
}
|
||||
|
||||
public int getVisibility() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return PDOMCPPAnnotation.getVisibility(getByte(record + ANNOTATION));
|
||||
}
|
||||
|
||||
public boolean isMutable() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATION), PDOMCPPAnnotation.MUTABLE_OFFSET);
|
||||
}
|
||||
|
||||
public IType getType() throws DOMException {
|
||||
|
@ -72,19 +90,22 @@ class PDOMCPPField extends PDOMCPPBinding implements ICPPField {
|
|||
}
|
||||
|
||||
public boolean isAuto() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 14882:2003 9.2.6
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isExtern() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 14882:2003 9.2.6
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isRegister() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 14882:2003 9.2.6
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isStatic() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATION), PDOMCAnnotation.STATIC_OFFSET);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
* IBM Corporation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
@ -27,9 +28,11 @@ 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.ICPPParameter;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
|
@ -38,18 +41,37 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*/
|
||||
class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, ICPPFunctionType {
|
||||
|
||||
public static final int NUM_PARAMS = PDOMBinding.RECORD_SIZE + 0;
|
||||
public static final int FIRST_PARAM = PDOMBinding.RECORD_SIZE + 4;
|
||||
/**
|
||||
* Offset of total number of function parameters (relative to the
|
||||
* beginning of the record).
|
||||
*/
|
||||
private static final int NUM_PARAMS = PDOMBinding.RECORD_SIZE + 0;
|
||||
|
||||
/**
|
||||
* Offset of pointer to the first parameter of this function (relative to
|
||||
* the beginning of the record).
|
||||
*/
|
||||
private static final int FIRST_PARAM = PDOMBinding.RECORD_SIZE + 4;
|
||||
|
||||
/**
|
||||
* Offset of annotation information (relative to the beginning of the
|
||||
* record).
|
||||
*/
|
||||
private static final int ANNOTATION = PDOMBinding.RECORD_SIZE + 8; // byte
|
||||
|
||||
public static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 8;
|
||||
/**
|
||||
* The size in bytes of a PDOMCPPFunction record in the database.
|
||||
*/
|
||||
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 9;
|
||||
|
||||
public PDOMCPPFunction(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name);
|
||||
IASTNode parentNode = name.getParent();
|
||||
Database db = pdom.getDB();
|
||||
if (parentNode instanceof ICPPASTFunctionDeclarator) {
|
||||
ICPPASTFunctionDeclarator funcDecl = (ICPPASTFunctionDeclarator)parentNode;
|
||||
IASTParameterDeclaration[] params = funcDecl.getParameters();
|
||||
pdom.getDB().putInt(record + NUM_PARAMS, params.length);
|
||||
db.putInt(record + NUM_PARAMS, params.length);
|
||||
for (int i = 0; i < params.length; ++i) {
|
||||
ICPPASTParameterDeclaration param = (ICPPASTParameterDeclaration)params[i];
|
||||
IASTName paramName = param.getDeclarator().getName();
|
||||
|
@ -60,6 +82,8 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, ICPPFuncti
|
|||
setFirstParameter(new PDOMCPPParameter(pdom, this, paramName, paramBinding));
|
||||
}
|
||||
}
|
||||
IBinding binding = name.resolveBinding();
|
||||
db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(binding));
|
||||
}
|
||||
|
||||
public PDOMCPPFunction(PDOM pdom, int bindingRecord) {
|
||||
|
@ -87,7 +111,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, ICPPFuncti
|
|||
}
|
||||
|
||||
public boolean isInline() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATION), PDOMCAnnotation.INLINE_OFFSET);
|
||||
}
|
||||
|
||||
public boolean isMutable() throws DOMException {
|
||||
|
@ -119,24 +143,25 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, ICPPFuncti
|
|||
}
|
||||
|
||||
public boolean isAuto() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 14882:2003 7.1.1.2
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isExtern() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATION), PDOMCAnnotation.EXTERN_OFFSET);
|
||||
}
|
||||
|
||||
public boolean isRegister() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 14882:2003 7.1.1.2
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isStatic() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATION), PDOMCAnnotation.STATIC_OFFSET);
|
||||
}
|
||||
|
||||
public boolean takesVarArgs() throws DOMException {
|
||||
// TODO
|
||||
return false;
|
||||
return getBit(getByte(record + ANNOTATION), PDOMCAnnotation.VARARGS_OFFSET);
|
||||
}
|
||||
|
||||
public IType[] getParameterTypes() throws DOMException {
|
||||
|
@ -161,11 +186,15 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, ICPPFuncti
|
|||
}
|
||||
|
||||
public boolean isConst() {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 14882:2003 9.3.1.3
|
||||
// Only applicable to member functions
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isVolatile() {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 14882:2003 9.3.1.3
|
||||
// Only applicable to member functions
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSameType(IType type) {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
* IBM Corporation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
@ -28,9 +29,11 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
|
@ -39,18 +42,49 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*/
|
||||
class PDOMCPPMethod extends PDOMCPPBinding implements ICPPMethod, ICPPFunctionType {
|
||||
|
||||
public static final int NUM_PARAMS = PDOMBinding.RECORD_SIZE + 0;
|
||||
public static final int FIRST_PARAM = PDOMBinding.RECORD_SIZE + 4;
|
||||
/**
|
||||
* Offset of total number of method parameters (relative to the
|
||||
* beginning of the record).
|
||||
*/
|
||||
private static final int NUM_PARAMS = PDOMBinding.RECORD_SIZE + 0;
|
||||
|
||||
public static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 8;
|
||||
/**
|
||||
* Offset of pointer to the first parameter of this method (relative to
|
||||
* the beginning of the record).
|
||||
*/
|
||||
private static final int FIRST_PARAM = PDOMBinding.RECORD_SIZE + 4;
|
||||
|
||||
/**
|
||||
* Offset of first byte of annotation information (relative to the
|
||||
* beginning of the record).
|
||||
*/
|
||||
private static final int ANNOTATION0 = PDOMBinding.RECORD_SIZE + 8; // byte
|
||||
|
||||
/**
|
||||
* Offset of remaining annotation information (relative to the
|
||||
* beginning of the record).
|
||||
*/
|
||||
private static final int ANNOTATION1 = PDOMBinding.RECORD_SIZE + 9; // byte
|
||||
|
||||
/**
|
||||
* The size in bytes of a PDOMCPPMethod record in the database.
|
||||
*/
|
||||
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 10;
|
||||
|
||||
/**
|
||||
* The bit offset of CV qualifier flags within ANNOTATION1.
|
||||
*/
|
||||
private static final int CV_OFFSET = 2;
|
||||
|
||||
public PDOMCPPMethod(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name);
|
||||
IASTNode parentNode = name.getParent();
|
||||
byte annotation = 0;
|
||||
Database db = pdom.getDB();
|
||||
if (parentNode instanceof ICPPASTFunctionDeclarator) {
|
||||
ICPPASTFunctionDeclarator funcDecl = (ICPPASTFunctionDeclarator)parentNode;
|
||||
IASTParameterDeclaration[] params = funcDecl.getParameters();
|
||||
pdom.getDB().putInt(record + NUM_PARAMS, params.length);
|
||||
db.putInt(record + NUM_PARAMS, params.length);
|
||||
for (int i = 0; i < params.length; ++i) {
|
||||
ICPPASTParameterDeclaration param = (ICPPASTParameterDeclaration)params[i];
|
||||
IASTName paramName = param.getDeclarator().getName();
|
||||
|
@ -58,7 +92,12 @@ class PDOMCPPMethod extends PDOMCPPBinding implements ICPPMethod, ICPPFunctionTy
|
|||
ICPPParameter paramBinding = (ICPPParameter)binding;
|
||||
setFirstParameter(new PDOMCPPParameter(pdom, this, paramName, paramBinding));
|
||||
}
|
||||
annotation |= PDOMCAnnotation.encodeCVQualifiers(funcDecl) << CV_OFFSET;
|
||||
}
|
||||
IBinding binding = name.resolveBinding();
|
||||
annotation |= PDOMCPPAnnotation.encodeExtraAnnotation(binding);
|
||||
db.putByte(record + ANNOTATION0, PDOMCPPAnnotation.encodeAnnotation(binding));
|
||||
db.putByte(record + ANNOTATION1, annotation);
|
||||
}
|
||||
|
||||
public PDOMCPPMethod(PDOM pdom, int record) {
|
||||
|
@ -86,11 +125,11 @@ class PDOMCPPMethod extends PDOMCPPBinding implements ICPPMethod, ICPPFunctionTy
|
|||
}
|
||||
|
||||
public boolean isVirtual() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.VIRTUAL_OFFSET);
|
||||
}
|
||||
|
||||
public boolean isDestructor() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.DESTRUCTOR_OFFSET);
|
||||
}
|
||||
|
||||
public boolean isMutable() throws DOMException {
|
||||
|
@ -98,7 +137,7 @@ class PDOMCPPMethod extends PDOMCPPBinding implements ICPPMethod, ICPPFunctionTy
|
|||
}
|
||||
|
||||
public boolean isInline() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATION0), PDOMCAnnotation.INLINE_OFFSET);
|
||||
}
|
||||
|
||||
public IParameter[] getParameters() throws DOMException {
|
||||
|
@ -126,29 +165,30 @@ class PDOMCPPMethod extends PDOMCPPBinding implements ICPPMethod, ICPPFunctionTy
|
|||
}
|
||||
|
||||
public boolean isStatic() throws DOMException {
|
||||
// TODO
|
||||
return false;
|
||||
return getBit(getByte(record + ANNOTATION0), PDOMCAnnotation.STATIC_OFFSET);
|
||||
}
|
||||
|
||||
public boolean isExtern() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 14882:2003 9.2.6
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAuto() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 14882:2003 9.2.6
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isRegister() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 14882:2003 9.2.6
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean takesVarArgs() throws DOMException {
|
||||
// TODO
|
||||
return false;
|
||||
return getBit(getByte(record + ANNOTATION0), PDOMCAnnotation.VARARGS_OFFSET);
|
||||
}
|
||||
|
||||
public int getVisibility() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return PDOMCPPAnnotation.getVisibility(getByte(record + ANNOTATION0));
|
||||
}
|
||||
|
||||
public ICPPClassType getClassOwner() throws DOMException {
|
||||
|
@ -175,13 +215,11 @@ class PDOMCPPMethod extends PDOMCPPBinding implements ICPPMethod, ICPPFunctionTy
|
|||
}
|
||||
|
||||
public boolean isConst() {
|
||||
return false;
|
||||
// TODO throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATION1), PDOMCAnnotation.CONST_OFFSET + CV_OFFSET);
|
||||
}
|
||||
|
||||
public boolean isVolatile() {
|
||||
return false;
|
||||
// TODO throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATION1), PDOMCAnnotation.VOLATILE_OFFSET + CV_OFFSET);
|
||||
}
|
||||
|
||||
public boolean isSameType(IType type) {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM Corporation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
@ -33,10 +34,22 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*/
|
||||
class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter {
|
||||
|
||||
/**
|
||||
* Offset of pointer to the next parameter (relative to the
|
||||
* beginning of the record).
|
||||
*/
|
||||
private static final int NEXT_PARAM = PDOMNamedNode.RECORD_SIZE + 0;
|
||||
|
||||
/**
|
||||
* Offset of pointer to type information for this parameter
|
||||
* (relative to the beginning of the record).
|
||||
*/
|
||||
private static final int TYPE = PDOMNamedNode.RECORD_SIZE + 4;
|
||||
|
||||
public static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 8;
|
||||
/**
|
||||
* The size in bytes of a PDOMCPPParameter record in the database.
|
||||
*/
|
||||
protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 8;
|
||||
|
||||
public PDOMCPPParameter(PDOM pdom, int record) {
|
||||
super(pdom, record);
|
||||
|
@ -93,7 +106,8 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter {
|
|||
}
|
||||
|
||||
public boolean isMutable() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 14882:2003 7.1.1.8
|
||||
return false;
|
||||
}
|
||||
|
||||
public IType getType() throws DOMException {
|
||||
|
@ -111,7 +125,8 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter {
|
|||
}
|
||||
|
||||
public boolean isExtern() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 14882:2003 7.1.1.5
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isRegister() throws DOMException {
|
||||
|
@ -119,7 +134,8 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter {
|
|||
}
|
||||
|
||||
public boolean isStatic() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 14882:2003 7.1.1.4
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM Corporation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
@ -21,9 +22,10 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
|
@ -32,22 +34,37 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*/
|
||||
class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable {
|
||||
|
||||
/**
|
||||
* Offset of pointer to type information for this parameter
|
||||
* (relative to the beginning of the record).
|
||||
*/
|
||||
private static final int TYPE_OFFSET = PDOMBinding.RECORD_SIZE + 0;
|
||||
|
||||
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 4;
|
||||
/**
|
||||
* Offset of annotation information (relative to the beginning of the
|
||||
* record).
|
||||
*/
|
||||
private static final int ANNOTATIONS = PDOMBinding.RECORD_SIZE + 1;
|
||||
|
||||
/**
|
||||
* The size in bytes of a PDOMCPPVariable record in the database.
|
||||
*/
|
||||
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 5;
|
||||
|
||||
public PDOMCPPVariable(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name);
|
||||
|
||||
// Find the type record
|
||||
IASTNode nameParent = name.getParent();
|
||||
Database db = pdom.getDB();
|
||||
if (nameParent instanceof IASTDeclarator) {
|
||||
IASTDeclarator declarator = (IASTDeclarator)nameParent;
|
||||
IType type = CPPVisitor.createType(declarator);
|
||||
PDOMNode typeNode = parent.getLinkageImpl().addType(this, type);
|
||||
if (typeNode != null)
|
||||
pdom.getDB().putInt(record + TYPE_OFFSET, typeNode.getRecord());
|
||||
db.putInt(record + TYPE_OFFSET, typeNode.getRecord());
|
||||
}
|
||||
db.putByte(record + ANNOTATIONS, PDOMCPPAnnotation.encodeAnnotation(name.resolveBinding()));
|
||||
}
|
||||
|
||||
public PDOMCPPVariable(PDOM pdom, int record) {
|
||||
|
@ -63,7 +80,8 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable {
|
|||
}
|
||||
|
||||
public boolean isMutable() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
// ISO/IEC 14882:2003 7.1.1.8
|
||||
return false;
|
||||
}
|
||||
|
||||
public IType getType() throws DOMException {
|
||||
|
@ -77,18 +95,18 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable {
|
|||
}
|
||||
|
||||
public boolean isAuto() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.AUTO_OFFSET);
|
||||
}
|
||||
|
||||
public boolean isExtern() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.EXTERN_OFFSET);
|
||||
}
|
||||
|
||||
public boolean isRegister() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.REGISTER_OFFSET);
|
||||
}
|
||||
|
||||
public boolean isStatic() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.STATIC_OFFSET);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue