mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-02 22:05:44 +02:00
Scopes for catch handlers, bug 209579.
This commit is contained in:
parent
ab54af8863
commit
0c1c0e52bd
5 changed files with 39 additions and 25 deletions
|
@ -5986,4 +5986,14 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
specs= fdtor.getExceptionSpecification();
|
specs= fdtor.getExceptionSpecification();
|
||||||
assertEquals(1, specs.length);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.ASTNodeProperty;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
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 {
|
public interface ICPPASTCatchHandler extends IASTStatement {
|
||||||
|
|
||||||
/**
|
|
||||||
* Constant
|
|
||||||
*/
|
|
||||||
public static final ICPPASTCatchHandler[] EMPTY_CATCHHANDLER_ARRAY = new ICPPASTCatchHandler[0];
|
public static final ICPPASTCatchHandler[] EMPTY_CATCHHANDLER_ARRAY = new ICPPASTCatchHandler[0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>DECLARATION</code> represnts the nested declaration within the
|
* <code>DECLARATION</code> represents the nested declaration within the catch handler.
|
||||||
* catch handler.
|
|
||||||
*/
|
*/
|
||||||
public static final ASTNodeProperty DECLARATION = new ASTNodeProperty(
|
public static final ASTNodeProperty DECLARATION = new ASTNodeProperty(
|
||||||
"ICPPASTCatchHandler.DECLARATION - Nested declaration within catch handler"); //$NON-NLS-1$
|
"ICPPASTCatchHandler.DECLARATION - Nested declaration within catch handler"); //$NON-NLS-1$
|
||||||
|
@ -41,47 +40,37 @@ public interface ICPPASTCatchHandler extends IASTStatement {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set is catch all handler.
|
* Set is catch all handler.
|
||||||
*
|
|
||||||
* @param isEllipsis
|
|
||||||
* boolean
|
|
||||||
*/
|
*/
|
||||||
public void setIsCatchAll(boolean isEllipsis);
|
public void setIsCatchAll(boolean isEllipsis);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this catch handler for all exceptions?
|
* Is this catch handler for all exceptions?
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
*/
|
||||||
public boolean isCatchAll();
|
public boolean isCatchAll();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the catch body.
|
* Set the catch body.
|
||||||
*
|
|
||||||
* @param compoundStatement
|
|
||||||
* <code>IASTStatement</code>
|
|
||||||
*/
|
*/
|
||||||
public void setCatchBody(IASTStatement compoundStatement);
|
public void setCatchBody(IASTStatement compoundStatement);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the cathc body.
|
* Get the catch body.
|
||||||
*
|
|
||||||
* @return <code>IASTStatement</code>
|
|
||||||
*/
|
*/
|
||||||
public IASTStatement getCatchBody();
|
public IASTStatement getCatchBody();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the declaration.
|
* Set the declaration.
|
||||||
*
|
|
||||||
* @param decl
|
|
||||||
* <code>IASTDeclaration</code>
|
|
||||||
*/
|
*/
|
||||||
public void setDeclaration(IASTDeclaration decl);
|
public void setDeclaration(IASTDeclaration decl);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the declaration.
|
* Get the declaration.
|
||||||
*
|
|
||||||
* @return <code>IASTDeclaration</code>
|
|
||||||
*/
|
*/
|
||||||
public IASTDeclaration getDeclaration();
|
public IASTDeclaration getDeclaration();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the scope represented by this catch handler.
|
||||||
|
* @since 5.1
|
||||||
|
*/
|
||||||
|
public IScope getScope();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* 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;
|
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.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
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.core.dom.ast.cpp.ICPPASTCatchHandler;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||||
|
|
||||||
|
@ -25,6 +27,7 @@ public class CPPASTCatchHandler extends CPPASTNode implements ICPPASTCatchHandle
|
||||||
private boolean isCatchAll;
|
private boolean isCatchAll;
|
||||||
private IASTStatement body;
|
private IASTStatement body;
|
||||||
private IASTDeclaration declaration;
|
private IASTDeclaration declaration;
|
||||||
|
private IScope scope;
|
||||||
|
|
||||||
public CPPASTCatchHandler() {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -459,6 +459,8 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
|
||||||
name = getScopeName();
|
name = getScopeName();
|
||||||
} catch (DOMException e) {
|
} 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() + ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.IASTEnumerationSpecifier.IASTEnumerator;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
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.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.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.ICPPASTConversionName;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
|
||||||
|
@ -770,6 +771,8 @@ public class CPPVisitor {
|
||||||
return ((ICPPASTWhileStatement)parent).getScope();
|
return ((ICPPASTWhileStatement)parent).getScope();
|
||||||
} else if (parent instanceof ICPPASTTemplateDeclaration) {
|
} else if (parent instanceof ICPPASTTemplateDeclaration) {
|
||||||
return ((ICPPASTTemplateDeclaration)parent).getScope();
|
return ((ICPPASTTemplateDeclaration)parent).getScope();
|
||||||
|
} else if (parent instanceof ICPPASTCatchHandler) {
|
||||||
|
return ((ICPPASTCatchHandler)parent).getScope();
|
||||||
}
|
}
|
||||||
} else if (node instanceof IASTStatement) {
|
} else if (node instanceof IASTStatement) {
|
||||||
return getContainingScope((IASTStatement) node);
|
return getContainingScope((IASTStatement) node);
|
||||||
|
|
Loading…
Add table
Reference in a new issue