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 #include "vm/flags.h" | 6 #include "vm/flags.h" |
7 | 7 |
8 #ifndef DART_PRECOMPILED | 8 #ifndef DART_PRECOMPILED |
9 | 9 |
10 #include "lib/invocation_mirror.h" | 10 #include "lib/invocation_mirror.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 DEFINE_FLAG(bool, enable_debug_break, false, "Allow use of break \"message\"."); | 43 DEFINE_FLAG(bool, enable_debug_break, false, "Allow use of break \"message\"."); |
44 DEFINE_FLAG(bool, enable_mirrors, true, | 44 DEFINE_FLAG(bool, enable_mirrors, true, |
45 "Disable to make importing dart:mirrors an error."); | 45 "Disable to make importing dart:mirrors an error."); |
46 DEFINE_FLAG(bool, load_deferred_eagerly, false, | 46 DEFINE_FLAG(bool, load_deferred_eagerly, false, |
47 "Load deferred libraries eagerly."); | 47 "Load deferred libraries eagerly."); |
48 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); | 48 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); |
49 DEFINE_FLAG(bool, warn_mixin_typedef, true, "Warning on legacy mixin typedef."); | 49 DEFINE_FLAG(bool, warn_mixin_typedef, true, "Warning on legacy mixin typedef."); |
50 DEFINE_FLAG(bool, link_natives_lazily, false, "Link native calls lazily"); | 50 DEFINE_FLAG(bool, link_natives_lazily, false, "Link native calls lazily"); |
51 DEFINE_FLAG(bool, move_super, false, "Move super initializer to end of list"); | 51 DEFINE_FLAG(bool, move_super, false, "Move super initializer to end of list"); |
| 52 DEFINE_FLAG(bool, conditional_directives, false, |
| 53 "Enable conditional directives"); |
52 | 54 |
53 DECLARE_FLAG(bool, lazy_dispatchers); | 55 DECLARE_FLAG(bool, lazy_dispatchers); |
54 DECLARE_FLAG(bool, load_deferred_eagerly); | 56 DECLARE_FLAG(bool, load_deferred_eagerly); |
55 DECLARE_FLAG(bool, profile_vm); | 57 DECLARE_FLAG(bool, profile_vm); |
56 DECLARE_FLAG(bool, throw_on_javascript_int_overflow); | 58 DECLARE_FLAG(bool, throw_on_javascript_int_overflow); |
57 DECLARE_FLAG(bool, warn_on_javascript_compatibility); | 59 DECLARE_FLAG(bool, warn_on_javascript_compatibility); |
58 | 60 |
59 // Quick access to the current thread, isolate and zone. | 61 // Quick access to the current thread, isolate and zone. |
60 #define T (thread()) | 62 #define T (thread()) |
61 #define I (isolate()) | 63 #define I (isolate()) |
(...skipping 5872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5934 | 5936 |
5935 void Parser::ParseLibraryImportExport(const Object& tl_owner, | 5937 void Parser::ParseLibraryImportExport(const Object& tl_owner, |
5936 intptr_t metadata_pos) { | 5938 intptr_t metadata_pos) { |
5937 bool is_import = (CurrentToken() == Token::kIMPORT); | 5939 bool is_import = (CurrentToken() == Token::kIMPORT); |
5938 bool is_export = (CurrentToken() == Token::kEXPORT); | 5940 bool is_export = (CurrentToken() == Token::kEXPORT); |
5939 ASSERT(is_import || is_export); | 5941 ASSERT(is_import || is_export); |
5940 const intptr_t import_pos = TokenPos(); | 5942 const intptr_t import_pos = TokenPos(); |
5941 ConsumeToken(); | 5943 ConsumeToken(); |
5942 CheckToken(Token::kSTRING, "library url expected"); | 5944 CheckToken(Token::kSTRING, "library url expected"); |
5943 AstNode* url_literal = ParseStringLiteral(false); | 5945 AstNode* url_literal = ParseStringLiteral(false); |
| 5946 if (FLAG_conditional_directives) { |
| 5947 bool condition_triggered = false; |
| 5948 while (CurrentToken() == Token::kIF) { |
| 5949 // Conditional import: if (env == val) uri. |
| 5950 ConsumeToken(); |
| 5951 ExpectToken(Token::kLPAREN); |
| 5952 // Parse dotted name. |
| 5953 const GrowableObjectArray& pieces = |
| 5954 GrowableObjectArray::Handle(Z, GrowableObjectArray::New()); |
| 5955 pieces.Add(*ExpectIdentifier("identifier expected")); |
| 5956 while (CurrentToken() == Token::kPERIOD) { |
| 5957 pieces.Add(Symbols::Dot()); |
| 5958 ConsumeToken(); |
| 5959 pieces.Add(*ExpectIdentifier("identifier expected")); |
| 5960 } |
| 5961 AstNode* valueNode = NULL; |
| 5962 if (CurrentToken() == Token::kEQ) { |
| 5963 ConsumeToken(); |
| 5964 CheckToken(Token::kSTRING, "string literal expected"); |
| 5965 valueNode = ParseStringLiteral(false); |
| 5966 ASSERT(valueNode->IsLiteralNode()); |
| 5967 ASSERT(valueNode->AsLiteralNode()->literal().IsString()); |
| 5968 } |
| 5969 ExpectToken(Token::kRPAREN); |
| 5970 CheckToken(Token::kSTRING, "library url expected"); |
| 5971 AstNode* conditional_url_literal = ParseStringLiteral(false); |
| 5972 |
| 5973 // If there was already a condition that triggered, don't try to match |
| 5974 // again. |
| 5975 if (condition_triggered) { |
| 5976 continue; |
| 5977 } |
| 5978 // Check if this conditional line overrides the default import. |
| 5979 const String& key = String::Handle( |
| 5980 String::ConcatAll(Array::Handle(Array::MakeArray(pieces)))); |
| 5981 const String& value = (valueNode == NULL) |
| 5982 ? Symbols::True() |
| 5983 : String::Cast(valueNode->AsLiteralNode()->literal()); |
| 5984 // Call the embedder to supply us with the environment. |
| 5985 const String& env_value = |
| 5986 String::Handle(Api::CallEnvironmentCallback(T, key)); |
| 5987 if (!env_value.IsNull() && env_value.Equals(value)) { |
| 5988 condition_triggered = true; |
| 5989 url_literal = conditional_url_literal; |
| 5990 } |
| 5991 } |
| 5992 } |
5944 ASSERT(url_literal->IsLiteralNode()); | 5993 ASSERT(url_literal->IsLiteralNode()); |
5945 ASSERT(url_literal->AsLiteralNode()->literal().IsString()); | 5994 ASSERT(url_literal->AsLiteralNode()->literal().IsString()); |
5946 const String& url = String::Cast(url_literal->AsLiteralNode()->literal()); | 5995 const String& url = String::Cast(url_literal->AsLiteralNode()->literal()); |
5947 if (url.Length() == 0) { | 5996 if (url.Length() == 0) { |
5948 ReportError("library url expected"); | 5997 ReportError("library url expected"); |
5949 } | 5998 } |
5950 bool is_deferred_import = false; | 5999 bool is_deferred_import = false; |
5951 if (is_import && (IsSymbol(Symbols::Deferred()))) { | 6000 if (is_import && (IsSymbol(Symbols::Deferred()))) { |
5952 is_deferred_import = true; | 6001 is_deferred_import = true; |
5953 ConsumeToken(); | 6002 ConsumeToken(); |
(...skipping 8526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14480 const ArgumentListNode& function_args, | 14529 const ArgumentListNode& function_args, |
14481 const LocalVariable* temp_for_last_arg, | 14530 const LocalVariable* temp_for_last_arg, |
14482 bool is_super_invocation) { | 14531 bool is_super_invocation) { |
14483 UNREACHABLE(); | 14532 UNREACHABLE(); |
14484 return NULL; | 14533 return NULL; |
14485 } | 14534 } |
14486 | 14535 |
14487 } // namespace dart | 14536 } // namespace dart |
14488 | 14537 |
14489 #endif // DART_PRECOMPILED | 14538 #endif // DART_PRECOMPILED |
OLD | NEW |