Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dev_compiler.src.checker.rules; | 5 library dev_compiler.src.checker.rules; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/resolver.dart'; | 9 import 'package:analyzer/src/generated/resolver.dart'; |
| 10 | 10 |
| 11 import 'package:dev_compiler/src/info.dart'; | 11 import 'package:dev_compiler/src/info.dart'; |
| 12 import 'package:dev_compiler/src/options.dart'; | 12 import 'package:dev_compiler/src/options.dart'; |
| 13 import 'package:dev_compiler/src/utils.dart' as utils; | |
| 13 | 14 |
| 14 abstract class TypeRules { | 15 abstract class TypeRules { |
| 15 final TypeProvider provider; | 16 final TypeProvider provider; |
| 16 LibraryInfo currentLibraryInfo = null; | 17 LibraryInfo currentLibraryInfo = null; |
| 17 | 18 |
| 18 TypeRules(TypeProvider this.provider); | 19 TypeRules(TypeProvider this.provider); |
| 19 | 20 |
| 20 MissingTypeReporter reportMissingType; | 21 MissingTypeReporter reportMissingType; |
| 21 | 22 |
| 22 bool isSubTypeOf(DartType t1, DartType t2); | 23 bool isSubTypeOf(DartType t1, DartType t2); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 38 bool maybeNonNullableType(DartType t) => false; | 39 bool maybeNonNullableType(DartType t) => false; |
| 39 | 40 |
| 40 StaticInfo checkAssignment(Expression expr, DartType t, bool constContext); | 41 StaticInfo checkAssignment(Expression expr, DartType t, bool constContext); |
| 41 | 42 |
| 42 DartType getStaticType(Expression expr) => expr.staticType; | 43 DartType getStaticType(Expression expr) => expr.staticType; |
| 43 | 44 |
| 44 DartType elementType(Element e); | 45 DartType elementType(Element e); |
| 45 | 46 |
| 46 bool isDynamic(DartType t); | 47 bool isDynamic(DartType t); |
| 47 bool isDynamicTarget(Expression expr); | 48 bool isDynamicTarget(Expression expr); |
| 48 bool isDynamicGet(Expression expr); | |
| 49 bool isDynamicCall(Expression call); | 49 bool isDynamicCall(Expression call); |
| 50 } | 50 } |
| 51 | 51 |
| 52 class DartRules extends TypeRules { | 52 class DartRules extends TypeRules { |
| 53 DartRules(TypeProvider provider) : super(provider); | 53 DartRules(TypeProvider provider) : super(provider); |
| 54 | 54 |
| 55 MissingTypeReporter reportMissingType = null; | 55 MissingTypeReporter reportMissingType = null; |
| 56 | 56 |
| 57 bool isSubTypeOf(DartType t1, DartType t2) { | 57 bool isSubTypeOf(DartType t1, DartType t2) { |
| 58 return t1.isSubtypeOf(t2); | 58 return t1.isSubtypeOf(t2); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 71 return null; | 71 return null; |
| 72 } | 72 } |
| 73 | 73 |
| 74 DartType elementType(Element e) { | 74 DartType elementType(Element e) { |
| 75 return (e as dynamic).type; | 75 return (e as dynamic).type; |
| 76 } | 76 } |
| 77 | 77 |
| 78 /// By default, all invocations are dynamic in Dart. | 78 /// By default, all invocations are dynamic in Dart. |
| 79 bool isDynamic(DartType t) => true; | 79 bool isDynamic(DartType t) => true; |
| 80 bool isDynamicTarget(Expression expr) => true; | 80 bool isDynamicTarget(Expression expr) => true; |
| 81 bool isDynamicGet(Expression expr) => true; | |
| 82 bool isDynamicCall(Expression call) => true; | 81 bool isDynamicCall(Expression call) => true; |
| 83 } | 82 } |
| 84 | 83 |
| 85 typedef void MissingTypeReporter(Expression expr); | 84 typedef void MissingTypeReporter(Expression expr); |
| 86 | 85 |
| 87 class RestrictedRules extends TypeRules { | 86 class RestrictedRules extends TypeRules { |
| 88 MissingTypeReporter reportMissingType = null; | 87 MissingTypeReporter reportMissingType = null; |
| 89 final RulesOptions options; | 88 final RulesOptions options; |
| 90 final List<DartType> _nonnullableTypes; | 89 final List<DartType> _nonnullableTypes; |
| 91 DownwardsInference inferrer; | 90 DownwardsInference inferrer; |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 return null; | 522 return null; |
| 524 } | 523 } |
| 525 | 524 |
| 526 DartType elementType(Element e) { | 525 DartType elementType(Element e) { |
| 527 return (e as dynamic).type; | 526 return (e as dynamic).type; |
| 528 } | 527 } |
| 529 | 528 |
| 530 bool isDynamic(DartType t) => options.ignoreTypes || t.isDynamic; | 529 bool isDynamic(DartType t) => options.ignoreTypes || t.isDynamic; |
| 531 | 530 |
| 532 /// Returns `true` if the target expression is dynamic. | 531 /// Returns `true` if the target expression is dynamic. |
| 533 bool isDynamicTarget(Expression expr) => | 532 bool isDynamicTarget(Expression target) => |
|
Jennifer Messerly
2015/04/07 23:00:20
nice!!!
| |
| 534 options.ignoreTypes || getStaticType(expr).isDynamic; | 533 options.ignoreTypes || utils.isDynamicTarget(target); |
| 535 | |
| 536 /// Returns `true` if the expression is a dynamic property access or prefixed | |
| 537 /// identifier. | |
| 538 bool isDynamicGet(Expression expr) { | |
| 539 if (options.ignoreTypes) return true; | |
| 540 var t = getStaticType(expr); | |
| 541 // TODO(jmesserly): we should not allow all property gets on `Function` | |
| 542 return t.isDynamic || t.isDartCoreFunction; | |
| 543 } | |
| 544 | 534 |
| 545 /// Returns `true` if the expression is a dynamic function call or method | 535 /// Returns `true` if the expression is a dynamic function call or method |
| 546 /// invocation. | 536 /// invocation. |
| 547 bool isDynamicCall(Expression call) { | 537 bool isDynamicCall(Expression call) { |
| 548 if (options.ignoreTypes) return true; | 538 if (options.ignoreTypes) return true; |
| 549 var t = getStaticType(call); | 539 var t = getStaticType(call); |
| 550 // TODO(jmesserly): fix handling of types with `call` methods. These are not | 540 // TODO(jmesserly): fix handling of types with `call` methods. These are not |
| 551 // FunctionType, but they also aren't dynamic calls. | 541 // FunctionType, but they also aren't dynamic calls. |
| 552 if (t.isDynamic || t.isDartCoreFunction || t is! FunctionType) { | 542 if (t.isDynamic || t.isDartCoreFunction || t is! FunctionType) { |
| 553 return true; | 543 return true; |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 833 var entries = e.entries; | 823 var entries = e.entries; |
| 834 bool inferEntry(MapLiteralEntry entry) { | 824 bool inferEntry(MapLiteralEntry entry) { |
| 835 return _inferExpression(entry.key, kType, errors) && | 825 return _inferExpression(entry.key, kType, errors) && |
| 836 _inferExpression(entry.value, vType, errors); | 826 _inferExpression(entry.value, vType, errors); |
| 837 } | 827 } |
| 838 var b = entries.every(inferEntry); | 828 var b = entries.every(inferEntry); |
| 839 if (b) annotateMapLiteral(e, targs); | 829 if (b) annotateMapLiteral(e, targs); |
| 840 return b; | 830 return b; |
| 841 } | 831 } |
| 842 } | 832 } |
| OLD | NEW |