mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
fix bug 103281 - references in catch block
This commit is contained in:
parent
6d9f16002a
commit
f817288fb3
2 changed files with 40 additions and 3 deletions
|
@ -4889,4 +4889,25 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
assertSame( f2, col.getName(16).resolveBinding() );
|
assertSame( f2, col.getName(16).resolveBinding() );
|
||||||
assertSame( BT, col.getName(17).resolveBinding() );
|
assertSame( BT, col.getName(17).resolveBinding() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug103281() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("struct Except { int blah; }; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("void f() { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" try { } \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" catch ( Except * e ) { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" e->blah; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" } \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("} \n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP, true, true );
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
tu.accept( col );
|
||||||
|
|
||||||
|
IField blah = (IField) col.getName(1).resolveBinding();
|
||||||
|
IVariable e = (IVariable) col.getName(4).resolveBinding();
|
||||||
|
|
||||||
|
assertSame( e, col.getName(5).resolveBinding() );
|
||||||
|
assertSame( blah, col.getName(6).resolveBinding() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator;
|
import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
||||||
|
@ -1346,11 +1347,14 @@ public class CPPSemantics {
|
||||||
IASTName[] found = null;
|
IASTName[] found = null;
|
||||||
|
|
||||||
if( parent instanceof IASTCompoundStatement ){
|
if( parent instanceof IASTCompoundStatement ){
|
||||||
if( parent.getParent() instanceof IASTFunctionDefinition ){
|
IASTNode p = parent.getParent();
|
||||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) ((IASTFunctionDefinition)parent.getParent()).getDeclarator();
|
if( p instanceof IASTFunctionDefinition ){
|
||||||
|
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) ((IASTFunctionDefinition)p).getDeclarator();
|
||||||
nodes = dtor.getParameters();
|
nodes = dtor.getParameters();
|
||||||
}
|
}
|
||||||
if( nodes == null || nodes.length == 0 ){
|
if( p instanceof ICPPASTCatchHandler ){
|
||||||
|
parent = p;
|
||||||
|
} else if( nodes == null || nodes.length == 0 ){
|
||||||
IASTCompoundStatement compound = (IASTCompoundStatement) parent;
|
IASTCompoundStatement compound = (IASTCompoundStatement) parent;
|
||||||
nodes = compound.getStatements();
|
nodes = compound.getStatements();
|
||||||
}
|
}
|
||||||
|
@ -1462,6 +1466,16 @@ public class CPPSemantics {
|
||||||
item = nodes[0];
|
item = nodes[0];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if( parent instanceof ICPPASTCatchHandler ){
|
||||||
|
parent = ((ICPPASTCatchHandler)parent).getCatchBody();
|
||||||
|
if( parent instanceof IASTCompoundStatement ){
|
||||||
|
nodes = ((IASTCompoundStatement)parent).getStatements();
|
||||||
|
}
|
||||||
|
if( nodes.length > 0 ){
|
||||||
|
idx = 0;
|
||||||
|
item = nodes[0];
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if( item == null && nodeStackPos >= 0 ){
|
if( item == null && nodeStackPos >= 0 ){
|
||||||
nodes = nodeStack[nodeStackPos];
|
nodes = nodeStack[nodeStackPos];
|
||||||
|
@ -1545,6 +1559,8 @@ public class CPPSemantics {
|
||||||
declaration = (IASTDeclaration) node;
|
declaration = (IASTDeclaration) node;
|
||||||
else if( node instanceof IASTDeclarationStatement )
|
else if( node instanceof IASTDeclarationStatement )
|
||||||
declaration = ((IASTDeclarationStatement)node).getDeclaration();
|
declaration = ((IASTDeclarationStatement)node).getDeclaration();
|
||||||
|
else if( node instanceof ICPPASTCatchHandler )
|
||||||
|
declaration = ((ICPPASTCatchHandler)node).getDeclaration();
|
||||||
else if( node instanceof ICPPASTForStatement && checkAux )
|
else if( node instanceof ICPPASTForStatement && checkAux )
|
||||||
{
|
{
|
||||||
ICPPASTForStatement forStatement = (ICPPASTForStatement) node;
|
ICPPASTForStatement forStatement = (ICPPASTForStatement) node;
|
||||||
|
|
Loading…
Add table
Reference in a new issue