1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Test case for bug 259460.

This commit is contained in:
Sergey Prigogin 2008-12-22 01:39:25 +00:00
parent 12982b88e7
commit 46ab6162f7
2 changed files with 33 additions and 44 deletions

View file

@ -6284,7 +6284,7 @@ public class AST2CPPTests extends AST2BaseTest {
// } // }
// struct B {}; // struct B {};
// }; // };
public void _testClassMemberScope_259460() throws Exception { public void _testScopeOfClassMember_259460() throws Exception {
parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP);
} }
} }

View file

@ -58,26 +58,25 @@ public class AST2SpecBaseTest extends AST2BaseTest {
* @param expectedProblemBindings the number of problem bindings you expect to encounter * @param expectedProblemBindings the number of problem bindings you expect to encounter
* @throws ParserException * @throws ParserException
*/ */
protected void parseCandCPP( String code, boolean checkBindings, int expectedProblemBindings ) throws ParserException { protected void parseCandCPP(String code, boolean checkBindings, int expectedProblemBindings) throws ParserException {
parse( code, ParserLanguage.C, false, true, checkBindings, expectedProblemBindings, null); parse(code, ParserLanguage.C, false, true, checkBindings, expectedProblemBindings, null);
parse( code, ParserLanguage.CPP, false, true, checkBindings, expectedProblemBindings, null ); parse(code, ParserLanguage.CPP, false, true, checkBindings, expectedProblemBindings, null);
} }
protected IASTTranslationUnit parseWithErrors( String code, ParserLanguage lang) throws ParserException { protected IASTTranslationUnit parseWithErrors(String code, ParserLanguage lang) throws ParserException {
return parse(code, lang, false, false, false, 0, null ); return parse(code, lang, false, false, false, 0, null);
} }
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean checkBindings, int expectedProblemBindings ) throws ParserException { protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean checkBindings, int expectedProblemBindings) throws ParserException {
return parse(code, lang, false, true, checkBindings, expectedProblemBindings, null ); return parse(code, lang, false, true, checkBindings, expectedProblemBindings, null);
} }
protected IASTTranslationUnit parse(String code, ParserLanguage lang, String[] problems) throws ParserException { protected IASTTranslationUnit parse(String code, ParserLanguage lang, String[] problems) throws ParserException {
return parse(code, lang, false, true, true, problems.length, problems ); return parse(code, lang, false, true, true, problems.length, problems);
} }
private IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems,
private IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, boolean checkBindings, int expectedProblemBindings, String[] problems) throws ParserException {
boolean checkBindings, int expectedProblemBindings, String[] problems ) throws ParserException {
// TODO beef this up with tests... i.e. run once with \n, and then run again with \r\n replacing \n ... etc // TODO beef this up with tests... i.e. run once with \n, and then run again with \r\n replacing \n ... etc
// TODO another example might be to replace all characters with corresponding trigraph/digraph tests... // TODO another example might be to replace all characters with corresponding trigraph/digraph tests...
@ -85,7 +84,7 @@ public class AST2SpecBaseTest extends AST2BaseTest {
return parse(codeReader, lang, useGNUExtensions, expectNoProblems, checkBindings, expectedProblemBindings, problems); return parse(codeReader, lang, useGNUExtensions, expectNoProblems, checkBindings, expectedProblemBindings, problems);
} }
// private IASTTranslationUnit parse( IFile filename, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException { // private IASTTranslationUnit parse(IFile filename, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems) throws ParserException {
// CodeReader codeReader=null; // CodeReader codeReader=null;
// try { // try {
// codeReader = new CodeReader(filename.getName(), filename.getContents()); // codeReader = new CodeReader(filename.getName(), filename.getContents());
@ -98,25 +97,21 @@ public class AST2SpecBaseTest extends AST2BaseTest {
// return parse(codeReader, lang, useGNUExtensions, expectNoProblems); // return parse(codeReader, lang, useGNUExtensions, expectNoProblems);
// } // }
private IASTTranslationUnit parse(CodeReader codeReader, ParserLanguage lang, boolean useGNUExtensions, private IASTTranslationUnit parse(CodeReader codeReader, ParserLanguage lang,
boolean expectNoProblems, boolean checkBindings, int expectedProblemBindings, String[] problems) throws ParserException { boolean useGNUExtensions, boolean expectNoProblems, boolean checkBindings,
int expectedProblemBindings, String[] problems) throws ParserException {
ScannerInfo scannerInfo = new ScannerInfo(); ScannerInfo scannerInfo = new ScannerInfo();
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo);
ISourceCodeParser parser2 = null; ISourceCodeParser parser2 = null;
if( lang == ParserLanguage.CPP ) if (lang == ParserLanguage.CPP) {
{
ICPPParserExtensionConfiguration config = null; ICPPParserExtensionConfiguration config = null;
if (useGNUExtensions) if (useGNUExtensions)
config = new GPPParserExtensionConfiguration(); config = new GPPParserExtensionConfiguration();
else else
config = new ANSICPPParserExtensionConfiguration(); config = new ANSICPPParserExtensionConfiguration();
parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config);
NULL_LOG, } else {
config );
}
else
{
ICParserExtensionConfiguration config = null; ICParserExtensionConfiguration config = null;
if (useGNUExtensions) if (useGNUExtensions)
@ -124,8 +119,8 @@ public class AST2SpecBaseTest extends AST2BaseTest {
else else
config = new ANSICParserExtensionConfiguration(); config = new ANSICParserExtensionConfiguration();
parser2 = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, parser2 = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE,
NULL_LOG, config ); NULL_LOG, config);
} }
if (expectedProblemBindings > 0) if (expectedProblemBindings > 0)
@ -136,9 +131,10 @@ public class AST2SpecBaseTest extends AST2BaseTest {
// resolve all bindings // resolve all bindings
if (checkBindings) { if (checkBindings) {
NameResolver res = new NameResolver(); NameResolver res = new NameResolver();
tu.accept( res ); tu.accept(res);
if (res.problemBindings.size() != expectedProblemBindings ) if (res.problemBindings.size() != expectedProblemBindings)
throw new ParserException("Expected " + expectedProblemBindings + " problems, encountered " + res.problemBindings.size() ); throw new ParserException("Expected " + expectedProblemBindings +
" problems, encountered " + res.problemBindings.size());
if (problems != null) { if (problems != null) {
for (int i = 0; i < problems.length; i++) { for (int i = 0; i < problems.length; i++) {
assertEquals(problems[i], res.problemBindings.get(i)); assertEquals(problems[i], res.problemBindings.get(i));
@ -146,33 +142,28 @@ public class AST2SpecBaseTest extends AST2BaseTest {
} }
} }
if( parser2.encounteredError() && expectNoProblems ) if (parser2.encounteredError() && expectNoProblems)
throw new ParserException( "FAILURE"); throw new ParserException("FAILURE");
if( lang == ParserLanguage.C && expectNoProblems ) if (lang == ParserLanguage.C && expectNoProblems) {
{
if (CVisitor.getProblems(tu).length != 0) { if (CVisitor.getProblems(tu).length != 0) {
throw new ParserException (" CVisitor has AST Problems " ); throw new ParserException("CVisitor has AST Problems");
} }
if (tu.getPreprocessorProblems().length != 0) { if (tu.getPreprocessorProblems().length != 0) {
throw new ParserException (" C TranslationUnit has Preprocessor Problems " ); throw new ParserException("C TranslationUnit has Preprocessor Problems");
} }
} } else if (lang == ParserLanguage.CPP && expectNoProblems) {
else if ( lang == ParserLanguage.CPP && expectNoProblems )
{
if (CPPVisitor.getProblems(tu).length != 0) { if (CPPVisitor.getProblems(tu).length != 0) {
throw new ParserException (" CPPVisitor has AST Problems " ); throw new ParserException("CPPVisitor has AST Problems");
} }
if (tu.getPreprocessorProblems().length != 0) { if (tu.getPreprocessorProblems().length != 0) {
throw new ParserException (" CPP TranslationUnit has Preprocessor Problems " ); throw new ParserException("CPP TranslationUnit has Preprocessor Problems");
} }
} }
return tu; return tu;
} }
static protected class NameResolver extends ASTVisitor { static protected class NameResolver extends ASTVisitor {
{ {
shouldVisitNames = true; shouldVisitNames = true;
@ -182,7 +173,6 @@ public class AST2SpecBaseTest extends AST2BaseTest {
public List<String> problemBindings = new ArrayList<String>(); public List<String> problemBindings = new ArrayList<String>();
public int numNullBindings = 0; public int numNullBindings = 0;
@Override @Override
public int visit(IASTName name) { public int visit(IASTName name) {
nameList.add(name); nameList.add(name);
@ -195,7 +185,7 @@ public class AST2SpecBaseTest extends AST2BaseTest {
} }
public IASTName getName(int idx) { public IASTName getName(int idx) {
if(idx < 0 || idx >= nameList.size()) if (idx < 0 || idx >= nameList.size())
return null; return null;
return nameList.get(idx); return nameList.get(idx);
} }
@ -204,5 +194,4 @@ public class AST2SpecBaseTest extends AST2BaseTest {
return nameList.size(); return nameList.size();
} }
} }
} }