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

Side by Side Diff: pkg/compiler/lib/src/universe/codegen_world_builder.dart

Issue 2939033002: Towards compiling Hello World! (Closed)
Patch Set: Fix parameter ordering Created 3 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 world_builder; 5 part of world_builder;
6 6
7 /// World builder specific to codegen. 7 /// World builder specific to codegen.
8 /// 8 ///
9 /// This adds additional access to liveness of selectors and elements. 9 /// This adds additional access to liveness of selectors and elements.
10 abstract class CodegenWorldBuilder implements WorldBuilder { 10 abstract class CodegenWorldBuilder implements WorldBuilder {
11 /// Calls [f] with every instance field, together with its declarer, in an 11 /// Calls [f] with every instance field, together with its declarer, in an
12 /// instance of [cls]. 12 /// instance of [cls].
13 void forEachInstanceField( 13 void forEachInstanceField(
14 ClassEntity cls, void f(ClassEntity declarer, FieldEntity field)); 14 ClassEntity cls, void f(ClassEntity declarer, FieldEntity field));
15 15
16 /// Calls [f] for each parameter of [function] providing the type and name of 16 /// Calls [f] for each parameter of [function] providing the type and name of
17 /// the parameter. 17 /// the parameter and the [defaultValue] if the parameter is optional.
18 void forEachParameter( 18 void forEachParameter(FunctionEntity function,
19 FunctionEntity function, void f(DartType type, String name)); 19 void f(DartType type, String name, ConstantValue defaultValue));
20 20
21 void forEachInvokedName( 21 void forEachInvokedName(
22 f(String name, Map<Selector, SelectorConstraints> selectors)); 22 f(String name, Map<Selector, SelectorConstraints> selectors));
23 23
24 void forEachInvokedGetter( 24 void forEachInvokedGetter(
25 f(String name, Map<Selector, SelectorConstraints> selectors)); 25 f(String name, Map<Selector, SelectorConstraints> selectors));
26 26
27 void forEachInvokedSetter( 27 void forEachInvokedSetter(
28 f(String name, Map<Selector, SelectorConstraints> selectors)); 28 f(String name, Map<Selector, SelectorConstraints> selectors));
29 29
30 /// Returns `true` if [field] constant or final with a constant initializer.
31 bool hasConstantFieldInitializer(FieldEntity field);
32
30 /// Returns `true` if [member] is invoked as a setter. 33 /// Returns `true` if [member] is invoked as a setter.
31 bool hasInvokedSetter(MemberEntity member, ClosedWorld world); 34 bool hasInvokedSetter(MemberEntity member, ClosedWorld world);
32 35
33 bool hasInvokedGetter(MemberEntity member, ClosedWorld world); 36 bool hasInvokedGetter(MemberEntity member, ClosedWorld world);
34 37
35 Map<Selector, SelectorConstraints> invocationsByName(String name); 38 Map<Selector, SelectorConstraints> invocationsByName(String name);
36 39
37 Map<Selector, SelectorConstraints> getterInvocationsByName(String name); 40 Map<Selector, SelectorConstraints> getterInvocationsByName(String name);
38 41
39 Map<Selector, SelectorConstraints> setterInvocationsByName(String name); 42 Map<Selector, SelectorConstraints> setterInvocationsByName(String name);
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 /// the constant use was new to the world. 538 /// the constant use was new to the world.
536 bool registerConstantUse(ConstantUse use) { 539 bool registerConstantUse(ConstantUse use) {
537 if (use.kind == ConstantUseKind.DIRECT) { 540 if (use.kind == ConstantUseKind.DIRECT) {
538 addCompileTimeConstantForEmission(use.value); 541 addCompileTimeConstantForEmission(use.value);
539 } 542 }
540 return _constantValues.add(use.value); 543 return _constantValues.add(use.value);
541 } 544 }
542 } 545 }
543 546
544 class ElementCodegenWorldBuilderImpl extends CodegenWorldBuilderImpl { 547 class ElementCodegenWorldBuilderImpl extends CodegenWorldBuilderImpl {
548 final JavaScriptConstantCompiler _constants;
549
545 ElementCodegenWorldBuilderImpl( 550 ElementCodegenWorldBuilderImpl(
551 this._constants,
546 ElementEnvironment elementEnvironment, 552 ElementEnvironment elementEnvironment,
547 NativeBasicData nativeBasicData, 553 NativeBasicData nativeBasicData,
548 ClosedWorld world, 554 ClosedWorld world,
549 SelectorConstraintsStrategy selectorConstraintsStrategy) 555 SelectorConstraintsStrategy selectorConstraintsStrategy)
550 : super(elementEnvironment, nativeBasicData, world, 556 : super(elementEnvironment, nativeBasicData, world,
551 selectorConstraintsStrategy); 557 selectorConstraintsStrategy);
552 558
559 @override
560 bool hasConstantFieldInitializer(FieldElement field) {
561 return field.constant != null;
562 }
563
553 /// Calls [f] with every instance field, together with its declarer, in an 564 /// Calls [f] with every instance field, together with its declarer, in an
554 /// instance of [cls]. 565 /// instance of [cls].
555 void forEachInstanceField( 566 void forEachInstanceField(
556 ClassElement cls, void f(ClassEntity declarer, FieldEntity field)) { 567 ClassElement cls, void f(ClassEntity declarer, FieldEntity field)) {
557 cls.implementation 568 cls.implementation
558 .forEachInstanceField(f, includeSuperAndInjectedMembers: true); 569 .forEachInstanceField(f, includeSuperAndInjectedMembers: true);
559 } 570 }
560 571
561 @override 572 @override
562 void forEachParameter( 573 void forEachParameter(MethodElement function,
563 MethodElement function, void f(DartType type, String name)) { 574 void f(DartType type, String name, ConstantValue defaultValue)) {
564 FunctionSignature parameters = function.functionSignature; 575 FunctionSignature parameters = function.functionSignature;
565 parameters.forEachParameter((_parameter) { 576 parameters.orderedForEachParameter((_parameter) {
566 ParameterElement parameter = _parameter; 577 ParameterElement parameter = _parameter;
567 f(parameter.type, parameter.name); 578 ConstantValue value;
579 if (parameter.constant != null) {
580 value = _constants.getConstantValue(parameter.constant);
581 } else {
582 value = new NullConstantValue();
583 }
584 f(parameter.type, parameter.name, value);
568 }); 585 });
569 } 586 }
570 587
571 @override 588 @override
572 void _processInstantiatedClassMember( 589 void _processInstantiatedClassMember(
573 ClassEntity cls, MemberElement member, MemberUsedCallback memberUsed) { 590 ClassEntity cls, MemberElement member, MemberUsedCallback memberUsed) {
574 assert(member.isDeclaration, failedAt(member)); 591 assert(member.isDeclaration, failedAt(member));
575 if (member.isMalformed) return; 592 if (member.isMalformed) return;
576 super._processInstantiatedClassMember(cls, member, memberUsed); 593 super._processInstantiatedClassMember(cls, member, memberUsed);
577 } 594 }
(...skipping 15 matching lines...) Expand all
593 void registerIsCheck(ResolutionDartType type) { 610 void registerIsCheck(ResolutionDartType type) {
594 // Even in checked mode, type annotations for return type and argument 611 // Even in checked mode, type annotations for return type and argument
595 // types do not imply type checks, so there should never be a check 612 // types do not imply type checks, so there should never be a check
596 // against the type variable of a typedef. 613 // against the type variable of a typedef.
597 assert(!type.isTypeVariable || !type.element.enclosingElement.isTypedef); 614 assert(!type.isTypeVariable || !type.element.enclosingElement.isTypedef);
598 super.registerIsCheck(type); 615 super.registerIsCheck(type);
599 } 616 }
600 } 617 }
601 618
602 class KernelCodegenWorldBuilder extends CodegenWorldBuilderImpl { 619 class KernelCodegenWorldBuilder extends CodegenWorldBuilderImpl {
620 KernelToElementMapImpl _elementMap;
621
603 KernelCodegenWorldBuilder( 622 KernelCodegenWorldBuilder(
623 this._elementMap,
604 ElementEnvironment elementEnvironment, 624 ElementEnvironment elementEnvironment,
605 NativeBasicData nativeBasicData, 625 NativeBasicData nativeBasicData,
606 ClosedWorld world, 626 ClosedWorld world,
607 SelectorConstraintsStrategy selectorConstraintsStrategy) 627 SelectorConstraintsStrategy selectorConstraintsStrategy)
608 : super(elementEnvironment, nativeBasicData, world, 628 : super(elementEnvironment, nativeBasicData, world,
609 selectorConstraintsStrategy); 629 selectorConstraintsStrategy);
610 630
611 @override 631 @override
612 void forEachParameter( 632 bool hasConstantFieldInitializer(FieldEntity field) {
613 FunctionEntity function, void f(DartType type, String name)) { 633 return _elementMap.hasConstantFieldInitializer(field);
614 throw new UnimplementedError('KernelCodegenWorldBuilder.forEachParameter');
615 } 634 }
616 635
617 @override 636 @override
637 void forEachParameter(FunctionEntity function,
638 void f(DartType type, String name, ConstantValue defaultValue)) {
639 _elementMap.forEachParameter(function, f);
640 }
641
642 @override
618 void forEachInstanceField( 643 void forEachInstanceField(
619 ClassEntity cls, void f(ClassEntity declarer, FieldEntity field)) { 644 ClassEntity cls, void f(ClassEntity declarer, FieldEntity field)) {
620 _elementEnvironment.forEachClassMember(cls, 645 _elementEnvironment.forEachClassMember(cls,
621 (ClassEntity declarer, MemberEntity member) { 646 (ClassEntity declarer, MemberEntity member) {
622 if (member.isField && member.isInstanceMember) f(declarer, member); 647 if (member.isField && member.isInstanceMember) f(declarer, member);
623 }); 648 });
624 } 649 }
625 } 650 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698