| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 native; | 5 library native; |
| 6 | 6 |
| 7 import 'dart:collection' show Queue; | 7 import 'dart:collection' show Queue; |
| 8 import 'dart2jslib.dart'; | 8 import 'dart2jslib.dart'; |
| 9 import 'dart_types.dart'; | 9 import 'dart_types.dart'; |
| 10 import 'elements/elements.dart'; | 10 import 'elements/elements.dart'; |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 if (name.contains('Error')) return true; | 530 if (name.contains('Error')) return true; |
| 531 return false; | 531 return false; |
| 532 }, | 532 }, |
| 533 'native exception'); | 533 'native exception'); |
| 534 } | 534 } |
| 535 } | 535 } |
| 536 | 536 |
| 537 | 537 |
| 538 class NativeResolutionEnqueuer extends NativeEnqueuerBase { | 538 class NativeResolutionEnqueuer extends NativeEnqueuerBase { |
| 539 | 539 |
| 540 Map<String, ClassElement> tagOwner = new Map<String, ClassElement>(); |
| 541 |
| 540 NativeResolutionEnqueuer(Enqueuer world, Compiler compiler) | 542 NativeResolutionEnqueuer(Enqueuer world, Compiler compiler) |
| 541 : super(world, compiler, compiler.enableNativeLiveTypeAnalysis); | 543 : super(world, compiler, compiler.enableNativeLiveTypeAnalysis); |
| 542 | 544 |
| 545 void processNativeClass(ClassElement classElement) { |
| 546 super.processNativeClass(classElement); |
| 547 |
| 548 // Since we map from dispatch tags to classes, a dispatch tag must be used |
| 549 // on only one native class. |
| 550 for (String tag in nativeTagsOfClass(classElement)) { |
| 551 ClassElement owner = tagOwner[tag]; |
| 552 if (owner != null) { |
| 553 compiler.reportError(classElement, |
| 554 MessageKind.GENERIC, |
| 555 {'text': "Tag '$tag' already in use by '${owner.name}'"}); |
| 556 } else { |
| 557 tagOwner[tag] = classElement; |
| 558 } |
| 559 } |
| 560 } |
| 561 |
| 543 void logSummary(log(message)) { | 562 void logSummary(log(message)) { |
| 544 log('Resolved ${registeredClasses.length} native elements used, ' | 563 log('Resolved ${registeredClasses.length} native elements used, ' |
| 545 '${unusedClasses.length} native elements dead.'); | 564 '${unusedClasses.length} native elements dead.'); |
| 546 } | 565 } |
| 547 } | 566 } |
| 548 | 567 |
| 549 | 568 |
| 550 class NativeCodegenEnqueuer extends NativeEnqueuerBase { | 569 class NativeCodegenEnqueuer extends NativeEnqueuerBase { |
| 551 | 570 |
| 552 final CodeEmitterTask emitter; | 571 final CodeEmitterTask emitter; |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 Node node = listener.nodes.head; | 1060 Node node = listener.nodes.head; |
| 1042 if (node != null | 1061 if (node != null |
| 1043 && node.asIdentifier() != null | 1062 && node.asIdentifier() != null |
| 1044 && node.asIdentifier().source == 'native') { | 1063 && node.asIdentifier().source == 'native') { |
| 1045 nativeTagInfo = node.asIdentifier().token.next.value; | 1064 nativeTagInfo = node.asIdentifier().token.next.value; |
| 1046 listener.popNode(); | 1065 listener.popNode(); |
| 1047 } | 1066 } |
| 1048 return nativeTagInfo; | 1067 return nativeTagInfo; |
| 1049 } | 1068 } |
| 1050 | 1069 |
| 1070 // The tags string contains comma-separated 'words' which are either dispatch |
| 1071 // tags (having JavaScript identifier syntax) and directives that begin with |
| 1072 // `!`. |
| 1073 List<String> nativeTagsOfClassRaw(ClassElement cls) { |
| 1074 String quotedName = cls.nativeTagInfo; |
| 1075 return quotedName.substring(1, quotedName.length - 1).split(','); |
| 1076 } |
| 1077 |
| 1078 List<String> nativeTagsOfClass(ClassElement cls) { |
| 1079 return nativeTagsOfClassRaw(cls).where((s) => !s.startsWith('!')).toList(); |
| 1080 } |
| 1081 |
| 1082 bool nativeTagsForcedNonLeaf(ClassElement cls) => |
| 1083 nativeTagsOfClassRaw(cls).contains('!nonleaf'); |
| 1084 |
| 1085 |
| 1051 final RegExp nativeRedirectionRegExp = new RegExp(r'^[a-zA-Z][a-zA-Z_$0-9]*$'); | 1086 final RegExp nativeRedirectionRegExp = new RegExp(r'^[a-zA-Z][a-zA-Z_$0-9]*$'); |
| 1052 | 1087 |
| 1053 void handleSsaNative(SsaBuilder builder, Expression nativeBody) { | 1088 void handleSsaNative(SsaBuilder builder, Expression nativeBody) { |
| 1054 Compiler compiler = builder.compiler; | 1089 Compiler compiler = builder.compiler; |
| 1055 FunctionElement element = builder.work.element; | 1090 FunctionElement element = builder.work.element; |
| 1056 NativeEmitter nativeEmitter = builder.nativeEmitter; | 1091 NativeEmitter nativeEmitter = builder.nativeEmitter; |
| 1057 JavaScriptBackend backend = builder.backend; | 1092 JavaScriptBackend backend = builder.backend; |
| 1058 | 1093 |
| 1059 HInstruction convertDartClosure(Element parameter, FunctionType type) { | 1094 HInstruction convertDartClosure(Element parameter, FunctionType type) { |
| 1060 HInstruction local = builder.localsHandler.readLocal(parameter); | 1095 HInstruction local = builder.localsHandler.readLocal(parameter); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1138 } | 1173 } |
| 1139 LiteralString jsCode = nativeBody.asLiteralString(); | 1174 LiteralString jsCode = nativeBody.asLiteralString(); |
| 1140 builder.push(new HForeign.statement( | 1175 builder.push(new HForeign.statement( |
| 1141 new js.LiteralStatement(jsCode.dartString.slowToString()), | 1176 new js.LiteralStatement(jsCode.dartString.slowToString()), |
| 1142 <HInstruction>[], | 1177 <HInstruction>[], |
| 1143 new SideEffects(), | 1178 new SideEffects(), |
| 1144 null, | 1179 null, |
| 1145 backend.dynamicType)); | 1180 backend.dynamicType)); |
| 1146 } | 1181 } |
| 1147 } | 1182 } |
| OLD | NEW |