mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Added getUnpreprocressedSignature() to IASTDeclSpecifier.
Added appropriate support to ILocationResolver.
This commit is contained in:
parent
07a476a1fe
commit
2091bd2767
8 changed files with 86 additions and 1 deletions
|
@ -37,4 +37,6 @@ public interface IASTDeclSpecifier extends IASTNode {
|
||||||
public boolean isInline();
|
public boolean isInline();
|
||||||
public void setInline( boolean value );
|
public void setInline( boolean value );
|
||||||
|
|
||||||
|
public String getUnpreprocessedSignature();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,4 +75,6 @@ public interface IASTTranslationUnit extends IASTNode {
|
||||||
|
|
||||||
public IASTProblem[] getPreprocesorProblems();
|
public IASTProblem[] getPreprocesorProblems();
|
||||||
|
|
||||||
|
public String getUnpreprocessedSignature( IASTNodeLocation [] locations );
|
||||||
|
|
||||||
}
|
}
|
|
@ -54,4 +54,11 @@ public abstract class ASTNode implements IASTNode {
|
||||||
public IASTNodeLocation[] getNodeLocations() {
|
public IASTNodeLocation[] getNodeLocations() {
|
||||||
return getTranslationUnit().getLocationInfo( offset, length );
|
return getTranslationUnit().getLocationInfo( offset, length );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getUnpreprocessedSignature()
|
||||||
|
*/
|
||||||
|
public String getUnpreprocessedSignature() {
|
||||||
|
return getTranslationUnit().getUnpreprocessedSignature( getNodeLocations() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0];
|
||||||
private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[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 IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0];
|
||||||
|
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
||||||
|
|
||||||
public void addDeclaration( IASTDeclaration d )
|
public void addDeclaration( IASTDeclaration d )
|
||||||
{
|
{
|
||||||
|
@ -222,4 +223,13 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
||||||
}
|
}
|
||||||
return result;
|
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) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
||||||
private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0];
|
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 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];
|
private static final IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0];
|
||||||
|
|
||||||
public void addDeclaration(IASTDeclaration d) {
|
public void addDeclaration(IASTDeclaration d) {
|
||||||
|
@ -261,4 +261,11 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
||||||
return result;
|
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) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,9 @@ public interface ILocationResolver {
|
||||||
|
|
||||||
public IASTNodeLocation [] getLocations( int offset, int length );
|
public IASTNodeLocation [] getLocations( int offset, int length );
|
||||||
public IASTNodeLocation getLocation( int offset );
|
public IASTNodeLocation getLocation( int offset );
|
||||||
|
|
||||||
|
public char [] getUnpreprocessedSignature( IASTNodeLocation [] locations );
|
||||||
|
|
||||||
public IASTProblem[] getScannerProblems();
|
public IASTProblem[] getScannerProblems();
|
||||||
|
|
||||||
public String getTranslationUnitPath();
|
public String getTranslationUnitPath();
|
||||||
|
|
|
@ -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.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
import org.eclipse.cdt.core.parser.CodeReader;
|
||||||
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
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_INCLUSIONS = 2;
|
||||||
protected static final int V_PROBLEMS = 3;
|
protected static final int V_PROBLEMS = 3;
|
||||||
protected static final int V_MACRODEFS = 4;
|
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) {
|
protected static void collectContexts(int key, _Context source, List result) {
|
||||||
switch (key) {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -10,6 +10,7 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.ui.tests.DOMAST;
|
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.IASTDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
|
@ -110,9 +111,15 @@ public class TreeObject implements IAdaptable {
|
||||||
buffer.append(fileName.substring(lastSlash+1)); // TODO make path relative to project, i.e. /projectName/path/file.c
|
buffer.append(fileName.substring(lastSlash+1)); // TODO make path relative to project, i.e. /projectName/path/file.c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return buffer.toString();
|
||||||
|
} else if( node instanceof IASTDeclSpecifier )
|
||||||
|
{
|
||||||
|
buffer.append( START_OF_LIST );
|
||||||
|
buffer.append( ((IASTDeclSpecifier)node).getUnpreprocessedSignature() );
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
public Object getAdapter(Class key) {
|
public Object getAdapter(Class key) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue