| 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, strict_function_literals, false, | |
| 33 "enforce new function literal rules"); | |
| 34 | 32 |
| 35 static void CheckedModeHandler(bool value) { | 33 static void CheckedModeHandler(bool value) { |
| 36 FLAG_enable_asserts = value; | 34 FLAG_enable_asserts = value; |
| 37 FLAG_enable_type_checks = value; | 35 FLAG_enable_type_checks = value; |
| 38 } | 36 } |
| 39 | 37 |
| 40 // --enable-checked-mode and --checked both enable checked mode which is | 38 // --enable-checked-mode and --checked both enable checked mode which is |
| 41 // equivalent to setting --enable-asserts and --enable-type-checks. | 39 // equivalent to setting --enable-asserts and --enable-type-checks. |
| 42 DEFINE_FLAG_HANDLER(CheckedModeHandler, | 40 DEFINE_FLAG_HANDLER(CheckedModeHandler, |
| 43 enable_checked_mode, | 41 enable_checked_mode, |
| (...skipping 4677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4721 | 4719 |
| 4722 AstNode* Parser::ParseFunctionStatement(bool is_literal) { | 4720 AstNode* Parser::ParseFunctionStatement(bool is_literal) { |
| 4723 TRACE_PARSER("ParseFunctionStatement"); | 4721 TRACE_PARSER("ParseFunctionStatement"); |
| 4724 AbstractType& result_type = AbstractType::Handle(); | 4722 AbstractType& result_type = AbstractType::Handle(); |
| 4725 const String* variable_name = NULL; | 4723 const String* variable_name = NULL; |
| 4726 const String* function_name = NULL; | 4724 const String* function_name = NULL; |
| 4727 | 4725 |
| 4728 result_type = Type::DynamicType(); | 4726 result_type = Type::DynamicType(); |
| 4729 | 4727 |
| 4730 intptr_t ident_pos = TokenPos(); | 4728 intptr_t ident_pos = TokenPos(); |
| 4731 if (FLAG_strict_function_literals) { | 4729 if (is_literal) { |
| 4732 if (is_literal) { | 4730 ASSERT(CurrentToken() == Token::kLPAREN); |
| 4733 ASSERT(CurrentToken() == Token::kLPAREN); | 4731 function_name = &Symbols::AnonymousClosure(); |
| 4734 function_name = &Symbols::AnonymousClosure(); | |
| 4735 } else { | |
| 4736 if (CurrentToken() == Token::kVOID) { | |
| 4737 ConsumeToken(); | |
| 4738 result_type = Type::VoidType(); | |
| 4739 } else if ((CurrentToken() == Token::kIDENT) && | |
| 4740 (LookaheadToken(1) != Token::kLPAREN)) { | |
| 4741 result_type = ParseType(ClassFinalizer::kCanonicalize); | |
| 4742 } | |
| 4743 ident_pos = TokenPos(); | |
| 4744 variable_name = ExpectIdentifier("function name expected"); | |
| 4745 function_name = variable_name; | |
| 4746 } | |
| 4747 } else { | 4732 } else { |
| 4748 // TODO(hausner) remove this block once support for old-style function | |
| 4749 // literals is gone. | |
| 4750 if (CurrentToken() == Token::kVOID) { | 4733 if (CurrentToken() == Token::kVOID) { |
| 4751 ConsumeToken(); | 4734 ConsumeToken(); |
| 4752 result_type = Type::VoidType(); | 4735 result_type = Type::VoidType(); |
| 4753 } else if ((CurrentToken() == Token::kIDENT) && | 4736 } else if ((CurrentToken() == Token::kIDENT) && |
| 4754 (LookaheadToken(1) != Token::kLPAREN)) { | 4737 (LookaheadToken(1) != Token::kLPAREN)) { |
| 4755 result_type = ParseType(ClassFinalizer::kCanonicalize); | 4738 result_type = ParseType(ClassFinalizer::kCanonicalize); |
| 4756 } | 4739 } |
| 4757 ident_pos = TokenPos(); | 4740 ident_pos = TokenPos(); |
| 4758 if (IsIdentifier()) { | 4741 variable_name = ExpectIdentifier("function name expected"); |
| 4759 variable_name = CurrentLiteral(); | 4742 function_name = variable_name; |
| 4760 function_name = variable_name; | |
| 4761 ConsumeToken(); | |
| 4762 } else { | |
| 4763 if (!is_literal) { | |
| 4764 ErrorMsg("function name expected"); | |
| 4765 } | |
| 4766 function_name = &Symbols::AnonymousClosure(); | |
| 4767 } | |
| 4768 } | 4743 } |
| 4769 | 4744 |
| 4770 if (CurrentToken() != Token::kLPAREN) { | 4745 if (CurrentToken() != Token::kLPAREN) { |
| 4771 ErrorMsg("'(' expected"); | 4746 ErrorMsg("'(' expected"); |
| 4772 } | 4747 } |
| 4773 intptr_t function_pos = TokenPos(); | 4748 intptr_t function_pos = TokenPos(); |
| 4774 | 4749 |
| 4775 // Check whether we have parsed this closure function before, in a previous | 4750 // Check whether we have parsed this closure function before, in a previous |
| 4776 // compilation. If so, reuse the function object, else create a new one | 4751 // compilation. If so, reuse the function object, else create a new one |
| 4777 // and register it in the current class. | 4752 // and register it in the current class. |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5164 return true; | 5139 return true; |
| 5165 } | 5140 } |
| 5166 } | 5141 } |
| 5167 } | 5142 } |
| 5168 SetPosition(saved_pos); | 5143 SetPosition(saved_pos); |
| 5169 return false; | 5144 return false; |
| 5170 } | 5145 } |
| 5171 | 5146 |
| 5172 | 5147 |
| 5173 bool Parser::IsFunctionLiteral() { | 5148 bool Parser::IsFunctionLiteral() { |
| 5174 // TODO(hausner): Remove code block that supports old-style function | 5149 if (CurrentToken() != Token::kLPAREN || !allow_function_literals_) { |
| 5175 // literals. | 5150 return false; |
| 5176 if (FLAG_strict_function_literals) { | |
| 5177 if (CurrentToken() != Token::kLPAREN || !allow_function_literals_) { | |
| 5178 return false; | |
| 5179 } | |
| 5180 const intptr_t saved_pos = TokenPos(); | |
| 5181 bool is_function_literal = false; | |
| 5182 SkipToMatchingParenthesis(); | |
| 5183 if ((CurrentToken() == Token::kLBRACE) || | |
| 5184 (CurrentToken() == Token::kARROW)) { | |
| 5185 is_function_literal = true; | |
| 5186 } | |
| 5187 SetPosition(saved_pos); | |
| 5188 return is_function_literal; | |
| 5189 } else { | |
| 5190 if (!allow_function_literals_) { | |
| 5191 return false; | |
| 5192 } | |
| 5193 const intptr_t saved_pos = TokenPos(); | |
| 5194 bool is_function_literal = false; | |
| 5195 if (IsIdentifier() && (LookaheadToken(1) == Token::kLPAREN)) { | |
| 5196 ConsumeToken(); // Consume function identifier. | |
| 5197 } else if (TryParseReturnType()) { | |
| 5198 if (!IsIdentifier()) { | |
| 5199 SetPosition(saved_pos); | |
| 5200 return false; | |
| 5201 } | |
| 5202 ConsumeToken(); // Comsume function identifier. | |
| 5203 } | |
| 5204 if (CurrentToken() == Token::kLPAREN) { | |
| 5205 SkipToMatchingParenthesis(); | |
| 5206 if ((CurrentToken() == Token::kLBRACE) || | |
| 5207 (CurrentToken() == Token::kARROW)) { | |
| 5208 is_function_literal = true; | |
| 5209 } | |
| 5210 } | |
| 5211 SetPosition(saved_pos); | |
| 5212 return is_function_literal; | |
| 5213 } | 5151 } |
| 5152 const intptr_t saved_pos = TokenPos(); |
| 5153 bool is_function_literal = false; |
| 5154 SkipToMatchingParenthesis(); |
| 5155 if ((CurrentToken() == Token::kLBRACE) || |
| 5156 (CurrentToken() == Token::kARROW)) { |
| 5157 is_function_literal = true; |
| 5158 } |
| 5159 SetPosition(saved_pos); |
| 5160 return is_function_literal; |
| 5214 } | 5161 } |
| 5215 | 5162 |
| 5216 | 5163 |
| 5217 // Current token position is the token after the opening ( of the for | 5164 // Current token position is the token after the opening ( of the for |
| 5218 // statement. Returns true if we recognize a for ( .. in expr) | 5165 // statement. Returns true if we recognize a for ( .. in expr) |
| 5219 // statement. | 5166 // statement. |
| 5220 bool Parser::IsForInStatement() { | 5167 bool Parser::IsForInStatement() { |
| 5221 const intptr_t saved_pos = TokenPos(); | 5168 const intptr_t saved_pos = TokenPos(); |
| 5222 bool result = false; | 5169 bool result = false; |
| 5223 // Allow const modifier as well when recognizing a for-in statement | 5170 // Allow const modifier as well when recognizing a for-in statement |
| (...skipping 4504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9728 void Parser::SkipQualIdent() { | 9675 void Parser::SkipQualIdent() { |
| 9729 ASSERT(IsIdentifier()); | 9676 ASSERT(IsIdentifier()); |
| 9730 ConsumeToken(); | 9677 ConsumeToken(); |
| 9731 if (CurrentToken() == Token::kPERIOD) { | 9678 if (CurrentToken() == Token::kPERIOD) { |
| 9732 ConsumeToken(); // Consume the kPERIOD token. | 9679 ConsumeToken(); // Consume the kPERIOD token. |
| 9733 ExpectIdentifier("identifier expected after '.'"); | 9680 ExpectIdentifier("identifier expected after '.'"); |
| 9734 } | 9681 } |
| 9735 } | 9682 } |
| 9736 | 9683 |
| 9737 } // namespace dart | 9684 } // namespace dart |
| OLD | NEW |