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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart

Issue 1148343004: Remove ConstantExpression.value (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Update comments. Created 5 years, 6 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 dart2js.ir_builder_task; 5 library dart2js.ir_builder_task;
6 6
7 import '../closure.dart' as closurelib; 7 import '../closure.dart' as closurelib;
8 import '../closure.dart' hide ClosureScope; 8 import '../closure.dart' hide ClosureScope;
9 import '../constants/expressions.dart'; 9 import '../constants/expressions.dart';
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 return irBuilder.buildNullConstant(); 462 return irBuilder.buildNullConstant();
463 } 463 }
464 464
465 ir.Primitive visitLiteralString(ast.LiteralString node) { 465 ir.Primitive visitLiteralString(ast.LiteralString node) {
466 assert(irBuilder.isOpen); 466 assert(irBuilder.isOpen);
467 return irBuilder.buildDartStringConstant(node.dartString); 467 return irBuilder.buildDartStringConstant(node.dartString);
468 } 468 }
469 469
470 ConstantExpression getConstantForNode(ast.Node node) { 470 ConstantExpression getConstantForNode(ast.Node node) {
471 ConstantExpression constant = 471 ConstantExpression constant =
472 compiler.backend.constants.getConstantForNode(node, elements); 472 irBuilder.state.constants.getConstantForNode(node, elements);
473 assert(invariant(node, constant != null, 473 assert(invariant(node, constant != null,
474 message: 'No constant computed for $node')); 474 message: 'No constant computed for $node'));
475 return constant; 475 return constant;
476 } 476 }
477 477
478 ConstantExpression getConstantForVariable(VariableElement element) { 478 ConstantExpression getConstantForVariable(VariableElement element) {
479 ConstantExpression constant = 479 ConstantExpression constant =
480 compiler.backend.constants.getConstantForVariable(element); 480 irBuilder.state.constants.getConstantForVariable(element);
481 assert(invariant(element, constant != null, 481 assert(invariant(element, constant != null,
482 message: 'No constant computed for $element')); 482 message: 'No constant computed for $element'));
483 return constant; 483 return constant;
484 } 484 }
485 485
486 /// Builds a constant pulling the value from the constant environment.
487 // TODO(johnniwinther): Remove this when [IrBuilder.buildConstant] only takes
488 // a [ConstantExpression].
489 ir.Primitive buildConstant(ConstantExpression expression) {
490 return irBuilder.buildConstant(expression,
491 irBuilder.state.constants.getConstantValue(expression));
492 }
493
486 ir.Primitive visitLiteralList(ast.LiteralList node) { 494 ir.Primitive visitLiteralList(ast.LiteralList node) {
487 if (node.isConst) { 495 if (node.isConst) {
488 return translateConstant(node); 496 return translateConstant(node);
489 } 497 }
490 List<ir.Primitive> values = node.elements.nodes.mapToList(visit); 498 List<ir.Primitive> values = node.elements.nodes.mapToList(visit);
491 InterfaceType type = elements.getType(node); 499 InterfaceType type = elements.getType(node);
492 return irBuilder.buildListLiteral(type, values); 500 return irBuilder.buildListLiteral(type, values);
493 } 501 }
494 502
495 ir.Primitive visitLiteralMap(ast.LiteralMap node) { 503 ir.Primitive visitLiteralMap(ast.LiteralMap node) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 /// Returns `true` if [node] is a super call. 578 /// Returns `true` if [node] is a super call.
571 // TODO(johnniwinther): Remove the need for this. 579 // TODO(johnniwinther): Remove the need for this.
572 bool isSuperCall(ast.Send node) { 580 bool isSuperCall(ast.Send node) {
573 return node != null && node.receiver != null && node.receiver.isSuper(); 581 return node != null && node.receiver != null && node.receiver.isSuper();
574 } 582 }
575 583
576 @override 584 @override
577 ir.Primitive handleConstantGet( 585 ir.Primitive handleConstantGet(
578 ast.Node node, 586 ast.Node node,
579 ConstantExpression constant, _) { 587 ConstantExpression constant, _) {
580 return irBuilder.buildConstant(constant); 588 return buildConstant(constant);
581 } 589 }
582 590
583 /// If [node] is null, returns this. 591 /// If [node] is null, returns this.
584 /// Otherwise visits [node] and returns the result. 592 /// Otherwise visits [node] and returns the result.
585 ir.Primitive translateReceiver(ast.Expression node) { 593 ir.Primitive translateReceiver(ast.Expression node) {
586 return node != null ? visit(node) : irBuilder.buildThis(); 594 return node != null ? visit(node) : irBuilder.buildThis();
587 } 595 }
588 596
589 @override 597 @override
590 ir.Primitive handleDynamicGet( 598 ir.Primitive handleDynamicGet(
(...skipping 16 matching lines...) Expand all
607 return irBuilder.buildIfNotNullSend( 615 return irBuilder.buildIfNotNullSend(
608 target, 616 target,
609 nested(() => irBuilder.buildDynamicGet(target, selector))); 617 nested(() => irBuilder.buildDynamicGet(target, selector)));
610 } 618 }
611 619
612 @override 620 @override
613 ir.Primitive visitDynamicTypeLiteralGet( 621 ir.Primitive visitDynamicTypeLiteralGet(
614 ast.Send node, 622 ast.Send node,
615 ConstantExpression constant, 623 ConstantExpression constant,
616 _) { 624 _) {
617 return irBuilder.buildConstant(constant); 625 return buildConstant(constant);
618 } 626 }
619 627
620 @override 628 @override
621 ir.Primitive visitLocalVariableGet( 629 ir.Primitive visitLocalVariableGet(
622 ast.Send node, 630 ast.Send node,
623 LocalVariableElement element, 631 LocalVariableElement element,
624 _) { 632 _) {
625 return element.isConst 633 return element.isConst
626 ? irBuilder.buildConstant(getConstantForVariable(element)) 634 ? buildConstant(getConstantForVariable(element))
627 : irBuilder.buildLocalVariableGet(element); 635 : irBuilder.buildLocalVariableGet(element);
628 } 636 }
629 637
630 @override 638 @override
631 ir.Primitive handleLocalGet( 639 ir.Primitive handleLocalGet(
632 ast.Send node, 640 ast.Send node,
633 LocalElement element, 641 LocalElement element,
634 _) { 642 _) {
635 return irBuilder.buildLocalVariableGet(element); 643 return irBuilder.buildLocalVariableGet(element);
636 } 644 }
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 translateDynamicArguments(arguments, callStructure)); 931 translateDynamicArguments(arguments, callStructure));
924 } 932 }
925 933
926 @override 934 @override
927 ir.Primitive handleConstantInvoke( 935 ir.Primitive handleConstantInvoke(
928 ast.Send node, 936 ast.Send node,
929 ConstantExpression constant, 937 ConstantExpression constant,
930 ast.NodeList arguments, 938 ast.NodeList arguments,
931 CallStructure callStructure, 939 CallStructure callStructure,
932 _) { 940 _) {
933 ir.Primitive target = irBuilder.buildConstant(constant); 941 ir.Primitive target = buildConstant(constant);
934 return translateCallInvoke(target, arguments, callStructure); 942 return translateCallInvoke(target, arguments, callStructure);
935 } 943 }
936 944
937 @override 945 @override
938 ir.Primitive handleDynamicInvoke( 946 ir.Primitive handleDynamicInvoke(
939 ast.Send node, 947 ast.Send node,
940 ast.Node receiver, 948 ast.Node receiver,
941 ast.NodeList arguments, 949 ast.NodeList arguments,
942 Selector selector, 950 Selector selector,
943 _) { 951 _) {
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 return irBuilder.buildStaticSetterSet(setter, visit(rhs)); 1268 return irBuilder.buildStaticSetterSet(setter, visit(rhs));
1261 } 1269 }
1262 1270
1263 @override 1271 @override
1264 ir.Primitive handleTypeLiteralConstantCompounds( 1272 ir.Primitive handleTypeLiteralConstantCompounds(
1265 ast.SendSet node, 1273 ast.SendSet node,
1266 ConstantExpression constant, 1274 ConstantExpression constant,
1267 CompoundRhs rhs, 1275 CompoundRhs rhs,
1268 arg) { 1276 arg) {
1269 return translateCompounds( 1277 return translateCompounds(
1270 getValue: () => irBuilder.buildConstant(constant), 1278 getValue: () => buildConstant(constant),
1271 rhs: rhs, 1279 rhs: rhs,
1272 setValue: (value) {}); // The binary operator will throw before this. 1280 setValue: (value) {}); // The binary operator will throw before this.
1273 } 1281 }
1274 1282
1275 @override 1283 @override
1276 ir.Primitive handleDynamicCompounds( 1284 ir.Primitive handleDynamicCompounds(
1277 ast.Send node, 1285 ast.Send node,
1278 ast.Node receiver, 1286 ast.Node receiver,
1279 CompoundRhs rhs, 1287 CompoundRhs rhs,
1280 Selector getterSelector, 1288 Selector getterSelector,
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 while (it.moveNext()) { 1511 while (it.moveNext()) {
1504 ast.StringInterpolationPart part = it.current; 1512 ast.StringInterpolationPart part = it.current;
1505 arguments.add(visit(part.expression)); 1513 arguments.add(visit(part.expression));
1506 arguments.add(visitLiteralString(part.string)); 1514 arguments.add(visitLiteralString(part.string));
1507 } 1515 }
1508 return irBuilder.buildStringConcatenation(arguments); 1516 return irBuilder.buildStringConcatenation(arguments);
1509 } 1517 }
1510 1518
1511 ir.Primitive translateConstant(ast.Node node) { 1519 ir.Primitive translateConstant(ast.Node node) {
1512 assert(irBuilder.isOpen); 1520 assert(irBuilder.isOpen);
1513 return irBuilder.buildConstant(getConstantForNode(node)); 1521 return buildConstant(getConstantForNode(node));
1514 } 1522 }
1515 1523
1516 ir.Primitive visitThrow(ast.Throw node) { 1524 ir.Primitive visitThrow(ast.Throw node) {
1517 assert(irBuilder.isOpen); 1525 assert(irBuilder.isOpen);
1518 // This function is not called for throw expressions occurring as 1526 // This function is not called for throw expressions occurring as
1519 // statements. 1527 // statements.
1520 return irBuilder.buildNonTailThrow(visit(node.expression)); 1528 return irBuilder.buildNonTailThrow(visit(node.expression));
1521 } 1529 }
1522 1530
1523 ir.Primitive buildStaticNoSuchMethod( 1531 ir.Primitive buildStaticNoSuchMethod(
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
2248 JsIrBuilderVisitor visitor = new JsIrBuilderVisitor( 2256 JsIrBuilderVisitor visitor = new JsIrBuilderVisitor(
2249 context.resolvedAst.elements, 2257 context.resolvedAst.elements,
2250 compiler, 2258 compiler,
2251 sourceInformationBuilder.forContext(context)); 2259 sourceInformationBuilder.forContext(context));
2252 return visitor.withBuilder(irBuilder, () => visitor.translateConstant(exp)); 2260 return visitor.withBuilder(irBuilder, () => visitor.translateConstant(exp));
2253 } 2261 }
2254 2262
2255 JsIrBuilder getBuilderFor(Element element) { 2263 JsIrBuilder getBuilderFor(Element element) {
2256 return new JsIrBuilder( 2264 return new JsIrBuilder(
2257 new GlobalProgramInformation(compiler), 2265 new GlobalProgramInformation(compiler),
2258 compiler.backend.constantSystem, 2266 compiler.backend.constants,
2259 element); 2267 element);
2260 } 2268 }
2261 2269
2262 /// Builds the IR for a given constructor. 2270 /// Builds the IR for a given constructor.
2263 /// 2271 ///
2264 /// 1. Computes the type held in all own or "inherited" type variables. 2272 /// 1. Computes the type held in all own or "inherited" type variables.
2265 /// 2. Evaluates all own or inherited field initializers. 2273 /// 2. Evaluates all own or inherited field initializers.
2266 /// 3. Creates the object and assigns its fields and runtime type. 2274 /// 3. Creates the object and assigns its fields and runtime type.
2267 /// 4. Calls constructor body and super constructor bodies. 2275 /// 4. Calls constructor body and super constructor bodies.
2268 /// 5. Returns the created object. 2276 /// 5. Returns the created object.
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
2804 @override 2812 @override
2805 ir.Primitive handleStaticFieldGet(ast.Send node, FieldElement field, _) { 2813 ir.Primitive handleStaticFieldGet(ast.Send node, FieldElement field, _) {
2806 SourceInformation src = sourceInformationBuilder.buildGet(node); 2814 SourceInformation src = sourceInformationBuilder.buildGet(node);
2807 return buildStaticFieldGet(field, src); 2815 return buildStaticFieldGet(field, src);
2808 } 2816 }
2809 2817
2810 ir.Primitive buildStaticFieldGet(FieldElement field, SourceInformation src) { 2818 ir.Primitive buildStaticFieldGet(FieldElement field, SourceInformation src) {
2811 ConstantExpression constant = 2819 ConstantExpression constant =
2812 backend.constants.getConstantForVariable(field); 2820 backend.constants.getConstantForVariable(field);
2813 if (constant != null && !field.isAssignable) { 2821 if (constant != null && !field.isAssignable) {
2814 return irBuilder.buildConstant(constant); 2822 return buildConstant(constant);
2815 } else if (backend.constants.lazyStatics.contains(field)) { 2823 } else if (backend.constants.lazyStatics.contains(field)) {
2816 return irBuilder.buildStaticFieldLazyGet(field, src); 2824 return irBuilder.buildStaticFieldLazyGet(field, src);
2817 } else { 2825 } else {
2818 return irBuilder.buildStaticFieldGet(field, src); 2826 return irBuilder.buildStaticFieldGet(field, src);
2819 } 2827 }
2820 } 2828 }
2821 } 2829 }
2822 2830
2823 /// Perform simple post-processing on the initial CPS-translated root term. 2831 /// Perform simple post-processing on the initial CPS-translated root term.
2824 /// 2832 ///
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2879 node.body = replacementFor(node.body); 2887 node.body = replacementFor(node.body);
2880 } 2888 }
2881 } 2889 }
2882 2890
2883 /// Visit a just-deleted subterm and unlink all [Reference]s in it. 2891 /// Visit a just-deleted subterm and unlink all [Reference]s in it.
2884 class RemovalVisitor extends ir.RecursiveVisitor { 2892 class RemovalVisitor extends ir.RecursiveVisitor {
2885 processReference(ir.Reference reference) { 2893 processReference(ir.Reference reference) {
2886 reference.unlink(); 2894 reference.unlink();
2887 } 2895 }
2888 } 2896 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698