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 engine.resolver; | 5 library engine.resolver; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import '../task/strong/info.dart' show InferredType, StaticInfo; | 9 import '../task/strong/info.dart' show InferredType, StaticInfo; |
10 import '../task/strong/rules.dart' show TypeRules; | 10 import '../task/strong/rules.dart' show TypeRules; |
(...skipping 5754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5765 // hash table help in an instance of this class. | 5765 // hash table help in an instance of this class. |
5766 static const String _typeProperty = | 5766 static const String _typeProperty = |
5767 'analyzer.src.generated.InferenceContext.contextType'; | 5767 'analyzer.src.generated.InferenceContext.contextType'; |
5768 | 5768 |
5769 /** | 5769 /** |
5770 * The error listener on which to record inference information. | 5770 * The error listener on which to record inference information. |
5771 */ | 5771 */ |
5772 final AnalysisErrorListener _errorListener; | 5772 final AnalysisErrorListener _errorListener; |
5773 | 5773 |
5774 /** | 5774 /** |
| 5775 * If true, emit hints when types are inferred |
| 5776 */ |
| 5777 final bool _inferenceHints; |
| 5778 |
| 5779 /** |
5775 * Type provider, needed for type matching. | 5780 * Type provider, needed for type matching. |
5776 */ | 5781 */ |
5777 final TypeProvider _typeProvider; | 5782 final TypeProvider _typeProvider; |
5778 | 5783 |
5779 /** | 5784 /** |
5780 * The type system in use. | 5785 * The type system in use. |
5781 */ | 5786 */ |
5782 final TypeSystem _typeSystem; | 5787 final TypeSystem _typeSystem; |
5783 | 5788 |
5784 /** | 5789 /** |
5785 * The DDC type rules, used to create the inference info nodes. | 5790 * The DDC type rules, used to create the inference info nodes. |
5786 */ | 5791 */ |
5787 final TypeRules _rules; | 5792 final TypeRules _rules; |
5788 | 5793 |
5789 /** | 5794 /** |
5790 * A stack of return types for all of the enclosing | 5795 * A stack of return types for all of the enclosing |
5791 * functions and methods. | 5796 * functions and methods. |
5792 */ | 5797 */ |
5793 List<DartType> _returnStack = <DartType>[]; | 5798 List<DartType> _returnStack = <DartType>[]; |
5794 | 5799 |
5795 InferenceContext._( | 5800 InferenceContext._(this._errorListener, TypeProvider typeProvider, |
5796 this._errorListener, TypeProvider typeProvider, this._typeSystem) | 5801 this._typeSystem, this._inferenceHints) |
5797 : _typeProvider = typeProvider, | 5802 : _typeProvider = typeProvider, |
5798 _rules = new TypeRules(typeProvider); | 5803 _rules = new TypeRules(typeProvider); |
5799 | 5804 |
5800 /** | 5805 /** |
5801 * Get the return type of the current enclosing function, if any. | 5806 * Get the return type of the current enclosing function, if any. |
5802 */ | 5807 */ |
5803 DartType get returnContext => | 5808 DartType get returnContext => |
5804 (_returnStack.isNotEmpty) ? _returnStack.last : null; | 5809 (_returnStack.isNotEmpty) ? _returnStack.last : null; |
5805 | 5810 |
5806 /** | 5811 /** |
(...skipping 23 matching lines...) Expand all Loading... |
5830 void pushReturnContext(DartType returnType) { | 5835 void pushReturnContext(DartType returnType) { |
5831 _returnStack.add(returnType); | 5836 _returnStack.add(returnType); |
5832 } | 5837 } |
5833 | 5838 |
5834 /** | 5839 /** |
5835 * Place an info node into the error stream indicating that a | 5840 * Place an info node into the error stream indicating that a |
5836 * [type] has been inferred as the type of [node]. | 5841 * [type] has been inferred as the type of [node]. |
5837 */ | 5842 */ |
5838 void recordInference(Expression node, DartType type) { | 5843 void recordInference(Expression node, DartType type) { |
5839 StaticInfo info = InferredType.create(_rules, node, type); | 5844 StaticInfo info = InferredType.create(_rules, node, type); |
5840 if (info == null) { | 5845 if (!_inferenceHints || info == null) { |
5841 return; | 5846 return; |
5842 } | 5847 } |
5843 AnalysisError error = info.toAnalysisError(); | 5848 AnalysisError error = info.toAnalysisError(); |
5844 _errorListener.onError(error); | 5849 _errorListener.onError(error); |
5845 } | 5850 } |
5846 | 5851 |
5847 List<DartType> _matchTypes(InterfaceType t1, InterfaceType t2) { | 5852 List<DartType> _matchTypes(InterfaceType t1, InterfaceType t2) { |
5848 if (t1 == t2) { | 5853 if (t1 == t2) { |
5849 return t2.typeArguments; | 5854 return t2.typeArguments; |
5850 } | 5855 } |
(...skipping 4837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10688 StaticTypeAnalyzerFactory typeAnalyzerFactory}) | 10693 StaticTypeAnalyzerFactory typeAnalyzerFactory}) |
10689 : super(definingLibrary, source, typeProvider, errorListener, | 10694 : super(definingLibrary, source, typeProvider, errorListener, |
10690 nameScope: nameScope) { | 10695 nameScope: nameScope) { |
10691 if (inheritanceManager == null) { | 10696 if (inheritanceManager == null) { |
10692 this._inheritanceManager = new InheritanceManager(definingLibrary); | 10697 this._inheritanceManager = new InheritanceManager(definingLibrary); |
10693 } else { | 10698 } else { |
10694 this._inheritanceManager = inheritanceManager; | 10699 this._inheritanceManager = inheritanceManager; |
10695 } | 10700 } |
10696 this.elementResolver = new ElementResolver(this); | 10701 this.elementResolver = new ElementResolver(this); |
10697 this.typeSystem = definingLibrary.context.typeSystem; | 10702 this.typeSystem = definingLibrary.context.typeSystem; |
10698 this.inferenceContext = | 10703 bool strongModeHints = false; |
10699 new InferenceContext._(errorListener, typeProvider, typeSystem); | 10704 AnalysisOptions options = definingLibrary.context.analysisOptions; |
| 10705 if (options is AnalysisOptionsImpl) { |
| 10706 strongModeHints = options.strongModeHints; |
| 10707 } |
| 10708 this.inferenceContext = new InferenceContext._( |
| 10709 errorListener, typeProvider, typeSystem, strongModeHints); |
10700 if (typeAnalyzerFactory == null) { | 10710 if (typeAnalyzerFactory == null) { |
10701 this.typeAnalyzer = new StaticTypeAnalyzer(this); | 10711 this.typeAnalyzer = new StaticTypeAnalyzer(this); |
10702 } else { | 10712 } else { |
10703 this.typeAnalyzer = typeAnalyzerFactory(this); | 10713 this.typeAnalyzer = typeAnalyzerFactory(this); |
10704 } | 10714 } |
10705 } | 10715 } |
10706 | 10716 |
10707 /** | 10717 /** |
10708 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 10718 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
10709 * | 10719 * |
(...skipping 5349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16059 nonFields.add(node); | 16069 nonFields.add(node); |
16060 return null; | 16070 return null; |
16061 } | 16071 } |
16062 | 16072 |
16063 @override | 16073 @override |
16064 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 16074 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
16065 | 16075 |
16066 @override | 16076 @override |
16067 Object visitWithClause(WithClause node) => null; | 16077 Object visitWithClause(WithClause node) => null; |
16068 } | 16078 } |
OLD | NEW |