| OLD | NEW |
| 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 ir.Constant buildNullLiteral() { | 363 ir.Constant buildNullLiteral() { |
| 364 return buildPrimConst(constantSystem.createNull()); | 364 return buildPrimConst(constantSystem.createNull()); |
| 365 } | 365 } |
| 366 | 366 |
| 367 /// Create a string literal. | 367 /// Create a string literal. |
| 368 ir.Constant buildStringLiteral(String value) { | 368 ir.Constant buildStringLiteral(String value) { |
| 369 return buildPrimConst( | 369 return buildPrimConst( |
| 370 constantSystem.createString(new ast.DartString.literal(value))); | 370 constantSystem.createString(new ast.DartString.literal(value))); |
| 371 } | 371 } |
| 372 | 372 |
| 373 /// Create a get access of [local]. |
| 374 ir.Primitive buildGetLocal(Element local) { |
| 375 assert(isOpen); |
| 376 return environment.lookup(local); |
| 377 } |
| 378 |
| 373 /** | 379 /** |
| 374 * Add an explicit `return null` for functions that don't have a return | 380 * Add an explicit `return null` for functions that don't have a return |
| 375 * statement on each branch. This includes functions with an empty body, | 381 * statement on each branch. This includes functions with an empty body, |
| 376 * such as `foo(){ }`. | 382 * such as `foo(){ }`. |
| 377 */ | 383 */ |
| 378 void ensureReturn() { | 384 void ensureReturn() { |
| 379 if (!isOpen) return; | 385 if (!isOpen) return; |
| 380 ir.Constant constant = makePrimConst(constantSystem.createNull()); | 386 ir.Constant constant = makePrimConst(constantSystem.createNull()); |
| 381 add(new ir.LetPrim(constant)); | 387 add(new ir.LetPrim(constant)); |
| 382 add(new ir.InvokeContinuation(returnContinuation, [constant])); | 388 add(new ir.InvokeContinuation(returnContinuation, [constant])); |
| (...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 | 1336 |
| 1331 if (element != null && element.isConst) { | 1337 if (element != null && element.isConst) { |
| 1332 // Reference to constant local, top-level or static field | 1338 // Reference to constant local, top-level or static field |
| 1333 result = translateConstant(node); | 1339 result = translateConstant(node); |
| 1334 } else if (isClosureVariable(element)) { | 1340 } else if (isClosureVariable(element)) { |
| 1335 LocalElement local = element; | 1341 LocalElement local = element; |
| 1336 result = new ir.GetClosureVariable(local); | 1342 result = new ir.GetClosureVariable(local); |
| 1337 add(new ir.LetPrim(result)); | 1343 add(new ir.LetPrim(result)); |
| 1338 } else if (Elements.isLocal(element)) { | 1344 } else if (Elements.isLocal(element)) { |
| 1339 // Reference to local variable | 1345 // Reference to local variable |
| 1340 result = environment.lookup(element); | 1346 result = buildGetLocal(element); |
| 1341 } else if (element == null || | 1347 } else if (element == null || |
| 1342 Elements.isInstanceField(element) || | 1348 Elements.isInstanceField(element) || |
| 1343 Elements.isInstanceMethod(element) || | 1349 Elements.isInstanceMethod(element) || |
| 1344 selector.isIndex || | 1350 selector.isIndex || |
| 1345 // TODO(johnniwinther): clean up semantics of resultion. | 1351 // TODO(johnniwinther): clean up semantics of resultion. |
| 1346 node.isSuperCall) { | 1352 node.isSuperCall) { |
| 1347 // Dynamic dispatch to a getter. Sometimes resolution will suggest a | 1353 // Dynamic dispatch to a getter. Sometimes resolution will suggest a |
| 1348 // target element, but in these cases we must still emit a dynamic | 1354 // target element, but in these cases we must still emit a dynamic |
| 1349 // dispatch. The target element may be an instance method in case we are | 1355 // dispatch. The target element may be an instance method in case we are |
| 1350 // converting a method to a function object. | 1356 // converting a method to a function object. |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1978 } | 1984 } |
| 1979 | 1985 |
| 1980 visitFunctionExpression(ast.FunctionExpression node) { | 1986 visitFunctionExpression(ast.FunctionExpression node) { |
| 1981 FunctionElement oldFunction = currentFunction; | 1987 FunctionElement oldFunction = currentFunction; |
| 1982 currentFunction = elements[node]; | 1988 currentFunction = elements[node]; |
| 1983 visit(node.body); | 1989 visit(node.body); |
| 1984 currentFunction = oldFunction; | 1990 currentFunction = oldFunction; |
| 1985 } | 1991 } |
| 1986 | 1992 |
| 1987 } | 1993 } |
| OLD | NEW |