Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-02-04 16:15:05 +0000
committerMarkus Schorn2008-02-04 16:15:05 +0000
commitdfb5057e5cd10ca36660affdce593aff52fc9a4a (patch)
tree0a87c56db57fece661afb5f904091ddcb6e45713 /core/org.eclipse.cdt.core/parser
parentfd1c9d4e2809db23c415f6abbb3ba2a73d5de0e9 (diff)
downloadorg.eclipse.cdt-dfb5057e5cd10ca36660affdce593aff52fc9a4a.tar.gz
org.eclipse.cdt-dfb5057e5cd10ca36660affdce593aff52fc9a4a.tar.xz
org.eclipse.cdt-dfb5057e5cd10ca36660affdce593aff52fc9a4a.zip
Keep types defined in source files separate from each other, bug 214146.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CTypedef.java17
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java12
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ProjectIndexerInputAdapter.java27
9 files changed, 68 insertions, 19 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java
index 9c7e81adaef..f665bdbb348 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java
@@ -110,7 +110,7 @@ public class ASTInternal {
}
}
- public static String getDeclaredInSourceFileOnly(IBinding binding) {
+ public static String getDeclaredInSourceFileOnly(IBinding binding, boolean requireDefinition) {
IASTNode[] decls;
IASTNode def;
if (binding instanceof ICPPInternalBinding) {
@@ -126,6 +126,9 @@ public class ASTInternal {
else {
return null;
}
+ if (requireDefinition && def == null) {
+ return null;
+ }
String filePath= null;
if (def != null) {
if ( (filePath= isPartOfSource(filePath, def)) == null) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CTypedef.java
index e60ed5c9418..1f0ce8db1ae 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CTypedef.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CTypedef.java
@@ -1,15 +1,14 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Rational Software - Initial API and implementation
- * Markus Schorn (Wind River Systems)
+ * IBM Rational Software - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
@@ -28,7 +27,7 @@ import org.eclipse.core.runtime.PlatformObject;
* Created on Nov 8, 2004
* @author aniefer
*/
-public class CTypedef extends PlatformObject implements ITypedef, ITypeContainer {
+public class CTypedef extends PlatformObject implements ITypedef, ITypeContainer, ICInternalBinding {
private final IASTName name;
private IType type = null;
@@ -105,4 +104,12 @@ public class CTypedef extends PlatformObject implements ITypedef, ITypeContainer
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
+
+ public IASTNode[] getDeclarations() {
+ return IASTNode.EMPTY_NODE_ARRAY;
+ }
+
+ public IASTNode getDefinition() {
+ return name;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
index 8874847f2c3..f845cc0a6ad 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
@@ -68,6 +68,7 @@ import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMNullIndexer;
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMRebuildTask;
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMUpdateTask;
+import org.eclipse.cdt.internal.core.pdom.indexer.ProjectIndexerInputAdapter;
import org.eclipse.cdt.internal.core.pdom.indexer.TriggerNotificationTask;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
import org.eclipse.core.resources.IFolder;
@@ -346,6 +347,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
writeProjectPDOMProperties(pdom, rproject);
pdom.releaseWriteLock();
}
+ pdom.setASTFilePathResolver(new ProjectIndexerInputAdapter(project, false));
pdom.addListener(this);
fFileToProject.put(dbFile, project);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java
index 8877dc2f442..5c7a45e041c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java
@@ -50,6 +50,10 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
public WritablePDOM(File dbPath, IIndexLocationConverter locationConverter, ChunkCache cache, Map<String, IPDOMLinkageFactory> linkageFactoryMappings) throws CoreException {
super(dbPath, locationConverter, cache, linkageFactoryMappings);
}
+
+ public void setASTFilePathResolver(ASTFilePathResolver resolver) {
+ fPathResolver= resolver;
+ }
public IIndexFragmentFile addFile(int linkageID, IIndexFileLocation location) throws CoreException {
return super.addFile(linkageID, location);
@@ -62,12 +66,13 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
PDOMFile pdomFile = (PDOMFile) sourceFile;
pdomFile.addIncludesTo(includes);
pdomFile.addMacros(macros);
+ final ASTFilePathResolver origResolver= fPathResolver;
fPathResolver= pathResolver;
try {
pdomFile.addNames(names);
}
finally {
- fPathResolver= null;
+ fPathResolver= origResolver;
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java
index 9c672990622..e7cd6a56541 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java
@@ -309,9 +309,12 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
* Compares two binding fully qualified names. If b0 has
* less segments than b1 then -1 is returned, if b0 has
* more segments than b1 then 1 is returned. If the segment
- * lengths are equal then comparison is lexographical on each
+ * lengths are equal then comparison is lexicographical on each
* component name, beginning with the most nested name and working
- * outward. The first non-zero comparison is returned as the result.
+ * outward.
+ * If one of the bindings in the hierarchy is file-local it is treated as a different
+ * binding.
+ * The first non-zero comparison is returned as the result.
* @param b0
* @param b1
* @return<ul><li> -1 if b0 &lt; b1
@@ -327,6 +330,11 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
IString s0 = b0.getDBName(), s1 = b1.getDBName();
cmp = s0.compare(s1, true);
if(cmp==0) {
+ int l1= b0.getLocalToFileRec();
+ int l2= b1.getLocalToFileRec();
+ if (l1 != l2) {
+ return l1 < l2 ? -1 : 1;
+ }
b0 = (PDOMBinding) b0.getParentBinding();
b1 = (PDOMBinding) b1.getParentBinding();
if(b0==null || b1==null) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java
index d603b9cd2a3..f9c0c2e9cf2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java
@@ -21,6 +21,7 @@ import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
+import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexLocationConverter;
@@ -243,6 +244,9 @@ public class PDOMFile implements IIndexFragmentFile {
}
private PDOMName createPDOMName(IASTName name, PDOMName caller) {
+ if (name.getBinding() instanceof IParameter) {
+ return null;
+ }
PDOMName result= null;
try {
PDOMBinding binding = ((WritablePDOM) pdom).addBinding(name);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
index 4925c795ef8..fe23d40428d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
@@ -24,6 +24,8 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IArrayType;
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.IField;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IPointerType;
@@ -31,6 +33,7 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
@@ -359,6 +362,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
return null;
}
boolean checkInSourceOnly= false;
+ boolean requireDefinition= false;
if (binding instanceof IVariable) {
if (!(binding instanceof IField)) {
checkInSourceOnly= ASTInternal.isStatic((IVariable) binding);
@@ -366,12 +370,13 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
} else if (binding instanceof IFunction) {
IFunction f= (IFunction) binding;
checkInSourceOnly= ASTInternal.isStatic(f, false);
-// } else if (binding instanceof ITypedef || binding instanceof ICompositeType || binding instanceof IEnumeration) {
-// checkInSourceOnly= true;
+ } else if (binding instanceof ITypedef || binding instanceof ICompositeType || binding instanceof IEnumeration) {
+ checkInSourceOnly= true;
+ requireDefinition= true;
}
if (checkInSourceOnly) {
- String path= ASTInternal.getDeclaredInSourceFileOnly(binding);
+ String path= ASTInternal.getDeclaredInSourceFileOnly(binding, requireDefinition);
if (path != null) {
return wpdom.getFileForASTPath(getLinkageID(), path);
}
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 8545ac2698c..87d5547caa7 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
@@ -795,7 +795,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return wpdom.getFileForASTPath(getLinkageID(), path);
}
} else if (binding instanceof ICPPNamespaceAlias) {
- String path= ASTInternal.getDeclaredInSourceFileOnly(binding);
+ String path= ASTInternal.getDeclaredInSourceFileOnly(binding, false);
if (path != null) {
return wpdom.getFileForASTPath(getLinkageID(), path);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ProjectIndexerInputAdapter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ProjectIndexerInputAdapter.java
index 3d52c17c7a0..27bf24ee100 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ProjectIndexerInputAdapter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ProjectIndexerInputAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -42,29 +42,44 @@ public class ProjectIndexerInputAdapter extends IndexerInputAdapter {
private final static boolean CASE_SENSITIVE_FILES= !new File("a").equals(new File("A")); //$NON-NLS-1$//$NON-NLS-2$
private final ICProject fCProject;
- private HashMap fIflCache= new HashMap();
+ private HashMap<String, IIndexFileLocation> fIflCache;
public ProjectIndexerInputAdapter(ICProject cproject) {
+ this(cproject, true);
+ }
+
+ public ProjectIndexerInputAdapter(ICProject cproject, boolean useCache) {
fCProject= cproject;
+ fIflCache= useCache ? new HashMap<String, IIndexFileLocation>() : null;
}
public IIndexFileLocation resolveASTPath(String astPath) {
- IIndexFileLocation result= (IIndexFileLocation) fIflCache.get(astPath);
+ if (fIflCache == null) {
+ return doResolveASTPath(astPath);
+ }
+ IIndexFileLocation result= fIflCache.get(astPath);
if (result == null) {
- result= IndexLocationFactory.getIFLExpensive(fCProject, astPath);
+ result = doResolveASTPath(astPath);
fIflCache.put(astPath, result);
}
return result;
}
+ private IIndexFileLocation doResolveASTPath(String astPath) {
+ return IndexLocationFactory.getIFLExpensive(fCProject, astPath);
+ }
+
public IIndexFileLocation resolveIncludeFile(String includePath) {
- IIndexFileLocation result= (IIndexFileLocation) fIflCache.get(includePath);
+ if (fIflCache == null) {
+ return doResolveASTPath(includePath);
+ }
+ IIndexFileLocation result= fIflCache.get(includePath);
if (result == null) {
File location= new File(includePath);
if (!location.exists()) {
return null;
}
- result= IndexLocationFactory.getIFLExpensive(fCProject, includePath);
+ result = doResolveASTPath(includePath);
if (result.getFullPath() == null && !CASE_SENSITIVE_FILES) {
try {
String canonicalPath= location.getCanonicalPath();

Back to the top