Chromium Code Reviews| 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 /** | 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 _currentElement = element; | 262 _currentElement = element; |
| 263 try { | 263 try { |
| 264 return f(); | 264 return f(); |
| 265 } catch (CompilerCancelledException ex) { | 265 } catch (CompilerCancelledException ex) { |
| 266 throw; | 266 throw; |
| 267 } catch (StackOverflowException ex) { | 267 } catch (StackOverflowException ex) { |
| 268 // We cannot report anything useful in this case, because we | 268 // We cannot report anything useful in this case, because we |
| 269 // do not have enough stack space. | 269 // do not have enough stack space. |
| 270 throw; | 270 throw; |
| 271 } catch (var ex) { | 271 } catch (var ex) { |
| 272 unhandledExceptionOnElement(element); | 272 try { |
| 273 unhandledExceptionOnElement(element); | |
| 274 } catch (var doubleFault) {} | |
|
Johnni Winther
2012/07/03 11:04:29
Move the ending } to a new line and insert a comme
Lasse Reichstein Nielsen
2012/07/03 13:01:03
Done.
| |
| 273 throw; | 275 throw; |
| 274 } finally { | 276 } finally { |
| 275 _currentElement = old; | 277 _currentElement = old; |
| 276 } | 278 } |
| 277 } | 279 } |
| 278 | 280 |
| 279 List<CompilerTask> tasks; | 281 List<CompilerTask> tasks; |
| 280 ScannerTask scanner; | 282 ScannerTask scanner; |
| 281 DietParserTask dietParser; | 283 DietParserTask dietParser; |
| 282 ParserTask parser; | 284 ParserTask parser; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 if (patchUri !== null) { | 520 if (patchUri !== null) { |
| 519 // TODO(lrn): Use a different parser to allow for "patch" annotations. | 521 // TODO(lrn): Use a different parser to allow for "patch" annotations. |
| 520 // For now just assume everything in the patch library is a patch | 522 // For now just assume everything in the patch library is a patch |
| 521 // function. | 523 // function. |
| 522 LibraryElement patchLibrary = scanner.loadLibrary(patchUri, null); | 524 LibraryElement patchLibrary = scanner.loadLibrary(patchUri, null); |
| 523 applyLibraryPatch(library, patchLibrary); | 525 applyLibraryPatch(library, patchLibrary); |
| 524 } | 526 } |
| 525 } | 527 } |
| 526 | 528 |
| 527 void applyLibraryPatch(LibraryElement library, LibraryElement patch) { | 529 void applyLibraryPatch(LibraryElement library, LibraryElement patch) { |
| 530 // We allow foreign functions in patched libraries. | |
| 531 addForeignFunctions(library); // Is safe even if already added. | |
| 532 | |
| 533 // Copy/patch top-level elements. | |
| 528 Link<Element> patches = patch.topLevelElements; | 534 Link<Element> patches = patch.topLevelElements; |
| 529 while (!patches.isEmpty()) { | 535 while (!patches.isEmpty()) { |
| 530 Element patchElement = patches.head; | 536 Element patchElement = patches.head; |
| 531 Element originalElement = library.elements[patchElement.name]; | 537 Element originalElement = library.elements[patchElement.name]; |
| 532 if (originalElement !== null) { | 538 if (originalElement !== null) { |
| 533 // Assume that we are patching if the original exists. | 539 // Assume that we are patching if the original exists. |
| 534 if (originalElement is! FunctionElement) { | 540 if (originalElement is! FunctionElement) { |
| 535 // TODO(lrn): Handle class declarations too. | 541 // TODO(lrn): Handle class declarations too. |
| 536 internalError("Can only patch functions", element: originalElement); | 542 internalError("Can only patch functions", element: originalElement); |
| 537 } | 543 } |
| 538 // TODO(lrn): Abort if the original isn't marked external, when | 544 // TODO(lrn): Abort if the original isn't marked external, when |
| 539 // that is added to the language. | 545 // that is added to the language. |
| 540 if (patchElement is! FunctionElement || | 546 if (patchElement is! FunctionElement || |
| 541 !patchSignatureMatches(originalElement, patchElement)) { | 547 !patchSignatureMatches(originalElement, patchElement)) { |
| 542 internalError("Can only patch functions with matching signatures", | 548 internalError("Can only patch functions with matching signatures", |
| 543 element: originalElement); | 549 element: originalElement); |
| 544 } | 550 } |
| 545 applyFunctionPatch(originalElement, patchElement); | 551 applyFunctionPatch(originalElement, patchElement); |
| 546 } else { | 552 } else { |
| 547 // TODO(lrn): Allow adding private elements to the original library. | 553 // TODO(lrn): Allow adding private elements to the original library. |
| 548 } | 554 } |
| 549 patches = patches.tail; | 555 patches = patches.tail; |
| 550 } | 556 } |
| 557 | |
| 558 // Copy imports. | |
| 559 Map<String, LibraryElement> delayedPatches = <LibraryElement>{}; | |
| 560 Uri base = patch.script.uri; | |
| 561 for (ScriptTag tag in patch.tags.reverse()) { | |
| 562 if (tag.isImport()) { | |
| 563 StringNode argument = tag.argument; | |
| 564 Uri resolved = base.resolve(argument.dartString.slowToString()); | |
| 565 LibraryElement importedLibrary = | |
| 566 scanner.loadLibrary(resolved, argument); | |
| 567 scanner.importLibrary(library, importedLibrary, tag, patch); | |
| 568 if (resolved.scheme == "dart") { | |
|
floitsch
2012/07/03 12:06:55
I would prefer this check in 'patchDartLibrary'. T
Lasse Reichstein Nielsen
2012/07/03 12:55:04
This is not a check to avoid patching non-dart lib
| |
| 569 delayedPatches[resolved.path] = importedLibrary; | |
| 570 } | |
| 571 } | |
| 572 } | |
| 573 // Mark library as already patched. | |
| 551 library.patch = patch; | 574 library.patch = patch; |
| 575 // We patch imported libraries after marking the current library as patched, | |
| 576 // to avoid problems with cyclic dependencies. | |
| 577 delayedPatches.forEach((String path, LibraryElement importedLibrary) { | |
| 578 patchDartLibrary(importedLibrary, path); | |
| 579 }); | |
| 552 } | 580 } |
| 553 | 581 |
| 554 bool patchSignatureMatches(FunctionElement original, FunctionElement patch) { | 582 bool patchSignatureMatches(FunctionElement original, FunctionElement patch) { |
| 555 // TODO(lrn): Check that patches actually match the signature of | 583 // TODO(lrn): Check that patches actually match the signature of |
| 556 // the function it's patching. | 584 // the function it's patching. |
| 557 return true; | 585 return true; |
| 558 } | 586 } |
| 559 | 587 |
| 560 void applyFunctionPatch(FunctionElement element, | 588 void applyFunctionPatch(FunctionElement element, |
| 561 FunctionElement patchElement) { | 589 FunctionElement patchElement) { |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 962 f(int beginOffset, int endOffset)) { | 990 f(int beginOffset, int endOffset)) { |
| 963 final beginOffset = begin.charOffset; | 991 final beginOffset = begin.charOffset; |
| 964 final endOffset = end.charOffset + end.slowCharCount; | 992 final endOffset = end.charOffset + end.slowCharCount; |
| 965 | 993 |
| 966 // [begin] and [end] might be the same for the same empty token. This | 994 // [begin] and [end] might be the same for the same empty token. This |
| 967 // happens for instance when scanning '$$'. | 995 // happens for instance when scanning '$$'. |
| 968 assert(endOffset >= beginOffset); | 996 assert(endOffset >= beginOffset); |
| 969 return f(beginOffset, endOffset); | 997 return f(beginOffset, endOffset); |
| 970 } | 998 } |
| 971 } | 999 } |
| OLD | NEW |