| OLD | NEW |
| 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 dart_codegen; | 5 library dart_codegen; |
| 6 | 6 |
| 7 import 'dart_tree.dart' as tree; | 7 import 'dart_tree.dart' as tree; |
| 8 import 'dart_printer.dart'; | 8 import 'dart_printer.dart'; |
| 9 import 'dart_tree_printer.dart' show TreePrinter; | 9 import 'dart_tree_printer.dart' show TreePrinter; |
| 10 import '../tree/tree.dart' as frontend; | 10 import '../tree/tree.dart' as frontend; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 158 |
| 159 Parameter emitParameter(tree.Variable param) { | 159 Parameter emitParameter(tree.Variable param) { |
| 160 return emitParameterFromElement(param.element, getVariableName(param)); | 160 return emitParameterFromElement(param.element, getVariableName(param)); |
| 161 } | 161 } |
| 162 | 162 |
| 163 Parameters emitParameters(List<tree.Variable> params) { | 163 Parameters emitParameters(List<tree.Variable> params) { |
| 164 return new Parameters(params.map(emitParameter).toList(growable:false)); | 164 return new Parameters(params.map(emitParameter).toList(growable:false)); |
| 165 } | 165 } |
| 166 | 166 |
| 167 /// True if the two expressions are a reference to the same variable. | 167 /// True if the two expressions are a reference to the same variable. |
| 168 bool isSameVariable(Expression e1, Expression e2) { | 168 bool isSameVariable(Receiver e1, Receiver e2) { |
| 169 // TODO(asgerf): Using the annotated element isn't the best way to do this | 169 // TODO(asgerf): Using the annotated element isn't the best way to do this |
| 170 // since elements are supposed to go away from codegen when we discard the | 170 // since elements are supposed to go away from codegen when we discard the |
| 171 // old backend. | 171 // old backend. |
| 172 return e1 is Identifier && | 172 return e1 is Identifier && |
| 173 e2 is Identifier && | 173 e2 is Identifier && |
| 174 e1.element is VariableElement && | 174 e1.element is VariableElement && |
| 175 e1.element == e2.element; | 175 e1.element == e2.element; |
| 176 } | 176 } |
| 177 | 177 |
| 178 Expression makeAssignment(Expression target, Expression value) { | 178 Expression makeAssignment(Expression target, Expression value) { |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 444 |
| 445 case SelectorKind.CALL: | 445 case SelectorKind.CALL: |
| 446 return new CallStatic(null, exp.target.name, emitArguments(exp)) | 446 return new CallStatic(null, exp.target.name, emitArguments(exp)) |
| 447 ..element = exp.target; | 447 ..element = exp.target; |
| 448 | 448 |
| 449 default: | 449 default: |
| 450 throw "Unexpected selector kind: ${exp.selector.kind}"; | 450 throw "Unexpected selector kind: ${exp.selector.kind}"; |
| 451 } | 451 } |
| 452 } | 452 } |
| 453 | 453 |
| 454 Expression visitInvokeMethod(tree.InvokeMethod exp) { | 454 Expression emitMethodCall(tree.Invoke exp, Receiver receiver) { |
| 455 Expression receiver = visitExpression(exp.receiver); | |
| 456 List<Argument> args = emitArguments(exp); | 455 List<Argument> args = emitArguments(exp); |
| 457 switch (exp.selector.kind) { | 456 switch (exp.selector.kind) { |
| 458 case SelectorKind.CALL: | 457 case SelectorKind.CALL: |
| 459 if (exp.selector.name == "call") { | 458 if (exp.selector.name == "call") { |
| 460 return new CallFunction(receiver, args); | 459 return new CallFunction(receiver, args); |
| 461 } | 460 } |
| 462 return new CallMethod(receiver, exp.selector.name, args); | 461 return new CallMethod(receiver, exp.selector.name, args); |
| 463 | 462 |
| 464 case SelectorKind.OPERATOR: | 463 case SelectorKind.OPERATOR: |
| 465 if (args.length == 0) { | 464 if (args.length == 0) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 484 if (args.length == 2) { | 483 if (args.length == 2) { |
| 485 e = makeAssignment(e, args[1]); | 484 e = makeAssignment(e, args[1]); |
| 486 } | 485 } |
| 487 return e; | 486 return e; |
| 488 | 487 |
| 489 default: | 488 default: |
| 490 throw "Unexpected selector in InvokeMethod: ${exp.selector.kind}"; | 489 throw "Unexpected selector in InvokeMethod: ${exp.selector.kind}"; |
| 491 } | 490 } |
| 492 } | 491 } |
| 493 | 492 |
| 493 Expression visitInvokeMethod(tree.InvokeMethod exp) { |
| 494 Expression receiver = visitExpression(exp.receiver); |
| 495 return emitMethodCall(exp, receiver); |
| 496 } |
| 497 |
| 498 Expression visitInvokeSuperMethod(tree.InvokeSuperMethod exp) { |
| 499 return emitMethodCall(exp, new SuperReceiver()); |
| 500 } |
| 501 |
| 494 Expression visitInvokeConstructor(tree.InvokeConstructor exp) { | 502 Expression visitInvokeConstructor(tree.InvokeConstructor exp) { |
| 495 List args = emitArguments(exp); | 503 List args = emitArguments(exp); |
| 496 FunctionElement constructor = exp.target; | 504 FunctionElement constructor = exp.target; |
| 497 String name = constructor.name.isEmpty ? null : constructor.name; | 505 String name = constructor.name.isEmpty ? null : constructor.name; |
| 498 return new CallNew(emitType(exp.type), | 506 return new CallNew(emitType(exp.type), |
| 499 args, | 507 args, |
| 500 constructorName: name, | 508 constructorName: name, |
| 501 isConst: exp.constant != null) | 509 isConst: exp.constant != null) |
| 502 ..constructor = constructor | 510 ..constructor = constructor |
| 503 ..dartType = exp.type; | 511 ..dartType = exp.type; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 return new Identifier(name) | 639 return new Identifier(name) |
| 632 ..element = exp.element; | 640 ..element = exp.element; |
| 633 } | 641 } |
| 634 | 642 |
| 635 Expression visitFunction(FunctionConstExp exp) { | 643 Expression visitFunction(FunctionConstExp exp) { |
| 636 return new Identifier(exp.element.name) | 644 return new Identifier(exp.element.name) |
| 637 ..element = exp.element; | 645 ..element = exp.element; |
| 638 } | 646 } |
| 639 | 647 |
| 640 } | 648 } |
| OLD | NEW |