1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

fix for bug 268714, NPE in CPPVisitor.getContainingScope()

This commit is contained in:
Mike Kucera 2009-03-16 17:56:28 +00:00
parent 8032868167
commit 85c91a8433
3 changed files with 39 additions and 17 deletions

View file

@ -7004,4 +7004,18 @@ public class AST2CPPTests extends AST2BaseTest {
final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.CPP);
}
// struct A {int a;};
//
// int foo();
// int bar(A);
//
// int func() {
// bar((A){foo()});
// }
public void testBug268714() throws Exception {
final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.CPP);
}
}

View file

@ -15,6 +15,8 @@ package org.eclipse.cdt.core.suite;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.cdescriptor.tests.CDescriptorOldTests;
import org.eclipse.cdt.core.cdescriptor.tests.CDescriptorTests;
import org.eclipse.cdt.core.internal.errorparsers.tests.ErrorParserTests;
import org.eclipse.cdt.core.internal.tests.PositionTrackerTests;
import org.eclipse.cdt.core.internal.tests.ResourceLookupTests;
@ -54,8 +56,8 @@ public class AutomatedIntegrationSuite extends TestSuite {
final AutomatedIntegrationSuite suite = new AutomatedIntegrationSuite();
// Add all success tests
//suite.addTest(CDescriptorTests.suite());
//suite.addTest(CDescriptorOldTests.suite());
suite.addTest(CDescriptorTests.suite());
suite.addTest(CDescriptorOldTests.suite());
suite.addTest(ErrorParserTests.suite());
suite.addTest(ParserTestSuite.suite());
suite.addTest(AllCoreTests.suite());

View file

@ -56,6 +56,7 @@ import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IBasicType;
@ -812,14 +813,16 @@ public class CPPVisitor extends ASTQueries {
}
} else if (node instanceof IASTInitializerExpression) {
IASTNode parent = node.getParent();
while (!(parent instanceof IASTDeclarator))
while (!(parent instanceof IASTDeclarator || parent instanceof IASTTypeIdInitializerExpression))
parent = parent.getParent();
if(parent instanceof IASTDeclarator) {
IASTDeclarator dtor = (IASTDeclarator) parent;
IASTName name = dtor.getName();
if (name instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
return getContainingScope(ns[ns.length - 1]);
}
}
} else if (node instanceof IASTExpression) {
IASTNode parent = node.getParent();
if (parent instanceof IASTForStatement) {
@ -840,8 +843,10 @@ public class CPPVisitor extends ASTQueries {
}
} else if (parent instanceof IASTArrayModifier || parent instanceof IASTInitializer) {
IASTNode d = parent.getParent();
while (!(d instanceof IASTDeclarator))
while (!(d instanceof IASTDeclarator || d instanceof IASTTypeIdInitializerExpression)) {
d = d.getParent();
}
if(d instanceof IASTDeclarator) {
IASTDeclarator dtor = (IASTDeclarator) d;
while (dtor.getNestedDeclarator() != null)
dtor = dtor.getNestedDeclarator();
@ -850,6 +855,7 @@ public class CPPVisitor extends ASTQueries {
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
return getContainingScope(ns[ns.length - 1]);
}
}
} else if (parent instanceof ICPPASTTemplateId &&
node.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) {
node= parent; // template-id