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

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

Issue 21511003: Support symbol literals. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 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 part of dart2js; 5 part of dart2js;
6 6
7 /** 7 /**
8 * The [ConstantHandler] keeps track of compile-time constants, 8 * The [ConstantHandler] keeps track of compile-time constants,
9 * initializations of global and static fields, and default values of 9 * initializations of global and static fields, and default values of
10 * optional parameters. 10 * optional parameters.
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 } 468 }
469 accumulator = new DartString.concat(accumulator, expressionString); 469 accumulator = new DartString.concat(accumulator, expressionString);
470 StringConstant partString = evaluate(part.string); 470 StringConstant partString = evaluate(part.string);
471 if (partString == null) return null; 471 if (partString == null) return null;
472 accumulator = new DartString.concat(accumulator, partString.value); 472 accumulator = new DartString.concat(accumulator, partString.value);
473 }; 473 };
474 handler.registerStringInstance(elements); 474 handler.registerStringInstance(elements);
475 return constantSystem.createString(accumulator, node); 475 return constantSystem.createString(accumulator, node);
476 } 476 }
477 477
478 Constant visitLiteralSymbol(LiteralSymbol node) {
479 InterfaceType type = compiler.symbolClass.computeType(compiler);
480 List<Constant> createArguments(_) {
481 return [constantSystem.createString(
ngeoffray 2013/09/04 07:14:17 add <Constant> (since you went into the trouble of
Johnni Winther 2013/09/10 09:09:07 Done.
482 new DartString.literal(node.slowNameString), node)];
483 }
484 return makeConstructedConstant(
485 node, type, compiler.symbolConstructor, createArguments);
486 }
487
478 Constant makeTypeConstant(Element element) { 488 Constant makeTypeConstant(Element element) {
479 DartType elementType = element.computeType(compiler).asRaw(); 489 DartType elementType = element.computeType(compiler).asRaw();
480 compiler.backend.registerTypeLiteral(element, elements); 490 compiler.backend.registerTypeLiteral(element, elements);
481 DartType constantType = 491 DartType constantType =
482 compiler.backend.typeImplementation.computeType(compiler); 492 compiler.backend.typeImplementation.computeType(compiler);
483 Constant constant = new TypeConstant(elementType, constantType); 493 Constant constant = new TypeConstant(elementType, constantType);
484 // If we use a type literal in a constant, the compile time 494 // If we use a type literal in a constant, the compile time
485 // constant emitter will generate a call to the createRuntimeType 495 // constant emitter will generate a call to the createRuntimeType
486 // helper so we register a use of that. 496 // helper so we register a use of that.
487 handler.registerCreateRuntimeTypeFunction(); 497 handler.registerCreateRuntimeTypeFunction();
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 } 690 }
681 691
682 Send send = node.send; 692 Send send = node.send;
683 FunctionElement constructor = elements[send]; 693 FunctionElement constructor = elements[send];
684 // TODO(ahe): This is nasty: we must eagerly analyze the 694 // TODO(ahe): This is nasty: we must eagerly analyze the
685 // constructor to ensure the redirectionTarget has been computed 695 // constructor to ensure the redirectionTarget has been computed
686 // correctly. Find a way to avoid this. 696 // correctly. Find a way to avoid this.
687 compiler.analyzeElement(constructor.declaration); 697 compiler.analyzeElement(constructor.declaration);
688 698
689 InterfaceType type = elements.getType(node); 699 InterfaceType type = elements.getType(node);
700 List<Constant> evaluateArguments(FunctionElement constructor) {
701 Selector selector = elements.getSelector(send);
702 return evaluateArgumentsToConstructor(
703 node, selector, send.arguments, constructor);
704 }
705 return makeConstructedConstant(node, type, constructor, evaluateArguments);
706 }
707
708 Constant makeConstructedConstant(
709 Node node, InterfaceType type, FunctionElement constructor,
710 List<Constant> getArguments(FunctionElement constructor)) {
690 if (constructor.isRedirectingFactory) { 711 if (constructor.isRedirectingFactory) {
691 type = constructor.computeTargetType(compiler, type); 712 type = constructor.computeTargetType(compiler, type);
692 } 713 }
693 714
694 constructor = constructor.redirectionTarget; 715 constructor = constructor.redirectionTarget;
695 ClassElement classElement = constructor.getEnclosingClass(); 716 ClassElement classElement = constructor.getEnclosingClass();
696 // The constructor must be an implementation to ensure that field 717 // The constructor must be an implementation to ensure that field
697 // initializers are handled correctly. 718 // initializers are handled correctly.
698 constructor = constructor.implementation; 719 constructor = constructor.implementation;
699 assert(invariant(node, constructor.isImplementation)); 720 assert(invariant(node, constructor.isImplementation));
700 721
701 Selector selector = elements.getSelector(send); 722 List<Constant> arguments = getArguments(constructor);
702 List<Constant> arguments = evaluateArgumentsToConstructor(
703 node, selector, send.arguments, constructor);
704 ConstructorEvaluator evaluator = 723 ConstructorEvaluator evaluator =
705 new ConstructorEvaluator(constructor, handler, compiler); 724 new ConstructorEvaluator(constructor, handler, compiler);
706 evaluator.evaluateConstructorFieldValues(arguments); 725 evaluator.evaluateConstructorFieldValues(arguments);
707 List<Constant> jsNewArguments = evaluator.buildJsNewArguments(classElement); 726 List<Constant> jsNewArguments = evaluator.buildJsNewArguments(classElement);
708 727
709 handler.registerInstantiatedType(type, elements); 728 handler.registerInstantiatedType(type, elements);
710 Constant constant = new ConstructedConstant(type, jsNewArguments); 729 Constant constant = new ConstructedConstant(type, jsNewArguments);
711 handler.registerCompileTimeConstant(constant, elements); 730 handler.registerCompileTimeConstant(constant, elements);
712 return constant; 731 return constant;
713 } 732 }
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 if (fieldValue == null) { 949 if (fieldValue == null) {
931 // Use the default value. 950 // Use the default value.
932 fieldValue = handler.compileConstant(field); 951 fieldValue = handler.compileConstant(field);
933 } 952 }
934 jsNewArguments.add(fieldValue); 953 jsNewArguments.add(fieldValue);
935 }, 954 },
936 includeSuperAndInjectedMembers: true); 955 includeSuperAndInjectedMembers: true);
937 return jsNewArguments; 956 return jsNewArguments;
938 } 957 }
939 } 958 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698