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

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: Address comments. 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
« no previous file with comments | « lib/compiler/implementation/compiler.dart ('k') | lib/compiler/implementation/resolver.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 : super(null, kind, enclosing), 439 : super(null, kind, enclosing),
440 this.cachedNode = node, 440 this.cachedNode = node,
441 this.modifiers = node.modifiers; 441 this.modifiers = node.modifiers;
442 442
443 VariableDefinitions parseNode(DiagnosticListener listener) { 443 VariableDefinitions parseNode(DiagnosticListener listener) {
444 return cachedNode; 444 return cachedNode;
445 } 445 }
446 446
447 Type computeType(Compiler compiler) { 447 Type computeType(Compiler compiler) {
448 if (type != null) return type; 448 if (type != null) return type;
449 type = getType(parseNode(compiler).type, compiler, getLibrary()); 449 type = compiler.resolveTypeAnnotation(this, parseNode(compiler).type);
450 return type; 450 return type;
451 } 451 }
452 452
453 Token position() => cachedNode.getBeginToken(); 453 Token position() => cachedNode.getBeginToken();
454 } 454 }
455 455
456 class ForeignElement extends Element { 456 class ForeignElement extends Element {
457 ForeignElement(SourceString name, ContainerElement enclosingElement) 457 ForeignElement(SourceString name, ContainerElement enclosingElement)
458 : super(name, ElementKind.FOREIGN, enclosingElement); 458 : super(name, ElementKind.FOREIGN, enclosingElement);
459 459
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 // the compilation unit of the abstract element. 493 // the compilation unit of the abstract element.
494 if (getter !== null && getter.enclosingElement === enclosingElement) { 494 if (getter !== null && getter.enclosingElement === enclosingElement) {
495 return getter.position(); 495 return getter.position();
496 } else if (setter != null) { 496 } else if (setter != null) {
497 // TODO(ahe): checking for null should not be necessary. 497 // TODO(ahe): checking for null should not be necessary.
498 return setter.position(); 498 return setter.position();
499 } 499 }
500 } 500 }
501 } 501 }
502 502
503 /** DEPRECATED. */
504 Type getType(TypeAnnotation typeAnnotation,
505 Compiler compiler,
506 LibraryElement library) {
507 // TODO(karlklose,ngeoffray): This method should be removed and the
508 // information should be computed by the resolver.
509
510 if (typeAnnotation == null || typeAnnotation.typeName == null) {
511 return compiler.types.dynamicType;
512 }
513 Identifier identifier = typeAnnotation.typeName.asIdentifier();
514 if (identifier === null) {
515 compiler.reportWarning(
516 typeAnnotation.typeName,
517 new ResolutionWarning(MessageKind.GENERIC,
518 ['library prefixes not handled']));
519 return compiler.types.dynamicType;
520 }
521 SourceString name = identifier.source;
522 Element element = library.find(name);
523 if (element !== null) {
524 if (element.isTypedef()) {
525 // TODO(ngeoffray): This is a hack to help us get support for the
526 // DOM library.
527 // TODO(ngeoffray): The list of types for the argument is wrong.
528 return new FunctionType(compiler.types.dynamicType,
529 const EmptyLink<Type>(),
530 element);
531 }
532 if (element.isClass()) {
533 // TODO(karlklose): substitute type parameters.
534 return element.computeType(compiler);
535 }
536 }
537 Type type = compiler.types.lookup(name);
538 if (type === null) {
539 type = compiler.types.dynamicType;
540 }
541 return type;
542 }
543
544 class FunctionParameters { 503 class FunctionParameters {
545 Link<Element> requiredParameters; 504 Link<Element> requiredParameters;
546 Link<Element> optionalParameters; 505 Link<Element> optionalParameters;
547 int requiredParameterCount; 506 int requiredParameterCount;
548 int optionalParameterCount; 507 int optionalParameterCount;
549 FunctionParameters(this.requiredParameters, 508 FunctionParameters(this.requiredParameters,
550 this.optionalParameters, 509 this.optionalParameters,
551 this.requiredParameterCount, 510 this.requiredParameterCount,
552 this.optionalParameterCount); 511 this.optionalParameterCount);
553 512
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 return computeParameters(compiler).parameterCount; 596 return computeParameters(compiler).parameterCount;
638 } 597 }
639 598
640 FunctionType computeType(Compiler compiler) { 599 FunctionType computeType(Compiler compiler) {
641 if (type != null) return type; 600 if (type != null) return type;
642 return compiler.withCurrentElement(this, () { 601 return compiler.withCurrentElement(this, () {
643 FunctionParameters parameters = computeParameters(compiler); 602 FunctionParameters parameters = computeParameters(compiler);
644 Types types = compiler.types; 603 Types types = compiler.types;
645 FunctionExpression node = 604 FunctionExpression node =
646 compiler.parser.measure(() => parseNode(compiler)); 605 compiler.parser.measure(() => parseNode(compiler));
647 Type returnType = getType(node.returnType, compiler, getLibrary()); 606 Type returnType = compiler.resolveTypeAnnotation(this, node.returnType);
648 if (returnType === null) returnType = types.dynamicType;
649 607
650 LinkBuilder<Type> parameterTypes = new LinkBuilder<Type>(); 608 LinkBuilder<Type> parameterTypes = new LinkBuilder<Type>();
651 for (Link<Element> link = parameters.requiredParameters; 609 for (Link<Element> link = parameters.requiredParameters;
652 !link.isEmpty(); 610 !link.isEmpty();
653 link = link.tail) { 611 link = link.tail) {
654 parameterTypes.addLast(link.head.computeType(compiler)); 612 parameterTypes.addLast(link.head.computeType(compiler));
655 } 613 }
656 type = new FunctionType(returnType, parameterTypes.toLink(), this); 614 type = new FunctionType(returnType, parameterTypes.toLink(), this);
657 return type; 615 return type;
658 }); 616 });
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 final Node node; 1021 final Node node;
1064 Type bound; 1022 Type bound;
1065 Type type; 1023 Type type;
1066 TypeVariableElement(name, Element enclosing, this.node, this.type, 1024 TypeVariableElement(name, Element enclosing, this.node, this.type,
1067 [this.bound]) 1025 [this.bound])
1068 : super(name, ElementKind.TYPE_VARIABLE, enclosing); 1026 : super(name, ElementKind.TYPE_VARIABLE, enclosing);
1069 Type computeType(compiler) => type; 1027 Type computeType(compiler) => type;
1070 Node parseNode(compiler) => node; 1028 Node parseNode(compiler) => node;
1071 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; 1029 toString() => "${enclosingElement.toString()}.${name.slowToString()}";
1072 } 1030 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/compiler.dart ('k') | lib/compiler/implementation/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698