mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Follow up for using declarations, bug 203385.
This commit is contained in:
parent
65f5219435
commit
d09429e1d5
9 changed files with 84 additions and 58 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Symbian Software Systems and others.
|
||||
* Copyright (c) 2007, 2008 Symbian 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
|
||||
|
@ -155,6 +155,7 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
|
|||
// class B {};
|
||||
// }
|
||||
|
||||
// #include "header.h"
|
||||
// b::A aa;
|
||||
// b::B bb;
|
||||
public void testUsingTypeDirective_177917_2() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2007 IBM Corporation.
|
||||
* Copyright (c) 2006, 2008 IBM Corporation.
|
||||
* 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
|
||||
|
@ -219,9 +219,7 @@ public class NamespaceTests extends PDOMTestBase {
|
|||
IName[] decls = pdom.findNames(variable1, IIndex.FIND_DECLARATIONS);
|
||||
assertEquals(0, decls.length);
|
||||
|
||||
//TODO: should this be 2?
|
||||
//Doug: Not sure but we're at one now...
|
||||
IName[] refs = pdom.findNames(variable1, IIndex.FIND_REFERENCES);
|
||||
assertEquals(1, refs.length);
|
||||
assertEquals(2, refs.length);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,4 +159,40 @@ public class ASTInternal {
|
|||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public static String getDeclaredInOneFileOnly(IBinding binding) {
|
||||
IASTNode[] decls;
|
||||
IASTNode def;
|
||||
if (binding instanceof ICPPInternalBinding) {
|
||||
ICPPInternalBinding ib= (ICPPInternalBinding) binding;
|
||||
decls= ib.getDeclarations();
|
||||
def= ib.getDefinition();
|
||||
}
|
||||
else if (binding instanceof ICInternalBinding) {
|
||||
ICInternalBinding ib= (ICInternalBinding) binding;
|
||||
decls= ib.getDeclarations();
|
||||
def= ib.getDefinition();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
String filePath= null;
|
||||
if (def != null) {
|
||||
filePath= def.getContainingFilename();
|
||||
}
|
||||
if (decls != null) {
|
||||
for (int i = 0; i < decls.length; i++) {
|
||||
final IASTNode node= decls[i];
|
||||
if (node != null) {
|
||||
final String fn = node.getContainingFilename();
|
||||
if (filePath == null) {
|
||||
filePath= fn;
|
||||
} else if (!filePath.equals(fn)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -549,34 +549,6 @@ public class CIndex implements IIndex {
|
|||
}
|
||||
}
|
||||
|
||||
public String getFileLocalScopeQualifier(IIndexFileLocation loc) {
|
||||
return new String(getFileLocalScopeQualifier(loc.getFullPath()));
|
||||
}
|
||||
|
||||
public static char[] getFileLocalScopeQualifier(String fullPath) {
|
||||
char[] fname= fullPath.toCharArray();
|
||||
int fnamestart= findFileNameStart(fname);
|
||||
StringBuffer buf= new StringBuffer();
|
||||
buf.append('{');
|
||||
buf.append(fname, fnamestart, fname.length-fnamestart);
|
||||
buf.append(':');
|
||||
buf.append(fullPath.hashCode());
|
||||
buf.append('}');
|
||||
fname= buf.toString().toCharArray();
|
||||
return fname;
|
||||
}
|
||||
|
||||
private static int findFileNameStart(char[] fname) {
|
||||
for (int i= fname.length-2; i>=0; i--) {
|
||||
switch (fname[i]) {
|
||||
case '/':
|
||||
case '\\':
|
||||
return i+1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public IIndexFileSet createFileSet() {
|
||||
return new IndexFileSet();
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
|
|||
return record;
|
||||
}
|
||||
|
||||
public boolean hasDeclaration() throws CoreException {
|
||||
public final boolean hasDeclaration() throws CoreException {
|
||||
Database db = pdom.getDB();
|
||||
return db.getInt(record + FIRST_DECL_OFFSET) != 0
|
||||
|| db.getInt(record + FIRST_DEF_OFFSET) != 0;
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
|||
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;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
|
@ -42,7 +43,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.index.IIndexLinkage;
|
||||
import org.eclipse.cdt.internal.core.Util;
|
||||
|
@ -259,6 +259,11 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
|||
if (binding instanceof ICPPTemplateInstance) {
|
||||
scopeBinding = ((ICPPTemplateInstance)binding).getTemplateDefinition();
|
||||
} else {
|
||||
// in case this is a delegate the scope of the delegate can be different to the
|
||||
// scope of the delegating party (e.g. using-declarations)
|
||||
while (binding instanceof ICPPDelegate && !(binding instanceof ICPPNamespaceAlias)) {
|
||||
binding= ((ICPPDelegate) binding).getBinding();
|
||||
}
|
||||
IScope scope = binding.getScope();
|
||||
if (scope == null) {
|
||||
if (binding instanceof ICPPDeferredTemplateInstance) {
|
||||
|
@ -359,11 +364,6 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
|||
} else if (binding instanceof IFunction) {
|
||||
IFunction f= (IFunction) binding;
|
||||
isFileLocal= ASTInternal.isStatic(f, false);
|
||||
} else if ((binding instanceof ICPPUsingDeclaration ||
|
||||
binding instanceof ICPPNamespaceAlias) && binding.getScope() == null) {
|
||||
// Using declarations and namespace aliases in global scope are restricted
|
||||
// to the containing file.
|
||||
isFileLocal= true;
|
||||
}
|
||||
|
||||
if (isFileLocal) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 QNX Software Systems and others.
|
||||
* Copyright (c) 2005, 2008 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
|
||||
|
@ -17,6 +17,7 @@ import java.util.ArrayList;
|
|||
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.cpp.ICPPUsingDeclaration;
|
||||
import org.eclipse.cdt.core.index.IIndexFile;
|
||||
import org.eclipse.cdt.core.index.IIndexName;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||
|
@ -64,13 +65,7 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
|
|||
record = db.malloc(RECORD_SIZE);
|
||||
|
||||
// What kind of name are we
|
||||
int flags = 0;
|
||||
if (name.isDefinition())
|
||||
flags = IS_DEFINITION;
|
||||
else if (name.isDeclaration())
|
||||
flags = IS_DECLARATION;
|
||||
else
|
||||
flags = IS_REFERENCE;
|
||||
int flags= getRoleOfName(name);
|
||||
|
||||
flags |= binding.getAdditionalNameFlags(flags, name);
|
||||
db.putByte(record + FLAGS, (byte) flags);
|
||||
|
@ -103,6 +98,21 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
|
|||
db.putShort(record + NODE_LENGTH_OFFSET, (short) fileloc.getNodeLength());
|
||||
}
|
||||
|
||||
private int getRoleOfName(IASTName name) {
|
||||
if (name.isDefinition()) {
|
||||
return IS_DEFINITION;
|
||||
}
|
||||
if (name.isDeclaration()) {
|
||||
return IS_DECLARATION;
|
||||
}
|
||||
|
||||
// special case a using-declaration is a declaration and a reference at the same time.
|
||||
if (name.getBinding() instanceof ICPPUsingDeclaration) {
|
||||
return IS_DEFINITION;
|
||||
}
|
||||
return IS_REFERENCE;
|
||||
}
|
||||
|
||||
public PDOMName(PDOM pdom, int nameRecord) {
|
||||
this.pdom = pdom;
|
||||
this.record = nameRecord;
|
||||
|
@ -350,7 +360,7 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
|
|||
}
|
||||
|
||||
public IIndexName[] getEnclosedNames() throws CoreException {
|
||||
ArrayList result= new ArrayList();
|
||||
ArrayList<PDOMName> result= new ArrayList<PDOMName>();
|
||||
PDOMName name= getNextInFile();
|
||||
while (name != null) {
|
||||
if (name.getEnclosingDefinitionRecord() == record) {
|
||||
|
@ -358,6 +368,6 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
|
|||
}
|
||||
name= name.getNextInFile();
|
||||
}
|
||||
return (IIndexName[]) result.toArray(new IIndexName[result.size()]);
|
||||
return result.toArray(new PDOMName[result.size()]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,10 +58,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPBasicType;
|
||||
import org.eclipse.cdt.internal.core.Util;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMASTAdapter;
|
||||
|
@ -785,6 +787,16 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
|
|||
if (binding instanceof ICPPMethod) {
|
||||
return null;
|
||||
}
|
||||
if (binding instanceof ICPPUsingDeclaration || binding instanceof ICPPNamespaceAlias) {
|
||||
if (pdom instanceof WritablePDOM) {
|
||||
final WritablePDOM wpdom= (WritablePDOM) pdom;
|
||||
String path= ASTInternal.getDeclaredInOneFileOnly(binding);
|
||||
if (path != null) {
|
||||
return wpdom.getFileForASTPath(getLinkageID(), path);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return super.getLocalToFile(binding);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Google, Inc and others.
|
||||
* Copyright (c) 2008 Google, 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
|
||||
|
@ -33,10 +33,13 @@ import org.eclipse.core.runtime.CoreException;
|
|||
* @see ICPPUsingDeclaration
|
||||
*/
|
||||
class PDOMCPPUsingDeclaration extends PDOMCPPBinding implements ICPPUsingDeclaration {
|
||||
@SuppressWarnings("static-access")
|
||||
private static final int TARGET_BINDING = PDOMCPPBinding.RECORD_SIZE + 0;
|
||||
// Using declarations for functions may have multiple delegates. We model such case
|
||||
// by creating a chain of PDOMCPPUsingDeclaration objects linked by NEXT_DELEGATE field.
|
||||
@SuppressWarnings("static-access")
|
||||
private static final int NEXT_DELEGATE = PDOMCPPBinding.RECORD_SIZE + 4;
|
||||
@SuppressWarnings({ "hiding", "static-access" })
|
||||
protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 8;
|
||||
private ICPPDelegate[] delegates;
|
||||
|
||||
|
@ -116,10 +119,4 @@ class PDOMCPPUsingDeclaration extends PDOMCPPBinding implements ICPPUsingDeclara
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasDeclaration() throws CoreException {
|
||||
// TODO(sprigogin) I'm not sure if returning unconditional true is legitimate,
|
||||
// but I couldn't figure out a better way to satisfy DeclaredBindingsFilter#acceptBinding.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue