mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Slow road for IASTNodeLocation.
This commit is contained in:
parent
8d0a12de55
commit
9e365df5f5
6 changed files with 4840 additions and 4555 deletions
|
@ -11,23 +11,27 @@
|
|||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
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 );
|
||||
|
||||
IASTNodeLocation[] nodeLocations = tu.getDeclarations()[0]
|
||||
.getNodeLocations();
|
||||
assertNotNull(nodeLocations);
|
||||
assertEquals(nodeLocations.length, 1);
|
||||
assertTrue(nodeLocations[0] instanceof IASTFileLocation);
|
||||
IASTFileLocation fileLocation = ((IASTFileLocation) nodeLocations[0]);
|
||||
assertEquals(fileLocation.getFileName(), "<text>"); //$NON-NLS-1$
|
||||
assertEquals(fileLocation.getNodeOffset(), 0);
|
||||
assertEquals(fileLocation.getNodeLength(), 6);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -26,7 +26,6 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
|||
*/
|
||||
public class CodeReader {
|
||||
public static final String SYSTEM_DEFAULT_ENCODING = System.getProperty( "file.encoding" ); //$NON-NLS-1$
|
||||
//private static final String UTF_8 = "UTF-8"; //$NON-NLS-1$
|
||||
private static final String NF = "<text>"; //$NON-NLS-1$
|
||||
private static final char [] NOFILE = NF.toCharArray(); //$NON-NLS-1$
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.core.parser.scanner2;
|
|||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.IMacro;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
|
@ -218,4 +219,22 @@ public class DOMScanner extends BaseScanner {
|
|||
return contextStart + offset;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#postConstructorSetup(org.eclipse.cdt.core.parser.CodeReader, org.eclipse.cdt.core.parser.IScannerInfo)
|
||||
*/
|
||||
protected void postConstructorSetup(CodeReader reader, IScannerInfo info) {
|
||||
super.postConstructorSetup(reader, info);
|
||||
locationMap.startTranslationUnit( getMainFilename() );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#throwEOF()
|
||||
*/
|
||||
protected void throwEOF() throws EndOfFileException {
|
||||
locationMap.endTranslationUnit( preprocessedOffset );
|
||||
super.throwEOF();
|
||||
}
|
||||
|
||||
protected int preprocessedOffset = 0;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,8 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
|||
*/
|
||||
public interface IScannerPreprocessorLog {
|
||||
|
||||
public void endTranslationUnit(int finalOffset);
|
||||
public void startTranslationUnit( char [] filename );
|
||||
public void endTranslationUnit(int offset);
|
||||
|
||||
public void startInclusion(char[] includePath, int offset);
|
||||
|
||||
|
|
|
@ -26,16 +26,22 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
|||
*/
|
||||
public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||
|
||||
private static final char [] EMPTY_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$
|
||||
private List problems = Collections.EMPTY_LIST;
|
||||
private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0];
|
||||
private static final IASTNodeLocation [] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0];
|
||||
private char[] tu_filename = EMPTY_CHAR_ARRAY ;
|
||||
private int finalOffset = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public LocationMap() {
|
||||
startTranslationUnit();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getMacroDefinitions()
|
||||
*/
|
||||
public IASTMacroDefinition[] getMacroDefinitions(IASTNode parent) {
|
||||
|
@ -43,31 +49,42 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getIncludeDirectives()
|
||||
*/
|
||||
public IASTPreprocessorIncludeStatement[] getIncludeDirectives(IASTNode newParam) {
|
||||
public IASTPreprocessorIncludeStatement[] getIncludeDirectives(
|
||||
IASTNode newParam) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getAllPreprocessorStatements()
|
||||
*/
|
||||
public IASTPreprocessorStatement[] getAllPreprocessorStatements(IASTNode newParam) {
|
||||
public IASTPreprocessorStatement[] getAllPreprocessorStatements(
|
||||
IASTNode newParam) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getLocations(int, int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getLocations(int,
|
||||
* int)
|
||||
*/
|
||||
public IASTNodeLocation[] getLocations(int offset, int length) {
|
||||
// TODO Auto-generated method stub
|
||||
if( tu_filename == EMPTY_CHAR_ARRAY ) return EMPTY_LOCATION_ARRAY;
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getLocation(int)
|
||||
*/
|
||||
public IASTNodeLocation getLocation(int offset) {
|
||||
|
@ -75,38 +92,51 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startTranslationUnit()
|
||||
*/
|
||||
protected void startTranslationUnit() {
|
||||
public void startTranslationUnit(char[] filename) {
|
||||
this.tu_filename = filename;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#endTranslationUnit(int)
|
||||
*/
|
||||
public void endTranslationUnit(int finalOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void endTranslationUnit(int offset) {
|
||||
this.finalOffset = offset;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startInclusion(char[], int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startInclusion(char[],
|
||||
* int)
|
||||
*/
|
||||
public void startInclusion(char[] includePath, int offset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#endInclusion(char[], int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#endInclusion(char[],
|
||||
* int)
|
||||
*/
|
||||
public void endInclusion(char[] includePath, int offset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#enterObjectStyleMacroExpansion(char[], char[], int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#enterObjectStyleMacroExpansion(char[],
|
||||
* char[], int)
|
||||
*/
|
||||
public void enterObjectStyleMacroExpansion(char[] name, char[] expansion,
|
||||
int offset) {
|
||||
|
@ -114,16 +144,22 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#exitObjectStyleMacroExpansion(char[], int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#exitObjectStyleMacroExpansion(char[],
|
||||
* int)
|
||||
*/
|
||||
public void exitObjectStyleMacroExpansion(char[] name, int offset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#enterFunctionStyleExpansion(char[], char[][], char[], int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#enterFunctionStyleExpansion(char[],
|
||||
* char[][], char[], int)
|
||||
*/
|
||||
public void enterFunctionStyleExpansion(char[] name, char[][] parameters,
|
||||
char[] expansion, int offset) {
|
||||
|
@ -131,16 +167,22 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#exitFunctionStyleExpansion(char[], int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#exitFunctionStyleExpansion(char[],
|
||||
* int)
|
||||
*/
|
||||
public void exitFunctionStyleExpansion(char[] name, int offset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#defineObjectStyleMacro(org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro, int, int, int, int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#defineObjectStyleMacro(org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro,
|
||||
* int, int, int, int)
|
||||
*/
|
||||
public void defineObjectStyleMacro(ObjectStyleMacro m, int startOffset,
|
||||
int nameOffset, int nameEndOffset, int endOffset) {
|
||||
|
@ -148,8 +190,11 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#defineFunctionStyleMacro(org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro, int, int, int, int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#defineFunctionStyleMacro(org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro,
|
||||
* int, int, int, int)
|
||||
*/
|
||||
public void defineFunctionStyleMacro(FunctionStyleMacro m, int startOffset,
|
||||
int nameOffset, int nameEndOffset, int endOffset) {
|
||||
|
@ -157,71 +202,97 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIf(int, int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIf(int,
|
||||
* int)
|
||||
*/
|
||||
public void encounterPoundIf(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundPragma(int, int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundPragma(int,
|
||||
* int)
|
||||
*/
|
||||
public void encounterPoundPragma(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundError(int, int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundError(int,
|
||||
* int)
|
||||
*/
|
||||
public void encounterPoundError(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIfdef(int, int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIfdef(int,
|
||||
* int)
|
||||
*/
|
||||
public void encounterPoundIfdef(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundUndef(int, int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundUndef(int,
|
||||
* int)
|
||||
*/
|
||||
public void encounterPoundUndef(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundElse(int, int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundElse(int,
|
||||
* int)
|
||||
*/
|
||||
public void encounterPoundElse(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundElif(int, int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundElif(int,
|
||||
* int)
|
||||
*/
|
||||
public void encounterPoundElif(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundEndIf(int, int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundEndIf(int,
|
||||
* int)
|
||||
*/
|
||||
public void encounterPoundEndIf(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getTranslationUnitPath()
|
||||
*/
|
||||
public String getTranslationUnitPath() {
|
||||
|
@ -229,7 +300,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getInclusionsPaths()
|
||||
*/
|
||||
public String[] getInclusionsPaths() {
|
||||
|
@ -237,22 +310,29 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#cleanup()
|
||||
*/
|
||||
public void cleanup() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getScannerProblems()
|
||||
*/
|
||||
public IASTProblem[] getScannerProblems() {
|
||||
if( problems == Collections.EMPTY_LIST ) return EMPTY_PROBLEMS_ARRAY;
|
||||
if (problems == Collections.EMPTY_LIST)
|
||||
return EMPTY_PROBLEMS_ARRAY;
|
||||
return (IASTProblem[]) problems.toArray(new IASTProblem[problems.size()]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterIProblem(org.eclipse.cdt.core.parser.IProblem)
|
||||
*/
|
||||
public void encounterProblem(IASTProblem problem) {
|
||||
|
|
Loading…
Add table
Reference in a new issue