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

Side by Side Diff: frog/leg/scanner/scanner_task.dart

Issue 9642001: Make string juxtaposition combine properly with string interpolations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments so far. Created 8 years, 9 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 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 if (compilationUnit.kind === ElementKind.LIBRARY) { 11 if (compilationUnit.kind === ElementKind.LIBRARY) {
12 compiler.log("scanning library ${compilationUnit.script.name}"); 12 compiler.log("scanning library ${compilationUnit.script.name}");
13 } 13 }
14 scanElements(compilationUnit); 14 scanElements(compilationUnit);
15 if (compilationUnit.kind === ElementKind.LIBRARY) { 15 if (compilationUnit.kind === ElementKind.LIBRARY) {
16 processScriptTags(compilationUnit); 16 processScriptTags(compilationUnit);
17 } 17 }
18 }); 18 });
19 } 19 }
20 20
21 void processScriptTags(LibraryElement library) { 21 void processScriptTags(LibraryElement library) {
22 LinkBuilder<ScriptTag> imports = new LinkBuilder<ScriptTag>(); 22 LinkBuilder<ScriptTag> imports = new LinkBuilder<ScriptTag>();
23 Uri cwd = new Uri(scheme: 'file', path: compiler.currentDirectory); 23 Uri cwd = new Uri(scheme: 'file', path: compiler.currentDirectory);
24 Uri base = cwd.resolve(library.script.name.toString()); 24 Uri base = cwd.resolve(library.script.name.toString());
25 for (ScriptTag tag in library.tags.reverse()) { 25 for (ScriptTag tag in library.tags.reverse()) {
26 SourceString argument = tag.argument.value.copyWithoutQuotes(1, 1); 26 StringNode argument = tag.argument;
27 Uri resolved = base.resolve(argument.slowToString()); 27 // TODO(lrn): When supporting (compile-time constant) interpolations,
ahe 2012/03/19 15:53:06 This TODO seems confused. We do not support compil
Lasse Reichstein Nielsen 2012/03/20 09:34:33 Reworded.
28 // find a way to convert them to a string here.
29 Uri resolved = base.resolve(argument.dartString.slowToString());
ahe 2012/03/19 15:53:06 FWIW, I like not having to call copyWithoutQuotes!
28 if (tag.isImport()) { 30 if (tag.isImport()) {
29 // It is not safe to import other libraries at this point as 31 // It is not safe to import other libraries at this point as
30 // another library could then observe the current library 32 // another library could then observe the current library
31 // before it fully declares all the members that are sourced 33 // before it fully declares all the members that are sourced
32 // in. 34 // in.
33 imports.addLast(tag); 35 imports.addLast(tag);
34 } else if (tag.isLibrary()) { 36 } else if (tag.isLibrary()) {
35 if (library.libraryTag !== null) { 37 if (library.libraryTag !== null) {
36 compiler.cancel("duplicated library declaration", node: tag); 38 compiler.cancel("duplicated library declaration", node: tag);
37 } else { 39 } else {
38 library.libraryTag = tag; 40 library.libraryTag = tag;
39 } 41 }
40 } else if (tag.isSource()) { 42 } else if (tag.isSource()) {
41 Script script = compiler.readScript(resolved, tag); 43 Script script = compiler.readScript(resolved, tag);
42 CompilationUnitElement unit = 44 CompilationUnitElement unit =
43 new CompilationUnitElement(script, library); 45 new CompilationUnitElement(script, library);
44 compiler.withCurrentElement(unit, () => scan(unit)); 46 compiler.withCurrentElement(unit, () => scan(unit));
45 } else { 47 } else {
46 compiler.cancel("illegal script tag: ${tag.tag}", node: tag); 48 compiler.cancel("illegal script tag: ${tag.tag}", node: tag);
47 } 49 }
48 } 50 }
49 // TODO(ahe): During Compiler.scanBuiltinLibraries, 51 // TODO(ahe): During Compiler.scanBuiltinLibraries,
50 // compiler.coreLibrary is null. Clean this up when there is a 52 // compiler.coreLibrary is null. Clean this up when there is a
51 // better way to access "dart:core". 53 // better way to access "dart:core".
52 bool implicitlyImportCoreLibrary = compiler.coreLibrary !== null; 54 bool implicitlyImportCoreLibrary = compiler.coreLibrary !== null;
53 for (ScriptTag tag in imports.toLink()) { 55 for (ScriptTag tag in imports.toLink()) {
54 // Now that we have processed all the source tags, it is safe to 56 // Now that we have processed all the source tags, it is safe to
55 // start loading other libraries. 57 // start loading other libraries.
56 SourceString argument = tag.argument.value.copyWithoutQuotes(1, 1); 58 StringNode argument = tag.argument;
57 Uri resolved = base.resolve(argument.slowToString()); 59 Uri resolved = base.resolve(argument.dartString.slowToString());
58 if (resolved.toString() == "dart:core") { 60 if (resolved.toString() == "dart:core") {
59 implicitlyImportCoreLibrary = false; 61 implicitlyImportCoreLibrary = false;
60 } 62 }
61 importLibrary(library, loadLibrary(resolved, tag), tag); 63 importLibrary(library, loadLibrary(resolved, tag), tag);
62 } 64 }
63 if (implicitlyImportCoreLibrary) { 65 if (implicitlyImportCoreLibrary) {
64 importLibrary(library, compiler.coreLibrary, null); 66 importLibrary(library, compiler.coreLibrary, null);
65 } 67 }
66 } 68 }
67 69
(...skipping 29 matching lines...) Expand all
97 if (newLibrary) { 99 if (newLibrary) {
98 compiler.withCurrentElement(library, () => scan(library)); 100 compiler.withCurrentElement(library, () => scan(library));
99 compiler.onLibraryLoaded(library, uri); 101 compiler.onLibraryLoaded(library, uri);
100 } 102 }
101 return library; 103 return library;
102 } 104 }
103 105
104 void importLibrary(LibraryElement library, LibraryElement imported, 106 void importLibrary(LibraryElement library, LibraryElement imported,
105 ScriptTag tag) { 107 ScriptTag tag) {
106 if (tag !== null && tag.prefix !== null) { 108 if (tag !== null && tag.prefix !== null) {
107 SourceString prefix = tag.prefix.dartString.source; 109 SourceString prefix =
110 new SourceString(tag.prefix.dartString.slowToString());
ahe 2012/03/19 15:53:06 Something to consider: having a method named asSou
Lasse Reichstein Nielsen 2012/03/20 09:34:33 We do have that (dartString.source), but it includ
ahe 2012/03/20 10:23:01 Perhaps. I'm not sure what the specification says,
108 Element e = library.find(prefix); 111 Element e = library.find(prefix);
109 if (e === null) { 112 if (e === null) {
110 e = new PrefixElement(prefix, library); 113 e = new PrefixElement(prefix, library);
111 library.define(e, compiler); 114 library.define(e, compiler);
112 } 115 }
113 if (e.kind !== ElementKind.PREFIX) { 116 if (e.kind !== ElementKind.PREFIX) {
114 compiler.withCurrentElement(e, () { 117 compiler.withCurrentElement(e, () {
115 compiler.reportWarning(new Identifier(e.position()), 118 compiler.reportWarning(new Identifier(e.position()),
116 'duplicated definition'); 119 'duplicated definition');
117 }); 120 });
(...skipping 27 matching lines...) Expand all
145 final String name = 'Diet Parser'; 148 final String name = 'Diet Parser';
146 149
147 dietParse(CompilationUnitElement compilationUnit, Token tokens) { 150 dietParse(CompilationUnitElement compilationUnit, Token tokens) {
148 measure(() { 151 measure(() {
149 ElementListener listener = new ElementListener(compiler, compilationUnit); 152 ElementListener listener = new ElementListener(compiler, compilationUnit);
150 PartialParser parser = new PartialParser(listener); 153 PartialParser parser = new PartialParser(listener);
151 parser.parseUnit(tokens); 154 parser.parseUnit(tokens);
152 }); 155 });
153 } 156 }
154 } 157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698