| 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 final LinkBuilder<tree.LibraryTag> imports; | 363 final LinkBuilder<tree.LibraryTag> imports; |
| 364 bool isMemberPatch = false; | 364 bool isMemberPatch = false; |
| 365 bool isClassPatch = false; | 365 bool isClassPatch = false; |
| 366 | 366 |
| 367 PatchElementListener(leg.DiagnosticListener listener, | 367 PatchElementListener(leg.DiagnosticListener listener, |
| 368 CompilationUnitElement patchElement, | 368 CompilationUnitElement patchElement, |
| 369 int idGenerator(), | 369 int idGenerator(), |
| 370 this.imports) | 370 this.imports) |
| 371 : super(listener, patchElement, idGenerator); | 371 : super(listener, patchElement, idGenerator); |
| 372 | 372 |
| 373 MetadataAnnotation popMetadata() { | 373 MetadataAnnotation popMetadataHack() { |
| 374 // TODO(ahe): Remove this method. | 374 // TODO(ahe): Remove this method. |
| 375 popNode(); // Discard null. | 375 popNode(); // Discard null. |
| 376 return new PatchMetadataAnnotation(); | 376 return new PatchMetadataAnnotation(); |
| 377 } | 377 } |
| 378 | 378 |
| 379 void beginPatch(Token token) { | 379 void beginPatch(Token token) { |
| 380 if (identical(token.next.stringValue, "class")) { | 380 if (identical(token.next.stringValue, "class")) { |
| 381 isClassPatch = true; | 381 isClassPatch = true; |
| 382 } else { | 382 } else { |
| 383 isMemberPatch = true; | 383 isMemberPatch = true; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 400 bool allowLibraryTags() => true; | 400 bool allowLibraryTags() => true; |
| 401 | 401 |
| 402 void addLibraryTag(tree.LibraryTag tag) { | 402 void addLibraryTag(tree.LibraryTag tag) { |
| 403 super.addLibraryTag(tag); | 403 super.addLibraryTag(tag); |
| 404 imports.addLast(tag); | 404 imports.addLast(tag); |
| 405 } | 405 } |
| 406 | 406 |
| 407 void pushElement(Element element) { | 407 void pushElement(Element element) { |
| 408 if (isMemberPatch || (isClassPatch && element is ClassElement)) { | 408 if (isMemberPatch || (isClassPatch && element is ClassElement)) { |
| 409 // Apply patch. | 409 // Apply patch. |
| 410 element.addMetadata(popMetadata()); | 410 element.addMetadata(popMetadataHack()); |
| 411 LibraryElement originLibrary = compilationUnitElement.getLibrary(); | 411 LibraryElement originLibrary = compilationUnitElement.getLibrary(); |
| 412 assert(originLibrary.isPatched); | 412 assert(originLibrary.isPatched); |
| 413 Element existing = originLibrary.localLookup(element.name); | 413 Element existing = originLibrary.localLookup(element.name); |
| 414 if (isMemberPatch) { | 414 if (isMemberPatch) { |
| 415 if (element is! FunctionElement) { | 415 if (element is! FunctionElement) { |
| 416 listener.internalErrorOnElement(element, | 416 listener.internalErrorOnElement(element, |
| 417 "Member patch is not a function."); | 417 "Member patch is not a function."); |
| 418 } | 418 } |
| 419 FunctionElement functionElement = element; | 419 FunctionElement functionElement = element; |
| 420 if (identical(existing.kind, ElementKind.ABSTRACT_FIELD)) { | 420 if (identical(existing.kind, ElementKind.ABSTRACT_FIELD)) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 /** | 463 /** |
| 464 * Extension of [MemberListener] for parsing patch class bodies. | 464 * Extension of [MemberListener] for parsing patch class bodies. |
| 465 */ | 465 */ |
| 466 class PatchMemberListener extends MemberListener implements PatchListener { | 466 class PatchMemberListener extends MemberListener implements PatchListener { |
| 467 bool isMemberPatch = false; | 467 bool isMemberPatch = false; |
| 468 bool isClassPatch = false; | 468 bool isClassPatch = false; |
| 469 PatchMemberListener(leg.DiagnosticListener listener, | 469 PatchMemberListener(leg.DiagnosticListener listener, |
| 470 Element enclosingElement) | 470 Element enclosingElement) |
| 471 : super(listener, enclosingElement); | 471 : super(listener, enclosingElement); |
| 472 | 472 |
| 473 MetadataAnnotation popMetadata() { | 473 MetadataAnnotation popMetadataHack() { |
| 474 // TODO(ahe): Remove this method. | 474 // TODO(ahe): Remove this method. |
| 475 popNode(); // Discard null. | 475 popNode(); // Discard null. |
| 476 return new PatchMetadataAnnotation(); | 476 return new PatchMetadataAnnotation(); |
| 477 } | 477 } |
| 478 | 478 |
| 479 void beginPatch(Token token) { | 479 void beginPatch(Token token) { |
| 480 if (identical(token.next.stringValue, "class")) { | 480 if (identical(token.next.stringValue, "class")) { |
| 481 isClassPatch = true; | 481 isClassPatch = true; |
| 482 } else { | 482 } else { |
| 483 isMemberPatch = true; | 483 isMemberPatch = true; |
| 484 } | 484 } |
| 485 handleIdentifier(token); | 485 handleIdentifier(token); |
| 486 } | 486 } |
| 487 | 487 |
| 488 void endPatch(Token token) { | 488 void endPatch(Token token) { |
| 489 if (identical(token.next.stringValue, "class")) { | 489 if (identical(token.next.stringValue, "class")) { |
| 490 isClassPatch = false; | 490 isClassPatch = false; |
| 491 } else { | 491 } else { |
| 492 isMemberPatch = false; | 492 isMemberPatch = false; |
| 493 } | 493 } |
| 494 } | 494 } |
| 495 | 495 |
| 496 void addMember(Element element) { | 496 void addMember(Element element) { |
| 497 if (isMemberPatch || (isClassPatch && element is ClassElement)) { | 497 if (isMemberPatch || (isClassPatch && element is ClassElement)) { |
| 498 element.addMetadata(popMetadata()); | 498 element.addMetadata(popMetadataHack()); |
| 499 } | 499 } |
| 500 super.addMember(element); | 500 super.addMember(element); |
| 501 } | 501 } |
| 502 } | 502 } |
| 503 | 503 |
| 504 // TODO(ahe): Get rid of this class. | 504 // TODO(ahe): Get rid of this class. |
| 505 class PatchMetadataAnnotation extends MetadataAnnotationX { | 505 class PatchMetadataAnnotation extends MetadataAnnotationX { |
| 506 final leg.Constant value = null; | 506 final leg.Constant value = null; |
| 507 | 507 |
| 508 PatchMetadataAnnotation() : super(STATE_DONE); | 508 PatchMetadataAnnotation() : super(STATE_DONE); |
| 509 | 509 |
| 510 Token get beginToken => null; | 510 Token get beginToken => null; |
| 511 } | 511 } |
| OLD | NEW |