mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Function style macro parameters working through IASTTranslationUnit#getMacroDefinitions()
This commit is contained in:
parent
af85d93c29
commit
c2664b26e1
5 changed files with 362 additions and 224 deletions
|
@ -13,9 +13,12 @@ package org.eclipse.cdt.core.parser.tests.ast2;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
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.IASTFunctionStyleMacroParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorObjectStyleMacroDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
|
@ -90,7 +93,7 @@ public class DOMLocationTests extends AST2BaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testSimpleMacroDefinition() throws Exception {
|
public void testSimpleObjectStyleMacroDefinition() throws Exception {
|
||||||
String code ="/* hi */\n#define FOOT 0x01\n\n"; //$NON-NLS-1$
|
String code ="/* hi */\n#define FOOT 0x01\n\n"; //$NON-NLS-1$
|
||||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||||
: null) {
|
: null) {
|
||||||
|
@ -101,12 +104,35 @@ public class DOMLocationTests extends AST2BaseTest {
|
||||||
assertNotNull( macros );
|
assertNotNull( macros );
|
||||||
assertEquals( macros.length, 1 );
|
assertEquals( macros.length, 1 );
|
||||||
assertSoleLocation( macros[0], code.indexOf( "#"), code.indexOf( "0x01") + 4 - code.indexOf( "#")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
assertSoleLocation( macros[0], code.indexOf( "#"), code.indexOf( "0x01") + 4 - code.indexOf( "#")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
|
assertTrue( macros[0] instanceof IASTPreprocessorObjectStyleMacroDefinition );
|
||||||
assertEquals( macros[0].getName().toString(), "FOOT" ); //$NON-NLS-1$
|
assertEquals( macros[0].getName().toString(), "FOOT" ); //$NON-NLS-1$
|
||||||
assertEquals( macros[0].getExpansion(), "0x01"); //$NON-NLS-1$
|
assertEquals( macros[0].getExpansion(), "0x01"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void testSimpleFunctionStyleMacroDefinition() throws Exception {
|
||||||
|
String code = "#define FOOBAH( WOOBAH ) JOHN##WOOBAH\n\n"; //$NON-NLS-1$
|
||||||
|
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||||
|
: null) {
|
||||||
|
IASTTranslationUnit tu = parse(code, p);
|
||||||
|
IASTDeclaration[] declarations = tu.getDeclarations();
|
||||||
|
assertEquals(declarations.length, 0);
|
||||||
|
IASTPreprocessorMacroDefinition [] macros = tu.getMacroDefinitions();
|
||||||
|
assertNotNull( macros );
|
||||||
|
assertEquals( macros.length, 1 );
|
||||||
|
assertTrue( macros[0] instanceof IASTPreprocessorFunctionStyleMacroDefinition );
|
||||||
|
assertSoleLocation( macros[0], code.indexOf( "#define"), code.indexOf( "##WOOBAH") + 8 - code.indexOf( "#define")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$s
|
||||||
|
assertEquals( macros[0].getName().toString(), "FOOBAH" ); //$NON-NLS-1$
|
||||||
|
assertEquals( macros[0].getExpansion(), "JOHN##WOOBAH"); //$NON-NLS-1$
|
||||||
|
IASTFunctionStyleMacroParameter [] parms = ((IASTPreprocessorFunctionStyleMacroDefinition)macros[0]).getParameters();
|
||||||
|
assertNotNull( parms );
|
||||||
|
assertEquals( parms.length, 1 );
|
||||||
|
assertEquals( parms[0].getParameter(), "WOOBAH" ); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param declarator
|
* @param declarator
|
||||||
* @param offset
|
* @param offset
|
||||||
|
|
|
@ -15,6 +15,8 @@ package org.eclipse.cdt.core.dom.ast;
|
||||||
*/
|
*/
|
||||||
public interface IASTFunctionStyleMacroParameter extends IASTNode {
|
public interface IASTFunctionStyleMacroParameter extends IASTNode {
|
||||||
|
|
||||||
|
public static final IASTFunctionStyleMacroParameter[] EMPTY_PARAMETER_ARRAY = new IASTFunctionStyleMacroParameter[0];
|
||||||
|
|
||||||
public String getParameter();
|
public String getParameter();
|
||||||
public void setParameter( String value );
|
public void setParameter( String value );
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,14 @@ package org.eclipse.cdt.core.dom.ast;
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
public interface IASTPreprocessorFunctionStyleMacroDefinition extends IASTPreprocessorMacroDefinition {
|
public interface IASTPreprocessorFunctionStyleMacroDefinition extends
|
||||||
|
IASTPreprocessorMacroDefinition {
|
||||||
|
|
||||||
|
public static final ASTNodeProperty PARAMETER = new ASTNodeProperty(
|
||||||
|
"Function Macro Parameter"); //$NON-NLS-1$
|
||||||
|
|
||||||
public IASTFunctionStyleMacroParameter[] getParameters();
|
public IASTFunctionStyleMacroParameter[] getParameters();
|
||||||
|
|
||||||
public void addParameter(IASTFunctionStyleMacroParameter parm);
|
public void addParameter(IASTFunctionStyleMacroParameter parm);
|
||||||
|
|
||||||
}
|
}
|
|
@ -112,12 +112,12 @@ public class DOMScanner extends BaseScanner {
|
||||||
protected void processMacro(char[] name, int startingOffset,
|
protected void processMacro(char[] name, int startingOffset,
|
||||||
int startingLineNumber, int idstart, int idend, int nameLine,
|
int startingLineNumber, int idstart, int idend, int nameLine,
|
||||||
int textEnd, int endingLine, IMacro macro) {
|
int textEnd, int endingLine, IMacro macro) {
|
||||||
if (macro instanceof ObjectStyleMacro)
|
if (macro instanceof FunctionStyleMacro)
|
||||||
locationMap.defineObjectStyleMacro((ObjectStyleMacro) macro,
|
|
||||||
startingOffset, idstart, idend, textEnd);
|
|
||||||
else if (macro instanceof FunctionStyleMacro)
|
|
||||||
locationMap.defineFunctionStyleMacro((FunctionStyleMacro) macro,
|
locationMap.defineFunctionStyleMacro((FunctionStyleMacro) macro,
|
||||||
startingOffset, idstart, idend, textEnd);
|
startingOffset, idstart, idend, textEnd);
|
||||||
|
else if (macro instanceof ObjectStyleMacro)
|
||||||
|
locationMap.defineObjectStyleMacro((ObjectStyleMacro) macro,
|
||||||
|
startingOffset, idstart, idend, textEnd);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,14 +16,14 @@ import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorObjectStyleMacroDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorObjectStyleMacroDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
@ -51,7 +51,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
this.path = cs;
|
this.path = cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement#getPath()
|
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement#getPath()
|
||||||
*/
|
*/
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
|
@ -59,63 +61,105 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
public static class ASTFunctionMacro extends ScannerASTNode implements
|
public static class ASTFunctionMacro extends ScannerASTNode implements
|
||||||
IASTPreprocessorFunctionStyleMacroDefinition {
|
IASTPreprocessorFunctionStyleMacroDefinition {
|
||||||
|
|
||||||
/* (non-Javadoc)
|
private IASTName name;
|
||||||
|
private String expansion;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroDefinition#getParameters()
|
* @see org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroDefinition#getParameters()
|
||||||
*/
|
*/
|
||||||
public IASTFunctionStyleMacroParameter[] getParameters() {
|
public IASTFunctionStyleMacroParameter[] getParameters() {
|
||||||
// TODO Auto-generated method stub
|
if (parameters == null)
|
||||||
return null;
|
return IASTFunctionStyleMacroParameter.EMPTY_PARAMETER_ARRAY;
|
||||||
|
removeNullParameters();
|
||||||
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroDefinition#addParameter(org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter)
|
* @see org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroDefinition#addParameter(org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter)
|
||||||
*/
|
*/
|
||||||
public void addParameter(IASTFunctionStyleMacroParameter parm) {
|
public void addParameter(IASTFunctionStyleMacroParameter parm) {
|
||||||
// TODO Auto-generated method stub
|
if (parameters == null) {
|
||||||
|
parameters = new IASTFunctionStyleMacroParameter[DEFAULT_PARMS_LIST_SIZE];
|
||||||
|
currentIndex = 0;
|
||||||
|
}
|
||||||
|
if (parameters.length == currentIndex) {
|
||||||
|
IASTFunctionStyleMacroParameter[] old = parameters;
|
||||||
|
parameters = new IASTFunctionStyleMacroParameter[old.length * 2];
|
||||||
|
for (int i = 0; i < old.length; ++i)
|
||||||
|
parameters[i] = old[i];
|
||||||
|
}
|
||||||
|
parameters[currentIndex++] = parm;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
private void removeNullParameters() {
|
||||||
|
int nullCount = 0;
|
||||||
|
for (int i = 0; i < parameters.length; ++i)
|
||||||
|
if (parameters[i] == null)
|
||||||
|
++nullCount;
|
||||||
|
if (nullCount == 0)
|
||||||
|
return;
|
||||||
|
IASTFunctionStyleMacroParameter[] old = parameters;
|
||||||
|
int newSize = old.length - nullCount;
|
||||||
|
parameters = new IASTFunctionStyleMacroParameter[newSize];
|
||||||
|
for (int i = 0; i < newSize; ++i)
|
||||||
|
parameters[i] = old[i];
|
||||||
|
currentIndex = newSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int currentIndex = 0;
|
||||||
|
private IASTFunctionStyleMacroParameter[] parameters = null;
|
||||||
|
private static final int DEFAULT_PARMS_LIST_SIZE = 2;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getName()
|
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getName()
|
||||||
*/
|
*/
|
||||||
public IASTName getName() {
|
public IASTName getName() {
|
||||||
// TODO Auto-generated method stub
|
return name;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setName(org.eclipse.cdt.core.dom.ast.IASTName)
|
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setName(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||||
*/
|
*/
|
||||||
public void setName(IASTName name) {
|
public void setName(IASTName name) {
|
||||||
// TODO Auto-generated method stub
|
this.name = name;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getExpansion()
|
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getExpansion()
|
||||||
*/
|
*/
|
||||||
public String getExpansion() {
|
public String getExpansion() {
|
||||||
// TODO Auto-generated method stub
|
return expansion;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setExpansion(java.lang.String)
|
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setExpansion(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public void setExpansion(String exp) {
|
public void setExpansion(String exp) {
|
||||||
// TODO Auto-generated method stub
|
this.expansion = exp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public static class ScannerASTNode extends ASTNode
|
|
||||||
{
|
public static class ScannerASTNode extends ASTNode {
|
||||||
private IASTNode parent;
|
private IASTNode parent;
|
||||||
private ASTNodeProperty property;
|
private ASTNodeProperty property;
|
||||||
|
|
||||||
|
@ -123,56 +167,64 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
/* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getPropertyInParent()
|
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getPropertyInParent()
|
||||||
*/
|
*/
|
||||||
public ASTNodeProperty getPropertyInParent() {
|
public ASTNodeProperty getPropertyInParent() {
|
||||||
return property;
|
return property;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setParent(org.eclipse.cdt.core.dom.ast.IASTNode)
|
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setParent(org.eclipse.cdt.core.dom.ast.IASTNode)
|
||||||
*/
|
*/
|
||||||
public void setParent(IASTNode parent) {
|
public void setParent(IASTNode parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setPropertyInParent(org.eclipse.cdt.core.dom.ast.IASTNodeProperty)
|
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setPropertyInParent(org.eclipse.cdt.core.dom.ast.IASTNodeProperty)
|
||||||
*/
|
*/
|
||||||
public void setPropertyInParent(ASTNodeProperty property) {
|
public void setPropertyInParent(ASTNodeProperty property) {
|
||||||
this.property = property;
|
this.property = property;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
/* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getTranslationUnit()
|
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getTranslationUnit()
|
||||||
*/
|
*/
|
||||||
public IASTTranslationUnit getTranslationUnit() {
|
public IASTTranslationUnit getTranslationUnit() {
|
||||||
if( this instanceof IASTTranslationUnit ) return (IASTTranslationUnit) this;
|
if (this instanceof IASTTranslationUnit)
|
||||||
|
return (IASTTranslationUnit) this;
|
||||||
IASTNode node = getParent();
|
IASTNode node = getParent();
|
||||||
while( ! (node instanceof IASTTranslationUnit ) && node != null )
|
while (!(node instanceof IASTTranslationUnit) && node != null) {
|
||||||
{
|
|
||||||
node = node.getParent();
|
node = node.getParent();
|
||||||
}
|
}
|
||||||
return (IASTTranslationUnit) node;
|
return (IASTTranslationUnit) node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
public static class ScannerASTName extends ScannerASTNode implements IASTName {
|
public static class ScannerASTName extends ScannerASTNode implements
|
||||||
|
IASTName {
|
||||||
private final char[] name;
|
private final char[] name;
|
||||||
|
|
||||||
public ScannerASTName( char [] n )
|
public ScannerASTName(char[] n) {
|
||||||
{
|
|
||||||
this.name = n;
|
this.name = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding()
|
* @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding()
|
||||||
*/
|
*/
|
||||||
public IBinding resolveBinding() {
|
public IBinding resolveBinding() {
|
||||||
|
@ -180,20 +232,25 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTName#toCharArray()
|
* @see org.eclipse.cdt.core.dom.ast.IASTName#toCharArray()
|
||||||
*/
|
*/
|
||||||
public char[] toCharArray() {
|
public char[] toCharArray() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new String(name);
|
return new String(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
|
@ -203,14 +260,18 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
private IASTName name;
|
private IASTName name;
|
||||||
private String expansion;
|
private String expansion;
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getName()
|
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getName()
|
||||||
*/
|
*/
|
||||||
public IASTName getName() {
|
public IASTName getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setName(org.eclipse.cdt.core.dom.ast.IASTName)
|
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setName(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||||
*/
|
*/
|
||||||
public void setName(IASTName name) {
|
public void setName(IASTName name) {
|
||||||
|
@ -218,14 +279,18 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getExpansion()
|
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getExpansion()
|
||||||
*/
|
*/
|
||||||
public String getExpansion() {
|
public String getExpansion() {
|
||||||
return expansion;
|
return expansion;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setExpansion(java.lang.String)
|
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setExpansion(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public void setExpansion(String exp) {
|
public void setExpansion(String exp) {
|
||||||
|
@ -233,6 +298,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Location implements IASTNodeLocation {
|
public static class Location implements IASTNodeLocation {
|
||||||
private final int nodeOffset;
|
private final int nodeOffset;
|
||||||
private final int nodeLength;
|
private final int nodeLength;
|
||||||
|
@ -266,6 +332,30 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ASTFunctionMacroParameter extends ScannerASTNode
|
||||||
|
implements IASTFunctionStyleMacroParameter {
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter#getParameter()
|
||||||
|
*/
|
||||||
|
public String getParameter() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter#setParameter(java.lang.String)
|
||||||
|
*/
|
||||||
|
public void setParameter(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static class FileLocation extends Location implements
|
public static class FileLocation extends Location implements
|
||||||
IASTFileLocation {
|
IASTFileLocation {
|
||||||
|
|
||||||
|
@ -348,8 +438,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
protected static class _Inclusion extends _CompositeContext {
|
protected static class _Inclusion extends _CompositeContext {
|
||||||
public final CodeReader reader;
|
public final CodeReader reader;
|
||||||
|
|
||||||
public _Inclusion(_CompositeContext parent, CodeReader reader, int startOffset,
|
public _Inclusion(_CompositeContext parent, CodeReader reader,
|
||||||
int endOffset) {
|
int startOffset, int endOffset) {
|
||||||
super(parent, startOffset, endOffset);
|
super(parent, startOffset, endOffset);
|
||||||
this.reader = reader;
|
this.reader = reader;
|
||||||
}
|
}
|
||||||
|
@ -368,16 +458,17 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class _MacroDefinition extends _Context
|
protected static class _MacroDefinition extends _Context {
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param parent
|
* @param parent
|
||||||
* @param startOffset
|
* @param startOffset
|
||||||
* @param endOffset
|
* @param endOffset
|
||||||
* @param nameOffset TODO
|
* @param nameOffset
|
||||||
|
* TODO
|
||||||
*/
|
*/
|
||||||
public _MacroDefinition(_CompositeContext parent, int startOffset, int endOffset, char[] name, int nameOffset, char[] expansion) {
|
public _MacroDefinition(_CompositeContext parent, int startOffset,
|
||||||
|
int endOffset, char[] name, int nameOffset, char[] expansion) {
|
||||||
super(parent, startOffset, endOffset);
|
super(parent, startOffset, endOffset);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.expansion = expansion;
|
this.expansion = expansion;
|
||||||
|
@ -389,38 +480,41 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
public final int nameOffset;
|
public final int nameOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class _ObjectMacroDefinition extends _MacroDefinition
|
protected static class _ObjectMacroDefinition extends _MacroDefinition {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @param parent
|
* @param parent
|
||||||
* @param startOffset
|
* @param startOffset
|
||||||
* @param endOffset
|
* @param endOffset
|
||||||
* @param name TODO
|
* @param name
|
||||||
* @param expansion TODO
|
* TODO
|
||||||
|
* @param expansion
|
||||||
|
* TODO
|
||||||
*/
|
*/
|
||||||
public _ObjectMacroDefinition(_CompositeContext parent, int startOffset, int endOffset, char[] name, int nameOffset, char[] expansion) {
|
public _ObjectMacroDefinition(_CompositeContext parent, int startOffset,
|
||||||
|
int endOffset, char[] name, int nameOffset, char[] expansion) {
|
||||||
super(parent, startOffset, endOffset, name, nameOffset, expansion);
|
super(parent, startOffset, endOffset, name, nameOffset, expansion);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class _FunctionMacroDefinition extends _MacroDefinition
|
protected static class _FunctionMacroDefinition extends _MacroDefinition {
|
||||||
{
|
|
||||||
|
|
||||||
public final char[][] parms;
|
public final char[][] parms;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param parent
|
* @param parent
|
||||||
* @param startOffset
|
* @param startOffset
|
||||||
* @param endOffset
|
* @param endOffset
|
||||||
* @param parameters
|
* @param parameters
|
||||||
*/
|
*/
|
||||||
public _FunctionMacroDefinition(_CompositeContext parent, int startOffset, int endOffset, char [] name, int nameOffset, char [] expansion, char[][] parameters ) {
|
public _FunctionMacroDefinition(_CompositeContext parent,
|
||||||
|
int startOffset, int endOffset, char[] name, int nameOffset,
|
||||||
|
char[] expansion, char[][] parameters) {
|
||||||
super(parent, startOffset, endOffset, name, nameOffset, expansion);
|
super(parent, startOffset, endOffset, name, nameOffset, expansion);
|
||||||
this.parms = parameters;
|
this.parms = parameters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static class _Problem extends _Context {
|
protected static class _Problem extends _Context {
|
||||||
public final IASTProblem problem;
|
public final IASTProblem problem;
|
||||||
|
|
||||||
|
@ -440,7 +534,6 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
protected _TranslationUnit tu;
|
protected _TranslationUnit tu;
|
||||||
protected _CompositeContext currentContext;
|
protected _CompositeContext currentContext;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -462,17 +555,25 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
LocationMap.collectContexts(V_MACRODEFS, tu, contexts);
|
LocationMap.collectContexts(V_MACRODEFS, tu, contexts);
|
||||||
if (contexts.isEmpty())
|
if (contexts.isEmpty())
|
||||||
return EMPTY_MACRO_DEFINITIONS_ARRAY;
|
return EMPTY_MACRO_DEFINITIONS_ARRAY;
|
||||||
IASTPreprocessorMacroDefinition[] result = new IASTPreprocessorMacroDefinition[contexts.size()];
|
IASTPreprocessorMacroDefinition[] result = new IASTPreprocessorMacroDefinition[contexts
|
||||||
for (int i = 0; i < contexts.size(); ++i)
|
.size()];
|
||||||
{
|
for (int i = 0; i < contexts.size(); ++i) {
|
||||||
_MacroDefinition d = (_MacroDefinition) contexts.get(i);
|
_MacroDefinition d = (_MacroDefinition) contexts.get(i);
|
||||||
IASTPreprocessorMacroDefinition r = null;
|
IASTPreprocessorMacroDefinition r = null;
|
||||||
if (d instanceof _ObjectMacroDefinition)
|
if (d instanceof _ObjectMacroDefinition)
|
||||||
r = new ASTObjectMacro();
|
r = new ASTObjectMacro();
|
||||||
else if ( d instanceof _FunctionMacroDefinition )
|
else if (d instanceof _FunctionMacroDefinition) {
|
||||||
{
|
|
||||||
IASTPreprocessorFunctionStyleMacroDefinition f = new ASTFunctionMacro();
|
IASTPreprocessorFunctionStyleMacroDefinition f = new ASTFunctionMacro();
|
||||||
//TODO parms
|
char[][] parms = ((_FunctionMacroDefinition) d).parms;
|
||||||
|
for (int j = 0; j < parms.length; ++j) {
|
||||||
|
if( parms[j] == null ) continue;
|
||||||
|
IASTFunctionStyleMacroParameter parm = new ASTFunctionMacroParameter();
|
||||||
|
parm.setParameter(new String(parms[j]));
|
||||||
|
f.addParameter(parm);
|
||||||
|
parm.setParent(f);
|
||||||
|
parm
|
||||||
|
.setPropertyInParent(IASTPreprocessorFunctionStyleMacroDefinition.PARAMETER);
|
||||||
|
}
|
||||||
r = f;
|
r = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,12 +581,14 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
name.setPropertyInParent(IASTPreprocessorMacroDefinition.MACRO_NAME);
|
name.setPropertyInParent(IASTPreprocessorMacroDefinition.MACRO_NAME);
|
||||||
name.setParent(r);
|
name.setParent(r);
|
||||||
r.setName(name);
|
r.setName(name);
|
||||||
r.setExpansion( new String( ((_ObjectMacroDefinition)d).expansion ) );
|
r.setExpansion(new String(d.expansion));
|
||||||
((ScannerASTNode)r).setOffsetAndLength( d.context_directive_start, d.context_directive_end - d.context_directive_start );
|
((ScannerASTNode) r).setOffsetAndLength(d.context_directive_start,
|
||||||
|
d.context_directive_end - d.context_directive_start);
|
||||||
result[i] = r;
|
result[i] = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result; }
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
@ -495,13 +598,16 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
|
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
|
||||||
List contexts = new ArrayList(8);
|
List contexts = new ArrayList(8);
|
||||||
collectContexts(V_INCLUSIONS, tu, contexts);
|
collectContexts(V_INCLUSIONS, tu, contexts);
|
||||||
if( contexts.isEmpty() ) return EMPTY_INCLUDES_ARRAY;
|
if (contexts.isEmpty())
|
||||||
IASTPreprocessorIncludeStatement [] result = new IASTPreprocessorIncludeStatement[ contexts.size() ];
|
return EMPTY_INCLUDES_ARRAY;
|
||||||
for( int i = 0; i < contexts.size(); ++i )
|
IASTPreprocessorIncludeStatement[] result = new IASTPreprocessorIncludeStatement[contexts
|
||||||
{
|
.size()];
|
||||||
|
for (int i = 0; i < contexts.size(); ++i) {
|
||||||
_Inclusion inc = ((_Inclusion) contexts.get(i));
|
_Inclusion inc = ((_Inclusion) contexts.get(i));
|
||||||
result[i] = new _InclusionStatement(inc.reader.filename);
|
result[i] = new _InclusionStatement(inc.reader.filename);
|
||||||
((ScannerASTNode)result[i]).setOffsetAndLength( inc.context_directive_start, inc.context_directive_end - inc.context_directive_start );
|
((ScannerASTNode) result[i]).setOffsetAndLength(
|
||||||
|
inc.context_directive_start, inc.context_directive_end
|
||||||
|
- inc.context_directive_start);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -542,14 +648,13 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
int length) {
|
int length) {
|
||||||
IASTNodeLocation[] result = new IASTNodeLocation[1];
|
IASTNodeLocation[] result = new IASTNodeLocation[1];
|
||||||
if (c instanceof _TranslationUnit) {
|
if (c instanceof _TranslationUnit) {
|
||||||
result[0] = new FileLocation(((_TranslationUnit) c).reader.filename, reconcileOffset( c, offset ),
|
result[0] = new FileLocation(((_TranslationUnit) c).reader.filename,
|
||||||
length);
|
reconcileOffset(c, offset), length);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if( c instanceof _Inclusion )
|
if (c instanceof _Inclusion) {
|
||||||
{
|
result[0] = new FileLocation(((_Inclusion) c).reader.filename,
|
||||||
result[0] = new FileLocation(((_Inclusion) c).reader.filename, reconcileOffset( c, offset ),
|
reconcileOffset(c, offset), length);
|
||||||
length);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return EMPTY_LOCATION_ARRAY;
|
return EMPTY_LOCATION_ARRAY;
|
||||||
|
@ -562,11 +667,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
*/
|
*/
|
||||||
protected static int reconcileOffset(_Context c, int offset) {
|
protected static int reconcileOffset(_Context c, int offset) {
|
||||||
int subtractOff = 0;
|
int subtractOff = 0;
|
||||||
if( c instanceof _CompositeContext )
|
if (c instanceof _CompositeContext) {
|
||||||
{
|
|
||||||
List subs = ((_CompositeContext) c).getSubContexts();
|
List subs = ((_CompositeContext) c).getSubContexts();
|
||||||
for( int i = 0; i < subs.size(); ++i )
|
for (int i = 0; i < subs.size(); ++i) {
|
||||||
{
|
|
||||||
_Context subC = (_Context) subs.get(i);
|
_Context subC = (_Context) subs.get(i);
|
||||||
if (subC.context_ends < offset)
|
if (subC.context_ends < offset)
|
||||||
subtractOff += subC.context_ends - subC.context_directive_end;
|
subtractOff += subC.context_ends - subC.context_directive_end;
|
||||||
|
@ -587,8 +690,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
|
|
||||||
protected static _Context findContextForOffset(_CompositeContext context,
|
protected static _Context findContextForOffset(_CompositeContext context,
|
||||||
int offset) {
|
int offset) {
|
||||||
if (!context.hasSubContexts() )
|
if (!context.hasSubContexts()) {
|
||||||
{
|
|
||||||
if (context.context_ends >= offset)
|
if (context.context_ends >= offset)
|
||||||
return context;
|
return context;
|
||||||
return null;
|
return null;
|
||||||
|
@ -651,8 +753,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
* int)
|
* int)
|
||||||
*/
|
*/
|
||||||
public void startInclusion(CodeReader reader, int offset, int endOffset) {
|
public void startInclusion(CodeReader reader, int offset, int endOffset) {
|
||||||
_Inclusion i = new _Inclusion(currentContext, reader, offset,
|
_Inclusion i = new _Inclusion(currentContext, reader, offset, endOffset);
|
||||||
endOffset);
|
|
||||||
currentContext.addSubContext(i);
|
currentContext.addSubContext(i);
|
||||||
currentContext = i;
|
currentContext = i;
|
||||||
}
|
}
|
||||||
|
@ -722,7 +823,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
*/
|
*/
|
||||||
public void defineObjectStyleMacro(ObjectStyleMacro m, int startOffset,
|
public void defineObjectStyleMacro(ObjectStyleMacro m, int startOffset,
|
||||||
int nameOffset, int nameEndOffset, int endOffset) {
|
int nameOffset, int nameEndOffset, int endOffset) {
|
||||||
currentContext.addSubContext(new _ObjectMacroDefinition( currentContext, startOffset, endOffset, m.name, nameOffset, m.expansion ));
|
currentContext.addSubContext(new _ObjectMacroDefinition(currentContext,
|
||||||
|
startOffset, endOffset, m.name, nameOffset, m.expansion));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -733,7 +835,10 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
*/
|
*/
|
||||||
public void defineFunctionStyleMacro(FunctionStyleMacro m, int startOffset,
|
public void defineFunctionStyleMacro(FunctionStyleMacro m, int startOffset,
|
||||||
int nameOffset, int nameEndOffset, int endOffset) {
|
int nameOffset, int nameEndOffset, int endOffset) {
|
||||||
currentContext.addSubContext(new _FunctionMacroDefinition( currentContext, startOffset, endOffset, m.name, nameOffset, m.expansion, m.arglist ));
|
currentContext
|
||||||
|
.addSubContext(new _FunctionMacroDefinition(currentContext,
|
||||||
|
startOffset, endOffset, m.name, nameOffset, m.expansion,
|
||||||
|
m.arglist));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Reference in a new issue