1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Fixed Bug 88996 - [DOM AST] IASTFileLocation needs to make reference to line numbers.

This commit is contained in:
John Camelon 2005-04-05 18:31:36 +00:00
parent 30fd798f6c
commit a11aba0b33
3 changed files with 72 additions and 8 deletions

View file

@ -23,4 +23,18 @@ public interface IASTFileLocation extends IASTNodeLocation {
* @return the name of the file * @return the name of the file
*/ */
public String getFileName(); public String getFileName();
/**
* Get the starting line number.
*
* @return in representing line number
*/
public int getStartingLineNumber();
/**
* Get the ending line number.
*
* @return int representing line number
*/
public int getEndingLineNumber();
} }

View file

@ -88,6 +88,11 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
return rootNode.flattenLocationsToFile(getExpansionLocations()); return rootNode.flattenLocationsToFile(getExpansionLocations());
} }
public String toString() {
return "Macro Expansion " + definition.getName().toString() + " flattened to " + asFileLocation().toString(); //$NON-NLS-1$ //$NON-NLS-2$
}
} }
private static final String NOT_VALID_MACRO = "Not a valid macro selection"; //$NON-NLS-1$ private static final String NOT_VALID_MACRO = "Not a valid macro selection"; //$NON-NLS-1$
@ -871,10 +876,11 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
} }
public static class FileLocation extends Location implements public class FileLocation extends Location implements
IASTFileLocation { IASTFileLocation {
private String fileName; private String fileName;
private _CompositeFileContext _fileContext;
/** /**
* @param length * @param length
@ -900,6 +906,40 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
return this; return this;
} }
public int getStartingLineNumber() {
_CompositeFileContext i = getFileContext();
if( i != null )
return i.getLineNumber( getNodeOffset() );
return 0;
}
private _CompositeFileContext getFileContext() {
if( _fileContext == null )
{
if( fileName.equals( getTranslationUnitPath() ))
_fileContext = tu;
else
_fileContext = findInclusion( tu, fileName );
}
return _fileContext;
}
public int getEndingLineNumber() {
_CompositeFileContext i = getFileContext();
if( i != null )
return i.getLineNumber( getNodeOffset() + getNodeLength());
return 0;
}
public String toString() {
StringBuffer buffer = new StringBuffer( fileName );
buffer.append(" line " ); //$NON-NLS-1$
buffer.append( getStartingLineNumber() );
buffer.append( " to " ); //$NON-NLS-1$
buffer.append( getEndingLineNumber() );
return buffer.toString();
}
} }
protected static class _Context { protected static class _Context {
@ -1050,6 +1090,16 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
this.reader = reader; this.reader = reader;
} }
public int getLineNumber(int nodeOffset) {
int lineNumber = 1;
for( int i = 0; i < nodeOffset; ++i )
{
if( reader.buffer[i] == '\n')
++lineNumber;
}
return lineNumber;
}
} }
protected static class _Inclusion extends _CompositeFileContext implements protected static class _Inclusion extends _CompositeFileContext implements
@ -2137,19 +2187,19 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
endOffset, taken)); endOffset, taken));
} }
private _Context findInclusion(_CompositeContext context, String path) { _Inclusion findInclusion(_CompositeContext context, String path) {
_Context foundContext = null; _Inclusion foundContext = null;
_Context[] contexts = context.getSubContexts(); _Context[] contexts = context.getSubContexts();
_Inclusion tempContext= null;
for (int i = 0; foundContext == null && i < contexts.length; i++) { for (int i = 0; foundContext == null && i < contexts.length; i++) {
if (contexts[i] instanceof _Inclusion) { if (contexts[i] instanceof _Inclusion) {
context = (_Inclusion) contexts[i]; tempContext = (_Inclusion) contexts[i];
// check if the file matches the #include // check if the file matches the #include
if (CharArrayUtils.equals( if (CharArrayUtils.equals(
((_Inclusion) context).reader.filename, path tempContext.reader.filename, path
.toCharArray())) { .toCharArray())) {
foundContext = context; foundContext = tempContext;
break; break;
} }
foundContext = findInclusion(context, path); foundContext = findInclusion(context, path);

View file

@ -481,7 +481,7 @@ public class DOMASTNodeLeaf implements IAdaptable {
else else
buffer.append(trimObjectToString(obj.toString())); buffer.append(trimObjectToString(obj.toString()));
} else } else
buffer.append(trimObjectToString(obj.toString())); buffer.append(obj.toString());
if( obj instanceof IBinding ){ if( obj instanceof IBinding ){
buffer.append( OPEN_PAREN ); buffer.append( OPEN_PAREN );