| OLD | NEW |
| 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 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/backend_api.dart'; | 8 import '../common/backend_api.dart'; |
| 9 import '../common/names.dart'; | 9 import '../common/names.dart'; |
| 10 import '../compile_time_constants.dart'; | 10 import '../compile_time_constants.dart'; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 <ir.TypeParameter, KTypeVariable>{}; | 50 <ir.TypeParameter, KTypeVariable>{}; |
| 51 | 51 |
| 52 Map<ir.Member, KConstructor> _constructorMap = <ir.Member, KConstructor>{}; | 52 Map<ir.Member, KConstructor> _constructorMap = <ir.Member, KConstructor>{}; |
| 53 // TODO(johnniwinther): Change this to a list of 'KConstructorData' class | 53 // TODO(johnniwinther): Change this to a list of 'KConstructorData' class |
| 54 // holding the [ConstantConstructor] if we need more data for constructors. | 54 // holding the [ConstantConstructor] if we need more data for constructors. |
| 55 List<ir.Member> _constructorList = <ir.Member>[]; | 55 List<ir.Member> _constructorList = <ir.Member>[]; |
| 56 Map<KConstructor, ConstantConstructor> _constructorConstantMap = | 56 Map<KConstructor, ConstantConstructor> _constructorConstantMap = |
| 57 <KConstructor, ConstantConstructor>{}; | 57 <KConstructor, ConstantConstructor>{}; |
| 58 | 58 |
| 59 Map<ir.Procedure, KFunction> _methodMap = <ir.Procedure, KFunction>{}; | 59 Map<ir.Procedure, KFunction> _methodMap = <ir.Procedure, KFunction>{}; |
| 60 |
| 60 Map<ir.Field, KField> _fieldMap = <ir.Field, KField>{}; | 61 Map<ir.Field, KField> _fieldMap = <ir.Field, KField>{}; |
| 62 // TODO(johnniwinther): Change this to a list of 'KFieldData' class |
| 63 // holding the [ConstantExpression] if we need more data for fields. |
| 64 List<ir.Field> _fieldList = <ir.Field>[]; |
| 65 Map<KField, ConstantExpression> _fieldConstantMap = |
| 66 <KField, ConstantExpression>{}; |
| 67 |
| 61 Map<ir.TreeNode, KLocalFunction> _localFunctionMap = | 68 Map<ir.TreeNode, KLocalFunction> _localFunctionMap = |
| 62 <ir.TreeNode, KLocalFunction>{}; | 69 <ir.TreeNode, KLocalFunction>{}; |
| 63 | 70 |
| 64 KernelWorldBuilder(this.reporter, ir.Program program) | 71 KernelWorldBuilder(this.reporter, ir.Program program) |
| 65 : _env = new KEnv(program) { | 72 : _env = new KEnv(program) { |
| 66 _elementEnvironment = new KernelElementEnvironment(this); | 73 _elementEnvironment = new KernelElementEnvironment(this); |
| 67 _commonElements = new KernelCommonElements(_elementEnvironment); | 74 _commonElements = new KernelCommonElements(_elementEnvironment); |
| 68 BackendHelpers helpers = | |
| 69 new BackendHelpers(_elementEnvironment, null, _commonElements); | |
| 70 ConstantEnvironment constants = new KernelConstantEnvironment(this); | 75 ConstantEnvironment constants = new KernelConstantEnvironment(this); |
| 71 _nativeBehaviorBuilder = | 76 _nativeBehaviorBuilder = |
| 72 new KernelBehaviorBuilder(_commonElements, helpers, constants); | 77 new KernelBehaviorBuilder(_commonElements, helpers, constants); |
| 73 _typeConverter = new DartTypeConverter(this); | 78 _typeConverter = new DartTypeConverter(this); |
| 74 } | 79 } |
| 75 | 80 |
| 81 @override |
| 76 CommonElements get commonElements => _commonElements; | 82 CommonElements get commonElements => _commonElements; |
| 77 | 83 |
| 84 @override |
| 78 ElementEnvironment get elementEnvironment => _elementEnvironment; | 85 ElementEnvironment get elementEnvironment => _elementEnvironment; |
| 79 | 86 |
| 87 @override |
| 80 native.BehaviorBuilder get nativeBehaviorBuilder => _nativeBehaviorBuilder; | 88 native.BehaviorBuilder get nativeBehaviorBuilder => _nativeBehaviorBuilder; |
| 81 | 89 |
| 82 LibraryEntity lookupLibrary(Uri uri) { | 90 LibraryEntity lookupLibrary(Uri uri) { |
| 83 KLibraryEnv libraryEnv = _env.lookupLibrary(uri); | 91 KLibraryEnv libraryEnv = _env.lookupLibrary(uri); |
| 84 return _getLibrary(libraryEnv.library, libraryEnv); | 92 return _getLibrary(libraryEnv.library, libraryEnv); |
| 85 } | 93 } |
| 86 | 94 |
| 87 KLibrary _getLibrary(ir.Library node, [KLibraryEnv libraryEnv]) { | 95 KLibrary _getLibrary(ir.Library node, [KLibraryEnv libraryEnv]) { |
| 88 return _libraryMap.putIfAbsent(node, () { | 96 return _libraryMap.putIfAbsent(node, () { |
| 89 _libraryEnvs.add(libraryEnv ?? _env.lookupLibrary(node.importUri)); | 97 _libraryEnvs.add(libraryEnv ?? _env.lookupLibrary(node.importUri)); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 return new KMethod(enclosingClass, name, isStatic: isStatic); | 206 return new KMethod(enclosingClass, name, isStatic: isStatic); |
| 199 case ir.ProcedureKind.Setter: | 207 case ir.ProcedureKind.Setter: |
| 200 return new KSetter(enclosingClass, getName(node.name).setter, | 208 return new KSetter(enclosingClass, getName(node.name).setter, |
| 201 isStatic: isStatic); | 209 isStatic: isStatic); |
| 202 } | 210 } |
| 203 }); | 211 }); |
| 204 } | 212 } |
| 205 | 213 |
| 206 KField _getField(ir.Field node) { | 214 KField _getField(ir.Field node) { |
| 207 return _fieldMap.putIfAbsent(node, () { | 215 return _fieldMap.putIfAbsent(node, () { |
| 216 int fieldIndex = _fieldList.length; |
| 208 KClass enclosingClass = | 217 KClass enclosingClass = |
| 209 node.enclosingClass != null ? _getClass(node.enclosingClass) : null; | 218 node.enclosingClass != null ? _getClass(node.enclosingClass) : null; |
| 210 Name name = getName(node.name); | 219 Name name = getName(node.name); |
| 211 bool isStatic = node.isStatic; | 220 bool isStatic = node.isStatic; |
| 212 return new KField(enclosingClass, name, | 221 _fieldList.add(node); |
| 222 return new KField(fieldIndex, enclosingClass, name, |
| 213 isStatic: isStatic, isAssignable: node.isMutable); | 223 isStatic: isStatic, isAssignable: node.isMutable); |
| 214 }); | 224 }); |
| 215 } | 225 } |
| 216 | 226 |
| 217 KLocalFunction _getLocal(ir.TreeNode node) { | 227 KLocalFunction _getLocal(ir.TreeNode node) { |
| 218 return _localFunctionMap.putIfAbsent(node, () { | 228 return _localFunctionMap.putIfAbsent(node, () { |
| 219 MemberEntity memberContext; | 229 MemberEntity memberContext; |
| 220 Entity executableContext; | 230 Entity executableContext; |
| 221 ir.TreeNode parent = node.parent; | 231 ir.TreeNode parent = node.parent; |
| 222 while (parent != null) { | 232 while (parent != null) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 | 359 |
| 350 @override | 360 @override |
| 351 FunctionEntity getConstructor(ir.Member node) => _getConstructor(node); | 361 FunctionEntity getConstructor(ir.Member node) => _getConstructor(node); |
| 352 | 362 |
| 353 ConstantConstructor _getConstructorConstant(KConstructor constructor) { | 363 ConstantConstructor _getConstructorConstant(KConstructor constructor) { |
| 354 return _constructorConstantMap.putIfAbsent(constructor, () { | 364 return _constructorConstantMap.putIfAbsent(constructor, () { |
| 355 ir.Member node = _constructorList[constructor.constructorIndex]; | 365 ir.Member node = _constructorList[constructor.constructorIndex]; |
| 356 if (node is ir.Constructor && node.isConst) { | 366 if (node is ir.Constructor && node.isConst) { |
| 357 return new Constantifier(this).computeConstantConstructor(node); | 367 return new Constantifier(this).computeConstantConstructor(node); |
| 358 } | 368 } |
| 359 throw new SpannableAssertionFailure(constructor, | 369 throw new SpannableAssertionFailure( |
| 360 "Unexpected constructor $constructor in KernelWorldBuilder._getConstru
ctorConstant"); | 370 constructor, |
| 371 "Unexpected constructor $constructor in " |
| 372 "KernelWorldBuilder._getConstructorConstant"); |
| 373 }); |
| 374 } |
| 375 |
| 376 ConstantExpression _getFieldConstant(KField field) { |
| 377 return _fieldConstantMap.putIfAbsent(field, () { |
| 378 ir.Field node = _fieldList[field.fieldIndex]; |
| 379 if (node.isConst) { |
| 380 return node.initializer.accept(new Constantifier(this)); |
| 381 } |
| 382 throw new SpannableAssertionFailure( |
| 383 field, |
| 384 "Unexpected field $field in " |
| 385 "KernelWorldBuilder._getConstructorConstant"); |
| 361 }); | 386 }); |
| 362 } | 387 } |
| 363 } | 388 } |
| 364 | 389 |
| 365 /// Environment for fast lookup of program libraries. | 390 /// Environment for fast lookup of program libraries. |
| 366 class KEnv { | 391 class KEnv { |
| 367 final ir.Program program; | 392 final ir.Program program; |
| 368 | 393 |
| 369 Map<Uri, KLibraryEnv> _libraryMap; | 394 Map<Uri, KLibraryEnv> _libraryMap; |
| 370 | 395 |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 return base; | 752 return base; |
| 728 } | 753 } |
| 729 | 754 |
| 730 @override | 755 @override |
| 731 ConstantConstructor getConstructorConstant(ConstructorEntity constructor) { | 756 ConstantConstructor getConstructorConstant(ConstructorEntity constructor) { |
| 732 return _worldBuilder._getConstructorConstant(constructor); | 757 return _worldBuilder._getConstructorConstant(constructor); |
| 733 } | 758 } |
| 734 | 759 |
| 735 @override | 760 @override |
| 736 ConstantExpression getFieldConstant(FieldEntity field) { | 761 ConstantExpression getFieldConstant(FieldEntity field) { |
| 737 throw new UnimplementedError("_EvaluationEnvironment.getFieldConstant"); | 762 return _worldBuilder._getFieldConstant(field); |
| 738 } | 763 } |
| 739 | 764 |
| 740 @override | 765 @override |
| 741 ConstantExpression getLocalConstant(Local local) { | 766 ConstantExpression getLocalConstant(Local local) { |
| 742 throw new UnimplementedError("_EvaluationEnvironment.getLocalConstant"); | 767 throw new UnimplementedError("_EvaluationEnvironment.getLocalConstant"); |
| 743 } | 768 } |
| 744 | 769 |
| 745 @override | 770 @override |
| 746 String readFromEnvironment(String name) { | 771 String readFromEnvironment(String name) { |
| 747 throw new UnimplementedError("_EvaluationEnvironment.readFromEnvironment"); | 772 throw new UnimplementedError("_EvaluationEnvironment.readFromEnvironment"); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 775 } | 800 } |
| 776 return builder._getLibrary(library); | 801 return builder._getLibrary(library); |
| 777 } | 802 } |
| 778 | 803 |
| 779 KLibrary getLibraryForFunction(KFunction function) => | 804 KLibrary getLibraryForFunction(KFunction function) => |
| 780 _getLibrary(function, builder._methodMap); | 805 _getLibrary(function, builder._methodMap); |
| 781 | 806 |
| 782 KLibrary getLibraryForField(KField field) => | 807 KLibrary getLibraryForField(KField field) => |
| 783 _getLibrary(field, builder._fieldMap); | 808 _getLibrary(field, builder._fieldMap); |
| 784 } | 809 } |
| OLD | NEW |