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

Side by Side Diff: lib/compiler/implementation/typechecker.dart

Issue 11229002: Handle type variable in static member. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Error => warning. Created 8 years, 2 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 class TypeCheckerTask extends CompilerTask { 5 class TypeCheckerTask extends CompilerTask {
6 TypeCheckerTask(Compiler compiler) : super(compiler); 6 TypeCheckerTask(Compiler compiler) : super(compiler);
7 String get name => "Type checker"; 7 String get name => "Type checker";
8 8
9 static const bool LOG_FAILURES = false; 9 static const bool LOG_FAILURES = false;
10 10
11 void check(Node tree, TreeElements elements) { 11 void check(Node tree, TreeElements elements) {
12 measure(() { 12 measure(() {
13 Visitor visitor = 13 Visitor visitor =
14 new TypeCheckerVisitor(compiler, elements, compiler.types); 14 new TypeCheckerVisitor(compiler, elements, compiler.types);
15 try { 15 try {
16 tree.accept(visitor); 16 tree.accept(visitor);
17 } on CancelTypeCheckException catch (e) { 17 } on CancelTypeCheckException catch (e) {
18 if (LOG_FAILURES) { 18 if (LOG_FAILURES) {
19 // Do not warn about unimplemented features; log message instead. 19 // Do not warn about unimplemented features; log message instead.
20 compiler.log("'${e.node}': ${e.reason}"); 20 compiler.log("'${e.node}': ${e.reason}");
21 } 21 }
22 } 22 }
23 }); 23 });
24 } 24 }
25 } 25 }
26 26
27 class TypeKind {
28 final String id;
29
30 const TypeKind(String this.id);
31
32 static const TypeKind FUNCTION = const TypeKind('function');
33 static const TypeKind INTERFACE = const TypeKind('interface');
34 static const TypeKind STATEMENT = const TypeKind('statement');
35 static const TypeKind TYPEDEF = const TypeKind('typedef');
36 static const TypeKind TYPE_VARIABLE = const TypeKind('type variable');
37 static const TypeKind VOID = const TypeKind('void');
ahe 2012/10/26 08:18:40 How about adding a "toString" mehod?
Johnni Winther 2012/10/29 09:20:14 Done.
38 }
39
27 abstract class DartType { 40 abstract class DartType {
28 abstract SourceString get name; 41 abstract SourceString get name;
29 42
43 abstract TypeKind get kind;
44
30 /** 45 /**
31 * Returns the [Element] which declared this type. 46 * Returns the [Element] which declared this type.
32 * 47 *
33 * This can be [ClassElement] for classes, [TypedefElement] for typedefs, 48 * This can be [ClassElement] for classes, [TypedefElement] for typedefs,
34 * [TypeVariableElement] for type variables and [FunctionElement] for 49 * [TypeVariableElement] for type variables and [FunctionElement] for
35 * function types. 50 * function types.
36 * 51 *
37 * Invariant: [element] must be a declaration element. 52 * Invariant: [element] must be a declaration element.
38 */ 53 */
39 abstract Element get element; 54 abstract Element get element;
(...skipping 11 matching lines...) Expand all
51 abstract DartType unalias(Compiler compiler); 66 abstract DartType unalias(Compiler compiler);
52 67
53 abstract bool operator ==(other); 68 abstract bool operator ==(other);
54 } 69 }
55 70
56 class TypeVariableType implements DartType { 71 class TypeVariableType implements DartType {
57 final TypeVariableElement element; 72 final TypeVariableElement element;
58 73
59 TypeVariableType(this.element); 74 TypeVariableType(this.element);
60 75
76 TypeKind get kind => TypeKind.TYPE_VARIABLE;
77
61 SourceString get name => element.name; 78 SourceString get name => element.name;
62 79
63 DartType unalias(Compiler compiler) => this; 80 DartType unalias(Compiler compiler) => this;
64 81
65 int get hashCode => 17 * element.hashCode; 82 int get hashCode => 17 * element.hashCode;
66 83
67 bool operator ==(other) { 84 bool operator ==(other) {
68 if (other is !TypeVariableType) return false; 85 if (other is !TypeVariableType) return false;
69 return identical(other.element, element); 86 return identical(other.element, element);
70 } 87 }
71 88
72 String toString() => name.slowToString(); 89 String toString() => name.slowToString();
73 } 90 }
74 91
75 /** 92 /**
76 * A statement type tracks whether a statement returns or may return. 93 * A statement type tracks whether a statement returns or may return.
77 */ 94 */
78 class StatementType implements DartType { 95 class StatementType implements DartType {
79 final String stringName; 96 final String stringName;
97
80 Element get element => null; 98 Element get element => null;
81 99
100 TypeKind get kind => TypeKind.STATEMENT;
101
82 SourceString get name => new SourceString(stringName); 102 SourceString get name => new SourceString(stringName);
83 103
84 const StatementType(this.stringName); 104 const StatementType(this.stringName);
85 105
86 static const RETURNING = const StatementType('<returning>'); 106 static const RETURNING = const StatementType('<returning>');
87 static const NOT_RETURNING = const StatementType('<not returning>'); 107 static const NOT_RETURNING = const StatementType('<not returning>');
88 static const MAYBE_RETURNING = const StatementType('<maybe returning>'); 108 static const MAYBE_RETURNING = const StatementType('<maybe returning>');
89 109
90 /** Combine the information about two control-flow edges that are joined. */ 110 /** Combine the information about two control-flow edges that are joined. */
91 StatementType join(StatementType other) { 111 StatementType join(StatementType other) {
92 return (identical(this, other)) ? this : MAYBE_RETURNING; 112 return (identical(this, other)) ? this : MAYBE_RETURNING;
93 } 113 }
94 114
95 DartType unalias(Compiler compiler) => this; 115 DartType unalias(Compiler compiler) => this;
96 116
97 int get hashCode => 17 * stringName.hashCode; 117 int get hashCode => 17 * stringName.hashCode;
98 118
99 bool operator ==(other) { 119 bool operator ==(other) {
100 if (other is !StatementType) return false; 120 if (other is !StatementType) return false;
101 return other.stringName == stringName; 121 return other.stringName == stringName;
102 } 122 }
103 123
104 String toString() => stringName; 124 String toString() => stringName;
105 } 125 }
106 126
107 class VoidType implements DartType { 127 class VoidType implements DartType {
108 const VoidType(this.element); 128 const VoidType(this.element);
129
130 TypeKind get kind => TypeKind.VOID;
131
109 SourceString get name => element.name; 132 SourceString get name => element.name;
133
110 final VoidElement element; 134 final VoidElement element;
111 135
112 DartType unalias(Compiler compiler) => this; 136 DartType unalias(Compiler compiler) => this;
113 137
114 int get hashCode => 1729; 138 int get hashCode => 1729;
115 139
116 bool operator ==(other) => other is VoidType; 140 bool operator ==(other) => other is VoidType;
117 141
118 String toString() => name.slowToString(); 142 String toString() => name.slowToString();
119 } 143 }
120 144
121 class InterfaceType implements DartType { 145 class InterfaceType implements DartType {
122 final Element element; 146 final Element element;
123 final Link<DartType> arguments; 147 final Link<DartType> arguments;
124 148
125 const InterfaceType(this.element, 149 const InterfaceType(this.element,
126 [this.arguments = const Link<DartType>()]); 150 [this.arguments = const Link<DartType>()]);
127 151
152 TypeKind get kind => TypeKind.INTERFACE;
153
128 SourceString get name => element.name; 154 SourceString get name => element.name;
129 155
130 DartType unalias(Compiler compiler) => this; 156 DartType unalias(Compiler compiler) => this;
131 157
132 String toString() { 158 String toString() {
133 StringBuffer sb = new StringBuffer(); 159 StringBuffer sb = new StringBuffer();
134 sb.add(name.slowToString()); 160 sb.add(name.slowToString());
135 if (!arguments.isEmpty()) { 161 if (!arguments.isEmpty()) {
136 sb.add('<'); 162 sb.add('<');
137 arguments.printOn(sb, ', '); 163 arguments.printOn(sb, ', ');
(...skipping 23 matching lines...) Expand all
161 class FunctionType implements DartType { 187 class FunctionType implements DartType {
162 final Element element; 188 final Element element;
163 DartType returnType; 189 DartType returnType;
164 Link<DartType> parameterTypes; 190 Link<DartType> parameterTypes;
165 191
166 FunctionType(DartType this.returnType, Link<DartType> this.parameterTypes, 192 FunctionType(DartType this.returnType, Link<DartType> this.parameterTypes,
167 Element this.element) { 193 Element this.element) {
168 assert(element == null || invariant(element, element.isDeclaration)); 194 assert(element == null || invariant(element, element.isDeclaration));
169 } 195 }
170 196
197 TypeKind get kind => TypeKind.FUNCTION;
198
171 DartType unalias(Compiler compiler) => this; 199 DartType unalias(Compiler compiler) => this;
172 200
173 String toString() { 201 String toString() {
174 StringBuffer sb = new StringBuffer(); 202 StringBuffer sb = new StringBuffer();
175 bool first = true; 203 bool first = true;
176 sb.add('('); 204 sb.add('(');
177 parameterTypes.printOn(sb, ', '); 205 parameterTypes.printOn(sb, ', ');
178 sb.add(') -> ${returnType}'); 206 sb.add(') -> ${returnType}');
179 return sb.toString(); 207 return sb.toString();
180 } 208 }
(...skipping 30 matching lines...) Expand all
211 } 239 }
212 } 240 }
213 241
214 class TypedefType implements DartType { 242 class TypedefType implements DartType {
215 final TypedefElement element; 243 final TypedefElement element;
216 final Link<DartType> typeArguments; 244 final Link<DartType> typeArguments;
217 245
218 const TypedefType(this.element, 246 const TypedefType(this.element,
219 [this.typeArguments = const Link<DartType>()]); 247 [this.typeArguments = const Link<DartType>()]);
220 248
249 TypeKind get kind => TypeKind.TYPEDEF;
250
221 SourceString get name => element.name; 251 SourceString get name => element.name;
222 252
223 DartType unalias(Compiler compiler) { 253 DartType unalias(Compiler compiler) {
224 // TODO(ahe): This should be [ensureResolved]. 254 // TODO(ahe): This should be [ensureResolved].
225 compiler.resolveTypedef(element); 255 compiler.resolveTypedef(element);
226 return element.alias.unalias(compiler); 256 return element.alias.unalias(compiler);
227 } 257 }
228 258
229 String toString() { 259 String toString() {
230 StringBuffer sb = new StringBuffer(); 260 StringBuffer sb = new StringBuffer();
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 } 1017 }
988 1018
989 DartType visitStringNode(StringNode node) { 1019 DartType visitStringNode(StringNode node) {
990 compiler.unimplemented('visitNode', node: node); 1020 compiler.unimplemented('visitNode', node: node);
991 } 1021 }
992 1022
993 DartType visitLibraryDependency(LibraryDependency node) { 1023 DartType visitLibraryDependency(LibraryDependency node) {
994 compiler.unimplemented('visitNode', node: node); 1024 compiler.unimplemented('visitNode', node: node);
995 } 1025 }
996 } 1026 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/resolution/members.dart ('k') | lib/compiler/implementation/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698