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

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

Issue 10824347: Make top-level patch injections be compilation unit under library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Offline discussed changes. Created 8 years, 4 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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 addForeignFunctions(jsHelperLibrary); 351 addForeignFunctions(jsHelperLibrary);
352 addForeignFunctions(interceptorsLibrary); 352 addForeignFunctions(interceptorsLibrary);
353 353
354 libraries['dart:core'] = coreLibrary; 354 libraries['dart:core'] = coreLibrary;
355 libraries['dart:coreimpl'] = coreImplLibrary; 355 libraries['dart:coreimpl'] = coreImplLibrary;
356 356
357 assertMethod = coreLibrary.find(const SourceString('assert')); 357 assertMethod = coreLibrary.find(const SourceString('assert'));
358 358
359 initializeSpecialClasses(); 359 initializeSpecialClasses();
360 360
361 patchDartLibrary(coreLibrary, 'core'); 361 //patchDartLibrary(coreLibrary, 'core');
362 patchDartLibrary(coreImplLibrary, 'coreimpl'); 362 //patchDartLibrary(coreImplLibrary, 'coreimpl');
363 } 363 }
364 364
365 void patchDartLibrary(LibraryElement library, String dartLibraryPath) { 365 void patchDartLibrary(LibraryElement library, String dartLibraryPath) {
366 print("[Patching; $library ($dartLibraryPath)");
366 if (library.isPatched) return; 367 if (library.isPatched) return;
367 Uri patchUri = resolvePatchUri(dartLibraryPath); 368 Uri patchUri = resolvePatchUri(dartLibraryPath);
368 if (patchUri !== null) { 369 if (patchUri !== null) {
369 LibraryElement patchLibrary = 370 print("[... loading patch ...]");
370 patchParser.loadPatchLibrary(patchUri); 371 patchParser.patchLibrary(patchUri, library);
371 // We allow foreign functions in patched libraries. 372 // We allow foreign functions in patched libraries.
372 addForeignFunctions(library); // Is safe even if already added. 373 addForeignFunctions(library); // Is safe even if already added.
373 applyLibraryPatch(library, patchLibrary); 374 // TODO(lrn): Make this lazy.
375 applyClassPatches(library);
374 } 376 }
375 } 377 }
376 378
377 void applyLibraryPatch(LibraryElement original, LibraryElement patch) { 379 void applyClassPatches(LibraryElement library) {
378 Link<Element> patches = patch.localMembers; 380 for (Element element in library.localMembers) {
379 applyContainerPatch(original, patches); 381 if (element.isClass()) {
380 382 ClassElement classElement = element;
381 // Copy imports from patch to original library. 383 if (classElement.isPatched) {
382 Map<String, LibraryElement> delayedPatches = <LibraryElement>{}; 384 applyClassPatch(classElement, classElement.patch);
383 Uri patchBase = patch.uri;
384 for (ScriptTag tag in patch.tags.reverse()) {
385 if (tag.isImport()) {
386 StringNode argument = tag.argument;
387 Uri resolved = patchBase.resolve(argument.dartString.slowToString());
388 LibraryElement importedLibrary =
389 scanner.loadLibrary(resolved, argument);
390 scanner.importLibrary(original, importedLibrary, tag,
391 patch.entryCompilationUnit);
392 if (resolved.scheme == "dart") {
393 delayedPatches[resolved.path] = importedLibrary;
394 } 385 }
395 } 386 }
396 } 387 }
397
398 // Mark library as already patched.
399 original.patch = patch;
400
401 // We patch imported libraries after marking the current library as
402 // patched, to avoid problems with cyclic dependencies.
403 delayedPatches.forEach((String path, LibraryElement importedLibrary) {
404 patchDartLibrary(importedLibrary, path);
405 });
406 } 388 }
407 389
408 void applyContainerPatch(ScopeContainerElement original, 390 void applyContainerPatch(ScopeContainerElement original,
409 Link<Element> patches) { 391 Link<Element> patches) {
410 while (!patches.isEmpty()) { 392 while (!patches.isEmpty()) {
411 Element patchElement = patches.head; 393 Element patchElement = patches.head;
412 Element originalElement = original.localLookup(patchElement.name); 394 Element originalElement = original.localLookup(patchElement.name);
413 if (patchElement.isAccessor()) { 395 if (patchElement.isAccessor()) {
414 // TODO(lrn): When we change to always add accessors to members, and 396 // TODO(lrn): When we change to always add accessors to members, and
415 // not add abstract fields, the logic here should be reversed. 397 // not add abstract fields, the logic here should be reversed.
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 library.addToScope(new ForeignElement( 546 library.addToScope(new ForeignElement(
565 const SourceString('JS_CURRENT_ISOLATE'), library), this); 547 const SourceString('JS_CURRENT_ISOLATE'), library), this);
566 library.addToScope(new ForeignElement( 548 library.addToScope(new ForeignElement(
567 const SourceString('JS_CALL_IN_ISOLATE'), library), this); 549 const SourceString('JS_CALL_IN_ISOLATE'), library), this);
568 library.addToScope(new ForeignElement( 550 library.addToScope(new ForeignElement(
569 const SourceString('DART_CLOSURE_TO_JS'), library), this); 551 const SourceString('DART_CLOSURE_TO_JS'), library), this);
570 } 552 }
571 553
572 void runCompiler(Uri uri) { 554 void runCompiler(Uri uri) {
573 scanBuiltinLibraries(); 555 scanBuiltinLibraries();
574 mainApp = scanner.loadLibrary(uri, null); 556 mainApp = scanner.loadLibrary(uri, null, uri);
575 final Element main = mainApp.find(MAIN); 557 final Element main = mainApp.find(MAIN);
576 if (main === null) { 558 if (main === null) {
577 reportFatalError('Could not find $MAIN', mainApp); 559 reportFatalError('Could not find $MAIN', mainApp);
578 } else { 560 } else {
579 if (!main.isFunction()) reportFatalError('main is not a function', main); 561 if (!main.isFunction()) reportFatalError('main is not a function', main);
580 FunctionElement mainMethod = main; 562 FunctionElement mainMethod = main;
581 FunctionSignature parameters = mainMethod.computeSignature(this); 563 FunctionSignature parameters = mainMethod.computeSignature(this);
582 parameters.forEachParameter((Element parameter) { 564 parameters.forEachParameter((Element parameter) {
583 reportFatalError('main cannot have parameters', parameter); 565 reportFatalError('main cannot have parameters', parameter);
584 }); 566 });
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 final endOffset = end.charOffset + end.slowCharCount; 925 final endOffset = end.charOffset + end.slowCharCount;
944 926
945 // [begin] and [end] might be the same for the same empty token. This 927 // [begin] and [end] might be the same for the same empty token. This
946 // happens for instance when scanning '$$'. 928 // happens for instance when scanning '$$'.
947 assert(endOffset >= beginOffset); 929 assert(endOffset >= beginOffset);
948 return f(beginOffset, endOffset); 930 return f(beginOffset, endOffset);
949 } 931 }
950 932
951 String toString() => 'SourceSpan($uri, $begin, $end)'; 933 String toString() => 'SourceSpan($uri, $begin, $end)';
952 } 934 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/apiimpl.dart ('k') | lib/compiler/implementation/diagnostic_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698