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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 param.name_pos = name_pos; | 316 param.name_pos = name_pos; |
317 param.name = &String::ZoneHandle(String::NewSymbol(name)); | 317 param.name = &String::ZoneHandle(String::NewSymbol(name)); |
318 param.is_final = true; | 318 param.is_final = true; |
319 param.type = type; | 319 param.type = type; |
320 this->parameters->Add(param); | 320 this->parameters->Add(param); |
321 } | 321 } |
322 | 322 |
323 void AddReceiver(intptr_t name_pos) { | 323 void AddReceiver(intptr_t name_pos) { |
324 ASSERT(this->parameters->length() == 0); | 324 ASSERT(this->parameters->length() == 0); |
325 // The receiver does not need to be type checked. | 325 // The receiver does not need to be type checked. |
326 AddFinalParameter(name_pos, kThisName, &Type::ZoneHandle(Type::VarType())); | 326 AddFinalParameter(name_pos, |
| 327 kThisName, |
| 328 &Type::ZoneHandle(Type::DynamicType())); |
327 } | 329 } |
328 | 330 |
329 void SetImplicitlyFinal() { | 331 void SetImplicitlyFinal() { |
330 implicitly_final = true; | 332 implicitly_final = true; |
331 } | 333 } |
332 | 334 |
333 int num_fixed_parameters; | 335 int num_fixed_parameters; |
334 int num_optional_parameters; | 336 int num_optional_parameters; |
335 bool has_named_optional_parameters; // Indicates use of the new syntax. | 337 bool has_named_optional_parameters; // Indicates use of the new syntax. |
336 bool has_field_initializer; | 338 bool has_field_initializer; |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 ParamDesc parameter; | 763 ParamDesc parameter; |
762 bool var_seen = false; | 764 bool var_seen = false; |
763 bool this_seen = false; | 765 bool this_seen = false; |
764 | 766 |
765 if (CurrentToken() == Token::kFINAL) { | 767 if (CurrentToken() == Token::kFINAL) { |
766 ConsumeToken(); | 768 ConsumeToken(); |
767 parameter.is_final = true; | 769 parameter.is_final = true; |
768 } else if (CurrentToken() == Token::kVAR) { | 770 } else if (CurrentToken() == Token::kVAR) { |
769 ConsumeToken(); | 771 ConsumeToken(); |
770 var_seen = true; | 772 var_seen = true; |
771 // The parameter type is the 'var' type. | 773 // The parameter type is the 'Dynamic' type. |
772 parameter.type = &Type::ZoneHandle(Type::VarType()); | 774 parameter.type = &Type::ZoneHandle(Type::DynamicType()); |
773 } | 775 } |
774 if (CurrentToken() == Token::kTHIS) { | 776 if (CurrentToken() == Token::kTHIS) { |
775 ConsumeToken(); | 777 ConsumeToken(); |
776 ExpectToken(Token::kPERIOD); | 778 ExpectToken(Token::kPERIOD); |
777 this_seen = true; | 779 this_seen = true; |
778 parameter.is_field_initializer = true; | 780 parameter.is_field_initializer = true; |
779 } | 781 } |
780 if (params->implicitly_final) { | 782 if (params->implicitly_final) { |
781 parameter.is_final = true; | 783 parameter.is_final = true; |
782 } | 784 } |
(...skipping 15 matching lines...) Expand all Loading... |
798 Token::Kind follower = LookaheadToken(1); | 800 Token::Kind follower = LookaheadToken(1); |
799 // We have an identifier followed by a 'follower' token. | 801 // We have an identifier followed by a 'follower' token. |
800 // We either parse a type or assume that no type is specified. | 802 // We either parse a type or assume that no type is specified. |
801 if ((follower == Token::kLT) || // Parameterized type. | 803 if ((follower == Token::kLT) || // Parameterized type. |
802 (follower == Token::kPERIOD) || // Qualified class name of type. | 804 (follower == Token::kPERIOD) || // Qualified class name of type. |
803 (follower == Token::kIDENT) || // Parameter name following a type. | 805 (follower == Token::kIDENT) || // Parameter name following a type. |
804 (follower == Token::kTHIS)) { // Field parameter following a type. | 806 (follower == Token::kTHIS)) { // Field parameter following a type. |
805 parameter.type = &Type::ZoneHandle( | 807 parameter.type = &Type::ZoneHandle( |
806 ParseType(is_top_level_ ? kCanResolve : kMustResolve)); | 808 ParseType(is_top_level_ ? kCanResolve : kMustResolve)); |
807 } else { | 809 } else { |
808 parameter.type = &Type::ZoneHandle(Type::VarType()); | 810 parameter.type = &Type::ZoneHandle(Type::DynamicType()); |
809 } | 811 } |
810 } | 812 } |
811 if (!this_seen && (CurrentToken() == Token::kTHIS)) { | 813 if (!this_seen && (CurrentToken() == Token::kTHIS)) { |
812 ConsumeToken(); | 814 ConsumeToken(); |
813 ExpectToken(Token::kPERIOD); | 815 ExpectToken(Token::kPERIOD); |
814 this_seen = true; | 816 this_seen = true; |
815 parameter.is_field_initializer = true; | 817 parameter.is_field_initializer = true; |
816 } | 818 } |
817 // At this point, we must see an identifier for the parameter name. | 819 // At this point, we must see an identifier for the parameter name. |
818 if (CurrentToken() != Token::kIDENT) { | 820 if (CurrentToken() != Token::kIDENT) { |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1452 | 1454 |
1453 // Parse expressions of instance fields that have an explicit | 1455 // Parse expressions of instance fields that have an explicit |
1454 // initializers. | 1456 // initializers. |
1455 GrowableArray<FieldInitExpression> initializers; | 1457 GrowableArray<FieldInitExpression> initializers; |
1456 Class& cls = Class::Handle(func.owner()); | 1458 Class& cls = Class::Handle(func.owner()); |
1457 ParseInitializedInstanceFields(cls, &initializers); | 1459 ParseInitializedInstanceFields(cls, &initializers); |
1458 | 1460 |
1459 LocalVariable* receiver = new LocalVariable( | 1461 LocalVariable* receiver = new LocalVariable( |
1460 ctor_pos, | 1462 ctor_pos, |
1461 String::ZoneHandle(String::NewSymbol(kThisName)), | 1463 String::ZoneHandle(String::NewSymbol(kThisName)), |
1462 Type::ZoneHandle(Type::VarType())); | 1464 Type::ZoneHandle(Type::DynamicType())); |
1463 current_block_->scope->AddVariable(receiver); | 1465 current_block_->scope->AddVariable(receiver); |
1464 | 1466 |
1465 // Now that the "this" parameter is in scope, we can generate the code | 1467 // Now that the "this" parameter is in scope, we can generate the code |
1466 // to strore the initializer expressions in the respective instance fields. | 1468 // to strore the initializer expressions in the respective instance fields. |
1467 for (int i = 0; i < initializers.length(); i++) { | 1469 for (int i = 0; i < initializers.length(); i++) { |
1468 const Field* field = initializers[i].inst_field; | 1470 const Field* field = initializers[i].inst_field; |
1469 AstNode* instance = new LoadLocalNode(field->token_index(), *receiver); | 1471 AstNode* instance = new LoadLocalNode(field->token_index(), *receiver); |
1470 AstNode* field_init = | 1472 AstNode* field_init = |
1471 new StoreInstanceFieldNode(field->token_index(), | 1473 new StoreInstanceFieldNode(field->token_index(), |
1472 instance, | 1474 instance, |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2054 } | 2056 } |
2055 if (CurrentToken() == Token::kVAR) { | 2057 if (CurrentToken() == Token::kVAR) { |
2056 if (member.has_const) { | 2058 if (member.has_const) { |
2057 ErrorMsg("identifier expected after 'const'"); | 2059 ErrorMsg("identifier expected after 'const'"); |
2058 } | 2060 } |
2059 if (member.has_final) { | 2061 if (member.has_final) { |
2060 ErrorMsg("identifier expected after 'final'"); | 2062 ErrorMsg("identifier expected after 'final'"); |
2061 } | 2063 } |
2062 ConsumeToken(); | 2064 ConsumeToken(); |
2063 member.has_var = true; | 2065 member.has_var = true; |
2064 // The member type is the 'var' type. | 2066 // The member type is the 'Dynamic' type. |
2065 member.type = &Type::ZoneHandle(Type::VarType()); | 2067 member.type = &Type::ZoneHandle(Type::DynamicType()); |
2066 } else if (CurrentToken() == Token::kFACTORY) { | 2068 } else if (CurrentToken() == Token::kFACTORY) { |
2067 ConsumeToken(); | 2069 ConsumeToken(); |
2068 member.has_factory = true; | 2070 member.has_factory = true; |
2069 member.has_static = true; | 2071 member.has_static = true; |
2070 // The member result type is the type of this class. | 2072 // The member result type is the type of this class. |
2071 // TODO(regis): What are the type arguments? | 2073 // TODO(regis): What are the type arguments? |
2072 member.type = | 2074 member.type = |
2073 &Type::ZoneHandle(Type::NewRawType(Class::Handle(members->clazz()))); | 2075 &Type::ZoneHandle(Type::NewRawType(Class::Handle(members->clazz()))); |
2074 } | 2076 } |
2075 // Optionally parse a type. | 2077 // Optionally parse a type. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2140 } | 2142 } |
2141 } | 2143 } |
2142 if (CurrentToken() != Token::kLPAREN) { | 2144 if (CurrentToken() != Token::kLPAREN) { |
2143 ErrorMsg("left parenthesis expected"); | 2145 ErrorMsg("left parenthesis expected"); |
2144 } | 2146 } |
2145 } else if (CurrentToken() == Token::kGET) { | 2147 } else if (CurrentToken() == Token::kGET) { |
2146 ConsumeToken(); | 2148 ConsumeToken(); |
2147 member.kind = RawFunction::kGetterFunction; | 2149 member.kind = RawFunction::kGetterFunction; |
2148 member.name_pos = this->token_index_; | 2150 member.name_pos = this->token_index_; |
2149 member.name = ExpectIdentifier("identifier expected"); | 2151 member.name = ExpectIdentifier("identifier expected"); |
2150 // If the result type was not specified, it will be set to VarType below. | 2152 // If the result type was not specified, it will be set to DynamicType. |
2151 } else if (CurrentToken() == Token::kSET) { | 2153 } else if (CurrentToken() == Token::kSET) { |
2152 ConsumeToken(); | 2154 ConsumeToken(); |
2153 member.kind = RawFunction::kSetterFunction; | 2155 member.kind = RawFunction::kSetterFunction; |
2154 member.name_pos = this->token_index_; | 2156 member.name_pos = this->token_index_; |
2155 member.name = ExpectIdentifier("identifier expected"); | 2157 member.name = ExpectIdentifier("identifier expected"); |
2156 // The grammar allows a return type, so member.type is not always NULL here. | 2158 // The grammar allows a return type, so member.type is not always NULL here. |
2157 // If no return type is specified, the return type of the setter is Dynamic. | 2159 // If no return type is specified, the return type of the setter is Dynamic. |
2158 if (member.type == NULL) { | 2160 if (member.type == NULL) { |
2159 member.type = &Type::ZoneHandle(Type::VarType()); | 2161 member.type = &Type::ZoneHandle(Type::DynamicType()); |
2160 } | 2162 } |
2161 } else if (CurrentToken() == Token::kOPERATOR) { | 2163 } else if (CurrentToken() == Token::kOPERATOR) { |
2162 ConsumeToken(); | 2164 ConsumeToken(); |
2163 if (!Token::CanBeOverloaded(CurrentToken())) { | 2165 if (!Token::CanBeOverloaded(CurrentToken())) { |
2164 ErrorMsg("invalid operator overloading"); | 2166 ErrorMsg("invalid operator overloading"); |
2165 } | 2167 } |
2166 if (member.has_static) { | 2168 if (member.has_static) { |
2167 ErrorMsg("operator overloading functions cannot be static"); | 2169 ErrorMsg("operator overloading functions cannot be static"); |
2168 } | 2170 } |
2169 member.kind = RawFunction::kFunction; | 2171 member.kind = RawFunction::kFunction; |
(...skipping 13 matching lines...) Expand all Loading... |
2183 if (CurrentToken() == Token::kLPAREN) { | 2185 if (CurrentToken() == Token::kLPAREN) { |
2184 if (members->is_interface() && member.has_static) { | 2186 if (members->is_interface() && member.has_static) { |
2185 if (member.has_factory) { | 2187 if (member.has_factory) { |
2186 ErrorMsg("factory constructors are not allowed in interfaces"); | 2188 ErrorMsg("factory constructors are not allowed in interfaces"); |
2187 } else { | 2189 } else { |
2188 ErrorMsg("static methods are not allowed in interfaces"); | 2190 ErrorMsg("static methods are not allowed in interfaces"); |
2189 } | 2191 } |
2190 } | 2192 } |
2191 // Constructor or method. | 2193 // Constructor or method. |
2192 if (member.type == NULL) { | 2194 if (member.type == NULL) { |
2193 member.type = &Type::ZoneHandle(Type::VarType()); | 2195 member.type = &Type::ZoneHandle(Type::DynamicType()); |
2194 } | 2196 } |
2195 ParseMethodOrConstructor(members, &member); | 2197 ParseMethodOrConstructor(members, &member); |
2196 } else if (CurrentToken() == Token::kSEMICOLON || | 2198 } else if (CurrentToken() == Token::kSEMICOLON || |
2197 CurrentToken() == Token::kCOMMA || | 2199 CurrentToken() == Token::kCOMMA || |
2198 CurrentToken() == Token::kASSIGN) { | 2200 CurrentToken() == Token::kASSIGN) { |
2199 // Field definition. | 2201 // Field definition. |
2200 if (member.type == NULL) { | 2202 if (member.type == NULL) { |
2201 if (member.has_final) { | 2203 if (member.has_final) { |
2202 member.type = &Type::ZoneHandle(Type::VarType()); | 2204 member.type = &Type::ZoneHandle(Type::DynamicType()); |
2203 } else { | 2205 } else { |
2204 ErrorMsg("missing 'var', 'final' or type in field declaration"); | 2206 ErrorMsg("missing 'var', 'final' or type in field declaration"); |
2205 } | 2207 } |
2206 } | 2208 } |
2207 if (members->is_interface() && member.has_static && !member.has_final) { | 2209 if (members->is_interface() && member.has_static && !member.has_final) { |
2208 ErrorMsg("static non-final fields are not allowed in interfaces"); | 2210 ErrorMsg("static non-final fields are not allowed in interfaces"); |
2209 } | 2211 } |
2210 ParseFieldDefinition(members, &member); | 2212 ParseFieldDefinition(members, &member); |
2211 } else { | 2213 } else { |
2212 UnexpectedToken(); | 2214 UnexpectedToken(); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2359 } | 2361 } |
2360 SetPosition(saved_pos); | 2362 SetPosition(saved_pos); |
2361 return is_alias_name; | 2363 return is_alias_name; |
2362 } | 2364 } |
2363 | 2365 |
2364 | 2366 |
2365 void Parser::ParseFunctionTypeAlias(GrowableArray<const Class*>* classes) { | 2367 void Parser::ParseFunctionTypeAlias(GrowableArray<const Class*>* classes) { |
2366 TRACE_PARSER("ParseFunctionTypeAlias"); | 2368 TRACE_PARSER("ParseFunctionTypeAlias"); |
2367 ExpectToken(Token::kTYPEDEF); | 2369 ExpectToken(Token::kTYPEDEF); |
2368 | 2370 |
2369 Type& result_type = Type::Handle(Type::VarType()); | 2371 Type& result_type = Type::Handle(Type::DynamicType()); |
2370 intptr_t result_type_pos = token_index_; | 2372 intptr_t result_type_pos = token_index_; |
2371 if (CurrentToken() == Token::kVOID) { | 2373 if (CurrentToken() == Token::kVOID) { |
2372 ConsumeToken(); | 2374 ConsumeToken(); |
2373 result_type = Type::VoidType(); | 2375 result_type = Type::VoidType(); |
2374 } else if (!IsFunctionTypeAliasName()) { | 2376 } else if (!IsFunctionTypeAliasName()) { |
2375 result_type = ParseType(kDoNotResolve); // No owner class yet. | 2377 result_type = ParseType(kDoNotResolve); // No owner class yet. |
2376 } | 2378 } |
2377 | 2379 |
2378 if (CurrentToken() != Token::kIDENT) { | 2380 if (CurrentToken() != Token::kIDENT) { |
2379 ErrorMsg("function alias name expected"); | 2381 ErrorMsg("function alias name expected"); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2580 if (CurrentToken() == Token::kLT) { | 2582 if (CurrentToken() == Token::kLT) { |
2581 GrowableArray<String*> type_parameters; | 2583 GrowableArray<String*> type_parameters; |
2582 GrowableArray<Type*> type_parameter_extends; | 2584 GrowableArray<Type*> type_parameter_extends; |
2583 do { | 2585 do { |
2584 ConsumeToken(); | 2586 ConsumeToken(); |
2585 if (CurrentToken() != Token::kIDENT) { | 2587 if (CurrentToken() != Token::kIDENT) { |
2586 ErrorMsg("type parameter name expected"); | 2588 ErrorMsg("type parameter name expected"); |
2587 } | 2589 } |
2588 String& type_parameter_name = *CurrentLiteral(); | 2590 String& type_parameter_name = *CurrentLiteral(); |
2589 ConsumeToken(); | 2591 ConsumeToken(); |
2590 Type& type_extends = Type::ZoneHandle(Type::VarType()); | 2592 Type& type_extends = Type::ZoneHandle(Type::DynamicType()); |
2591 if (CurrentToken() == Token::kEXTENDS) { | 2593 if (CurrentToken() == Token::kEXTENDS) { |
2592 ConsumeToken(); | 2594 ConsumeToken(); |
2593 type_extends = ParseType(kCanResolve); | 2595 type_extends = ParseType(kCanResolve); |
2594 } | 2596 } |
2595 type_parameters.Add(&type_parameter_name); | 2597 type_parameters.Add(&type_parameter_name); |
2596 type_parameter_extends.Add(&type_extends); | 2598 type_parameter_extends.Add(&type_extends); |
2597 } while (CurrentToken() == Token::kCOMMA); | 2599 } while (CurrentToken() == Token::kCOMMA); |
2598 Token::Kind token = CurrentToken(); | 2600 Token::Kind token = CurrentToken(); |
2599 if ((token == Token::kGT) || | 2601 if ((token == Token::kGT) || |
2600 (token == Token::kSAR) || | 2602 (token == Token::kSAR) || |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2717 ConsumeToken(); | 2719 ConsumeToken(); |
2718 break; | 2720 break; |
2719 } else { | 2721 } else { |
2720 ExpectSemicolon(); // Reports error. | 2722 ExpectSemicolon(); // Reports error. |
2721 } | 2723 } |
2722 } | 2724 } |
2723 } | 2725 } |
2724 | 2726 |
2725 | 2727 |
2726 void Parser::ParseTopLevelFunction(TopLevel* top_level) { | 2728 void Parser::ParseTopLevelFunction(TopLevel* top_level) { |
2727 Type& result_type = Type::Handle(Type::VarType()); | 2729 Type& result_type = Type::Handle(Type::DynamicType()); |
2728 const bool is_static = true; | 2730 const bool is_static = true; |
2729 if (CurrentToken() == Token::kVOID) { | 2731 if (CurrentToken() == Token::kVOID) { |
2730 ConsumeToken(); | 2732 ConsumeToken(); |
2731 result_type = Type::VoidType(); | 2733 result_type = Type::VoidType(); |
2732 } else { | 2734 } else { |
2733 // Parse optional type. | 2735 // Parse optional type. |
2734 if ((CurrentToken() == Token::kIDENT) && | 2736 if ((CurrentToken() == Token::kIDENT) && |
2735 (LookaheadToken(1) != Token::kLPAREN)) { | 2737 (LookaheadToken(1) != Token::kLPAREN)) { |
2736 result_type = ParseType(kCanResolve); | 2738 result_type = ParseType(kCanResolve); |
2737 } | 2739 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2772 } | 2774 } |
2773 | 2775 |
2774 | 2776 |
2775 void Parser::ParseTopLevelAccessor(TopLevel* top_level) { | 2777 void Parser::ParseTopLevelAccessor(TopLevel* top_level) { |
2776 const bool is_static = true; | 2778 const bool is_static = true; |
2777 Type& result_type = Type::Handle(); | 2779 Type& result_type = Type::Handle(); |
2778 bool is_getter = (CurrentToken() == Token::kGET); | 2780 bool is_getter = (CurrentToken() == Token::kGET); |
2779 if (CurrentToken() == Token::kGET || | 2781 if (CurrentToken() == Token::kGET || |
2780 CurrentToken() == Token::kSET) { | 2782 CurrentToken() == Token::kSET) { |
2781 ConsumeToken(); | 2783 ConsumeToken(); |
2782 result_type = Type::VarType(); | 2784 result_type = Type::DynamicType(); |
2783 } else { | 2785 } else { |
2784 if (CurrentToken() == Token::kVOID) { | 2786 if (CurrentToken() == Token::kVOID) { |
2785 ConsumeToken(); | 2787 ConsumeToken(); |
2786 result_type = Type::VoidType(); | 2788 result_type = Type::VoidType(); |
2787 } else { | 2789 } else { |
2788 result_type = ParseType(kCanResolve); | 2790 result_type = ParseType(kCanResolve); |
2789 } | 2791 } |
2790 is_getter = (CurrentToken() == Token::kGET); | 2792 is_getter = (CurrentToken() == Token::kGET); |
2791 if (CurrentToken() == Token::kGET || CurrentToken() == Token::kSET) { | 2793 if (CurrentToken() == Token::kGET || CurrentToken() == Token::kSET) { |
2792 ConsumeToken(); | 2794 ConsumeToken(); |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3248 if (is_final) { | 3250 if (is_final) { |
3249 variable->set_is_final(); | 3251 variable->set_is_final(); |
3250 } | 3252 } |
3251 return initialization; | 3253 return initialization; |
3252 } | 3254 } |
3253 | 3255 |
3254 | 3256 |
3255 // Parses ('var' | 'final' [type] | type). | 3257 // Parses ('var' | 'final' [type] | type). |
3256 // The presence of 'final' must be detected and remembered before the call. | 3258 // The presence of 'final' must be detected and remembered before the call. |
3257 // If type_specification is kIsOptional, and no type can be parsed, then return | 3259 // If type_specification is kIsOptional, and no type can be parsed, then return |
3258 // the VarType. | 3260 // the DynamicType. |
3259 // If a type is parsed, it is resolved (or not) according to type_resolution. | 3261 // If a type is parsed, it is resolved (or not) according to type_resolution. |
3260 RawType* Parser::ParseFinalVarOrType(TypeSpecification type_specification, | 3262 RawType* Parser::ParseFinalVarOrType(TypeSpecification type_specification, |
3261 TypeResolution type_resolution) { | 3263 TypeResolution type_resolution) { |
3262 if (CurrentToken() == Token::kVAR) { | 3264 if (CurrentToken() == Token::kVAR) { |
3263 ConsumeToken(); | 3265 ConsumeToken(); |
3264 return Type::VarType(); | 3266 return Type::DynamicType(); |
3265 } | 3267 } |
3266 if (CurrentToken() == Token::kFINAL) { | 3268 if (CurrentToken() == Token::kFINAL) { |
3267 ConsumeToken(); | 3269 ConsumeToken(); |
3268 type_specification = kIsOptional; | 3270 type_specification = kIsOptional; |
3269 } | 3271 } |
3270 if (CurrentToken() != Token::kIDENT) { | 3272 if (CurrentToken() != Token::kIDENT) { |
3271 if (type_specification == kIsOptional) { | 3273 if (type_specification == kIsOptional) { |
3272 return Type::VarType(); | 3274 return Type::DynamicType(); |
3273 } else { | 3275 } else { |
3274 ErrorMsg("identifier expected"); | 3276 ErrorMsg("identifier expected"); |
3275 } | 3277 } |
3276 } | 3278 } |
3277 if (type_specification == kIsOptional) { | 3279 if (type_specification == kIsOptional) { |
3278 Token::Kind follower = LookaheadToken(1); | 3280 Token::Kind follower = LookaheadToken(1); |
3279 // We have an identifier followed by a 'follower' token. | 3281 // We have an identifier followed by a 'follower' token. |
3280 // We either parse a type or return now. | 3282 // We either parse a type or return now. |
3281 if ((follower != Token::kLT) && // Parameterized type. | 3283 if ((follower != Token::kLT) && // Parameterized type. |
3282 (follower != Token::kPERIOD) && // Qualified class name of type. | 3284 (follower != Token::kPERIOD) && // Qualified class name of type. |
3283 (follower != Token::kIDENT) && // Variable name following a type. | 3285 (follower != Token::kIDENT) && // Variable name following a type. |
3284 (follower != Token::kTHIS)) { // Field parameter following a type. | 3286 (follower != Token::kTHIS)) { // Field parameter following a type. |
3285 return Type::VarType(); | 3287 return Type::DynamicType(); |
3286 } | 3288 } |
3287 } | 3289 } |
3288 return ParseType(type_resolution); | 3290 return ParseType(type_resolution); |
3289 } | 3291 } |
3290 | 3292 |
3291 | 3293 |
3292 // Returns ast nodes of the variable initialization, or NULL if variables | 3294 // Returns ast nodes of the variable initialization, or NULL if variables |
3293 // are not initialized. If several variables are declared and initialized, | 3295 // are not initialized. If several variables are declared and initialized, |
3294 // the individual initializers are collected in a sequence node. | 3296 // the individual initializers are collected in a sequence node. |
3295 AstNode* Parser::ParseVariableDeclarationList() { | 3297 AstNode* Parser::ParseVariableDeclarationList() { |
(...skipping 28 matching lines...) Expand all Loading... |
3324 return initializers; | 3326 return initializers; |
3325 } | 3327 } |
3326 | 3328 |
3327 | 3329 |
3328 AstNode* Parser::ParseFunctionStatement(bool is_literal) { | 3330 AstNode* Parser::ParseFunctionStatement(bool is_literal) { |
3329 TRACE_PARSER("ParseFunctionStatement"); | 3331 TRACE_PARSER("ParseFunctionStatement"); |
3330 Type& result_type = Type::Handle(); | 3332 Type& result_type = Type::Handle(); |
3331 const String* variable_name = NULL; | 3333 const String* variable_name = NULL; |
3332 const String* function_name = NULL; | 3334 const String* function_name = NULL; |
3333 | 3335 |
3334 result_type = Type::VarType(); | 3336 result_type = Type::DynamicType(); |
3335 if (CurrentToken() == Token::kVOID) { | 3337 if (CurrentToken() == Token::kVOID) { |
3336 ConsumeToken(); | 3338 ConsumeToken(); |
3337 result_type = Type::VoidType(); | 3339 result_type = Type::VoidType(); |
3338 } else if ((CurrentToken() == Token::kIDENT) && | 3340 } else if ((CurrentToken() == Token::kIDENT) && |
3339 (LookaheadToken(1) != Token::kLPAREN)) { | 3341 (LookaheadToken(1) != Token::kLPAREN)) { |
3340 result_type = ParseType(kMustResolve); | 3342 result_type = ParseType(kMustResolve); |
3341 } | 3343 } |
3342 intptr_t ident_pos = token_index_; | 3344 intptr_t ident_pos = token_index_; |
3343 if (CurrentToken() == Token::kIDENT) { | 3345 if (CurrentToken() == Token::kIDENT) { |
3344 variable_name = CurrentLiteral(); | 3346 variable_name = CurrentLiteral(); |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3874 ExpectToken(Token::kRPAREN); | 3876 ExpectToken(Token::kRPAREN); |
3875 } | 3877 } |
3876 ExpectToken(Token::kLBRACE); | 3878 ExpectToken(Token::kLBRACE); |
3877 OpenBlock(); | 3879 OpenBlock(); |
3878 current_block_->scope->AddLabel(label); | 3880 current_block_->scope->AddLabel(label); |
3879 | 3881 |
3880 // Store switch expression in temporary local variable. | 3882 // Store switch expression in temporary local variable. |
3881 LocalVariable* temp_variable = | 3883 LocalVariable* temp_variable = |
3882 new LocalVariable(expr_pos, | 3884 new LocalVariable(expr_pos, |
3883 String::ZoneHandle(String::NewSymbol(":switch_expr")), | 3885 String::ZoneHandle(String::NewSymbol(":switch_expr")), |
3884 Type::ZoneHandle(Type::VarType())); | 3886 Type::ZoneHandle(Type::DynamicType())); |
3885 current_block_->scope->AddVariable(temp_variable); | 3887 current_block_->scope->AddVariable(temp_variable); |
3886 AstNode* save_switch_expr = | 3888 AstNode* save_switch_expr = |
3887 new StoreLocalNode(expr_pos, *temp_variable, switch_expr); | 3889 new StoreLocalNode(expr_pos, *temp_variable, switch_expr); |
3888 current_block_->statements->Add(save_switch_expr); | 3890 current_block_->statements->Add(save_switch_expr); |
3889 | 3891 |
3890 // Parse case clauses | 3892 // Parse case clauses |
3891 bool default_seen = false; | 3893 bool default_seen = false; |
3892 while (true) { | 3894 while (true) { |
3893 // Check for statement label | 3895 // Check for statement label |
3894 SourceLabel* case_label = NULL; | 3896 SourceLabel* case_label = NULL; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4006 OpenBlock(); // Implicit block around while loop. | 4008 OpenBlock(); // Implicit block around while loop. |
4007 | 4009 |
4008 // Generate implicit iterator variable and add to scope. | 4010 // Generate implicit iterator variable and add to scope. |
4009 const String& iterator_name = | 4011 const String& iterator_name = |
4010 String::ZoneHandle(String::NewSymbol(":for-in-iter")); | 4012 String::ZoneHandle(String::NewSymbol(":for-in-iter")); |
4011 // We could set the type of the implicit iterator variable to Iterator<T> | 4013 // We could set the type of the implicit iterator variable to Iterator<T> |
4012 // where T is the type of the for loop variable. However, the type error | 4014 // where T is the type of the for loop variable. However, the type error |
4013 // would refer to the compiler generated iterator and could confuse the user. | 4015 // would refer to the compiler generated iterator and could confuse the user. |
4014 // It is better to leave the iterator untyped and postpone the type error | 4016 // It is better to leave the iterator untyped and postpone the type error |
4015 // until the loop variable is assigned to. | 4017 // until the loop variable is assigned to. |
4016 const Type& iterator_type = Type::ZoneHandle(Type::VarType()); | 4018 const Type& iterator_type = Type::ZoneHandle(Type::DynamicType()); |
4017 LocalVariable* iterator_var = | 4019 LocalVariable* iterator_var = |
4018 new LocalVariable(collection_pos, iterator_name, iterator_type); | 4020 new LocalVariable(collection_pos, iterator_name, iterator_type); |
4019 current_block_->scope->AddVariable(iterator_var); | 4021 current_block_->scope->AddVariable(iterator_var); |
4020 | 4022 |
4021 // Generate initialization of iterator variable. | 4023 // Generate initialization of iterator variable. |
4022 const String& iterator_method_name = | 4024 const String& iterator_method_name = |
4023 String::ZoneHandle(String::NewSymbol(kGetIteratorName)); | 4025 String::ZoneHandle(String::NewSymbol(kGetIteratorName)); |
4024 ArgumentListNode* no_args = new ArgumentListNode(collection_pos); | 4026 ArgumentListNode* no_args = new ArgumentListNode(collection_pos); |
4025 AstNode* get_iterator = new InstanceCallNode( | 4027 AstNode* get_iterator = new InstanceCallNode( |
4026 collection_pos, collection_expr, iterator_method_name, no_args); | 4028 collection_pos, collection_expr, iterator_method_name, no_args); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4344 // :exception_var and :stacktrace_var get set with the exception object | 4346 // :exception_var and :stacktrace_var get set with the exception object |
4345 // and the stacktrace object when an exception is thrown. | 4347 // and the stacktrace object when an exception is thrown. |
4346 // These three implicit variables can never be captured variables. | 4348 // These three implicit variables can never be captured variables. |
4347 const String& context_var_name = | 4349 const String& context_var_name = |
4348 String::ZoneHandle(String::NewSymbol(":saved_context_var")); | 4350 String::ZoneHandle(String::NewSymbol(":saved_context_var")); |
4349 LocalVariable* context_var = | 4351 LocalVariable* context_var = |
4350 current_block_->scope->LocalLookupVariable(context_var_name); | 4352 current_block_->scope->LocalLookupVariable(context_var_name); |
4351 if (context_var == NULL) { | 4353 if (context_var == NULL) { |
4352 context_var = new LocalVariable(token_index_, | 4354 context_var = new LocalVariable(token_index_, |
4353 context_var_name, | 4355 context_var_name, |
4354 Type::ZoneHandle(Type::VarType())); | 4356 Type::ZoneHandle(Type::DynamicType())); |
4355 current_block_->scope->AddVariable(context_var); | 4357 current_block_->scope->AddVariable(context_var); |
4356 } | 4358 } |
4357 const String& catch_excp_var_name = | 4359 const String& catch_excp_var_name = |
4358 String::ZoneHandle(String::NewSymbol(":exception_var")); | 4360 String::ZoneHandle(String::NewSymbol(":exception_var")); |
4359 LocalVariable* catch_excp_var = | 4361 LocalVariable* catch_excp_var = |
4360 current_block_->scope->LocalLookupVariable(catch_excp_var_name); | 4362 current_block_->scope->LocalLookupVariable(catch_excp_var_name); |
4361 if (catch_excp_var == NULL) { | 4363 if (catch_excp_var == NULL) { |
4362 catch_excp_var = new LocalVariable(token_index_, | 4364 catch_excp_var = new LocalVariable(token_index_, |
4363 catch_excp_var_name, | 4365 catch_excp_var_name, |
4364 Type::ZoneHandle(Type::VarType())); | 4366 Type::ZoneHandle(Type::DynamicType())); |
4365 current_block_->scope->AddVariable(catch_excp_var); | 4367 current_block_->scope->AddVariable(catch_excp_var); |
4366 } | 4368 } |
4367 const String& catch_trace_var_name = | 4369 const String& catch_trace_var_name = |
4368 String::ZoneHandle(String::NewSymbol(":stacktrace_var")); | 4370 String::ZoneHandle(String::NewSymbol(":stacktrace_var")); |
4369 LocalVariable* catch_trace_var = | 4371 LocalVariable* catch_trace_var = |
4370 current_block_->scope->LocalLookupVariable(catch_trace_var_name); | 4372 current_block_->scope->LocalLookupVariable(catch_trace_var_name); |
4371 if (catch_trace_var == NULL) { | 4373 if (catch_trace_var == NULL) { |
4372 catch_trace_var = new LocalVariable(token_index_, | 4374 catch_trace_var = new LocalVariable(token_index_, |
4373 catch_trace_var_name, | 4375 catch_trace_var_name, |
4374 Type::ZoneHandle(Type::VarType())); | 4376 Type::ZoneHandle(Type::DynamicType())); |
4375 current_block_->scope->AddVariable(catch_trace_var); | 4377 current_block_->scope->AddVariable(catch_trace_var); |
4376 } | 4378 } |
4377 | 4379 |
4378 intptr_t try_pos = token_index_; | 4380 intptr_t try_pos = token_index_; |
4379 ConsumeToken(); // Consume the 'try'. | 4381 ConsumeToken(); // Consume the 'try'. |
4380 | 4382 |
4381 SourceLabel* try_label = NULL; | 4383 SourceLabel* try_label = NULL; |
4382 if (label_name != NULL) { | 4384 if (label_name != NULL) { |
4383 try_label = SourceLabel::New(try_pos, label_name, SourceLabel::kStatement); | 4385 try_label = SourceLabel::New(try_pos, label_name, SourceLabel::kStatement); |
4384 OpenBlock(); | 4386 OpenBlock(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4462 *trace, | 4464 *trace, |
4463 new LoadLocalNode(catch_pos, *catch_trace_var))); | 4465 new LoadLocalNode(catch_pos, *catch_trace_var))); |
4464 } | 4466 } |
4465 | 4467 |
4466 ParseStatementSequence(); // Parse the catch handler code. | 4468 ParseStatementSequence(); // Parse the catch handler code. |
4467 current_block_->statements->Add( | 4469 current_block_->statements->Add( |
4468 new JumpNode(catch_pos, Token::kCONTINUE, end_catch_label)); | 4470 new JumpNode(catch_pos, Token::kCONTINUE, end_catch_label)); |
4469 SequenceNode* catch_handler = CloseBlock(); | 4471 SequenceNode* catch_handler = CloseBlock(); |
4470 ExpectToken(Token::kRBRACE); | 4472 ExpectToken(Token::kRBRACE); |
4471 | 4473 |
4472 if (!exception_param.type->IsVarType()) { // Has a type specification. | 4474 if (!exception_param.type->IsDynamicType()) { // Has a type specification. |
4473 // Now form an 'if type check' as an exception type exists in | 4475 // Now form an 'if type check' as an exception type exists in |
4474 // the catch specifier. | 4476 // the catch specifier. |
4475 if (!exception_param.type->IsInstantiated() && | 4477 if (!exception_param.type->IsInstantiated() && |
4476 (current_block_->scope->function_level() > 0)) { | 4478 (current_block_->scope->function_level() > 0)) { |
4477 // Make sure that the instantiator is captured. | 4479 // Make sure that the instantiator is captured. |
4478 CaptureReceiver(); | 4480 CaptureReceiver(); |
4479 } | 4481 } |
4480 AstNode* exception_type = new TypeNode(catch_pos, *exception_param.type); | 4482 AstNode* exception_type = new TypeNode(catch_pos, *exception_param.type); |
4481 AstNode* exception_var = new LoadLocalNode(catch_pos, *catch_excp_var); | 4483 AstNode* exception_var = new LoadLocalNode(catch_pos, *catch_excp_var); |
4482 AstNode* cond_expr = new ComparisonNode( | 4484 AstNode* cond_expr = new ComparisonNode( |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4954 | 4956 |
4955 | 4957 |
4956 LocalVariable* Parser::CreateTempConstVariable(intptr_t token_index, | 4958 LocalVariable* Parser::CreateTempConstVariable(intptr_t token_index, |
4957 intptr_t token_id, | 4959 intptr_t token_id, |
4958 const char* s) { | 4960 const char* s) { |
4959 char name[64]; | 4961 char name[64]; |
4960 OS::SNPrint(name, 64, "%s%d", s, token_id); | 4962 OS::SNPrint(name, 64, "%s%d", s, token_id); |
4961 LocalVariable* temp = | 4963 LocalVariable* temp = |
4962 new LocalVariable(token_index, | 4964 new LocalVariable(token_index, |
4963 String::ZoneHandle(String::NewSymbol(name)), | 4965 String::ZoneHandle(String::NewSymbol(name)), |
4964 Type::ZoneHandle(Type::VarType())); | 4966 Type::ZoneHandle(Type::DynamicType())); |
4965 temp->set_is_final(); | 4967 temp->set_is_final(); |
4966 current_block_->scope->AddVariable(temp); | 4968 current_block_->scope->AddVariable(temp); |
4967 return temp; | 4969 return temp; |
4968 } | 4970 } |
4969 | 4971 |
4970 | 4972 |
4971 // If 'node' can create side effects, store its result in a temporary variable | 4973 // If 'node' can create side effects, store its result in a temporary variable |
4972 // and return a LoadLocalNode instead. | 4974 // and return a LoadLocalNode instead. |
4973 // Side effect free nodes are LoadLocalNode and LiteralNode. | 4975 // Side effect free nodes are LoadLocalNode and LiteralNode. |
4974 AstNode* Parser::AsSideEffectFreeNode(AstNode* node) { | 4976 AstNode* Parser::AsSideEffectFreeNode(AstNode* node) { |
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6132 // as one token of type Token::kINDEX. | 6134 // as one token of type Token::kINDEX. |
6133 AstNode* Parser::ParseArrayLiteral(intptr_t type_pos, | 6135 AstNode* Parser::ParseArrayLiteral(intptr_t type_pos, |
6134 bool is_const, | 6136 bool is_const, |
6135 const TypeArguments& type_arguments) { | 6137 const TypeArguments& type_arguments) { |
6136 ASSERT(CurrentToken() == Token::kLBRACK || CurrentToken() == Token::kINDEX); | 6138 ASSERT(CurrentToken() == Token::kLBRACK || CurrentToken() == Token::kINDEX); |
6137 intptr_t literal_pos = token_index_; | 6139 intptr_t literal_pos = token_index_; |
6138 bool is_empty_literal = CurrentToken() == Token::kINDEX; | 6140 bool is_empty_literal = CurrentToken() == Token::kINDEX; |
6139 ConsumeToken(); | 6141 ConsumeToken(); |
6140 | 6142 |
6141 // If no type arguments are provided, leave them as null, which is equivalent | 6143 // If no type arguments are provided, leave them as null, which is equivalent |
6142 // to using Array<var>. See issue 4966724. | 6144 // to using Array<Dynamic>. See issue 4966724. |
6143 if (!type_arguments.IsNull()) { | 6145 if (!type_arguments.IsNull()) { |
6144 // For now, only check the number of type arguments. See issue 4975876. | 6146 // For now, only check the number of type arguments. See issue 4975876. |
6145 if (type_arguments.Length() != 1) { | 6147 if (type_arguments.Length() != 1) { |
6146 ASSERT(type_pos >= 0); | 6148 ASSERT(type_pos >= 0); |
6147 ErrorMsg(type_pos, "wrong number of type arguments for Array literal"); | 6149 ErrorMsg(type_pos, "wrong number of type arguments for Array literal"); |
6148 } | 6150 } |
6149 } | 6151 } |
6150 | 6152 |
6151 // Parse the array elements. Note: there may be an optional extra | 6153 // Parse the array elements. Note: there may be an optional extra |
6152 // comma after the last element. | 6154 // comma after the last element. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6246 ConsumeToken(); | 6248 ConsumeToken(); |
6247 | 6249 |
6248 String& map_class_name = String::Handle( | 6250 String& map_class_name = String::Handle( |
6249 String::NewSymbol(is_const ? kImmutableMapName : kMutableMapName)); | 6251 String::NewSymbol(is_const ? kImmutableMapName : kMutableMapName)); |
6250 const Class& map_class = Class::Handle(LookupImplClass(map_class_name)); | 6252 const Class& map_class = Class::Handle(LookupImplClass(map_class_name)); |
6251 ASSERT(!map_class.IsNull()); | 6253 ASSERT(!map_class.IsNull()); |
6252 | 6254 |
6253 TypeArguments& map_type_arguments = | 6255 TypeArguments& map_type_arguments = |
6254 TypeArguments::ZoneHandle(type_arguments.raw()); | 6256 TypeArguments::ZoneHandle(type_arguments.raw()); |
6255 // If no type arguments are provided, leave them as null, which is equivalent | 6257 // If no type arguments are provided, leave them as null, which is equivalent |
6256 // to using Map<var, var>. See issue 4966724. | 6258 // to using Map<Dynamic, Dynamic>. See issue 4966724. |
6257 if (!map_type_arguments.IsNull()) { | 6259 if (!map_type_arguments.IsNull()) { |
6258 // For now, only check the number of type arguments. See issue 4975876. | 6260 // For now, only check the number of type arguments. See issue 4975876. |
6259 if (map_type_arguments.Length() != 2) { | 6261 if (map_type_arguments.Length() != 2) { |
6260 ASSERT(type_pos >= 0); | 6262 ASSERT(type_pos >= 0); |
6261 ErrorMsg(type_pos, "wrong number of type arguments for Map literal"); | 6263 ErrorMsg(type_pos, "wrong number of type arguments for Map literal"); |
6262 } | 6264 } |
6263 } | 6265 } |
6264 | 6266 |
6265 // Parse the map entries. Note: there may be an optional extra | 6267 // Parse the map entries. Note: there may be an optional extra |
6266 // comma after the last entry. | 6268 // comma after the last entry. |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6991 } | 6993 } |
6992 | 6994 |
6993 | 6995 |
6994 void Parser::SkipNestedExpr() { | 6996 void Parser::SkipNestedExpr() { |
6995 const bool saved_mode = SetAllowFunctionLiterals(true); | 6997 const bool saved_mode = SetAllowFunctionLiterals(true); |
6996 SkipExpr(); | 6998 SkipExpr(); |
6997 SetAllowFunctionLiterals(saved_mode); | 6999 SetAllowFunctionLiterals(saved_mode); |
6998 } | 7000 } |
6999 | 7001 |
7000 } // namespace dart | 7002 } // namespace dart |
OLD | NEW |