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

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

Issue 10917285: Stub implementation of patch invariants for the patch refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Leftovers from rebase. Created 8 years, 3 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 /** 5 /**
6 * The [ConstantHandler] keeps track of compile-time constants, 6 * The [ConstantHandler] keeps track of compile-time constants,
7 * initializations of global and static fields, and default values of 7 * initializations of global and static fields, and default values of
8 * optional parameters. 8 * optional parameters.
9 */ 9 */
10 class ConstantHandler extends CompilerTask { 10 class ConstantHandler extends CompilerTask {
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 if (folded === null) return signalNotCompileTimeConstant(send); 522 if (folded === null) return signalNotCompileTimeConstant(send);
523 return folded; 523 return folded;
524 } 524 }
525 return signalNotCompileTimeConstant(send); 525 return signalNotCompileTimeConstant(send);
526 } 526 }
527 527
528 Constant visitSendSet(SendSet node) { 528 Constant visitSendSet(SendSet node) {
529 return signalNotCompileTimeConstant(node); 529 return signalNotCompileTimeConstant(node);
530 } 530 }
531 531
532 /** Returns the list of constants that are passed to the static function. */ 532 /**
533 * Returns the list of constants that are passed to the static function.
534 *
535 * Invariant: [target] must be the implementation element.
ahe 2012/09/18 11:25:54 the -> an.
Johnni Winther 2012/09/20 08:12:23 Done.
536 */
533 List<Constant> evaluateArgumentsToConstructor(Selector selector, 537 List<Constant> evaluateArgumentsToConstructor(Selector selector,
534 Link<Node> arguments, 538 Link<Node> arguments,
535 FunctionElement target) { 539 FunctionElement target) {
540 assert(target.isImplementation);
536 List<Constant> compiledArguments = <Constant>[]; 541 List<Constant> compiledArguments = <Constant>[];
537 542
538 Function compileArgument = evaluateConstant; 543 Function compileArgument = evaluateConstant;
539 Function compileConstant = compiler.compileConstant; 544 Function compileConstant = compiler.compileConstant;
540 bool succeeded = selector.addArgumentsToList(arguments, 545 bool succeeded = selector.addArgumentsToList(arguments,
541 compiledArguments, 546 compiledArguments,
542 target, 547 target,
543 compileArgument, 548 compileArgument,
544 compileConstant, 549 compileConstant,
545 compiler); 550 compiler);
546 assert(succeeded); 551 assert(succeeded);
547 return compiledArguments; 552 return compiledArguments;
548 } 553 }
549 554
550 Constant visitNewExpression(NewExpression node) { 555 Constant visitNewExpression(NewExpression node) {
551 if (!node.isConst()) { 556 if (!node.isConst()) {
552 return signalNotCompileTimeConstant(node); 557 return signalNotCompileTimeConstant(node);
553 } 558 }
554 559
555 Send send = node.send; 560 Send send = node.send;
556 FunctionElement constructor = elements[send]; 561 FunctionElement constructor = elements[send];
557 ClassElement classElement = constructor.getEnclosingClass(); 562 ClassElement classElement = constructor.getEnclosingClass();
558 if (classElement.isInterface()) { 563 if (classElement.isInterface()) {
559 compiler.resolver.resolveMethodElement(constructor); 564 compiler.resolver.resolveMethodElement(constructor);
560 constructor = constructor.defaultImplementation; 565 constructor = constructor.defaultImplementation;
561 classElement = constructor.getEnclosingClass(); 566 classElement = constructor.getEnclosingClass();
562 } 567 }
568 // The constructor must be the implementation to ensure that field
ahe 2012/09/18 11:25:54 the -> an.
Johnni Winther 2012/09/20 08:12:23 Done.
569 // initializers are handled correctly.
570 constructor = constructor.implementation;
ahe 2012/09/18 11:25:54 Is this temporary?
Johnni Winther 2012/09/20 08:12:23 No. That is why I put in the comment.
571 assert(constructor.isImplementation);
563 572
564 Selector selector = elements.getSelector(send); 573 Selector selector = elements.getSelector(send);
565 List<Constant> arguments = 574 List<Constant> arguments =
566 evaluateArgumentsToConstructor(selector, send.arguments, constructor); 575 evaluateArgumentsToConstructor(selector, send.arguments, constructor);
567 ConstructorEvaluator evaluator = 576 ConstructorEvaluator evaluator =
568 new ConstructorEvaluator(constructor, constantSystem, compiler); 577 new ConstructorEvaluator(constructor, constantSystem, compiler);
569 evaluator.evaluateConstructorFieldValues(arguments); 578 evaluator.evaluateConstructorFieldValues(arguments);
570 List<Constant> jsNewArguments = evaluator.buildJsNewArguments(classElement); 579 List<Constant> jsNewArguments = evaluator.buildJsNewArguments(classElement);
571 580
572 compiler.enqueuer.codegen.registerInstantiatedClass(classElement); 581 compiler.enqueuer.codegen.registerInstantiatedClass(classElement);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 : super(constantSystem, elements, compiler, isConst: true); 617 : super(constantSystem, elements, compiler, isConst: true);
609 618
610 error(Node node) { 619 error(Node node) {
611 // Just fail without reporting it anywhere. 620 // Just fail without reporting it anywhere.
612 throw new CompileTimeConstantError( 621 throw new CompileTimeConstantError(
613 MessageKind.NOT_A_COMPILE_TIME_CONSTANT, const []); 622 MessageKind.NOT_A_COMPILE_TIME_CONSTANT, const []);
614 } 623 }
615 } 624 }
616 625
617 class ConstructorEvaluator extends CompileTimeConstantEvaluator { 626 class ConstructorEvaluator extends CompileTimeConstantEvaluator {
618 FunctionElement constructor; 627 final FunctionElement constructor;
619 final Map<Element, Constant> definitions; 628 final Map<Element, Constant> definitions;
620 final Map<Element, Constant> fieldValues; 629 final Map<Element, Constant> fieldValues;
621 630
631 /**
632 * Invariant: [constructor] must be the implementation element.
ahe 2012/09/18 11:25:54 This is not documentation.
Johnni Winther 2012/09/20 08:12:23 Done.
633 */
622 ConstructorEvaluator(FunctionElement constructor, 634 ConstructorEvaluator(FunctionElement constructor,
623 ConstantSystem constantSystem, 635 ConstantSystem constantSystem,
624 Compiler compiler) 636 Compiler compiler)
625 : this.constructor = constructor, 637 : this.constructor = constructor,
626 this.definitions = new Map<Element, Constant>(), 638 this.definitions = new Map<Element, Constant>(),
627 this.fieldValues = new Map<Element, Constant>(), 639 this.fieldValues = new Map<Element, Constant>(),
628 super(constantSystem, 640 super(constantSystem,
629 compiler.resolver.resolveMethodElement(constructor), 641 compiler.resolver.resolveMethodElement(constructor.declaration),
630 compiler, 642 compiler,
631 isConst: true); 643 isConst: true) {
644 assert(constructor.isImplementation);
645 }
632 646
633 Constant visitSend(Send send) { 647 Constant visitSend(Send send) {
634 Element element = elements[send]; 648 Element element = elements[send];
635 if (Elements.isLocal(element)) { 649 if (Elements.isLocal(element)) {
636 Constant constant = definitions[element]; 650 Constant constant = definitions[element];
637 if (constant === null) { 651 if (constant === null) {
638 compiler.internalError("Local variable without value", node: send); 652 compiler.internalError("Local variable without value", node: send);
639 } 653 }
640 return constant; 654 return constant;
641 } 655 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 Constant fieldValue = fieldValues[field]; 768 Constant fieldValue = fieldValues[field];
755 if (fieldValue === null) { 769 if (fieldValue === null) {
756 // Use the default value. 770 // Use the default value.
757 fieldValue = compiler.compileConstant(field); 771 fieldValue = compiler.compileConstant(field);
758 } 772 }
759 jsNewArguments.add(fieldValue); 773 jsNewArguments.add(fieldValue);
760 }); 774 });
761 return jsNewArguments; 775 return jsNewArguments;
762 } 776 }
763 } 777 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/compiler.dart » ('j') | lib/compiler/implementation/compiler.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698