diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java new file mode 100644 index 00000000000..cd0601b4d7c --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2006 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.pdom.tests; + +import java.util.regex.Pattern; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.IASTFileLocation; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IEnumeration; +import org.eclipse.cdt.core.dom.ast.IEnumerator; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.internal.core.pdom.PDOM; + +/** + * @author Doug Schaefer + * + */ +public class EnumerationTests extends PDOMTestBase { + + protected ICProject project; + + protected void setUp() throws Exception { + project = createProject("enumerationTests"); + } + + public void testC() throws Exception { + // Check bindings + PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project); + Pattern pattern = Pattern.compile("TestCEnum"); + IBinding[] bindings = pdom.findBindings(pattern); + assertEquals(1, bindings.length); + IEnumeration enumeration = (IEnumeration)bindings[0]; + assertEquals("TestCEnum", enumeration.getName()); + IEnumerator[] enumerators = enumeration.getEnumerators(); + assertEquals(3, enumerators.length); + assertEquals("ca", enumerators[0].getName()); + assertEquals("cb", enumerators[1].getName()); + assertEquals("cc", enumerators[2].getName()); + + // Declaration of TestEnum + IASTName[] enumDecls = pdom.getDeclarations(enumeration); + assertEquals(1, enumDecls.length); + IASTFileLocation loc = enumDecls[0].getFileLocation(); + assertEquals(5, loc.getNodeOffset()); + + // Reference to TestEnum + IASTName[] enumRefs = pdom.getReferences(enumeration); + assertEquals(1, enumRefs.length); + loc = enumRefs[0].getFileLocation(); + assertEquals(offset(46, 40), loc.getNodeOffset()); + + // Reference to a + IASTName[] aRefs = pdom.getReferences(enumerators[0]); + assertEquals(1, aRefs.length); + loc = aRefs[0].getFileLocation(); + assertEquals(offset(74, 67), loc.getNodeOffset()); + } + + public void testCPP() throws Exception { + // Check bindings + PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project); + Pattern pattern = Pattern.compile("TestCPPEnum"); + IBinding[] bindings = pdom.findBindings(pattern); + assertEquals(1, bindings.length); + IEnumeration enumeration = (IEnumeration)bindings[0]; + assertEquals("TestCPPEnum", enumeration.getName()); + IEnumerator[] enumerators = enumeration.getEnumerators(); + assertEquals(3, enumerators.length); + assertEquals("cppa", enumerators[0].getName()); + assertEquals("cppb", enumerators[1].getName()); + assertEquals("cppc", enumerators[2].getName()); + + // Declaration of TestEnum + IASTName[] enumDecls = pdom.getDeclarations(enumeration); + assertEquals(1, enumDecls.length); + IASTFileLocation loc = enumDecls[0].getFileLocation(); + assertEquals(5, loc.getNodeOffset()); + + // Reference to TestEnum + IASTName[] enumRefs = pdom.getReferences(enumeration); + assertEquals(1, enumRefs.length); + loc = enumRefs[0].getFileLocation(); + assertEquals(offset(49, 43), loc.getNodeOffset()); + + // Reference to a + IASTName[] aRefs = pdom.getReferences(enumerators[0]); + assertEquals(1, aRefs.length); + loc = aRefs[0].getFileLocation(); + assertEquals(offset(79, 72), loc.getNodeOffset()); + } + +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java new file mode 100644 index 00000000000..643583ba034 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2006 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.pdom.tests; + +import java.io.File; + +import junit.framework.TestCase; + +import org.eclipse.cdt.core.CCProjectNature; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.CProjectNature; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.testplugin.CTestPlugin; +import org.eclipse.cdt.internal.core.pdom.indexer.fast.PDOMFastIndexer; +import org.eclipse.cdt.internal.core.pdom.indexer.fast.PDOMFastReindex; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; +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.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.ui.dialogs.IOverwriteQuery; +import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider; +import org.eclipse.ui.wizards.datatransfer.ImportOperation; + +/** + * @author Doug Schaefer + */ +public class PDOMTestBase extends TestCase { + + static IPath rootPath = new Path("resources/pdomtests"); + + protected ICProject createProject(String folderName) throws CoreException { + + // Create the project + final String projectName = "ProjTest_" + System.currentTimeMillis(); + final File rootDir = CTestPlugin.getDefault().getFileInPlugin(rootPath.append(folderName)); + final IWorkspace workspace = ResourcesPlugin.getWorkspace(); + final ICProject cprojects[] = new ICProject[1]; + workspace.run(new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException { + IProject project = workspace.getRoot().getProject(projectName); + project.create(monitor); + project.open(monitor); + + // Set up as C++ project + IProjectDescription description = project.getDescription(); + String[] prevNatures = description.getNatureIds(); + String[] newNatures = new String[prevNatures.length + 2]; + System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length); + newNatures[prevNatures.length] = CProjectNature.C_NATURE_ID; + newNatures[prevNatures.length + 1] = CCProjectNature.CC_NATURE_ID; + description.setNatureIds(newNatures); + project.setDescription(description, monitor); + + // Import the files at the root + ImportOperation importOp = new ImportOperation(project.getFullPath(), + rootDir, FileSystemStructureProvider.INSTANCE, new IOverwriteQuery() { + public String queryOverwrite(String pathString) { + return IOverwriteQuery.ALL; + } + }); + try { + importOp.run(monitor); + } catch (Exception e) { + throw new CoreException(new Status(IStatus.ERROR, + CTestPlugin.PLUGIN_ID, 0, "Import Interrupted", e)); + } + + ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project); + + // Index the project + PDOMFastIndexer indexer = new PDOMFastIndexer(); + indexer.setProject(cproject); + PDOMFastReindex reindex = new PDOMFastReindex(indexer); + reindex.run(monitor); + + cprojects[0] = cproject; + } + }, null); + + return cprojects[0]; + } + + /** + * Use to pick the right offset depending on what platform we're + * running. Windows has the extra character for new lines. + * + * @param winNum + * @param nixNum + * @return + */ + protected int offset(int winNum, int nixNum) { + return Platform.getOS().equals(Platform.OS_WIN32) ? winNum : nixNum; + } +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java new file mode 100644 index 00000000000..e00084e0698 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2006 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.pdom.tests; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * @author Doug Schaefer + * + */ +public class PDOMTests extends TestSuite { + + public static Test suite() { + TestSuite suite = new TestSuite(); + + suite.addTestSuite(EnumerationTests.class); + + return suite; + } + +} diff --git a/core/org.eclipse.cdt.core.tests/resources/pdomtests/enumerationTests/enumTest.c b/core/org.eclipse.cdt.core.tests/resources/pdomtests/enumerationTests/enumTest.c new file mode 100644 index 00000000000..4f27a529023 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/resources/pdomtests/enumerationTests/enumTest.c @@ -0,0 +1,9 @@ +enum TestCEnum { + ca, + cb, + cc +}; + +enum TestCEnum test() { + return ca; +} diff --git a/core/org.eclipse.cdt.core.tests/resources/pdomtests/enumerationTests/enumTest.cpp b/core/org.eclipse.cdt.core.tests/resources/pdomtests/enumerationTests/enumTest.cpp new file mode 100644 index 00000000000..83d528fd48b --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/resources/pdomtests/enumerationTests/enumTest.cpp @@ -0,0 +1,9 @@ +enum TestCPPEnum { + cppa, + cppb, + cppc +}; + +TestCPPEnum test() { + return cppa; +} diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java index 56346be2a3d..3bf7ff4a058 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java @@ -30,6 +30,7 @@ import org.eclipse.cdt.core.parser.failedTests.ASTFailedTests; import org.eclipse.cdt.core.parser.failedTests.FailedCompleteParseASTTest; import org.eclipse.cdt.core.parser.failedTests.STLFailedTests; import org.eclipse.cdt.core.parser.tests.ParserTestSuite; +import org.eclipse.cdt.internal.pdom.tests.PDOMTests; /** * @author vhirsl @@ -76,6 +77,9 @@ public class AutomatedIntegrationSuite extends TestSuite { // suite.addTest(DOMSourceIndexerTests.suite()); // Last test to trigger report generation + // Add in PDOM tests + suite.addTest(PDOMTests.suite()); + // Add all failed tests suite.addTestSuite(ASTFailedTests.class); suite.addTestSuite(STLFailedTests.class); diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index 1a13709025a..a83285be7bd 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -74,7 +74,6 @@ Require-Bundle: org.eclipse.core.resources, org.eclipse.core.runtime, org.eclipse.text, org.eclipse.core.variables, - org.eclipse.core.filebuffers, - org.eclipse.jface + org.eclipse.core.filebuffers Eclipse-LazyStart: true Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMResolver.java index e56dc353b39..9b4a2a39b9b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMResolver.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMResolver.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.core.dom; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; /** @@ -25,8 +26,10 @@ public interface IPDOMResolver extends IAdaptable { public IBinding resolveBinding(IASTName name); - public IASTName[] getDeclarations(IBinding binding); + public IASTName[] getDeclarations(IBinding binding) throws CoreException; - public IASTName[] getDefinitions(IBinding binding); + public IASTName[] getDefinitions(IBinding binding) throws CoreException; + + public IASTName[] getReferences(IBinding binding) throws CoreException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index 875ba6f578b..2c7c19ca292 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -54,7 +54,7 @@ public class PDOM extends PlatformObject private Database db; - public static final int VERSION = 7; + public static final int VERSION = 8; // 0 - the beginning of it all // 1 - first change to kick off upgrades // 2 - added file inclusions @@ -63,6 +63,7 @@ public class PDOM extends PlatformObject // 5 - added types and restructured nodes a bit // 6 - function style macros. // 7 - class key + // 8 - enumerators public static final int LINKAGES = Database.DATA_AREA; public static final int FILE_INDEX = Database.DATA_AREA + 4; @@ -193,33 +194,43 @@ public class PDOM extends PlatformObject return new PDOMCodeReaderFactory(this, root); } - public IASTName[] getDeclarations(IBinding binding) { - try { - if (binding instanceof PDOMBinding) { - List names = new ArrayList(); - for (PDOMName name = ((PDOMBinding)binding).getFirstDeclaration(); name != null; name = name.getNextInBinding()) - names.add(name); - // Add in definitions, too - for (PDOMName name = ((PDOMBinding)binding).getFirstDefinition(); name != null; name = name.getNextInBinding()) - names.add(name); - return (IASTName[])names.toArray(new IASTName[names.size()]); - } - } catch (CoreException e) { - CCorePlugin.log(e); + public IASTName[] getDeclarations(IBinding binding) throws CoreException { + if (binding instanceof PDOMBinding) { + List names = new ArrayList(); + for (PDOMName name = ((PDOMBinding)binding).getFirstDeclaration(); + name != null; + name = name.getNextInBinding()) + names.add(name); + // Add in definitions, too + for (PDOMName name = ((PDOMBinding)binding).getFirstDefinition(); + name != null; + name = name.getNextInBinding()) + names.add(name); + return (IASTName[])names.toArray(new IASTName[names.size()]); } return new IASTName[0]; } - public IASTName[] getDefinitions(IBinding binding) { - try { - if (binding instanceof PDOMBinding) { - List names = new ArrayList(); - for (PDOMName name = ((PDOMBinding)binding).getFirstDefinition(); name != null; name = name.getNextInBinding()) - names.add(name); - return (IASTName[])names.toArray(new IASTName[names.size()]); - } - } catch (CoreException e) { - CCorePlugin.log(e); + public IASTName[] getDefinitions(IBinding binding) throws CoreException { + if (binding instanceof PDOMBinding) { + List names = new ArrayList(); + for (PDOMName name = ((PDOMBinding)binding).getFirstDefinition(); + name != null; + name = name.getNextInBinding()) + names.add(name); + return (IASTName[])names.toArray(new IASTName[names.size()]); + } + return new IASTName[0]; + } + + public IASTName[] getReferences(IBinding binding) throws CoreException { + if (binding instanceof PDOMBinding) { + List names = new ArrayList(); + for (PDOMName name = ((PDOMBinding)binding).getFirstReference(); + name != null; + name = name.getNextInBinding()) + names.add(name); + return (IASTName[])names.toArray(new IASTName[names.size()]); } return new IASTName[0]; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumeration.java new file mode 100644 index 00000000000..47cdfef63b1 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumeration.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2006 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.pdom.dom.c; + +import java.util.ArrayList; + +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.IEnumeration; +import org.eclipse.cdt.core.dom.ast.IEnumerator; +import org.eclipse.cdt.core.dom.ast.IType; +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; + +/** + * @author Doug Schaefer + */ +public class PDOMCEnumeration extends PDOMBinding implements IEnumeration { + + private static final int FIRST_ENUMERATOR = PDOMBinding.RECORD_SIZE + 0; + + protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 4; + + public PDOMCEnumeration(PDOM pdom, PDOMNode parent, IASTName name) + throws CoreException { + super(pdom, parent, name); + } + + public PDOMCEnumeration(PDOM pdom, int record) { + super(pdom, record); + } + + protected int getRecordSize() { + return RECORD_SIZE; + } + + public int getNodeType() { + return PDOMCLinkage.CENUMERATION; + } + + public IEnumerator[] getEnumerators() throws DOMException { + try { + ArrayList enums = new ArrayList(); + for (PDOMCEnumerator enumerator = getFirstEnumerator(); + enumerator != null; + enumerator = enumerator.getNextEnumerator()) { + enums.add(enumerator); + } + + IEnumerator[] enumerators = (IEnumerator[])enums.toArray(new IEnumerator[enums.size()]); + + // Reverse the list since they are last in first out + int n = enumerators.length; + for (int i = 0; i < n / 2; ++i) { + IEnumerator tmp = enumerators[i]; + enumerators[i] = enumerators[n - 1 - i]; + enumerators[n - 1 - i] = tmp; + } + + return enumerators; + } catch (CoreException e) { + CCorePlugin.log(e); + return new IEnumerator[0]; + } + } + + private PDOMCEnumerator getFirstEnumerator() throws CoreException { + int value = pdom.getDB().getInt(record + FIRST_ENUMERATOR); + return value != 0 ? new PDOMCEnumerator(pdom, value) : null; + } + + public void addEnumerator(PDOMCEnumerator enumerator) throws CoreException { + PDOMCEnumerator first = getFirstEnumerator(); + enumerator.setNextEnumerator(first); + pdom.getDB().putInt(record + FIRST_ENUMERATOR, enumerator.getRecord()); + } + + public boolean isSameType(IType type) { + throw new PDOMNotImplementedError(); + } + + public Object clone() { + throw new PDOMNotImplementedError(); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumerator.java new file mode 100644 index 00000000000..448631852db --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumerator.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2006 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.core.pdom.dom.c; + +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.IEnumerator; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; +import org.eclipse.core.runtime.CoreException; + +/** + * @author Doug Schaefer + * + */ +public class PDOMCEnumerator extends PDOMBinding implements IEnumerator { + + private static final int ENUMERATION = PDOMBinding.RECORD_SIZE + 0; + private static final int NEXT_ENUMERATOR = PDOMBinding.RECORD_SIZE + 4; + + protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 8; + + public PDOMCEnumerator(PDOM pdom, PDOMNode parent, IASTName name, PDOMCEnumeration enumeration) + throws CoreException { + super(pdom, parent, name); + pdom.getDB().putInt(record + ENUMERATION, enumeration.getRecord()); + enumeration.addEnumerator(this); + } + + public PDOMCEnumerator(PDOM pdom, int record) { + super(pdom, record); + } + + protected int getRecordSize() { + return RECORD_SIZE; + } + + public int getNodeType() { + return PDOMCLinkage.CENUMERATOR; + } + + public PDOMCEnumerator getNextEnumerator() throws CoreException { + int value = pdom.getDB().getInt(record + NEXT_ENUMERATOR); + return value != 0 ? new PDOMCEnumerator(pdom, value) : null; + } + + public void setNextEnumerator(PDOMCEnumerator enumerator) throws CoreException { + int value = enumerator != null ? enumerator.getRecord() : 0; + pdom.getDB().putInt(record + NEXT_ENUMERATOR, value); + } + + public IType getType() throws DOMException { + try { + return new PDOMCEnumeration(pdom, pdom.getDB().getInt(record + ENUMERATION)); + } catch (CoreException e) { + CCorePlugin.log(e); + return null; + } + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java index 252cdde670e..b3e826f9562 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java @@ -22,6 +22,8 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IEnumeration; +import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IParameter; @@ -64,6 +66,8 @@ public class PDOMCLinkage extends PDOMLinkage { public static final int CFUNCTION = PDOMLinkage.LAST_NODE_TYPE + 2; public static final int CSTRUCTURE = PDOMLinkage.LAST_NODE_TYPE + 3; public static final int CFIELD = PDOMLinkage.LAST_NODE_TYPE + 4; + public static final int CENUMERATION = PDOMLinkage.LAST_NODE_TYPE + 5; + public static final int CENUMERATOR = PDOMLinkage.LAST_NODE_TYPE + 6; public ILanguage getLanguage() { return new GCCLanguage(); @@ -126,6 +130,15 @@ public class PDOMCLinkage extends PDOMLinkage { pdomBinding = new PDOMCFunction(pdom, parent, name); else if (binding instanceof ICompositeType) pdomBinding = new PDOMCStructure(pdom, parent, name); + else if (binding instanceof IEnumeration) + pdomBinding = new PDOMCEnumeration(pdom, parent, name); + else if (binding instanceof IEnumerator) { + IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType(); + PDOMBinding pdomEnumeration = adaptBinding(enumeration); + if (pdomEnumeration instanceof PDOMCEnumeration) + pdomBinding = new PDOMCEnumerator(pdom, parent, name, + (PDOMCEnumeration)pdomEnumeration); + } } if (pdomBinding != null) @@ -167,6 +180,10 @@ public class PDOMCLinkage extends PDOMLinkage { return CSTRUCTURE; else if (binding instanceof IField) return CFIELD; + else if (binding instanceof IEnumeration) + return CENUMERATION; + else if (binding instanceof IEnumerator) + return CENUMERATOR; else return 0; } @@ -202,6 +219,10 @@ public class PDOMCLinkage extends PDOMLinkage { return new PDOMCStructure(pdom, record); case CFIELD: return new PDOMCField(pdom, record); + case CENUMERATION: + return new PDOMCEnumeration(pdom, record); + case CENUMERATOR: + return new PDOMCEnumerator(pdom, record); } return super.getNode(record); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumeration.java new file mode 100644 index 00000000000..cc30bd8aca4 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumeration.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2006 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.pdom.dom.cpp; + +import java.util.ArrayList; + +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.IEnumeration; +import org.eclipse.cdt.core.dom.ast.IEnumerator; +import org.eclipse.cdt.core.dom.ast.IType; +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; + +/** + * @author Doug Schaefer + */ +public class PDOMCPPEnumeration extends PDOMBinding implements IEnumeration { + + private static final int FIRST_ENUMERATOR = PDOMBinding.RECORD_SIZE + 0; + + protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 4; + + public PDOMCPPEnumeration(PDOM pdom, PDOMNode parent, IASTName name) + throws CoreException { + super(pdom, parent, name); + } + + public PDOMCPPEnumeration(PDOM pdom, int record) { + super(pdom, record); + } + + protected int getRecordSize() { + return RECORD_SIZE; + } + + public int getNodeType() { + return PDOMCPPLinkage.CPPENUMERATION; + } + + public IEnumerator[] getEnumerators() throws DOMException { + try { + ArrayList enums = new ArrayList(); + for (PDOMCPPEnumerator enumerator = getFirstEnumerator(); + enumerator != null; + enumerator = enumerator.getNextEnumerator()) { + enums.add(enumerator); + } + + IEnumerator[] enumerators = (IEnumerator[])enums.toArray(new IEnumerator[enums.size()]); + + // Reverse the list since they are last in first out + int n = enumerators.length; + for (int i = 0; i < n / 2; ++i) { + IEnumerator tmp = enumerators[i]; + enumerators[i] = enumerators[n - 1 - i]; + enumerators[n - 1 - i] = tmp; + } + + return enumerators; + } catch (CoreException e) { + CCorePlugin.log(e); + return new IEnumerator[0]; + } + } + + private PDOMCPPEnumerator getFirstEnumerator() throws CoreException { + int value = pdom.getDB().getInt(record + FIRST_ENUMERATOR); + return value != 0 ? new PDOMCPPEnumerator(pdom, value) : null; + } + + public void addEnumerator(PDOMCPPEnumerator enumerator) throws CoreException { + PDOMCPPEnumerator first = getFirstEnumerator(); + enumerator.setNextEnumerator(first); + pdom.getDB().putInt(record + FIRST_ENUMERATOR, enumerator.getRecord()); + } + + public boolean isSameType(IType type) { + throw new PDOMNotImplementedError(); + } + + public Object clone() { + throw new PDOMNotImplementedError(); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumerator.java new file mode 100644 index 00000000000..6050cf26876 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumerator.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2006 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX - Initial API and implementation + *******************************************************************************/ + +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.IEnumerator; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; +import org.eclipse.core.runtime.CoreException; + +/** + * @author Doug Schaefer + * + */ +public class PDOMCPPEnumerator extends PDOMBinding implements IEnumerator { + + private static final int ENUMERATION = PDOMBinding.RECORD_SIZE + 0; + private static final int NEXT_ENUMERATOR = PDOMBinding.RECORD_SIZE + 4; + + protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 8; + + public PDOMCPPEnumerator(PDOM pdom, PDOMNode parent, IASTName name, PDOMCPPEnumeration enumeration) + throws CoreException { + super(pdom, parent, name); + pdom.getDB().putInt(record + ENUMERATION, enumeration.getRecord()); + enumeration.addEnumerator(this); + } + + public PDOMCPPEnumerator(PDOM pdom, int record) { + super(pdom, record); + } + + protected int getRecordSize() { + return RECORD_SIZE; + } + + public int getNodeType() { + return PDOMCPPLinkage.CPPENUMERATOR; + } + + public PDOMCPPEnumerator getNextEnumerator() throws CoreException { + int value = pdom.getDB().getInt(record + NEXT_ENUMERATOR); + return value != 0 ? new PDOMCPPEnumerator(pdom, value) : null; + } + + public void setNextEnumerator(PDOMCPPEnumerator enumerator) throws CoreException { + int value = enumerator != null ? enumerator.getRecord() : 0; + pdom.getDB().putInt(record + NEXT_ENUMERATOR, value); + } + + public IType getType() throws DOMException { + try { + return new PDOMCPPEnumeration(pdom, pdom.getDB().getInt(record + ENUMERATION)); + } catch (CoreException e) { + CCorePlugin.log(e); + return null; + } + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java index 3195ba74374..b76c22d6cab 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java @@ -20,6 +20,8 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IEnumeration; +import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IScope; @@ -37,14 +39,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage; import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPField; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethod; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNamespace; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNamespaceAlias; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable; 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.PDOMFile; @@ -89,6 +84,8 @@ public class PDOMCPPLinkage extends PDOMLinkage { public static final int CPPNAMESPACEALIAS = PDOMLinkage.LAST_NODE_TYPE + 7; public static final int CPPBASICTYPE = PDOMLinkage.LAST_NODE_TYPE + 8; public static final int CPPPARAMETER = PDOMLinkage.LAST_NODE_TYPE + 9; + public static final int CPPENUMERATION = PDOMLinkage.LAST_NODE_TYPE + 10; + public static final int CPPENUMERATOR = PDOMLinkage.LAST_NODE_TYPE + 11; public ILanguage getLanguage() { return new GPPLanguage(); @@ -131,26 +128,35 @@ public class PDOMCPPLinkage extends PDOMLinkage { if (pdomBinding == null) { PDOMNode parent = getParent(binding); - if (binding instanceof CPPField && parent instanceof PDOMCPPClassType) + if (binding instanceof ICPPField && parent instanceof PDOMCPPClassType) pdomBinding = new PDOMCPPField(pdom, (PDOMCPPClassType)parent, name); - else if (binding instanceof CPPVariable) { + else if (binding instanceof ICPPVariable) { if (!(binding.getScope() instanceof CPPBlockScope)) pdomBinding = new PDOMCPPVariable(pdom, parent, name); - } else if (binding instanceof CPPMethod && parent instanceof PDOMCPPClassType) { + } else if (binding instanceof ICPPMethod && parent instanceof PDOMCPPClassType) { pdomBinding = new PDOMCPPMethod(pdom, (PDOMCPPClassType)parent, name); } else if (binding instanceof CPPImplicitMethod && parent instanceof PDOMCPPClassType) { if(!name.isReference()) { - //because we got the implicit method off of an IASTName that is not a reference, it is no longer completly implicit and it should be treated as a normal method. + //because we got the implicit method off of an IASTName that is not a reference, + //it is no longer completly implicit and it should be treated as a normal method. pdomBinding = new PDOMCPPMethod(pdom, (PDOMCPPClassType)parent, name); } - } else if (binding instanceof CPPFunction) { + } else if (binding instanceof ICPPFunction) { pdomBinding = new PDOMCPPFunction(pdom, parent, name); - } else if (binding instanceof CPPClassType) { + } else if (binding instanceof ICPPClassType) { pdomBinding = new PDOMCPPClassType(pdom, parent, name); - } else if (binding instanceof CPPNamespaceAlias) { + } else if (binding instanceof ICPPNamespaceAlias) { pdomBinding = new PDOMCPPNamespaceAlias(pdom, parent, name); - } else if (binding instanceof CPPNamespace) { + } else if (binding instanceof ICPPNamespace) { pdomBinding = new PDOMCPPNamespace(pdom, parent, name); + } else if (binding instanceof IEnumeration) { + pdomBinding = new PDOMCPPEnumeration(pdom, parent, name); + } else if (binding instanceof IEnumerator) { + IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType(); + PDOMBinding pdomEnumeration = adaptBinding(enumeration); + if (pdomEnumeration instanceof PDOMCPPEnumeration) + pdomBinding = new PDOMCPPEnumerator(pdom, parent, name, + (PDOMCPPEnumeration)pdomEnumeration); } } @@ -206,6 +212,10 @@ public class PDOMCPPLinkage extends PDOMLinkage { return CPPNAMESPACEALIAS; else if (binding instanceof ICPPNamespace) return CPPNAMESPACE; + else if (binding instanceof IEnumeration) + return CPPENUMERATION; + else if (binding instanceof IEnumerator) + return CPPENUMERATOR; else return 0; } @@ -351,9 +361,13 @@ public class PDOMCPPLinkage extends PDOMLinkage { return new PDOMCPPNamespaceAlias(pdom, record); case CPPBASICTYPE: return new PDOMCPPBasicType(pdom, record); + case CPPENUMERATION: + return new PDOMCPPEnumeration(pdom, record); + case CPPENUMERATOR: + return new PDOMCPPEnumerator(pdom, record); + default: + return super.getNode(record); } - - return super.getNode(record); } }