Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 super(prefix, ElementKind.PREFIX, enclosing); | 347 super(prefix, ElementKind.PREFIX, enclosing); |
| 348 | 348 |
| 349 lookupLocalMember(SourceString memberName) => imported[memberName]; | 349 lookupLocalMember(SourceString memberName) => imported[memberName]; |
| 350 | 350 |
| 351 Type computeType(Compiler compiler) => compiler.types.dynamicType; | 351 Type computeType(Compiler compiler) => compiler.types.dynamicType; |
| 352 | 352 |
| 353 Token position() => firstPosition; | 353 Token position() => firstPosition; |
| 354 } | 354 } |
| 355 | 355 |
| 356 class TypedefElement extends Element { | 356 class TypedefElement extends Element { |
| 357 final Token token; | |
| 358 Type cachedType; | 357 Type cachedType; |
| 358 Typedef cachedNode; | |
| 359 | 359 |
| 360 TypedefElement(SourceString name, Element enclosing, this.token) | 360 TypedefElement(SourceString name, Element enclosing) |
| 361 : super(name, ElementKind.TYPEDEF, enclosing) { | 361 : super(name, ElementKind.TYPEDEF, enclosing); |
| 362 cachedType = new InterfaceType(this); | 362 |
| 363 Type computeType(Compiler compiler) { | |
|
ahe
2012/05/29 13:21:50
I'm absolutely 100% lukewarm on this approach. Thi
| |
| 364 if (cachedType !== null) return cachedType; | |
| 365 compiler.withCurrentElement(this, () { | |
| 366 FunctionSignature signature = compiler.resolveTypedef(this); | |
| 367 LinkBuilder<Type> parameterTypes = new LinkBuilder<Type>(); | |
| 368 for (Link<Element> link = signature.requiredParameters; | |
| 369 !link.isEmpty(); | |
| 370 link = link.tail) { | |
| 371 parameterTypes.addLast(link.head.computeType(compiler)); | |
| 372 // TODO(karlklose): optional parameters. | |
| 373 } | |
| 374 cachedType = new FunctionType(compiler.types.dynamicType, | |
| 375 parameterTypes.toLink(), | |
| 376 this); | |
| 377 }); | |
| 378 return cachedType; | |
| 363 } | 379 } |
| 364 | |
| 365 position() => findMyName(token); | |
| 366 | |
| 367 Type computeType(Compiler compiler) => cachedType; | |
| 368 } | 380 } |
| 369 | 381 |
| 370 class VariableElement extends Element { | 382 class VariableElement extends Element { |
| 371 final VariableListElement variables; | 383 final VariableListElement variables; |
| 372 Expression cachedNode; // The send or the identifier in the variables list. | 384 Expression cachedNode; // The send or the identifier in the variables list. |
| 373 | 385 |
| 374 Modifiers get modifiers() => variables.modifiers; | 386 Modifiers get modifiers() => variables.modifiers; |
| 375 | 387 |
| 376 VariableElement(SourceString name, | 388 VariableElement(SourceString name, |
| 377 VariableListElement this.variables, | 389 VariableListElement this.variables, |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1046 final Node node; | 1058 final Node node; |
| 1047 Type bound; | 1059 Type bound; |
| 1048 Type type; | 1060 Type type; |
| 1049 TypeVariableElement(name, Element enclosing, this.node, this.type, | 1061 TypeVariableElement(name, Element enclosing, this.node, this.type, |
| 1050 [this.bound]) | 1062 [this.bound]) |
| 1051 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | 1063 : super(name, ElementKind.TYPE_VARIABLE, enclosing); |
| 1052 Type computeType(compiler) => type; | 1064 Type computeType(compiler) => type; |
| 1053 Node parseNode(compiler) => node; | 1065 Node parseNode(compiler) => node; |
| 1054 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; | 1066 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; |
| 1055 } | 1067 } |
| OLD | NEW |