1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 12:55:40 +02:00

Continued DOMLocation fixes. (ad infinitum)

This commit is contained in:
John Camelon 2005-02-02 04:30:35 +00:00
parent c2d34df02e
commit 33390e2e03
2 changed files with 1374 additions and 1245 deletions

View file

@ -125,8 +125,8 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
assertEquals(locations.length, 1);
IASTFileLocation nodeLocation = (IASTFileLocation) locations[0];
assertTrue(nodeLocation.getFileName().endsWith(pathEndsWith));
assertEquals(nodeLocation.getNodeOffset(), offset);
assertEquals(nodeLocation.getNodeLength(), length);
assertEquals(offset, nodeLocation.getNodeOffset());
assertEquals(length, nodeLocation.getNodeLength());
}
public void testSimpleInclusion() throws Exception {
@ -191,7 +191,7 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
}
public void testMacrosInIncludeFile() throws Exception {
String c_file_code = "#define X 4\n\n#include \"blarg.h\"\n\n"; //$NON-NLS-1$
String c_file_code = "#define X 4\n\n#include \"blarg.h\"\n\n#define POST_INCLUDE\n\n"; //$NON-NLS-1$
String h_file_code = "#ifndef _BLARG_H_\r\n#define _BLARG_H_\r\n// macro\r\n#define PRINT(s,m) printf(s,m)\r\n#endif //_BLARG_H_\r\n"; //$NON-NLS-1$
importFile( "blarg.h", h_file_code ); //$NON-NLS-1$
IFile c_file = importFile( "blarg.c", c_file_code ); //$NON-NLS-1$
@ -201,13 +201,44 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
assertEquals( tu.getDeclarations().length, 0 );
IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions();
assertNotNull( macroDefinitions );
assertEquals( macroDefinitions.length, 3 );
assertEquals( macroDefinitions.length, 4 );
assertSoleFileLocation( macroDefinitions[0], "blarg.c", c_file_code.indexOf( "#define"), c_file_code.indexOf( "4" ) + 1- c_file_code.indexOf( "#define" ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
assertSoleFileLocation( macroDefinitions[0].getName(), "blarg.c", c_file_code.indexOf( "X"), 1 ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
assertSoleFileLocation( macroDefinitions[1], "blarg.h", h_file_code.indexOf( "#define _BLARG_H_"), "#define _BLARG_H_\r".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertSoleFileLocation( macroDefinitions[1].getName(), "blarg.h", h_file_code.indexOf( "e _BLARG_H_") + 2, "_BLARG_H_".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertSoleFileLocation( macroDefinitions[2], "blarg.h", h_file_code.indexOf( "#define PRINT(s,m) printf(s,m)\r"), "#define PRINT(s,m) printf(s,m)".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
assertSoleFileLocation( macroDefinitions[2].getName(), "blarg.h", h_file_code.indexOf( "PRINT"), "PRINT".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
assertSoleFileLocation( macroDefinitions[3], "blarg.c", c_file_code.indexOf( "#define POST_INCLUDE"), "#define POST_INCLUDE".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertSoleFileLocation( macroDefinitions[3].getName(), "blarg.c", c_file_code.indexOf( "POST_INCLUDE"), "POST_INCLUDE".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
}
// public void testMacrosInIncludeFile2() throws Exception {
// String c_file_code = "#define X 4\n\n#include \"blarg.h\"\n\n#define POST_INCLUDE\n#include \"second.h\"\n#define POST_SECOND\n"; //$NON-NLS-1$
// String h_file_code = "#ifndef _BLARG_H_\r\n#define _BLARG_H_\r\n// macro\r\n#define PRINT(s,m) printf(s,m)\r\n#endif //_BLARG_H_\r\n"; //$NON-NLS-1$
// String h_file2_code = "#ifndef _SECOND_H_ \n#define _SECOND_H_\n#endif\n"; //$NON-NLS-1$
// importFile( "blarg.h", h_file_code ); //$NON-NLS-1$
// importFile( "second.h", h_file2_code ); //$NON-NLS-1$
// IFile c_file = importFile( "blarg.c", c_file_code ); //$NON-NLS-1$
// for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
// : null) {
// IASTTranslationUnit tu = parse(c_file, p); //$NON-NLS-1$
// assertEquals( tu.getDeclarations().length, 0 );
// IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions();
// assertNotNull( macroDefinitions );
// assertEquals( macroDefinitions.length, 6 );
// assertSoleFileLocation( macroDefinitions[0], "blarg.c", c_file_code.indexOf( "#define"), c_file_code.indexOf( "4" ) + 1- c_file_code.indexOf( "#define" ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
// assertSoleFileLocation( macroDefinitions[0].getName(), "blarg.c", c_file_code.indexOf( "X"), 1 ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
// assertSoleFileLocation( macroDefinitions[1], "blarg.h", h_file_code.indexOf( "#define _BLARG_H_"), "#define _BLARG_H_\r".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// assertSoleFileLocation( macroDefinitions[1].getName(), "blarg.h", h_file_code.indexOf( "e _BLARG_H_") + 2, "_BLARG_H_".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// assertSoleFileLocation( macroDefinitions[2], "blarg.h", h_file_code.indexOf( "#define PRINT(s,m) printf(s,m)\r"), "#define PRINT(s,m) printf(s,m)".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
// assertSoleFileLocation( macroDefinitions[2].getName(), "blarg.h", h_file_code.indexOf( "PRINT"), "PRINT".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
// assertSoleFileLocation( macroDefinitions[3], "blarg.c", c_file_code.indexOf( "#define POST_INCLUDE"), "#define POST_INCLUDE".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// assertSoleFileLocation( macroDefinitions[3].getName(), "blarg.c", c_file_code.indexOf( "POST_INCLUDE"), "POST_INCLUDE".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// assertSoleFileLocation( macroDefinitions[4], "second.h", h_file2_code.indexOf( "#define _SECOND_H_"), "#define _SECOND_H_".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// assertSoleFileLocation( macroDefinitions[5], "blarg.c", c_file_code.indexOf( "#define POST_SECOND"), "#define POST_SECOND".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
// }
// }
public static Test suite() {
TestSuite suite = new TestSuite(DOMLocationInclusionTests.class);

View file

@ -41,7 +41,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @author jcamelon
*/
protected static class _Endif extends _Context implements
_IPreprocessorDirective{
_IPreprocessorDirective {
/**
* @param parent
@ -54,6 +54,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
}
/**
* @author jcamelon
*/
@ -61,17 +62,20 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
_IPreprocessorDirective {
public final boolean taken;
/**
* @param parent
* @param startOffset
* @param endOffset
*/
public _Elif(_CompositeContext parent, int startOffset, int endOffset, boolean taken ) {
public _Elif(_CompositeContext parent, int startOffset, int endOffset,
boolean taken) {
super(parent, startOffset, endOffset);
this.taken = taken;
}
}
/**
* @author jcamelon
*/
@ -79,17 +83,20 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
_IPreprocessorDirective {
public final boolean taken;
/**
* @param parent
* @param startOffset
* @param endOffset
*/
public _Ifdef(_CompositeContext parent, int startOffset, int endOffset, boolean taken) {
public _Ifdef(_CompositeContext parent, int startOffset, int endOffset,
boolean taken) {
super(parent, startOffset, endOffset);
this.taken = taken;
}
}
/**
* @author jcamelon
*/
@ -103,12 +110,14 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @param startOffset
* @param endOffset
*/
public _Ifndef(_CompositeContext parent, int startOffset, int endOffset, boolean taken ) {
public _Ifndef(_CompositeContext parent, int startOffset,
int endOffset, boolean taken) {
super(parent, startOffset, endOffset);
this.taken = taken;
}
}
/**
* @author jcamelon
*/
@ -126,6 +135,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
}
/**
* @author jcamelon
*/
@ -142,6 +152,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
}
/**
* @author jcamelon
*/
@ -154,12 +165,14 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @param startOffset
* @param endOffset
*/
public _If(_CompositeContext parent, int startOffset, int endOffset, boolean taken) {
public _If(_CompositeContext parent, int startOffset, int endOffset,
boolean taken) {
super(parent, startOffset, endOffset);
this.taken = taken;
}
}
/**
* @author jcamelon
*/
@ -167,22 +180,25 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
_IPreprocessorDirective {
public final boolean taken;
/**
* @param parent
* @param startOffset
* @param endOffset
*/
public _Else(_CompositeContext parent, int startOffset, int endOffset, boolean taken) {
public _Else(_CompositeContext parent, int startOffset, int endOffset,
boolean taken) {
super(parent, startOffset, endOffset);
this.taken = taken;
}
}
/**
* @author jcamelon
*/
protected static class ASTInclusionStatement extends ScannerASTNode implements
IASTPreprocessorIncludeStatement {
protected static class ASTInclusionStatement extends ScannerASTNode
implements IASTPreprocessorIncludeStatement {
private final char[] path;
@ -211,6 +227,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorFunctionStyleMacroDefinition {
private IASTName name;
private String expansion;
/*
@ -260,7 +277,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
private int currentIndex = 0;
private IASTFunctionStyleMacroParameter[] parameters = null;
private static final int DEFAULT_PARMS_LIST_SIZE = 2;
/*
@ -301,12 +320,11 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
public static interface _IPreprocessorDirective
{
public static interface _IPreprocessorDirective {
}
protected static class _Undef extends _Context implements _IPreprocessorDirective
{
protected static class _Undef extends _Context implements
_IPreprocessorDirective {
/**
* @param parent
* @param startOffset
@ -318,9 +336,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
private static class ScannerASTNode extends ASTNode {
private IASTNode parent;
private ASTNodeProperty property;
public IASTNode getParent() {
@ -418,6 +436,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorObjectStyleMacroDefinition {
private IASTName name;
private String expansion;
/*
@ -461,6 +480,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
public static class Location implements IASTNodeLocation {
private final int nodeOffset;
private final int nodeLength;
/**
@ -556,9 +576,12 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
public final int context_directive_start;
public final int context_directive_end;
public int context_ends;
private final _CompositeContext parent;
final _CompositeContext parent;
public _CompositeContext getParent() {
return parent;
@ -595,26 +618,33 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
protected static class _Inclusion extends _CompositeContext implements _IPreprocessorDirective {
protected static class _CompositeFileContext extends _CompositeContext {
public final CodeReader reader;
public _Inclusion(_CompositeContext parent, CodeReader reader,
int startOffset, int endOffset) {
public _CompositeFileContext(_CompositeContext parent, int startOffset,
int endOffset, CodeReader reader) {
super(parent, startOffset, endOffset);
this.reader = reader;
}
}
protected static class _TranslationUnit extends _CompositeContext {
public final CodeReader reader;
protected static class _Inclusion extends _CompositeFileContext implements
_IPreprocessorDirective {
public _Inclusion(_CompositeContext parent, CodeReader reader,
int startOffset, int endOffset) {
super(parent, startOffset, endOffset, reader);
}
}
protected static class _TranslationUnit extends _CompositeFileContext {
/**
* @param startOffset
* @param endOffset
*/
public _TranslationUnit(CodeReader reader) {
super(null, 0, 0);
this.reader = reader;
super(null, 0, 0, reader);
}
}
@ -636,11 +666,14 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
public final char[] name;
public final char[] expansion;
public final int nameOffset;
}
protected static class _ObjectMacroDefinition extends _MacroDefinition implements _IPreprocessorDirective {
protected static class _ObjectMacroDefinition extends _MacroDefinition
implements _IPreprocessorDirective {
/**
* @param parent
* @param startOffset
@ -650,14 +683,16 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @param expansion
* TODO
*/
public _ObjectMacroDefinition(_CompositeContext parent, int startOffset,
int endOffset, char[] name, int nameOffset, char[] expansion) {
public _ObjectMacroDefinition(_CompositeContext parent,
int startOffset, int endOffset, char[] name, int nameOffset,
char[] expansion) {
super(parent, startOffset, endOffset, name, nameOffset, expansion);
}
}
protected static class _FunctionMacroDefinition extends _MacroDefinition implements _IPreprocessorDirective {
protected static class _FunctionMacroDefinition extends _MacroDefinition
implements _IPreprocessorDirective {
public final char[][] parms;
@ -683,8 +718,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @param startOffset
* @param endOffset
*/
public _Problem(_CompositeContext parent, int startOffset, int endOffset,
IASTProblem problem) {
public _Problem(_CompositeContext parent, int startOffset,
int endOffset, IASTProblem problem) {
super(parent, startOffset, endOffset);
this.problem = problem;
}
@ -692,6 +727,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
protected _TranslationUnit tu;
protected _CompositeContext currentContext;
/**
@ -701,8 +737,11 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0];
private static final IASTNodeLocation[] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0];
private static final IASTPreprocessorMacroDefinition[] EMPTY_MACRO_DEFINITIONS_ARRAY = new IASTPreprocessorMacroDefinition[0];
private static final IASTPreprocessorIncludeStatement[] EMPTY_INCLUDES_ARRAY = new IASTPreprocessorIncludeStatement[0];
/*
@ -712,16 +751,15 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
*/
public IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
int size = collectContexts(V_MACRODEFS, tu, null, 0);
if( size == 0 ) return EMPTY_MACRO_DEFINITIONS_ARRAY;
_Context [] contexts = new _Context[size];
if (size == 0)
return EMPTY_MACRO_DEFINITIONS_ARRAY;
_Context[] contexts = new _Context[size];
collectContexts(V_MACRODEFS, tu, contexts, 0);
IASTPreprocessorMacroDefinition[] result = new IASTPreprocessorMacroDefinition[contexts
.length];
IASTPreprocessorMacroDefinition[] result = new IASTPreprocessorMacroDefinition[contexts.length];
for (int i = 0; i < contexts.length; ++i)
result[i] = createASTMacroDefinition((_MacroDefinition) contexts[i]);
return result;
}
@ -729,7 +767,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @param d
* @return
*/
protected IASTPreprocessorMacroDefinition createASTMacroDefinition(_MacroDefinition d) {
protected IASTPreprocessorMacroDefinition createASTMacroDefinition(
_MacroDefinition d) {
IASTPreprocessorMacroDefinition r = null;
if (d instanceof _ObjectMacroDefinition)
r = new ASTObjectMacro();
@ -750,7 +789,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTName name = new ScannerASTName(d.name);
name.setPropertyInParent(IASTPreprocessorMacroDefinition.MACRO_NAME);
name.setParent(r);
((ScannerASTNode)name).setOffsetAndLength( d.nameOffset, d.name.length );
((ScannerASTNode) name).setOffsetAndLength(d.nameOffset, d.name.length);
r.setName(name);
r.setExpansion(new String(d.expansion));
((ScannerASTNode) r).setOffsetAndLength(d.context_directive_start,
@ -765,9 +804,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
*/
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
int size = collectContexts(V_INCLUSIONS, tu, null, 0);
if (size == 0 )
if (size == 0)
return EMPTY_INCLUDES_ARRAY;
_Context [] contexts = new _Context[size];
_Context[] contexts = new _Context[size];
collectContexts(V_INCLUSIONS, tu, contexts, 0);
IASTPreprocessorIncludeStatement[] result = new IASTPreprocessorIncludeStatement[size];
for (int i = 0; i < size; ++i) {
@ -815,19 +854,49 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
protected IASTNodeLocation[] createSoleLocation(_Context c, int offset,
int length) {
IASTNodeLocation[] result = new IASTNodeLocation[1];
if (c instanceof _TranslationUnit) {
result[0] = new FileLocation(((_TranslationUnit) c).reader.filename,
if (c instanceof _CompositeFileContext) {
result[0] = new FileLocation(
((_CompositeFileContext) c).reader.filename,
reconcileOffset(c, offset), length);
return result;
}
if (c instanceof _Inclusion) {
result[0] = new FileLocation(((_Inclusion) c).reader.filename,
reconcileOffset(c, offset), length);
if (c instanceof _IPreprocessorDirective) {
_CompositeContext parent = c.parent;
while (!(parent instanceof _CompositeFileContext))
parent = c.parent;
_CompositeFileContext fc = (_CompositeFileContext) parent;
result[0] = new FileLocation(fc.reader.filename, reconcileOffset(
fc, c, offset), length);
return result;
}
return EMPTY_LOCATION_ARRAY;
}
/**
* @param fc
* @param c
* @param offset
* @return
*/
protected int reconcileOffset(_CompositeFileContext fc, _Context c,
int offset) {
int subtractOff = 0;
if( c.parent == fc )
{
List subs = fc.getSubContexts();
for( int i = 0; i < subs.size(); ++i )
{
_Context sample = (_Context) subs.get(i);
if( sample == c )
break;
if( ! ( sample instanceof _CompositeContext ) )
continue;
subtractOff += sample.context_ends - sample.context_directive_end;
}
}
return offset - fc.context_directive_end - subtractOff;
}
/**
* @param c
* @param offset
@ -839,10 +908,14 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
List subs = ((_CompositeContext) c).getSubContexts();
for (int i = 0; i < subs.size(); ++i) {
_Context subC = (_Context) subs.get(i);
if (subC.context_ends < offset)
subtractOff += subC.context_ends - subC.context_directive_end;
else
if (subC.context_ends > offset)
break;
if( !( subC instanceof _CompositeContext ) )
continue;
subtractOff += subC.context_ends
- subC.context_directive_end;
}
}
return offset - c.context_directive_end - subtractOff;
@ -873,7 +946,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
_Context nextContext = (_Context) subContexts.get(i);
if (nextContext.context_directive_end < offset)
bestContext = nextContext;
else if( nextContext.context_directive_start < offset && nextContext.context_ends > offset )
else if (nextContext.context_directive_start < offset
&& nextContext.context_ends > offset)
bestContext = nextContext;
else
break;
@ -1005,26 +1079,25 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
*/
public void defineFunctionStyleMacro(FunctionStyleMacro m, int startOffset,
int nameOffset, int nameEndOffset, int endOffset) {
currentContext
.addSubContext(new _FunctionMacroDefinition(currentContext,
startOffset, endOffset, m.name, nameOffset, m.expansion,
removeNullArguments( m.arglist)));
currentContext.addSubContext(new _FunctionMacroDefinition(
currentContext, startOffset, endOffset, m.name, nameOffset,
m.expansion, removeNullArguments(m.arglist)));
}
/**
* @param arglist
* @return
*/
private char [][] removeNullArguments(char[][] arglist) {
private char[][] removeNullArguments(char[][] arglist) {
int nullCount = 0;
for (int i = 0; i < arglist.length; ++i)
if (arglist[i] == null)
++nullCount;
if (nullCount == 0)
return arglist;
char [][] old = arglist;
char[][] old = arglist;
int newSize = old.length - nullCount;
arglist = new char [newSize][];
arglist = new char[newSize][];
for (int i = 0; i < newSize; ++i)
arglist[i] = old[i];
return arglist;
@ -1037,7 +1110,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* int)
*/
public void encounterPoundIf(int startOffset, int endOffset, boolean taken) {
currentContext.addSubContext( new _If( currentContext, startOffset, endOffset, taken ) );
currentContext.addSubContext(new _If(currentContext, startOffset,
endOffset, taken));
}
@ -1048,7 +1122,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* int)
*/
public void encounterPoundPragma(int startOffset, int endOffset) {
currentContext.addSubContext( new _Pragma( currentContext, startOffset, endOffset ) );
currentContext.addSubContext(new _Pragma(currentContext, startOffset,
endOffset));
}
/*
@ -1058,7 +1133,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* int)
*/
public void encounterPoundError(int startOffset, int endOffset) {
currentContext.addSubContext( new _Error( currentContext, startOffset, endOffset ) );
currentContext.addSubContext(new _Error(currentContext, startOffset,
endOffset));
}
/*
@ -1067,8 +1143,10 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIfdef(int,
* int)
*/
public void encounterPoundIfdef(int startOffset, int endOffset, boolean taken) {
currentContext.addSubContext( new _Ifdef( currentContext, startOffset, endOffset, taken ) );
public void encounterPoundIfdef(int startOffset, int endOffset,
boolean taken) {
currentContext.addSubContext(new _Ifdef(currentContext, startOffset,
endOffset, taken));
}
/*
@ -1078,7 +1156,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* int)
*/
public void encounterPoundUndef(int startOffset, int endOffset) {
currentContext.addSubContext( new _Undef( currentContext, startOffset, endOffset ) );
currentContext.addSubContext(new _Undef(currentContext, startOffset,
endOffset));
}
/*
@ -1088,7 +1167,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* int)
*/
public void encounterPoundElse(int startOffset, int endOffset, boolean taken) {
currentContext.addSubContext( new _Else( currentContext, startOffset, endOffset, taken ));
currentContext.addSubContext(new _Else(currentContext, startOffset,
endOffset, taken));
}
/*
@ -1098,8 +1178,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* int)
*/
public void encounterPoundElif(int startOffset, int endOffset, boolean taken) {
currentContext.addSubContext( new _Elif( currentContext, startOffset, endOffset, taken ) );
currentContext.addSubContext(new _Elif(currentContext, startOffset,
endOffset, taken));
}
/*
@ -1109,7 +1189,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* int)
*/
public void encounterPoundEndIf(int startOffset, int endOffset) {
currentContext.addSubContext( new _Endif( currentContext, startOffset, endOffset) );
currentContext.addSubContext(new _Endif(currentContext, startOffset,
endOffset));
}
/*
@ -1137,8 +1218,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
*/
public IASTProblem[] getScannerProblems() {
int size = LocationMap.collectContexts(V_PROBLEMS, tu, null, 0);
if( size == 0 ) return EMPTY_PROBLEMS_ARRAY;
_Context [] contexts = new _Context[size];
if (size == 0)
return EMPTY_PROBLEMS_ARRAY;
_Context[] contexts = new _Context[size];
LocationMap.collectContexts(V_PROBLEMS, tu, contexts, 0);
IASTProblem[] result = new IASTProblem[size];
for (int i = 0; i < size; ++i)
@ -1157,54 +1239,56 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
_Problem pr = new _Problem(currentContext, p.getOffset(), p.getOffset()
+ p.getLength(), problem);
pr.context_ends = p.getOffset() + p.getLength();
currentContext.addSubContext( pr );
currentContext.addSubContext(pr);
}
protected static final int V_ALL = 1;
protected static final int V_INCLUSIONS = 2;
protected static final int V_PROBLEMS = 3;
protected static final int V_MACRODEFS = 4;
protected static final int V_PREPROCESSOR = 5;
private static final char[] EMPTY_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$
protected static int collectContexts(int key, _Context source, _Context[] result, int s ) {
protected static int collectContexts(int key, _Context source,
_Context[] result, int s) {
int startAt = s;
int count = 0;
switch (key) {
case V_ALL:
if( result != null )
if (result != null)
result[startAt++] = source;
++count;
break;
case V_INCLUSIONS:
if (source instanceof _Inclusion)
{
if( result != null )
if (source instanceof _Inclusion) {
if (result != null)
result[startAt++] = source;
++count;
}
break;
case V_PROBLEMS:
if (source instanceof _Problem)
{
if (source instanceof _Problem) {
if( result != null )
if (result != null)
result[startAt++] = source;
++count;
}
break;
case V_MACRODEFS:
if (source instanceof _MacroDefinition)
{
if( result != null )
if (source instanceof _MacroDefinition) {
if (result != null)
result[startAt++] = source;
++count;
}
break;
case V_PREPROCESSOR:
if( source instanceof _IPreprocessorDirective )
{
if( result != null )
if (source instanceof _IPreprocessorDirective) {
if (result != null)
result[startAt++] = source;
++count;
}
@ -1212,9 +1296,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
if (source instanceof _CompositeContext) {
List l = ((_CompositeContext) source).getSubContexts();
for (int i = 0; i < l.size(); ++i)
{
int value = collectContexts(key, (_Context) l.get(i), result, startAt);
for (int i = 0; i < l.size(); ++i) {
int value = collectContexts(key, (_Context) l.get(i), result,
startAt);
count += value;
startAt += value;
}
@ -1222,30 +1306,35 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
return count;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getSignature(org.eclipse.cdt.core.dom.ast.IASTNodeLocation[])
*/
public char[] getUnpreprocessedSignature( IASTNodeLocation[] locations) {
public char[] getUnpreprocessedSignature(IASTNodeLocation[] locations) {
switch ( locations.length )
{
switch (locations.length) {
case 1:
if( locations[0] instanceof IASTFileLocation )
{
if (locations[0] instanceof IASTFileLocation) {
IASTNodeLocation nodeLocation = locations[0];
char [] name = ((IASTFileLocation)nodeLocation).getFileName().toCharArray();
if( readerCompatable( nodeLocation, tu.reader, name ) )
return CharArrayUtils.extract( tu.reader.buffer, nodeLocation.getNodeOffset(), nodeLocation.getNodeLength() );
char[] name = ((IASTFileLocation) nodeLocation).getFileName()
.toCharArray();
if (readerCompatable(nodeLocation, tu.reader, name))
return CharArrayUtils.extract(tu.reader.buffer,
nodeLocation.getNodeOffset(), nodeLocation
.getNodeLength());
int size = collectContexts( V_INCLUSIONS, tu, null, 0 );
if( size == 0 ) return EMPTY_CHAR_ARRAY;
_Context [] inclusions = new _Context[size];
collectContexts( V_INCLUSIONS, tu, inclusions, 0 );
for( int i = 0; i < size; ++i )
{
int size = collectContexts(V_INCLUSIONS, tu, null, 0);
if (size == 0)
return EMPTY_CHAR_ARRAY;
_Context[] inclusions = new _Context[size];
collectContexts(V_INCLUSIONS, tu, inclusions, 0);
for (int i = 0; i < size; ++i) {
_Inclusion inc = (_Inclusion) inclusions[i];
if( readerCompatable( nodeLocation, inc.reader, name ) )
return CharArrayUtils.extract( inc.reader.buffer, nodeLocation.getNodeOffset(), nodeLocation.getNodeLength() );
if (readerCompatable(nodeLocation, inc.reader, name))
return CharArrayUtils.extract(inc.reader.buffer,
nodeLocation.getNodeOffset(), nodeLocation
.getNodeLength());
}
}
return EMPTY_CHAR_ARRAY;
@ -1263,18 +1352,27 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @param name
* @return
*/
private boolean readerCompatable(IASTNodeLocation nodeLocation, CodeReader reader, char[] name) {
if( !CharArrayUtils.equals( reader.filename, name )) return false;
if( nodeLocation.getNodeOffset() > reader.buffer.length ) return false;
if( nodeLocation.getNodeOffset() + nodeLocation.getNodeLength() > reader.buffer.length ) return false;
private boolean readerCompatable(IASTNodeLocation nodeLocation,
CodeReader reader, char[] name) {
if (!CharArrayUtils.equals(reader.filename, name))
return false;
if (nodeLocation.getNodeOffset() > reader.buffer.length)
return false;
if (nodeLocation.getNodeOffset() + nodeLocation.getNodeLength() > reader.buffer.length)
return false;
return true;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIfndef(int, int, boolean)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIfndef(int,
* int, boolean)
*/
public void encounterPoundIfndef(int startOffset, int endOffset, boolean taken) {
currentContext.addSubContext( new _Ifndef( currentContext, startOffset, endOffset, taken ) );
public void encounterPoundIfndef(int startOffset, int endOffset,
boolean taken) {
currentContext.addSubContext(new _Ifndef(currentContext, startOffset,
endOffset, taken));
}
}