1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Scopes for catch handlers, bug 209579.

This commit is contained in:
Markus Schorn 2008-08-05 12:05:59 +00:00
parent ab54af8863
commit 0c1c0e52bd
5 changed files with 39 additions and 25 deletions

View file

@ -5986,4 +5986,14 @@ public class AST2CPPTests extends AST2BaseTest {
specs= fdtor.getExceptionSpecification();
assertEquals(1, specs.length);
}
// int test() {
// try {
// } catch (const int &ex) {
// } catch (const char &ex) {
// }
// }
public void testScopeOfCatchHandler_Bug209579() throws Exception {
parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP);
}
}

View file

@ -13,22 +13,21 @@ package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
/**
* Catch handler serves as a standalone stage.
* Catch handler used for try block statements or for functions with try block.
* @see ICPPASTFunctionWithTryBlock
* @see ICPPASTTryBlockStatement
*
* @author jcamelon
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface ICPPASTCatchHandler extends IASTStatement {
/**
* Constant
*/
public static final ICPPASTCatchHandler[] EMPTY_CATCHHANDLER_ARRAY = new ICPPASTCatchHandler[0];
/**
* <code>DECLARATION</code> represnts the nested declaration within the
* catch handler.
* <code>DECLARATION</code> represents the nested declaration within the catch handler.
*/
public static final ASTNodeProperty DECLARATION = new ASTNodeProperty(
"ICPPASTCatchHandler.DECLARATION - Nested declaration within catch handler"); //$NON-NLS-1$
@ -41,47 +40,37 @@ public interface ICPPASTCatchHandler extends IASTStatement {
/**
* Set is catch all handler.
*
* @param isEllipsis
* boolean
*/
public void setIsCatchAll(boolean isEllipsis);
/**
* Is this catch handler for all exceptions?
*
* @return boolean
*/
public boolean isCatchAll();
/**
* Set the catch body.
*
* @param compoundStatement
* <code>IASTStatement</code>
*/
public void setCatchBody(IASTStatement compoundStatement);
/**
* Get the cathc body.
*
* @return <code>IASTStatement</code>
* Get the catch body.
*/
public IASTStatement getCatchBody();
/**
* Set the declaration.
*
* @param decl
* <code>IASTDeclaration</code>
*/
public void setDeclaration(IASTDeclaration decl);
/**
* Get the declaration.
*
* @return <code>IASTDeclaration</code>
*/
public IASTDeclaration getDeclaration();
/**
* Get the scope represented by this catch handler.
* @since 5.1
*/
public IScope getScope();
}

View file

@ -6,7 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -14,6 +15,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
@ -25,6 +27,7 @@ public class CPPASTCatchHandler extends CPPASTNode implements ICPPASTCatchHandle
private boolean isCatchAll;
private IASTStatement body;
private IASTDeclaration declaration;
private IScope scope;
public CPPASTCatchHandler() {
}
@ -103,4 +106,11 @@ public class CPPASTCatchHandler extends CPPASTNode implements ICPPASTCatchHandle
}
}
public IScope getScope() {
if (scope == null) {
scope = new CPPBlockScope(this);
}
return scope;
}
}

View file

@ -459,6 +459,8 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
name = getScopeName();
} catch (DOMException e) {
}
return name != null ? name.toString() : "<unnamed scope>"; //$NON-NLS-1$
final String n= name != null ? name.toString() : "<unnamed scope>"; //$NON-NLS-1$
return getKind().toString() + ' ' + n + ' ' + '(' + super.toString() + ')';
}
}

View file

@ -86,6 +86,7 @@ import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
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.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
@ -770,6 +771,8 @@ public class CPPVisitor {
return ((ICPPASTWhileStatement)parent).getScope();
} else if (parent instanceof ICPPASTTemplateDeclaration) {
return ((ICPPASTTemplateDeclaration)parent).getScope();
} else if (parent instanceof ICPPASTCatchHandler) {
return ((ICPPASTCatchHandler)parent).getScope();
}
} else if (node instanceof IASTStatement) {
return getContainingScope((IASTStatement) node);