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

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

Issue 10779010: Parameters with function types supported + Added features in mirrors implementation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 for (Element e = this; e !== null; e = e.enclosingElement) { 209 for (Element e = this; e !== null; e = e.enclosingElement) {
210 if (e.isMember() || e.isTopLevel()) { 210 if (e.isMember() || e.isTopLevel()) {
211 return e; 211 return e;
212 } 212 }
213 } 213 }
214 return null; 214 return null;
215 } 215 }
216 216
217 String toString() { 217 String toString() {
218 // TODO(johnniwinther): Test for nullness of name, or make non-nullness an 218 // TODO(johnniwinther): Test for nullness of name, or make non-nullness an
219 // invariant for all element types. 219 // invariant for all element types?
220 var nameText = name !== null ? name.slowToString() : '?';
220 if (enclosingElement !== null && !isTopLevel()) { 221 if (enclosingElement !== null && !isTopLevel()) {
221 String holderName = enclosingElement.name.slowToString(); 222 String holderName = enclosingElement.name !== null
222 return '$kind($holderName#${name.slowToString()})'; 223 ? enclosingElement.name.slowToString()
224 : '${enclosingElement.kind}?';
225 return '$kind($holderName#${nameText})';
223 } else { 226 } else {
224 return '$kind(${name.slowToString()})'; 227 return '$kind(${nameText})';
225 } 228 }
226 } 229 }
227 230
228 bool _isNative = false; 231 bool _isNative = false;
229 void setNative() { _isNative = true; } 232 void setNative() { _isNative = true; }
230 bool isNative() => _isNative; 233 bool isNative() => _isNative;
231 234
232 FunctionElement asFunctionElement() => null; 235 FunctionElement asFunctionElement() => null;
233 } 236 }
234 237
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 496
494 // This element represents a list of variable or field declaration. 497 // This element represents a list of variable or field declaration.
495 // It contains the node, and the type. A [VariableElement] always 498 // It contains the node, and the type. A [VariableElement] always
496 // references its [VariableListElement]. It forwards its 499 // references its [VariableListElement]. It forwards its
497 // [computeType] and [parseNode] methods to this element. 500 // [computeType] and [parseNode] methods to this element.
498 class VariableListElement extends Element { 501 class VariableListElement extends Element {
499 VariableDefinitions cachedNode; 502 VariableDefinitions cachedNode;
500 Type type; 503 Type type;
501 final Modifiers modifiers; 504 final Modifiers modifiers;
502 505
506 /**
507 * Function signature for variable of a function type. The signature is kept
floitsch 2012/07/17 18:53:04 for variables with a function type.
Johnni Winther 2012/07/18 13:32:50 Done.
508 * in order to provide full information about parameter names through the
floitsch 2012/07/17 18:53:04 remove "in order".
Johnni Winther 2012/07/18 13:32:50 Done.
509 * the mirror system.
510 */
511 FunctionSignature functionSignature;
512
503 VariableListElement(ElementKind kind, 513 VariableListElement(ElementKind kind,
504 Modifiers this.modifiers, 514 Modifiers this.modifiers,
505 Element enclosing) 515 Element enclosing)
506 : super(null, kind, enclosing); 516 : super(null, kind, enclosing);
507 517
508 VariableListElement.node(VariableDefinitions node, 518 VariableListElement.node(VariableDefinitions node,
509 ElementKind kind, 519 ElementKind kind,
510 Element enclosing) 520 Element enclosing)
511 : super(null, kind, enclosing), 521 : super(null, kind, enclosing),
512 this.cachedNode = node, 522 this.cachedNode = node,
513 this.modifiers = node.modifiers; 523 this.modifiers = node.modifiers;
514 524
515 VariableDefinitions parseNode(DiagnosticListener listener) { 525 VariableDefinitions parseNode(DiagnosticListener listener) {
516 return cachedNode; 526 return cachedNode;
517 } 527 }
518 528
519 Type computeType(Compiler compiler) { 529 Type computeType(Compiler compiler) {
520 if (type != null) return type; 530 if (type != null) return type;
521 type = compiler.resolveTypeAnnotation(this, parseNode(compiler).type); 531 var node = parseNode(compiler);
floitsch 2012/07/17 18:53:04 s/var/Node.
Johnni Winther 2012/07/18 13:32:50 Done.
532 if (node.type !== null) {
533 type = compiler.resolveTypeAnnotation(this, node.type);
534 } else {
535 // Is node.definitions exactly one FunctionExpression?
536 var link = node.definitions.nodes;
floitsch 2012/07/17 18:53:04 s/var/Link
Johnni Winther 2012/07/18 13:32:50 Done.
537 if (!link.isEmpty() &&
538 link.head is FunctionExpression &&
floitsch 2012/07/17 18:53:04 .asFunctionExpression() != null
Johnni Winther 2012/07/18 13:32:50 Done.
539 link.tail.isEmpty())
540 {
floitsch 2012/07/17 18:53:04 move into previous line.
Johnni Winther 2012/07/18 13:32:50 Done.
541 var functionExpression = link.head;
floitsch 2012/07/17 18:53:04 s/var/FunctionExpression
Johnni Winther 2012/07/18 13:32:50 Done.
542 // We found exactly one FunctionExpression
543 compiler.withCurrentElement(this, () {
544 functionSignature = compiler.resolveFunctionExpression(
floitsch 2012/07/17 18:53:04 nit: I would prefer a new line after the "=" (if i
Johnni Winther 2012/07/18 13:32:50 Done.
545 this, functionExpression);
546 });
547 type = compiler.computeFunctionType(compiler.functionClass,
548 functionSignature);
549 } else {
550 type = compiler.types.dynamicType;
551 }
552 }
553 assert(type != null);
522 return type; 554 return type;
523 } 555 }
524 556
525 Token position() => cachedNode.getBeginToken(); 557 Token position() => cachedNode.getBeginToken();
526 } 558 }
527 559
528 class ForeignElement extends Element { 560 class ForeignElement extends Element {
529 ForeignElement(SourceString name, ContainerElement enclosingElement) 561 ForeignElement(SourceString name, ContainerElement enclosingElement)
530 : super(name, ElementKind.FOREIGN, enclosingElement); 562 : super(name, ElementKind.FOREIGN, enclosingElement);
531 563
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 final Node node; 1183 final Node node;
1152 Type bound; 1184 Type bound;
1153 Type type; 1185 Type type;
1154 TypeVariableElement(name, Element enclosing, this.node, this.type, 1186 TypeVariableElement(name, Element enclosing, this.node, this.type,
1155 [this.bound]) 1187 [this.bound])
1156 : super(name, ElementKind.TYPE_VARIABLE, enclosing); 1188 : super(name, ElementKind.TYPE_VARIABLE, enclosing);
1157 Type computeType(compiler) => type; 1189 Type computeType(compiler) => type;
1158 Node parseNode(compiler) => node; 1190 Node parseNode(compiler) => node;
1159 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; 1191 toString() => "${enclosingElement.toString()}.${name.slowToString()}";
1160 } 1192 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698