mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
IASTTranslationUnit#getAllPreprocessorStatements() is now implemented.
This commit is contained in:
parent
8b9f51bf19
commit
131e9d4d75
11 changed files with 2026 additions and 1641 deletions
|
@ -31,9 +31,13 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorEndifStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfndefStatement;
|
||||
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.IASTPreprocessorUndefStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
||||
|
@ -55,6 +59,7 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
public class DOMLocationTests extends AST2BaseTest {
|
||||
|
||||
private static final String _TEXT_ = "<text>"; //$NON-NLS-1$
|
||||
|
||||
public void testBaseCase() throws ParserException {
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
|
@ -80,7 +85,7 @@ public class DOMLocationTests extends AST2BaseTest {
|
|||
}
|
||||
|
||||
public void testSimpleDeclaration() throws ParserException {
|
||||
String code ="int xLen5, * yLength8, zLength16( int );"; //$NON-NLS-1$
|
||||
String code = "int xLen5, * yLength8, zLength16( int );"; //$NON-NLS-1$
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
IASTTranslationUnit tu = parse(code, p);
|
||||
|
@ -94,22 +99,24 @@ public class DOMLocationTests extends AST2BaseTest {
|
|||
IASTFileLocation fileLocation = ((IASTFileLocation) nodeLocations[0]);
|
||||
assertEquals(fileLocation.getFileName(), _TEXT_); //$NON-NLS-1$
|
||||
assertEquals(fileLocation.getNodeOffset(), 0);
|
||||
assertEquals(fileLocation.getNodeLength(), code.indexOf( ";") + 1); //$NON-NLS-1$
|
||||
assertEquals(fileLocation.getNodeLength(), code.indexOf(";") + 1); //$NON-NLS-1$
|
||||
IASTDeclarator[] declarators = declaration.getDeclarators();
|
||||
assertEquals( declarators.length, 3 );
|
||||
for( int i = 0; i < 3; ++i )
|
||||
{
|
||||
assertEquals(declarators.length, 3);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
IASTDeclarator declarator = declarators[i];
|
||||
switch( i )
|
||||
{
|
||||
switch (i) {
|
||||
case 0:
|
||||
assertSoleLocation( declarator, code.indexOf( "xLen5"), "xLen5".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertSoleLocation(declarator,
|
||||
code.indexOf("xLen5"), "xLen5".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
break;
|
||||
case 1:
|
||||
assertSoleLocation( declarator, code.indexOf( "* yLength8"), "* yLength8".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertSoleLocation(declarator,
|
||||
code.indexOf("* yLength8"), "* yLength8".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
break;
|
||||
case 2:
|
||||
assertSoleLocation( declarator, code.indexOf( "zLength16( int )"), "zLength16( int )".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertSoleLocation(
|
||||
declarator,
|
||||
code.indexOf("zLength16( int )"), "zLength16( int )".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -117,25 +124,25 @@ public class DOMLocationTests extends AST2BaseTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
: null) {
|
||||
IASTTranslationUnit tu = parse(code, p);
|
||||
IASTDeclaration[] declarations = tu.getDeclarations();
|
||||
assertEquals(declarations.length, 0);
|
||||
IASTPreprocessorMacroDefinition [] macros = tu.getMacroDefinitions();
|
||||
assertNotNull( macros );
|
||||
assertEquals( macros.length, 1 );
|
||||
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].getExpansion(), "0x01"); //$NON-NLS-1$
|
||||
IASTPreprocessorMacroDefinition[] macros = tu.getMacroDefinitions();
|
||||
assertNotNull(macros);
|
||||
assertEquals(macros.length, 1);
|
||||
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].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
|
||||
|
@ -143,17 +150,20 @@ public class DOMLocationTests extends AST2BaseTest {
|
|||
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$
|
||||
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$
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -164,122 +174,142 @@ public class DOMLocationTests extends AST2BaseTest {
|
|||
* @param length
|
||||
*/
|
||||
private void assertSoleLocation(IASTNode n, int offset, int length) {
|
||||
IASTNodeLocation [] locations = n.getNodeLocations();
|
||||
assertEquals( 1, locations.length );
|
||||
IASTNodeLocation[] locations = n.getNodeLocations();
|
||||
assertEquals(1, locations.length);
|
||||
IASTNodeLocation nodeLocation = locations[0];
|
||||
assertEquals( offset, nodeLocation.getNodeOffset() );
|
||||
assertEquals( length, nodeLocation.getNodeLength() );
|
||||
assertEquals(offset, nodeLocation.getNodeOffset());
|
||||
assertEquals(length, nodeLocation.getNodeLength());
|
||||
}
|
||||
|
||||
public void testBug83664() throws Exception {
|
||||
String code = "int foo(x) int x; {\n return x;\n }\n"; //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( code, ParserLanguage.C );
|
||||
IASTDeclaration [] declarations = tu.getDeclarations();
|
||||
assertEquals( declarations.length, 1 );
|
||||
IASTTranslationUnit tu = parse(code, ParserLanguage.C);
|
||||
IASTDeclaration[] declarations = tu.getDeclarations();
|
||||
assertEquals(declarations.length, 1);
|
||||
IASTFunctionDefinition definition = (IASTFunctionDefinition) declarations[0];
|
||||
IASTFunctionDeclarator declarator = definition.getDeclarator();
|
||||
assertSoleLocation( declarator, code.indexOf( "foo" ), code.indexOf( "int x;") + 6 - code.indexOf( "foo")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
IASTCompoundStatement body = (IASTCompoundStatement) definition.getBody();
|
||||
assertEquals( body.getStatements().length, 1 );
|
||||
IASTReturnStatement returnStatement= (IASTReturnStatement) body.getStatements()[0];
|
||||
IASTIdExpression expression = (IASTIdExpression) returnStatement.getReturnValue();
|
||||
assertSoleLocation( expression, code.indexOf( "return ") + "return ".length(), 1 ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertSoleLocation(
|
||||
declarator,
|
||||
code.indexOf("foo"), code.indexOf("int x;") + 6 - code.indexOf("foo")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
IASTCompoundStatement body = (IASTCompoundStatement) definition
|
||||
.getBody();
|
||||
assertEquals(body.getStatements().length, 1);
|
||||
IASTReturnStatement returnStatement = (IASTReturnStatement) body
|
||||
.getStatements()[0];
|
||||
IASTIdExpression expression = (IASTIdExpression) returnStatement
|
||||
.getReturnValue();
|
||||
assertSoleLocation(expression,
|
||||
code.indexOf("return ") + "return ".length(), 1); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
public void testBug84343() throws Exception {
|
||||
String code = "class A {}; int f() {\nA * b = 0;\nreturn b;}"; //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( code, ParserLanguage.CPP );
|
||||
IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[1];
|
||||
IASTDeclarationStatement ds = (IASTDeclarationStatement) ((IASTCompoundStatement)f.getBody()).getStatements()[0];
|
||||
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
|
||||
IASTFunctionDefinition f = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[1];
|
||||
IASTDeclarationStatement ds = (IASTDeclarationStatement) ((IASTCompoundStatement) f
|
||||
.getBody()).getStatements()[0];
|
||||
IASTSimpleDeclaration b = (IASTSimpleDeclaration) ds.getDeclaration();
|
||||
ICPPASTNamedTypeSpecifier namedTypeSpec = (ICPPASTNamedTypeSpecifier) b.getDeclSpecifier();
|
||||
assertSoleLocation( namedTypeSpec, code.indexOf( "\nA") + 1, 1 ); //$NON-NLS-1$
|
||||
ICPPASTNamedTypeSpecifier namedTypeSpec = (ICPPASTNamedTypeSpecifier) b
|
||||
.getDeclSpecifier();
|
||||
assertSoleLocation(namedTypeSpec, code.indexOf("\nA") + 1, 1); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testBug84366() throws Exception {
|
||||
String code = "enum hue { red, blue, green };"; //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( code, ParserLanguage.CPP );
|
||||
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
|
||||
IASTSimpleDeclaration d = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTEnumerationSpecifier enum = (IASTEnumerationSpecifier) d.getDeclSpecifier();
|
||||
IASTEnumerationSpecifier.IASTEnumerator enumerator = enum.getEnumerators()[0];
|
||||
assertSoleLocation( enumerator, code.indexOf( "red"), "red".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IASTEnumerationSpecifier enum = (IASTEnumerationSpecifier) d
|
||||
.getDeclSpecifier();
|
||||
IASTEnumerationSpecifier.IASTEnumerator enumerator = enum
|
||||
.getEnumerators()[0];
|
||||
assertSoleLocation(enumerator, code.indexOf("red"), "red".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
public void testBug84375() throws Exception {
|
||||
String code = "class D { public: int x; };\nclass C : public virtual D {};"; //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( code, ParserLanguage.CPP );
|
||||
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
|
||||
IASTSimpleDeclaration d2 = (IASTSimpleDeclaration) tu.getDeclarations()[1];
|
||||
ICPPASTCompositeTypeSpecifier classSpec = (ICPPASTCompositeTypeSpecifier) d2.getDeclSpecifier();
|
||||
ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier [] bases = classSpec.getBaseSpecifiers();
|
||||
assertSoleLocation( bases[0], code.indexOf( "public virtual D"), "public virtual D".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
ICPPASTCompositeTypeSpecifier classSpec = (ICPPASTCompositeTypeSpecifier) d2
|
||||
.getDeclSpecifier();
|
||||
ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier [] bases = classSpec
|
||||
.getBaseSpecifiers();
|
||||
assertSoleLocation(bases[0],
|
||||
code.indexOf("public virtual D"), "public virtual D".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
}
|
||||
|
||||
public void testBug84357() throws Exception {
|
||||
String code = "class X { int a;\n};\nint X:: * pmi = &X::a;"; //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( code, ParserLanguage.CPP );
|
||||
IASTSimpleDeclaration pmi = (IASTSimpleDeclaration) tu.getDeclarations()[1];
|
||||
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
|
||||
IASTSimpleDeclaration pmi = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[1];
|
||||
IASTDeclarator d = pmi.getDeclarators()[0];
|
||||
IASTPointerOperator p = d.getPointerOperators()[0];
|
||||
assertSoleLocation( p, code.indexOf( "X:: *") , "X:: *".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertSoleLocation(p, code.indexOf("X:: *"), "X:: *".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
public void testBug84367() throws Exception {
|
||||
String code = "void foo( int );"; //$NON-NLS-1$
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
IASTTranslationUnit tu = parse(code, p);
|
||||
IASTSimpleDeclaration definition = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTStandardFunctionDeclarator declarator = (IASTStandardFunctionDeclarator) definition.getDeclarators()[0];
|
||||
IASTSimpleDeclaration definition = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
IASTStandardFunctionDeclarator declarator = (IASTStandardFunctionDeclarator) definition
|
||||
.getDeclarators()[0];
|
||||
IASTParameterDeclaration parameter = declarator.getParameters()[0];
|
||||
assertSoleLocation( parameter, code.indexOf( "int" ), 3 ); //$NON-NLS-1$
|
||||
assertSoleLocation(parameter, code.indexOf("int"), 3); //$NON-NLS-1$
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void testElaboratedTypeSpecifier() throws ParserException {
|
||||
String code = "/* blah */ struct A anA; /* blah */"; //$NON-NLS-1$
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
IASTTranslationUnit tu = parse(code, p);
|
||||
IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTElaboratedTypeSpecifier elabType = (IASTElaboratedTypeSpecifier) declaration.getDeclSpecifier();
|
||||
assertSoleLocation( elabType, code.indexOf( "struct"), "struct A".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
IASTElaboratedTypeSpecifier elabType = (IASTElaboratedTypeSpecifier) declaration
|
||||
.getDeclSpecifier();
|
||||
assertSoleLocation(elabType,
|
||||
code.indexOf("struct"), "struct A".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testBug83852() throws Exception {
|
||||
String code = "/* blah */ typedef short jc; int x = 4; jc myJc = (jc)x; "; //$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( 3, declarations.length );
|
||||
for( int i = 0; i < 3; ++i )
|
||||
{
|
||||
IASTDeclaration[] declarations = tu.getDeclarations();
|
||||
assertEquals(3, declarations.length);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) declarations[i];
|
||||
int start = 0, length = 0;
|
||||
switch( i )
|
||||
{
|
||||
switch (i) {
|
||||
case 0:
|
||||
start = code.indexOf( "typedef"); //$NON-NLS-1$
|
||||
start = code.indexOf("typedef"); //$NON-NLS-1$
|
||||
length = "typedef short jc;".length(); //$NON-NLS-1$
|
||||
break;
|
||||
case 1:
|
||||
start = code.indexOf( "int x = 4;"); //$NON-NLS-1$
|
||||
start = code.indexOf("int x = 4;"); //$NON-NLS-1$
|
||||
length = "int x = 4;".length(); //$NON-NLS-1$
|
||||
break;
|
||||
case 2:
|
||||
start = code.indexOf( "jc myJc = (jc)x;"); //$NON-NLS-1$
|
||||
start = code.indexOf("jc myJc = (jc)x;"); //$NON-NLS-1$
|
||||
length = "jc myJc = (jc)x;".length(); //$NON-NLS-1$
|
||||
break;
|
||||
}
|
||||
assertSoleLocation( decl, start, length );
|
||||
assertSoleLocation(decl, start, length);
|
||||
}
|
||||
IASTInitializerExpression initializer = (IASTInitializerExpression) ((IASTSimpleDeclaration)declarations[2]).getDeclarators()[0].getInitializer();
|
||||
IASTCastExpression castExpression = (IASTCastExpression) initializer.getExpression();
|
||||
IASTInitializerExpression initializer = (IASTInitializerExpression) ((IASTSimpleDeclaration) declarations[2])
|
||||
.getDeclarators()[0].getInitializer();
|
||||
IASTCastExpression castExpression = (IASTCastExpression) initializer
|
||||
.getExpression();
|
||||
IASTTypeId typeId = castExpression.getTypeId();
|
||||
assertSoleLocation( typeId, code.indexOf( "(jc)") + 1, "jc".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertSoleLocation(typeId, code.indexOf("(jc)") + 1, "jc".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -288,28 +318,41 @@ public class DOMLocationTests extends AST2BaseTest {
|
|||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
IASTTranslationUnit tu = parse(code, p);
|
||||
IASTFunctionDefinition definition = (IASTFunctionDefinition) tu.getDeclarations()[0];
|
||||
IASTCompoundStatement statement = (IASTCompoundStatement) definition.getBody();
|
||||
IASTReturnStatement returnStatement = (IASTReturnStatement) statement.getStatements()[0];
|
||||
IASTUnaryExpression unaryExpression = (IASTUnaryExpression) returnStatement.getReturnValue();
|
||||
assertEquals( unaryExpression.getOperator(), IASTUnaryExpression.op_bracketedPrimary );
|
||||
IASTConditionalExpression conditional = (IASTConditionalExpression) unaryExpression.getOperand();
|
||||
assertSoleLocation( conditional,code.indexOf( "1?0:1"), "1?0:1".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IASTFunctionDefinition definition = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[0];
|
||||
IASTCompoundStatement statement = (IASTCompoundStatement) definition
|
||||
.getBody();
|
||||
IASTReturnStatement returnStatement = (IASTReturnStatement) statement
|
||||
.getStatements()[0];
|
||||
IASTUnaryExpression unaryExpression = (IASTUnaryExpression) returnStatement
|
||||
.getReturnValue();
|
||||
assertEquals(unaryExpression.getOperator(),
|
||||
IASTUnaryExpression.op_bracketedPrimary);
|
||||
IASTConditionalExpression conditional = (IASTConditionalExpression) unaryExpression
|
||||
.getOperand();
|
||||
assertSoleLocation(conditional,
|
||||
code.indexOf("1?0:1"), "1?0:1".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
|
||||
public void testBug84374() throws Exception
|
||||
{
|
||||
public void testBug84374() throws Exception {
|
||||
String code = "class P1 { public: int x; };\nclass P2 { public: int x; };\nclass B : public P1, public P2 {};\nvoid main() {\nB * b = new B();\n}"; //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( code, ParserLanguage.CPP );
|
||||
IASTFunctionDefinition main = (IASTFunctionDefinition) tu.getDeclarations()[3];
|
||||
IASTCompoundStatement statement = (IASTCompoundStatement) main.getBody();
|
||||
IASTDeclarationStatement decl = (IASTDeclarationStatement) statement.getStatements()[0];
|
||||
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
|
||||
IASTFunctionDefinition main = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[3];
|
||||
IASTCompoundStatement statement = (IASTCompoundStatement) main
|
||||
.getBody();
|
||||
IASTDeclarationStatement decl = (IASTDeclarationStatement) statement
|
||||
.getStatements()[0];
|
||||
IASTSimpleDeclaration b = (IASTSimpleDeclaration) decl.getDeclaration();
|
||||
IASTInitializerExpression initializerExpression = (IASTInitializerExpression) b.getDeclarators()[0].getInitializer();
|
||||
assertSoleLocation( initializerExpression, code.indexOf( "new B()"), "new B()".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) initializerExpression.getExpression();
|
||||
assertSoleLocation( newExpression, code.indexOf( "new B()"), "new B()".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IASTInitializerExpression initializerExpression = (IASTInitializerExpression) b
|
||||
.getDeclarators()[0].getInitializer();
|
||||
assertSoleLocation(initializerExpression,
|
||||
code.indexOf("new B()"), "new B()".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) initializerExpression
|
||||
.getExpression();
|
||||
assertSoleLocation(newExpression,
|
||||
code.indexOf("new B()"), "new B()".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
public void testBug83737() throws Exception {
|
||||
|
@ -317,42 +360,84 @@ public class DOMLocationTests extends AST2BaseTest {
|
|||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
IASTTranslationUnit tu = parse(code, p);
|
||||
IASTFunctionDefinition definition = (IASTFunctionDefinition) tu.getDeclarations()[0];
|
||||
IASTCompoundStatement statement = (IASTCompoundStatement) definition.getBody();
|
||||
IASTIfStatement first_if = (IASTIfStatement) statement.getStatements()[0];
|
||||
IASTIfStatement second_if = (IASTIfStatement) first_if.getElseClause();
|
||||
IASTIfStatement third_if = (IASTIfStatement) second_if.getElseClause();
|
||||
assertNull( third_if.getElseClause() );
|
||||
int first_if_start = code.indexOf( "if( a == 0 )" ); //$NON-NLS-1$
|
||||
IASTFunctionDefinition definition = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[0];
|
||||
IASTCompoundStatement statement = (IASTCompoundStatement) definition
|
||||
.getBody();
|
||||
IASTIfStatement first_if = (IASTIfStatement) statement
|
||||
.getStatements()[0];
|
||||
IASTIfStatement second_if = (IASTIfStatement) first_if
|
||||
.getElseClause();
|
||||
IASTIfStatement third_if = (IASTIfStatement) second_if
|
||||
.getElseClause();
|
||||
assertNull(third_if.getElseClause());
|
||||
int first_if_start = code.indexOf("if( a == 0 )"); //$NON-NLS-1$
|
||||
int total_if_length = "if( a == 0 ) g( a ); else if( a < 0 ) g( a >> 1 ); else if( a > 0 ) g( *(&a + 2) );".length(); //$NON-NLS-1$
|
||||
int total_if_end = first_if_start + total_if_length;
|
||||
int second_if_start = code.indexOf( "if( a < 0 )"); //$NON-NLS-1$
|
||||
int third_if_start = code.indexOf( "if( a > 0 )"); //$NON-NLS-1$
|
||||
assertSoleLocation( first_if, first_if_start, total_if_length );
|
||||
assertSoleLocation( second_if, second_if_start, total_if_end - second_if_start );
|
||||
assertSoleLocation( third_if, third_if_start, total_if_end - third_if_start );
|
||||
int second_if_start = code.indexOf("if( a < 0 )"); //$NON-NLS-1$
|
||||
int third_if_start = code.indexOf("if( a > 0 )"); //$NON-NLS-1$
|
||||
assertSoleLocation(first_if, first_if_start, total_if_length);
|
||||
assertSoleLocation(second_if, second_if_start, total_if_end
|
||||
- second_if_start);
|
||||
assertSoleLocation(third_if, third_if_start, total_if_end
|
||||
- third_if_start);
|
||||
}
|
||||
}
|
||||
|
||||
public void testBug84467() throws Exception
|
||||
{
|
||||
public void testBug84467() throws Exception {
|
||||
String code = "class D { };\n D d1;\n const D d2;\n void foo() {\n typeid(d1) == typeid(d2);\n }"; //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( code, ParserLanguage.CPP );
|
||||
IASTBinaryExpression bexp = (IASTBinaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[3]).getBody()).getStatements()[0]).getExpression();
|
||||
IASTTypeIdExpression exp = (IASTTypeIdExpression)((IASTBinaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[3]).getBody()).getStatements()[0]).getExpression()).getOperand1();
|
||||
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
|
||||
IASTBinaryExpression bexp = (IASTBinaryExpression) ((IASTExpressionStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) tu
|
||||
.getDeclarations()[3]).getBody()).getStatements()[0])
|
||||
.getExpression();
|
||||
IASTTypeIdExpression exp = (IASTTypeIdExpression) ((IASTBinaryExpression) ((IASTExpressionStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) tu
|
||||
.getDeclarations()[3]).getBody()).getStatements()[0])
|
||||
.getExpression()).getOperand1();
|
||||
|
||||
assertSoleLocation( bexp, code.indexOf( "typeid(d1) == typeid(d2)"), "typeid(d1) == typeid(d2)".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertSoleLocation( exp, code.indexOf( "typeid(d1)"), "typeid(d1)".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
exp = (IASTTypeIdExpression)((IASTBinaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[3]).getBody()).getStatements()[0]).getExpression()).getOperand2();
|
||||
assertSoleLocation( exp, code.indexOf( "typeid(d2)"), "typeid(d2)".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertSoleLocation(
|
||||
bexp,
|
||||
code.indexOf("typeid(d1) == typeid(d2)"), "typeid(d1) == typeid(d2)".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertSoleLocation(exp,
|
||||
code.indexOf("typeid(d1)"), "typeid(d1)".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
exp = (IASTTypeIdExpression) ((IASTBinaryExpression) ((IASTExpressionStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) tu
|
||||
.getDeclarations()[3]).getBody()).getStatements()[0])
|
||||
.getExpression()).getOperand2();
|
||||
assertSoleLocation(exp,
|
||||
code.indexOf("typeid(d2)"), "typeid(d2)".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
public void testBug84576() throws Exception
|
||||
{
|
||||
public void testBug84576() throws Exception {
|
||||
String code = "namespace A {\n extern \"C\" int g();\n }"; //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( code, ParserLanguage.CPP );
|
||||
ICPPASTLinkageSpecification spec = (ICPPASTLinkageSpecification)((ICPPASTNamespaceDefinition)tu.getDeclarations()[0]).getDeclarations()[0];
|
||||
assertSoleLocation( spec, code.indexOf( "extern \"C\""), "extern \"C\" int g();".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
|
||||
ICPPASTLinkageSpecification spec = (ICPPASTLinkageSpecification) ((ICPPASTNamespaceDefinition) tu
|
||||
.getDeclarations()[0]).getDeclarations()[0];
|
||||
assertSoleLocation(spec,
|
||||
code.indexOf("extern \"C\""), "extern \"C\" int g();".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
public void testSimplePreprocessorStatements() throws Exception
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "#ifndef _APPLE_H_\n"); //$NON-NLS-1$
|
||||
buffer.append( "#define _APPLE_H_\n"); //$NON-NLS-1$
|
||||
buffer.append( "#undef _APPLE_H_\n"); //$NON-NLS-1$
|
||||
buffer.append( "#endif\n"); //$NON-NLS-1$
|
||||
String code = buffer.toString();
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
IASTTranslationUnit tu = parse(code, p);
|
||||
assertEquals( tu.getDeclarations().length, 0 );
|
||||
IASTPreprocessorStatement [] statements = tu.getAllPreprocessorStatements();
|
||||
assertEquals( statements.length, 4 );
|
||||
IASTPreprocessorIfndefStatement ifndef = (IASTPreprocessorIfndefStatement) statements[0];
|
||||
assertTrue( ifndef.taken() );
|
||||
assertSoleLocation( ifndef, code.indexOf( "#ifndef _APPLE_H_"), "#ifndef _APPLE_H_".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IASTPreprocessorObjectStyleMacroDefinition definition = (IASTPreprocessorObjectStyleMacroDefinition) statements[1];
|
||||
assertSoleLocation( definition, code.indexOf( "#define _APPLE_H_"), "#define _APPLE_H_".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IASTPreprocessorUndefStatement undef = (IASTPreprocessorUndefStatement) statements[2];
|
||||
assertSoleLocation( undef, code.indexOf("#undef _APPLE_H_"), "#undef _APPLE_H_".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IASTPreprocessorEndifStatement endif = (IASTPreprocessorEndifStatement) statements[3];
|
||||
assertSoleLocation( endif, code.indexOf( "#endif"), "#endif".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,6 +13,8 @@ package org.eclipse.cdt.core.dom.ast;
|
|||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public interface IASTPreprocessorElsifStatement extends IASTPreprocessorStatement {
|
||||
public interface IASTPreprocessorElifStatement extends IASTPreprocessorStatement {
|
||||
|
||||
public boolean taken();
|
||||
|
||||
}
|
|
@ -15,4 +15,5 @@ package org.eclipse.cdt.core.dom.ast;
|
|||
*/
|
||||
public interface IASTPreprocessorElseStatement extends IASTPreprocessorStatement {
|
||||
|
||||
public boolean taken();
|
||||
}
|
||||
|
|
|
@ -15,4 +15,5 @@ package org.eclipse.cdt.core.dom.ast;
|
|||
*/
|
||||
public interface IASTPreprocessorIfStatement extends IASTPreprocessorStatement {
|
||||
|
||||
public boolean taken();
|
||||
}
|
||||
|
|
|
@ -15,4 +15,5 @@ package org.eclipse.cdt.core.dom.ast;
|
|||
*/
|
||||
public interface IASTPreprocessorIfdefStatement extends IASTPreprocessorStatement {
|
||||
|
||||
public boolean taken();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public interface IASTPreprocessorIfndefStatement extends
|
||||
IASTPreprocessorStatement {
|
||||
|
||||
public boolean taken();
|
||||
}
|
|
@ -174,7 +174,9 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
|||
*/
|
||||
public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
|
||||
if( resolver == null ) return EMPTY_PREPROCESSOR_STATEMENT_ARRAY;
|
||||
return resolver.getAllPreprocessorStatements();
|
||||
IASTPreprocessorStatement [] result = resolver.getAllPreprocessorStatements();
|
||||
setParentRelationship( result, IASTTranslationUnit.PREPROCESSOR_STATEMENT );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -196,7 +196,9 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
|||
public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
|
||||
if (resolver == null)
|
||||
return EMPTY_PREPROCESSOR_STATEMENT_ARRAY;
|
||||
return resolver.getAllPreprocessorStatements();
|
||||
IASTPreprocessorStatement [] result = resolver.getAllPreprocessorStatements();
|
||||
setParentRelationship( result, IASTTranslationUnit.PREPROCESSOR_STATEMENT );
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -2509,7 +2509,7 @@ abstract class BaseScanner implements IScanner {
|
|||
if (!branchState(BRANCH_END))
|
||||
handleProblem(IProblem.PREPROCESSOR_UNBALANCE_CONDITION,
|
||||
start, ppKeywords.findKey(buffer, start, len));
|
||||
processEndif(pos, bufferPos[bufferStackPos]);
|
||||
processEndif(pos, bufferPos[bufferStackPos] + 1);
|
||||
break;
|
||||
case ppPragma:
|
||||
skipToNewLine();
|
||||
|
|
|
@ -20,11 +20,20 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorElseStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorEndifStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorErrorStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfdefStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfndefStatement;
|
||||
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.IASTPreprocessorPragmaStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorUndefStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
@ -37,6 +46,142 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
|||
*/
|
||||
public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
static class ASTEndif extends ScannerASTNode implements
|
||||
IASTPreprocessorEndifStatement {
|
||||
|
||||
}
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
static class ASTElif extends ScannerASTNode implements
|
||||
IASTPreprocessorElifStatement {
|
||||
|
||||
private final boolean taken;
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#taken()
|
||||
*/
|
||||
public boolean taken() {
|
||||
return taken;
|
||||
}
|
||||
/**
|
||||
* @param taken
|
||||
*/
|
||||
public ASTElif(boolean taken) {
|
||||
this.taken = taken;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
static class ASTElse extends ScannerASTNode implements
|
||||
IASTPreprocessorElseStatement {
|
||||
private final boolean taken;
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#taken()
|
||||
*/
|
||||
public boolean taken() {
|
||||
return taken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param taken
|
||||
*/
|
||||
public ASTElse(boolean taken) {
|
||||
this.taken = taken;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
static class ASTIfndef extends ScannerASTNode implements IASTPreprocessorIfndefStatement {
|
||||
|
||||
private final boolean taken;
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#taken()
|
||||
*/
|
||||
public boolean taken() {
|
||||
return taken;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param taken
|
||||
*/
|
||||
public ASTIfndef(boolean taken) {
|
||||
this.taken = taken;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
static class ASTIfdef extends ScannerASTNode implements
|
||||
IASTPreprocessorIfdefStatement {
|
||||
|
||||
private final boolean taken;
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#taken()
|
||||
*/
|
||||
public boolean taken() {
|
||||
return taken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param taken
|
||||
*/
|
||||
public ASTIfdef(boolean taken) {
|
||||
this.taken = taken;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
static class ASTIf extends ScannerASTNode implements
|
||||
IASTPreprocessorIfStatement {
|
||||
|
||||
private final boolean taken;
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#taken()
|
||||
*/
|
||||
public boolean taken() {
|
||||
return taken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param taken
|
||||
*/
|
||||
public ASTIf(boolean taken) {
|
||||
this.taken = taken;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
static class ASTError extends ScannerASTNode implements
|
||||
IASTPreprocessorErrorStatement {
|
||||
|
||||
}
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
static class ASTPragma extends ScannerASTNode implements
|
||||
IASTPreprocessorPragmaStatement {
|
||||
|
||||
}
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
static class ASTUndef extends ScannerASTNode implements
|
||||
IASTPreprocessorUndefStatement {
|
||||
|
||||
}
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
|
@ -197,11 +342,13 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public static class ASTInclusionStatement extends ScannerASTNode
|
||||
implements IASTPreprocessorIncludeStatement {
|
||||
public static class ASTInclusionStatement extends ScannerASTNode implements
|
||||
IASTPreprocessorIncludeStatement {
|
||||
|
||||
private final char[] path;
|
||||
|
||||
public int startOffset;
|
||||
|
||||
public int endOffset;
|
||||
|
||||
/**
|
||||
|
@ -338,7 +485,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
|
||||
}
|
||||
|
||||
private static class ScannerASTNode extends ASTNode {
|
||||
static class ScannerASTNode extends ASTNode {
|
||||
private IASTNode parent;
|
||||
|
||||
private ASTNodeProperty property;
|
||||
|
@ -739,12 +886,10 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
}
|
||||
|
||||
private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0];
|
||||
|
||||
private static final IASTNodeLocation[] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0];
|
||||
|
||||
private static final IASTPreprocessorMacroDefinition[] EMPTY_MACRO_DEFINITIONS_ARRAY = new IASTPreprocessorMacroDefinition[0];
|
||||
|
||||
private static final IASTPreprocessorIncludeStatement[] EMPTY_INCLUDES_ARRAY = new IASTPreprocessorIncludeStatement[0];
|
||||
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_ARRAY = new IASTPreprocessorStatement[0];
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
@ -769,7 +914,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
* @param d
|
||||
* @return
|
||||
*/
|
||||
protected IASTPreprocessorMacroDefinition createASTMacroDefinition(
|
||||
private IASTPreprocessorMacroDefinition createASTMacroDefinition(
|
||||
_MacroDefinition d) {
|
||||
IASTPreprocessorMacroDefinition r = null;
|
||||
if (d instanceof _ObjectMacroDefinition)
|
||||
|
@ -811,15 +956,23 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
_Context[] contexts = new _Context[size];
|
||||
collectContexts(V_INCLUSIONS, tu, contexts, 0);
|
||||
IASTPreprocessorIncludeStatement[] result = new IASTPreprocessorIncludeStatement[size];
|
||||
for (int i = 0; i < size; ++i) {
|
||||
_Inclusion inc = ((_Inclusion) contexts[i]);
|
||||
result[i] = new ASTInclusionStatement(inc.reader.filename);
|
||||
((ScannerASTNode) result[i]).setOffsetAndLength(
|
||||
inc.context_directive_start, inc.context_directive_end
|
||||
- inc.context_directive_start);
|
||||
((ASTInclusionStatement)result[i]).startOffset = inc.context_directive_end;
|
||||
((ASTInclusionStatement)result[i]).endOffset = inc.context_ends;
|
||||
for (int i = 0; i < size; ++i)
|
||||
result[i] = createASTInclusion(((_Inclusion) contexts[i]));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param inc
|
||||
* @return
|
||||
*/
|
||||
private IASTPreprocessorIncludeStatement createASTInclusion(_Inclusion inc) {
|
||||
IASTPreprocessorIncludeStatement result = new ASTInclusionStatement(
|
||||
inc.reader.filename);
|
||||
((ScannerASTNode) result).setOffsetAndLength(inc.context_directive_start,
|
||||
inc.context_directive_end - inc.context_directive_start);
|
||||
((ASTInclusionStatement) result).startOffset = inc.context_directive_end;
|
||||
((ASTInclusionStatement) result).endOffset = inc.context_ends;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -829,8 +982,128 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getAllPreprocessorStatements()
|
||||
*/
|
||||
public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
int size = collectContexts(V_PREPROCESSOR, tu, null, 0);
|
||||
if (size == 0)
|
||||
return EMPTY_PREPROCESSOR_ARRAY;
|
||||
_Context[] contexts = new _Context[size];
|
||||
collectContexts(V_PREPROCESSOR, tu, contexts, 0);
|
||||
IASTPreprocessorStatement[] result = new IASTPreprocessorStatement[size];
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
if( contexts[i] instanceof _Inclusion )
|
||||
result[i] = createASTInclusion(((_Inclusion) contexts[i]));
|
||||
else if( contexts[i] instanceof _MacroDefinition )
|
||||
result[i] = createASTMacroDefinition( (_MacroDefinition) contexts[i] );
|
||||
else if ( contexts[i] instanceof _Undef )
|
||||
result[i] = createASTUndef( (_Undef)contexts[i] );
|
||||
else if ( contexts[i] instanceof _Pragma )
|
||||
result[i] = createASTPragma( (_Pragma)contexts[i]);
|
||||
else if ( contexts[i] instanceof _Error )
|
||||
result[i] = createASTError( (_Error)contexts[i] );
|
||||
else if ( contexts[i] instanceof _If )
|
||||
result[i] = createASTIf( (_If)contexts[i] );
|
||||
else if( contexts[i] instanceof _Ifdef )
|
||||
result[i] = createASTIfdef( (_Ifdef)contexts[i] );
|
||||
else if( contexts[i] instanceof _Ifndef )
|
||||
result[i] = createASTIfndef( (_Ifndef)contexts[i]);
|
||||
else if( contexts[i] instanceof _Else )
|
||||
result[i] = createASTElse( (_Else)contexts[i] );
|
||||
else if ( contexts[i] instanceof _Elif )
|
||||
result[i] = createASTElif( (_Elif)contexts[i] );
|
||||
else if( contexts[i] instanceof _Endif )
|
||||
result[i] = createASTEndif( (_Endif)contexts[i ]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param endif
|
||||
* @return
|
||||
*/
|
||||
private IASTPreprocessorStatement createASTEndif(_Endif endif) {
|
||||
IASTPreprocessorEndifStatement result = new ASTEndif();
|
||||
((ASTNode)result).setOffsetAndLength( endif.context_directive_start, endif.context_directive_end - endif.context_directive_start );
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param elif
|
||||
* @return
|
||||
*/
|
||||
private IASTPreprocessorStatement createASTElif(_Elif elif) {
|
||||
IASTPreprocessorElifStatement result = new ASTElif(elif.taken);
|
||||
((ASTNode)result).setOffsetAndLength( elif.context_directive_start, elif.context_directive_end - elif.context_directive_start);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param else1
|
||||
* @return
|
||||
*/
|
||||
private IASTPreprocessorStatement createASTElse(_Else e) {
|
||||
IASTPreprocessorElseStatement result = new ASTElse(e.taken);
|
||||
((ASTNode)result).setOffsetAndLength( e.context_directive_start, e.context_directive_end- e.context_directive_start );
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ifndef
|
||||
* @return
|
||||
*/
|
||||
private IASTPreprocessorStatement createASTIfndef(_Ifndef ifndef) {
|
||||
IASTPreprocessorIfndefStatement result = new ASTIfndef(ifndef.taken);
|
||||
((ASTNode)result).setOffsetAndLength( ifndef.context_directive_start, ifndef.context_directive_end - ifndef.context_directive_start );
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ifdef
|
||||
* @return
|
||||
*/
|
||||
private IASTPreprocessorStatement createASTIfdef(_Ifdef ifdef) {
|
||||
IASTPreprocessorIfdefStatement result = new ASTIfdef(ifdef.taken);
|
||||
((ASTNode)result).setOffsetAndLength( ifdef.context_directive_start, ifdef.context_directive_end - ifdef.context_directive_start);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param if1
|
||||
* @return
|
||||
*/
|
||||
private IASTPreprocessorStatement createASTIf(_If i ) {
|
||||
IASTPreprocessorIfStatement result = new ASTIf(i.taken);
|
||||
((ASTNode)result).setOffsetAndLength( i.context_directive_start, i.context_directive_end - - i.context_directive_start );
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param error
|
||||
* @return
|
||||
*/
|
||||
private IASTPreprocessorStatement createASTError(_Error error) {
|
||||
IASTPreprocessorErrorStatement result = new ASTError();
|
||||
((ASTNode)result).setOffsetAndLength( error.context_directive_start, error.context_directive_end - error.context_directive_start);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pragma
|
||||
* @return
|
||||
*/
|
||||
private IASTPreprocessorStatement createASTPragma(_Pragma pragma) {
|
||||
IASTPreprocessorPragmaStatement result = new ASTPragma();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param undef
|
||||
* @return
|
||||
*/
|
||||
private IASTPreprocessorStatement createASTUndef(_Undef undef) {
|
||||
IASTPreprocessorUndefStatement result = new ASTUndef();
|
||||
((ASTNode)result).setOffsetAndLength( undef.context_directive_start, undef.context_directive_end - undef.context_directive_start );
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -843,7 +1116,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
if (tu == null)
|
||||
return EMPTY_LOCATION_ARRAY;
|
||||
_Context c = findContextForOffset(offset);
|
||||
if( c == null )
|
||||
if (c == null)
|
||||
return EMPTY_LOCATION_ARRAY;
|
||||
if (c.context_ends >= offset + length)
|
||||
return createSoleLocation(c, offset, length);
|
||||
|
@ -887,17 +1160,16 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
protected int reconcileOffset(_CompositeFileContext fc, _Context c,
|
||||
int offset) {
|
||||
int subtractOff = 0;
|
||||
if( c.parent == fc )
|
||||
{
|
||||
if (c.parent == fc) {
|
||||
List subs = fc.getSubContexts();
|
||||
for( int i = 0; i < subs.size(); ++i )
|
||||
{
|
||||
for (int i = 0; i < subs.size(); ++i) {
|
||||
_Context sample = (_Context) subs.get(i);
|
||||
if( sample == c )
|
||||
if (sample == c)
|
||||
break;
|
||||
if( ! ( sample instanceof _CompositeContext ) )
|
||||
if (!(sample instanceof _CompositeContext))
|
||||
continue;
|
||||
subtractOff += sample.context_ends - sample.context_directive_end;
|
||||
subtractOff += sample.context_ends
|
||||
- sample.context_directive_end;
|
||||
}
|
||||
}
|
||||
return offset - fc.context_directive_end - subtractOff;
|
||||
|
@ -916,11 +1188,10 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
_Context subC = (_Context) subs.get(i);
|
||||
if (subC.context_ends > offset)
|
||||
break;
|
||||
if( !( subC instanceof _CompositeContext ) )
|
||||
if (!(subC instanceof _CompositeContext))
|
||||
continue;
|
||||
|
||||
subtractOff += subC.context_ends
|
||||
- subC.context_directive_end;
|
||||
subtractOff += subC.context_ends - subC.context_directive_end;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue