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

Side by Side Diff: pkg/analyzer2dart/lib/src/cps_generator.dart

Issue 652403005: Support assignment of locals in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 years, 1 month 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
« no previous file with comments | « no previous file | pkg/analyzer2dart/lib/src/identifier_semantics.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 analyzer2dart.cps_generator; 5 library analyzer2dart.cps_generator;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 8
9 import 'package:compiler/implementation/dart_types.dart' as dart2js; 9 import 'package:compiler/implementation/dart_types.dart' as dart2js;
10 import 'package:compiler/implementation/elements/elements.dart' as dart2js; 10 import 'package:compiler/implementation/elements/elements.dart' as dart2js;
(...skipping 28 matching lines...) Expand all
39 dart2js.FunctionElement element = converter.convertElement(function); 39 dart2js.FunctionElement element = converter.convertElement(function);
40 return withBuilder( 40 return withBuilder(
41 new IrBuilder(DART_CONSTANT_SYSTEM, 41 new IrBuilder(DART_CONSTANT_SYSTEM,
42 element, 42 element,
43 // TODO(johnniwinther): Supported closure variables. 43 // TODO(johnniwinther): Supported closure variables.
44 const <dart2js.Local>[]), 44 const <dart2js.Local>[]),
45 () { 45 () {
46 function.parameters.forEach((analyzer.ParameterElement parameter) { 46 function.parameters.forEach((analyzer.ParameterElement parameter) {
47 // TODO(johnniwinther): Support "closure variables", that is variables 47 // TODO(johnniwinther): Support "closure variables", that is variables
48 // accessed from an inner function. 48 // accessed from an inner function.
49 irBuilder.createParameter(converter.convertElement(parameter), 49 irBuilder.createParameter(converter.convertElement(parameter));
50 isClosureVariable: false);
51 }); 50 });
52 // Visit the body directly to avoid processing the signature as 51 // Visit the body directly to avoid processing the signature as
53 // expressions. 52 // expressions.
54 visit(node.functionExpression.body); 53 visit(node.functionExpression.body);
55 return irBuilder.buildFunctionDefinition(element, const []); 54 return irBuilder.buildFunctionDefinition(element, const []);
56 }); 55 });
57 } 56 }
58 57
59 List<ir.Definition> visitArguments(ArgumentList argumentList) { 58 List<ir.Definition> visitArguments(ArgumentList argumentList) {
60 List<ir.Definition> arguments = <ir.Definition>[]; 59 List<ir.Definition> arguments = <ir.Definition>[];
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 183
185 @override 184 @override
186 visitVariableDeclaration(VariableDeclaration node) { 185 visitVariableDeclaration(VariableDeclaration node) {
187 // TODO(johnniwinther): Handle constant local variables. 186 // TODO(johnniwinther): Handle constant local variables.
188 ir.Node initialValue = build(node.initializer); 187 ir.Node initialValue = build(node.initializer);
189 irBuilder.declareLocalVariable( 188 irBuilder.declareLocalVariable(
190 converter.convertElement(node.element), 189 converter.convertElement(node.element),
191 initialValue: initialValue); 190 initialValue: initialValue);
192 } 191 }
193 192
194 ir.Primitive handleLocalAccess(AstNode node, AccessSemantics semantics) { 193 dart2js.Element getLocal(AstNode node, AccessSemantics semantics) {
195 analyzer.Element element = semantics.element; 194 analyzer.Element element = semantics.element;
196 dart2js.Element target = converter.convertElement(element); 195 dart2js.Element target = converter.convertElement(element);
197 assert(invariant(node, target.isLocal, '$target expected to be local.')); 196 assert(invariant(node, target.isLocal, '$target expected to be local.'));
198 return irBuilder.buildLocalGet(target); 197 return target;
198 }
199
200 ir.Primitive handleLocalAccess(AstNode node, AccessSemantics semantics) {
201 return irBuilder.buildLocalGet(getLocal(node, semantics));
202 }
203
204 ir.Primitive handleLocalAssignment(AssignmentExpression node,
205 AccessSemantics semantics) {
206 if (node.operator.lexeme != '=') {
207 return giveUp(node, 'Assignment operator: ${node.operator.lexeme}');
208 }
209 return irBuilder.buildLocalSet(
210 getLocal(node, semantics),
211 build(node.rightHandSide));
199 } 212 }
200 213
201 @override 214 @override
215 ir.Node visitAssignmentExpression(AssignmentExpression node) {
216 // Avoid eager visiting of left and right hand side.
217 return handleAssignmentExpression(node);
218 }
219
220 @override
221 ir.Node visitLocalVariableAssignment(AssignmentExpression node,
222 AccessSemantics semantics) {
223 return handleLocalAssignment(node, semantics);
224 }
225
226 @override
227 ir.Node visitParameterAssignment(AssignmentExpression node,
228 AccessSemantics semantics) {
229 return handleLocalAssignment(node, semantics);
230 }
231
232 @override
202 ir.Node visitDynamicAccess(AstNode node, AccessSemantics semantics) { 233 ir.Node visitDynamicAccess(AstNode node, AccessSemantics semantics) {
203 // TODO(johnniwinther): Handle implicit `this`. 234 // TODO(johnniwinther): Handle implicit `this`.
204 ir.Primitive receiver = build(semantics.target); 235 ir.Primitive receiver = build(semantics.target);
205 return irBuilder.buildDynamicGet(receiver, 236 return irBuilder.buildDynamicGet(receiver,
206 new Selector.getter(semantics.identifier.name, 237 new Selector.getter(semantics.identifier.name,
207 converter.convertElement(element.library))); 238 converter.convertElement(element.library)));
208 } 239 }
209 240
210 @override 241 @override
211 ir.Node visitStaticFieldAccess(AstNode node, AccessSemantics semantics) { 242 ir.Node visitStaticFieldAccess(AstNode node, AccessSemantics semantics) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 build(node.condition), 296 build(node.condition),
266 subbuild(node.thenStatement), 297 subbuild(node.thenStatement),
267 subbuild(node.elseStatement)); 298 subbuild(node.elseStatement));
268 } 299 }
269 300
270 @override 301 @override
271 visitBlock(Block node) { 302 visitBlock(Block node) {
272 irBuilder.buildBlock(node.statements, build); 303 irBuilder.buildBlock(node.statements, build);
273 } 304 }
274 } 305 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer2dart/lib/src/identifier_semantics.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698