| 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 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1308 const ArgumentListNode& function_args) { | 1308 const ArgumentListNode& function_args) { |
| 1309 ASSERT(function_args.length() >= 1); // The receiver is the first argument. | 1309 ASSERT(function_args.length() >= 1); // The receiver is the first argument. |
| 1310 const intptr_t args_pos = function_args.token_pos(); | 1310 const intptr_t args_pos = function_args.token_pos(); |
| 1311 ArgumentListNode* arguments = new ArgumentListNode(args_pos); | 1311 ArgumentListNode* arguments = new ArgumentListNode(args_pos); |
| 1312 arguments->Add(function_args.NodeAt(0)); | 1312 arguments->Add(function_args.NodeAt(0)); |
| 1313 // The second argument is the original function name. | 1313 // The second argument is the original function name. |
| 1314 // TODO(regis): This will change once mirrors are supported. | 1314 // TODO(regis): This will change once mirrors are supported. |
| 1315 arguments->Add(new LiteralNode(args_pos, function_name)); | 1315 arguments->Add(new LiteralNode(args_pos, function_name)); |
| 1316 // The third argument is an array containing the original function arguments. | 1316 // The third argument is an array containing the original function arguments. |
| 1317 ArrayNode* args_array = new ArrayNode( | 1317 ArrayNode* args_array = new ArrayNode( |
| 1318 args_pos, Type::ZoneHandle(Type::ListInterface())); | 1318 args_pos, Type::ZoneHandle(Type::ListType())); |
| 1319 for (intptr_t i = 1; i < function_args.length(); i++) { | 1319 for (intptr_t i = 1; i < function_args.length(); i++) { |
| 1320 args_array->AddElement(function_args.NodeAt(i)); | 1320 args_array->AddElement(function_args.NodeAt(i)); |
| 1321 } | 1321 } |
| 1322 arguments->Add(args_array); | 1322 arguments->Add(args_array); |
| 1323 return arguments; | 1323 return arguments; |
| 1324 } | 1324 } |
| 1325 | 1325 |
| 1326 | 1326 |
| 1327 AstNode* Parser::ParseSuperCall(const String& function_name) { | 1327 AstNode* Parser::ParseSuperCall(const String& function_name) { |
| 1328 TRACE_PARSER("ParseSuperCall"); | 1328 TRACE_PARSER("ParseSuperCall"); |
| (...skipping 3710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5039 bool no_check = type.IsDynamicType(); | 5039 bool no_check = type.IsDynamicType(); |
| 5040 if ((CurrentToken() == Token::kINTEGER) && | 5040 if ((CurrentToken() == Token::kINTEGER) && |
| 5041 (no_check || type.IsIntType() || type.IsNumberType())) { | 5041 (no_check || type.IsIntType() || type.IsNumberType())) { |
| 5042 *value = CurrentIntegerLiteral(); | 5042 *value = CurrentIntegerLiteral(); |
| 5043 return true; | 5043 return true; |
| 5044 } else if ((CurrentToken() == Token::kDOUBLE) && | 5044 } else if ((CurrentToken() == Token::kDOUBLE) && |
| 5045 (no_check || type.IsDoubleType() || type.IsNumberType())) { | 5045 (no_check || type.IsDoubleType() || type.IsNumberType())) { |
| 5046 *value = CurrentDoubleLiteral(); | 5046 *value = CurrentDoubleLiteral(); |
| 5047 return true; | 5047 return true; |
| 5048 } else if ((CurrentToken() == Token::kSTRING) && | 5048 } else if ((CurrentToken() == Token::kSTRING) && |
| 5049 (no_check || type.IsStringInterface())) { | 5049 (no_check || type.IsStringType())) { |
| 5050 *value = CurrentLiteral()->raw(); | 5050 *value = CurrentLiteral()->raw(); |
| 5051 return true; | 5051 return true; |
| 5052 } else if ((CurrentToken() == Token::kTRUE) && | 5052 } else if ((CurrentToken() == Token::kTRUE) && |
| 5053 (no_check || type.IsBoolType())) { | 5053 (no_check || type.IsBoolType())) { |
| 5054 *value = Bool::True(); | 5054 *value = Bool::True(); |
| 5055 return true; | 5055 return true; |
| 5056 } else if ((CurrentToken() == Token::kFALSE) && | 5056 } else if ((CurrentToken() == Token::kFALSE) && |
| 5057 (no_check || type.IsBoolType())) { | 5057 (no_check || type.IsBoolType())) { |
| 5058 *value = Bool::False(); | 5058 *value = Bool::False(); |
| 5059 return true; | 5059 return true; |
| (...skipping 3421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8481 "the element type"); | 8481 "the element type"); |
| 8482 } | 8482 } |
| 8483 if (is_const && !element_type.IsInstantiated()) { | 8483 if (is_const && !element_type.IsInstantiated()) { |
| 8484 ErrorMsg(type_pos, | 8484 ErrorMsg(type_pos, |
| 8485 "the type argument of a constant list literal cannot include " | 8485 "the type argument of a constant list literal cannot include " |
| 8486 "a type variable"); | 8486 "a type variable"); |
| 8487 } | 8487 } |
| 8488 } | 8488 } |
| 8489 ASSERT(type_arguments.IsNull() || (type_arguments.Length() == 1)); | 8489 ASSERT(type_arguments.IsNull() || (type_arguments.Length() == 1)); |
| 8490 const Class& list_class = Class::Handle( | 8490 const Class& list_class = Class::Handle( |
| 8491 Type::Handle(Type::ListInterface()).type_class()); | 8491 Type::Handle(Type::ListType()).type_class()); |
| 8492 Type& type = Type::ZoneHandle( | 8492 Type& type = Type::ZoneHandle( |
| 8493 Type::New(list_class, type_arguments, type_pos)); | 8493 Type::New(list_class, type_arguments, type_pos)); |
| 8494 type ^= ClassFinalizer::FinalizeType( | 8494 type ^= ClassFinalizer::FinalizeType( |
| 8495 current_class(), type, ClassFinalizer::kCanonicalize); | 8495 current_class(), type, ClassFinalizer::kCanonicalize); |
| 8496 ArrayNode* list = new ArrayNode(TokenPos(), type); | 8496 ArrayNode* list = new ArrayNode(TokenPos(), type); |
| 8497 | 8497 |
| 8498 // Parse the list elements. Note: there may be an optional extra | 8498 // Parse the list elements. Note: there may be an optional extra |
| 8499 // comma after the last element. | 8499 // comma after the last element. |
| 8500 if (!is_empty_literal) { | 8500 if (!is_empty_literal) { |
| 8501 const bool saved_mode = SetAllowFunctionLiterals(true); | 8501 const bool saved_mode = SetAllowFunctionLiterals(true); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8646 // Map literals take two type arguments. | 8646 // Map literals take two type arguments. |
| 8647 if (map_type_arguments.Length() < 2) { | 8647 if (map_type_arguments.Length() < 2) { |
| 8648 // TODO(hausner): Remove legacy syntax support. | 8648 // TODO(hausner): Remove legacy syntax support. |
| 8649 // We temporarily accept a single type argument. | 8649 // We temporarily accept a single type argument. |
| 8650 if (FLAG_warn_legacy_map_literal) { | 8650 if (FLAG_warn_legacy_map_literal) { |
| 8651 Warning(type_pos, | 8651 Warning(type_pos, |
| 8652 "a map literal takes two type arguments specifying " | 8652 "a map literal takes two type arguments specifying " |
| 8653 "the key type and the value type"); | 8653 "the key type and the value type"); |
| 8654 } | 8654 } |
| 8655 TypeArguments& type_array = TypeArguments::Handle(TypeArguments::New(2)); | 8655 TypeArguments& type_array = TypeArguments::Handle(TypeArguments::New(2)); |
| 8656 type_array.SetTypeAt(0, Type::Handle(Type::StringInterface())); | 8656 type_array.SetTypeAt(0, Type::Handle(Type::StringType())); |
| 8657 type_array.SetTypeAt(1, value_type); | 8657 type_array.SetTypeAt(1, value_type); |
| 8658 map_type_arguments = type_array.raw(); | 8658 map_type_arguments = type_array.raw(); |
| 8659 } else if (map_type_arguments.Length() > 2) { | 8659 } else if (map_type_arguments.Length() > 2) { |
| 8660 ErrorMsg(type_pos, | 8660 ErrorMsg(type_pos, |
| 8661 "a map literal takes two type arguments specifying " | 8661 "a map literal takes two type arguments specifying " |
| 8662 "the key type and the value type"); | 8662 "the key type and the value type"); |
| 8663 } else { | 8663 } else { |
| 8664 const AbstractType& key_type = | 8664 const AbstractType& key_type = |
| 8665 AbstractType::Handle(map_type_arguments.TypeAt(0)); | 8665 AbstractType::Handle(map_type_arguments.TypeAt(0)); |
| 8666 value_type = map_type_arguments.TypeAt(1); | 8666 value_type = map_type_arguments.TypeAt(1); |
| 8667 if (!key_type.IsStringInterface()) { | 8667 if (!key_type.IsStringType()) { |
| 8668 ErrorMsg(type_pos, "the key type of a map literal must be 'String'"); | 8668 ErrorMsg(type_pos, "the key type of a map literal must be 'String'"); |
| 8669 } | 8669 } |
| 8670 } | 8670 } |
| 8671 if (is_const && !value_type.IsInstantiated()) { | 8671 if (is_const && !value_type.IsInstantiated()) { |
| 8672 ErrorMsg(type_pos, | 8672 ErrorMsg(type_pos, |
| 8673 "the type argument of a constant map literal cannot include " | 8673 "the type argument of a constant map literal cannot include " |
| 8674 "a type variable"); | 8674 "a type variable"); |
| 8675 } | 8675 } |
| 8676 } | 8676 } |
| 8677 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); | 8677 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); |
| 8678 map_type_arguments ^= map_type_arguments.Canonicalize(); | 8678 map_type_arguments ^= map_type_arguments.Canonicalize(); |
| 8679 | 8679 |
| 8680 // The kv_pair array is temporary and of element type Dynamic. It is passed | 8680 // The kv_pair array is temporary and of element type Dynamic. It is passed |
| 8681 // to the factory to initialize a properly typed map. | 8681 // to the factory to initialize a properly typed map. |
| 8682 ArrayNode* kv_pairs = | 8682 ArrayNode* kv_pairs = |
| 8683 new ArrayNode(TokenPos(), Type::ZoneHandle(Type::ListInterface())); | 8683 new ArrayNode(TokenPos(), Type::ZoneHandle(Type::ListType())); |
| 8684 | 8684 |
| 8685 // Parse the map entries. Note: there may be an optional extra | 8685 // Parse the map entries. Note: there may be an optional extra |
| 8686 // comma after the last entry. | 8686 // comma after the last entry. |
| 8687 const String& dst_name = String::ZoneHandle(Symbols::ListLiteralElement()); | 8687 const String& dst_name = String::ZoneHandle(Symbols::ListLiteralElement()); |
| 8688 while (CurrentToken() != Token::kRBRACE) { | 8688 while (CurrentToken() != Token::kRBRACE) { |
| 8689 AstNode* key = NULL; | 8689 AstNode* key = NULL; |
| 8690 if (CurrentToken() == Token::kSTRING) { | 8690 if (CurrentToken() == Token::kSTRING) { |
| 8691 key = ParseStringLiteral(); | 8691 key = ParseStringLiteral(); |
| 8692 } | 8692 } |
| 8693 if (key == NULL) { | 8693 if (key == NULL) { |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9185 (l1_token != Token::kINTERPOL_VAR) && | 9185 (l1_token != Token::kINTERPOL_VAR) && |
| 9186 (l1_token != Token::kINTERPOL_START)) { | 9186 (l1_token != Token::kINTERPOL_START)) { |
| 9187 // Common case: no interpolation. | 9187 // Common case: no interpolation. |
| 9188 primary = new LiteralNode(literal_start, *CurrentLiteral()); | 9188 primary = new LiteralNode(literal_start, *CurrentLiteral()); |
| 9189 ConsumeToken(); | 9189 ConsumeToken(); |
| 9190 return primary; | 9190 return primary; |
| 9191 } | 9191 } |
| 9192 // String interpolation needed. | 9192 // String interpolation needed. |
| 9193 bool is_compiletime_const = true; | 9193 bool is_compiletime_const = true; |
| 9194 ArrayNode* values = new ArrayNode(TokenPos(), | 9194 ArrayNode* values = new ArrayNode(TokenPos(), |
| 9195 Type::ZoneHandle(Type::ListInterface())); | 9195 Type::ZoneHandle(Type::ListType())); |
| 9196 while (CurrentToken() == Token::kSTRING) { | 9196 while (CurrentToken() == Token::kSTRING) { |
| 9197 values->AddElement(new LiteralNode(TokenPos(), *CurrentLiteral())); | 9197 values->AddElement(new LiteralNode(TokenPos(), *CurrentLiteral())); |
| 9198 ConsumeToken(); | 9198 ConsumeToken(); |
| 9199 while ((CurrentToken() == Token::kINTERPOL_VAR) || | 9199 while ((CurrentToken() == Token::kINTERPOL_VAR) || |
| 9200 (CurrentToken() == Token::kINTERPOL_START)) { | 9200 (CurrentToken() == Token::kINTERPOL_START)) { |
| 9201 AstNode* expr = NULL; | 9201 AstNode* expr = NULL; |
| 9202 const intptr_t expr_pos = TokenPos(); | 9202 const intptr_t expr_pos = TokenPos(); |
| 9203 if (CurrentToken() == Token::kINTERPOL_VAR) { | 9203 if (CurrentToken() == Token::kINTERPOL_VAR) { |
| 9204 expr = ResolveIdent(TokenPos(), *CurrentLiteral(), true); | 9204 expr = ResolveIdent(TokenPos(), *CurrentLiteral(), true); |
| 9205 ConsumeToken(); | 9205 ConsumeToken(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9263 OS::SNPrint(name, 64, "%s_%"Pd"", | 9263 OS::SNPrint(name, 64, "%s_%"Pd"", |
| 9264 Symbols::Name(Symbols::kSavedArgDescVarPrefix), | 9264 Symbols::Name(Symbols::kSavedArgDescVarPrefix), |
| 9265 owner_function.token_pos()); | 9265 owner_function.token_pos()); |
| 9266 const String& saved_args_desc_name = String::ZoneHandle(Symbols::New(name)); | 9266 const String& saved_args_desc_name = String::ZoneHandle(Symbols::New(name)); |
| 9267 LocalVariable* saved_args_desc_var = LookupLocalScope(saved_args_desc_name); | 9267 LocalVariable* saved_args_desc_var = LookupLocalScope(saved_args_desc_name); |
| 9268 if (saved_args_desc_var == NULL) { | 9268 if (saved_args_desc_var == NULL) { |
| 9269 ASSERT(owner_scope != NULL); | 9269 ASSERT(owner_scope != NULL); |
| 9270 saved_args_desc_var = | 9270 saved_args_desc_var = |
| 9271 new LocalVariable(owner_function.token_pos(), | 9271 new LocalVariable(owner_function.token_pos(), |
| 9272 saved_args_desc_name, | 9272 saved_args_desc_name, |
| 9273 Type::ZoneHandle(Type::ListInterface())); | 9273 Type::ZoneHandle(Type::ListType())); |
| 9274 saved_args_desc_var->set_is_final(); | 9274 saved_args_desc_var->set_is_final(); |
| 9275 // The saved arguments descriptor variable must be added just after the | 9275 // The saved arguments descriptor variable must be added just after the |
| 9276 // formal parameters. This simplifies the 2-step saving of a captured | 9276 // formal parameters. This simplifies the 2-step saving of a captured |
| 9277 // arguments descriptor. | 9277 // arguments descriptor. |
| 9278 // At this time, the owner scope should only contain formal parameters. | 9278 // At this time, the owner scope should only contain formal parameters. |
| 9279 ASSERT(owner_scope->num_variables() == owner_function.NumParameters()); | 9279 ASSERT(owner_scope->num_variables() == owner_function.NumParameters()); |
| 9280 bool success = owner_scope->AddVariable(saved_args_desc_var); | 9280 bool success = owner_scope->AddVariable(saved_args_desc_var); |
| 9281 ASSERT(success); | 9281 ASSERT(success); |
| 9282 // Capture the saved argument descriptor variable if necessary. | 9282 // Capture the saved argument descriptor variable if necessary. |
| 9283 LocalVariable* local = LookupLocalScope(saved_args_desc_name); | 9283 LocalVariable* local = LookupLocalScope(saved_args_desc_name); |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9721 void Parser::SkipQualIdent() { | 9721 void Parser::SkipQualIdent() { |
| 9722 ASSERT(IsIdentifier()); | 9722 ASSERT(IsIdentifier()); |
| 9723 ConsumeToken(); | 9723 ConsumeToken(); |
| 9724 if (CurrentToken() == Token::kPERIOD) { | 9724 if (CurrentToken() == Token::kPERIOD) { |
| 9725 ConsumeToken(); // Consume the kPERIOD token. | 9725 ConsumeToken(); // Consume the kPERIOD token. |
| 9726 ExpectIdentifier("identifier expected after '.'"); | 9726 ExpectIdentifier("identifier expected after '.'"); |
| 9727 } | 9727 } |
| 9728 } | 9728 } |
| 9729 | 9729 |
| 9730 } // namespace dart | 9730 } // namespace dart |
| OLD | NEW |