1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 08:55:25 +02:00

Fixed locations for scanner problems.

This commit is contained in:
John Camelon 2005-05-04 15:28:22 +00:00
parent 249b5eb68e
commit 2bd5960655
2 changed files with 22 additions and 2 deletions

View file

@ -351,6 +351,27 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
assertEquals( "_INCLUDE_H_".length(), flatLoc.getNodeLength() ); //$NON-NLS-1$
}
}
public void testIProblemLocation() throws Exception
{
StringBuffer buffer = new StringBuffer();
buffer.append( "#include <not_found.h>\n"); //$NON-NLS-1$
buffer.append( "int x,y,z;"); //$NON-NLS-1$
String code = buffer.toString();
IFile f = importFile( "blah.c", code ); //$NON-NLS-1$
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
: null) {
IASTTranslationUnit tu = parse( f, p ); //$NON-NLS-1$
IASTProblem [] prbs = tu.getPreprocessorProblems();
assertEquals( prbs.length, 1 );
IASTNodeLocation [] locs = prbs[0].getNodeLocations();
assertEquals( locs.length, 1 );
IASTFileLocation fileLoc = (IASTFileLocation) locs[0];
assertEquals( code.indexOf( "#include" ), fileLoc.getNodeOffset() ); //$NON-NLS-1$
assertEquals( "#include <not_found.h>\n".length(), fileLoc.getNodeLength() ); //$NON-NLS-1$
}
}
public static Test suite() {
TestSuite suite = new TestSuite(DOMLocationInclusionTests.class);

View file

@ -1736,7 +1736,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
protected IASTNodeLocation createSoleLocation(_Context c, int offset,
int length) {
if (c instanceof _IPreprocessorDirective) {
if (c instanceof _IPreprocessorDirective || c instanceof _Problem ) {
if (c.containsInDirective(offset, length)) {
_CompositeContext parent = c.parent;
while (!(parent instanceof _CompositeFileContext))
@ -1745,7 +1745,6 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
return new FileLocation(fc.reader.filename, reconcileOffset(fc,
c, offset), length);
}
}
if (c instanceof _CompositeFileContext) {
return new FileLocation(