mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Fix for 161216, store static variables and functions in index.
This commit is contained in:
parent
841997be25
commit
b84f87ee1a
11 changed files with 384 additions and 160 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems and others.
|
||||
* Copyright (c) 2006, 2007 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
|
||||
|
@ -23,10 +23,16 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
|||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexFile;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IIndexName;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||
import org.eclipse.cdt.internal.core.CCoreInternals;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -204,25 +210,35 @@ public class DefDeclTests extends PDOMTestBase {
|
|||
assertDefDeclRef("foo", "06", 1, 1, 1);
|
||||
}
|
||||
|
||||
public void testWrongMatchedStaticDefinition_unexpected() throws Exception {
|
||||
assertDefDeclRef("foo", "07", 1, 1, 1);
|
||||
public void testWrongMatchedStaticDefinition() throws Exception {
|
||||
assertDefDeclRef("foo", "07", 0, 1, 1);
|
||||
}
|
||||
|
||||
public void testStaticBindings_f08_unexpected() throws Exception {
|
||||
// should be 2 bindings, otherwise how to distinguish proper def/decl
|
||||
// pairs?
|
||||
// static elements cannot be found on global scope, see bug 161216
|
||||
public void testStaticBindings_f08() throws Exception {
|
||||
String elName = "foo" + "08";
|
||||
IBinding[] binds = pdom.findBindings(Pattern.compile(elName), true,
|
||||
IndexFilter.ALL, new NullProgressMonitor());
|
||||
assertEquals(0, binds.length);
|
||||
// assertEquals(elName, binds[0].getName());
|
||||
// IBinding element = binds[0];
|
||||
// IBinding binding = element;
|
||||
// checkDefinition(binding, "def" + "08", 2);
|
||||
// checkReference(binding, "ref" + "08", 2);
|
||||
// checkDefinition(binding, "defS" + "08", 2);
|
||||
// checkReference(binding, "refS" + "08", 2);
|
||||
|
||||
IIndexFileLocation ifl= IndexLocationFactory.getIFL((ITranslationUnit) cproject.findElement(new Path("func.c")));
|
||||
IIndexFile file= pdom.getFile(ifl);
|
||||
int offset= TestSourceReader.indexOfInFile("foo08();", new Path(ifl.getFullPath()));
|
||||
IIndexName[] names= file.findNames(offset, 5);
|
||||
assertEquals(1, names.length);
|
||||
|
||||
IBinding element = pdom.findBinding((IIndexFragmentName)names[0]);
|
||||
assertEquals(elName, element.getName());
|
||||
checkDefinition(element, "def" + "08", 1);
|
||||
checkReference(element, "ref" + "08", 1);
|
||||
|
||||
// check the other file
|
||||
ifl= IndexLocationFactory.getIFL((ITranslationUnit) cproject.findElement(new Path("second.c")));
|
||||
file= pdom.getFile(ifl);
|
||||
offset= TestSourceReader.indexOfInFile("foo08();", new Path(ifl.getFullPath()));
|
||||
names= file.findNames(offset, 5);
|
||||
assertEquals(1, names.length);
|
||||
|
||||
element = pdom.findBinding((IIndexFragmentName)names[0]);
|
||||
assertEquals(elName, element.getName());
|
||||
checkDefinition(element, "defS" + "08", 1);
|
||||
checkReference(element, "refS" + "08", 1);
|
||||
}
|
||||
|
||||
public void testSimpleGlobalWrite_v09() throws Exception {
|
||||
|
@ -263,7 +279,7 @@ public class DefDeclTests extends PDOMTestBase {
|
|||
assertDefDeclRef("type", "_t03", 1, 1, 1);
|
||||
}
|
||||
|
||||
public void _testStructAndTypedef_t04_unexpected() throws Exception {
|
||||
public void testStructAndTypedef_t04() throws Exception {
|
||||
String num = "_t04";
|
||||
String elName = "type" + num;
|
||||
|
||||
|
@ -274,7 +290,7 @@ public class DefDeclTests extends PDOMTestBase {
|
|||
IBinding struct = bindings[0] instanceof ICompositeType ? bindings[0] : bindings[1];
|
||||
|
||||
checkReference(typedef, "ref" + num, 1);
|
||||
checkDeclaration(typedef, "def" + num, 1);
|
||||
checkDefinition(typedef, "def" + num, 1);
|
||||
|
||||
checkReference(struct, "refS" + num, 1);
|
||||
checkDefinition(struct, "defS" + num, 1);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2007 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
|
||||
|
@ -12,6 +12,7 @@
|
|||
package org.eclipse.cdt.core.index;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Represents the semantics of a name in the index.
|
||||
|
@ -35,4 +36,11 @@ public interface IIndexBinding extends IBinding {
|
|||
* Returns the qualified name of this binding as array of strings.
|
||||
*/
|
||||
String[] getQualifiedName();
|
||||
|
||||
/**
|
||||
* Returns whether the scope of the binding is file-local. A file local
|
||||
* binding is private to an index and should not be adapted to a binding
|
||||
* in another index.
|
||||
*/
|
||||
boolean isFileLocal() throws CoreException;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2007 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
|
||||
|
@ -165,7 +165,6 @@ public class CPPField extends CPPVariable implements ICPPField, ICPPInternalBind
|
|||
}
|
||||
|
||||
public ICompositeType getCompositeTypeOwner() throws DOMException {
|
||||
// mstodo Auto-generated method stub
|
||||
return null;
|
||||
return getClassOwner();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
|||
|
||||
private Database db;
|
||||
|
||||
public static final int VERSION = 22;
|
||||
public static final int VERSION = 24;
|
||||
// 0 - the beginning of it all
|
||||
// 1 - first change to kick off upgrades
|
||||
// 2 - added file inclusions
|
||||
|
@ -97,6 +97,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
|||
// 21 - change representation of paths in the pdom (167549)
|
||||
// 22 - fix inheritance relations (167396)
|
||||
// 23 - types on c-variables, return types on c-functions
|
||||
// 24 - file local scopes (161216)
|
||||
|
||||
public static final int LINKAGES = Database.DATA_AREA;
|
||||
public static final int FILE_INDEX = Database.DATA_AREA + 4;
|
||||
|
|
|
@ -11,27 +11,17 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IPDOMNode;
|
||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Visitor to find bindings in a BTree or below a PDOMNode. Nested bindings are not visited.
|
||||
* @since 4.0
|
||||
*/
|
||||
public final class BindingCollector implements IBTreeVisitor, IPDOMVisitor {
|
||||
private final PDOMLinkage linkage;
|
||||
private final char[] name;
|
||||
private final boolean prefixLookup;
|
||||
public final class BindingCollector extends NamedNodeCollector {
|
||||
private IndexFilter filter;
|
||||
|
||||
private List bindings = new ArrayList();
|
||||
|
||||
/**
|
||||
* Collects all bindings with given name.
|
||||
|
@ -45,55 +35,21 @@ public final class BindingCollector implements IBTreeVisitor, IPDOMVisitor {
|
|||
* <code>true</code> a binding is considered if its name starts with the given prefix.
|
||||
*/
|
||||
public BindingCollector(PDOMLinkage linkage, char[] name, IndexFilter filter, boolean prefixLookup) {
|
||||
this.name = name;
|
||||
this.linkage= linkage;
|
||||
super(linkage, name, prefixLookup);
|
||||
this.filter= filter;
|
||||
this.prefixLookup = prefixLookup;
|
||||
}
|
||||
|
||||
public int compare(int record) throws CoreException {
|
||||
PDOMNamedNode node = ((PDOMNamedNode)linkage.getNode(record));
|
||||
return compare(node);
|
||||
}
|
||||
|
||||
private int compare(PDOMNamedNode node) throws CoreException {
|
||||
if (prefixLookup) {
|
||||
return node.getDBName().comparePrefix(name);
|
||||
}
|
||||
return node.getDBName().compare(name);
|
||||
}
|
||||
|
||||
public boolean visit(int record) throws CoreException {
|
||||
if (record == 0)
|
||||
return true;
|
||||
|
||||
PDOMBinding tBinding = linkage.getPDOM().getBinding(record);
|
||||
if (tBinding != null) {
|
||||
visit(tBinding);
|
||||
public boolean addNode(PDOMNamedNode tBinding) {
|
||||
if (tBinding instanceof IBinding) {
|
||||
if (filter == null || filter.acceptBinding((IBinding) tBinding)) {
|
||||
return super.addNode(tBinding);
|
||||
}
|
||||
}
|
||||
return true; // look for more
|
||||
}
|
||||
|
||||
private void visit(PDOMBinding tBinding) {
|
||||
if (filter == null || filter.acceptBinding(tBinding)) {
|
||||
bindings.add(tBinding);
|
||||
}
|
||||
}
|
||||
|
||||
public IBinding[] getBindings() {
|
||||
List bindings= getNodeList();
|
||||
return (IBinding[])bindings.toArray(new IBinding[bindings.size()]);
|
||||
}
|
||||
|
||||
public boolean visit(IPDOMNode node) throws CoreException {
|
||||
if (node instanceof PDOMBinding) {
|
||||
PDOMBinding pb= (PDOMBinding) node;
|
||||
if (compare(pb) == 0) {
|
||||
visit(pb);
|
||||
}
|
||||
}
|
||||
return false; // don't visit children
|
||||
}
|
||||
|
||||
public void leave(IPDOMNode node) throws CoreException {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IPDOMNode;
|
||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Visitor to find named nodes in a BTree or below a PDOMNode. Nested nodes are not visited.
|
||||
* @since 4.0
|
||||
*/
|
||||
public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor {
|
||||
private final PDOMLinkage linkage;
|
||||
private final char[] name;
|
||||
private final boolean prefixLookup;
|
||||
|
||||
private List nodes = new ArrayList();
|
||||
|
||||
/**
|
||||
* Collects all nodes with given name.
|
||||
*/
|
||||
public NamedNodeCollector(PDOMLinkage linkage, char[] name) {
|
||||
this(linkage, name, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects all nodes with given name, passing the filter. If prefixLookup is set to
|
||||
* <code>true</code> a binding is considered if its name starts with the given prefix.
|
||||
*/
|
||||
public NamedNodeCollector(PDOMLinkage linkage, char[] name, boolean prefixLookup) {
|
||||
this.name = name;
|
||||
this.linkage= linkage;
|
||||
this.prefixLookup = prefixLookup;
|
||||
}
|
||||
|
||||
final public int compare(int record) throws CoreException {
|
||||
PDOMNamedNode node = ((PDOMNamedNode)linkage.getNode(record));
|
||||
return compare(node);
|
||||
}
|
||||
|
||||
private int compare(PDOMNamedNode node) throws CoreException {
|
||||
if (prefixLookup) {
|
||||
return node.getDBName().comparePrefix(name);
|
||||
}
|
||||
return node.getDBName().compare(name);
|
||||
}
|
||||
|
||||
final public boolean visit(int record) throws CoreException {
|
||||
if (record == 0)
|
||||
return true;
|
||||
|
||||
PDOMNode node= linkage.getNode(record);
|
||||
if (node instanceof PDOMNamedNode) {
|
||||
return addNode((PDOMNamedNode) node);
|
||||
}
|
||||
return true; // look for more
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true to continue the visit.
|
||||
*/
|
||||
protected boolean addNode(PDOMNamedNode node) {
|
||||
nodes.add(node);
|
||||
return true; // look for more
|
||||
}
|
||||
|
||||
final protected List getNodeList() {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
final public PDOMNamedNode[] getNodes() {
|
||||
return (PDOMNamedNode[])nodes.toArray(new PDOMNamedNode[nodes.size()]);
|
||||
}
|
||||
|
||||
final public boolean visit(IPDOMNode node) throws CoreException {
|
||||
if (node instanceof PDOMNamedNode) {
|
||||
PDOMNamedNode pb= (PDOMNamedNode) node;
|
||||
if (compare(pb) == 0) {
|
||||
addNode(pb);
|
||||
}
|
||||
}
|
||||
return false; // don't visit children
|
||||
}
|
||||
|
||||
final public void leave(IPDOMNode node) throws CoreException {
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2006 QNX Software Systems and others.
|
||||
* Copyright (c) 2005, 2007 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
|
||||
|
@ -234,4 +234,8 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final public boolean isFileLocal() throws CoreException {
|
||||
return getParentNode() instanceof PDOMFileLocalScope;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class PDOMFileLocalScope extends PDOMNamedNode implements IPDOMMemberOwner {
|
||||
private static final int MEMBERLIST = PDOMNamedNode.RECORD_SIZE;
|
||||
private static final int RECORD_SIZE = MEMBERLIST+4;
|
||||
|
||||
|
||||
public PDOMFileLocalScope(PDOM pdom, PDOMNode parent, char[] name) throws CoreException {
|
||||
super(pdom, parent, name);
|
||||
}
|
||||
|
||||
public PDOMFileLocalScope(PDOM pdom, int record) {
|
||||
super(pdom, record);
|
||||
}
|
||||
|
||||
protected int getRecordSize() {
|
||||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMLinkage.FILE_LOCAL_SCOPE_TYPE;
|
||||
}
|
||||
|
||||
public void accept(IPDOMVisitor visitor) throws CoreException {
|
||||
super.accept(visitor);
|
||||
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl());
|
||||
list.accept(visitor);
|
||||
}
|
||||
|
||||
public void addMember(PDOMNode member) throws CoreException {
|
||||
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl());
|
||||
list.addMember(member);
|
||||
}
|
||||
|
||||
public void addChild(PDOMNode child) throws CoreException {
|
||||
addMember(child);
|
||||
}
|
||||
}
|
|
@ -59,12 +59,13 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
|||
protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 12;
|
||||
|
||||
// node types
|
||||
protected static final int LINKAGE = 0; // special one for myself
|
||||
static final int POINTER_TYPE = 1;
|
||||
static final int ARRAY_TYPE = 2;
|
||||
static final int QUALIFIER_TYPE = 3;
|
||||
protected static final int LINKAGE= 0; // special one for myself
|
||||
static final int POINTER_TYPE= 1;
|
||||
static final int ARRAY_TYPE= 2;
|
||||
static final int QUALIFIER_TYPE= 3;
|
||||
static final int FILE_LOCAL_SCOPE_TYPE= 4;
|
||||
|
||||
protected static final int LAST_NODE_TYPE = QUALIFIER_TYPE;
|
||||
protected static final int LAST_NODE_TYPE = FILE_LOCAL_SCOPE_TYPE;
|
||||
|
||||
public PDOMLinkage(PDOM pdom, int record) {
|
||||
super(pdom, record);
|
||||
|
@ -144,6 +145,8 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
|||
return new PDOMArrayType(pdom, record);
|
||||
case QUALIFIER_TYPE:
|
||||
return new PDOMQualifierType(pdom, record);
|
||||
case FILE_LOCAL_SCOPE_TYPE:
|
||||
return new PDOMFileLocalScope(pdom, record);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -178,17 +181,28 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
|||
/**
|
||||
*
|
||||
* @param binding
|
||||
* @param createFileLocalScope if <code>true</code> the creation of a file local
|
||||
* scope object is allowed.
|
||||
* @return <ul><li> null - skip this binding (don't add to pdom)
|
||||
* <li>this - for filescope
|
||||
* <li>a PDOMBinding instance - parent adapted binding
|
||||
* </ul>
|
||||
* @throws CoreException
|
||||
*/
|
||||
public PDOMNode getAdaptedParent(IBinding binding) throws CoreException {
|
||||
protected PDOMNode getAdaptedParent(IBinding binding, boolean createFileLocalScope) throws CoreException {
|
||||
try {
|
||||
IScope scope = binding.getScope();
|
||||
if (scope == null) {
|
||||
return binding instanceof PDOMBinding ? this : null;
|
||||
if (binding instanceof IIndexBinding) {
|
||||
IIndexBinding ib= (IIndexBinding) binding;
|
||||
// don't adapt file local bindings from other fragments to this one.
|
||||
if (ib.isFileLocal()) {
|
||||
return null;
|
||||
}
|
||||
// in an index the null scope represents global scope.
|
||||
return this;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (scope instanceof IIndexBinding) {
|
||||
|
@ -207,8 +221,13 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
|||
IASTNode scopeNode = ASTInternal.getPhysicalNodeOfScope(scope);
|
||||
if (scopeNode instanceof IASTCompoundStatement)
|
||||
return null;
|
||||
else if (scopeNode instanceof IASTTranslationUnit)
|
||||
else if (scopeNode instanceof IASTTranslationUnit) {
|
||||
if (isFileLocalBinding(binding)) {
|
||||
IASTTranslationUnit tu= (IASTTranslationUnit) scopeNode;
|
||||
return findFileLocalScope(tu.getFilePath(), createFileLocalScope);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
else {
|
||||
IName scopeName = scope.getScopeName();
|
||||
if (scopeName instanceof IASTName) {
|
||||
|
@ -224,6 +243,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
|||
return null;
|
||||
}
|
||||
|
||||
protected abstract boolean isFileLocalBinding(IBinding binding) throws DOMException;
|
||||
public abstract int getBindingType(IBinding binding);
|
||||
|
||||
public IBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) throws CoreException {
|
||||
|
@ -263,4 +283,51 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
|||
*/
|
||||
public void onDeleteName(PDOMName nextName) throws CoreException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the a file local scope object. If none is found depending
|
||||
* on the value of the parameter 'create' such an object is created.
|
||||
* @param fileName
|
||||
* @param create
|
||||
* @since 4.0
|
||||
*/
|
||||
final protected PDOMFileLocalScope findFileLocalScope(String fileName, boolean create) throws CoreException {
|
||||
char[] fname= fileName.toCharArray();
|
||||
int fnamestart= findFileNameStart(fname);
|
||||
StringBuffer buf= new StringBuffer();
|
||||
buf.append('{');
|
||||
buf.append(fname, fnamestart, fname.length-fnamestart);
|
||||
buf.append(':');
|
||||
buf.append(fileName.hashCode());
|
||||
buf.append('}');
|
||||
fname= buf.toString().toCharArray();
|
||||
|
||||
final PDOMFileLocalScope[] fls= new PDOMFileLocalScope[] {null};
|
||||
NamedNodeCollector collector= new NamedNodeCollector(this, fname) {
|
||||
public boolean addNode(PDOMNamedNode node) {
|
||||
if (node instanceof PDOMFileLocalScope) {
|
||||
fls[0]= (PDOMFileLocalScope) node;
|
||||
return false; // done
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
getIndex().accept(collector);
|
||||
if (fls[0] == null && create) {
|
||||
fls[0]= new PDOMFileLocalScope(pdom, this, fname);
|
||||
addChild(fls[0]);
|
||||
}
|
||||
return fls[0];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,6 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
|
|||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.internal.core.Util;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
|
||||
|
@ -79,53 +77,45 @@ class PDOMCLinkage extends PDOMLinkage {
|
|||
|
||||
public PDOMBinding addBinding(IBinding binding) throws CoreException {
|
||||
PDOMBinding pdomBinding = adaptBinding(binding);
|
||||
try {
|
||||
if (pdomBinding == null) {
|
||||
PDOMNode parent = getAdaptedParent(binding);
|
||||
if (parent == null)
|
||||
return null;
|
||||
|
||||
// assign names to anonymous types.
|
||||
binding= PDOMASTAdapter.getAdapterIfAnonymous(binding);
|
||||
if (pdomBinding == null) {
|
||||
PDOMNode parent = getAdaptedParent(binding, true);
|
||||
if (parent == null)
|
||||
return null;
|
||||
|
||||
// assign names to anonymous types.
|
||||
binding= PDOMASTAdapter.getAdapterIfAnonymous(binding);
|
||||
|
||||
if (binding == null || binding instanceof IParameter)
|
||||
return null; // skip parameters
|
||||
|
||||
if (binding instanceof IField) { // must be before IVariable
|
||||
if (parent instanceof IPDOMMemberOwner)
|
||||
pdomBinding = new PDOMCField(pdom, (IPDOMMemberOwner)parent, (IField) binding);
|
||||
} else if (binding instanceof IVariable) {
|
||||
IVariable var= (IVariable) binding;
|
||||
if (!var.isStatic()) { // bug 161216
|
||||
pdomBinding = new PDOMCVariable(pdom, parent, var);
|
||||
}
|
||||
} else if (binding instanceof IFunction) {
|
||||
IFunction func= (IFunction) binding;
|
||||
if (!func.isStatic()) { // bug 161216
|
||||
pdomBinding = new PDOMCFunction(pdom, parent, func);
|
||||
}
|
||||
} else if (binding instanceof ICompositeType)
|
||||
pdomBinding = new PDOMCStructure(pdom, parent, (ICompositeType) binding);
|
||||
else if (binding instanceof IEnumeration)
|
||||
pdomBinding = new PDOMCEnumeration(pdom, parent, (IEnumeration) binding);
|
||||
else if (binding instanceof IEnumerator) {
|
||||
try {
|
||||
IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType();
|
||||
PDOMBinding pdomEnumeration = adaptBinding(enumeration);
|
||||
if (pdomEnumeration instanceof PDOMCEnumeration)
|
||||
pdomBinding = new PDOMCEnumerator(pdom, parent, (IEnumerator) binding, (PDOMCEnumeration)pdomEnumeration);
|
||||
} catch (DOMException e) {
|
||||
throw new CoreException(Util.createStatus(e));
|
||||
}
|
||||
} else if (binding instanceof ITypedef)
|
||||
pdomBinding = new PDOMCTypedef(pdom, parent, (ITypedef)binding);
|
||||
|
||||
if(pdomBinding!=null) {
|
||||
parent.addChild(pdomBinding);
|
||||
if (binding == null || binding instanceof IParameter)
|
||||
return null; // skip parameters
|
||||
|
||||
if (binding instanceof IField) { // must be before IVariable
|
||||
if (parent instanceof IPDOMMemberOwner)
|
||||
pdomBinding = new PDOMCField(pdom, (IPDOMMemberOwner)parent, (IField) binding);
|
||||
} else if (binding instanceof IVariable) {
|
||||
IVariable var= (IVariable) binding;
|
||||
pdomBinding = new PDOMCVariable(pdom, parent, var);
|
||||
} else if (binding instanceof IFunction) {
|
||||
IFunction func= (IFunction) binding;
|
||||
pdomBinding = new PDOMCFunction(pdom, parent, func);
|
||||
} else if (binding instanceof ICompositeType)
|
||||
pdomBinding = new PDOMCStructure(pdom, parent, (ICompositeType) binding);
|
||||
else if (binding instanceof IEnumeration)
|
||||
pdomBinding = new PDOMCEnumeration(pdom, parent, (IEnumeration) binding);
|
||||
else if (binding instanceof IEnumerator) {
|
||||
try {
|
||||
IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType();
|
||||
PDOMBinding pdomEnumeration = adaptBinding(enumeration);
|
||||
if (pdomEnumeration instanceof PDOMCEnumeration)
|
||||
pdomBinding = new PDOMCEnumerator(pdom, parent, (IEnumerator) binding, (PDOMCEnumeration)pdomEnumeration);
|
||||
} catch (DOMException e) {
|
||||
throw new CoreException(Util.createStatus(e));
|
||||
}
|
||||
} else if (binding instanceof ITypedef)
|
||||
pdomBinding = new PDOMCTypedef(pdom, parent, (ITypedef)binding);
|
||||
|
||||
if(pdomBinding!=null) {
|
||||
parent.addChild(pdomBinding);
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
throw new CoreException(Util.createStatus(e));
|
||||
}
|
||||
return pdomBinding;
|
||||
}
|
||||
|
@ -186,7 +176,7 @@ class PDOMCLinkage extends PDOMLinkage {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
PDOMNode parent = getAdaptedParent(binding);
|
||||
PDOMNode parent = getAdaptedParent(binding, false);
|
||||
|
||||
if (parent == this) {
|
||||
return FindBinding.findBinding(getIndex(), getPDOM(), binding.getNameCharArray(), new int[] {getBindingType(binding)});
|
||||
|
@ -262,7 +252,18 @@ class PDOMCLinkage extends PDOMLinkage {
|
|||
return new FindBinding.DefaultBindingBTreeComparator(getPDOM());
|
||||
}
|
||||
|
||||
public IBinding findInGlobalScope(String filePath, IASTName name) throws CoreException {
|
||||
return null;
|
||||
protected boolean isFileLocalBinding(IBinding binding) throws DOMException {
|
||||
if (binding instanceof IField) {
|
||||
return false;
|
||||
}
|
||||
if (binding instanceof IVariable) {
|
||||
IVariable var= (IVariable) binding;
|
||||
return var.isStatic();
|
||||
}
|
||||
if (binding instanceof IFunction) {
|
||||
IFunction f= (IFunction) binding;
|
||||
return f.isStatic();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,8 +40,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
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.GPPLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.internal.core.Util;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction;
|
||||
|
@ -128,10 +126,16 @@ class PDOMCPPLinkage extends PDOMLinkage {
|
|||
}
|
||||
|
||||
private PDOMBinding addBinding(IBinding binding) throws CoreException {
|
||||
// assign names to anonymous types.
|
||||
binding= PDOMASTAdapter.getAdapterIfAnonymous(binding);
|
||||
if (binding == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PDOMBinding pdomBinding = adaptBinding(binding);
|
||||
try {
|
||||
if (pdomBinding == null) {
|
||||
PDOMNode parent = getAdaptedParent(binding);
|
||||
PDOMNode parent = getAdaptedParent(binding, true);
|
||||
if (parent == null)
|
||||
return null;
|
||||
pdomBinding = addBinding(parent, binding);
|
||||
|
@ -146,32 +150,25 @@ class PDOMCPPLinkage extends PDOMLinkage {
|
|||
private PDOMBinding addBinding(PDOMNode parent, IBinding binding) throws CoreException, DOMException {
|
||||
PDOMBinding pdomBinding= null;
|
||||
|
||||
// assign names to anonymous types.
|
||||
binding= PDOMASTAdapter.getAdapterIfAnonymous(binding);
|
||||
if (binding == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (binding instanceof ICPPField && parent instanceof PDOMCPPClassType)
|
||||
pdomBinding = new PDOMCPPField(pdom, (PDOMCPPClassType)parent, (ICPPField) binding);
|
||||
else if (binding instanceof ICPPVariable && !(binding.getScope() instanceof CPPBlockScope)) {
|
||||
if (binding instanceof ICPPField ) {
|
||||
if (parent instanceof PDOMCPPClassType) {
|
||||
pdomBinding = new PDOMCPPField(pdom, (PDOMCPPClassType)parent, (ICPPField) binding);
|
||||
}
|
||||
} else if (binding instanceof ICPPVariable) {
|
||||
if (!(binding.getScope() instanceof CPPBlockScope)) {
|
||||
ICPPVariable var= (ICPPVariable) binding;
|
||||
if (!var.isStatic()) { // bug 161216
|
||||
pdomBinding = new PDOMCPPVariable(pdom, parent, var);
|
||||
}
|
||||
pdomBinding = new PDOMCPPVariable(pdom, parent, var);
|
||||
}
|
||||
} else if (binding instanceof ICPPConstructor) {
|
||||
if (parent instanceof PDOMCPPClassType) {
|
||||
pdomBinding = new PDOMCPPConstructor(pdom, parent, (ICPPConstructor)binding);
|
||||
}
|
||||
} else if (binding instanceof ICPPMethod) {
|
||||
if (parent instanceof PDOMCPPClassType) {
|
||||
pdomBinding = new PDOMCPPMethod(pdom, parent, (ICPPMethod)binding);
|
||||
}
|
||||
} else if (binding instanceof ICPPConstructor && parent instanceof PDOMCPPClassType) {
|
||||
pdomBinding = new PDOMCPPConstructor(pdom, parent, (ICPPConstructor)binding);
|
||||
} else if (binding instanceof ICPPMethod && parent instanceof PDOMCPPClassType) {
|
||||
pdomBinding = new PDOMCPPMethod(pdom, parent, (ICPPMethod)binding);
|
||||
} else if (binding instanceof ICPPFunction) {
|
||||
ICPPFunction func = (ICPPFunction)binding;
|
||||
if (binding instanceof ICPPInternalFunction) {
|
||||
if (!((ICPPInternalFunction)binding).isStatic(false))
|
||||
pdomBinding = new PDOMCPPFunction(pdom, parent, func);
|
||||
} else
|
||||
pdomBinding = new PDOMCPPFunction(pdom, parent, func);
|
||||
pdomBinding = new PDOMCPPFunction(pdom, parent, (ICPPFunction) binding);
|
||||
} else if (binding instanceof ICPPClassType) {
|
||||
pdomBinding= new PDOMCPPClassType(pdom, parent, (ICPPClassType) binding);
|
||||
} else if (binding instanceof ICPPNamespaceAlias) {
|
||||
|
@ -269,7 +266,7 @@ class PDOMCPPLinkage extends PDOMLinkage {
|
|||
}
|
||||
}
|
||||
|
||||
PDOMNode parent = getAdaptedParent(binding);
|
||||
PDOMNode parent = getAdaptedParent(binding, false);
|
||||
|
||||
if (parent == this) {
|
||||
return CPPFindBinding.findBinding(getIndex(), this, binding);
|
||||
|
@ -392,4 +389,25 @@ class PDOMCPPLinkage extends PDOMLinkage {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isFileLocalBinding(IBinding binding) throws DOMException {
|
||||
if (binding instanceof ICPPField) {
|
||||
return false;
|
||||
}
|
||||
if (binding instanceof ICPPVariable) {
|
||||
if (!(binding.getScope() instanceof CPPBlockScope)) {
|
||||
ICPPVariable var= (ICPPVariable) binding;
|
||||
return var.isStatic();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (binding instanceof ICPPMethod) {
|
||||
return false;
|
||||
}
|
||||
if (binding instanceof ICPPInternalFunction) {
|
||||
ICPPInternalFunction func = (ICPPInternalFunction)binding;
|
||||
return func.isStatic(false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue