| OLD | NEW |
| 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; | 5 library dart2js.ir_builder; |
| 6 | 6 |
| 7 import '../common/names.dart' show |
| 8 Names; |
| 7 import '../compile_time_constants.dart' show | 9 import '../compile_time_constants.dart' show |
| 8 BackendConstantEnvironment; | 10 BackendConstantEnvironment; |
| 9 import '../constants/constant_system.dart'; | 11 import '../constants/constant_system.dart'; |
| 10 import '../constants/values.dart' show | 12 import '../constants/values.dart' show |
| 11 ConstantValue, | 13 ConstantValue, |
| 12 PrimitiveConstantValue; | 14 PrimitiveConstantValue; |
| 13 import '../dart_types.dart'; | 15 import '../dart_types.dart'; |
| 14 import '../diagnostics/invariant.dart' show | 16 import '../diagnostics/invariant.dart' show |
| 15 invariant; | 17 invariant; |
| 16 import '../elements/elements.dart'; | 18 import '../elements/elements.dart'; |
| (...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 return _buildInvokeSuper(method, selector, arguments, sourceInformation); | 824 return _buildInvokeSuper(method, selector, arguments, sourceInformation); |
| 823 } | 825 } |
| 824 | 826 |
| 825 /// Create a read access of the [method] on the super class, i.e. a | 827 /// Create a read access of the [method] on the super class, i.e. a |
| 826 /// closurization of [method]. | 828 /// closurization of [method]. |
| 827 ir.Primitive buildSuperMethodGet(MethodElement method, | 829 ir.Primitive buildSuperMethodGet(MethodElement method, |
| 828 {SourceInformation sourceInformation}) { | 830 {SourceInformation sourceInformation}) { |
| 829 // TODO(johnniwinther): This should have its own ir node. | 831 // TODO(johnniwinther): This should have its own ir node. |
| 830 return _buildInvokeSuper( | 832 return _buildInvokeSuper( |
| 831 method, | 833 method, |
| 832 new Selector.getter(method.name, method.library), | 834 new Selector.getter(method.memberName), |
| 833 const <ir.Primitive>[], | 835 const <ir.Primitive>[], |
| 834 sourceInformation); | 836 sourceInformation); |
| 835 } | 837 } |
| 836 | 838 |
| 837 /// Create a getter invocation of the [getter] on the super class. | 839 /// Create a getter invocation of the [getter] on the super class. |
| 838 ir.Primitive buildSuperGetterGet(MethodElement getter, | 840 ir.Primitive buildSuperGetterGet(MethodElement getter, |
| 839 SourceInformation sourceInformation) { | 841 SourceInformation sourceInformation) { |
| 840 // TODO(johnniwinther): This should have its own ir node. | 842 // TODO(johnniwinther): This should have its own ir node. |
| 841 return _buildInvokeSuper( | 843 return _buildInvokeSuper( |
| 842 getter, | 844 getter, |
| 843 new Selector.getter(getter.name, getter.library), | 845 new Selector.getter(getter.memberName), |
| 844 const <ir.Primitive>[], | 846 const <ir.Primitive>[], |
| 845 sourceInformation); | 847 sourceInformation); |
| 846 } | 848 } |
| 847 | 849 |
| 848 /// Create an setter invocation of the [setter] on the super class with | 850 /// Create an setter invocation of the [setter] on the super class with |
| 849 /// [value]. | 851 /// [value]. |
| 850 ir.Primitive buildSuperSetterSet(MethodElement setter, | 852 ir.Primitive buildSuperSetterSet(MethodElement setter, |
| 851 ir.Primitive value, | 853 ir.Primitive value, |
| 852 {SourceInformation sourceInformation}) { | 854 {SourceInformation sourceInformation}) { |
| 853 // TODO(johnniwinther): This should have its own ir node. | 855 // TODO(johnniwinther): This should have its own ir node. |
| 854 _buildInvokeSuper( | 856 _buildInvokeSuper( |
| 855 setter, | 857 setter, |
| 856 new Selector.setter(setter.name, setter.library), | 858 new Selector.setter(setter.memberName), |
| 857 <ir.Primitive>[value], | 859 <ir.Primitive>[value], |
| 858 sourceInformation); | 860 sourceInformation); |
| 859 return value; | 861 return value; |
| 860 } | 862 } |
| 861 | 863 |
| 862 /// Create an invocation of the index [method] on the super class with | 864 /// Create an invocation of the index [method] on the super class with |
| 863 /// the provided [index]. | 865 /// the provided [index]. |
| 864 ir.Primitive buildSuperIndex(MethodElement method, | 866 ir.Primitive buildSuperIndex(MethodElement method, |
| 865 ir.Primitive index, | 867 ir.Primitive index, |
| 866 {SourceInformation sourceInformation}) { | 868 {SourceInformation sourceInformation}) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 /// initialized yet. | 1009 /// initialized yet. |
| 1008 ir.Primitive buildStaticFieldLazyGet(FieldElement field, | 1010 ir.Primitive buildStaticFieldLazyGet(FieldElement field, |
| 1009 SourceInformation sourceInformation) { | 1011 SourceInformation sourceInformation) { |
| 1010 return _continueWithExpression( | 1012 return _continueWithExpression( |
| 1011 (k) => new ir.GetLazyStatic(field, k, sourceInformation)); | 1013 (k) => new ir.GetLazyStatic(field, k, sourceInformation)); |
| 1012 } | 1014 } |
| 1013 | 1015 |
| 1014 /// Create a getter invocation of the static [getter]. | 1016 /// Create a getter invocation of the static [getter]. |
| 1015 ir.Primitive buildStaticGetterGet(MethodElement getter, | 1017 ir.Primitive buildStaticGetterGet(MethodElement getter, |
| 1016 SourceInformation sourceInformation) { | 1018 SourceInformation sourceInformation) { |
| 1017 Selector selector = new Selector.getter(getter.name, getter.library); | 1019 Selector selector = new Selector.getter(getter.memberName); |
| 1018 return _buildInvokeStatic( | 1020 return _buildInvokeStatic( |
| 1019 getter, selector, const <ir.Primitive>[], sourceInformation); | 1021 getter, selector, const <ir.Primitive>[], sourceInformation); |
| 1020 } | 1022 } |
| 1021 | 1023 |
| 1022 /// Create a read access of the static [function], i.e. a closurization of | 1024 /// Create a read access of the static [function], i.e. a closurization of |
| 1023 /// [function]. | 1025 /// [function]. |
| 1024 ir.Primitive buildStaticFunctionGet(MethodElement function, | 1026 ir.Primitive buildStaticFunctionGet(MethodElement function, |
| 1025 {SourceInformation sourceInformation}) { | 1027 {SourceInformation sourceInformation}) { |
| 1026 return addPrimitive(new ir.GetStatic(function, sourceInformation)); | 1028 return addPrimitive(new ir.GetStatic(function, sourceInformation)); |
| 1027 } | 1029 } |
| 1028 | 1030 |
| 1029 /// Create a write access to the static [field] with the [value]. | 1031 /// Create a write access to the static [field] with the [value]. |
| 1030 ir.Primitive buildStaticFieldSet(FieldElement field, | 1032 ir.Primitive buildStaticFieldSet(FieldElement field, |
| 1031 ir.Primitive value, | 1033 ir.Primitive value, |
| 1032 [SourceInformation sourceInformation]) { | 1034 [SourceInformation sourceInformation]) { |
| 1033 addPrimitive(new ir.SetStatic(field, value, sourceInformation)); | 1035 addPrimitive(new ir.SetStatic(field, value, sourceInformation)); |
| 1034 return value; | 1036 return value; |
| 1035 } | 1037 } |
| 1036 | 1038 |
| 1037 /// Create a setter invocation of the static [setter] with the [value]. | 1039 /// Create a setter invocation of the static [setter] with the [value]. |
| 1038 ir.Primitive buildStaticSetterSet(MethodElement setter, | 1040 ir.Primitive buildStaticSetterSet(MethodElement setter, |
| 1039 ir.Primitive value, | 1041 ir.Primitive value, |
| 1040 {SourceInformation sourceInformation}) { | 1042 {SourceInformation sourceInformation}) { |
| 1041 Selector selector = new Selector.setter(setter.name, setter.library); | 1043 Selector selector = new Selector.setter(setter.memberName); |
| 1042 _buildInvokeStatic( | 1044 _buildInvokeStatic( |
| 1043 setter, selector, <ir.Primitive>[value], sourceInformation); | 1045 setter, selector, <ir.Primitive>[value], sourceInformation); |
| 1044 return value; | 1046 return value; |
| 1045 } | 1047 } |
| 1046 | 1048 |
| 1047 /// Create an erroneous invocation where argument structure is defined by | 1049 /// Create an erroneous invocation where argument structure is defined by |
| 1048 /// [selector] and the argument values are defined by [arguments]. | 1050 /// [selector] and the argument values are defined by [arguments]. |
| 1049 // TODO(johnniwinther): Make this more fine-grained. | 1051 // TODO(johnniwinther): Make this more fine-grained. |
| 1050 ir.Primitive buildErroneousInvocation( | 1052 ir.Primitive buildErroneousInvocation( |
| 1051 Element element, | 1053 Element element, |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1349 // let prim expressionReceiver = [[e]] in | 1351 // let prim expressionReceiver = [[e]] in |
| 1350 // let cont iteratorInvoked(iterator) = | 1352 // let cont iteratorInvoked(iterator) = |
| 1351 // [ ] | 1353 // [ ] |
| 1352 // in expressionReceiver.iterator () iteratorInvoked | 1354 // in expressionReceiver.iterator () iteratorInvoked |
| 1353 ir.Primitive expressionReceiver = buildExpression(this); | 1355 ir.Primitive expressionReceiver = buildExpression(this); |
| 1354 List<ir.Primitive> emptyArguments = <ir.Primitive>[]; | 1356 List<ir.Primitive> emptyArguments = <ir.Primitive>[]; |
| 1355 ir.Parameter iterator = new ir.Parameter(null); | 1357 ir.Parameter iterator = new ir.Parameter(null); |
| 1356 ir.Continuation iteratorInvoked = new ir.Continuation([iterator]); | 1358 ir.Continuation iteratorInvoked = new ir.Continuation([iterator]); |
| 1357 add(new ir.LetCont(iteratorInvoked, | 1359 add(new ir.LetCont(iteratorInvoked, |
| 1358 new ir.InvokeMethod(expressionReceiver, | 1360 new ir.InvokeMethod(expressionReceiver, |
| 1359 new Selector.getter("iterator", null), | 1361 new Selector.getter(const PublicName("iterator")), |
| 1360 iteratorMask, | 1362 iteratorMask, |
| 1361 emptyArguments, | 1363 emptyArguments, |
| 1362 iteratorInvoked))); | 1364 iteratorInvoked))); |
| 1363 | 1365 |
| 1364 // Fill with: | 1366 // Fill with: |
| 1365 // let cont loop(x, ...) = | 1367 // let cont loop(x, ...) = |
| 1366 // let cont moveNextInvoked(condition) = | 1368 // let cont moveNextInvoked(condition) = |
| 1367 // [ ] | 1369 // [ ] |
| 1368 // in iterator.moveNext () moveNextInvoked | 1370 // in iterator.moveNext () moveNextInvoked |
| 1369 // in loop(v, ...) | 1371 // in loop(v, ...) |
| 1370 JumpCollector loop = new BackwardJumpCollector(environment, target: target); | 1372 JumpCollector loop = new BackwardJumpCollector(environment, target: target); |
| 1371 addRecursiveContinuation(loop); | 1373 addRecursiveContinuation(loop); |
| 1372 ir.Parameter condition = new ir.Parameter(null); | 1374 ir.Parameter condition = new ir.Parameter(null); |
| 1373 ir.Continuation moveNextInvoked = new ir.Continuation([condition]); | 1375 ir.Continuation moveNextInvoked = new ir.Continuation([condition]); |
| 1374 add(new ir.LetCont(moveNextInvoked, | 1376 add(new ir.LetCont(moveNextInvoked, |
| 1375 new ir.InvokeMethod(iterator, | 1377 new ir.InvokeMethod(iterator, |
| 1376 new Selector.call("moveNext", null, 0), | 1378 new Selector.call(Names.moveNext, 0), |
| 1377 moveNextMask, | 1379 moveNextMask, |
| 1378 emptyArguments, | 1380 emptyArguments, |
| 1379 moveNextInvoked))); | 1381 moveNextInvoked))); |
| 1380 | 1382 |
| 1381 // As a delimited term, build: | 1383 // As a delimited term, build: |
| 1382 // <<BODY>> = | 1384 // <<BODY>> = |
| 1383 // _enterScope(); | 1385 // _enterScope(); |
| 1384 // [[variableDeclaration]] | 1386 // [[variableDeclaration]] |
| 1385 // let cont currentInvoked(currentValue) = | 1387 // let cont currentInvoked(currentValue) = |
| 1386 // [[a = currentValue]]; | 1388 // [[a = currentValue]]; |
| 1387 // [ ] | 1389 // [ ] |
| 1388 // in iterator.current () currentInvoked | 1390 // in iterator.current () currentInvoked |
| 1389 IrBuilder bodyBuilder = makeDelimitedBuilder(); | 1391 IrBuilder bodyBuilder = makeDelimitedBuilder(); |
| 1390 bodyBuilder._enterScope(closureScope); | 1392 bodyBuilder._enterScope(closureScope); |
| 1391 if (buildVariableDeclaration != null) { | 1393 if (buildVariableDeclaration != null) { |
| 1392 buildVariableDeclaration(bodyBuilder); | 1394 buildVariableDeclaration(bodyBuilder); |
| 1393 } | 1395 } |
| 1394 ir.Parameter currentValue = new ir.Parameter(null); | 1396 ir.Parameter currentValue = new ir.Parameter(null); |
| 1395 ir.Continuation currentInvoked = new ir.Continuation([currentValue]); | 1397 ir.Continuation currentInvoked = new ir.Continuation([currentValue]); |
| 1396 bodyBuilder.add(new ir.LetCont(currentInvoked, | 1398 bodyBuilder.add(new ir.LetCont(currentInvoked, |
| 1397 new ir.InvokeMethod( | 1399 new ir.InvokeMethod( |
| 1398 iterator, | 1400 iterator, |
| 1399 new Selector.getter("current", null), | 1401 new Selector.getter(Names.current), |
| 1400 currentMask, | 1402 currentMask, |
| 1401 emptyArguments, currentInvoked))); | 1403 emptyArguments, currentInvoked))); |
| 1402 // TODO(sra): Does this cover all cases? The general setter case include | 1404 // TODO(sra): Does this cover all cases? The general setter case include |
| 1403 // super. | 1405 // super. |
| 1404 // TODO(johnniwinther): Extract this as a provided strategy. | 1406 // TODO(johnniwinther): Extract this as a provided strategy. |
| 1405 if (Elements.isLocal(variableElement)) { | 1407 if (Elements.isLocal(variableElement)) { |
| 1406 bodyBuilder.buildLocalVariableSet(variableElement, currentValue); | 1408 bodyBuilder.buildLocalVariableSet(variableElement, currentValue); |
| 1407 } else if (Elements.isErroneous(variableElement)) { | 1409 } else if (Elements.isErroneous(variableElement)) { |
| 1408 bodyBuilder.buildErroneousInvocation(variableElement, | 1410 bodyBuilder.buildErroneousInvocation(variableElement, |
| 1409 new Selector.setter(variableElement.name, variableElement.library), | 1411 new Selector.setter( |
| 1412 new Name(variableElement.name, variableElement.library)), |
| 1410 <ir.Primitive>[currentValue]); | 1413 <ir.Primitive>[currentValue]); |
| 1411 } else if (Elements.isStaticOrTopLevel(variableElement)) { | 1414 } else if (Elements.isStaticOrTopLevel(variableElement)) { |
| 1412 if (variableElement.isField) { | 1415 if (variableElement.isField) { |
| 1413 bodyBuilder.buildStaticFieldSet(variableElement, currentValue); | 1416 bodyBuilder.buildStaticFieldSet(variableElement, currentValue); |
| 1414 } else { | 1417 } else { |
| 1415 bodyBuilder.buildStaticSetterSet(variableElement, currentValue); | 1418 bodyBuilder.buildStaticSetterSet(variableElement, currentValue); |
| 1416 } | 1419 } |
| 1417 } else { | 1420 } else { |
| 1418 ir.Primitive receiver = bodyBuilder.buildThis(); | 1421 ir.Primitive receiver = bodyBuilder.buildThis(); |
| 1419 assert(receiver != null); | 1422 assert(receiver != null); |
| (...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2484 | 2487 |
| 2485 ir.Primitive buildSuperFieldGet(FieldElement target) { | 2488 ir.Primitive buildSuperFieldGet(FieldElement target) { |
| 2486 return addPrimitive(new ir.GetField(buildThis(), target)); | 2489 return addPrimitive(new ir.GetField(buildThis(), target)); |
| 2487 } | 2490 } |
| 2488 | 2491 |
| 2489 ir.Primitive buildSuperFieldSet(FieldElement target, ir.Primitive value) { | 2492 ir.Primitive buildSuperFieldSet(FieldElement target, ir.Primitive value) { |
| 2490 addPrimitive(new ir.SetField(buildThis(), target, value)); | 2493 addPrimitive(new ir.SetField(buildThis(), target, value)); |
| 2491 return value; | 2494 return value; |
| 2492 } | 2495 } |
| 2493 | 2496 |
| 2494 ir.Primitive buildInvokeDirectly(FunctionElement target, | 2497 ir.Primitive buildInvokeDirectly(MethodElement target, |
| 2495 ir.Primitive receiver, | 2498 ir.Primitive receiver, |
| 2496 List<ir.Primitive> arguments, | 2499 List<ir.Primitive> arguments, |
| 2497 {SourceInformation sourceInformation}) { | 2500 {SourceInformation sourceInformation}) { |
| 2498 assert(isOpen); | 2501 assert(isOpen); |
| 2499 Selector selector = | 2502 Selector selector = |
| 2500 new Selector.call(target.name, target.library, arguments.length); | 2503 new Selector.call(target.memberName, arguments.length); |
| 2501 return _continueWithExpression( | 2504 return _continueWithExpression( |
| 2502 (k) => new ir.InvokeMethodDirectly( | 2505 (k) => new ir.InvokeMethodDirectly( |
| 2503 receiver, target, selector, arguments, k, sourceInformation)); | 2506 receiver, target, selector, arguments, k, sourceInformation)); |
| 2504 } | 2507 } |
| 2505 | 2508 |
| 2506 /// Loads parameters to a constructor body into the environment. | 2509 /// Loads parameters to a constructor body into the environment. |
| 2507 /// | 2510 /// |
| 2508 /// The header for a constructor body differs from other functions in that | 2511 /// The header for a constructor body differs from other functions in that |
| 2509 /// some parameters are already boxed, and the box is passed as an argument | 2512 /// some parameters are already boxed, and the box is passed as an argument |
| 2510 /// instead of being created in the header. | 2513 /// instead of being created in the header. |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2801 } | 2804 } |
| 2802 | 2805 |
| 2803 class SwitchCaseInfo { | 2806 class SwitchCaseInfo { |
| 2804 final List<ir.Primitive> constants = <ir.Primitive>[]; | 2807 final List<ir.Primitive> constants = <ir.Primitive>[]; |
| 2805 final SubbuildFunction buildBody; | 2808 final SubbuildFunction buildBody; |
| 2806 | 2809 |
| 2807 SwitchCaseInfo(this.buildBody); | 2810 SwitchCaseInfo(this.buildBody); |
| 2808 | 2811 |
| 2809 void addConstant(ir.Primitive constant) => constants.add(constant); | 2812 void addConstant(ir.Primitive constant) => constants.add(constant); |
| 2810 } | 2813 } |
| OLD | NEW |