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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_builder.dart

Issue 609783002: Support static field access in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 years, 2 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 dart2js.ir_builder; 5 library dart2js.ir_builder;
6 6
7 import 'cps_ir_nodes.dart' as ir; 7 import 'cps_ir_nodes.dart' as ir;
8 import '../elements/elements.dart'; 8 import '../elements/elements.dart';
9 import '../dart2jslib.dart'; 9 import '../dart2jslib.dart';
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 return buildPrimConst( 343 return buildPrimConst(
344 constantSystem.createString(new ast.DartString.literal(value))); 344 constantSystem.createString(new ast.DartString.literal(value)));
345 } 345 }
346 346
347 /// Create a get access of [local]. 347 /// Create a get access of [local].
348 ir.Primitive buildGetLocal(Element local) { 348 ir.Primitive buildGetLocal(Element local) {
349 assert(isOpen); 349 assert(isOpen);
350 return environment.lookup(local); 350 return environment.lookup(local);
351 } 351 }
352 352
353 /// Create a get access of the static [element].
354 ir.Primitive buildGetStatic(Element element, Selector selector) {
355 assert(isOpen);
356 assert(selector.isGetter);
357 return continueWithExpression(
358 (k) => new ir.InvokeStatic(element, selector, k, []));
359 }
360
353 /** 361 /**
354 * Add an explicit `return null` for functions that don't have a return 362 * Add an explicit `return null` for functions that don't have a return
355 * statement on each branch. This includes functions with an empty body, 363 * statement on each branch. This includes functions with an empty body,
356 * such as `foo(){ }`. 364 * such as `foo(){ }`.
357 */ 365 */
358 void ensureReturn() { 366 void ensureReturn() {
359 if (!isOpen) return; 367 if (!isOpen) return;
360 ir.Constant constant = makePrimConst(constantSystem.createNull()); 368 ir.Constant constant = makePrimConst(constantSystem.createNull());
361 add(new ir.LetPrim(constant)); 369 add(new ir.LetPrim(constant));
362 add(new ir.InvokeContinuation(returnContinuation, [constant])); 370 add(new ir.InvokeContinuation(returnContinuation, [constant]));
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 LocalElement local = element; 1439 LocalElement local = element;
1432 result = new ir.GetClosureVariable(local); 1440 result = new ir.GetClosureVariable(local);
1433 add(new ir.LetPrim(result)); 1441 add(new ir.LetPrim(result));
1434 } else if (Elements.isLocal(element)) { 1442 } else if (Elements.isLocal(element)) {
1435 // Reference to local variable 1443 // Reference to local variable
1436 result = buildGetLocal(element); 1444 result = buildGetLocal(element);
1437 } else if (element == null || 1445 } else if (element == null ||
1438 Elements.isInstanceField(element) || 1446 Elements.isInstanceField(element) ||
1439 Elements.isInstanceMethod(element) || 1447 Elements.isInstanceMethod(element) ||
1440 selector.isIndex || 1448 selector.isIndex ||
1441 // TODO(johnniwinther): clean up semantics of resultion. 1449 // TODO(johnniwinther): clean up semantics of resolution.
1442 node.isSuperCall) { 1450 node.isSuperCall) {
1443 // Dynamic dispatch to a getter. Sometimes resolution will suggest a 1451 // Dynamic dispatch to a getter. Sometimes resolution will suggest a
1444 // target element, but in these cases we must still emit a dynamic 1452 // target element, but in these cases we must still emit a dynamic
1445 // dispatch. The target element may be an instance method in case we are 1453 // dispatch. The target element may be an instance method in case we are
1446 // converting a method to a function object. 1454 // converting a method to a function object.
1447 1455
1448 receiver = visitReceiver(node.receiver); 1456 receiver = visitReceiver(node.receiver);
1449 List<ir.Primitive> arguments = new List<ir.Primitive>(); 1457 List<ir.Primitive> arguments = new List<ir.Primitive>();
1450 if (selector.isIndex) { 1458 if (selector.isIndex) {
1451 index = visit(node.arguments.head); 1459 index = visit(node.arguments.head);
1452 arguments.add(index); 1460 arguments.add(index);
1453 } 1461 }
1454 1462
1455 assert(selector.kind == SelectorKind.GETTER || 1463 assert(selector.kind == SelectorKind.GETTER ||
1456 selector.kind == SelectorKind.INDEX); 1464 selector.kind == SelectorKind.INDEX);
1457 result = continueWithExpression( 1465 result = continueWithExpression(
1458 (k) => createDynamicInvoke(node, selector, receiver, k, arguments)); 1466 (k) => createDynamicInvoke(node, selector, receiver, k, arguments));
1459 } else if (element.isField || element.isGetter || element.isErroneous || 1467 } else if (element.isField || element.isGetter || element.isErroneous ||
1460 element.isSetter) { 1468 element.isSetter) {
1469 // TODO(johnniwinther): Change handling of setter selectors.
1461 // Access to a static field or getter (non-static case handled above). 1470 // Access to a static field or getter (non-static case handled above).
1462 // Even if there is only a setter, we compile as if it was a getter, 1471 // Even if there is only a setter, we compile as if it was a getter,
1463 // so the vm can fail at runtime. 1472 // so the vm can fail at runtime.
1464 assert(selector.kind == SelectorKind.GETTER || 1473 assert(selector.kind == SelectorKind.GETTER ||
1465 selector.kind == SelectorKind.SETTER); 1474 selector.kind == SelectorKind.SETTER);
1466 result = continueWithExpression( 1475 result = buildGetStatic(element, selector);
1467 (k) => new ir.InvokeStatic(element, selector, k, []));
1468 } else if (Elements.isStaticOrTopLevelFunction(element)) { 1476 } else if (Elements.isStaticOrTopLevelFunction(element)) {
1469 // Convert a top-level or static function to a function object. 1477 // Convert a top-level or static function to a function object.
1470 result = translateConstant(node); 1478 result = translateConstant(node);
1471 } else { 1479 } else {
1472 throw "Unexpected SendSet getter: $node, $element"; 1480 throw "Unexpected SendSet getter: $node, $element";
1473 } 1481 }
1474 return new _GetterElements( 1482 return new _GetterElements(
1475 result: result,index: index, receiver: receiver); 1483 result: result,index: index, receiver: receiver);
1476 } 1484 }
1477 1485
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
2103 } 2111 }
2104 2112
2105 visitFunctionExpression(ast.FunctionExpression node) { 2113 visitFunctionExpression(ast.FunctionExpression node) {
2106 FunctionElement oldFunction = currentFunction; 2114 FunctionElement oldFunction = currentFunction;
2107 currentFunction = elements[node]; 2115 currentFunction = elements[node];
2108 visit(node.body); 2116 visit(node.body);
2109 currentFunction = oldFunction; 2117 currentFunction = oldFunction;
2110 } 2118 }
2111 2119
2112 } 2120 }
OLDNEW
« no previous file with comments | « pkg/analyzer2dart/test/tree_shaker_test.dart ('k') | sdk/lib/_internal/compiler/implementation/source_file.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698