mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
PDOM - Hooked up resolveBinding and OpenDeclarations.
This commit is contained in:
parent
1849e12a38
commit
314113adb0
16 changed files with 284 additions and 74 deletions
|
@ -12,11 +12,10 @@
|
|||
package org.eclipse.cdt.core.model;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOMDatabase;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IStorage;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
|
||||
/**
|
||||
|
@ -55,14 +54,31 @@ public interface ILanguage extends IAdaptable {
|
|||
public String getId();
|
||||
|
||||
/**
|
||||
* Create the AST for the given translation unit with the given style.
|
||||
* Create the AST for the given file with the given style.
|
||||
*
|
||||
* @param file
|
||||
* @param style
|
||||
* @return
|
||||
*/
|
||||
public IASTTranslationUnit getTranslationUnit(ITranslationUnit file, int style);
|
||||
public IASTTranslationUnit getTranslationUnit(IFile file, int style);
|
||||
|
||||
/**
|
||||
* Create the AST for the given external file with the given style.
|
||||
*
|
||||
* @param file
|
||||
* @param style
|
||||
* @return
|
||||
*/
|
||||
public IASTTranslationUnit getTranslationUnit(IStorage file, IProject project, int style);
|
||||
|
||||
/**
|
||||
* Return the ASt for the given working copy
|
||||
* @param workingCopy
|
||||
* @param style
|
||||
* @return
|
||||
*/
|
||||
public IASTTranslationUnit getTranslationUnit(IWorkingCopy workingCopy, int style);
|
||||
|
||||
/**
|
||||
* Return the AST Completion Node for the given working copy at the given
|
||||
* offset.
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom;
|
||||
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
||||
|
||||
|
@ -37,8 +36,6 @@ public interface ICodeReaderFactory {
|
|||
*/
|
||||
public CodeReader createCodeReaderForTranslationUnit(String path);
|
||||
|
||||
public CodeReader createCodeReaderForTranslationUnit(ITranslationUnit tu);
|
||||
|
||||
/**
|
||||
* Create CodeReader for inclusion.
|
||||
*
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.core.dom.ast;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IPDOM;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
|
||||
/**
|
||||
|
@ -202,5 +203,12 @@ public interface IASTTranslationUnit extends IASTNode {
|
|||
* @param index
|
||||
*/
|
||||
public void setIndex(IPDOM index);
|
||||
|
||||
/**
|
||||
* Returns the language for this translation unit.
|
||||
*
|
||||
* @return language for this translation unit
|
||||
*/
|
||||
public ILanguage getLanguage();
|
||||
|
||||
}
|
||||
|
|
|
@ -13,10 +13,11 @@ package org.eclipse.cdt.core.dom.ast.gnu.c;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.IPDOM;
|
||||
import org.eclipse.cdt.core.dom.PDOM;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
|
@ -40,6 +41,8 @@ import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
|
|||
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IStorage;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
|
@ -63,31 +66,46 @@ public class GCCLanguage extends PlatformObject implements ILanguage {
|
|||
return super.getAdapter(adapter);
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit(ITranslationUnit tu, int style) {
|
||||
IFile file = (IFile)tu.getResource();
|
||||
IProject project = file.getProject();
|
||||
public IASTTranslationUnit getTranslationUnit(IStorage file, IProject project, int style) {
|
||||
return getTranslationUnit(file.getFullPath().toOSString(), project, project, style, null);
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit(IFile file, int style) {
|
||||
return getTranslationUnit(file.getLocation().toOSString(), file.getProject(), file, style, null);
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit(IWorkingCopy workingCopy, int style) {
|
||||
IFile file = (IFile)workingCopy.getResource();
|
||||
String path = file.getLocation().toOSString();
|
||||
CodeReader reader = new CodeReader(path, workingCopy.getContents());
|
||||
return getTranslationUnit(path, file.getProject(), file, style, reader);
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit getTranslationUnit(String path, IProject project, IResource infoResource, int style,
|
||||
CodeReader reader) {
|
||||
IScannerInfo scanInfo = null;
|
||||
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
|
||||
if (provider != null){
|
||||
IScannerInfo buildScanInfo = provider.getScannerInformation(file);
|
||||
IScannerInfo buildScanInfo = provider.getScannerInformation(infoResource);
|
||||
if (buildScanInfo != null)
|
||||
scanInfo = buildScanInfo;
|
||||
else
|
||||
scanInfo = new ScannerInfo();
|
||||
}
|
||||
|
||||
// TODO - use different factories if we are working copy, or style
|
||||
// is skip headers.
|
||||
IPDOM pdom = PDOM.getPDOM(project);
|
||||
ICodeReaderFactory fileCreator;
|
||||
if ((style & ILanguage.AST_SKIP_INDEXED_HEADERS) != 0)
|
||||
fileCreator = new PDOMCodeReaderFactory((PDOMDatabase)tu.getCProject().getIndex());
|
||||
fileCreator = new PDOMCodeReaderFactory((PDOMDatabase)pdom);
|
||||
else
|
||||
fileCreator = SavedCodeReaderFactory.getInstance();
|
||||
|
||||
CodeReader reader = fileCreator.createCodeReaderForTranslationUnit(tu);
|
||||
if( reader == null )
|
||||
return null;
|
||||
|
||||
if (reader == null) {
|
||||
reader = fileCreator.createCodeReaderForTranslationUnit(path);
|
||||
if( reader == null )
|
||||
return null;
|
||||
}
|
||||
|
||||
IScannerExtensionConfiguration scannerExtensionConfiguration =
|
||||
scannerExtensionConfiguration = C_GNU_SCANNER_EXTENSION;
|
||||
|
||||
|
@ -101,7 +119,7 @@ public class GCCLanguage extends PlatformObject implements ILanguage {
|
|||
IASTTranslationUnit ast = parser.parse();
|
||||
|
||||
if ((style & AST_USE_INDEX) != 0)
|
||||
ast.setIndex(tu.getCProject().getIndex());
|
||||
ast.setIndex(pdom);
|
||||
|
||||
return ast;
|
||||
}
|
||||
|
|
|
@ -13,10 +13,11 @@ package org.eclipse.cdt.core.dom.ast.gnu.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.IPDOM;
|
||||
import org.eclipse.cdt.core.dom.PDOM;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
|
@ -40,6 +41,8 @@ import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
|
|||
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IStorage;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
|
@ -62,30 +65,45 @@ public class GPPLanguage extends PlatformObject implements ILanguage {
|
|||
return super.getAdapter(adapter);
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit(ITranslationUnit tu, int style) {
|
||||
IFile file = (IFile)tu.getResource();
|
||||
IProject project = file.getProject();
|
||||
public IASTTranslationUnit getTranslationUnit(IStorage file, IProject project, int style) {
|
||||
return getTranslationUnit(file.getFullPath().toOSString(), project, project, style, null);
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit(IFile file, int style) {
|
||||
return getTranslationUnit(file.getLocation().toOSString(), file.getProject(), file, style, null);
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit(IWorkingCopy workingCopy, int style) {
|
||||
IFile file = (IFile)workingCopy.getResource();
|
||||
String path = file.getLocation().toOSString();
|
||||
CodeReader reader = new CodeReader(path, workingCopy.getContents());
|
||||
return getTranslationUnit(path, file.getProject(), file, style, reader);
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit getTranslationUnit(String path, IProject project, IResource infoResource, int style,
|
||||
CodeReader reader) {
|
||||
IScannerInfo scanInfo = null;
|
||||
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
|
||||
if (provider != null){
|
||||
IScannerInfo buildScanInfo = provider.getScannerInformation(file);
|
||||
IScannerInfo buildScanInfo = provider.getScannerInformation(infoResource);
|
||||
if (buildScanInfo != null)
|
||||
scanInfo = buildScanInfo;
|
||||
else
|
||||
scanInfo = new ScannerInfo();
|
||||
}
|
||||
|
||||
// TODO - use different factories if we are working copy, or style
|
||||
// is skip headers.
|
||||
IPDOM pdom = PDOM.getPDOM(project);
|
||||
ICodeReaderFactory fileCreator;
|
||||
if ((style & ILanguage.AST_SKIP_INDEXED_HEADERS) != 0)
|
||||
fileCreator = new PDOMCodeReaderFactory((PDOMDatabase)tu.getCProject().getIndex());
|
||||
fileCreator = new PDOMCodeReaderFactory((PDOMDatabase)pdom);
|
||||
else
|
||||
fileCreator = SavedCodeReaderFactory.getInstance();
|
||||
|
||||
CodeReader reader = fileCreator.createCodeReaderForTranslationUnit(tu);
|
||||
if( reader == null )
|
||||
return null;
|
||||
if (reader == null) {
|
||||
reader = fileCreator.createCodeReaderForTranslationUnit(path);
|
||||
if( reader == null )
|
||||
return null;
|
||||
}
|
||||
|
||||
IScannerExtensionConfiguration scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION;
|
||||
|
||||
|
@ -98,7 +116,7 @@ public class GPPLanguage extends PlatformObject implements ILanguage {
|
|||
IASTTranslationUnit ast = parser.parse();
|
||||
|
||||
if ((style & AST_USE_INDEX) != 0)
|
||||
ast.setIndex(tu.getCProject().getIndex());
|
||||
ast.setIndex(pdom);
|
||||
|
||||
return ast;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
|||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
|
@ -521,6 +523,11 @@ public class CASTTranslationUnit extends CASTNode implements
|
|||
return ParserLanguage.C;
|
||||
}
|
||||
|
||||
public ILanguage getLanguage() {
|
||||
// Assuming gnu C for now.
|
||||
return new GCCLanguage();
|
||||
}
|
||||
|
||||
public IPDOM getIndex() {
|
||||
return pdom;
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
|
@ -573,6 +575,11 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
|||
return ParserLanguage.CPP;
|
||||
}
|
||||
|
||||
public ILanguage getLanguage() {
|
||||
// Assuming gnu C++ for now.
|
||||
return new GPPLanguage();
|
||||
}
|
||||
|
||||
public IPDOM getIndex() {
|
||||
return pdom;
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ public class PDOMDatabase implements IPDOM {
|
|||
if (linkage == null)
|
||||
return;
|
||||
|
||||
IASTTranslationUnit ast = language.getTranslationUnit(tu,
|
||||
IASTTranslationUnit ast = language.getTranslationUnit((IFile)tu.getResource(),
|
||||
ILanguage.AST_USE_INDEX |
|
||||
ILanguage.AST_SKIP_INDEXED_HEADERS);
|
||||
if (ast == null)
|
||||
|
@ -180,6 +180,13 @@ public class PDOMDatabase implements IPDOM {
|
|||
}
|
||||
|
||||
public IBinding resolveBinding(IASTName name) {
|
||||
try {
|
||||
ILanguage language = name.getTranslationUnit().getLanguage();
|
||||
return getLinkage(language).resolveBinding(name);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -87,4 +87,6 @@ public abstract class PDOMLinkage extends PDOMNode {
|
|||
|
||||
public abstract PDOMBinding getBinding(int record) throws CoreException;
|
||||
|
||||
public abstract PDOMBinding resolveBinding(IASTName name) throws CoreException;
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
|||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope2;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
|
||||
/**
|
||||
|
@ -160,5 +161,9 @@ public class PDOMTranslationUnit implements IASTTranslationUnit {
|
|||
public IScope2 getScope(IASTNode child, ASTNodeProperty childProperty) {
|
||||
throw new PDOMNotImplementedError();
|
||||
}
|
||||
|
||||
public ILanguage getLanguage() {
|
||||
throw new PDOMNotImplementedError();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -178,4 +178,8 @@ public class PDOMCLinkage extends PDOMLinkage {
|
|||
return null;
|
||||
}
|
||||
|
||||
public PDOMBinding resolveBinding(IASTName name) throws CoreException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,18 +11,22 @@
|
|||
|
||||
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.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOMDatabase;
|
||||
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.PDOMNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||
|
@ -32,7 +36,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMCPPClassType extends PDOMMemberOwner implements ICPPClassType {
|
||||
public class PDOMCPPClassType extends PDOMMemberOwner implements ICPPClassType, ICPPClassScope {
|
||||
|
||||
protected static final int RECORD_SIZE = PDOMMemberOwner.RECORD_SIZE + 0;
|
||||
|
||||
|
@ -97,7 +101,7 @@ public class PDOMCPPClassType extends PDOMMemberOwner implements ICPPClassType {
|
|||
}
|
||||
|
||||
public IScope getCompositeScope() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getKey() throws DOMException {
|
||||
|
@ -116,4 +120,63 @@ public class PDOMCPPClassType extends PDOMMemberOwner implements ICPPClassType {
|
|||
throw new PDOMNotImplementedError();
|
||||
}
|
||||
|
||||
public ICPPClassType getClassType() {
|
||||
throw new PDOMNotImplementedError();
|
||||
}
|
||||
|
||||
public ICPPMethod[] getImplicitMethods() {
|
||||
throw new PDOMNotImplementedError();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
|
||||
try {
|
||||
PDOMMember[] matches = findMembers(name.toCharArray());
|
||||
// TODO - need to check for overloads
|
||||
return matches[0];
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IScope getParent() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOMDatabase;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMember;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
|
@ -52,7 +52,7 @@ public class PDOMCPPField extends PDOMMember implements ICPPField {
|
|||
}
|
||||
|
||||
public String[] getQualifiedName() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
return CPPVisitor.getQualifiedName( this );
|
||||
}
|
||||
|
||||
public char[][] getQualifiedNameCharArray() throws DOMException {
|
||||
|
|
|
@ -11,7 +11,11 @@
|
|||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
||||
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.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
|
@ -112,43 +116,43 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
}
|
||||
|
||||
private static final class FindBinding extends PDOMNode.NodeVisitor {
|
||||
private final IBinding binding;
|
||||
public PDOMBinding pdomBinding;
|
||||
public FindBinding(PDOMDatabase pdom, IBinding binding) {
|
||||
super(pdom, binding.getNameCharArray());
|
||||
this.binding = binding;
|
||||
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;
|
||||
switch (tBinding.getBindingType()) {
|
||||
case CPPVARIABLE:
|
||||
if (binding instanceof ICPPVariable)
|
||||
pdomBinding = tBinding;
|
||||
break;
|
||||
case CPPFUNCTION:
|
||||
if (binding instanceof ICPPFunction)
|
||||
pdomBinding = tBinding;
|
||||
break;
|
||||
case CPPCLASSTYPE:
|
||||
if (binding instanceof ICPPClassType)
|
||||
pdomBinding = tBinding;
|
||||
break;
|
||||
case CPPFIELD:
|
||||
if (binding instanceof ICPPField)
|
||||
pdomBinding = tBinding;
|
||||
break;
|
||||
case CPPMETHOD:
|
||||
if (binding instanceof ICPPMethod)
|
||||
pdomBinding = tBinding;
|
||||
break;
|
||||
}
|
||||
return pdomBinding == null;
|
||||
if (tBinding.getBindingType() != desiredType)
|
||||
// wrong type, try again
|
||||
return true;
|
||||
|
||||
// got it
|
||||
pdomBinding = tBinding;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int getBindingType(IBinding binding) {
|
||||
if (binding instanceof ICPPVariable)
|
||||
return CPPVARIABLE;
|
||||
else if (binding instanceof ICPPFunction)
|
||||
return CPPFUNCTION;
|
||||
else if (binding instanceof ICPPClassType)
|
||||
return CPPCLASSTYPE;
|
||||
else if (binding instanceof ICPPField)
|
||||
return CPPFIELD;
|
||||
else if (binding instanceof ICPPMethod)
|
||||
return CPPMETHOD;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public PDOMBinding adaptBinding(IBinding binding) throws CoreException {
|
||||
if (binding == null)
|
||||
|
@ -156,7 +160,7 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
|
||||
PDOMNode parent = getParent(binding);
|
||||
if (parent == this) {
|
||||
FindBinding visitor = new FindBinding(pdom, binding);
|
||||
FindBinding visitor = new FindBinding(pdom, binding.getNameCharArray(), getBindingType(binding));
|
||||
getIndex().visit(visitor);
|
||||
return visitor.pdomBinding;
|
||||
} else if (parent instanceof PDOMMemberOwner) {
|
||||
|
@ -187,4 +191,27 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
public PDOMBinding resolveBinding(IASTName name) throws CoreException {
|
||||
IASTNode parent = name.getParent();
|
||||
if (parent instanceof IASTIdExpression) {
|
||||
// reference
|
||||
IASTNode eParent = parent.getParent();
|
||||
if (eParent instanceof IASTFunctionCallExpression) {
|
||||
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CPPFUNCTION);
|
||||
getIndex().visit(visitor);
|
||||
return visitor.pdomBinding;
|
||||
} else {
|
||||
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CPPVARIABLE);
|
||||
getIndex().visit(visitor);
|
||||
return visitor.pdomBinding;
|
||||
}
|
||||
} else if (parent instanceof IASTNamedTypeSpecifier) {
|
||||
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CPPCLASSTYPE);
|
||||
getIndex().visit(visitor);
|
||||
return visitor.pdomBinding;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,9 +52,12 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
|||
import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor;
|
||||
import org.eclipse.cdt.internal.core.index.domsourceindexer.IndexVisitorUtil;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.content.IContentType;
|
||||
|
||||
|
@ -356,6 +359,25 @@ public class DOMSearchUtil {
|
|||
&& binding.getScope() instanceof ICPPClassScope) {
|
||||
binding = ((ICPPClassScope)binding.getScope()).getClassType();
|
||||
names = getNames(tu, binding, limitTo);
|
||||
} else if (binding instanceof PDOMBinding) {
|
||||
try {
|
||||
ArrayList pdomNames = new ArrayList();
|
||||
// First decls
|
||||
PDOMName name = ((PDOMBinding)binding).getFirstDeclaration();
|
||||
while (name != null) {
|
||||
pdomNames.add(name);
|
||||
name = name.getNextInBinding();
|
||||
}
|
||||
// Next defs
|
||||
name = ((PDOMBinding)binding).getFirstDefinition();
|
||||
while (name != null) {
|
||||
pdomNames.add(name);
|
||||
name = name.getNextInBinding();
|
||||
}
|
||||
names = (IASTName[])pdomNames.toArray(new IASTName[pdomNames.size()]);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
|
@ -40,6 +41,7 @@ import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
|
|||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||
|
@ -125,13 +127,20 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd
|
|||
IWorkingCopy workingCopy = (IWorkingCopy)fEditor.getInputCElement();
|
||||
IFile resourceFile = (IFile)workingCopy.getResource();
|
||||
project = new CProject(null, resourceFile.getProject());
|
||||
IPDOM pdom = null; //PDOM.getPDOM(resourceFile.getProject());
|
||||
IPDOM pdom = PDOM.getPDOM(resourceFile.getProject());
|
||||
try {
|
||||
if (pdom != null)
|
||||
tu = CDOM.getInstance().getASTService().getTranslationUnit(
|
||||
resourceFile,
|
||||
pdom.getCodeReaderFactory(workingCopy));
|
||||
else
|
||||
if (pdom != null) {
|
||||
try {
|
||||
ILanguage language = workingCopy.getLanguage();
|
||||
tu = language.getTranslationUnit(workingCopy,
|
||||
ILanguage.AST_USE_INDEX |
|
||||
ILanguage.AST_SKIP_INDEXED_HEADERS);
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
tu = CDOM.getInstance().getASTService().getTranslationUnit(
|
||||
resourceFile);
|
||||
} catch (IASTServiceProvider.UnsupportedDialectException e) {
|
||||
|
|
Loading…
Add table
Reference in a new issue