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