mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
set up tests to run C++ parser, fixed a few bugs
This commit is contained in:
parent
c575310b92
commit
2d00884258
29 changed files with 4542 additions and 4527 deletions
|
@ -68,19 +68,15 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
IExtendedScannerInfo scannerInfo = new ExtendedScannerInfo(
|
||||
Collections.EMPTY_MAP, EMPTY_STRING_ARRAY, macros, includes);
|
||||
String code = "int main() { return BEAST * sizeof( Include ); } "; //$NON-NLS-1$
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
for (ParserLanguage p : ParserLanguage.values()) {
|
||||
String filename = (p == ParserLanguage.CPP) ? "main.cc" : "main.c"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IFile c = importFile(filename, code); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
IASTTranslationUnit tu = parse(c, scannerInfo); //$NON-NLS-1$
|
||||
IASTFunctionDefinition fd = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[3];
|
||||
IASTFunctionDefinition fd = (IASTFunctionDefinition) tu.getDeclarations()[3];
|
||||
IASTFileLocation floc = fd.getFileLocation();
|
||||
assertEquals(
|
||||
floc.getNodeOffset(),
|
||||
code
|
||||
.indexOf("int main() { return BEAST * sizeof( Include ); }")); //$NON-NLS-1$
|
||||
assertEquals(floc.getNodeOffset(),
|
||||
code.indexOf("int main() { return BEAST * sizeof( Include ); }")); //$NON-NLS-1$
|
||||
assertEquals(floc.getNodeLength(),
|
||||
"int main() { return BEAST * sizeof( Include ); }".length()); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -104,15 +100,12 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
buffer.append("int SomeStructure;\n"); //$NON-NLS-1$
|
||||
String code = buffer.toString();
|
||||
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
for (ParserLanguage p : ParserLanguage.values()) {
|
||||
String filename = (p == ParserLanguage.CPP) ? "blah.cc" : "blah.c"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IFile source = importFile(filename, code); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(source); //$NON-NLS-1$
|
||||
IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
assertSoleFileLocation(declaration.getDeclarators()[0],
|
||||
filename,
|
||||
IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
assertSoleFileLocation(declaration.getDeclarators()[0], filename,
|
||||
code.indexOf("SomeStructure"), "SomeStructure".length()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
}
|
||||
|
@ -133,8 +126,7 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
// The problem is that it really depends on how the header was
|
||||
// included.
|
||||
String id = null;
|
||||
IContentType contentType = CCorePlugin
|
||||
.getContentType(prj, filename);
|
||||
IContentType contentType = CCorePlugin.getContentType(prj, filename);
|
||||
if (contentType != null) {
|
||||
id = contentType.getId();
|
||||
}
|
||||
|
@ -179,8 +171,7 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
SavedCodeReaderFactory.getInstance().getCodeReaderCache().flush();
|
||||
return CDOM.getInstance().getTranslationUnit(
|
||||
code,
|
||||
CDOM.getInstance().getCodeReaderFactory(
|
||||
CDOM.PARSE_SAVED_RESOURCES),
|
||||
CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_SAVED_RESOURCES),
|
||||
new ParserConfiguration(s, code));
|
||||
}
|
||||
|
||||
|
@ -191,8 +182,7 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
* @param length
|
||||
* @param declarator
|
||||
*/
|
||||
protected void assertSoleFileLocation(IASTNode n, String pathEndsWith,
|
||||
int offset, int length) {
|
||||
protected void assertSoleFileLocation(IASTNode n, String pathEndsWith, int offset, int length) {
|
||||
IASTNodeLocation[] locations = n.getNodeLocations();
|
||||
assertEquals(locations.length, 1);
|
||||
IASTFileLocation nodeLocation = (IASTFileLocation) locations[0];
|
||||
|
@ -201,8 +191,7 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
assertEquals(length, nodeLocation.getNodeLength());
|
||||
}
|
||||
|
||||
private void assertFileLocation(IASTNode n, String pathEndsWith,
|
||||
int offset, int length) {
|
||||
private void assertFileLocation(IASTNode n, String pathEndsWith, int offset, int length) {
|
||||
IASTFileLocation location = n.getFileLocation();
|
||||
assertTrue(location.getFileName().endsWith(pathEndsWith));
|
||||
assertEquals(offset, location.getNodeOffset());
|
||||
|
@ -215,8 +204,7 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
|
||||
importFile("foo.h", foo); //$NON-NLS-1$
|
||||
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
for (ParserLanguage p : ParserLanguage.values()) {
|
||||
String filename = (p == ParserLanguage.CPP) ? "code.cc" : "code.c"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IFile cpp = importFile(filename, code); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(cpp); //$NON-NLS-1$
|
||||
|
@ -224,11 +212,9 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
assertEquals(declarations.length, 2);
|
||||
IASTSimpleDeclaration bar = (IASTSimpleDeclaration) declarations[0];
|
||||
IASTSimpleDeclaration FOO = (IASTSimpleDeclaration) declarations[1];
|
||||
assertSoleFileLocation(bar, filename,
|
||||
code.indexOf("int"), code.indexOf(";") + 1); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
assertSoleFileLocation(bar, filename, code.indexOf("int"), code.indexOf(";") + 1); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
||||
assertSoleFileLocation(FOO,
|
||||
"foo.h", foo.indexOf("int"), foo.indexOf(";") + 1); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
assertSoleFileLocation(FOO, "foo.h", foo.indexOf("int"), foo.indexOf(";") + 1); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
IASTPreprocessorIncludeStatement[] incs = tu.getIncludeDirectives();
|
||||
assertNotNull(incs);
|
||||
assertEquals(incs.length, 1);
|
||||
|
@ -255,8 +241,7 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
|
||||
importFile("foo.h", foo); //$NON-NLS-1$
|
||||
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
for (ParserLanguage p : ParserLanguage.values()) {
|
||||
String filename = (p == ParserLanguage.CPP) ? "code.cc" : "code.c"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IFile cpp = importFile(filename, code); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(cpp); //$NON-NLS-1$
|
||||
|
@ -291,8 +276,7 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
String h_file_code = "#ifndef _BLARG_H_\r\n#define _BLARG_H_\r\n// macro\r\n#define PRINT(s,m) printf(s,m)\r\n#endif //_BLARG_H_\r\n"; //$NON-NLS-1$
|
||||
importFile("blarg.h", h_file_code); //$NON-NLS-1$
|
||||
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
for (ParserLanguage p : ParserLanguage.values()) {
|
||||
String filename = (p == ParserLanguage.CPP) ? "blah.cc" : "blah.c"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IFile c_file = importFile(filename, c_file_code); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(c_file); //$NON-NLS-1$
|
||||
|
@ -336,8 +320,7 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
importFile("header1.h", header1_code); //$NON-NLS-1$
|
||||
importFile("header2.h", header2_code); //$NON-NLS-1$
|
||||
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
for (ParserLanguage p : ParserLanguage.values()) {
|
||||
String filename = (p == ParserLanguage.CPP) ? "source.cc" : "source.c"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IFile f = importFile(filename, cpp_code); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(f);
|
||||
|
@ -372,14 +355,12 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
importFile("blarg.h", h_file_code); //$NON-NLS-1$
|
||||
importFile("second.h", h_file2_code); //$NON-NLS-1$
|
||||
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
for (ParserLanguage p : ParserLanguage.values()) {
|
||||
String filename = (p == ParserLanguage.CPP) ? "blah.cc" : "blah.c"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IFile c_file = importFile(filename, c_file_code); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(c_file); //$NON-NLS-1$
|
||||
assertEquals(tu.getDeclarations().length, 0);
|
||||
IASTPreprocessorMacroDefinition[] macroDefinitions = tu
|
||||
.getMacroDefinitions();
|
||||
IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions();
|
||||
assertNotNull(macroDefinitions);
|
||||
assertEquals(macroDefinitions.length, 6);
|
||||
assertSoleFileLocation(
|
||||
|
@ -433,31 +414,23 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
IFile include_file = importFile("include.h", inc_file_code); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
String[] macros = { imacro_file.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) {
|
||||
IExtendedScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, EMPTY_STRING_ARRAY, macros, includes);
|
||||
|
||||
for (ParserLanguage p : ParserLanguage.values()) {
|
||||
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$
|
||||
|
||||
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();
|
||||
IASTPreprocessorMacroDefinition[] macro_defs = tu.getMacroDefinitions();
|
||||
assertEquals(macro_defs.length, 2);
|
||||
IASTPreprocessorMacroDefinition BEAST = macro_defs[0];
|
||||
assertEquals(BEAST.getName().toString(), "BEAST"); //$NON-NLS-1$
|
||||
IASTPreprocessorMacroDefinition INCLUDE_H = macro_defs[1];
|
||||
final IASTNodeLocation[] nodeLocations = INCLUDE_H.getName()
|
||||
.getNodeLocations();
|
||||
final IASTNodeLocation[] nodeLocations = INCLUDE_H.getName().getNodeLocations();
|
||||
assertEquals(nodeLocations.length, 1);
|
||||
final IASTFileLocation flatLoc = INCLUDE_H.getName()
|
||||
.getFileLocation();
|
||||
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_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$
|
||||
}
|
||||
}
|
||||
|
@ -468,8 +441,7 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
buffer.append("int x,y,z;"); //$NON-NLS-1$
|
||||
String code = buffer.toString();
|
||||
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
for (ParserLanguage p : ParserLanguage.values()) {
|
||||
String filename = (p == ParserLanguage.CPP) ? "blah.cc" : "blah.c"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IFile f = importFile(filename, code); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(f); //$NON-NLS-1$
|
||||
|
@ -507,29 +479,22 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
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) {
|
||||
for (ParserLanguage p : ParserLanguage.values()) {
|
||||
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$
|
||||
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();
|
||||
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();
|
||||
final IASTNodeLocation[] nodeLocations = INCLUDE_H.getName().getNodeLocations();
|
||||
assertEquals(nodeLocations.length, 1);
|
||||
final IASTFileLocation flatLoc = INCLUDE_H.getName()
|
||||
.getFileLocation();
|
||||
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_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());
|
||||
|
@ -553,31 +518,24 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
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) {
|
||||
IExtendedScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, EMPTY_STRING_ARRAY, macros, includes);
|
||||
|
||||
for (ParserLanguage p : ParserLanguage.values()) {
|
||||
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$
|
||||
IFile code = importFile(filename, "int main() { return BEAST * sizeof( Include ); } "); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
IASTTranslationUnit tu = parse(code, scannerInfo);
|
||||
IASTPreprocessorMacroDefinition[] macro_defs = tu
|
||||
.getMacroDefinitions();
|
||||
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();
|
||||
final IASTNodeLocation[] nodeLocations = INCLUDE_H.getName().getNodeLocations();
|
||||
assertEquals(nodeLocations.length, 1);
|
||||
final IASTFileLocation flatLoc = INCLUDE_H.getName()
|
||||
.getFileLocation();
|
||||
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_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());
|
||||
|
@ -593,10 +551,9 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
buffer.append("#define TARG <incs.h>\n");
|
||||
buffer.append("#include TARG\n");
|
||||
String code= buffer.toString();
|
||||
IExtendedScannerInfo scannerInfo = new ExtendedScannerInfo(
|
||||
Collections.EMPTY_MAP, new String[] {incsh.getLocation().removeLastSegments(1).toOSString()}, null, null);
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
IExtendedScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, new String[] {incsh.getLocation().removeLastSegments(1).toOSString()}, null, null);
|
||||
|
||||
for (ParserLanguage p : ParserLanguage.values()) {
|
||||
String filename = (p == ParserLanguage.CPP) ? "main.cc" : "main.c";
|
||||
IFile sfile = importFile(filename, code);
|
||||
IASTTranslationUnit tu = parse(sfile, scannerInfo);
|
||||
|
@ -633,8 +590,7 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest {
|
|||
IExtendedScannerInfo scannerInfo = new ExtendedScannerInfo(
|
||||
Collections.EMPTY_MAP, new String[] {tmpDir}, null, null);
|
||||
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
for (ParserLanguage p : ParserLanguage.values()) {
|
||||
String filename = (p == ParserLanguage.CPP) ? "main.cc" : "main.c";
|
||||
IFile sfile = importFile(filename, code);
|
||||
IASTTranslationUnit tu = parse(sfile, scannerInfo);
|
||||
|
|
|
@ -15,37 +15,40 @@ import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.CommentTests;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPLabel;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
||||
public class C99CommentTests extends CommentTests {
|
||||
|
||||
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems )
|
||||
throws ParserException {
|
||||
if(lang != ParserLanguage.C)
|
||||
return super.parse(code, lang, useGNUExtensions, expectNoProblems);
|
||||
|
||||
return ParseHelper.parse(code, getLanguage(), expectNoProblems);
|
||||
@Override
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language();
|
||||
return ParseHelper.parse(code, language, expectNoProblems);
|
||||
}
|
||||
|
||||
|
||||
protected IASTTranslationUnit parse(String code, ParserLanguage lang,
|
||||
@Override
|
||||
protected IASTTranslationUnit parse(String code, ParserLanguage lang,
|
||||
boolean useGNUExtensions, boolean expectNoProblems,
|
||||
boolean parseComments) throws ParserException {
|
||||
|
||||
|
||||
if(lang != ParserLanguage.C)
|
||||
return super.parse(code, lang, useGNUExtensions, expectNoProblems, parseComments);
|
||||
|
||||
return ParseHelper.commentParse(code, getLanguage());
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language();
|
||||
return ParseHelper.commentParse(code, language);
|
||||
}
|
||||
|
||||
protected BaseExtensibleLanguage getLanguage() {
|
||||
protected ILanguage getC99Language() {
|
||||
return C99Language.getDefault();
|
||||
}
|
||||
|
||||
protected ILanguage getCPPLanguage() {
|
||||
return ISOCPPLanguage.getDefault();
|
||||
}
|
||||
|
||||
|
||||
public void testBug191266() throws Exception {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
|
|
@ -15,25 +15,29 @@ import junit.framework.AssertionFailedError;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.CompleteParser2Tests;
|
||||
|
||||
public class C99CompleteParser2Tests extends CompleteParser2Tests {
|
||||
|
||||
@Override
|
||||
protected IASTTranslationUnit parse(String code, boolean expectedToPass,
|
||||
ParserLanguage lang, boolean gcc) throws Exception {
|
||||
|
||||
if(lang != ParserLanguage.C)
|
||||
return super.parse(code, expectedToPass, lang, gcc);
|
||||
|
||||
return ParseHelper.parse(code, getLanguage(), expectedToPass);
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language();
|
||||
return ParseHelper.parse(code, language, expectedToPass);
|
||||
}
|
||||
|
||||
protected BaseExtensibleLanguage getLanguage() {
|
||||
protected ILanguage getC99Language() {
|
||||
return C99Language.getDefault();
|
||||
}
|
||||
|
||||
protected ILanguage getCPPLanguage() {
|
||||
return ISOCPPLanguage.getDefault();
|
||||
}
|
||||
|
||||
|
||||
// Tests that are failing at this point
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ import org.eclipse.cdt.core.dom.ast.IFunction;
|
|||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.tests.prefix.BasicCompletionTest;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
@ -26,24 +28,23 @@ public class C99CompletionBasicTest extends BasicCompletionTest {
|
|||
public C99CompletionBasicTest() { }
|
||||
|
||||
|
||||
@Override
|
||||
protected IASTCompletionNode getCompletionNode(String code,
|
||||
ParserLanguage lang, boolean useGNUExtensions)
|
||||
throws ParserException {
|
||||
|
||||
if(ParserLanguage.C == lang) {
|
||||
return ParseHelper.getCompletionNode(code, getLanguage());
|
||||
}
|
||||
else {
|
||||
// TODO: parsing of C++
|
||||
return super.getCompletionNode(code, lang, useGNUExtensions);
|
||||
}
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language();
|
||||
return ParseHelper.getCompletionNode(code, language);
|
||||
}
|
||||
|
||||
|
||||
protected BaseExtensibleLanguage getLanguage() {
|
||||
return C99Language.getDefault();
|
||||
}
|
||||
protected ILanguage getC99Language() {
|
||||
return C99Language.getDefault();
|
||||
}
|
||||
|
||||
protected ILanguage getCPPLanguage() {
|
||||
return ISOCPPLanguage.getDefault();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testFunction() throws Exception {
|
||||
|
|
|
@ -30,6 +30,8 @@ import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
|||
* Reuse the completion parse tests from the old parser for now.
|
||||
*
|
||||
* This test suite is specific to C99.
|
||||
*
|
||||
* TODO run this against C++
|
||||
*/
|
||||
public class C99CompletionParseTest extends TestCase {
|
||||
|
||||
|
|
|
@ -10,16 +10,13 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.lrparser.tests.c99;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.DOMLocationInclusionTests;
|
||||
|
@ -31,7 +28,7 @@ public class C99DOMLocationInclusionTests extends DOMLocationInclusionTests {
|
|||
public C99DOMLocationInclusionTests() {
|
||||
}
|
||||
|
||||
public C99DOMLocationInclusionTests(String name, Class className) {
|
||||
public C99DOMLocationInclusionTests(String name, Class<Object> className) {
|
||||
super(name, className);
|
||||
}
|
||||
|
||||
|
@ -39,23 +36,30 @@ public class C99DOMLocationInclusionTests extends DOMLocationInclusionTests {
|
|||
super(name);
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit parse(IFile code, IScannerInfo s)
|
||||
throws Exception {
|
||||
@Override
|
||||
protected IASTTranslationUnit parse(IFile code, IScannerInfo s)throws Exception {
|
||||
// TODO: total freakin hack! the test suite needs to be refactored
|
||||
ILanguage lang = code.getName().endsWith("cc") ? getCPPLanguage() : getC99Language();
|
||||
|
||||
CodeReader codeReader = new CodeReader(code.getLocation().toOSString());
|
||||
BaseExtensibleLanguage lang = getLanguage();
|
||||
IASTTranslationUnit tu = lang.getASTTranslationUnit(codeReader, s, SavedCodeReaderFactory.getInstance(), null, BaseExtensibleLanguage.OPTION_ADD_COMMENTS, ParserUtil.getParserLogService());
|
||||
|
||||
return tu;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IASTTranslationUnit parse(IFile code) throws Exception {
|
||||
|
||||
return parse(code, new ExtendedScannerInfo());
|
||||
}
|
||||
|
||||
protected BaseExtensibleLanguage getLanguage() {
|
||||
return C99Language.getDefault();
|
||||
|
||||
protected ILanguage getC99Language() {
|
||||
return C99Language.getDefault();
|
||||
}
|
||||
|
||||
protected ILanguage getCPPLanguage() {
|
||||
return ISOCPPLanguage.getDefault();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.DOMLocationMacroTests;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
@ -38,17 +40,18 @@ public class C99DOMLocationMacroTests extends DOMLocationMacroTests {
|
|||
|
||||
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
if(lang == ParserLanguage.C) {
|
||||
return ParseHelper.parse(code, getLanguage(), expectNoProblems);
|
||||
}
|
||||
else
|
||||
return super.parse(code, lang, useGNUExtensions, expectNoProblems);
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language();
|
||||
return ParseHelper.parse(code, language, expectNoProblems);
|
||||
}
|
||||
|
||||
|
||||
protected BaseExtensibleLanguage getLanguage() {
|
||||
protected ILanguage getC99Language() {
|
||||
return C99Language.getDefault();
|
||||
}
|
||||
|
||||
protected ILanguage getCPPLanguage() {
|
||||
return ISOCPPLanguage.getDefault();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,6 +15,8 @@ import junit.framework.AssertionFailedError;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.DOMLocationTests;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
@ -25,18 +27,19 @@ public class C99DOMLocationTests extends DOMLocationTests {
|
|||
public C99DOMLocationTests(String name) { super(name); }
|
||||
|
||||
@Override
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems )
|
||||
throws ParserException {
|
||||
if(lang != ParserLanguage.C)
|
||||
return super.parse(code, lang, useGNUExtensions, expectNoProblems);
|
||||
|
||||
return ParseHelper.parse(code, getLanguage(), expectNoProblems);
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language();
|
||||
return ParseHelper.parse(code, language, expectNoProblems);
|
||||
}
|
||||
|
||||
|
||||
protected BaseExtensibleLanguage getLanguage() {
|
||||
protected ILanguage getC99Language() {
|
||||
return C99Language.getDefault();
|
||||
}
|
||||
|
||||
protected ILanguage getCPPLanguage() {
|
||||
return ISOCPPLanguage.getDefault();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// this one fails because the C99 parser does error recovery differently
|
||||
|
|
|
@ -13,23 +13,27 @@ package org.eclipse.cdt.core.lrparser.tests.c99;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.DOMPreprocessorInformationTest;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
||||
public class C99DOMPreprocessorInformationTest extends DOMPreprocessorInformationTest {
|
||||
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
//if(lang != ParserLanguage.C)
|
||||
// return super.parse(code, lang, useGNUExtensions, expectNoProblems);
|
||||
|
||||
return ParseHelper.parse(code, getLanguage(), expectNoProblems);
|
||||
@Override
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language();
|
||||
return ParseHelper.parse(code, language, expectNoProblems);
|
||||
}
|
||||
|
||||
|
||||
protected BaseExtensibleLanguage getLanguage() {
|
||||
protected ILanguage getC99Language() {
|
||||
return C99Language.getDefault();
|
||||
}
|
||||
|
||||
|
||||
protected ILanguage getCPPLanguage() {
|
||||
return ISOCPPLanguage.getDefault();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ package org.eclipse.cdt.core.lrparser.tests.c99;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.GCCTests;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
@ -23,16 +25,19 @@ public class C99GCCTests extends GCCTests {
|
|||
public C99GCCTests(String name) { super(name); }
|
||||
|
||||
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
if(lang != ParserLanguage.C)
|
||||
return super.parse(code, lang, useGNUExtensions, expectNoProblems);
|
||||
|
||||
return ParseHelper.parse(code, getLanguage(), expectNoProblems);
|
||||
@Override
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language();
|
||||
return ParseHelper.parse(code, language, expectNoProblems);
|
||||
}
|
||||
|
||||
|
||||
protected BaseExtensibleLanguage getLanguage() {
|
||||
protected ILanguage getC99Language() {
|
||||
return C99Language.getDefault();
|
||||
}
|
||||
|
||||
protected ILanguage getCPPLanguage() {
|
||||
return ISOCPPLanguage.getDefault();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,11 +10,10 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.lrparser.tests.c99;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.AST2KnRTests;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
@ -25,41 +24,48 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
public class C99KnRTests extends AST2KnRTests {
|
||||
|
||||
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
if(lang == ParserLanguage.C) {
|
||||
return ParseHelper.parse(code, getLanguage(), expectNoProblems);
|
||||
}
|
||||
else
|
||||
return super.parse(code, lang, useGNUExtensions, expectNoProblems);
|
||||
@Override
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language();
|
||||
return ParseHelper.parse(code, language, expectNoProblems);
|
||||
}
|
||||
|
||||
protected BaseExtensibleLanguage getLanguage() {
|
||||
|
||||
protected ILanguage getC99Language() {
|
||||
return C99Language.getDefault();
|
||||
}
|
||||
|
||||
protected ILanguage getCPPLanguage() {
|
||||
return ISOCPPLanguage.getDefault();
|
||||
}
|
||||
|
||||
// TODO: Failing tests, will get around to fixing these bugs
|
||||
|
||||
public void testKRCProblem3() throws Exception {
|
||||
@Override
|
||||
public void testKRCProblem3() throws Exception {
|
||||
try {
|
||||
super.testKRCProblem3();
|
||||
fail();
|
||||
} catch(Throwable _) { }
|
||||
}
|
||||
|
||||
public void testKRCProblem4() throws Exception {
|
||||
@Override
|
||||
public void testKRCProblem4() throws Exception {
|
||||
try {
|
||||
super.testKRCProblem4();
|
||||
fail();
|
||||
} catch(Throwable _) { }
|
||||
}
|
||||
|
||||
public void testKRCProblem5() throws Exception {
|
||||
@Override
|
||||
public void testKRCProblem5() throws Exception {
|
||||
try {
|
||||
super.testKRCProblem5();
|
||||
fail();
|
||||
} catch(Throwable _) { }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testKRCProblem2() throws Exception {
|
||||
try {
|
||||
super.testKRCProblem2();
|
||||
|
|
|
@ -19,6 +19,8 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
|
@ -36,47 +38,34 @@ public class C99SelectionParseTest extends AST2SelectionParseTest {
|
|||
public C99SelectionParseTest(String name) { super(name); }
|
||||
|
||||
protected IASTNode parse(String code, ParserLanguage lang, int offset, int length) throws ParserException {
|
||||
if(lang == ParserLanguage.C)
|
||||
return parse(code, lang, false, false, offset, length);
|
||||
else
|
||||
return super.parse(code, lang, offset, length);
|
||||
return parse(code, lang, false, false, offset, length);
|
||||
}
|
||||
|
||||
protected IASTNode parse(IFile file, ParserLanguage lang, int offset, int length) throws ParserException {
|
||||
if(lang == ParserLanguage.C) {
|
||||
IASTTranslationUnit tu = parse(file, lang, false, false);
|
||||
return tu.selectNodeForLocation(tu.getFilePath(), offset, length);
|
||||
}
|
||||
else
|
||||
return super.parse(file, lang, offset, length);
|
||||
IASTTranslationUnit tu = parse(file, lang, false, false);
|
||||
return tu.selectNodeForLocation(tu.getFilePath(), offset, length);
|
||||
}
|
||||
|
||||
protected IASTNode parse(String code, ParserLanguage lang, int offset, int length, boolean expectedToPass) throws ParserException {
|
||||
if(lang == ParserLanguage.C)
|
||||
return parse(code, lang, false, expectedToPass, offset, length);
|
||||
else
|
||||
return super.parse(code, lang, offset, length, expectedToPass);
|
||||
return parse(code, lang, false, expectedToPass, offset, length);
|
||||
}
|
||||
|
||||
protected IASTNode parse(String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, int offset, int length) throws ParserException {
|
||||
if(lang == ParserLanguage.C) {
|
||||
IASTTranslationUnit tu = ParseHelper.parse(code, getLanguage(), useGNUExtensions, expectNoProblems, 0);
|
||||
return tu.selectNodeForLocation(tu.getFilePath(), offset, length);
|
||||
}
|
||||
else
|
||||
return super.parse(code, lang, useGNUExtensions, expectNoProblems, offset, length);
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language();
|
||||
|
||||
IASTTranslationUnit tu = ParseHelper.parse(code, language, useGNUExtensions, expectNoProblems, 0);
|
||||
return tu.selectNodeForLocation(tu.getFilePath(), offset, length);
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit parse( IFile file, ParserLanguage lang, IScannerInfo scanInfo, boolean useGNUExtensions, boolean expectNoProblems )
|
||||
throws ParserException {
|
||||
|
||||
if(lang != ParserLanguage.C)
|
||||
return super.parse(file, lang, useGNUExtensions, expectNoProblems);
|
||||
|
||||
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language();
|
||||
|
||||
String fileName = file.getLocation().toOSString();
|
||||
ICodeReaderFactory fileCreator = SavedCodeReaderFactory.getInstance();
|
||||
CodeReader reader = fileCreator.createCodeReaderForTranslationUnit(fileName);
|
||||
return ParseHelper.parse(reader, getLanguage(), scanInfo, fileCreator, expectNoProblems, true, 0);
|
||||
return ParseHelper.parse(reader, language, scanInfo, fileCreator, expectNoProblems, true, 0);
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit parse( IFile file, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems )
|
||||
|
@ -84,8 +73,12 @@ public class C99SelectionParseTest extends AST2SelectionParseTest {
|
|||
return parse(file, lang, new ScannerInfo(), useGNUExtensions, expectNoProblems);
|
||||
}
|
||||
|
||||
protected BaseExtensibleLanguage getLanguage() {
|
||||
return C99Language.getDefault();
|
||||
protected ILanguage getC99Language() {
|
||||
return C99Language.getDefault();
|
||||
}
|
||||
|
||||
protected ILanguage getCPPLanguage() {
|
||||
return ISOCPPLanguage.getDefault();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,21 +13,27 @@ package org.eclipse.cdt.core.lrparser.tests.c99;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.TaskParserTest;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
||||
public class C99TaskParserTest extends TaskParserTest {
|
||||
|
||||
@Override
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
if(lang != ParserLanguage.C)
|
||||
return super.parse(code, lang, useGNUExtensions, expectNoProblems);
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language();
|
||||
|
||||
return ParseHelper.parse(code, getLanguage(), expectNoProblems);
|
||||
return ParseHelper.parse(code, language, expectNoProblems);
|
||||
}
|
||||
|
||||
|
||||
protected BaseExtensibleLanguage getLanguage() {
|
||||
protected ILanguage getC99Language() {
|
||||
return C99Language.getDefault();
|
||||
}
|
||||
|
||||
protected ILanguage getCPPLanguage() {
|
||||
return ISOCPPLanguage.getDefault();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ import junit.framework.AssertionFailedError;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.AST2UtilOldTests;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
@ -22,17 +24,20 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
public class C99UtilOldTests extends AST2UtilOldTests {
|
||||
|
||||
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
if(lang != ParserLanguage.C)
|
||||
return super.parse(code, lang, useGNUExtensions, expectNoProblems);
|
||||
|
||||
return ParseHelper.parse(code, getLanguage(), expectNoProblems);
|
||||
@Override
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language();
|
||||
return ParseHelper.parse(code, language, expectNoProblems);
|
||||
}
|
||||
|
||||
|
||||
protected BaseExtensibleLanguage getLanguage() {
|
||||
protected ILanguage getC99Language() {
|
||||
return C99Language.getDefault();
|
||||
}
|
||||
|
||||
protected ILanguage getCPPLanguage() {
|
||||
return ISOCPPLanguage.getDefault();
|
||||
}
|
||||
|
||||
|
||||
public void testCastExpression() throws Exception { // A not typedefed
|
||||
|
|
|
@ -13,35 +13,36 @@ package org.eclipse.cdt.core.lrparser.tests.c99;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.AST2UtilTests;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
||||
public class C99UtilTests extends AST2UtilTests {
|
||||
|
||||
@Override
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang ) throws ParserException {
|
||||
if(lang != ParserLanguage.C)
|
||||
return super.parse(code, lang);
|
||||
|
||||
return parse(code, lang, false, true );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions ) throws ParserException {
|
||||
if(lang != ParserLanguage.C)
|
||||
return super.parse(code, lang, useGNUExtensions);
|
||||
|
||||
return parse( code, lang, useGNUExtensions, true );
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
if(lang != ParserLanguage.C)
|
||||
return super.parse(code, lang, useGNUExtensions, expectNoProblems);
|
||||
|
||||
return ParseHelper.parse(code, getLanguage(), expectNoProblems);
|
||||
@Override
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language();
|
||||
return ParseHelper.parse(code, language, expectNoProblems);
|
||||
}
|
||||
|
||||
|
||||
protected BaseExtensibleLanguage getLanguage() {
|
||||
protected ILanguage getC99Language() {
|
||||
return C99Language.getDefault();
|
||||
}
|
||||
|
||||
protected ILanguage getCPPLanguage() {
|
||||
return ISOCPPLanguage.getDefault();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,14 +13,12 @@ package org.eclipse.cdt.core.lrparser.tests.c99;
|
|||
import junit.framework.AssertionFailedError;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
|
@ -118,7 +116,7 @@ public class ParseHelper {
|
|||
}
|
||||
|
||||
|
||||
public static IASTTranslationUnit commentParse(String code, BaseExtensibleLanguage language) {
|
||||
public static IASTTranslationUnit commentParse(String code, ILanguage language) {
|
||||
CodeReader codeReader = new CodeReader(code.toCharArray());
|
||||
IASTTranslationUnit tu;
|
||||
try {
|
||||
|
@ -129,14 +127,18 @@ public class ParseHelper {
|
|||
return tu;
|
||||
}
|
||||
|
||||
public static IASTCompletionNode getCompletionNode(String code, BaseExtensibleLanguage lang) {
|
||||
public static IASTCompletionNode getCompletionNode(String code, ILanguage lang) {
|
||||
return getCompletionNode(code, lang, code.length());
|
||||
}
|
||||
|
||||
|
||||
public static IASTCompletionNode getCompletionNode(String code, BaseExtensibleLanguage language, int offset) {
|
||||
public static IASTCompletionNode getCompletionNode(String code, ILanguage language, int offset) {
|
||||
CodeReader reader = new CodeReader(code.toCharArray());
|
||||
return language.getCompletionNode(reader, new ScannerInfo(), null, null, ParserUtil.getParserLogService(), offset);
|
||||
try {
|
||||
return language.getCompletionNode(reader, new ScannerInfo(), null, null, ParserUtil.getParserLogService(), offset);
|
||||
} catch (CoreException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -350,6 +350,8 @@ $Rules
|
|||
-- Basic Concepts
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO declaration errors need to be caught
|
||||
-- TODO in C99 as well, nested declarations should be able to have errors
|
||||
|
||||
translation_unit
|
||||
::= declaration_seq
|
||||
|
@ -569,9 +571,9 @@ unary_expression
|
|||
|
||||
new_expression -- done
|
||||
::= dcolon_opt 'new' new_placement_opt new_type_id <openscope-ast> new_array_expressions_opt new_initializer_opt
|
||||
/. $Build consumeExpressionNew(false); $EndBuild ./
|
||||
| dcolon_opt 'new' new_placement_opt '(' type_id ')' new_initializer_opt
|
||||
/. $Build consumeExpressionNew(true); $EndBuild ./
|
||||
| dcolon_opt 'new' new_placement_opt '(' type_id ')' new_initializer_opt
|
||||
/. $Build consumeExpressionNew(false); $EndBuild ./
|
||||
|
||||
|
||||
new_placement -- done
|
||||
|
@ -1142,7 +1144,7 @@ namespace_name
|
|||
|
||||
|
||||
original_namespace_name
|
||||
::= 'identifier'
|
||||
::= identifier_name
|
||||
|
||||
|
||||
namespace_definition
|
||||
|
|
|
@ -45,6 +45,9 @@ import org.eclipse.core.runtime.CoreException;
|
|||
public abstract class BaseExtensibleLanguage extends AbstractLanguage implements ILanguage, ICLanguageKeywords {
|
||||
|
||||
|
||||
private static final boolean DEBUG_PRINT_GCC_AST = false;
|
||||
private static final boolean DEBUG_PRINT_AST = false;
|
||||
|
||||
/**
|
||||
* Retrieve the parser (runs after the preprocessor runs).
|
||||
*
|
||||
|
@ -98,17 +101,18 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage implements
|
|||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
|
||||
ICodeReaderFactory fileCreator, IIndex index, int options, IParserLogService log) throws CoreException {
|
||||
|
||||
ILanguage gppLanguage = GPPLanguage.getDefault();
|
||||
IASTTranslationUnit gtu = gppLanguage.getASTTranslationUnit(reader, scanInfo, fileCreator, index, log);
|
||||
|
||||
System.out.println();
|
||||
System.out.println("********************************************************");
|
||||
System.out.println("Parsing");
|
||||
System.out.println("Options: " + options);
|
||||
System.out.println("GPP AST:");
|
||||
DebugUtil.printAST(gtu);
|
||||
System.out.println();
|
||||
|
||||
if(DEBUG_PRINT_GCC_AST) {
|
||||
ILanguage gppLanguage = GPPLanguage.getDefault();
|
||||
IASTTranslationUnit gtu = gppLanguage.getASTTranslationUnit(reader, scanInfo, fileCreator, index, log);
|
||||
|
||||
System.out.println();
|
||||
System.out.println("********************************************************");
|
||||
System.out.println("Parsing");
|
||||
System.out.println("Options: " + options);
|
||||
System.out.println("GPP AST:");
|
||||
DebugUtil.printAST(gtu);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
// TODO temporary
|
||||
IScannerExtensionConfiguration config = new GCCScannerExtensionConfiguration();
|
||||
|
@ -125,9 +129,11 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage implements
|
|||
|
||||
parser.parse(tu); // the parser will fill in the rest of the AST
|
||||
|
||||
if(DEBUG_PRINT_AST) {
|
||||
System.out.println("Base Extensible Language AST:");
|
||||
DebugUtil.printAST(tu);
|
||||
}
|
||||
|
||||
System.out.println("Base Extensible Language AST:");
|
||||
DebugUtil.printAST(tu);
|
||||
return tu;
|
||||
}
|
||||
|
||||
|
@ -136,7 +142,6 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage implements
|
|||
IScannerInfo scanInfo, ICodeReaderFactory fileCreator,
|
||||
IIndex index, IParserLogService log) throws CoreException {
|
||||
|
||||
System.out.println("Second Method");
|
||||
return getASTTranslationUnit(reader, scanInfo, fileCreator, index, 0, log);
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ public abstract class BuildASTParserAction {
|
|||
|
||||
// turn debug tracing on and off
|
||||
// TODO move this into an AspectJ project
|
||||
protected static final boolean TRACE_ACTIONS = true;
|
||||
protected static final boolean TRACE_ACTIONS = false;
|
||||
protected static final boolean TRACE_AST_STACK = false;
|
||||
|
||||
|
||||
|
|
|
@ -171,7 +171,7 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
|
|||
*/
|
||||
public void consumeExpressionNew(boolean isNewTypeId) {
|
||||
if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
|
||||
|
||||
|
||||
IASTExpression initializer = (IASTExpression) astStack.pop(); // may be null
|
||||
|
||||
List<Object> arrayExpressions = Collections.emptyList();
|
||||
|
|
|
@ -709,14 +709,14 @@ public CPPExpressionStatementParser(String[] mapFrom) { // constructor
|
|||
// Rule 85: new_expression ::= dcolon_opt new new_placement_opt new_type_id <openscope-ast> new_array_expressions_opt new_initializer_opt
|
||||
//
|
||||
case 85: { action.builder.
|
||||
consumeExpressionNew(false); break;
|
||||
consumeExpressionNew(true); break;
|
||||
}
|
||||
|
||||
//
|
||||
// Rule 86: new_expression ::= dcolon_opt new new_placement_opt ( type_id ) new_initializer_opt
|
||||
//
|
||||
case 86: { action.builder.
|
||||
consumeExpressionNew(true); break;
|
||||
consumeExpressionNew(false); break;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -86,9 +86,9 @@ public interface CPPExpressionStatementParsersym {
|
|||
TK_Completion = 121,
|
||||
TK_EndOfCompletion = 122,
|
||||
TK_Invalid = 123,
|
||||
TK_LeftBracket = 59,
|
||||
TK_LeftBracket = 58,
|
||||
TK_LeftParen = 2,
|
||||
TK_LeftBrace = 58,
|
||||
TK_LeftBrace = 59,
|
||||
TK_Dot = 114,
|
||||
TK_DotStar = 94,
|
||||
TK_Arrow = 101,
|
||||
|
@ -198,8 +198,8 @@ public interface CPPExpressionStatementParsersym {
|
|||
"static",
|
||||
"typedef",
|
||||
"class",
|
||||
"LeftBrace",
|
||||
"LeftBracket",
|
||||
"LeftBrace",
|
||||
"using",
|
||||
"LT",
|
||||
"enum",
|
||||
|
|
|
@ -709,14 +709,14 @@ public CPPNoCastExpressionParser(String[] mapFrom) { // constructor
|
|||
// Rule 85: new_expression ::= dcolon_opt new new_placement_opt new_type_id <openscope-ast> new_array_expressions_opt new_initializer_opt
|
||||
//
|
||||
case 85: { action.builder.
|
||||
consumeExpressionNew(false); break;
|
||||
consumeExpressionNew(true); break;
|
||||
}
|
||||
|
||||
//
|
||||
// Rule 86: new_expression ::= dcolon_opt new new_placement_opt ( type_id ) new_initializer_opt
|
||||
//
|
||||
case 86: { action.builder.
|
||||
consumeExpressionNew(true); break;
|
||||
consumeExpressionNew(false); break;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -22,7 +22,7 @@ public interface CPPNoCastExpressionParsersym {
|
|||
TK_case = 77,
|
||||
TK_catch = 116,
|
||||
TK_char = 14,
|
||||
TK_class = 58,
|
||||
TK_class = 57,
|
||||
TK_const = 47,
|
||||
TK_const_cast = 26,
|
||||
TK_continue = 78,
|
||||
|
@ -86,9 +86,9 @@ public interface CPPNoCastExpressionParsersym {
|
|||
TK_Completion = 121,
|
||||
TK_EndOfCompletion = 122,
|
||||
TK_Invalid = 123,
|
||||
TK_LeftBracket = 59,
|
||||
TK_LeftBracket = 58,
|
||||
TK_LeftParen = 2,
|
||||
TK_LeftBrace = 57,
|
||||
TK_LeftBrace = 59,
|
||||
TK_Dot = 115,
|
||||
TK_DotStar = 94,
|
||||
TK_Arrow = 101,
|
||||
|
@ -197,9 +197,9 @@ public interface CPPNoCastExpressionParsersym {
|
|||
"register",
|
||||
"static",
|
||||
"typedef",
|
||||
"LeftBrace",
|
||||
"class",
|
||||
"LeftBracket",
|
||||
"LeftBrace",
|
||||
"using",
|
||||
"LT",
|
||||
"namespace",
|
||||
|
|
|
@ -709,14 +709,14 @@ public CPPParser(String[] mapFrom) { // constructor
|
|||
// Rule 85: new_expression ::= dcolon_opt new new_placement_opt new_type_id <openscope-ast> new_array_expressions_opt new_initializer_opt
|
||||
//
|
||||
case 85: { action.builder.
|
||||
consumeExpressionNew(false); break;
|
||||
consumeExpressionNew(true); break;
|
||||
}
|
||||
|
||||
//
|
||||
// Rule 86: new_expression ::= dcolon_opt new new_placement_opt ( type_id ) new_initializer_opt
|
||||
//
|
||||
case 86: { action.builder.
|
||||
consumeExpressionNew(true); break;
|
||||
consumeExpressionNew(false); break;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -46,7 +46,7 @@ public interface CPPParsersym {
|
|||
TK_int = 17,
|
||||
TK_long = 18,
|
||||
TK_mutable = 53,
|
||||
TK_namespace = 60,
|
||||
TK_namespace = 59,
|
||||
TK_new = 42,
|
||||
TK_operator = 6,
|
||||
TK_private = 116,
|
||||
|
@ -86,9 +86,9 @@ public interface CPPParsersym {
|
|||
TK_Completion = 121,
|
||||
TK_EndOfCompletion = 122,
|
||||
TK_Invalid = 123,
|
||||
TK_LeftBracket = 61,
|
||||
TK_LeftBracket = 60,
|
||||
TK_LeftParen = 2,
|
||||
TK_LeftBrace = 59,
|
||||
TK_LeftBrace = 61,
|
||||
TK_Dot = 114,
|
||||
TK_DotStar = 94,
|
||||
TK_Arrow = 101,
|
||||
|
@ -199,9 +199,9 @@ public interface CPPParsersym {
|
|||
"typedef",
|
||||
"class",
|
||||
"using",
|
||||
"LeftBrace",
|
||||
"namespace",
|
||||
"LeftBracket",
|
||||
"LeftBrace",
|
||||
"asm",
|
||||
"LT",
|
||||
"enum",
|
||||
|
|
Loading…
Add table
Reference in a new issue