Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Hirsl2005-04-08 15:52:28 +0000
committerVladimir Hirsl2005-04-08 15:52:28 +0000
commitd7c2d4834e253015044f801ab7fcfccf041ac173 (patch)
treef6e372f8a3a94b387c07d5c25f82115366d8ec6e
parentcfbadc7405e607fed4b4ad435dc0cb65b921684b (diff)
downloadorg.eclipse.cdt-d7c2d4834e253015044f801ab7fcfccf041ac173.tar.gz
org.eclipse.cdt-d7c2d4834e253015044f801ab7fcfccf041ac173.tar.xz
org.eclipse.cdt-d7c2d4834e253015044f801ab7fcfccf041ac173.zip
Added offset and length parameters for index entries.
Refactoring of AbstractIndexer. Moved old parser specific stuff to the appropriate subclass.
-rw-r--r--core/org.eclipse.cdt.core/ChangeLog13
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsIndexerRunner.java4
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java82
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java168
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/DOMSourceIndexerRunner.java269
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexEncoderUtil.java36
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java552
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java2
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRunner.java540
9 files changed, 891 insertions, 775 deletions
diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog
index f042d6d18a5..412eb791d93 100644
--- a/core/org.eclipse.cdt.core/ChangeLog
+++ b/core/org.eclipse.cdt.core/ChangeLog
@@ -1,3 +1,16 @@
+2005-04-08 Vladimir Hirsl
+ Added offset and length parameters for index entries.
+ Refactoring of AbstractIndexer. Moved old parser specific stuff to the appropriate subclass.
+
+ * index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsIndexerRunner.java
+ * index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java
+ * index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java
+ * index/org/eclipse/cdt/internal/core/index/domsourceindexer/DOMSourceIndexerRunner.java
+ * index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexEncoderUtil.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRunner.java
+
2005-04-05 Vladimir Hirsl
Improved filtering of indexer problem markers
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsIndexerRunner.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsIndexerRunner.java
index 1d77685baff..af573114392 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsIndexerRunner.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsIndexerRunner.java
@@ -125,9 +125,9 @@ public class CTagsIndexerRunner extends AbstractIndexer {
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer#addMarkers(org.eclipse.core.resources.IFile, org.eclipse.core.resources.IFile, java.lang.Object)
+ * @see org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer#addMarkers(org.eclipse.core.resources.IFile, org.eclipse.core.resources.IFile, java.lang.Object, java.lang.Object)
*/
- protected void addMarkers(IFile tempFile, IFile originator, Object problem) {
+ protected void addMarkers(IFile tempFile, IFile originator, Object problem, Object location) {
// TODO Auto-generated method stub
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java
index 001aa017727..8de88225bf7 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java
@@ -19,7 +19,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
@@ -33,6 +33,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
import org.eclipse.cdt.core.search.ICSearchConstants;
+import org.eclipse.cdt.internal.core.index.cindexstorage.ICIndexStorageConstants;
import org.eclipse.cdt.internal.core.search.indexing.IIndexEncodingConstants;
import org.eclipse.cdt.internal.core.search.indexing.IIndexEncodingConstants.EntryType;
import org.eclipse.core.resources.IFile;
@@ -70,15 +71,11 @@ public class CGenerateIndexVisitor extends CASTVisitor {
* @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTName)
*/
public int visit(IASTName name) {
- //Check to see if this reference actually occurs in the file being indexed
- //or if it occurs in another file
- int indexFlag = IndexEncoderUtil.calculateIndexFlags(indexer, name);
-
// qualified names are going to be handled segment by segment
// if (name instanceof ICPPASTQualifiedName) return PROCESS_CONTINUE;
try {
- processName(name, indexFlag);
+ processName(name);
}
catch (DOMException e) {
// TODO Auto-generated catch block
@@ -92,60 +89,63 @@ public class CGenerateIndexVisitor extends CASTVisitor {
*/
public int visit(IASTProblem problem) {
if (indexer.areProblemMarkersEnabled() && indexer.shouldRecordProblem(problem)){
- IFile tempFile = resourceFile;
-
- //If we are in an include file, get the include file
- IASTNodeLocation[] locs = problem.getNodeLocations();
- if (locs[0] instanceof IASTFileLocation) {
- IASTFileLocation fileLoc = (IASTFileLocation) locs[0];
- String fileName = fileLoc.getFileName();
- tempFile = CCorePlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileName));
- }
-
- if( tempFile != null ){
- indexer.generateMarkerProblem(tempFile, resourceFile, problem);
- }
+ // Get the location
+ IASTFileLocation loc = IndexEncoderUtil.getFileLocation(problem);
+ processProblem(problem, loc);
}
return super.visit(problem);
}
/**
* @param name
- * @param indexFlag
* @throws DOMException
*/
- private void processName(IASTName name, int indexFlag) throws DOMException {
+ private void processName(IASTName name) throws DOMException {
IBinding binding = name.resolveBinding();
// check for IProblemBinding
if (binding instanceof IProblemBinding) {
IProblemBinding problem = (IProblemBinding) binding;
if (indexer.areProblemMarkersEnabled() && indexer.shouldRecordProblem(problem)){
- IFile tempFile = resourceFile;
-
- //If we are in an include file, get the include file
- IASTNodeLocation[] locs = name.getNodeLocations();
- if (locs[0] instanceof IASTFileLocation) {
- IASTFileLocation fileLoc = (IASTFileLocation) locs[0];
- String fileName = fileLoc.getFileName();
- tempFile = CCorePlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileName));
- }
-
- if( tempFile != null ){
- indexer.generateMarkerProblem(tempFile, resourceFile, problem);
- }
+ // Get the location
+ IASTFileLocation loc = IndexEncoderUtil.getFileLocation(name);
+ processProblem(name, loc);
}
return;
}
- processNameBinding(name, binding, indexFlag);
+ // Get the location
+ IASTFileLocation loc = IndexEncoderUtil.getFileLocation(name);
+ if (loc != null) {
+ //Check to see if this reference actually occurs in the file being indexed
+ //or if it occurs in another file
+ int indexFlag = IndexEncoderUtil.calculateIndexFlags(indexer, loc);
+
+ processNameBinding(name, binding, loc, indexFlag);
+ }
}
/**
* @param name
+ */
+ private void processProblem(IASTNode node, IASTFileLocation loc) {
+ IFile tempFile = resourceFile;
+ //If we are in an include file, get the include file
+ if (loc != null) {
+ String fileName = loc.getFileName();
+ tempFile = CCorePlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileName));
+ if (tempFile != null) {
+ indexer.generateMarkerProblem(tempFile, resourceFile, node, loc);
+ }
+ }
+ }
+
+ /**
+ * @param name
* @param binding
+ * @param loc
* @param indexFlag
* @throws DOMException
*/
- private void processNameBinding(IASTName name, IBinding binding, int fileNumber) throws DOMException {
+ private void processNameBinding(IASTName name, IBinding binding, IASTFileLocation loc, int fileNumber) throws DOMException {
// determine type
EntryType entryType = null;
if (binding instanceof ICompositeType) {
@@ -183,13 +183,19 @@ public class CGenerateIndexVisitor extends CASTVisitor {
indexer.getOutput().addRef(fileNumber,IndexEncoderUtil.encodeEntry(
getFullyQualifiedName(name),
entryType,
- ICSearchConstants.DECLARATIONS));
+ ICSearchConstants.DECLARATIONS),
+ loc.getNodeOffset(),
+ loc.getNodeLength(),
+ ICIndexStorageConstants.OFFSET);
}
else if (name.isReference()) {
indexer.getOutput().addRef(fileNumber, IndexEncoderUtil.encodeEntry(
getFullyQualifiedName(name),
entryType,
- ICSearchConstants.REFERENCES));
+ ICSearchConstants.REFERENCES),
+ loc.getNodeOffset(),
+ loc.getNodeLength(),
+ ICIndexStorageConstants.OFFSET);
}
}
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java
index 40ecf139ce1..ff41d619b9f 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java
@@ -16,7 +16,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
@@ -30,16 +30,16 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo;
-import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBaseClause.CPPBaseProblem;
+import org.eclipse.cdt.internal.core.index.cindexstorage.ICIndexStorageConstants;
import org.eclipse.cdt.internal.core.search.indexing.IIndexEncodingConstants;
import org.eclipse.cdt.internal.core.search.indexing.IIndexEncodingConstants.EntryType;
import org.eclipse.core.resources.IFile;
@@ -78,15 +78,11 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
* @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTName)
*/
public int visit(IASTName name) {
- //Check to see if this reference actually occurs in the file being indexed
- //or if it occurs in another file
- int indexFlag = IndexEncoderUtil.calculateIndexFlags(indexer, name);
-
// qualified names are going to be handled segment by segment
if (name instanceof ICPPASTQualifiedName) return PROCESS_CONTINUE;
try {
- processName(name, indexFlag);
+ processName(name);
}
catch (DOMException e) {
// TODO Auto-generated catch block
@@ -99,72 +95,66 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
* @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTProblem)
*/
public int visit(IASTProblem problem) {
- if (indexer.areProblemMarkersEnabled() && indexer.shouldRecordProblem(problem)){
- IFile tempFile = resourceFile;
-
- //If we are in an include file, get the include file
- IASTNodeLocation[] locs = problem.getNodeLocations();
- if (locs[0] instanceof IASTFileLocation) {
- IASTFileLocation fileLoc = (IASTFileLocation) locs[0];
- String fileName = fileLoc.getFileName();
- tempFile = CCorePlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileName));
- }
-
- if( tempFile != null ){
- indexer.generateMarkerProblem(tempFile, resourceFile, problem);
- }
+ if (indexer.areProblemMarkersEnabled() && indexer.shouldRecordProblem(problem)) {
+ // Get the location
+ IASTFileLocation loc = IndexEncoderUtil.getFileLocation(problem);
+ processProblem(problem, loc);
}
return super.visit(problem);
}
/**
* @param name
- * @param indexFlag
* @throws DOMException
*/
- private void processName(IASTName name, int indexFlag) throws DOMException {
+ private void processName(IASTName name) throws DOMException {
IBinding binding = name.resolveBinding();
// check for IProblemBinding
if (binding instanceof IProblemBinding) {
IProblemBinding problem = (IProblemBinding) binding;
if (indexer.areProblemMarkersEnabled() && indexer.shouldRecordProblem(problem)){
- IFile tempFile = resourceFile;
-
- //If we are in an include file, get the include file
- IASTNodeLocation[] locs = name.getNodeLocations();
- if (locs[0] instanceof IASTFileLocation) {
- IASTFileLocation fileLoc = (IASTFileLocation) locs[0];
- String fileName = fileLoc.getFileName();
- tempFile = CCorePlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileName));
- }
-
- if (tempFile != null) {
- indexer.generateMarkerProblem(tempFile, resourceFile, name);
- }
+ // Get the location
+ IASTFileLocation loc = IndexEncoderUtil.getFileLocation(name);
+ processProblem(name, loc);
}
return;
}
- processNameBinding(name, binding, indexFlag, null); // function will determine limitTo
+ // Get the location
+ IASTFileLocation loc = IndexEncoderUtil.getFileLocation(name);
+ if (loc != null) {
+ //Check to see if this reference actually occurs in the file being indexed
+ //or if it occurs in another file
+ int indexFlag = IndexEncoderUtil.calculateIndexFlags(indexer, loc);
+
+ processNameBinding(name, binding, loc, indexFlag, null); // function will determine limitTo
+ }
}
/**
* @param name
- * @return
*/
- private char[][] createEnumeratorFullyQualifiedName(IASTName name) {
- // TODO Auto-generated method stub
- return null;
+ private void processProblem(IASTNode node, IASTFileLocation loc) {
+ IFile tempFile = resourceFile;
+ //If we are in an include file, get the include file
+ if (loc != null) {
+ String fileName = loc.getFileName();
+ tempFile = CCorePlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileName));
+ if (tempFile != null) {
+ indexer.generateMarkerProblem(tempFile, resourceFile, node, loc);
+ }
+ }
}
/**
* @param name
* @param binding
+ * @param loc
* @param indexFlag
* @param limitTo
* @throws DOMException
*/
- private void processNameBinding(IASTName name, IBinding binding, int fileNumber, LimitTo limitTo) throws DOMException {
+ private void processNameBinding(IASTName name, IBinding binding, IASTFileLocation loc, int fileNumber, LimitTo limitTo) throws DOMException {
// determine LimitTo
if (limitTo == null) {
if (name.isDeclaration()) {
@@ -181,7 +171,8 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
// determine type
EntryType entryType = null;
if (binding instanceof ICompositeType) {
- int compositeKey = ((ICompositeType) binding).getKey();
+ ICompositeType compBinding = (ICompositeType) binding;
+ int compositeKey = compBinding.getKey();
ASTNodeProperty prop = name.getPropertyInParent();
switch (compositeKey) {
case ICPPClassType.k_class:
@@ -200,6 +191,7 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
entryType = IIndexEncodingConstants.FWD_UNION;
break;
}
+ addDerivedAndFriendDeclaration(name, compBinding, loc, fileNumber);
}
else if (binding instanceof IEnumeration)
entryType = IIndexEncodingConstants.ENUM;
@@ -216,14 +208,17 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
entryType = IIndexEncodingConstants.VAR;
else if (binding instanceof ICPPMethod)
entryType = IIndexEncodingConstants.METHOD;
- else if (binding instanceof IFunction)
+ else if (binding instanceof IFunction) {
entryType = IIndexEncodingConstants.FUNCTION;
+ // TODO In case we want to add friend function declarations to index
+ // addDerivedAndFriendDeclaration(name, binding, loc, fileNumber);
+ }
else if (binding instanceof ICPPUsingDeclaration) {
ICPPDelegate[] delegates = ((ICPPUsingDeclaration)binding).getDelegates();
for (int i = 0; i < delegates.length; i++) {
IBinding orig = delegates[i].getBinding();
- processNameBinding(name, orig, fileNumber, ICSearchConstants.REFERENCES); // reference to the original binding
- processNameBinding(name, delegates[i], fileNumber, ICSearchConstants.DECLARATIONS); // declaration of the new name
+ processNameBinding(name, orig, loc, fileNumber, ICSearchConstants.REFERENCES); // reference to the original binding
+ processNameBinding(name, delegates[i], loc, fileNumber, ICSearchConstants.DECLARATIONS); // declaration of the new name
}
return;
}
@@ -232,38 +227,71 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
indexer.getOutput().addRef(fileNumber, IndexEncoderUtil.encodeEntry(
getFullyQualifiedName(binding),
entryType,
- limitTo));
+ limitTo),
+ loc.getNodeOffset(),
+ loc.getNodeLength(),
+ ICIndexStorageConstants.OFFSET);
}
-
- // add base classes and friends
- if (binding instanceof ICPPClassType &&
- limitTo.equals(ICSearchConstants.DECLARATIONS) &&
- (IIndexEncodingConstants.CLASS.equals(entryType) ||
- IIndexEncodingConstants.STRUCT.equals(entryType))) {
- ICPPClassType classBinding = (ICPPClassType) binding;
- //Get base clauses
- ICPPBase[] baseClauses = classBinding.getBases();
- for (int i = 0; i < baseClauses.length; ++i) {
- if (!(baseClauses[i] instanceof CPPBaseProblem)) {
- ICompositeType baseClass = (ICompositeType) ((ICPPBase)baseClauses[i]).getBaseClass();
+ }
+
+ /**
+ * @param name
+ * @param fileNumber
+ * @param loc
+ * @param compBinding
+ * @throws DOMException
+ */
+ private void addDerivedAndFriendDeclaration(IASTName name, IBinding binding, IASTFileLocation loc, int fileNumber) throws DOMException {
+ ASTNodeProperty prop = name.getPropertyInParent();
+ if (binding instanceof ICompositeType) {
+ ICompositeType compBinding = (ICompositeType) binding;
+ int compositeKey = compBinding.getKey();
+ if (compositeKey == ICPPClassType.k_class ||
+ compositeKey == ICompositeType.k_struct) {
+ if (prop == ICPPASTBaseSpecifier.NAME) {
+ // base class
indexer.getOutput().addRef(fileNumber, IndexEncoderUtil.encodeEntry(
- getFullyQualifiedName(baseClass),
+ getFullyQualifiedName(binding),
IIndexEncodingConstants.DERIVED,
- ICSearchConstants.DECLARATIONS));
+ ICSearchConstants.DECLARATIONS),
+ loc.getNodeOffset(),
+ loc.getNodeLength(),
+ ICIndexStorageConstants.OFFSET);
}
- }
- //Get friends
- IBinding[] friendClauses = classBinding.getFriends();
- for (int i = 0; i < friendClauses.length; ++i) {
- IBinding friendClause = friendClauses[i];
- if (friendClause instanceof ICompositeType) {
+ else if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) {
+ // friend
indexer.getOutput().addRef(fileNumber, IndexEncoderUtil.encodeEntry(
- getFullyQualifiedName(friendClause),
+ getFullyQualifiedName(binding),
IIndexEncodingConstants.FRIEND,
- ICSearchConstants.DECLARATIONS));
+ ICSearchConstants.DECLARATIONS),
+ loc.getNodeOffset(),
+ loc.getNodeLength(),
+ ICIndexStorageConstants.OFFSET);
}
}
}
+ // TODO In case we want to add friend function declarations to index
+// else if (binding instanceof IFunction) {
+// IFunction funBinding = (IFunction) binding;
+// if (prop == IASTFunctionDeclarator.DECLARATOR_NAME) {
+// IASTFunctionDeclarator fDecl = (IASTFunctionDeclarator) name.getParent();
+// IASTNode fDeclParent = fDecl.getParent();
+// if (fDeclParent instanceof IASTSimpleDeclaration) {
+// IASTSimpleDeclaration sDecl = (IASTSimpleDeclaration) fDeclParent;
+// IASTDeclSpecifier declSpec = sDecl.getDeclSpecifier();
+// if (declSpec instanceof ICPPASTSimpleDeclSpecifier) {
+// ICPPASTSimpleDeclSpecifier fDeclSpec = (ICPPASTSimpleDeclSpecifier) declSpec;
+// if (fDeclSpec.isFriend()) {
+// // friend
+// indexer.getOutput().addRef(fileNumber, IndexEncoderUtil.encodeEntry(
+// getFullyQualifiedName(binding),
+// IIndexEncodingConstants.FRIEND,
+// ICSearchConstants.DECLARATIONS));
+// }
+// }
+// }
+// }
+// }
}
/**
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/DOMSourceIndexerRunner.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/DOMSourceIndexerRunner.java
index 9097a9da919..0496adbdc21 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/DOMSourceIndexerRunner.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/DOMSourceIndexerRunner.java
@@ -12,27 +12,31 @@ package org.eclipse.cdt.internal.core.index.domsourceindexer;
import java.io.IOException;
import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICLogConstants;
import org.eclipse.cdt.core.dom.CDOM;
import org.eclipse.cdt.core.dom.IASTServiceProvider.UnsupportedDialectException;
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.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree.IASTInclusionNode;
import org.eclipse.cdt.core.index.IIndexDelta;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.core.parser.ParseError;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.search.ICSearchConstants;
+import org.eclipse.cdt.internal.core.index.cindexstorage.ICIndexStorageConstants;
import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry;
import org.eclipse.cdt.internal.core.index.impl.IndexDelta;
import org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer;
@@ -40,9 +44,9 @@ import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.core.search.indexing.IIndexEncodingConstants;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
@@ -54,6 +58,11 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
private IFile resourceFile;
private SourceIndexer indexer;
+ // timing & errors
+ static int totalParseTime = 0;
+ static int totalVisitTime = 0;
+ static int errorCount = 0;
+ static Map errors = new HashMap();
public DOMSourceIndexerRunner(IFile resource, SourceIndexer indexer) {
this.resourceFile = resource;
@@ -70,7 +79,7 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
protected void indexFile(IFile file) throws IOException {
// Add the name of the file to the index
- IndexedFileEntry indFile =output.addIndexedFile(file.getFullPath().toString());
+ IndexedFileEntry indFile = output.addIndexedFile(file.getFullPath().toString());
int problems = indexer.indexProblemsEnabled(resourceFile.getProject());
setProblemMarkersEnabled(problems);
@@ -80,9 +89,9 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
ParserLanguage language = CoreModel.hasCCNature(resourceFile.getProject()) ?
ParserLanguage.CPP : ParserLanguage.C;
IASTTranslationUnit tu = null;
- try {
- long startTime = 0, parseTime = 0, endTime = 0;
-
+ long startTime = 0, parseTime = 0, endTime = 0;
+ String error = null;
+ try {
if (AbstractIndexer.TIMING)
startTime = System.currentTimeMillis();
@@ -92,9 +101,7 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
if (AbstractIndexer.TIMING)
parseTime = System.currentTimeMillis();
- // TODO Use new method to get ordered include directives instead of
- // IASTTranslationUnit.getIncludeDirectives
- processIncludeDirectives(tu.getIncludeDirectives());
+ processIncludeDirectives(tu.getDependencyTree());
processMacroDefinitions(tu.getMacroDefinitions());
ASTVisitor visitor = null;
@@ -104,39 +111,53 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
visitor = new CGenerateIndexVisitor(this, resourceFile);
}
- tu.accept(visitor);
-
- if (AbstractIndexer.TIMING){
- endTime = System.currentTimeMillis();
- System.out.println("DOM Indexer - Total Parse Time for " + resourceFile.getName() + ": " + (parseTime - startTime)); //$NON-NLS-1$ //$NON-NLS-2$
- System.out.println("DOM Indexer - Total Visit Time for " + resourceFile.getName() + ": " + (endTime - parseTime)); //$NON-NLS-1$ //$NON-NLS-2$
- long currentTime = endTime - startTime;
- System.out.println("DOM Indexer - Total Index Time for " + resourceFile.getName() + ": " + currentTime); //$NON-NLS-1$ //$NON-NLS-2$
- long tempTotaltime = indexer.getTotalIndexTime() + currentTime;
- indexer.setTotalIndexTime(tempTotaltime);
- System.out.println("DOM Indexer - Overall Index Time: " + tempTotaltime); //$NON-NLS-1$
- System.out.flush();
- }
- if (AbstractIndexer.VERBOSE){
- AbstractIndexer.verbose("DOM AST TRAVERSAL FINISHED " + resourceFile.getName().toString()); //$NON-NLS-1$
- }
+ tu.accept(visitor);
+
}
- catch ( VirtualMachineError vmErr){
- if (vmErr instanceof OutOfMemoryError){
+ catch (VirtualMachineError vmErr) {
+ error = vmErr.toString();
+ if (vmErr instanceof OutOfMemoryError) {
org.eclipse.cdt.internal.core.model.Util.log(null, "Out Of Memory error: " + vmErr.getMessage() + " on File: " + resourceFile.getName(), ICLogConstants.CDT); //$NON-NLS-1$ //$NON-NLS-2$
}
}
- catch (ParseError e){
+ catch (ParseError e) {
+ error = e.toString();
org.eclipse.cdt.internal.core.model.Util.log(null, "Parser Timeout on File: " + resourceFile.getName(), ICLogConstants.CDT); //$NON-NLS-1$
}
catch (UnsupportedDialectException e) {
+ error = e.toString();
org.eclipse.cdt.internal.core.model.Util.log(null, "Unsupported C/C++ dialect on File: " + resourceFile.getName(), ICLogConstants.CDT); //$NON-NLS-1$
}
catch (Exception ex) {
+ error = ex.toString();
if (ex instanceof IOException)
throw (IOException) ex;
}
- finally{
+ finally {
+ if (AbstractIndexer.TIMING) {
+ endTime = System.currentTimeMillis();
+ if (error != null) {
+ errorCount++;
+ System.out.print(error + ':' + resourceFile.getName() + ':');
+ if (!errors.containsKey(error)) {
+ errors.put(error, new Integer(0));
+ }
+ errors.put(error, new Integer(((Integer) errors.get(error)).intValue()+1));
+ }
+ System.out.println("DOM Indexer - Total Parse Time for " + resourceFile.getName() + ": " + (parseTime - startTime)); //$NON-NLS-1$ //$NON-NLS-2$
+ System.out.println("DOM Indexer - Total Visit Time for " + resourceFile.getName() + ": " + (endTime - parseTime)); //$NON-NLS-1$ //$NON-NLS-2$
+ totalParseTime += parseTime - startTime;
+ totalVisitTime += endTime - parseTime;
+ long currentTime = endTime - startTime;
+ System.out.println("DOM Indexer - Total Index Time for " + resourceFile.getName() + ": " + currentTime); //$NON-NLS-1$ //$NON-NLS-2$
+ long tempTotaltime = indexer.getTotalIndexTime() + currentTime;
+ indexer.setTotalIndexTime(tempTotaltime);
+ System.out.println("DOM Indexer - Overall Index Time: " + tempTotaltime + "(" + totalParseTime + ", " + totalVisitTime + ") " + errorCount + " errors"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ System.out.flush();
+ }
+ if (AbstractIndexer.VERBOSE){
+ AbstractIndexer.verbose("DOM AST TRAVERSAL FINISHED " + resourceFile.getName().toString()); //$NON-NLS-1$
+ }
// if the user disable problem reporting since we last checked, don't report the collected problems
if (areProblemMarkersEnabled()) {
reportProblems();
@@ -153,37 +174,47 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
}
/**
- * @param includeDirectives
+ * @param tree
*/
- private void processIncludeDirectives(IASTPreprocessorIncludeStatement[] includeDirectives) {
- IProject resourceProject = resourceFile.getProject();
- for (int i = 0; i < includeDirectives.length; i++) {
- String include = includeDirectives[i].getPath();
- // TODO reimplement when ordered collection becomes available
-// getOutput().addIncludeRef(include);
-// // where is this header file included
-// IASTNodeLocation[] locations = includeDirectives[i].getNodeLocations();
-// for (int j = 0; j < locations.length; j++) {
-// if (locations[j] instanceof IASTFileLocation) {
-// IASTFileLocation fileLocation = (IASTFileLocation) locations[j];
-// String parent = fileLocation.getFileName();
-// /* Check to see if this is a header file */
-// ICFileType type = CCorePlugin.getDefault().getFileType(resourceProject, parent);
-//
-// if (type.isHeader()) {
-// getOutput().addRelatives(include, parent);
-// }
-// }
-// }
- int fileNumber = getOutput().getIndexedFile(
- getResourceFile().getFullPath().toString()).getFileID();
- getOutput().addRef(fileNumber,IndexEncoderUtil.encodeEntry(
+ private void processIncludeDirectives(IDependencyTree tree) {
+ int fileNumber = getOutput().getIndexedFile(
+ getResourceFile().getFullPath().toString()).getFileID();
+
+ processNestedInclusions(fileNumber, tree.getInclusions(), null);
+ }
+
+ /**
+ * @param fileNumber
+ * @param inclusions
+ * @param parent
+ */
+ private void processNestedInclusions(int fileNumber, IASTInclusionNode[] inclusions, IASTInclusionNode parent) {
+ for (int i = 0; i < inclusions.length; i++) {
+ IASTInclusionNode inclusion = inclusions[i];
+ String include = inclusion.getIncludeDirective().getPath();
+
+ if (areProblemMarkersEnabled()) {
+ IPath newPath = new Path(include);
+ IFile tempFile = CCorePlugin.getWorkspace().getRoot().getFileForLocation(newPath);
+ if (tempFile != null) {
+ //File is in the workspace
+ requestRemoveMarkers(tempFile, resourceFile);
+ }
+ }
+
+ getOutput().addIncludeRef(fileNumber, include);
+ getOutput().addRelatives(fileNumber, include,
+ (parent != null) ? parent.getIncludeDirective().getPath() : null);
+ getOutput().addRef(fileNumber, IndexEncoderUtil.encodeEntry(
new char[][] {include.toCharArray()},
IIndexEncodingConstants.INCLUDE,
ICSearchConstants.REFERENCES));
-
+
/* See if this file has been encountered before */
- indexer.haveEncounteredHeader(resourceProject.getFullPath(),new Path(include));
+ indexer.haveEncounteredHeader(resourceFile.getProject().getFullPath(), new Path(include));
+
+ // recurse
+ processNestedInclusions(fileNumber, inclusion.getNestedInclusions(), inclusion);
}
}
@@ -193,90 +224,85 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
private void processMacroDefinitions(IASTPreprocessorMacroDefinition[] macroDefinitions) {
for (int i = 0; i < macroDefinitions.length; i++) {
IASTName macro = macroDefinitions[i].getName();
- int fileNumber = IndexEncoderUtil.calculateIndexFlags(this, macro);
+ // Get the location
+ IASTFileLocation loc = IndexEncoderUtil.getFileLocation(macro);
+ int fileNumber = IndexEncoderUtil.calculateIndexFlags(this, loc);
getOutput().addRef(fileNumber, IndexEncoderUtil.encodeEntry(
new char[][] {macro.toCharArray()},
IIndexEncodingConstants.MACRO,
- ICSearchConstants.DECLARATIONS));
+ ICSearchConstants.DECLARATIONS),
+ loc.getNodeOffset(),
+ loc.getNodeLength(),
+ ICIndexStorageConstants.OFFSET);
}
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer#addMarkers(org.eclipse.core.resources.IFile, org.eclipse.core.resources.IFile, java.lang.Object)
+ * @see org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer#addMarkers(org.eclipse.core.resources.IFile, org.eclipse.core.resources.IFile, java.lang.Object, java.lang.Object)
*/
- protected void addMarkers(IFile tempFile, IFile originator, Object problem) {
+ protected void addMarkers(IFile tempFile, IFile originator, Object problem, Object location) {
String fileName;
int sourceLineNumber = -1;
String errorMessage = ""; //$NON-NLS-1$
- IASTNodeLocation location = null;
if (problem instanceof IASTProblem) {
IASTProblem astProblem = (IASTProblem) problem;
errorMessage = astProblem.getMessage();
- location = astProblem.getNodeLocations()[0];
}
else if (problem instanceof IASTName) { // semantic error specified in IProblemBinding
IASTName name = (IASTName) problem;
if (name.resolveBinding() instanceof IProblemBinding) {
IProblemBinding problemBinding = (IProblemBinding) name.resolveBinding();
errorMessage = problemBinding.getMessage();
- location = name.getNodeLocations()[0];
- IASTNode node = problemBinding.getASTNode();
-// if (node != null && !name.equals(node)) {
-// // TODO may require further processing - looking at the IProblemBinding id
-// location = node.getNodeLocations()[0];
-// }
}
}
- if (location != null) {
- if (location instanceof IASTFileLocation) {
- IASTFileLocation fileLoc = (IASTFileLocation) location;
- fileName = fileLoc.getFileName();
- try {
- //we only ever add index markers on the file, so DEPTH_ZERO is far enough
- IMarker[] markers = tempFile.findMarkers(ICModelMarker.INDEXER_MARKER, true,IResource.DEPTH_ZERO);
+ if (location != null && location instanceof IASTFileLocation) {
+ IASTFileLocation fileLoc = (IASTFileLocation) location;
+ fileName = fileLoc.getFileName();
+ try {
+ //we only ever add index markers on the file, so DEPTH_ZERO is far enough
+ IMarker[] markers = tempFile.findMarkers(ICModelMarker.INDEXER_MARKER, true,IResource.DEPTH_ZERO);
+
+ boolean newProblem = true;
+
+ if (markers.length > 0) {
+ IMarker tempMarker = null;
+ int nameStart = -1;
+ int nameLen = -1;
+ String tempMsgString = null;
- boolean newProblem = true;
-
- if (markers.length > 0) {
- IMarker tempMarker = null;
- int nameStart = -1;
- int nameLen = -1;
- String tempMsgString = null;
-
- for (int i=0; i<markers.length; i++) {
- tempMarker = markers[i];
- nameStart = ((Integer) tempMarker.getAttribute(IMarker.CHAR_START)).intValue();
- nameLen = ((Integer) tempMarker.getAttribute(IMarker.CHAR_END)).intValue() - nameStart;
- tempMsgString = (String) tempMarker.getAttribute(IMarker.MESSAGE);
- if (nameStart != -1 &&
- nameStart == fileLoc.getNodeOffset() &&
- nameLen == fileLoc.getNodeLength() &&
- tempMsgString.equalsIgnoreCase(INDEXER_MARKER_PREFIX + errorMessage)) {
- newProblem = false;
- break;
- }
+ for (int i=0; i<markers.length; i++) {
+ tempMarker = markers[i];
+ nameStart = ((Integer) tempMarker.getAttribute(IMarker.CHAR_START)).intValue();
+ nameLen = ((Integer) tempMarker.getAttribute(IMarker.CHAR_END)).intValue() - nameStart;
+ tempMsgString = (String) tempMarker.getAttribute(IMarker.MESSAGE);
+ if (nameStart != -1 &&
+ nameStart == fileLoc.getNodeOffset() &&
+ nameLen == fileLoc.getNodeLength() &&
+ tempMsgString.equalsIgnoreCase(INDEXER_MARKER_PREFIX + errorMessage)) {
+ newProblem = false;
+ break;
}
}
- if (newProblem) {
- IMarker marker = tempFile.createMarker(ICModelMarker.INDEXER_MARKER);
- int start = fileLoc.getNodeOffset();
- int end = start + fileLoc.getNodeLength();
- // marker.setAttribute(IMarker.LOCATION, iProblem.getSourceLineNumber());
- marker.setAttribute(IMarker.LOCATION, 1);
- marker.setAttribute(IMarker.MESSAGE, INDEXER_MARKER_PREFIX + errorMessage);
- marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
- // marker.setAttribute(IMarker.LINE_NUMBER, iProblem.getSourceLineNumber());
- marker.setAttribute(IMarker.LINE_NUMBER, 1);
- marker.setAttribute(IMarker.CHAR_START, start);
- marker.setAttribute(IMarker.CHAR_END, end);
- marker.setAttribute(INDEXER_MARKER_ORIGINATOR, originator.getFullPath().toString());
- }
-
- } catch (CoreException e) {
- // You need to handle the cases where attribute value is rejected
- }
+ }
+ if (newProblem) {
+ IMarker marker = tempFile.createMarker(ICModelMarker.INDEXER_MARKER);
+ int start = fileLoc.getNodeOffset();
+ int end = start + fileLoc.getNodeLength();
+ marker.setAttribute(IMarker.LOCATION, fileLoc.getStartingLineNumber());
+ marker.setAttribute(IMarker.LOCATION, 1);
+ marker.setAttribute(IMarker.MESSAGE, INDEXER_MARKER_PREFIX + errorMessage);
+ marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
+ marker.setAttribute(IMarker.LINE_NUMBER, fileLoc.getStartingLineNumber());
+ marker.setAttribute(IMarker.LINE_NUMBER, 1);
+ marker.setAttribute(IMarker.CHAR_START, start);
+ marker.setAttribute(IMarker.CHAR_END, end);
+ marker.setAttribute(INDEXER_MARKER_ORIGINATOR, originator.getFullPath().toString());
+ }
+
+ } catch (CoreException e) {
+ // You need to handle the cases where attribute value is rejected
}
}
}
@@ -305,4 +331,19 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
return (getProblemMarkersEnabled() & SourceIndexer.SEMANTIC_PROBLEMS_BIT) != 0;
}
+ /**
+ *
+ */
+ public static void printErrors() {
+ if (AbstractIndexer.TIMING) {
+ totalParseTime = 0;
+ totalVisitTime = 0;
+ System.out.println("Errors during indexing"); //$NON-NLS-1$
+ for (Iterator i = errors.keySet().iterator(); i.hasNext(); ) {
+ String error = (String) i.next();;
+ System.out.println(error + " : " + ((Integer) errors.get(error)).toString()); //$NON-NLS-1$
+ }
+ }
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexEncoderUtil.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexEncoderUtil.java
index 99e0bb2b5c6..b51b9b80c15 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexEncoderUtil.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexEncoderUtil.java
@@ -12,7 +12,7 @@ package org.eclipse.cdt.internal.core.index.domsourceindexer;
import org.eclipse.cdt.core.CCorePlugin;
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.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo;
@@ -26,6 +26,10 @@ import org.eclipse.core.runtime.Path;
public class IndexEncoderUtil {
public static final char[] encodeEntry(char[][] elementName, EntryType entryType, LimitTo encodeType) {
+ // Temporarily
+ if (elementName == null) {
+ return "NPE".toCharArray(); //$NON-NLS-1$
+ }
int pos, nameLength = 0;
for (int i=0; i < elementName.length; i++){
char[] namePart = elementName[i];
@@ -64,7 +68,7 @@ public class IndexEncoderUtil {
return result;
}
- public static int calculateIndexFlags(DOMSourceIndexerRunner indexer, IASTName name) {
+ public static int calculateIndexFlags(DOMSourceIndexerRunner indexer, IASTFileLocation loc) {
int fileNum= 0;
//Initialize the file number to be the file number for the file that triggerd
@@ -77,14 +81,7 @@ public class IndexEncoderUtil {
if (mainIndexFile != null)
fileNum = mainIndexFile.getFileID();
- String fileName = null;
- IASTNodeLocation[] nameLocations = name.getNodeLocations();
- if (nameLocations.length > 0) {
- if (nameLocations[0] instanceof IASTFileLocation) {
- fileName = ((IASTFileLocation) nameLocations[0]).getFileName();
- }
- }
-
+ String fileName = loc.getFileName();
if (fileName != null) {
IFile tempFile = CCorePlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileName));
String filePath = ""; //$NON-NLS-1$
@@ -127,4 +124,23 @@ public class IndexEncoderUtil {
return fileNum;
}
+ /**
+ * @param name
+ * @return
+ */
+ public static IASTFileLocation getFileLocation(IASTNode node) {
+ IASTFileLocation fileLoc = null;
+
+ IASTNodeLocation[] locs = node.getNodeLocations();
+ if (locs.length == 1) {
+ if (locs[0] instanceof IASTFileLocation) {
+ fileLoc = (IASTFileLocation) locs[0];
+ }
+ }
+ else if (locs.length > 1) {
+ fileLoc = node.getTranslationUnit().flattenLocationsToFile(locs);
+ }
+ return fileLoc;
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java
index e72f4baa5d0..6e6b934d29c 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java
@@ -22,29 +22,11 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.filetype.ICFileType;
import org.eclipse.cdt.core.filetype.ICFileTypeConstants;
import org.eclipse.cdt.core.model.ICModelMarker;
-import org.eclipse.cdt.core.parser.ast.ASTClassKind;
-import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
-import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
-import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
-import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
-import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
-import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
-import org.eclipse.cdt.core.parser.ast.IASTField;
-import org.eclipse.cdt.core.parser.ast.IASTFunction;
-import org.eclipse.cdt.core.parser.ast.IASTInclusion;
-import org.eclipse.cdt.core.parser.ast.IASTMacro;
-import org.eclipse.cdt.core.parser.ast.IASTMethod;
-import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
-import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
-import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
-import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
-import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.index.IIndexer;
import org.eclipse.cdt.internal.core.index.IIndexerOutput;
-import org.eclipse.cdt.internal.core.index.cindexstorage.ICIndexStorageConstants;
import org.eclipse.cdt.internal.core.search.indexing.IIndexConstants;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.core.resources.IFile;
@@ -59,18 +41,6 @@ import org.eclipse.core.runtime.jobs.Job;
public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSearchConstants {
- final static int CLASS = 1;
- final static int STRUCT = 2;
- final static int UNION = 3;
- final static int ENUM = 4;
- final static int VAR = 5;
- final static int TYPEDEF = 6;
- final static int DERIVED = 7;
- final static int FRIEND = 8;
- final static int FWD_CLASS = 9;
- final static int FWD_STRUCT = 10;
- final static int FWD_UNION = 11;
-
public static boolean VERBOSE = false;
public static boolean TIMING = false;
@@ -96,496 +66,6 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
}
- public void addClassSpecifier(IASTClassSpecifier classSpecification, int fileNumber){
-
- if (classSpecification.getClassKind().equals(ASTClassKind.CLASS))
- {
- //Get base clauses
- Iterator baseClauses = classSpecification.getBaseClauses();
- while (baseClauses.hasNext()){
- IASTBaseSpecifier baseSpec = (IASTBaseSpecifier) baseClauses.next();
- try {
- IASTTypeSpecifier typeSpec = baseSpec.getParentClassSpecifier();
- if (typeSpec instanceof IASTClassSpecifier){
- IASTClassSpecifier baseClassSpec = (IASTClassSpecifier) typeSpec;
- char[][] baseFullyQualifiedName = baseClassSpec.getFullyQualifiedNameCharArrays();
- int offset = baseClassSpec.getNameOffset();
- int offsetLength = baseClassSpec.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,DERIVED,ICSearchConstants.DECLARATIONS), offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- } catch (ASTNotImplementedException e) {}
- }
-
- //Get friends
- Iterator friends = classSpecification.getFriends();
- while (friends.hasNext()){
- Object decl = friends.next();
- if (decl instanceof IASTClassSpecifier){
- IASTClassSpecifier friendClassSpec = (IASTClassSpecifier) decl;
- char[][] baseFullyQualifiedName = friendClassSpec.getFullyQualifiedNameCharArrays();
- int offset = friendClassSpec.getNameOffset();
- int offsetLength = friendClassSpec.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS),offset, offsetLength, ICIndexStorageConstants.OFFSET);
- }
- else if (decl instanceof IASTElaboratedTypeSpecifier){
- IASTElaboratedTypeSpecifier friendClassSpec = (IASTElaboratedTypeSpecifier) decl;
- char[][] baseFullyQualifiedName = friendClassSpec.getFullyQualifiedNameCharArrays();
- int offset = friendClassSpec.getNameOffset();
- int offsetLength = friendClassSpec.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS), offset, offsetLength, ICIndexStorageConstants.OFFSET);
- }
- else if (decl instanceof IASTFunction){
-
- }
- else if (decl instanceof IASTMethod){
- //
- }
-
- }
-
- int offset = classSpecification.getNameOffset();
- int offsetLength = classSpecification.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeTypeEntry(classSpecification.getFullyQualifiedNameCharArrays(),CLASS, ICSearchConstants.DECLARATIONS),offset, offsetLength, ICIndexStorageConstants.OFFSET);
- }
- else if (classSpecification.getClassKind().equals(ASTClassKind.STRUCT))
- {
- //Get base clauses
- Iterator i = classSpecification.getBaseClauses();
- while (i.hasNext()){
- IASTBaseSpecifier baseSpec = (IASTBaseSpecifier) i.next();
- try {
- IASTTypeSpecifier typeSpec = baseSpec.getParentClassSpecifier();
- if (typeSpec instanceof IASTClassSpecifier){
- IASTClassSpecifier baseClassSpec = (IASTClassSpecifier) typeSpec;
- char[][] baseFullyQualifiedName = baseClassSpec.getFullyQualifiedNameCharArrays();
- int offset = baseClassSpec.getNameOffset();
- int offsetLength = baseClassSpec.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,DERIVED,ICSearchConstants.DECLARATIONS),offset, offsetLength, ICIndexStorageConstants.OFFSET);
- }
- } catch (ASTNotImplementedException e) {}
- }
-
-// Get friends
- Iterator friends = classSpecification.getFriends();
- while (friends.hasNext()){
- Object decl = friends.next();
- if (decl instanceof IASTClassSpecifier){
- IASTClassSpecifier friendClassSpec = (IASTClassSpecifier) decl;
- char[][] baseFullyQualifiedName = friendClassSpec.getFullyQualifiedNameCharArrays();
- int offset = friendClassSpec.getNameOffset();
- int offsetLength = friendClassSpec.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- else if (decl instanceof IASTElaboratedTypeSpecifier){
- IASTElaboratedTypeSpecifier friendClassSpec = (IASTElaboratedTypeSpecifier) decl;
- char[][] baseFullyQualifiedName = friendClassSpec.getFullyQualifiedNameCharArrays();
- int offset = friendClassSpec.getNameOffset();
- int offsetLength = friendClassSpec.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- else if (decl instanceof IASTFunction){
-
- }
- else if (decl instanceof IASTMethod){
- //
- }
- }
-
- int offset = classSpecification.getNameOffset();
- int offsetLength = classSpecification.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeTypeEntry(classSpecification.getFullyQualifiedNameCharArrays(),STRUCT, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- else if (classSpecification.getClassKind().equals(ASTClassKind.UNION))
- {
- int offset = classSpecification.getNameOffset();
- int offsetLength = classSpecification.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeTypeEntry(classSpecification.getFullyQualifiedNameCharArrays(),UNION, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- }
-
- public void addEnumerationSpecifier(IASTEnumerationSpecifier enumeration, int fileNumber) {
-
- int offset = enumeration.getNameOffset();
- int offsetLength = enumeration.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeTypeEntry(enumeration.getFullyQualifiedNameCharArrays(), ENUM, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
-
- Iterator i = enumeration.getEnumerators();
- while (i.hasNext())
- {
- IASTEnumerator en = (IASTEnumerator) i.next();
- char[][] enumeratorFullName =
- createEnumeratorFullyQualifiedName(en);
-
- offset = en.getNameOffset();
- offsetLength = en.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeEntry( enumeratorFullName, ENUMTOR_DECL, ENUMTOR_DECL_LENGTH ),offset,offsetLength, ICIndexStorageConstants.OFFSET);
-
- }
- }
-
- protected char[][] createEnumeratorFullyQualifiedName(IASTEnumerator en) {
- char[] name = en.getNameCharArray();
- IASTEnumerationSpecifier parent = en.getOwnerEnumerationSpecifier();
- char[][] parentName = parent.getFullyQualifiedNameCharArrays();
-
- //See spec 7.2-10, the the scope of the enumerator is the same level as the enumeration
- char[][] enumeratorFullName = new char[parentName.length][];
-
- System.arraycopy( parentName, 0, enumeratorFullName, 0, parentName.length);
- enumeratorFullName[ parentName.length - 1 ] = name;
- return enumeratorFullName;
- }
-
- public void addEnumeratorReference(IASTEnumerator enumerator, int fileNumber) {
-
- int offset = enumerator.getNameOffset();
- int offsetLength = enumerator.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeEntry(createEnumeratorFullyQualifiedName(enumerator),ENUMTOR_REF,ENUMTOR_REF_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
-
- public void addMacro(IASTMacro macro, int fileNumber) {
- char[][] macroName = new char[][] { macro.getNameCharArray() };
- int offset = macro.getNameOffset();
- int offsetLength = macro.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeEntry(macroName,MACRO_DECL,MACRO_DECL_LENGTH), offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
-
- public void addEnumerationReference(IASTEnumerationSpecifier enumeration, int fileNumber) {
- int offset = enumeration.getNameOffset();
- int offsetLength = enumeration.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeTypeEntry(enumeration.getFullyQualifiedNameCharArrays(), ENUM, ICSearchConstants.REFERENCES), offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- public void addVariable(IASTVariable variable, int fileNumber) {
- int offset = variable.getNameOffset();
- int offsetLength = variable.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeTypeEntry(variable.getFullyQualifiedNameCharArrays(), VAR, ICSearchConstants.DECLARATIONS), offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
-
- public void addVariableReference(IASTVariable variable, int fileNumber) {
- int offset = variable.getNameOffset();
- int offsetLength = variable.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeTypeEntry(variable.getFullyQualifiedNameCharArrays(), VAR, ICSearchConstants.REFERENCES),offset, offsetLength, ICIndexStorageConstants.OFFSET);
- }
-
- public void addParameterReference( IASTParameterDeclaration parameter, int fileNumber ){
- int offset = parameter.getNameOffset();
- int offsetLength = parameter.getNameEndOffset() - offset;
- this.output.addRef(fileNumber,encodeTypeEntry( new char[][] { parameter.getNameCharArray() }, VAR, ICSearchConstants.REFERENCES), offset, offsetLength, ICIndexStorageConstants.OFFSET);
- }
-
- public void addTypedefDeclaration(IASTTypedefDeclaration typedef, int fileNumber) {
- int offset = typedef.getNameOffset();
- int offsetLength = typedef.getNameEndOffset() - offset;
- this.output.addRef(fileNumber,encodeEntry(typedef.getFullyQualifiedNameCharArrays(), TYPEDEF_DECL, TYPEDEF_DECL_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
-
- public void addFieldDeclaration(IASTField field, int fileNumber) {
- int offset = field.getNameOffset();
- int offsetLength = field.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeEntry(field.getFullyQualifiedNameCharArrays(),FIELD_DECL,FIELD_DECL_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
-
- public void addFieldReference(IASTField field, int fileNumber) {
- int offset = field.getNameOffset();
- int offsetLength = field.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeEntry(field.getFullyQualifiedNameCharArrays(),FIELD_REF,FIELD_REF_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
-
- public void addMethodDeclaration(IASTMethod method, int fileNumber) {
- int offset = method.getNameOffset();
- int offsetLength = method.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeEntry(method.getFullyQualifiedNameCharArrays(),METHOD_DECL,METHOD_DECL_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
-
- Iterator i=method.getParameters();
- while (i.hasNext()){
- Object parm = i.next();
- if (parm instanceof IASTParameterDeclaration){
- IASTParameterDeclaration parmDecl = (IASTParameterDeclaration) parm;
- offset = parmDecl.getNameOffset();
- offsetLength = parmDecl.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeTypeEntry(new char[][]{parmDecl.getNameCharArray()}, VAR, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- }
- }
-
- public void addMethodReference(IASTMethod method, int fileNumber) {
- int offset = method.getNameOffset();
- int offsetLength = method.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeEntry(method.getFullyQualifiedNameCharArrays(),METHOD_REF,METHOD_REF_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
-
- public void addElaboratedForwardDeclaration(IASTElaboratedTypeSpecifier elaboratedType, int fileNumber) {
- int offset = elaboratedType.getNameOffset();
- int offsetLength = elaboratedType.getNameEndOffset() - offset;
-
- if (elaboratedType.getClassKind().equals(ASTClassKind.CLASS))
- {
- this.output.addRef(fileNumber,encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),FWD_CLASS, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- else if (elaboratedType.getClassKind().equals(ASTClassKind.STRUCT))
- {
- this.output.addRef(fileNumber,encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),FWD_STRUCT, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- else if (elaboratedType.getClassKind().equals(ASTClassKind.UNION))
- {
- this.output.addRef(fileNumber,encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),FWD_UNION, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- }
-
- public void addConstructorDeclaration(){
-
- }
- public void addConstructorReference(){
-
- }
-
- public void addMemberDeclaration(){
-
- }
- public void addMemberReference(){
-
- }
-
- public void addFunctionDeclaration(IASTFunction function, int fileNumber){
- int offset = function.getNameOffset();
- int offsetLength = function.getNameEndOffset() - offset;
-
- this.output.addRef(fileNumber, encodeEntry(function.getFullyQualifiedNameCharArrays(),FUNCTION_DECL,FUNCTION_DECL_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
-
- Iterator i=function.getParameters();
- while (i.hasNext()){
- Object parm = i.next();
- if (parm instanceof IASTParameterDeclaration){
- IASTParameterDeclaration parmDecl = (IASTParameterDeclaration) parm;
- offset = parmDecl.getNameOffset();
- offsetLength = parmDecl.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeTypeEntry(new char[][]{parmDecl.getNameCharArray()}, VAR, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- }
- }
-
- public void addFunctionReference(IASTFunction function, int fileNumber){
- int offset = function.getNameOffset();
- int offsetLength = function.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeEntry(function.getFullyQualifiedNameCharArrays(),FUNCTION_REF,FUNCTION_REF_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
-
- public void addNameReference(){
-
- }
-
- public void addNamespaceDefinition(IASTNamespaceDefinition namespace, int fileNumber){
- int offset = namespace.getNameOffset();
- int offsetLength = namespace.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeEntry(namespace.getFullyQualifiedNameCharArrays(),NAMESPACE_DECL,NAMESPACE_DECL_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
-
- public void addNamespaceReference(IASTNamespaceDefinition namespace, int fileNumber) {
- int offset = namespace.getNameOffset();
- int offsetLength = namespace.getNameEndOffset() - offset;
- this.output.addRef(fileNumber, encodeEntry(namespace.getFullyQualifiedNameCharArrays(),NAMESPACE_REF,NAMESPACE_REF_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
-
- public void addTypedefReference( IASTTypedefDeclaration typedef, int fileNumber ){
- int offset = typedef.getNameOffset();
- int offsetLength = typedef.getNameEndOffset() - offset;
- this.output.addRef(fileNumber,encodeTypeEntry( typedef.getFullyQualifiedNameCharArrays(), TYPEDEF, ICSearchConstants.REFERENCES),offset, offsetLength, ICIndexStorageConstants.OFFSET);
- }
-
- private void addSuperTypeReference(int modifiers, char[] packageName, char[] typeName, char[][] enclosingTypeNames, char classOrInterface, char[] superTypeName, char superClassOrInterface){
-
- }
-
- public void addTypeReference(char[] typeName){
- //this.output.addRef(CharOperation.concat(TYPE_REF, CharOperation.lastSegment(typeName, '.')));
- }
-
- public void addClassReference(IASTTypeSpecifier reference, int fileNumber){
- char[][] fullyQualifiedName = null;
- ASTClassKind classKind = null;
- int offset=0;
- int offsetLength=1;
-
- if (reference instanceof IASTClassSpecifier){
- IASTClassSpecifier classRef = (IASTClassSpecifier) reference;
- fullyQualifiedName = classRef.getFullyQualifiedNameCharArrays();
- classKind = classRef.getClassKind();
- offset=classRef.getNameOffset();
- offsetLength=classRef.getNameEndOffset() - offset;
- }
- else if (reference instanceof IASTElaboratedTypeSpecifier){
- IASTElaboratedTypeSpecifier typeRef = (IASTElaboratedTypeSpecifier) reference;
- fullyQualifiedName = typeRef.getFullyQualifiedNameCharArrays();
- classKind = typeRef.getClassKind();
- offset=typeRef.getNameOffset();
- offsetLength=typeRef.getNameEndOffset()-offset;
- }
-
- if (classKind.equals(ASTClassKind.CLASS))
- {
- this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,CLASS, ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- else if (classKind.equals(ASTClassKind.STRUCT))
- {
- this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,STRUCT,ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- else if (classKind.equals(ASTClassKind.UNION))
- {
- this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,UNION,ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- }
- public void addForwardClassReference(IASTTypeSpecifier reference, int fileNumber){
- char[][] fullyQualifiedName = null;
- ASTClassKind classKind = null;
- int offset=0;
- int offsetLength=1;
- if (reference instanceof IASTElaboratedTypeSpecifier){
- IASTElaboratedTypeSpecifier typeRef = (IASTElaboratedTypeSpecifier) reference;
- fullyQualifiedName = typeRef.getFullyQualifiedNameCharArrays();
- classKind = typeRef.getClassKind();
- offset=typeRef.getNameOffset();
- offsetLength=typeRef.getNameEndOffset() - offset;
- }
-
- if (classKind == null)
- return;
-
- if (classKind.equals(ASTClassKind.CLASS))
- {
- this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,FWD_CLASS, ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- else if (classKind.equals(ASTClassKind.STRUCT))
- {
- this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,FWD_STRUCT,ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- else if (classKind.equals(ASTClassKind.UNION))
- {
- this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,FWD_UNION,ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
- }
- }
- /**
- * Type entries are encoded as follow: 'typeDecl/' ('C' | 'S' | 'U' | 'E' ) '/' TypeName ['/' Qualifier]*
- */
- protected static final char[] encodeTypeEntry( char[][] fullTypeName, int typeType, LimitTo encodeType){
-
- int pos = 0, nameLength = 0;
- for (int i=0; i<fullTypeName.length; i++){
- char[] namePart = fullTypeName[i];
- nameLength+= namePart.length;
- }
-
- char [] result = null;
- if( encodeType == REFERENCES ){
- //char[] has to be of size - [type decl length + length of the name + separators + letter]
- result = new char[TYPE_REF_LENGTH + nameLength + fullTypeName.length + 1 ];
- System.arraycopy(TYPE_REF, 0, result, 0, pos = TYPE_REF_LENGTH);
-
- } else if( encodeType == DECLARATIONS ){
- //char[] has to be of size - [type decl length + length of the name + separators + letter]
- result = new char[TYPE_DECL_LENGTH + nameLength + fullTypeName.length + 1 ];
- System.arraycopy(TYPE_DECL, 0, result, 0, pos = TYPE_DECL_LENGTH);
- }
- switch (typeType)
- {
- case(CLASS):
- result[pos++] = CLASS_SUFFIX;
- break;
-
- case(STRUCT):
- result[pos++] = STRUCT_SUFFIX;
- break;
-
- case(UNION):
- result[pos++] = UNION_SUFFIX;
- break;
-
- case(ENUM):
- result[pos++] = ENUM_SUFFIX;
- break;
-
- case (VAR):
- result[pos++] = VAR_SUFFIX;
- break;
-
- case (TYPEDEF):
- result[pos++] = TYPEDEF_SUFFIX;
- break;
-
- case(DERIVED):
- result[pos++]= DERIVED_SUFFIX;
- break;
-
- case(FRIEND):
- result[pos++]=FRIEND_SUFFIX;
- break;
-
- case(FWD_CLASS):
- result[pos++]=FWD_CLASS_SUFFIX;
- break;
-
- case (FWD_STRUCT):
- result[pos++]=FWD_STRUCT_SUFFIX;
- break;
-
- case (FWD_UNION):
- result[pos++]=FWD_UNION_SUFFIX;
- break;
- }
- result[pos++] = SEPARATOR;
- //Encode in the following manner
- // [typeDecl info]/[typeName]/[qualifiers]
- if (fullTypeName.length > 0){
- //Extract the name first
- char [] tempName = fullTypeName[fullTypeName.length-1];
- System.arraycopy(tempName, 0, result, pos, tempName.length);
- pos += tempName.length;
- }
- //Extract the qualifiers
- for (int i=fullTypeName.length - 2; i >= 0; i--){
- result[pos++] = SEPARATOR;
- char [] tempName = fullTypeName[i];
- System.arraycopy(tempName, 0, result, pos, tempName.length);
- pos+=tempName.length;
- }
-
- if (AbstractIndexer.VERBOSE)
- AbstractIndexer.verbose(new String(result));
-
- return result;
- }
- /**
- * Namespace entries are encoded as follow: '[prefix]/' TypeName ['/' Qualifier]*
- */
- protected static final char[] encodeEntry(char[][] elementName, char[] prefix, int prefixSize){
- int pos, nameLength = 0;
- for (int i=0; i<elementName.length; i++){
- char[] namePart = elementName[i];
- nameLength+= namePart.length;
- }
- //char[] has to be of size - [type length + length of the name (including qualifiers) +
- //separators (need one less than fully qualified name length)
- char[] result = new char[prefixSize + nameLength + elementName.length - 1 ];
- System.arraycopy(prefix, 0, result, 0, pos = prefix.length);
- if (elementName.length > 0){
- //Extract the name first
- char [] tempName = elementName[elementName.length-1];
- System.arraycopy(tempName, 0, result, pos, tempName.length);
- pos += tempName.length;
- }
- //Extract the qualifiers
- for (int i=elementName.length - 2; i>=0; i--){
- result[pos++] = SEPARATOR;
- char [] tempName = elementName[i];
- System.arraycopy(tempName, 0, result, pos, tempName.length);
- pos+=tempName.length;
- }
-
- if (AbstractIndexer.VERBOSE)
- AbstractIndexer.verbose(new String(result));
-
- return result;
- }
-
/**
* Returns the file types being indexed.
*/
@@ -926,19 +406,6 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
return bestPrefix( prefix, (char)0, incName, null, matchMode, isCaseSenstive );
}
- public void addInclude(IASTInclusion inclusion, IASTInclusion parent, int fileNumber){
- this.output.addIncludeRef(fileNumber, inclusion.getFullFileName());
- this.output.addRelatives(fileNumber, inclusion.getFullFileName(),(parent != null ) ? parent.getFullFileName() : null);
-
- //Add Dep Table entry
- char[][] incName = new char[1][];
- incName[0] = inclusion.getFullFileName().toCharArray();
- //TODO: Kludge! Get rid of BOGUS entry - need to restructure Dep Tree to use reference indexes
- int BOGUS_ENTRY = 1;
- this.output.addRef(fileNumber, encodeEntry(incName, INCLUDE_REF, INCLUDE_REF_LENGTH));
- }
-
-
abstract private class Problem {
public IFile file;
@@ -950,11 +417,13 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
abstract public boolean isAddProblem();
abstract public Object getProblem();
+ abstract public Object getLocation();
}
private class AddMarkerProblem extends Problem {
private Object problem;
- public AddMarkerProblem(IFile file, IFile orig, Object problem) {
+ private Object location;
+ public AddMarkerProblem(IFile file, IFile orig, Object problem, Object location) {
super( file, orig );
this.problem = problem;
}
@@ -964,6 +433,9 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
public Object getProblem(){
return problem;
}
+ public Object getLocation() {
+ return location;
+ }
}
private class RemoveMarkerProblem extends Problem {
@@ -976,6 +448,9 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
public Object getProblem() {
return null;
}
+ public Object getLocation() {
+ return null;
+ }
}
// Problem markers ******************************
@@ -999,9 +474,10 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
* @param tempFile - not null
* @param resourceFile
* @param problem
+ * @param location
*/
- public void generateMarkerProblem(IFile tempFile, IFile resourceFile, Object problem) {
- Problem tempProblem = new AddMarkerProblem(tempFile, resourceFile, problem);
+ public void generateMarkerProblem(IFile tempFile, IFile resourceFile, Object problem, Object location) {
+ Problem tempProblem = new AddMarkerProblem(tempFile, resourceFile, problem, location);
if (problemsMap.containsKey(tempFile)) {
List list = (List) problemsMap.get(tempFile);
list.add(tempProblem);
@@ -1098,14 +574,14 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
while (i.hasNext()) {
Problem prob = (Problem) i.next();
if (prob.isAddProblem()) {
- addMarkers(prob.file, prob.originator, prob.getProblem());
+ addMarkers(prob.file, prob.originator, prob.getProblem(), prob.getLocation());
} else {
removeMarkers(prob.file, prob.originator);
}
}
}
- abstract protected void addMarkers(IFile tempFile, IFile originator, Object problem);
+ abstract protected void addMarkers(IFile tempFile, IFile originator, Object problem, Object location);
public void removeMarkers(IFile resource, IFile originator) {
if (originator == null) {
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java
index 7edaab5ff29..246bf4b7af9 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java
@@ -118,7 +118,7 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
}
if( tempFile != null ){
- indexer.generateMarkerProblem(tempFile, resourceFile, problem);
+ indexer.generateMarkerProblem(tempFile, resourceFile, problem, null);
}
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRunner.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRunner.java
index f03a795849d..1bee749288e 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRunner.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRunner.java
@@ -18,6 +18,7 @@ package org.eclipse.cdt.internal.core.index.sourceindexer;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Iterator;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICLogConstants;
@@ -35,6 +36,25 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo;
+import org.eclipse.cdt.core.parser.ast.ASTClassKind;
+import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
+import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
+import org.eclipse.cdt.core.parser.ast.IASTField;
+import org.eclipse.cdt.core.parser.ast.IASTFunction;
+import org.eclipse.cdt.core.parser.ast.IASTInclusion;
+import org.eclipse.cdt.core.parser.ast.IASTMacro;
+import org.eclipse.cdt.core.parser.ast.IASTMethod;
+import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
+import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTVariable;
+import org.eclipse.cdt.core.search.ICSearchConstants;
+import org.eclipse.cdt.internal.core.index.cindexstorage.ICIndexStorageConstants;
import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry;
import org.eclipse.cdt.internal.core.index.impl.IndexDelta;
import org.eclipse.core.resources.IFile;
@@ -58,6 +78,18 @@ import org.eclipse.core.runtime.Path;
*/
public class SourceIndexerRunner extends AbstractIndexer {
+ final static int CLASS = 1;
+ final static int STRUCT = 2;
+ final static int UNION = 3;
+ final static int ENUM = 4;
+ final static int VAR = 5;
+ final static int TYPEDEF = 6;
+ final static int DERIVED = 7;
+ final static int FRIEND = 8;
+ final static int FWD_CLASS = 9;
+ final static int FWD_STRUCT = 10;
+ final static int FWD_UNION = 11;
+
IFile resourceFile;
private SourceIndexer indexer;
@@ -179,9 +211,9 @@ public class SourceIndexerRunner extends AbstractIndexer {
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer#addMarkers(org.eclipse.core.resources.IFile, org.eclipse.core.resources.IFile, java.lang.Object)
+ * @see org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer#addMarkers(org.eclipse.core.resources.IFile, org.eclipse.core.resources.IFile, java.lang.Object, java.lang.Object)
*/
- protected void addMarkers(IFile tempFile, IFile originator, Object problem) {
+ protected void addMarkers(IFile tempFile, IFile originator, Object problem, Object location) {
if (problem instanceof IProblem) {
IProblem iProblem = (IProblem) problem;
@@ -229,4 +261,508 @@ public class SourceIndexerRunner extends AbstractIndexer {
}
}
}
+
+ public void addClassSpecifier(IASTClassSpecifier classSpecification, int fileNumber){
+
+ if (classSpecification.getClassKind().equals(ASTClassKind.CLASS))
+ {
+ //Get base clauses
+ Iterator baseClauses = classSpecification.getBaseClauses();
+ while (baseClauses.hasNext()){
+ IASTBaseSpecifier baseSpec = (IASTBaseSpecifier) baseClauses.next();
+ try {
+ IASTTypeSpecifier typeSpec = baseSpec.getParentClassSpecifier();
+ if (typeSpec instanceof IASTClassSpecifier){
+ IASTClassSpecifier baseClassSpec = (IASTClassSpecifier) typeSpec;
+ char[][] baseFullyQualifiedName = baseClassSpec.getFullyQualifiedNameCharArrays();
+ int offset = baseClassSpec.getNameOffset();
+ int offsetLength = baseClassSpec.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,DERIVED,ICSearchConstants.DECLARATIONS), offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ } catch (ASTNotImplementedException e) {}
+ }
+
+ //Get friends
+ Iterator friends = classSpecification.getFriends();
+ while (friends.hasNext()){
+ Object decl = friends.next();
+ if (decl instanceof IASTClassSpecifier){
+ IASTClassSpecifier friendClassSpec = (IASTClassSpecifier) decl;
+ char[][] baseFullyQualifiedName = friendClassSpec.getFullyQualifiedNameCharArrays();
+ int offset = friendClassSpec.getNameOffset();
+ int offsetLength = friendClassSpec.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS),offset, offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ else if (decl instanceof IASTElaboratedTypeSpecifier){
+ IASTElaboratedTypeSpecifier friendClassSpec = (IASTElaboratedTypeSpecifier) decl;
+ char[][] baseFullyQualifiedName = friendClassSpec.getFullyQualifiedNameCharArrays();
+ int offset = friendClassSpec.getNameOffset();
+ int offsetLength = friendClassSpec.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS), offset, offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ else if (decl instanceof IASTFunction){
+
+ }
+ else if (decl instanceof IASTMethod){
+ //
+ }
+
+ }
+
+ int offset = classSpecification.getNameOffset();
+ int offsetLength = classSpecification.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeTypeEntry(classSpecification.getFullyQualifiedNameCharArrays(),CLASS, ICSearchConstants.DECLARATIONS),offset, offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ else if (classSpecification.getClassKind().equals(ASTClassKind.STRUCT))
+ {
+ //Get base clauses
+ Iterator i = classSpecification.getBaseClauses();
+ while (i.hasNext()){
+ IASTBaseSpecifier baseSpec = (IASTBaseSpecifier) i.next();
+ try {
+ IASTTypeSpecifier typeSpec = baseSpec.getParentClassSpecifier();
+ if (typeSpec instanceof IASTClassSpecifier){
+ IASTClassSpecifier baseClassSpec = (IASTClassSpecifier) typeSpec;
+ char[][] baseFullyQualifiedName = baseClassSpec.getFullyQualifiedNameCharArrays();
+ int offset = baseClassSpec.getNameOffset();
+ int offsetLength = baseClassSpec.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,DERIVED,ICSearchConstants.DECLARATIONS),offset, offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ } catch (ASTNotImplementedException e) {}
+ }
+
+// Get friends
+ Iterator friends = classSpecification.getFriends();
+ while (friends.hasNext()){
+ Object decl = friends.next();
+ if (decl instanceof IASTClassSpecifier){
+ IASTClassSpecifier friendClassSpec = (IASTClassSpecifier) decl;
+ char[][] baseFullyQualifiedName = friendClassSpec.getFullyQualifiedNameCharArrays();
+ int offset = friendClassSpec.getNameOffset();
+ int offsetLength = friendClassSpec.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ else if (decl instanceof IASTElaboratedTypeSpecifier){
+ IASTElaboratedTypeSpecifier friendClassSpec = (IASTElaboratedTypeSpecifier) decl;
+ char[][] baseFullyQualifiedName = friendClassSpec.getFullyQualifiedNameCharArrays();
+ int offset = friendClassSpec.getNameOffset();
+ int offsetLength = friendClassSpec.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ else if (decl instanceof IASTFunction){
+
+ }
+ else if (decl instanceof IASTMethod){
+ //
+ }
+ }
+
+ int offset = classSpecification.getNameOffset();
+ int offsetLength = classSpecification.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeTypeEntry(classSpecification.getFullyQualifiedNameCharArrays(),STRUCT, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ else if (classSpecification.getClassKind().equals(ASTClassKind.UNION))
+ {
+ int offset = classSpecification.getNameOffset();
+ int offsetLength = classSpecification.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeTypeEntry(classSpecification.getFullyQualifiedNameCharArrays(),UNION, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ }
+
+ public void addEnumerationSpecifier(IASTEnumerationSpecifier enumeration, int fileNumber) {
+
+ int offset = enumeration.getNameOffset();
+ int offsetLength = enumeration.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeTypeEntry(enumeration.getFullyQualifiedNameCharArrays(), ENUM, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+
+ Iterator i = enumeration.getEnumerators();
+ while (i.hasNext())
+ {
+ IASTEnumerator en = (IASTEnumerator) i.next();
+ char[][] enumeratorFullName =
+ createEnumeratorFullyQualifiedName(en);
+
+ offset = en.getNameOffset();
+ offsetLength = en.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeEntry( enumeratorFullName, ENUMTOR_DECL, ENUMTOR_DECL_LENGTH ),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+
+ }
+ }
+
+ protected char[][] createEnumeratorFullyQualifiedName(IASTEnumerator en) {
+ char[] name = en.getNameCharArray();
+ IASTEnumerationSpecifier parent = en.getOwnerEnumerationSpecifier();
+ char[][] parentName = parent.getFullyQualifiedNameCharArrays();
+
+ //See spec 7.2-10, the the scope of the enumerator is the same level as the enumeration
+ char[][] enumeratorFullName = new char[parentName.length][];
+
+ System.arraycopy( parentName, 0, enumeratorFullName, 0, parentName.length);
+ enumeratorFullName[ parentName.length - 1 ] = name;
+ return enumeratorFullName;
+ }
+
+ public void addEnumeratorReference(IASTEnumerator enumerator, int fileNumber) {
+
+ int offset = enumerator.getNameOffset();
+ int offsetLength = enumerator.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeEntry(createEnumeratorFullyQualifiedName(enumerator),ENUMTOR_REF,ENUMTOR_REF_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+
+ public void addMacro(IASTMacro macro, int fileNumber) {
+ char[][] macroName = new char[][] { macro.getNameCharArray() };
+ int offset = macro.getNameOffset();
+ int offsetLength = macro.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeEntry(macroName,MACRO_DECL,MACRO_DECL_LENGTH), offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+
+ public void addEnumerationReference(IASTEnumerationSpecifier enumeration, int fileNumber) {
+ int offset = enumeration.getNameOffset();
+ int offsetLength = enumeration.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeTypeEntry(enumeration.getFullyQualifiedNameCharArrays(), ENUM, ICSearchConstants.REFERENCES), offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ public void addVariable(IASTVariable variable, int fileNumber) {
+ int offset = variable.getNameOffset();
+ int offsetLength = variable.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeTypeEntry(variable.getFullyQualifiedNameCharArrays(), VAR, ICSearchConstants.DECLARATIONS), offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+
+ public void addVariableReference(IASTVariable variable, int fileNumber) {
+ int offset = variable.getNameOffset();
+ int offsetLength = variable.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeTypeEntry(variable.getFullyQualifiedNameCharArrays(), VAR, ICSearchConstants.REFERENCES),offset, offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+
+ public void addParameterReference( IASTParameterDeclaration parameter, int fileNumber ){
+ int offset = parameter.getNameOffset();
+ int offsetLength = parameter.getNameEndOffset() - offset;
+ output.addRef(fileNumber,encodeTypeEntry( new char[][] { parameter.getNameCharArray() }, VAR, ICSearchConstants.REFERENCES), offset, offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+
+ public void addTypedefDeclaration(IASTTypedefDeclaration typedef, int fileNumber) {
+ int offset = typedef.getNameOffset();
+ int offsetLength = typedef.getNameEndOffset() - offset;
+ output.addRef(fileNumber,encodeEntry(typedef.getFullyQualifiedNameCharArrays(), TYPEDEF_DECL, TYPEDEF_DECL_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+
+ public void addFieldDeclaration(IASTField field, int fileNumber) {
+ int offset = field.getNameOffset();
+ int offsetLength = field.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeEntry(field.getFullyQualifiedNameCharArrays(),FIELD_DECL,FIELD_DECL_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+
+ public void addFieldReference(IASTField field, int fileNumber) {
+ int offset = field.getNameOffset();
+ int offsetLength = field.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeEntry(field.getFullyQualifiedNameCharArrays(),FIELD_REF,FIELD_REF_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+
+ public void addMethodDeclaration(IASTMethod method, int fileNumber) {
+ int offset = method.getNameOffset();
+ int offsetLength = method.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeEntry(method.getFullyQualifiedNameCharArrays(),METHOD_DECL,METHOD_DECL_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+
+ Iterator i=method.getParameters();
+ while (i.hasNext()){
+ Object parm = i.next();
+ if (parm instanceof IASTParameterDeclaration){
+ IASTParameterDeclaration parmDecl = (IASTParameterDeclaration) parm;
+ offset = parmDecl.getNameOffset();
+ offsetLength = parmDecl.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeTypeEntry(new char[][]{parmDecl.getNameCharArray()}, VAR, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ }
+ }
+
+ public void addMethodReference(IASTMethod method, int fileNumber) {
+ int offset = method.getNameOffset();
+ int offsetLength = method.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeEntry(method.getFullyQualifiedNameCharArrays(),METHOD_REF,METHOD_REF_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+
+ public void addElaboratedForwardDeclaration(IASTElaboratedTypeSpecifier elaboratedType, int fileNumber) {
+ int offset = elaboratedType.getNameOffset();
+ int offsetLength = elaboratedType.getNameEndOffset() - offset;
+
+ if (elaboratedType.getClassKind().equals(ASTClassKind.CLASS))
+ {
+ output.addRef(fileNumber,encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),FWD_CLASS, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ else if (elaboratedType.getClassKind().equals(ASTClassKind.STRUCT))
+ {
+ output.addRef(fileNumber,encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),FWD_STRUCT, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ else if (elaboratedType.getClassKind().equals(ASTClassKind.UNION))
+ {
+ output.addRef(fileNumber,encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),FWD_UNION, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ }
+
+ public void addConstructorDeclaration(){
+
+ }
+ public void addConstructorReference(){
+
+ }
+
+ public void addMemberDeclaration(){
+
+ }
+ public void addMemberReference(){
+
+ }
+
+ public void addFunctionDeclaration(IASTFunction function, int fileNumber){
+ int offset = function.getNameOffset();
+ int offsetLength = function.getNameEndOffset() - offset;
+
+ output.addRef(fileNumber, encodeEntry(function.getFullyQualifiedNameCharArrays(),FUNCTION_DECL,FUNCTION_DECL_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+
+ Iterator i=function.getParameters();
+ while (i.hasNext()){
+ Object parm = i.next();
+ if (parm instanceof IASTParameterDeclaration){
+ IASTParameterDeclaration parmDecl = (IASTParameterDeclaration) parm;
+ offset = parmDecl.getNameOffset();
+ offsetLength = parmDecl.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeTypeEntry(new char[][]{parmDecl.getNameCharArray()}, VAR, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ }
+ }
+
+ public void addFunctionReference(IASTFunction function, int fileNumber){
+ int offset = function.getNameOffset();
+ int offsetLength = function.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeEntry(function.getFullyQualifiedNameCharArrays(),FUNCTION_REF,FUNCTION_REF_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+
+ public void addNameReference(){
+
+ }
+
+ public void addNamespaceDefinition(IASTNamespaceDefinition namespace, int fileNumber){
+ int offset = namespace.getNameOffset();
+ int offsetLength = namespace.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeEntry(namespace.getFullyQualifiedNameCharArrays(),NAMESPACE_DECL,NAMESPACE_DECL_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+
+ public void addNamespaceReference(IASTNamespaceDefinition namespace, int fileNumber) {
+ int offset = namespace.getNameOffset();
+ int offsetLength = namespace.getNameEndOffset() - offset;
+ output.addRef(fileNumber, encodeEntry(namespace.getFullyQualifiedNameCharArrays(),NAMESPACE_REF,NAMESPACE_REF_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+
+ public void addTypedefReference( IASTTypedefDeclaration typedef, int fileNumber ){
+ int offset = typedef.getNameOffset();
+ int offsetLength = typedef.getNameEndOffset() - offset;
+ output.addRef(fileNumber,encodeTypeEntry( typedef.getFullyQualifiedNameCharArrays(), TYPEDEF, ICSearchConstants.REFERENCES),offset, offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+
+ private void addSuperTypeReference(int modifiers, char[] packageName, char[] typeName, char[][] enclosingTypeNames, char classOrInterface, char[] superTypeName, char superClassOrInterface){
+
+ }
+
+ public void addTypeReference(char[] typeName){
+ //output.addRef(CharOperation.concat(TYPE_REF, CharOperation.lastSegment(typeName, '.')));
+ }
+
+ public void addClassReference(IASTTypeSpecifier reference, int fileNumber){
+ char[][] fullyQualifiedName = null;
+ ASTClassKind classKind = null;
+ int offset=0;
+ int offsetLength=1;
+
+ if (reference instanceof IASTClassSpecifier){
+ IASTClassSpecifier classRef = (IASTClassSpecifier) reference;
+ fullyQualifiedName = classRef.getFullyQualifiedNameCharArrays();
+ classKind = classRef.getClassKind();
+ offset=classRef.getNameOffset();
+ }
+ else if (reference instanceof IASTElaboratedTypeSpecifier){
+ IASTElaboratedTypeSpecifier typeRef = (IASTElaboratedTypeSpecifier) reference;
+ fullyQualifiedName = typeRef.getFullyQualifiedNameCharArrays();
+ classKind = typeRef.getClassKind();
+ offset=typeRef.getNameOffset();
+ offsetLength=typeRef.getNameEndOffset()-offset;
+ }
+
+ if (classKind.equals(ASTClassKind.CLASS))
+ {
+ output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,CLASS, ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ else if (classKind.equals(ASTClassKind.STRUCT))
+ {
+ output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,STRUCT,ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ else if (classKind.equals(ASTClassKind.UNION))
+ {
+ output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,UNION,ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ }
+
+ public void addForwardClassReference(IASTTypeSpecifier reference, int fileNumber){
+ char[][] fullyQualifiedName = null;
+ ASTClassKind classKind = null;
+ int offset=0;
+ int offsetLength=1;
+ if (reference instanceof IASTElaboratedTypeSpecifier){
+ IASTElaboratedTypeSpecifier typeRef = (IASTElaboratedTypeSpecifier) reference;
+ fullyQualifiedName = typeRef.getFullyQualifiedNameCharArrays();
+ classKind = typeRef.getClassKind();
+ offset=typeRef.getNameOffset();
+ offsetLength=typeRef.getNameEndOffset() - offset;
+ }
+
+ if (classKind == null)
+ return;
+
+ if (classKind.equals(ASTClassKind.CLASS))
+ {
+ output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,FWD_CLASS, ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ else if (classKind.equals(ASTClassKind.STRUCT))
+ {
+ output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,FWD_STRUCT,ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ else if (classKind.equals(ASTClassKind.UNION))
+ {
+ output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,FWD_UNION,ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
+ }
+ }
+
+ public void addInclude(IASTInclusion inclusion, IASTInclusion parent, int fileNumber){
+ this.output.addIncludeRef(fileNumber, inclusion.getFullFileName());
+ this.output.addRelatives(fileNumber, inclusion.getFullFileName(),(parent != null ) ? parent.getFullFileName() : null);
+
+ //Add Dep Table entry
+ char[][] incName = new char[1][];
+ incName[0] = inclusion.getFullFileName().toCharArray();
+ //TODO: Kludge! Get rid of BOGUS entry - need to restructure Dep Tree to use reference indexes
+ int BOGUS_ENTRY = 1;
+ this.output.addRef(fileNumber, encodeEntry(incName, INCLUDE_REF, INCLUDE_REF_LENGTH),1,1, ICIndexStorageConstants.LINE);
+ }
+
+ /**
+ * Type entries are encoded as follow: 'typeDecl/' ('C' | 'S' | 'U' | 'E' ) '/' TypeName ['/' Qualifier]*
+ */
+ protected static final char[] encodeTypeEntry( char[][] fullTypeName, int typeType, LimitTo encodeType){
+
+ int pos = 0, nameLength = 0;
+ for (int i=0; i<fullTypeName.length; i++){
+ char[] namePart = fullTypeName[i];
+ nameLength+= namePart.length;
+ }
+
+ char [] result = null;
+ if( encodeType == REFERENCES ){
+ //char[] has to be of size - [type decl length + length of the name + separators + letter]
+ result = new char[TYPE_REF_LENGTH + nameLength + fullTypeName.length + 1 ];
+ System.arraycopy(TYPE_REF, 0, result, 0, pos = TYPE_REF_LENGTH);
+
+ } else if( encodeType == DECLARATIONS ){
+ //char[] has to be of size - [type decl length + length of the name + separators + letter]
+ result = new char[TYPE_DECL_LENGTH + nameLength + fullTypeName.length + 1 ];
+ System.arraycopy(TYPE_DECL, 0, result, 0, pos = TYPE_DECL_LENGTH);
+ }
+ switch (typeType)
+ {
+ case(CLASS):
+ result[pos++] = CLASS_SUFFIX;
+ break;
+
+ case(STRUCT):
+ result[pos++] = STRUCT_SUFFIX;
+ break;
+
+ case(UNION):
+ result[pos++] = UNION_SUFFIX;
+ break;
+
+ case(ENUM):
+ result[pos++] = ENUM_SUFFIX;
+ break;
+
+ case (VAR):
+ result[pos++] = VAR_SUFFIX;
+ break;
+
+ case (TYPEDEF):
+ result[pos++] = TYPEDEF_SUFFIX;
+ break;
+
+ case(DERIVED):
+ result[pos++]= DERIVED_SUFFIX;
+ break;
+
+ case(FRIEND):
+ result[pos++]=FRIEND_SUFFIX;
+ break;
+
+ case(FWD_CLASS):
+ result[pos++]=FWD_CLASS_SUFFIX;
+ break;
+
+ case (FWD_STRUCT):
+ result[pos++]=FWD_STRUCT_SUFFIX;
+ break;
+
+ case (FWD_UNION):
+ result[pos++]=FWD_UNION_SUFFIX;
+ break;
+ }
+ result[pos++] = SEPARATOR;
+ //Encode in the following manner
+ // [typeDecl info]/[typeName]/[qualifiers]
+ if (fullTypeName.length > 0){
+ //Extract the name first
+ char [] tempName = fullTypeName[fullTypeName.length-1];
+ System.arraycopy(tempName, 0, result, pos, tempName.length);
+ pos += tempName.length;
+ }
+ //Extract the qualifiers
+ for (int i=fullTypeName.length - 2; i >= 0; i--){
+ result[pos++] = SEPARATOR;
+ char [] tempName = fullTypeName[i];
+ System.arraycopy(tempName, 0, result, pos, tempName.length);
+ pos+=tempName.length;
+ }
+
+ if (AbstractIndexer.VERBOSE)
+ AbstractIndexer.verbose(new String(result));
+
+ return result;
+ }
+ /**
+ * Namespace entries are encoded as follow: '[prefix]/' TypeName ['/' Qualifier]*
+ */
+ protected static final char[] encodeEntry(char[][] elementName, char[] prefix, int prefixSize){
+ int pos, nameLength = 0;
+ for (int i=0; i<elementName.length; i++){
+ char[] namePart = elementName[i];
+ nameLength+= namePart.length;
+ }
+ //char[] has to be of size - [type length + length of the name (including qualifiers) +
+ //separators (need one less than fully qualified name length)
+ char[] result = new char[prefixSize + nameLength + elementName.length - 1 ];
+ System.arraycopy(prefix, 0, result, 0, pos = prefix.length);
+ if (elementName.length > 0){
+ //Extract the name first
+ char [] tempName = elementName[elementName.length-1];
+ System.arraycopy(tempName, 0, result, pos, tempName.length);
+ pos += tempName.length;
+ }
+ //Extract the qualifiers
+ for (int i=elementName.length - 2; i>=0; i--){
+ result[pos++] = SEPARATOR;
+ char [] tempName = elementName[i];
+ System.arraycopy(tempName, 0, result, pos, tempName.length);
+ pos+=tempName.length;
+ }
+
+ if (AbstractIndexer.VERBOSE)
+ AbstractIndexer.verbose(new String(result));
+
+ return result;
+ }
+
}

Back to the top