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

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

Issue 9838038: "Implement" #resource tag and various restrictions on library definitions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
« no previous file with comments | « dart/frog/leg/compiler.dart ('k') | dart/frog/leg/tree/nodes.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 class ScannerTask extends CompilerTask { 5 class ScannerTask extends CompilerTask {
6 static final int LIBRARY = 1;
Lasse Reichstein Nielsen 2012/03/23 08:10:59 Add comment saying that these are numbered in the
7 static final int IMPORT = 2;
8 static final int SOURCE = 3;
Lasse Reichstein Nielsen 2012/03/23 08:10:59 The spec uses the word "include" about the product
ahe 2012/03/23 08:44:35 I prefer the word "source" because I find it confu
9 static final int RESOURCE = 4;
10
6 ScannerTask(Compiler compiler) : super(compiler); 11 ScannerTask(Compiler compiler) : super(compiler);
7 String get name() => 'Scanner'; 12 String get name() => 'Scanner';
8 13
9 void scan(CompilationUnitElement compilationUnit) { 14 void scan(CompilationUnitElement compilationUnit) {
10 measure(() { 15 measure(() {
11 if (compilationUnit.kind === ElementKind.LIBRARY) { 16 if (compilationUnit.kind === ElementKind.LIBRARY) {
12 compiler.log("scanning library ${compilationUnit.script.name}"); 17 compiler.log("scanning library ${compilationUnit.script.name}");
13 } 18 }
14 scanElements(compilationUnit); 19 scanElements(compilationUnit);
15 if (compilationUnit.kind === ElementKind.LIBRARY) { 20 if (compilationUnit.kind === ElementKind.LIBRARY) {
16 processScriptTags(compilationUnit); 21 processScriptTags(compilationUnit);
17 } 22 }
18 }); 23 });
19 } 24 }
20 25
21 void processScriptTags(LibraryElement library) { 26 void processScriptTags(LibraryElement library) {
27 int tagState = 0;
Lasse Reichstein Nielsen 2012/03/23 08:10:59 Name is undescriptive. It is being used to remembe
ahe 2012/03/23 08:44:35 There is something about starting a zero that help
28
29 int checkTag(int currentState, ScriptTag tag) {
Lasse Reichstein Nielsen 2012/03/23 08:10:59 Add comment explaining that checkTag returns the [
30 if (tagState > currentState) {
Lasse Reichstein Nielsen 2012/03/23 08:10:59 Rename currentState to, e.g., newState. It's too e
ahe 2012/03/23 17:15:22 I agree. I can't come up with anything better so I
31 compiler.reportError(tag, 'out of order');
ngeoffray 2012/03/23 07:54:30 That's news to me. Not sure I like it.
ahe 2012/03/23 08:44:35 This is the same problem we have with final, stati
32 return tagState;
33 }
34 return currentState;
35 }
36
22 LinkBuilder<ScriptTag> imports = new LinkBuilder<ScriptTag>(); 37 LinkBuilder<ScriptTag> imports = new LinkBuilder<ScriptTag>();
23 Uri cwd = new Uri(scheme: 'file', path: compiler.currentDirectory); 38 Uri cwd = new Uri(scheme: 'file', path: compiler.currentDirectory);
24 Uri base = cwd.resolve(library.script.name.toString()); 39 Uri base = cwd.resolve(library.script.name.toString());
25 for (ScriptTag tag in library.tags.reverse()) { 40 for (ScriptTag tag in library.tags.reverse()) {
26 StringNode argument = tag.argument; 41 StringNode argument = tag.argument;
27 // TODO(lrn): Support interpolations here. We need access to the 42 // TODO(lrn): Support interpolations here. We need access to the
28 // special constants that can be inserted into script tag strings. 43 // special constants that can be inserted into script tag strings.
29 Uri resolved = base.resolve(argument.dartString.slowToString()); 44 Uri resolved = base.resolve(argument.dartString.slowToString());
30 if (tag.isImport()) { 45 if (tag.isImport()) {
46 tagState = checkTag(IMPORT, tag);
31 // It is not safe to import other libraries at this point as 47 // It is not safe to import other libraries at this point as
32 // another library could then observe the current library 48 // another library could then observe the current library
33 // before it fully declares all the members that are sourced 49 // before it fully declares all the members that are sourced
34 // in. 50 // in.
35 imports.addLast(tag); 51 imports.addLast(tag);
36 } else if (tag.isLibrary()) { 52 } else if (tag.isLibrary()) {
53 tagState = checkTag(LIBRARY, tag) + 1;
Lasse Reichstein Nielsen 2012/03/23 08:10:59 This is too cute. If the check fails, you increme
ahe 2012/03/23 17:15:22 Done.
37 if (library.libraryTag !== null) { 54 if (library.libraryTag !== null) {
38 compiler.cancel("duplicated library declaration", node: tag); 55 compiler.cancel("duplicated library declaration", node: tag);
39 } else { 56 } else {
40 library.libraryTag = tag; 57 library.libraryTag = tag;
41 } 58 }
42 } else if (tag.isSource()) { 59 } else if (tag.isSource()) {
60 tagState = checkTag(SOURCE, tag);
43 Script script = compiler.readScript(resolved, tag); 61 Script script = compiler.readScript(resolved, tag);
44 CompilationUnitElement unit = 62 CompilationUnitElement unit =
45 new CompilationUnitElement(script, library); 63 new CompilationUnitElement(script, library);
46 compiler.withCurrentElement(unit, () => scan(unit)); 64 compiler.withCurrentElement(unit, () => scan(unit));
65 } else if (tag.isResource()) {
66 tagState = checkTag(RESOURCE, tag);
67 compiler.reportWarning(tag, 'ignoring resource tag');
47 } else { 68 } else {
48 compiler.cancel("illegal script tag: ${tag.tag}", node: tag); 69 compiler.cancel("illegal script tag: ${tag.tag}", node: tag);
49 } 70 }
50 } 71 }
51 // TODO(ahe): During Compiler.scanBuiltinLibraries, 72 // TODO(ahe): During Compiler.scanBuiltinLibraries,
52 // compiler.coreLibrary is null. Clean this up when there is a 73 // compiler.coreLibrary is null. Clean this up when there is a
53 // better way to access "dart:core". 74 // better way to access "dart:core".
54 bool implicitlyImportCoreLibrary = compiler.coreLibrary !== null; 75 bool implicitlyImportCoreLibrary = compiler.coreLibrary !== null;
55 for (ScriptTag tag in imports.toLink()) { 76 for (ScriptTag tag in imports.toLink()) {
56 // Now that we have processed all the source tags, it is safe to 77 // Now that we have processed all the source tags, it is safe to
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 }); 119 });
99 if (newLibrary) { 120 if (newLibrary) {
100 compiler.withCurrentElement(library, () => scan(library)); 121 compiler.withCurrentElement(library, () => scan(library));
101 compiler.onLibraryLoaded(library, uri); 122 compiler.onLibraryLoaded(library, uri);
102 } 123 }
103 return library; 124 return library;
104 } 125 }
105 126
106 void importLibrary(LibraryElement library, LibraryElement imported, 127 void importLibrary(LibraryElement library, LibraryElement imported,
107 ScriptTag tag) { 128 ScriptTag tag) {
129 if (imported.tags.isEmpty()) {
ngeoffray 2012/03/23 07:54:30 Please add a comment that since we're checking the
ahe 2012/03/23 17:15:22 This is actually not correct. I forgot to add the
130 compiler.withCurrentElement(library, () {
131 compiler.reportError(tag,
132 'no #library tag found in ${imported.script.uri}');
133 });
134 }
108 if (tag !== null && tag.prefix !== null) { 135 if (tag !== null && tag.prefix !== null) {
109 SourceString prefix = 136 SourceString prefix =
110 new SourceString(tag.prefix.dartString.slowToString()); 137 new SourceString(tag.prefix.dartString.slowToString());
111 Element e = library.find(prefix); 138 Element e = library.find(prefix);
112 if (e === null) { 139 if (e === null) {
113 e = new PrefixElement(prefix, library, tag.getBeginToken()); 140 e = new PrefixElement(prefix, library, tag.getBeginToken());
114 library.define(e, compiler); 141 library.define(e, compiler);
115 } 142 }
116 if (e.kind !== ElementKind.PREFIX) { 143 if (e.kind !== ElementKind.PREFIX) {
117 compiler.withCurrentElement(e, () { 144 compiler.withCurrentElement(e, () {
(...skipping 30 matching lines...) Expand all
148 final String name = 'Diet Parser'; 175 final String name = 'Diet Parser';
149 176
150 dietParse(CompilationUnitElement compilationUnit, Token tokens) { 177 dietParse(CompilationUnitElement compilationUnit, Token tokens) {
151 measure(() { 178 measure(() {
152 ElementListener listener = new ElementListener(compiler, compilationUnit); 179 ElementListener listener = new ElementListener(compiler, compilationUnit);
153 PartialParser parser = new PartialParser(listener); 180 PartialParser parser = new PartialParser(listener);
154 parser.parseUnit(tokens); 181 parser.parseUnit(tokens);
155 }); 182 });
156 } 183 }
157 } 184 }
OLDNEW
« no previous file with comments | « dart/frog/leg/compiler.dart ('k') | dart/frog/leg/tree/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698