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

Side by Side Diff: runtime/vm/parser.cc

Issue 1851753002: Enable conditional directives by default. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
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 #include "vm/flags.h" 6 #include "vm/flags.h"
7 7
8 #ifndef DART_PRECOMPILED_RUNTIME 8 #ifndef DART_PRECOMPILED_RUNTIME
9 9
10 #include "lib/invocation_mirror.h" 10 #include "lib/invocation_mirror.h"
(...skipping 26 matching lines...) Expand all
37 #include "vm/tags.h" 37 #include "vm/tags.h"
38 #include "vm/timeline.h" 38 #include "vm/timeline.h"
39 #include "vm/timer.h" 39 #include "vm/timer.h"
40 #include "vm/zone.h" 40 #include "vm/zone.h"
41 41
42 namespace dart { 42 namespace dart {
43 43
44 DEFINE_FLAG(bool, enable_debug_break, false, "Allow use of break \"message\"."); 44 DEFINE_FLAG(bool, enable_debug_break, false, "Allow use of break \"message\".");
45 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); 45 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations.");
46 DEFINE_FLAG(bool, warn_mixin_typedef, true, "Warning on legacy mixin typedef."); 46 DEFINE_FLAG(bool, warn_mixin_typedef, true, "Warning on legacy mixin typedef.");
47 DEFINE_FLAG(bool, conditional_directives, false,
48 "Enable conditional directives");
49 DEFINE_FLAG(bool, warn_super, false, 47 DEFINE_FLAG(bool, warn_super, false,
50 "Warning if super initializer not last in initializer list."); 48 "Warning if super initializer not last in initializer list.");
51 DEFINE_FLAG(bool, await_is_keyword, false, 49 DEFINE_FLAG(bool, await_is_keyword, false,
52 "await and yield are treated as proper keywords in synchronous code."); 50 "await and yield are treated as proper keywords in synchronous code.");
53 51
54 DECLARE_FLAG(bool, profile_vm); 52 DECLARE_FLAG(bool, profile_vm);
55 DECLARE_FLAG(bool, trace_service); 53 DECLARE_FLAG(bool, trace_service);
56 54
57 // Quick access to the current thread, isolate and zone. 55 // Quick access to the current thread, isolate and zone.
58 #define T (thread()) 56 #define T (thread())
(...skipping 5732 matching lines...) Expand 10 before | Expand all | Expand 10 after
5791 5789
5792 void Parser::ParseLibraryImportExport(const Object& tl_owner, 5790 void Parser::ParseLibraryImportExport(const Object& tl_owner,
5793 TokenPosition metadata_pos) { 5791 TokenPosition metadata_pos) {
5794 bool is_import = (CurrentToken() == Token::kIMPORT); 5792 bool is_import = (CurrentToken() == Token::kIMPORT);
5795 bool is_export = (CurrentToken() == Token::kEXPORT); 5793 bool is_export = (CurrentToken() == Token::kEXPORT);
5796 ASSERT(is_import || is_export); 5794 ASSERT(is_import || is_export);
5797 const TokenPosition import_pos = TokenPos(); 5795 const TokenPosition import_pos = TokenPos();
5798 ConsumeToken(); 5796 ConsumeToken();
5799 CheckToken(Token::kSTRING, "library url expected"); 5797 CheckToken(Token::kSTRING, "library url expected");
5800 AstNode* url_literal = ParseStringLiteral(false); 5798 AstNode* url_literal = ParseStringLiteral(false);
5801 if (FLAG_conditional_directives) { 5799 bool condition_triggered = false;
5802 bool condition_triggered = false; 5800 while (CurrentToken() == Token::kIF) {
5803 while (CurrentToken() == Token::kIF) { 5801 // Conditional import: if (env == val) uri.
5804 // Conditional import: if (env == val) uri. 5802 ConsumeToken();
5803 ExpectToken(Token::kLPAREN);
5804 // Parse dotted name.
5805 const GrowableObjectArray& pieces =
5806 GrowableObjectArray::Handle(Z, GrowableObjectArray::New());
5807 pieces.Add(*ExpectIdentifier("identifier expected"));
5808 while (CurrentToken() == Token::kPERIOD) {
5809 pieces.Add(Symbols::Dot());
5805 ConsumeToken(); 5810 ConsumeToken();
5806 ExpectToken(Token::kLPAREN);
5807 // Parse dotted name.
5808 const GrowableObjectArray& pieces =
5809 GrowableObjectArray::Handle(Z, GrowableObjectArray::New());
5810 pieces.Add(*ExpectIdentifier("identifier expected")); 5811 pieces.Add(*ExpectIdentifier("identifier expected"));
5811 while (CurrentToken() == Token::kPERIOD) { 5812 }
5812 pieces.Add(Symbols::Dot()); 5813 AstNode* valueNode = NULL;
5813 ConsumeToken(); 5814 if (CurrentToken() == Token::kEQ) {
5814 pieces.Add(*ExpectIdentifier("identifier expected")); 5815 ConsumeToken();
5815 } 5816 CheckToken(Token::kSTRING, "string literal expected");
5816 AstNode* valueNode = NULL; 5817 valueNode = ParseStringLiteral(false);
5817 if (CurrentToken() == Token::kEQ) { 5818 ASSERT(valueNode->IsLiteralNode());
5818 ConsumeToken(); 5819 ASSERT(valueNode->AsLiteralNode()->literal().IsString());
5819 CheckToken(Token::kSTRING, "string literal expected"); 5820 }
5820 valueNode = ParseStringLiteral(false); 5821 ExpectToken(Token::kRPAREN);
5821 ASSERT(valueNode->IsLiteralNode()); 5822 CheckToken(Token::kSTRING, "library url expected");
5822 ASSERT(valueNode->AsLiteralNode()->literal().IsString()); 5823 AstNode* conditional_url_literal = ParseStringLiteral(false);
5823 }
5824 ExpectToken(Token::kRPAREN);
5825 CheckToken(Token::kSTRING, "library url expected");
5826 AstNode* conditional_url_literal = ParseStringLiteral(false);
5827 5824
5828 // If there was already a condition that triggered, don't try to match 5825 // If there was already a condition that triggered, don't try to match
5829 // again. 5826 // again.
5830 if (condition_triggered) { 5827 if (condition_triggered) {
5831 continue; 5828 continue;
5832 } 5829 }
5833 // Check if this conditional line overrides the default import. 5830 // Check if this conditional line overrides the default import.
5834 const String& key = String::Handle( 5831 const String& key = String::Handle(
5835 String::ConcatAll(Array::Handle(Array::MakeArray(pieces)))); 5832 String::ConcatAll(Array::Handle(Array::MakeArray(pieces))));
5836 const String& value = (valueNode == NULL) 5833 const String& value = (valueNode == NULL)
5837 ? Symbols::True() 5834 ? Symbols::True()
5838 : String::Cast(valueNode->AsLiteralNode()->literal()); 5835 : String::Cast(valueNode->AsLiteralNode()->literal());
5839 // Call the embedder to supply us with the environment. 5836 // Call the embedder to supply us with the environment.
5840 const String& env_value = 5837 const String& env_value =
5841 String::Handle(Api::GetEnvironmentValue(T, key)); 5838 String::Handle(Api::GetEnvironmentValue(T, key));
5842 if (!env_value.IsNull() && env_value.Equals(value)) { 5839 if (!env_value.IsNull() && env_value.Equals(value)) {
5843 condition_triggered = true; 5840 condition_triggered = true;
5844 url_literal = conditional_url_literal; 5841 url_literal = conditional_url_literal;
5845 }
5846 } 5842 }
5847 } 5843 }
5848 ASSERT(url_literal->IsLiteralNode()); 5844 ASSERT(url_literal->IsLiteralNode());
5849 ASSERT(url_literal->AsLiteralNode()->literal().IsString()); 5845 ASSERT(url_literal->AsLiteralNode()->literal().IsString());
5850 const String& url = String::Cast(url_literal->AsLiteralNode()->literal()); 5846 const String& url = String::Cast(url_literal->AsLiteralNode()->literal());
5851 if (url.Length() == 0) { 5847 if (url.Length() == 0) {
5852 ReportError("library url expected"); 5848 ReportError("library url expected");
5853 } 5849 }
5854 bool is_deferred_import = false; 5850 bool is_deferred_import = false;
5855 if (is_import && (IsSymbol(Symbols::Deferred()))) { 5851 if (is_import && (IsSymbol(Symbols::Deferred()))) {
(...skipping 8606 matching lines...) Expand 10 before | Expand all | Expand 10 after
14462 const ArgumentListNode& function_args, 14458 const ArgumentListNode& function_args,
14463 const LocalVariable* temp_for_last_arg, 14459 const LocalVariable* temp_for_last_arg,
14464 bool is_super_invocation) { 14460 bool is_super_invocation) {
14465 UNREACHABLE(); 14461 UNREACHABLE();
14466 return NULL; 14462 return NULL;
14467 } 14463 }
14468 14464
14469 } // namespace dart 14465 } // namespace dart
14470 14466
14471 #endif // DART_PRECOMPILED_RUNTIME 14467 #endif // DART_PRECOMPILED_RUNTIME
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698