| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** A formal parameter to a [Method]. */ | 5 /** A formal parameter to a [Method]. */ |
| 6 class Parameter { | 6 class Parameter { |
| 7 FormalNode definition; | 7 FormalNode definition; |
| 8 | 8 |
| 9 String name; | 9 String name; |
| 10 Type type; | 10 Type type; |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 if (!isDynamic) { | 395 if (!isDynamic) { |
| 396 declaringType.markUsed(); | 396 declaringType.markUsed(); |
| 397 } | 397 } |
| 398 if (isStatic) { | 398 if (isStatic) { |
| 399 // Make sure to compute the value of all static fields, even if we don't | 399 // Make sure to compute the value of all static fields, even if we don't |
| 400 // use this value immediately. | 400 // use this value immediately. |
| 401 var cv = computeValue(); | 401 var cv = computeValue(); |
| 402 if (isFinal) { | 402 if (isFinal) { |
| 403 return cv; | 403 return cv; |
| 404 } | 404 } |
| 405 world.gen.hasStatics = true; |
| 405 if (declaringType.isTop) { | 406 if (declaringType.isTop) { |
| 406 return new Value(type, '$jsname', node.span); | 407 if (declaringType.library == world.dom) { |
| 408 return new Value(type, '$jsname', node.span); |
| 409 } else { |
| 410 return new Value(type, '\$globals.$jsname', node.span); |
| 411 } |
| 412 } else if (declaringType.isNative) { |
| 413 return new Value(type, '${declaringType.jsname}.$jsname', node.span); |
| 407 } else { | 414 } else { |
| 408 return new Value(type, '${declaringType.jsname}.$jsname', node.span); | 415 return new Value(type, |
| 416 '\$globals.${declaringType.jsname}_$jsname', node.span); |
| 409 } | 417 } |
| 410 } else if (target.isConst && isFinal) { | 418 } else if (target.isConst && isFinal) { |
| 411 // take advantage of consts and retrieve the value directly if possible | 419 // take advantage of consts and retrieve the value directly if possible |
| 412 var constTarget = target is GlobalValue ? target.dynamic.exp : target; | 420 var constTarget = target is GlobalValue ? target.dynamic.exp : target; |
| 413 if (constTarget is ConstObjectValue) { | 421 if (constTarget is ConstObjectValue) { |
| 414 return constTarget.fields[name]; | 422 return constTarget.fields[name]; |
| 415 } else if (constTarget.type == world.stringType && name == 'length') { | 423 } else if (constTarget.type == world.stringType && name == 'length') { |
| 416 return new Value(type, '${constTarget.actualValue.length}', node.span); | 424 return new Value(type, '${constTarget.actualValue.length}', node.span); |
| 417 } | 425 } |
| 418 } | 426 } |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 [bool isDynamic=false]) { | 754 [bool isDynamic=false]) { |
| 747 world.error('can not set method', definition.span); | 755 world.error('can not set method', definition.span); |
| 748 } | 756 } |
| 749 | 757 |
| 750 Value _get(MethodGenerator context, Node node, Value target, | 758 Value _get(MethodGenerator context, Node node, Value target, |
| 751 [bool isDynamic=false]) { | 759 [bool isDynamic=false]) { |
| 752 // TODO(jimhug): Would prefer to invoke! | 760 // TODO(jimhug): Would prefer to invoke! |
| 753 declaringType.genMethod(this); | 761 declaringType.genMethod(this); |
| 754 _provideOptionalParamInfo = true; | 762 _provideOptionalParamInfo = true; |
| 755 if (isStatic) { | 763 if (isStatic) { |
| 764 // ensure the type is generated. |
| 765 // TODO(sigmund): can we avoid generating the entire type, but only what |
| 766 // we need? |
| 767 declaringType.markUsed(); |
| 756 var type = declaringType.isTop ? '' : '${declaringType.jsname}.'; | 768 var type = declaringType.isTop ? '' : '${declaringType.jsname}.'; |
| 757 return new Value(functionType, '$type$jsname', node.span); | 769 return new Value(functionType, '$type$jsname', node.span); |
| 758 } | 770 } |
| 759 _providePropertySyntax = true; | 771 _providePropertySyntax = true; |
| 760 return new Value(functionType, '${target.code}.get\$$jsname()', node.span); | 772 return new Value(functionType, '${target.code}.get\$$jsname()', node.span); |
| 761 } | 773 } |
| 762 | 774 |
| 763 bool namesInOrder(Arguments args) { | 775 bool namesInOrder(Arguments args) { |
| 764 if (!args.hasNames) return true; | 776 if (!args.hasNames) return true; |
| 765 | 777 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 Arguments args, [bool isDynamic=false]) { | 843 Arguments args, [bool isDynamic=false]) { |
| 832 // TODO(jimhug): Fix this hack for ensuring a method is resolved. | 844 // TODO(jimhug): Fix this hack for ensuring a method is resolved. |
| 833 if (parameters == null) { | 845 if (parameters == null) { |
| 834 world.info('surprised to need to resolve: ${declaringType.name}.$name'); | 846 world.info('surprised to need to resolve: ${declaringType.name}.$name'); |
| 835 this.resolve(declaringType); | 847 this.resolve(declaringType); |
| 836 } | 848 } |
| 837 | 849 |
| 838 declaringType.genMethod(this); | 850 declaringType.genMethod(this); |
| 839 | 851 |
| 840 if (isStatic || isFactory) { | 852 if (isStatic || isFactory) { |
| 853 // TODO(sigmund): can we avoid generating the entire type, but only what |
| 854 // we need? |
| 841 declaringType.markUsed(); | 855 declaringType.markUsed(); |
| 842 } | 856 } |
| 843 | 857 |
| 844 if (isNative && returnType != null) returnType.markUsed(); | 858 if (isNative && returnType != null) returnType.markUsed(); |
| 845 | 859 |
| 846 if (!namesInOrder(args)) { | 860 if (!namesInOrder(args)) { |
| 847 // Names aren't in order. For now, use a var call because it's an | 861 // Names aren't in order. For now, use a var call because it's an |
| 848 // easy way to get the right eval order for out of order arguments. | 862 // easy way to get the right eval order for out of order arguments. |
| 849 return context.findMembers(name).invokeOnVar(context, node, target, args); | 863 return context.findMembers(name).invokeOnVar(context, node, target, args); |
| 850 } | 864 } |
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1675 } | 1689 } |
| 1676 | 1690 |
| 1677 void forEach(void f(Member member)) { | 1691 void forEach(void f(Member member)) { |
| 1678 factories.forEach((_, Map constructors) { | 1692 factories.forEach((_, Map constructors) { |
| 1679 constructors.forEach((_, Member member) { | 1693 constructors.forEach((_, Member member) { |
| 1680 f(member); | 1694 f(member); |
| 1681 }); | 1695 }); |
| 1682 }); | 1696 }); |
| 1683 } | 1697 } |
| 1684 } | 1698 } |
| OLD | NEW |