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

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: Add #import tags. 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
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..d0a09b680ae26f03fb0ae604f2e911de9876a881 100644
--- a/dart/frog/leg/scanner/scanner_task.dart
+++ b/dart/frog/leg/scanner/scanner_task.dart
@@ -19,6 +19,21 @@ class ScannerTask extends CompilerTask {
}
void processScriptTags(LibraryElement library) {
+ int tagState = TagState.NO_TAG_SEEN;
+
+ /**
+ * If [value] is less than [tagState] complain and return
+ * [tagState]. Otherwise return the new value for [tagState]
+ * (transition function for state machine).
+ */
+ int checkTag(int value, ScriptTag tag) {
+ if (tagState > value) {
+ compiler.reportError(tag, 'out of order');
+ return tagState;
+ }
+ return TagState.NEXT[value];
+ }
+
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(TagState.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(TagState.LIBRARY, tag);
if (library.libraryTag !== null) {
compiler.cancel("duplicated library declaration", node: tag);
} else {
library.libraryTag = tag;
}
} else if (tag.isSource()) {
+ tagState = checkTag(TagState.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(TagState.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.hasLibraryName()) {
+ 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());
@@ -155,3 +182,23 @@ class DietParserTask extends CompilerTask {
});
}
}
+
+/**
+ * The fields of this class models a state machine for checking script
+ * tags come in the correct order.
+ */
+class TagState {
+ static final int NO_TAG_SEEN = 0;
+ static final int LIBRARY = 1;
+ static final int IMPORT = 2;
+ static final int SOURCE = 3;
+ static final int RESOURCE = 4;
+
+ /** Next state. */
+ static final List<int> NEXT =
+ const <int>[NO_TAG_SEEN,
+ IMPORT, // Only one library tag is allowed.
+ IMPORT,
+ SOURCE,
+ RESOURCE];
+}

Powered by Google App Engine
This is Rietveld 408576698