| 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 assert(listener.nodes.isEmpty); | 226 assert(listener.nodes.isEmpty); |
| 227 })); | 227 })); |
| 228 } | 228 } |
| 229 } | 229 } |
| 230 | 230 |
| 231 class PatchMemberListener extends MemberListener { | 231 class PatchMemberListener extends MemberListener { |
| 232 final Compiler compiler; | 232 final Compiler compiler; |
| 233 | 233 |
| 234 PatchMemberListener(Compiler compiler, ClassElement enclosingClass) | 234 PatchMemberListener(Compiler compiler, ClassElement enclosingClass) |
| 235 : this.compiler = compiler, | 235 : this.compiler = compiler, |
| 236 super(compiler.reporter, enclosingClass); | 236 super(compiler.parsing.getScannerOptionsFor(enclosingClass), |
| 237 compiler.reporter, |
| 238 enclosingClass); |
| 237 | 239 |
| 238 @override | 240 @override |
| 239 void addMember(Element patch) { | 241 void addMember(Element patch) { |
| 240 addMetadata(patch); | 242 addMetadata(patch); |
| 241 | 243 |
| 242 PatchVersion patchVersion = getPatchVersion(compiler, patch); | 244 PatchVersion patchVersion = getPatchVersion(compiler, patch); |
| 243 if (patchVersion != null) { | 245 if (patchVersion != null) { |
| 244 if (patchVersion.isActive(compiler.patchVersion)) { | 246 if (patchVersion.isActive(compiler.patchVersion)) { |
| 245 Element origin = enclosingClass.origin.localLookup(patch.name); | 247 Element origin = enclosingClass.origin.localLookup(patch.name); |
| 246 patchElement(compiler, reporter, origin, patch); | 248 patchElement(compiler, reporter, origin, patch); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 267 /** | 269 /** |
| 268 * Extension of [ElementListener] for parsing patch files. | 270 * Extension of [ElementListener] for parsing patch files. |
| 269 */ | 271 */ |
| 270 class PatchElementListener extends ElementListener implements Listener { | 272 class PatchElementListener extends ElementListener implements Listener { |
| 271 final Compiler compiler; | 273 final Compiler compiler; |
| 272 | 274 |
| 273 PatchElementListener(Compiler compiler, | 275 PatchElementListener(Compiler compiler, |
| 274 CompilationUnitElement patchElement, | 276 CompilationUnitElement patchElement, |
| 275 int idGenerator()) | 277 int idGenerator()) |
| 276 : this.compiler = compiler, | 278 : this.compiler = compiler, |
| 277 super(compiler.reporter, patchElement, idGenerator); | 279 super(compiler.parsing.getScannerOptionsFor(patchElement), |
| 280 compiler.reporter, patchElement, idGenerator); |
| 278 | 281 |
| 279 @override | 282 @override |
| 280 void pushElement(Element patch) { | 283 void pushElement(Element patch) { |
| 281 popMetadata(patch); | 284 popMetadata(patch); |
| 282 | 285 |
| 283 PatchVersion patchVersion = getPatchVersion(compiler, patch); | 286 PatchVersion patchVersion = getPatchVersion(compiler, patch); |
| 284 if (patchVersion != null) { | 287 if (patchVersion != null) { |
| 285 if (patchVersion.isActive(compiler.patchVersion)) { | 288 if (patchVersion.isActive(compiler.patchVersion)) { |
| 286 LibraryElement originLibrary = compilationUnitElement.library; | 289 LibraryElement originLibrary = compilationUnitElement.library; |
| 287 assert(originLibrary.isPatched); | 290 assert(originLibrary.isPatched); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 } | 441 } |
| 439 return null; | 442 return null; |
| 440 } | 443 } |
| 441 | 444 |
| 442 String apply(Compiler compiler, | 445 String apply(Compiler compiler, |
| 443 Element element, | 446 Element element, |
| 444 MetadataAnnotation annotation) { | 447 MetadataAnnotation annotation) { |
| 445 if (element.isClass) { | 448 if (element.isClass) { |
| 446 String native = getNativeAnnotation(annotation); | 449 String native = getNativeAnnotation(annotation); |
| 447 if (native != null) { | 450 if (native != null) { |
| 448 ClassElementX declaration = element.declaration; | 451 JavaScriptBackend backend = compiler.backend; |
| 449 declaration.setNative(native); | 452 backend.setNativeClassTagInfo(element, native); |
| 450 return native; | 453 return native; |
| 451 } | 454 } |
| 452 } | 455 } |
| 453 return null; | 456 return null; |
| 454 } | 457 } |
| 455 | 458 |
| 456 void validate(Compiler compiler, | 459 void validate(Compiler compiler, |
| 457 Element element, | 460 Element element, |
| 458 MetadataAnnotation annotation, | 461 MetadataAnnotation annotation, |
| 459 ConstantValue constant) { | 462 ConstantValue constant) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 471 const JsInteropAnnotationHandler(); | 474 const JsInteropAnnotationHandler(); |
| 472 | 475 |
| 473 bool hasJsNameAnnotation(MetadataAnnotation annotation) => | 476 bool hasJsNameAnnotation(MetadataAnnotation annotation) => |
| 474 annotation.beginToken != null && annotation.beginToken.next.value == 'Js'; | 477 annotation.beginToken != null && annotation.beginToken.next.value == 'Js'; |
| 475 | 478 |
| 476 bool apply(Compiler compiler, | 479 bool apply(Compiler compiler, |
| 477 Element element, | 480 Element element, |
| 478 MetadataAnnotation annotation) { | 481 MetadataAnnotation annotation) { |
| 479 bool hasJsInterop = hasJsNameAnnotation(annotation); | 482 bool hasJsInterop = hasJsNameAnnotation(annotation); |
| 480 if (hasJsInterop) { | 483 if (hasJsInterop) { |
| 481 element.markAsJsInterop(); | 484 JavaScriptBackend backend = compiler.backend; |
| 485 backend.markAsJsInterop(element); |
| 482 } | 486 } |
| 483 // Due to semantics of apply in the baseclass we have to return null to | 487 // Due to semantics of apply in the baseclass we have to return null to |
| 484 // indicate that no match was found. | 488 // indicate that no match was found. |
| 485 return hasJsInterop ? true : null; | 489 return hasJsInterop ? true : null; |
| 486 } | 490 } |
| 487 | 491 |
| 488 @override | 492 @override |
| 489 void validate(Compiler compiler, | 493 void validate(Compiler compiler, |
| 490 Element element, | 494 Element element, |
| 491 MetadataAnnotation annotation, | 495 MetadataAnnotation annotation, |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 | 682 |
| 679 class PatchVersion { | 683 class PatchVersion { |
| 680 final String tag; | 684 final String tag; |
| 681 | 685 |
| 682 const PatchVersion(this.tag); | 686 const PatchVersion(this.tag); |
| 683 | 687 |
| 684 bool isActive(String patchTag) => tag == null || tag == patchTag; | 688 bool isActive(String patchTag) => tag == null || tag == patchTag; |
| 685 | 689 |
| 686 String toString() => 'PatchVersion($tag)'; | 690 String toString() => 'PatchVersion($tag)'; |
| 687 } | 691 } |
| OLD | NEW |