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 /** | 5 /** |
6 * Represents a meta-value for code generation. | 6 * Represents a meta-value for code generation. |
7 */ | 7 */ |
8 class Value { | 8 class Value { |
9 /** The [Type] of the [Value]. */ | 9 /** The [Type] of the [Value]. */ |
10 Type type; | 10 Type type; |
11 | 11 |
12 /** The code to generate this value. */ | 12 /** The code to generate this value. */ |
13 String code; | 13 String code; |
14 | 14 |
15 /** The source location that created this value for error messages. */ | 15 /** The source location that created this value for error messages. */ |
16 SourceSpan span; | 16 SourceSpan span; |
17 | 17 |
18 /** Is this a reference to super? */ | 18 /** Is this a reference to super? */ |
19 bool isSuper; | 19 bool isSuper; |
20 | 20 |
21 /** Is this a pretend first-class type? */ | 21 /** Is this a pretend first-class type? */ |
22 bool isType; | 22 bool isType; |
23 | 23 |
24 /** If we reference this value multiple times, do we need a temp? */ | 24 /** If we reference this value multiple times, do we need a temp? */ |
25 bool needsTemp; | 25 bool needsTemp; |
26 | 26 |
27 // TODO(jmesserly): until reified generics are fixed, treat ParameterType as | |
28 // "var". | |
29 bool get _typeIsVarOrParameterType() => type.isVar || type is ParameterType; | |
30 | |
27 Value(this.type, this.code, this.span, | 31 Value(this.type, this.code, this.span, |
28 // TODO(sigmund): reorder, so that needsTemp comes first. | 32 // TODO(sigmund): reorder, so that needsTemp comes first. |
29 [this.isSuper = false, this.needsTemp = true, this.isType = false]) { | 33 [this.isSuper = false, this.needsTemp = true, this.isType = false]) { |
30 if (type == null) type = world.varType; | 34 if (type == null) type = world.varType; |
31 } | 35 } |
32 | 36 |
33 /** Is this value a constant expression? */ | 37 /** Is this value a constant expression? */ |
34 bool get isConst() => false; | 38 bool get isConst() => false; |
35 | 39 |
36 // TODO(jimhug): Fix these names once get/set are truly pseudo-keywords. | 40 // TODO(jimhug): Fix these names once get/set are truly pseudo-keywords. |
(...skipping 13 matching lines...) Expand all Loading... | |
50 final member = _resolveMember(context, name, node, isDynamic); | 54 final member = _resolveMember(context, name, node, isDynamic); |
51 if (member != null) { | 55 if (member != null) { |
52 return member._set(context, node, this, value, isDynamic); | 56 return member._set(context, node, this, value, isDynamic); |
53 } else { | 57 } else { |
54 return invokeNoSuchMethod(context, 'set:$name', node, | 58 return invokeNoSuchMethod(context, 'set:$name', node, |
55 new Arguments(null, [value])); | 59 new Arguments(null, [value])); |
56 } | 60 } |
57 } | 61 } |
58 | 62 |
59 | 63 |
60 | |
61 Value invoke(MethodGenerator context, String name, Node node, Arguments args, | 64 Value invoke(MethodGenerator context, String name, Node node, Arguments args, |
62 [bool isDynamic=false]) { | 65 [bool isDynamic=false]) { |
63 // TODO(jimhug): The != method is weird - understand it better. | 66 // TODO(jimhug): The != method is weird - understand it better. |
64 if (type.isVar && name == '\$ne') { | 67 if (_typeIsVarOrParameterType && name == '\$ne') { |
Siggi Cherem (dart-lang)
2011/11/11 01:25:51
is is to fix observable_tests, it was failing beca
| |
65 if (args.values.length != 1) { | 68 if (args.values.length != 1) { |
66 world.warning('wrong number of arguments for !=', node.span); | 69 world.warning('wrong number of arguments for !=', node.span); |
67 } | 70 } |
68 world.gen.corejs.useOperator('\$ne'); | 71 world.gen.corejs.useOperator('\$ne'); |
69 return new Value(null, '\$ne($code, ${args.values[0].code})', node.span); | 72 return new Value(null, '\$ne($code, ${args.values[0].code})', node.span); |
70 } | 73 } |
71 | 74 |
72 // TODO(jmesserly): it'd be nice to remove these special cases | 75 // TODO(jmesserly): it'd be nice to remove these special cases |
73 // We could create a $call (and $ne) in world members, and have | 76 // We could create a $call (and $ne) in world members, and have |
74 // those guys handle the canInvoke/Invoke logic. | 77 // those guys handle the canInvoke/Invoke logic. |
(...skipping 15 matching lines...) Expand all Loading... | |
90 var member = _resolveMember(context, name, node, isDynamic); | 93 var member = _resolveMember(context, name, node, isDynamic); |
91 if (member == null) { | 94 if (member == null) { |
92 return invokeNoSuchMethod(context, name, node, args); | 95 return invokeNoSuchMethod(context, name, node, args); |
93 } else { | 96 } else { |
94 return member.invoke(context, node, this, args, isDynamic); | 97 return member.invoke(context, node, this, args, isDynamic); |
95 } | 98 } |
96 } | 99 } |
97 | 100 |
98 bool canInvoke(MethodGenerator context, String name, Arguments args) { | 101 bool canInvoke(MethodGenerator context, String name, Arguments args) { |
99 // TODO(jimhug): The != method is weird - understand it better. | 102 // TODO(jimhug): The != method is weird - understand it better. |
100 if (type.isVar && name == '\$ne') { | 103 if (_typeIsVarOrParameterType && name == '\$ne') { |
101 return true; | 104 return true; |
102 } | 105 } |
103 | 106 |
104 if (type.isVarOrFunction && name == '\$call') { | 107 if (type.isVarOrFunction && name == '\$call') { |
105 return true; | 108 return true; |
106 } | 109 } |
107 | 110 |
108 var member = _resolveMember(context, name, null, isDynamic:true); | 111 var member = _resolveMember(context, name, null, isDynamic:true); |
109 return member != null && member.canInvoke(context, args); | 112 return member != null && member.canInvoke(context, args); |
110 } | 113 } |
(...skipping 17 matching lines...) Expand all Loading... | |
128 return type.getMember(name); | 131 return type.getMember(name); |
129 } else { | 132 } else { |
130 return type.resolveMember(name); | 133 return type.resolveMember(name); |
131 } | 134 } |
132 } | 135 } |
133 | 136 |
134 // TODO(jimhug): Better type here - currently is union(Member, MemberSet) | 137 // TODO(jimhug): Better type here - currently is union(Member, MemberSet) |
135 _resolveMember(MethodGenerator context, String name, Node node, | 138 _resolveMember(MethodGenerator context, String name, Node node, |
136 [bool isDynamic=false]) { | 139 [bool isDynamic=false]) { |
137 | 140 |
138 // TODO(jmesserly): until reified generic lists are fixed, treat | |
139 // ParameterType as "var". | |
140 var member; | 141 var member; |
141 if (!type.isVar && type is! ParameterType) { | 142 if (!_typeIsVarOrParameterType) { |
142 member = _tryResolveMember(context, name); | 143 member = _tryResolveMember(context, name); |
143 | 144 |
144 if (member != null && isType && !member.isStatic) { | 145 if (member != null && isType && !member.isStatic) { |
145 if (!isDynamic) { | 146 if (!isDynamic) { |
146 world.error('can not refer to instance member as static', node.span); | 147 world.error('can not refer to instance member as static', node.span); |
147 } | 148 } |
148 return null; | 149 return null; |
149 } | 150 } |
150 | 151 |
151 if (member == null && !isDynamic && !_hasOverriddenNoSuchMethod()) { | 152 if (member == null && !isDynamic && !_hasOverriddenNoSuchMethod()) { |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
664 | 665 |
665 // Then look for members in my library. | 666 // Then look for members in my library. |
666 member = home.library.lookup(name, span); | 667 member = home.library.lookup(name, span); |
667 if (member != null) { | 668 if (member != null) { |
668 return member; | 669 return member; |
669 } | 670 } |
670 | 671 |
671 return null; | 672 return null; |
672 } | 673 } |
673 } | 674 } |
OLD | NEW |