Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: pkg/compiler/lib/src/typechecker.dart

Issue 938173004: Small fixes in preparation for SemanticVisitor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of dart2js; 5 part of dart2js;
6 6
7 class TypeCheckerTask extends CompilerTask { 7 class TypeCheckerTask extends CompilerTask {
8 TypeCheckerTask(Compiler compiler) : super(compiler); 8 TypeCheckerTask(Compiler compiler) : super(compiler);
9 String get name => "Type checker"; 9 String get name => "Type checker";
10 10
(...skipping 29 matching lines...) Expand all
40 String toString() => name; 40 String toString() => name;
41 } 41 }
42 42
43 /** 43 /**
44 * [ElementAccess] represents the access of [element], either as a property 44 * [ElementAccess] represents the access of [element], either as a property
45 * access or invocation. 45 * access or invocation.
46 */ 46 */
47 abstract class ElementAccess { 47 abstract class ElementAccess {
48 Element get element; 48 Element get element;
49 49
50 String get name => element.name;
51
50 DartType computeType(Compiler compiler); 52 DartType computeType(Compiler compiler);
51 53
52 /// Returns [: true :] if the element can be access as an invocation. 54 /// Returns [: true :] if the element can be access as an invocation.
53 bool isCallable(Compiler compiler) { 55 bool isCallable(Compiler compiler) {
54 if (element != null && element.isAbstractField) { 56 if (element != null && element.isAbstractField) {
55 AbstractFieldElement abstractFieldElement = element; 57 AbstractFieldElement abstractFieldElement = element;
56 if (abstractFieldElement.getter == null) { 58 if (abstractFieldElement.getter == null) {
57 // Setters cannot be invoked as function invocations. 59 // Setters cannot be invoked as function invocations.
58 return false; 60 return false;
59 } 61 }
(...skipping 15 matching lines...) Expand all
75 77
76 String toString() => 'MemberAccess($member)'; 78 String toString() => 'MemberAccess($member)';
77 } 79 }
78 80
79 /// An access of an unresolved element. 81 /// An access of an unresolved element.
80 class DynamicAccess implements ElementAccess { 82 class DynamicAccess implements ElementAccess {
81 const DynamicAccess(); 83 const DynamicAccess();
82 84
83 Element get element => null; 85 Element get element => null;
84 86
87 String get name => 'dynamic';
88
85 DartType computeType(Compiler compiler) => const DynamicType(); 89 DartType computeType(Compiler compiler) => const DynamicType();
86 90
87 bool isCallable(Compiler compiler) => true; 91 bool isCallable(Compiler compiler) => true;
88 92
89 String toString() => 'DynamicAccess'; 93 String toString() => 'DynamicAccess';
90 } 94 }
91 95
92 /// An access of the `assert` method. 96 /// An access of the `assert` method.
93 class AssertAccess implements ElementAccess { 97 class AssertAccess implements ElementAccess {
94 const AssertAccess(); 98 const AssertAccess();
95 99
96 Element get element => null; 100 Element get element => null;
97 101
102 String get name => 'assert';
103
98 DartType computeType(Compiler compiler) { 104 DartType computeType(Compiler compiler) {
99 return new FunctionType.synthesized( 105 return new FunctionType.synthesized(
100 const VoidType(), 106 const VoidType(),
101 <DartType>[const DynamicType()]); 107 <DartType>[const DynamicType()]);
102 } 108 }
103 109
104 bool isCallable(Compiler compiler) => true; 110 bool isCallable(Compiler compiler) => true;
105 111
106 String toString() => 'AssertAccess'; 112 String toString() => 'AssertAccess';
107 } 113 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 */ 180 */
175 class TypeLiteralAccess extends ElementAccess { 181 class TypeLiteralAccess extends ElementAccess {
176 final DartType type; 182 final DartType type;
177 183
178 TypeLiteralAccess(this.type) { 184 TypeLiteralAccess(this.type) {
179 assert(type != null); 185 assert(type != null);
180 } 186 }
181 187
182 Element get element => type.element; 188 Element get element => type.element;
183 189
190 String get name => type.name;
191
184 DartType computeType(Compiler compiler) => compiler.typeClass.rawType; 192 DartType computeType(Compiler compiler) => compiler.typeClass.rawType;
185 193
186 String toString() => 'TypeLiteralAccess($type)'; 194 String toString() => 'TypeLiteralAccess($type)';
187 } 195 }
188 196
189 197
190 /// An access to the 'call' method of a function type. 198 /// An access to the 'call' method of a function type.
191 class FunctionCallAccess implements ElementAccess { 199 class FunctionCallAccess implements ElementAccess {
192 final Element element; 200 final Element element;
193 final DartType type; 201 final DartType type;
194 202
195 const FunctionCallAccess(this.element, this.type); 203 const FunctionCallAccess(this.element, this.type);
196 204
205 String get name => 'call';
206
197 DartType computeType(Compiler compiler) => type; 207 DartType computeType(Compiler compiler) => type;
198 208
199 bool isCallable(Compiler compiler) => true; 209 bool isCallable(Compiler compiler) => true;
200 210
201 String toString() => 'FunctionAccess($element, $type)'; 211 String toString() => 'FunctionAccess($element, $type)';
202 } 212 }
203 213
204 214
205 /// An is-expression that potentially promotes a variable. 215 /// An is-expression that potentially promotes a variable.
206 class TypePromotion { 216 class TypePromotion {
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 // 934 //
925 // If provided [argumentTypes] is filled with the argument types during 935 // If provided [argumentTypes] is filled with the argument types during
926 // analysis. 936 // analysis.
927 DartType analyzeInvocation(Send node, ElementAccess elementAccess, 937 DartType analyzeInvocation(Send node, ElementAccess elementAccess,
928 [LinkBuilder<DartType> argumentTypes]) { 938 [LinkBuilder<DartType> argumentTypes]) {
929 DartType type = elementAccess.computeType(compiler); 939 DartType type = elementAccess.computeType(compiler);
930 if (elementAccess.isCallable(compiler)) { 940 if (elementAccess.isCallable(compiler)) {
931 analyzeArguments(node, elementAccess.element, type, argumentTypes); 941 analyzeArguments(node, elementAccess.element, type, argumentTypes);
932 } else { 942 } else {
933 reportTypeWarning(node, MessageKind.NOT_CALLABLE, 943 reportTypeWarning(node, MessageKind.NOT_CALLABLE,
934 {'elementName': elementAccess.element.name}); 944 {'elementName': elementAccess.name});
935 analyzeArguments(node, elementAccess.element, const DynamicType(), 945 analyzeArguments(node, elementAccess.element, const DynamicType(),
936 argumentTypes); 946 argumentTypes);
937 } 947 }
938 type = type.unalias(compiler); 948 type = type.unalias(compiler);
939 if (identical(type.kind, TypeKind.FUNCTION)) { 949 if (identical(type.kind, TypeKind.FUNCTION)) {
940 FunctionType funType = type; 950 FunctionType funType = type;
941 return funType.returnType; 951 return funType.returnType;
942 } else { 952 } else {
943 return const DynamicType(); 953 return const DynamicType();
944 } 954 }
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 1854
1845 visitTypedef(Typedef node) { 1855 visitTypedef(Typedef node) {
1846 // Do not typecheck [Typedef] nodes. 1856 // Do not typecheck [Typedef] nodes.
1847 } 1857 }
1848 1858
1849 visitNode(Node node) { 1859 visitNode(Node node) {
1850 compiler.internalError(node, 1860 compiler.internalError(node,
1851 'Unexpected node ${node.getObjectDescription()} in the type checker.'); 1861 'Unexpected node ${node.getObjectDescription()} in the type checker.');
1852 } 1862 }
1853 } 1863 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/elements/modelx.dart ('k') | tests/compiler/dart2js/analyze_unused_dart2js_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698