Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2014-08-22 05:29:30 +0000
committerSergey Prigogin2014-08-27 21:39:26 +0000
commit3779d88f41326b126af1c16daffd326b3207d016 (patch)
treedb8b5b76d2587f0ef1e1df339476f4f1bba1a888
parent7ed07030b24717e699b534c2cce9e38a428d2e20 (diff)
downloadorg.eclipse.cdt-3779d88f41326b126af1c16daffd326b3207d016.tar.gz
org.eclipse.cdt-3779d88f41326b126af1c16daffd326b3207d016.tar.xz
org.eclipse.cdt-3779d88f41326b126af1c16daffd326b3207d016.zip
More consistent treatment of anonymous namespaces betwenn index and
non-index bindings.
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java34
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java65
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFileSet.java30
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java10
5 files changed, 105 insertions, 41 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 d8c4b819507..252f7e22cdf 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 IBM Corporation and others.
+ * Copyright (c) 2005, 2014 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
@@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
+import java.net.URI;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
@@ -38,6 +39,7 @@ import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.parser.GCCKeywords;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
+import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTTypeId;
@@ -50,7 +52,10 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownMemberClassInstan
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.utils.UNCPathConverter;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
/**
* This is a utility class to help convert AST elements to Strings corresponding to
@@ -582,7 +587,7 @@ public class ASTTypeUtil {
needSpace= true;
} else {
if (postfix == null) {
- postfix= new ArrayList<IType>();
+ postfix= new ArrayList<>();
}
postfix.add(tj);
needParenthesis= true;
@@ -739,16 +744,27 @@ public class ASTTypeUtil {
if (owner instanceof ICPPNamespace || owner instanceof IType) {
int pos= result.length();
appendCppName(owner, normalize, qualify, result);
- if (binding instanceof IIndexBinding && owner instanceof ICPPNamespace && owner.getNameCharArray().length == 0) {
- try {
- IIndexFile file = ((IIndexBinding) binding).getLocalToFile();
- if (file != null) {
+ if (owner instanceof ICPPNamespace && owner.getNameCharArray().length == 0) {
+ if (binding instanceof IIndexBinding) {
+ try {
+ IIndexFile file = ((IIndexBinding) binding).getLocalToFile();
+ if (file != null) {
+ result.append('{');
+ result.append(file.getLocation().getURI().toString());
+ result.append('}');
+ }
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ }
+ } else {
+ IASTNode node = ASTInternal.getDeclaredInSourceFileOnly(binding);
+ if (node != null) {
+ IPath filePath = new Path(node.getTranslationUnit().getFilePath());
+ URI uri = UNCPathConverter.getInstance().toURI(filePath);
result.append('{');
- result.append(file.getLocation().getURI().toString());
+ result.append(uri.toString());
result.append('}');
}
- } catch (CoreException e) {
- CCorePlugin.log(e);
}
}
if (result.length() > pos)
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 e7bfd50b3bd..3ad61ea68f2 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2012 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2014 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser;
@@ -18,12 +19,17 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.index.IIndexBinding;
+import org.eclipse.cdt.core.index.IIndexFileLocation;
+import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.index.IndexFilter;
+import org.eclipse.cdt.core.index.IndexLocationFactory;
+import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding;
import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
+import org.eclipse.cdt.internal.core.index.IndexFileSet;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.core.runtime.CoreException;
@@ -76,6 +82,47 @@ public class ASTInternal {
public static IASTNode getDeclaredInSourceFileOnly(IIndexFragment forFragment, IBinding binding,
boolean requireDefinition, PDOMBinding glob) {
+ IASTNode result = getDeclaredInSourceFileOnly(binding, requireDefinition);
+ if (result == null)
+ return null;
+
+ if (requireDefinition && glob != null) {
+ try {
+ if (glob.hasDeclaration())
+ return null;
+ } catch (CoreException e) {
+ }
+ }
+
+ IASTTranslationUnit tu= result.getTranslationUnit();
+ if (tu != null) {
+ if (tu.getIndexFileSet().containsNonLocalDeclaration(binding, forFragment))
+ return null;
+ }
+ return result;
+ }
+
+ public static IASTNode getDeclaredInSourceFileOnly(IBinding binding) {
+ IASTNode result = getDeclaredInSourceFileOnly(binding, false);
+ if (result == null)
+ return null;
+
+ IASTTranslationUnit ast= result.getTranslationUnit();
+ if (ast != null) {
+ ITranslationUnit tu = ast.getOriginatingTranslationUnit();
+ if (tu == null)
+ return null;
+ IIndexFileLocation location = IndexLocationFactory.getIFL(tu);
+ IIndexFileSet fileSet = ast.getIndexFileSet();
+ if (!(fileSet instanceof IndexFileSet))
+ return null;
+ if (((IndexFileSet) fileSet).containsNonLocalDeclaration(binding, location))
+ return null;
+ }
+ return result;
+ }
+
+ private static IASTNode getDeclaredInSourceFileOnly(IBinding binding, boolean requireDefinition) {
IASTNode[] decls;
IASTNode def;
if (binding instanceof ICPPInternalBinding) {
@@ -108,22 +155,6 @@ public class ASTInternal {
}
}
}
- if (result == null)
- return null;
-
- if (requireDefinition && glob != null) {
- try {
- if (glob.hasDeclaration())
- return null;
- } catch (CoreException e) {
- }
- }
-
- IASTTranslationUnit tu= result.getTranslationUnit();
- if (tu != null) {
- if (tu.getIndexFileSet().containsNonLocalDeclaration(binding, forFragment))
- return null;
- }
return result;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java
index d8b9645d568..2d9887cd974 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java
@@ -650,15 +650,8 @@ public class SemanticUtil {
while (true) {
for (int i = 0; b1 instanceof ICPPNamespaceAlias && i < 20; i++)
b1= ((ICPPNamespaceAlias) b1).getBinding();
- // TODO(sprigogin): Anonymous namespaces should not be ignored here.
- // Ignore anonymous namespaces.
- while (b1 instanceof ICPPNamespace && b1.getNameCharArray().length == 0)
- b1= b1.getOwner();
for (int i = 0; b2 instanceof ICPPNamespaceAlias && i < 20; i++)
b2= ((ICPPNamespaceAlias) b2).getBinding();
- // Ignore anonymous namespaces.
- while (b2 instanceof ICPPNamespace && b2.getNameCharArray().length == 0)
- b2= b2.getOwner();
if (b1 == null)
return b2 == null;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFileSet.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFileSet.java
index 3a27ba8276e..9852e90e40e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFileSet.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexFileSet.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2012 Wind River Systems, Inc. and others.
+ * Copyright (c) 2008, 2014 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
@@ -18,13 +19,14 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFile;
+import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
public class IndexFileSet implements IIndexFileSet {
private IIndexFileSet fInverse;
- private HashMap<IIndexFragment, IIndexFragmentFileSet> fSubSets= new HashMap<IIndexFragment, IIndexFragmentFileSet>();
+ private HashMap<IIndexFragment, IIndexFragmentFileSet> fSubSets= new HashMap<>();
public IndexFileSet() {
}
@@ -98,6 +100,30 @@ public class IndexFileSet implements IIndexFileSet {
return false;
}
+ public boolean containsNonLocalDeclaration(IBinding binding, IIndexFileLocation ignore) {
+ for (Map.Entry<IIndexFragment, IIndexFragmentFileSet> entry : fSubSets.entrySet()) {
+ try {
+ final IIndexFragment fragment = entry.getKey();
+ final IIndexFragmentFileSet subset = entry.getValue();
+ IIndexFragmentName[] names =
+ fragment.findNames(binding, IIndexFragment.FIND_DECLARATIONS_DEFINITIONS | IIndexFragment.FIND_NON_LOCAL_ONLY);
+ for (IIndexFragmentName name : names) {
+ try {
+ IIndexFile file = name.getFile();
+ if (!file.getLocation().equals(ignore) && subset.contains((IIndexFragmentFile) file)) {
+ return true;
+ }
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ }
+ }
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ }
+ }
+ return false;
+ }
+
@Override
public IBinding[] filterFileLocalBindings(IBinding[] bindings) {
return filterFileLocalBindings(bindings, false);
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 f23ebca3ca9..afd5ce44c3d 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
@@ -1166,12 +1166,10 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
if (file == null && !(binding instanceof IIndexBinding)) {
IBinding owner= binding.getOwner();
- if (owner instanceof ICPPNamespace) {
- if (owner.getNameCharArray().length == 0) {
- IASTNode node= ASTInternal.getDeclaredInSourceFileOnly(getPDOM(), binding, false, glob);
- if (node != null) {
- file= wpdom.getFileForASTNode(getLinkageID(), node);
- }
+ if (owner instanceof ICPPNamespace && owner.getNameCharArray().length == 0) {
+ IASTNode node= ASTInternal.getDeclaredInSourceFileOnly(getPDOM(), binding, false, glob);
+ if (node != null) {
+ file= wpdom.getFileForASTNode(getLinkageID(), node);
}
}
}

Back to the top