Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: lib/compiler/implementation/compiler.dart

Issue 10689036: First step towards having patch files for generic libraries. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 /** 6 /**
7 * If true, print a warning for each method that was resolved, but not 7 * If true, print a warning for each method that was resolved, but not
8 * compiled. 8 * compiled.
9 */ 9 */
10 final bool REPORT_EXCESS_RESOLUTION = false; 10 final bool REPORT_EXCESS_RESOLUTION = false;
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 scanner.importLibrary(interceptorsLibrary, coreLibrary, null); 500 scanner.importLibrary(interceptorsLibrary, coreLibrary, null);
501 addForeignFunctions(jsHelperLibrary); 501 addForeignFunctions(jsHelperLibrary);
502 addForeignFunctions(interceptorsLibrary); 502 addForeignFunctions(interceptorsLibrary);
503 503
504 libraries['dart:core'] = coreLibrary; 504 libraries['dart:core'] = coreLibrary;
505 libraries['dart:coreimpl'] = coreImplLibrary; 505 libraries['dart:coreimpl'] = coreImplLibrary;
506 506
507 assertMethod = coreLibrary.find(const SourceString('assert')); 507 assertMethod = coreLibrary.find(const SourceString('assert'));
508 508
509 initializeSpecialClasses(); 509 initializeSpecialClasses();
510
511 patchDartLibrary(coreLibrary, 'core');
512 patchDartLibrary(coreImplLibrary, 'coreimpl');
510 } 513 }
511 514
515 void patchDartLibrary(LibraryElement library, String dartLibraryPath) {
516 if (library.isPatched) return;
517 Uri patchUri = resolvePatchUri(dartLibraryPath);
518 if (patchUri !== null) {
519 // TODO(lrn): Use a different parser to allow for "patch" annotations.
520 // For now just assume everything in the patch library is a patch
521 // function.
522 LibraryElement patchLibrary = scanner.loadLibrary(patchUri, null);
523 applyLibraryPatch(library, patchLibrary);
524 }
525 }
526
527 void applyLibraryPatch(LibraryElement library, LibraryElement patch) {
528 Link<Element> patches = patch.topLevelElements;
529 while (!patches.isEmpty()) {
530 Element patchElement = patches.head;
531 Element originalElement = library.elements[patchElement.name];
532 if (originalElement !== null) {
533 // Assume that we are patching if the original exists.
534 if (originalElement is! FunctionElement) {
535 // TODO(lrn): Handle class declarations too.
536 cancel("Can only patch functions", element: originalElement);
537 }
538 // TODO(lrn): Abort if the original isn't marked external, when
539 // that is added to the language.
540 if (patchElement is! FunctionElement ||
541 !patchSignatureMatches(originalElement, patchElement)) {
542 cancel("Can only patch functions with matching signatures",
543 element: originalElement);
544 }
545 applyFunctionPatch(originalElement, patchElement);
546 } else {
547 // TODO(lrn): Allow adding private elements to the original library.
548 }
549 patches = patches.tail;
550 }
551 library.patch = patch;
552 }
553
554 bool patchSignatureMatches(FunctionElement original, FunctionElement patch) {
555 // TODO(lrn): Check that patches actually match the signature of
556 // the function it's patching.
557 return true;
558 }
559
560 void applyFunctionPatch(FunctionElement element,
561 FunctionElement patchElement) {
562 // Don't just assign the patch field. This also updates the cachedNode.
563 element.setPatch(patchElement);
564 }
565
566 /**
567 * Get an [Uri] pointing to a patch for the dart: library with
568 * the given path. Returns null if there is no patch.
569 */
570 abstract Uri resolvePatchUri(String dartLibraryPath);
571
512 /** Define the JS helper functions in the given library. */ 572 /** Define the JS helper functions in the given library. */
513 void addForeignFunctions(LibraryElement library) { 573 void addForeignFunctions(LibraryElement library) {
514 library.define(new ForeignElement( 574 library.define(new ForeignElement(
515 const SourceString('JS'), library), this); 575 const SourceString('JS'), library), this);
516 library.define(new ForeignElement( 576 library.define(new ForeignElement(
517 const SourceString('UNINTERCEPTED'), library), this); 577 const SourceString('UNINTERCEPTED'), library), this);
518 library.define(new ForeignElement( 578 library.define(new ForeignElement(
519 const SourceString('JS_HAS_EQUALS'), library), this); 579 const SourceString('JS_HAS_EQUALS'), library), this);
520 library.define(new ForeignElement( 580 library.define(new ForeignElement(
521 const SourceString('JS_CURRENT_ISOLATE'), library), this); 581 const SourceString('JS_CURRENT_ISOLATE'), library), this);
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 // invariant that endOffset > beginOffset, but for EOF the 958 // invariant that endOffset > beginOffset, but for EOF the
899 // charoffset of the next token may be [beginOffset]. This can 959 // charoffset of the next token may be [beginOffset]. This can
900 // also happen for synthetized tokens that are produced during 960 // also happen for synthetized tokens that are produced during
901 // error handling. 961 // error handling.
902 final endOffset = 962 final endOffset =
903 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1); 963 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1);
904 assert(endOffset > beginOffset); 964 assert(endOffset > beginOffset);
905 return f(beginOffset, endOffset); 965 return f(beginOffset, endOffset);
906 } 966 }
907 } 967 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698