From 74a6d68f291a3c986825ebbc6951782c2ebfd199 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 15 Nov 2007 15:41:39 +0000 Subject: [PATCH] Implementation of flattenLocations for new LocationMap. --- .../parser/scanner/ASTPreprocessorName.java | 4 ++-- .../parser/scanner/ASTPreprocessorNode.java | 8 ++++++++ .../core/parser/scanner/LocationMap.java | 18 ++++++++++++++++-- .../cdt/internal/core/pdom/PDOMWriter.java | 10 ++++++---- .../internal/core/pdom/dom/PDOMASTAdapter.java | 6 ++++-- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorName.java index 5846add5258..b3f3abdedb7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorName.java @@ -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(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorNode.java index dbc05543e5e..201039f951b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorNode.java @@ -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 { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java index a6886529b4b..fe3011bf87f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java index 18268e6e9ac..c12dea48261 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java @@ -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}); + } } } }); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMASTAdapter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMASTAdapter.java index a9da78a16a6..12dd90e87ac 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMASTAdapter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMASTAdapter.java @@ -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 null 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;