| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 } else { | 889 } else { |
| 890 const Object& const_value = ParseConstExpr()->literal(); | 890 const Object& const_value = ParseConstExpr()->literal(); |
| 891 parameter.default_value = &const_value; | 891 parameter.default_value = &const_value; |
| 892 } | 892 } |
| 893 } else { | 893 } else { |
| 894 if (params->has_named_optional_parameters) { | 894 if (params->has_named_optional_parameters) { |
| 895 // Implicit default value is null. | 895 // Implicit default value is null. |
| 896 params->num_optional_parameters++; | 896 params->num_optional_parameters++; |
| 897 parameter.default_value = &Object::ZoneHandle(); | 897 parameter.default_value = &Object::ZoneHandle(); |
| 898 } else { | 898 } else { |
| 899 // TODO(regis): Remove support of legacy syntax. | |
| 900 params->num_fixed_parameters++; | 899 params->num_fixed_parameters++; |
| 901 if (params->num_optional_parameters > 0) { | 900 ASSERT(params->num_optional_parameters == 0); |
| 902 ErrorMsg("optional parameters must be last"); | |
| 903 } | |
| 904 } | 901 } |
| 905 } | 902 } |
| 906 if (parameter.type->IsVoidType()) { | 903 if (parameter.type->IsVoidType()) { |
| 907 ErrorMsg("parameter '%s' may not be 'void'", parameter.name->ToCString()); | 904 ErrorMsg("parameter '%s' may not be 'void'", parameter.name->ToCString()); |
| 908 } | 905 } |
| 909 params->parameters->Add(parameter); | 906 params->parameters->Add(parameter); |
| 910 } | 907 } |
| 911 | 908 |
| 912 | 909 |
| 913 void Parser::ParseFormalParameterList(bool allow_explicit_default_values, | 910 void Parser::ParseFormalParameterList(bool allow_explicit_default_values, |
| (...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2150 member.kind = RawFunction::kGetterFunction; | 2147 member.kind = RawFunction::kGetterFunction; |
| 2151 member.name_pos = this->token_index_; | 2148 member.name_pos = this->token_index_; |
| 2152 member.name = ExpectIdentifier("identifier expected"); | 2149 member.name = ExpectIdentifier("identifier expected"); |
| 2153 // If the result type was not specified, it will be set to VarType below. | 2150 // If the result type was not specified, it will be set to VarType below. |
| 2154 } else if (CurrentToken() == Token::kSET) { | 2151 } else if (CurrentToken() == Token::kSET) { |
| 2155 ConsumeToken(); | 2152 ConsumeToken(); |
| 2156 member.kind = RawFunction::kSetterFunction; | 2153 member.kind = RawFunction::kSetterFunction; |
| 2157 member.name_pos = this->token_index_; | 2154 member.name_pos = this->token_index_; |
| 2158 member.name = ExpectIdentifier("identifier expected"); | 2155 member.name = ExpectIdentifier("identifier expected"); |
| 2159 // The grammar allows a return type, so member.type is not always NULL here. | 2156 // The grammar allows a return type, so member.type is not always NULL here. |
| 2160 // However, the return type of a setter is ignored. | 2157 // If no return type is specified, the return type of the setter is Dynamic. |
| 2161 // TODO(regis): Revisit depending on the outcome of issue 4745047. | |
| 2162 if (member.type == NULL) { | 2158 if (member.type == NULL) { |
| 2163 member.type = &Type::ZoneHandle(Type::VoidType()); | 2159 member.type = &Type::ZoneHandle(Type::VarType()); |
| 2164 } | 2160 } |
| 2165 } else if (CurrentToken() == Token::kOPERATOR) { | 2161 } else if (CurrentToken() == Token::kOPERATOR) { |
| 2166 ConsumeToken(); | 2162 ConsumeToken(); |
| 2167 if (!Token::CanBeOverloaded(CurrentToken())) { | 2163 if (!Token::CanBeOverloaded(CurrentToken())) { |
| 2168 ErrorMsg("invalid operator overloading"); | 2164 ErrorMsg("invalid operator overloading"); |
| 2169 } | 2165 } |
| 2170 if (member.has_static) { | 2166 if (member.has_static) { |
| 2171 ErrorMsg("operator overloading functions cannot be static"); | 2167 ErrorMsg("operator overloading functions cannot be static"); |
| 2172 } | 2168 } |
| 2173 member.kind = RawFunction::kFunction; | 2169 member.kind = RawFunction::kFunction; |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2636 } | 2632 } |
| 2637 | 2633 |
| 2638 | 2634 |
| 2639 // Parse and return an array of interface types. | 2635 // Parse and return an array of interface types. |
| 2640 RawArray* Parser::ParseInterfaceList() { | 2636 RawArray* Parser::ParseInterfaceList() { |
| 2641 ASSERT((CurrentToken() == Token::kIMPLEMENTS) || | 2637 ASSERT((CurrentToken() == Token::kIMPLEMENTS) || |
| 2642 (CurrentToken() == Token::kEXTENDS)); | 2638 (CurrentToken() == Token::kEXTENDS)); |
| 2643 GrowableArray<Type*> interfaces; | 2639 GrowableArray<Type*> interfaces; |
| 2644 do { | 2640 do { |
| 2645 ConsumeToken(); | 2641 ConsumeToken(); |
| 2646 // TODO(regis): The way we handle unresolved classes is not going to fly. | |
| 2647 // We are currently not able to provide a token position for errors occuring | |
| 2648 // after parsing, as in the class finalizer. We need to introduce an | |
| 2649 // 'unresolved class' class consisting of a string, a token position, and a | |
| 2650 // script, maybe a library too. | |
| 2651 Type& interface = Type::ZoneHandle(ParseType(kCanResolve)); | 2642 Type& interface = Type::ZoneHandle(ParseType(kCanResolve)); |
| 2652 interfaces.Add(&interface); | 2643 interfaces.Add(&interface); |
| 2653 } while (CurrentToken() == Token::kCOMMA); | 2644 } while (CurrentToken() == Token::kCOMMA); |
| 2654 return NewArray<Type>(interfaces); | 2645 return NewArray<Type>(interfaces); |
| 2655 } | 2646 } |
| 2656 | 2647 |
| 2657 | 2648 |
| 2658 void Parser::AddInterfaces(intptr_t interfaces_pos, | 2649 void Parser::AddInterfaces(intptr_t interfaces_pos, |
| 2659 const Class& cls, | 2650 const Class& cls, |
| 2660 const Array& interfaces) { | 2651 const Array& interfaces) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2781 } | 2772 } |
| 2782 | 2773 |
| 2783 | 2774 |
| 2784 void Parser::ParseTopLevelAccessor(TopLevel* top_level) { | 2775 void Parser::ParseTopLevelAccessor(TopLevel* top_level) { |
| 2785 const bool is_static = true; | 2776 const bool is_static = true; |
| 2786 Type& result_type = Type::Handle(); | 2777 Type& result_type = Type::Handle(); |
| 2787 bool is_getter = (CurrentToken() == Token::kGET); | 2778 bool is_getter = (CurrentToken() == Token::kGET); |
| 2788 if (CurrentToken() == Token::kGET || | 2779 if (CurrentToken() == Token::kGET || |
| 2789 CurrentToken() == Token::kSET) { | 2780 CurrentToken() == Token::kSET) { |
| 2790 ConsumeToken(); | 2781 ConsumeToken(); |
| 2791 // TODO(regis): Revisit, see issue 4745047. | |
| 2792 result_type = Type::VarType(); | 2782 result_type = Type::VarType(); |
| 2793 } else { | 2783 } else { |
| 2794 if (CurrentToken() == Token::kVOID) { | 2784 if (CurrentToken() == Token::kVOID) { |
| 2795 ConsumeToken(); | 2785 ConsumeToken(); |
| 2796 result_type = Type::VoidType(); | 2786 result_type = Type::VoidType(); |
| 2797 } else { | 2787 } else { |
| 2798 result_type = ParseType(kCanResolve); | 2788 result_type = ParseType(kCanResolve); |
| 2799 } | 2789 } |
| 2800 is_getter = (CurrentToken() == Token::kGET); | 2790 is_getter = (CurrentToken() == Token::kGET); |
| 2801 if (CurrentToken() == Token::kGET || CurrentToken() == Token::kSET) { | 2791 if (CurrentToken() == Token::kGET || CurrentToken() == Token::kSET) { |
| (...skipping 4202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7004 } | 6994 } |
| 7005 | 6995 |
| 7006 | 6996 |
| 7007 void Parser::SkipNestedExpr() { | 6997 void Parser::SkipNestedExpr() { |
| 7008 const bool saved_mode = SetAllowFunctionLiterals(true); | 6998 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7009 SkipExpr(); | 6999 SkipExpr(); |
| 7010 SetAllowFunctionLiterals(saved_mode); | 7000 SetAllowFunctionLiterals(saved_mode); |
| 7011 } | 7001 } |
| 7012 | 7002 |
| 7013 } // namespace dart | 7003 } // namespace dart |
| OLD | NEW |