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

Side by Side Diff: pkg/compiler/lib/src/dart_backend/backend_ast_emitter.dart

Issue 958603002: Added VariableUse expression to tree IR. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library backend_ast_emitter; 5 library backend_ast_emitter;
6 6
7 import '../tree_ir/tree_ir_nodes.dart' as tree; 7 import '../tree_ir/tree_ir_nodes.dart' as tree;
8 import 'backend_ast_nodes.dart'; 8 import 'backend_ast_nodes.dart';
9 import '../constants/expressions.dart'; 9 import '../constants/expressions.dart';
10 import '../constants/values.dart'; 10 import '../constants/values.dart';
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 // Try to pull into initializer. 529 // Try to pull into initializer.
530 if (context.firstStatement == stmt && isFirstOccurrence && isDeclaredHere) { 530 if (context.firstStatement == stmt && isFirstOccurrence && isDeclaredHere) {
531 if (isNullLiteral(definition)) definition = null; 531 if (isNullLiteral(definition)) definition = null;
532 context.addDeclaration(stmt.variable, definition); 532 context.addDeclaration(stmt.variable, definition);
533 context.firstStatement = stmt.next; 533 context.firstStatement = stmt.next;
534 visitStatement(stmt.next, context); 534 visitStatement(stmt.next, context);
535 return; 535 return;
536 } 536 }
537 537
538 // Emit a variable declaration if we are required to do so. 538 // Emit a variable declaration if we are required to do so.
539 // This is to ensure that a fresh closure variable is created. 539 // For captured variables, this ensures that a fresh variable is created.
540 if (stmt.isDeclaration) { 540 if (stmt.isDeclaration) {
541 assert(isFirstOccurrence); 541 assert(isFirstOccurrence);
542 assert(isDeclaredHere); 542 assert(isDeclaredHere);
543 if (isNullLiteral(definition)) definition = null; 543 if (isNullLiteral(definition)) definition = null;
544 VariableDeclaration decl = new VariableDeclaration(name, definition) 544 VariableDeclaration decl = new VariableDeclaration(name, definition)
545 ..element = stmt.variable.element; 545 ..element = stmt.variable.element;
546 context.declaredVariables.add(stmt.variable); 546 context.declaredVariables.add(stmt.variable);
547 context.addStatement(new VariableDeclarations([decl])); 547 context.addStatement(new VariableDeclarations([decl]));
548 visitStatement(stmt.next, context); 548 visitStatement(stmt.next, context);
549 return; 549 return;
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 visitExpression(exp.right, context)); 824 visitExpression(exp.right, context));
825 } 825 }
826 826
827 @override 827 @override
828 Expression visitNot(tree.Not exp, 828 Expression visitNot(tree.Not exp,
829 BuilderContext<Statement> context) { 829 BuilderContext<Statement> context) {
830 return new UnaryOperator('!', visitExpression(exp.operand, context)); 830 return new UnaryOperator('!', visitExpression(exp.operand, context));
831 } 831 }
832 832
833 @override 833 @override
834 Expression visitVariableUse(tree.VariableUse exp,
835 BuilderContext<Statement> context) {
Kevin Millikin (Google) 2015/02/26 12:43:17 Indentation is messed up.
asgerf 2015/02/27 12:05:19 Done.
836 return visitVariable(exp.variable, context);
837 }
838
834 Expression visitVariable(tree.Variable exp, 839 Expression visitVariable(tree.Variable exp,
Kevin Millikin (Google) 2015/02/26 12:43:17 I'd probably get rid of this visitVariable method
asgerf 2015/02/27 12:05:19 Done.
835 BuilderContext<Statement> context) { 840 BuilderContext<Statement> context) {
836 return new Identifier(context.getVariableName(exp)) 841 return new Identifier(context.getVariableName(exp))
837 ..element = exp.element; 842 ..element = exp.element;
838 } 843 }
839 844
840 FunctionExpression makeSubFunction(tree.FunctionDefinition function, 845 FunctionExpression makeSubFunction(tree.FunctionDefinition function,
841 BuilderContext<Statement> context) { 846 BuilderContext<Statement> context) {
842 return emit(function, new BuilderContext<Statement>.inner(context)); 847 return emit(function, new BuilderContext<Statement>.inner(context));
843 } 848 }
844 849
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 visitStatement(definition.body); 1231 visitStatement(definition.body);
1227 environment = oldEnvironment; 1232 environment = oldEnvironment;
1228 shadowedParameters = oldShadow; 1233 shadowedParameters = oldShadow;
1229 1234
1230 for (int i=0; i<definition.parameters.length; i++) { 1235 for (int i=0; i<definition.parameters.length; i++) {
1231 tree.Variable param = definition.parameters[i]; 1236 tree.Variable param = definition.parameters[i];
1232 if (hasShadowedUse.remove(param)) { 1237 if (hasShadowedUse.remove(param)) {
1233 tree.Variable newParam = new tree.Variable(definition.element, 1238 tree.Variable newParam = new tree.Variable(definition.element,
1234 param.element); 1239 param.element);
1235 definition.parameters[i] = newParam; 1240 definition.parameters[i] = newParam;
1236 definition.body = new tree.Assign(param, newParam, definition.body); 1241 definition.body = new tree.Assign(param, new tree.VariableUse(newParam),
1242 definition.body);
1237 newParam.writeCount = 1; // Being a parameter counts as a write. 1243 newParam.writeCount = 1; // Being a parameter counts as a write.
1244 param.writeCount--; // Not a parameter anymore.
asgerf 2015/02/25 12:40:30 This was technically a bug, although the reference
1238 } 1245 }
1239 } 1246 }
1240 } 1247 }
1241 1248
1249 @override
1242 visitVariable(tree.Variable variable) { 1250 visitVariable(tree.Variable variable) {
1243 if (shadowedParameters.contains(variable)) { 1251 if (shadowedParameters.contains(variable)) {
1244 hasShadowedUse.add(variable); 1252 hasShadowedUse.add(variable);
1245 } 1253 }
1246 } 1254 }
1247 1255
1248 } 1256 }
1249 1257
1250 // TODO(johnniwinther): Remove this when the dart `backend_ast` does not need 1258 // TODO(johnniwinther): Remove this when the dart `backend_ast` does not need
1251 // [Element] for entities. 1259 // [Element] for entities.
1252 class _SyntheticLocalVariableElement extends modelx.VariableElementX 1260 class _SyntheticLocalVariableElement extends modelx.VariableElementX
1253 implements LocalVariableElement { 1261 implements LocalVariableElement {
1254 1262
1255 _SyntheticLocalVariableElement(String name, 1263 _SyntheticLocalVariableElement(String name,
1256 ExecutableElement enclosingElement, 1264 ExecutableElement enclosingElement,
1257 modelx.VariableList variables) 1265 modelx.VariableList variables)
1258 : super(name, ElementKind.VARIABLE, enclosingElement, variables, null); 1266 : super(name, ElementKind.VARIABLE, enclosingElement, variables, null);
1259 1267
1260 ExecutableElement get executableContext => enclosingElement; 1268 ExecutableElement get executableContext => enclosingElement;
1261 1269
1262 ExecutableElement get memberContext => executableContext.memberContext; 1270 ExecutableElement get memberContext => executableContext.memberContext;
1263 1271
1264 bool get isLocal => true; 1272 bool get isLocal => true;
1265 1273
1266 LibraryElement get implementationLibrary => enclosingElement.library; 1274 LibraryElement get implementationLibrary => enclosingElement.library;
1267 } 1275 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698