| 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 325 |
| 326 /// Returns the JSName annotation string or `null` if no JSName annotation is | 326 /// Returns the JSName annotation string or `null` if no JSName annotation is |
| 327 /// present. | 327 /// present. |
| 328 String findJsNameFromAnnotation(Element element) { | 328 String findJsNameFromAnnotation(Element element) { |
| 329 String name = null; | 329 String name = null; |
| 330 ClassElement annotationClass = annotationJsNameClass; | 330 ClassElement annotationClass = annotationJsNameClass; |
| 331 for (Link<MetadataAnnotation> link = element.metadata; | 331 for (Link<MetadataAnnotation> link = element.metadata; |
| 332 !link.isEmpty; | 332 !link.isEmpty; |
| 333 link = link.tail) { | 333 link = link.tail) { |
| 334 MetadataAnnotation annotation = link.head.ensureResolved(compiler); | 334 MetadataAnnotation annotation = link.head.ensureResolved(compiler); |
| 335 var value = annotation.value; | 335 var value = annotation.constant; |
| 336 if (value is! ConstructedConstant) continue; | 336 if (value is! ConstructedConstant) continue; |
| 337 if (value.type is! InterfaceType) continue; | 337 if (value.type is! InterfaceType) continue; |
| 338 if (!identical(value.type.element, annotationClass)) continue; | 338 if (!identical(value.type.element, annotationClass)) continue; |
| 339 | 339 |
| 340 var fields = value.fields; | 340 var fields = value.fields; |
| 341 // TODO(sra): Better validation of the constant. | 341 // TODO(sra): Better validation of the constant. |
| 342 if (fields.length != 1 || fields[0] is! StringConstant) { | 342 if (fields.length != 1 || fields[0] is! StringConstant) { |
| 343 PartialMetadataAnnotation partial = annotation; | 343 PartialMetadataAnnotation partial = annotation; |
| 344 compiler.internalError(annotation, | 344 compiler.internalError(annotation, |
| 345 'Annotations needs one string: ${partial.parseNode(compiler)}'); | 345 'Annotations needs one string: ${partial.parseNode(compiler)}'); |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 * [annotationClass]. | 1090 * [annotationClass]. |
| 1091 * Returns `null` if no constraints. | 1091 * Returns `null` if no constraints. |
| 1092 */ | 1092 */ |
| 1093 static _collect(Element element, Compiler compiler, Element annotationClass, | 1093 static _collect(Element element, Compiler compiler, Element annotationClass, |
| 1094 lookup(str)) { | 1094 lookup(str)) { |
| 1095 var types = null; | 1095 var types = null; |
| 1096 for (Link<MetadataAnnotation> link = element.metadata; | 1096 for (Link<MetadataAnnotation> link = element.metadata; |
| 1097 !link.isEmpty; | 1097 !link.isEmpty; |
| 1098 link = link.tail) { | 1098 link = link.tail) { |
| 1099 MetadataAnnotation annotation = link.head.ensureResolved(compiler); | 1099 MetadataAnnotation annotation = link.head.ensureResolved(compiler); |
| 1100 var value = annotation.value; | 1100 var value = annotation.constant; |
| 1101 if (value is! ConstructedConstant) continue; | 1101 if (value is! ConstructedConstant) continue; |
| 1102 if (value.type is! InterfaceType) continue; | 1102 if (value.type is! InterfaceType) continue; |
| 1103 if (!identical(value.type.element, annotationClass)) continue; | 1103 if (!identical(value.type.element, annotationClass)) continue; |
| 1104 | 1104 |
| 1105 var fields = value.fields; | 1105 var fields = value.fields; |
| 1106 // TODO(sra): Better validation of the constant. | 1106 // TODO(sra): Better validation of the constant. |
| 1107 if (fields.length != 1 || fields[0] is! StringConstant) { | 1107 if (fields.length != 1 || fields[0] is! StringConstant) { |
| 1108 PartialMetadataAnnotation partial = annotation; | 1108 PartialMetadataAnnotation partial = annotation; |
| 1109 compiler.internalError(annotation, | 1109 compiler.internalError(annotation, |
| 1110 'Annotations needs one string: ${partial.parseNode(compiler)}'); | 1110 'Annotations needs one string: ${partial.parseNode(compiler)}'); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 LiteralString jsCode = nativeBody.asLiteralString(); | 1333 LiteralString jsCode = nativeBody.asLiteralString(); |
| 1334 builder.push(new HForeign.statement( | 1334 builder.push(new HForeign.statement( |
| 1335 js.js.statementTemplateYielding( | 1335 js.js.statementTemplateYielding( |
| 1336 new js.LiteralStatement(jsCode.dartString.slowToString())), | 1336 new js.LiteralStatement(jsCode.dartString.slowToString())), |
| 1337 <HInstruction>[], | 1337 <HInstruction>[], |
| 1338 new SideEffects(), | 1338 new SideEffects(), |
| 1339 null, | 1339 null, |
| 1340 backend.dynamicType)); | 1340 backend.dynamicType)); |
| 1341 } | 1341 } |
| 1342 } | 1342 } |
| OLD | NEW |