Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Unified Diff: pkg/compiler/lib/src/dart_backend/backend_ast_emitter.dart

Issue 923013002: dart2dart: Implementation of simple try/catch. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/dart_backend/backend_ast_emitter.dart
diff --git a/pkg/compiler/lib/src/dart_backend/backend_ast_emitter.dart b/pkg/compiler/lib/src/dart_backend/backend_ast_emitter.dart
index 277966315b3c6ee24c63c05a598664cff5034e28..a333a607960cfc1d3c84ac35f7aca3d6c6a80b9b 100644
--- a/pkg/compiler/lib/src/dart_backend/backend_ast_emitter.dart
+++ b/pkg/compiler/lib/src/dart_backend/backend_ast_emitter.dart
@@ -38,6 +38,9 @@ class BuilderContext<T> {
/// Variables that have had their declaration created.
final Set<tree.Variable> declaredVariables = new Set<tree.Variable>();
+ /// Variables that are used as catch handler parameters.
+ final Set<tree.Variable> handlerVariables = new Set<tree.Variable>();
+
/// Variable names that have already been used. Used to avoid name clashes.
final Set<String> usedVariableNames;
@@ -83,7 +86,7 @@ class BuilderContext<T> {
new Map<tree.Variable, String>.from(parent.variableNames);
// TODO(johnniwinther): Fully encapsulate handling of parameter, variable
- // and local funciton declarations.
+ // and local function declarations.
void addDeclaration(tree.Variable variable, [Expression initializer]) {
assert(!declaredVariables.contains(variable));
String name = getVariableName(variable);
@@ -360,7 +363,8 @@ class ASTEmitter
// if their first assignment could be pulled into the initializer.
// Add the remaining variable declarations now.
for (tree.Variable variable in context.variableNames.keys) {
- if (!context.declaredVariables.contains(variable)) {
+ if (!context.declaredVariables.contains(variable) &&
+ !context.handlerVariables.contains(variable)) {
context.addDeclaration(variable);
}
}
@@ -629,6 +633,34 @@ class ASTEmitter
}
@override
+ void visitTryStatement(tree.TryStatement stmt,
+ BuilderContext<Statement> context) {
+ Block tryBody = visitInSubContext(stmt.tryBody, context);
+ Block catchBody = visitInSubContext(stmt.catchBody, context);
+ CatchBlock catchBlock;
+ tree.Variable exceptionVariable = stmt.catchParameters[0];
+ context.handlerVariables.add(exceptionVariable);
+ VariableDeclaration exceptionParameter =
+ new VariableDeclaration(context.getVariableName(exceptionVariable));
+ exceptionParameter.element = exceptionVariable.element;
+ if (stmt.catchParameters.length == 2) {
+ tree.Variable stackTraceVariable = stmt.catchParameters[1];
+ context.handlerVariables.add(stackTraceVariable);
+ VariableDeclaration stackTraceParameter =
+ new VariableDeclaration(context.getVariableName(stackTraceVariable));
+ stackTraceParameter.element = stackTraceVariable.element;
+ catchBlock = new CatchBlock(catchBody,
+ exceptionVar: exceptionParameter,
+ stackVar: stackTraceParameter);
+ } else {
+ assert(stmt.catchParameters.length == 1);
+ catchBlock = new CatchBlock(catchBody,
+ exceptionVar: exceptionParameter);
+ }
+ context.addStatement(new Try(tryBody, <CatchBlock>[catchBlock], null));
+ }
+
+ @override
Expression visitConstant(tree.Constant exp,
BuilderContext<Statement> context) {
return ConstantEmitter.createExpression(exp.expression, context);

Powered by Google App Engine
This is Rietveld 408576698