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

Side by Side 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: Add flag. Created 5 years, 2 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
« no previous file with comments | « no previous file | tests/language/config_import_test.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 #include "vm/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/ast_transformer.h" 9 #include "vm/ast_transformer.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 28 matching lines...) Expand all
39 namespace dart { 39 namespace dart {
40 40
41 DEFINE_FLAG(bool, enable_debug_break, false, "Allow use of break \"message\"."); 41 DEFINE_FLAG(bool, enable_debug_break, false, "Allow use of break \"message\".");
42 DEFINE_FLAG(bool, enable_mirrors, true, 42 DEFINE_FLAG(bool, enable_mirrors, true,
43 "Disable to make importing dart:mirrors an error."); 43 "Disable to make importing dart:mirrors an error.");
44 DEFINE_FLAG(bool, load_deferred_eagerly, false, 44 DEFINE_FLAG(bool, load_deferred_eagerly, false,
45 "Load deferred libraries eagerly."); 45 "Load deferred libraries eagerly.");
46 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); 46 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations.");
47 DEFINE_FLAG(bool, warn_mixin_typedef, true, "Warning on legacy mixin typedef."); 47 DEFINE_FLAG(bool, warn_mixin_typedef, true, "Warning on legacy mixin typedef.");
48 DEFINE_FLAG(bool, link_natives_lazily, false, "Link native calls lazily"); 48 DEFINE_FLAG(bool, link_natives_lazily, false, "Link native calls lazily");
49 DEFINE_FLAG(bool, conditional_directives, false,
50 "Enable conditional directives");
49 51
50 DECLARE_FLAG(bool, lazy_dispatchers); 52 DECLARE_FLAG(bool, lazy_dispatchers);
51 DECLARE_FLAG(bool, load_deferred_eagerly); 53 DECLARE_FLAG(bool, load_deferred_eagerly);
52 DECLARE_FLAG(bool, profile_vm); 54 DECLARE_FLAG(bool, profile_vm);
53 DECLARE_FLAG(bool, throw_on_javascript_int_overflow); 55 DECLARE_FLAG(bool, throw_on_javascript_int_overflow);
54 DECLARE_FLAG(bool, warn_on_javascript_compatibility); 56 DECLARE_FLAG(bool, warn_on_javascript_compatibility);
55 57
56 // Quick access to the current thread, isolate and zone. 58 // Quick access to the current thread, isolate and zone.
57 #define T (thread()) 59 #define T (thread())
58 #define I (isolate()) 60 #define I (isolate())
(...skipping 5766 matching lines...) Expand 10 before | Expand all | Expand 10 after
5825 5827
5826 5828
5827 void Parser::ParseLibraryImportExport(intptr_t metadata_pos) { 5829 void Parser::ParseLibraryImportExport(intptr_t metadata_pos) {
5828 bool is_import = (CurrentToken() == Token::kIMPORT); 5830 bool is_import = (CurrentToken() == Token::kIMPORT);
5829 bool is_export = (CurrentToken() == Token::kEXPORT); 5831 bool is_export = (CurrentToken() == Token::kEXPORT);
5830 ASSERT(is_import || is_export); 5832 ASSERT(is_import || is_export);
5831 const intptr_t import_pos = TokenPos(); 5833 const intptr_t import_pos = TokenPos();
5832 ConsumeToken(); 5834 ConsumeToken();
5833 CheckToken(Token::kSTRING, "library url expected"); 5835 CheckToken(Token::kSTRING, "library url expected");
5834 AstNode* url_literal = ParseStringLiteral(false); 5836 AstNode* url_literal = ParseStringLiteral(false);
5837 if (FLAG_conditional_directives) {
5838 bool condition_triggered = false;
5839 while (CurrentToken() == Token::kIF) {
5840 // Conditional import: if (env == val) uri.
5841 ConsumeToken();
5842 ExpectToken(Token::kLPAREN);
5843 // Parse dotted name.
5844 GrowableHandlePtrArray<const String> pieces(Z, 3);
5845 pieces.Add(*ExpectIdentifier("identifier expected"));
5846 while (CurrentToken() == Token::kPERIOD) {
5847 pieces.Add(Symbols::Dot());
5848 ConsumeToken();
5849 pieces.Add(*ExpectIdentifier("identifier expected"));
5850 }
5851 String& key = String::ZoneHandle(Z);
5852 key = Symbols::FromConcatAll(pieces);
5853 AstNode* valueNode = NULL;
5854 if (CurrentToken() == Token::kEQ) {
5855 ConsumeToken();
5856 valueNode = ParseStringLiteral(false);
hausner 2015/10/13 23:48:36 Can't just assume that the next token is indeed a
floitsch 2015/10/14 13:20:55 good catch. thanks. I mistakenly assumed the "Pars
5857 }
5858 ExpectToken(Token::kRPAREN);
5859 AstNode* conditional_url_literal = ParseStringLiteral(false);
hausner 2015/10/13 23:48:36 Ditto.
floitsch 2015/10/14 13:20:55 Done.
5860
5861 // If there was already a condition that triggered, don't try to match
5862 // again.
5863 if (condition_triggered) continue;
5864 // Check if this conditional line overrides the default import.
5865 const String& value = valueNode == NULL
hausner 2015/10/13 23:48:36 Instead of computing the value here, you could dec
floitsch 2015/10/14 13:20:55 Tried to do it, but then I had to allocate a new h
5866 ? Symbols::True()
5867 : String::Cast(valueNode->AsLiteralNode()->literal());
5868 // Call the embedder to supply us with the environment.
5869 const String& env_value =
5870 String::Handle(Api::CallEnvironmentCallback(isolate(), key));
5871 if (!env_value.IsNull() && env_value.Equals(value)) {
5872 condition_triggered = true;
5873 url_literal = conditional_url_literal;
5874 }
5875 }
5876 }
5835 ASSERT(url_literal->IsLiteralNode()); 5877 ASSERT(url_literal->IsLiteralNode());
5836 ASSERT(url_literal->AsLiteralNode()->literal().IsString()); 5878 ASSERT(url_literal->AsLiteralNode()->literal().IsString());
5837 const String& url = String::Cast(url_literal->AsLiteralNode()->literal()); 5879 const String& url = String::Cast(url_literal->AsLiteralNode()->literal());
5838 if (url.Length() == 0) { 5880 if (url.Length() == 0) {
5839 ReportError("library url expected"); 5881 ReportError("library url expected");
5840 } 5882 }
5841 bool is_deferred_import = false; 5883 bool is_deferred_import = false;
5842 if (is_import && (IsSymbol(Symbols::Deferred()))) { 5884 if (is_import && (IsSymbol(Symbols::Deferred()))) {
5843 is_deferred_import = true; 5885 is_deferred_import = true;
5844 ConsumeToken(); 5886 ConsumeToken();
(...skipping 8416 matching lines...) Expand 10 before | Expand all | Expand 10 after
14261 void Parser::SkipQualIdent() { 14303 void Parser::SkipQualIdent() {
14262 ASSERT(IsIdentifier()); 14304 ASSERT(IsIdentifier());
14263 ConsumeToken(); 14305 ConsumeToken();
14264 if (CurrentToken() == Token::kPERIOD) { 14306 if (CurrentToken() == Token::kPERIOD) {
14265 ConsumeToken(); // Consume the kPERIOD token. 14307 ConsumeToken(); // Consume the kPERIOD token.
14266 ExpectIdentifier("identifier expected after '.'"); 14308 ExpectIdentifier("identifier expected after '.'");
14267 } 14309 }
14268 } 14310 }
14269 14311
14270 } // namespace dart 14312 } // namespace dart
OLDNEW
« 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