mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 162180, scanner locations
This commit is contained in:
parent
cfea65c227
commit
92b49872f2
10 changed files with 580 additions and 401 deletions
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM - Initial API and implementation
|
* IBM - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||||
|
|
||||||
|
@ -3379,8 +3380,9 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
buffer.append("((int arg1)){\r\n"); //$NON-NLS-1$
|
buffer.append("((int arg1)){\r\n"); //$NON-NLS-1$
|
||||||
buffer.append("return 0;\r\n"); //$NON-NLS-1$
|
buffer.append("return 0;\r\n"); //$NON-NLS-1$
|
||||||
buffer.append("}\r\n"); //$NON-NLS-1$
|
buffer.append("}\r\n"); //$NON-NLS-1$
|
||||||
parse(buffer.toString(), ParserLanguage.C);
|
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
assertFalse( tu.getDeclarations()[1] instanceof IASTProblemDeclaration );
|
||||||
|
tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||||
assertFalse( tu.getDeclarations()[1] instanceof IASTProblemDeclaration );
|
assertFalse( tu.getDeclarations()[1] instanceof IASTProblemDeclaration );
|
||||||
|
|
||||||
buffer = new StringBuffer();
|
buffer = new StringBuffer();
|
||||||
|
@ -3392,7 +3394,8 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
buffer.append("((int arg1)){\n"); //$NON-NLS-1$
|
buffer.append("((int arg1)){\n"); //$NON-NLS-1$
|
||||||
buffer.append("return 0;\n"); //$NON-NLS-1$
|
buffer.append("return 0;\n"); //$NON-NLS-1$
|
||||||
buffer.append("}\n"); //$NON-NLS-1$
|
buffer.append("}\n"); //$NON-NLS-1$
|
||||||
parse(buffer.toString(), ParserLanguage.C);
|
tu= parse(buffer.toString(), ParserLanguage.C);
|
||||||
|
assertFalse( tu.getDeclarations()[1] instanceof IASTProblemDeclaration );
|
||||||
tu= parse(buffer.toString(), ParserLanguage.CPP);
|
tu= parse(buffer.toString(), ParserLanguage.CPP);
|
||||||
assertFalse( tu.getDeclarations()[1] instanceof IASTProblemDeclaration );
|
assertFalse( tu.getDeclarations()[1] instanceof IASTProblemDeclaration );
|
||||||
}
|
}
|
||||||
|
@ -3407,8 +3410,10 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
buffer.append("((int arg1)){\r\n"); //$NON-NLS-1$
|
buffer.append("((int arg1)){\r\n"); //$NON-NLS-1$
|
||||||
buffer.append("return 0;\r\n"); //$NON-NLS-1$
|
buffer.append("return 0;\r\n"); //$NON-NLS-1$
|
||||||
buffer.append("}\r\n"); //$NON-NLS-1$
|
buffer.append("}\r\n"); //$NON-NLS-1$
|
||||||
parse(buffer.toString(), ParserLanguage.C);
|
IASTTranslationUnit tu= parse(buffer.toString(), ParserLanguage.C);
|
||||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
assertFalse( tu.getDeclarations()[1] instanceof IASTProblemDeclaration );
|
||||||
|
|
||||||
|
tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||||
assertFalse( tu.getDeclarations()[1] instanceof IASTProblemDeclaration );
|
assertFalse( tu.getDeclarations()[1] instanceof IASTProblemDeclaration );
|
||||||
|
|
||||||
buffer = new StringBuffer();
|
buffer = new StringBuffer();
|
||||||
|
@ -3420,7 +3425,8 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
buffer.append("((int arg1)){\n"); //$NON-NLS-1$
|
buffer.append("((int arg1)){\n"); //$NON-NLS-1$
|
||||||
buffer.append("return 0;\n"); //$NON-NLS-1$
|
buffer.append("return 0;\n"); //$NON-NLS-1$
|
||||||
buffer.append("}\n"); //$NON-NLS-1$
|
buffer.append("}\n"); //$NON-NLS-1$
|
||||||
parse(buffer.toString(), ParserLanguage.C);
|
tu = parse(buffer.toString(), ParserLanguage.C);
|
||||||
|
assertFalse( tu.getDeclarations()[1] instanceof IASTProblemDeclaration );
|
||||||
tu = parse(buffer.toString(), ParserLanguage.CPP);
|
tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||||
assertFalse( tu.getDeclarations()[1] instanceof IASTProblemDeclaration );
|
assertFalse( tu.getDeclarations()[1] instanceof IASTProblemDeclaration );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2004, 2005 IBM Corporation and others.
|
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM - Initial API and implementation
|
* IBM - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||||
|
|
||||||
|
@ -214,11 +215,7 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
||||||
IASTPreprocessorIncludeStatement[] incs = tu.getIncludeDirectives();
|
IASTPreprocessorIncludeStatement[] incs = tu.getIncludeDirectives();
|
||||||
assertNotNull(incs);
|
assertNotNull(incs);
|
||||||
assertEquals(incs.length, 1);
|
assertEquals(incs.length, 1);
|
||||||
assertSoleFileLocation(
|
assertSoleFileLocation(incs[0], filename, code.indexOf("#inc"), "#include \"foo.h\"".length());
|
||||||
incs[0],
|
|
||||||
filename,
|
|
||||||
code.indexOf("#inc"), code.indexOf(".h\"\n") + ".h\"".length() - code.indexOf("#inc")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,8 +449,7 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
||||||
assertEquals(locs.length, 1);
|
assertEquals(locs.length, 1);
|
||||||
IASTFileLocation fileLoc = (IASTFileLocation) locs[0];
|
IASTFileLocation fileLoc = (IASTFileLocation) locs[0];
|
||||||
assertEquals(code.indexOf("#include"), fileLoc.getNodeOffset()); //$NON-NLS-1$
|
assertEquals(code.indexOf("#include"), fileLoc.getNodeOffset()); //$NON-NLS-1$
|
||||||
assertEquals(
|
assertEquals("#include <not_found.h>".length(), fileLoc.getNodeLength()); //$NON-NLS-1$
|
||||||
"#include <not_found.h>\n".length(), fileLoc.getNodeLength()); //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -465,8 +461,7 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBug97603() throws Exception {
|
public void testBug97603() throws Exception {
|
||||||
IFile imacro_file = importFile(
|
IFile imacro_file = importFile("macro.h", "#define JEDEN 1\n#define DVA 2\n#define TRI 3\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
"macro.h", "#define JEDEN 1\n#define DVA 2\n#define TRI 3\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
buffer.append("#ifndef _INCLUDE_H_\n"); //$NON-NLS-1$
|
buffer.append("#ifndef _INCLUDE_H_\n"); //$NON-NLS-1$
|
||||||
buffer.append("#define _INCLUDE_H_\n"); //$NON-NLS-1$
|
buffer.append("#define _INCLUDE_H_\n"); //$NON-NLS-1$
|
||||||
|
@ -511,4 +506,52 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug97603_2() throws Exception {
|
||||||
|
IFile imacro_file1= importFile("macro1.h", "#define JEDEN 1\n");
|
||||||
|
IFile imacro_file2= importFile("macro2.h", "#define DVA 2\n#define TRI 3\n");
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("#ifndef _INCLUDE_H_\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#define _INCLUDE_H_\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("typedef void (*vfp)();\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("typedef int (*ifp)();\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("struct Include {\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int i;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("};\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("#endif /*_INCLUDE_H_*/\n"); //$NON-NLS-1$
|
||||||
|
final String inc_file_code = buffer.toString();
|
||||||
|
IFile include_file = importFile("include.h", inc_file_code); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
String[] macros = { imacro_file1.getLocation().toOSString(), imacro_file2.getLocation().toOSString() };
|
||||||
|
String[] includes = { include_file.getLocation().toOSString() };
|
||||||
|
IExtendedScannerInfo scannerInfo = new ExtendedScannerInfo(
|
||||||
|
Collections.EMPTY_MAP, EMPTY_STRING_ARRAY, macros, includes);
|
||||||
|
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||||
|
: null) {
|
||||||
|
String filename = (p == ParserLanguage.CPP) ? "main.cc" : "main.c"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
IFile code = importFile(filename,
|
||||||
|
"int main() { return BEAST * sizeof( Include ); } "); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse(code, scannerInfo); //$NON-NLS-1$
|
||||||
|
IASTPreprocessorMacroDefinition[] macro_defs = tu
|
||||||
|
.getMacroDefinitions();
|
||||||
|
assertEquals(macro_defs.length, 4);
|
||||||
|
IASTPreprocessorMacroDefinition BEAST = macro_defs[0];
|
||||||
|
assertEquals(BEAST.getName().toString(), "JEDEN"); //$NON-NLS-1$
|
||||||
|
IASTPreprocessorMacroDefinition INCLUDE_H = macro_defs[3];
|
||||||
|
final IASTNodeLocation[] nodeLocations = INCLUDE_H.getName()
|
||||||
|
.getNodeLocations();
|
||||||
|
assertEquals(nodeLocations.length, 1);
|
||||||
|
final IASTFileLocation flatLoc = INCLUDE_H.getName()
|
||||||
|
.getFileLocation();
|
||||||
|
assertNotNull(flatLoc);
|
||||||
|
assertEquals(include_file.getLocation().toOSString(), flatLoc
|
||||||
|
.getFileName());
|
||||||
|
assertEquals(
|
||||||
|
inc_file_code.indexOf("#define _INCLUDE_H_") + "#define ".length(), flatLoc.getNodeOffset()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
assertEquals("_INCLUDE_H_".length(), flatLoc.getNodeLength()); //$NON-NLS-1$
|
||||||
|
for (int j = 0; j < macro_defs.length; ++j)
|
||||||
|
assertNotNull(macro_defs[j].getName().getFileLocation());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2004, 2005 IBM Corporation and others.
|
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM - Initial API and implementation
|
* IBM - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||||
|
|
||||||
|
@ -113,15 +114,15 @@ public class DOMLocationMacroTests extends AST2BaseTest {
|
||||||
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) {
|
||||||
IASTTranslationUnit tu = parse(code, p);
|
IASTTranslationUnit tu = parse(code, p);
|
||||||
IASTPreprocessorObjectStyleMacroDefinition XYZ = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0];
|
IASTPreprocessorObjectStyleMacroDefinition defXYZ = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0];
|
||||||
IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||||
IASTSimpleDeclSpecifier declSpec = (IASTSimpleDeclSpecifier) var.getDeclSpecifier();
|
IASTSimpleDeclSpecifier declSpec = (IASTSimpleDeclSpecifier) var.getDeclSpecifier();
|
||||||
IASTNodeLocation [] declSpecLocations = declSpec.getNodeLocations();
|
IASTNodeLocation [] declSpecLocations = declSpec.getNodeLocations();
|
||||||
assertEquals( declSpecLocations.length, 2 );
|
assertEquals( declSpecLocations.length, 2 );
|
||||||
IASTMacroExpansion expansion = (IASTMacroExpansion) declSpecLocations[0];
|
IASTMacroExpansion expansion = (IASTMacroExpansion) declSpecLocations[0];
|
||||||
assertEqualsMacros( XYZ, expansion.getMacroDefinition() );
|
assertEqualsMacros( defXYZ, expansion.getMacroDefinition() );
|
||||||
assertEquals( expansion.getNodeOffset(), 0 );
|
assertEquals( expansion.getNodeOffset(), 0 );
|
||||||
assertEquals( expansion.getNodeLength(), 6 );
|
assertEquals( expansion.getNodeLength(), "const".length() );
|
||||||
IASTNodeLocation [] expansionLocations = expansion.getExpansionLocations();
|
IASTNodeLocation [] expansionLocations = expansion.getExpansionLocations();
|
||||||
assertEquals( expansionLocations.length, 1 );
|
assertEquals( expansionLocations.length, 1 );
|
||||||
assertTrue( expansionLocations[0] instanceof IASTFileLocation );
|
assertTrue( expansionLocations[0] instanceof IASTFileLocation );
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2004, 2005 IBM Corporation and others.
|
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM - Initial API and implementation
|
* IBM - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||||
|
|
||||||
|
@ -189,6 +190,12 @@ public class DOMLocationTests extends AST2BaseTest {
|
||||||
assertEquals(length, nodeLocation.getNodeLength());
|
assertEquals(length, nodeLocation.getNodeLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertFileLocation(IASTNode n, int offset, int length) {
|
||||||
|
IASTNodeLocation location = n.getFileLocation();
|
||||||
|
assertEquals(offset, location.getNodeOffset());
|
||||||
|
assertEquals(length, location.getNodeLength());
|
||||||
|
}
|
||||||
|
|
||||||
public void testBug83664() throws Exception {
|
public void testBug83664() throws Exception {
|
||||||
String code = "int foo(x) int x; {\n return x;\n }\n"; //$NON-NLS-1$
|
String code = "int foo(x) int x; {\n return x;\n }\n"; //$NON-NLS-1$
|
||||||
IASTTranslationUnit tu = parse(code, ParserLanguage.C, true);
|
IASTTranslationUnit tu = parse(code, ParserLanguage.C, true);
|
||||||
|
@ -449,7 +456,7 @@ public class DOMLocationTests extends AST2BaseTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void _testBug162180() throws Exception {
|
public void testBug162180() throws Exception {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
buffer.append( "#include <notfound.h>\n"); //$NON-NLS-1$
|
buffer.append( "#include <notfound.h>\n"); //$NON-NLS-1$
|
||||||
int declOffset= buffer.length();
|
int declOffset= buffer.length();
|
||||||
|
@ -464,7 +471,124 @@ public class DOMLocationTests extends AST2BaseTest {
|
||||||
assertEquals( statements.length, 0 );
|
assertEquals( statements.length, 0 );
|
||||||
IASTProblem[] problems = tu.getPreprocessorProblems();
|
IASTProblem[] problems = tu.getPreprocessorProblems();
|
||||||
assertEquals( problems.length, 1 );
|
assertEquals( problems.length, 1 );
|
||||||
assertSoleLocation( decls[0], code.indexOf( "int x;"), "int x;".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
assertSoleLocation( decls[0], code, "int x;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertSoleLocation(IASTNode node, String code, String snip) {
|
||||||
|
assertSoleLocation(node, code.indexOf(snip), snip.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertFileLocation(IASTNode node, String code, String snip) {
|
||||||
|
assertFileLocation(node, code.indexOf(snip), snip.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBug162180_0() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append( "#include <notfound.h>\n"); //$NON-NLS-1$
|
||||||
|
buffer.append( "#include <notfound1.h> \r\n"); //$NON-NLS-1$
|
||||||
|
buffer.append( "#include <notfound2.h> // more stuff \n"); //$NON-NLS-1$
|
||||||
|
int declOffset= buffer.length();
|
||||||
|
buffer.append( "int x;\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, false, false);
|
||||||
|
IASTDeclaration[] decls= tu.getDeclarations();
|
||||||
|
IASTPreprocessorStatement [] statements = tu.getAllPreprocessorStatements();
|
||||||
|
IASTProblem[] problems = tu.getPreprocessorProblems();
|
||||||
|
assertEquals( 1, decls.length);
|
||||||
|
assertEquals( 0, statements.length);
|
||||||
|
assertEquals( 3, problems.length);
|
||||||
|
String snip= "<notfound.h>";
|
||||||
|
assertSoleLocation(problems[0], code, "#include <notfound.h>");
|
||||||
|
assertSoleLocation(problems[1], code, "#include <notfound1.h> ");
|
||||||
|
assertSoleLocation(problems[2], code, "#include <notfound2.h> // more stuff ");
|
||||||
|
assertSoleLocation(decls[0], code, "int x;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test162180_1() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append( "#define xxx(!) int a\n"); // [0-20]
|
||||||
|
buffer.append( "int x;\n"); // [21-27]
|
||||||
|
buffer.append( "int x\\i;\n"); // [28-36]
|
||||||
|
buffer.append( "int x2;\n"); // [37-44]
|
||||||
|
String code = buffer.toString();
|
||||||
|
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||||
|
: null) {
|
||||||
|
IASTTranslationUnit tu = parse(code, p, false, false);
|
||||||
|
IASTDeclaration[] decls= tu.getDeclarations();
|
||||||
|
IASTPreprocessorStatement [] statements = tu.getAllPreprocessorStatements();
|
||||||
|
IASTProblem[] problems = tu.getPreprocessorProblems();
|
||||||
|
assertEquals( 3, decls.length);
|
||||||
|
assertEquals( 0, statements.length);
|
||||||
|
assertEquals( 2, problems.length);
|
||||||
|
assertSoleLocation(problems[0], code, "xxx(!");
|
||||||
|
assertSoleLocation( decls[0], code, "int x;");
|
||||||
|
assertSoleLocation( problems[1], code, "\\");
|
||||||
|
assertFileLocation( decls[1], code, "int x\\i");
|
||||||
|
assertSoleLocation( decls[2], code, "int x2;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test162180_2() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append( "#define ! x\n");
|
||||||
|
buffer.append( "int x;\n");
|
||||||
|
String code = buffer.toString();
|
||||||
|
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||||
|
: null) {
|
||||||
|
IASTTranslationUnit tu = parse(code, p, false, false);
|
||||||
|
IASTDeclaration[] decls= tu.getDeclarations();
|
||||||
|
IASTPreprocessorStatement [] statements = tu.getAllPreprocessorStatements();
|
||||||
|
IASTProblem[] problems = tu.getPreprocessorProblems();
|
||||||
|
assertEquals( 1, decls.length);
|
||||||
|
assertEquals( 0, statements.length);
|
||||||
|
assertEquals( 1, problems.length);
|
||||||
|
assertSoleLocation(problems[0], code, "!");
|
||||||
|
assertSoleLocation( decls[0], code, "int x;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test162180_3() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append( "#define nix(x) x\n");
|
||||||
|
buffer.append( "nix(y,z);");
|
||||||
|
buffer.append( "int x;\n");
|
||||||
|
String code = buffer.toString();
|
||||||
|
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||||
|
: null) {
|
||||||
|
IASTTranslationUnit tu = parse(code, p, false, false);
|
||||||
|
IASTDeclaration[] decls= tu.getDeclarations();
|
||||||
|
IASTPreprocessorStatement [] statements = tu.getAllPreprocessorStatements();
|
||||||
|
IASTProblem[] problems = tu.getPreprocessorProblems();
|
||||||
|
assertEquals( 2, decls.length);
|
||||||
|
assertEquals( 1, statements.length);
|
||||||
|
assertEquals( 1, problems.length);
|
||||||
|
assertSoleLocation(problems[0], code, "z");
|
||||||
|
assertSoleLocation( decls[1], code, "int x;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test162180_4() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append( "#include \"\"\n");
|
||||||
|
buffer.append( "#else\n");
|
||||||
|
buffer.append( "int x;\n");
|
||||||
|
String code = buffer.toString();
|
||||||
|
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||||
|
: null) {
|
||||||
|
IASTTranslationUnit tu = parse(code, p, false, false);
|
||||||
|
IASTDeclaration[] decls= tu.getDeclarations();
|
||||||
|
IASTPreprocessorStatement [] statements = tu.getAllPreprocessorStatements();
|
||||||
|
IASTProblem[] problems = tu.getPreprocessorProblems();
|
||||||
|
assertEquals( 1, decls.length);
|
||||||
|
assertEquals( 0, statements.length);
|
||||||
|
assertEquals( 2, problems.length);
|
||||||
|
assertSoleLocation(problems[0], code, "#include \"\"");
|
||||||
|
assertSoleLocation(problems[1], code, "else");
|
||||||
|
assertSoleLocation( decls[0], code, "int x;");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2004, 2005 IBM Corporation and others.
|
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM - Initial API and implementation
|
* IBM - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||||
|
|
||||||
|
@ -16,7 +17,6 @@ import junit.framework.TestSuite;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
|
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
|
||||||
import org.eclipse.cdt.core.parser.tests.prefix.CompletionTestSuite;
|
import org.eclipse.cdt.core.parser.tests.prefix.CompletionTestSuite;
|
||||||
import org.eclipse.cdt.core.tests.FailingTest;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
|
@ -32,7 +32,6 @@ public class DOMParserTestSuite extends TestCase {
|
||||||
suite.addTestSuite( QuickParser2Tests.class );
|
suite.addTestSuite( QuickParser2Tests.class );
|
||||||
suite.addTestSuite( CompleteParser2Tests.class );
|
suite.addTestSuite( CompleteParser2Tests.class );
|
||||||
suite.addTestSuite( DOMLocationTests.class );
|
suite.addTestSuite( DOMLocationTests.class );
|
||||||
suite.addTest( new FailingTest(new DOMLocationTests("_testBug162180"), 162180) );
|
|
||||||
suite.addTestSuite( DOMLocationMacroTests.class );
|
suite.addTestSuite( DOMLocationMacroTests.class );
|
||||||
suite.addTest( DOMLocationInclusionTests.suite() );
|
suite.addTest( DOMLocationInclusionTests.suite() );
|
||||||
suite.addTestSuite( AST2KnRTests.class );
|
suite.addTestSuite( AST2KnRTests.class );
|
||||||
|
|
|
@ -607,12 +607,11 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
if (LA(1).hashCode() == checkOffset)
|
if (LA(1).hashCode() == checkOffset)
|
||||||
failParseWithErrorHandling();
|
failParseWithErrorHandling();
|
||||||
} catch (EndOfFileException e) {
|
} catch (EndOfFileException e) {
|
||||||
|
IASTDeclaration[] declarations = translationUnit.getDeclarations();
|
||||||
// As expected
|
// As expected
|
||||||
if (translationUnit.getDeclarations().length != 0) {
|
if (declarations.length != 0) {
|
||||||
CASTNode d = (CASTNode) translationUnit.getDeclarations()[translationUnit
|
CASTNode d = (CASTNode) declarations[declarations.length-1];
|
||||||
.getDeclarations().length - 1];
|
((CASTNode) translationUnit).setLength(d.getOffset() + d.getLength());
|
||||||
((CASTNode) translationUnit).setLength(d.getOffset()
|
|
||||||
+ d.getLength());
|
|
||||||
} else
|
} else
|
||||||
((CASTNode) translationUnit).setLength(0);
|
((CASTNode) translationUnit).setLength(0);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -91,15 +91,21 @@ abstract class BaseScanner implements IScanner {
|
||||||
this.macro = macro;
|
this.macro = macro;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int startOffset;
|
private final int startOffset;
|
||||||
|
private final int endOffset;
|
||||||
public final int endOffset;
|
|
||||||
|
|
||||||
public final IMacro macro;
|
public final IMacro macro;
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return macro.toString();
|
return macro.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getStartOffset() {
|
||||||
|
return startOffset;
|
||||||
|
}
|
||||||
|
public int getLength() {
|
||||||
|
return endOffset-startOffset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ParserLanguage language;
|
protected ParserLanguage language;
|
||||||
|
@ -2110,17 +2116,19 @@ abstract class BaseScanner implements IScanner {
|
||||||
} else if (expObject instanceof ObjectStyleMacro) {
|
} else if (expObject instanceof ObjectStyleMacro) {
|
||||||
ObjectStyleMacro expMacro = (ObjectStyleMacro) expObject;
|
ObjectStyleMacro expMacro = (ObjectStyleMacro) expObject;
|
||||||
char[] expText = expMacro.getExpansion();
|
char[] expText = expMacro.getExpansion();
|
||||||
if (expText.length > 0)
|
if (expText.length > 0) {
|
||||||
pushContext(expText, new MacroData(
|
final int endOffset= bufferPos[bufferStackPos]+1;
|
||||||
bufferPos[bufferStackPos] - expMacro.name.length + 1,
|
final int startOffset= endOffset - expMacro.name.length;
|
||||||
bufferPos[bufferStackPos], expMacro));
|
pushContext(expText, new MacroData(startOffset, endOffset, expMacro));
|
||||||
|
}
|
||||||
} else if (expObject instanceof DynamicStyleMacro) {
|
} else if (expObject instanceof DynamicStyleMacro) {
|
||||||
DynamicStyleMacro expMacro = (DynamicStyleMacro) expObject;
|
DynamicStyleMacro expMacro = (DynamicStyleMacro) expObject;
|
||||||
char[] expText = expMacro.execute();
|
char[] expText = expMacro.execute();
|
||||||
if (expText.length > 0)
|
if (expText.length > 0) {
|
||||||
pushContext(expText, new MacroData(
|
final int endOffset= bufferPos[bufferStackPos]+1;
|
||||||
bufferPos[bufferStackPos] - expMacro.name.length
|
final int startOffset= endOffset - expMacro.name.length;
|
||||||
+ 1, bufferPos[bufferStackPos], expMacro));
|
pushContext(expText, new MacroData(startOffset, endOffset, expMacro));
|
||||||
|
}
|
||||||
|
|
||||||
} else if (expObject instanceof char[]) {
|
} else if (expObject instanceof char[]) {
|
||||||
char[] expText = (char[]) expObject;
|
char[] expText = (char[]) expObject;
|
||||||
|
@ -2863,7 +2871,7 @@ abstract class BaseScanner implements IScanner {
|
||||||
char[] fileNameArray = filename.toCharArray();
|
char[] fileNameArray = filename.toCharArray();
|
||||||
// TODO else we need to do macro processing on the rest of the line
|
// TODO else we need to do macro processing on the rest of the line
|
||||||
endLine = getLineNumber(bufferPos[bufferStackPos]);
|
endLine = getLineNumber(bufferPos[bufferStackPos]);
|
||||||
skipToNewLine();
|
skipToLastBeforeNewline();
|
||||||
|
|
||||||
findAndPushInclusion(filename, fileNameArray, local, include_next, startOffset, nameOffset, nameEndOffset, endOffset, startingLineNumber, nameLine, endLine);
|
findAndPushInclusion(filename, fileNameArray, local, include_next, startOffset, nameOffset, nameEndOffset, endOffset, startingLineNumber, nameLine, endLine);
|
||||||
}
|
}
|
||||||
|
@ -3967,6 +3975,78 @@ abstract class BaseScanner implements IScanner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Skips everything up to the next newline. Returns offset for last
|
||||||
|
* character that was not a whitespace and no comment.
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
protected int skipToLastBeforeNewline() {
|
||||||
|
char[] buffer = bufferStack[bufferStackPos];
|
||||||
|
int limit = bufferLimit[bufferStackPos];
|
||||||
|
int pos = bufferPos[bufferStackPos];
|
||||||
|
int lastMeaningful= pos;
|
||||||
|
|
||||||
|
boolean escaped = false;
|
||||||
|
boolean inComment= false;
|
||||||
|
while (++pos < limit) {
|
||||||
|
char ch= buffer[pos];
|
||||||
|
switch (ch) {
|
||||||
|
case '/':
|
||||||
|
if (pos + 1 < limit) {
|
||||||
|
char c= buffer[pos + 1];
|
||||||
|
if (c == '*') {
|
||||||
|
pos+=2;
|
||||||
|
while (++pos < limit) {
|
||||||
|
if (buffer[pos-1] == '*' && buffer[pos] == '/') {
|
||||||
|
pos++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pos--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (c == '/') {
|
||||||
|
inComment= true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!inComment) {
|
||||||
|
lastMeaningful= pos;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '\\':
|
||||||
|
escaped = !escaped;
|
||||||
|
if (!inComment) {
|
||||||
|
lastMeaningful= pos;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
case '\n':
|
||||||
|
if (escaped) {
|
||||||
|
escaped = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
bufferPos[bufferStackPos]= pos-1;
|
||||||
|
return lastMeaningful;
|
||||||
|
case '\r':
|
||||||
|
if (escaped) {
|
||||||
|
escaped = false;
|
||||||
|
break;
|
||||||
|
} else if (pos+1 < limit && buffer[pos+1] == '\n') {
|
||||||
|
bufferPos[bufferStackPos]= pos-1;
|
||||||
|
return lastMeaningful;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (!inComment && !Character.isWhitespace(ch)) {
|
||||||
|
lastMeaningful= pos;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
escaped = false;
|
||||||
|
}
|
||||||
|
bufferPos[bufferStackPos]= pos-1;
|
||||||
|
return lastMeaningful;
|
||||||
|
}
|
||||||
|
|
||||||
protected char[] handleFunctionStyleMacro(FunctionStyleMacro macro,
|
protected char[] handleFunctionStyleMacro(FunctionStyleMacro macro,
|
||||||
boolean pushContext) {
|
boolean pushContext) {
|
||||||
char[] buffer = bufferStack[bufferStackPos];
|
char[] buffer = bufferStack[bufferStackPos];
|
||||||
|
@ -4133,8 +4213,7 @@ abstract class BaseScanner implements IScanner {
|
||||||
}
|
}
|
||||||
if (pushContext)
|
if (pushContext)
|
||||||
{
|
{
|
||||||
pushContext(result, new MacroData(start, bufferPos[bufferStackPos],
|
pushContext(result, new MacroData(start, bufferPos[bufferStackPos]+1, macro));
|
||||||
macro));
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -4583,13 +4662,13 @@ abstract class BaseScanner implements IScanner {
|
||||||
|
|
||||||
// standard built-ins
|
// standard built-ins
|
||||||
protected static final ObjectStyleMacro __cplusplus = new ObjectStyleMacro(
|
protected static final ObjectStyleMacro __cplusplus = new ObjectStyleMacro(
|
||||||
"__cplusplus".toCharArray(), ONE); //$NON-NLS-1$ //$NON-NLS-2$
|
"__cplusplus".toCharArray(), ONE); //$NON-NLS-1$
|
||||||
|
|
||||||
protected static final ObjectStyleMacro __STDC__ = new ObjectStyleMacro(
|
protected static final ObjectStyleMacro __STDC__ = new ObjectStyleMacro(
|
||||||
"__STDC__".toCharArray(), ONE); //$NON-NLS-1$ //$NON-NLS-2$
|
"__STDC__".toCharArray(), ONE); //$NON-NLS-1$
|
||||||
|
|
||||||
protected static final ObjectStyleMacro __STDC_HOSTED__ = new ObjectStyleMacro(
|
protected static final ObjectStyleMacro __STDC_HOSTED__ = new ObjectStyleMacro(
|
||||||
"__STDC_HOSTED_".toCharArray(), ONE); //$NON-NLS-1$ //$NON-NLS-2$
|
"__STDC_HOSTED_".toCharArray(), ONE); //$NON-NLS-1$
|
||||||
|
|
||||||
protected static final ObjectStyleMacro __STDC_VERSION__ = new ObjectStyleMacro(
|
protected static final ObjectStyleMacro __STDC_VERSION__ = new ObjectStyleMacro(
|
||||||
"__STDC_VERSION_".toCharArray(), "199901L".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
"__STDC_VERSION_".toCharArray(), "199901L".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
@ -4780,107 +4859,107 @@ abstract class BaseScanner implements IScanner {
|
||||||
CharArrayIntMap words = new CharArrayIntMap(IToken.tLAST, -1);
|
CharArrayIntMap words = new CharArrayIntMap(IToken.tLAST, -1);
|
||||||
|
|
||||||
// Common keywords
|
// Common keywords
|
||||||
words.put(Keywords.cAUTO, IToken.t_auto); //$NON-NLS-1$
|
words.put(Keywords.cAUTO, IToken.t_auto);
|
||||||
words.put(Keywords.cBREAK, IToken.t_break); //$NON-NLS-1$
|
words.put(Keywords.cBREAK, IToken.t_break);
|
||||||
words.put(Keywords.cCASE, IToken.t_case); //$NON-NLS-1$
|
words.put(Keywords.cCASE, IToken.t_case);
|
||||||
words.put(Keywords.cCHAR, IToken.t_char); //$NON-NLS-1$
|
words.put(Keywords.cCHAR, IToken.t_char);
|
||||||
words.put(Keywords.cCONST, IToken.t_const); //$NON-NLS-1$
|
words.put(Keywords.cCONST, IToken.t_const);
|
||||||
words.put(Keywords.cCONTINUE, IToken.t_continue); //$NON-NLS-1$
|
words.put(Keywords.cCONTINUE, IToken.t_continue);
|
||||||
words.put(Keywords.cDEFAULT, IToken.t_default); //$NON-NLS-1$
|
words.put(Keywords.cDEFAULT, IToken.t_default);
|
||||||
words.put(Keywords.cDO, IToken.t_do); //$NON-NLS-1$
|
words.put(Keywords.cDO, IToken.t_do);
|
||||||
words.put(Keywords.cDOUBLE, IToken.t_double); //$NON-NLS-1$
|
words.put(Keywords.cDOUBLE, IToken.t_double);
|
||||||
words.put(Keywords.cELSE, IToken.t_else); //$NON-NLS-1$
|
words.put(Keywords.cELSE, IToken.t_else);
|
||||||
words.put(Keywords.cENUM, IToken.t_enum); //$NON-NLS-1$
|
words.put(Keywords.cENUM, IToken.t_enum);
|
||||||
words.put(Keywords.cEXTERN, IToken.t_extern); //$NON-NLS-1$
|
words.put(Keywords.cEXTERN, IToken.t_extern);
|
||||||
words.put(Keywords.cFLOAT, IToken.t_float); //$NON-NLS-1$
|
words.put(Keywords.cFLOAT, IToken.t_float);
|
||||||
words.put(Keywords.cFOR, IToken.t_for); //$NON-NLS-1$
|
words.put(Keywords.cFOR, IToken.t_for);
|
||||||
words.put(Keywords.cGOTO, IToken.t_goto); //$NON-NLS-1$
|
words.put(Keywords.cGOTO, IToken.t_goto);
|
||||||
words.put(Keywords.cIF, IToken.t_if); //$NON-NLS-1$
|
words.put(Keywords.cIF, IToken.t_if);
|
||||||
words.put(Keywords.cINLINE, IToken.t_inline); //$NON-NLS-1$
|
words.put(Keywords.cINLINE, IToken.t_inline);
|
||||||
words.put(Keywords.cINT, IToken.t_int); //$NON-NLS-1$
|
words.put(Keywords.cINT, IToken.t_int);
|
||||||
words.put(Keywords.cLONG, IToken.t_long); //$NON-NLS-1$
|
words.put(Keywords.cLONG, IToken.t_long);
|
||||||
words.put(Keywords.cREGISTER, IToken.t_register); //$NON-NLS-1$
|
words.put(Keywords.cREGISTER, IToken.t_register);
|
||||||
words.put(Keywords.cRETURN, IToken.t_return); //$NON-NLS-1$
|
words.put(Keywords.cRETURN, IToken.t_return);
|
||||||
words.put(Keywords.cSHORT, IToken.t_short); //$NON-NLS-1$
|
words.put(Keywords.cSHORT, IToken.t_short);
|
||||||
words.put(Keywords.cSIGNED, IToken.t_signed); //$NON-NLS-1$
|
words.put(Keywords.cSIGNED, IToken.t_signed);
|
||||||
words.put(Keywords.cSIZEOF, IToken.t_sizeof); //$NON-NLS-1$
|
words.put(Keywords.cSIZEOF, IToken.t_sizeof);
|
||||||
words.put(Keywords.cSTATIC, IToken.t_static); //$NON-NLS-1$
|
words.put(Keywords.cSTATIC, IToken.t_static);
|
||||||
words.put(Keywords.cSTRUCT, IToken.t_struct); //$NON-NLS-1$
|
words.put(Keywords.cSTRUCT, IToken.t_struct);
|
||||||
words.put(Keywords.cSWITCH, IToken.t_switch); //$NON-NLS-1$
|
words.put(Keywords.cSWITCH, IToken.t_switch);
|
||||||
words.put(Keywords.cTYPEDEF, IToken.t_typedef); //$NON-NLS-1$
|
words.put(Keywords.cTYPEDEF, IToken.t_typedef);
|
||||||
words.put(Keywords.cUNION, IToken.t_union); //$NON-NLS-1$
|
words.put(Keywords.cUNION, IToken.t_union);
|
||||||
words.put(Keywords.cUNSIGNED, IToken.t_unsigned); //$NON-NLS-1$
|
words.put(Keywords.cUNSIGNED, IToken.t_unsigned);
|
||||||
words.put(Keywords.cVOID, IToken.t_void); //$NON-NLS-1$
|
words.put(Keywords.cVOID, IToken.t_void);
|
||||||
words.put(Keywords.cVOLATILE, IToken.t_volatile); //$NON-NLS-1$
|
words.put(Keywords.cVOLATILE, IToken.t_volatile);
|
||||||
words.put(Keywords.cWHILE, IToken.t_while); //$NON-NLS-1$
|
words.put(Keywords.cWHILE, IToken.t_while);
|
||||||
words.put(Keywords.cASM, IToken.t_asm); //$NON-NLS-1$
|
words.put(Keywords.cASM, IToken.t_asm);
|
||||||
|
|
||||||
// ANSI C keywords
|
// ANSI C keywords
|
||||||
ckeywords = (CharArrayIntMap) words.clone();
|
ckeywords = (CharArrayIntMap) words.clone();
|
||||||
ckeywords.put(Keywords.cRESTRICT, IToken.t_restrict); //$NON-NLS-1$
|
ckeywords.put(Keywords.cRESTRICT, IToken.t_restrict);
|
||||||
ckeywords.put(Keywords.c_BOOL, IToken.t__Bool); //$NON-NLS-1$
|
ckeywords.put(Keywords.c_BOOL, IToken.t__Bool);
|
||||||
ckeywords.put(Keywords.c_COMPLEX, IToken.t__Complex); //$NON-NLS-1$
|
ckeywords.put(Keywords.c_COMPLEX, IToken.t__Complex);
|
||||||
ckeywords.put(Keywords.c_IMAGINARY, IToken.t__Imaginary); //$NON-NLS-1$
|
ckeywords.put(Keywords.c_IMAGINARY, IToken.t__Imaginary);
|
||||||
|
|
||||||
// C++ Keywords
|
// C++ Keywords
|
||||||
cppkeywords = words;
|
cppkeywords = words;
|
||||||
cppkeywords.put(Keywords.cBOOL, IToken.t_bool); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cBOOL, IToken.t_bool);
|
||||||
cppkeywords.put(Keywords.cCATCH, IToken.t_catch); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cCATCH, IToken.t_catch);
|
||||||
cppkeywords.put(Keywords.cCLASS, IToken.t_class); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cCLASS, IToken.t_class);
|
||||||
cppkeywords.put(Keywords.cCONST_CAST, IToken.t_const_cast); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cCONST_CAST, IToken.t_const_cast);
|
||||||
cppkeywords.put(Keywords.cDELETE, IToken.t_delete); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cDELETE, IToken.t_delete);
|
||||||
cppkeywords.put(Keywords.cDYNAMIC_CAST, IToken.t_dynamic_cast); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cDYNAMIC_CAST, IToken.t_dynamic_cast);
|
||||||
cppkeywords.put(Keywords.cEXPLICIT, IToken.t_explicit); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cEXPLICIT, IToken.t_explicit);
|
||||||
cppkeywords.put(Keywords.cEXPORT, IToken.t_export); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cEXPORT, IToken.t_export);
|
||||||
cppkeywords.put(Keywords.cFALSE, IToken.t_false); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cFALSE, IToken.t_false);
|
||||||
cppkeywords.put(Keywords.cFRIEND, IToken.t_friend); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cFRIEND, IToken.t_friend);
|
||||||
cppkeywords.put(Keywords.cMUTABLE, IToken.t_mutable); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cMUTABLE, IToken.t_mutable);
|
||||||
cppkeywords.put(Keywords.cNAMESPACE, IToken.t_namespace); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cNAMESPACE, IToken.t_namespace);
|
||||||
cppkeywords.put(Keywords.cNEW, IToken.t_new); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cNEW, IToken.t_new);
|
||||||
cppkeywords.put(Keywords.cOPERATOR, IToken.t_operator); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cOPERATOR, IToken.t_operator);
|
||||||
cppkeywords.put(Keywords.cPRIVATE, IToken.t_private); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cPRIVATE, IToken.t_private);
|
||||||
cppkeywords.put(Keywords.cPROTECTED, IToken.t_protected); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cPROTECTED, IToken.t_protected);
|
||||||
cppkeywords.put(Keywords.cPUBLIC, IToken.t_public); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cPUBLIC, IToken.t_public);
|
||||||
cppkeywords.put(Keywords.cREINTERPRET_CAST, IToken.t_reinterpret_cast); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cREINTERPRET_CAST, IToken.t_reinterpret_cast);
|
||||||
cppkeywords.put(Keywords.cSTATIC_CAST, IToken.t_static_cast); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cSTATIC_CAST, IToken.t_static_cast);
|
||||||
cppkeywords.put(Keywords.cTEMPLATE, IToken.t_template); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cTEMPLATE, IToken.t_template);
|
||||||
cppkeywords.put(Keywords.cTHIS, IToken.t_this); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cTHIS, IToken.t_this);
|
||||||
cppkeywords.put(Keywords.cTHROW, IToken.t_throw); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cTHROW, IToken.t_throw);
|
||||||
cppkeywords.put(Keywords.cTRUE, IToken.t_true); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cTRUE, IToken.t_true);
|
||||||
cppkeywords.put(Keywords.cTRY, IToken.t_try); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cTRY, IToken.t_try);
|
||||||
cppkeywords.put(Keywords.cTYPEID, IToken.t_typeid); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cTYPEID, IToken.t_typeid);
|
||||||
cppkeywords.put(Keywords.cTYPENAME, IToken.t_typename); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cTYPENAME, IToken.t_typename);
|
||||||
cppkeywords.put(Keywords.cUSING, IToken.t_using); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cUSING, IToken.t_using);
|
||||||
cppkeywords.put(Keywords.cVIRTUAL, IToken.t_virtual); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cVIRTUAL, IToken.t_virtual);
|
||||||
cppkeywords.put(Keywords.cWCHAR_T, IToken.t_wchar_t); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cWCHAR_T, IToken.t_wchar_t);
|
||||||
|
|
||||||
// C++ operator alternative
|
// C++ operator alternative
|
||||||
cppkeywords.put(Keywords.cAND, IToken.t_and); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cAND, IToken.t_and);
|
||||||
cppkeywords.put(Keywords.cAND_EQ, IToken.t_and_eq); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cAND_EQ, IToken.t_and_eq);
|
||||||
cppkeywords.put(Keywords.cBITAND, IToken.t_bitand); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cBITAND, IToken.t_bitand);
|
||||||
cppkeywords.put(Keywords.cBITOR, IToken.t_bitor); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cBITOR, IToken.t_bitor);
|
||||||
cppkeywords.put(Keywords.cCOMPL, IToken.t_compl); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cCOMPL, IToken.t_compl);
|
||||||
cppkeywords.put(Keywords.cNOT, IToken.t_not); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cNOT, IToken.t_not);
|
||||||
cppkeywords.put(Keywords.cNOT_EQ, IToken.t_not_eq); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cNOT_EQ, IToken.t_not_eq);
|
||||||
cppkeywords.put(Keywords.cOR, IToken.t_or); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cOR, IToken.t_or);
|
||||||
cppkeywords.put(Keywords.cOR_EQ, IToken.t_or_eq); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cOR_EQ, IToken.t_or_eq);
|
||||||
cppkeywords.put(Keywords.cXOR, IToken.t_xor); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cXOR, IToken.t_xor);
|
||||||
cppkeywords.put(Keywords.cXOR_EQ, IToken.t_xor_eq); //$NON-NLS-1$
|
cppkeywords.put(Keywords.cXOR_EQ, IToken.t_xor_eq);
|
||||||
|
|
||||||
// Preprocessor keywords
|
// Preprocessor keywords
|
||||||
ppKeywords = new CharArrayIntMap(16, -1);
|
ppKeywords = new CharArrayIntMap(16, -1);
|
||||||
ppKeywords.put(Keywords.cIF, ppIf); //$NON-NLS-1$
|
ppKeywords.put(Keywords.cIF, ppIf);
|
||||||
ppKeywords.put(Keywords.cIFDEF, ppIfdef); //$NON-NLS-1$
|
ppKeywords.put(Keywords.cIFDEF, ppIfdef);
|
||||||
ppKeywords.put(Keywords.cIFNDEF, ppIfndef); //$NON-NLS-1$
|
ppKeywords.put(Keywords.cIFNDEF, ppIfndef);
|
||||||
ppKeywords.put(Keywords.cELIF, ppElif); //$NON-NLS-1$
|
ppKeywords.put(Keywords.cELIF, ppElif);
|
||||||
ppKeywords.put(Keywords.cELSE, ppElse); //$NON-NLS-1$
|
ppKeywords.put(Keywords.cELSE, ppElse);
|
||||||
ppKeywords.put(Keywords.cENDIF, ppEndif); //$NON-NLS-1$
|
ppKeywords.put(Keywords.cENDIF, ppEndif);
|
||||||
ppKeywords.put(Keywords.cINCLUDE, ppInclude); //$NON-NLS-1$
|
ppKeywords.put(Keywords.cINCLUDE, ppInclude);
|
||||||
ppKeywords.put(Keywords.cDEFINE, ppDefine); //$NON-NLS-1$
|
ppKeywords.put(Keywords.cDEFINE, ppDefine);
|
||||||
ppKeywords.put(Keywords.cUNDEF, ppUndef); //$NON-NLS-1$
|
ppKeywords.put(Keywords.cUNDEF, ppUndef);
|
||||||
ppKeywords.put(Keywords.cERROR, ppError); //$NON-NLS-1$
|
ppKeywords.put(Keywords.cERROR, ppError);
|
||||||
ppKeywords.put(Keywords.cINCLUDE_NEXT, ppInclude_next); //$NON-NLS-1$
|
ppKeywords.put(Keywords.cINCLUDE_NEXT, ppInclude_next);
|
||||||
ppKeywords.put(Keywords.cPRAGMA, ppPragma); //$NON-NLS-1$
|
ppKeywords.put(Keywords.cPRAGMA, ppPragma);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class DOMScanner extends BaseScanner {
|
||||||
char[] filenamePath, boolean local, int startOffset,
|
char[] filenamePath, boolean local, int startOffset,
|
||||||
int startingLineNumber, int nameOffset, int nameEndOffset,
|
int startingLineNumber, int nameOffset, int nameEndOffset,
|
||||||
int nameLine, int endOffset, int endLine, boolean isForced) {
|
int nameLine, int endOffset, int endLine, boolean isForced) {
|
||||||
return new DOMInclusion(filenamePath, resolveOffset(startOffset));
|
return new DOMInclusion(filenamePath, getGlobalOffset(startOffset));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -148,13 +148,13 @@ public class DOMScanner extends BaseScanner {
|
||||||
IScannerPreprocessorLog.IMacroDefinition m = null;
|
IScannerPreprocessorLog.IMacroDefinition m = null;
|
||||||
if (macro instanceof FunctionStyleMacro)
|
if (macro instanceof FunctionStyleMacro)
|
||||||
m = locationMap.defineFunctionStyleMacro(
|
m = locationMap.defineFunctionStyleMacro(
|
||||||
(FunctionStyleMacro) macro, resolveOffset(startingOffset),
|
(FunctionStyleMacro) macro, getGlobalOffset(startingOffset),
|
||||||
resolveOffset(idstart), resolveOffset(idend),
|
getGlobalOffset(idstart), getGlobalOffset(idend),
|
||||||
resolveOffset(textEnd));
|
getGlobalOffset(textEnd));
|
||||||
else if (macro instanceof ObjectStyleMacro)
|
else if (macro instanceof ObjectStyleMacro)
|
||||||
m = locationMap.defineObjectStyleMacro((ObjectStyleMacro) macro,
|
m = locationMap.defineObjectStyleMacro((ObjectStyleMacro) macro,
|
||||||
resolveOffset(startingOffset), resolveOffset(idstart),
|
getGlobalOffset(startingOffset), getGlobalOffset(idstart),
|
||||||
resolveOffset(idend), resolveOffset(textEnd));
|
getGlobalOffset(idend), getGlobalOffset(textEnd));
|
||||||
if (m != null && macro instanceof ObjectStyleMacro)
|
if (m != null && macro instanceof ObjectStyleMacro)
|
||||||
((ObjectStyleMacro) macro).attachment = m;
|
((ObjectStyleMacro) macro).attachment = m;
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ public class DOMScanner extends BaseScanner {
|
||||||
if( ! isCircularInclusion( (InclusionData) data ))
|
if( ! isCircularInclusion( (InclusionData) data ))
|
||||||
{
|
{
|
||||||
DOMInclusion inc = ((DOMInclusion) ((InclusionData) data).inclusion);
|
DOMInclusion inc = ((DOMInclusion) ((InclusionData) data).inclusion);
|
||||||
locationMap.startInclusion(((InclusionData) data).reader, inc.o, resolveOffset(getCurrentOffset()));
|
locationMap.startInclusion(((InclusionData) data).reader, inc.o, getGlobalOffset(getCurrentOffset())+1);
|
||||||
bufferDelta[bufferStackPos + 1] = 0;
|
bufferDelta[bufferStackPos + 1] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,21 +203,23 @@ public class DOMScanner extends BaseScanner {
|
||||||
MacroData d = (MacroData) data;
|
MacroData d = (MacroData) data;
|
||||||
if (d.macro instanceof FunctionStyleMacro && fsmCount == 0) {
|
if (d.macro instanceof FunctionStyleMacro && fsmCount == 0) {
|
||||||
FunctionStyleMacro fsm = (FunctionStyleMacro) d.macro;
|
FunctionStyleMacro fsm = (FunctionStyleMacro) d.macro;
|
||||||
|
int startOffset= getGlobalOffset(d.getStartOffset());
|
||||||
|
int endOffset= startOffset+d.getLength();
|
||||||
locationMap.startFunctionStyleExpansion(fsm.attachment,
|
locationMap.startFunctionStyleExpansion(fsm.attachment,
|
||||||
fsm.arglist, resolveOffset(d.startOffset),
|
fsm.arglist, startOffset, endOffset);
|
||||||
resolveOffset(d.endOffset));
|
|
||||||
bufferDelta[bufferStackPos + 1] = 0;
|
bufferDelta[bufferStackPos + 1] = 0;
|
||||||
} else if (d.macro instanceof ObjectStyleMacro && fsmCount == 0) {
|
} else if (d.macro instanceof ObjectStyleMacro && fsmCount == 0) {
|
||||||
ObjectStyleMacro osm = (ObjectStyleMacro) d.macro;
|
ObjectStyleMacro osm = (ObjectStyleMacro) d.macro;
|
||||||
|
int startOffset= getGlobalOffset(d.getStartOffset());
|
||||||
|
int endOffset= startOffset+d.getLength();
|
||||||
locationMap.startObjectStyleMacroExpansion(osm.attachment,
|
locationMap.startObjectStyleMacroExpansion(osm.attachment,
|
||||||
resolveOffset(d.startOffset),
|
startOffset, endOffset);
|
||||||
resolveOffset(d.endOffset));
|
|
||||||
bufferDelta[bufferStackPos + 1] = 0;
|
bufferDelta[bufferStackPos + 1] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if( data instanceof CodeReader && !macroFilesInitialized )
|
else if( data instanceof CodeReader && !macroFilesInitialized )
|
||||||
{
|
{
|
||||||
int resolved = getGlobalCounter(0);
|
int resolved = getGlobalOffset(0, 0);
|
||||||
locationMap.startInclusion( (CodeReader) data, resolved, resolved );
|
locationMap.startInclusion( (CodeReader) data, resolved, resolved );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,23 +235,21 @@ public class DOMScanner extends BaseScanner {
|
||||||
*/
|
*/
|
||||||
protected Object popContext() {
|
protected Object popContext() {
|
||||||
Object result = super.popContext();
|
Object result = super.popContext();
|
||||||
int delta_pos = 0;
|
int bufferEndOffset = Math.min(bufferPos[bufferStackPos+1] + 1, bufferLimit[bufferStackPos+1]);
|
||||||
if( bufferPos[bufferStackPos + 1] > bufferLimit[ bufferStackPos + 1 ] )
|
|
||||||
delta_pos += bufferLimit[ bufferStackPos + 1 ];
|
|
||||||
else
|
|
||||||
delta_pos += bufferPos[ bufferStackPos + 1 ];
|
|
||||||
|
|
||||||
if (result instanceof CodeReader) {
|
if (result instanceof CodeReader) {
|
||||||
if( isInitialized )
|
CodeReader codeReader = (CodeReader) result;
|
||||||
locationMap.endTranslationUnit(bufferDelta[0]
|
if( isInitialized ) {
|
||||||
+ ((CodeReader) result).buffer.length);
|
locationMap.endTranslationUnit(bufferDelta[0] + codeReader.buffer.length);
|
||||||
else
|
}
|
||||||
{
|
else {
|
||||||
bufferDelta[0] += bufferDelta[bufferStackPos + 1] + ((CodeReader) result).buffer.length;
|
// handling of macro-file
|
||||||
locationMap.endInclusion( ((CodeReader) result), getGlobalCounter(0) );
|
bufferDelta[0] += codeReader.buffer.length;
|
||||||
|
locationMap.endInclusion(codeReader, getGlobalOffset(0,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (result instanceof InclusionData) {
|
}
|
||||||
|
else if (result instanceof InclusionData) {
|
||||||
CodeReader codeReader = ((InclusionData) result).reader;
|
CodeReader codeReader = ((InclusionData) result).reader;
|
||||||
if (log.isTracing()) {
|
if (log.isTracing()) {
|
||||||
StringBuffer buffer = new StringBuffer("Exiting inclusion "); //$NON-NLS-1$
|
StringBuffer buffer = new StringBuffer("Exiting inclusion "); //$NON-NLS-1$
|
||||||
|
@ -257,64 +257,33 @@ public class DOMScanner extends BaseScanner {
|
||||||
log.traceLog(buffer.toString());
|
log.traceLog(buffer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
int value = getGlobalCounter(bufferStackPos + 1) + delta_pos;
|
int endOffset = getGlobalOffset(bufferStackPos+1, bufferEndOffset);
|
||||||
locationMap.endInclusion(codeReader, value);
|
locationMap.endInclusion(codeReader, endOffset);
|
||||||
bufferDelta[bufferStackPos] += bufferDelta[bufferStackPos + 1]
|
bufferDelta[bufferStackPos] += bufferDelta[bufferStackPos + 1] + bufferEndOffset;
|
||||||
+ codeReader.buffer.length;
|
}
|
||||||
} else if (result instanceof MacroData) {
|
else if (result instanceof MacroData) {
|
||||||
|
int endOffset = getGlobalOffset(bufferStackPos + 1, bufferEndOffset);
|
||||||
MacroData data = (MacroData) result;
|
MacroData data = (MacroData) result;
|
||||||
if (data.macro instanceof FunctionStyleMacro && fsmCount == 0) {
|
if (data.macro instanceof FunctionStyleMacro && fsmCount == 0) {
|
||||||
|
locationMap.endFunctionStyleExpansion(((FunctionStyleMacro)data.macro).attachment, endOffset);
|
||||||
locationMap
|
bufferDelta[bufferStackPos]+= bufferDelta[bufferStackPos + 1] + bufferEndOffset;
|
||||||
.endFunctionStyleExpansion(((FunctionStyleMacro)data.macro).attachment, getGlobalCounter(bufferStackPos + 1)
|
}
|
||||||
+ delta_pos + 1); // functionstyle
|
else if (data.macro instanceof ObjectStyleMacro && fsmCount == 0) {
|
||||||
// macro)
|
locationMap.endObjectStyleMacroExpansion(((ObjectStyleMacro)data.macro).attachment, endOffset);
|
||||||
// ;
|
bufferDelta[bufferStackPos]+= bufferDelta[bufferStackPos + 1] + bufferEndOffset;
|
||||||
bufferDelta[bufferStackPos] += bufferDelta[bufferStackPos + 1]
|
|
||||||
+ delta_pos + 1;
|
|
||||||
} else if (data.macro instanceof ObjectStyleMacro && fsmCount == 0) {
|
|
||||||
locationMap
|
|
||||||
.endObjectStyleMacroExpansion(((ObjectStyleMacro)data.macro).attachment, getGlobalCounter(bufferStackPos + 1)
|
|
||||||
+ delta_pos );
|
|
||||||
bufferDelta[bufferStackPos] += bufferDelta[bufferStackPos + 1]
|
|
||||||
+ delta_pos;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getGlobalCounter(int value) {
|
|
||||||
if (value < 0)
|
|
||||||
return 0;
|
|
||||||
int result = bufferDelta[value];
|
|
||||||
for (int i = value - 1; i >= 0; --i)
|
|
||||||
{
|
|
||||||
if( bufferPos[i] > bufferLimit[i] )
|
|
||||||
result += bufferLimit[i] + bufferDelta[i];
|
|
||||||
else
|
|
||||||
result += bufferPos[i] + bufferDelta[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getGlobalCounter() {
|
|
||||||
return getGlobalCounter(bufferStackPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected IToken newToken(int signal) {
|
protected IToken newToken(int signal) {
|
||||||
return new _BasicToken(signal,
|
return new _BasicToken(signal,
|
||||||
resolveOffset(bufferPos[bufferStackPos] + 1));
|
getGlobalOffset(bufferPos[bufferStackPos] + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IToken newToken(int signal, char[] buffer) {
|
protected IToken newToken(int signal, char[] buffer) {
|
||||||
IToken i = new _ImagedToken(signal, buffer,
|
IToken i = new _ImagedToken(signal, buffer,
|
||||||
resolveOffset(bufferPos[bufferStackPos] + 1));
|
getGlobalOffset(bufferPos[bufferStackPos] + 1));
|
||||||
if (buffer != null && buffer.length == 0 && signal != IToken.tSTRING
|
if (buffer != null && buffer.length == 0 && signal != IToken.tSTRING
|
||||||
&& signal != IToken.tLSTRING)
|
&& signal != IToken.tLSTRING)
|
||||||
bufferPos[bufferStackPos] += 1; // TODO - remove this hack at some
|
bufferPos[bufferStackPos] += 1; // TODO - remove this hack at some
|
||||||
|
@ -340,18 +309,27 @@ public class DOMScanner extends BaseScanner {
|
||||||
*/
|
*/
|
||||||
protected void handleProblem(int id, int offset, char[] arg) {
|
protected void handleProblem(int id, int offset, char[] arg) {
|
||||||
IASTProblem problem = new ScannerASTProblem(id, arg, true, false);
|
IASTProblem problem = new ScannerASTProblem(id, arg, true, false);
|
||||||
int o = resolveOffset(offset);
|
int o = getGlobalOffset(offset);
|
||||||
((ScannerASTProblem) problem).setOffsetAndLength(o,
|
((ScannerASTProblem) problem).setOffsetAndLength(o,
|
||||||
resolveOffset(getCurrentOffset() + 1) - o);
|
getGlobalOffset(getCurrentOffset() + 1) - o);
|
||||||
locationMap.encounterProblem(problem);
|
locationMap.encounterProblem(problem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param offset
|
* works only if bufferOffset is past the last context inserted in the current one.
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
private int resolveOffset(int offset) {
|
private int getGlobalOffset(int bufferOffset) {
|
||||||
return getGlobalCounter() + offset;
|
return getGlobalOffset(bufferStackPos, bufferOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getGlobalOffset(int stackPos, int offset) {
|
||||||
|
if (stackPos < 0)
|
||||||
|
return offset;
|
||||||
|
offset+= bufferDelta[stackPos];
|
||||||
|
for (int i = stackPos - 1; i >= 0; --i) {
|
||||||
|
offset+= Math.min(bufferPos[i]+1, bufferLimit[i]) + bufferDelta[i];
|
||||||
|
}
|
||||||
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -375,11 +353,11 @@ public class DOMScanner extends BaseScanner {
|
||||||
protected void processIfdef(int startPos, int endPos, boolean positive,
|
protected void processIfdef(int startPos, int endPos, boolean positive,
|
||||||
boolean taken) {
|
boolean taken) {
|
||||||
if (positive)
|
if (positive)
|
||||||
locationMap.encounterPoundIfdef(resolveOffset(startPos),
|
locationMap.encounterPoundIfdef(getGlobalOffset(startPos),
|
||||||
resolveOffset(endPos), taken);
|
getGlobalOffset(endPos), taken);
|
||||||
else
|
else
|
||||||
locationMap.encounterPoundIfndef(resolveOffset(startPos),
|
locationMap.encounterPoundIfndef(getGlobalOffset(startPos),
|
||||||
resolveOffset(endPos), taken);
|
getGlobalOffset(endPos), taken);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,8 +368,8 @@ public class DOMScanner extends BaseScanner {
|
||||||
* int, boolean)
|
* int, boolean)
|
||||||
*/
|
*/
|
||||||
protected void processIf(int startPos, int endPos, boolean taken) {
|
protected void processIf(int startPos, int endPos, boolean taken) {
|
||||||
locationMap.encounterPoundIf(resolveOffset(startPos),
|
locationMap.encounterPoundIf(getGlobalOffset(startPos),
|
||||||
resolveOffset(endPos), taken);
|
getGlobalOffset(endPos), taken);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -401,8 +379,8 @@ public class DOMScanner extends BaseScanner {
|
||||||
* int, boolean)
|
* int, boolean)
|
||||||
*/
|
*/
|
||||||
protected void processElsif(int startPos, int endPos, boolean taken) {
|
protected void processElsif(int startPos, int endPos, boolean taken) {
|
||||||
locationMap.encounterPoundElif(resolveOffset(startPos),
|
locationMap.encounterPoundElif(getGlobalOffset(startPos),
|
||||||
resolveOffset(endPos), taken);
|
getGlobalOffset(endPos), taken);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -412,8 +390,8 @@ public class DOMScanner extends BaseScanner {
|
||||||
* int, boolean)
|
* int, boolean)
|
||||||
*/
|
*/
|
||||||
protected void processElse(int startPos, int endPos, boolean taken) {
|
protected void processElse(int startPos, int endPos, boolean taken) {
|
||||||
locationMap.encounterPoundElse(resolveOffset(startPos),
|
locationMap.encounterPoundElse(getGlobalOffset(startPos),
|
||||||
resolveOffset(endPos), taken);
|
getGlobalOffset(endPos), taken);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -426,8 +404,8 @@ public class DOMScanner extends BaseScanner {
|
||||||
int namePos, Object definition) {
|
int namePos, Object definition) {
|
||||||
final IScannerPreprocessorLog.IMacroDefinition macroDefinition = (definition instanceof ObjectStyleMacro) ? ((ObjectStyleMacro) definition).attachment
|
final IScannerPreprocessorLog.IMacroDefinition macroDefinition = (definition instanceof ObjectStyleMacro) ? ((ObjectStyleMacro) definition).attachment
|
||||||
: null;
|
: null;
|
||||||
locationMap.encounterPoundUndef(resolveOffset(pos),
|
locationMap.encounterPoundUndef(getGlobalOffset(pos),
|
||||||
resolveOffset(endPos), symbol, namePos, macroDefinition);
|
getGlobalOffset(endPos), symbol, namePos, macroDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -437,8 +415,8 @@ public class DOMScanner extends BaseScanner {
|
||||||
* int)
|
* int)
|
||||||
*/
|
*/
|
||||||
protected void processError(int startPos, int endPos) {
|
protected void processError(int startPos, int endPos) {
|
||||||
locationMap.encounterPoundError(resolveOffset(startPos),
|
locationMap.encounterPoundError(getGlobalOffset(startPos),
|
||||||
resolveOffset(endPos));
|
getGlobalOffset(endPos));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -448,8 +426,7 @@ public class DOMScanner extends BaseScanner {
|
||||||
* int)
|
* int)
|
||||||
*/
|
*/
|
||||||
protected void processEndif(int startPos, int endPos) {
|
protected void processEndif(int startPos, int endPos) {
|
||||||
locationMap.encounterPoundEndIf(resolveOffset(startPos),
|
locationMap.encounterPoundEndIf(getGlobalOffset(startPos), getGlobalOffset(endPos));
|
||||||
resolveOffset(endPos));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -459,8 +436,7 @@ public class DOMScanner extends BaseScanner {
|
||||||
* int)
|
* int)
|
||||||
*/
|
*/
|
||||||
protected void processPragma(int startPos, int endPos) {
|
protected void processPragma(int startPos, int endPos) {
|
||||||
locationMap.encounterPoundPragma(resolveOffset(startPos),
|
locationMap.encounterPoundPragma(getGlobalOffset(startPos), getGlobalOffset(endPos));
|
||||||
resolveOffset(endPos));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void beforeReplaceAllMacros() {
|
protected void beforeReplaceAllMacros() {
|
||||||
|
|
|
@ -913,26 +913,50 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global offset of start of directive (inclusive).
|
||||||
|
*/
|
||||||
public int context_directive_start;
|
public int context_directive_start;
|
||||||
public int context_directive_end; // inclusive
|
/**
|
||||||
public int context_ends; // inclusive
|
* Global offset of end of directive (exclusive).
|
||||||
|
*/
|
||||||
|
public int context_directive_end;
|
||||||
|
/**
|
||||||
|
* Global offset of end of context introduced by directive (exclusive).
|
||||||
|
*/
|
||||||
|
public int context_ends;
|
||||||
public _CompositeContext parent;
|
public _CompositeContext parent;
|
||||||
|
|
||||||
public _CompositeContext getParent() {
|
public _CompositeContext getParent() {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDirectiveStart() {
|
||||||
|
return context_directive_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDirectiveLength() {
|
||||||
|
return context_directive_end - context_directive_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getContextStart() {
|
||||||
|
return context_directive_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getContextLength() {
|
||||||
|
return context_ends- context_directive_end;
|
||||||
|
}
|
||||||
|
|
||||||
public final boolean contains(int offset) {
|
public final boolean contains(int offset) {
|
||||||
return (offset >= context_directive_start && offset <= context_ends);
|
return (offset >= context_directive_start && offset < context_ends);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean containsInContext(int offset) {
|
||||||
|
return (offset >= context_directive_end && offset < context_ends);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsInDirective(int offset, int length) {
|
public boolean containsInDirective(int offset, int length) {
|
||||||
if( length > 0 && offset == context_directive_end )
|
return context_directive_start <= offset && offset + length <= context_directive_end;
|
||||||
return false;
|
|
||||||
if (offset >= context_directive_start
|
|
||||||
&& offset + length - 1 <= context_directive_end )
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAncestor(_Context cc) {
|
public boolean hasAncestor(_Context cc) {
|
||||||
|
@ -1005,7 +1029,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
if (c== null || offset < c.context_directive_start) {
|
if (c== null || offset < c.context_directive_start) {
|
||||||
right= middle-1;
|
right= middle-1;
|
||||||
}
|
}
|
||||||
else if (offset > c.context_ends) {
|
else if (offset >= c.context_ends) {
|
||||||
left= middle+1;
|
left= middle+1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1021,7 +1045,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if no sub context contains this, do it this way
|
// if no sub context contains this, do it this way
|
||||||
if ((offset >= context_directive_start && offset <= context_ends))
|
if ((offset >= context_directive_start && offset < context_ends))
|
||||||
return this;
|
return this;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1037,6 +1061,23 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getOffsetInContext(int globalOffset) {
|
||||||
|
int externalCount= 0;
|
||||||
|
if (subContexts != null) {
|
||||||
|
for (int i = 0; i < subContexts.length; ++i) {
|
||||||
|
_Context subC = subContexts[i];
|
||||||
|
if (subC == null || globalOffset < subC.getContextStart()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (subC instanceof _CompositeContext) {
|
||||||
|
assert !subC.containsInContext(globalOffset);
|
||||||
|
externalCount+= subC.getContextLength();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final int result = globalOffset - externalCount - getContextStart();
|
||||||
|
return ((result < 0) ? 0 : result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class _CompositeFileContext extends _CompositeContext {
|
protected static class _CompositeFileContext extends _CompositeContext {
|
||||||
|
@ -1065,7 +1106,6 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
}
|
}
|
||||||
return lineNumber;
|
return lineNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class _Inclusion extends _CompositeFileContext implements
|
protected static class _Inclusion extends _CompositeFileContext implements
|
||||||
|
@ -1079,10 +1119,6 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
|
|
||||||
protected static class _TranslationUnit extends _CompositeFileContext {
|
protected static class _TranslationUnit extends _CompositeFileContext {
|
||||||
|
|
||||||
/**
|
|
||||||
* @param startOffset
|
|
||||||
* @param endOffset
|
|
||||||
*/
|
|
||||||
public _TranslationUnit() {
|
public _TranslationUnit() {
|
||||||
super(null, 0, 0 );
|
super(null, 0, 0 );
|
||||||
}
|
}
|
||||||
|
@ -1248,7 +1284,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
expansionName = new ASTMacroName( definition.getName() );
|
expansionName = new ASTMacroName( definition.getName() );
|
||||||
expansionName.setParent( rootNode );
|
expansionName.setParent( rootNode );
|
||||||
expansionName.setPropertyInParent( IASTTranslationUnit.EXPANSION_NAME );
|
expansionName.setPropertyInParent( IASTTranslationUnit.EXPANSION_NAME );
|
||||||
((ASTNode)expansionName).setOffsetAndLength( context_directive_start, context_directive_end - context_directive_start + 1);
|
((ASTNode)expansionName).setOffsetAndLength(context_directive_start, getDirectiveLength());
|
||||||
}
|
}
|
||||||
return expansionName;
|
return expansionName;
|
||||||
}
|
}
|
||||||
|
@ -1358,8 +1394,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
((ASTNode) name).setOffsetAndLength(d.nameOffset, d.name.length);
|
((ASTNode) name).setOffsetAndLength(d.nameOffset, d.name.length);
|
||||||
r.setName(name);
|
r.setName(name);
|
||||||
r.setExpansion(new String(d.getExpansion()));
|
r.setExpansion(new String(d.getExpansion()));
|
||||||
((ASTNode) r).setOffsetAndLength(d.context_directive_start,
|
((ASTNode) r).setOffsetAndLength(d.context_directive_start, d.getDirectiveLength());
|
||||||
d.context_directive_end - d.context_directive_start);
|
|
||||||
d.astNode = r;
|
d.astNode = r;
|
||||||
r.setParent(rootNode);
|
r.setParent(rootNode);
|
||||||
r.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
r.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
||||||
|
@ -1392,11 +1427,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
private IASTPreprocessorIncludeStatement createASTInclusion(_Inclusion inc) {
|
private IASTPreprocessorIncludeStatement createASTInclusion(_Inclusion inc) {
|
||||||
IASTPreprocessorIncludeStatement result = new ASTInclusionStatement(
|
IASTPreprocessorIncludeStatement result = new ASTInclusionStatement(
|
||||||
inc.reader.filename);
|
inc.reader.filename);
|
||||||
((ASTNode) result).setOffsetAndLength(
|
((ASTNode) result).setOffsetAndLength(inc.context_directive_start, inc.getDirectiveLength());
|
||||||
inc.context_directive_start, inc.context_directive_end
|
((ASTInclusionStatement) result).startOffset = inc.getContextStart();
|
||||||
- inc.context_directive_start);
|
((ASTInclusionStatement) result).endOffset = inc.context_directive_end;
|
||||||
((ASTInclusionStatement) result).startOffset = inc.context_directive_end;
|
|
||||||
((ASTInclusionStatement) result).endOffset = inc.context_ends;
|
|
||||||
((ASTInclusionStatement) result).setParent(rootNode);
|
((ASTInclusionStatement) result).setParent(rootNode);
|
||||||
((ASTInclusionStatement) result).setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
((ASTInclusionStatement) result).setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
||||||
result.setParent(rootNode);
|
result.setParent(rootNode);
|
||||||
|
@ -1457,8 +1490,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
*/
|
*/
|
||||||
private IASTPreprocessorStatement createASTEndif(_Endif endif) {
|
private IASTPreprocessorStatement createASTEndif(_Endif endif) {
|
||||||
IASTPreprocessorEndifStatement result = new ASTEndif();
|
IASTPreprocessorEndifStatement result = new ASTEndif();
|
||||||
((ASTNode) result).setOffsetAndLength(endif.context_directive_start,
|
((ASTNode) result).setOffsetAndLength(endif.context_directive_start, endif.getDirectiveLength());
|
||||||
endif.context_directive_end - endif.context_directive_start);
|
|
||||||
result.setParent(rootNode);
|
result.setParent(rootNode);
|
||||||
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1470,8 +1502,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
*/
|
*/
|
||||||
private IASTPreprocessorStatement createASTElif(_Elif elif) {
|
private IASTPreprocessorStatement createASTElif(_Elif elif) {
|
||||||
IASTPreprocessorElifStatement result = new ASTElif(elif.taken);
|
IASTPreprocessorElifStatement result = new ASTElif(elif.taken);
|
||||||
((ASTNode) result).setOffsetAndLength(elif.context_directive_start,
|
((ASTNode) result).setOffsetAndLength(elif.context_directive_start, elif.getDirectiveLength());
|
||||||
elif.context_directive_end - elif.context_directive_start);
|
|
||||||
result.setParent(rootNode);
|
result.setParent(rootNode);
|
||||||
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1483,8 +1514,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
*/
|
*/
|
||||||
private IASTPreprocessorStatement createASTElse(_Else e) {
|
private IASTPreprocessorStatement createASTElse(_Else e) {
|
||||||
IASTPreprocessorElseStatement result = new ASTElse(e.taken);
|
IASTPreprocessorElseStatement result = new ASTElse(e.taken);
|
||||||
((ASTNode) result).setOffsetAndLength(e.context_directive_start,
|
((ASTNode) result).setOffsetAndLength(e.context_directive_start, e.getDirectiveLength());
|
||||||
e.context_directive_end - e.context_directive_start);
|
|
||||||
result.setParent(rootNode);
|
result.setParent(rootNode);
|
||||||
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1496,8 +1526,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
*/
|
*/
|
||||||
private IASTPreprocessorStatement createASTIfndef(_Ifndef ifndef) {
|
private IASTPreprocessorStatement createASTIfndef(_Ifndef ifndef) {
|
||||||
IASTPreprocessorIfndefStatement result = new ASTIfndef(ifndef.taken);
|
IASTPreprocessorIfndefStatement result = new ASTIfndef(ifndef.taken);
|
||||||
((ASTNode) result).setOffsetAndLength(ifndef.context_directive_start,
|
((ASTNode) result).setOffsetAndLength(ifndef.context_directive_start, ifndef.getDirectiveLength());
|
||||||
ifndef.context_directive_end - ifndef.context_directive_start);
|
|
||||||
result.setParent(rootNode);
|
result.setParent(rootNode);
|
||||||
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1509,8 +1538,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
*/
|
*/
|
||||||
private IASTPreprocessorStatement createASTIfdef(_Ifdef ifdef) {
|
private IASTPreprocessorStatement createASTIfdef(_Ifdef ifdef) {
|
||||||
IASTPreprocessorIfdefStatement result = new ASTIfdef(ifdef.taken);
|
IASTPreprocessorIfdefStatement result = new ASTIfdef(ifdef.taken);
|
||||||
((ASTNode) result).setOffsetAndLength(ifdef.context_directive_start,
|
((ASTNode) result).setOffsetAndLength(ifdef.context_directive_start, ifdef.getDirectiveLength());
|
||||||
ifdef.context_directive_end - ifdef.context_directive_start);
|
|
||||||
result.setParent(rootNode);
|
result.setParent(rootNode);
|
||||||
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1522,8 +1550,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
*/
|
*/
|
||||||
private IASTPreprocessorStatement createASTIf(_If i) {
|
private IASTPreprocessorStatement createASTIf(_If i) {
|
||||||
IASTPreprocessorIfStatement result = new ASTIf(i.taken);
|
IASTPreprocessorIfStatement result = new ASTIf(i.taken);
|
||||||
((ASTNode) result).setOffsetAndLength(i.context_directive_start,
|
((ASTNode) result).setOffsetAndLength(i.context_directive_start, i.getDirectiveLength());
|
||||||
i.context_directive_end - i.context_directive_start);
|
|
||||||
result.setParent(rootNode);
|
result.setParent(rootNode);
|
||||||
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1535,8 +1562,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
*/
|
*/
|
||||||
private IASTPreprocessorStatement createASTError(_Error error) {
|
private IASTPreprocessorStatement createASTError(_Error error) {
|
||||||
IASTPreprocessorErrorStatement result = new ASTError();
|
IASTPreprocessorErrorStatement result = new ASTError();
|
||||||
((ASTNode) result).setOffsetAndLength(error.context_directive_start,
|
((ASTNode) result).setOffsetAndLength(error.context_directive_start, error.getDirectiveLength());
|
||||||
error.context_directive_end - error.context_directive_start);
|
|
||||||
result.setParent(rootNode);
|
result.setParent(rootNode);
|
||||||
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1548,8 +1574,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
*/
|
*/
|
||||||
private IASTPreprocessorStatement createASTPragma(_Pragma pragma) {
|
private IASTPreprocessorStatement createASTPragma(_Pragma pragma) {
|
||||||
IASTPreprocessorPragmaStatement result = new ASTPragma();
|
IASTPreprocessorPragmaStatement result = new ASTPragma();
|
||||||
((ASTNode) result).setOffsetAndLength(pragma.context_directive_start,
|
((ASTNode) result).setOffsetAndLength(pragma.getDirectiveStart(), pragma.getDirectiveLength());
|
||||||
pragma.context_directive_end - pragma.context_directive_start);
|
|
||||||
result.setParent(rootNode);
|
result.setParent(rootNode);
|
||||||
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1561,8 +1586,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
*/
|
*/
|
||||||
private IASTPreprocessorStatement createASTUndef(_Undef undef) {
|
private IASTPreprocessorStatement createASTUndef(_Undef undef) {
|
||||||
IASTPreprocessorUndefStatement result = new ASTUndef(undef.getName());
|
IASTPreprocessorUndefStatement result = new ASTUndef(undef.getName());
|
||||||
((ASTNode) result).setOffsetAndLength(undef.context_directive_start,
|
((ASTNode) result).setOffsetAndLength(undef.getDirectiveStart(), undef.getDirectiveLength());
|
||||||
undef.context_directive_end - undef.context_directive_start);
|
|
||||||
result.setParent(rootNode);
|
result.setParent(rootNode);
|
||||||
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1580,8 +1604,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
_Context c = findContextForOffset(offset);
|
_Context c = findContextForOffset(offset);
|
||||||
if( c == null )
|
if( c == null )
|
||||||
return EMPTY_LOCATION_ARRAY;
|
return EMPTY_LOCATION_ARRAY;
|
||||||
int offset1 = offset + length - 1;
|
if (offset + length <= c.context_ends) {
|
||||||
if (offset1 < c.context_ends) {
|
|
||||||
if (c instanceof _CompositeContext) {
|
if (c instanceof _CompositeContext) {
|
||||||
_Context[] subz = ((_CompositeContext) c).getSubContexts();
|
_Context[] subz = ((_CompositeContext) c).getSubContexts();
|
||||||
boolean foundNested = findNested( subz, offset, length);
|
boolean foundNested = findNested( subz, offset, length);
|
||||||
|
@ -1615,7 +1638,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
if (offset2 < sub.context_directive_start) {
|
if (offset2 < sub.context_directive_start) {
|
||||||
right= middle-1;
|
right= middle-1;
|
||||||
}
|
}
|
||||||
else if (offset > sub.context_ends) {
|
else if (offset >= sub.context_ends) {
|
||||||
left= middle+1;
|
left= middle+1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1678,38 +1701,32 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
|
|
||||||
protected IASTNodeLocation createSoleLocation(_Context c, int offset,
|
protected IASTNodeLocation createSoleLocation(_Context c, int offset,
|
||||||
int length) {
|
int length) {
|
||||||
|
|
||||||
if (c instanceof _IPreprocessorDirective || c instanceof _Problem ) {
|
if (c instanceof _IPreprocessorDirective || c instanceof _Problem ) {
|
||||||
if (c.containsInDirective(offset, length)) {
|
if (c.containsInDirective(offset, length)) {
|
||||||
_CompositeContext parent = c.parent;
|
_CompositeContext parent = c.parent;
|
||||||
while (!(parent instanceof _CompositeFileContext))
|
if (parent instanceof _CompositeFileContext) {
|
||||||
parent = parent.parent;
|
|
||||||
_CompositeFileContext fc = (_CompositeFileContext) parent;
|
_CompositeFileContext fc = (_CompositeFileContext) parent;
|
||||||
return new FileLocation(fc.reader.filename, reconcileOffset(fc,
|
return new FileLocation(fc.reader.filename, fc.getOffsetInContext(offset), length);
|
||||||
c, offset), length);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (c instanceof _CompositeFileContext) {
|
if (c instanceof _CompositeFileContext) {
|
||||||
return new FileLocation(
|
_CompositeFileContext cfc = (_CompositeFileContext) c;
|
||||||
((_CompositeFileContext) c).reader.filename,
|
return new FileLocation(cfc.reader.filename, cfc.getOffsetInContext(offset), length);
|
||||||
reconcileOffset(c, offset), length);
|
|
||||||
}
|
}
|
||||||
if (c instanceof _MacroExpansion) {
|
if (c instanceof _MacroExpansion) {
|
||||||
_MacroExpansion expansion = (_MacroExpansion) c;
|
_MacroExpansion expansion = (_MacroExpansion) c;
|
||||||
//first check to see if we are in the directive rather than the expansion
|
if (c.containsInDirective(offset, length)) {
|
||||||
if( c.containsInDirective( offset, length ) )
|
|
||||||
{
|
|
||||||
_CompositeContext parent = c.parent;
|
_CompositeContext parent = c.parent;
|
||||||
while (!(parent instanceof _CompositeFileContext))
|
if (parent instanceof _CompositeFileContext) {
|
||||||
parent = parent.parent;
|
|
||||||
_CompositeFileContext fc = (_CompositeFileContext) parent;
|
_CompositeFileContext fc = (_CompositeFileContext) parent;
|
||||||
return new FileLocation(fc.reader.filename, reconcileOffset(fc,
|
return new FileLocation(fc.reader.filename, fc.getOffsetInContext(offset), length);
|
||||||
c, offset), length);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IASTNodeLocation[] locations = createSoleLocationArray(c.parent,
|
IASTNodeLocation[] locations = createSoleLocationArray(c.parent, c.getDirectiveStart(), c.getDirectiveLength());
|
||||||
c.context_directive_start, c.context_directive_end
|
|
||||||
- c.context_directive_start + 1);
|
|
||||||
IASTPreprocessorMacroDefinition definition = null;
|
IASTPreprocessorMacroDefinition definition = null;
|
||||||
_MacroDefinition d = (_MacroDefinition) expansion.definition;
|
_MacroDefinition d = (_MacroDefinition) expansion.definition;
|
||||||
if (d.astNode != null)
|
if (d.astNode != null)
|
||||||
|
@ -1720,8 +1737,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
definition = astNode;
|
definition = astNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MacroExpansionLocation(definition, locations,
|
return new MacroExpansionLocation(definition, locations, expansion.getOffsetInContext(offset), length);
|
||||||
reconcileOffset(c, offset), length);
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1743,58 +1759,6 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param fc
|
|
||||||
* @param c
|
|
||||||
* @param offset
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected int reconcileOffset(_CompositeFileContext fc, _Context c,
|
|
||||||
int offset) {
|
|
||||||
int subtractOff = 0;
|
|
||||||
if (c.parent == fc) {
|
|
||||||
_Context[] subs = fc.getSubContexts();
|
|
||||||
for (int i = 0; i < subs.length; ++i) {
|
|
||||||
_Context sample = subs[i];
|
|
||||||
if (sample == c)
|
|
||||||
break;
|
|
||||||
if (!(sample instanceof _CompositeContext))
|
|
||||||
continue;
|
|
||||||
subtractOff += sample.context_ends
|
|
||||||
- sample.context_directive_end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return offset - fc.context_directive_end - subtractOff;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param c
|
|
||||||
* @param offset
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected static int reconcileOffset(_Context c, int offset) {
|
|
||||||
int subtractOff = 0;
|
|
||||||
if (c instanceof _CompositeFileContext) {
|
|
||||||
_Context[] subs = ((_CompositeFileContext) c).getSubContexts();
|
|
||||||
for (int i = 0; i < subs.length; ++i) {
|
|
||||||
_Context subC = subs[i];
|
|
||||||
if (subC.context_ends > offset)
|
|
||||||
break;
|
|
||||||
if (!(subC instanceof _CompositeContext))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
subtractOff += subC.context_ends - subC.context_directive_end;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final int result = offset - c.context_directive_end - subtractOff;
|
|
||||||
return ((result < 0) ? 0 : result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param offset
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected _Context findContextForOffset(int offset) {
|
protected _Context findContextForOffset(int offset) {
|
||||||
return tu.findContextContainingOffset(offset);
|
return tu.findContextContainingOffset(offset);
|
||||||
}
|
}
|
||||||
|
@ -2126,9 +2090,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
*/
|
*/
|
||||||
public void encounterProblem(IASTProblem problem) {
|
public void encounterProblem(IASTProblem problem) {
|
||||||
ScannerASTProblem p = (ScannerASTProblem) problem;
|
ScannerASTProblem p = (ScannerASTProblem) problem;
|
||||||
_Problem pr = new _Problem(currentContext, p.getOffset(), p.getOffset()
|
int offset= p.getOffset();
|
||||||
+ p.getLength(), problem);
|
int endoffset= offset + p.getLength();
|
||||||
pr.context_ends = p.getOffset() + p.getLength();
|
_Problem pr = new _Problem(currentContext, offset, endoffset, problem);
|
||||||
currentContext.addSubContext(pr);
|
currentContext.addSubContext(pr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2310,46 +2274,45 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
if (!(startContext instanceof _CompositeContext))
|
if (!(startContext instanceof _CompositeContext))
|
||||||
throw new InvalidPreprocessorNodeException(NOT_VALID_MACRO,
|
throw new InvalidPreprocessorNodeException(NOT_VALID_MACRO,
|
||||||
globalOffset);
|
globalOffset);
|
||||||
_Context[] contexts = ((_CompositeContext) startContext)
|
_Context[] contexts = ((_CompositeContext) startContext).getSubContexts();
|
||||||
.getSubContexts();
|
|
||||||
|
|
||||||
// check if a macro in the location map is the selection
|
// check if a macro in the location map is the selection
|
||||||
for (int i = 0; result == null && i < contexts.length; i++) {
|
for (int i = 0; result == null && i < contexts.length; i++) {
|
||||||
_Context context = contexts[i];
|
_Context context = contexts[i];
|
||||||
|
|
||||||
// if offset is past the _Context then increment globalOffset
|
if (globalOffset < context.getDirectiveStart()) {
|
||||||
if (globalOffset > context.context_directive_end) {
|
break;
|
||||||
globalOffset += context.context_ends
|
|
||||||
- context.context_directive_end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the _Context is the selection
|
// check if the _Context is the selection
|
||||||
if (globalOffset == context.context_directive_start
|
if (globalOffset == context.getDirectiveStart()) {
|
||||||
&& length == context.context_directive_end
|
if( context instanceof _MacroExpansion) {
|
||||||
- context.context_directive_start) {
|
|
||||||
result = createPreprocessorStatement(context);
|
|
||||||
}
|
|
||||||
else if( context instanceof _MacroExpansion && globalOffset == context.context_directive_start )
|
|
||||||
{
|
|
||||||
_MacroExpansion expansion = (_MacroExpansion)context;
|
_MacroExpansion expansion = (_MacroExpansion)context;
|
||||||
if( expansion.definition.getName().length == length )
|
if( expansion.definition.getName().length == length )
|
||||||
result = expansion.getName();
|
result = expansion.getName();
|
||||||
}
|
}
|
||||||
|
else if (length == context.getDirectiveLength()) {
|
||||||
|
result = createPreprocessorStatement(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check if a sub node of the macro is the selection // TODO
|
// check if a sub node of the macro is the selection // TODO
|
||||||
// determine how this can be kept in sync with logic in
|
// determine how this can be kept in sync with logic in
|
||||||
// getAllPreprocessorStatements (i.e. 1:1 mapping)
|
// getAllPreprocessorStatements (i.e. 1:1 mapping)
|
||||||
if ((globalOffset >= context.context_directive_start && globalOffset <= context.context_ends) && context instanceof _MacroDefinition) {
|
if (context.containsInDirective(globalOffset, length)) {
|
||||||
if (globalOffset == ((_MacroDefinition) context).nameOffset
|
if (context instanceof _MacroDefinition) {
|
||||||
&& length == ((_MacroDefinition) context).name.length)
|
_MacroDefinition macroDefinition = (_MacroDefinition) context;
|
||||||
result = createASTMacroDefinition(
|
if (globalOffset == macroDefinition.nameOffset
|
||||||
(_MacroDefinition) context).getName();
|
&& length == macroDefinition.name.length) {
|
||||||
|
result = createASTMacroDefinition(macroDefinition).getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop searching the _Contexts if they've gone past the selection
|
// if offset is past the _Context then increment globalOffset
|
||||||
if (globalOffset < context.context_directive_end)
|
if (globalOffset >= context.getContextStart()) {
|
||||||
break;
|
globalOffset += context.getContextLength();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ASTPreprocessorSelectionResult(result, globalOffset);
|
return new ASTPreprocessorSelectionResult(result, globalOffset);
|
||||||
|
@ -2375,16 +2338,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
foundContext = findInclusion(tu, path);
|
foundContext = findInclusion(tu, path);
|
||||||
|
|
||||||
if (foundContext == null) {
|
if (foundContext == null) {
|
||||||
throw new InvalidPreprocessorNodeException(
|
throw new InvalidPreprocessorNodeException(TU_INCLUDE_NOT_FOUND, globalOffset);
|
||||||
TU_INCLUDE_NOT_FOUND, globalOffset);
|
|
||||||
} else if (foundContext instanceof _Inclusion) {
|
} else if (foundContext instanceof _Inclusion) {
|
||||||
globalOffset = foundContext.context_directive_end + offset; // start
|
globalOffset = foundContext.getContextStart() + offset;
|
||||||
// at
|
|
||||||
// #include's
|
|
||||||
// directive_end
|
|
||||||
// +
|
|
||||||
// real
|
|
||||||
// offset
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -193,8 +193,8 @@ public class Scanner2 extends BaseScanner {
|
||||||
|| bufferData[mostRelevant] instanceof CodeReader)
|
|| bufferData[mostRelevant] instanceof CodeReader)
|
||||||
break;
|
break;
|
||||||
MacroData data = (MacroData) bufferData[mostRelevant + 1];
|
MacroData data = (MacroData) bufferData[mostRelevant + 1];
|
||||||
return new SimpleExpansionToken(signal, data.startOffset,
|
return new SimpleExpansionToken(signal, data.getStartOffset(),
|
||||||
data.endOffset - data.startOffset + 1,
|
data.getLength(),
|
||||||
getCurrentFilename(),
|
getCurrentFilename(),
|
||||||
getLineNumber(bufferPos[mostRelevant] + 1));
|
getLineNumber(bufferPos[mostRelevant] + 1));
|
||||||
}
|
}
|
||||||
|
@ -211,18 +211,14 @@ public class Scanner2 extends BaseScanner {
|
||||||
|| bufferData[mostRelevant] instanceof CodeReader)
|
|| bufferData[mostRelevant] instanceof CodeReader)
|
||||||
break;
|
break;
|
||||||
MacroData data = (MacroData) bufferData[mostRelevant + 1];
|
MacroData data = (MacroData) bufferData[mostRelevant + 1];
|
||||||
return new ImagedExpansionToken(signal, buffer, data.startOffset,
|
return new ImagedExpansionToken(signal, buffer, data.getStartOffset(),
|
||||||
data.endOffset - data.startOffset + 1,
|
data.getLength(),
|
||||||
getCurrentFilename(),
|
getCurrentFilename(),
|
||||||
getLineNumber(bufferPos[mostRelevant] + 1));
|
getLineNumber(bufferPos[mostRelevant] + 1));
|
||||||
}
|
}
|
||||||
IToken i = new ImagedToken(signal, buffer,
|
IToken i = new ImagedToken(signal, buffer,
|
||||||
bufferPos[bufferStackPos] + 1, getCurrentFilename(),
|
bufferPos[bufferStackPos] + 1, getCurrentFilename(),
|
||||||
getLineNumber(bufferPos[bufferStackPos] + 1));
|
getLineNumber(bufferPos[bufferStackPos] + 1));
|
||||||
if (buffer != null && buffer.length == 0 && signal != IToken.tSTRING
|
|
||||||
&& signal != IToken.tLSTRING)
|
|
||||||
bufferPos[bufferStackPos] += 1; // TODO - remove this hack at some
|
|
||||||
// point
|
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue