1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 09:55:29 +02:00

Hooked up ctags indexer, although it doesn't record any bindings yet. Got rid of IScope2 since I can't remember what I was going to do with it. Started work on recording inclusions in PDOM.

This commit is contained in:
Doug Schaefer 2006-04-17 19:02:10 +00:00
parent 103ba0e9c1
commit 7814922230
17 changed files with 717 additions and 160 deletions

View file

@ -108,14 +108,4 @@ public interface IASTNode {
*/
public String getRawSignature();
/**
* Internal interface.
*
* Get the scope for this node. Different children may get different nodes.
*
* @param childProperty
* @return
*/
public IScope2 getScope(IASTNode child, ASTNodeProperty childProperty);
}

View file

@ -1,21 +0,0 @@
/*******************************************************************************
* Copyright (c) 2005 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.core.dom.ast;
/**
* @author Doug Schaefer
*
*/
public interface IScope2 {
public IBinding getBinding(IASTName name);
}

View file

@ -16,7 +16,6 @@ import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IScope2;
/**
* @author jcamelon
@ -103,10 +102,6 @@ public abstract class ASTNode implements IASTNode {
return fileLocation;
}
public IScope2 getScope(IASTNode child, ASTNodeProperty childProperty) {
return parent != null ? parent.getScope(this, property) : null;
}
public IASTTranslationUnit getTranslationUnit() {
return parent != null ? parent.getTranslationUnit() : null;
}

View file

@ -39,20 +39,9 @@ public class CASTName extends CASTNode implements IASTName {
name = EMPTY_CHAR_ARRAY;
}
private static boolean inited = false;
private static boolean useScope2 = false;
public IBinding resolveBinding() {
if (binding == null) {
if (!inited) {
useScope2 = System.getProperty("doug.useScope2") != null ? true : false;
inited = true;
}
if (useScope2)
binding = getScope(this, getPropertyInParent()).getBinding(this);
else
CVisitor.createBinding(this);
CVisitor.createBinding(this);
}
return binding;

View file

@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.IPDOMWriter;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.model.ICProject;
@ -164,50 +165,20 @@ public class PDOM extends PlatformObject
return fileIndex;
}
/**
* @deprecated
*/
public void addSymbols(ITranslationUnit tu) throws CoreException {
final ILanguage language = tu.getLanguage();
if (language == null)
return;
final PDOMLinkage linkage = getLinkage(language);
if (linkage == null)
return;
IASTTranslationUnit ast = language.getASTTranslationUnit(tu,
ILanguage.AST_USE_INDEX |
ILanguage.AST_SKIP_INDEXED_HEADERS |
ILanguage.AST_SKIP_IF_NO_BUILD_INFO);
if (ast == null)
return;
ast.accept(new ASTVisitor() {
{
shouldVisitNames = true;
shouldVisitDeclarations = true;
}
public int visit(IASTName name) {
try {
linkage.addName(name);
return PROCESS_CONTINUE;
} catch (CoreException e) {
CCorePlugin.log(e);
return PROCESS_ABORT;
}
};
});;
fireChange();
}
public void addSymbols(ILanguage language, IASTTranslationUnit ast) throws CoreException {
final PDOMLinkage linkage = getLinkage(language);
if (linkage == null)
return;
IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives();
for (int i = 0; i < includes.length; ++i) {
IASTPreprocessorIncludeStatement include = includes[i];
String sourcePath = include.getFileLocation().getFileName();
String destPath = include.getPath();
//System.out.println(sourcePath + " -> " + destPath);
}
ast.accept(new ASTVisitor() {
{
shouldVisitNames = true;

View file

@ -59,6 +59,13 @@ public class PDOMCodeReaderFactory implements ICodeReaderFactory {
return new CodeReader(tu.getResource().getLocation().toOSString(), tu.getContents());
}
private static class SkippedInclusion extends CodeReader {
private static char[] buffer = "".toCharArray();
public SkippedInclusion(String filename) {
super(filename, buffer);
}
}
public CodeReader createCodeReaderForInclusion(String path) {
// Don't parse inclusion if it is already captured
try {
@ -70,7 +77,7 @@ public class PDOMCodeReaderFactory implements ICodeReaderFactory {
PDOMFile file = PDOMFile.find(pdom, path);
if (file != null && file.getFirstName() != null)
// Already got things from here
return null;
return new SkippedInclusion(path);
} catch (CoreException e) {
CCorePlugin.log(new CoreException(new Status(IStatus.ERROR,
CCorePlugin.PLUGIN_ID, 0, "PDOM Exception", e)));

View file

@ -27,10 +27,12 @@ import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.core.runtime.preferences.InstanceScope;
@ -143,17 +145,47 @@ public class PDOMManager implements IPDOMManager, IElementChangedListener {
if (ref != null && ref.length > 0) {
indexerId = ref[0].getID();
}
if (indexerId != null) {
// Make sure it is a valid indexer
IExtension indexerExt = Platform.getExtensionRegistry()
.getExtension(CCorePlugin.INDEXER_UNIQ_ID, indexerId);
if (indexerExt == null) {
// It is not, forget about it.
indexerId = null;
}
}
} catch (CoreException e) {
}
if (indexerId == null)
// make it the default
indexerId = getDefaultIndexerId();
// Start a job to set the id.
new SetId(project, indexerId).schedule();
}
return indexerId;
}
public void setIndexerId(ICProject project, String indexerId) throws CoreException {
private static class SetId extends Job {
private final ICProject project;
private final String indexerId;
public SetId(ICProject project, String indexerId) {
super("Set Indexer Id");
this.project = project;
this.indexerId = indexerId;
}
protected IStatus run(IProgressMonitor monitor) {
try {
setId(project, indexerId);
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();
}
}
}
private static void setId(ICProject project, String indexerId) throws CoreException {
IEclipsePreferences prefs = new ProjectScope(project.getProject()).getNode(CCorePlugin.PLUGIN_ID);
if (prefs == null)
return; // TODO why would this be null?
@ -163,7 +195,10 @@ public class PDOMManager implements IPDOMManager, IElementChangedListener {
prefs.flush();
} catch (BackingStoreException e) {
}
}
public void setIndexerId(ICProject project, String indexerId) throws CoreException {
setId(project, indexerId);
IPDOM pdom = getPDOM(project);
pdom.setIndexer(createIndexer(indexerId));
}

View file

@ -19,7 +19,6 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope2;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.core.runtime.CoreException;
@ -321,11 +320,6 @@ public class PDOMName implements IASTName, IASTFileLocation {
}
}
public IScope2 getScope(IASTNode child, ASTNodeProperty childProperty) {
// TODO Auto-generated method stub
return null;
}
public void delete() throws CoreException {
// Delete from the binding chain
PDOMName prevName = getPrevInBinding();

View file

@ -25,7 +25,6 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem;
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;
@ -158,10 +157,6 @@ public class PDOMTranslationUnit implements IASTTranslationUnit {
throw new PDOMNotImplementedError();
}
public IScope2 getScope(IASTNode child, ASTNodeProperty childProperty) {
throw new PDOMNotImplementedError();
}
public ILanguage getLanguage() {
throw new PDOMNotImplementedError();
}

View file

@ -0,0 +1,293 @@
/*******************************************************************************
* 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.indexer.ctags;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.IPDOMIndexer;
import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.service.prefs.BackingStoreException;
/**
* @author Doug Schaefer
*/
public class CtagsIndexer implements IPDOMIndexer {
private PDOM pdom;
private boolean useCtagsOnPath = true;
private String ctagsCommand = ""; //$NON-NLS-1$
private boolean useInternalCtagsFile = true;
private String ctagsFileName = ""; //$NON-NLS-1$
public void handleDelta(ICElementDelta delta) {
// TODO Auto-generated method stub
}
public void reindex() throws CoreException {
new CtagsReindex(this).schedule();
}
public void setPDOM(IPDOM pdom) {
this.pdom = (PDOM)pdom;
loadPreferences();
}
public IPDOM getPDOM() {
return pdom;
}
// Indexing functions
void runCtags(IPath sourcePath) {
String ctagsFileName = getResolvedCtagsFileName();
String[] cmd = new String[] {
getResolvedCtagsCommand(),
"--excmd=number", //$NON-NLS-1$
"--format=2", //$NON-NLS-1$
"--sort=no", //$NON-NLS-1$
"--fields=aiKlmnsSz", //$NON-NLS-1$
"--c-types=cdefgmnpstuvx", //$NON-NLS-1$
"--c++-types=cdefgmnpstuvx", //$NON-NLS-1$
"--languages=c,c++", //$NON-NLS-1$
"-a", //$NON-NLS-1$ // All locations are collected in one file
"-f", //$NON-NLS-1$
ctagsFileName,
"-R", //$NON-NLS-2$
sourcePath.toOSString() // Give absolute path so that tag file entries will be absolute
};
try {
// Run ctags
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
// Parse the ctags file
processCtagsFile(ctagsFileName);
} catch (InterruptedException e) {
return;
} catch (IOException e) {
CCorePlugin.log(e);
return;
} catch (CoreException e) {
CCorePlugin.log(e);
return;
}
}
private void processCtagsFile(String ctagsFileName) throws IOException, CoreException {
BufferedReader reader = new BufferedReader(new FileReader(ctagsFileName));
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
if (line.charAt(0) == '!')
// skip over header
continue;
String elementName = null;
String fileName = null;
int lineNum = -1;
Map fields = new HashMap();
StringTokenizer tokenizer = new StringTokenizer(line, "\t"); //$NON-NLS-1$
for (int state = 0; tokenizer.hasMoreTokens(); ++state) {
String token = tokenizer.nextToken();
switch (state) {
case 0:
// element name
elementName = token;
break;
case 1:
// file name
fileName = token;
break;
case 2:
// line number
try {
token = token.trim();
int i = token.indexOf(';');
lineNum = Integer.parseInt(token.substring(0, i));
} catch (NumberFormatException e) {
// Not sure what the line number is.
lineNum = -1;
}
break;
default:
// extension field
int i = token.indexOf(':');
if (i != -1) {
String key = token.substring(0, i);
String value = token.substring(i + 1);
fields.put(key, value);
}
}
}
if (elementName != null && fileName != null)
new CtagsName(pdom, fileName, lineNum, elementName, fields).addToPDOM();
}
}
// Preference Management
private static final String useCtagsOnPathId = "useCtagsOnPath"; //$NON-NLS-1$
private static final String ctagsCommandId = "ctagsCommand"; //$NON-NLS-1$
private static final String useInternalCtagsFileId = "useInternalCtagsFile"; //$NON-NLS-$
private static final String ctagsFileNameId = "ctagsFileName"; //$NON-NLS-1$
// project preferences
private void loadPreferences() {
IProject project = pdom.getProject().getProject();
IEclipsePreferences prefs = new ProjectScope(project.getProject()).getNode(CCorePlugin.PLUGIN_ID);
if (prefs == null)
return;
useCtagsOnPath = prefs.getBoolean(useCtagsOnPathId, getDefaultUseCtagsOnPath());
ctagsCommand = prefs.get(ctagsCommandId, getDefaultCtagsCommand());
useInternalCtagsFile = prefs.getBoolean(useInternalCtagsFileId, getDefaultUseInternalCtagsFile());
ctagsFileName = prefs.get(ctagsFileNameId, getDefaultCtagsFileName());
}
public void setPreferences(
boolean useCtagsOnPath,
String ctagsCommand,
boolean useInternalCtagsFile,
String ctagsFileName) {
IProject project = pdom.getProject().getProject();
IEclipsePreferences prefs = new ProjectScope(project.getProject()).getNode(CCorePlugin.PLUGIN_ID);
if (prefs == null)
return;
boolean changed = false;
if (this.useCtagsOnPath != useCtagsOnPath) {
this.useCtagsOnPath = useCtagsOnPath;
prefs.putBoolean(useCtagsOnPathId, useCtagsOnPath);
changed = true;
}
if (! this.ctagsCommand.equals(ctagsCommand)) {
this.ctagsCommand = ctagsCommand;
prefs.put(ctagsCommandId, ctagsCommand);
changed = true;
}
if (this.useInternalCtagsFile != useInternalCtagsFile) {
this.useInternalCtagsFile = useInternalCtagsFile;
prefs.putBoolean(useInternalCtagsFileId, useInternalCtagsFile);
changed = true;
}
if (! this.ctagsFileName.equals(ctagsFileName)) {
this.ctagsFileName = ctagsFileName;
prefs.put(ctagsFileNameId, ctagsFileName);
changed = true;
}
if (changed) {
try {
prefs.flush();
} catch (BackingStoreException e) {
CCorePlugin.log(e);
}
}
}
public boolean useCtagsOnPath() {
return useCtagsOnPath;
}
public String getCtagsCommand() {
return ctagsCommand;
}
public String getResolvedCtagsCommand() {
return useCtagsOnPath ? "ctags" : ctagsCommand; //$NON-NLS-1
}
public boolean useInternalCtagsFile() {
return useInternalCtagsFile;
}
public String getCtagsFileName() {
return ctagsFileName;
}
public String getResolvedCtagsFileName() {
if (useInternalCtagsFile)
return CCorePlugin.getDefault().getStateLocation().append(pdom.getProject().getElementName() + ".ctags").toOSString(); //$NON-NLS-1$
else
return ctagsFileName;
}
// Defaults stored in metadata
public static boolean getDefaultUseCtagsOnPath() {
IPreferencesService prefService = Platform.getPreferencesService();
return prefService.getBoolean(CCorePlugin.PLUGIN_ID, useCtagsOnPathId,
true, null);
}
public static String getDefaultCtagsCommand() {
IPreferencesService prefService = Platform.getPreferencesService();
return prefService.getString(CCorePlugin.PLUGIN_ID, ctagsCommandId,
"", null); //$NON-NLS-1$
}
public static boolean getDefaultUseInternalCtagsFile() {
IPreferencesService prefService = Platform.getPreferencesService();
return prefService.getBoolean(CCorePlugin.PLUGIN_ID, useInternalCtagsFileId,
true, null);
}
public static String getDefaultCtagsFileName() {
IPreferencesService prefService = Platform.getPreferencesService();
return prefService.getString(CCorePlugin.PLUGIN_ID, ctagsFileNameId,
"", null); //$NON-NLS-1$
}
public static void setDefaultPreferences(
boolean useCtagsOnPath,
String ctagsCommand,
boolean useInternalCtagsFile,
String ctagsFileName) {
IEclipsePreferences prefs = new InstanceScope().getNode(CCorePlugin.PLUGIN_ID);
if (prefs == null)
return;
prefs.putBoolean(useCtagsOnPathId, useCtagsOnPath);
prefs.put(ctagsCommandId, ctagsCommand);
prefs.putBoolean(useInternalCtagsFileId, useInternalCtagsFile);
prefs.put(ctagsFileNameId, ctagsFileName);
try {
prefs.flush();
} catch (BackingStoreException e) {
CCorePlugin.log(e);
}
}
}

View file

@ -0,0 +1,212 @@
/*******************************************************************************
* 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.indexer.ctags;
import java.util.Map;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException;
/**
* A fake AST Name derived from a ctags entry.
*
* @author Doug Schaefer
*/
public class CtagsName implements IASTName, IASTFileLocation {
private final PDOM pdom;
private final PDOMLinkage linkage;
private final String fileName;
private final int lineNum;
private final String elementName;
private final Map fields;
private int kind; // Enum from below
private final static int K_UNKNOWN = 0;
private final static int K_CLASS = 1;
private final static int K_MACRO = 2;
private final static int K_ENUMERATOR = 3;
private final static int K_FUNCTION = 4;
private final static int K_ENUM = 5;
private final static int K_MEMBER = 6;
private final static int K_NAMESPACE = 7;
private final static int K_PROTOTYPE = 8;
private final static int K_STRUCT = 9;
private final static int K_TYPEDEF = 10;
private final static int K_UNION = 11;
private final static int K_VARIABLE = 12;
private final static int K_EXTERNALVAR = 13;
private final static String[] kinds = { // Order must match value of enum above
null, // unknown kinds
"class", //$NON-NLS-1$
"macro", //$NON-NLS-1$
"enumerator", //$NON-NLS-1$
"function", //$NON-NLS-1$
"enum", //$NON-NLS-1$
"member", //$NON-NLS-1$
"namespace", //$NON-NLS-1$
"prototype", //$NON-NLS-1$
"struct", //$NON-NLS-1$
"typedef", //$NON-NLS-1$
"union", //$NON-NLS-1$
"variable", //$NON-NLS-1$
"externvar", //$NON-NLS-1$
};
public CtagsName(PDOM pdom, String fileName, int lineNum, String elementName, Map fields) throws CoreException {
this.pdom = pdom;
this.fileName = fileName;
this.lineNum = lineNum;
this.elementName = elementName;
this.fields = fields;
kind = K_UNKNOWN;
String kindField = (String)fields.get("kind"); //$NON-NLS-1$
if (kindField != null) {
for (int i = 1; i < kinds.length; ++i) {
if (kindField.equals(kinds[i])) {
kind = i;
break;
}
}
}
String languageName = (String)fields.get("language");
ILanguage language
= (languageName != null && languageName.equals("C++"))
? (ILanguage)new GPPLanguage()
: (ILanguage)new GCCLanguage();
linkage = pdom.getLinkage(language);
}
public void addToPDOM() throws CoreException {
linkage.addName(this);
}
public IBinding getBinding() {
throw new PDOMNotImplementedError();
}
public boolean isDeclaration() {
throw new PDOMNotImplementedError();
}
public boolean isDefinition() {
throw new PDOMNotImplementedError();
}
public boolean isReference() {
// We're never a reference
return false;
}
public IBinding resolveBinding() {
switch (kind) {
default:
return null;
}
}
public IBinding[] resolvePrefix() {
throw new PDOMNotImplementedError();
}
public void setBinding(IBinding binding) {
throw new PDOMNotImplementedError();
}
public char[] toCharArray() {
return elementName.toCharArray();
}
public boolean accept(ASTVisitor visitor) {
throw new PDOMNotImplementedError();
}
public String getContainingFilename() {
return fileName;
}
public IASTFileLocation getFileLocation() {
return this;
}
public IASTNodeLocation[] getNodeLocations() {
throw new PDOMNotImplementedError();
}
public IASTNode getParent() {
throw new PDOMNotImplementedError();
}
public ASTNodeProperty getPropertyInParent() {
throw new PDOMNotImplementedError();
}
public String getRawSignature() {
throw new PDOMNotImplementedError();
}
public IASTTranslationUnit getTranslationUnit() {
throw new PDOMNotImplementedError();
}
public void setParent(IASTNode node) {
throw new PDOMNotImplementedError();
}
public void setPropertyInParent(ASTNodeProperty property) {
throw new PDOMNotImplementedError();
}
public int getEndingLineNumber() {
throw new PDOMNotImplementedError();
}
public String getFileName() {
return fileName;
}
public int getStartingLineNumber() {
return lineNum;
}
public IASTFileLocation asFileLocation() {
throw new PDOMNotImplementedError();
}
public int getNodeLength() {
// -1 means we have a line num as the offset
return -1;
}
public int getNodeOffset() {
// since node length is -1, we can return the line number here
return lineNum;
}
}

View file

@ -0,0 +1,95 @@
/*******************************************************************************
* 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.indexer.ctags;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IIncludeReference;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
/**
* @author Doug Schaefer
*
*/
public class CtagsReindex extends Job {
private final CtagsIndexer indexer;
private final PDOM pdom;
public CtagsReindex(CtagsIndexer indexer) {
super("Ctags Indexer");
this.indexer = indexer;
this.pdom = (PDOM)indexer.getPDOM();
}
protected IStatus run(IProgressMonitor monitor) {
try {
// Index the include path
indexIncludes();
// Index the source roots
final ICProject project = pdom.getProject();
ISourceRoot[] sourceRoots = project.getAllSourceRoots();
for (int i = 0; i < sourceRoots.length; ++i) {
ISourceRoot sourceRoot = sourceRoots[i];
IPath sourcePath = sourceRoot.getResource().getLocation();
if (sourcePath != null)
indexer.runCtags(sourcePath);
}
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();
}
}
protected void indexIncludes() throws CoreException {
ICProject project = pdom.getProject();
IIncludeReference[] includes = project.getIncludeReferences();
// This project has no references, don't bother processing any further
if (includes.length == 0)
return;
// Find common prefix paths
for (int i = 0; i < includes.length; ++i) {
if (includes[i] == null)
continue;
IPath pathi = includes[i].getPath();
for (int j = i + 1; j < includes.length; ++j) {
if (includes[j] == null)
continue;
IPath pathj = includes[j].getPath();
if (pathi.isPrefixOf(pathj)) {
includes[j] = null;
} else if (pathj.isPrefixOf(pathi)) {
includes[i] = null;
break;
}
}
}
includes = (IIncludeReference[])ArrayUtil.removeNulls(IIncludeReference.class, includes);
for (int i = 0; i < includes.length; ++i) {
indexer.runCtags(includes[i].getPath());
}
}
}

View file

@ -27,11 +27,8 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
class PDOMFastHandleDelta extends Job {
private final PDOM pdom;
class PDOMFastHandleDelta extends PDOMFastIndexerJob {
private final ICElementDelta delta;
@ -42,8 +39,7 @@ class PDOMFastHandleDelta extends Job {
private List removedTUs;
public PDOMFastHandleDelta(PDOM pdom, ICElementDelta delta) {
super("Delta Handler");
this.pdom = pdom;
super("Delta Handler", pdom);
this.delta = delta;
}
@ -152,27 +148,6 @@ class PDOMFastHandleDelta extends Job {
}
}
protected void addTU(ITranslationUnit tu) throws InterruptedException, CoreException {
ILanguage language = tu.getLanguage();
if (language == null)
return;
// get the AST in a "Fast" way
IASTTranslationUnit ast = language.getASTTranslationUnit(tu,
ILanguage.AST_USE_INDEX
| ILanguage.AST_SKIP_INDEXED_HEADERS
| ILanguage.AST_SKIP_IF_NO_BUILD_INFO);
if (ast == null)
return;
pdom.acquireWriteLock();
try {
pdom.addSymbols(language, ast);
} finally {
pdom.releaseWriteLock();
}
}
protected void changeTU(ITranslationUnit tu) throws InterruptedException, CoreException {
ILanguage language = tu.getLanguage();
if (language == null)

View file

@ -17,8 +17,6 @@ import org.eclipse.cdt.core.dom.IPDOMIndexer;
import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
/**
* @author Doug Schaefer

View file

@ -0,0 +1,56 @@
/*******************************************************************************
* 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.indexer.fast;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
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.internal.core.pdom.PDOM;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.jobs.Job;
/**
* @author Doug Schaefer
*
*/
public abstract class PDOMFastIndexerJob extends Job {
protected final PDOM pdom;
public PDOMFastIndexerJob(String name, PDOM pdom) {
super(name);
this.pdom = pdom;
}
protected void addTU(ITranslationUnit tu) throws InterruptedException, CoreException {
ILanguage language = tu.getLanguage();
if (language == null)
return;
// get the AST in a "Fast" way
IASTTranslationUnit ast = language.getASTTranslationUnit(tu,
ILanguage.AST_USE_INDEX
| ILanguage.AST_SKIP_INDEXED_HEADERS
| ILanguage.AST_SKIP_IF_NO_BUILD_INFO);
if (ast == null)
return;
pdom.acquireWriteLock();
try {
pdom.addSymbols(language, ast);
} finally {
pdom.releaseWriteLock();
}
}
}

View file

@ -16,9 +16,7 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.resources.IFile;
@ -31,19 +29,15 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.jobs.Job;
/**
* @author Doug Schaefer
*
*/
public class PDOMFastReindex extends Job {
public class PDOMFastReindex extends PDOMFastIndexerJob {
private final PDOM pdom;
public PDOMFastReindex(PDOM pdom) {
super("Reindex");
this.pdom = pdom;
super("Reindex", pdom);
}
protected IStatus run(IProgressMonitor monitor) {
@ -93,25 +87,4 @@ public class PDOMFastReindex extends Job {
}
}
protected void addTU(ITranslationUnit tu) throws InterruptedException, CoreException {
ILanguage language = tu.getLanguage();
if (language == null)
return;
// get the AST in a "Fast" way
IASTTranslationUnit ast = language.getASTTranslationUnit(tu,
ILanguage.AST_USE_INDEX
| ILanguage.AST_SKIP_INDEXED_HEADERS
| ILanguage.AST_SKIP_IF_NO_BUILD_INFO);
if (ast == null)
return;
pdom.acquireWriteLock();
try {
pdom.addSymbols(language, ast);
} finally {
pdom.releaseWriteLock();
}
}
}

View file

@ -551,7 +551,7 @@
class="org.eclipse.cdt.internal.core.index.ctagsindexer.CTagsIndexer">
</run>
</cextension>
<run class="org.eclipse.cdt.internal.core.pdom.indexer.nulli.PDOMNullIndexer"/>
<run class="org.eclipse.cdt.internal.core.pdom.indexer.ctags.CtagsIndexer"/>
</extension>
<extension
id="nullindexer"