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

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

Issue 10270010: Remove getType; use the resolver instead. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 : super(null, kind, enclosing), 422 : super(null, kind, enclosing),
423 this.cachedNode = node, 423 this.cachedNode = node,
424 this.modifiers = node.modifiers; 424 this.modifiers = node.modifiers;
425 425
426 VariableDefinitions parseNode(DiagnosticListener listener) { 426 VariableDefinitions parseNode(DiagnosticListener listener) {
427 return cachedNode; 427 return cachedNode;
428 } 428 }
429 429
430 Type computeType(Compiler compiler) { 430 Type computeType(Compiler compiler) {
431 if (type != null) return type; 431 if (type != null) return type;
432 type = getType(parseNode(compiler).type, compiler, getLibrary()); 432 type = compiler.resolveType(this, parseNode(compiler).type);
433 return type; 433 return type;
434 } 434 }
435 435
436 Token position() => cachedNode.getBeginToken(); 436 Token position() => cachedNode.getBeginToken();
437 } 437 }
438 438
439 class ForeignElement extends Element { 439 class ForeignElement extends Element {
440 ForeignElement(SourceString name, ContainerElement enclosingElement) 440 ForeignElement(SourceString name, ContainerElement enclosingElement)
441 : super(name, ElementKind.FOREIGN, enclosingElement); 441 : super(name, ElementKind.FOREIGN, enclosingElement);
442 442
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 // the compilation unit of the abstract element. 476 // the compilation unit of the abstract element.
477 if (getter !== null && getter.enclosingElement === enclosingElement) { 477 if (getter !== null && getter.enclosingElement === enclosingElement) {
478 return getter.position(); 478 return getter.position();
479 } else if (setter != null) { 479 } else if (setter != null) {
480 // TODO(ahe): checking for null should not be necessary. 480 // TODO(ahe): checking for null should not be necessary.
481 return setter.position(); 481 return setter.position();
482 } 482 }
483 } 483 }
484 } 484 }
485 485
486 /** DEPRECATED. */
487 Type getType(TypeAnnotation typeAnnotation,
488 Compiler compiler,
489 LibraryElement library) {
490 // TODO(karlklose,ngeoffray): This method should be removed and the
491 // information should be computed by the resolver.
492
493 if (typeAnnotation == null || typeAnnotation.typeName == null) {
494 return compiler.types.dynamicType;
495 }
496 Identifier identifier = typeAnnotation.typeName.asIdentifier();
497 if (identifier === null) {
498 compiler.reportWarning(
499 typeAnnotation.typeName,
500 new ResolutionWarning(MessageKind.GENERIC,
501 ['library prefixes not handled']));
502 return compiler.types.dynamicType;
503 }
504 SourceString name = identifier.source;
505 Element element = library.find(name);
506 if (element !== null) {
507 if (element.isTypedef()) {
508 // TODO(ngeoffray): This is a hack to help us get support for the
509 // DOM library.
510 // TODO(ngeoffray): The list of types for the argument is wrong.
511 return new FunctionType(compiler.types.dynamicType,
512 const EmptyLink<Type>(),
513 element);
514 }
515 if (element.isClass()) {
516 // TODO(karlklose): substitute type parameters.
517 return element.computeType(compiler);
518 }
519 }
520 Type type = compiler.types.lookup(name);
521 if (type === null) {
522 type = compiler.types.dynamicType;
523 }
524 return type;
525 }
526
527 class FunctionParameters { 486 class FunctionParameters {
528 Link<Element> requiredParameters; 487 Link<Element> requiredParameters;
529 Link<Element> optionalParameters; 488 Link<Element> optionalParameters;
530 int requiredParameterCount; 489 int requiredParameterCount;
531 int optionalParameterCount; 490 int optionalParameterCount;
532 FunctionParameters(this.requiredParameters, 491 FunctionParameters(this.requiredParameters,
533 this.optionalParameters, 492 this.optionalParameters,
534 this.requiredParameterCount, 493 this.requiredParameterCount,
535 this.optionalParameterCount); 494 this.optionalParameterCount);
536 495
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 return computeParameters(compiler).parameterCount; 579 return computeParameters(compiler).parameterCount;
621 } 580 }
622 581
623 FunctionType computeType(Compiler compiler) { 582 FunctionType computeType(Compiler compiler) {
624 if (type != null) return type; 583 if (type != null) return type;
625 return compiler.withCurrentElement(this, () { 584 return compiler.withCurrentElement(this, () {
626 FunctionParameters parameters = computeParameters(compiler); 585 FunctionParameters parameters = computeParameters(compiler);
627 Types types = compiler.types; 586 Types types = compiler.types;
628 FunctionExpression node = 587 FunctionExpression node =
629 compiler.parser.measure(() => parseNode(compiler)); 588 compiler.parser.measure(() => parseNode(compiler));
630 Type returnType = getType(node.returnType, compiler, getLibrary()); 589 Type returnType = compiler.resolveType(this, node.returnType);
631 if (returnType === null) returnType = types.dynamicType;
632 590
633 LinkBuilder<Type> parameterTypes = new LinkBuilder<Type>(); 591 LinkBuilder<Type> parameterTypes = new LinkBuilder<Type>();
634 for (Link<Element> link = parameters.requiredParameters; 592 for (Link<Element> link = parameters.requiredParameters;
635 !link.isEmpty(); 593 !link.isEmpty();
636 link = link.tail) { 594 link = link.tail) {
637 parameterTypes.addLast(link.head.computeType(compiler)); 595 parameterTypes.addLast(link.head.computeType(compiler));
638 } 596 }
639 type = new FunctionType(returnType, parameterTypes.toLink(), this); 597 type = new FunctionType(returnType, parameterTypes.toLink(), this);
640 return type; 598 return type;
641 }); 599 });
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 final Node node; 1004 final Node node;
1047 Type bound; 1005 Type bound;
1048 Type type; 1006 Type type;
1049 TypeVariableElement(name, Element enclosing, this.node, this.type, 1007 TypeVariableElement(name, Element enclosing, this.node, this.type,
1050 [this.bound]) 1008 [this.bound])
1051 : super(name, ElementKind.TYPE_VARIABLE, enclosing); 1009 : super(name, ElementKind.TYPE_VARIABLE, enclosing);
1052 Type computeType(compiler) => type; 1010 Type computeType(compiler) => type;
1053 Node parseNode(compiler) => node; 1011 Node parseNode(compiler) => node;
1054 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; 1012 toString() => "${enclosingElement.toString()}.${name.slowToString()}";
1055 } 1013 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698