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:
parent
8032868167
commit
85c91a8433
3 changed files with 39 additions and 17 deletions
|
@ -7004,4 +7004,18 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
final String code = getAboveComment();
|
final String code = getAboveComment();
|
||||||
parseAndCheckBindings(code, ParserLanguage.CPP);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ package org.eclipse.cdt.core.suite;
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestSuite;
|
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.errorparsers.tests.ErrorParserTests;
|
||||||
import org.eclipse.cdt.core.internal.tests.PositionTrackerTests;
|
import org.eclipse.cdt.core.internal.tests.PositionTrackerTests;
|
||||||
import org.eclipse.cdt.core.internal.tests.ResourceLookupTests;
|
import org.eclipse.cdt.core.internal.tests.ResourceLookupTests;
|
||||||
|
@ -54,8 +56,8 @@ public class AutomatedIntegrationSuite extends TestSuite {
|
||||||
final AutomatedIntegrationSuite suite = new AutomatedIntegrationSuite();
|
final AutomatedIntegrationSuite suite = new AutomatedIntegrationSuite();
|
||||||
|
|
||||||
// Add all success tests
|
// Add all success tests
|
||||||
//suite.addTest(CDescriptorTests.suite());
|
suite.addTest(CDescriptorTests.suite());
|
||||||
//suite.addTest(CDescriptorOldTests.suite());
|
suite.addTest(CDescriptorOldTests.suite());
|
||||||
suite.addTest(ErrorParserTests.suite());
|
suite.addTest(ErrorParserTests.suite());
|
||||||
suite.addTest(ParserTestSuite.suite());
|
suite.addTest(ParserTestSuite.suite());
|
||||||
suite.addTest(AllCoreTests.suite());
|
suite.addTest(AllCoreTests.suite());
|
||||||
|
|
|
@ -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.IASTStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
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.IASTUnaryExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||||
|
@ -812,14 +813,16 @@ public class CPPVisitor extends ASTQueries {
|
||||||
}
|
}
|
||||||
} else if (node instanceof IASTInitializerExpression) {
|
} else if (node instanceof IASTInitializerExpression) {
|
||||||
IASTNode parent = node.getParent();
|
IASTNode parent = node.getParent();
|
||||||
while (!(parent instanceof IASTDeclarator))
|
while (!(parent instanceof IASTDeclarator || parent instanceof IASTTypeIdInitializerExpression))
|
||||||
parent = parent.getParent();
|
parent = parent.getParent();
|
||||||
IASTDeclarator dtor = (IASTDeclarator) parent;
|
if(parent instanceof IASTDeclarator) {
|
||||||
IASTName name = dtor.getName();
|
IASTDeclarator dtor = (IASTDeclarator) parent;
|
||||||
if (name instanceof ICPPASTQualifiedName) {
|
IASTName name = dtor.getName();
|
||||||
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
|
if (name instanceof ICPPASTQualifiedName) {
|
||||||
return getContainingScope(ns[ns.length - 1]);
|
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
|
||||||
}
|
return getContainingScope(ns[ns.length - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (node instanceof IASTExpression) {
|
} else if (node instanceof IASTExpression) {
|
||||||
IASTNode parent = node.getParent();
|
IASTNode parent = node.getParent();
|
||||||
if (parent instanceof IASTForStatement) {
|
if (parent instanceof IASTForStatement) {
|
||||||
|
@ -840,15 +843,18 @@ public class CPPVisitor extends ASTQueries {
|
||||||
}
|
}
|
||||||
} else if (parent instanceof IASTArrayModifier || parent instanceof IASTInitializer) {
|
} else if (parent instanceof IASTArrayModifier || parent instanceof IASTInitializer) {
|
||||||
IASTNode d = parent.getParent();
|
IASTNode d = parent.getParent();
|
||||||
while (!(d instanceof IASTDeclarator))
|
while (!(d instanceof IASTDeclarator || d instanceof IASTTypeIdInitializerExpression)) {
|
||||||
d = d.getParent();
|
d = d.getParent();
|
||||||
IASTDeclarator dtor = (IASTDeclarator) d;
|
}
|
||||||
while (dtor.getNestedDeclarator() != null)
|
if(d instanceof IASTDeclarator) {
|
||||||
dtor = dtor.getNestedDeclarator();
|
IASTDeclarator dtor = (IASTDeclarator) d;
|
||||||
IASTName name = dtor.getName();
|
while (dtor.getNestedDeclarator() != null)
|
||||||
if (name instanceof ICPPASTQualifiedName) {
|
dtor = dtor.getNestedDeclarator();
|
||||||
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
|
IASTName name = dtor.getName();
|
||||||
return getContainingScope(ns[ns.length - 1]);
|
if (name instanceof ICPPASTQualifiedName) {
|
||||||
|
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
|
||||||
|
return getContainingScope(ns[ns.length - 1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (parent instanceof ICPPASTTemplateId &&
|
} else if (parent instanceof ICPPASTTemplateId &&
|
||||||
node.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) {
|
node.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue