| 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 /** | 5 /** |
| 6 * This library contains the infrastructure to parse and integrate patch files. | 6 * This library contains the infrastructure to parse and integrate patch files. |
| 7 * | 7 * |
| 8 * Three types of elements can be patched: [LibraryElement], [ClassElement], | 8 * Three types of elements can be patched: [LibraryElement], [ClassElement], |
| 9 * [FunctionElement]. Patches are introduced in patch libraries which are loaded | 9 * [FunctionElement]. Patches are introduced in patch libraries which are loaded |
| 10 * together with the corresponding origin library. Which libraries that are | 10 * together with the corresponding origin library. Which libraries that are |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 import 'compiler.dart' show Compiler; | 121 import 'compiler.dart' show Compiler; |
| 122 import 'constants/values.dart' show ConstantValue; | 122 import 'constants/values.dart' show ConstantValue; |
| 123 import 'dart_types.dart' show DartType; | 123 import 'dart_types.dart' show DartType; |
| 124 import 'elements/elements.dart'; | 124 import 'elements/elements.dart'; |
| 125 import 'elements/modelx.dart' | 125 import 'elements/modelx.dart' |
| 126 show | 126 show |
| 127 BaseFunctionElementX, | 127 BaseFunctionElementX, |
| 128 ClassElementX, | 128 ClassElementX, |
| 129 GetterElementX, | 129 GetterElementX, |
| 130 LibraryElementX, | 130 LibraryElementX, |
| 131 MetadataAnnotationX, |
| 131 SetterElementX; | 132 SetterElementX; |
| 132 import 'id_generator.dart'; | 133 import 'id_generator.dart'; |
| 133 import 'js_backend/js_backend.dart' show JavaScriptBackend; | 134 import 'js_backend/js_backend.dart' show JavaScriptBackend; |
| 134 import 'library_loader.dart' show LibraryLoader; | 135 import 'library_loader.dart' show LibraryLoader; |
| 135 import 'options.dart' show ParserOptions; | 136 import 'options.dart' show ParserOptions; |
| 136 import 'parser/element_listener.dart' show ElementListener; | 137 import 'parser/element_listener.dart' show ElementListener; |
| 137 import 'parser/listener.dart' show Listener, ParserError; | 138 import 'parser/listener.dart' show Listener, ParserError; |
| 138 import 'parser/member_listener.dart' show MemberListener; | 139 import 'parser/member_listener.dart' show MemberListener; |
| 139 import 'parser/parser.dart' show Parser; | 140 import 'parser/parser.dart' show Parser; |
| 140 import 'parser/partial_elements.dart' show PartialClassElement; | 141 import 'parser/partial_elements.dart' show PartialClassElement; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 } | 397 } |
| 397 return null; | 398 return null; |
| 398 } | 399 } |
| 399 } | 400 } |
| 400 | 401 |
| 401 /// Annotation handler for pre-resolution detection of `@Native(...)` | 402 /// Annotation handler for pre-resolution detection of `@Native(...)` |
| 402 /// annotations. | 403 /// annotations. |
| 403 class NativeAnnotationHandler implements EagerAnnotationHandler<String> { | 404 class NativeAnnotationHandler implements EagerAnnotationHandler<String> { |
| 404 const NativeAnnotationHandler(); | 405 const NativeAnnotationHandler(); |
| 405 | 406 |
| 406 String getNativeAnnotation(MetadataAnnotation annotation) { | 407 String getNativeAnnotation(MetadataAnnotationX annotation) { |
| 407 if (annotation.beginToken != null && | 408 if (annotation.beginToken != null && |
| 408 annotation.beginToken.next.value == 'Native') { | 409 annotation.beginToken.next.value == 'Native') { |
| 409 // Skipping '@', 'Native', and '('. | 410 // Skipping '@', 'Native', and '('. |
| 410 Token argument = annotation.beginToken.next.next.next; | 411 Token argument = annotation.beginToken.next.next.next; |
| 411 if (argument is StringToken) { | 412 if (argument is StringToken) { |
| 412 return argument.value; | 413 return argument.value; |
| 413 } | 414 } |
| 414 } | 415 } |
| 415 return null; | 416 return null; |
| 416 } | 417 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 436 reporter.internalError(annotation, 'Invalid @Native(...) annotation.'); | 437 reporter.internalError(annotation, 'Invalid @Native(...) annotation.'); |
| 437 } | 438 } |
| 438 } | 439 } |
| 439 } | 440 } |
| 440 | 441 |
| 441 /// Annotation handler for pre-resolution detection of `@JS(...)` | 442 /// Annotation handler for pre-resolution detection of `@JS(...)` |
| 442 /// annotations. | 443 /// annotations. |
| 443 class JsInteropAnnotationHandler implements EagerAnnotationHandler<bool> { | 444 class JsInteropAnnotationHandler implements EagerAnnotationHandler<bool> { |
| 444 const JsInteropAnnotationHandler(); | 445 const JsInteropAnnotationHandler(); |
| 445 | 446 |
| 446 bool hasJsNameAnnotation(MetadataAnnotation annotation) => | 447 bool hasJsNameAnnotation(MetadataAnnotationX annotation) => |
| 447 annotation.beginToken != null && annotation.beginToken.next.value == 'JS'; | 448 annotation.beginToken != null && annotation.beginToken.next.value == 'JS'; |
| 448 | 449 |
| 449 bool apply( | 450 bool apply( |
| 450 Compiler compiler, Element element, MetadataAnnotation annotation) { | 451 Compiler compiler, Element element, MetadataAnnotation annotation) { |
| 451 bool hasJsInterop = hasJsNameAnnotation(annotation); | 452 bool hasJsInterop = hasJsNameAnnotation(annotation); |
| 452 if (hasJsInterop) { | 453 if (hasJsInterop) { |
| 453 JavaScriptBackend backend = compiler.backend; | 454 JavaScriptBackend backend = compiler.backend; |
| 454 backend.nativeData.markAsJsInterop(element); | 455 backend.nativeData.markAsJsInterop(element); |
| 455 } | 456 } |
| 456 // Due to semantics of apply in the baseclass we have to return null to | 457 // Due to semantics of apply in the baseclass we have to return null to |
| (...skipping 10 matching lines...) Expand all Loading... |
| 467 compiler.reporter | 468 compiler.reporter |
| 468 .internalError(annotation, 'Invalid @JS(...) annotation.'); | 469 .internalError(annotation, 'Invalid @JS(...) annotation.'); |
| 469 } | 470 } |
| 470 } | 471 } |
| 471 } | 472 } |
| 472 | 473 |
| 473 /// Annotation handler for pre-resolution detection of `@patch` annotations. | 474 /// Annotation handler for pre-resolution detection of `@patch` annotations. |
| 474 class PatchAnnotationHandler implements EagerAnnotationHandler<PatchVersion> { | 475 class PatchAnnotationHandler implements EagerAnnotationHandler<PatchVersion> { |
| 475 const PatchAnnotationHandler(); | 476 const PatchAnnotationHandler(); |
| 476 | 477 |
| 477 PatchVersion getPatchVersion(MetadataAnnotation annotation) { | 478 PatchVersion getPatchVersion(MetadataAnnotationX annotation) { |
| 478 if (annotation.beginToken != null) { | 479 if (annotation.beginToken != null) { |
| 479 if (annotation.beginToken.next.value == 'patch') { | 480 if (annotation.beginToken.next.value == 'patch') { |
| 480 return const PatchVersion(null); | 481 return const PatchVersion(null); |
| 481 } else if (annotation.beginToken.next.value == 'patch_full') { | 482 } else if (annotation.beginToken.next.value == 'patch_full') { |
| 482 return const PatchVersion('full'); | 483 return const PatchVersion('full'); |
| 483 } else if (annotation.beginToken.next.value == 'patch_lazy') { | 484 } else if (annotation.beginToken.next.value == 'patch_lazy') { |
| 484 return const PatchVersion('lazy'); | 485 return const PatchVersion('lazy'); |
| 485 } else if (annotation.beginToken.next.value == 'patch_startup') { | 486 } else if (annotation.beginToken.next.value == 'patch_startup') { |
| 486 return const PatchVersion('startup'); | 487 return const PatchVersion('startup'); |
| 487 } | 488 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 | 616 |
| 616 class PatchVersion { | 617 class PatchVersion { |
| 617 final String tag; | 618 final String tag; |
| 618 | 619 |
| 619 const PatchVersion(this.tag); | 620 const PatchVersion(this.tag); |
| 620 | 621 |
| 621 bool isActive(String patchTag) => tag == null || tag == patchTag; | 622 bool isActive(String patchTag) => tag == null || tag == patchTag; |
| 622 | 623 |
| 623 String toString() => 'PatchVersion($tag)'; | 624 String toString() => 'PatchVersion($tag)'; |
| 624 } | 625 } |
| OLD | NEW |