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

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

Issue 10628007: Resolve typedefs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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 #library('elements'); 5 #library('elements');
6 6
7 #import('../tree/tree.dart'); 7 #import('../tree/tree.dart');
8 #import('../scanner/scannerlib.dart'); 8 #import('../scanner/scannerlib.dart');
9 #import('../leg.dart'); // TODO(karlklose): we only need type. 9 #import('../leg.dart'); // TODO(karlklose): we only need type.
10 #import('../util/util.dart'); 10 #import('../util/util.dart');
(...skipping 20 matching lines...) Expand all
31 31
32 static final int ALIAS = 32; 32 static final int ALIAS = 32;
33 33
34 static final int SUPER = 64; 34 static final int SUPER = 64;
35 35
36 /** Type variable */ 36 /** Type variable */
37 static final int TYPE_VARIABLE = 128; 37 static final int TYPE_VARIABLE = 128;
38 38
39 static final int IMPLIES_TYPE = CLASS | ALIAS | TYPE_VARIABLE; 39 static final int IMPLIES_TYPE = CLASS | ALIAS | TYPE_VARIABLE;
40 40
41 static final int IS_EXTENDABLE = CLASS | ALIAS; 41 static final int IS_EXTENDABLE = CLASS;
ahe 2012/06/22 08:59:11 Could you add a TODO that this will be legal when
42 } 42 }
43 43
44 class ElementKind { 44 class ElementKind {
45 final String id; 45 final String id;
46 final int category; 46 final int category;
47 47
48 const ElementKind(String this.id, this.category); 48 const ElementKind(String this.id, this.category);
49 49
50 static final ElementKind VARIABLE = 50 static final ElementKind VARIABLE =
51 const ElementKind('variable', ElementCategory.VARIABLE); 51 const ElementKind('variable', ElementCategory.VARIABLE);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return element; 179 return element;
180 } 180 }
181 181
182 ClassElement getEnclosingClass() { 182 ClassElement getEnclosingClass() {
183 for (Element e = this; e !== null; e = e.enclosingElement) { 183 for (Element e = this; e !== null; e = e.enclosingElement) {
184 if (e.kind === ElementKind.CLASS) return e; 184 if (e.kind === ElementKind.CLASS) return e;
185 } 185 }
186 return null; 186 return null;
187 } 187 }
188 188
189 Element getEnclosingClassOrTypedef() {
190 for (Element e = this; e !== null; e = e.enclosingElement) {
191 if (e.kind === ElementKind.CLASS
192 || e.kind === ElementKind.TYPEDEF) return e;
193 }
194 return null;
195 }
196
189 Element getEnclosingMember() { 197 Element getEnclosingMember() {
190 for (Element e = this; e !== null; e = e.enclosingElement) { 198 for (Element e = this; e !== null; e = e.enclosingElement) {
191 if (e.isMember()) return e; 199 if (e.isMember()) return e;
192 } 200 }
193 return null; 201 return null;
194 } 202 }
195 203
196 Element getOutermostEnclosingMemberOrTopLevel() { 204 Element getOutermostEnclosingMemberOrTopLevel() {
197 for (Element e = this; e !== null; e = e.enclosingElement) { 205 for (Element e = this; e !== null; e = e.enclosingElement) {
198 if (e.isMember() || e.isTopLevel()) { 206 if (e.isMember() || e.isTopLevel()) {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 super(prefix, ElementKind.PREFIX, enclosing); 376 super(prefix, ElementKind.PREFIX, enclosing);
369 377
370 lookupLocalMember(SourceString memberName) => imported[memberName]; 378 lookupLocalMember(SourceString memberName) => imported[memberName];
371 379
372 Type computeType(Compiler compiler) => compiler.types.dynamicType; 380 Type computeType(Compiler compiler) => compiler.types.dynamicType;
373 381
374 Token position() => firstPosition; 382 Token position() => firstPosition;
375 } 383 }
376 384
377 class TypedefElement extends Element { 385 class TypedefElement extends Element {
386 TypedefElement(SourceString name, Element enclosing)
387 : typeParameters = new LinkedHashMap<SourceString, TypeVariableElement>(),
388 super(name, ElementKind.TYPEDEF, enclosing);
389
390 LinkedHashMap<SourceString, TypeVariableElement> typeParameters;
ahe 2012/06/22 08:59:11 I think it is overkill to have a map here. A list
391
378 Type cachedType; 392 Type cachedType;
379 Typedef cachedNode; 393 Typedef cachedNode;
380 394
381 TypedefElement(SourceString name, Element enclosing)
382 : super(name, ElementKind.TYPEDEF, enclosing);
383
384 Type computeType(Compiler compiler) { 395 Type computeType(Compiler compiler) {
385 if (cachedType !== null) return cachedType; 396 if (cachedType !== null) return cachedType;
386 cachedType = compiler.computeFunctionType( 397 compiler.resolveTypedef(this);
387 this, compiler.resolveTypedef(this));
388 return cachedType; 398 return cachedType;
389 } 399 }
390 } 400 }
391 401
392 class VariableElement extends Element { 402 class VariableElement extends Element {
393 final VariableListElement variables; 403 final VariableListElement variables;
394 Expression cachedNode; // The send or the identifier in the variables list. 404 Expression cachedNode; // The send or the identifier in the variables list.
395 405
396 Modifiers get modifiers() => variables.modifiers; 406 Modifiers get modifiers() => variables.modifiers;
397 407
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 final Node node; 1072 final Node node;
1063 Type bound; 1073 Type bound;
1064 Type type; 1074 Type type;
1065 TypeVariableElement(name, Element enclosing, this.node, this.type, 1075 TypeVariableElement(name, Element enclosing, this.node, this.type,
1066 [this.bound]) 1076 [this.bound])
1067 : super(name, ElementKind.TYPE_VARIABLE, enclosing); 1077 : super(name, ElementKind.TYPE_VARIABLE, enclosing);
1068 Type computeType(compiler) => type; 1078 Type computeType(compiler) => type;
1069 Node parseNode(compiler) => node; 1079 Node parseNode(compiler) => node;
1070 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; 1080 toString() => "${enclosingElement.toString()}.${name.slowToString()}";
1071 } 1081 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/resolver.dart » ('j') | lib/compiler/implementation/resolver.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698