mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Combine CFindNodeForOffsetAction and CPPFindNodeForOffsetAction.
This commit is contained in:
parent
2250f00e98
commit
a8e7f57545
7 changed files with 259 additions and 422 deletions
|
@ -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.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
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.IASTNodeLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||||
|
@ -308,4 +309,27 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
||||||
public final IIndexFileSet getIndexFileSet() {
|
public final IIndexFileSet getIndexFileSet() {
|
||||||
return fIndexFileSet;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.ILinkage;
|
||||||
import org.eclipse.cdt.core.dom.IName;
|
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.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.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
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.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
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;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,216 +72,6 @@ public class CASTTranslationUnit extends ASTTranslationUnit {
|
||||||
return CVisitor.getReferences(this, binding);
|
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() {
|
public ParserLanguage getParserLanguage() {
|
||||||
return ParserLanguage.C;
|
return ParserLanguage.C;
|
||||||
}
|
}
|
||||||
|
|
|
@ -571,13 +571,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
if (LA(1).hashCode() == checkOffset)
|
if (LA(1).hashCode() == checkOffset)
|
||||||
failParseWithErrorHandling();
|
failParseWithErrorHandling();
|
||||||
} catch (EndOfFileException e) {
|
} 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;
|
break;
|
||||||
} catch (BacktrackException b) {
|
} catch (BacktrackException b) {
|
||||||
try {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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.ILinkage;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
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.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.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
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.IBasicType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
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.IParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
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.ICPPASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
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.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
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.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.ASTTranslationUnit;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter;
|
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);
|
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() {
|
public IBinding resolveBinding() {
|
||||||
if (fBinding == null)
|
if (fBinding == null)
|
||||||
fBinding = new CPPNamespace(this);
|
fBinding = new CPPNamespace(this);
|
||||||
|
@ -341,6 +162,7 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener#skippedFile(org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent)
|
* @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) {
|
public void skippedFile(int offset, IncludeFileContent fileContent) {
|
||||||
super.skippedFile(offset, fileContent);
|
super.skippedFile(offset, fileContent);
|
||||||
fScopeMapper.registerAdditionalDirectives(offset, fileContent.getUsingDirectives());
|
fScopeMapper.registerAdditionalDirectives(offset, fileContent.getUsingDirectives());
|
||||||
|
|
|
@ -4320,12 +4320,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
if (LA(1).hashCode() == checkOffset)
|
if (LA(1).hashCode() == checkOffset)
|
||||||
failParseWithErrorHandling();
|
failParseWithErrorHandling();
|
||||||
} catch (EndOfFileException e) {
|
} catch (EndOfFileException e) {
|
||||||
if (translationUnit.getDeclarations().length != 0) {
|
break;
|
||||||
ASTNode d = (ASTNode) translationUnit.getDeclarations()[translationUnit.getDeclarations().length - 1];
|
|
||||||
((ASTNode) translationUnit).setLength(d.getOffset() + d.getLength());
|
|
||||||
} else
|
|
||||||
((ASTNode) translationUnit).setLength(0);
|
|
||||||
break;
|
|
||||||
} catch (BacktrackException b) {
|
} catch (BacktrackException b) {
|
||||||
try {
|
try {
|
||||||
// Mark as failure and try to reach a recovery point
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -328,12 +328,13 @@ public class BaseUITestCase extends BaseTestCase {
|
||||||
final String text= firstItem.getText();
|
final String text= firstItem.getText();
|
||||||
if (text.length() > 0 && !text.equals("...")) {
|
if (text.length() > 0 && !text.equals("...")) {
|
||||||
item= root.getItem(i1);
|
item= root.getItem(i1);
|
||||||
assertNotNull("Unexpected tree node " + item.getText(), label);
|
itemText= item.getText();
|
||||||
if (label.equals(item.getText())) {
|
assertNotNull("Unexpected tree node " + itemText, label);
|
||||||
|
if (label.equals(itemText)) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
if (i > 100) {
|
if (i > 100) {
|
||||||
assertEquals(label, item.getText());
|
assertEquals(label, itemText);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -349,7 +350,7 @@ public class BaseUITestCase extends BaseTestCase {
|
||||||
}
|
}
|
||||||
runEventQueue(10);
|
runEventQueue(10);
|
||||||
}
|
}
|
||||||
fail("Timeout expired waiting for tree node " + label + "{" + i0 + "," + i1 + "}");
|
assertEquals("Timeout expired waiting for tree node {" + i0 + "," + i1 + "}", label, itemText);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue