| 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; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 Value(this.type, this.code, this.span, | 27 Value(this.type, this.code, this.span, |
| 28 // TODO(sigmund): reorder, so that needsTemp comes first. | 28 // TODO(sigmund): reorder, so that needsTemp comes first. |
| 29 [this.isSuper = false, this.needsTemp = true, this.isType = false]) { | 29 [this.isSuper = false, this.needsTemp = true, this.isType = false]) { |
| 30 if (type == null) type = world.varType; | 30 if (type == null) type = world.varType; |
| 31 } | 31 } |
| 32 | 32 |
| 33 /** Is this value a constant expression? */ | 33 /** Is this value a constant expression? */ |
| 34 bool get isConst() => false; | 34 bool get isConst() => false; |
| 35 | 35 |
| 36 /** |
| 37 * A canonicalized form of the code. Two const expressions that result in the |
| 38 * same instance should have the same [canonicalCode]. |
| 39 */ |
| 40 String get canonicalCode() => null; |
| 41 |
| 36 // TODO(jimhug): Fix these names once get/set are truly pseudo-keywords. | 42 // TODO(jimhug): Fix these names once get/set are truly pseudo-keywords. |
| 37 // See issue #379. | 43 // See issue #379. |
| 38 Value get_(MethodGenerator context, String name, Node node) { | 44 Value get_(MethodGenerator context, String name, Node node) { |
| 39 final member = _resolveMember(context, name, node); | 45 final member = _resolveMember(context, name, node); |
| 40 if (member != null) { | 46 if (member != null) { |
| 41 return member._get(context, node, this); | 47 return member._get(context, node, this); |
| 42 } else { | 48 } else { |
| 43 return invokeNoSuchMethod(context, 'get:$name', node); | 49 return invokeNoSuchMethod(context, 'get:$name', node); |
| 44 } | 50 } |
| 45 } | 51 } |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 // TODO(jmesserly): better assert for integers? | 326 // TODO(jmesserly): better assert for integers? |
| 321 if (toType.isNum) toType = world.numType; | 327 if (toType.isNum) toType = world.numType; |
| 322 | 328 |
| 323 // Generate a check like these: | 329 // Generate a check like these: |
| 324 // obj && obj.is$TypeName() | 330 // obj && obj.is$TypeName() |
| 325 // $assert_int(obj) | 331 // $assert_int(obj) |
| 326 // | 332 // |
| 327 // We rely on the fact that calling an undefined method produces a JS | 333 // We rely on the fact that calling an undefined method produces a JS |
| 328 // TypeError. Alternatively we could define fallbacks on Object that throw. | 334 // TypeError. Alternatively we could define fallbacks on Object that throw. |
| 329 String check; | 335 String check; |
| 330 if (toType.library.isCore && toType.typeofName != null) { | 336 if (toType.isVoid) { |
| 337 check = '\$assert_void($code)'; |
| 338 if (toType.typeCheckCode == null) { |
| 339 toType.typeCheckCode = ''' |
| 340 function \$assert_void(x) { |
| 341 return x == null ? x : x.is\$void(); // throws TypeError |
| 342 }'''; |
| 343 } |
| 344 } else if (toType.library.isCore && toType.typeofName != null) { |
| 331 check = '\$assert_${toType.name}($code)'; | 345 check = '\$assert_${toType.name}($code)'; |
| 332 | 346 |
| 333 if (toType.typeCheckCode == null) { | 347 if (toType.typeCheckCode == null) { |
| 334 toType.typeCheckCode = ''' | 348 toType.typeCheckCode = ''' |
| 335 function \$assert_${toType.name}(x) { | 349 function \$assert_${toType.name}(x) { |
| 336 if (x == null || typeof(x) == "${toType.typeofName}") return x; | 350 if (x == null || typeof(x) == "${toType.typeofName}") return x; |
| 337 throw new TypeError("'" + x + "' is not a ${toType.name}."); | 351 throw new TypeError("'" + x + "' is not a ${toType.name}."); |
| 338 }'''; | 352 }'''; |
| 339 } | 353 } |
| 340 } else { | 354 } else { |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 | 678 |
| 665 // Then look for members in my library. | 679 // Then look for members in my library. |
| 666 member = home.library.lookup(name, span); | 680 member = home.library.lookup(name, span); |
| 667 if (member != null) { | 681 if (member != null) { |
| 668 return member; | 682 return member; |
| 669 } | 683 } |
| 670 | 684 |
| 671 return null; | 685 return null; |
| 672 } | 686 } |
| 673 } | 687 } |
| OLD | NEW |