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 "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 namespace dart { | 23 namespace dart { |
24 | 24 |
25 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements."); | 25 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements."); |
26 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks."); | 26 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks."); |
27 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); | 27 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); |
28 DEFINE_FLAG(bool, warning_as_error, false, "Treat warnings as errors."); | 28 DEFINE_FLAG(bool, warning_as_error, false, "Treat warnings as errors."); |
29 DEFINE_FLAG(bool, silent_warnings, false, "Silence warnings."); | 29 DEFINE_FLAG(bool, silent_warnings, false, "Silence warnings."); |
30 DEFINE_FLAG(bool, warn_legacy_map_literal, false, | 30 DEFINE_FLAG(bool, warn_legacy_map_literal, false, |
31 "Warning on legacy map literal syntax (single type argument)"); | 31 "Warning on legacy map literal syntax (single type argument)"); |
32 DEFINE_FLAG(bool, warn_legacy_dynamic, false, | |
33 "Warning on legacy type Dynamic)"); | |
34 DEFINE_FLAG(bool, warn_legacy_getters, false, | 32 DEFINE_FLAG(bool, warn_legacy_getters, false, |
35 "Warning on legacy getter syntax"); | 33 "Warning on legacy getter syntax"); |
36 DEFINE_FLAG(bool, strict_function_literals, false, | 34 DEFINE_FLAG(bool, strict_function_literals, false, |
37 "enforce new function literal rules"); | 35 "enforce new function literal rules"); |
38 DEFINE_FLAG(bool, fail_legacy_abstract, false, | 36 DEFINE_FLAG(bool, fail_legacy_abstract, false, |
39 "error on explicit use of abstract on class members"); | 37 "error on explicit use of abstract on class members"); |
40 | 38 |
41 static void CheckedModeHandler(bool value) { | 39 static void CheckedModeHandler(bool value) { |
42 FLAG_enable_asserts = value; | 40 FLAG_enable_asserts = value; |
43 FLAG_enable_type_checks = value; | 41 FLAG_enable_type_checks = value; |
(...skipping 6672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6716 CurrentToken() == Token::kIDENT ? | 6714 CurrentToken() == Token::kIDENT ? |
6717 CurrentLiteral()->ToCString() : Token::Str(CurrentToken())); | 6715 CurrentLiteral()->ToCString() : Token::Str(CurrentToken())); |
6718 } | 6716 } |
6719 | 6717 |
6720 | 6718 |
6721 String* Parser::ExpectUserDefinedTypeIdentifier(const char* msg) { | 6719 String* Parser::ExpectUserDefinedTypeIdentifier(const char* msg) { |
6722 if (CurrentToken() != Token::kIDENT) { | 6720 if (CurrentToken() != Token::kIDENT) { |
6723 ErrorMsg("%s", msg); | 6721 ErrorMsg("%s", msg); |
6724 } | 6722 } |
6725 String* ident = CurrentLiteral(); | 6723 String* ident = CurrentLiteral(); |
6726 // TODO(hausner): Remove check for 'Dynamic' once support for upper-case | 6724 if (ident->Equals("dynamic")) { |
6727 // type dynamic is gone. | |
6728 if (ident->Equals("Dynamic") || ident->Equals("dynamic")) { | |
6729 ErrorMsg("%s", msg); | 6725 ErrorMsg("%s", msg); |
6730 } | 6726 } |
6731 ConsumeToken(); | 6727 ConsumeToken(); |
6732 return ident; | 6728 return ident; |
6733 } | 6729 } |
6734 | 6730 |
6735 | 6731 |
6736 // Check whether current token is an identifier or a built-in identifier. | 6732 // Check whether current token is an identifier or a built-in identifier. |
6737 String* Parser::ExpectIdentifier(const char* msg) { | 6733 String* Parser::ExpectIdentifier(const char* msg) { |
6738 if (!IsIdentifier()) { | 6734 if (!IsIdentifier()) { |
(...skipping 1857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8596 ClassFinalizer::FinalizationKind finalization) { | 8592 ClassFinalizer::FinalizationKind finalization) { |
8597 TRACE_PARSER("ParseType"); | 8593 TRACE_PARSER("ParseType"); |
8598 if (CurrentToken() != Token::kIDENT) { | 8594 if (CurrentToken() != Token::kIDENT) { |
8599 ErrorMsg("type name expected"); | 8595 ErrorMsg("type name expected"); |
8600 } | 8596 } |
8601 QualIdent type_name; | 8597 QualIdent type_name; |
8602 if (finalization == ClassFinalizer::kIgnore) { | 8598 if (finalization == ClassFinalizer::kIgnore) { |
8603 SkipQualIdent(); | 8599 SkipQualIdent(); |
8604 } else { | 8600 } else { |
8605 ParseQualIdent(&type_name); | 8601 ParseQualIdent(&type_name); |
8606 // TODO(hausner): Remove this once support for legacy type 'Dynamic' | |
8607 // is removed. | |
8608 if ((type_name.lib_prefix == NULL) && type_name.ident->Equals("Dynamic")) { | |
8609 if (FLAG_warn_legacy_dynamic) { | |
8610 Warning(type_name.ident_pos, | |
8611 "legacy type 'Dynamic' found; auto-converting to 'dynamic'"); | |
8612 } | |
8613 // Replace with lower-case 'dynamic'. | |
8614 *type_name.ident ^= Symbols::Dynamic(); | |
8615 } | |
8616 // An identifier cannot be resolved in a local scope when top level parsing. | 8602 // An identifier cannot be resolved in a local scope when top level parsing. |
8617 if (!is_top_level_ && | 8603 if (!is_top_level_ && |
8618 (type_name.lib_prefix == NULL) && | 8604 (type_name.lib_prefix == NULL) && |
8619 ResolveIdentInLocalScope(type_name.ident_pos, *type_name.ident, NULL)) { | 8605 ResolveIdentInLocalScope(type_name.ident_pos, *type_name.ident, NULL)) { |
8620 ErrorMsg(type_name.ident_pos, "using '%s' in this context is invalid", | 8606 ErrorMsg(type_name.ident_pos, "using '%s' in this context is invalid", |
8621 type_name.ident->ToCString()); | 8607 type_name.ident->ToCString()); |
8622 } | 8608 } |
8623 } | 8609 } |
8624 Object& type_class = Object::Handle(); | 8610 Object& type_class = Object::Handle(); |
8625 // Leave type_class as null if type finalization mode is kIgnore. | 8611 // Leave type_class as null if type finalization mode is kIgnore. |
(...skipping 1417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10043 void Parser::SkipQualIdent() { | 10029 void Parser::SkipQualIdent() { |
10044 ASSERT(IsIdentifier()); | 10030 ASSERT(IsIdentifier()); |
10045 ConsumeToken(); | 10031 ConsumeToken(); |
10046 if (CurrentToken() == Token::kPERIOD) { | 10032 if (CurrentToken() == Token::kPERIOD) { |
10047 ConsumeToken(); // Consume the kPERIOD token. | 10033 ConsumeToken(); // Consume the kPERIOD token. |
10048 ExpectIdentifier("identifier expected after '.'"); | 10034 ExpectIdentifier("identifier expected after '.'"); |
10049 } | 10035 } |
10050 } | 10036 } |
10051 | 10037 |
10052 } // namespace dart | 10038 } // namespace dart |
OLD | NEW |