mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-19 06:55:23 +02:00
Implementation of flattenLocations for new LocationMap.
This commit is contained in:
parent
e46d0efe27
commit
74a6d68f29
5 changed files with 36 additions and 10 deletions
|
@ -103,14 +103,14 @@ class ASTBuiltinName extends ASTPreprocessorDefinition {
|
|||
|
||||
public IASTNodeLocation[] getNodeLocations() {
|
||||
if (fFileLocation == null) {
|
||||
throw new UnsupportedOperationException();
|
||||
return new IASTNodeLocation[0];
|
||||
}
|
||||
return new IASTNodeLocation[]{fFileLocation};
|
||||
}
|
||||
|
||||
public String getRawSignature() {
|
||||
if (fFileLocation == null) {
|
||||
throw new UnsupportedOperationException();
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
return toString();
|
||||
}
|
||||
|
|
|
@ -459,6 +459,14 @@ class ASTFileLocation implements IASTFileLocation {
|
|||
public String toString() {
|
||||
return getFileName() + "[" + fOffset + "," + (fOffset+fLength) + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
|
||||
}
|
||||
|
||||
public int getSequenceNumber() {
|
||||
return fLocationCtx.getSequenceNumberForOffset(fOffset, true);
|
||||
}
|
||||
|
||||
public int getSequenceEndNumber() {
|
||||
return fLocationCtx.getSequenceNumberForOffset(fOffset+fLength, true);
|
||||
}
|
||||
}
|
||||
|
||||
class ASTMacroExpansionLocation implements IASTMacroExpansion {
|
||||
|
|
|
@ -445,9 +445,23 @@ public class LocationMap implements ILocationResolver {
|
|||
return -1;
|
||||
}
|
||||
|
||||
// mstodo implement
|
||||
public IASTFileLocation flattenLocations(IASTNodeLocation[] locations) {
|
||||
throw new UnsupportedOperationException();
|
||||
if (locations.length == 0) {
|
||||
return null;
|
||||
}
|
||||
IASTFileLocation from= locations[0].asFileLocation();
|
||||
IASTFileLocation to= locations[locations.length-1].asFileLocation();
|
||||
if (from == to) {
|
||||
return from;
|
||||
}
|
||||
if (from instanceof ASTFileLocation && to instanceof ASTFileLocation) {
|
||||
int sequenceNumber= ((ASTFileLocation) from).getSequenceNumber();
|
||||
int length= ((ASTFileLocation) from).getSequenceEndNumber() - sequenceNumber;
|
||||
if (length > 0) {
|
||||
return getMappedFileLocation(sequenceNumber, length);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -364,10 +364,12 @@ abstract public class PDOMWriter {
|
|||
|
||||
// assign a location to anonymous types.
|
||||
name= PDOMASTAdapter.getAdapterIfAnonymous(name);
|
||||
IASTFileLocation nameLoc = name.getFileLocation();
|
||||
if (nameLoc != null) {
|
||||
IIndexFileLocation location = findLocation(nameLoc.getFileName());
|
||||
addToMap(symbolMap, 2, location, new IASTName[]{name, caller});
|
||||
if (name != null) {
|
||||
IASTFileLocation nameLoc = name.getFileLocation();
|
||||
if (nameLoc != null) {
|
||||
IIndexFileLocation location = findLocation(nameLoc.getFileName());
|
||||
addToMap(symbolMap, 2, location, new IASTName[]{name, caller});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -421,8 +421,9 @@ public class PDOMASTAdapter {
|
|||
/**
|
||||
* If the name is empty and has no file location, either an adapter
|
||||
* that has a file location is returned, or <code>null</code> if that
|
||||
* is not possible.
|
||||
* Otherwise if the provided name is not empty, it is returned unchanged.
|
||||
* is not possible (no parent with a file location).
|
||||
* Otherwise if the provided name is not empty or has a file location,
|
||||
* it is returned unchanged.
|
||||
*/
|
||||
public static IASTName getAdapterIfAnonymous(IASTName name) {
|
||||
if (name.toCharArray().length == 0) {
|
||||
|
@ -434,6 +435,7 @@ public class PDOMASTAdapter {
|
|||
return new AnonymousASTName(name, loc);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
|
|
Loading…
Add table
Reference in a new issue