1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-07 08:15:48 +02:00

PDOM - Added Handling for C++ namespaces.

This commit is contained in:
Doug Schaefer 2006-02-02 21:27:14 +00:00
parent 8811ecbb05
commit 59830a2ba7
8 changed files with 346 additions and 8 deletions

View file

@ -55,6 +55,8 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.internal.core.pdom,
org.eclipse.cdt.internal.core.pdom.db,
org.eclipse.cdt.internal.core.pdom.dom,
org.eclipse.cdt.internal.core.pdom.dom.c,
org.eclipse.cdt.internal.core.pdom.dom.cpp,
org.eclipse.cdt.internal.core.search,
org.eclipse.cdt.internal.core.search.indexing,
org.eclipse.cdt.internal.core.search.matching,

View file

@ -42,6 +42,13 @@ public interface ICPPASTQualifiedName extends IASTName, IASTNameOwner {
*/
public IASTName[] getNames();
/**
* The last name is often semantically significant.
*
* @return
*/
public IASTName getLastName();
/**
* Is this name fully qualified?
*

View file

@ -41,12 +41,14 @@ public class CPPASTQualifiedName extends CPPASTNode implements
public IBinding resolveBinding() {
// The full qualified name resolves to the same thing as the last name
removeNullNames();
return names[names.length - 1].resolveBinding();
IASTName lastName = getLastName();
return lastName != null ? lastName.resolveBinding() : null;
}
public IBinding[] resolvePrefix() {
removeNullNames();
return names[names.length - 1].resolvePrefix();
IASTName lastName = getLastName();
return lastName != null ? lastName.resolvePrefix() : new IBinding[0];
}
/*
@ -96,6 +98,13 @@ public class CPPASTQualifiedName extends CPPASTNode implements
return names;
}
public IASTName getLastName() {
if (names == null || names.length == 0)
return null;
return names[names.length - 1];
}
/*
* (non-Javadoc)
*

View file

@ -162,7 +162,8 @@ public class CPPVisitor {
parent instanceof ICPPASTTemplateId )
{
binding = CPPSemantics.resolveBinding( name );
if( binding instanceof IProblemBinding && parent instanceof ICPPASTQualifiedName )
if( binding instanceof IProblemBinding && parent instanceof ICPPASTQualifiedName
&& !(parent.getParent() instanceof ICPPASTNamespaceAlias))
{
if( ((IProblemBinding)binding).getID() == IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND ){
IASTNode node = getContainingBlockItem( name.getParent() );

View file

@ -19,10 +19,14 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope;
@ -30,6 +34,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPField;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethod;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNamespace;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNamespaceAlias;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable;
import org.eclipse.cdt.internal.core.pdom.PDOMDatabase;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
@ -65,6 +71,8 @@ public class PDOMCPPLinkage extends PDOMLinkage {
public static final int CPPCLASSTYPE = 3;
public static final int CPPFIELD = 4;
public static final int CPPMETHOD = 5;
public static final int CPPNAMESPACE = 6;
public static final int CPPNAMESPACEALIAS = 7;
public PDOMNode getParent(IBinding binding) throws CoreException {
PDOMNode parent = this;
@ -82,7 +90,8 @@ public class PDOMCPPLinkage extends PDOMLinkage {
}
public PDOMBinding addName(IASTName name) throws CoreException {
if (name == null || name.toCharArray().length == 0)
if (name == null || name.toCharArray().length == 0
|| name instanceof ICPPASTQualifiedName)
return null;
IBinding binding = name.resolveBinding();
@ -105,6 +114,10 @@ public class PDOMCPPLinkage extends PDOMLinkage {
pdomBinding = new PDOMCPPFunction(pdom, parent, name);
} else if (binding instanceof CPPClassType) {
pdomBinding = new PDOMCPPClassType(pdom, parent, name);
} else if (binding instanceof CPPNamespaceAlias) {
pdomBinding = new PDOMCPPNamespaceAlias(pdom, parent, name);
} else if (binding instanceof CPPNamespace) {
pdomBinding = new PDOMCPPNamespace(pdom, parent, name);
}
}
@ -150,6 +163,10 @@ public class PDOMCPPLinkage extends PDOMLinkage {
return CPPFIELD;
else if (binding instanceof ICPPMethod)
return CPPMETHOD;
else if (binding instanceof ICPPNamespaceAlias)
return CPPNAMESPACEALIAS;
else if (binding instanceof ICPPNamespace)
return CPPNAMESPACE;
else
return 0;
}
@ -190,13 +207,23 @@ public class PDOMCPPLinkage extends PDOMLinkage {
return new PDOMCPPField(pdom, record);
case CPPMETHOD:
return new PDOMCPPMethod(pdom, record);
case CPPNAMESPACE:
return new PDOMCPPNamespace(pdom, record);
case CPPNAMESPACEALIAS:
return new PDOMCPPNamespaceAlias(pdom, record);
}
return null;
}
public PDOMBinding resolveBinding(IASTName name) throws CoreException {
if (name instanceof ICPPASTQualifiedName) {
IASTName lastName = ((ICPPASTQualifiedName)name).getLastName();
return lastName != null ? resolveBinding(lastName) : null;
}
IASTNode parent = name.getParent();
if (parent instanceof ICPPASTQualifiedName)
parent = parent.getParent();
if (parent instanceof IASTIdExpression) {
// reference
IASTNode eParent = parent.getParent();
@ -205,7 +232,10 @@ public class PDOMCPPLinkage extends PDOMLinkage {
getIndex().visit(visitor);
return visitor.pdomBinding;
} else {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CPPVARIABLE);
FindBinding visitor = new FindBinding(pdom, name.toCharArray(),
(name.getParent() instanceof ICPPASTQualifiedName
&& ((ICPPASTQualifiedName)name.getParent()).getLastName() != name)
? CPPNAMESPACE : CPPVARIABLE);
getIndex().visit(visitor);
return visitor.pdomBinding;
}
@ -213,7 +243,12 @@ public class PDOMCPPLinkage extends PDOMLinkage {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CPPCLASSTYPE);
getIndex().visit(visitor);
return visitor.pdomBinding;
} else if (parent instanceof ICPPASTNamespaceAlias) {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CPPNAMESPACE);
getIndex().visit(visitor);
return visitor.pdomBinding;
}
return null;
}

View file

@ -0,0 +1,194 @@
/*******************************************************************************
* Copyright (c) 2006 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.internal.core.pdom.PDOMDatabase;
import org.eclipse.cdt.internal.core.pdom.db.BTree;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException;
/**
* @author Doug Schaefer
*
*/
public class PDOMCPPNamespace extends PDOMBinding
implements ICPPNamespace, ICPPNamespaceScope {
private static final int INDEX_OFFSET = PDOMBinding.RECORD_SIZE + 0;
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 4;
public PDOMCPPNamespace(PDOMDatabase pdom, PDOMNode parent, IASTName name) throws CoreException {
super(pdom, parent, name, PDOMCPPLinkage.CPPNAMESPACE);
}
public PDOMCPPNamespace(PDOMDatabase pdom, int record) {
super(pdom, record);
}
protected int getRecordSize() {
return RECORD_SIZE;
}
public BTree getIndex() throws CoreException {
return new BTree(pdom.getDB(), record + INDEX_OFFSET);
}
public void addChild(PDOMNode child) throws CoreException {
getIndex().insert(child.getRecord(), child.getIndexComparator());
}
public String[] getQualifiedName() throws DOMException {
throw new PDOMNotImplementedError();
}
public char[][] getQualifiedNameCharArray() throws DOMException {
throw new PDOMNotImplementedError();
}
public boolean isGloballyQualified() throws DOMException {
throw new PDOMNotImplementedError();
}
public IBinding[] getMemberBindings() throws DOMException {
throw new PDOMNotImplementedError();
}
public ICPPNamespaceScope getNamespaceScope() throws DOMException {
return this;
}
public void addUsingDirective(IASTNode directive) throws DOMException {
throw new PDOMNotImplementedError();
}
public IASTNode[] getUsingDirectives() throws DOMException {
// TODO
return new IASTNode[0];
}
public void addBinding(IBinding binding) throws DOMException {
throw new PDOMNotImplementedError();
}
public void addName(IASTName name) throws DOMException {
throw new PDOMNotImplementedError();
}
public IBinding[] find(String name) throws DOMException {
throw new PDOMNotImplementedError();
}
public void flushCache() throws DOMException {
throw new PDOMNotImplementedError();
}
private static final class FindBinding extends PDOMNode.NodeVisitor {
PDOMBinding pdomBinding;
final int desiredType;
public FindBinding(PDOMDatabase pdom, char[] name, int desiredType) {
super(pdom, name);
this.desiredType = desiredType;
}
public boolean visit(int record) throws CoreException {
if (record == 0)
return true;
PDOMBinding tBinding = pdom.getBinding(record);
if (!tBinding.hasName(name))
// no more bindings with our desired name
return false;
if (tBinding.getBindingType() != desiredType)
// wrong type, try again
return true;
// got it
pdomBinding = tBinding;
return false;
}
}
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
try {
if (name instanceof ICPPASTQualifiedName) {
IASTName lastName = ((ICPPASTQualifiedName)name).getLastName();
return lastName != null ? lastName.resolveBinding() : null;
}
IASTNode parent = name.getParent();
if (parent instanceof ICPPASTQualifiedName)
parent = parent.getParent();
if (parent instanceof IASTIdExpression) {
// reference
IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression) {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), PDOMCPPLinkage.CPPFUNCTION);
getIndex().visit(visitor);
return visitor.pdomBinding;
} else {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(),
(name.getParent() instanceof ICPPASTQualifiedName
&& ((ICPPASTQualifiedName)name.getParent()).getLastName() != name)
? PDOMCPPLinkage.CPPNAMESPACE : PDOMCPPLinkage.CPPVARIABLE);
getIndex().visit(visitor);
return visitor.pdomBinding;
}
} else if (parent instanceof IASTNamedTypeSpecifier) {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE);
getIndex().visit(visitor);
return visitor.pdomBinding;
}
return null;
} catch (CoreException e) {
CCorePlugin.log(e);
return null;
}
}
public IScope getParent() throws DOMException {
// TODO
return null;
}
public IASTNode getPhysicalNode() throws DOMException {
throw new PDOMNotImplementedError();
}
public IASTName getScopeName() throws DOMException {
throw new PDOMNotImplementedError();
}
public boolean isFullyCached() throws DOMException {
return true;
}
public void removeBinding(IBinding binding) throws DOMException {
throw new PDOMNotImplementedError();
}
public void setFullyCached(boolean b) throws DOMException {
throw new PDOMNotImplementedError();
}
}

View file

@ -0,0 +1,73 @@
/*******************************************************************************
* Copyright (c) 2006 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.internal.core.pdom.PDOMDatabase;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException;
/**
* @author Doug Schaefer
*
*/
public class PDOMCPPNamespaceAlias extends PDOMBinding implements
ICPPNamespaceAlias {
public PDOMCPPNamespaceAlias(PDOMDatabase pdom, PDOMNode parent,
IASTName name) throws CoreException {
super(pdom, parent, name, PDOMCPPLinkage.CPPNAMESPACEALIAS);
}
public PDOMCPPNamespaceAlias(PDOMDatabase pdom, int record) {
super(pdom, record);
}
protected int getRecordSize() {
return RECORD_SIZE;
}
public ICPPNamespaceScope getNamespaceScope() throws DOMException {
throw new PDOMNotImplementedError();
}
public IBinding[] getMemberBindings() throws DOMException {
throw new PDOMNotImplementedError();
}
public String[] getQualifiedName() throws DOMException {
throw new PDOMNotImplementedError();
}
public char[][] getQualifiedNameCharArray() throws DOMException {
throw new PDOMNotImplementedError();
}
public boolean isGloballyQualified() throws DOMException {
throw new PDOMNotImplementedError();
}
public int getDelegateType() {
throw new PDOMNotImplementedError();
}
public IBinding getBinding() {
throw new PDOMNotImplementedError();
}
}

View file

@ -11,8 +11,6 @@
package org.eclipse.cdt.internal.ui.indexview;
import java.util.ArrayList;
import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.PDOM;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
@ -21,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICModel;
@ -35,6 +34,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMMember;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMemberOwner;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPNamespace;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
import org.eclipse.cdt.ui.CUIPlugin;
@ -217,6 +217,19 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
} else if (parentElement instanceof PDOMCPPNamespace) {
try {
PDOMCPPNamespace namespace = (PDOMCPPNamespace)parentElement;
PDOMDatabase pdom = namespace.getPDOM();
Counter counter = new Counter(pdom);
namespace.getIndex().visit(counter);
PDOMBinding[] bindings = new PDOMBinding[counter.count];
Children children = new Children(pdom, bindings);
namespace.getIndex().visit(children);
return bindings;
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
} else if (parentElement instanceof PDOMMemberOwner) {
try {
PDOMMemberOwner owner = (PDOMMemberOwner)parentElement;
@ -251,7 +264,8 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
} else if (element instanceof PDOMLinkage) {
} else if (element instanceof PDOMLinkage
|| element instanceof PDOMCPPNamespace) {
return true;
} else if (element instanceof PDOMMemberOwner) {
try {
@ -318,6 +332,9 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
else if (element instanceof ICompositeType)
return CUIPlugin.getImageDescriptorRegistry().get(
CElementImageProvider.getStructImageDescriptor());
else if (element instanceof ICPPNamespace)
return CUIPlugin.getImageDescriptorRegistry().get(
CElementImageProvider.getNamespaceImageDescriptor());
else if (element instanceof IBinding)
return PlatformUI.getWorkbench().getSharedImages().getImage(
ISharedImages.IMG_OBJ_ELEMENT);