| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 'dart:collection' show Queue; | 5 import 'dart:collection' show Queue; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/backend_api.dart' show | 8 import '../common/backend_api.dart' show |
| 9 ForeignResolver; | 9 ForeignResolver; |
| 10 import '../common/registry.dart' show | 10 import '../common/registry.dart' show |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 } else if (element.isField) { | 411 } else if (element.isField) { |
| 412 handleFieldAnnotations(element); | 412 handleFieldAnnotations(element); |
| 413 if (backend.isNative(element)) { | 413 if (backend.isNative(element)) { |
| 414 registerFieldLoad(element); | 414 registerFieldLoad(element); |
| 415 registerFieldStore(element); | 415 registerFieldStore(element); |
| 416 } | 416 } |
| 417 } | 417 } |
| 418 }); | 418 }); |
| 419 } | 419 } |
| 420 | 420 |
| 421 handleFieldAnnotations(Element element) { | 421 void handleFieldAnnotations(Element element) { |
| 422 if (compiler.serialization.isDeserialized(element)) { |
| 423 return; |
| 424 } |
| 422 if (backend.isNative(element.enclosingElement)) { | 425 if (backend.isNative(element.enclosingElement)) { |
| 423 // Exclude non-instance (static) fields - they not really native and are | 426 // Exclude non-instance (static) fields - they not really native and are |
| 424 // compiled as isolate globals. Access of a property of a constructor | 427 // compiled as isolate globals. Access of a property of a constructor |
| 425 // function or a non-method property in the prototype chain, must be coded | 428 // function or a non-method property in the prototype chain, must be coded |
| 426 // using a JS-call. | 429 // using a JS-call. |
| 427 if (element.isInstanceMember) { | 430 if (element.isInstanceMember) { |
| 428 setNativeName(element); | 431 _setNativeName(element); |
| 429 } | 432 } |
| 430 } | 433 } |
| 431 } | 434 } |
| 432 | 435 |
| 433 handleMethodAnnotations(Element method) { | 436 void handleMethodAnnotations(Element method) { |
| 437 if (compiler.serialization.isDeserialized(method)) { |
| 438 return; |
| 439 } |
| 434 if (isNativeMethod(method)) { | 440 if (isNativeMethod(method)) { |
| 435 if (method.isStatic) { | 441 if (method.isStatic) { |
| 436 setNativeNameForStaticMethod(method); | 442 _setNativeNameForStaticMethod(method); |
| 437 } else { | 443 } else { |
| 438 setNativeName(method); | 444 _setNativeName(method); |
| 439 } | 445 } |
| 440 } | 446 } |
| 441 } | 447 } |
| 442 | 448 |
| 443 /// Sets the native name of [element], either from an annotation, or | 449 /// Sets the native name of [element], either from an annotation, or |
| 444 /// defaulting to the Dart name. | 450 /// defaulting to the Dart name. |
| 445 void setNativeName(MemberElement element) { | 451 void _setNativeName(MemberElement element) { |
| 446 String name = findJsNameFromAnnotation(element); | 452 String name = findJsNameFromAnnotation(element); |
| 447 if (name == null) name = element.name; | 453 if (name == null) name = element.name; |
| 448 backend.setNativeMemberName(element, name); | 454 backend.nativeData.setNativeMemberName(element, name); |
| 449 } | 455 } |
| 450 | 456 |
| 451 /// Sets the native name of the static native method [element], using the | 457 /// Sets the native name of the static native method [element], using the |
| 452 /// following rules: | 458 /// following rules: |
| 453 /// 1. If [element] has a @JSName annotation that is an identifier, qualify | 459 /// 1. If [element] has a @JSName annotation that is an identifier, qualify |
| 454 /// that identifier to the @Native name of the enclosing class | 460 /// that identifier to the @Native name of the enclosing class |
| 455 /// 2. If [element] has a @JSName annotation that is not an identifier, | 461 /// 2. If [element] has a @JSName annotation that is not an identifier, |
| 456 /// use the declared @JSName as the expression | 462 /// use the declared @JSName as the expression |
| 457 /// 3. If [element] does not have a @JSName annotation, qualify the name of | 463 /// 3. If [element] does not have a @JSName annotation, qualify the name of |
| 458 /// the method with the @Native name of the enclosing class. | 464 /// the method with the @Native name of the enclosing class. |
| 459 void setNativeNameForStaticMethod(MethodElement element) { | 465 void _setNativeNameForStaticMethod(MethodElement element) { |
| 460 String name = findJsNameFromAnnotation(element); | 466 String name = findJsNameFromAnnotation(element); |
| 461 if (name == null) name = element.name; | 467 if (name == null) name = element.name; |
| 462 if (isIdentifier(name)) { | 468 if (isIdentifier(name)) { |
| 463 List<String> nativeNames = | 469 List<String> nativeNames = |
| 464 backend.getNativeTagsOfClassRaw(element.enclosingClass); | 470 backend.nativeData.getNativeTagsOfClassRaw(element.enclosingClass); |
| 465 if (nativeNames.length != 1) { | 471 if (nativeNames.length != 1) { |
| 466 reporter.internalError(element, | 472 reporter.internalError(element, |
| 467 'Unable to determine a native name for the enclosing class, ' | 473 'Unable to determine a native name for the enclosing class, ' |
| 468 'options: $nativeNames'); | 474 'options: $nativeNames'); |
| 469 } | 475 } |
| 470 backend.setNativeMemberName(element, '${nativeNames[0]}.$name'); | 476 backend.nativeData.setNativeMemberName( |
| 477 element, '${nativeNames[0]}.$name'); |
| 471 } else { | 478 } else { |
| 472 backend.setNativeMemberName(element, name); | 479 backend.nativeData.setNativeMemberName(element, name); |
| 473 } | 480 } |
| 474 } | 481 } |
| 475 | 482 |
| 476 bool isIdentifier(String s) => _identifier.hasMatch(s); | 483 bool isIdentifier(String s) => _identifier.hasMatch(s); |
| 477 | 484 |
| 478 bool isNativeMethod(FunctionElementX element) { | 485 bool isNativeMethod(FunctionElementX element) { |
| 479 if (!backend.canLibraryUseNative(element.library)) return false; | 486 if (!backend.canLibraryUseNative(element.library)) return false; |
| 480 // Native method? | 487 // Native method? |
| 481 return reporter.withCurrentElement(element, () { | 488 return reporter.withCurrentElement(element, () { |
| 482 Node node = element.parseNode(resolution.parsing); | 489 Node node = element.parseNode(resolution.parsing); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 NativeResolutionEnqueuer(Enqueuer world, Compiler compiler) | 604 NativeResolutionEnqueuer(Enqueuer world, Compiler compiler) |
| 598 : super(world, compiler, compiler.options.enableNativeLiveTypeAnalysis); | 605 : super(world, compiler, compiler.options.enableNativeLiveTypeAnalysis); |
| 599 | 606 |
| 600 void processNativeClass(ClassElement classElement) { | 607 void processNativeClass(ClassElement classElement) { |
| 601 super.processNativeClass(classElement); | 608 super.processNativeClass(classElement); |
| 602 | 609 |
| 603 // Js Interop interfaces do not have tags. | 610 // Js Interop interfaces do not have tags. |
| 604 if (backend.isJsInterop(classElement)) return; | 611 if (backend.isJsInterop(classElement)) return; |
| 605 // Since we map from dispatch tags to classes, a dispatch tag must be used | 612 // Since we map from dispatch tags to classes, a dispatch tag must be used |
| 606 // on only one native class. | 613 // on only one native class. |
| 607 for (String tag in backend.getNativeTagsOfClass(classElement)) { | 614 for (String tag in backend.nativeData.getNativeTagsOfClass(classElement)) { |
| 608 ClassElement owner = tagOwner[tag]; | 615 ClassElement owner = tagOwner[tag]; |
| 609 if (owner != null) { | 616 if (owner != null) { |
| 610 if (owner != classElement) { | 617 if (owner != classElement) { |
| 611 reporter.internalError( | 618 reporter.internalError( |
| 612 classElement, "Tag '$tag' already in use by '${owner.name}'"); | 619 classElement, "Tag '$tag' already in use by '${owner.name}'"); |
| 613 } | 620 } |
| 614 } else { | 621 } else { |
| 615 tagOwner[tag] = classElement; | 622 tagOwner[tag] = classElement; |
| 616 } | 623 } |
| 617 } | 624 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 superclass, | 739 superclass, |
| 733 () => <ClassElement>[]); | 740 () => <ClassElement>[]); |
| 734 directSubtypes.add(cls); | 741 directSubtypes.add(cls); |
| 735 } | 742 } |
| 736 | 743 |
| 737 void logSummary(log(message)) { | 744 void logSummary(log(message)) { |
| 738 log('Compiled ${registeredClasses.length} native classes, ' | 745 log('Compiled ${registeredClasses.length} native classes, ' |
| 739 '${unusedClasses.length} native classes omitted.'); | 746 '${unusedClasses.length} native classes omitted.'); |
| 740 } | 747 } |
| 741 } | 748 } |
| OLD | NEW |