mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 06:32:10 +02:00
Fixed Bug 88996 - [DOM AST] IASTFileLocation needs to make reference to line numbers.
This commit is contained in:
parent
30fd798f6c
commit
a11aba0b33
3 changed files with 72 additions and 8 deletions
|
@ -23,4 +23,18 @@ public interface IASTFileLocation extends IASTNodeLocation {
|
|||
* @return the name of the file
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -88,6 +88,11 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
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$
|
||||
|
@ -871,10 +876,11 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
|
||||
}
|
||||
|
||||
public static class FileLocation extends Location implements
|
||||
public class FileLocation extends Location implements
|
||||
IASTFileLocation {
|
||||
|
||||
private String fileName;
|
||||
private _CompositeFileContext _fileContext;
|
||||
|
||||
/**
|
||||
* @param length
|
||||
|
@ -900,6 +906,40 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
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 {
|
||||
|
@ -1050,6 +1090,16 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
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
|
||||
|
@ -2137,19 +2187,19 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
endOffset, taken));
|
||||
}
|
||||
|
||||
private _Context findInclusion(_CompositeContext context, String path) {
|
||||
_Context foundContext = null;
|
||||
_Inclusion findInclusion(_CompositeContext context, String path) {
|
||||
_Inclusion foundContext = null;
|
||||
_Context[] contexts = context.getSubContexts();
|
||||
|
||||
_Inclusion tempContext= null;
|
||||
for (int i = 0; foundContext == null && i < contexts.length; i++) {
|
||||
if (contexts[i] instanceof _Inclusion) {
|
||||
context = (_Inclusion) contexts[i];
|
||||
tempContext = (_Inclusion) contexts[i];
|
||||
|
||||
// check if the file matches the #include
|
||||
if (CharArrayUtils.equals(
|
||||
((_Inclusion) context).reader.filename, path
|
||||
tempContext.reader.filename, path
|
||||
.toCharArray())) {
|
||||
foundContext = context;
|
||||
foundContext = tempContext;
|
||||
break;
|
||||
}
|
||||
foundContext = findInclusion(context, path);
|
||||
|
|
|
@ -481,7 +481,7 @@ public class DOMASTNodeLeaf implements IAdaptable {
|
|||
else
|
||||
buffer.append(trimObjectToString(obj.toString()));
|
||||
} else
|
||||
buffer.append(trimObjectToString(obj.toString()));
|
||||
buffer.append(obj.toString());
|
||||
|
||||
if( obj instanceof IBinding ){
|
||||
buffer.append( OPEN_PAREN );
|
||||
|
|
Loading…
Add table
Reference in a new issue