| 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 class ScannerTask extends CompilerTask { | 5 class ScannerTask extends CompilerTask { |
| 6 ScannerTask(Compiler compiler) : super(compiler); | 6 ScannerTask(Compiler compiler) : super(compiler); |
| 7 String get name() => 'Scanner'; | 7 String get name() => 'Scanner'; |
| 8 | 8 |
| 9 void scan(CompilationUnitElement compilationUnit) { | 9 void scan(CompilationUnitElement compilationUnit) { |
| 10 measure(() { | 10 measure(() { |
| 11 scanElements(compilationUnit); | 11 scanElements(compilationUnit); |
| 12 if (compilationUnit.kind === ElementKind.LIBRARY) { | 12 if (compilationUnit.kind === ElementKind.LIBRARY) { |
| 13 processScriptTags(compilationUnit); | 13 processScriptTags(compilationUnit); |
| 14 } | 14 } |
| 15 }); | 15 }); |
| 16 } | 16 } |
| 17 | 17 |
| 18 void processScriptTags(LibraryElement library) { | 18 void processScriptTags(LibraryElement library) { |
| 19 LinkBuilder<ScriptTag> imports = new LinkBuilder<ScriptTag>(); |
| 20 Uri cwd = new Uri(scheme: 'file', path: compiler.currentDirectory); |
| 21 Uri base = cwd.resolve(library.script.name.toString()); |
| 19 for (ScriptTag tag in library.tags.reverse()) { | 22 for (ScriptTag tag in library.tags.reverse()) { |
| 20 SourceString argument = tag.argument.value.copyWithoutQuotes(1, 1); | 23 SourceString argument = tag.argument.value.copyWithoutQuotes(1, 1); |
| 21 Uri cwd = new Uri(scheme: 'file', path: compiler.currentDirectory); | |
| 22 Uri base = cwd.resolve(library.script.name.toString()); | |
| 23 Uri resolved = base.resolve(argument.toString()); | 24 Uri resolved = base.resolve(argument.toString()); |
| 24 if (tag.isImport()) { | 25 if (tag.isImport()) { |
| 25 importLibrary(library, loadLibrary(resolved, tag), tag.prefix); | 26 // It is not safe to import other libraries at this point as |
| 27 // another library could then observe the current library |
| 28 // before it fully declares all the members that are sourced |
| 29 // in. |
| 30 imports.addLast(tag); |
| 26 } else if (tag.isLibrary()) { | 31 } else if (tag.isLibrary()) { |
| 27 if (library.libraryTag !== null) { | 32 if (library.libraryTag !== null) { |
| 28 compiler.cancel("duplicated library declaration", node: tag); | 33 compiler.cancel("duplicated library declaration", node: tag); |
| 29 } else { | 34 } else { |
| 30 library.libraryTag = tag; | 35 library.libraryTag = tag; |
| 31 } | 36 } |
| 32 } else if (tag.isSource()) { | 37 } else if (tag.isSource()) { |
| 33 Script script = compiler.readScript(resolved, tag); | 38 Script script = compiler.readScript(resolved, tag); |
| 34 CompilationUnitElement unit = | 39 CompilationUnitElement unit = |
| 35 new CompilationUnitElement(script, library); | 40 new CompilationUnitElement(script, library); |
| 36 compiler.withCurrentElement(unit, () => scan(unit)); | 41 compiler.withCurrentElement(unit, () => scan(unit)); |
| 37 } else { | 42 } else { |
| 38 compiler.cancel("illegal script tag: ${tag.tag}", node: tag); | 43 compiler.cancel("illegal script tag: ${tag.tag}", node: tag); |
| 39 } | 44 } |
| 40 } | 45 } |
| 46 for (ScriptTag tag in imports.toLink()) { |
| 47 // Now that we have processed all the source tags, it is safe to |
| 48 // start loading other libraries. |
| 49 SourceString argument = tag.argument.value.copyWithoutQuotes(1, 1); |
| 50 Uri resolved = base.resolve(argument.toString()); |
| 51 importLibrary(library, loadLibrary(resolved, tag), tag.prefix); |
| 52 } |
| 41 if (compiler.coreLibrary !== null) { | 53 if (compiler.coreLibrary !== null) { |
| 42 importLibrary(library, compiler.coreLibrary, null); | 54 importLibrary(library, compiler.coreLibrary, null); |
| 43 } | 55 } |
| 44 } | 56 } |
| 45 | 57 |
| 46 void scanElements(CompilationUnitElement compilationUnit) { | 58 void scanElements(CompilationUnitElement compilationUnit) { |
| 47 compiler.log("scanning $compilationUnit"); | 59 compiler.log("scanning $compilationUnit"); |
| 48 Script script = compilationUnit.script; | 60 Script script = compilationUnit.script; |
| 49 Token tokens; | 61 Token tokens; |
| 50 try { | 62 try { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } else { | 98 } else { |
| 87 for (Link<Element> link = imported.topLevelElements; !link.isEmpty(); | 99 for (Link<Element> link = imported.topLevelElements; !link.isEmpty(); |
| 88 link = link.tail) { | 100 link = link.tail) { |
| 89 compiler.withCurrentElement(link.head, () { | 101 compiler.withCurrentElement(link.head, () { |
| 90 library.define(link.head, compiler); | 102 library.define(link.head, compiler); |
| 91 }); | 103 }); |
| 92 } | 104 } |
| 93 } | 105 } |
| 94 } | 106 } |
| 95 } | 107 } |
| OLD | NEW |