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

Unified Diff: sdk/lib/_internal/compiler/implementation/dart_backend/dart_codegen.dart

Issue 312793002: dart2dart: Preserve variable names throughout the IR. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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: sdk/lib/_internal/compiler/implementation/dart_backend/dart_codegen.dart
diff --git a/sdk/lib/_internal/compiler/implementation/dart_backend/dart_codegen.dart b/sdk/lib/_internal/compiler/implementation/dart_backend/dart_codegen.dart
index 8738ec6421d19e08451d471aba754bb729f66542..964c84819d6f6d43df7e9379494a80d16938bd46 100644
--- a/sdk/lib/_internal/compiler/implementation/dart_backend/dart_codegen.dart
+++ b/sdk/lib/_internal/compiler/implementation/dart_backend/dart_codegen.dart
@@ -54,7 +54,6 @@ class ASTEmitter extends tree.Visitor<dynamic, Expression> {
variables = <VariableDeclaration>[];
statementBuffer = <Statement>[];
seenVariables = new Set<tree.Variable>();
- tree.Variable.counter = 0;
variableList = new modelx.VariableList(tree.Modifiers.EMPTY);
fallthrough = null;
usedLabels = new Set<tree.Label>();
@@ -174,18 +173,32 @@ class ASTEmitter extends tree.Visitor<dynamic, Expression> {
visitStatement(stmt.next);
}
- void visitAssign(tree.Assign stmt) {
- // Synthesize an element for the variable, if necessary.
- if (stmt.variable.element == null) {
- stmt.variable.element = new modelx.VariableElementX(
- stmt.variable.name,
- ElementKind.VARIABLE,
- functionElement,
- variableList,
- null);
+ String getVariableName(tree.Variable variable) {
sigurdm 2014/06/04 07:51:56 Maybe move this to a getter, so the .name field is
asgerf 2014/06/04 09:40:51 Not so easy since it depends on this.variableList
sigurdm 2014/06/04 10:29:39 True - my mistake
+ if (variable.element != null && variable.index == 0) {
+ return variable.element.name;
+ }
+ // FIXME(asgerf): prevent name clashes
+ String name;
+ if (variable.element != null) {
+ name = '${variable.element.name}${variable.index}';
+ } else {
+ name = 'v${variable.index}';
}
+ // Synthesize an element for the variable
+ variable.element = new modelx.VariableElementX(
+ name,
+ ElementKind.VARIABLE,
+ functionElement,
+ variableList,
+ null);
+ variable.index = 0; // Index is relative to the new synthesized element.
+ return name;
+ }
+
+ void visitAssign(tree.Assign stmt) {
+ String name = getVariableName(stmt.variable);
if (seenVariables.add(stmt.variable)) {
- variables.add(new VariableDeclaration(stmt.variable.name)
+ variables.add(new VariableDeclaration(name)
..element = stmt.variable.element);
}
statementBuffer.add(new ExpressionStatement(makeAssignment(
@@ -349,7 +362,7 @@ class ASTEmitter extends tree.Visitor<dynamic, Expression> {
}
Expression visitVariable(tree.Variable exp) {
- return new Identifier(exp.name)
+ return new Identifier(getVariableName(exp))
..element = exp.element;
}
@@ -366,6 +379,9 @@ class ASTEmitter extends tree.Visitor<dynamic, Expression> {
} else if (type is TypeVariableType) {
return new TypeAnnotation(type.name)
..dartType = type;
+ } else if (type is DynamicType) {
+ return new TypeAnnotation("dynamic")
+ ..dartType = type;
} else {
throw "Unsupported type annotation: $type";
}

Powered by Google App Engine
This is Rietveld 408576698