mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 297550: NPE skipping trivial initializers.
This commit is contained in:
parent
5687f0ee0f
commit
7831fac919
5 changed files with 21 additions and 12 deletions
|
@ -619,7 +619,12 @@ public class AST2BaseTest extends BaseTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang, boolean useGnuExtensions) throws Exception {
|
final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang, boolean useGnuExtensions) throws Exception {
|
||||||
IASTTranslationUnit tu = parse(code, lang, useGnuExtensions);
|
return parseAndCheckBindings(code, lang, useGnuExtensions, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang, boolean useGnuExtensions,
|
||||||
|
boolean skipTrivialInitializers) throws Exception {
|
||||||
|
IASTTranslationUnit tu = parse(code, lang, useGnuExtensions, skipTrivialInitializers);
|
||||||
CNameCollector col = new CNameCollector();
|
CNameCollector col = new CNameCollector();
|
||||||
tu.accept(col);
|
tu.accept(col);
|
||||||
assertNoProblemBindings(col);
|
assertNoProblemBindings(col);
|
||||||
|
|
|
@ -7202,4 +7202,10 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
IASTTranslationUnit tu = parseAndCheckBindings(code, lang);
|
IASTTranslationUnit tu = parseAndCheckBindings(code, lang);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static a[2]= {0,0};
|
||||||
|
public void testSkipAggregateInitializer_297550() throws Exception {
|
||||||
|
final String code = getAboveComment();
|
||||||
|
parseAndCheckBindings(code, ParserLanguage.C, false, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,8 +90,9 @@ import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
|
||||||
public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
protected static class FoundAggregateInitializer extends Exception {
|
protected static class FoundAggregateInitializer extends Exception {
|
||||||
public final IASTDeclarator fDeclarator;
|
public final IASTDeclarator fDeclarator;
|
||||||
public IASTDeclSpecifier fDeclSpec;
|
public final IASTDeclSpecifier fDeclSpec;
|
||||||
public FoundAggregateInitializer(IASTDeclarator d) {
|
public FoundAggregateInitializer(IASTDeclSpecifier declSpec, IASTDeclarator d) {
|
||||||
|
fDeclSpec= declSpec;
|
||||||
fDeclarator= d;
|
fDeclarator= d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1566,10 +1567,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
try {
|
try {
|
||||||
// declarator for first variant
|
// declarator for first variant
|
||||||
dtor1= initDeclarator(declspec1, option);
|
dtor1= initDeclarator(declspec1, option);
|
||||||
} catch (FoundAggregateInitializer e) {
|
} catch (BacktrackException e) {
|
||||||
e.fDeclSpec= declspec1;
|
|
||||||
throw e;
|
|
||||||
} catch (BacktrackException e) {
|
|
||||||
if (acceptEmpty) {
|
if (acceptEmpty) {
|
||||||
backup(dtorMark1);
|
backup(dtorMark1);
|
||||||
return result.set(declspec1, null, null);
|
return result.set(declspec1, null, null);
|
||||||
|
|
|
@ -1281,7 +1281,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lt1 == IToken.tASSIGN && LT(2) == IToken.tLBRACE)
|
if (lt1 == IToken.tASSIGN && LT(2) == IToken.tLBRACE)
|
||||||
throw new FoundAggregateInitializer(d);
|
throw new FoundAggregateInitializer(declspec, d);
|
||||||
|
|
||||||
IASTInitializer i = optionalCInitializer();
|
IASTInitializer i = optionalCInitializer();
|
||||||
if (i != null) {
|
if (i != null) {
|
||||||
|
|
|
@ -2515,7 +2515,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTDeclarator dtor2= null;
|
IASTDeclarator dtor2= null;
|
||||||
BacktrackException bt= null;
|
BacktrackException bt= null;
|
||||||
try {
|
try {
|
||||||
dtor1= initDeclarator(DtorStrategy.PREFER_FUNCTION, option);
|
dtor1= initDeclarator(DtorStrategy.PREFER_FUNCTION, declspec, option);
|
||||||
verifyDtor(declspec, dtor1, option);
|
verifyDtor(declspec, dtor1, option);
|
||||||
|
|
||||||
int lt1= LTcatchEOF(1);
|
int lt1= LTcatchEOF(1);
|
||||||
|
@ -2555,7 +2555,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
|
|
||||||
backup(mark);
|
backup(mark);
|
||||||
try {
|
try {
|
||||||
dtor2= initDeclarator(DtorStrategy.PREFER_NESTED, option);
|
dtor2= initDeclarator(DtorStrategy.PREFER_NESTED, declspec, option);
|
||||||
if (dtor1 == null) {
|
if (dtor1 == null) {
|
||||||
return dtor2;
|
return dtor2;
|
||||||
}
|
}
|
||||||
|
@ -2671,12 +2671,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
* request a backtrack
|
* request a backtrack
|
||||||
* @throws FoundAggregateInitializer
|
* @throws FoundAggregateInitializer
|
||||||
*/
|
*/
|
||||||
protected IASTDeclarator initDeclarator(DtorStrategy strategy, DeclarationOptions option)
|
private IASTDeclarator initDeclarator(DtorStrategy strategy, IASTDeclSpecifier declspec, DeclarationOptions option)
|
||||||
throws EndOfFileException, BacktrackException, FoundAggregateInitializer {
|
throws EndOfFileException, BacktrackException, FoundAggregateInitializer {
|
||||||
final IASTDeclarator dtor= declarator(strategy, option);
|
final IASTDeclarator dtor= declarator(strategy, option);
|
||||||
if (option.fAllowInitializer) {
|
if (option.fAllowInitializer) {
|
||||||
if (LTcatchEOF(1) == IToken.tASSIGN && LTcatchEOF(2) == IToken.tLBRACE)
|
if (LTcatchEOF(1) == IToken.tASSIGN && LTcatchEOF(2) == IToken.tLBRACE)
|
||||||
throw new FoundAggregateInitializer(dtor);
|
throw new FoundAggregateInitializer(declspec, dtor);
|
||||||
|
|
||||||
IASTInitializer initializer= optionalCPPInitializer(dtor, option);
|
IASTInitializer initializer= optionalCPPInitializer(dtor, option);
|
||||||
if (initializer != null) {
|
if (initializer != null) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue