mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Added lengths to ASTNodes.
This commit is contained in:
parent
11b1607681
commit
cdfc350d10
14 changed files with 7573 additions and 8862 deletions
|
@ -10,6 +10,7 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||||
|
@ -24,6 +25,8 @@ public class DOMScannerTests extends AST2BaseTest {
|
||||||
public void testSimpleLocation() throws ParserException {
|
public void testSimpleLocation() throws ParserException {
|
||||||
IASTTranslationUnit tu = parse( "int x;", ParserLanguage.C ); //$NON-NLS-1$
|
IASTTranslationUnit tu = parse( "int x;", ParserLanguage.C ); //$NON-NLS-1$
|
||||||
assertEquals( tu.getDeclarations()[0].getNodeLocations().length, 1 );
|
assertEquals( tu.getDeclarations()[0].getNodeLocations().length, 1 );
|
||||||
|
assertTrue( tu.getDeclarations()[0].getNodeLocations()[0] instanceof IASTFileLocation );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -28,14 +28,25 @@ public abstract class ASTNode implements IASTNode {
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOffset(int offset) {
|
public void setOffset( int offset )
|
||||||
|
{
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLength(int length) {
|
public void setLength( int length )
|
||||||
|
{
|
||||||
this.length = length;
|
this.length = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOffsetAndLength(int offset, int length) {
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOffsetAndLength( ASTNode node )
|
||||||
|
{
|
||||||
|
setOffsetAndLength( node.getOffset(), node.getLength() );
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getNodeLocations()
|
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getNodeLocations()
|
||||||
*/
|
*/
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -112,8 +112,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CollectProblemsAction;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -95,7 +95,7 @@ abstract class BaseScanner implements IScanner {
|
||||||
|
|
||||||
// The context stack
|
// The context stack
|
||||||
protected static final int bufferInitialSize = 8;
|
protected static final int bufferInitialSize = 8;
|
||||||
int bufferStackPos = -1;
|
protected int bufferStackPos = -1;
|
||||||
protected char[][] bufferStack = new char[bufferInitialSize][];
|
protected char[][] bufferStack = new char[bufferInitialSize][];
|
||||||
protected Object[] bufferData = new Object[bufferInitialSize];
|
protected Object[] bufferData = new Object[bufferInitialSize];
|
||||||
protected int[] bufferPos = new int[bufferInitialSize];
|
protected int[] bufferPos = new int[bufferInitialSize];
|
||||||
|
@ -1269,16 +1269,18 @@ abstract class BaseScanner implements IScanner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void popContext() {
|
protected Object popContext() {
|
||||||
bufferStack[bufferStackPos] = null;
|
bufferStack[bufferStackPos] = null;
|
||||||
if( bufferData[bufferStackPos] instanceof InclusionData )
|
if( bufferData[bufferStackPos] instanceof InclusionData )
|
||||||
popInclusion(((InclusionData)bufferData[bufferStackPos]).inclusion);
|
popInclusion(((InclusionData)bufferData[bufferStackPos]).inclusion);
|
||||||
|
|
||||||
|
Object result = bufferData[bufferStackPos];
|
||||||
bufferData[bufferStackPos] = null;
|
bufferData[bufferStackPos] = null;
|
||||||
--bufferStackPos;
|
--bufferStackPos;
|
||||||
|
|
||||||
if( preIncludeFiles.hasNext() )
|
if( preIncludeFiles.hasNext() )
|
||||||
pushForcedInclusion();
|
pushForcedInclusion();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2115,7 +2117,7 @@ abstract class BaseScanner implements IScanner {
|
||||||
/**
|
/**
|
||||||
* @param scanner_bad_character
|
* @param scanner_bad_character
|
||||||
*/
|
*/
|
||||||
protected abstract void handleProblem(int id, int startOffset, char [] arg );
|
protected abstract void handleProblem(int id, int offset, char [] arg );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param i
|
* @param i
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.cdt.internal.core.parser.token.SimpleToken;
|
||||||
public class DOMScanner extends BaseScanner {
|
public class DOMScanner extends BaseScanner {
|
||||||
|
|
||||||
private final ICodeReaderFactory codeReaderFactory;
|
private final ICodeReaderFactory codeReaderFactory;
|
||||||
|
private int contextStart = 0;
|
||||||
|
|
||||||
private static class DOMInclusion
|
private static class DOMInclusion
|
||||||
{
|
{
|
||||||
|
@ -128,9 +129,11 @@ public class DOMScanner extends BaseScanner {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContext()
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContext()
|
||||||
*/
|
*/
|
||||||
protected void popContext() {
|
protected Object popContext() {
|
||||||
//TODO calibrate offsets
|
//TODO calibrate offsets
|
||||||
super.popContext();
|
Object result = super.popContext();
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
|
@ -200,9 +203,19 @@ public class DOMScanner extends BaseScanner {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int, int, char[])
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int, int, char[])
|
||||||
*/
|
*/
|
||||||
protected void handleProblem(int id, int startOffset, char[] arg) {
|
protected void handleProblem(int id, int offset, char[] arg) {
|
||||||
IASTProblem problem = new ScannerASTProblem(id, arg, true, false );
|
IASTProblem problem = new ScannerASTProblem(id, arg, true, false );
|
||||||
|
int o = resolveOffset( offset );
|
||||||
|
((ScannerASTProblem)problem).setOffsetAndLength( o, resolveOffset( getCurrentOffset() + 1 ) - o );
|
||||||
locationMap.encounterProblem(problem);
|
locationMap.encounterProblem(problem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param offset
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int resolveOffset(int offset) {
|
||||||
|
return contextStart + offset;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,6 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||||
*/
|
*/
|
||||||
public interface IScannerPreprocessorLog {
|
public interface IScannerPreprocessorLog {
|
||||||
|
|
||||||
public void startTranslationUnit();
|
|
||||||
|
|
||||||
public void endTranslationUnit(int finalOffset);
|
public void endTranslationUnit(int finalOffset);
|
||||||
|
|
||||||
public void startInclusion(char[] includePath, int offset);
|
public void startInclusion(char[] includePath, int offset);
|
||||||
|
@ -54,7 +52,7 @@ public interface IScannerPreprocessorLog {
|
||||||
public void encounterPoundElse(int startOffset, int endOffset);
|
public void encounterPoundElse(int startOffset, int endOffset);
|
||||||
|
|
||||||
public void encounterPoundElif(int startOffset, int endOffset);
|
public void encounterPoundElif(int startOffset, int endOffset);
|
||||||
|
|
||||||
public void encounterPoundEndIf(int startOffset, int endOffset);
|
public void encounterPoundEndIf(int startOffset, int endOffset);
|
||||||
|
|
||||||
public void encounterProblem( IASTProblem problem );
|
public void encounterProblem( IASTProblem problem );
|
||||||
|
|
|
@ -28,6 +28,12 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
|
|
||||||
private List problems = Collections.EMPTY_LIST;
|
private List problems = Collections.EMPTY_LIST;
|
||||||
private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0];
|
private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0];
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public LocationMap() {
|
||||||
|
startTranslationUnit();
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getMacroDefinitions()
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getMacroDefinitions()
|
||||||
|
@ -72,9 +78,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startTranslationUnit()
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startTranslationUnit()
|
||||||
*/
|
*/
|
||||||
public void startTranslationUnit() {
|
protected void startTranslationUnit() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -242,10 +242,10 @@ public class Scanner2 extends BaseScanner {
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int,
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int,
|
||||||
* int, char[])
|
* int, char[])
|
||||||
*/
|
*/
|
||||||
protected void handleProblem(int id, int startOffset, char[] arg) {
|
protected void handleProblem(int id, int offset, char[] arg) {
|
||||||
if (parserMode == ParserMode.COMPLETION_PARSE)
|
if (parserMode == ParserMode.COMPLETION_PARSE)
|
||||||
return;
|
return;
|
||||||
IProblem p = spf.createProblem(id, startOffset,
|
IProblem p = spf.createProblem(id, offset,
|
||||||
bufferPos[bufferStackPos],
|
bufferPos[bufferStackPos],
|
||||||
getLineNumber(bufferPos[bufferStackPos]), getCurrentFilename(),
|
getLineNumber(bufferPos[bufferStackPos]), getCurrentFilename(),
|
||||||
arg != null ? arg : EMPTY_CHAR_ARRAY, false, true);
|
arg != null ? arg : EMPTY_CHAR_ARRAY, false, true);
|
||||||
|
|
|
@ -106,7 +106,7 @@ public class BasicTokenDuple implements ITokenDuple {
|
||||||
if( token.getType() == IToken.tLT )
|
if( token.getType() == IToken.tLT )
|
||||||
token = TokenFactory.consumeTemplateIdArguments( token, last );
|
token = TokenFactory.consumeTemplateIdArguments( token, last );
|
||||||
if( token.getType() == IToken.tCOLONCOLON ){
|
if( token.getType() == IToken.tCOLONCOLON ){
|
||||||
ITokenDuple d = TokenFactory.createTokenDuple( startOfSegment, prev );
|
ITokenDuple d = TokenFactory.createTokenDuple( startOfSegment, ( prev == null ) ? startOfSegment : prev );
|
||||||
r.add( d );
|
r.add( d );
|
||||||
startOfSegment = token.getNext();
|
startOfSegment = token.getNext();
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class TemplateTokenDuple extends BasicTokenDuple {
|
||||||
newArgs = new ArrayList( 1 );
|
newArgs = new ArrayList( 1 );
|
||||||
newArgs.add( argLists[count]);
|
newArgs.add( argLists[count]);
|
||||||
}
|
}
|
||||||
ITokenDuple d = TokenFactory.createTokenDuple( startOfSegment, prev, newArgs );
|
ITokenDuple d = TokenFactory.createTokenDuple( startOfSegment, prev != null ? prev : startOfSegment, newArgs );
|
||||||
r.add( d );
|
r.add( d );
|
||||||
startOfSegment = token.getNext();
|
startOfSegment = token.getNext();
|
||||||
++count;
|
++count;
|
||||||
|
|
Loading…
Add table
Reference in a new issue