OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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); | |
Ivan Posva
2015/12/17 06:29:43
Why is this not a const String&? Also you do not n
floitsch
2015/12/17 17:08:43
Done.
| |
5852 key = Symbols::FromConcatAll(pieces); | |
Ivan Posva
2015/12/17 06:29:43
The key does not need to be a Symbol and should on
floitsch
2015/12/17 17:08:43
There isn't a good way to concatenate strings exce
| |
5853 AstNode* valueNode = NULL; | |
5854 if (CurrentToken() == Token::kEQ) { | |
5855 ConsumeToken(); | |
5856 CheckToken(Token::kSTRING, "string literal expected"); | |
5857 valueNode = ParseStringLiteral(false); | |
5858 } | |
5859 ExpectToken(Token::kRPAREN); | |
5860 CheckToken(Token::kSTRING, "library url expected"); | |
5861 AstNode* conditional_url_literal = ParseStringLiteral(false); | |
5862 | |
5863 // If there was already a condition that triggered, don't try to match | |
5864 // again. | |
5865 if (condition_triggered) continue; | |
Ivan Posva
2015/12/17 06:29:43
VM style is:
if (expr) {
statements;
}
floitsch
2015/12/17 17:08:43
Done.
| |
5866 // Check if this conditional line overrides the default import. | |
5867 const String& value = valueNode == NULL | |
Ivan Posva
2015/12/17 06:29:43
(valueNode == NULL)
floitsch
2015/12/17 17:08:43
Done.
| |
5868 ? Symbols::True() | |
5869 : String::Cast(valueNode->AsLiteralNode()->literal()); | |
Ivan Posva
2015/12/17 06:29:43
Please use the same assertions as below on line 58
floitsch
2015/12/17 17:08:43
Done.
| |
5870 // Call the embedder to supply us with the environment. | |
5871 const String& env_value = | |
5872 String::Handle(Api::CallEnvironmentCallback(isolate(), key)); | |
5873 if (!env_value.IsNull() && env_value.Equals(value)) { | |
5874 condition_triggered = true; | |
5875 url_literal = conditional_url_literal; | |
5876 } | |
5877 } | |
5878 } | |
5835 ASSERT(url_literal->IsLiteralNode()); | 5879 ASSERT(url_literal->IsLiteralNode()); |
5836 ASSERT(url_literal->AsLiteralNode()->literal().IsString()); | 5880 ASSERT(url_literal->AsLiteralNode()->literal().IsString()); |
5837 const String& url = String::Cast(url_literal->AsLiteralNode()->literal()); | 5881 const String& url = String::Cast(url_literal->AsLiteralNode()->literal()); |
5838 if (url.Length() == 0) { | 5882 if (url.Length() == 0) { |
5839 ReportError("library url expected"); | 5883 ReportError("library url expected"); |
5840 } | 5884 } |
5841 bool is_deferred_import = false; | 5885 bool is_deferred_import = false; |
5842 if (is_import && (IsSymbol(Symbols::Deferred()))) { | 5886 if (is_import && (IsSymbol(Symbols::Deferred()))) { |
5843 is_deferred_import = true; | 5887 is_deferred_import = true; |
5844 ConsumeToken(); | 5888 ConsumeToken(); |
(...skipping 8416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14261 void Parser::SkipQualIdent() { | 14305 void Parser::SkipQualIdent() { |
14262 ASSERT(IsIdentifier()); | 14306 ASSERT(IsIdentifier()); |
14263 ConsumeToken(); | 14307 ConsumeToken(); |
14264 if (CurrentToken() == Token::kPERIOD) { | 14308 if (CurrentToken() == Token::kPERIOD) { |
14265 ConsumeToken(); // Consume the kPERIOD token. | 14309 ConsumeToken(); // Consume the kPERIOD token. |
14266 ExpectIdentifier("identifier expected after '.'"); | 14310 ExpectIdentifier("identifier expected after '.'"); |
14267 } | 14311 } |
14268 } | 14312 } |
14269 | 14313 |
14270 } // namespace dart | 14314 } // namespace dart |
OLD | NEW |