mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 21:05:37 +02:00
More consistent treatment of anonymous namespaces betwenn index and
non-index bindings.
This commit is contained in:
parent
cf448ee139
commit
698bb0afe4
5 changed files with 105 additions and 41 deletions
|
@ -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,7 +744,8 @@ 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) {
|
||||
if (owner instanceof ICPPNamespace && owner.getNameCharArray().length == 0) {
|
||||
if (binding instanceof IIndexBinding) {
|
||||
try {
|
||||
IIndexFile file = ((IIndexBinding) binding).getLocalToFile();
|
||||
if (file != null) {
|
||||
|
@ -750,6 +756,16 @@ public class ASTTypeUtil {
|
|||
} 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(uri.toString());
|
||||
result.append('}');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result.length() > pos)
|
||||
result.append("::"); //$NON-NLS-1$
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1166,15 +1166,13 @@ 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) {
|
||||
if (owner instanceof ICPPNamespace && owner.getNameCharArray().length == 0) {
|
||||
IASTNode node= ASTInternal.getDeclaredInSourceFileOnly(getPDOM(), binding, false, glob);
|
||||
if (node != null) {
|
||||
file= wpdom.getFileForASTNode(getLinkageID(), node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (file != null) {
|
||||
return file;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue