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

Unified Diff: runtime/vm/parser.cc

Issue 1380383002: Add support for configuration-specific imports to the VM. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments. Created 5 years 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 | « no previous file | tests/language/config_import_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc
index 15393a0d0b41b74017becaeb4d9af45f9354077c..06478250fb51fe054d616621a133470740128c4b 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -49,6 +49,8 @@ DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations.");
DEFINE_FLAG(bool, warn_mixin_typedef, true, "Warning on legacy mixin typedef.");
DEFINE_FLAG(bool, link_natives_lazily, false, "Link native calls lazily");
DEFINE_FLAG(bool, move_super, false, "Move super initializer to end of list");
+DEFINE_FLAG(bool, conditional_directives, false,
+ "Enable conditional directives");
DECLARE_FLAG(bool, lazy_dispatchers);
DECLARE_FLAG(bool, load_deferred_eagerly);
@@ -5941,6 +5943,53 @@ void Parser::ParseLibraryImportExport(const Object& tl_owner,
ConsumeToken();
CheckToken(Token::kSTRING, "library url expected");
AstNode* url_literal = ParseStringLiteral(false);
+ if (FLAG_conditional_directives) {
+ bool condition_triggered = false;
+ while (CurrentToken() == Token::kIF) {
+ // Conditional import: if (env == val) uri.
+ ConsumeToken();
+ ExpectToken(Token::kLPAREN);
+ // Parse dotted name.
+ const GrowableObjectArray& pieces =
+ GrowableObjectArray::Handle(Z, GrowableObjectArray::New());
+ pieces.Add(*ExpectIdentifier("identifier expected"));
+ while (CurrentToken() == Token::kPERIOD) {
+ pieces.Add(Symbols::Dot());
+ ConsumeToken();
+ pieces.Add(*ExpectIdentifier("identifier expected"));
+ }
+ AstNode* valueNode = NULL;
+ if (CurrentToken() == Token::kEQ) {
+ ConsumeToken();
+ CheckToken(Token::kSTRING, "string literal expected");
+ valueNode = ParseStringLiteral(false);
+ ASSERT(valueNode->IsLiteralNode());
+ ASSERT(valueNode->AsLiteralNode()->literal().IsString());
+ }
+ ExpectToken(Token::kRPAREN);
+ CheckToken(Token::kSTRING, "library url expected");
+ AstNode* conditional_url_literal = ParseStringLiteral(false);
+
+ // If there was already a condition that triggered, don't try to match
+ // again.
+ if (condition_triggered) {
+ continue;
+ }
+ // Check if this conditional line overrides the default import.
+ const String& key = String::Handle(
+ String::ConcatAll(Array::Handle(Array::MakeArray(pieces))));
+ const String& value = (valueNode == NULL)
+ ? Symbols::True()
+ : String::Cast(valueNode->AsLiteralNode()->literal());
+ // Call the embedder to supply us with the environment.
+ const String& env_value =
+ String::Handle(Api::CallEnvironmentCallback(T, key));
+ if (!env_value.IsNull() && env_value.Equals(value)) {
+ condition_triggered = true;
+ url_literal = conditional_url_literal;
+ }
+ }
+ }
ASSERT(url_literal->IsLiteralNode());
ASSERT(url_literal->AsLiteralNode()->literal().IsString());
const String& url = String::Cast(url_literal->AsLiteralNode()->literal());
« no previous file with comments | « no previous file | tests/language/config_import_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698