1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-30 20:35:38 +02:00

Propogate PDOM changes to support search down the PDOM hierarchy.

This commit is contained in:
Doug Schaefer 2006-08-25 01:46:32 +00:00
parent d1c5dd658c
commit cec3d1b1ef
28 changed files with 265 additions and 1591 deletions

View file

@ -47,7 +47,6 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.internal.core.pdom.dom,
org.eclipse.cdt.internal.core.pdom.dom.c,
org.eclipse.cdt.internal.core.pdom.dom.cpp,
org.eclipse.cdt.internal.core.pdom.indexer.ctags,
org.eclipse.cdt.internal.core.pdom.indexer.fast,
org.eclipse.cdt.internal.core.pdom.indexer.nulli,
org.eclipse.cdt.internal.core.util,

View file

@ -67,6 +67,9 @@ public class AllTypesCache {
return true;
}
public void leave(IPDOMNode node) throws CoreException {
}
public List getTypes() {
return types;
}

View file

@ -26,7 +26,7 @@ import org.eclipse.core.runtime.IAdaptable;
public interface IPDOM extends IAdaptable {
/**
* Find all the bindings that match the pattern.
* Find all the bindings whose names that match the pattern.
*
* @param pattern
* @return
@ -34,6 +34,15 @@ public interface IPDOM extends IAdaptable {
*/
public IBinding[] findBindings(Pattern pattern) throws CoreException;
/**
* Find all bindings whose qualified names match the array of patterns.
*
* @param pattern
* @return
* @throws CoreException
*/
public IBinding[] findBindings(Pattern[] pattern) throws CoreException;
/**
* Recursively visit the nodes in this PDOM using the given visitor.
*

View file

@ -24,9 +24,17 @@ public interface IPDOMVisitor {
* this node, or false to skip to the next sibling of this node.
* Throw CoreException to stop the visit.
*
* @param node
* @return
* @param node being visited
* @return whether to visit children
*/
public boolean visit(IPDOMNode node) throws CoreException;
/**
* All children have been visited, about to go back to the parent.
*
* @param node that has just completed visitation
* @throws CoreException
*/
public void leave(IPDOMNode node) throws CoreException;
}

View file

@ -22,6 +22,7 @@ import java.util.regex.Pattern;
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.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMResolver;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.IPDOMWriter;
@ -249,14 +250,60 @@ public class PDOM extends PlatformObject
return null;
}
private static class BindingFinder implements IPDOMVisitor {
private final Pattern[] pattern;
private final IBinding[] match;
private int level = 0;
private List bindings = new ArrayList();
public BindingFinder(Pattern[] pattern) {
this.pattern = pattern;
match = new IBinding[pattern.length];
}
public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof IBinding) {
IBinding binding = (IBinding)node;
if (pattern[level].matcher(binding.getName()).matches()) {
if (level < pattern.length - 1) {
match[level++] = binding;
} else {
bindings.add(binding);
// Only visit children if using simple name
return pattern.length == 1;
}
}
}
return true;
}
public void leave(IPDOMNode node) throws CoreException {
if (node instanceof IBinding) {
if (level > 0 && match[level - 1] == (IBinding)node)
// pop the stack
--level;
}
}
public IBinding[] getBindings() {
return (IBinding[])bindings.toArray(new IBinding[bindings.size()]);
}
}
public IBinding[] findBindings(Pattern pattern) throws CoreException {
List bindings = new ArrayList();
return findBindings(new Pattern[] { pattern });
}
public IBinding[] findBindings(Pattern[] pattern) throws CoreException {
BindingFinder finder = new BindingFinder(pattern);
PDOMLinkage linkage = getFirstLinkage();
while (linkage != null) {
linkage.findBindings(pattern, bindings);
linkage.accept(finder);
linkage = linkage.getNextLinkage();
}
return (IBinding[])bindings.toArray(new IBinding[bindings.size()]);
return finder.getBindings();
}
public PDOMLinkage getLinkage(ILanguage language) throws CoreException {

View file

@ -25,7 +25,6 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IElementChangedListener;
import org.eclipse.cdt.internal.core.pdom.indexer.ctags.CtagsIndexer;
import org.eclipse.cdt.internal.core.pdom.indexer.nulli.PDOMNullIndexer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
@ -199,7 +198,7 @@ public class PDOMManager implements IPDOMManager, IElementChangedListener {
}
// if Indexer still null schedule a job to get it
if (indexerId == null || indexerId.equals(CtagsIndexer.ID))
if (indexerId == null || indexerId.equals("org.eclipse.cdt.core.ctagsindexer")) //$NON-NLS-1$
// make it the default, ctags is gone
indexerId = getDefaultIndexerId();

View file

@ -0,0 +1,87 @@
/*******************************************************************************
* 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 java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.runtime.CoreException;
public final class FindBindingsInBTree extends PDOMNamedNode.NodeFinder {
private List bindings = new ArrayList();
private final int[] desiredType;
/**
* Matches all types.
*
* @param pdom
* @param name
*/
public FindBindingsInBTree(PDOM pdom, char[] name) {
this(pdom, name, null);
}
/**
* Match a specific type.
*
* @param pdom
* @param name
* @param desiredType
*/
public FindBindingsInBTree(PDOM pdom, char[] name, int desiredType) {
this(pdom, name, new int[] { desiredType });
}
/**
* Match a collection of types.
*
* @param pdom
* @param name
* @param desiredType
*/
public FindBindingsInBTree(PDOM pdom, char[] name, int[] desiredType) {
super(pdom, name);
this.desiredType = desiredType;
}
public boolean visit(int record) throws CoreException {
if (record == 0)
return true;
PDOMBinding tBinding = pdom.getBinding(record);
if (!tBinding.hasName(name))
// no more bindings with our desired name
return false;
if (desiredType == null) {
bindings.add(tBinding);
return true; // look for more
} else {
int nodeType = tBinding.getNodeType();
for (int i = 0; i < desiredType.length; ++i)
if (nodeType == desiredType[i]) {
bindings.add(tBinding);
return true; // look for more
}
}
// wrong type, try again
return true;
}
public IBinding[] getBinding() {
return (IBinding[])bindings.toArray(new IBinding[bindings.size()]);
}
}

View file

@ -11,10 +11,6 @@
package org.eclipse.cdt.internal.core.pdom.dom;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
@ -37,35 +33,6 @@ import org.eclipse.core.runtime.CoreException;
*/
public abstract class PDOMLinkage extends PDOMNamedNode {
protected static final class MatchBinding implements IBTreeVisitor {
private final PDOM pdom;
private final List bindings;
private final Pattern pattern;
public MatchBinding(PDOM pdom, Pattern pattern, List bindings) {
this.pdom = pdom;
this.bindings = bindings;
this.pattern = pattern;
}
public boolean visit(int record) throws CoreException {
if (record == 0)
return true;
// TODO of course do something smarter here
PDOMBinding binding = pdom.getBinding(record);
if (binding != null) {
Matcher matcher = pattern.matcher(binding.getName());
if (matcher.matches())
bindings.add(binding);
}
return true;
}
public int compare(int record) throws CoreException {
return 1;
}
}
// record offsets
private static final int ID_OFFSET = PDOMNamedNode.RECORD_SIZE + 0;
private static final int NEXT_OFFSET = PDOMNamedNode.RECORD_SIZE + 4;
@ -133,6 +100,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode {
if (binding != null) {
if (visitor.visit(binding))
binding.accept(visitor);
visitor.leave(binding);
}
return true;
};
@ -172,6 +140,4 @@ public abstract class PDOMLinkage extends PDOMNamedNode {
public abstract IBinding resolveBinding(IASTName name) throws CoreException;
public abstract void findBindings(Pattern pattern, List bindings) throws CoreException;
}

View file

@ -52,6 +52,7 @@ public abstract class PDOMMemberOwner extends PDOMBinding {
PDOMNode node = linkage.getNode(item.getItem());
if (visitor.visit(node))
node.accept(visitor);
visitor.leave(node);
item = item.getNext();
} while (!item.equals(firstItem));
}

View file

@ -11,9 +11,6 @@
package org.eclipse.cdt.internal.core.pdom.dom.c;
import java.util.List;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
@ -202,6 +199,8 @@ public class PDOMCLinkage extends PDOMLinkage {
}
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
public PDOMBinding getBinding() { return binding; }
}
@ -295,14 +294,9 @@ public class PDOMCLinkage extends PDOMLinkage {
return null;
}
public void findBindings(Pattern pattern, List bindings) throws CoreException {
MatchBinding visitor = new MatchBinding(pdom, pattern, bindings);
getIndex().accept(visitor);
}
public PDOMNode addType(PDOMNode parent, IType type) throws CoreException {
// TODO Auto-generated method stub
return null;
}
}
}

View file

@ -63,6 +63,8 @@ public class PDOMCStructure extends PDOMMemberOwner implements ICompositeType {
fields.add(node);
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
public IField[] getFields() {
return (IField[])fields.toArray(new IField[fields.size()]);
}
@ -94,6 +96,8 @@ public class PDOMCStructure extends PDOMMemberOwner implements ICompositeType {
}
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
public IField getField() { return field; }
}
@ -125,4 +129,4 @@ public class PDOMCStructure extends PDOMMemberOwner implements ICompositeType {
return false;
}
}
}

View file

@ -144,6 +144,8 @@ public class PDOMCPPClassType extends PDOMMemberOwner implements ICPPClassType,
methods.add(node);
return false; // don't visit the method
}
public void leave(IPDOMNode node) throws CoreException {
}
public ICPPMethod[] getMethods() {
return (ICPPMethod[])methods.toArray(new ICPPMethod[methods.size()]);
}
@ -200,6 +202,8 @@ public class PDOMCPPClassType extends PDOMMemberOwner implements ICPPClassType,
fields.add(node);
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
public IField[] getFields() {
return (IField[])fields.toArray(new IField[fields.size()]);
}
@ -227,6 +231,8 @@ public class PDOMCPPClassType extends PDOMMemberOwner implements ICPPClassType,
nestedClasses.add(node);
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
public ICPPClassType[] getNestedClasses() {
return (ICPPClassType[])nestedClasses.toArray(new ICPPClassType[nestedClasses.size()]);
}
@ -333,4 +339,4 @@ public class PDOMCPPClassType extends PDOMMemberOwner implements ICPPClassType,
throw new PDOMNotImplementedError();
}
}
}

View file

@ -11,9 +11,6 @@
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import java.util.List;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
@ -247,6 +244,8 @@ public class PDOMCPPLinkage extends PDOMLinkage {
}
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
public PDOMBinding getBinding() { return binding; }
}
@ -394,11 +393,6 @@ public class PDOMCPPLinkage extends PDOMLinkage {
}
}
public void findBindings(Pattern pattern, List bindings) throws CoreException {
MatchBinding visitor = new MatchBinding(pdom, pattern, bindings);
getIndex().accept(visitor);
}
public PDOMNode addType(PDOMNode parent, IType type) throws CoreException {
if (type instanceof ICPPBasicType)
return new PDOMCPPBasicType(pdom, parent, (ICPPBasicType)type);
@ -438,4 +432,4 @@ public class PDOMCPPLinkage extends PDOMLinkage {
}
}
}
}

View file

@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
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.IBTreeVisitor;
import org.eclipse.cdt.internal.core.pdom.dom.FindBindingsInBTree;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
@ -75,6 +76,7 @@ public class PDOMCPPNamespace extends PDOMBinding
if (binding != null) {
if (visitor.visit(binding))
binding.accept(visitor);
visitor.leave(binding);
}
return true;
};
@ -123,43 +125,20 @@ public class PDOMCPPNamespace extends PDOMBinding
}
public IBinding[] find(String name) throws DOMException {
throw new PDOMNotImplementedError();
try {
FindBindingsInBTree visitor = new FindBindingsInBTree(pdom, name.toCharArray());
getIndex().accept(visitor);
return visitor.getBinding();
} catch (CoreException e) {
CCorePlugin.log(e);
return new IBinding[0];
}
}
public void flushCache() throws DOMException {
throw new PDOMNotImplementedError();
}
private static final class FindBinding extends PDOMNamedNode.NodeFinder {
PDOMBinding pdomBinding;
final int[] desiredType;
public FindBinding(PDOM pdom, char[] name, int desiredType) {
this(pdom, name, new int[] { desiredType });
}
public FindBinding(PDOM 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;
int nodeType = tBinding.getNodeType();
for (int i = 0; i < desiredType.length; ++i)
if (nodeType == desiredType[i]) {
// got it
pdomBinding = tBinding;
return false;
}
// wrong type, try again
return true;
}
}
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
try {
if (name instanceof ICPPASTQualifiedName) {
@ -182,7 +161,7 @@ public class PDOMCPPNamespace extends PDOMBinding
return null;
// Look up the name
FindBinding visitor = new FindBinding(pdom, name.toCharArray(),
FindBindingsInBTree visitor = new FindBindingsInBTree(pdom, name.toCharArray(),
new int[] {
PDOMCPPLinkage.CPPCLASSTYPE,
PDOMCPPLinkage.CPPNAMESPACE,
@ -190,28 +169,32 @@ public class PDOMCPPNamespace extends PDOMBinding
PDOMCPPLinkage.CPPVARIABLE
});
getIndex().accept(visitor);
return visitor.pdomBinding;
IBinding[] bindings = visitor.getBinding();
return bindings.length > 0 ? bindings[0] : null;
}
}
if (parent instanceof IASTIdExpression) {
// reference
IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression) {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), PDOMCPPLinkage.CPPFUNCTION);
FindBindingsInBTree visitor = new FindBindingsInBTree(pdom, name.toCharArray(), PDOMCPPLinkage.CPPFUNCTION);
getIndex().accept(visitor);
return visitor.pdomBinding;
IBinding[] bindings = visitor.getBinding();
return bindings.length > 0 ? bindings[0] : null;
} else {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(),
FindBindingsInBTree visitor = new FindBindingsInBTree(pdom, name.toCharArray(),
(name.getParent() instanceof ICPPASTQualifiedName
&& ((ICPPASTQualifiedName)name.getParent()).getLastName() != name)
? PDOMCPPLinkage.CPPNAMESPACE : PDOMCPPLinkage.CPPVARIABLE);
getIndex().accept(visitor);
return visitor.pdomBinding;
IBinding[] bindings = visitor.getBinding();
return bindings.length > 0 ? bindings[0] : null;
}
} else if (parent instanceof IASTNamedTypeSpecifier) {
FindBinding visitor = new FindBinding(pdom, name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE);
FindBindingsInBTree visitor = new FindBindingsInBTree(pdom, name.toCharArray(), PDOMCPPLinkage.CPPCLASSTYPE);
getIndex().accept(visitor);
return visitor.pdomBinding;
IBinding[] bindings = visitor.getBinding();
return bindings.length > 0 ? bindings[0] : null;
}
return null;
} catch (CoreException e) {

View file

@ -1,54 +0,0 @@
/*******************************************************************************
* 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.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.core.runtime.CoreException;
/**
* @author Doug Schaefer
*
*/
public class CtagsBindingFinder implements IPDOMVisitor {
private final String name;
private final int[] types;
private List bindings = new ArrayList();
public CtagsBindingFinder(String name, int[] types) {
this.name = name;
this.types = types;
}
public boolean visit(IPDOMNode node) throws CoreException {
PDOMBinding binding = (PDOMBinding)node;
if (name.equals(binding.getDBName())) {
int type = binding.getNodeType();
for (int i = 0; i < types.length; ++i) {
if (type == types[i]) {
bindings.add(binding);
break;
}
}
}
return false;
}
public PDOMBinding[] getBindings() {
return (PDOMBinding[])bindings.toArray(new PDOMBinding[bindings.size()]);
}
}

View file

@ -1,245 +0,0 @@
/*******************************************************************************
* 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.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMNode;
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.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.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCFunction;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCVariable;
import org.eclipse.core.runtime.CoreException;
/**
* @author Doug Schaefer
*
*/
public class CtagsCName implements IASTName, IASTFileLocation {
private final PDOMLinkage linkage;
private final String fileName;
private final int lineNum;
private final String elementName;
private final Map fields;
private PDOMBinding binding;
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 CtagsCName(PDOMLinkage linkage, String fileName, int lineNum, String elementName, Map fields) throws CoreException {
this.linkage = linkage;
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;
}
}
}
}
public void addToPDOM(PDOMFile file) throws CoreException {
linkage.addName(this, file);
}
public IBinding getBinding() {
return binding;
}
public boolean isDeclaration() {
throw new PDOMNotImplementedError();
}
public boolean isDefinition() {
// TODO base on kind
return true;
}
public boolean isReference() {
// We're never a reference
return false;
}
private PDOMBinding makeNewBinding(IPDOMNode scope) throws CoreException {
switch (kind) {
case K_VARIABLE:
return new PDOMCVariable(linkage.getPDOM(), (PDOMNode)scope, this);
case K_FUNCTION:
return new PDOMCFunction(linkage.getPDOM(), (PDOMNode)scope, this);
default:
return null;
}
}
public IBinding resolveBinding() {
try {
IPDOMNode scope = linkage;
int[] types = null;
switch (kind) {
case K_VARIABLE:
types = new int[] { PDOMCLinkage.CVARIABLE };
break;
case K_FUNCTION:
types = new int[] { PDOMCLinkage.CFUNCTION };
break;
default:
return null;
}
CtagsBindingFinder finder = new CtagsBindingFinder(elementName, types);
scope.accept(finder);
PDOMBinding[] bindings = finder.getBindings();
if (bindings.length == 0)
binding = makeNewBinding(scope);
else if (bindings.length == 1)
binding = bindings[0];
else
// TODO resolve overloads
binding = bindings[0];
return binding;
} catch (CoreException e) {
CCorePlugin.log(e);
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

@ -1,245 +0,0 @@
/*******************************************************************************
* 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.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMNode;
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.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.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPFunction;
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPVariable;
import org.eclipse.core.runtime.CoreException;
/**
* @author Doug Schaefer
*
*/
public class CtagsCPPName implements IASTName, IASTFileLocation {
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 PDOMBinding binding;
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 CtagsCPPName(PDOMLinkage linkage, String fileName, int lineNum, String elementName, Map fields) throws CoreException {
this.linkage = linkage;
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;
}
}
}
}
public void addToPDOM(PDOMFile file) throws CoreException {
linkage.addName(this, file);
}
public IBinding getBinding() {
return binding;
}
public boolean isDeclaration() {
throw new PDOMNotImplementedError();
}
public boolean isDefinition() {
// Find out how function definitions are done
return true;
}
public boolean isReference() {
// We're never a reference
return false;
}
private PDOMBinding makeNewBinding(IPDOMNode scope) throws CoreException {
switch (kind) {
case K_VARIABLE:
return new PDOMCPPVariable(linkage.getPDOM(), (PDOMNode)scope, this);
case K_FUNCTION:
return new PDOMCPPFunction(linkage.getPDOM(), (PDOMNode)scope, this);
default:
return null;
}
}
public IBinding resolveBinding() {
try {
IPDOMNode scope = linkage;
int[] types = null;
switch (kind) {
case K_VARIABLE:
types = new int[] { PDOMCPPLinkage.CPPVARIABLE };
break;
case K_FUNCTION:
types = new int[] { PDOMCPPLinkage.CPPFUNCTION };
break;
default:
return null;
}
CtagsBindingFinder finder = new CtagsBindingFinder(elementName, types);
scope.accept(finder);
PDOMBinding[] bindings = finder.getBindings();
if (bindings.length == 0)
binding = makeNewBinding(scope);
else if (bindings.length == 1)
binding = bindings[0];
else
// TODO resolve overloads
binding = bindings[0];
return binding;
} catch (CoreException e) {
CCorePlugin.log(e);
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() {
return null;
}
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

@ -1,163 +0,0 @@
/*******************************************************************************
* 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.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
import org.eclipse.core.resources.IFile;
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.Platform;
import org.eclipse.core.runtime.Status;
/**
* @author Doug Schaefer
*
*/
public class CtagsHandleDelta extends CtagsIndexerJob {
private final ICElementDelta delta;
private List added = new ArrayList();
private List changed = new ArrayList();
private List removed = new ArrayList();
public CtagsHandleDelta(CtagsIndexer indexer, ICElementDelta delta) throws CoreException {
super(indexer);
this.delta = delta;
}
protected IStatus run(IProgressMonitor monitor) {
try {
long start = System.currentTimeMillis();
processDelta(delta);
int count = changed.size() + added.size() + removed.size();
if (count > 0) {
monitor.beginTask("Indexing", count);
Iterator i = changed.iterator();
while (i.hasNext()) {
ITranslationUnit tu = (ITranslationUnit)i.next();
monitor.subTask(tu.getElementName());
changeTU(tu);
monitor.worked(1);
}
i = added.iterator();
while (i.hasNext()) {
ITranslationUnit tu = (ITranslationUnit)i.next();
monitor.subTask(tu.getElementName());
addTU(tu);
monitor.worked(1);
}
i = removed.iterator();
while (i.hasNext()) {
ITranslationUnit tu = (ITranslationUnit)i.next();
monitor.subTask(tu.getElementName());
removeTU(tu);
monitor.worked(1);
}
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 Delta Time: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
}
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
}
}
protected void processDelta(ICElementDelta delta) throws CoreException {
int flags = delta.getFlags();
if ((flags & ICElementDelta.F_CHILDREN) != 0) {
ICElementDelta[] children = delta.getAffectedChildren();
for (int i = 0; i < children.length; ++i) {
processDelta(children[i]);
}
}
ICElement element = delta.getElement();
switch (element.getElementType()) {
case ICElement.C_UNIT:
ITranslationUnit tu = (ITranslationUnit)element;
switch (delta.getKind()) {
case ICElementDelta.CHANGED:
if ((flags & ICElementDelta.F_CONTENT) != 0)
changed.add(tu);
break;
case ICElementDelta.ADDED:
if (!tu.isWorkingCopy())
added.add(tu);
break;
case ICElementDelta.REMOVED:
if (!tu.isWorkingCopy())
removed.add(tu);
break;
}
break;
}
}
protected void addTU(ITranslationUnit tu) throws CoreException, InterruptedException {
IPath path = ((IFile)tu.getResource()).getLocation();
runCtags(path);
}
protected void changeTU(ITranslationUnit tu) throws CoreException, InterruptedException {
IPath path = ((IFile)tu.getResource()).getLocation();
pdom.acquireWriteLock();
try {
// Remove the old symbols in the tu
PDOMFile file = pdom.getFile(path);
if (file != null)
file.clear();
} finally {
pdom.releaseWriteLock();
}
// Add the new symbols
runCtags(path);
}
protected void removeTU(ITranslationUnit tu) throws CoreException, InterruptedException {
pdom.acquireWriteLock();
try {
IPath path = ((IFile)tu.getResource()).getLocation();
PDOMFile file = pdom.getFile(path);
if (file != null)
file.clear();
} finally {
pdom.releaseWriteLock();
}
}
}

View file

@ -1,239 +0,0 @@
/*******************************************************************************
* 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.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.core.dom.IPDOMIndexer;
import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.pdom.indexer.nulli.PDOMNullIndexer;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
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 {
public static final String ID = "org.eclipse.cdt.core.ctagsindexer"; //$NON-NLS-1$
private ICProject project;
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) throws CoreException {
// Don't use me, I'm broken
CCorePlugin.getPDOMManager().setIndexerId(project, PDOMNullIndexer.ID);
// new CtagsHandleDelta(this,delta).schedule();
}
public void reindex() throws CoreException {
// Don't use me, I'm broken
CCorePlugin.getPDOMManager().setIndexerId(project, PDOMNullIndexer.ID);
// new CtagsReindex(this).schedule();
}
public ICProject getProject() {
return project;
}
public void setProject(ICProject project) {
this.project = project;
}
// 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() {
IEclipsePreferences prefs = new ProjectScope(project.getProject()).getNode(CCorePlugin.PLUGIN_ID);
if (prefs == null)
return;
ctagsCommand = prefs.get(ctagsCommandId, null);
if (ctagsCommand != null) {
useCtagsOnPath = prefs.getBoolean(useCtagsOnPathId, getDefaultUseCtagsOnPath());
useInternalCtagsFile = prefs.getBoolean(useInternalCtagsFileId, getDefaultUseInternalCtagsFile());
ctagsFileName = prefs.get(ctagsFileNameId, getDefaultCtagsFileName());
} else {
// Not defined yet check in cdescriptor
try {
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(project.getProject(), false);
if (desc != null) {
ICExtensionReference[] cext = desc.get(CCorePlugin.INDEXER_UNIQ_ID);
if (cext.length > 0) {
for (int i = 0; i < cext.length; i++) {
String orig = cext[i].getExtensionData("ctagslocationtype"); //$NON-NLS-1$
useCtagsOnPath = orig != null
? !orig.equals("ctags_path_specified")
: getDefaultUseCtagsOnPath();
orig = cext[i].getExtensionData("ctagslocation"); //$NON-NLS-1$
ctagsCommand = orig != null ? orig : getDefaultCtagsCommand();
orig = cext[i].getExtensionData("ctagfiletype"); //$NON-NLS-1$
useInternalCtagsFile = orig != null
? !orig.equals("ctags_external") //$NON-NLS-1$
: getDefaultUseInternalCtagsFile();
orig = cext[i].getExtensionData("ctagfilelocation"); //$NON-NLS-1$
ctagsFileName = orig != null ? orig : getDefaultCtagsFileName();
}
}
}
} catch (CoreException e) {
}
if (ctagsCommand == null) {
useCtagsOnPath = getDefaultUseCtagsOnPath();
ctagsCommand = getDefaultCtagsCommand();
useInternalCtagsFile = getDefaultUseInternalCtagsFile();
ctagsFileName = getDefaultCtagsFileName();
}
}
}
public void setPreferences(
boolean useCtagsOnPath,
String ctagsCommand,
boolean useInternalCtagsFile,
String ctagsFileName) throws CoreException {
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);
}
reindex();
}
}
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(project.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

@ -1,153 +0,0 @@
/*******************************************************************************
* 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.File;
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.ast.gnu.c.GCCLanguage;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.jobs.Job;
/**
* @author Doug Schaefer
*
*/
public abstract class CtagsIndexerJob extends Job {
protected final CtagsIndexer indexer;
protected final PDOM pdom;
public CtagsIndexerJob(CtagsIndexer indexer) throws CoreException {
super("ctags Indexer: " + indexer.getProject().getElementName());
this.indexer = indexer;
this.pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(indexer.getProject());
}
// Indexing functions
void runCtags(IPath sourcePath) {
String ctagsFileName = indexer.getResolvedCtagsFileName();
File ctagsFile = new File(ctagsFileName);
if (ctagsFile.exists())
ctagsFile.delete();
String[] cmd = new String[] {
indexer.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$
"-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
pdom.acquireWriteLock();
try {
processCtagsFile(ctagsFileName);
} finally {
pdom.releaseWriteLock();
}
} 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)) - 1; // Make it 0 based
} 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) {
PDOMFile file = pdom.addFile(fileName);
String languageName = (String)fields.get("language"); //$NON-NLS-1$
if (languageName.equals("C++")) { //$NON-NLS-1$
PDOMLinkage linkage = pdom.getLinkage(new GPPLanguage());
new CtagsCPPName(linkage, fileName, lineNum, elementName, fields).addToPDOM(file);
} else {
PDOMLinkage linkage = pdom.getLinkage(new GCCLanguage());
new CtagsCName(linkage, fileName, lineNum, elementName, fields).addToPDOM(file);
}
}
}
}
}

View file

@ -1,101 +0,0 @@
/*******************************************************************************
* 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.ISourceRoot;
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;
/**
* @author Doug Schaefer
*
*/
public class CtagsReindex extends CtagsIndexerJob {
public CtagsReindex(CtagsIndexer indexer) throws CoreException {
super(indexer);
}
protected IStatus run(IProgressMonitor monitor) {
try {
// What do we need to index
final ICProject project = indexer.getProject();
// final IIncludeReference[] pincludes = project.getIncludeReferences();
// IIncludeReference[] includes = new IIncludeReference[pincludes.length];
// System.arraycopy(pincludes, 0, includes, 0, pincludes.length);
// 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);
ISourceRoot[] sourceRoots = project.getAllSourceRoots();
monitor.beginTask("Indexing", sourceRoots.length + 1);
// + includes.length + 1);
// Clear out the PDOM
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
monitor.subTask("Clearing Index");
pdom.clear();
monitor.worked(1);
// Index the include path
// for (int i = 0; i < includes.length; ++i) {
// if (monitor.isCanceled())
// return Status.CANCEL_STATUS;
// monitor.subTask(includes[i].getElementName());
// runCtags(includes[i].getPath());
// monitor.worked(1);
// }
// Index the source roots
for (int i = 0; i < sourceRoots.length; ++i) {
ISourceRoot sourceRoot = sourceRoots[i];
IPath sourcePath = sourceRoot.getResource().getLocation();
if (sourcePath != null) {
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
monitor.subTask(sourceRoot.getElementName());
runCtags(sourcePath);
monitor.worked(1);
}
}
} catch (CoreException e) {
return e.getStatus();
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
}

View file

@ -103,6 +103,8 @@ public class CountNodeAction extends IndexAction {
}
return true;
}
public void leave(IPDOMNode node) throws CoreException {
}
});
}
} catch (CoreException e) {

View file

@ -139,6 +139,8 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
++count;
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
}
private static class Children implements IPDOMVisitor {
@ -151,6 +153,8 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
nodes[index++] = node;
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
}
private static class HasChildren implements IPDOMVisitor {
@ -159,6 +163,8 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
hasChildren = true;
throw new CoreException(Status.OK_STATUS);
}
public void leave(IPDOMNode node) throws CoreException {
}
}
static PDOMBinding[] trim(PDOMBinding []binding) {
@ -438,4 +444,4 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
}
}
}
}

View file

@ -146,3 +146,4 @@ PDOMSearch.query.refs.label = Find references to
PDOMSearch.query.defs.label = Find definitions of
PDOMSearch.query.decls.label = Find declarations of
PDOMSearchPatternQuery.PatternQuery_labelPatternInScope={0} {1} in {2}
PDOMSearch.query.pattern.error = Illegal Search String

View file

@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.ui.search;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.eclipse.cdt.core.model.CoreModel;
@ -159,31 +158,6 @@ public class PDOMSearchPage extends DialogPage implements ISearchPage {
// get the pattern and turn it into a regular expression
String patternStr = patternCombo.getText();
String realStr = patternStr;
if (realStr.indexOf('*') >= 0 || realStr.indexOf('?') >= 0) {
StringBuffer buff = new StringBuffer(patternStr.length() + 1);
for (int i = 0; i < patternStr.length(); ++i) {
char c = patternStr.charAt(i);
switch (c) {
case '*':
buff.append(".*"); //$NON-NLS-1$
break;
case '?':
buff.append('.');
break;
default:
buff.append(c);
}
}
realStr = buff.toString();
}
Pattern pattern;
try {
pattern = Pattern.compile(realStr);
} catch (PatternSyntaxException e) {
return false;
}
// Get search flags
int searchFlags = 0;
@ -250,12 +224,17 @@ public class PDOMSearchPage extends DialogPage implements ISearchPage {
? null
: (ICElement[])elements.toArray(new ICElement[elements.size()]);
PDOMSearchPatternQuery job = new PDOMSearchPatternQuery(scope, scopeDescription, pattern, patternStr,
isCaseSensitive, searchFlags);
try {
PDOMSearchPatternQuery job = new PDOMSearchPatternQuery(scope, scopeDescription, patternStr,
isCaseSensitive, searchFlags);
NewSearchUI.activateSearchResultView();
NewSearchUI.activateSearchResultView();
NewSearchUI.runQueryInBackground(job);
NewSearchUI.runQueryInBackground(job);
} catch (PatternSyntaxException e) {
fLineManager.setErrorMessage(CSearchMessages.getString("PDOMSearch.query.pattern.error")); //$NON-NLS-1$
return false;
}
// Save our settings
IDialogSettings settings = getDialogSettings();
@ -267,7 +246,7 @@ public class PDOMSearchPage extends DialogPage implements ISearchPage {
// Add only if we don't have it already
boolean addit = true;
for (int i = 0; i < previousPatterns.length; ++i) {
if (pattern.equals(previousPatterns[i])) {
if (patternStr.equals(previousPatterns[i])) {
addit = false;
break;
}
@ -597,4 +576,4 @@ public class PDOMSearchPage extends DialogPage implements ISearchPage {
super.setVisible(visible);
}
}
}

View file

@ -11,7 +11,10 @@
package org.eclipse.cdt.internal.ui.search;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOM;
@ -53,19 +56,48 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
private String scopeDesc;
private String patternStr;
private Pattern pattern;
private Pattern[] pattern;
public PDOMSearchPatternQuery(
ICElement[] scope,
String scopeDesc,
Pattern pattern,
String patternStr,
boolean isCaseSensitive,
int flags) {
int flags) throws PatternSyntaxException {
super(scope, flags);
this.scopeDesc = scopeDesc;
this.pattern = pattern;
this.patternStr = patternStr;
// Parse the pattern string
List patternList = new ArrayList();
StringBuffer buff = new StringBuffer();
int n = patternStr.length();
for (int i = 0; i < n; ++i) {
char c = patternStr.charAt(i);
switch (c) {
case '*':
buff.append(".*"); //$NON-NLS-1$
break;
case '?':
buff.append('.');
break;
case '.':
case ':':
if (buff.length() > 0) {
patternList.add(Pattern.compile(buff.toString()));
buff = new StringBuffer();
}
break;
default:
buff.append(c);
}
}
if (buff.length() > 0)
patternList.add(Pattern.compile(buff.toString()));
pattern = (Pattern[])patternList.toArray(new Pattern[patternList.size()]);
}
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
@ -102,4 +134,4 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
return Messages.format(CSearchMessages.getString("PDOMSearchPatternQuery.PatternQuery_labelPatternInScope"), super.getLabel(), patternStr, scopeDesc); //$NON-NLS-1$
}
}
}

View file

@ -78,6 +78,8 @@ public class PDOMCompletionContributor extends DOMCompletionContributor implemen
}
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
});
} else if (parent instanceof IASTFieldReference) {
// Find the type the look at the fields
@ -98,6 +100,8 @@ public class PDOMCompletionContributor extends DOMCompletionContributor implemen
}
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
});
}
}

View file

@ -1,250 +0,0 @@
/*******************************************************************************
* Copyright (c) 2005, 2006 IBM Corporation 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:
* IBM - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.dialogs;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMIndexer;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.pdom.indexer.ctags.CtagsIndexer;
import org.eclipse.cdt.internal.ui.CUIMessages;
import org.eclipse.cdt.internal.ui.util.SWTUtil;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.index.AbstractIndexerPage;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
/**
* @author Bogdan Gheorghe
*/
public class CTagsIndexerBlock extends AbstractIndexerPage {
protected CtagsIndexer ctagsIndexer;
protected boolean internalTagsFile = true;
protected Button internalCTagsFile;
protected Button externalCTagsFile;
protected Button browseButton;
protected Text cTagsFile;
protected boolean useDefaultCTags = true;
protected Button useCTagsPath;
protected Button useCTagsExecutable;
protected Button browseButtonCTagsExec;
protected Text cTagsExecutable;
public final static String PREF_INTOREXT_CTAGS = CUIPlugin.PLUGIN_ID + ".intorextctags"; //$NON-NLS-1$
public final static String PREF_CTAGS_FILE_LOCATION_CTAGS = CUIPlugin.PLUGIN_ID + ".ctagsfilelocation"; //$NON-NLS-1$
public final static String PREF_CTAGS_INDEXINCLUDEFILES = CUIPlugin.PLUGIN_ID + ".ctagsindexincludes"; //$NON-NLS-1$
public final static String PREF_CTAGS_LOCATION_TYPE = CUIPlugin.PLUGIN_ID + ".ctagslocationtype"; //$NON-NLS-1$
public final static String PREF_CTAGS_LOCATION = CUIPlugin.PLUGIN_ID + ".ctagslocation"; //$NON-NLS-1$
public void initialize(ICProject project) {
this.currentProject = project;
try {
loadPersistedValues(project);
} catch (CoreException e) {}
}
public void performApply(IProgressMonitor monitor) throws CoreException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask(CUIMessages.getString("IndexerOptiosn.task.savingAttributes "), 1); //$NON-NLS-1$
if (ctagsIndexer != null) {
ctagsIndexer.setPreferences(
useDefaultCTags,
cTagsExecutable.getText(),
internalTagsFile,
cTagsFile.getText());
} else {
CtagsIndexer.setDefaultPreferences(
useDefaultCTags,
cTagsExecutable.getText(),
internalTagsFile,
cTagsFile.getText());
}
}
public void performDefaults() {
//ctag file options
internalTagsFile=true;
internalCTagsFile.setSelection(true);
externalCTagsFile.setSelection(false);
cTagsFile.setText(""); //$NON-NLS-1$
browseButton.setEnabled(false);
//ctag path options
useDefaultCTags=true;
useCTagsPath.setSelection(true);
useCTagsExecutable.setSelection(false);
cTagsExecutable.setText(""); //$NON-NLS-1$
browseButtonCTagsExec.setEnabled(false);
}
public void createControl(Composite parent) {
Composite page = ControlFactory.createComposite(parent, 1);
Group cTagsExecutableGroup = ControlFactory.createGroup(page,CUIMessages.getString("CTagsIndexerBlock.ctagsLocation"),3); //$NON-NLS-1$
GridData gd3 = (GridData) cTagsExecutableGroup.getLayoutData();
gd3.grabExcessHorizontalSpace = true;
gd3.horizontalAlignment = GridData.FILL;
SelectionListener cTagsListener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
useDefaultCTags = useCTagsPath.getSelection();
if (useDefaultCTags){
setCommandState();
}
}
};
useCTagsPath = ControlFactory.createRadioButton(cTagsExecutableGroup,CUIMessages.getString("CTagsIndexerBlock.radioButtonCTagsDefault"),"CTagsDefault",cTagsListener);//$NON-NLS-1$ //$NON-NLS-2$
((GridData)useCTagsPath.getLayoutData()).horizontalSpan = 3;
((GridData)useCTagsPath.getLayoutData()).grabExcessHorizontalSpace = true;
useCTagsPath.setSelection(internalTagsFile);
useCTagsExecutable = ControlFactory.createRadioButton(cTagsExecutableGroup,CUIMessages.getString("CTagsIndexerBlock.radioButtonCTagsSpecified"),"CTafsSpecified",cTagsListener);//$NON-NLS-1$ //$NON-NLS-2$
((GridData)useCTagsExecutable.getLayoutData()).horizontalSpan = 3;
((GridData)useCTagsExecutable.getLayoutData()).grabExcessHorizontalSpace = true;
cTagsExecutable = ControlFactory.createTextField(cTagsExecutableGroup);
((GridData)cTagsExecutable.getLayoutData()).horizontalSpan = 2;
((GridData)cTagsExecutable.getLayoutData()).grabExcessHorizontalSpace = true;
browseButtonCTagsExec = ControlFactory.createPushButton(cTagsExecutableGroup,CUIMessages.getString("CTagsIndexerBlock.browseButton")); //$NON-NLS-1$
((GridData)browseButtonCTagsExec.getLayoutData()).widthHint = SWTUtil.getButtonWidthHint(browseButtonCTagsExec);
browseButtonCTagsExec.setEnabled(false);
browseButtonCTagsExec.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
handleBrowseButtonSelected();
}
void handleBrowseButtonSelected() {
cTagsExecutable.setText(openFileBrowser());
}
});
//
Group group = ControlFactory.createGroup(page, CUIMessages.getString("CTagsIndexerBlock.blockName"),3); //$NON-NLS-1$
GridData gd = (GridData) group.getLayoutData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = GridData.FILL;
SelectionListener cListener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
internalTagsFile = internalCTagsFile.getSelection();
if (internalTagsFile){
setFilenameState();
}
}
};
internalCTagsFile = ControlFactory.createRadioButton(group,CUIMessages.getString("CTagsIndexerBlock.radioButtonInternal"),"Internal",cListener);//$NON-NLS-1$ //$NON-NLS-2$
((GridData)internalCTagsFile.getLayoutData()).horizontalSpan = 3;
((GridData)internalCTagsFile.getLayoutData()).grabExcessHorizontalSpace = true;
internalCTagsFile.setSelection(internalTagsFile);
externalCTagsFile = ControlFactory.createRadioButton(group,CUIMessages.getString("CTagsIndexerBlock.radioButtonExternal"),"External",cListener);//$NON-NLS-1$ //$NON-NLS-2$
((GridData)externalCTagsFile.getLayoutData()).horizontalSpan = 3;
((GridData)externalCTagsFile.getLayoutData()).grabExcessHorizontalSpace = true;
cTagsFile = ControlFactory.createTextField(group);
((GridData)cTagsFile.getLayoutData()).horizontalSpan = 2;
((GridData)cTagsFile.getLayoutData()).grabExcessHorizontalSpace = true;
browseButton = ControlFactory.createPushButton(group,CUIMessages.getString("CTagsIndexerBlock.browseButton")); //$NON-NLS-1$
((GridData)browseButton.getLayoutData()).widthHint = SWTUtil.getButtonWidthHint(browseButton);
browseButton.setEnabled(false);
browseButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
handleBrowseButtonSelected();
}
private void handleBrowseButtonSelected() {
cTagsFile.setText(openFileBrowser());
}
});
setControl(page);
}
String openFileBrowser(){
FileDialog dialog = new FileDialog(getShell(), SWT.NONE);
dialog.setText(CUIMessages.getString("CTagsIndexerBlock.fileBrowser")); //$NON-NLS-1$
String fileName = dialog.open();
if (fileName == null) {
return ""; //$NON-NLS-1$
}
return fileName;
}
public void loadPersistedValues(ICProject project) throws CoreException {
IPDOMIndexer indexer = CCorePlugin.getPDOMManager().getIndexer(project);
if (!(indexer instanceof CtagsIndexer))
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, "Wrong indexer", null)); //$NON-NLS-1$
ctagsIndexer = (CtagsIndexer)indexer;
useDefaultCTags = ctagsIndexer.useCtagsOnPath();
cTagsExecutable.setText(ctagsIndexer.getCtagsCommand());
setCommandState();
internalTagsFile = ctagsIndexer.useInternalCtagsFile();
cTagsFile.setText(ctagsIndexer.getCtagsFileName());
setFilenameState();
}
private void setCommandState() {
useCTagsPath.setSelection(useDefaultCTags);
useCTagsExecutable.setSelection(!useDefaultCTags);
browseButtonCTagsExec.setEnabled(!useDefaultCTags);
}
private void setFilenameState() {
internalCTagsFile.setSelection(internalTagsFile);
externalCTagsFile.setSelection(!internalTagsFile);
browseButton.setEnabled(!internalTagsFile);
}
public void loadPreferences() {
useDefaultCTags = CtagsIndexer.getDefaultUseCtagsOnPath();
cTagsExecutable.setText(CtagsIndexer.getDefaultCtagsCommand());
setCommandState();
internalTagsFile = CtagsIndexer.getDefaultUseInternalCtagsFile();
cTagsFile.setText(CtagsIndexer.getDefaultCtagsFileName());
setFilenameState();
}
public void removePreferences() {
prefStore.setToDefault(PREF_CTAGS_FILE_LOCATION_CTAGS);
prefStore.setToDefault(PREF_INTOREXT_CTAGS);
}
}