| 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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 class FunctionParameters { | 503 class FunctionSignature { |
| 504 Link<Element> requiredParameters; | 504 Link<Element> requiredParameters; |
| 505 Link<Element> optionalParameters; | 505 Link<Element> optionalParameters; |
| 506 Type returnType; |
| 506 int requiredParameterCount; | 507 int requiredParameterCount; |
| 507 int optionalParameterCount; | 508 int optionalParameterCount; |
| 508 FunctionParameters(this.requiredParameters, | 509 FunctionSignature(this.requiredParameters, |
| 509 this.optionalParameters, | 510 this.optionalParameters, |
| 510 this.requiredParameterCount, | 511 this.requiredParameterCount, |
| 511 this.optionalParameterCount); | 512 this.optionalParameterCount, |
| 513 this.returnType); |
| 512 | 514 |
| 513 void forEachParameter(void function(Element parameter)) { | 515 void forEachParameter(void function(Element parameter)) { |
| 514 for (Link<Element> link = requiredParameters; | 516 for (Link<Element> link = requiredParameters; |
| 515 !link.isEmpty(); | 517 !link.isEmpty(); |
| 516 link = link.tail) { | 518 link = link.tail) { |
| 517 function(link.head); | 519 function(link.head); |
| 518 } | 520 } |
| 519 for (Link<Element> link = optionalParameters; | 521 for (Link<Element> link = optionalParameters; |
| 520 !link.isEmpty(); | 522 !link.isEmpty(); |
| 521 link = link.tail) { | 523 link = link.tail) { |
| 522 function(link.head); | 524 function(link.head); |
| 523 } | 525 } |
| 524 } | 526 } |
| 525 | 527 |
| 526 int get parameterCount() => requiredParameterCount + optionalParameterCount; | 528 int get parameterCount() => requiredParameterCount + optionalParameterCount; |
| 527 } | 529 } |
| 528 | 530 |
| 529 class FunctionElement extends Element { | 531 class FunctionElement extends Element { |
| 530 FunctionExpression cachedNode; | 532 FunctionExpression cachedNode; |
| 531 Type type; | 533 Type type; |
| 532 final Modifiers modifiers; | 534 final Modifiers modifiers; |
| 533 | 535 |
| 534 FunctionParameters functionParameters; | 536 FunctionSignature functionSignature; |
| 535 | 537 |
| 536 /** | 538 /** |
| 537 * If this is an interface constructor, [defaultImplementation] will | 539 * If this is an interface constructor, [defaultImplementation] will |
| 538 * changed by the resolver to point to the default | 540 * changed by the resolver to point to the default |
| 539 * implementation. Otherwise, [:defaultImplementation === this:]. | 541 * implementation. Otherwise, [:defaultImplementation === this:]. |
| 540 */ | 542 */ |
| 541 FunctionElement defaultImplementation; | 543 FunctionElement defaultImplementation; |
| 542 | 544 |
| 543 FunctionElement(SourceString name, | 545 FunctionElement(SourceString name, |
| 544 ElementKind kind, | 546 ElementKind kind, |
| 545 Modifiers modifiers, | 547 Modifiers modifiers, |
| 546 Element enclosing) | 548 Element enclosing) |
| 547 : this.tooMuchOverloading(name, null, kind, modifiers, enclosing, null); | 549 : this.tooMuchOverloading(name, null, kind, modifiers, enclosing, null); |
| 548 | 550 |
| 549 FunctionElement.node(SourceString name, | 551 FunctionElement.node(SourceString name, |
| 550 FunctionExpression node, | 552 FunctionExpression node, |
| 551 ElementKind kind, | 553 ElementKind kind, |
| 552 Modifiers modifiers, | 554 Modifiers modifiers, |
| 553 Element enclosing) | 555 Element enclosing) |
| 554 : this.tooMuchOverloading(name, node, kind, modifiers, enclosing, null); | 556 : this.tooMuchOverloading(name, node, kind, modifiers, enclosing, null); |
| 555 | 557 |
| 556 FunctionElement.from(SourceString name, | 558 FunctionElement.from(SourceString name, |
| 557 FunctionElement other, | 559 FunctionElement other, |
| 558 Element enclosing) | 560 Element enclosing) |
| 559 : this.tooMuchOverloading(name, other.cachedNode, other.kind, | 561 : this.tooMuchOverloading(name, other.cachedNode, other.kind, |
| 560 other.modifiers, enclosing, | 562 other.modifiers, enclosing, |
| 561 other.functionParameters); | 563 other.functionSignature); |
| 562 | 564 |
| 563 FunctionElement.tooMuchOverloading(SourceString name, | 565 FunctionElement.tooMuchOverloading(SourceString name, |
| 564 FunctionExpression this.cachedNode, | 566 FunctionExpression this.cachedNode, |
| 565 ElementKind kind, | 567 ElementKind kind, |
| 566 Modifiers this.modifiers, | 568 Modifiers this.modifiers, |
| 567 Element enclosing, | 569 Element enclosing, |
| 568 FunctionParameters this.functionParameters) | 570 FunctionSignature this.functionSignature) |
| 569 : super(name, kind, enclosing) | 571 : super(name, kind, enclosing) |
| 570 { | 572 { |
| 571 defaultImplementation = this; | 573 defaultImplementation = this; |
| 572 } | 574 } |
| 573 | 575 |
| 574 bool isInstanceMember() { | 576 bool isInstanceMember() { |
| 575 return isMember() | 577 return isMember() |
| 576 && kind != ElementKind.GENERATIVE_CONSTRUCTOR | 578 && kind != ElementKind.GENERATIVE_CONSTRUCTOR |
| 577 && !modifiers.isFactory() | 579 && !modifiers.isFactory() |
| 578 && !modifiers.isStatic(); | 580 && !modifiers.isStatic(); |
| 579 } | 581 } |
| 580 | 582 |
| 581 FunctionParameters computeParameters(Compiler compiler) { | 583 FunctionSignature computeSignature(Compiler compiler) { |
| 582 if (functionParameters !== null) return functionParameters; | 584 if (functionSignature !== null) return functionSignature; |
| 583 functionParameters = compiler.resolveSignature(this); | 585 compiler.withCurrentElement(this, () { |
| 584 return functionParameters; | 586 functionSignature = compiler.resolveSignature(this); |
| 587 }); |
| 588 return functionSignature; |
| 585 } | 589 } |
| 586 | 590 |
| 587 int requiredParameterCount(Compiler compiler) { | 591 int requiredParameterCount(Compiler compiler) { |
| 588 return computeParameters(compiler).requiredParameterCount; | 592 return computeSignature(compiler).requiredParameterCount; |
| 589 } | 593 } |
| 590 | 594 |
| 591 int optionalParameterCount(Compiler compiler) { | 595 int optionalParameterCount(Compiler compiler) { |
| 592 return computeParameters(compiler).optionalParameterCount; | 596 return computeSignature(compiler).optionalParameterCount; |
| 593 } | 597 } |
| 594 | 598 |
| 595 int parameterCount(Compiler compiler) { | 599 int parameterCount(Compiler compiler) { |
| 596 return computeParameters(compiler).parameterCount; | 600 return computeSignature(compiler).parameterCount; |
| 597 } | 601 } |
| 598 | 602 |
| 599 FunctionType computeType(Compiler compiler) { | 603 FunctionType computeType(Compiler compiler) { |
| 600 if (type != null) return type; | 604 if (type != null) return type; |
| 601 return compiler.withCurrentElement(this, () { | 605 compiler.withCurrentElement(this, () { |
| 602 FunctionParameters parameters = computeParameters(compiler); | 606 FunctionSignature signature = computeSignature(compiler); |
| 603 Types types = compiler.types; | |
| 604 FunctionExpression node = | |
| 605 compiler.parser.measure(() => parseNode(compiler)); | |
| 606 Type returnType = compiler.resolveTypeAnnotation(this, node.returnType); | |
| 607 | |
| 608 LinkBuilder<Type> parameterTypes = new LinkBuilder<Type>(); | 607 LinkBuilder<Type> parameterTypes = new LinkBuilder<Type>(); |
| 609 for (Link<Element> link = parameters.requiredParameters; | 608 for (Link<Element> link = signature.requiredParameters; |
| 610 !link.isEmpty(); | 609 !link.isEmpty(); |
| 611 link = link.tail) { | 610 link = link.tail) { |
| 612 parameterTypes.addLast(link.head.computeType(compiler)); | 611 parameterTypes.addLast(link.head.computeType(compiler)); |
| 612 // TODO(karlklose): optional parameters. |
| 613 } | 613 } |
| 614 type = new FunctionType(returnType, parameterTypes.toLink(), this); | 614 type = new FunctionType(signature.returnType, |
| 615 return type; | 615 parameterTypes.toLink(), |
| 616 this); |
| 616 }); | 617 }); |
| 618 return type; |
| 617 } | 619 } |
| 618 | 620 |
| 619 Node parseNode(DiagnosticListener listener) => cachedNode; | 621 Node parseNode(DiagnosticListener listener) => cachedNode; |
| 620 | 622 |
| 621 Token position() => cachedNode.getBeginToken(); | 623 Token position() => cachedNode.getBeginToken(); |
| 622 } | 624 } |
| 623 | 625 |
| 624 class ConstructorBodyElement extends FunctionElement { | 626 class ConstructorBodyElement extends FunctionElement { |
| 625 FunctionElement constructor; | 627 FunctionElement constructor; |
| 626 | 628 |
| 627 ConstructorBodyElement(FunctionElement constructor) | 629 ConstructorBodyElement(FunctionElement constructor) |
| 628 : this.constructor = constructor, | 630 : this.constructor = constructor, |
| 629 super(constructor.name, | 631 super(constructor.name, |
| 630 ElementKind.GENERATIVE_CONSTRUCTOR_BODY, | 632 ElementKind.GENERATIVE_CONSTRUCTOR_BODY, |
| 631 null, | 633 null, |
| 632 constructor.enclosingElement) { | 634 constructor.enclosingElement) { |
| 633 functionParameters = constructor.functionParameters; | 635 functionSignature = constructor.functionSignature; |
| 634 } | 636 } |
| 635 | 637 |
| 636 bool isInstanceMember() => true; | 638 bool isInstanceMember() => true; |
| 637 | 639 |
| 638 FunctionType computeType(Compiler compiler) { unreachable(); } | 640 FunctionType computeType(Compiler compiler) { unreachable(); } |
| 639 | 641 |
| 640 Node parseNode(DiagnosticListener listener) { | 642 Node parseNode(DiagnosticListener listener) { |
| 641 if (cachedNode !== null) return cachedNode; | 643 if (cachedNode !== null) return cachedNode; |
| 642 cachedNode = constructor.parseNode(listener); | 644 cachedNode = constructor.parseNode(listener); |
| 643 assert(cachedNode !== null); | 645 assert(cachedNode !== null); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 final Node node; | 1023 final Node node; |
| 1022 Type bound; | 1024 Type bound; |
| 1023 Type type; | 1025 Type type; |
| 1024 TypeVariableElement(name, Element enclosing, this.node, this.type, | 1026 TypeVariableElement(name, Element enclosing, this.node, this.type, |
| 1025 [this.bound]) | 1027 [this.bound]) |
| 1026 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | 1028 : super(name, ElementKind.TYPE_VARIABLE, enclosing); |
| 1027 Type computeType(compiler) => type; | 1029 Type computeType(compiler) => type; |
| 1028 Node parseNode(compiler) => node; | 1030 Node parseNode(compiler) => node; |
| 1029 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; | 1031 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; |
| 1030 } | 1032 } |
| OLD | NEW |