1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Added getUnpreprocressedSignature() to IASTDeclSpecifier.

Added appropriate support to ILocationResolver.
This commit is contained in:
John Camelon 2005-01-28 15:18:04 +00:00
parent 07a476a1fe
commit 2091bd2767
8 changed files with 86 additions and 1 deletions

View file

@ -37,4 +37,6 @@ public interface IASTDeclSpecifier extends IASTNode {
public boolean isInline();
public void setInline( boolean value );
public String getUnpreprocessedSignature();
}

View file

@ -74,5 +74,7 @@ public interface IASTTranslationUnit extends IASTNode {
public IASTPreprocessorStatement[] getAllPreprocessorStatements();
public IASTProblem[] getPreprocesorProblems();
public String getUnpreprocessedSignature( IASTNodeLocation [] locations );
}

View file

@ -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() );
}
}

View file

@ -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) );
}
}

View file

@ -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) );
}
}

View file

@ -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();

View file

@ -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;
}
}

View file

@ -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) {