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

Side by Side Diff: pkg/compiler/lib/src/kernel/element_map_impl.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 library dart2js.kernel.element_map; 5 library dart2js.kernel.element_map;
6 6
7 import 'package:kernel/ast.dart' as ir; 7 import 'package:kernel/ast.dart' as ir;
8 import 'package:kernel/clone.dart'; 8 import 'package:kernel/clone.dart';
9 import 'package:kernel/type_algebra.dart'; 9 import 'package:kernel/type_algebra.dart';
10 10
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 native.BehaviorBuilder get nativeBehaviorBuilder => _nativeBehaviorBuilder; 135 native.BehaviorBuilder get nativeBehaviorBuilder => _nativeBehaviorBuilder;
136 136
137 @override 137 @override
138 ConstantValue computeConstantValue(ConstantExpression constant, 138 ConstantValue computeConstantValue(ConstantExpression constant,
139 {bool requireConstant: true}) { 139 {bool requireConstant: true}) {
140 return _constantEnvironment.getConstantValue(constant); 140 return _constantEnvironment.getConstantValue(constant);
141 } 141 }
142 142
143 @override 143 @override
144 ConstantValue getFieldConstantValue(ir.Field field) { 144 ConstantValue getFieldConstantValue(ir.Field field) {
145 // TODO(johnniwinther): Cache the result in [_FieldData].
145 return getConstantValue(field.initializer, requireConstant: field.isConst); 146 return getConstantValue(field.initializer, requireConstant: field.isConst);
146 } 147 }
147 148
148 LibraryEntity lookupLibrary(Uri uri) { 149 LibraryEntity lookupLibrary(Uri uri) {
149 _KLibraryEnv libraryEnv = _env.lookupLibrary(uri); 150 _KLibraryEnv libraryEnv = _env.lookupLibrary(uri);
150 if (libraryEnv == null) return null; 151 if (libraryEnv == null) return null;
151 return _getLibrary(libraryEnv.library, libraryEnv); 152 return _getLibrary(libraryEnv.library, libraryEnv);
152 } 153 }
153 154
154 KLibrary _getLibrary(ir.Library node, [_KLibraryEnv libraryEnv]) { 155 KLibrary _getLibrary(ir.Library node, [_KLibraryEnv libraryEnv]) {
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 668
668 @override 669 @override
669 Local getLocalFunction(ir.TreeNode node) => _getLocal(node); 670 Local getLocalFunction(ir.TreeNode node) => _getLocal(node);
670 671
671 @override 672 @override
672 ClassEntity getClass(ir.Class node) => _getClass(node); 673 ClassEntity getClass(ir.Class node) => _getClass(node);
673 674
674 @override 675 @override
675 FieldEntity getField(ir.Field node) => _getField(node); 676 FieldEntity getField(ir.Field node) => _getField(node);
676 677
678 bool hasConstantFieldInitializer(KField field) {
679 _FieldData data = _memberList[field.memberIndex];
680 return getFieldConstantValue(data.node) != null;
681 }
682
677 TypeVariableEntity getTypeVariable(ir.TypeParameter node) => 683 TypeVariableEntity getTypeVariable(ir.TypeParameter node) =>
678 _getTypeVariable(node); 684 _getTypeVariable(node);
679 685
680 @override 686 @override
681 FunctionEntity getMethod(ir.Procedure node) => _getMethod(node); 687 FunctionEntity getMethod(ir.Procedure node) => _getMethod(node);
682 688
689 void forEachParameter(KFunction function,
690 void f(DartType type, String name, ConstantValue defaultValue)) {
691 _FunctionData data = _memberList[function.memberIndex];
692 data.forEachParameter(this, f);
693 }
694
683 @override 695 @override
684 MemberEntity getMember(ir.Member node) { 696 MemberEntity getMember(ir.Member node) {
685 if (node is ir.Field) { 697 if (node is ir.Field) {
686 return _getField(node); 698 return _getField(node);
687 } else if (node is ir.Constructor) { 699 } else if (node is ir.Constructor) {
688 return _getConstructor(node); 700 return _getConstructor(node);
689 } else if (node is ir.Procedure) { 701 } else if (node is ir.Procedure) {
690 if (node.kind == ir.ProcedureKind.Factory) { 702 if (node.kind == ir.ProcedureKind.Factory) {
691 return _getConstructor(node); 703 return _getConstructor(node);
692 } else { 704 } else {
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 1072
1061 class _FunctionData extends _MemberData { 1073 class _FunctionData extends _MemberData {
1062 final ir.FunctionNode functionNode; 1074 final ir.FunctionNode functionNode;
1063 FunctionType _type; 1075 FunctionType _type;
1064 1076
1065 _FunctionData(ir.Member node, this.functionNode) : super(node); 1077 _FunctionData(ir.Member node, this.functionNode) : super(node);
1066 1078
1067 FunctionType getFunctionType(KernelToElementMapImpl elementMap) { 1079 FunctionType getFunctionType(KernelToElementMapImpl elementMap) {
1068 return _type ??= elementMap.getFunctionType(functionNode); 1080 return _type ??= elementMap.getFunctionType(functionNode);
1069 } 1081 }
1082
1083 void forEachParameter(KernelToElementMap elementMap,
1084 void f(DartType type, String name, ConstantValue defaultValue)) {
1085 void handleParameter(ir.VariableDeclaration node, {bool isOptional: true}) {
1086 DartType type = elementMap.getDartType(node.type);
1087 String name = node.name;
1088 ConstantValue defaultValue;
1089 if (isOptional) {
1090 if (node.initializer != null) {
1091 defaultValue = elementMap.getConstantValue(node.initializer);
1092 } else {
1093 defaultValue = new NullConstantValue();
1094 }
1095 }
1096 f(type, name, defaultValue);
1097 }
1098
1099 for (int i = 0; i < functionNode.positionalParameters.length; i++) {
1100 handleParameter(functionNode.positionalParameters[i],
1101 isOptional: i < functionNode.requiredParameterCount);
1102 }
1103 functionNode.namedParameters.toList()
Siggi Cherem (dart-lang) 2017/06/16 16:31:09 alternatively - we could mutate the original once,
Johnni Winther 2017/06/19 12:45:42 I don't like mutating our input (and relying upon
1104 ..sort(namedOrdering).forEach(handleParameter);
Johnni Winther 2017/06/16 12:57:17 .forEach changed to ..forEach before commit
1105 }
1070 } 1106 }
1071 1107
1072 class _ConstructorData extends _FunctionData { 1108 class _ConstructorData extends _FunctionData {
1073 ConstantConstructor _constantConstructor; 1109 ConstantConstructor _constantConstructor;
1074 1110
1075 _ConstructorData(ir.Member node, ir.FunctionNode functionNode) 1111 _ConstructorData(ir.Member node, ir.FunctionNode functionNode)
1076 : super(node, functionNode); 1112 : super(node, functionNode);
1077 1113
1078 ConstantConstructor getConstructorConstant( 1114 ConstantConstructor getConstructorConstant(
1079 KernelToElementMapImpl elementMap, KConstructor constructor) { 1115 KernelToElementMapImpl elementMap, KConstructor constructor) {
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
1826 @override 1862 @override
1827 DiagnosticReporter get reporter { 1863 DiagnosticReporter get reporter {
1828 return _elementMap.reporter; 1864 return _elementMap.reporter;
1829 } 1865 }
1830 1866
1831 @override 1867 @override
1832 ConstantValue getFieldConstantValue(ir.Field field) { 1868 ConstantValue getFieldConstantValue(ir.Field field) {
1833 throw new UnsupportedError("JsKernelToElementMap.getFieldConstantValue"); 1869 throw new UnsupportedError("JsKernelToElementMap.getFieldConstantValue");
1834 } 1870 }
1835 } 1871 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/kernel/element_map.dart ('k') | pkg/compiler/lib/src/kernel/kernel_backend_strategy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698