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

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

Issue 10824275: Revert "Refactor Library/CompilationUnit and how we define local Scope." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« no previous file with comments | « no previous file | lib/compiler/implementation/elements/elements.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 284
285 void onLibraryLoaded(LibraryElement library, Uri uri) { 285 void onLibraryLoaded(LibraryElement library, Uri uri) {
286 if (uri.toString() == 'dart:isolate') { 286 if (uri.toString() == 'dart:isolate') {
287 enableIsolateSupport(library); 287 enableIsolateSupport(library);
288 } 288 }
289 if (dynamicClass !== null) { 289 if (dynamicClass !== null) {
290 // When loading the built-in libraries, dynamicClass is null. We 290 // When loading the built-in libraries, dynamicClass is null. We
291 // take advantage of this as core and coreimpl import js_helper 291 // take advantage of this as core and coreimpl import js_helper
292 // and see Dynamic this way. 292 // and see Dynamic this way.
293 withCurrentElement(dynamicClass, () { 293 withCurrentElement(dynamicClass, () {
294 library.addToScope(dynamicClass, this); 294 library.define(dynamicClass, this);
295 }); 295 });
296 } 296 }
297 } 297 }
298 298
299 abstract LibraryElement scanBuiltinLibrary(String filename); 299 abstract LibraryElement scanBuiltinLibrary(String filename);
300 300
301 void initializeSpecialClasses() { 301 void initializeSpecialClasses() {
302 bool coreLibValid = true; 302 bool coreLibValid = true;
303 ClassElement lookupSpecialClass(SourceString name) { 303 ClassElement lookupSpecialClass(SourceString name) {
304 ClassElement result = coreLibrary.find(name); 304 ClassElement result = coreLibrary.find(name);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 if (patchUri !== null) { 363 if (patchUri !== null) {
364 LibraryElement patchLibrary = 364 LibraryElement patchLibrary =
365 patchParser.loadPatchLibrary(patchUri); 365 patchParser.loadPatchLibrary(patchUri);
366 // We allow foreign functions in patched libraries. 366 // We allow foreign functions in patched libraries.
367 addForeignFunctions(library); // Is safe even if already added. 367 addForeignFunctions(library); // Is safe even if already added.
368 applyLibraryPatch(library, patchLibrary); 368 applyLibraryPatch(library, patchLibrary);
369 } 369 }
370 } 370 }
371 371
372 void applyLibraryPatch(LibraryElement original, LibraryElement patch) { 372 void applyLibraryPatch(LibraryElement original, LibraryElement patch) {
373 Link<Element> patches = patch.localMembers; 373 Link<Element> patches = patch.topLevelElements;
374 applyContainerPatch(original, patches); 374 applyContainerPatch(original, patches, original.findLocal);
375 375
376 // Copy imports from patch to original library. 376 // Copy imports from patch to original library.
377 Map<String, LibraryElement> delayedPatches = <LibraryElement>{}; 377 Map<String, LibraryElement> delayedPatches = <LibraryElement>{};
378 Uri patchBase = patch.uri; 378 Uri patchBase = patch.script.uri;
379 for (ScriptTag tag in patch.tags.reverse()) { 379 for (ScriptTag tag in patch.tags.reverse()) {
380 if (tag.isImport()) { 380 if (tag.isImport()) {
381 StringNode argument = tag.argument; 381 StringNode argument = tag.argument;
382 Uri resolved = patchBase.resolve(argument.dartString.slowToString()); 382 Uri resolved = patchBase.resolve(argument.dartString.slowToString());
383 LibraryElement importedLibrary = 383 LibraryElement importedLibrary =
384 scanner.loadLibrary(resolved, argument); 384 scanner.loadLibrary(resolved, argument);
385 scanner.importLibrary(original, importedLibrary, tag, 385 scanner.importLibrary(original, importedLibrary, tag, patch);
386 patch.entryCompilationUnit);
387 if (resolved.scheme == "dart") { 386 if (resolved.scheme == "dart") {
388 delayedPatches[resolved.path] = importedLibrary; 387 delayedPatches[resolved.path] = importedLibrary;
389 } 388 }
390 } 389 }
391 } 390 }
392 391
393 // Mark library as already patched. 392 // Mark library as already patched.
394 original.patch = patch; 393 original.patch = patch;
395 394
396 // We patch imported libraries after marking the current library as 395 // We patch imported libraries after marking the current library as
397 // patched, to avoid problems with cyclic dependencies. 396 // patched, to avoid problems with cyclic dependencies.
398 delayedPatches.forEach((String path, LibraryElement importedLibrary) { 397 delayedPatches.forEach((String path, LibraryElement importedLibrary) {
399 patchDartLibrary(importedLibrary, path); 398 patchDartLibrary(importedLibrary, path);
400 }); 399 });
401 } 400 }
402 401
403 void applyContainerPatch(ScopeContainerElement original, 402 void applyContainerPatch(ContainerElement original, Link<Element> patches,
404 Link<Element> patches) { 403 Element lookup(SourceString name)) {
405 while (!patches.isEmpty()) { 404 while (!patches.isEmpty()) {
406 Element patchElement = patches.head; 405 Element patchElement = patches.head;
407 Element originalElement = original.localLookup(patchElement.name); 406 Element originalElement = lookup(patchElement.name);
408 if (patchElement.isAccessor()) { 407 if (patchElement.isAccessor()) {
409 // Skip accessors. An accessor always has an abstract field, 408 // Skip accessors. An accessor always has an abstract field,
410 // representing the accessor in the lookup scope. We can thus skip the 409 // representing the accessor in the lookup scope. We can thus skip the
411 // accessors and just handle the abstract field. 410 // accessors and just handle the abstract field.
412 } else if (patchElement.kind === ElementKind.ABSTRACT_FIELD) { 411 } else if (patchElement.kind === ElementKind.ABSTRACT_FIELD) {
413 // Getters and setters are kept inside a synthetic field. 412 // Getters and setters are kept inside a synthetic field.
414 if (originalElement !== null && 413 if (originalElement !== null &&
415 originalElement.kind !== ElementKind.ABSTRACT_FIELD) { 414 originalElement.kind !== ElementKind.ABSTRACT_FIELD) {
416 internalError("Cannot patch non-getter/setter with getter/setter", 415 internalError("Cannot patch non-getter/setter with getter/setter",
417 element: originalElement); 416 element: originalElement);
418 } 417 }
419 AbstractFieldElement patchField = patchElement; 418 AbstractFieldElement patchField = patchElement;
420 AbstractFieldElement originalField = originalElement; 419 AbstractFieldElement originalField = originalElement;
421 if (patchField.getter !== null) { 420 if (patchField.getter !== null) {
422 if (originalField === null || originalField.getter === null) { 421 if (originalField === null || originalField.getter === null) {
423 original.addGetterOrSetter(clonePatch(patchField.getter), 422 original.addGetterOrSetter(clonePatch(patchField.getter),
424 originalField, 423 originalField,
425 this); 424 this);
426 if (originalField === null && patchField.setter !== null) { 425 if (originalField === null && patchField.setter !== null) {
427 // It exists now, so find it for the setter patching. 426 // It exists now, so find it for the setter patching.
428 originalField = original.localLookup(patchElement.name); 427 originalField = lookup(patchElement.name);
429 } 428 }
430 } else { 429 } else {
431 patchMember(originalField.getter, patchField.getter); 430 patchMember(originalField.getter, patchField.getter);
432 } 431 }
433 } 432 }
434 if (patchField.setter !== null) { 433 if (patchField.setter !== null) {
435 if (originalField === null || originalField.setter === null) { 434 if (originalField === null || originalField.setter === null) {
436 original.addGetterOrSetter(clonePatch(patchField.setter), 435 original.addGetterOrSetter(clonePatch(patchField.setter),
437 originalField, 436 originalField,
438 this); 437 this);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 } 528 }
530 529
531 void applyClassPatch(PartialClassElement original, 530 void applyClassPatch(PartialClassElement original,
532 PartialClassElement patch) { 531 PartialClassElement patch) {
533 // Eagerly parse the class so we can patch it. 532 // Eagerly parse the class so we can patch it.
534 // TODO(lrn): Perhaps find a way to delay parsing until the class is needed, 533 // TODO(lrn): Perhaps find a way to delay parsing until the class is needed,
535 // i.e., until [parseNode] is called on [original]. 534 // i.e., until [parseNode] is called on [original].
536 ClassNode node = original.parseNode(this); 535 ClassNode node = original.parseNode(this);
537 // Parse patch class with "patch" parser. 536 // Parse patch class with "patch" parser.
538 ClassNode patchNode = patchParser.parsePatchClassNode(patch); 537 ClassNode patchNode = patchParser.parsePatchClassNode(patch);
539 Link<Element> patches = patch.localMembers; 538 Link<Element> patches = patch.members;
540 applyContainerPatch(original, patches); 539 Element lookupMemberOrConstructor(SourceString name) {
540 Element result = original.lookupLocalMember(name);
541 if (result !== null) return result;
542 return original.lookupConstructor(name);
543 }
544 applyContainerPatch(original, patches, lookupMemberOrConstructor);
541 } 545 }
542 546
543 /** 547 /**
544 * Get an [Uri] pointing to a patch for the dart: library with 548 * Get an [Uri] pointing to a patch for the dart: library with
545 * the given path. Returns null if there is no patch. 549 * the given path. Returns null if there is no patch.
546 */ 550 */
547 abstract Uri resolvePatchUri(String dartLibraryPath); 551 abstract Uri resolvePatchUri(String dartLibraryPath);
548 552
549 /** Define the JS helper functions in the given library. */ 553 /** Define the JS helper functions in the given library. */
550 void addForeignFunctions(LibraryElement library) { 554 void addForeignFunctions(LibraryElement library) {
551 library.addToScope(new ForeignElement( 555 library.define(new ForeignElement(
552 const SourceString('JS'), library), this); 556 const SourceString('JS'), library), this);
553 library.addToScope(new ForeignElement( 557 library.define(new ForeignElement(
554 const SourceString('UNINTERCEPTED'), library), this); 558 const SourceString('UNINTERCEPTED'), library), this);
555 library.addToScope(new ForeignElement( 559 library.define(new ForeignElement(
556 const SourceString('JS_HAS_EQUALS'), library), this); 560 const SourceString('JS_HAS_EQUALS'), library), this);
557 library.addToScope(new ForeignElement( 561 library.define(new ForeignElement(
558 const SourceString('JS_CURRENT_ISOLATE'), library), this); 562 const SourceString('JS_CURRENT_ISOLATE'), library), this);
559 library.addToScope(new ForeignElement( 563 library.define(new ForeignElement(
560 const SourceString('JS_CALL_IN_ISOLATE'), library), this); 564 const SourceString('JS_CALL_IN_ISOLATE'), library), this);
561 library.addToScope(new ForeignElement( 565 library.define(new ForeignElement(
562 const SourceString('DART_CLOSURE_TO_JS'), library), this); 566 const SourceString('DART_CLOSURE_TO_JS'), library), this);
563 } 567 }
564 568
565 void runCompiler(Uri uri) { 569 void runCompiler(Uri uri) {
566 scanBuiltinLibraries(); 570 scanBuiltinLibraries();
567 mainApp = scanner.loadLibrary(uri, null); 571 mainApp = scanner.loadLibrary(uri, null);
568 final Element main = mainApp.find(MAIN); 572 final Element main = mainApp.find(MAIN);
569 if (main === null) { 573 if (main === null) {
570 reportFatalError('Could not find $MAIN', mainApp); 574 reportFatalError('Could not find $MAIN', mainApp);
571 } else { 575 } else {
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 final endOffset = end.charOffset + end.slowCharCount; 946 final endOffset = end.charOffset + end.slowCharCount;
943 947
944 // [begin] and [end] might be the same for the same empty token. This 948 // [begin] and [end] might be the same for the same empty token. This
945 // happens for instance when scanning '$$'. 949 // happens for instance when scanning '$$'.
946 assert(endOffset >= beginOffset); 950 assert(endOffset >= beginOffset);
947 return f(beginOffset, endOffset); 951 return f(beginOffset, endOffset);
948 } 952 }
949 953
950 String toString() => 'SourceSpan($uri, $begin, $end)'; 954 String toString() => 'SourceSpan($uri, $begin, $end)';
951 } 955 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/elements/elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698