mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 20:05:35 +02:00
Fix and testcases for 181305, NPE parsing reference to 'void (f)(char)'.
This commit is contained in:
parent
56523f3c6a
commit
6d4221b57f
3 changed files with 70 additions and 13 deletions
|
@ -5194,12 +5194,14 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
assertTrue(field.isStatic());
|
assertTrue(field.isStatic());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// namespace nsSplit {}
|
||||||
|
// namespace nsSplit {
|
||||||
|
// void a();
|
||||||
|
// }
|
||||||
|
// void nsSplit::a() {
|
||||||
|
// }
|
||||||
public void testBug180979() throws Exception {
|
public void testBug180979() throws Exception {
|
||||||
StringBuffer buffer = new StringBuffer( );
|
StringBuffer buffer = getContents(1)[0];
|
||||||
buffer.append( "namespace nsSplit {}\r\n"); //$NON-NLS-1$
|
|
||||||
buffer.append( "namespace nsSplit {void a();}\r\n"); //$NON-NLS-1$
|
|
||||||
buffer.append( "void nsSplit::a() {}\r\n"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP, true, true );
|
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP, true, true );
|
||||||
|
|
||||||
// check class
|
// check class
|
||||||
|
|
|
@ -97,6 +97,7 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*/
|
*/
|
||||||
public class AST2Tests extends AST2BaseTest {
|
public class AST2Tests extends AST2BaseTest {
|
||||||
|
private static ParserLanguage[] LANGUAGES= {ParserLanguage.C, ParserLanguage.CPP};
|
||||||
|
|
||||||
public static TestSuite suite() {
|
public static TestSuite suite() {
|
||||||
return suite(AST2Tests.class);
|
return suite(AST2Tests.class);
|
||||||
|
@ -3579,4 +3580,47 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
// TODO: exhaustive macro testing
|
// TODO: exhaustive macro testing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void (decl)(char);
|
||||||
|
// void foo() {
|
||||||
|
// decl('a');
|
||||||
|
// }
|
||||||
|
public void testBug181305_1() throws Exception {
|
||||||
|
StringBuffer buffer = getContents(1)[0];
|
||||||
|
for (int i = 0; i < LANGUAGES.length; i++) {
|
||||||
|
final ParserLanguage lang= LANGUAGES[i];
|
||||||
|
IASTTranslationUnit tu = parse( buffer.toString(), lang, true, true );
|
||||||
|
|
||||||
|
// check class
|
||||||
|
IASTFunctionDefinition fd = (IASTFunctionDefinition) tu.getDeclarations()[1];
|
||||||
|
IASTCompoundStatement comp_stmt= (IASTCompoundStatement) fd.getBody();
|
||||||
|
IASTExpressionStatement expr_stmt= (IASTExpressionStatement) comp_stmt.getStatements()[0];
|
||||||
|
IASTFunctionCallExpression expr= (IASTFunctionCallExpression) expr_stmt.getExpression();
|
||||||
|
IASTIdExpression idExpr= (IASTIdExpression) expr.getFunctionNameExpression();
|
||||||
|
IBinding binding= idExpr.getName().resolveBinding();
|
||||||
|
assertTrue(lang.toString(), binding instanceof IFunction);
|
||||||
|
assertFalse(lang.toString(), binding instanceof IProblemBinding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// void (*decl)(char);
|
||||||
|
// void foo() {
|
||||||
|
// decl('a');
|
||||||
|
// }
|
||||||
|
public void testBug181305_2() throws Exception {
|
||||||
|
StringBuffer buffer = getContents(1)[0];
|
||||||
|
for (int i = 0; i < LANGUAGES.length; i++) {
|
||||||
|
final ParserLanguage lang= LANGUAGES[i];
|
||||||
|
IASTTranslationUnit tu = parse( buffer.toString(), lang, true, true );
|
||||||
|
|
||||||
|
// check class
|
||||||
|
IASTFunctionDefinition fd = (IASTFunctionDefinition) tu.getDeclarations()[1];
|
||||||
|
IASTCompoundStatement comp_stmt= (IASTCompoundStatement) fd.getBody();
|
||||||
|
IASTExpressionStatement expr_stmt= (IASTExpressionStatement) comp_stmt.getStatements()[0];
|
||||||
|
IASTFunctionCallExpression expr= (IASTFunctionCallExpression) expr_stmt.getExpression();
|
||||||
|
IASTIdExpression idExpr= (IASTIdExpression) expr.getFunctionNameExpression();
|
||||||
|
IBinding binding= idExpr.getName().resolveBinding();
|
||||||
|
assertTrue(lang.toString(), binding instanceof IVariable);
|
||||||
|
assertFalse(lang.toString(), binding instanceof IProblemBinding);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -470,19 +470,19 @@ public class CPPVisitor {
|
||||||
declarator = declarator.getNestedDeclarator();
|
declarator = declarator.getNestedDeclarator();
|
||||||
|
|
||||||
IASTFunctionDeclarator funcDeclarator= null;
|
IASTFunctionDeclarator funcDeclarator= null;
|
||||||
IASTNode node= declarator;
|
IASTNode tmpNode= declarator;
|
||||||
do {
|
do {
|
||||||
if (node instanceof IASTFunctionDeclarator) {
|
if (tmpNode instanceof IASTFunctionDeclarator) {
|
||||||
funcDeclarator= (IASTFunctionDeclarator) node;
|
funcDeclarator= (IASTFunctionDeclarator) tmpNode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (((IASTDeclarator) node).getPointerOperators().length > 0 ||
|
if (((IASTDeclarator) tmpNode).getPointerOperators().length > 0 ||
|
||||||
node.getPropertyInParent() != IASTDeclarator.NESTED_DECLARATOR) {
|
tmpNode.getPropertyInParent() != IASTDeclarator.NESTED_DECLARATOR) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
node= node.getParent();
|
tmpNode= tmpNode.getParent();
|
||||||
}
|
}
|
||||||
while (node instanceof IASTDeclarator);
|
while (tmpNode instanceof IASTDeclarator);
|
||||||
|
|
||||||
IASTName name = declarator.getName();
|
IASTName name = declarator.getName();
|
||||||
if( name instanceof ICPPASTQualifiedName ){
|
if( name instanceof ICPPASTQualifiedName ){
|
||||||
|
@ -534,7 +534,7 @@ public class CPPVisitor {
|
||||||
parent = param.getParent();
|
parent = param.getParent();
|
||||||
if( parent instanceof IASTStandardFunctionDeclarator ) {
|
if( parent instanceof IASTStandardFunctionDeclarator ) {
|
||||||
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) param.getParent();
|
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) param.getParent();
|
||||||
if( /*fDtor.getParent() instanceof IASTDeclarator ||*/ fDtor.getNestedDeclarator() != null )
|
if( hasNestedPointerOperator(fDtor) )
|
||||||
return null;
|
return null;
|
||||||
IBinding temp = fDtor.getName().resolveBinding();
|
IBinding temp = fDtor.getName().resolveBinding();
|
||||||
if( temp instanceof ICPPInternalFunction ){
|
if( temp instanceof ICPPInternalFunction ){
|
||||||
|
@ -645,6 +645,17 @@ public class CPPVisitor {
|
||||||
return binding;
|
return binding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean hasNestedPointerOperator(IASTDeclarator decl) {
|
||||||
|
decl= decl.getNestedDeclarator();
|
||||||
|
while (decl != null) {
|
||||||
|
if (decl.getPointerOperators().length > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
decl= decl.getNestedDeclarator();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isConstructor( IScope containingScope, IASTDeclarator declarator ){
|
public static boolean isConstructor( IScope containingScope, IASTDeclarator declarator ){
|
||||||
if( containingScope == null || !(containingScope instanceof ICPPClassScope) )
|
if( containingScope == null || !(containingScope instanceof ICPPClassScope) )
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue