1
0
Fork 0
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:
John Camelon 2005-01-12 02:16:26 +00:00
parent 11b1607681
commit cdfc350d10
14 changed files with 7573 additions and 8862 deletions

View file

@ -10,6 +10,7 @@
**********************************************************************/
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.parser.ParserLanguage;
import org.eclipse.cdt.internal.core.parser.ParserException;
@ -24,6 +25,8 @@ public class DOMScannerTests extends AST2BaseTest {
public void testSimpleLocation() throws ParserException {
IASTTranslationUnit tu = parse( "int x;", ParserLanguage.C ); //$NON-NLS-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

View file

@ -28,14 +28,25 @@ public abstract class ASTNode implements IASTNode {
return length;
}
public void setOffset(int offset) {
public void setOffset( int offset )
{
this.offset = offset;
}
public void setLength(int length) {
public void setLength( int 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)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getNodeLocations()
*/

View file

@ -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.gnu.IGNUASTCompoundStatementExpression;
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

View file

@ -95,7 +95,7 @@ abstract class BaseScanner implements IScanner {
// The context stack
protected static final int bufferInitialSize = 8;
int bufferStackPos = -1;
protected int bufferStackPos = -1;
protected char[][] bufferStack = new char[bufferInitialSize][];
protected Object[] bufferData = new Object[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;
if( bufferData[bufferStackPos] instanceof InclusionData )
popInclusion(((InclusionData)bufferData[bufferStackPos]).inclusion);
Object result = bufferData[bufferStackPos];
bufferData[bufferStackPos] = null;
--bufferStackPos;
if( preIncludeFiles.hasNext() )
pushForcedInclusion();
return result;
}
/**
@ -2115,7 +2117,7 @@ abstract class BaseScanner implements IScanner {
/**
* @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

View file

@ -32,6 +32,7 @@ import org.eclipse.cdt.internal.core.parser.token.SimpleToken;
public class DOMScanner extends BaseScanner {
private final ICodeReaderFactory codeReaderFactory;
private int contextStart = 0;
private static class DOMInclusion
{
@ -128,9 +129,11 @@ public class DOMScanner extends BaseScanner {
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContext()
*/
protected void popContext() {
protected Object popContext() {
//TODO calibrate offsets
super.popContext();
Object result = super.popContext();
return result;
}
/**
* @return
@ -200,9 +203,19 @@ public class DOMScanner extends BaseScanner {
/* (non-Javadoc)
* @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 );
int o = resolveOffset( offset );
((ScannerASTProblem)problem).setOffsetAndLength( o, resolveOffset( getCurrentOffset() + 1 ) - o );
locationMap.encounterProblem(problem);
}
/**
* @param offset
* @return
*/
private int resolveOffset(int offset) {
return contextStart + offset;
}
}

View file

@ -17,8 +17,6 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem;
*/
public interface IScannerPreprocessorLog {
public void startTranslationUnit();
public void endTranslationUnit(int finalOffset);
public void startInclusion(char[] includePath, int offset);
@ -54,7 +52,7 @@ public interface IScannerPreprocessorLog {
public void encounterPoundElse(int startOffset, int endOffset);
public void encounterPoundElif(int startOffset, int endOffset);
public void encounterPoundEndIf(int startOffset, int endOffset);
public void encounterProblem( IASTProblem problem );

View file

@ -28,6 +28,12 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
private List problems = Collections.EMPTY_LIST;
private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0];
/**
*
*/
public LocationMap() {
startTranslationUnit();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getMacroDefinitions()
@ -72,9 +78,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startTranslationUnit()
*/
public void startTranslationUnit() {
// TODO Auto-generated method stub
protected void startTranslationUnit() {
}
/* (non-Javadoc)

View file

@ -242,10 +242,10 @@ public class Scanner2 extends BaseScanner {
* @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) {
if (parserMode == ParserMode.COMPLETION_PARSE)
return;
IProblem p = spf.createProblem(id, startOffset,
IProblem p = spf.createProblem(id, offset,
bufferPos[bufferStackPos],
getLineNumber(bufferPos[bufferStackPos]), getCurrentFilename(),
arg != null ? arg : EMPTY_CHAR_ARRAY, false, true);

View file

@ -106,7 +106,7 @@ public class BasicTokenDuple implements ITokenDuple {
if( token.getType() == IToken.tLT )
token = TokenFactory.consumeTemplateIdArguments( token, last );
if( token.getType() == IToken.tCOLONCOLON ){
ITokenDuple d = TokenFactory.createTokenDuple( startOfSegment, prev );
ITokenDuple d = TokenFactory.createTokenDuple( startOfSegment, ( prev == null ) ? startOfSegment : prev );
r.add( d );
startOfSegment = token.getNext();
continue;

View file

@ -155,7 +155,7 @@ public class TemplateTokenDuple extends BasicTokenDuple {
newArgs = new ArrayList( 1 );
newArgs.add( argLists[count]);
}
ITokenDuple d = TokenFactory.createTokenDuple( startOfSegment, prev, newArgs );
ITokenDuple d = TokenFactory.createTokenDuple( startOfSegment, prev != null ? prev : startOfSegment, newArgs );
r.add( d );
startOfSegment = token.getNext();
++count;