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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/frog/leg/compiler.dart ('k') | dart/frog/leg/tree/nodes.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/scanner/scanner_task.dart
diff --git a/dart/frog/leg/scanner/scanner_task.dart b/dart/frog/leg/scanner/scanner_task.dart
index 74b0a97e27d114505d18464a7326522e3bd3f830..3997acdeae4131b40b815ca70cefba882927fe3d 100644
--- a/dart/frog/leg/scanner/scanner_task.dart
+++ b/dart/frog/leg/scanner/scanner_task.dart
@@ -3,6 +3,11 @@
// BSD-style license that can be found in the LICENSE file.
class ScannerTask extends CompilerTask {
+ static final int LIBRARY = 1;
Lasse Reichstein Nielsen 2012/03/23 08:10:59 Add comment saying that these are numbered in the
+ static final int IMPORT = 2;
+ 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
+ static final int RESOURCE = 4;
+
ScannerTask(Compiler compiler) : super(compiler);
String get name() => 'Scanner';
@@ -19,6 +24,16 @@ class ScannerTask extends CompilerTask {
}
void processScriptTags(LibraryElement library) {
+ 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
+
+ int checkTag(int currentState, ScriptTag tag) {
Lasse Reichstein Nielsen 2012/03/23 08:10:59 Add comment explaining that checkTag returns the [
+ 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
+ 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
+ return tagState;
+ }
+ return currentState;
+ }
+
LinkBuilder<ScriptTag> imports = new LinkBuilder<ScriptTag>();
Uri cwd = new Uri(scheme: 'file', path: compiler.currentDirectory);
Uri base = cwd.resolve(library.script.name.toString());
@@ -28,22 +43,28 @@ class ScannerTask extends CompilerTask {
// special constants that can be inserted into script tag strings.
Uri resolved = base.resolve(argument.dartString.slowToString());
if (tag.isImport()) {
+ tagState = checkTag(IMPORT, tag);
// It is not safe to import other libraries at this point as
// another library could then observe the current library
// before it fully declares all the members that are sourced
// in.
imports.addLast(tag);
} else if (tag.isLibrary()) {
+ 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.
if (library.libraryTag !== null) {
compiler.cancel("duplicated library declaration", node: tag);
} else {
library.libraryTag = tag;
}
} else if (tag.isSource()) {
+ tagState = checkTag(SOURCE, tag);
Script script = compiler.readScript(resolved, tag);
CompilationUnitElement unit =
new CompilationUnitElement(script, library);
compiler.withCurrentElement(unit, () => scan(unit));
+ } else if (tag.isResource()) {
+ tagState = checkTag(RESOURCE, tag);
+ compiler.reportWarning(tag, 'ignoring resource tag');
} else {
compiler.cancel("illegal script tag: ${tag.tag}", node: tag);
}
@@ -105,6 +126,12 @@ class ScannerTask extends CompilerTask {
void importLibrary(LibraryElement library, LibraryElement imported,
ScriptTag tag) {
+ 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
+ compiler.withCurrentElement(library, () {
+ compiler.reportError(tag,
+ 'no #library tag found in ${imported.script.uri}');
+ });
+ }
if (tag !== null && tag.prefix !== null) {
SourceString prefix =
new SourceString(tag.prefix.dartString.slowToString());
« 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