Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-02-29 09:10:44 +0000
committerMarkus Schorn2008-02-29 09:10:44 +0000
commita8e7f57545b557806b2a10fb1fb95c3e4489d9c6 (patch)
tree7928261fc4ac1cc8c841e2497440f5daeb132cf4 /core/org.eclipse.cdt.core/parser
parent2250f00e98e6da685c175678bd7b2643b34ad876 (diff)
downloadorg.eclipse.cdt-a8e7f57545b557806b2a10fb1fb95c3e4489d9c6.tar.gz
org.eclipse.cdt-a8e7f57545b557806b2a10fb1fb95c3e4489d9c6.tar.xz
org.eclipse.cdt-a8e7f57545b557806b2a10fb1fb95c3e4489d9c6.zip
Combine CFindNodeForOffsetAction and CPPFindNodeForOffsetAction.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java24
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FindNodeForOffsetAction.java214
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java226
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java180
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java14
6 files changed, 254 insertions, 418 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java
index 5a9a8bb9387..caa28508919 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java
@@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTComment;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
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;
@@ -308,4 +309,27 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
public final IIndexFileSet getIndexFileSet() {
return fIndexFileSet;
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getNodeForLocation(org.eclipse.cdt.core.dom.ast.IASTNodeLocation)
+ */
+ public final IASTNode selectNodeForLocation(String path, int realOffset, int realLength) {
+ IASTNode result= null;
+ if (fLocationResolver != null) {
+ int start= fLocationResolver.getSequenceNumberForFileOffset(path, realOffset);
+ if (start >= 0) {
+ int length= realLength < 1 ? 0 :
+ fLocationResolver.getSequenceNumberForFileOffset(path, realOffset+realLength-1) + 1 - start;
+ result= fLocationResolver.findSurroundingPreprocessorNode(start, length);
+ if (result == null) {
+ FindNodeForOffsetAction nodeFinder = new FindNodeForOffsetAction(start, length);
+ accept(nodeFinder);
+ result = nodeFinder.getNode();
+ }
+ }
+ }
+ return result;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FindNodeForOffsetAction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FindNodeForOffsetAction.java
new file mode 100644
index 00000000000..a42d41926e6
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FindNodeForOffsetAction.java
@@ -0,0 +1,214 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Wind River Systems, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.parser;
+
+import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
+import org.eclipse.cdt.core.dom.ast.IASTProblem;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.IASTTypeId;
+import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
+import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
+import org.eclipse.cdt.core.dom.ast.c.ICASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
+
+public class FindNodeForOffsetAction extends CPPASTVisitor implements ICASTVisitor, ICPPASTVisitor {
+ private IASTNode fFoundNode = null;
+ private int fOffset = 0;
+ private int fLength = 0;
+
+ public FindNodeForOffsetAction(int offset, int length) {
+ fOffset = offset;
+ fLength = length;
+
+ shouldVisitNames = true;
+ shouldVisitDeclarations = true;
+ shouldVisitInitializers = true;
+ shouldVisitParameterDeclarations = true;
+ shouldVisitDeclarators = true;
+ shouldVisitDeclSpecifiers = true;
+ shouldVisitDesignators = true;
+ shouldVisitEnumerators = true;
+ shouldVisitExpressions = true;
+ shouldVisitStatements = true;
+ shouldVisitTypeIds = true;
+ shouldVisitEnumerators = true;
+ shouldVisitBaseSpecifiers = true;
+ shouldVisitNamespaces = true;
+ shouldVisitTemplateParameters= true;
+ shouldVisitTranslationUnit= true;
+ }
+
+ public int processNode(IASTNode node) {
+ if (fFoundNode != null)
+ return PROCESS_ABORT;
+
+ if (node instanceof ASTNode) {
+ final int offset = ((ASTNode) node).getOffset();
+ final int length = ((ASTNode) node).getLength();
+
+ if (offset == fOffset && length == fLength) {
+ fFoundNode = node;
+ return PROCESS_ABORT;
+ }
+
+ // skip the rest of this node if the selection is outside of its
+ // bounds
+ if (fOffset > offset + length)
+ return PROCESS_SKIP;
+ }
+ return PROCESS_CONTINUE;
+ }
+
+ @Override
+ public int visit(IASTDeclaration declaration) {
+ // use declarations to determine if the search has gone past the
+ // offset (i.e. don't know the order the visitor visits the nodes)
+ if (declaration instanceof ASTNode
+ && ((ASTNode) declaration).getOffset() > fOffset)
+ return PROCESS_ABORT;
+
+ return processNode(declaration);
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ int ret = processNode(declarator);
+
+ IASTPointerOperator[] ops = declarator.getPointerOperators();
+ for (int i = 0; i < ops.length; i++)
+ processNode(ops[i]);
+
+ if (declarator instanceof IASTArrayDeclarator) {
+ IASTArrayModifier[] mods = ((IASTArrayDeclarator) declarator)
+ .getArrayModifiers();
+ for (int i = 0; i < mods.length; i++)
+ processNode(mods[i]);
+ }
+ else if (declarator instanceof ICPPASTFunctionDeclarator) {
+ ICPPASTConstructorChainInitializer[] chainInit = ((ICPPASTFunctionDeclarator)declarator).getConstructorChain();
+ for(int i=0; i<chainInit.length; i++) {
+ processNode(chainInit[i]);
+ }
+
+ if( declarator instanceof ICPPASTFunctionTryBlockDeclarator ){
+ ICPPASTCatchHandler [] catchHandlers = ((ICPPASTFunctionTryBlockDeclarator)declarator).getCatchHandlers();
+ for( int i = 0; i < catchHandlers.length; i++ ){
+ processNode(catchHandlers[i]);
+ }
+ }
+ }
+ return ret;
+ }
+
+ @Override
+ public int visit(IASTDeclSpecifier declSpec) {
+ return processNode(declSpec);
+ }
+
+ @Override
+ public int visit(IASTEnumerator enumerator) {
+ return processNode(enumerator);
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ return processNode(expression);
+ }
+
+ @Override
+ public int visit(IASTInitializer initializer) {
+ return processNode(initializer);
+ }
+
+ @Override
+ public int visit(IASTName name) {
+ if (name.toString() != null)
+ return processNode(name);
+ return PROCESS_CONTINUE;
+ }
+
+ @Override
+ public int visit(IASTParameterDeclaration parameterDeclaration) {
+ return processNode(parameterDeclaration);
+ }
+
+ @Override
+ public int visit(IASTStatement statement) {
+ return processNode(statement);
+ }
+
+ @Override
+ public int visit(IASTTypeId typeId) {
+ return processNode(typeId);
+ }
+
+ @Override
+ public int visit(ICPPASTBaseSpecifier baseSpecifier) {
+ return processNode(baseSpecifier);
+ }
+
+ @Override
+ public int visit(ICPPASTNamespaceDefinition namespaceDefinition) {
+ return processNode(namespaceDefinition);
+ }
+
+ @Override
+ public int visit(ICPPASTTemplateParameter templateParameter) {
+ return processNode(templateParameter);
+ }
+
+ @Override
+ public int visit(IASTProblem problem) {
+ return processNode(problem);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator)
+ */
+ public int visit(ICASTDesignator designator) {
+ return processNode(designator);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.dom.ast.c.ICASTVisitor#leave(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator)
+ */
+ public int leave(ICASTDesignator designator) {
+ return PROCESS_CONTINUE;
+ }
+
+ @Override
+ public int visit(IASTTranslationUnit tu) {
+ return processNode(tu);
+ }
+
+ public IASTNode getNode() {
+ return fFoundNode;
+ }
+} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java
index f9a120f0726..5da9607a04d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java
@@ -14,29 +14,13 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IName;
-import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
-import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
-import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
-import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
-import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
-import org.eclipse.cdt.core.dom.ast.IASTExpression;
-import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.core.dom.ast.IASTNode;
-import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
-import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
-import org.eclipse.cdt.core.dom.ast.IASTStatement;
-import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
-import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
-import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
-import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
/**
@@ -88,216 +72,6 @@ public class CASTTranslationUnit extends ASTTranslationUnit {
return CVisitor.getReferences(this, binding);
}
- private class CFindNodeForOffsetAction extends CASTVisitor {
- {
- shouldVisitNames = true;
- shouldVisitDeclarations = true;
- shouldVisitInitializers = true;
- shouldVisitParameterDeclarations = true;
- shouldVisitDeclarators = true;
- shouldVisitDeclSpecifiers = true;
- shouldVisitDesignators = true;
- shouldVisitExpressions = true;
- shouldVisitStatements = true;
- shouldVisitTypeIds = true;
- shouldVisitEnumerators = true;
- }
-
- IASTNode foundNode = null;
-
- int offset = 0;
-
- int length = 0;
-
- /**
- *
- */
- public CFindNodeForOffsetAction(int offset, int length) {
- this.offset = offset;
- this.length = length;
- }
-
- public int processNode(IASTNode node) {
- if (foundNode != null)
- return PROCESS_ABORT;
-
- if (node instanceof ASTNode
- && ((ASTNode) node).getOffset() == offset
- && ((ASTNode) node).getLength() == length) {
- foundNode = node;
- return PROCESS_ABORT;
- }
-
- // skip the rest of this node if the selection is outside of its
- // bounds
- if (node instanceof ASTNode
- && offset > ((ASTNode) node).getOffset()
- + ((ASTNode) node).getLength())
- return PROCESS_SKIP;
-
- return PROCESS_CONTINUE;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
- */
- @Override
- public int visit(IASTDeclaration declaration) {
- // use declarations to determine if the search has gone past the
- // offset (i.e. don't know the order the visitor visits the nodes)
- if (declaration instanceof ASTNode
- && ((ASTNode) declaration).getOffset() > offset)
- return PROCESS_ABORT;
-
- return processNode(declaration);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
- */
- @Override
- public int visit(IASTDeclarator declarator) {
- int ret = processNode(declarator);
-
- IASTPointerOperator[] ops = declarator.getPointerOperators();
- for (int i = 0; i < ops.length; i++)
- processNode(ops[i]);
-
- if (declarator instanceof IASTArrayDeclarator) {
- IASTArrayModifier[] mods = ((IASTArrayDeclarator) declarator)
- .getArrayModifiers();
- for (int i = 0; i < mods.length; i++)
- processNode(mods[i]);
- }
-
- return ret;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator)
- */
- @Override
- public int visit(ICASTDesignator designator) {
- return processNode(designator);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
- */
- @Override
- public int visit(IASTDeclSpecifier declSpec) {
- return processNode(declSpec);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
- */
- @Override
- public int visit(IASTEnumerator enumerator) {
- return processNode(enumerator);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
- */
- @Override
- public int visit(IASTExpression expression) {
- return processNode(expression);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer)
- */
- @Override
- public int visit(IASTInitializer initializer) {
- return processNode(initializer);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
- */
- @Override
- public int visit(IASTName name) {
- if (name.toString() != null)
- return processNode(name);
- return PROCESS_CONTINUE;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration)
- */
- @Override
- public int visit(
- IASTParameterDeclaration parameterDeclaration) {
- return processNode(parameterDeclaration);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement)
- */
- @Override
- public int visit(IASTStatement statement) {
- return processNode(statement);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId)
- */
- @Override
- public int visit(IASTTypeId typeId) {
- return processNode(typeId);
- }
-
- public IASTNode getNode() {
- return foundNode;
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getNodeForLocation(org.eclipse.cdt.core.dom.ast.IASTNodeLocation)
- */
- public IASTNode selectNodeForLocation(String path, int realOffset, int realLength) {
- IASTNode result= null;
- if (fLocationResolver != null) {
- int start= fLocationResolver.getSequenceNumberForFileOffset(path, realOffset);
- if (start >= 0) {
- int length= realLength < 1 ? 0 :
- fLocationResolver.getSequenceNumberForFileOffset(path, realOffset+realLength-1) + 1 - start;
- result= fLocationResolver.findSurroundingPreprocessorNode(start, length);
- if (result == null) {
- CFindNodeForOffsetAction nodeFinder = new CFindNodeForOffsetAction(start, length);
- accept(nodeFinder);
- result = nodeFinder.getNode();
- }
- }
- }
- return result;
- }
-
public ParserLanguage getParserLanguage() {
return ParserLanguage.C;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
index d389f23603b..6b67e444f57 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
@@ -571,13 +571,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
if (LA(1).hashCode() == checkOffset)
failParseWithErrorHandling();
} catch (EndOfFileException e) {
- IASTDeclaration[] declarations = translationUnit.getDeclarations();
- // As expected
- if (declarations.length != 0) {
- ASTNode d = (ASTNode) declarations[declarations.length-1];
- ((ASTNode) translationUnit).setLength(d.getOffset() + d.getLength());
- } else
- ((ASTNode) translationUnit).setLength(0);
break;
} catch (BacktrackException b) {
try {
@@ -612,6 +605,13 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
}
}
}
+ IASTDeclaration[] declarations = translationUnit.getDeclarations();
+ if (declarations.length != 0) {
+ ASTNode d = (ASTNode) declarations[declarations.length-1];
+ ((ASTNode) translationUnit).setLength(d.getOffset() + d.getLength());
+ } else {
+ ((ASTNode) translationUnit).setLength(0);
+ }
}
/**
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java
index aab457d9ff7..562a6a574d7 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java
@@ -13,19 +13,9 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException;
-import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
-import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
-import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
-import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
-import org.eclipse.cdt.core.dom.ast.IASTExpression;
-import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
-import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
-import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
-import org.eclipse.cdt.core.dom.ast.IASTStatement;
-import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
@@ -33,13 +23,6 @@ import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
-import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
-import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
@@ -48,7 +31,6 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter;
@@ -148,167 +130,6 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
return CPPVisitor.getReferences(this, binding);
}
- private class CPPFindNodeForOffsetAction extends CPPASTVisitor {
- {
- shouldVisitNames = true;
- shouldVisitDeclarations = true;
- shouldVisitInitializers = true;
- shouldVisitParameterDeclarations = true;
- shouldVisitDeclarators = true;
- shouldVisitDeclSpecifiers = true;
- shouldVisitExpressions = true;
- shouldVisitStatements = true;
- shouldVisitTypeIds = true;
- shouldVisitEnumerators = true;
- shouldVisitBaseSpecifiers = true;
- shouldVisitNamespaces = true;
- }
-
- IASTNode foundNode = null;
- int offset = 0;
- int length = 0;
-
- /**
- *
- */
- public CPPFindNodeForOffsetAction(int offset, int length) {
- this.offset = offset;
- this.length = length;
- }
-
- public int processNode(IASTNode node) {
- if (foundNode != null)
- return PROCESS_ABORT;
-
- if (node instanceof ASTNode &&
- ((ASTNode)node).getOffset() == offset &&
- ((ASTNode)node).getLength() == length) {
- foundNode = node;
- return PROCESS_ABORT;
- }
-
- // skip the rest of this node if the selection is outside of its bounds
- if (node instanceof ASTNode &&
- offset > ((ASTNode)node).getOffset() + ((ASTNode)node).getLength())
- return PROCESS_SKIP;
-
- return PROCESS_CONTINUE;
- }
-
-
- @Override
- public int visit(IASTDeclaration declaration) {
- // use declarations to determine if the search has gone past the offset (i.e. don't know the order the visitor visits the nodes)
- if (declaration instanceof ASTNode && ((ASTNode)declaration).getOffset() > offset)
- return PROCESS_ABORT;
-
- return processNode(declaration);
- }
-
-
- @Override
- public int visit(IASTDeclarator declarator) {
- int ret = processNode(declarator);
-
- IASTPointerOperator[] ops = declarator.getPointerOperators();
- for(int i=0; i<ops.length; i++)
- processNode(ops[i]);
-
- if (declarator instanceof IASTArrayDeclarator) {
- IASTArrayModifier[] mods = ((IASTArrayDeclarator)declarator).getArrayModifiers();
- for(int i=0; i<mods.length; i++)
- processNode(mods[i]);
- }
-
- if (declarator instanceof ICPPASTFunctionDeclarator) {
- ICPPASTConstructorChainInitializer[] chainInit = ((ICPPASTFunctionDeclarator)declarator).getConstructorChain();
- for(int i=0; i<chainInit.length; i++) {
- processNode(chainInit[i]);
- }
-
- if( declarator instanceof ICPPASTFunctionTryBlockDeclarator ){
- ICPPASTCatchHandler [] catchHandlers = ((ICPPASTFunctionTryBlockDeclarator)declarator).getCatchHandlers();
- for( int i = 0; i < catchHandlers.length; i++ ){
- processNode(catchHandlers[i]);
- }
- }
- }
-
- return ret;
- }
-
-
- public int processDesignator(ICASTDesignator designator) {
- return processNode(designator);
- }
-
- @Override
- public int visit(IASTDeclSpecifier declSpec) {
- return processNode(declSpec);
- }
-
- @Override
- public int visit(IASTEnumerator enumerator) {
- return processNode(enumerator);
- }
-
- @Override
- public int visit(IASTExpression expression) {
- return processNode(expression);
- }
-
- @Override
- public int visit(IASTInitializer initializer) {
- return processNode(initializer);
- }
-
- @Override
- public int visit(IASTName name) {
- if ( name.toString() != null )
- return processNode(name);
- return PROCESS_CONTINUE;
- }
-
- @Override
- public int visit(
- IASTParameterDeclaration parameterDeclaration) {
- return processNode(parameterDeclaration);
- }
-
- @Override
- public int visit(IASTStatement statement) {
- return processNode(statement);
- }
-
- @Override
- public int visit(IASTTypeId typeId) {
- return processNode(typeId);
- }
-
- public IASTNode getNode() {
- return foundNode;
- }
- }
-
-
- public IASTNode selectNodeForLocation(String path, int realOffset, int realLength) {
- IASTNode result= null;
- if (fLocationResolver != null) {
- int start= fLocationResolver.getSequenceNumberForFileOffset(path, realOffset);
- if (start >= 0) {
- int length= realLength < 1 ? 0 :
- fLocationResolver.getSequenceNumberForFileOffset(path, realOffset+realLength-1) + 1 - start;
- result= fLocationResolver.findSurroundingPreprocessorNode(start, length);
- if (result == null) {
- CPPFindNodeForOffsetAction nodeFinder = new CPPFindNodeForOffsetAction(start, length);
- accept(nodeFinder);
- result = nodeFinder.getNode();
- }
- }
- }
- return result;
- }
-
public IBinding resolveBinding() {
if (fBinding == null)
fBinding = new CPPNamespace(this);
@@ -341,6 +162,7 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener#skippedFile(org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent)
*/
+ @Override
public void skippedFile(int offset, IncludeFileContent fileContent) {
super.skippedFile(offset, fileContent);
fScopeMapper.registerAdditionalDirectives(offset, fileContent.getUsingDirectives());
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
index f24c498e592..1b23a8128d4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
@@ -4320,12 +4320,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (LA(1).hashCode() == checkOffset)
failParseWithErrorHandling();
} catch (EndOfFileException e) {
- if (translationUnit.getDeclarations().length != 0) {
- ASTNode d = (ASTNode) translationUnit.getDeclarations()[translationUnit.getDeclarations().length - 1];
- ((ASTNode) translationUnit).setLength(d.getOffset() + d.getLength());
- } else
- ((ASTNode) translationUnit).setLength(0);
- break;
+ break;
} catch (BacktrackException b) {
try {
// Mark as failure and try to reach a recovery point
@@ -4350,6 +4345,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
}
}
+ IASTDeclaration[] declarations = translationUnit.getDeclarations();
+ if (declarations.length != 0) {
+ ASTNode d = (ASTNode) declarations[declarations.length-1];
+ ((ASTNode) translationUnit).setLength(d.getOffset() + d.getLength());
+ } else {
+ ((ASTNode) translationUnit).setLength(0);
+ }
}

Back to the top