diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclSpecifier.java index 27b6c733d7b..a73bb40f23a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclSpecifier.java @@ -37,4 +37,6 @@ public interface IASTDeclSpecifier extends IASTNode { public boolean isInline(); public void setInline( boolean value ); + public String getUnpreprocessedSignature(); + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java index 6071afec35d..0066a7cfa74 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java @@ -74,5 +74,7 @@ public interface IASTTranslationUnit extends IASTNode { public IASTPreprocessorStatement[] getAllPreprocessorStatements(); public IASTProblem[] getPreprocesorProblems(); + + public String getUnpreprocessedSignature( IASTNodeLocation [] locations ); } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java index 85c1300f935..fb6b9ffb904 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java @@ -54,4 +54,11 @@ public abstract class ASTNode implements IASTNode { public IASTNodeLocation[] getNodeLocations() { return getTranslationUnit().getLocationInfo( offset, length ); } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTNode#getUnpreprocessedSignature() + */ + public String getUnpreprocessedSignature() { + return getTranslationUnit().getUnpreprocessedSignature( getNodeLocations() ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java index de2f1a91e20..172376a7e29 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java @@ -43,6 +43,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0]; private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0]; private static final IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0]; + private static final String EMPTY_STRING = ""; //$NON-NLS-1$ public void addDeclaration( IASTDeclaration d ) { @@ -222,4 +223,13 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit } return result; } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getUnpreprocessedSignature(org.eclipse.cdt.core.dom.ast.IASTNodeLocation[]) + */ + public String getUnpreprocessedSignature(IASTNodeLocation[] locations) { + if( resolver == null ) return EMPTY_STRING; + return new String( resolver.getUnpreprocessedSignature(locations) ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index 7529be8b27a..625f52848d7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -54,7 +54,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0]; private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0]; - + private static final String EMPTY_STRING = ""; //$NON-NLS-1$ private static final IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0]; public void addDeclaration(IASTDeclaration d) { @@ -261,4 +261,11 @@ public class CPPASTTranslationUnit extends CPPASTNode implements return result; } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getUnpreprocessedSignature(org.eclipse.cdt.core.dom.ast.IASTNodeLocation[]) + */ + public String getUnpreprocessedSignature(IASTNodeLocation[] locations) { + if( resolver == null ) return EMPTY_STRING; + return new String( resolver.getUnpreprocessedSignature(locations) ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java index 199767e2201..3284547a3c4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java @@ -27,6 +27,9 @@ public interface ILocationResolver { public IASTNodeLocation [] getLocations( int offset, int length ); public IASTNodeLocation getLocation( int offset ); + + public char [] getUnpreprocessedSignature( IASTNodeLocation [] locations ); + public IASTProblem[] getScannerProblems(); public String getTranslationUnitPath(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java index 61de6b97e07..bc7abaeb9ed 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java @@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.parser.CodeReader; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; /** @@ -1008,6 +1009,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { protected static final int V_INCLUSIONS = 2; protected static final int V_PROBLEMS = 3; protected static final int V_MACRODEFS = 4; + private static final char[] EMPTY_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$ protected static void collectContexts(int key, _Context source, List result) { switch (key) { @@ -1034,4 +1036,49 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { } } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getSignature(org.eclipse.cdt.core.dom.ast.IASTNodeLocation[]) + */ + public char[] getUnpreprocessedSignature( IASTNodeLocation[] locations) { + + switch ( locations.length ) + { + case 1: + if( locations[0] instanceof IASTFileLocation ) + { + IASTNodeLocation nodeLocation = locations[0]; + char [] name = ((IASTFileLocation)nodeLocation).getFileName().toCharArray(); + if( readerCompatable( nodeLocation, tu.reader, name ) ) + return CharArrayUtils.extract( tu.reader.buffer, nodeLocation.getNodeOffset(), nodeLocation.getNodeLength() ); + List inclusions = new ArrayList(); + collectContexts( V_INCLUSIONS, tu, inclusions ); + for( int i = 0; i < inclusions.size(); ++i ) + { + _Inclusion inc = (_Inclusion) inclusions.get(i); + if( readerCompatable( nodeLocation, inc.reader, name ) ) + return CharArrayUtils.extract( inc.reader.buffer, nodeLocation.getNodeOffset(), nodeLocation.getNodeLength() ); + } + } + return EMPTY_CHAR_ARRAY; + case 0: + return EMPTY_CHAR_ARRAY; + default: + //TODO + return EMPTY_CHAR_ARRAY; + } + } + + /** + * @param nodeLocation + * @param reader + * @param name + * @return + */ + private boolean readerCompatable(IASTNodeLocation nodeLocation, CodeReader reader, char[] name) { + if( !CharArrayUtils.equals( reader.filename, name )) return false; + if( nodeLocation.getNodeOffset() > reader.buffer.length ) return false; + if( nodeLocation.getNodeOffset() + nodeLocation.getNodeLength() > reader.buffer.length ) return false; + return true; + } + } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/TreeObject.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/TreeObject.java index 95050cfcea8..5f8e7f4cc2f 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/TreeObject.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/TreeObject.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.ui.tests.DOMAST; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; @@ -111,8 +112,14 @@ public class TreeObject implements IAdaptable { } return buffer.toString(); + } else if( node instanceof IASTDeclSpecifier ) + { + buffer.append( START_OF_LIST ); + buffer.append( ((IASTDeclSpecifier)node).getUnpreprocessedSignature() ); + return buffer.toString(); } + return buffer.toString(); } public Object getAdapter(Class key) {