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 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 for (ScriptTag tag in library.tags) { | 19 for (ScriptTag tag in library.tags.reverse()) { |
| 20 compiler.reportWarning(tag, "library tags are not implemented"); | 20 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 if (tag.isImport()) { | |
| 25 importLibrary(library, loadLibrary(resolved, tag), tag.prefix); | |
| 26 } else if (tag.isLibrary()) { | |
| 27 if (library.libraryTag !== null) { | |
| 28 compiler.cancel("duplicated library declaration", node: tag); | |
| 29 } else { | |
| 30 library.libraryTag = tag; | |
| 31 } | |
| 32 } else if (tag.isSource()) { | |
| 33 Script script = compiler.readScript(resolved, tag); | |
| 34 CompilationUnitElement unit = | |
| 35 new CompilationUnitElement(script, library); | |
| 36 compiler.withCurrentElement(unit, () => scan(unit)); | |
| 37 } else { | |
| 38 compiler.cancel("illegal script tag: ${tag.tag}", node: tag); | |
| 39 } | |
| 21 } | 40 } |
| 22 if (library !== compiler.coreLibrary) { | 41 if (library !== compiler.coreLibrary) { |
| 23 importLibrary(library, compiler.coreLibrary, null); | 42 importLibrary(library, compiler.coreLibrary, null); |
| 24 } | 43 } |
| 25 } | 44 } |
| 26 | 45 |
| 27 void scanElements(CompilationUnitElement compilationUnit) { | 46 void scanElements(CompilationUnitElement compilationUnit) { |
| 28 compiler.log("scanning $compilationUnit"); | 47 compiler.log("scanning $compilationUnit"); |
| 29 Script script = compilationUnit.script; | 48 Script script = compilationUnit.script; |
| 30 Token tokens; | 49 Token tokens; |
| 31 try { | 50 try { |
| 32 tokens = new StringScanner(script.text).tokenize(); | 51 tokens = new StringScanner(script.text).tokenize(); |
| 33 } catch (MalformedInputException ex) { | 52 } catch (MalformedInputException ex) { |
| 34 Token token; | 53 Token token; |
| 35 var message; | 54 var message; |
| 36 if (ex.position is num) { | 55 if (ex.position is num) { |
| 37 // TODO(ahe): Always use tokens in MalformedInputException. | 56 // TODO(ahe): Always use tokens in MalformedInputException. |
| 38 token = new Token(EOF_INFO, ex.position); | 57 token = new Token(EOF_INFO, ex.position); |
| 39 } else { | 58 } else { |
| 40 token = ex.position; | 59 token = ex.position; |
| 41 } | 60 } |
| 42 compiler.cancel(ex.message, token: token); | 61 compiler.cancel(ex.message, token: token); |
| 43 } | 62 } |
| 44 ElementListener listener = new ElementListener(compiler, compilationUnit); | 63 ElementListener listener = new ElementListener(compiler, compilationUnit); |
| 45 PartialParser parser = new PartialParser(listener); | 64 PartialParser parser = new PartialParser(listener); |
| 46 parser.parseUnit(tokens); | 65 parser.parseUnit(tokens); |
| 47 } | 66 } |
| 48 | 67 |
| 68 LibraryElement loadLibrary(Uri uri, ScriptTag node) { | |
| 69 bool newLibrary = false; | |
| 70 LibraryElement library = | |
| 71 compiler.universe.libraries.putIfAbsent(uri.toString(), () { | |
| 72 newLibrary = true; | |
|
kasperl
2012/02/03 11:51:37
Weird indentation.
ahe
2012/02/03 17:36:19
This is what Dart mode in Emacs does. What would y
kasperl
2012/02/05 07:58:29
I'd much prefer something like this:
xxx.yyy.z
sra1
2012/02/05 19:01:38
Emacs is closer to the style guide.
Style guide s
| |
| 73 Script script = compiler.readScript(uri, node); | |
| 74 return new LibraryElement(script); | |
| 75 }); | |
| 76 if (newLibrary) { | |
| 77 compiler.withCurrentElement(library, () => scan(library)); | |
| 78 } | |
| 79 return library; | |
| 80 } | |
| 81 | |
| 49 void importLibrary(LibraryElement library, LibraryElement imported, | 82 void importLibrary(LibraryElement library, LibraryElement imported, |
| 50 LiteralString prefix) { | 83 LiteralString prefix) { |
| 51 if (prefix !== null) { | 84 if (prefix !== null) { |
| 52 withCurrentElement(library, () { | 85 library.define(new PrefixElement(prefix, imported, library), compiler); |
| 53 compiler.cancel("prefixes are not implemented", node: prefix); | |
| 54 }); | |
| 55 } else { | 86 } else { |
| 56 for (Link<Element> link = imported.topLevelElements; !link.isEmpty(); | 87 for (Link<Element> link = imported.topLevelElements; !link.isEmpty(); |
| 57 link = link.tail) { | 88 link = link.tail) { |
| 58 compiler.withCurrentElement(link.head, () { | 89 compiler.withCurrentElement(link.head, () { |
| 59 library.define(link.head, compiler); | 90 library.define(link.head, compiler); |
| 60 }); | 91 }); |
| 61 } | 92 } |
| 62 } | 93 } |
| 63 } | 94 } |
| 64 } | 95 } |
| OLD | NEW |