| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 template<typename T> | 77 template<typename T> |
| 78 static RawArray* NewArray(const GrowableArray<T*>& objs) { | 78 static RawArray* NewArray(const GrowableArray<T*>& objs) { |
| 79 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld)); | 79 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld)); |
| 80 for (int i = 0; i < objs.length(); i++) { | 80 for (int i = 0; i < objs.length(); i++) { |
| 81 a.SetAt(i, *objs[i]); | 81 a.SetAt(i, *objs[i]); |
| 82 } | 82 } |
| 83 return a.raw(); | 83 return a.raw(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 | 86 |
| 87 static RawTypeArray* NewTypeArray(const GrowableArray<Type*>& objs) { | 87 static RawTypeArray* NewTypeArray(const GrowableArray<AbstractType*>& objs) { |
| 88 TypeArray& a = TypeArray::Handle(TypeArray::New(objs.length())); | 88 TypeArray& a = TypeArray::Handle(TypeArray::New(objs.length())); |
| 89 for (int i = 0; i < objs.length(); i++) { | 89 for (int i = 0; i < objs.length(); i++) { |
| 90 a.SetTypeAt(i, *objs[i]); | 90 a.SetTypeAt(i, *objs[i]); |
| 91 } | 91 } |
| 92 return a.raw(); | 92 return a.raw(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 | 95 |
| 96 static ThrowNode* CreateEvalConstConstructorThrow(intptr_t token_pos, | 96 static ThrowNode* CreateEvalConstConstructorThrow(intptr_t token_pos, |
| 97 const Instance& instance) { | 97 const Instance& instance) { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 285 |
| 286 | 286 |
| 287 struct ParamDesc { | 287 struct ParamDesc { |
| 288 ParamDesc() | 288 ParamDesc() |
| 289 : type(NULL), | 289 : type(NULL), |
| 290 name_pos(0), | 290 name_pos(0), |
| 291 name(NULL), | 291 name(NULL), |
| 292 default_value(NULL), | 292 default_value(NULL), |
| 293 is_final(false), | 293 is_final(false), |
| 294 is_field_initializer(false) { } | 294 is_field_initializer(false) { } |
| 295 const Type* type; | 295 const AbstractType* type; |
| 296 intptr_t name_pos; | 296 intptr_t name_pos; |
| 297 const String* name; | 297 const String* name; |
| 298 const Object* default_value; // NULL if not an optional parameter. | 298 const Object* default_value; // NULL if not an optional parameter. |
| 299 bool is_final; | 299 bool is_final; |
| 300 bool is_field_initializer; | 300 bool is_field_initializer; |
| 301 }; | 301 }; |
| 302 | 302 |
| 303 | 303 |
| 304 struct ParamList { | 304 struct ParamList { |
| 305 ParamList() { | 305 ParamList() { |
| 306 Clear(); | 306 Clear(); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void Clear() { | 309 void Clear() { |
| 310 num_fixed_parameters = 0; | 310 num_fixed_parameters = 0; |
| 311 num_optional_parameters = 0; | 311 num_optional_parameters = 0; |
| 312 has_named_optional_parameters = false; | 312 has_named_optional_parameters = false; |
| 313 has_field_initializer = false; | 313 has_field_initializer = false; |
| 314 implicitly_final = false; | 314 implicitly_final = false; |
| 315 this->parameters = new ZoneGrowableArray<ParamDesc>(); | 315 this->parameters = new ZoneGrowableArray<ParamDesc>(); |
| 316 } | 316 } |
| 317 | 317 |
| 318 void AddFinalParameter(intptr_t name_pos, | 318 void AddFinalParameter(intptr_t name_pos, |
| 319 const char* name, | 319 const char* name, |
| 320 const Type* type) { | 320 const AbstractType* type) { |
| 321 this->num_fixed_parameters++; | 321 this->num_fixed_parameters++; |
| 322 ParamDesc param; | 322 ParamDesc param; |
| 323 param.name_pos = name_pos; | 323 param.name_pos = name_pos; |
| 324 param.name = &String::ZoneHandle(String::NewSymbol(name)); | 324 param.name = &String::ZoneHandle(String::NewSymbol(name)); |
| 325 param.is_final = true; | 325 param.is_final = true; |
| 326 param.type = type; | 326 param.type = type; |
| 327 this->parameters->Add(param); | 327 this->parameters->Add(param); |
| 328 } | 328 } |
| 329 | 329 |
| 330 void AddReceiver(intptr_t name_pos) { | 330 void AddReceiver(intptr_t name_pos) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 } | 380 } |
| 381 bool IsSetter() const { | 381 bool IsSetter() const { |
| 382 return kind == RawFunction::kSetterFunction; | 382 return kind == RawFunction::kSetterFunction; |
| 383 } | 383 } |
| 384 bool has_abstract; | 384 bool has_abstract; |
| 385 bool has_final; | 385 bool has_final; |
| 386 bool has_const; | 386 bool has_const; |
| 387 bool has_static; | 387 bool has_static; |
| 388 bool has_var; | 388 bool has_var; |
| 389 bool has_factory; | 389 bool has_factory; |
| 390 const Type* type; | 390 const AbstractType* type; |
| 391 intptr_t name_pos; | 391 intptr_t name_pos; |
| 392 String* name; | 392 String* name; |
| 393 String* redirect_name; // For constructors: NULL or redirected constructor. | 393 String* redirect_name; // For constructors: NULL or redirected constructor. |
| 394 ParamList params; | 394 ParamList params; |
| 395 RawFunction::Kind kind; | 395 RawFunction::Kind kind; |
| 396 }; | 396 }; |
| 397 | 397 |
| 398 | 398 |
| 399 class ClassDesc : public ValueObject { | 399 class ClassDesc : public ValueObject { |
| 400 public: | 400 public: |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 CompilerStats::parser_timer.Stop(); | 608 CompilerStats::parser_timer.Stop(); |
| 609 } | 609 } |
| 610 isolate->set_ast_node_id(prev_ast_node_id); | 610 isolate->set_ast_node_id(prev_ast_node_id); |
| 611 } | 611 } |
| 612 | 612 |
| 613 | 613 |
| 614 SequenceNode* Parser::ParseStaticConstGetter(const Function& func) { | 614 SequenceNode* Parser::ParseStaticConstGetter(const Function& func) { |
| 615 ParamList params; | 615 ParamList params; |
| 616 ASSERT(func.num_fixed_parameters() == 0); // static. | 616 ASSERT(func.num_fixed_parameters() == 0); // static. |
| 617 ASSERT(func.num_optional_parameters() == 0); | 617 ASSERT(func.num_optional_parameters() == 0); |
| 618 ASSERT(Type::Handle(func.result_type()).IsResolved()); | 618 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 619 | 619 |
| 620 // Build local scope for function and populate with the formal parameters. | 620 // Build local scope for function and populate with the formal parameters. |
| 621 OpenFunctionBlock(func); | 621 OpenFunctionBlock(func); |
| 622 AddFormalParamsToScope(¶ms, current_block_->scope); | 622 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 623 | 623 |
| 624 // Static const fields must have an initializer. | 624 // Static const fields must have an initializer. |
| 625 ExpectToken(Token::kIDENT); | 625 ExpectToken(Token::kIDENT); |
| 626 ExpectToken(Token::kASSIGN); | 626 ExpectToken(Token::kASSIGN); |
| 627 | 627 |
| 628 // We don't want to use ParseConstExpr() here because we don't want | 628 // We don't want to use ParseConstExpr() here because we don't want |
| (...skipping 15 matching lines...) Expand all Loading... |
| 644 // Create AstNodes for an implicit instance getter method: | 644 // Create AstNodes for an implicit instance getter method: |
| 645 // LoadLocalNode 0 ('this'); | 645 // LoadLocalNode 0 ('this'); |
| 646 // LoadInstanceFieldNode (field_name); | 646 // LoadInstanceFieldNode (field_name); |
| 647 // ReturnNode (field's value); | 647 // ReturnNode (field's value); |
| 648 SequenceNode* Parser::ParseInstanceGetter(const Function& func) { | 648 SequenceNode* Parser::ParseInstanceGetter(const Function& func) { |
| 649 TRACE_PARSER("ParseInstanceGetter"); | 649 TRACE_PARSER("ParseInstanceGetter"); |
| 650 ParamList params; | 650 ParamList params; |
| 651 params.AddReceiver(token_index_); | 651 params.AddReceiver(token_index_); |
| 652 ASSERT(func.num_fixed_parameters() == 1); // receiver. | 652 ASSERT(func.num_fixed_parameters() == 1); // receiver. |
| 653 ASSERT(func.num_optional_parameters() == 0); | 653 ASSERT(func.num_optional_parameters() == 0); |
| 654 ASSERT(Type::Handle(func.result_type()).IsResolved()); | 654 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 655 | 655 |
| 656 // Build local scope for function and populate with the formal parameters. | 656 // Build local scope for function and populate with the formal parameters. |
| 657 OpenFunctionBlock(func); | 657 OpenFunctionBlock(func); |
| 658 AddFormalParamsToScope(¶ms, current_block_->scope); | 658 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 659 | 659 |
| 660 // Receiver is local 0. | 660 // Receiver is local 0. |
| 661 LocalVariable* receiver = current_block_->scope->VariableAt(0); | 661 LocalVariable* receiver = current_block_->scope->VariableAt(0); |
| 662 LoadLocalNode* load_receiver = new LoadLocalNode(token_index_, *receiver); | 662 LoadLocalNode* load_receiver = new LoadLocalNode(token_index_, *receiver); |
| 663 // token_index_ is the function's token position which points to the name of | 663 // token_index_ is the function's token position which points to the name of |
| 664 // the field; | 664 // the field; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 683 // SetInstanceField (field_name); | 683 // SetInstanceField (field_name); |
| 684 // ReturnNode (void); | 684 // ReturnNode (void); |
| 685 SequenceNode* Parser::ParseInstanceSetter(const Function& func) { | 685 SequenceNode* Parser::ParseInstanceSetter(const Function& func) { |
| 686 TRACE_PARSER("ParseInstanceSetter"); | 686 TRACE_PARSER("ParseInstanceSetter"); |
| 687 // token_index_ is the function's token position which points to the name of | 687 // token_index_ is the function's token position which points to the name of |
| 688 // the field; we can use it to form the field_name. | 688 // the field; we can use it to form the field_name. |
| 689 const String& field_name = *CurrentLiteral(); | 689 const String& field_name = *CurrentLiteral(); |
| 690 const Class& field_class = Class::ZoneHandle(func.owner()); | 690 const Class& field_class = Class::ZoneHandle(func.owner()); |
| 691 const Field& field = | 691 const Field& field = |
| 692 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); | 692 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); |
| 693 const Type& field_type = Type::ZoneHandle(field.type()); | 693 const AbstractType& field_type = AbstractType::ZoneHandle(field.type()); |
| 694 | 694 |
| 695 ParamList params; | 695 ParamList params; |
| 696 params.AddReceiver(token_index_); | 696 params.AddReceiver(token_index_); |
| 697 params.AddFinalParameter(token_index_, "value", &field_type); | 697 params.AddFinalParameter(token_index_, "value", &field_type); |
| 698 ASSERT(func.num_fixed_parameters() == 2); // receiver, value. | 698 ASSERT(func.num_fixed_parameters() == 2); // receiver, value. |
| 699 ASSERT(func.num_optional_parameters() == 0); | 699 ASSERT(func.num_optional_parameters() == 0); |
| 700 ASSERT(Type::Handle(func.result_type()).IsVoidType()); | 700 ASSERT(AbstractType::Handle(func.result_type()).IsVoidType()); |
| 701 | 701 |
| 702 // Build local scope for function and populate with the formal parameters. | 702 // Build local scope for function and populate with the formal parameters. |
| 703 OpenFunctionBlock(func); | 703 OpenFunctionBlock(func); |
| 704 AddFormalParamsToScope(¶ms, current_block_->scope); | 704 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 705 | 705 |
| 706 LoadLocalNode* receiver = | 706 LoadLocalNode* receiver = |
| 707 new LoadLocalNode(token_index_, *current_block_->scope->VariableAt(0)); | 707 new LoadLocalNode(token_index_, *current_block_->scope->VariableAt(0)); |
| 708 LoadLocalNode* value = | 708 LoadLocalNode* value = |
| 709 new LoadLocalNode(token_index_, *current_block_->scope->VariableAt(1)); | 709 new LoadLocalNode(token_index_, *current_block_->scope->VariableAt(1)); |
| 710 | 710 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 } | 803 } |
| 804 // We have not seen a parameter type yet, so we check if the next | 804 // We have not seen a parameter type yet, so we check if the next |
| 805 // identifier could represent a type before parsing it. | 805 // identifier could represent a type before parsing it. |
| 806 Token::Kind follower = LookaheadToken(1); | 806 Token::Kind follower = LookaheadToken(1); |
| 807 // We have an identifier followed by a 'follower' token. | 807 // We have an identifier followed by a 'follower' token. |
| 808 // We either parse a type or assume that no type is specified. | 808 // We either parse a type or assume that no type is specified. |
| 809 if ((follower == Token::kLT) || // Parameterized type. | 809 if ((follower == Token::kLT) || // Parameterized type. |
| 810 (follower == Token::kPERIOD) || // Qualified class name of type. | 810 (follower == Token::kPERIOD) || // Qualified class name of type. |
| 811 (follower == Token::kIDENT) || // Parameter name following a type. | 811 (follower == Token::kIDENT) || // Parameter name following a type. |
| 812 (follower == Token::kTHIS)) { // Field parameter following a type. | 812 (follower == Token::kTHIS)) { // Field parameter following a type. |
| 813 parameter.type = &Type::ZoneHandle( | 813 parameter.type = &AbstractType::ZoneHandle( |
| 814 ParseType(is_top_level_ ? kCanResolve : kMustResolve)); | 814 ParseType(is_top_level_ ? kCanResolve : kMustResolve)); |
| 815 } else { | 815 } else { |
| 816 parameter.type = &Type::ZoneHandle(Type::DynamicType()); | 816 parameter.type = &Type::ZoneHandle(Type::DynamicType()); |
| 817 } | 817 } |
| 818 } | 818 } |
| 819 if (!this_seen && (CurrentToken() == Token::kTHIS)) { | 819 if (!this_seen && (CurrentToken() == Token::kTHIS)) { |
| 820 ConsumeToken(); | 820 ConsumeToken(); |
| 821 ExpectToken(Token::kPERIOD); | 821 ExpectToken(Token::kPERIOD); |
| 822 this_seen = true; | 822 this_seen = true; |
| 823 parameter.is_field_initializer = true; | 823 parameter.is_field_initializer = true; |
| 824 } | 824 } |
| 825 // At this point, we must see an identifier for the parameter name. | 825 // At this point, we must see an identifier for the parameter name. |
| 826 if (CurrentToken() != Token::kIDENT) { | 826 if (CurrentToken() != Token::kIDENT) { |
| 827 ErrorMsg("parameter name expected"); | 827 ErrorMsg("parameter name expected"); |
| 828 } | 828 } |
| 829 parameter.name = CurrentLiteral(); | 829 parameter.name = CurrentLiteral(); |
| 830 parameter.name_pos = token_index_; | 830 parameter.name_pos = token_index_; |
| 831 ConsumeToken(); | 831 ConsumeToken(); |
| 832 if (parameter.is_field_initializer) { | 832 if (parameter.is_field_initializer) { |
| 833 params->has_field_initializer = true; | 833 params->has_field_initializer = true; |
| 834 } | 834 } |
| 835 | 835 |
| 836 if (CurrentToken() == Token::kLPAREN) { | 836 if (CurrentToken() == Token::kLPAREN) { |
| 837 // This parameter is probably a closure. If we saw the keyword 'var' | 837 // This parameter is probably a closure. If we saw the keyword 'var' |
| 838 // or 'final', a closure is not legal here and we ignore the | 838 // or 'final', a closure is not legal here and we ignore the |
| 839 // opening parens. | 839 // opening parens. |
| 840 if (!var_seen && !parameter.is_final) { | 840 if (!var_seen && !parameter.is_final) { |
| 841 // The parsed parameter type is actually the function result type. | 841 // The parsed parameter type is actually the function result type. |
| 842 const Type& result_type = Type::Handle(parameter.type->raw()); | 842 const AbstractType& result_type = |
| 843 AbstractType::Handle(parameter.type->raw()); |
| 843 | 844 |
| 844 // Finish parsing the function type parameter. | 845 // Finish parsing the function type parameter. |
| 845 ParamList func_params; | 846 ParamList func_params; |
| 846 const bool no_explicit_default_values = false; | 847 const bool no_explicit_default_values = false; |
| 847 ParseFormalParameterList(no_explicit_default_values, &func_params); | 848 ParseFormalParameterList(no_explicit_default_values, &func_params); |
| 848 | 849 |
| 849 // The field 'is_static' has no meaning for signature functions. | 850 // The field 'is_static' has no meaning for signature functions. |
| 850 const Function& signature_function = Function::Handle( | 851 const Function& signature_function = Function::Handle( |
| 851 Function::New(*parameter.name, | 852 Function::New(*parameter.name, |
| 852 RawFunction::kSignatureFunction, | 853 RawFunction::kSignatureFunction, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 865 if (signature_class.IsNull()) { | 866 if (signature_class.IsNull()) { |
| 866 signature_class = Class::NewSignatureClass(signature, | 867 signature_class = Class::NewSignatureClass(signature, |
| 867 signature_function, | 868 signature_function, |
| 868 script_); | 869 script_); |
| 869 // Record the function signature class in the current library. | 870 // Record the function signature class in the current library. |
| 870 library_.AddClass(signature_class); | 871 library_.AddClass(signature_class); |
| 871 } else { | 872 } else { |
| 872 signature_function.set_signature_class(signature_class); | 873 signature_function.set_signature_class(signature_class); |
| 873 } | 874 } |
| 874 ASSERT(signature_function.signature_class() == signature_class.raw()); | 875 ASSERT(signature_function.signature_class() == signature_class.raw()); |
| 875 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType()); | 876 AbstractType& signature_type = |
| 877 AbstractType::ZoneHandle(signature_class.SignatureType()); |
| 876 if (!is_top_level_ && !signature_type.IsFinalized()) { | 878 if (!is_top_level_ && !signature_type.IsFinalized()) { |
| 877 String& errmsg = String::Handle(); | 879 String& errmsg = String::Handle(); |
| 878 signature_type = | 880 signature_type = |
| 879 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, | 881 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, |
| 880 &errmsg); | 882 &errmsg); |
| 881 if (!errmsg.IsNull()) { | 883 if (!errmsg.IsNull()) { |
| 882 ErrorMsg(errmsg.ToCString()); | 884 ErrorMsg(errmsg.ToCString()); |
| 883 } | 885 } |
| 884 } | 886 } |
| 885 // The type of the parameter is now the signature type. | 887 // The type of the parameter is now the signature type. |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 OpenFunctionBlock(func); | 1543 OpenFunctionBlock(func); |
| 1542 ParamList params; | 1544 ParamList params; |
| 1543 const bool allow_explicit_default_values = true; | 1545 const bool allow_explicit_default_values = true; |
| 1544 ASSERT(CurrentToken() == Token::kLPAREN); | 1546 ASSERT(CurrentToken() == Token::kLPAREN); |
| 1545 | 1547 |
| 1546 // Add implicit receiver parameter which is passed the allocated | 1548 // Add implicit receiver parameter which is passed the allocated |
| 1547 // but uninitialized instance to construct. | 1549 // but uninitialized instance to construct. |
| 1548 params.AddReceiver(token_index_); | 1550 params.AddReceiver(token_index_); |
| 1549 | 1551 |
| 1550 // Add implicit parameter for construction phase. | 1552 // Add implicit parameter for construction phase. |
| 1551 params.AddFinalParameter(token_index_, kPhaseParameterName, | 1553 params.AddFinalParameter( |
| 1552 &Type::ZoneHandle(Type::DynamicType())); | 1554 token_index_, |
| 1555 kPhaseParameterName, |
| 1556 &Type::ZoneHandle(Type::DynamicType())); |
| 1553 | 1557 |
| 1554 if (func.is_const()) { | 1558 if (func.is_const()) { |
| 1555 params.SetImplicitlyFinal(); | 1559 params.SetImplicitlyFinal(); |
| 1556 } | 1560 } |
| 1557 ParseFormalParameterList(allow_explicit_default_values, ¶ms); | 1561 ParseFormalParameterList(allow_explicit_default_values, ¶ms); |
| 1558 | 1562 |
| 1559 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); | 1563 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); |
| 1560 ASSERT(Type::Handle(func.result_type()).IsResolved()); | 1564 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 1561 ASSERT(func.NumberOfParameters() == params.parameters->length()); | 1565 ASSERT(func.NumberOfParameters() == params.parameters->length()); |
| 1562 | 1566 |
| 1563 // Initialize instance fields that have an explicit initializer expression. | 1567 // Initialize instance fields that have an explicit initializer expression. |
| 1564 // This has to be done before code for field initializer parameters | 1568 // This has to be done before code for field initializer parameters |
| 1565 // is generated. | 1569 // is generated. |
| 1566 // NB: the instance field initializers have to be compiled before | 1570 // NB: the instance field initializers have to be compiled before |
| 1567 // the parameters are added to the scope, so that a parameter | 1571 // the parameters are added to the scope, so that a parameter |
| 1568 // name cannot shadow a name used in the field initializer expression. | 1572 // name cannot shadow a name used in the field initializer expression. |
| 1569 GrowableArray<FieldInitExpression> initializers; | 1573 GrowableArray<FieldInitExpression> initializers; |
| 1570 ParseInitializedInstanceFields(cls, &initializers); | 1574 ParseInitializedInstanceFields(cls, &initializers); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1789 } | 1793 } |
| 1790 ASSERT(CurrentToken() == Token::kLPAREN); | 1794 ASSERT(CurrentToken() == Token::kLPAREN); |
| 1791 ParseFormalParameterList(allow_explicit_default_values, ¶ms); | 1795 ParseFormalParameterList(allow_explicit_default_values, ¶ms); |
| 1792 | 1796 |
| 1793 // The number of parameters and their type are not yet set in local functions, | 1797 // The number of parameters and their type are not yet set in local functions, |
| 1794 // since they are not 'top-level' parsed. | 1798 // since they are not 'top-level' parsed. |
| 1795 if (func.IsLocalFunction()) { | 1799 if (func.IsLocalFunction()) { |
| 1796 AddFormalParamsToFunction(¶ms, func); | 1800 AddFormalParamsToFunction(¶ms, func); |
| 1797 } | 1801 } |
| 1798 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); | 1802 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); |
| 1799 ASSERT(Type::Handle(func.result_type()).IsResolved()); | 1803 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 1800 ASSERT(func.NumberOfParameters() == params.parameters->length()); | 1804 ASSERT(func.NumberOfParameters() == params.parameters->length()); |
| 1801 | 1805 |
| 1802 // Check whether the function has any field initializer formal parameters, | 1806 // Check whether the function has any field initializer formal parameters, |
| 1803 // which are not allowed in non-constructor functions. | 1807 // which are not allowed in non-constructor functions. |
| 1804 if (params.has_field_initializer) { | 1808 if (params.has_field_initializer) { |
| 1805 for (int i = 0; i < params.parameters->length(); i++) { | 1809 for (int i = 0; i < params.parameters->length(); i++) { |
| 1806 ParamDesc& param = (*params.parameters)[i]; | 1810 ParamDesc& param = (*params.parameters)[i]; |
| 1807 if (param.is_field_initializer) { | 1811 if (param.is_field_initializer) { |
| 1808 ErrorMsg(param.name_pos, | 1812 ErrorMsg(param.name_pos, |
| 1809 "field initializer only allowed in constructors"); | 1813 "field initializer only allowed in constructors"); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1983 const bool are_implicitly_final = method->has_const; | 1987 const bool are_implicitly_final = method->has_const; |
| 1984 const bool allow_explicit_default_values = | 1988 const bool allow_explicit_default_values = |
| 1985 (!method->has_abstract && !members->is_interface()); | 1989 (!method->has_abstract && !members->is_interface()); |
| 1986 const intptr_t formal_param_pos = token_index_; | 1990 const intptr_t formal_param_pos = token_index_; |
| 1987 method->params.Clear(); | 1991 method->params.Clear(); |
| 1988 if (has_this_param) { | 1992 if (has_this_param) { |
| 1989 method->params.AddReceiver(formal_param_pos); | 1993 method->params.AddReceiver(formal_param_pos); |
| 1990 } | 1994 } |
| 1991 // Constructors have an implicit parameter for the construction phase. | 1995 // Constructors have an implicit parameter for the construction phase. |
| 1992 if (method->IsConstructor()) { | 1996 if (method->IsConstructor()) { |
| 1993 method->params.AddFinalParameter(token_index_, kPhaseParameterName, | 1997 method->params.AddFinalParameter( |
| 1994 &Type::ZoneHandle(Type::DynamicType())); | 1998 token_index_, |
| 1999 kPhaseParameterName, |
| 2000 &Type::ZoneHandle(Type::DynamicType())); |
| 1995 } | 2001 } |
| 1996 if (are_implicitly_final) { | 2002 if (are_implicitly_final) { |
| 1997 method->params.SetImplicitlyFinal(); | 2003 method->params.SetImplicitlyFinal(); |
| 1998 } | 2004 } |
| 1999 ParseFormalParameterList(allow_explicit_default_values, &method->params); | 2005 ParseFormalParameterList(allow_explicit_default_values, &method->params); |
| 2000 if (method->IsGetter() || method->IsSetter()) { | 2006 if (method->IsGetter() || method->IsSetter()) { |
| 2001 int expected_num_parameters = 0; | 2007 int expected_num_parameters = 0; |
| 2002 if (method->IsGetter()) { | 2008 if (method->IsGetter()) { |
| 2003 expected_num_parameters = (method->has_static) ? 0 : 1; | 2009 expected_num_parameters = (method->has_static) ? 0 : 1; |
| 2004 method->name = &String::ZoneHandle(Field::GetterName(*method->name)); | 2010 method->name = &String::ZoneHandle(Field::GetterName(*method->name)); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2299 // We have an identifier followed by a 'follower' token. | 2305 // We have an identifier followed by a 'follower' token. |
| 2300 // We either parse a type or assume that no type is specified. | 2306 // We either parse a type or assume that no type is specified. |
| 2301 if ((follower == Token::kLT) || // Parameterized type. | 2307 if ((follower == Token::kLT) || // Parameterized type. |
| 2302 (follower == Token::kGET) || // Getter following a type. | 2308 (follower == Token::kGET) || // Getter following a type. |
| 2303 (follower == Token::kSET) || // Setter following a type. | 2309 (follower == Token::kSET) || // Setter following a type. |
| 2304 (follower == Token::kOPERATOR) || // Operator following a type. | 2310 (follower == Token::kOPERATOR) || // Operator following a type. |
| 2305 (follower == Token::kIDENT) || // Member name following a type. | 2311 (follower == Token::kIDENT) || // Member name following a type. |
| 2306 ((follower == Token::kPERIOD) && // Qualified class name of type, | 2312 ((follower == Token::kPERIOD) && // Qualified class name of type, |
| 2307 (LookaheadToken(3) != Token::kLPAREN))) { // but not a named constr. | 2313 (LookaheadToken(3) != Token::kLPAREN))) { // but not a named constr. |
| 2308 ASSERT(is_top_level_); | 2314 ASSERT(is_top_level_); |
| 2309 member.type = &Type::ZoneHandle(ParseType(kCanResolve)); | 2315 member.type = &AbstractType::ZoneHandle(ParseType(kCanResolve)); |
| 2310 } | 2316 } |
| 2311 } | 2317 } |
| 2312 } | 2318 } |
| 2313 // Optionally parse a (possibly named) constructor name or factory. | 2319 // Optionally parse a (possibly named) constructor name or factory. |
| 2314 if ((CurrentToken() == Token::kIDENT) && | 2320 if ((CurrentToken() == Token::kIDENT) && |
| 2315 (CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) { | 2321 (CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) { |
| 2316 member.name = CurrentLiteral(); | 2322 member.name = CurrentLiteral(); |
| 2317 member.name_pos = this->token_index_; | 2323 member.name_pos = this->token_index_; |
| 2318 ConsumeToken(); | 2324 ConsumeToken(); |
| 2319 // Resolution of the factory result type is always postponed until class | 2325 // Resolution of the factory result type is always postponed until class |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2461 class_name.ToCString()); | 2467 class_name.ToCString()); |
| 2462 } else if (cls.functions() != Array::Empty()) { | 2468 } else if (cls.functions() != Array::Empty()) { |
| 2463 ErrorMsg(classname_pos, "class '%s' is already defined", | 2469 ErrorMsg(classname_pos, "class '%s' is already defined", |
| 2464 class_name.ToCString()); | 2470 class_name.ToCString()); |
| 2465 } | 2471 } |
| 2466 } | 2472 } |
| 2467 ASSERT(!cls.IsNull()); | 2473 ASSERT(!cls.IsNull()); |
| 2468 ASSERT(cls.functions() == Array::Empty()); | 2474 ASSERT(cls.functions() == Array::Empty()); |
| 2469 set_current_class(cls); | 2475 set_current_class(cls); |
| 2470 ParseTypeParameters(cls); | 2476 ParseTypeParameters(cls); |
| 2471 Type& super_type = Type::Handle(); | 2477 AbstractType& super_type = AbstractType::Handle(); |
| 2472 if (CurrentToken() == Token::kEXTENDS) { | 2478 if (CurrentToken() == Token::kEXTENDS) { |
| 2473 ConsumeToken(); | 2479 ConsumeToken(); |
| 2474 super_type = ParseType(kCanResolve); | 2480 super_type = ParseType(kCanResolve); |
| 2475 if (super_type.IsInterfaceType()) { | 2481 if (super_type.IsInterfaceType()) { |
| 2476 ErrorMsg("class '%s' may implement, but cannot extend interface '%s'", | 2482 ErrorMsg("class '%s' may implement, but cannot extend interface '%s'", |
| 2477 class_name.ToCString(), | 2483 class_name.ToCString(), |
| 2478 String::Handle(super_type.Name()).ToCString()); | 2484 String::Handle(super_type.Name()).ToCString()); |
| 2479 } | 2485 } |
| 2480 } else { | 2486 } else { |
| 2481 // No extends clause: Implicitly extend Object. | 2487 // No extends clause: Implicitly extend Object. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2522 Function& ctor = Function::ZoneHandle( | 2528 Function& ctor = Function::ZoneHandle( |
| 2523 Function::New(ctor_name, | 2529 Function::New(ctor_name, |
| 2524 RawFunction::kConstructor, | 2530 RawFunction::kConstructor, |
| 2525 /* is_static = */ false, | 2531 /* is_static = */ false, |
| 2526 /* is_const = */ false, | 2532 /* is_const = */ false, |
| 2527 class_desc->token_pos())); | 2533 class_desc->token_pos())); |
| 2528 ParamList params; | 2534 ParamList params; |
| 2529 // Add implicit 'this' parameter. | 2535 // Add implicit 'this' parameter. |
| 2530 params.AddReceiver(token_index_); | 2536 params.AddReceiver(token_index_); |
| 2531 // Add implicit parameter for construction phase. | 2537 // Add implicit parameter for construction phase. |
| 2532 params.AddFinalParameter(token_index_, kPhaseParameterName, | 2538 params.AddFinalParameter( |
| 2533 &Type::ZoneHandle(Type::DynamicType())); | 2539 token_index_, |
| 2540 kPhaseParameterName, |
| 2541 &Type::ZoneHandle(Type::DynamicType())); |
| 2534 | 2542 |
| 2535 AddFormalParamsToFunction(¶ms, ctor); | 2543 AddFormalParamsToFunction(¶ms, ctor); |
| 2536 // The body of the constructor cannot modify the type arguments of the | 2544 // The body of the constructor cannot modify the type arguments of the |
| 2537 // constructed instance, which is passed in as a hidden parameter. | 2545 // constructed instance, which is passed in as a hidden parameter. |
| 2538 // Therefore, there is no need to set the result type to be checked. | 2546 // Therefore, there is no need to set the result type to be checked. |
| 2539 const Type& result_type = Type::ZoneHandle(Type::DynamicType()); | 2547 const AbstractType& result_type = Type::ZoneHandle(Type::DynamicType()); |
| 2540 ctor.set_result_type(result_type); | 2548 ctor.set_result_type(result_type); |
| 2541 class_desc->AddFunction(&ctor); | 2549 class_desc->AddFunction(&ctor); |
| 2542 } | 2550 } |
| 2543 | 2551 |
| 2544 // Check for cycles in constructor redirection. | 2552 // Check for cycles in constructor redirection. |
| 2545 const GrowableArray<MemberDesc>& members = class_desc->members(); | 2553 const GrowableArray<MemberDesc>& members = class_desc->members(); |
| 2546 for (int i = 0; i < members.length(); i++) { | 2554 for (int i = 0; i < members.length(); i++) { |
| 2547 MemberDesc* member = &members[i]; | 2555 MemberDesc* member = &members[i]; |
| 2548 GrowableArray<MemberDesc*> ctors; | 2556 GrowableArray<MemberDesc*> ctors; |
| 2549 while ((member != NULL) && (member->redirect_name != NULL)) { | 2557 while ((member != NULL) && (member->redirect_name != NULL)) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2587 } | 2595 } |
| 2588 SetPosition(saved_pos); | 2596 SetPosition(saved_pos); |
| 2589 return is_alias_name; | 2597 return is_alias_name; |
| 2590 } | 2598 } |
| 2591 | 2599 |
| 2592 | 2600 |
| 2593 void Parser::ParseFunctionTypeAlias(GrowableArray<const Class*>* classes) { | 2601 void Parser::ParseFunctionTypeAlias(GrowableArray<const Class*>* classes) { |
| 2594 TRACE_PARSER("ParseFunctionTypeAlias"); | 2602 TRACE_PARSER("ParseFunctionTypeAlias"); |
| 2595 ExpectToken(Token::kTYPEDEF); | 2603 ExpectToken(Token::kTYPEDEF); |
| 2596 | 2604 |
| 2597 Type& result_type = Type::Handle(Type::DynamicType()); | 2605 AbstractType& result_type = Type::Handle(Type::DynamicType()); |
| 2598 const intptr_t result_type_pos = token_index_; | 2606 const intptr_t result_type_pos = token_index_; |
| 2599 if (CurrentToken() == Token::kVOID) { | 2607 if (CurrentToken() == Token::kVOID) { |
| 2600 ConsumeToken(); | 2608 ConsumeToken(); |
| 2601 result_type = Type::VoidType(); | 2609 result_type = Type::VoidType(); |
| 2602 } else if (!IsFunctionTypeAliasName()) { | 2610 } else if (!IsFunctionTypeAliasName()) { |
| 2603 result_type = ParseType(kDoNotResolve); // No owner class yet. | 2611 result_type = ParseType(kDoNotResolve); // No owner class yet. |
| 2604 } | 2612 } |
| 2605 | 2613 |
| 2606 if (CurrentToken() != Token::kIDENT) { | 2614 if (CurrentToken() != Token::kIDENT) { |
| 2607 ErrorMsg("function alias name expected"); | 2615 ErrorMsg("function alias name expected"); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2812 } | 2820 } |
| 2813 SkipTypeArguments(); | 2821 SkipTypeArguments(); |
| 2814 } | 2822 } |
| 2815 } | 2823 } |
| 2816 | 2824 |
| 2817 | 2825 |
| 2818 void Parser::ParseTypeParameters(const Class& cls) { | 2826 void Parser::ParseTypeParameters(const Class& cls) { |
| 2819 if (CurrentToken() == Token::kLT) { | 2827 if (CurrentToken() == Token::kLT) { |
| 2820 const intptr_t type_pos = token_index_; | 2828 const intptr_t type_pos = token_index_; |
| 2821 GrowableArray<String*> type_parameters; | 2829 GrowableArray<String*> type_parameters; |
| 2822 GrowableArray<Type*> type_parameter_extends; | 2830 GrowableArray<AbstractType*> type_parameter_extends; |
| 2823 do { | 2831 do { |
| 2824 ConsumeToken(); | 2832 ConsumeToken(); |
| 2825 if (CurrentToken() != Token::kIDENT) { | 2833 if (CurrentToken() != Token::kIDENT) { |
| 2826 ErrorMsg("type parameter name expected"); | 2834 ErrorMsg("type parameter name expected"); |
| 2827 } | 2835 } |
| 2828 String& type_parameter_name = *CurrentLiteral(); | 2836 String& type_parameter_name = *CurrentLiteral(); |
| 2829 ConsumeToken(); | 2837 ConsumeToken(); |
| 2830 Type& type_extends = Type::ZoneHandle(Type::DynamicType()); | 2838 AbstractType& type_extends = Type::ZoneHandle(Type::DynamicType()); |
| 2831 if (CurrentToken() == Token::kEXTENDS) { | 2839 if (CurrentToken() == Token::kEXTENDS) { |
| 2832 ConsumeToken(); | 2840 ConsumeToken(); |
| 2833 type_extends = ParseType(kCanResolve); | 2841 type_extends = ParseType(kCanResolve); |
| 2834 } | 2842 } |
| 2835 type_parameters.Add(&type_parameter_name); | 2843 type_parameters.Add(&type_parameter_name); |
| 2836 type_parameter_extends.Add(&type_extends); | 2844 type_parameter_extends.Add(&type_extends); |
| 2837 } while (CurrentToken() == Token::kCOMMA); | 2845 } while (CurrentToken() == Token::kCOMMA); |
| 2838 Token::Kind token = CurrentToken(); | 2846 Token::Kind token = CurrentToken(); |
| 2839 if ((token == Token::kGT) || | 2847 if ((token == Token::kGT) || |
| 2840 (token == Token::kSAR) || | 2848 (token == Token::kSAR) || |
| 2841 (token == Token::kSHR)) { | 2849 (token == Token::kSHR)) { |
| 2842 ConsumeRightAngleBracket(); | 2850 ConsumeRightAngleBracket(); |
| 2843 } else { | 2851 } else { |
| 2844 ErrorMsg("right angle bracket expected"); | 2852 ErrorMsg("right angle bracket expected"); |
| 2845 } | 2853 } |
| 2846 cls.set_type_parameters(Array::Handle(NewArray<String>(type_parameters))); | 2854 cls.set_type_parameters(Array::Handle(NewArray<String>(type_parameters))); |
| 2847 const TypeArray& extends_array = | 2855 const TypeArray& extends_array = |
| 2848 TypeArray::Handle(NewTypeArray(type_parameter_extends)); | 2856 TypeArray::Handle(NewTypeArray(type_parameter_extends)); |
| 2849 cls.set_type_parameter_extends(extends_array); | 2857 cls.set_type_parameter_extends(extends_array); |
| 2850 // Try to resolve the upper bounds, which will at least resolve the | 2858 // Try to resolve the upper bounds, which will at least resolve the |
| 2851 // referenced type parameters. | 2859 // referenced type parameters. |
| 2852 Type& type_extends = Type::Handle(); | 2860 AbstractType& type_extends = AbstractType::Handle(); |
| 2853 const intptr_t num_types = extends_array.Length(); | 2861 const intptr_t num_types = extends_array.Length(); |
| 2854 for (intptr_t i = 0; i < num_types; i++) { | 2862 for (intptr_t i = 0; i < num_types; i++) { |
| 2855 type_extends = extends_array.TypeAt(i); | 2863 type_extends = extends_array.TypeAt(i); |
| 2856 TryResolveTypeFromClass(type_pos, cls, &type_extends); | 2864 TryResolveTypeFromClass(type_pos, cls, &type_extends); |
| 2857 extends_array.SetTypeAt(i, type_extends); | 2865 extends_array.SetTypeAt(i, type_extends); |
| 2858 } | 2866 } |
| 2859 } | 2867 } |
| 2860 } | 2868 } |
| 2861 | 2869 |
| 2862 | 2870 |
| 2863 RawTypeArguments* Parser::ParseTypeArguments(TypeResolution type_resolution) { | 2871 RawTypeArguments* Parser::ParseTypeArguments(TypeResolution type_resolution) { |
| 2864 if (CurrentToken() == Token::kLT) { | 2872 if (CurrentToken() == Token::kLT) { |
| 2865 GrowableArray<Type*> types; | 2873 GrowableArray<AbstractType*> types; |
| 2866 do { | 2874 do { |
| 2867 ConsumeToken(); | 2875 ConsumeToken(); |
| 2868 Type& type = Type::ZoneHandle(ParseType(type_resolution)); | 2876 AbstractType& type = AbstractType::ZoneHandle(ParseType(type_resolution)); |
| 2869 types.Add(&type); | 2877 types.Add(&type); |
| 2870 } while (CurrentToken() == Token::kCOMMA); | 2878 } while (CurrentToken() == Token::kCOMMA); |
| 2871 Token::Kind token = CurrentToken(); | 2879 Token::Kind token = CurrentToken(); |
| 2872 if ((token == Token::kGT) || | 2880 if ((token == Token::kGT) || |
| 2873 (token == Token::kSAR) || | 2881 (token == Token::kSAR) || |
| 2874 (token == Token::kSHR)) { | 2882 (token == Token::kSHR)) { |
| 2875 ConsumeRightAngleBracket(); | 2883 ConsumeRightAngleBracket(); |
| 2876 } else { | 2884 } else { |
| 2877 ErrorMsg("right angle bracket expected"); | 2885 ErrorMsg("right angle bracket expected"); |
| 2878 } | 2886 } |
| 2879 return NewTypeArray(types); | 2887 return NewTypeArray(types); |
| 2880 } | 2888 } |
| 2881 return TypeArray::null(); | 2889 return TypeArray::null(); |
| 2882 } | 2890 } |
| 2883 | 2891 |
| 2884 | 2892 |
| 2885 // Parse and return an array of interface types. | 2893 // Parse and return an array of interface types. |
| 2886 RawArray* Parser::ParseInterfaceList() { | 2894 RawArray* Parser::ParseInterfaceList() { |
| 2887 ASSERT((CurrentToken() == Token::kIMPLEMENTS) || | 2895 ASSERT((CurrentToken() == Token::kIMPLEMENTS) || |
| 2888 (CurrentToken() == Token::kEXTENDS)); | 2896 (CurrentToken() == Token::kEXTENDS)); |
| 2889 GrowableArray<Type*> interfaces; | 2897 GrowableArray<AbstractType*> interfaces; |
| 2890 do { | 2898 do { |
| 2891 ConsumeToken(); | 2899 ConsumeToken(); |
| 2892 Type& interface = Type::ZoneHandle(ParseType(kCanResolve)); | 2900 AbstractType& interface = AbstractType::ZoneHandle(ParseType(kCanResolve)); |
| 2893 interfaces.Add(&interface); | 2901 interfaces.Add(&interface); |
| 2894 } while (CurrentToken() == Token::kCOMMA); | 2902 } while (CurrentToken() == Token::kCOMMA); |
| 2895 return NewArray<Type>(interfaces); | 2903 return NewArray<AbstractType>(interfaces); |
| 2896 } | 2904 } |
| 2897 | 2905 |
| 2898 | 2906 |
| 2899 void Parser::AddInterfaces(intptr_t interfaces_pos, | 2907 void Parser::AddInterfaces(intptr_t interfaces_pos, |
| 2900 const Class& cls, | 2908 const Class& cls, |
| 2901 const Array& interfaces) { | 2909 const Array& interfaces) { |
| 2902 GrowableArray<Type*> all_interfaces; | 2910 GrowableArray<AbstractType*> all_interfaces; |
| 2903 // First get all the interfaces already implemented by class. | 2911 // First get all the interfaces already implemented by class. |
| 2904 Array& cls_interfaces = Array::Handle(cls.interfaces()); | 2912 Array& cls_interfaces = Array::Handle(cls.interfaces()); |
| 2905 for (intptr_t i = 0; i < cls_interfaces.Length(); i++) { | 2913 for (intptr_t i = 0; i < cls_interfaces.Length(); i++) { |
| 2906 Type& interface = Type::ZoneHandle(); | 2914 AbstractType& interface = AbstractType::ZoneHandle(); |
| 2907 interface ^= cls_interfaces.At(i); | 2915 interface ^= cls_interfaces.At(i); |
| 2908 all_interfaces.Add(&interface); | 2916 all_interfaces.Add(&interface); |
| 2909 } | 2917 } |
| 2910 // Now add the new interfaces. | 2918 // Now add the new interfaces. |
| 2911 Type& conflicting = Type::Handle(); | 2919 AbstractType& conflicting = AbstractType::Handle(); |
| 2912 for (intptr_t i = 0; i < interfaces.Length(); i++) { | 2920 for (intptr_t i = 0; i < interfaces.Length(); i++) { |
| 2913 Type& interface = Type::ZoneHandle(); | 2921 AbstractType& interface = AbstractType::ZoneHandle(); |
| 2914 interface ^= interfaces.At(i); | 2922 interface ^= interfaces.At(i); |
| 2915 if (!ClassFinalizer::AddInterfaceIfUnique(&all_interfaces, | 2923 if (!ClassFinalizer::AddInterfaceIfUnique(&all_interfaces, |
| 2916 &interface, | 2924 &interface, |
| 2917 &conflicting)) { | 2925 &conflicting)) { |
| 2918 ASSERT(!conflicting.IsNull()); | 2926 ASSERT(!conflicting.IsNull()); |
| 2919 ErrorMsg(interfaces_pos, | 2927 ErrorMsg(interfaces_pos, |
| 2920 "interface '%s' conflicts with interface '%s'", | 2928 "interface '%s' conflicts with interface '%s'", |
| 2921 String::Handle(interface.Name()).ToCString(), | 2929 String::Handle(interface.Name()).ToCString(), |
| 2922 String::Handle(conflicting.Name()).ToCString()); | 2930 String::Handle(conflicting.Name()).ToCString()); |
| 2923 } | 2931 } |
| 2924 } | 2932 } |
| 2925 cls_interfaces = NewArray<Type>(all_interfaces); | 2933 cls_interfaces = NewArray<AbstractType>(all_interfaces); |
| 2926 cls.set_interfaces(cls_interfaces); | 2934 cls.set_interfaces(cls_interfaces); |
| 2927 } | 2935 } |
| 2928 | 2936 |
| 2929 | 2937 |
| 2930 void Parser::ParseTopLevelVariable(TopLevel* top_level) { | 2938 void Parser::ParseTopLevelVariable(TopLevel* top_level) { |
| 2931 const bool is_final = (CurrentToken() == Token::kFINAL); | 2939 const bool is_final = (CurrentToken() == Token::kFINAL); |
| 2932 const bool is_static = true; | 2940 const bool is_static = true; |
| 2933 const Type& type = Type::ZoneHandle( | 2941 const AbstractType& type = AbstractType::ZoneHandle( |
| 2934 ParseFinalVarOrType(kIsMandatory, kCanResolve)); | 2942 ParseFinalVarOrType(kIsMandatory, kCanResolve)); |
| 2935 | 2943 |
| 2936 while (true) { | 2944 while (true) { |
| 2937 const intptr_t name_pos = token_index_; | 2945 const intptr_t name_pos = token_index_; |
| 2938 String& var_name = *ExpectIdentifier("variable name expected"); | 2946 String& var_name = *ExpectIdentifier("variable name expected"); |
| 2939 | 2947 |
| 2940 if (library_.LookupObject(var_name) != Object::null()) { | 2948 if (library_.LookupObject(var_name) != Object::null()) { |
| 2941 ErrorMsg(name_pos, "'%s' is already defined", var_name.ToCString()); | 2949 ErrorMsg(name_pos, "'%s' is already defined", var_name.ToCString()); |
| 2942 } | 2950 } |
| 2943 String& accessor_name = String::Handle(Field::GetterName(var_name)); | 2951 String& accessor_name = String::Handle(Field::GetterName(var_name)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2978 ConsumeToken(); | 2986 ConsumeToken(); |
| 2979 break; | 2987 break; |
| 2980 } else { | 2988 } else { |
| 2981 ExpectSemicolon(); // Reports error. | 2989 ExpectSemicolon(); // Reports error. |
| 2982 } | 2990 } |
| 2983 } | 2991 } |
| 2984 } | 2992 } |
| 2985 | 2993 |
| 2986 | 2994 |
| 2987 void Parser::ParseTopLevelFunction(TopLevel* top_level) { | 2995 void Parser::ParseTopLevelFunction(TopLevel* top_level) { |
| 2988 Type& result_type = Type::Handle(Type::DynamicType()); | 2996 AbstractType& result_type = Type::Handle(Type::DynamicType()); |
| 2989 const bool is_static = true; | 2997 const bool is_static = true; |
| 2990 if (CurrentToken() == Token::kVOID) { | 2998 if (CurrentToken() == Token::kVOID) { |
| 2991 ConsumeToken(); | 2999 ConsumeToken(); |
| 2992 result_type = Type::VoidType(); | 3000 result_type = Type::VoidType(); |
| 2993 } else { | 3001 } else { |
| 2994 // Parse optional type. | 3002 // Parse optional type. |
| 2995 if ((CurrentToken() == Token::kIDENT) && | 3003 if ((CurrentToken() == Token::kIDENT) && |
| 2996 (LookaheadToken(1) != Token::kLPAREN)) { | 3004 (LookaheadToken(1) != Token::kLPAREN)) { |
| 2997 result_type = ParseType(kCanResolve); | 3005 result_type = ParseType(kCanResolve); |
| 2998 } | 3006 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3038 is_static, false, function_pos)); | 3046 is_static, false, function_pos)); |
| 3039 func.set_result_type(result_type); | 3047 func.set_result_type(result_type); |
| 3040 AddFormalParamsToFunction(¶ms, func); | 3048 AddFormalParamsToFunction(¶ms, func); |
| 3041 top_level->functions.Add(&func); | 3049 top_level->functions.Add(&func); |
| 3042 library_.AddObject(func, func_name); | 3050 library_.AddObject(func, func_name); |
| 3043 } | 3051 } |
| 3044 | 3052 |
| 3045 | 3053 |
| 3046 void Parser::ParseTopLevelAccessor(TopLevel* top_level) { | 3054 void Parser::ParseTopLevelAccessor(TopLevel* top_level) { |
| 3047 const bool is_static = true; | 3055 const bool is_static = true; |
| 3048 Type& result_type = Type::Handle(); | 3056 AbstractType& result_type = AbstractType::Handle(); |
| 3049 bool is_getter = (CurrentToken() == Token::kGET); | 3057 bool is_getter = (CurrentToken() == Token::kGET); |
| 3050 if (CurrentToken() == Token::kGET || | 3058 if (CurrentToken() == Token::kGET || |
| 3051 CurrentToken() == Token::kSET) { | 3059 CurrentToken() == Token::kSET) { |
| 3052 ConsumeToken(); | 3060 ConsumeToken(); |
| 3053 result_type = Type::DynamicType(); | 3061 result_type = Type::DynamicType(); |
| 3054 } else { | 3062 } else { |
| 3055 if (CurrentToken() == Token::kVOID) { | 3063 if (CurrentToken() == Token::kVOID) { |
| 3056 ConsumeToken(); | 3064 ConsumeToken(); |
| 3057 result_type = Type::VoidType(); | 3065 result_type = Type::VoidType(); |
| 3058 } else { | 3066 } else { |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3498 | 3506 |
| 3499 | 3507 |
| 3500 AstNode* Parser::CallGetter(intptr_t token_index, | 3508 AstNode* Parser::CallGetter(intptr_t token_index, |
| 3501 AstNode* object, | 3509 AstNode* object, |
| 3502 const String& name) { | 3510 const String& name) { |
| 3503 return new InstanceGetterNode(token_index_, object, name); | 3511 return new InstanceGetterNode(token_index_, object, name); |
| 3504 } | 3512 } |
| 3505 | 3513 |
| 3506 | 3514 |
| 3507 // Returns ast nodes of the variable initialization. | 3515 // Returns ast nodes of the variable initialization. |
| 3508 AstNode* Parser::ParseVariableDeclaration(const Type& type, bool is_final) { | 3516 AstNode* Parser::ParseVariableDeclaration( |
| 3517 const AbstractType& type, bool is_final) { |
| 3509 TRACE_PARSER("ParseVariableDeclaration"); | 3518 TRACE_PARSER("ParseVariableDeclaration"); |
| 3510 ASSERT(CurrentToken() == Token::kIDENT); | 3519 ASSERT(CurrentToken() == Token::kIDENT); |
| 3511 const intptr_t ident_pos = token_index_; | 3520 const intptr_t ident_pos = token_index_; |
| 3512 LocalVariable* variable = | 3521 LocalVariable* variable = |
| 3513 new LocalVariable(ident_pos, *CurrentLiteral(), type); | 3522 new LocalVariable(ident_pos, *CurrentLiteral(), type); |
| 3514 ASSERT(current_block_ != NULL); | 3523 ASSERT(current_block_ != NULL); |
| 3515 ASSERT(current_block_->scope != NULL); | 3524 ASSERT(current_block_->scope != NULL); |
| 3516 ConsumeToken(); // Variable identifier. | 3525 ConsumeToken(); // Variable identifier. |
| 3517 AstNode* initialization = NULL; | 3526 AstNode* initialization = NULL; |
| 3518 if (CurrentToken() == Token::kASSIGN) { | 3527 if (CurrentToken() == Token::kASSIGN) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3539 } | 3548 } |
| 3540 return initialization; | 3549 return initialization; |
| 3541 } | 3550 } |
| 3542 | 3551 |
| 3543 | 3552 |
| 3544 // Parses ('var' | 'final' [type] | type). | 3553 // Parses ('var' | 'final' [type] | type). |
| 3545 // The presence of 'final' must be detected and remembered before the call. | 3554 // The presence of 'final' must be detected and remembered before the call. |
| 3546 // If type_specification is kIsOptional, and no type can be parsed, then return | 3555 // If type_specification is kIsOptional, and no type can be parsed, then return |
| 3547 // the DynamicType. | 3556 // the DynamicType. |
| 3548 // If a type is parsed, it is resolved (or not) according to type_resolution. | 3557 // If a type is parsed, it is resolved (or not) according to type_resolution. |
| 3549 RawType* Parser::ParseFinalVarOrType(TypeSpecification type_specification, | 3558 RawAbstractType* Parser::ParseFinalVarOrType( |
| 3550 TypeResolution type_resolution) { | 3559 TypeSpecification type_specification, TypeResolution type_resolution) { |
| 3551 if (CurrentToken() == Token::kVAR) { | 3560 if (CurrentToken() == Token::kVAR) { |
| 3552 ConsumeToken(); | 3561 ConsumeToken(); |
| 3553 return Type::DynamicType(); | 3562 return Type::DynamicType(); |
| 3554 } | 3563 } |
| 3555 if (CurrentToken() == Token::kFINAL) { | 3564 if (CurrentToken() == Token::kFINAL) { |
| 3556 ConsumeToken(); | 3565 ConsumeToken(); |
| 3557 type_specification = kIsOptional; | 3566 type_specification = kIsOptional; |
| 3558 } | 3567 } |
| 3559 if (CurrentToken() != Token::kIDENT) { | 3568 if (CurrentToken() != Token::kIDENT) { |
| 3560 if (type_specification == kIsOptional) { | 3569 if (type_specification == kIsOptional) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3577 return ParseType(type_resolution); | 3586 return ParseType(type_resolution); |
| 3578 } | 3587 } |
| 3579 | 3588 |
| 3580 | 3589 |
| 3581 // Returns ast nodes of the variable initialization, or NULL if variables | 3590 // Returns ast nodes of the variable initialization, or NULL if variables |
| 3582 // are not initialized. If several variables are declared and initialized, | 3591 // are not initialized. If several variables are declared and initialized, |
| 3583 // the individual initializers are collected in a sequence node. | 3592 // the individual initializers are collected in a sequence node. |
| 3584 AstNode* Parser::ParseVariableDeclarationList() { | 3593 AstNode* Parser::ParseVariableDeclarationList() { |
| 3585 TRACE_PARSER("ParseVariableDeclarationList"); | 3594 TRACE_PARSER("ParseVariableDeclarationList"); |
| 3586 bool is_final = (CurrentToken() == Token::kFINAL); | 3595 bool is_final = (CurrentToken() == Token::kFINAL); |
| 3587 const Type& type = Type::ZoneHandle( | 3596 const AbstractType& type = AbstractType::ZoneHandle( |
| 3588 ParseFinalVarOrType(kIsMandatory, kMustResolve)); | 3597 ParseFinalVarOrType(kIsMandatory, kMustResolve)); |
| 3589 if (CurrentToken() != Token::kIDENT) { | 3598 if (CurrentToken() != Token::kIDENT) { |
| 3590 ErrorMsg("identifier expected"); | 3599 ErrorMsg("identifier expected"); |
| 3591 } | 3600 } |
| 3592 | 3601 |
| 3593 AstNode* initializers = ParseVariableDeclaration(type, is_final); | 3602 AstNode* initializers = ParseVariableDeclaration(type, is_final); |
| 3594 while (CurrentToken() == Token::kCOMMA) { | 3603 while (CurrentToken() == Token::kCOMMA) { |
| 3595 ConsumeToken(); | 3604 ConsumeToken(); |
| 3596 if (CurrentToken() != Token::kIDENT) { | 3605 if (CurrentToken() != Token::kIDENT) { |
| 3597 ErrorMsg("identifier expected after comma"); | 3606 ErrorMsg("identifier expected after comma"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3609 initializers = sequence; | 3618 initializers = sequence; |
| 3610 } | 3619 } |
| 3611 } | 3620 } |
| 3612 } | 3621 } |
| 3613 return initializers; | 3622 return initializers; |
| 3614 } | 3623 } |
| 3615 | 3624 |
| 3616 | 3625 |
| 3617 AstNode* Parser::ParseFunctionStatement(bool is_literal) { | 3626 AstNode* Parser::ParseFunctionStatement(bool is_literal) { |
| 3618 TRACE_PARSER("ParseFunctionStatement"); | 3627 TRACE_PARSER("ParseFunctionStatement"); |
| 3619 Type& result_type = Type::Handle(); | 3628 AbstractType& result_type = AbstractType::Handle(); |
| 3620 const String* variable_name = NULL; | 3629 const String* variable_name = NULL; |
| 3621 const String* function_name = NULL; | 3630 const String* function_name = NULL; |
| 3622 | 3631 |
| 3623 result_type = Type::DynamicType(); | 3632 result_type = Type::DynamicType(); |
| 3624 if (CurrentToken() == Token::kVOID) { | 3633 if (CurrentToken() == Token::kVOID) { |
| 3625 ConsumeToken(); | 3634 ConsumeToken(); |
| 3626 result_type = Type::VoidType(); | 3635 result_type = Type::VoidType(); |
| 3627 } else if ((CurrentToken() == Token::kIDENT) && | 3636 } else if ((CurrentToken() == Token::kIDENT) && |
| 3628 (LookaheadToken(1) != Token::kLPAREN)) { | 3637 (LookaheadToken(1) != Token::kLPAREN)) { |
| 3629 result_type = ParseType(kMustResolve); | 3638 result_type = ParseType(kMustResolve); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3651 current_function(), | 3660 current_function(), |
| 3652 token_index_)); | 3661 token_index_)); |
| 3653 function.set_result_type(result_type); | 3662 function.set_result_type(result_type); |
| 3654 | 3663 |
| 3655 // The function type does not need to be determined at compile time, unless | 3664 // The function type does not need to be determined at compile time, unless |
| 3656 // the closure is assigned to a function variable and type checks are enabled. | 3665 // the closure is assigned to a function variable and type checks are enabled. |
| 3657 // At run time, the function type is derived from the signature class of the | 3666 // At run time, the function type is derived from the signature class of the |
| 3658 // closure function and from the type arguments of the instantiator. | 3667 // closure function and from the type arguments of the instantiator. |
| 3659 | 3668 |
| 3660 LocalVariable* function_variable = NULL; | 3669 LocalVariable* function_variable = NULL; |
| 3661 ParameterizedType& function_type = ParameterizedType::ZoneHandle(); | 3670 Type& function_type = Type::ZoneHandle(); |
| 3662 if (variable_name != NULL) { | 3671 if (variable_name != NULL) { |
| 3663 // Since the function type depends on the signature of the closure function, | 3672 // Since the function type depends on the signature of the closure function, |
| 3664 // it cannot be determined before the formal parameter list of the closure | 3673 // it cannot be determined before the formal parameter list of the closure |
| 3665 // function is parsed. Therefore, we set the function type to a new | 3674 // function is parsed. Therefore, we set the function type to a new |
| 3666 // parameterized type to be patched after the actual type is known. | 3675 // parameterized type to be patched after the actual type is known. |
| 3667 // We temporarily use the class of the Function interface. | 3676 // We temporarily use the class of the Function interface. |
| 3668 const Class& unknown_signature_class = Class::Handle( | 3677 const Class& unknown_signature_class = Class::Handle( |
| 3669 Type::Handle(Type::FunctionInterface()).type_class()); | 3678 Type::Handle(Type::FunctionInterface()).type_class()); |
| 3670 function_type = ParameterizedType::New(unknown_signature_class, | 3679 function_type = Type::New(unknown_signature_class, |
| 3671 TypeArguments::Handle()); | 3680 TypeArguments::Handle()); |
| 3672 function_type.set_is_finalized(); // No real finalization needed. | 3681 function_type.set_is_finalized(); // No real finalization needed. |
| 3673 | 3682 |
| 3674 // Add the function variable to the scope before parsing the function in | 3683 // Add the function variable to the scope before parsing the function in |
| 3675 // order to allow self reference from inside the function. | 3684 // order to allow self reference from inside the function. |
| 3676 function_variable = new LocalVariable(ident_pos, | 3685 function_variable = new LocalVariable(ident_pos, |
| 3677 *variable_name, | 3686 *variable_name, |
| 3678 function_type); | 3687 function_type); |
| 3679 function_variable->set_is_final(); | 3688 function_variable->set_is_final(); |
| 3680 ASSERT(current_block_ != NULL); | 3689 ASSERT(current_block_ != NULL); |
| 3681 ASSERT(current_block_->scope != NULL); | 3690 ASSERT(current_block_->scope != NULL); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3713 // Make sure that the instantiator is captured. | 3722 // Make sure that the instantiator is captured. |
| 3714 if ((signature_class.NumTypeParameters() > 0) && | 3723 if ((signature_class.NumTypeParameters() > 0) && |
| 3715 (current_block_->scope->function_level() > 0)) { | 3724 (current_block_->scope->function_level() > 0)) { |
| 3716 CaptureReceiver(); | 3725 CaptureReceiver(); |
| 3717 } | 3726 } |
| 3718 | 3727 |
| 3719 if (variable_name != NULL) { | 3728 if (variable_name != NULL) { |
| 3720 // Patch the function type now that the signature is known. | 3729 // Patch the function type now that the signature is known. |
| 3721 // We need to create a new type for proper finalization, since the existing | 3730 // We need to create a new type for proper finalization, since the existing |
| 3722 // type is already marked as finalized. | 3731 // type is already marked as finalized. |
| 3723 Type& signature_type = Type::Handle(signature_class.SignatureType()); | 3732 AbstractType& signature_type = |
| 3733 AbstractType::Handle(signature_class.SignatureType()); |
| 3724 const TypeArguments& signature_type_arguments = TypeArguments::Handle( | 3734 const TypeArguments& signature_type_arguments = TypeArguments::Handle( |
| 3725 signature_type.arguments()); | 3735 signature_type.arguments()); |
| 3726 | 3736 |
| 3727 // Since the signature type is cached by the signature class, it may have | 3737 // Since the signature type is cached by the signature class, it may have |
| 3728 // been finalized already. | 3738 // been finalized already. |
| 3729 if (!signature_type.IsFinalized()) { | 3739 if (!signature_type.IsFinalized()) { |
| 3730 String& errmsg = String::Handle(); | 3740 String& errmsg = String::Handle(); |
| 3731 signature_type = | 3741 signature_type = |
| 3732 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg); | 3742 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg); |
| 3733 if (!errmsg.IsNull()) { | 3743 if (!errmsg.IsNull()) { |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4272 SourceLabel* label) { | 4282 SourceLabel* label) { |
| 4273 bool is_final = (CurrentToken() == Token::kFINAL); | 4283 bool is_final = (CurrentToken() == Token::kFINAL); |
| 4274 const String* loop_var_name = NULL; | 4284 const String* loop_var_name = NULL; |
| 4275 LocalVariable* loop_var = NULL; | 4285 LocalVariable* loop_var = NULL; |
| 4276 intptr_t loop_var_pos = 0; | 4286 intptr_t loop_var_pos = 0; |
| 4277 if (LookaheadToken(1) == Token::kIN) { | 4287 if (LookaheadToken(1) == Token::kIN) { |
| 4278 loop_var_pos = token_index_; | 4288 loop_var_pos = token_index_; |
| 4279 loop_var_name = ExpectIdentifier("variable name expected"); | 4289 loop_var_name = ExpectIdentifier("variable name expected"); |
| 4280 } else { | 4290 } else { |
| 4281 // The case without a type is handled above, so require a type here. | 4291 // The case without a type is handled above, so require a type here. |
| 4282 const Type& type = Type::ZoneHandle( | 4292 const AbstractType& type = AbstractType::ZoneHandle( |
| 4283 ParseFinalVarOrType(kIsMandatory, kMustResolve)); | 4293 ParseFinalVarOrType(kIsMandatory, kMustResolve)); |
| 4284 loop_var_pos = token_index_; | 4294 loop_var_pos = token_index_; |
| 4285 loop_var_name = ExpectIdentifier("variable name expected"); | 4295 loop_var_name = ExpectIdentifier("variable name expected"); |
| 4286 loop_var = new LocalVariable(loop_var_pos, *loop_var_name, type); | 4296 loop_var = new LocalVariable(loop_var_pos, *loop_var_name, type); |
| 4287 if (is_final) { | 4297 if (is_final) { |
| 4288 loop_var->set_is_final(); | 4298 loop_var->set_is_final(); |
| 4289 } | 4299 } |
| 4290 } | 4300 } |
| 4291 ExpectToken(Token::kIN); | 4301 ExpectToken(Token::kIN); |
| 4292 const intptr_t collection_pos = token_index_; | 4302 const intptr_t collection_pos = token_index_; |
| 4293 AstNode* collection_expr = ParseExpr(kAllowConst); | 4303 AstNode* collection_expr = ParseExpr(kAllowConst); |
| 4294 ExpectToken(Token::kRPAREN); | 4304 ExpectToken(Token::kRPAREN); |
| 4295 | 4305 |
| 4296 OpenBlock(); // Implicit block around while loop. | 4306 OpenBlock(); // Implicit block around while loop. |
| 4297 | 4307 |
| 4298 // Generate implicit iterator variable and add to scope. | 4308 // Generate implicit iterator variable and add to scope. |
| 4299 const String& iterator_name = | 4309 const String& iterator_name = |
| 4300 String::ZoneHandle(String::NewSymbol(":for-in-iter")); | 4310 String::ZoneHandle(String::NewSymbol(":for-in-iter")); |
| 4301 // We could set the type of the implicit iterator variable to Iterator<T> | 4311 // We could set the type of the implicit iterator variable to Iterator<T> |
| 4302 // where T is the type of the for loop variable. However, the type error | 4312 // where T is the type of the for loop variable. However, the type error |
| 4303 // would refer to the compiler generated iterator and could confuse the user. | 4313 // would refer to the compiler generated iterator and could confuse the user. |
| 4304 // It is better to leave the iterator untyped and postpone the type error | 4314 // It is better to leave the iterator untyped and postpone the type error |
| 4305 // until the loop variable is assigned to. | 4315 // until the loop variable is assigned to. |
| 4306 const Type& iterator_type = Type::ZoneHandle(Type::DynamicType()); | 4316 const AbstractType& iterator_type = Type::ZoneHandle(Type::DynamicType()); |
| 4307 LocalVariable* iterator_var = | 4317 LocalVariable* iterator_var = |
| 4308 new LocalVariable(collection_pos, iterator_name, iterator_type); | 4318 new LocalVariable(collection_pos, iterator_name, iterator_type); |
| 4309 current_block_->scope->AddVariable(iterator_var); | 4319 current_block_->scope->AddVariable(iterator_var); |
| 4310 | 4320 |
| 4311 // Generate initialization of iterator variable. | 4321 // Generate initialization of iterator variable. |
| 4312 const String& iterator_method_name = | 4322 const String& iterator_method_name = |
| 4313 String::ZoneHandle(String::NewSymbol(kGetIteratorName)); | 4323 String::ZoneHandle(String::NewSymbol(kGetIteratorName)); |
| 4314 ArgumentListNode* no_args = new ArgumentListNode(collection_pos); | 4324 ArgumentListNode* no_args = new ArgumentListNode(collection_pos); |
| 4315 AstNode* get_iterator = new InstanceCallNode( | 4325 AstNode* get_iterator = new InstanceCallNode( |
| 4316 collection_pos, collection_expr, iterator_method_name, no_args); | 4326 collection_pos, collection_expr, iterator_method_name, no_args); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4524 assert_throw, | 4534 assert_throw, |
| 4525 current_block_->scope), | 4535 current_block_->scope), |
| 4526 NULL); | 4536 NULL); |
| 4527 } | 4537 } |
| 4528 | 4538 |
| 4529 | 4539 |
| 4530 struct CatchParamDesc { | 4540 struct CatchParamDesc { |
| 4531 CatchParamDesc() | 4541 CatchParamDesc() |
| 4532 : token_index(0), type(NULL), var(NULL), is_final(false) { } | 4542 : token_index(0), type(NULL), var(NULL), is_final(false) { } |
| 4533 intptr_t token_index; | 4543 intptr_t token_index; |
| 4534 const Type* type; | 4544 const AbstractType* type; |
| 4535 const String* var; | 4545 const String* var; |
| 4536 bool is_final; | 4546 bool is_final; |
| 4537 }; | 4547 }; |
| 4538 | 4548 |
| 4539 | 4549 |
| 4540 // Parse the parameter specified in the catch clause. | 4550 // Parse the parameter specified in the catch clause. |
| 4541 void Parser::ParseCatchParameter(CatchParamDesc* catch_param) { | 4551 void Parser::ParseCatchParameter(CatchParamDesc* catch_param) { |
| 4542 TRACE_PARSER("ParseCatchParameter"); | 4552 TRACE_PARSER("ParseCatchParameter"); |
| 4543 ASSERT(catch_param != NULL); | 4553 ASSERT(catch_param != NULL); |
| 4544 catch_param->is_final = (CurrentToken() == Token::kFINAL); | 4554 catch_param->is_final = (CurrentToken() == Token::kFINAL); |
| 4545 catch_param->type = &Type::ZoneHandle( | 4555 catch_param->type = &AbstractType::ZoneHandle( |
| 4546 ParseFinalVarOrType(kIsMandatory, kMustResolve)); | 4556 ParseFinalVarOrType(kIsMandatory, kMustResolve)); |
| 4547 if (CurrentToken() != Token::kIDENT) { | 4557 if (CurrentToken() != Token::kIDENT) { |
| 4548 ErrorMsg("identifier expected"); | 4558 ErrorMsg("identifier expected"); |
| 4549 } | 4559 } |
| 4550 catch_param->token_index = token_index_; | 4560 catch_param->token_index = token_index_; |
| 4551 catch_param->var = CurrentLiteral(); | 4561 catch_param->var = CurrentLiteral(); |
| 4552 ConsumeToken(); | 4562 ConsumeToken(); |
| 4553 } | 4563 } |
| 4554 | 4564 |
| 4555 | 4565 |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5266 AstNode* right_operand = NULL; | 5276 AstNode* right_operand = NULL; |
| 5267 if (op_kind != Token::kIS) { | 5277 if (op_kind != Token::kIS) { |
| 5268 right_operand = ParseBinaryExpr(current_preced + 1); | 5278 right_operand = ParseBinaryExpr(current_preced + 1); |
| 5269 } else { | 5279 } else { |
| 5270 // For 'is' we expect the right operand to be a type. | 5280 // For 'is' we expect the right operand to be a type. |
| 5271 if (CurrentToken() == Token::kNOT) { | 5281 if (CurrentToken() == Token::kNOT) { |
| 5272 ConsumeToken(); | 5282 ConsumeToken(); |
| 5273 op_kind = Token::kISNOT; | 5283 op_kind = Token::kISNOT; |
| 5274 } | 5284 } |
| 5275 const intptr_t type_pos = token_index_; | 5285 const intptr_t type_pos = token_index_; |
| 5276 const Type& type = Type::ZoneHandle(ParseType(kMustResolve)); | 5286 const AbstractType& type = |
| 5287 AbstractType::ZoneHandle(ParseType(kMustResolve)); |
| 5277 if (!type.IsInstantiated() && | 5288 if (!type.IsInstantiated() && |
| 5278 (current_block_->scope->function_level() > 0)) { | 5289 (current_block_->scope->function_level() > 0)) { |
| 5279 // Make sure that the instantiator is captured. | 5290 // Make sure that the instantiator is captured. |
| 5280 CaptureReceiver(); | 5291 CaptureReceiver(); |
| 5281 } | 5292 } |
| 5282 right_operand = new TypeNode(type_pos, type); | 5293 right_operand = new TypeNode(type_pos, type); |
| 5283 } | 5294 } |
| 5284 if (Token::IsRelationalOperator(op_kind) | 5295 if (Token::IsRelationalOperator(op_kind) |
| 5285 || Token::IsInstanceofOperator(op_kind) | 5296 || Token::IsInstanceofOperator(op_kind) |
| 5286 || Token::IsEqualityOperator(op_kind)) { | 5297 || Token::IsEqualityOperator(op_kind)) { |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6018 return postfix_expr; | 6029 return postfix_expr; |
| 6019 } | 6030 } |
| 6020 | 6031 |
| 6021 | 6032 |
| 6022 // Try to resolve the given type and its type arguments from the given class. | 6033 // Try to resolve the given type and its type arguments from the given class. |
| 6023 // Not all involved type classes may get resolved yet, but at least the type | 6034 // Not all involved type classes may get resolved yet, but at least the type |
| 6024 // parameters of the given class will get resolved, thereby relieving the class | 6035 // parameters of the given class will get resolved, thereby relieving the class |
| 6025 // finalizer from resolving type parameters out of context. | 6036 // finalizer from resolving type parameters out of context. |
| 6026 void Parser::TryResolveTypeFromClass(intptr_t type_pos, | 6037 void Parser::TryResolveTypeFromClass(intptr_t type_pos, |
| 6027 const Class& cls, | 6038 const Class& cls, |
| 6028 Type* type) { | 6039 AbstractType* type) { |
| 6029 ASSERT(type != NULL); | 6040 ASSERT(type != NULL); |
| 6030 // Resolve class. | 6041 // Resolve class. |
| 6031 if (!type->HasResolvedTypeClass()) { | 6042 if (!type->HasResolvedTypeClass()) { |
| 6032 const UnresolvedClass& unresolved_class = | 6043 const UnresolvedClass& unresolved_class = |
| 6033 UnresolvedClass::Handle(type->unresolved_class()); | 6044 UnresolvedClass::Handle(type->unresolved_class()); |
| 6034 const String& unresolved_class_name = | 6045 const String& unresolved_class_name = |
| 6035 String::Handle(unresolved_class.ident()); | 6046 String::Handle(unresolved_class.ident()); |
| 6036 // First check if the type is a type parameter of the given class. | 6047 // First check if the type is a type parameter of the given class. |
| 6037 const TypeParameter& type_parameter = TypeParameter::Handle( | 6048 const TypeParameter& type_parameter = TypeParameter::Handle( |
| 6038 cls.LookupTypeParameter(unresolved_class_name)); | 6049 cls.LookupTypeParameter(unresolved_class_name)); |
| 6039 if (!type_parameter.IsNull()) { | 6050 if (!type_parameter.IsNull()) { |
| 6040 // A type parameter cannot be parameterized, so report an error if type | 6051 // A type parameter cannot be parameterized, so report an error if type |
| 6041 // arguments have previously been parsed. | 6052 // arguments have previously been parsed. |
| 6042 if (!TypeArguments::Handle(type->arguments()).IsNull()) { | 6053 if (!TypeArguments::Handle(type->arguments()).IsNull()) { |
| 6043 ErrorMsg(type_pos, "type parameter '%s' cannot be parameterized", | 6054 ErrorMsg(type_pos, "type parameter '%s' cannot be parameterized", |
| 6044 type_parameter.ToCString()); | 6055 type_parameter.ToCString()); |
| 6045 } | 6056 } |
| 6046 *type = type_parameter.raw(); | 6057 *type = type_parameter.raw(); |
| 6047 return; | 6058 return; |
| 6048 } | 6059 } |
| 6049 const Class& resolved_type_class = | 6060 const Class& resolved_type_class = |
| 6050 Class::Handle(LookupClass(unresolved_class_name)); | 6061 Class::Handle(LookupClass(unresolved_class_name)); |
| 6051 if (!resolved_type_class.IsNull()) { | 6062 if (!resolved_type_class.IsNull()) { |
| 6052 Object& type_class = Object::Handle(resolved_type_class.raw()); | 6063 Object& type_class = Object::Handle(resolved_type_class.raw()); |
| 6053 ASSERT(type->IsParameterizedType()); | 6064 ASSERT(type->IsType()); |
| 6054 // Replace unresolved class with resolved type class. | 6065 // Replace unresolved class with resolved type class. |
| 6055 ParameterizedType& parameterized_type = ParameterizedType::Handle(); | 6066 Type& parameterized_type = Type::Handle(); |
| 6056 parameterized_type ^= type->raw(); | 6067 parameterized_type ^= type->raw(); |
| 6057 parameterized_type.set_type_class(type_class); | 6068 parameterized_type.set_type_class(type_class); |
| 6058 } | 6069 } |
| 6059 } | 6070 } |
| 6060 // Resolve type arguments, if any. | 6071 // Resolve type arguments, if any. |
| 6061 const TypeArguments& arguments = TypeArguments::Handle(type->arguments()); | 6072 const TypeArguments& arguments = TypeArguments::Handle(type->arguments()); |
| 6062 if (!arguments.IsNull()) { | 6073 if (!arguments.IsNull()) { |
| 6063 const intptr_t num_arguments = arguments.Length(); | 6074 const intptr_t num_arguments = arguments.Length(); |
| 6064 for (intptr_t i = 0; i < num_arguments; i++) { | 6075 for (intptr_t i = 0; i < num_arguments; i++) { |
| 6065 Type& type_argument = Type::Handle(arguments.TypeAt(i)); | 6076 AbstractType& type_argument = AbstractType::Handle(arguments.TypeAt(i)); |
| 6066 TryResolveTypeFromClass(type_pos, cls, &type_argument); | 6077 TryResolveTypeFromClass(type_pos, cls, &type_argument); |
| 6067 arguments.SetTypeAt(i, type_argument); | 6078 arguments.SetTypeAt(i, type_argument); |
| 6068 } | 6079 } |
| 6069 } | 6080 } |
| 6070 } | 6081 } |
| 6071 | 6082 |
| 6072 | 6083 |
| 6073 // Return class for type name. If the name cannot be resolved (yet), give an | 6084 // Return class for type name. If the name cannot be resolved (yet), give an |
| 6074 // error (if type_resolution == kMustResolve) or return the unresolved name. | 6085 // error (if type_resolution == kMustResolve) or return the unresolved name. |
| 6075 RawObject* Parser::LookupTypeClass(const QualIdent& type_name, | 6086 RawObject* Parser::LookupTypeClass(const QualIdent& type_name, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6126 | 6137 |
| 6127 | 6138 |
| 6128 // If type parameters are currently in scope, return their declaring class, | 6139 // If type parameters are currently in scope, return their declaring class, |
| 6129 // otherwise return null. | 6140 // otherwise return null. |
| 6130 RawClass* Parser::TypeParametersScopeClass() { | 6141 RawClass* Parser::TypeParametersScopeClass() { |
| 6131 // Type parameters cannot be referred to from a static function, except from | 6142 // Type parameters cannot be referred to from a static function, except from |
| 6132 // a constructor or from a factory. | 6143 // a constructor or from a factory. |
| 6133 // A constructor is considered as non-static by the compiler. | 6144 // A constructor is considered as non-static by the compiler. |
| 6134 if (is_top_level_) { | 6145 if (is_top_level_) { |
| 6135 if ((current_member_ != NULL) && current_member_->has_factory) { | 6146 if ((current_member_ != NULL) && current_member_->has_factory) { |
| 6136 const Type& factory_result_type = *current_member_->type; | 6147 const AbstractType& factory_result_type = *current_member_->type; |
| 6137 ASSERT(!factory_result_type.IsNull()); | 6148 ASSERT(!factory_result_type.IsNull()); |
| 6138 const UnresolvedClass& unresolved_factory_class = | 6149 const UnresolvedClass& unresolved_factory_class = |
| 6139 UnresolvedClass::Handle(factory_result_type.unresolved_class()); | 6150 UnresolvedClass::Handle(factory_result_type.unresolved_class()); |
| 6140 // TODO(regis): For now, and until the core lib is fixed, we accept a | 6151 // TODO(regis): For now, and until the core lib is fixed, we accept a |
| 6141 // factory method with missing list of type parameters and use the | 6152 // factory method with missing list of type parameters and use the |
| 6142 // list of the enclosing class. | 6153 // list of the enclosing class. |
| 6143 // See bug 5408808. | 6154 // See bug 5408808. |
| 6144 // Therefore, we temporarily return the current class instead of the | 6155 // Therefore, we temporarily return the current class instead of the |
| 6145 // factory signature class if the latter one does not declare any type | 6156 // factory signature class if the latter one does not declare any type |
| 6146 // parameters. | 6157 // parameters. |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6318 return true; | 6329 return true; |
| 6319 } | 6330 } |
| 6320 | 6331 |
| 6321 // Now check if a getter/setter method exists for it in which case | 6332 // Now check if a getter/setter method exists for it in which case |
| 6322 // it is still a field. | 6333 // it is still a field. |
| 6323 const String& getter_name = String::Handle(Field::GetterName(ident)); | 6334 const String& getter_name = String::Handle(Field::GetterName(ident)); |
| 6324 func = cls.LookupDynamicFunction(getter_name); | 6335 func = cls.LookupDynamicFunction(getter_name); |
| 6325 if (!func.IsNull()) { | 6336 if (!func.IsNull()) { |
| 6326 if (node != NULL) { | 6337 if (node != NULL) { |
| 6327 CheckInstanceFieldAccess(ident_pos, ident); | 6338 CheckInstanceFieldAccess(ident_pos, ident); |
| 6328 ASSERT(Type::Handle(func.result_type()).IsResolved()); | 6339 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 6329 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | 6340 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); |
| 6330 } | 6341 } |
| 6331 return true; | 6342 return true; |
| 6332 } | 6343 } |
| 6333 func = cls.LookupStaticFunction(getter_name); | 6344 func = cls.LookupStaticFunction(getter_name); |
| 6334 if (!func.IsNull()) { | 6345 if (!func.IsNull()) { |
| 6335 if (node != NULL) { | 6346 if (node != NULL) { |
| 6336 ASSERT(Type::Handle(func.result_type()).IsResolved()); | 6347 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 6337 *node = new StaticGetterNode(ident_pos, | 6348 *node = new StaticGetterNode(ident_pos, |
| 6338 Class::ZoneHandle(cls.raw()), | 6349 Class::ZoneHandle(cls.raw()), |
| 6339 ident); | 6350 ident); |
| 6340 } | 6351 } |
| 6341 return true; | 6352 return true; |
| 6342 } | 6353 } |
| 6343 const String& setter_name = String::Handle(Field::SetterName(ident)); | 6354 const String& setter_name = String::Handle(Field::SetterName(ident)); |
| 6344 func = cls.LookupDynamicFunction(setter_name); | 6355 func = cls.LookupDynamicFunction(setter_name); |
| 6345 if (!func.IsNull()) { | 6356 if (!func.IsNull()) { |
| 6346 if (node != NULL) { | 6357 if (node != NULL) { |
| 6347 // We create a getter node even though a getter doesn't exist as | 6358 // We create a getter node even though a getter doesn't exist as |
| 6348 // it could be followed by an assignment which will convert it to | 6359 // it could be followed by an assignment which will convert it to |
| 6349 // a setter node. If there is no assignment we will get an error | 6360 // a setter node. If there is no assignment we will get an error |
| 6350 // when we try to invoke the getter. | 6361 // when we try to invoke the getter. |
| 6351 CheckInstanceFieldAccess(ident_pos, ident); | 6362 CheckInstanceFieldAccess(ident_pos, ident); |
| 6352 ASSERT(Type::Handle(func.result_type()).IsResolved()); | 6363 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 6353 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | 6364 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); |
| 6354 } | 6365 } |
| 6355 return true; | 6366 return true; |
| 6356 } | 6367 } |
| 6357 func = cls.LookupStaticFunction(setter_name); | 6368 func = cls.LookupStaticFunction(setter_name); |
| 6358 if (!func.IsNull()) { | 6369 if (!func.IsNull()) { |
| 6359 if (node != NULL) { | 6370 if (node != NULL) { |
| 6360 // We create a getter node even though a getter doesn't exist as | 6371 // We create a getter node even though a getter doesn't exist as |
| 6361 // it could be followed by an assignment which will convert it to | 6372 // it could be followed by an assignment which will convert it to |
| 6362 // a setter node. If there is no assignment we will get an error | 6373 // a setter node. If there is no assignment we will get an error |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6438 if (resolve_locally) { | 6449 if (resolve_locally) { |
| 6439 obj = lib.LookupLocalObject(accessor_name); | 6450 obj = lib.LookupLocalObject(accessor_name); |
| 6440 } else { | 6451 } else { |
| 6441 obj = lib.LookupObject(accessor_name); | 6452 obj = lib.LookupObject(accessor_name); |
| 6442 } | 6453 } |
| 6443 } | 6454 } |
| 6444 if (!obj.IsNull()) { | 6455 if (!obj.IsNull()) { |
| 6445 ASSERT(obj.IsFunction()); | 6456 ASSERT(obj.IsFunction()); |
| 6446 func ^= obj.raw(); | 6457 func ^= obj.raw(); |
| 6447 ASSERT(func.is_static()); | 6458 ASSERT(func.is_static()); |
| 6448 ASSERT(Type::Handle(func.result_type()).IsResolved()); | 6459 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 6449 return new StaticGetterNode(qual_ident.ident_pos, | 6460 return new StaticGetterNode(qual_ident.ident_pos, |
| 6450 Class::ZoneHandle(func.owner()), | 6461 Class::ZoneHandle(func.owner()), |
| 6451 *qual_ident.ident); | 6462 *qual_ident.ident); |
| 6452 } | 6463 } |
| 6453 if (qual_ident.qualifier != NULL) { | 6464 if (qual_ident.qualifier != NULL) { |
| 6454 // This is an unresolved prefixed primary identifier, need to report | 6465 // This is an unresolved prefixed primary identifier, need to report |
| 6455 // an error. | 6466 // an error. |
| 6456 ErrorMsg(qual_ident.ident_pos, "identifier '%s.%s' cannot be resolved", | 6467 ErrorMsg(qual_ident.ident_pos, "identifier '%s.%s' cannot be resolved", |
| 6457 (qual_ident.qualifier)->ToCString(), | 6468 (qual_ident.qualifier)->ToCString(), |
| 6458 (qual_ident.ident)->ToCString()); | 6469 (qual_ident.ident)->ToCString()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6509 } | 6520 } |
| 6510 } | 6521 } |
| 6511 return var_or_field; | 6522 return var_or_field; |
| 6512 } | 6523 } |
| 6513 | 6524 |
| 6514 | 6525 |
| 6515 // Parses type = [ident "."] ident ["<" type { "," type } ">"]. | 6526 // Parses type = [ident "."] ident ["<" type { "," type } ">"]. |
| 6516 // Returns the class object if the type can be resolved. Otherwise, either give | 6527 // Returns the class object if the type can be resolved. Otherwise, either give |
| 6517 // an error if type resolution was required, or return the unresolved name as a | 6528 // an error if type resolution was required, or return the unresolved name as a |
| 6518 // string object. | 6529 // string object. |
| 6519 RawType* Parser::ParseType(TypeResolution type_resolution) { | 6530 RawAbstractType* Parser::ParseType(TypeResolution type_resolution) { |
| 6520 if (CurrentToken() != Token::kIDENT) { | 6531 if (CurrentToken() != Token::kIDENT) { |
| 6521 ErrorMsg("type name expected"); | 6532 ErrorMsg("type name expected"); |
| 6522 } | 6533 } |
| 6523 QualIdent type_name; | 6534 QualIdent type_name; |
| 6524 const intptr_t type_pos = token_index_; | 6535 const intptr_t type_pos = token_index_; |
| 6525 ParseQualIdent(&type_name); | 6536 ParseQualIdent(&type_name); |
| 6526 if (type_name.is_local_scope_ident) { | 6537 if (type_name.is_local_scope_ident) { |
| 6527 ErrorMsg(type_pos, "using '%s' in this context is invalid", | 6538 ErrorMsg(type_pos, "using '%s' in this context is invalid", |
| 6528 type_name.ident->ToCString()); | 6539 type_name.ident->ToCString()); |
| 6529 } | 6540 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 6556 } | 6567 } |
| 6557 return type_parameter.raw(); | 6568 return type_parameter.raw(); |
| 6558 } | 6569 } |
| 6559 } | 6570 } |
| 6560 } | 6571 } |
| 6561 // Try to resolve the type class. | 6572 // Try to resolve the type class. |
| 6562 type_class = LookupTypeClass(type_name, type_resolution); | 6573 type_class = LookupTypeClass(type_name, type_resolution); |
| 6563 } | 6574 } |
| 6564 TypeArguments& type_arguments = | 6575 TypeArguments& type_arguments = |
| 6565 TypeArguments::Handle(ParseTypeArguments(type_resolution)); | 6576 TypeArguments::Handle(ParseTypeArguments(type_resolution)); |
| 6566 Type& type = Type::Handle( | 6577 AbstractType& type = AbstractType::Handle( |
| 6567 Type::NewParameterizedType(type_class, type_arguments)); | 6578 Type::NewParameterizedType(type_class, type_arguments)); |
| 6568 if (type_resolution == kMustResolve) { | 6579 if (type_resolution == kMustResolve) { |
| 6569 ASSERT(type_class.IsClass()); // Must be resolved. | 6580 ASSERT(type_class.IsClass()); // Must be resolved. |
| 6570 String& errmsg = String::Handle(); | 6581 String& errmsg = String::Handle(); |
| 6571 type = ClassFinalizer::FinalizeAndCanonicalizeType(type, &errmsg); | 6582 type = ClassFinalizer::FinalizeAndCanonicalizeType(type, &errmsg); |
| 6572 if (!errmsg.IsNull()) { | 6583 if (!errmsg.IsNull()) { |
| 6573 ErrorMsg(errmsg.ToCString()); | 6584 ErrorMsg(errmsg.ToCString()); |
| 6574 } | 6585 } |
| 6575 } | 6586 } |
| 6576 return type.raw(); | 6587 return type.raw(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 6604 AstNode* Parser::ParseListLiteral(intptr_t type_pos, | 6615 AstNode* Parser::ParseListLiteral(intptr_t type_pos, |
| 6605 bool is_const, | 6616 bool is_const, |
| 6606 const TypeArguments& type_arguments) { | 6617 const TypeArguments& type_arguments) { |
| 6607 TRACE_PARSER("ParseListLiteral"); | 6618 TRACE_PARSER("ParseListLiteral"); |
| 6608 ASSERT(type_pos >= 0); | 6619 ASSERT(type_pos >= 0); |
| 6609 ASSERT(CurrentToken() == Token::kLBRACK || CurrentToken() == Token::kINDEX); | 6620 ASSERT(CurrentToken() == Token::kLBRACK || CurrentToken() == Token::kINDEX); |
| 6610 const intptr_t literal_pos = token_index_; | 6621 const intptr_t literal_pos = token_index_; |
| 6611 bool is_empty_literal = CurrentToken() == Token::kINDEX; | 6622 bool is_empty_literal = CurrentToken() == Token::kINDEX; |
| 6612 ConsumeToken(); | 6623 ConsumeToken(); |
| 6613 | 6624 |
| 6614 Type& element_type = Type::ZoneHandle(Type::DynamicType()); | 6625 AbstractType& element_type = Type::ZoneHandle(Type::DynamicType()); |
| 6615 // If no type argument vector is provided, leave it as null, which is | 6626 // If no type argument vector is provided, leave it as null, which is |
| 6616 // equivalent to using Dynamic as the type argument for the element type. | 6627 // equivalent to using Dynamic as the type argument for the element type. |
| 6617 if (!type_arguments.IsNull()) { | 6628 if (!type_arguments.IsNull()) { |
| 6618 ASSERT(type_arguments.Length() > 0); | 6629 ASSERT(type_arguments.Length() > 0); |
| 6619 // List literals take a single type argument. | 6630 // List literals take a single type argument. |
| 6620 element_type = type_arguments.TypeAt(0); | 6631 element_type = type_arguments.TypeAt(0); |
| 6621 if (type_arguments.Length() != 1) { | 6632 if (type_arguments.Length() != 1) { |
| 6622 ErrorMsg(type_pos, | 6633 ErrorMsg(type_pos, |
| 6623 "a list literal takes one type argument specifying " | 6634 "a list literal takes one type argument specifying " |
| 6624 "the element type"); | 6635 "the element type"); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6746 | 6757 |
| 6747 AstNode* Parser::ParseMapLiteral(intptr_t type_pos, | 6758 AstNode* Parser::ParseMapLiteral(intptr_t type_pos, |
| 6748 bool is_const, | 6759 bool is_const, |
| 6749 const TypeArguments& type_arguments) { | 6760 const TypeArguments& type_arguments) { |
| 6750 TRACE_PARSER("ParseMapLiteral"); | 6761 TRACE_PARSER("ParseMapLiteral"); |
| 6751 ASSERT(type_pos >= 0); | 6762 ASSERT(type_pos >= 0); |
| 6752 ASSERT(CurrentToken() == Token::kLBRACE); | 6763 ASSERT(CurrentToken() == Token::kLBRACE); |
| 6753 const intptr_t literal_pos = token_index_; | 6764 const intptr_t literal_pos = token_index_; |
| 6754 ConsumeToken(); | 6765 ConsumeToken(); |
| 6755 | 6766 |
| 6756 Type& value_type = Type::ZoneHandle(Type::DynamicType()); | 6767 AbstractType& value_type = Type::ZoneHandle(Type::DynamicType()); |
| 6757 TypeArguments& map_type_arguments = | 6768 TypeArguments& map_type_arguments = |
| 6758 TypeArguments::ZoneHandle(type_arguments.raw()); | 6769 TypeArguments::ZoneHandle(type_arguments.raw()); |
| 6759 // If no type argument vector is provided, leave it as null, which is | 6770 // If no type argument vector is provided, leave it as null, which is |
| 6760 // equivalent to using Dynamic as the type argument for the value type. | 6771 // equivalent to using Dynamic as the type argument for the value type. |
| 6761 if (!map_type_arguments.IsNull()) { | 6772 if (!map_type_arguments.IsNull()) { |
| 6762 ASSERT(map_type_arguments.Length() > 0); | 6773 ASSERT(map_type_arguments.Length() > 0); |
| 6763 // Map literals take a single type argument. | 6774 // Map literals take a single type argument. |
| 6764 value_type = map_type_arguments.TypeAt(0); | 6775 value_type = map_type_arguments.TypeAt(0); |
| 6765 if (map_type_arguments.Length() > 1) { | 6776 if (map_type_arguments.Length() > 1) { |
| 6766 // We temporarily accept two type arguments, as long as the first one is | 6777 // We temporarily accept two type arguments, as long as the first one is |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7100 // argument vector to be passed. | 7111 // argument vector to be passed. |
| 7101 { | 7112 { |
| 7102 Class& signature_class = Class::Handle(); | 7113 Class& signature_class = Class::Handle(); |
| 7103 if (constructor.IsFactory()) { | 7114 if (constructor.IsFactory()) { |
| 7104 signature_class = constructor.signature_class(); | 7115 signature_class = constructor.signature_class(); |
| 7105 } else { | 7116 } else { |
| 7106 signature_class = constructor.owner(); | 7117 signature_class = constructor.owner(); |
| 7107 ASSERT(signature_class.raw() == type_class.raw()); | 7118 ASSERT(signature_class.raw() == type_class.raw()); |
| 7108 } | 7119 } |
| 7109 // TODO(regis): Temporary type should be allocated in new gen heap. | 7120 // TODO(regis): Temporary type should be allocated in new gen heap. |
| 7110 Type& type = Type::Handle( | 7121 AbstractType& type = Type::Handle( |
| 7111 Type::NewParameterizedType(signature_class, type_arguments)); | 7122 Type::NewParameterizedType(signature_class, type_arguments)); |
| 7112 String& errmsg = String::Handle(); | 7123 String& errmsg = String::Handle(); |
| 7113 type = ClassFinalizer::FinalizeAndCanonicalizeType(type, &errmsg); | 7124 type = ClassFinalizer::FinalizeAndCanonicalizeType(type, &errmsg); |
| 7114 if (!errmsg.IsNull()) { | 7125 if (!errmsg.IsNull()) { |
| 7115 ErrorMsg(errmsg.ToCString()); | 7126 ErrorMsg(errmsg.ToCString()); |
| 7116 } | 7127 } |
| 7117 // The type argument vector may have been expanded with the type arguments | 7128 // The type argument vector may have been expanded with the type arguments |
| 7118 // of the super type when finalizing the type. | 7129 // of the super type when finalizing the type. |
| 7119 type_arguments = type.arguments(); | 7130 type_arguments = type.arguments(); |
| 7120 } | 7131 } |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7582 } | 7593 } |
| 7583 | 7594 |
| 7584 | 7595 |
| 7585 void Parser::SkipNestedExpr() { | 7596 void Parser::SkipNestedExpr() { |
| 7586 const bool saved_mode = SetAllowFunctionLiterals(true); | 7597 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7587 SkipExpr(); | 7598 SkipExpr(); |
| 7588 SetAllowFunctionLiterals(saved_mode); | 7599 SetAllowFunctionLiterals(saved_mode); |
| 7589 } | 7600 } |
| 7590 | 7601 |
| 7591 } // namespace dart | 7602 } // namespace dart |
| OLD | NEW |