OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 8 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
9 import '../common/names.dart'; | 9 import '../common/names.dart'; |
10 import '../common/tasks.dart' show CompilerTask; | 10 import '../common/tasks.dart' show CompilerTask; |
11 import '../compiler.dart'; | 11 import '../compiler.dart'; |
12 import '../constants/values.dart' show StringConstantValue; | 12 import '../constants/values.dart' |
| 13 show |
| 14 ConstantValue, |
| 15 InterceptorConstantValue, |
| 16 StringConstantValue, |
| 17 TypeConstantValue; |
13 import '../dart_types.dart'; | 18 import '../dart_types.dart'; |
14 import '../elements/elements.dart'; | 19 import '../elements/elements.dart'; |
15 import '../io/source_information.dart'; | 20 import '../io/source_information.dart'; |
16 import '../js/js.dart' as js; | 21 import '../js/js.dart' as js; |
17 import '../js_backend/backend.dart' show JavaScriptBackend; | 22 import '../js_backend/backend.dart' show JavaScriptBackend; |
18 import '../kernel/kernel.dart'; | 23 import '../kernel/kernel.dart'; |
19 import '../native/native.dart' as native; | 24 import '../native/native.dart' as native; |
20 import '../resolution/tree_elements.dart'; | 25 import '../resolution/tree_elements.dart'; |
21 import '../tree/dartstring.dart'; | 26 import '../tree/dartstring.dart'; |
22 import '../tree/nodes.dart' show FunctionExpression, Node; | 27 import '../tree/nodes.dart' show FunctionExpression, Node; |
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 | 866 |
862 @override | 867 @override |
863 void visitMapEntry(ir.MapEntry mapEntry) { | 868 void visitMapEntry(ir.MapEntry mapEntry) { |
864 // Visit value before the key because each will push an expression to the | 869 // Visit value before the key because each will push an expression to the |
865 // stack, so when we pop them off, the key is popped first, then the value. | 870 // stack, so when we pop them off, the key is popped first, then the value. |
866 mapEntry.value.accept(this); | 871 mapEntry.value.accept(this); |
867 mapEntry.key.accept(this); | 872 mapEntry.key.accept(this); |
868 } | 873 } |
869 | 874 |
870 @override | 875 @override |
| 876 void visitTypeLiteral(ir.TypeLiteral typeLiteral) { |
| 877 ir.DartType type = typeLiteral.type; |
| 878 if (type is ir.InterfaceType) { |
| 879 ConstantValue constant = astAdapter.getConstantForType(type); |
| 880 stack.add(graph.addConstant(constant, compiler)); |
| 881 return; |
| 882 } |
| 883 if (type is ir.TypeParameterType) { |
| 884 // TODO(27394): Load type parameter from current 'this' object. |
| 885 defaultExpression(typeLiteral); |
| 886 return; |
| 887 } |
| 888 // TODO(27394): 'dynamic' and function types observed. Where are they from? |
| 889 defaultExpression(typeLiteral); |
| 890 return; |
| 891 } |
| 892 |
| 893 @override |
871 void visitStaticGet(ir.StaticGet staticGet) { | 894 void visitStaticGet(ir.StaticGet staticGet) { |
872 ir.Member staticTarget = staticGet.target; | 895 ir.Member staticTarget = staticGet.target; |
873 if (staticTarget is ir.Procedure && | 896 if (staticTarget is ir.Procedure && |
874 staticTarget.kind == ir.ProcedureKind.Getter) { | 897 staticTarget.kind == ir.ProcedureKind.Getter) { |
875 // Invoke the getter | 898 // Invoke the getter |
876 _pushStaticInvocation(staticTarget, const <HInstruction>[], | 899 _pushStaticInvocation(staticTarget, const <HInstruction>[], |
877 astAdapter.returnTypeOf(staticTarget)); | 900 astAdapter.returnTypeOf(staticTarget)); |
878 } else if (staticTarget is ir.Field && staticTarget.isConst) { | 901 } else if (staticTarget is ir.Field && staticTarget.isConst) { |
879 assert(staticTarget.initializer != null); | 902 assert(staticTarget.initializer != null); |
880 stack.add(graph.addConstant( | 903 stack.add(graph.addConstant( |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 default: | 1327 default: |
1305 compiler.reporter.reportErrorMessage( | 1328 compiler.reporter.reportErrorMessage( |
1306 astAdapter.getNode(invocation), | 1329 astAdapter.getNode(invocation), |
1307 MessageKind.GENERIC, | 1330 MessageKind.GENERIC, |
1308 {'text': 'Error: Unknown internal flag "$name".'}); | 1331 {'text': 'Error: Unknown internal flag "$name".'}); |
1309 } | 1332 } |
1310 stack.add(graph.addConstantBool(value, compiler)); | 1333 stack.add(graph.addConstantBool(value, compiler)); |
1311 } | 1334 } |
1312 | 1335 |
1313 void handleJsInterceptorConstant(ir.StaticInvocation invocation) { | 1336 void handleJsInterceptorConstant(ir.StaticInvocation invocation) { |
1314 unhandledForeign(invocation); | 1337 // Single argument must be a TypeConstant which is converted into a |
| 1338 // InterceptorConstant. |
| 1339 if (_unexpectedForeignArguments(invocation, 1, 1)) { |
| 1340 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. |
| 1341 return; |
| 1342 } |
| 1343 ir.Expression argument = invocation.arguments.positional.single; |
| 1344 argument.accept(this); |
| 1345 HInstruction argumentInstruction = pop(); |
| 1346 if (argumentInstruction is HConstant) { |
| 1347 ConstantValue argumentConstant = argumentInstruction.constant; |
| 1348 if (argumentConstant is TypeConstantValue) { |
| 1349 // TODO(sra): Check that type is a subclass of [Interceptor]. |
| 1350 ConstantValue constant = |
| 1351 new InterceptorConstantValue(argumentConstant.representedType); |
| 1352 HInstruction instruction = graph.addConstant(constant, compiler); |
| 1353 stack.add(instruction); |
| 1354 return; |
| 1355 } |
| 1356 } |
| 1357 |
| 1358 compiler.reporter.reportErrorMessage(astAdapter.getNode(invocation), |
| 1359 MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT); |
| 1360 stack.add(graph.addConstantNull(compiler)); |
1315 } | 1361 } |
1316 | 1362 |
1317 void handleForeignJs(ir.StaticInvocation invocation) { | 1363 void handleForeignJs(ir.StaticInvocation invocation) { |
1318 if (_unexpectedForeignArguments(invocation, 2)) { | 1364 if (_unexpectedForeignArguments(invocation, 2)) { |
1319 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. | 1365 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. |
1320 return; | 1366 return; |
1321 } | 1367 } |
1322 | 1368 |
1323 native.NativeBehavior nativeBehavior = | 1369 native.NativeBehavior nativeBehavior = |
1324 astAdapter.getNativeBehavior(invocation); | 1370 astAdapter.getNativeBehavior(invocation); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1507 push(new HNot(popBoolified(), backend.boolType)); | 1553 push(new HNot(popBoolified(), backend.boolType)); |
1508 } | 1554 } |
1509 | 1555 |
1510 @override | 1556 @override |
1511 void visitStringConcatenation(ir.StringConcatenation stringConcat) { | 1557 void visitStringConcatenation(ir.StringConcatenation stringConcat) { |
1512 KernelStringBuilder stringBuilder = new KernelStringBuilder(this); | 1558 KernelStringBuilder stringBuilder = new KernelStringBuilder(this); |
1513 stringConcat.accept(stringBuilder); | 1559 stringConcat.accept(stringBuilder); |
1514 stack.add(stringBuilder.result); | 1560 stack.add(stringBuilder.result); |
1515 } | 1561 } |
1516 } | 1562 } |
OLD | NEW |