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

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: Fixed break/continue, incorporated comments. 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..8ef7aecf4dffb5371483c52ae280b5c2194d5dbf 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 visitTry(tree.Try stmt,
+ BuilderContext<Statement> context) {
karlklose 2015/02/26 11:24:23 Align parameters.
Kevin Millikin (Google) 2015/02/26 12:47:06 Done.
+ 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);
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | pkg/compiler/lib/src/dart_backend/backend_ast_nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698