mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 23:05:47 +02:00
More preparation for language specific PDOM bindings. Including a fancy new language registary since language ID will be stored in the database.
This commit is contained in:
parent
fe67ae0785
commit
56254fd6f3
5 changed files with 138 additions and 100 deletions
|
@ -12,11 +12,13 @@
|
|||
package org.eclipse.cdt.core.dom;
|
||||
|
||||
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.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOMDatabase;
|
||||
import org.eclipse.cdt.internal.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
|
@ -45,6 +47,22 @@ public interface ILanguage {
|
|||
*/
|
||||
public static final int AST_SKIP_INDEXED_HEADERS = 4;
|
||||
|
||||
/**
|
||||
* Return the language id for this language. This is used in the PDOM database
|
||||
* to differentiate languages from eachother.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getId();
|
||||
|
||||
// Language ID registry. This is here mainly to avoid languages trampling
|
||||
// over eachother. It is not critical that language ids be put here, but it
|
||||
// is critical that two languages in a given installion do not have the same
|
||||
// id.
|
||||
public static final int GCC_ID = 1; // gnu C
|
||||
public static final int GPP_ID = 2; // gnu C++
|
||||
public static final int GNAT_ID = 3; // gnu Ada
|
||||
|
||||
/**
|
||||
* Create the AST for the given translation unit with the given style.
|
||||
*
|
||||
|
@ -65,20 +83,23 @@ public interface ILanguage {
|
|||
public ASTCompletionNode getCompletionNode(IWorkingCopy workingCopy, int offset);
|
||||
|
||||
/**
|
||||
* Return the PDOM Binding for the given AST binding.
|
||||
* Return the PDOM Binding for the given name. Create a new one if necessary
|
||||
* and store it in the PDOM.
|
||||
*
|
||||
* @param binding
|
||||
* @return
|
||||
*/
|
||||
public PDOMBinding getPDOMBinding(IBinding binding);
|
||||
public PDOMBinding getPDOMBinding(PDOMDatabase pdom, IASTName name) throws CoreException;
|
||||
|
||||
/**
|
||||
* Return a new PDOM Binding that has the given language specific type.
|
||||
* The type id is extracted from the PDOM Database.
|
||||
*
|
||||
* @param pdom
|
||||
* @param bindingType
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public PDOMBinding createPDOMBinding(int bindingType);
|
||||
|
||||
public PDOMBinding createPDOMBinding(PDOMDatabase pdom, int bindingType);
|
||||
|
||||
}
|
||||
|
|
|
@ -14,10 +14,13 @@ 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.ILanguage;
|
||||
import org.eclipse.cdt.core.dom.PDOM;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
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.IType;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
|
@ -36,9 +39,14 @@ import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
|
|||
import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOMDatabase;
|
||||
import org.eclipse.cdt.internal.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.pdom.dom.PDOMName;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
|
@ -48,6 +56,10 @@ public class GCCLanguage implements ILanguage {
|
|||
|
||||
protected static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = new GCCScannerExtensionConfiguration();
|
||||
|
||||
public int getId() {
|
||||
return GCC_ID;
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit(ITranslationUnit tu, int style) {
|
||||
IFile file = (IFile)tu.getResource();
|
||||
IProject project = file.getProject();
|
||||
|
@ -90,12 +102,37 @@ public class GCCLanguage implements ILanguage {
|
|||
return null;
|
||||
}
|
||||
|
||||
public PDOMBinding getPDOMBinding(IBinding binding) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public PDOMBinding getPDOMBinding(PDOMDatabase pdom, IASTName name) throws CoreException {
|
||||
try {
|
||||
IBinding binding = name.resolveBinding();
|
||||
if (binding == null)
|
||||
return null;
|
||||
|
||||
IScope scope = binding.getScope();
|
||||
if (scope == null)
|
||||
return null;
|
||||
|
||||
PDOMBinding pdomBinding = null;
|
||||
IASTName scopeName = scope.getScopeName();
|
||||
|
||||
if (scopeName == null) {
|
||||
pdomBinding = new PDOMBinding(pdom, name, binding);
|
||||
new PDOMName(pdom, name, pdomBinding);
|
||||
} else {
|
||||
IBinding scopeBinding = scopeName.resolveBinding();
|
||||
if (scopeBinding instanceof IType) {
|
||||
pdomBinding = new PDOMBinding(pdom, name, binding);
|
||||
new PDOMName(pdom, name, pdomBinding);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (DOMException e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR,
|
||||
CCorePlugin.PLUGIN_ID, 0, "DOM Exception", e));
|
||||
}
|
||||
}
|
||||
|
||||
public PDOMBinding createPDOMBinding(int bindingType) {
|
||||
public PDOMBinding createPDOMBinding(PDOMDatabase pdom, int bindingType) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -15,8 +15,12 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.ILanguage;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
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.IType;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
|
@ -35,9 +39,14 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfigurat
|
|||
import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOMDatabase;
|
||||
import org.eclipse.cdt.internal.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.pdom.dom.PDOMName;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
|
@ -47,6 +56,10 @@ public class GPPLanguage implements ILanguage {
|
|||
|
||||
protected static final GPPScannerExtensionConfiguration CPP_GNU_SCANNER_EXTENSION = new GPPScannerExtensionConfiguration();
|
||||
|
||||
public int getId() {
|
||||
return GPP_ID;
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit(ITranslationUnit tu, int style) {
|
||||
IFile file = (IFile)tu.getResource();
|
||||
IProject project = file.getProject();
|
||||
|
@ -88,12 +101,37 @@ public class GPPLanguage implements ILanguage {
|
|||
return null;
|
||||
}
|
||||
|
||||
public PDOMBinding getPDOMBinding(IBinding binding) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public PDOMBinding getPDOMBinding(PDOMDatabase pdom, IASTName name) throws CoreException {
|
||||
try {
|
||||
IBinding binding = name.resolveBinding();
|
||||
if (binding == null)
|
||||
return null;
|
||||
|
||||
IScope scope = binding.getScope();
|
||||
if (scope == null)
|
||||
return null;
|
||||
|
||||
PDOMBinding pdomBinding = null;
|
||||
IASTName scopeName = scope.getScopeName();
|
||||
|
||||
if (scopeName == null) {
|
||||
pdomBinding = new PDOMBinding(pdom, name, binding);
|
||||
new PDOMName(pdom, name, pdomBinding);
|
||||
} else {
|
||||
IBinding scopeBinding = scopeName.resolveBinding();
|
||||
if (scopeBinding instanceof IType) {
|
||||
pdomBinding = new PDOMBinding(pdom, name, binding);
|
||||
new PDOMName(pdom, name, pdomBinding);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (DOMException e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR,
|
||||
CCorePlugin.PLUGIN_ID, 0, "DOM Exception", e));
|
||||
}
|
||||
}
|
||||
|
||||
public PDOMBinding createPDOMBinding(int bindingType) {
|
||||
public PDOMBinding createPDOMBinding(PDOMDatabase pdom, int bindingType) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.util.ArrayList;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.ILanguage;
|
||||
import org.eclipse.cdt.core.dom.IPDOM;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
|
@ -23,11 +24,8 @@ 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.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.BTree;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.pdom.dom.PDOMBinding;
|
||||
|
@ -104,68 +102,32 @@ public class PDOMDatabase implements IPDOM {
|
|||
return bindingIndex;
|
||||
}
|
||||
|
||||
public void addSymbols(IASTTranslationUnit ast) {
|
||||
ParserLanguage language = ast.getParserLanguage();
|
||||
ASTVisitor visitor;
|
||||
if (language == ParserLanguage.C)
|
||||
visitor = new CASTVisitor() {
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
shouldVisitDeclarations = true;
|
||||
}
|
||||
|
||||
public int visit(IASTName name) {
|
||||
if (name.toCharArray().length > 0)
|
||||
addSymbol(name);
|
||||
return PROCESS_CONTINUE;
|
||||
};
|
||||
};
|
||||
else if (language == ParserLanguage.CPP)
|
||||
visitor = new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
shouldVisitDeclarations = true;
|
||||
}
|
||||
|
||||
public int visit(IASTName name) {
|
||||
if (name.toCharArray().length > 0)
|
||||
addSymbol(name);
|
||||
return PROCESS_CONTINUE;
|
||||
};
|
||||
};
|
||||
else
|
||||
public void addSymbols(ITranslationUnit tu) throws CoreException {
|
||||
final ILanguage language = tu.getLanguage();
|
||||
if (language == null)
|
||||
return;
|
||||
|
||||
IASTTranslationUnit ast = language.getTranslationUnit(tu,
|
||||
ILanguage.AST_USE_INDEX |
|
||||
ILanguage.AST_SKIP_INDEXED_HEADERS);
|
||||
|
||||
ast.accept(visitor);
|
||||
}
|
||||
|
||||
public void addSymbol(IASTName name) {
|
||||
try {
|
||||
IBinding binding = name.resolveBinding();
|
||||
if (binding == null)
|
||||
return;
|
||||
|
||||
IScope scope = binding.getScope();
|
||||
if (scope == null)
|
||||
return;
|
||||
|
||||
IASTName scopeName = scope.getScopeName();
|
||||
|
||||
if (scopeName == null) {
|
||||
PDOMBinding pdomBinding = new PDOMBinding(this, name, binding);
|
||||
new PDOMName(this, name, pdomBinding);
|
||||
} else {
|
||||
IBinding scopeBinding = scopeName.resolveBinding();
|
||||
if (scopeBinding instanceof IType) {
|
||||
PDOMBinding pdomBinding = new PDOMBinding(this, name, binding);
|
||||
new PDOMName(this, name, pdomBinding);
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
} catch (DOMException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
ast.accept(new ASTVisitor() {
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
shouldVisitDeclarations = true;
|
||||
}
|
||||
|
||||
public int visit(IASTName name) {
|
||||
try {
|
||||
if (name.toCharArray().length > 0)
|
||||
language.getPDOMBinding(PDOMDatabase.this, name);
|
||||
return PROCESS_CONTINUE;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return PROCESS_ABORT;
|
||||
}
|
||||
};
|
||||
});;
|
||||
}
|
||||
|
||||
public void removeSymbols(ITranslationUnit ast) {
|
||||
|
|
|
@ -187,20 +187,12 @@ public class PDOMUpdator extends Job {
|
|||
}
|
||||
|
||||
private void processAddedTU(ITranslationUnit tu) throws CoreException {
|
||||
ILanguage language = tu.getLanguage();
|
||||
if (language == null)
|
||||
return;
|
||||
|
||||
IASTTranslationUnit ast = language.getTranslationUnit(tu,
|
||||
ILanguage.AST_USE_INDEX |
|
||||
ILanguage.AST_SKIP_INDEXED_HEADERS);
|
||||
|
||||
IPDOM pdom = ast.getIndex();
|
||||
IPDOM pdom = tu.getCProject().getIndex();
|
||||
if (pdom == null || !(pdom instanceof PDOMDatabase))
|
||||
return;
|
||||
|
||||
PDOMDatabase mypdom = (PDOMDatabase)pdom;
|
||||
mypdom.addSymbols(ast);
|
||||
mypdom.addSymbols(tu);
|
||||
}
|
||||
|
||||
private void processRemovedTU(ITranslationUnit tu) {
|
||||
|
@ -219,20 +211,8 @@ public class PDOMUpdator extends Job {
|
|||
return;
|
||||
PDOMDatabase mypdom = (PDOMDatabase)pdom;
|
||||
|
||||
ILanguage language = tu.getLanguage();
|
||||
if (language == null)
|
||||
return;
|
||||
|
||||
IASTTranslationUnit ast = language.getTranslationUnit(tu,
|
||||
ILanguage.AST_SKIP_ALL_HEADERS |
|
||||
ILanguage.AST_USE_INDEX);
|
||||
|
||||
if (pdom != ast.getIndex())
|
||||
// weird
|
||||
return;
|
||||
|
||||
mypdom.removeSymbols(tu);
|
||||
mypdom.addSymbols(ast);
|
||||
mypdom.addSymbols(tu);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue