1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-03 05:33:33 +02:00

Implementation of flattenLocations for new LocationMap.

This commit is contained in:
Markus Schorn 2007-11-15 15:41:39 +00:00
parent e46d0efe27
commit 74a6d68f29
5 changed files with 36 additions and 10 deletions

View file

@ -103,14 +103,14 @@ class ASTBuiltinName extends ASTPreprocessorDefinition {
public IASTNodeLocation[] getNodeLocations() { public IASTNodeLocation[] getNodeLocations() {
if (fFileLocation == null) { if (fFileLocation == null) {
throw new UnsupportedOperationException(); return new IASTNodeLocation[0];
} }
return new IASTNodeLocation[]{fFileLocation}; return new IASTNodeLocation[]{fFileLocation};
} }
public String getRawSignature() { public String getRawSignature() {
if (fFileLocation == null) { if (fFileLocation == null) {
throw new UnsupportedOperationException(); return ""; //$NON-NLS-1$
} }
return toString(); return toString();
} }

View file

@ -459,6 +459,14 @@ class ASTFileLocation implements IASTFileLocation {
public String toString() { public String toString() {
return getFileName() + "[" + fOffset + "," + (fOffset+fLength) + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ 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 { class ASTMacroExpansionLocation implements IASTMacroExpansion {

View file

@ -445,9 +445,23 @@ public class LocationMap implements ILocationResolver {
return -1; return -1;
} }
// mstodo implement
public IASTFileLocation flattenLocations(IASTNodeLocation[] locations) { 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;
} }

View file

@ -364,10 +364,12 @@ abstract public class PDOMWriter {
// assign a location to anonymous types. // assign a location to anonymous types.
name= PDOMASTAdapter.getAdapterIfAnonymous(name); name= PDOMASTAdapter.getAdapterIfAnonymous(name);
IASTFileLocation nameLoc = name.getFileLocation(); if (name != null) {
if (nameLoc != null) { IASTFileLocation nameLoc = name.getFileLocation();
IIndexFileLocation location = findLocation(nameLoc.getFileName()); if (nameLoc != null) {
addToMap(symbolMap, 2, location, new IASTName[]{name, caller}); IIndexFileLocation location = findLocation(nameLoc.getFileName());
addToMap(symbolMap, 2, location, new IASTName[]{name, caller});
}
} }
} }
}); });

View file

@ -421,8 +421,9 @@ public class PDOMASTAdapter {
/** /**
* If the name is empty and has no file location, either an adapter * 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 * that has a file location is returned, or <code>null</code> if that
* is not possible. * is not possible (no parent with a file location).
* Otherwise if the provided name is not empty, it is returned unchanged. * Otherwise if the provided name is not empty or has a file location,
* it is returned unchanged.
*/ */
public static IASTName getAdapterIfAnonymous(IASTName name) { public static IASTName getAdapterIfAnonymous(IASTName name) {
if (name.toCharArray().length == 0) { if (name.toCharArray().length == 0) {
@ -434,6 +435,7 @@ public class PDOMASTAdapter {
return new AnonymousASTName(name, loc); return new AnonymousASTName(name, loc);
} }
} }
return null;
} }
} }
return name; return name;