mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
PDOM - Added file inclusions to index. Started the Full Indexer. Change the visit method on BTrees to be accept, as is the standard name for such things.
This commit is contained in:
parent
064456a3b1
commit
d29e62720b
20 changed files with 589 additions and 92 deletions
|
@ -92,7 +92,7 @@ public class DBTest extends TestCase {
|
|||
}
|
||||
|
||||
public int findIn(BTree btree) throws CoreException {
|
||||
btree.visit(this);
|
||||
btree.accept(this);
|
||||
return record;
|
||||
}
|
||||
|
||||
|
|
|
@ -631,6 +631,9 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
* @see org.eclipse.cdt.core.model.ITranslationUnit#isSourceUnit()
|
||||
*/
|
||||
public boolean isSourceUnit() {
|
||||
if (isHeaderUnit())
|
||||
return false;
|
||||
|
||||
return (
|
||||
CCorePlugin.CONTENT_TYPE_CSOURCE.equals(contentTypeId)
|
||||
|| CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(contentTypeId)
|
||||
|
|
|
@ -39,6 +39,8 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
|||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile.Comparator;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile.Finder;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -60,7 +62,10 @@ public class PDOM extends PlatformObject
|
|||
private final IPath dbPath;
|
||||
private Database db;
|
||||
|
||||
public static final int VERSION = 1;
|
||||
public static final int VERSION = 2;
|
||||
// 0 - the beginning of it all
|
||||
// 1 - first change to kick off upgrades
|
||||
// 2 - added file inclusions
|
||||
|
||||
public static final int LINKAGES = Database.DATA_AREA;
|
||||
public static final int FILE_INDEX = Database.DATA_AREA + 4;
|
||||
|
@ -165,21 +170,41 @@ public class PDOM extends PlatformObject
|
|||
fileIndex = new BTree(getDB(), FILE_INDEX);
|
||||
return fileIndex;
|
||||
}
|
||||
|
||||
public PDOMFile getFile(String filename) throws CoreException {
|
||||
Finder finder = new Finder(db, filename);
|
||||
getFileIndex().accept(finder);
|
||||
int record = finder.getRecord();
|
||||
return record != 0 ? new PDOMFile(this, record) : null;
|
||||
}
|
||||
|
||||
public PDOMFile addFile(String filename) throws CoreException {
|
||||
PDOMFile file = getFile(filename);
|
||||
if (file == null) {
|
||||
file = new PDOMFile(this, filename);
|
||||
getFileIndex().insert(file.getRecord(), new Comparator(db));
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
public void addSymbols(ILanguage language, IASTTranslationUnit ast) throws CoreException {
|
||||
final PDOMLinkage linkage = getLinkage(language);
|
||||
if (linkage == null)
|
||||
return;
|
||||
|
||||
// Add in the includes
|
||||
IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives();
|
||||
for (int i = 0; i < includes.length; ++i) {
|
||||
IASTPreprocessorIncludeStatement include = includes[i];
|
||||
|
||||
String sourcePath = include.getFileLocation().getFileName();
|
||||
PDOMFile sourceFile = addFile(sourcePath);
|
||||
String destPath = include.getPath();
|
||||
//System.out.println(sourcePath + " -> " + destPath);
|
||||
PDOMFile destFile = addFile(destPath);
|
||||
sourceFile.addIncludeTo(destFile);
|
||||
}
|
||||
|
||||
// Add in the names
|
||||
ast.accept(new ASTVisitor() {
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
|
@ -197,12 +222,13 @@ public class PDOM extends PlatformObject
|
|||
};
|
||||
});;
|
||||
|
||||
// Tell the world
|
||||
fireChange();
|
||||
}
|
||||
|
||||
public void removeSymbols(ITranslationUnit tu) throws CoreException {
|
||||
String filename = ((IFile)tu.getResource()).getLocation().toOSString();
|
||||
PDOMFile file = PDOMFile.find(this, filename);
|
||||
PDOMFile file = getFile(filename);
|
||||
if (file == null)
|
||||
return;
|
||||
file.clear();
|
||||
|
|
|
@ -74,7 +74,7 @@ public class PDOMCodeReaderFactory implements ICodeReaderFactory {
|
|||
} catch (IOException e) {
|
||||
// ignore and use the path we were passed in
|
||||
}
|
||||
PDOMFile file = PDOMFile.find(pdom, path);
|
||||
PDOMFile file = pdom.getFile(path);
|
||||
if (file != null && file.getFirstName() != null)
|
||||
// Already got things from here
|
||||
return new SkippedInclusion(path);
|
||||
|
|
|
@ -191,11 +191,11 @@ public class BTree {
|
|||
*
|
||||
* @param visitor
|
||||
*/
|
||||
public void visit(IBTreeVisitor visitor) throws CoreException {
|
||||
visit(db.getInt(rootPointer), visitor, false);
|
||||
public void accept(IBTreeVisitor visitor) throws CoreException {
|
||||
accept(db.getInt(rootPointer), visitor, false);
|
||||
}
|
||||
|
||||
private boolean visit(int node, IBTreeVisitor visitor, boolean found) throws CoreException {
|
||||
private boolean accept(int node, IBTreeVisitor visitor, boolean found) throws CoreException {
|
||||
// if found is false, we are still in search mode
|
||||
// once found is true visit everything
|
||||
// return false when ready to quit
|
||||
|
@ -207,7 +207,7 @@ public class BTree {
|
|||
if (found) {
|
||||
int child = getChild(chunk, node, 0);
|
||||
if (child != 0)
|
||||
if (!visit(child, visitor, true))
|
||||
if (!accept(child, visitor, true))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -220,23 +220,23 @@ public class BTree {
|
|||
if (found) {
|
||||
if (!visitor.visit(record))
|
||||
return false;
|
||||
if (!visit(getChild(chunk, node, i + 1), visitor, true))
|
||||
if (!accept(getChild(chunk, node, i + 1), visitor, true))
|
||||
return false;
|
||||
} else {
|
||||
int compare = visitor.compare(record);
|
||||
if (compare > 0) {
|
||||
// start point is to the left
|
||||
if (!visit(getChild(chunk, node, i), visitor, false))
|
||||
if (!accept(getChild(chunk, node, i), visitor, false))
|
||||
return false;
|
||||
if (!visitor.visit(record))
|
||||
return false;
|
||||
if (!visit(getChild(chunk, node, i + 1), visitor, true))
|
||||
if (!accept(getChild(chunk, node, i + 1), visitor, true))
|
||||
return false;
|
||||
found = true;
|
||||
} else if (compare == 0) {
|
||||
if (!visitor.visit(record))
|
||||
return false;
|
||||
if (!visit(getChild(chunk, node, i + 1), visitor, true))
|
||||
if (!accept(getChild(chunk, node, i + 1), visitor, true))
|
||||
return false;
|
||||
found = true;
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ public class BTree {
|
|||
}
|
||||
|
||||
if (!found)
|
||||
return visit(getChild(chunk, node, i), visitor, false);
|
||||
return accept(getChild(chunk, node, i), visitor, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,12 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.BTree;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||
|
@ -25,11 +29,15 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*/
|
||||
public class PDOMFile {
|
||||
|
||||
private PDOM pdom;
|
||||
private int record;
|
||||
private final PDOM pdom;
|
||||
private final int record;
|
||||
|
||||
private static final int FIRST_NAME_OFFSET = 0;
|
||||
private static final int FILE_NAME_OFFSET = Database.INT_SIZE;
|
||||
private static final int FIRST_NAME = 0;
|
||||
private static final int FIRST_INCLUDE = 4;
|
||||
private static final int FIRST_INCLUDED_BY = 8;
|
||||
private static final int FILE_NAME = 12;
|
||||
|
||||
private static final int RECORD_SIZE = 12; // + length of string
|
||||
|
||||
public static class Comparator implements IBTreeComparator {
|
||||
private Database db;
|
||||
|
@ -39,62 +47,32 @@ public class PDOMFile {
|
|||
}
|
||||
|
||||
public int compare(int record1, int record2) throws CoreException {
|
||||
return db.stringCompare(record1 + FILE_NAME_OFFSET, record2 + FILE_NAME_OFFSET);
|
||||
return db.stringCompare(record1 + FILE_NAME, record2 + FILE_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class Visitor implements IBTreeVisitor {
|
||||
private Database db;
|
||||
private String key;
|
||||
public static class Finder implements IBTreeVisitor {
|
||||
private final Database db;
|
||||
private final String key;
|
||||
private int record;
|
||||
|
||||
public Visitor(Database db, String key) {
|
||||
public Finder(Database db, String key) {
|
||||
this.db = db;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public int compare(int record) throws CoreException {
|
||||
return db.stringCompare(record + FILE_NAME_OFFSET, key);
|
||||
return db.stringCompare(record + FILE_NAME, key);
|
||||
}
|
||||
}
|
||||
|
||||
public static class FindVisitor extends Visitor {
|
||||
|
||||
private int record;
|
||||
|
||||
public FindVisitor(Database db, String key) {
|
||||
super(db, key);
|
||||
}
|
||||
|
||||
public boolean visit(int record) throws CoreException {
|
||||
this.record = record;
|
||||
return false;
|
||||
}
|
||||
|
||||
public int findIn(BTree btree) throws CoreException {
|
||||
btree.visit(this);
|
||||
public int getRecord() {
|
||||
return record;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static PDOMFile insert(PDOM pdom, String filename) throws CoreException {
|
||||
BTree index = pdom.getFileIndex();
|
||||
PDOMFile pdomFile = find(pdom, filename);
|
||||
if (pdomFile == null) {
|
||||
Database db = pdom.getDB();
|
||||
int record = db.malloc(FILE_NAME_OFFSET + (filename.length() + 1) * Database.CHAR_SIZE);
|
||||
db.putInt(record + FIRST_NAME_OFFSET, 0);
|
||||
db.putString(record + FILE_NAME_OFFSET, filename);
|
||||
index.insert(record, new Comparator(db));
|
||||
pdomFile = new PDOMFile(pdom, record);
|
||||
}
|
||||
return pdomFile;
|
||||
}
|
||||
|
||||
public static PDOMFile find(PDOM pdom, String filename) throws CoreException {
|
||||
BTree index = pdom.getFileIndex();
|
||||
int record = new FindVisitor(pdom.getDB(), filename).findIn(index);
|
||||
return (record != 0) ? new PDOMFile(pdom, record) : null;
|
||||
}
|
||||
|
||||
public PDOMFile(PDOM pdom, int record) {
|
||||
|
@ -102,25 +80,64 @@ public class PDOMFile {
|
|||
this.record = record;
|
||||
}
|
||||
|
||||
public PDOMFile(PDOM pdom, String filename) throws CoreException {
|
||||
this.pdom = pdom;
|
||||
Database db = pdom.getDB();
|
||||
record = db.malloc(RECORD_SIZE + (filename.length() + 1) * 2);
|
||||
db.putString(record + FILE_NAME, filename);
|
||||
setFirstName(null);
|
||||
setFirstInclude(null);
|
||||
setFirstIncludedBy(null);
|
||||
}
|
||||
|
||||
public int getRecord() {
|
||||
return record;
|
||||
}
|
||||
|
||||
public String getFileName() throws CoreException {
|
||||
return pdom.getDB().getString(record + FILE_NAME_OFFSET);
|
||||
return pdom.getDB().getString(record + FILE_NAME);
|
||||
}
|
||||
|
||||
public PDOMName getFirstName() throws CoreException {
|
||||
int namerec = pdom.getDB().getInt(record + FIRST_NAME_OFFSET);
|
||||
int namerec = pdom.getDB().getInt(record + FIRST_NAME);
|
||||
return namerec != 0 ? new PDOMName(pdom, namerec) : null;
|
||||
}
|
||||
|
||||
public void setFirstName(PDOMName firstName) throws CoreException {
|
||||
int namerec = firstName != null ? firstName.getRecord() : 0;
|
||||
pdom.getDB().putInt(record + FIRST_NAME_OFFSET, namerec);
|
||||
pdom.getDB().putInt(record + FIRST_NAME, namerec);
|
||||
}
|
||||
|
||||
public PDOMInclude getFirstInclude() throws CoreException {
|
||||
int increc = pdom.getDB().getInt(record + FIRST_INCLUDE);
|
||||
return increc != 0 ? new PDOMInclude(pdom, increc) : null;
|
||||
}
|
||||
|
||||
public void setFirstInclude(PDOMInclude include) throws CoreException {
|
||||
int rec = include != null ? include.getRecord() : 0;
|
||||
pdom.getDB().putInt(record + FIRST_INCLUDE, rec);
|
||||
}
|
||||
|
||||
public PDOMInclude getFirstIncludedBy() throws CoreException {
|
||||
int rec = pdom.getDB().getInt(record + FIRST_INCLUDED_BY);
|
||||
return rec != 0 ? new PDOMInclude(pdom, rec) : null;
|
||||
}
|
||||
|
||||
public void setFirstIncludedBy(PDOMInclude includedBy) throws CoreException {
|
||||
int rec = includedBy != null ? includedBy.getRecord() : 0;
|
||||
pdom.getDB().putInt(record + FIRST_INCLUDED_BY, rec);
|
||||
}
|
||||
|
||||
public void clear() throws CoreException {
|
||||
// Remove the includes
|
||||
PDOMInclude include = getFirstInclude();
|
||||
while (include != null) {
|
||||
PDOMInclude nextInclude = include.getNextInIncludes();
|
||||
include.delete();
|
||||
include = nextInclude;
|
||||
}
|
||||
setFirstInclude(include);
|
||||
|
||||
// Delete all the names in this file
|
||||
PDOMName name = getFirstName();
|
||||
while (name != null) {
|
||||
|
@ -132,4 +149,56 @@ public class PDOMFile {
|
|||
setFirstName(null);
|
||||
}
|
||||
|
||||
public PDOMInclude addIncludeTo(PDOMFile file) throws CoreException {
|
||||
PDOMInclude include = new PDOMInclude(pdom);
|
||||
|
||||
PDOMInclude firstInclude = getFirstInclude();
|
||||
if (firstInclude != null) {
|
||||
include.setNextInIncludes(firstInclude);
|
||||
}
|
||||
setFirstInclude(include);
|
||||
|
||||
file.addIncludedBy(include);
|
||||
return include;
|
||||
}
|
||||
|
||||
public void addIncludedBy(PDOMInclude include) throws CoreException {
|
||||
PDOMInclude firstIncludedBy = getFirstIncludedBy();
|
||||
if (firstIncludedBy != null) {
|
||||
include.setNextInIncludedBy(firstIncludedBy);
|
||||
firstIncludedBy.setPrevInIncludedBy(include);
|
||||
}
|
||||
setFirstIncludedBy(include);
|
||||
}
|
||||
|
||||
public PDOMFile[] getAllIncludedBy() throws CoreException {
|
||||
Map files = new HashMap();
|
||||
LinkedList todo = new LinkedList();
|
||||
|
||||
// Add me in to make sure we don't get caught in a circular include
|
||||
String myFileName = getFileName();
|
||||
files.put(myFileName, this);
|
||||
|
||||
todo.addLast(this);
|
||||
while (todo.size() > 0) {
|
||||
PDOMFile file = (PDOMFile)todo.removeFirst();
|
||||
PDOMInclude includedBy = getFirstIncludedBy();
|
||||
while (includedBy != null) {
|
||||
PDOMFile incFile = includedBy.getIncludedBy();
|
||||
String incFileName = incFile.getFileName();
|
||||
if (files.get(incFileName) == null) {
|
||||
files.put(incFileName, incFile);
|
||||
todo.addLast(incFile);
|
||||
}
|
||||
includedBy = includedBy.getNextInIncludedBy();
|
||||
}
|
||||
}
|
||||
|
||||
// Now remove me
|
||||
files.remove(myFileName);
|
||||
|
||||
Collection values = files.values();
|
||||
return (PDOMFile[])values.toArray(new PDOMFile[values.size()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMInclude {
|
||||
|
||||
private final PDOM pdom;
|
||||
private final int record;
|
||||
|
||||
private final int INCLUDES = 0;
|
||||
private final int INCLUDED_BY = 4;
|
||||
private final int INCLUDES_NEXT = 8;
|
||||
private final int INCLUDED_BY_NEXT = 12;
|
||||
private final int INCLUDED_BY_PREV = 16;
|
||||
|
||||
private final int RECORD_SIZE = 20;
|
||||
|
||||
public PDOMInclude(PDOM pdom, int record) {
|
||||
this.pdom = pdom;
|
||||
this.record = record;
|
||||
}
|
||||
|
||||
public PDOMInclude(PDOM pdom) throws CoreException {
|
||||
this.pdom = pdom;
|
||||
this.record = pdom.getDB().malloc(RECORD_SIZE);
|
||||
}
|
||||
|
||||
public int getRecord() {
|
||||
return record;
|
||||
}
|
||||
|
||||
public void delete() throws CoreException {
|
||||
// Remove us from the includedBy chain
|
||||
PDOMInclude prevInclude = getPrevInIncludedBy();
|
||||
PDOMInclude nextInclude = getNextInIncludedBy();
|
||||
if (prevInclude != null)
|
||||
prevInclude.setNextInIncludedBy(nextInclude);
|
||||
else
|
||||
getIncludes().setFirstIncludedBy(null);
|
||||
|
||||
if (nextInclude != null)
|
||||
nextInclude.setPrevInIncludedBy(prevInclude);
|
||||
|
||||
// Delete our record
|
||||
pdom.getDB().free(record);
|
||||
}
|
||||
|
||||
public PDOMFile getIncludes() throws CoreException {
|
||||
int rec = pdom.getDB().getInt(record + INCLUDES);
|
||||
return rec != 0 ? new PDOMFile(pdom, rec) : null;
|
||||
}
|
||||
|
||||
public void setIncludes(PDOMFile includes) throws CoreException {
|
||||
pdom.getDB().putInt(record + INCLUDES, includes.getRecord());
|
||||
}
|
||||
|
||||
public PDOMFile getIncludedBy() throws CoreException {
|
||||
int rec = pdom.getDB().getInt(record + INCLUDED_BY);
|
||||
return rec != 0 ? new PDOMFile(pdom, rec) : null;
|
||||
}
|
||||
|
||||
public void setIncludedBy(PDOMFile includedBy) throws CoreException {
|
||||
int rec = includedBy != null ? includedBy.getRecord() : 0;
|
||||
pdom.getDB().putInt(record + INCLUDED_BY, rec);
|
||||
}
|
||||
|
||||
public PDOMInclude getNextInIncludes() throws CoreException {
|
||||
int rec = pdom.getDB().getInt(record + INCLUDES_NEXT);
|
||||
return rec != 0 ? new PDOMInclude(pdom, rec) : null;
|
||||
}
|
||||
|
||||
public void setNextInIncludes(PDOMInclude include) throws CoreException {
|
||||
pdom.getDB().putInt(record + INCLUDES_NEXT, include.getRecord());
|
||||
}
|
||||
|
||||
public PDOMInclude getNextInIncludedBy() throws CoreException {
|
||||
int rec = pdom.getDB().getInt(record + INCLUDED_BY_NEXT);
|
||||
return rec != 0 ? new PDOMInclude(pdom, rec) : null;
|
||||
}
|
||||
|
||||
public void setNextInIncludedBy(PDOMInclude include) throws CoreException {
|
||||
pdom.getDB().putInt(record + INCLUDED_BY_NEXT, include.getRecord());
|
||||
}
|
||||
|
||||
public PDOMInclude getPrevInIncludedBy() throws CoreException {
|
||||
int rec = pdom.getDB().getInt(record + INCLUDED_BY_PREV);
|
||||
return rec != 0 ? new PDOMInclude(pdom, rec) : null;
|
||||
}
|
||||
|
||||
public void setPrevInIncludedBy(PDOMInclude include) throws CoreException {
|
||||
pdom.getDB().putInt(record + INCLUDED_BY_PREV, include.getRecord());
|
||||
}
|
||||
|
||||
}
|
|
@ -113,7 +113,7 @@ public abstract class PDOMLinkage extends PDOMNode {
|
|||
|
||||
public void accept(final IPDOMVisitor visitor) throws CoreException {
|
||||
super.accept(visitor);
|
||||
getIndex().visit(new IBTreeVisitor() {
|
||||
getIndex().accept(new IBTreeVisitor() {
|
||||
public int compare(int record) throws CoreException {
|
||||
return 1;
|
||||
};
|
||||
|
|
|
@ -84,7 +84,7 @@ public class PDOMName implements IASTName, IASTFileLocation {
|
|||
// Hook us up the the liked name list from file
|
||||
IASTFileLocation fileloc = name.getFileLocation();
|
||||
String filename = fileloc.getFileName();
|
||||
PDOMFile pdomFile = PDOMFile.insert(pdom, filename);
|
||||
PDOMFile pdomFile = pdom.addFile(filename);
|
||||
db.putInt(record + FILE_REC_OFFSET, pdomFile.getRecord());
|
||||
PDOMName firstName = pdomFile.getFirstName();
|
||||
if (firstName != null) {
|
||||
|
|
|
@ -161,7 +161,7 @@ public class PDOMCLinkage extends PDOMLinkage {
|
|||
PDOMNode parent = getParent(binding);
|
||||
if (parent == this) {
|
||||
FindBinding visitor = new FindBinding(pdom, binding.getNameCharArray(), getBindingType(binding));
|
||||
getIndex().visit(visitor);
|
||||
getIndex().accept(visitor);
|
||||
return visitor.pdomBinding;
|
||||
} else if (parent instanceof PDOMMemberOwner) {
|
||||
PDOMMemberOwner owner = (PDOMMemberOwner)parent;
|
||||
|
@ -200,16 +200,16 @@ public class PDOMCLinkage extends PDOMLinkage {
|
|||
IASTNode eParent = parent.getParent();
|
||||
if (eParent instanceof IASTFunctionCallExpression) {
|
||||
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CFUNCTION);
|
||||
getIndex().visit(visitor);
|
||||
getIndex().accept(visitor);
|
||||
return visitor.pdomBinding;
|
||||
} else {
|
||||
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CVARIABLE);
|
||||
getIndex().visit(visitor);
|
||||
getIndex().accept(visitor);
|
||||
return visitor.pdomBinding;
|
||||
}
|
||||
} else if (parent instanceof ICASTElaboratedTypeSpecifier) {
|
||||
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CSTRUCTURE);
|
||||
getIndex().visit(visitor);
|
||||
getIndex().accept(visitor);
|
||||
return visitor.pdomBinding;
|
||||
}
|
||||
return null;
|
||||
|
@ -217,6 +217,6 @@ public class PDOMCLinkage extends PDOMLinkage {
|
|||
|
||||
public void findBindings(String pattern, List bindings) throws CoreException {
|
||||
MatchBinding visitor = new MatchBinding(pdom, pattern, bindings);
|
||||
getIndex().visit(visitor);
|
||||
getIndex().accept(visitor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
PDOMNode parent = getParent(binding);
|
||||
if (parent == this) {
|
||||
FindBinding visitor = new FindBinding(pdom, binding.getNameCharArray(), getBindingType(binding));
|
||||
getIndex().visit(visitor);
|
||||
getIndex().accept(visitor);
|
||||
return visitor.pdomBinding;
|
||||
} else if (parent instanceof PDOMMemberOwner) {
|
||||
PDOMMemberOwner owner = (PDOMMemberOwner)parent;
|
||||
|
@ -240,23 +240,23 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
IASTNode eParent = parent.getParent();
|
||||
if (eParent instanceof IASTFunctionCallExpression) {
|
||||
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CPPFUNCTION);
|
||||
getIndex().visit(visitor);
|
||||
getIndex().accept(visitor);
|
||||
return visitor.pdomBinding;
|
||||
} else {
|
||||
FindBinding visitor = new FindBinding(pdom, name.toCharArray(),
|
||||
(name.getParent() instanceof ICPPASTQualifiedName
|
||||
&& ((ICPPASTQualifiedName)name.getParent()).getLastName() != name)
|
||||
? CPPNAMESPACE : CPPVARIABLE);
|
||||
getIndex().visit(visitor);
|
||||
getIndex().accept(visitor);
|
||||
return visitor.pdomBinding;
|
||||
}
|
||||
} else if (parent instanceof IASTNamedTypeSpecifier) {
|
||||
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CPPCLASSTYPE);
|
||||
getIndex().visit(visitor);
|
||||
getIndex().accept(visitor);
|
||||
return visitor.pdomBinding;
|
||||
} else if (parent instanceof ICPPASTNamespaceAlias) {
|
||||
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), CPPNAMESPACE);
|
||||
getIndex().visit(visitor);
|
||||
getIndex().accept(visitor);
|
||||
return visitor.pdomBinding;
|
||||
}
|
||||
|
||||
|
@ -265,7 +265,7 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
|
||||
public void findBindings(String pattern, List bindings) throws CoreException {
|
||||
MatchBinding visitor = new MatchBinding(pdom, pattern, bindings);
|
||||
getIndex().visit(visitor);
|
||||
getIndex().accept(visitor);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class PDOMCPPNamespace extends PDOMBinding
|
|||
|
||||
public void accept(final IPDOMVisitor visitor) throws CoreException {
|
||||
super.accept(visitor);
|
||||
getIndex().visit(new IBTreeVisitor() {
|
||||
getIndex().accept(new IBTreeVisitor() {
|
||||
public int compare(int record) throws CoreException {
|
||||
return 1;
|
||||
};
|
||||
|
@ -163,19 +163,19 @@ public class PDOMCPPNamespace extends PDOMBinding
|
|||
IASTNode eParent = parent.getParent();
|
||||
if (eParent instanceof IASTFunctionCallExpression) {
|
||||
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), PDOMCPPLinkage.CPPFUNCTION);
|
||||
getIndex().visit(visitor);
|
||||
getIndex().accept(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);
|
||||
getIndex().accept(visitor);
|
||||
return visitor.pdomBinding;
|
||||
}
|
||||
} else if (parent instanceof IASTNamedTypeSpecifier) {
|
||||
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE);
|
||||
getIndex().visit(visitor);
|
||||
getIndex().accept(visitor);
|
||||
return visitor.pdomBinding;
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -33,20 +33,16 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob {
|
|||
private final ICElementDelta delta;
|
||||
|
||||
private List addedTUs;
|
||||
|
||||
private List changedTUs;
|
||||
|
||||
private List removedTUs;
|
||||
|
||||
public PDOMFastHandleDelta(PDOM pdom, ICElementDelta delta) {
|
||||
super(pdom);
|
||||
this.delta = delta;
|
||||
setRule(CCorePlugin.getPDOMManager().getIndexerSchedulingRule());
|
||||
}
|
||||
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
try {
|
||||
monitor.subTask("Delta");
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
processDelta(delta);
|
||||
|
@ -56,7 +52,6 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob {
|
|||
+ (removedTUs != null ? removedTUs.size() : 0);
|
||||
|
||||
if (count == 0) {
|
||||
monitor.done();
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,12 +43,13 @@ public class PDOMFastReindex extends PDOMFastIndexerJob {
|
|||
protected IStatus run(IProgressMonitor monitor) {
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
final List addedTUs = new ArrayList();
|
||||
|
||||
// First clear out the DB
|
||||
pdom.clear();
|
||||
|
||||
// Now repopulate it
|
||||
// First index all the source files (i.e. not headers)
|
||||
final List addedSources = new ArrayList();
|
||||
|
||||
pdom.getProject().getProject().accept(new IResourceProxyVisitor() {
|
||||
public boolean visit(IResourceProxy proxy) throws CoreException {
|
||||
if (proxy.getType() == IResource.FILE) {
|
||||
|
@ -60,8 +61,7 @@ public class PDOMFastReindex extends PDOMFastIndexerJob {
|
|||
|
||||
if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(contentTypeId)
|
||||
|| CCorePlugin.CONTENT_TYPE_CSOURCE.equals(contentTypeId)) {
|
||||
// TODO handle header files
|
||||
addedTUs.add((ITranslationUnit)CoreModel.getDefault().create((IFile)proxy.requestResource()));
|
||||
addedSources.add((ITranslationUnit)CoreModel.getDefault().create((IFile)proxy.requestResource()));
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
|
@ -70,15 +70,43 @@ public class PDOMFastReindex extends PDOMFastIndexerJob {
|
|||
}
|
||||
}, 0);
|
||||
|
||||
for (Iterator i = addedTUs.iterator(); i.hasNext();)
|
||||
for (Iterator i = addedSources.iterator(); i.hasNext();)
|
||||
addTU((ITranslationUnit)i.next());
|
||||
|
||||
// Now add in the header files but only if they aren't already indexed
|
||||
final List addedHeaders = new ArrayList();
|
||||
|
||||
pdom.getProject().getProject().accept(new IResourceProxyVisitor() {
|
||||
public boolean visit(IResourceProxy proxy) throws CoreException {
|
||||
if (proxy.getType() == IResource.FILE) {
|
||||
String fileName = proxy.getName();
|
||||
IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(fileName);
|
||||
if (contentType == null)
|
||||
return true;
|
||||
String contentTypeId = contentType.getId();
|
||||
|
||||
if (CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(contentTypeId)
|
||||
|| CCorePlugin.CONTENT_TYPE_CHEADER.equals(contentTypeId)) {
|
||||
IFile rfile = (IFile)proxy.requestResource();
|
||||
String filename = rfile.getLocation().toOSString();
|
||||
if (pdom.getFile(filename) == null)
|
||||
addedHeaders.add((ITranslationUnit)CoreModel.getDefault().create(rfile));
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}, 0);
|
||||
|
||||
for (Iterator i = addedHeaders.iterator(); i.hasNext();)
|
||||
addTU((ITranslationUnit)i.next());
|
||||
|
||||
String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID
|
||||
+ "/debug/pdomtimings"); //$NON-NLS-1$
|
||||
if (showTimings != null && showTimings.equalsIgnoreCase("true")) //$NON-NLS-1$
|
||||
System.out.println("PDOM Reindex Time: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
|
||||
System.out.println("PDOM Fast Reindex Time: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
|
||||
|
||||
monitor.done();
|
||||
return Status.OK_STATUS;
|
||||
} catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*******************************************************************************
|
||||
* 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.full;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElementDelta;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMFullHandleDelta extends PDOMFullIndexerJob {
|
||||
|
||||
private final ICElementDelta delta;
|
||||
|
||||
public PDOMFullHandleDelta(PDOM pdom, ICElementDelta delta) {
|
||||
super(pdom);
|
||||
this.delta = delta;
|
||||
}
|
||||
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
// try {
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
return Status.OK_STATUS;
|
||||
// } catch (CoreException e) {
|
||||
// return e.getStatus();
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*******************************************************************************
|
||||
* 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.full;
|
||||
|
||||
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.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* The Full indexer does full parsing in order to gather index information.
|
||||
* It has good accuracy but is relatively slow.
|
||||
*
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMFullIndexer implements IPDOMIndexer {
|
||||
|
||||
private IPDOM pdom;
|
||||
|
||||
public void handleDelta(ICElementDelta delta) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void reindex() throws CoreException {
|
||||
new PDOMFullReindex((PDOM)pdom).schedule();
|
||||
}
|
||||
|
||||
public void setPDOM(IPDOM pdom) {
|
||||
this.pdom = pdom;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*******************************************************************************
|
||||
* 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.full;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
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 PDOMFullIndexerJob extends Job {
|
||||
|
||||
protected final PDOM pdom;
|
||||
|
||||
public PDOMFullIndexerJob(PDOM pdom) {
|
||||
super("Full Indexer: " + pdom.getProject().getElementName());
|
||||
this.pdom = pdom;
|
||||
setRule(CCorePlugin.getPDOMManager().getIndexerSchedulingRule());
|
||||
}
|
||||
|
||||
protected void addTU(ITranslationUnit tu) throws InterruptedException, CoreException {
|
||||
ILanguage language = tu.getLanguage();
|
||||
if (language == null)
|
||||
return;
|
||||
|
||||
// get the AST in the "Full" way, i.e. don't skip anything.
|
||||
IASTTranslationUnit ast = language.getASTTranslationUnit(tu, ILanguage.AST_SKIP_IF_NO_BUILD_INFO);
|
||||
|
||||
if (ast == null)
|
||||
return;
|
||||
|
||||
pdom.acquireWriteLock();
|
||||
try {
|
||||
pdom.addSymbols(language, ast);
|
||||
} finally {
|
||||
pdom.releaseWriteLock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
/*******************************************************************************
|
||||
* 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.full;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICElementVisitor;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMFullReindex extends PDOMFullIndexerJob {
|
||||
|
||||
public PDOMFullReindex(PDOM pdom) {
|
||||
super(pdom);
|
||||
}
|
||||
|
||||
protected IStatus run(final IProgressMonitor monitor) {
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
// First clear out the PDOM
|
||||
pdom.clear();
|
||||
|
||||
// Get a count of all the elements that we'll be visiting for the monitor
|
||||
final int[] count = { 0 };
|
||||
pdom.getProject().accept(new ICElementVisitor() {
|
||||
public boolean visit(ICElement element) throws CoreException {
|
||||
switch (element.getElementType()) {
|
||||
case ICElement.C_UNIT:
|
||||
++count[0];
|
||||
return false;
|
||||
case ICElement.C_CCONTAINER:
|
||||
case ICElement.C_PROJECT:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
monitor.beginTask("Indexing", count[0]);
|
||||
|
||||
// First index all the source files (i.e. not headers)
|
||||
pdom.getProject().accept(new ICElementVisitor() {
|
||||
public boolean visit(ICElement element) throws CoreException {
|
||||
switch (element.getElementType()) {
|
||||
case ICElement.C_UNIT:
|
||||
ITranslationUnit tu = (ITranslationUnit)element;
|
||||
if (tu.isSourceUnit()) {
|
||||
monitor.subTask(tu.getElementName());
|
||||
try {
|
||||
addTU(tu);
|
||||
} catch (InterruptedException e) {
|
||||
throw new CoreException(Status.CANCEL_STATUS);
|
||||
}
|
||||
monitor.worked(1);
|
||||
}
|
||||
return false;
|
||||
case ICElement.C_CCONTAINER:
|
||||
case ICElement.C_PROJECT:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Now add in the header files but only if they aren't already indexed
|
||||
pdom.getProject().accept(new ICElementVisitor() {
|
||||
public boolean visit(ICElement element) throws CoreException {
|
||||
switch (element.getElementType()) {
|
||||
case ICElement.C_UNIT:
|
||||
ITranslationUnit tu = (ITranslationUnit)element;
|
||||
if (tu.isHeaderUnit()) {
|
||||
IFile rfile = (IFile)tu.getUnderlyingResource();
|
||||
String filename = rfile.getLocation().toOSString();
|
||||
if (pdom.getFile(filename) == null) {
|
||||
monitor.subTask(tu.getElementName());
|
||||
try {
|
||||
addTU(tu);
|
||||
} catch (InterruptedException e) {
|
||||
throw new CoreException(Status.CANCEL_STATUS);
|
||||
}
|
||||
}
|
||||
monitor.worked(1);
|
||||
}
|
||||
return false;
|
||||
case ICElement.C_CCONTAINER:
|
||||
case ICElement.C_PROJECT:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID
|
||||
+ "/debug/pdomtimings"); //$NON-NLS-1$
|
||||
if (showTimings != null && showTimings.equalsIgnoreCase("true")) //$NON-NLS-1$
|
||||
System.out.println("PDOM Full Reindex Time: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
|
||||
|
||||
return Status.OK_STATUS;
|
||||
} catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -540,7 +540,7 @@
|
|||
class="org.eclipse.cdt.internal.core.index.domsourceindexer.DOMSourceIndexer">
|
||||
</run>
|
||||
</cextension>
|
||||
<run class="org.eclipse.cdt.internal.core.pdom.indexer.nulli.PDOMNullIndexer"/>
|
||||
<run class="org.eclipse.cdt.internal.core.pdom.indexer.full.PDOMFullIndexer"/>
|
||||
</extension>
|
||||
<extension
|
||||
id="ctagsindexer"
|
||||
|
|
|
@ -68,10 +68,10 @@ public class LinkageCache {
|
|||
this.linkage = linkage;
|
||||
|
||||
Counter counter = new Counter(pdom);
|
||||
linkage.getIndex().visit(counter);
|
||||
linkage.getIndex().accept(counter);
|
||||
cache = new int[counter.count];
|
||||
FillCache fillCache = new FillCache(pdom, cache);
|
||||
linkage.getIndex().visit(fillCache);
|
||||
linkage.getIndex().accept(fillCache);
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
|
|
Loading…
Add table
Reference in a new issue