| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 */ | 113 */ |
| 114 | 114 |
| 115 library dart2js.patchparser; | 115 library dart2js.patchparser; |
| 116 | 116 |
| 117 import 'dart:async'; | 117 import 'dart:async'; |
| 118 | 118 |
| 119 import 'common/tasks.dart' show CompilerTask; | 119 import 'common/tasks.dart' show CompilerTask; |
| 120 import 'common.dart'; | 120 import 'common.dart'; |
| 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 'elements/resolution_types.dart' show DartType; | 123 import 'elements/resolution_types.dart' show ResolutionDartType; |
| 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 MetadataAnnotationX, |
| 132 SetterElementX; | 132 SetterElementX; |
| 133 import 'id_generator.dart'; | 133 import 'id_generator.dart'; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // of calling its [parseNode] method. | 197 // of calling its [parseNode] method. |
| 198 if (cls.cachedNode != null) return; | 198 if (cls.cachedNode != null) return; |
| 199 | 199 |
| 200 measure(() => reporter.withCurrentElement(cls, () { | 200 measure(() => reporter.withCurrentElement(cls, () { |
| 201 MemberListener listener = new PatchMemberListener(compiler, cls); | 201 MemberListener listener = new PatchMemberListener(compiler, cls); |
| 202 Parser parser = new PatchClassElementParser(listener); | 202 Parser parser = new PatchClassElementParser(listener); |
| 203 try { | 203 try { |
| 204 Token token = parser.parseTopLevelDeclaration(cls.beginToken); | 204 Token token = parser.parseTopLevelDeclaration(cls.beginToken); |
| 205 assert(identical(token, cls.endToken.next)); | 205 assert(identical(token, cls.endToken.next)); |
| 206 } on ParserError catch (e) { | 206 } on ParserError catch (e) { |
| 207 // No need to recover from a parser error in platform libraries, use
r | 207 // No need to recover from a parser error in platform libraries, |
| 208 // will never see this if the libraries are tested correctly. | 208 // user will never see this if the libraries are tested correctly. |
| 209 reporter.internalError(cls, "Parser error in patch file: $e"); | 209 reporter.internalError(cls, "Parser error in patch file: $e"); |
| 210 } | 210 } |
| 211 cls.cachedNode = listener.popNode(); | 211 cls.cachedNode = listener.popNode(); |
| 212 assert(listener.nodes.isEmpty); | 212 assert(listener.nodes.isEmpty); |
| 213 })); | 213 })); |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 | 216 |
| 217 class PatchMemberListener extends MemberListener { | 217 class PatchMemberListener extends MemberListener { |
| 218 final Compiler compiler; | 218 final Compiler compiler; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 JavaScriptBackend backend = compiler.backend; | 421 JavaScriptBackend backend = compiler.backend; |
| 422 backend.nativeData.setNativeClassTagInfo(element, native); | 422 backend.nativeData.setNativeClassTagInfo(element, native); |
| 423 return native; | 423 return native; |
| 424 } | 424 } |
| 425 } | 425 } |
| 426 return null; | 426 return null; |
| 427 } | 427 } |
| 428 | 428 |
| 429 void validate(Compiler compiler, Element element, | 429 void validate(Compiler compiler, Element element, |
| 430 MetadataAnnotation annotation, ConstantValue constant) { | 430 MetadataAnnotation annotation, ConstantValue constant) { |
| 431 DartType annotationType = constant.getType(compiler.commonElements); | 431 ResolutionDartType annotationType = |
| 432 constant.getType(compiler.commonElements); |
| 432 if (annotationType.element != | 433 if (annotationType.element != |
| 433 compiler.commonElements.nativeAnnotationClass) { | 434 compiler.commonElements.nativeAnnotationClass) { |
| 434 DiagnosticReporter reporter = compiler.reporter; | 435 DiagnosticReporter reporter = compiler.reporter; |
| 435 reporter.internalError(annotation, 'Invalid @Native(...) annotation.'); | 436 reporter.internalError(annotation, 'Invalid @Native(...) annotation.'); |
| 436 } | 437 } |
| 437 } | 438 } |
| 438 } | 439 } |
| 439 | 440 |
| 440 /// Annotation handler for pre-resolution detection of `@JS(...)` | 441 /// Annotation handler for pre-resolution detection of `@JS(...)` |
| 441 /// annotations. | 442 /// annotations. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 | 491 |
| 491 @override | 492 @override |
| 492 PatchVersion apply( | 493 PatchVersion apply( |
| 493 Compiler compiler, Element element, MetadataAnnotation annotation) { | 494 Compiler compiler, Element element, MetadataAnnotation annotation) { |
| 494 return getPatchVersion(annotation); | 495 return getPatchVersion(annotation); |
| 495 } | 496 } |
| 496 | 497 |
| 497 @override | 498 @override |
| 498 void validate(Compiler compiler, Element element, | 499 void validate(Compiler compiler, Element element, |
| 499 MetadataAnnotation annotation, ConstantValue constant) { | 500 MetadataAnnotation annotation, ConstantValue constant) { |
| 500 DartType annotationType = constant.getType(compiler.commonElements); | 501 ResolutionDartType annotationType = |
| 502 constant.getType(compiler.commonElements); |
| 501 if (annotationType.element != | 503 if (annotationType.element != |
| 502 compiler.commonElements.patchAnnotationClass) { | 504 compiler.commonElements.patchAnnotationClass) { |
| 503 DiagnosticReporter reporter = compiler.reporter; | 505 DiagnosticReporter reporter = compiler.reporter; |
| 504 reporter.internalError(annotation, 'Invalid patch annotation.'); | 506 reporter.internalError(annotation, 'Invalid patch annotation.'); |
| 505 } | 507 } |
| 506 } | 508 } |
| 507 } | 509 } |
| 508 | 510 |
| 509 void tryPatchGetter( | 511 void tryPatchGetter( |
| 510 DiagnosticReporter reporter, Element origin, FunctionElement patch) { | 512 DiagnosticReporter reporter, Element origin, FunctionElement patch) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 | 617 |
| 616 class PatchVersion { | 618 class PatchVersion { |
| 617 final String tag; | 619 final String tag; |
| 618 | 620 |
| 619 const PatchVersion(this.tag); | 621 const PatchVersion(this.tag); |
| 620 | 622 |
| 621 bool isActive(String patchTag) => tag == null || tag == patchTag; | 623 bool isActive(String patchTag) => tag == null || tag == patchTag; |
| 622 | 624 |
| 623 String toString() => 'PatchVersion($tag)'; | 625 String toString() => 'PatchVersion($tag)'; |
| 624 } | 626 } |
| OLD | NEW |