Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2018-05-04 04:49:06 +0000
committerNathan Ridge2018-06-26 20:51:41 +0000
commit40133cceb4616d0eee2f8d68f15d4faa3c04db8f (patch)
treece8a6789a1c5b8776f7ddc2bdfe324797e8cdbd1 /core/org.eclipse.cdt.core/parser
parentcc23d88b5486ace4e73cde115ad551329a2d3ec4 (diff)
downloadorg.eclipse.cdt-40133cceb4616d0eee2f8d68f15d4faa3c04db8f.tar.gz
org.eclipse.cdt-40133cceb4616d0eee2f8d68f15d4faa3c04db8f.tar.xz
org.eclipse.cdt-40133cceb4616d0eee2f8d68f15d4faa3c04db8f.zip
Bug 534330 - Use the full path of the file when inventing names for anonymous types
Otherwise we can get clashes if two anonymous types happen to be at the same offset in files with the same name but different paths. Change-Id: Ia269a7c6fa1dc7e37d23d9333b245143d7c33e5d
Diffstat (limited to 'core/org.eclipse.cdt.core/parser')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java42
1 files changed, 30 insertions, 12 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java
index c508ecf7ea2..b256f7aab65 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java
@@ -42,6 +42,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPQualifierType;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFile;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.GCCKeywords;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
@@ -60,7 +62,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.TypeOfDependentExpression;
+import org.eclipse.cdt.internal.core.resources.ResourceLookup;
import org.eclipse.cdt.utils.UNCPathConverter;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@@ -997,10 +1001,9 @@ public class ASTTypeUtil {
}
}
if (loc != null) {
- char[] fname= loc.getFileName().toCharArray();
- int fnamestart= findFileNameStart(fname);
+ char[] file = getWorkspaceRelativePath(loc.getFileName(), node).toCharArray();
buf.append('{');
- buf.append(fname, fnamestart, fname.length - fnamestart);
+ buf.append(file);
if (includeOffset) {
buf.append(':');
buf.append(loc.getNodeOffset());
@@ -1009,17 +1012,32 @@ public class ASTTypeUtil {
}
}
- private static int findFileNameStart(char[] fname) {
- for (int i= fname.length - 2; i >= 0; i--) {
- switch (fname[i]) {
- case '/':
- case '\\':
- return i+1;
- }
+ /**
+ * Try to get a workspace-relative path for a filename.
+ * If that fails, just return the input path.
+ */
+ private static String getWorkspaceRelativePath(String filename, IASTNode context) {
+ if (context == null) {
+ return filename;
+ }
+ IASTTranslationUnit ast = context.getTranslationUnit();
+ if (ast == null) {
+ return filename;
}
- return 0;
+ ITranslationUnit tu = ast.getOriginatingTranslationUnit();
+ if (tu == null) {
+ return filename;
+ }
+ ICProject cproject = tu.getCProject();
+ if (cproject == null) {
+ return filename;
+ }
+ IPath path = new Path(filename);
+ IFile file = ResourceLookup.selectFileForLocation(path, cproject.getProject());
+ IPath workspaceRelative = file.getFullPath();
+ return workspaceRelative.toString();
}
-
+
/**
* @noreference This method is not intended to be referenced by clients.
* @deprecated This method is no longer used and is scheduled for removal in 10.0.

Back to the top