Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/parser.h" | 5 #include "vm/parser.h" |
| 6 | 6 |
| 7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
| 10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 is_top_level_(false), | 298 is_top_level_(false), |
| 299 parsing_metadata_(false), | 299 parsing_metadata_(false), |
| 300 current_member_(NULL), | 300 current_member_(NULL), |
| 301 allow_function_literals_(true), | 301 allow_function_literals_(true), |
| 302 parsed_function_(parsed_function), | 302 parsed_function_(parsed_function), |
| 303 innermost_function_(Function::Handle(isolate_, | 303 innermost_function_(Function::Handle(isolate_, |
| 304 parsed_function->function().raw())), | 304 parsed_function->function().raw())), |
| 305 literal_token_(LiteralToken::Handle(isolate_)), | 305 literal_token_(LiteralToken::Handle(isolate_)), |
| 306 current_class_(Class::Handle(isolate_, | 306 current_class_(Class::Handle(isolate_, |
| 307 parsed_function->function().Owner())), | 307 parsed_function->function().Owner())), |
| 308 library_(Library::Handle(Class::Handle( | 308 library_(Library::Handle(isolate_, Class::Handle( |
|
Cutch
2014/05/27 10:00:02
Should this use isolate() instead of isolate_?
Ivan Posva
2014/05/27 10:15:53
This is in the constructor, so I use isolate_ like
| |
| 309 isolate_, | 309 isolate_, |
| 310 parsed_function->function().origin()).library())), | 310 parsed_function->function().origin()).library())), |
| 311 try_blocks_list_(NULL), | 311 try_blocks_list_(NULL), |
| 312 last_used_try_index_(0), | 312 last_used_try_index_(0), |
| 313 unregister_pending_function_(false) { | 313 unregister_pending_function_(false) { |
| 314 ASSERT(tokens_iterator_.IsValid()); | 314 ASSERT(tokens_iterator_.IsValid()); |
| 315 ASSERT(!current_function().IsNull()); | 315 ASSERT(!current_function().IsNull()); |
| 316 if (FLAG_enable_type_checks) { | 316 if (FLAG_enable_type_checks) { |
| 317 EnsureExpressionTemp(); | 317 EnsureExpressionTemp(); |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 | 320 |
| 321 | 321 |
| 322 Parser::~Parser() { | 322 Parser::~Parser() { |
| 323 if (unregister_pending_function_) { | 323 if (unregister_pending_function_) { |
| 324 const GrowableObjectArray& pending_functions = | 324 const GrowableObjectArray& pending_functions = |
| 325 GrowableObjectArray::Handle( | 325 GrowableObjectArray::Handle( |
| 326 isolate()->object_store()->pending_functions()); | 326 isolate()->object_store()->pending_functions()); |
| 327 ASSERT(pending_functions.Length() > 0); | 327 ASSERT(pending_functions.Length() > 0); |
| 328 ASSERT(pending_functions.At(pending_functions.Length()-1) == | 328 ASSERT(pending_functions.At(pending_functions.Length()-1) == |
| 329 current_function().raw()); | 329 current_function().raw()); |
| 330 pending_functions.RemoveLast(); | 330 pending_functions.RemoveLast(); |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 | 333 |
| 334 | 334 |
| 335 void Parser::SetScript(const Script& script, intptr_t token_pos) { | 335 void Parser::SetScript(const Script& script, intptr_t token_pos) { |
| 336 script_ = script.raw(); | 336 script_ = script.raw(); |
| 337 tokens_iterator_.SetStream(TokenStream::Handle(script.tokens()), token_pos); | 337 tokens_iterator_.SetStream( |
| 338 TokenStream::Handle(isolate(), script.tokens()), token_pos); | |
| 338 token_kind_ = Token::kILLEGAL; | 339 token_kind_ = Token::kILLEGAL; |
| 339 } | 340 } |
| 340 | 341 |
| 341 | 342 |
| 342 bool Parser::SetAllowFunctionLiterals(bool value) { | 343 bool Parser::SetAllowFunctionLiterals(bool value) { |
| 343 bool current_value = allow_function_literals_; | 344 bool current_value = allow_function_literals_; |
| 344 allow_function_literals_ = value; | 345 allow_function_literals_ = value; |
| 345 return current_value; | 346 return current_value; |
| 346 } | 347 } |
| 347 | 348 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 ASSERT(literal_token_.kind() == Token::kDOUBLE); | 419 ASSERT(literal_token_.kind() == Token::kDOUBLE); |
| 419 return Double::RawCast(literal_token_.value()); | 420 return Double::RawCast(literal_token_.value()); |
| 420 } | 421 } |
| 421 | 422 |
| 422 | 423 |
| 423 RawInteger* Parser::CurrentIntegerLiteral() const { | 424 RawInteger* Parser::CurrentIntegerLiteral() const { |
| 424 literal_token_ ^= tokens_iterator_.CurrentToken(); | 425 literal_token_ ^= tokens_iterator_.CurrentToken(); |
| 425 ASSERT(literal_token_.kind() == Token::kINTEGER); | 426 ASSERT(literal_token_.kind() == Token::kINTEGER); |
| 426 RawInteger* ri = Integer::RawCast(literal_token_.value()); | 427 RawInteger* ri = Integer::RawCast(literal_token_.value()); |
| 427 if (FLAG_throw_on_javascript_int_overflow) { | 428 if (FLAG_throw_on_javascript_int_overflow) { |
| 428 const Integer& i = Integer::Handle(ri); | 429 const Integer& i = Integer::Handle(isolate(), ri); |
| 429 if (i.CheckJavascriptIntegerOverflow()) { | 430 if (i.CheckJavascriptIntegerOverflow()) { |
| 430 ErrorMsg(TokenPos(), | 431 ErrorMsg(TokenPos(), |
| 431 "Integer literal does not fit in a Javascript integer: %s.", | 432 "Integer literal does not fit in a Javascript integer: %s.", |
| 432 i.ToCString()); | 433 i.ToCString()); |
| 433 } | 434 } |
| 434 } | 435 } |
| 435 return ri; | 436 return ri; |
| 436 } | 437 } |
| 437 | 438 |
| 438 | 439 |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 875 | 876 |
| 876 parsed_function->set_default_parameter_values(default_parameter_values); | 877 parsed_function->set_default_parameter_values(default_parameter_values); |
| 877 } | 878 } |
| 878 | 879 |
| 879 | 880 |
| 880 RawObject* Parser::ParseMetadata(const Class& cls, intptr_t token_pos) { | 881 RawObject* Parser::ParseMetadata(const Class& cls, intptr_t token_pos) { |
| 881 Isolate* isolate = Isolate::Current(); | 882 Isolate* isolate = Isolate::Current(); |
| 882 StackZone zone(isolate); | 883 StackZone zone(isolate); |
| 883 LongJumpScope jump; | 884 LongJumpScope jump; |
| 884 if (setjmp(*jump.Set()) == 0) { | 885 if (setjmp(*jump.Set()) == 0) { |
| 885 const Script& script = Script::Handle(cls.script()); | 886 const Script& script = Script::Handle(isolate, cls.script()); |
|
Cutch
2014/05/27 10:00:02
You can use: isolate() right?
Ivan Posva
2014/05/27 10:15:53
No, as this is a static method.
| |
| 886 const Library& lib = Library::Handle(cls.library()); | 887 const Library& lib = Library::Handle(isolate, cls.library()); |
| 887 Parser parser(script, lib, token_pos); | 888 Parser parser(script, lib, token_pos); |
| 888 parser.set_current_class(cls); | 889 parser.set_current_class(cls); |
| 889 parser.set_parsing_metadata(true); | 890 parser.set_parsing_metadata(true); |
| 890 | 891 |
| 891 RawObject* metadata = parser.EvaluateMetadata(); | 892 RawObject* metadata = parser.EvaluateMetadata(); |
| 892 return metadata; | 893 return metadata; |
| 893 } else { | 894 } else { |
| 894 Error& error = Error::Handle(); | 895 Error& error = Error::Handle(isolate); |
| 895 error = isolate->object_store()->sticky_error(); | 896 error = isolate->object_store()->sticky_error(); |
| 896 isolate->object_store()->clear_sticky_error(); | 897 isolate->object_store()->clear_sticky_error(); |
| 897 return error.raw(); | 898 return error.raw(); |
| 898 } | 899 } |
| 899 UNREACHABLE(); | 900 UNREACHABLE(); |
| 900 return Object::null(); | 901 return Object::null(); |
| 901 } | 902 } |
| 902 | 903 |
| 903 | 904 |
| 904 RawArray* Parser::EvaluateMetadata() { | 905 RawArray* Parser::EvaluateMetadata() { |
| 905 CheckToken(Token::kAT, "Metadata character '@' expected"); | 906 CheckToken(Token::kAT, "Metadata character '@' expected"); |
| 906 GrowableObjectArray& meta_values = | 907 GrowableObjectArray& meta_values = |
| 907 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 908 GrowableObjectArray::Handle(isolate(), GrowableObjectArray::New()); |
| 908 while (CurrentToken() == Token::kAT) { | 909 while (CurrentToken() == Token::kAT) { |
| 909 ConsumeToken(); | 910 ConsumeToken(); |
| 910 intptr_t expr_pos = TokenPos(); | 911 intptr_t expr_pos = TokenPos(); |
| 911 if (!IsIdentifier()) { | 912 if (!IsIdentifier()) { |
| 912 ExpectIdentifier("identifier expected"); | 913 ExpectIdentifier("identifier expected"); |
| 913 } | 914 } |
| 914 // Reject expressions with deferred library prefix eagerly. | 915 // Reject expressions with deferred library prefix eagerly. |
| 915 Object& obj = Object::Handle(library_.LookupLocalObject(*CurrentLiteral())); | 916 Object& obj = Object::Handle(isolate(), |
| 917 library_.LookupLocalObject(*CurrentLiteral())); | |
| 916 if (!obj.IsNull() && obj.IsLibraryPrefix()) { | 918 if (!obj.IsNull() && obj.IsLibraryPrefix()) { |
| 917 if (LibraryPrefix::Cast(obj).is_deferred_load()) { | 919 if (LibraryPrefix::Cast(obj).is_deferred_load()) { |
| 918 ErrorMsg("Metadata must be compile-time constant"); | 920 ErrorMsg("Metadata must be compile-time constant"); |
| 919 } | 921 } |
| 920 } | 922 } |
| 921 AstNode* expr = NULL; | 923 AstNode* expr = NULL; |
| 922 if ((LookaheadToken(1) == Token::kLPAREN) || | 924 if ((LookaheadToken(1) == Token::kLPAREN) || |
| 923 ((LookaheadToken(1) == Token::kPERIOD) && | 925 ((LookaheadToken(1) == Token::kPERIOD) && |
| 924 (LookaheadToken(3) == Token::kLPAREN)) || | 926 (LookaheadToken(3) == Token::kLPAREN)) || |
| 925 ((LookaheadToken(1) == Token::kPERIOD) && | 927 ((LookaheadToken(1) == Token::kPERIOD) && |
| 926 (LookaheadToken(3) == Token::kPERIOD) && | 928 (LookaheadToken(3) == Token::kPERIOD) && |
| 927 (LookaheadToken(5) == Token::kLPAREN))) { | 929 (LookaheadToken(5) == Token::kLPAREN))) { |
| 928 expr = ParseNewOperator(Token::kCONST); | 930 expr = ParseNewOperator(Token::kCONST); |
| 929 } else { | 931 } else { |
| 930 // Can be x, C.x, or L.C.x. | 932 // Can be x, C.x, or L.C.x. |
| 931 expr = ParsePrimary(); // Consumes x, C or L.C. | 933 expr = ParsePrimary(); // Consumes x, C or L.C. |
| 932 Class& cls = Class::Handle(); | 934 Class& cls = Class::Handle(isolate()); |
| 933 if (expr->IsPrimaryNode()) { | 935 if (expr->IsPrimaryNode()) { |
| 934 PrimaryNode* primary_node = expr->AsPrimaryNode(); | 936 PrimaryNode* primary_node = expr->AsPrimaryNode(); |
| 935 if (primary_node->primary().IsClass()) { | 937 if (primary_node->primary().IsClass()) { |
| 936 // If the primary node referred to a class we are loading a | 938 // If the primary node referred to a class we are loading a |
| 937 // qualified static field. | 939 // qualified static field. |
| 938 cls ^= primary_node->primary().raw(); | 940 cls ^= primary_node->primary().raw(); |
| 939 } else { | 941 } else { |
| 940 ErrorMsg(expr_pos, "Metadata expressions must refer to a const field " | 942 ErrorMsg(expr_pos, "Metadata expressions must refer to a const field " |
| 941 "or constructor"); | 943 "or constructor"); |
| 942 } | 944 } |
| 943 } | 945 } |
| 944 if (CurrentToken() == Token::kPERIOD) { | 946 if (CurrentToken() == Token::kPERIOD) { |
| 945 // C.x or L.C.X. | 947 // C.x or L.C.X. |
| 946 if (cls.IsNull()) { | 948 if (cls.IsNull()) { |
| 947 ErrorMsg(expr_pos, "Metadata expressions must refer to a const field " | 949 ErrorMsg(expr_pos, "Metadata expressions must refer to a const field " |
| 948 "or constructor"); | 950 "or constructor"); |
| 949 } | 951 } |
| 950 ConsumeToken(); | 952 ConsumeToken(); |
| 951 const intptr_t ident_pos = TokenPos(); | 953 const intptr_t ident_pos = TokenPos(); |
| 952 String* ident = ExpectIdentifier("identifier expected"); | 954 String* ident = ExpectIdentifier("identifier expected"); |
| 953 const Field& field = Field::Handle(cls.LookupStaticField(*ident)); | 955 const Field& field = Field::Handle(isolate(), |
| 956 cls.LookupStaticField(*ident)); | |
| 954 if (field.IsNull()) { | 957 if (field.IsNull()) { |
| 955 ErrorMsg(ident_pos, | 958 ErrorMsg(ident_pos, |
| 956 "Class '%s' has no field '%s'", | 959 "Class '%s' has no field '%s'", |
| 957 cls.ToCString(), | 960 cls.ToCString(), |
| 958 ident->ToCString()); | 961 ident->ToCString()); |
| 959 } | 962 } |
| 960 if (!field.is_const()) { | 963 if (!field.is_const()) { |
| 961 ErrorMsg(ident_pos, | 964 ErrorMsg(ident_pos, |
| 962 "Field '%s' of class '%s' is not const", | 965 "Field '%s' of class '%s' is not const", |
| 963 ident->ToCString(), | 966 ident->ToCString(), |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 974 } | 977 } |
| 975 return Array::MakeArray(meta_values); | 978 return Array::MakeArray(meta_values); |
| 976 } | 979 } |
| 977 | 980 |
| 978 | 981 |
| 979 SequenceNode* Parser::ParseStaticFinalGetter(const Function& func) { | 982 SequenceNode* Parser::ParseStaticFinalGetter(const Function& func) { |
| 980 TRACE_PARSER("ParseStaticFinalGetter"); | 983 TRACE_PARSER("ParseStaticFinalGetter"); |
| 981 ParamList params; | 984 ParamList params; |
| 982 ASSERT(func.num_fixed_parameters() == 0); // static. | 985 ASSERT(func.num_fixed_parameters() == 0); // static. |
| 983 ASSERT(!func.HasOptionalParameters()); | 986 ASSERT(!func.HasOptionalParameters()); |
| 984 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 987 ASSERT(AbstractType::Handle(isolate(), func.result_type()).IsResolved()); |
| 985 | 988 |
| 986 // Build local scope for function and populate with the formal parameters. | 989 // Build local scope for function and populate with the formal parameters. |
| 987 OpenFunctionBlock(func); | 990 OpenFunctionBlock(func); |
| 988 AddFormalParamsToScope(¶ms, current_block_->scope); | 991 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 989 | 992 |
| 990 intptr_t ident_pos = TokenPos(); | 993 intptr_t ident_pos = TokenPos(); |
| 991 const String& field_name = *ExpectIdentifier("field name expected"); | 994 const String& field_name = *ExpectIdentifier("field name expected"); |
| 992 const Class& field_class = Class::Handle(func.Owner()); | 995 const Class& field_class = Class::Handle(isolate(), func.Owner()); |
| 993 const Field& field = | 996 const Field& field = |
| 994 Field::ZoneHandle(field_class.LookupStaticField(field_name)); | 997 Field::ZoneHandle(field_class.LookupStaticField(field_name)); |
| 995 | 998 |
| 996 // Static final fields must have an initializer. | 999 // Static final fields must have an initializer. |
| 997 ExpectToken(Token::kASSIGN); | 1000 ExpectToken(Token::kASSIGN); |
| 998 | 1001 |
| 999 const intptr_t expr_pos = TokenPos(); | 1002 const intptr_t expr_pos = TokenPos(); |
| 1000 if (field.is_const()) { | 1003 if (field.is_const()) { |
| 1001 // We don't want to use ParseConstExpr() here because we don't want | 1004 // We don't want to use ParseConstExpr() here because we don't want |
| 1002 // the constant folding code to create, compile and execute a code | 1005 // the constant folding code to create, compile and execute a code |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1054 ident_pos, | 1057 ident_pos, |
| 1055 Token::kEQ_STRICT, | 1058 Token::kEQ_STRICT, |
| 1056 new LoadStaticFieldNode(ident_pos, field), | 1059 new LoadStaticFieldNode(ident_pos, field), |
| 1057 new LiteralNode(ident_pos, Object::sentinel())); | 1060 new LiteralNode(ident_pos, Object::sentinel())); |
| 1058 SequenceNode* initialize_field = new SequenceNode(ident_pos, NULL); | 1061 SequenceNode* initialize_field = new SequenceNode(ident_pos, NULL); |
| 1059 initialize_field->Add( | 1062 initialize_field->Add( |
| 1060 new StoreStaticFieldNode( | 1063 new StoreStaticFieldNode( |
| 1061 ident_pos, | 1064 ident_pos, |
| 1062 field, | 1065 field, |
| 1063 new LiteralNode(ident_pos, Object::transition_sentinel()))); | 1066 new LiteralNode(ident_pos, Object::transition_sentinel()))); |
| 1064 const String& init_name = String::Handle( | 1067 const String& init_name = String::Handle(isolate(), Symbols::New( |
| 1065 Symbols::New(String::Handle(String::Concat( | 1068 String::Handle(isolate(), String::Concat( |
| 1066 Symbols::InitPrefix(), String::Handle(field.name()))))); | 1069 Symbols::InitPrefix(), String::Handle(isolate(), field.name()))))); |
| 1067 const Function& init_function = Function::ZoneHandle( | 1070 const Function& init_function = Function::ZoneHandle( |
| 1068 field_class.LookupStaticFunction(init_name)); | 1071 field_class.LookupStaticFunction(init_name)); |
| 1069 ASSERT(!init_function.IsNull()); | 1072 ASSERT(!init_function.IsNull()); |
| 1070 ArgumentListNode* arguments = new ArgumentListNode(expr_pos); | 1073 ArgumentListNode* arguments = new ArgumentListNode(expr_pos); |
| 1071 StaticCallNode* init_call = | 1074 StaticCallNode* init_call = |
| 1072 new StaticCallNode(expr_pos, init_function, arguments); | 1075 new StaticCallNode(expr_pos, init_function, arguments); |
| 1073 initialize_field->Add(init_call); | 1076 initialize_field->Add(init_call); |
| 1074 | 1077 |
| 1075 AstNode* uninitialized_check = | 1078 AstNode* uninitialized_check = |
| 1076 new IfNode(ident_pos, compare_uninitialized, initialize_field, NULL); | 1079 new IfNode(ident_pos, compare_uninitialized, initialize_field, NULL); |
| 1077 current_block_->statements->Add(uninitialized_check); | 1080 current_block_->statements->Add(uninitialized_check); |
| 1078 | 1081 |
| 1079 // Generate code returning the field value. | 1082 // Generate code returning the field value. |
| 1080 ReturnNode* return_node = | 1083 ReturnNode* return_node = |
| 1081 new ReturnNode(ident_pos, | 1084 new ReturnNode(ident_pos, |
| 1082 new LoadStaticFieldNode(ident_pos, field)); | 1085 new LoadStaticFieldNode(ident_pos, field)); |
| 1083 current_block_->statements->Add(return_node); | 1086 current_block_->statements->Add(return_node); |
| 1084 } | 1087 } |
| 1085 return CloseBlock(); | 1088 return CloseBlock(); |
| 1086 } | 1089 } |
| 1087 | 1090 |
| 1088 | 1091 |
| 1089 SequenceNode* Parser::ParseStaticInitializer(const Function& func) { | 1092 SequenceNode* Parser::ParseStaticInitializer(const Function& func) { |
| 1090 TRACE_PARSER("ParseStaticInitializer"); | 1093 TRACE_PARSER("ParseStaticInitializer"); |
| 1091 ParamList params; | 1094 ParamList params; |
| 1092 ASSERT(func.num_fixed_parameters() == 0); // static. | 1095 ASSERT(func.num_fixed_parameters() == 0); // static. |
| 1093 ASSERT(!func.HasOptionalParameters()); | 1096 ASSERT(!func.HasOptionalParameters()); |
| 1094 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 1097 ASSERT(AbstractType::Handle(isolate(), func.result_type()).IsResolved()); |
| 1095 | 1098 |
| 1096 // Build local scope for function and populate with the formal parameters. | 1099 // Build local scope for function and populate with the formal parameters. |
| 1097 OpenFunctionBlock(func); | 1100 OpenFunctionBlock(func); |
| 1098 AddFormalParamsToScope(¶ms, current_block_->scope); | 1101 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 1099 | 1102 |
| 1100 // Move forward to the start of the initializer expression. | 1103 // Move forward to the start of the initializer expression. |
| 1101 intptr_t ident_pos = TokenPos(); | 1104 intptr_t ident_pos = TokenPos(); |
| 1102 ExpectIdentifier("identifier expected"); | 1105 ExpectIdentifier("identifier expected"); |
| 1103 ExpectToken(Token::kASSIGN); | 1106 ExpectToken(Token::kASSIGN); |
| 1104 intptr_t token_pos = TokenPos(); | 1107 intptr_t token_pos = TokenPos(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1191 // ReturnNode (field's value); | 1194 // ReturnNode (field's value); |
| 1192 SequenceNode* Parser::ParseInstanceGetter(const Function& func) { | 1195 SequenceNode* Parser::ParseInstanceGetter(const Function& func) { |
| 1193 TRACE_PARSER("ParseInstanceGetter"); | 1196 TRACE_PARSER("ParseInstanceGetter"); |
| 1194 ParamList params; | 1197 ParamList params; |
| 1195 // func.token_pos() points to the name of the field. | 1198 // func.token_pos() points to the name of the field. |
| 1196 const intptr_t ident_pos = func.token_pos(); | 1199 const intptr_t ident_pos = func.token_pos(); |
| 1197 ASSERT(current_class().raw() == func.Owner()); | 1200 ASSERT(current_class().raw() == func.Owner()); |
| 1198 params.AddReceiver(ReceiverType(current_class()), ident_pos); | 1201 params.AddReceiver(ReceiverType(current_class()), ident_pos); |
| 1199 ASSERT(func.num_fixed_parameters() == 1); // receiver. | 1202 ASSERT(func.num_fixed_parameters() == 1); // receiver. |
| 1200 ASSERT(!func.HasOptionalParameters()); | 1203 ASSERT(!func.HasOptionalParameters()); |
| 1201 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 1204 ASSERT(AbstractType::Handle(isolate(), func.result_type()).IsResolved()); |
| 1202 | 1205 |
| 1203 // Build local scope for function and populate with the formal parameters. | 1206 // Build local scope for function and populate with the formal parameters. |
| 1204 OpenFunctionBlock(func); | 1207 OpenFunctionBlock(func); |
| 1205 AddFormalParamsToScope(¶ms, current_block_->scope); | 1208 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 1206 | 1209 |
| 1207 // Receiver is local 0. | 1210 // Receiver is local 0. |
| 1208 LocalVariable* receiver = current_block_->scope->VariableAt(0); | 1211 LocalVariable* receiver = current_block_->scope->VariableAt(0); |
| 1209 LoadLocalNode* load_receiver = new LoadLocalNode(ident_pos, receiver); | 1212 LoadLocalNode* load_receiver = new LoadLocalNode(ident_pos, receiver); |
| 1210 ASSERT(IsIdentifier()); | 1213 ASSERT(IsIdentifier()); |
| 1211 const String& field_name = *CurrentLiteral(); | 1214 const String& field_name = *CurrentLiteral(); |
| 1212 const Class& field_class = Class::Handle(func.Owner()); | 1215 const Class& field_class = Class::Handle(isolate(), func.Owner()); |
| 1213 const Field& field = | 1216 const Field& field = |
| 1214 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); | 1217 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); |
| 1215 | 1218 |
| 1216 LoadInstanceFieldNode* load_field = | 1219 LoadInstanceFieldNode* load_field = |
| 1217 new LoadInstanceFieldNode(ident_pos, load_receiver, field); | 1220 new LoadInstanceFieldNode(ident_pos, load_receiver, field); |
| 1218 | 1221 |
| 1219 ReturnNode* return_node = | 1222 ReturnNode* return_node = |
| 1220 new ReturnNode(Scanner::kNoSourcePos, load_field); | 1223 new ReturnNode(Scanner::kNoSourcePos, load_field); |
| 1221 current_block_->statements->Add(return_node); | 1224 current_block_->statements->Add(return_node); |
| 1222 return CloseBlock(); | 1225 return CloseBlock(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1239 const AbstractType& field_type = AbstractType::ZoneHandle(field.type()); | 1242 const AbstractType& field_type = AbstractType::ZoneHandle(field.type()); |
| 1240 | 1243 |
| 1241 ParamList params; | 1244 ParamList params; |
| 1242 ASSERT(current_class().raw() == func.Owner()); | 1245 ASSERT(current_class().raw() == func.Owner()); |
| 1243 params.AddReceiver(ReceiverType(current_class()), ident_pos); | 1246 params.AddReceiver(ReceiverType(current_class()), ident_pos); |
| 1244 params.AddFinalParameter(ident_pos, | 1247 params.AddFinalParameter(ident_pos, |
| 1245 &Symbols::Value(), | 1248 &Symbols::Value(), |
| 1246 &field_type); | 1249 &field_type); |
| 1247 ASSERT(func.num_fixed_parameters() == 2); // receiver, value. | 1250 ASSERT(func.num_fixed_parameters() == 2); // receiver, value. |
| 1248 ASSERT(!func.HasOptionalParameters()); | 1251 ASSERT(!func.HasOptionalParameters()); |
| 1249 ASSERT(AbstractType::Handle(func.result_type()).IsVoidType()); | 1252 ASSERT(AbstractType::Handle(isolate(), func.result_type()).IsVoidType()); |
| 1250 | 1253 |
| 1251 // Build local scope for function and populate with the formal parameters. | 1254 // Build local scope for function and populate with the formal parameters. |
| 1252 OpenFunctionBlock(func); | 1255 OpenFunctionBlock(func); |
| 1253 AddFormalParamsToScope(¶ms, current_block_->scope); | 1256 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 1254 | 1257 |
| 1255 LoadLocalNode* receiver = | 1258 LoadLocalNode* receiver = |
| 1256 new LoadLocalNode(ident_pos, current_block_->scope->VariableAt(0)); | 1259 new LoadLocalNode(ident_pos, current_block_->scope->VariableAt(0)); |
| 1257 LoadLocalNode* value = | 1260 LoadLocalNode* value = |
| 1258 new LoadLocalNode(ident_pos, current_block_->scope->VariableAt(1)); | 1261 new LoadLocalNode(ident_pos, current_block_->scope->VariableAt(1)); |
| 1259 | 1262 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1339 | 1342 |
| 1340 SequenceNode* Parser::ParseNoSuchMethodDispatcher(const Function& func, | 1343 SequenceNode* Parser::ParseNoSuchMethodDispatcher(const Function& func, |
| 1341 Array* default_values) { | 1344 Array* default_values) { |
| 1342 TRACE_PARSER("ParseNoSuchMethodDispatcher"); | 1345 TRACE_PARSER("ParseNoSuchMethodDispatcher"); |
| 1343 | 1346 |
| 1344 ASSERT(func.IsNoSuchMethodDispatcher()); | 1347 ASSERT(func.IsNoSuchMethodDispatcher()); |
| 1345 intptr_t token_pos = func.token_pos(); | 1348 intptr_t token_pos = func.token_pos(); |
| 1346 ASSERT(func.token_pos() == 0); | 1349 ASSERT(func.token_pos() == 0); |
| 1347 ASSERT(current_class().raw() == func.Owner()); | 1350 ASSERT(current_class().raw() == func.Owner()); |
| 1348 | 1351 |
| 1349 ArgumentsDescriptor desc(Array::Handle(func.saved_args_desc())); | 1352 ArgumentsDescriptor desc(Array::Handle(isolate(), func.saved_args_desc())); |
| 1350 ASSERT(desc.Count() > 0); | 1353 ASSERT(desc.Count() > 0); |
| 1351 | 1354 |
| 1352 // Set up scope for this function. | 1355 // Set up scope for this function. |
| 1353 BuildDispatcherScope(func, desc, default_values); | 1356 BuildDispatcherScope(func, desc, default_values); |
| 1354 | 1357 |
| 1355 // Receiver is local 0. | 1358 // Receiver is local 0. |
| 1356 LocalScope* scope = current_block_->scope; | 1359 LocalScope* scope = current_block_->scope; |
| 1357 ArgumentListNode* func_args = new ArgumentListNode(token_pos); | 1360 ArgumentListNode* func_args = new ArgumentListNode(token_pos); |
| 1358 for (intptr_t i = 0; i < desc.Count(); ++i) { | 1361 for (intptr_t i = 0; i < desc.Count(); ++i) { |
| 1359 func_args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); | 1362 func_args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); |
| 1360 } | 1363 } |
| 1361 | 1364 |
| 1362 if (desc.NamedCount() > 0) { | 1365 if (desc.NamedCount() > 0) { |
| 1363 const Array& arg_names = Array::ZoneHandle(Array::New(desc.NamedCount())); | 1366 const Array& arg_names = Array::ZoneHandle(Array::New(desc.NamedCount())); |
| 1364 for (intptr_t i = 0; i < arg_names.Length(); ++i) { | 1367 for (intptr_t i = 0; i < arg_names.Length(); ++i) { |
| 1365 arg_names.SetAt(i, String::Handle(desc.NameAt(i))); | 1368 arg_names.SetAt(i, String::Handle(isolate(), desc.NameAt(i))); |
| 1366 } | 1369 } |
| 1367 func_args->set_names(arg_names); | 1370 func_args->set_names(arg_names); |
| 1368 } | 1371 } |
| 1369 | 1372 |
| 1370 const String& func_name = String::ZoneHandle(func.name()); | 1373 const String& func_name = String::ZoneHandle(func.name()); |
| 1371 ArgumentListNode* arguments = BuildNoSuchMethodArguments( | 1374 ArgumentListNode* arguments = BuildNoSuchMethodArguments( |
| 1372 token_pos, func_name, *func_args, NULL, false); | 1375 token_pos, func_name, *func_args, NULL, false); |
| 1373 const Function& no_such_method = Function::ZoneHandle( | 1376 const Function& no_such_method = Function::ZoneHandle( |
| 1374 Resolver::ResolveDynamicAnyArgs(Class::Handle(func.Owner()), | 1377 Resolver::ResolveDynamicAnyArgs(Class::Handle( |
| 1375 Symbols::NoSuchMethod())); | 1378 isolate(), func.Owner()), Symbols::NoSuchMethod())); |
| 1376 StaticCallNode* call = | 1379 StaticCallNode* call = |
| 1377 new StaticCallNode(token_pos, no_such_method, arguments); | 1380 new StaticCallNode(token_pos, no_such_method, arguments); |
| 1378 | 1381 |
| 1379 ReturnNode* return_node = new ReturnNode(token_pos, call); | 1382 ReturnNode* return_node = new ReturnNode(token_pos, call); |
| 1380 current_block_->statements->Add(return_node); | 1383 current_block_->statements->Add(return_node); |
| 1381 return CloseBlock(); | 1384 return CloseBlock(); |
| 1382 } | 1385 } |
| 1383 | 1386 |
| 1384 | 1387 |
| 1385 SequenceNode* Parser::ParseInvokeFieldDispatcher(const Function& func, | 1388 SequenceNode* Parser::ParseInvokeFieldDispatcher(const Function& func, |
| 1386 Array* default_values) { | 1389 Array* default_values) { |
| 1387 TRACE_PARSER("ParseInvokeFieldDispatcher"); | 1390 TRACE_PARSER("ParseInvokeFieldDispatcher"); |
| 1388 | 1391 |
| 1389 ASSERT(func.IsInvokeFieldDispatcher()); | 1392 ASSERT(func.IsInvokeFieldDispatcher()); |
| 1390 intptr_t token_pos = func.token_pos(); | 1393 intptr_t token_pos = func.token_pos(); |
| 1391 ASSERT(func.token_pos() == 0); | 1394 ASSERT(func.token_pos() == 0); |
| 1392 ASSERT(current_class().raw() == func.Owner()); | 1395 ASSERT(current_class().raw() == func.Owner()); |
| 1393 | 1396 |
| 1394 const Array& args_desc = Array::Handle(func.saved_args_desc()); | 1397 const Array& args_desc = Array::Handle(isolate(), func.saved_args_desc()); |
| 1395 ArgumentsDescriptor desc(args_desc); | 1398 ArgumentsDescriptor desc(args_desc); |
| 1396 ASSERT(desc.Count() > 0); | 1399 ASSERT(desc.Count() > 0); |
| 1397 | 1400 |
| 1398 // Set up scope for this function. | 1401 // Set up scope for this function. |
| 1399 BuildDispatcherScope(func, desc, default_values); | 1402 BuildDispatcherScope(func, desc, default_values); |
| 1400 | 1403 |
| 1401 // Receiver is local 0. | 1404 // Receiver is local 0. |
| 1402 LocalScope* scope = current_block_->scope; | 1405 LocalScope* scope = current_block_->scope; |
| 1403 ArgumentListNode* no_args = new ArgumentListNode(token_pos); | 1406 ArgumentListNode* no_args = new ArgumentListNode(token_pos); |
| 1404 LoadLocalNode* receiver = new LoadLocalNode(token_pos, scope->VariableAt(0)); | 1407 LoadLocalNode* receiver = new LoadLocalNode(token_pos, scope->VariableAt(0)); |
| 1405 | 1408 |
| 1406 const String& name = String::Handle(func.name()); | 1409 const String& name = String::Handle(isolate(), func.name()); |
| 1407 const String& getter_name = | 1410 const String& getter_name = String::ZoneHandle( |
|
srdjan
2014/05/27 10:00:53
pass isolate to ZoneHandle as well
Ivan Posva
2014/05/27 10:15:53
This change only dealt with Handle, even though th
| |
| 1408 String::ZoneHandle(Symbols::New(String::Handle(Field::GetterName(name)))); | 1411 Symbols::New(String::Handle(isolate(), Field::GetterName(name)))); |
| 1409 InstanceCallNode* getter_call = new InstanceCallNode(token_pos, | 1412 InstanceCallNode* getter_call = new(isolate()) InstanceCallNode( |
| 1410 receiver, | 1413 token_pos, receiver, getter_name, no_args); |
| 1411 getter_name, | |
| 1412 no_args); | |
| 1413 | 1414 |
| 1414 // Pass arguments 1..n to the closure call. | 1415 // Pass arguments 1..n to the closure call. |
| 1415 ArgumentListNode* args = new ArgumentListNode(token_pos); | 1416 ArgumentListNode* args = new ArgumentListNode(token_pos); |
| 1416 const Array& names = Array::Handle(Array::New(desc.NamedCount(), Heap::kOld)); | 1417 const Array& names = Array::Handle( |
| 1418 isolate(), Array::New(desc.NamedCount(), Heap::kOld)); | |
| 1417 // Positional parameters. | 1419 // Positional parameters. |
| 1418 intptr_t i = 1; | 1420 intptr_t i = 1; |
| 1419 for (; i < desc.PositionalCount(); ++i) { | 1421 for (; i < desc.PositionalCount(); ++i) { |
| 1420 args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); | 1422 args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); |
| 1421 } | 1423 } |
| 1422 // Named parameters. | 1424 // Named parameters. |
| 1423 for (; i < desc.Count(); i++) { | 1425 for (; i < desc.Count(); i++) { |
| 1424 args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); | 1426 args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); |
| 1425 intptr_t index = i - desc.PositionalCount(); | 1427 intptr_t index = i - desc.PositionalCount(); |
| 1426 names.SetAt(index, String::Handle(desc.NameAt(index))); | 1428 names.SetAt(index, String::Handle(isolate(), desc.NameAt(index))); |
| 1427 } | 1429 } |
| 1428 args->set_names(names); | 1430 args->set_names(names); |
| 1429 | 1431 |
| 1430 const Class& owner = Class::Handle(func.Owner()); | 1432 const Class& owner = Class::Handle(isolate(), func.Owner()); |
| 1431 ASSERT(!owner.IsNull()); | 1433 ASSERT(!owner.IsNull()); |
| 1432 AstNode* result = NULL; | 1434 AstNode* result = NULL; |
| 1433 if (owner.IsSignatureClass() && name.Equals(Symbols::Call())) { | 1435 if (owner.IsSignatureClass() && name.Equals(Symbols::Call())) { |
| 1434 EnsureSavedCurrentContext(); | 1436 EnsureSavedCurrentContext(); |
| 1435 result = new ClosureCallNode(token_pos, getter_call, args); | 1437 result = new ClosureCallNode(token_pos, getter_call, args); |
| 1436 } else { | 1438 } else { |
| 1437 result = BuildClosureCall(token_pos, getter_call, args); | 1439 result = BuildClosureCall(token_pos, getter_call, args); |
| 1438 } | 1440 } |
| 1439 | 1441 |
| 1440 ReturnNode* return_node = new ReturnNode(token_pos, result); | 1442 ReturnNode* return_node = new ReturnNode(token_pos, result); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1595 } | 1597 } |
| 1596 } | 1598 } |
| 1597 | 1599 |
| 1598 if (CurrentToken() == Token::kLPAREN) { | 1600 if (CurrentToken() == Token::kLPAREN) { |
| 1599 // This parameter is probably a closure. If we saw the keyword 'var' | 1601 // This parameter is probably a closure. If we saw the keyword 'var' |
| 1600 // or 'final', a closure is not legal here and we ignore the | 1602 // or 'final', a closure is not legal here and we ignore the |
| 1601 // opening parens. | 1603 // opening parens. |
| 1602 if (!var_seen && !parameter.is_final) { | 1604 if (!var_seen && !parameter.is_final) { |
| 1603 // The parsed parameter type is actually the function result type. | 1605 // The parsed parameter type is actually the function result type. |
| 1604 const AbstractType& result_type = | 1606 const AbstractType& result_type = |
| 1605 AbstractType::Handle(parameter.type->raw()); | 1607 AbstractType::Handle(isolate(), parameter.type->raw()); |
| 1606 | 1608 |
| 1607 // Finish parsing the function type parameter. | 1609 // Finish parsing the function type parameter. |
| 1608 ParamList func_params; | 1610 ParamList func_params; |
| 1609 | 1611 |
| 1610 // Add implicit closure object parameter. | 1612 // Add implicit closure object parameter. |
| 1611 func_params.AddFinalParameter( | 1613 func_params.AddFinalParameter( |
| 1612 TokenPos(), | 1614 TokenPos(), |
| 1613 &Symbols::ClosureParameter(), | 1615 &Symbols::ClosureParameter(), |
| 1614 &Type::ZoneHandle(Type::DynamicType())); | 1616 &Type::ZoneHandle(Type::DynamicType())); |
| 1615 | 1617 |
| 1616 const bool no_explicit_default_values = false; | 1618 const bool no_explicit_default_values = false; |
| 1617 ParseFormalParameterList(no_explicit_default_values, false, &func_params); | 1619 ParseFormalParameterList(no_explicit_default_values, false, &func_params); |
| 1618 | 1620 |
| 1619 // The field 'is_static' has no meaning for signature functions. | 1621 // The field 'is_static' has no meaning for signature functions. |
| 1620 const Function& signature_function = Function::Handle( | 1622 const Function& signature_function = Function::Handle(isolate(), |
| 1621 Function::New(*parameter.name, | 1623 Function::New(*parameter.name, |
| 1622 RawFunction::kSignatureFunction, | 1624 RawFunction::kSignatureFunction, |
| 1623 /* is_static = */ false, | 1625 /* is_static = */ false, |
| 1624 /* is_const = */ false, | 1626 /* is_const = */ false, |
| 1625 /* is_abstract = */ false, | 1627 /* is_abstract = */ false, |
| 1626 /* is_external = */ false, | 1628 /* is_external = */ false, |
| 1627 /* is_native = */ false, | 1629 /* is_native = */ false, |
| 1628 current_class(), | 1630 current_class(), |
| 1629 parameter.name_pos)); | 1631 parameter.name_pos)); |
| 1630 signature_function.set_result_type(result_type); | 1632 signature_function.set_result_type(result_type); |
| 1631 AddFormalParamsToFunction(&func_params, signature_function); | 1633 AddFormalParamsToFunction(&func_params, signature_function); |
| 1632 const String& signature = String::Handle(signature_function.Signature()); | 1634 const String& signature = String::Handle(isolate(), |
| 1635 signature_function.Signature()); | |
| 1633 // Lookup the signature class, i.e. the class whose name is the signature. | 1636 // Lookup the signature class, i.e. the class whose name is the signature. |
| 1634 // We only lookup in the current library, but not in its imports, and only | 1637 // We only lookup in the current library, but not in its imports, and only |
| 1635 // create a new canonical signature class if it does not exist yet. | 1638 // create a new canonical signature class if it does not exist yet. |
| 1636 Class& signature_class = Class::ZoneHandle( | 1639 Class& signature_class = Class::ZoneHandle( |
| 1637 library_.LookupLocalClass(signature)); | 1640 library_.LookupLocalClass(signature)); |
| 1638 if (signature_class.IsNull()) { | 1641 if (signature_class.IsNull()) { |
| 1639 signature_class = Class::NewSignatureClass(signature, | 1642 signature_class = Class::NewSignatureClass(signature, |
| 1640 signature_function, | 1643 signature_function, |
| 1641 script_, | 1644 script_, |
| 1642 parameter.name_pos); | 1645 parameter.name_pos); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1782 | 1785 |
| 1783 // Resolve and return the dynamic function of the given name in the superclass. | 1786 // Resolve and return the dynamic function of the given name in the superclass. |
| 1784 // If it is not found, and resolve_getter is true, try to resolve a getter of | 1787 // If it is not found, and resolve_getter is true, try to resolve a getter of |
| 1785 // the same name. If it is still not found, return noSuchMethod and | 1788 // the same name. If it is still not found, return noSuchMethod and |
| 1786 // set is_no_such_method to true.. | 1789 // set is_no_such_method to true.. |
| 1787 RawFunction* Parser::GetSuperFunction(intptr_t token_pos, | 1790 RawFunction* Parser::GetSuperFunction(intptr_t token_pos, |
| 1788 const String& name, | 1791 const String& name, |
| 1789 ArgumentListNode* arguments, | 1792 ArgumentListNode* arguments, |
| 1790 bool resolve_getter, | 1793 bool resolve_getter, |
| 1791 bool* is_no_such_method) { | 1794 bool* is_no_such_method) { |
| 1792 const Class& super_class = Class::Handle(current_class().SuperClass()); | 1795 const Class& super_class = Class::Handle( |
| 1796 isolate(), current_class().SuperClass()); | |
| 1793 if (super_class.IsNull()) { | 1797 if (super_class.IsNull()) { |
| 1794 ErrorMsg(token_pos, "class '%s' does not have a superclass", | 1798 ErrorMsg(token_pos, "class '%s' does not have a superclass", |
| 1795 String::Handle(current_class().Name()).ToCString()); | 1799 String::Handle(isolate(), current_class().Name()).ToCString()); |
| 1796 } | 1800 } |
| 1797 Function& super_func = Function::Handle( | 1801 Function& super_func = Function::Handle(isolate(), |
| 1798 Resolver::ResolveDynamicAnyArgs(super_class, name)); | 1802 Resolver::ResolveDynamicAnyArgs(super_class, name)); |
| 1799 if (!super_func.IsNull() && | 1803 if (!super_func.IsNull() && |
| 1800 !super_func.AreValidArguments(arguments->length(), | 1804 !super_func.AreValidArguments(arguments->length(), |
| 1801 arguments->names(), | 1805 arguments->names(), |
| 1802 NULL)) { | 1806 NULL)) { |
| 1803 super_func = Function::null(); | 1807 super_func = Function::null(); |
| 1804 } else if (super_func.IsNull() && resolve_getter) { | 1808 } else if (super_func.IsNull() && resolve_getter) { |
| 1805 const String& getter_name = String::ZoneHandle(Field::GetterName(name)); | 1809 const String& getter_name = String::ZoneHandle(Field::GetterName(name)); |
| 1806 super_func = Resolver::ResolveDynamicAnyArgs(super_class, getter_name); | 1810 super_func = Resolver::ResolveDynamicAnyArgs(super_class, getter_name); |
| 1807 ASSERT(super_func.IsNull() || | 1811 ASSERT(super_func.IsNull() || |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2029 ClosureNode* Parser::CreateImplicitClosureNode(const Function& func, | 2033 ClosureNode* Parser::CreateImplicitClosureNode(const Function& func, |
| 2030 intptr_t token_pos, | 2034 intptr_t token_pos, |
| 2031 AstNode* receiver) { | 2035 AstNode* receiver) { |
| 2032 Function& implicit_closure_function = | 2036 Function& implicit_closure_function = |
| 2033 Function::ZoneHandle(func.ImplicitClosureFunction()); | 2037 Function::ZoneHandle(func.ImplicitClosureFunction()); |
| 2034 if (receiver != NULL) { | 2038 if (receiver != NULL) { |
| 2035 // If we create an implicit instance closure from inside a closure of a | 2039 // If we create an implicit instance closure from inside a closure of a |
| 2036 // parameterized class, make sure that the receiver is captured as | 2040 // parameterized class, make sure that the receiver is captured as |
| 2037 // instantiator. | 2041 // instantiator. |
| 2038 if (current_block_->scope->function_level() > 0) { | 2042 if (current_block_->scope->function_level() > 0) { |
| 2039 const Class& signature_class = Class::Handle( | 2043 const Class& signature_class = Class::Handle(isolate(), |
| 2040 implicit_closure_function.signature_class()); | 2044 implicit_closure_function.signature_class()); |
| 2041 if (signature_class.NumTypeParameters() > 0) { | 2045 if (signature_class.NumTypeParameters() > 0) { |
| 2042 CaptureInstantiator(); | 2046 CaptureInstantiator(); |
| 2043 } | 2047 } |
| 2044 } | 2048 } |
| 2045 } | 2049 } |
| 2046 return new ClosureNode(token_pos, implicit_closure_function, receiver, NULL); | 2050 return new ClosureNode(token_pos, implicit_closure_function, receiver, NULL); |
| 2047 } | 2051 } |
| 2048 | 2052 |
| 2049 | 2053 |
| 2050 AstNode* Parser::ParseSuperFieldAccess(const String& field_name, | 2054 AstNode* Parser::ParseSuperFieldAccess(const String& field_name, |
| 2051 intptr_t field_pos) { | 2055 intptr_t field_pos) { |
| 2052 TRACE_PARSER("ParseSuperFieldAccess"); | 2056 TRACE_PARSER("ParseSuperFieldAccess"); |
| 2053 const Class& super_class = Class::ZoneHandle(current_class().SuperClass()); | 2057 const Class& super_class = Class::ZoneHandle(current_class().SuperClass()); |
| 2054 if (super_class.IsNull()) { | 2058 if (super_class.IsNull()) { |
| 2055 ErrorMsg("class '%s' does not have a superclass", | 2059 ErrorMsg("class '%s' does not have a superclass", |
| 2056 String::Handle(current_class().Name()).ToCString()); | 2060 String::Handle(isolate(), current_class().Name()).ToCString()); |
| 2057 } | 2061 } |
| 2058 AstNode* implicit_argument = LoadReceiver(field_pos); | 2062 AstNode* implicit_argument = LoadReceiver(field_pos); |
| 2059 | 2063 |
| 2060 const String& getter_name = | 2064 const String& getter_name = |
| 2061 String::ZoneHandle(Field::GetterName(field_name)); | 2065 String::ZoneHandle(Field::GetterName(field_name)); |
| 2062 const Function& super_getter = Function::ZoneHandle( | 2066 const Function& super_getter = Function::ZoneHandle( |
| 2063 Resolver::ResolveDynamicAnyArgs(super_class, getter_name)); | 2067 Resolver::ResolveDynamicAnyArgs(super_class, getter_name)); |
| 2064 if (super_getter.IsNull()) { | 2068 if (super_getter.IsNull()) { |
| 2065 const String& setter_name = | 2069 const String& setter_name = |
| 2066 String::ZoneHandle(Field::SetterName(field_name)); | 2070 String::ZoneHandle(Field::SetterName(field_name)); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 2086 } | 2090 } |
| 2087 return new StaticGetterNode( | 2091 return new StaticGetterNode( |
| 2088 field_pos, implicit_argument, true, super_class, field_name); | 2092 field_pos, implicit_argument, true, super_class, field_name); |
| 2089 } | 2093 } |
| 2090 | 2094 |
| 2091 | 2095 |
| 2092 void Parser::GenerateSuperConstructorCall(const Class& cls, | 2096 void Parser::GenerateSuperConstructorCall(const Class& cls, |
| 2093 intptr_t supercall_pos, | 2097 intptr_t supercall_pos, |
| 2094 LocalVariable* receiver, | 2098 LocalVariable* receiver, |
| 2095 ArgumentListNode* forwarding_args) { | 2099 ArgumentListNode* forwarding_args) { |
| 2096 const Class& super_class = Class::Handle(cls.SuperClass()); | 2100 const Class& super_class = Class::Handle(isolate(), cls.SuperClass()); |
| 2097 // Omit the implicit super() if there is no super class (i.e. | 2101 // Omit the implicit super() if there is no super class (i.e. |
| 2098 // we're not compiling class Object), or if the super class is an | 2102 // we're not compiling class Object), or if the super class is an |
| 2099 // artificially generated "wrapper class" that has no constructor. | 2103 // artificially generated "wrapper class" that has no constructor. |
| 2100 if (super_class.IsNull() || | 2104 if (super_class.IsNull() || |
| 2101 (super_class.num_native_fields() > 0 && | 2105 (super_class.num_native_fields() > 0 && |
| 2102 Class::Handle(super_class.SuperClass()).IsObjectClass())) { | 2106 Class::Handle(isolate(), super_class.SuperClass()).IsObjectClass())) { |
| 2103 return; | 2107 return; |
| 2104 } | 2108 } |
| 2105 String& super_ctor_name = String::Handle(super_class.Name()); | 2109 String& super_ctor_name = String::Handle(isolate(), super_class.Name()); |
| 2106 super_ctor_name = String::Concat(super_ctor_name, Symbols::Dot()); | 2110 super_ctor_name = String::Concat(super_ctor_name, Symbols::Dot()); |
| 2107 | 2111 |
| 2108 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); | 2112 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); |
| 2109 // Implicit 'this' parameter is the first argument. | 2113 // Implicit 'this' parameter is the first argument. |
| 2110 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver); | 2114 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver); |
| 2111 arguments->Add(implicit_argument); | 2115 arguments->Add(implicit_argument); |
| 2112 // Implicit construction phase parameter is second argument. | 2116 // Implicit construction phase parameter is second argument. |
| 2113 AstNode* phase_parameter = | 2117 AstNode* phase_parameter = |
| 2114 new LiteralNode(supercall_pos, | 2118 new LiteralNode(supercall_pos, |
| 2115 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll))); | 2119 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll))); |
| 2116 arguments->Add(phase_parameter); | 2120 arguments->Add(phase_parameter); |
| 2117 | 2121 |
| 2118 // If this is a super call in a forwarding constructor, add the user- | 2122 // If this is a super call in a forwarding constructor, add the user- |
| 2119 // defined arguments to the super call and adjust the the super | 2123 // defined arguments to the super call and adjust the the super |
| 2120 // constructor name to the respective named constructor if necessary. | 2124 // constructor name to the respective named constructor if necessary. |
| 2121 if (forwarding_args != NULL) { | 2125 if (forwarding_args != NULL) { |
| 2122 for (int i = 0; i < forwarding_args->length(); i++) { | 2126 for (int i = 0; i < forwarding_args->length(); i++) { |
| 2123 arguments->Add(forwarding_args->NodeAt(i)); | 2127 arguments->Add(forwarding_args->NodeAt(i)); |
| 2124 } | 2128 } |
| 2125 String& ctor_name = String::Handle(current_function().name()); | 2129 String& ctor_name = String::Handle(isolate(), current_function().name()); |
| 2126 String& class_name = String::Handle(cls.Name()); | 2130 String& class_name = String::Handle(isolate(), cls.Name()); |
| 2127 if (ctor_name.Length() > class_name.Length() + 1) { | 2131 if (ctor_name.Length() > class_name.Length() + 1) { |
| 2128 // Generating a forwarding call to a named constructor 'C.n'. | 2132 // Generating a forwarding call to a named constructor 'C.n'. |
| 2129 // Add the constructor name 'n' to the super constructor. | 2133 // Add the constructor name 'n' to the super constructor. |
| 2130 ctor_name = String::SubString(ctor_name, class_name.Length() + 1); | 2134 ctor_name = String::SubString(ctor_name, class_name.Length() + 1); |
| 2131 super_ctor_name = String::Concat(super_ctor_name, ctor_name); | 2135 super_ctor_name = String::Concat(super_ctor_name, ctor_name); |
| 2132 } | 2136 } |
| 2133 } | 2137 } |
| 2134 | 2138 |
| 2135 // Resolve super constructor function and check arguments. | 2139 // Resolve super constructor function and check arguments. |
| 2136 const Function& super_ctor = Function::ZoneHandle( | 2140 const Function& super_ctor = Function::ZoneHandle( |
| 2137 super_class.LookupConstructor(super_ctor_name)); | 2141 super_class.LookupConstructor(super_ctor_name)); |
| 2138 if (super_ctor.IsNull()) { | 2142 if (super_ctor.IsNull()) { |
| 2139 ErrorMsg(supercall_pos, | 2143 ErrorMsg(supercall_pos, |
| 2140 "unresolved implicit call to super constructor '%s()'", | 2144 "unresolved implicit call to super constructor '%s()'", |
| 2141 String::Handle(super_class.Name()).ToCString()); | 2145 String::Handle(isolate(), super_class.Name()).ToCString()); |
| 2142 } | 2146 } |
| 2143 if (current_function().is_const() && !super_ctor.is_const()) { | 2147 if (current_function().is_const() && !super_ctor.is_const()) { |
| 2144 ErrorMsg(supercall_pos, "implicit call to non-const super constructor"); | 2148 ErrorMsg(supercall_pos, "implicit call to non-const super constructor"); |
| 2145 } | 2149 } |
| 2146 | 2150 |
| 2147 String& error_message = String::Handle(); | 2151 String& error_message = String::Handle(isolate()); |
| 2148 if (!super_ctor.AreValidArguments(arguments->length(), | 2152 if (!super_ctor.AreValidArguments(arguments->length(), |
| 2149 arguments->names(), | 2153 arguments->names(), |
| 2150 &error_message)) { | 2154 &error_message)) { |
| 2151 ErrorMsg(supercall_pos, | 2155 ErrorMsg(supercall_pos, |
| 2152 "invalid arguments passed to super constructor '%s()': %s", | 2156 "invalid arguments passed to super constructor '%s()': %s", |
| 2153 String::Handle(super_class.Name()).ToCString(), | 2157 String::Handle(isolate(), super_class.Name()).ToCString(), |
| 2154 error_message.ToCString()); | 2158 error_message.ToCString()); |
| 2155 } | 2159 } |
| 2156 current_block_->statements->Add( | 2160 current_block_->statements->Add( |
| 2157 new StaticCallNode(supercall_pos, super_ctor, arguments)); | 2161 new StaticCallNode(supercall_pos, super_ctor, arguments)); |
| 2158 } | 2162 } |
| 2159 | 2163 |
| 2160 | 2164 |
| 2161 AstNode* Parser::ParseSuperInitializer(const Class& cls, | 2165 AstNode* Parser::ParseSuperInitializer(const Class& cls, |
| 2162 LocalVariable* receiver) { | 2166 LocalVariable* receiver) { |
| 2163 TRACE_PARSER("ParseSuperInitializer"); | 2167 TRACE_PARSER("ParseSuperInitializer"); |
| 2164 ASSERT(CurrentToken() == Token::kSUPER); | 2168 ASSERT(CurrentToken() == Token::kSUPER); |
| 2165 const intptr_t supercall_pos = TokenPos(); | 2169 const intptr_t supercall_pos = TokenPos(); |
| 2166 ConsumeToken(); | 2170 ConsumeToken(); |
| 2167 const Class& super_class = Class::Handle(cls.SuperClass()); | 2171 const Class& super_class = Class::Handle(isolate(), cls.SuperClass()); |
| 2168 ASSERT(!super_class.IsNull()); | 2172 ASSERT(!super_class.IsNull()); |
| 2169 String& ctor_name = String::Handle(super_class.Name()); | 2173 String& ctor_name = String::Handle(isolate(), super_class.Name()); |
| 2170 ctor_name = String::Concat(ctor_name, Symbols::Dot()); | 2174 ctor_name = String::Concat(ctor_name, Symbols::Dot()); |
| 2171 if (CurrentToken() == Token::kPERIOD) { | 2175 if (CurrentToken() == Token::kPERIOD) { |
| 2172 ConsumeToken(); | 2176 ConsumeToken(); |
| 2173 ctor_name = String::Concat(ctor_name, | 2177 ctor_name = String::Concat(ctor_name, |
| 2174 *ExpectIdentifier("constructor name expected")); | 2178 *ExpectIdentifier("constructor name expected")); |
| 2175 } | 2179 } |
| 2176 CheckToken(Token::kLPAREN, "parameter list expected"); | 2180 CheckToken(Token::kLPAREN, "parameter list expected"); |
| 2177 | 2181 |
| 2178 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); | 2182 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); |
| 2179 // 'this' parameter is the first argument to super class constructor. | 2183 // 'this' parameter is the first argument to super class constructor. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2196 const Function& super_ctor = Function::ZoneHandle( | 2200 const Function& super_ctor = Function::ZoneHandle( |
| 2197 super_class.LookupConstructor(ctor_name)); | 2201 super_class.LookupConstructor(ctor_name)); |
| 2198 if (super_ctor.IsNull()) { | 2202 if (super_ctor.IsNull()) { |
| 2199 ErrorMsg(supercall_pos, | 2203 ErrorMsg(supercall_pos, |
| 2200 "super class constructor '%s' not found", | 2204 "super class constructor '%s' not found", |
| 2201 ctor_name.ToCString()); | 2205 ctor_name.ToCString()); |
| 2202 } | 2206 } |
| 2203 if (current_function().is_const() && !super_ctor.is_const()) { | 2207 if (current_function().is_const() && !super_ctor.is_const()) { |
| 2204 ErrorMsg(supercall_pos, "super constructor must be const"); | 2208 ErrorMsg(supercall_pos, "super constructor must be const"); |
| 2205 } | 2209 } |
| 2206 String& error_message = String::Handle(); | 2210 String& error_message = String::Handle(isolate()); |
| 2207 if (!super_ctor.AreValidArguments(arguments->length(), | 2211 if (!super_ctor.AreValidArguments(arguments->length(), |
| 2208 arguments->names(), | 2212 arguments->names(), |
| 2209 &error_message)) { | 2213 &error_message)) { |
| 2210 ErrorMsg(supercall_pos, | 2214 ErrorMsg(supercall_pos, |
| 2211 "invalid arguments passed to super class constructor '%s': %s", | 2215 "invalid arguments passed to super class constructor '%s': %s", |
| 2212 ctor_name.ToCString(), | 2216 ctor_name.ToCString(), |
| 2213 error_message.ToCString()); | 2217 error_message.ToCString()); |
| 2214 } | 2218 } |
| 2215 return new StaticCallNode(supercall_pos, super_ctor, arguments); | 2219 return new StaticCallNode(supercall_pos, super_ctor, arguments); |
| 2216 } | 2220 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 2247 field_name.ToCString()); | 2251 field_name.ToCString()); |
| 2248 } | 2252 } |
| 2249 CheckDuplicateFieldInit(field_pos, initialized_fields, &field); | 2253 CheckDuplicateFieldInit(field_pos, initialized_fields, &field); |
| 2250 AstNode* instance = new LoadLocalNode(field_pos, receiver); | 2254 AstNode* instance = new LoadLocalNode(field_pos, receiver); |
| 2251 EnsureExpressionTemp(); | 2255 EnsureExpressionTemp(); |
| 2252 return new StoreInstanceFieldNode(field_pos, instance, field, init_expr); | 2256 return new StoreInstanceFieldNode(field_pos, instance, field, init_expr); |
| 2253 } | 2257 } |
| 2254 | 2258 |
| 2255 | 2259 |
| 2256 void Parser::CheckFieldsInitialized(const Class& cls) { | 2260 void Parser::CheckFieldsInitialized(const Class& cls) { |
| 2257 const Array& fields = Array::Handle(cls.fields()); | 2261 const Array& fields = Array::Handle(isolate(), cls.fields()); |
| 2258 Field& field = Field::Handle(); | 2262 Field& field = Field::Handle(isolate()); |
| 2259 SequenceNode* initializers = current_block_->statements; | 2263 SequenceNode* initializers = current_block_->statements; |
| 2260 for (int field_num = 0; field_num < fields.Length(); field_num++) { | 2264 for (int field_num = 0; field_num < fields.Length(); field_num++) { |
| 2261 field ^= fields.At(field_num); | 2265 field ^= fields.At(field_num); |
| 2262 if (field.is_static()) { | 2266 if (field.is_static()) { |
| 2263 continue; | 2267 continue; |
| 2264 } | 2268 } |
| 2265 | 2269 |
| 2266 bool found = false; | 2270 bool found = false; |
| 2267 for (int i = 0; i < initializers->length(); i++) { | 2271 for (int i = 0; i < initializers->length(); i++) { |
| 2268 found = false; | 2272 found = false; |
| 2269 if (initializers->NodeAt(i)->IsStoreInstanceFieldNode()) { | 2273 if (initializers->NodeAt(i)->IsStoreInstanceFieldNode()) { |
| 2270 StoreInstanceFieldNode* initializer = | 2274 StoreInstanceFieldNode* initializer = |
| 2271 initializers->NodeAt(i)->AsStoreInstanceFieldNode(); | 2275 initializers->NodeAt(i)->AsStoreInstanceFieldNode(); |
| 2272 if (initializer->field().raw() == field.raw()) { | 2276 if (initializer->field().raw() == field.raw()) { |
| 2273 found = true; | 2277 found = true; |
| 2274 break; | 2278 break; |
| 2275 } | 2279 } |
| 2276 } | 2280 } |
| 2277 } | 2281 } |
| 2278 | 2282 |
| 2279 if (found) continue; | 2283 if (found) continue; |
| 2280 | 2284 |
| 2281 field.UpdateGuardedCidAndLength(Object::Handle()); | 2285 field.UpdateGuardedCidAndLength(Object::Handle(isolate())); |
| 2282 } | 2286 } |
| 2283 } | 2287 } |
| 2284 | 2288 |
| 2285 | 2289 |
| 2286 AstNode* Parser::ParseExternalInitializedField(const Field& field) { | 2290 AstNode* Parser::ParseExternalInitializedField(const Field& field) { |
| 2287 // Only use this function if the initialized field originates | 2291 // Only use this function if the initialized field originates |
| 2288 // from a different class. We need to save and restore current | 2292 // from a different class. We need to save and restore current |
| 2289 // class, library, and token stream (script). | 2293 // class, library, and token stream (script). |
| 2290 ASSERT(current_class().raw() != field.origin()); | 2294 ASSERT(current_class().raw() != field.origin()); |
| 2291 const Class& saved_class = Class::Handle(current_class().raw()); | 2295 const Class& saved_class = Class::Handle(isolate(), current_class().raw()); |
| 2292 const Library& saved_library = Library::Handle(library().raw()); | 2296 const Library& saved_library = Library::Handle(isolate(), library().raw()); |
| 2293 const Script& saved_script = Script::Handle(script().raw()); | 2297 const Script& saved_script = Script::Handle(isolate(), script().raw()); |
| 2294 const intptr_t saved_token_pos = TokenPos(); | 2298 const intptr_t saved_token_pos = TokenPos(); |
| 2295 | 2299 |
| 2296 set_current_class(Class::Handle(field.origin())); | 2300 set_current_class(Class::Handle(isolate(), field.origin())); |
| 2297 set_library(Library::Handle(current_class().library())); | 2301 set_library(Library::Handle(isolate(), current_class().library())); |
| 2298 SetScript(Script::Handle(current_class().script()), field.token_pos()); | 2302 SetScript(Script::Handle(isolate(), current_class().script()), |
| 2303 field.token_pos()); | |
| 2299 | 2304 |
| 2300 ASSERT(IsIdentifier()); | 2305 ASSERT(IsIdentifier()); |
| 2301 ConsumeToken(); | 2306 ConsumeToken(); |
| 2302 ExpectToken(Token::kASSIGN); | 2307 ExpectToken(Token::kASSIGN); |
| 2303 AstNode* init_expr = NULL; | 2308 AstNode* init_expr = NULL; |
| 2304 intptr_t expr_pos = TokenPos(); | 2309 intptr_t expr_pos = TokenPos(); |
| 2305 if (field.is_const()) { | 2310 if (field.is_const()) { |
| 2306 init_expr = ParseConstExpr(); | 2311 init_expr = ParseConstExpr(); |
| 2307 } else { | 2312 } else { |
| 2308 init_expr = ParseExpr(kAllowConst, kConsumeCascades); | 2313 init_expr = ParseExpr(kAllowConst, kConsumeCascades); |
| 2309 if (init_expr->EvalConstExpr() != NULL) { | 2314 if (init_expr->EvalConstExpr() != NULL) { |
| 2310 init_expr = | 2315 init_expr = |
| 2311 new LiteralNode(field.token_pos(), | 2316 new LiteralNode(field.token_pos(), |
| 2312 EvaluateConstExpr(expr_pos, init_expr)); | 2317 EvaluateConstExpr(expr_pos, init_expr)); |
| 2313 } | 2318 } |
| 2314 } | 2319 } |
| 2315 set_current_class(saved_class); | 2320 set_current_class(saved_class); |
| 2316 set_library(saved_library); | 2321 set_library(saved_library); |
| 2317 SetScript(saved_script, saved_token_pos); | 2322 SetScript(saved_script, saved_token_pos); |
| 2318 return init_expr; | 2323 return init_expr; |
| 2319 } | 2324 } |
| 2320 | 2325 |
| 2321 | 2326 |
| 2322 void Parser::ParseInitializedInstanceFields(const Class& cls, | 2327 void Parser::ParseInitializedInstanceFields(const Class& cls, |
| 2323 LocalVariable* receiver, | 2328 LocalVariable* receiver, |
| 2324 GrowableArray<Field*>* initialized_fields) { | 2329 GrowableArray<Field*>* initialized_fields) { |
| 2325 TRACE_PARSER("ParseInitializedInstanceFields"); | 2330 TRACE_PARSER("ParseInitializedInstanceFields"); |
| 2326 const Array& fields = Array::Handle(cls.fields()); | 2331 const Array& fields = Array::Handle(isolate(), cls.fields()); |
| 2327 Field& f = Field::Handle(); | 2332 Field& f = Field::Handle(isolate()); |
| 2328 const intptr_t saved_pos = TokenPos(); | 2333 const intptr_t saved_pos = TokenPos(); |
| 2329 for (int i = 0; i < fields.Length(); i++) { | 2334 for (int i = 0; i < fields.Length(); i++) { |
| 2330 f ^= fields.At(i); | 2335 f ^= fields.At(i); |
| 2331 if (!f.is_static() && f.has_initializer()) { | 2336 if (!f.is_static() && f.has_initializer()) { |
| 2332 Field& field = Field::ZoneHandle(); | 2337 Field& field = Field::ZoneHandle(); |
| 2333 field ^= fields.At(i); | 2338 field ^= fields.At(i); |
| 2334 if (field.is_final()) { | 2339 if (field.is_final()) { |
| 2335 // Final fields with initializer expression may not be initialized | 2340 // Final fields with initializer expression may not be initialized |
| 2336 // again by constructors. Remember that this field is already | 2341 // again by constructors. Remember that this field is already |
| 2337 // initialized. | 2342 // initialized. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2373 | 2378 |
| 2374 void Parser::CheckDuplicateFieldInit(intptr_t init_pos, | 2379 void Parser::CheckDuplicateFieldInit(intptr_t init_pos, |
| 2375 GrowableArray<Field*>* initialized_fields, | 2380 GrowableArray<Field*>* initialized_fields, |
| 2376 Field* field) { | 2381 Field* field) { |
| 2377 ASSERT(!field->is_static()); | 2382 ASSERT(!field->is_static()); |
| 2378 for (int i = 0; i < initialized_fields->length(); i++) { | 2383 for (int i = 0; i < initialized_fields->length(); i++) { |
| 2379 Field* initialized_field = (*initialized_fields)[i]; | 2384 Field* initialized_field = (*initialized_fields)[i]; |
| 2380 if (initialized_field->raw() == field->raw()) { | 2385 if (initialized_field->raw() == field->raw()) { |
| 2381 ErrorMsg(init_pos, | 2386 ErrorMsg(init_pos, |
| 2382 "duplicate initialization for field %s", | 2387 "duplicate initialization for field %s", |
| 2383 String::Handle(field->name()).ToCString()); | 2388 String::Handle(isolate(), field->name()).ToCString()); |
| 2384 } | 2389 } |
| 2385 } | 2390 } |
| 2386 initialized_fields->Add(field); | 2391 initialized_fields->Add(field); |
| 2387 } | 2392 } |
| 2388 | 2393 |
| 2389 | 2394 |
| 2390 void Parser::ParseInitializers(const Class& cls, | 2395 void Parser::ParseInitializers(const Class& cls, |
| 2391 LocalVariable* receiver, | 2396 LocalVariable* receiver, |
| 2392 GrowableArray<Field*>* initialized_fields) { | 2397 GrowableArray<Field*>* initialized_fields) { |
| 2393 TRACE_PARSER("ParseInitializers"); | 2398 TRACE_PARSER("ParseInitializers"); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 2417 } | 2422 } |
| 2418 | 2423 |
| 2419 | 2424 |
| 2420 void Parser::ParseConstructorRedirection(const Class& cls, | 2425 void Parser::ParseConstructorRedirection(const Class& cls, |
| 2421 LocalVariable* receiver) { | 2426 LocalVariable* receiver) { |
| 2422 TRACE_PARSER("ParseConstructorRedirection"); | 2427 TRACE_PARSER("ParseConstructorRedirection"); |
| 2423 ExpectToken(Token::kCOLON); | 2428 ExpectToken(Token::kCOLON); |
| 2424 ASSERT(CurrentToken() == Token::kTHIS); | 2429 ASSERT(CurrentToken() == Token::kTHIS); |
| 2425 const intptr_t call_pos = TokenPos(); | 2430 const intptr_t call_pos = TokenPos(); |
| 2426 ConsumeToken(); | 2431 ConsumeToken(); |
| 2427 String& ctor_name = String::Handle(cls.Name()); | 2432 String& ctor_name = String::Handle(isolate(), cls.Name()); |
| 2428 | 2433 |
| 2429 ctor_name = String::Concat(ctor_name, Symbols::Dot()); | 2434 ctor_name = String::Concat(ctor_name, Symbols::Dot()); |
| 2430 if (CurrentToken() == Token::kPERIOD) { | 2435 if (CurrentToken() == Token::kPERIOD) { |
| 2431 ConsumeToken(); | 2436 ConsumeToken(); |
| 2432 ctor_name = String::Concat(ctor_name, | 2437 ctor_name = String::Concat(ctor_name, |
| 2433 *ExpectIdentifier("constructor name expected")); | 2438 *ExpectIdentifier("constructor name expected")); |
| 2434 } | 2439 } |
| 2435 CheckToken(Token::kLPAREN, "parameter list expected"); | 2440 CheckToken(Token::kLPAREN, "parameter list expected"); |
| 2436 | 2441 |
| 2437 ArgumentListNode* arguments = new ArgumentListNode(call_pos); | 2442 ArgumentListNode* arguments = new ArgumentListNode(call_pos); |
| 2438 // 'this' parameter is the first argument to constructor. | 2443 // 'this' parameter is the first argument to constructor. |
| 2439 AstNode* implicit_argument = new LoadLocalNode(call_pos, receiver); | 2444 AstNode* implicit_argument = new LoadLocalNode(call_pos, receiver); |
| 2440 arguments->Add(implicit_argument); | 2445 arguments->Add(implicit_argument); |
| 2441 // Construction phase parameter is second argument. | 2446 // Construction phase parameter is second argument. |
| 2442 LocalVariable* phase_param = LookupPhaseParameter(); | 2447 LocalVariable* phase_param = LookupPhaseParameter(); |
| 2443 ASSERT(phase_param != NULL); | 2448 ASSERT(phase_param != NULL); |
| 2444 AstNode* phase_argument = new LoadLocalNode(call_pos, phase_param); | 2449 AstNode* phase_argument = new LoadLocalNode(call_pos, phase_param); |
| 2445 arguments->Add(phase_argument); | 2450 arguments->Add(phase_argument); |
| 2446 receiver->set_invisible(true); | 2451 receiver->set_invisible(true); |
| 2447 ParseActualParameters(arguments, kAllowConst); | 2452 ParseActualParameters(arguments, kAllowConst); |
| 2448 receiver->set_invisible(false); | 2453 receiver->set_invisible(false); |
| 2449 // Resolve the constructor. | 2454 // Resolve the constructor. |
| 2450 const Function& redirect_ctor = Function::ZoneHandle( | 2455 const Function& redirect_ctor = Function::ZoneHandle( |
| 2451 cls.LookupConstructor(ctor_name)); | 2456 cls.LookupConstructor(ctor_name)); |
| 2452 if (redirect_ctor.IsNull()) { | 2457 if (redirect_ctor.IsNull()) { |
| 2453 ErrorMsg(call_pos, "constructor '%s' not found", ctor_name.ToCString()); | 2458 ErrorMsg(call_pos, "constructor '%s' not found", ctor_name.ToCString()); |
| 2454 } | 2459 } |
| 2455 String& error_message = String::Handle(); | 2460 String& error_message = String::Handle(isolate()); |
| 2456 if (!redirect_ctor.AreValidArguments(arguments->length(), | 2461 if (!redirect_ctor.AreValidArguments(arguments->length(), |
| 2457 arguments->names(), | 2462 arguments->names(), |
| 2458 &error_message)) { | 2463 &error_message)) { |
| 2459 ErrorMsg(call_pos, | 2464 ErrorMsg(call_pos, |
| 2460 "invalid arguments passed to constructor '%s': %s", | 2465 "invalid arguments passed to constructor '%s': %s", |
| 2461 ctor_name.ToCString(), | 2466 ctor_name.ToCString(), |
| 2462 error_message.ToCString()); | 2467 error_message.ToCString()); |
| 2463 } | 2468 } |
| 2464 current_block_->statements->Add( | 2469 current_block_->statements->Add( |
| 2465 new StaticCallNode(call_pos, redirect_ctor, arguments)); | 2470 new StaticCallNode(call_pos, redirect_ctor, arguments)); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2534 | 2539 |
| 2535 // Empty constructor body. | 2540 // Empty constructor body. |
| 2536 current_block_->statements->Add(new ReturnNode(Scanner::kNoSourcePos)); | 2541 current_block_->statements->Add(new ReturnNode(Scanner::kNoSourcePos)); |
| 2537 SequenceNode* statements = CloseBlock(); | 2542 SequenceNode* statements = CloseBlock(); |
| 2538 return statements; | 2543 return statements; |
| 2539 } | 2544 } |
| 2540 | 2545 |
| 2541 | 2546 |
| 2542 void Parser::CheckRecursiveInvocation() { | 2547 void Parser::CheckRecursiveInvocation() { |
| 2543 const GrowableObjectArray& pending_functions = | 2548 const GrowableObjectArray& pending_functions = |
| 2544 GrowableObjectArray::Handle( | 2549 GrowableObjectArray::Handle(isolate(), |
| 2545 isolate()->object_store()->pending_functions()); | 2550 isolate()->object_store()->pending_functions()); |
| 2546 for (int i = 0; i < pending_functions.Length(); i++) { | 2551 for (int i = 0; i < pending_functions.Length(); i++) { |
| 2547 if (pending_functions.At(i) == current_function().raw()) { | 2552 if (pending_functions.At(i) == current_function().raw()) { |
| 2548 const String& fname = | 2553 const String& fname = |
| 2549 String::Handle(current_function().UserVisibleName()); | 2554 String::Handle(isolate(), current_function().UserVisibleName()); |
| 2550 ErrorMsg("circular dependency for function %s", fname.ToCString()); | 2555 ErrorMsg("circular dependency for function %s", fname.ToCString()); |
| 2551 } | 2556 } |
| 2552 } | 2557 } |
| 2553 ASSERT(!unregister_pending_function_); | 2558 ASSERT(!unregister_pending_function_); |
| 2554 pending_functions.Add(current_function()); | 2559 pending_functions.Add(current_function()); |
| 2555 unregister_pending_function_ = true; | 2560 unregister_pending_function_ = true; |
| 2556 } | 2561 } |
| 2557 | 2562 |
| 2558 | 2563 |
| 2559 // Parser is at the opening parenthesis of the formal parameter declaration | 2564 // Parser is at the opening parenthesis of the formal parameter declaration |
| 2560 // of function. Parse the formal parameters, initializers and code. | 2565 // of function. Parse the formal parameters, initializers and code. |
| 2561 SequenceNode* Parser::ParseConstructor(const Function& func, | 2566 SequenceNode* Parser::ParseConstructor(const Function& func, |
| 2562 Array* default_parameter_values) { | 2567 Array* default_parameter_values) { |
| 2563 TRACE_PARSER("ParseConstructor"); | 2568 TRACE_PARSER("ParseConstructor"); |
| 2564 ASSERT(func.IsConstructor()); | 2569 ASSERT(func.IsConstructor()); |
| 2565 ASSERT(!func.IsFactory()); | 2570 ASSERT(!func.IsFactory()); |
| 2566 ASSERT(!func.is_static()); | 2571 ASSERT(!func.is_static()); |
| 2567 ASSERT(!func.IsLocalFunction()); | 2572 ASSERT(!func.IsLocalFunction()); |
| 2568 const Class& cls = Class::Handle(func.Owner()); | 2573 const Class& cls = Class::Handle(isolate(), func.Owner()); |
| 2569 ASSERT(!cls.IsNull()); | 2574 ASSERT(!cls.IsNull()); |
| 2570 | 2575 |
| 2571 CheckRecursiveInvocation(); | 2576 CheckRecursiveInvocation(); |
| 2572 | 2577 |
| 2573 if (func.IsImplicitConstructor()) { | 2578 if (func.IsImplicitConstructor()) { |
| 2574 // Special case: implicit constructor. | 2579 // Special case: implicit constructor. |
| 2575 // The parser adds an implicit default constructor when a class | 2580 // The parser adds an implicit default constructor when a class |
| 2576 // does not have any explicit constructor or factory (see | 2581 // does not have any explicit constructor or factory (see |
| 2577 // Parser::AddImplicitConstructor). | 2582 // Parser::AddImplicitConstructor). |
| 2578 // There is no source text to parse. We just build the | 2583 // There is no source text to parse. We just build the |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2595 TokenPos(), | 2600 TokenPos(), |
| 2596 &Symbols::PhaseParameter(), | 2601 &Symbols::PhaseParameter(), |
| 2597 &Type::ZoneHandle(Type::SmiType())); | 2602 &Type::ZoneHandle(Type::SmiType())); |
| 2598 | 2603 |
| 2599 if (func.is_const()) { | 2604 if (func.is_const()) { |
| 2600 params.SetImplicitlyFinal(); | 2605 params.SetImplicitlyFinal(); |
| 2601 } | 2606 } |
| 2602 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); | 2607 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); |
| 2603 | 2608 |
| 2604 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); | 2609 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); |
| 2605 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 2610 ASSERT(AbstractType::Handle(isolate(), func.result_type()).IsResolved()); |
| 2606 ASSERT(func.NumParameters() == params.parameters->length()); | 2611 ASSERT(func.NumParameters() == params.parameters->length()); |
| 2607 | 2612 |
| 2608 // Now populate function scope with the formal parameters. | 2613 // Now populate function scope with the formal parameters. |
| 2609 AddFormalParamsToScope(¶ms, current_block_->scope); | 2614 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 2610 | 2615 |
| 2611 const bool is_redirecting_constructor = | 2616 const bool is_redirecting_constructor = |
| 2612 (CurrentToken() == Token::kCOLON) && | 2617 (CurrentToken() == Token::kCOLON) && |
| 2613 ((LookaheadToken(1) == Token::kTHIS) && | 2618 ((LookaheadToken(1) == Token::kTHIS) && |
| 2614 ((LookaheadToken(2) == Token::kLPAREN) || | 2619 ((LookaheadToken(2) == Token::kLPAREN) || |
| 2615 ((LookaheadToken(2) == Token::kPERIOD) && | 2620 ((LookaheadToken(2) == Token::kPERIOD) && |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2847 } | 2852 } |
| 2848 | 2853 |
| 2849 | 2854 |
| 2850 // Parser is at the opening parenthesis of the formal parameter | 2855 // Parser is at the opening parenthesis of the formal parameter |
| 2851 // declaration of the function or constructor. | 2856 // declaration of the function or constructor. |
| 2852 // Parse the formal parameters and code. | 2857 // Parse the formal parameters and code. |
| 2853 SequenceNode* Parser::ParseFunc(const Function& func, | 2858 SequenceNode* Parser::ParseFunc(const Function& func, |
| 2854 Array* default_parameter_values) { | 2859 Array* default_parameter_values) { |
| 2855 TRACE_PARSER("ParseFunc"); | 2860 TRACE_PARSER("ParseFunc"); |
| 2856 Function& saved_innermost_function = | 2861 Function& saved_innermost_function = |
| 2857 Function::Handle(innermost_function().raw()); | 2862 Function::Handle(isolate(), innermost_function().raw()); |
| 2858 innermost_function_ = func.raw(); | 2863 innermost_function_ = func.raw(); |
| 2859 | 2864 |
| 2860 // Save current try index. Try index starts at zero for each function. | 2865 // Save current try index. Try index starts at zero for each function. |
| 2861 intptr_t saved_try_index = last_used_try_index_; | 2866 intptr_t saved_try_index = last_used_try_index_; |
| 2862 last_used_try_index_ = 0; | 2867 last_used_try_index_ = 0; |
| 2863 | 2868 |
| 2864 // TODO(12455) : Need better validation mechanism. | 2869 // TODO(12455) : Need better validation mechanism. |
| 2865 | 2870 |
| 2866 if (func.IsConstructor()) { | 2871 if (func.IsConstructor()) { |
| 2867 SequenceNode* statements = ParseConstructor(func, default_parameter_values); | 2872 SequenceNode* statements = ParseConstructor(func, default_parameter_values); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2903 AddFormalParamsToScope(¶ms, current_block_->scope); | 2908 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 2904 } else { | 2909 } else { |
| 2905 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); | 2910 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); |
| 2906 | 2911 |
| 2907 // The number of parameters and their type are not yet set in local | 2912 // The number of parameters and their type are not yet set in local |
| 2908 // functions, since they are not 'top-level' parsed. | 2913 // functions, since they are not 'top-level' parsed. |
| 2909 if (func.IsLocalFunction()) { | 2914 if (func.IsLocalFunction()) { |
| 2910 AddFormalParamsToFunction(¶ms, func); | 2915 AddFormalParamsToFunction(¶ms, func); |
| 2911 } | 2916 } |
| 2912 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); | 2917 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); |
| 2913 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 2918 ASSERT(AbstractType::Handle(isolate(), func.result_type()).IsResolved()); |
| 2914 ASSERT(func.NumParameters() == params.parameters->length()); | 2919 ASSERT(func.NumParameters() == params.parameters->length()); |
| 2915 | 2920 |
| 2916 // Check whether the function has any field initializer formal parameters, | 2921 // Check whether the function has any field initializer formal parameters, |
| 2917 // which are not allowed in non-constructor functions. | 2922 // which are not allowed in non-constructor functions. |
| 2918 if (params.has_field_initializer) { | 2923 if (params.has_field_initializer) { |
| 2919 for (int i = 0; i < params.parameters->length(); i++) { | 2924 for (int i = 0; i < params.parameters->length(); i++) { |
| 2920 ParamDesc& param = (*params.parameters)[i]; | 2925 ParamDesc& param = (*params.parameters)[i]; |
| 2921 if (param.is_field_initializer) { | 2926 if (param.is_field_initializer) { |
| 2922 ErrorMsg(param.name_pos, | 2927 ErrorMsg(param.name_pos, |
| 2923 "field initializer only allowed in constructors"); | 2928 "field initializer only allowed in constructors"); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2938 // instantiate types. | 2943 // instantiate types. |
| 2939 CaptureInstantiator(); | 2944 CaptureInstantiator(); |
| 2940 } | 2945 } |
| 2941 } | 2946 } |
| 2942 } | 2947 } |
| 2943 | 2948 |
| 2944 OpenBlock(); // Open a nested scope for the outermost function block. | 2949 OpenBlock(); // Open a nested scope for the outermost function block. |
| 2945 intptr_t end_token_pos = 0; | 2950 intptr_t end_token_pos = 0; |
| 2946 if (CurrentToken() == Token::kLBRACE) { | 2951 if (CurrentToken() == Token::kLBRACE) { |
| 2947 ConsumeToken(); | 2952 ConsumeToken(); |
| 2948 if (String::Handle(func.name()).Equals(Symbols::EqualOperator())) { | 2953 if (String::Handle(isolate(), func.name()).Equals( |
| 2949 const Class& owner = Class::Handle(func.Owner()); | 2954 Symbols::EqualOperator())) { |
| 2955 const Class& owner = Class::Handle(isolate(), func.Owner()); | |
| 2950 if (!owner.IsObjectClass()) { | 2956 if (!owner.IsObjectClass()) { |
| 2951 AddEqualityNullCheck(); | 2957 AddEqualityNullCheck(); |
| 2952 } | 2958 } |
| 2953 } | 2959 } |
| 2954 ParseStatementSequence(); | 2960 ParseStatementSequence(); |
| 2955 end_token_pos = TokenPos(); | 2961 end_token_pos = TokenPos(); |
| 2956 ExpectToken(Token::kRBRACE); | 2962 ExpectToken(Token::kRBRACE); |
| 2957 } else if (CurrentToken() == Token::kARROW) { | 2963 } else if (CurrentToken() == Token::kARROW) { |
| 2958 ConsumeToken(); | 2964 ConsumeToken(); |
| 2959 if (String::Handle(func.name()).Equals(Symbols::EqualOperator())) { | 2965 if (String::Handle(isolate(), func.name()).Equals( |
| 2960 const Class& owner = Class::Handle(func.Owner()); | 2966 Symbols::EqualOperator())) { |
| 2967 const Class& owner = Class::Handle(isolate(), func.Owner()); | |
| 2961 if (!owner.IsObjectClass()) { | 2968 if (!owner.IsObjectClass()) { |
| 2962 AddEqualityNullCheck(); | 2969 AddEqualityNullCheck(); |
| 2963 } | 2970 } |
| 2964 } | 2971 } |
| 2965 const intptr_t expr_pos = TokenPos(); | 2972 const intptr_t expr_pos = TokenPos(); |
| 2966 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades); | 2973 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades); |
| 2967 ASSERT(expr != NULL); | 2974 ASSERT(expr != NULL); |
| 2968 current_block_->statements->Add(new ReturnNode(expr_pos, expr)); | 2975 current_block_->statements->Add(new ReturnNode(expr_pos, expr)); |
| 2969 end_token_pos = TokenPos(); | 2976 end_token_pos = TokenPos(); |
| 2970 } else if (IsLiteral("native")) { | 2977 } else if (IsLiteral("native")) { |
| 2971 if (String::Handle(func.name()).Equals(Symbols::EqualOperator())) { | 2978 if (String::Handle(isolate(), func.name()).Equals( |
| 2972 const Class& owner = Class::Handle(func.Owner()); | 2979 Symbols::EqualOperator())) { |
| 2980 const Class& owner = Class::Handle(isolate(), func.Owner()); | |
| 2973 if (!owner.IsObjectClass()) { | 2981 if (!owner.IsObjectClass()) { |
| 2974 AddEqualityNullCheck(); | 2982 AddEqualityNullCheck(); |
| 2975 } | 2983 } |
| 2976 } | 2984 } |
| 2977 ParseNativeFunctionBlock(¶ms, func); | 2985 ParseNativeFunctionBlock(¶ms, func); |
| 2978 end_token_pos = TokenPos(); | 2986 end_token_pos = TokenPos(); |
| 2979 ExpectSemicolon(); | 2987 ExpectSemicolon(); |
| 2980 } else if (func.is_external()) { | 2988 } else if (func.is_external()) { |
| 2981 // Body of an external method contains a single throw. | 2989 // Body of an external method contains a single throw. |
| 2982 const String& function_name = String::ZoneHandle(func.name()); | 2990 const String& function_name = String::ZoneHandle(func.name()); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3094 if (is_top_level_ || | 3102 if (is_top_level_ || |
| 3095 !ResolveIdentInLocalScope(qual_ident->ident_pos, | 3103 !ResolveIdentInLocalScope(qual_ident->ident_pos, |
| 3096 *(qual_ident->ident), | 3104 *(qual_ident->ident), |
| 3097 NULL)) { | 3105 NULL)) { |
| 3098 LibraryPrefix& lib_prefix = LibraryPrefix::ZoneHandle(); | 3106 LibraryPrefix& lib_prefix = LibraryPrefix::ZoneHandle(); |
| 3099 if (!current_class().IsMixinApplication()) { | 3107 if (!current_class().IsMixinApplication()) { |
| 3100 lib_prefix = current_class().LookupLibraryPrefix(*(qual_ident->ident)); | 3108 lib_prefix = current_class().LookupLibraryPrefix(*(qual_ident->ident)); |
| 3101 } else { | 3109 } else { |
| 3102 // TODO(hausner): Should we resolve the prefix via the library scope | 3110 // TODO(hausner): Should we resolve the prefix via the library scope |
| 3103 // rather than via the class? | 3111 // rather than via the class? |
| 3104 Class& cls = Class::Handle(parsed_function()->function().origin()); | 3112 Class& cls = Class::Handle(isolate(), |
| 3113 parsed_function()->function().origin()); | |
| 3105 lib_prefix = cls.LookupLibraryPrefix(*(qual_ident->ident)); | 3114 lib_prefix = cls.LookupLibraryPrefix(*(qual_ident->ident)); |
| 3106 } | 3115 } |
| 3107 if (!lib_prefix.IsNull()) { | 3116 if (!lib_prefix.IsNull()) { |
| 3108 // We have a library prefix qualified identifier, unless the prefix is | 3117 // We have a library prefix qualified identifier, unless the prefix is |
| 3109 // shadowed by a type parameter in scope. | 3118 // shadowed by a type parameter in scope. |
| 3110 if (current_class().IsNull() || | 3119 if (current_class().IsNull() || |
| 3111 (current_class().LookupTypeParameter(*(qual_ident->ident)) == | 3120 (current_class().LookupTypeParameter(*(qual_ident->ident)) == |
| 3112 TypeParameter::null())) { | 3121 TypeParameter::null())) { |
| 3113 ConsumeToken(); // Consume the kPERIOD token. | 3122 ConsumeToken(); // Consume the kPERIOD token. |
| 3114 qual_ident->lib_prefix = &lib_prefix; | 3123 qual_ident->lib_prefix = &lib_prefix; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3211 method->name = &String::ZoneHandle(Field::SetterSymbol(*method->name)); | 3220 method->name = &String::ZoneHandle(Field::SetterSymbol(*method->name)); |
| 3212 } | 3221 } |
| 3213 if ((method->params.num_fixed_parameters != expected_num_parameters) || | 3222 if ((method->params.num_fixed_parameters != expected_num_parameters) || |
| 3214 (method->params.num_optional_parameters != 0)) { | 3223 (method->params.num_optional_parameters != 0)) { |
| 3215 ErrorMsg(method->name_pos, "illegal %s parameters", | 3224 ErrorMsg(method->name_pos, "illegal %s parameters", |
| 3216 method->IsGetter() ? "getter" : "setter"); | 3225 method->IsGetter() ? "getter" : "setter"); |
| 3217 } | 3226 } |
| 3218 } | 3227 } |
| 3219 | 3228 |
| 3220 // Parse redirecting factory constructor. | 3229 // Parse redirecting factory constructor. |
| 3221 Type& redirection_type = Type::Handle(); | 3230 Type& redirection_type = Type::Handle(isolate()); |
| 3222 String& redirection_identifier = String::Handle(); | 3231 String& redirection_identifier = String::Handle(isolate()); |
| 3223 bool is_redirecting = false; | 3232 bool is_redirecting = false; |
| 3224 if (method->IsFactory() && (CurrentToken() == Token::kASSIGN)) { | 3233 if (method->IsFactory() && (CurrentToken() == Token::kASSIGN)) { |
| 3225 // Default parameter values are disallowed in redirecting factories. | 3234 // Default parameter values are disallowed in redirecting factories. |
| 3226 if (method->params.has_explicit_default_values) { | 3235 if (method->params.has_explicit_default_values) { |
| 3227 ErrorMsg("redirecting factory '%s' may not specify default values " | 3236 ErrorMsg("redirecting factory '%s' may not specify default values " |
| 3228 "for optional parameters", | 3237 "for optional parameters", |
| 3229 method->name->ToCString()); | 3238 method->name->ToCString()); |
| 3230 } | 3239 } |
| 3231 ConsumeToken(); | 3240 ConsumeToken(); |
| 3232 const intptr_t type_pos = TokenPos(); | 3241 const intptr_t type_pos = TokenPos(); |
| 3233 is_redirecting = true; | 3242 is_redirecting = true; |
| 3234 const AbstractType& type = AbstractType::Handle( | 3243 const AbstractType& type = AbstractType::Handle(isolate(), |
| 3235 ParseType(ClassFinalizer::kResolveTypeParameters)); | 3244 ParseType(ClassFinalizer::kResolveTypeParameters)); |
| 3236 if (!type.IsMalformed() && type.IsTypeParameter()) { | 3245 if (!type.IsMalformed() && type.IsTypeParameter()) { |
| 3237 // Replace the type with a malformed type and compile a throw when called. | 3246 // Replace the type with a malformed type and compile a throw when called. |
| 3238 redirection_type = ClassFinalizer::NewFinalizedMalformedType( | 3247 redirection_type = ClassFinalizer::NewFinalizedMalformedType( |
| 3239 Error::Handle(), // No previous error. | 3248 Error::Handle(isolate()), // No previous error. |
| 3240 script_, | 3249 script_, |
| 3241 type_pos, | 3250 type_pos, |
| 3242 "factory '%s' may not redirect to type parameter '%s'", | 3251 "factory '%s' may not redirect to type parameter '%s'", |
| 3243 method->name->ToCString(), | 3252 method->name->ToCString(), |
| 3244 String::Handle(type.UserVisibleName()).ToCString()); | 3253 String::Handle(isolate(), type.UserVisibleName()).ToCString()); |
| 3245 } else { | 3254 } else { |
| 3246 // We handle malformed and malbounded redirection type at run time. | 3255 // We handle malformed and malbounded redirection type at run time. |
| 3247 redirection_type ^= type.raw(); | 3256 redirection_type ^= type.raw(); |
| 3248 } | 3257 } |
| 3249 if (CurrentToken() == Token::kPERIOD) { | 3258 if (CurrentToken() == Token::kPERIOD) { |
| 3250 // Named constructor or factory. | 3259 // Named constructor or factory. |
| 3251 ConsumeToken(); | 3260 ConsumeToken(); |
| 3252 redirection_identifier = ExpectIdentifier("identifier expected")->raw(); | 3261 redirection_identifier = ExpectIdentifier("identifier expected")->raw(); |
| 3253 } | 3262 } |
| 3254 } else if (CurrentToken() == Token::kCOLON) { | 3263 } else if (CurrentToken() == Token::kCOLON) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3380 RawFunction::Kind function_kind; | 3389 RawFunction::Kind function_kind; |
| 3381 if (method->IsFactoryOrConstructor()) { | 3390 if (method->IsFactoryOrConstructor()) { |
| 3382 function_kind = RawFunction::kConstructor; | 3391 function_kind = RawFunction::kConstructor; |
| 3383 } else if (method->IsGetter()) { | 3392 } else if (method->IsGetter()) { |
| 3384 function_kind = RawFunction::kGetterFunction; | 3393 function_kind = RawFunction::kGetterFunction; |
| 3385 } else if (method->IsSetter()) { | 3394 } else if (method->IsSetter()) { |
| 3386 function_kind = RawFunction::kSetterFunction; | 3395 function_kind = RawFunction::kSetterFunction; |
| 3387 } else { | 3396 } else { |
| 3388 function_kind = RawFunction::kRegularFunction; | 3397 function_kind = RawFunction::kRegularFunction; |
| 3389 } | 3398 } |
| 3390 Function& func = Function::Handle( | 3399 Function& func = Function::Handle(isolate(), |
| 3391 Function::New(*method->name, | 3400 Function::New(*method->name, |
| 3392 function_kind, | 3401 function_kind, |
| 3393 method->has_static, | 3402 method->has_static, |
| 3394 method->has_const, | 3403 method->has_const, |
| 3395 method->has_abstract, | 3404 method->has_abstract, |
| 3396 method->has_external, | 3405 method->has_external, |
| 3397 method->has_native, | 3406 method->has_native, |
| 3398 current_class(), | 3407 current_class(), |
| 3399 method->decl_begin_pos)); | 3408 method->decl_begin_pos)); |
| 3400 func.set_result_type(*method->type); | 3409 func.set_result_type(*method->type); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3446 } | 3455 } |
| 3447 if (field->has_external) { | 3456 if (field->has_external) { |
| 3448 ErrorMsg("keyword 'external' not allowed in field declaration"); | 3457 ErrorMsg("keyword 'external' not allowed in field declaration"); |
| 3449 } | 3458 } |
| 3450 if (field->has_factory) { | 3459 if (field->has_factory) { |
| 3451 ErrorMsg("keyword 'factory' not allowed in field declaration"); | 3460 ErrorMsg("keyword 'factory' not allowed in field declaration"); |
| 3452 } | 3461 } |
| 3453 if (!field->has_static && field->has_const) { | 3462 if (!field->has_static && field->has_const) { |
| 3454 ErrorMsg(field->name_pos, "instance field may not be 'const'"); | 3463 ErrorMsg(field->name_pos, "instance field may not be 'const'"); |
| 3455 } | 3464 } |
| 3456 Function& getter = Function::Handle(); | 3465 Function& getter = Function::Handle(isolate()); |
| 3457 Function& setter = Function::Handle(); | 3466 Function& setter = Function::Handle(isolate()); |
| 3458 Field& class_field = Field::ZoneHandle(); | 3467 Field& class_field = Field::ZoneHandle(); |
| 3459 Instance& init_value = Instance::Handle(); | 3468 Instance& init_value = Instance::Handle(isolate()); |
| 3460 while (true) { | 3469 while (true) { |
| 3461 bool has_initializer = CurrentToken() == Token::kASSIGN; | 3470 bool has_initializer = CurrentToken() == Token::kASSIGN; |
| 3462 bool has_simple_literal = false; | 3471 bool has_simple_literal = false; |
| 3463 if (has_initializer) { | 3472 if (has_initializer) { |
| 3464 ConsumeToken(); | 3473 ConsumeToken(); |
| 3465 init_value = Object::sentinel().raw(); | 3474 init_value = Object::sentinel().raw(); |
| 3466 // For static fields, the initialization expression will be parsed | 3475 // For static fields, the initialization expression will be parsed |
| 3467 // through the kImplicitStaticFinalGetter method invocation/compilation. | 3476 // through the kImplicitStaticFinalGetter method invocation/compilation. |
| 3468 // For instance fields, the expression is parsed when a constructor | 3477 // For instance fields, the expression is parsed when a constructor |
| 3469 // is compiled. | 3478 // is compiled. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3503 field->field_ = &class_field; | 3512 field->field_ = &class_field; |
| 3504 if (field->metadata_pos >= 0) { | 3513 if (field->metadata_pos >= 0) { |
| 3505 library_.AddFieldMetadata(class_field, field->metadata_pos); | 3514 library_.AddFieldMetadata(class_field, field->metadata_pos); |
| 3506 } | 3515 } |
| 3507 | 3516 |
| 3508 // For static final fields (this includes static const fields), set value to | 3517 // For static final fields (this includes static const fields), set value to |
| 3509 // "uninitialized" and create a kImplicitStaticFinalGetter getter method. | 3518 // "uninitialized" and create a kImplicitStaticFinalGetter getter method. |
| 3510 if (field->has_static && has_initializer) { | 3519 if (field->has_static && has_initializer) { |
| 3511 class_field.set_value(init_value); | 3520 class_field.set_value(init_value); |
| 3512 if (!has_simple_literal) { | 3521 if (!has_simple_literal) { |
| 3513 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); | 3522 String& getter_name = String::Handle(isolate(), |
| 3523 Field::GetterSymbol(*field->name)); | |
| 3514 getter = Function::New(getter_name, | 3524 getter = Function::New(getter_name, |
| 3515 RawFunction::kImplicitStaticFinalGetter, | 3525 RawFunction::kImplicitStaticFinalGetter, |
| 3516 field->has_static, | 3526 field->has_static, |
| 3517 field->has_const, | 3527 field->has_const, |
| 3518 /* is_abstract = */ false, | 3528 /* is_abstract = */ false, |
| 3519 /* is_external = */ false, | 3529 /* is_external = */ false, |
| 3520 /* is_native = */ false, | 3530 /* is_native = */ false, |
| 3521 current_class(), | 3531 current_class(), |
| 3522 field->name_pos); | 3532 field->name_pos); |
| 3523 getter.set_result_type(*field->type); | 3533 getter.set_result_type(*field->type); |
| 3524 members->AddFunction(getter); | 3534 members->AddFunction(getter); |
| 3525 | 3535 |
| 3526 // Create initializer function for non-const fields. | 3536 // Create initializer function for non-const fields. |
| 3527 if (!class_field.is_const()) { | 3537 if (!class_field.is_const()) { |
| 3528 const Function& init_function = Function::ZoneHandle( | 3538 const Function& init_function = Function::ZoneHandle( |
| 3529 Function::NewStaticInitializer(class_field)); | 3539 Function::NewStaticInitializer(class_field)); |
| 3530 members->AddFunction(init_function); | 3540 members->AddFunction(init_function); |
| 3531 } | 3541 } |
| 3532 } | 3542 } |
| 3533 } | 3543 } |
| 3534 | 3544 |
| 3535 // For instance fields, we create implicit getter and setter methods. | 3545 // For instance fields, we create implicit getter and setter methods. |
| 3536 if (!field->has_static) { | 3546 if (!field->has_static) { |
| 3537 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); | 3547 String& getter_name = String::Handle(isolate(), |
| 3548 Field::GetterSymbol(*field->name)); | |
| 3538 getter = Function::New(getter_name, RawFunction::kImplicitGetter, | 3549 getter = Function::New(getter_name, RawFunction::kImplicitGetter, |
| 3539 field->has_static, | 3550 field->has_static, |
| 3540 field->has_final, | 3551 field->has_final, |
| 3541 /* is_abstract = */ false, | 3552 /* is_abstract = */ false, |
| 3542 /* is_external = */ false, | 3553 /* is_external = */ false, |
| 3543 /* is_native = */ false, | 3554 /* is_native = */ false, |
| 3544 current_class(), | 3555 current_class(), |
| 3545 field->name_pos); | 3556 field->name_pos); |
| 3546 ParamList params; | 3557 ParamList params; |
| 3547 ASSERT(current_class().raw() == getter.Owner()); | 3558 ASSERT(current_class().raw() == getter.Owner()); |
| 3548 params.AddReceiver(ReceiverType(current_class()), field->name_pos); | 3559 params.AddReceiver(ReceiverType(current_class()), field->name_pos); |
| 3549 getter.set_result_type(*field->type); | 3560 getter.set_result_type(*field->type); |
| 3550 AddFormalParamsToFunction(¶ms, getter); | 3561 AddFormalParamsToFunction(¶ms, getter); |
| 3551 members->AddFunction(getter); | 3562 members->AddFunction(getter); |
| 3552 if (!field->has_final) { | 3563 if (!field->has_final) { |
| 3553 // Build a setter accessor for non-const fields. | 3564 // Build a setter accessor for non-const fields. |
| 3554 String& setter_name = String::Handle(Field::SetterSymbol(*field->name)); | 3565 String& setter_name = String::Handle(isolate(), |
| 3566 Field::SetterSymbol(*field->name)); | |
| 3555 setter = Function::New(setter_name, RawFunction::kImplicitSetter, | 3567 setter = Function::New(setter_name, RawFunction::kImplicitSetter, |
| 3556 field->has_static, | 3568 field->has_static, |
| 3557 field->has_final, | 3569 field->has_final, |
| 3558 /* is_abstract = */ false, | 3570 /* is_abstract = */ false, |
| 3559 /* is_external = */ false, | 3571 /* is_external = */ false, |
| 3560 /* is_native = */ false, | 3572 /* is_native = */ false, |
| 3561 current_class(), | 3573 current_class(), |
| 3562 field->name_pos); | 3574 field->name_pos); |
| 3563 ParamList params; | 3575 ParamList params; |
| 3564 ASSERT(current_class().raw() == setter.Owner()); | 3576 ASSERT(current_class().raw() == setter.Owner()); |
| 3565 params.AddReceiver(ReceiverType(current_class()), field->name_pos); | 3577 params.AddReceiver(ReceiverType(current_class()), field->name_pos); |
| 3566 params.AddFinalParameter(TokenPos(), | 3578 params.AddFinalParameter(TokenPos(), |
| 3567 &Symbols::Value(), | 3579 &Symbols::Value(), |
| 3568 field->type); | 3580 field->type); |
| 3569 setter.set_result_type(Type::Handle(Type::VoidType())); | 3581 setter.set_result_type(Type::Handle(isolate(), Type::VoidType())); |
| 3570 AddFormalParamsToFunction(¶ms, setter); | 3582 AddFormalParamsToFunction(¶ms, setter); |
| 3571 members->AddFunction(setter); | 3583 members->AddFunction(setter); |
| 3572 } | 3584 } |
| 3573 } | 3585 } |
| 3574 | 3586 |
| 3575 if (CurrentToken() != Token::kCOMMA) { | 3587 if (CurrentToken() != Token::kCOMMA) { |
| 3576 break; | 3588 break; |
| 3577 } | 3589 } |
| 3578 ConsumeToken(); | 3590 ConsumeToken(); |
| 3579 field->name_pos = this->TokenPos(); | 3591 field->name_pos = this->TokenPos(); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3723 members->class_name().ToCString()); | 3735 members->class_name().ToCString()); |
| 3724 } | 3736 } |
| 3725 } else if (member.has_static) { | 3737 } else if (member.has_static) { |
| 3726 ErrorMsg(member.name_pos, "constructor cannot be static"); | 3738 ErrorMsg(member.name_pos, "constructor cannot be static"); |
| 3727 } | 3739 } |
| 3728 if (member.type != NULL) { | 3740 if (member.type != NULL) { |
| 3729 ErrorMsg(member.name_pos, "constructor must not specify return type"); | 3741 ErrorMsg(member.name_pos, "constructor must not specify return type"); |
| 3730 } | 3742 } |
| 3731 // Do not bypass class resolution by using current_class() directly, since | 3743 // Do not bypass class resolution by using current_class() directly, since |
| 3732 // it may be a patch class. | 3744 // it may be a patch class. |
| 3733 const Object& result_type_class = Object::Handle( | 3745 const Object& result_type_class = Object::Handle(isolate(), |
| 3734 UnresolvedClass::New(LibraryPrefix::Handle(), | 3746 UnresolvedClass::New(LibraryPrefix::Handle(isolate()), |
| 3735 *member.name, | 3747 *member.name, |
| 3736 member.name_pos)); | 3748 member.name_pos)); |
| 3737 // The type arguments of the result type are the type parameters of the | 3749 // The type arguments of the result type are the type parameters of the |
| 3738 // current class. Note that in the case of a patch class, they are copied | 3750 // current class. Note that in the case of a patch class, they are copied |
| 3739 // from the class being patched. | 3751 // from the class being patched. |
| 3740 member.type = &Type::ZoneHandle(Type::New( | 3752 member.type = &Type::ZoneHandle(Type::New( |
| 3741 result_type_class, | 3753 result_type_class, |
| 3742 TypeArguments::Handle(current_class().type_parameters()), | 3754 TypeArguments::Handle(isolate(), current_class().type_parameters()), |
| 3743 member.name_pos)); | 3755 member.name_pos)); |
| 3744 | 3756 |
| 3745 // We must be dealing with a constructor or named constructor. | 3757 // We must be dealing with a constructor or named constructor. |
| 3746 member.kind = RawFunction::kConstructor; | 3758 member.kind = RawFunction::kConstructor; |
| 3747 *member.name = String::Concat(*member.name, Symbols::Dot()); | 3759 *member.name = String::Concat(*member.name, Symbols::Dot()); |
| 3748 if (CurrentToken() == Token::kPERIOD) { | 3760 if (CurrentToken() == Token::kPERIOD) { |
| 3749 // Named constructor. | 3761 // Named constructor. |
| 3750 ConsumeToken(); | 3762 ConsumeToken(); |
| 3751 member.dict_name = ExpectIdentifier("identifier expected"); | 3763 member.dict_name = ExpectIdentifier("identifier expected"); |
| 3752 *member.name = String::Concat(*member.name, *member.dict_name); | 3764 *member.name = String::Concat(*member.name, *member.dict_name); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3855 } else if (CurrentToken() == Token::kABSTRACT) { | 3867 } else if (CurrentToken() == Token::kABSTRACT) { |
| 3856 is_abstract = true; | 3868 is_abstract = true; |
| 3857 ConsumeToken(); | 3869 ConsumeToken(); |
| 3858 } | 3870 } |
| 3859 ExpectToken(Token::kCLASS); | 3871 ExpectToken(Token::kCLASS); |
| 3860 const intptr_t classname_pos = TokenPos(); | 3872 const intptr_t classname_pos = TokenPos(); |
| 3861 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected"); | 3873 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected"); |
| 3862 if (FLAG_trace_parser) { | 3874 if (FLAG_trace_parser) { |
| 3863 OS::Print("TopLevel parsing class '%s'\n", class_name.ToCString()); | 3875 OS::Print("TopLevel parsing class '%s'\n", class_name.ToCString()); |
| 3864 } | 3876 } |
| 3865 Class& cls = Class::Handle(); | 3877 Class& cls = Class::Handle(isolate()); |
| 3866 TypeArguments& orig_type_parameters = TypeArguments::Handle(); | 3878 TypeArguments& orig_type_parameters = TypeArguments::Handle(isolate()); |
| 3867 Object& obj = Object::Handle(library_.LookupLocalObject(class_name)); | 3879 Object& obj = Object::Handle(isolate(), |
| 3880 library_.LookupLocalObject(class_name)); | |
| 3868 if (obj.IsNull()) { | 3881 if (obj.IsNull()) { |
| 3869 if (is_patch) { | 3882 if (is_patch) { |
| 3870 ErrorMsg(classname_pos, "missing class '%s' cannot be patched", | 3883 ErrorMsg(classname_pos, "missing class '%s' cannot be patched", |
| 3871 class_name.ToCString()); | 3884 class_name.ToCString()); |
| 3872 } | 3885 } |
| 3873 cls = Class::New(class_name, script_, classname_pos); | 3886 cls = Class::New(class_name, script_, classname_pos); |
| 3874 library_.AddClass(cls); | 3887 library_.AddClass(cls); |
| 3875 } else { | 3888 } else { |
| 3876 if (!obj.IsClass()) { | 3889 if (!obj.IsClass()) { |
| 3877 ErrorMsg(classname_pos, "'%s' is already defined", | 3890 ErrorMsg(classname_pos, "'%s' is already defined", |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 3901 cls.set_token_pos(classname_pos); | 3914 cls.set_token_pos(classname_pos); |
| 3902 } | 3915 } |
| 3903 } | 3916 } |
| 3904 ASSERT(!cls.IsNull()); | 3917 ASSERT(!cls.IsNull()); |
| 3905 ASSERT(cls.functions() == Object::empty_array().raw()); | 3918 ASSERT(cls.functions() == Object::empty_array().raw()); |
| 3906 set_current_class(cls); | 3919 set_current_class(cls); |
| 3907 ParseTypeParameters(cls); | 3920 ParseTypeParameters(cls); |
| 3908 if (is_patch) { | 3921 if (is_patch) { |
| 3909 // Check that the new type parameters are identical to the original ones. | 3922 // Check that the new type parameters are identical to the original ones. |
| 3910 const TypeArguments& new_type_parameters = | 3923 const TypeArguments& new_type_parameters = |
| 3911 TypeArguments::Handle(cls.type_parameters()); | 3924 TypeArguments::Handle(isolate(), cls.type_parameters()); |
| 3912 const int new_type_params_count = | 3925 const int new_type_params_count = |
| 3913 new_type_parameters.IsNull() ? 0 : new_type_parameters.Length(); | 3926 new_type_parameters.IsNull() ? 0 : new_type_parameters.Length(); |
| 3914 const int orig_type_params_count = | 3927 const int orig_type_params_count = |
| 3915 orig_type_parameters.IsNull() ? 0 : orig_type_parameters.Length(); | 3928 orig_type_parameters.IsNull() ? 0 : orig_type_parameters.Length(); |
| 3916 if (new_type_params_count != orig_type_params_count) { | 3929 if (new_type_params_count != orig_type_params_count) { |
| 3917 ErrorMsg(classname_pos, | 3930 ErrorMsg(classname_pos, |
| 3918 "class '%s' must be patched with identical type parameters", | 3931 "class '%s' must be patched with identical type parameters", |
| 3919 class_name.ToCString()); | 3932 class_name.ToCString()); |
| 3920 } | 3933 } |
| 3921 TypeParameter& new_type_param = TypeParameter::Handle(); | 3934 TypeParameter& new_type_param = TypeParameter::Handle(isolate()); |
| 3922 TypeParameter& orig_type_param = TypeParameter::Handle(); | 3935 TypeParameter& orig_type_param = TypeParameter::Handle(isolate()); |
| 3923 String& new_name = String::Handle(); | 3936 String& new_name = String::Handle(isolate()); |
| 3924 String& orig_name = String::Handle(); | 3937 String& orig_name = String::Handle(isolate()); |
| 3925 for (int i = 0; i < new_type_params_count; i++) { | 3938 for (int i = 0; i < new_type_params_count; i++) { |
| 3926 new_type_param ^= new_type_parameters.TypeAt(i); | 3939 new_type_param ^= new_type_parameters.TypeAt(i); |
| 3927 orig_type_param ^= orig_type_parameters.TypeAt(i); | 3940 orig_type_param ^= orig_type_parameters.TypeAt(i); |
| 3928 new_name = new_type_param.name(); | 3941 new_name = new_type_param.name(); |
| 3929 orig_name = orig_type_param.name(); | 3942 orig_name = orig_type_param.name(); |
| 3930 if (!new_name.Equals(orig_name)) { | 3943 if (!new_name.Equals(orig_name)) { |
| 3931 ErrorMsg(new_type_param.token_pos(), | 3944 ErrorMsg(new_type_param.token_pos(), |
| 3932 "type parameter '%s' of patch class '%s' does not match " | 3945 "type parameter '%s' of patch class '%s' does not match " |
| 3933 "original type parameter '%s'", | 3946 "original type parameter '%s'", |
| 3934 new_name.ToCString(), | 3947 new_name.ToCString(), |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 3948 library_.AddClassMetadata(cls, toplevel_class, metadata_pos); | 3961 library_.AddClassMetadata(cls, toplevel_class, metadata_pos); |
| 3949 } | 3962 } |
| 3950 | 3963 |
| 3951 const bool is_mixin_declaration = (CurrentToken() == Token::kASSIGN); | 3964 const bool is_mixin_declaration = (CurrentToken() == Token::kASSIGN); |
| 3952 if (is_mixin_declaration && is_patch) { | 3965 if (is_mixin_declaration && is_patch) { |
| 3953 ErrorMsg(classname_pos, | 3966 ErrorMsg(classname_pos, |
| 3954 "mixin application '%s' may not be a patch class", | 3967 "mixin application '%s' may not be a patch class", |
| 3955 class_name.ToCString()); | 3968 class_name.ToCString()); |
| 3956 } | 3969 } |
| 3957 | 3970 |
| 3958 AbstractType& super_type = Type::Handle(); | 3971 AbstractType& super_type = Type::Handle(isolate()); |
| 3959 if ((CurrentToken() == Token::kEXTENDS) || is_mixin_declaration) { | 3972 if ((CurrentToken() == Token::kEXTENDS) || is_mixin_declaration) { |
| 3960 ConsumeToken(); // extends or = | 3973 ConsumeToken(); // extends or = |
| 3961 const intptr_t type_pos = TokenPos(); | 3974 const intptr_t type_pos = TokenPos(); |
| 3962 super_type = ParseType(ClassFinalizer::kResolveTypeParameters); | 3975 super_type = ParseType(ClassFinalizer::kResolveTypeParameters); |
| 3963 if (super_type.IsMalformedOrMalbounded()) { | 3976 if (super_type.IsMalformedOrMalbounded()) { |
| 3964 ErrorMsg(Error::Handle(super_type.error())); | 3977 ErrorMsg(Error::Handle(isolate(), super_type.error())); |
| 3965 } | 3978 } |
| 3966 if (super_type.IsDynamicType()) { | 3979 if (super_type.IsDynamicType()) { |
| 3967 // Unlikely here, since super type is not resolved yet. | 3980 // Unlikely here, since super type is not resolved yet. |
| 3968 ErrorMsg(type_pos, | 3981 ErrorMsg(type_pos, |
| 3969 "class '%s' may not extend 'dynamic'", | 3982 "class '%s' may not extend 'dynamic'", |
| 3970 class_name.ToCString()); | 3983 class_name.ToCString()); |
| 3971 } | 3984 } |
| 3972 if (super_type.IsTypeParameter()) { | 3985 if (super_type.IsTypeParameter()) { |
| 3973 ErrorMsg(type_pos, | 3986 ErrorMsg(type_pos, |
| 3974 "class '%s' may not extend type parameter '%s'", | 3987 "class '%s' may not extend type parameter '%s'", |
| 3975 class_name.ToCString(), | 3988 class_name.ToCString(), |
| 3976 String::Handle(super_type.UserVisibleName()).ToCString()); | 3989 String::Handle(isolate(), |
| 3990 super_type.UserVisibleName()).ToCString()); | |
| 3977 } | 3991 } |
| 3978 // The class finalizer will check whether the super type is malbounded. | 3992 // The class finalizer will check whether the super type is malbounded. |
| 3979 if (is_mixin_declaration) { | 3993 if (is_mixin_declaration) { |
| 3980 if (CurrentToken() != Token::kWITH) { | 3994 if (CurrentToken() != Token::kWITH) { |
| 3981 ErrorMsg("mixin application clause 'with type' expected"); | 3995 ErrorMsg("mixin application clause 'with type' expected"); |
| 3982 } | 3996 } |
| 3983 cls.set_is_mixin_app_alias(); | 3997 cls.set_is_mixin_app_alias(); |
| 3984 cls.set_is_synthesized_class(); | 3998 cls.set_is_synthesized_class(); |
| 3985 } | 3999 } |
| 3986 if (CurrentToken() == Token::kWITH) { | 4000 if (CurrentToken() == Token::kWITH) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4018 ExpectToken(Token::kRBRACE); | 4032 ExpectToken(Token::kRBRACE); |
| 4019 } | 4033 } |
| 4020 } | 4034 } |
| 4021 | 4035 |
| 4022 | 4036 |
| 4023 void Parser::ParseClassDefinition(const Class& cls) { | 4037 void Parser::ParseClassDefinition(const Class& cls) { |
| 4024 TRACE_PARSER("ParseClassDefinition"); | 4038 TRACE_PARSER("ParseClassDefinition"); |
| 4025 CompilerStats::num_classes_compiled++; | 4039 CompilerStats::num_classes_compiled++; |
| 4026 set_current_class(cls); | 4040 set_current_class(cls); |
| 4027 is_top_level_ = true; | 4041 is_top_level_ = true; |
| 4028 String& class_name = String::Handle(cls.Name()); | 4042 String& class_name = String::Handle(isolate(), cls.Name()); |
| 4029 const intptr_t class_pos = TokenPos(); | 4043 const intptr_t class_pos = TokenPos(); |
| 4030 ClassDesc members(cls, class_name, false, class_pos); | 4044 ClassDesc members(cls, class_name, false, class_pos); |
| 4031 while (CurrentToken() != Token::kLBRACE) { | 4045 while (CurrentToken() != Token::kLBRACE) { |
| 4032 ConsumeToken(); | 4046 ConsumeToken(); |
| 4033 } | 4047 } |
| 4034 ExpectToken(Token::kLBRACE); | 4048 ExpectToken(Token::kLBRACE); |
| 4035 while (CurrentToken() != Token::kRBRACE) { | 4049 while (CurrentToken() != Token::kRBRACE) { |
| 4036 intptr_t metadata_pos = SkipMetadata(); | 4050 intptr_t metadata_pos = SkipMetadata(); |
| 4037 ParseClassMemberDefinition(&members, metadata_pos); | 4051 ParseClassMemberDefinition(&members, metadata_pos); |
| 4038 } | 4052 } |
| 4039 ExpectToken(Token::kRBRACE); | 4053 ExpectToken(Token::kRBRACE); |
| 4040 | 4054 |
| 4041 CheckConstructors(&members); | 4055 CheckConstructors(&members); |
| 4042 | 4056 |
| 4043 // Need to compute this here since MakeArray() will clear the | 4057 // Need to compute this here since MakeArray() will clear the |
| 4044 // functions array in members. | 4058 // functions array in members. |
| 4045 const bool need_implicit_constructor = | 4059 const bool need_implicit_constructor = |
| 4046 !members.has_constructor() && !cls.is_patch(); | 4060 !members.has_constructor() && !cls.is_patch(); |
| 4047 | 4061 |
| 4048 cls.AddFields(members.fields()); | 4062 cls.AddFields(members.fields()); |
| 4049 | 4063 |
| 4050 // Creating a new array for functions marks the class as parsed. | 4064 // Creating a new array for functions marks the class as parsed. |
| 4051 const Array& array = Array::Handle(Array::MakeArray(members.functions())); | 4065 const Array& array = Array::Handle(isolate(), |
| 4066 Array::MakeArray(members.functions())); | |
| 4052 cls.SetFunctions(array); | 4067 cls.SetFunctions(array); |
| 4053 | 4068 |
| 4054 // Add an implicit constructor if no explicit constructor is present. | 4069 // Add an implicit constructor if no explicit constructor is present. |
| 4055 // No implicit constructors are needed for patch classes. | 4070 // No implicit constructors are needed for patch classes. |
| 4056 if (need_implicit_constructor) { | 4071 if (need_implicit_constructor) { |
| 4057 AddImplicitConstructor(cls); | 4072 AddImplicitConstructor(cls); |
| 4058 } | 4073 } |
| 4059 | 4074 |
| 4060 if (cls.is_patch()) { | 4075 if (cls.is_patch()) { |
| 4061 // Apply the changes to the patched class looked up above. | 4076 // Apply the changes to the patched class looked up above. |
| 4062 Object& obj = Object::Handle(library_.LookupLocalObject(class_name)); | 4077 Object& obj = Object::Handle(isolate(), |
| 4078 library_.LookupLocalObject(class_name)); | |
| 4063 // The patched class must not be finalized yet. | 4079 // The patched class must not be finalized yet. |
| 4064 const Class& orig_class = Class::Cast(obj); | 4080 const Class& orig_class = Class::Cast(obj); |
| 4065 ASSERT(!orig_class.is_finalized()); | 4081 ASSERT(!orig_class.is_finalized()); |
| 4066 Error& error = Error::Handle(); | 4082 Error& error = Error::Handle(isolate()); |
| 4067 if (!orig_class.ApplyPatch(cls, &error)) { | 4083 if (!orig_class.ApplyPatch(cls, &error)) { |
| 4068 AppendErrorMsg(error, class_pos, "applying patch failed"); | 4084 AppendErrorMsg(error, class_pos, "applying patch failed"); |
| 4069 } | 4085 } |
| 4070 } | 4086 } |
| 4071 } | 4087 } |
| 4072 | 4088 |
| 4073 | 4089 |
| 4074 // Add an implicit constructor to the given class. | 4090 // Add an implicit constructor to the given class. |
| 4075 void Parser::AddImplicitConstructor(const Class& cls) { | 4091 void Parser::AddImplicitConstructor(const Class& cls) { |
| 4076 // The implicit constructor is unnamed, has no explicit parameter. | 4092 // The implicit constructor is unnamed, has no explicit parameter. |
| 4077 String& ctor_name = String::ZoneHandle(cls.Name()); | 4093 String& ctor_name = String::ZoneHandle(cls.Name()); |
| 4078 ctor_name = String::Concat(ctor_name, Symbols::Dot()); | 4094 ctor_name = String::Concat(ctor_name, Symbols::Dot()); |
| 4079 ctor_name = Symbols::New(ctor_name); | 4095 ctor_name = Symbols::New(ctor_name); |
| 4080 // To indicate that this is an implicit constructor, we set the | 4096 // To indicate that this is an implicit constructor, we set the |
| 4081 // token position and end token position of the function | 4097 // token position and end token position of the function |
| 4082 // to the token position of the class. | 4098 // to the token position of the class. |
| 4083 Function& ctor = Function::Handle( | 4099 Function& ctor = Function::Handle(isolate(), |
| 4084 Function::New(ctor_name, | 4100 Function::New(ctor_name, |
| 4085 RawFunction::kConstructor, | 4101 RawFunction::kConstructor, |
| 4086 /* is_static = */ false, | 4102 /* is_static = */ false, |
| 4087 /* is_const = */ false, | 4103 /* is_const = */ false, |
| 4088 /* is_abstract = */ false, | 4104 /* is_abstract = */ false, |
| 4089 /* is_external = */ false, | 4105 /* is_external = */ false, |
| 4090 /* is_native = */ false, | 4106 /* is_native = */ false, |
| 4091 cls, | 4107 cls, |
| 4092 cls.token_pos())); | 4108 cls.token_pos())); |
| 4093 ctor.set_end_token_pos(ctor.token_pos()); | 4109 ctor.set_end_token_pos(ctor.token_pos()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4147 const GrowableObjectArray& pending_classes, | 4163 const GrowableObjectArray& pending_classes, |
| 4148 const Class& toplevel_class, | 4164 const Class& toplevel_class, |
| 4149 intptr_t metadata_pos) { | 4165 intptr_t metadata_pos) { |
| 4150 TRACE_PARSER("ParseMixinAppAlias"); | 4166 TRACE_PARSER("ParseMixinAppAlias"); |
| 4151 const intptr_t classname_pos = TokenPos(); | 4167 const intptr_t classname_pos = TokenPos(); |
| 4152 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected"); | 4168 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected"); |
| 4153 if (FLAG_trace_parser) { | 4169 if (FLAG_trace_parser) { |
| 4154 OS::Print("toplevel parsing mixin application alias class '%s'\n", | 4170 OS::Print("toplevel parsing mixin application alias class '%s'\n", |
| 4155 class_name.ToCString()); | 4171 class_name.ToCString()); |
| 4156 } | 4172 } |
| 4157 const Object& obj = Object::Handle(library_.LookupLocalObject(class_name)); | 4173 const Object& obj = Object::Handle(isolate(), |
| 4174 library_.LookupLocalObject(class_name)); | |
| 4158 if (!obj.IsNull()) { | 4175 if (!obj.IsNull()) { |
| 4159 ErrorMsg(classname_pos, "'%s' is already defined", | 4176 ErrorMsg(classname_pos, "'%s' is already defined", |
| 4160 class_name.ToCString()); | 4177 class_name.ToCString()); |
| 4161 } | 4178 } |
| 4162 const Class& mixin_application = | 4179 const Class& mixin_application = |
| 4163 Class::Handle(Class::New(class_name, script_, classname_pos)); | 4180 Class::Handle(isolate(), Class::New(class_name, script_, classname_pos)); |
| 4164 mixin_application.set_is_mixin_app_alias(); | 4181 mixin_application.set_is_mixin_app_alias(); |
| 4165 library_.AddClass(mixin_application); | 4182 library_.AddClass(mixin_application); |
| 4166 set_current_class(mixin_application); | 4183 set_current_class(mixin_application); |
| 4167 ParseTypeParameters(mixin_application); | 4184 ParseTypeParameters(mixin_application); |
| 4168 | 4185 |
| 4169 ExpectToken(Token::kASSIGN); | 4186 ExpectToken(Token::kASSIGN); |
| 4170 | 4187 |
| 4171 if (CurrentToken() == Token::kABSTRACT) { | 4188 if (CurrentToken() == Token::kABSTRACT) { |
| 4172 mixin_application.set_is_abstract(); | 4189 mixin_application.set_is_abstract(); |
| 4173 ConsumeToken(); | 4190 ConsumeToken(); |
| 4174 } | 4191 } |
| 4175 | 4192 |
| 4176 const intptr_t type_pos = TokenPos(); | 4193 const intptr_t type_pos = TokenPos(); |
| 4177 AbstractType& type = | 4194 AbstractType& type = |
| 4178 AbstractType::Handle(ParseType(ClassFinalizer::kResolveTypeParameters)); | 4195 AbstractType::Handle(isolate(), |
| 4196 ParseType(ClassFinalizer::kResolveTypeParameters)); | |
| 4179 if (type.IsTypeParameter()) { | 4197 if (type.IsTypeParameter()) { |
| 4180 ErrorMsg(type_pos, | 4198 ErrorMsg(type_pos, |
| 4181 "class '%s' may not extend type parameter '%s'", | 4199 "class '%s' may not extend type parameter '%s'", |
| 4182 class_name.ToCString(), | 4200 class_name.ToCString(), |
| 4183 String::Handle(type.UserVisibleName()).ToCString()); | 4201 String::Handle(isolate(), type.UserVisibleName()).ToCString()); |
| 4184 } | 4202 } |
| 4185 | 4203 |
| 4186 CheckToken(Token::kWITH, "mixin application 'with Type' expected"); | 4204 CheckToken(Token::kWITH, "mixin application 'with Type' expected"); |
| 4187 type = ParseMixins(type); | 4205 type = ParseMixins(type); |
| 4188 | 4206 |
| 4189 mixin_application.set_super_type(type); | 4207 mixin_application.set_super_type(type); |
| 4190 mixin_application.set_is_synthesized_class(); | 4208 mixin_application.set_is_synthesized_class(); |
| 4191 | 4209 |
| 4192 // This mixin application alias needs an implicit constructor, but it is | 4210 // This mixin application alias needs an implicit constructor, but it is |
| 4193 // too early to call 'AddImplicitConstructor(mixin_application)' here, | 4211 // too early to call 'AddImplicitConstructor(mixin_application)' here, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4251 | 4269 |
| 4252 if (IsMixinAppAlias()) { | 4270 if (IsMixinAppAlias()) { |
| 4253 if (FLAG_warn_mixin_typedef) { | 4271 if (FLAG_warn_mixin_typedef) { |
| 4254 Warning("deprecated mixin application typedef"); | 4272 Warning("deprecated mixin application typedef"); |
| 4255 } | 4273 } |
| 4256 ParseMixinAppAlias(pending_classes, toplevel_class, metadata_pos); | 4274 ParseMixinAppAlias(pending_classes, toplevel_class, metadata_pos); |
| 4257 return; | 4275 return; |
| 4258 } | 4276 } |
| 4259 | 4277 |
| 4260 // Parse the result type of the function type. | 4278 // Parse the result type of the function type. |
| 4261 AbstractType& result_type = Type::Handle(Type::DynamicType()); | 4279 AbstractType& result_type = Type::Handle(isolate(), Type::DynamicType()); |
| 4262 if (CurrentToken() == Token::kVOID) { | 4280 if (CurrentToken() == Token::kVOID) { |
| 4263 ConsumeToken(); | 4281 ConsumeToken(); |
| 4264 result_type = Type::VoidType(); | 4282 result_type = Type::VoidType(); |
| 4265 } else if (!IsFunctionTypeAliasName()) { | 4283 } else if (!IsFunctionTypeAliasName()) { |
| 4266 // Type annotations in typedef are never ignored, even in production mode. | 4284 // Type annotations in typedef are never ignored, even in production mode. |
| 4267 // Wait until we have an owner class before resolving the result type. | 4285 // Wait until we have an owner class before resolving the result type. |
| 4268 result_type = ParseType(ClassFinalizer::kDoNotResolve); | 4286 result_type = ParseType(ClassFinalizer::kDoNotResolve); |
| 4269 } | 4287 } |
| 4270 | 4288 |
| 4271 const intptr_t alias_name_pos = TokenPos(); | 4289 const intptr_t alias_name_pos = TokenPos(); |
| 4272 const String* alias_name = | 4290 const String* alias_name = |
| 4273 ExpectUserDefinedTypeIdentifier("function alias name expected"); | 4291 ExpectUserDefinedTypeIdentifier("function alias name expected"); |
| 4274 | 4292 |
| 4275 // Lookup alias name and report an error if it is already defined in | 4293 // Lookup alias name and report an error if it is already defined in |
| 4276 // the library scope. | 4294 // the library scope. |
| 4277 const Object& obj = Object::Handle(library_.LookupLocalObject(*alias_name)); | 4295 const Object& obj = Object::Handle(isolate(), |
| 4296 library_.LookupLocalObject(*alias_name)); | |
| 4278 if (!obj.IsNull()) { | 4297 if (!obj.IsNull()) { |
| 4279 ErrorMsg(alias_name_pos, | 4298 ErrorMsg(alias_name_pos, |
| 4280 "'%s' is already defined", alias_name->ToCString()); | 4299 "'%s' is already defined", alias_name->ToCString()); |
| 4281 } | 4300 } |
| 4282 | 4301 |
| 4283 // Create the function type alias signature class. It will be linked to its | 4302 // Create the function type alias signature class. It will be linked to its |
| 4284 // signature function after it has been parsed. The type parameters, in order | 4303 // signature function after it has been parsed. The type parameters, in order |
| 4285 // to be properly finalized, need to be associated to this signature class as | 4304 // to be properly finalized, need to be associated to this signature class as |
| 4286 // they are parsed. | 4305 // they are parsed. |
| 4287 const Class& function_type_alias = Class::Handle( | 4306 const Class& function_type_alias = Class::Handle(isolate(), |
| 4288 Class::NewSignatureClass(*alias_name, | 4307 Class::NewSignatureClass(*alias_name, |
| 4289 Function::Handle(), | 4308 Function::Handle(isolate()), |
| 4290 script_, | 4309 script_, |
| 4291 alias_name_pos)); | 4310 alias_name_pos)); |
| 4292 library_.AddClass(function_type_alias); | 4311 library_.AddClass(function_type_alias); |
| 4293 set_current_class(function_type_alias); | 4312 set_current_class(function_type_alias); |
| 4294 // Parse the type parameters of the function type. | 4313 // Parse the type parameters of the function type. |
| 4295 ParseTypeParameters(function_type_alias); | 4314 ParseTypeParameters(function_type_alias); |
| 4296 // At this point, the type parameters have been parsed, so we can resolve the | 4315 // At this point, the type parameters have been parsed, so we can resolve the |
| 4297 // result type. | 4316 // result type. |
| 4298 if (!result_type.IsNull()) { | 4317 if (!result_type.IsNull()) { |
| 4299 ResolveTypeFromClass(function_type_alias, | 4318 ResolveTypeFromClass(function_type_alias, |
| 4300 ClassFinalizer::kResolveTypeParameters, | 4319 ClassFinalizer::kResolveTypeParameters, |
| 4301 &result_type); | 4320 &result_type); |
| 4302 } | 4321 } |
| 4303 // Parse the formal parameters of the function type. | 4322 // Parse the formal parameters of the function type. |
| 4304 CheckToken(Token::kLPAREN, "formal parameter list expected"); | 4323 CheckToken(Token::kLPAREN, "formal parameter list expected"); |
| 4305 ParamList func_params; | 4324 ParamList func_params; |
| 4306 | 4325 |
| 4307 // Add implicit closure object parameter. | 4326 // Add implicit closure object parameter. |
| 4308 func_params.AddFinalParameter( | 4327 func_params.AddFinalParameter( |
| 4309 TokenPos(), | 4328 TokenPos(), |
| 4310 &Symbols::ClosureParameter(), | 4329 &Symbols::ClosureParameter(), |
| 4311 &Type::ZoneHandle(Type::DynamicType())); | 4330 &Type::ZoneHandle(Type::DynamicType())); |
| 4312 | 4331 |
| 4313 const bool no_explicit_default_values = false; | 4332 const bool no_explicit_default_values = false; |
| 4314 ParseFormalParameterList(no_explicit_default_values, false, &func_params); | 4333 ParseFormalParameterList(no_explicit_default_values, false, &func_params); |
| 4315 ExpectSemicolon(); | 4334 ExpectSemicolon(); |
| 4316 // The field 'is_static' has no meaning for signature functions. | 4335 // The field 'is_static' has no meaning for signature functions. |
| 4317 Function& signature_function = Function::Handle( | 4336 Function& signature_function = Function::Handle(isolate(), |
| 4318 Function::New(*alias_name, | 4337 Function::New(*alias_name, |
| 4319 RawFunction::kSignatureFunction, | 4338 RawFunction::kSignatureFunction, |
| 4320 /* is_static = */ false, | 4339 /* is_static = */ false, |
| 4321 /* is_const = */ false, | 4340 /* is_const = */ false, |
| 4322 /* is_abstract = */ false, | 4341 /* is_abstract = */ false, |
| 4323 /* is_external = */ false, | 4342 /* is_external = */ false, |
| 4324 /* is_native = */ false, | 4343 /* is_native = */ false, |
| 4325 function_type_alias, | 4344 function_type_alias, |
| 4326 alias_name_pos)); | 4345 alias_name_pos)); |
| 4327 signature_function.set_result_type(result_type); | 4346 signature_function.set_result_type(result_type); |
| 4328 AddFormalParamsToFunction(&func_params, signature_function); | 4347 AddFormalParamsToFunction(&func_params, signature_function); |
| 4329 | 4348 |
| 4330 // Patch the signature function in the signature class. | 4349 // Patch the signature function in the signature class. |
| 4331 function_type_alias.PatchSignatureFunction(signature_function); | 4350 function_type_alias.PatchSignatureFunction(signature_function); |
| 4332 | 4351 |
| 4333 const String& signature = String::Handle(signature_function.Signature()); | 4352 const String& signature = String::Handle(isolate(), |
| 4353 signature_function.Signature()); | |
| 4334 if (FLAG_trace_parser) { | 4354 if (FLAG_trace_parser) { |
| 4335 OS::Print("TopLevel parsing function type alias '%s'\n", | 4355 OS::Print("TopLevel parsing function type alias '%s'\n", |
| 4336 signature.ToCString()); | 4356 signature.ToCString()); |
| 4337 } | 4357 } |
| 4338 // Lookup the signature class, i.e. the class whose name is the signature. | 4358 // Lookup the signature class, i.e. the class whose name is the signature. |
| 4339 // We only lookup in the current library, but not in its imports, and only | 4359 // We only lookup in the current library, but not in its imports, and only |
| 4340 // create a new canonical signature class if it does not exist yet. | 4360 // create a new canonical signature class if it does not exist yet. |
| 4341 Class& signature_class = Class::ZoneHandle( | 4361 Class& signature_class = Class::ZoneHandle( |
| 4342 library_.LookupLocalClass(signature)); | 4362 library_.LookupLocalClass(signature)); |
| 4343 if (signature_class.IsNull()) { | 4363 if (signature_class.IsNull()) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4436 } | 4456 } |
| 4437 SkipTypeArguments(); | 4457 SkipTypeArguments(); |
| 4438 } | 4458 } |
| 4439 } | 4459 } |
| 4440 | 4460 |
| 4441 | 4461 |
| 4442 void Parser::ParseTypeParameters(const Class& cls) { | 4462 void Parser::ParseTypeParameters(const Class& cls) { |
| 4443 TRACE_PARSER("ParseTypeParameters"); | 4463 TRACE_PARSER("ParseTypeParameters"); |
| 4444 if (CurrentToken() == Token::kLT) { | 4464 if (CurrentToken() == Token::kLT) { |
| 4445 const GrowableObjectArray& type_parameters_array = | 4465 const GrowableObjectArray& type_parameters_array = |
| 4446 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 4466 GrowableObjectArray::Handle(isolate(), GrowableObjectArray::New()); |
| 4447 intptr_t index = 0; | 4467 intptr_t index = 0; |
| 4448 TypeParameter& type_parameter = TypeParameter::Handle(); | 4468 TypeParameter& type_parameter = TypeParameter::Handle(isolate()); |
| 4449 TypeParameter& existing_type_parameter = TypeParameter::Handle(); | 4469 TypeParameter& existing_type_parameter = TypeParameter::Handle(isolate()); |
| 4450 String& existing_type_parameter_name = String::Handle(); | 4470 String& existing_type_parameter_name = String::Handle(isolate()); |
| 4451 AbstractType& type_parameter_bound = Type::Handle(); | 4471 AbstractType& type_parameter_bound = Type::Handle(isolate()); |
| 4452 do { | 4472 do { |
| 4453 ConsumeToken(); | 4473 ConsumeToken(); |
| 4454 const intptr_t metadata_pos = SkipMetadata(); | 4474 const intptr_t metadata_pos = SkipMetadata(); |
| 4455 const intptr_t type_parameter_pos = TokenPos(); | 4475 const intptr_t type_parameter_pos = TokenPos(); |
| 4456 String& type_parameter_name = | 4476 String& type_parameter_name = |
| 4457 *ExpectUserDefinedTypeIdentifier("type parameter expected"); | 4477 *ExpectUserDefinedTypeIdentifier("type parameter expected"); |
| 4458 // Check for duplicate type parameters. | 4478 // Check for duplicate type parameters. |
| 4459 for (intptr_t i = 0; i < index; i++) { | 4479 for (intptr_t i = 0; i < index; i++) { |
| 4460 existing_type_parameter ^= type_parameters_array.At(i); | 4480 existing_type_parameter ^= type_parameters_array.At(i); |
| 4461 existing_type_parameter_name = existing_type_parameter.name(); | 4481 existing_type_parameter_name = existing_type_parameter.name(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 4485 } | 4505 } |
| 4486 index++; | 4506 index++; |
| 4487 } while (CurrentToken() == Token::kCOMMA); | 4507 } while (CurrentToken() == Token::kCOMMA); |
| 4488 Token::Kind token = CurrentToken(); | 4508 Token::Kind token = CurrentToken(); |
| 4489 if ((token == Token::kGT) || (token == Token::kSHR)) { | 4509 if ((token == Token::kGT) || (token == Token::kSHR)) { |
| 4490 ConsumeRightAngleBracket(); | 4510 ConsumeRightAngleBracket(); |
| 4491 } else { | 4511 } else { |
| 4492 ErrorMsg("right angle bracket expected"); | 4512 ErrorMsg("right angle bracket expected"); |
| 4493 } | 4513 } |
| 4494 const TypeArguments& type_parameters = | 4514 const TypeArguments& type_parameters = |
| 4495 TypeArguments::Handle(NewTypeArguments(type_parameters_array)); | 4515 TypeArguments::Handle(isolate(), |
| 4516 NewTypeArguments(type_parameters_array)); | |
| 4496 cls.set_type_parameters(type_parameters); | 4517 cls.set_type_parameters(type_parameters); |
| 4497 // Try to resolve the upper bounds, which will at least resolve the | 4518 // Try to resolve the upper bounds, which will at least resolve the |
| 4498 // referenced type parameters. | 4519 // referenced type parameters. |
| 4499 const intptr_t num_types = type_parameters.Length(); | 4520 const intptr_t num_types = type_parameters.Length(); |
| 4500 for (intptr_t i = 0; i < num_types; i++) { | 4521 for (intptr_t i = 0; i < num_types; i++) { |
| 4501 type_parameter ^= type_parameters.TypeAt(i); | 4522 type_parameter ^= type_parameters.TypeAt(i); |
| 4502 type_parameter_bound = type_parameter.bound(); | 4523 type_parameter_bound = type_parameter.bound(); |
| 4503 ResolveTypeFromClass(cls, | 4524 ResolveTypeFromClass(cls, |
| 4504 ClassFinalizer::kResolveTypeParameters, | 4525 ClassFinalizer::kResolveTypeParameters, |
| 4505 &type_parameter_bound); | 4526 &type_parameter_bound); |
| 4506 type_parameter.set_bound(type_parameter_bound); | 4527 type_parameter.set_bound(type_parameter_bound); |
| 4507 } | 4528 } |
| 4508 } | 4529 } |
| 4509 } | 4530 } |
| 4510 | 4531 |
| 4511 | 4532 |
| 4512 RawTypeArguments* Parser::ParseTypeArguments( | 4533 RawTypeArguments* Parser::ParseTypeArguments( |
| 4513 ClassFinalizer::FinalizationKind finalization) { | 4534 ClassFinalizer::FinalizationKind finalization) { |
| 4514 TRACE_PARSER("ParseTypeArguments"); | 4535 TRACE_PARSER("ParseTypeArguments"); |
| 4515 if (CurrentToken() == Token::kLT) { | 4536 if (CurrentToken() == Token::kLT) { |
| 4516 const GrowableObjectArray& types = | 4537 const GrowableObjectArray& types = |
| 4517 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 4538 GrowableObjectArray::Handle(isolate(), GrowableObjectArray::New()); |
| 4518 AbstractType& type = AbstractType::Handle(); | 4539 AbstractType& type = AbstractType::Handle(isolate()); |
| 4519 do { | 4540 do { |
| 4520 ConsumeToken(); | 4541 ConsumeToken(); |
| 4521 type = ParseType(finalization); | 4542 type = ParseType(finalization); |
| 4522 // Map a malformed type argument to dynamic. | 4543 // Map a malformed type argument to dynamic. |
| 4523 if (type.IsMalformed()) { | 4544 if (type.IsMalformed()) { |
| 4524 type = Type::DynamicType(); | 4545 type = Type::DynamicType(); |
| 4525 } | 4546 } |
| 4526 types.Add(type); | 4547 types.Add(type); |
| 4527 } while (CurrentToken() == Token::kCOMMA); | 4548 } while (CurrentToken() == Token::kCOMMA); |
| 4528 Token::Kind token = CurrentToken(); | 4549 Token::Kind token = CurrentToken(); |
| 4529 if ((token == Token::kGT) || (token == Token::kSHR)) { | 4550 if ((token == Token::kGT) || (token == Token::kSHR)) { |
| 4530 ConsumeRightAngleBracket(); | 4551 ConsumeRightAngleBracket(); |
| 4531 } else { | 4552 } else { |
| 4532 ErrorMsg("right angle bracket expected"); | 4553 ErrorMsg("right angle bracket expected"); |
| 4533 } | 4554 } |
| 4534 if (finalization != ClassFinalizer::kIgnore) { | 4555 if (finalization != ClassFinalizer::kIgnore) { |
| 4535 return NewTypeArguments(types); | 4556 return NewTypeArguments(types); |
| 4536 } | 4557 } |
| 4537 } | 4558 } |
| 4538 return TypeArguments::null(); | 4559 return TypeArguments::null(); |
| 4539 } | 4560 } |
| 4540 | 4561 |
| 4541 | 4562 |
| 4542 // Parse interface list and add to class cls. | 4563 // Parse interface list and add to class cls. |
| 4543 void Parser::ParseInterfaceList(const Class& cls) { | 4564 void Parser::ParseInterfaceList(const Class& cls) { |
| 4544 TRACE_PARSER("ParseInterfaceList"); | 4565 TRACE_PARSER("ParseInterfaceList"); |
| 4545 ASSERT(CurrentToken() == Token::kIMPLEMENTS); | 4566 ASSERT(CurrentToken() == Token::kIMPLEMENTS); |
| 4546 const GrowableObjectArray& all_interfaces = | 4567 const GrowableObjectArray& all_interfaces = |
| 4547 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 4568 GrowableObjectArray::Handle(isolate(), GrowableObjectArray::New()); |
| 4548 AbstractType& interface = AbstractType::Handle(); | 4569 AbstractType& interface = AbstractType::Handle(isolate()); |
| 4549 // First get all the interfaces already implemented by class. | 4570 // First get all the interfaces already implemented by class. |
| 4550 Array& cls_interfaces = Array::Handle(cls.interfaces()); | 4571 Array& cls_interfaces = Array::Handle(isolate(), cls.interfaces()); |
| 4551 for (intptr_t i = 0; i < cls_interfaces.Length(); i++) { | 4572 for (intptr_t i = 0; i < cls_interfaces.Length(); i++) { |
| 4552 interface ^= cls_interfaces.At(i); | 4573 interface ^= cls_interfaces.At(i); |
| 4553 all_interfaces.Add(interface); | 4574 all_interfaces.Add(interface); |
| 4554 } | 4575 } |
| 4555 // Now parse and add the new interfaces. | 4576 // Now parse and add the new interfaces. |
| 4556 do { | 4577 do { |
| 4557 ConsumeToken(); | 4578 ConsumeToken(); |
| 4558 intptr_t interface_pos = TokenPos(); | 4579 intptr_t interface_pos = TokenPos(); |
| 4559 interface = ParseType(ClassFinalizer::kResolveTypeParameters); | 4580 interface = ParseType(ClassFinalizer::kResolveTypeParameters); |
| 4560 if (interface.IsTypeParameter()) { | 4581 if (interface.IsTypeParameter()) { |
| 4561 ErrorMsg(interface_pos, | 4582 ErrorMsg(interface_pos, |
| 4562 "type parameter '%s' may not be used in interface list", | 4583 "type parameter '%s' may not be used in interface list", |
| 4563 String::Handle(interface.UserVisibleName()).ToCString()); | 4584 String::Handle(isolate(), |
| 4585 interface.UserVisibleName()).ToCString()); | |
| 4564 } | 4586 } |
| 4565 all_interfaces.Add(interface); | 4587 all_interfaces.Add(interface); |
| 4566 } while (CurrentToken() == Token::kCOMMA); | 4588 } while (CurrentToken() == Token::kCOMMA); |
| 4567 cls_interfaces = Array::MakeArray(all_interfaces); | 4589 cls_interfaces = Array::MakeArray(all_interfaces); |
| 4568 cls.set_interfaces(cls_interfaces); | 4590 cls.set_interfaces(cls_interfaces); |
| 4569 } | 4591 } |
| 4570 | 4592 |
| 4571 | 4593 |
| 4572 RawAbstractType* Parser::ParseMixins(const AbstractType& super_type) { | 4594 RawAbstractType* Parser::ParseMixins(const AbstractType& super_type) { |
| 4573 TRACE_PARSER("ParseMixins"); | 4595 TRACE_PARSER("ParseMixins"); |
| 4574 ASSERT(CurrentToken() == Token::kWITH); | 4596 ASSERT(CurrentToken() == Token::kWITH); |
| 4575 const GrowableObjectArray& mixin_types = | 4597 const GrowableObjectArray& mixin_types = |
| 4576 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 4598 GrowableObjectArray::Handle(isolate(), GrowableObjectArray::New()); |
| 4577 AbstractType& mixin_type = AbstractType::Handle(); | 4599 AbstractType& mixin_type = AbstractType::Handle(isolate()); |
| 4578 do { | 4600 do { |
| 4579 ConsumeToken(); | 4601 ConsumeToken(); |
| 4580 mixin_type = ParseType(ClassFinalizer::kResolveTypeParameters); | 4602 mixin_type = ParseType(ClassFinalizer::kResolveTypeParameters); |
| 4581 if (mixin_type.IsDynamicType()) { | 4603 if (mixin_type.IsDynamicType()) { |
| 4582 // The string 'dynamic' is not resolved yet at this point, but a malformed | 4604 // The string 'dynamic' is not resolved yet at this point, but a malformed |
| 4583 // type mapped to dynamic can be encountered here. | 4605 // type mapped to dynamic can be encountered here. |
| 4584 ErrorMsg(mixin_type.token_pos(), "illegal mixin of a malformed type"); | 4606 ErrorMsg(mixin_type.token_pos(), "illegal mixin of a malformed type"); |
| 4585 } | 4607 } |
| 4586 if (mixin_type.IsTypeParameter()) { | 4608 if (mixin_type.IsTypeParameter()) { |
| 4587 ErrorMsg(mixin_type.token_pos(), | 4609 ErrorMsg(mixin_type.token_pos(), |
| 4588 "mixin type '%s' may not be a type parameter", | 4610 "mixin type '%s' may not be a type parameter", |
| 4589 String::Handle(mixin_type.UserVisibleName()).ToCString()); | 4611 String::Handle(isolate(), |
| 4612 mixin_type.UserVisibleName()).ToCString()); | |
| 4590 } | 4613 } |
| 4591 mixin_types.Add(mixin_type); | 4614 mixin_types.Add(mixin_type); |
| 4592 } while (CurrentToken() == Token::kCOMMA); | 4615 } while (CurrentToken() == Token::kCOMMA); |
| 4593 return MixinAppType::New(super_type, | 4616 return MixinAppType::New(super_type, |
| 4594 Array::Handle(Array::MakeArray(mixin_types))); | 4617 Array::Handle(isolate(), Array::MakeArray(mixin_types))); |
| 4595 } | 4618 } |
| 4596 | 4619 |
| 4597 | 4620 |
| 4598 void Parser::ParseTopLevelVariable(TopLevel* top_level, | 4621 void Parser::ParseTopLevelVariable(TopLevel* top_level, |
| 4599 intptr_t metadata_pos) { | 4622 intptr_t metadata_pos) { |
| 4600 TRACE_PARSER("ParseTopLevelVariable"); | 4623 TRACE_PARSER("ParseTopLevelVariable"); |
| 4601 const bool is_const = (CurrentToken() == Token::kCONST); | 4624 const bool is_const = (CurrentToken() == Token::kCONST); |
| 4602 // Const fields are implicitly final. | 4625 // Const fields are implicitly final. |
| 4603 const bool is_final = is_const || (CurrentToken() == Token::kFINAL); | 4626 const bool is_final = is_const || (CurrentToken() == Token::kFINAL); |
| 4604 const bool is_static = true; | 4627 const bool is_static = true; |
| 4605 const AbstractType& type = AbstractType::ZoneHandle(ParseConstFinalVarOrType( | 4628 const AbstractType& type = AbstractType::ZoneHandle(ParseConstFinalVarOrType( |
| 4606 ClassFinalizer::kResolveTypeParameters)); | 4629 ClassFinalizer::kResolveTypeParameters)); |
| 4607 Field& field = Field::Handle(); | 4630 Field& field = Field::Handle(isolate()); |
| 4608 Function& getter = Function::Handle(); | 4631 Function& getter = Function::Handle(isolate()); |
| 4609 while (true) { | 4632 while (true) { |
| 4610 const intptr_t name_pos = TokenPos(); | 4633 const intptr_t name_pos = TokenPos(); |
| 4611 String& var_name = *ExpectIdentifier("variable name expected"); | 4634 String& var_name = *ExpectIdentifier("variable name expected"); |
| 4612 | 4635 |
| 4613 if (library_.LookupLocalObject(var_name) != Object::null()) { | 4636 if (library_.LookupLocalObject(var_name) != Object::null()) { |
| 4614 ErrorMsg(name_pos, "'%s' is already defined", var_name.ToCString()); | 4637 ErrorMsg(name_pos, "'%s' is already defined", var_name.ToCString()); |
| 4615 } | 4638 } |
| 4616 | 4639 |
| 4617 // Check whether a getter or setter for this name exists. A const | 4640 // Check whether a getter or setter for this name exists. A const |
| 4618 // or final field implies a setter which throws a NoSuchMethodError, | 4641 // or final field implies a setter which throws a NoSuchMethodError, |
| 4619 // thus we need to check for conflicts with existing setters and | 4642 // thus we need to check for conflicts with existing setters and |
| 4620 // getters. | 4643 // getters. |
| 4621 String& accessor_name = String::Handle(Field::GetterName(var_name)); | 4644 String& accessor_name = String::Handle(isolate(), |
| 4645 Field::GetterName(var_name)); | |
| 4622 if (library_.LookupLocalObject(accessor_name) != Object::null()) { | 4646 if (library_.LookupLocalObject(accessor_name) != Object::null()) { |
| 4623 ErrorMsg(name_pos, "getter for '%s' is already defined", | 4647 ErrorMsg(name_pos, "getter for '%s' is already defined", |
| 4624 var_name.ToCString()); | 4648 var_name.ToCString()); |
| 4625 } | 4649 } |
| 4626 accessor_name = Field::SetterName(var_name); | 4650 accessor_name = Field::SetterName(var_name); |
| 4627 if (library_.LookupLocalObject(accessor_name) != Object::null()) { | 4651 if (library_.LookupLocalObject(accessor_name) != Object::null()) { |
| 4628 ErrorMsg(name_pos, "setter for '%s' is already defined", | 4652 ErrorMsg(name_pos, "setter for '%s' is already defined", |
| 4629 var_name.ToCString()); | 4653 var_name.ToCString()); |
| 4630 } | 4654 } |
| 4631 | 4655 |
| 4632 field = Field::New(var_name, is_static, is_final, is_const, | 4656 field = Field::New(var_name, is_static, is_final, is_const, |
| 4633 current_class(), name_pos); | 4657 current_class(), name_pos); |
| 4634 field.set_type(type); | 4658 field.set_type(type); |
| 4635 field.set_value(Instance::Handle(Instance::null())); | 4659 field.set_value(Instance::Handle(isolate(), Instance::null())); |
| 4636 top_level->fields.Add(field); | 4660 top_level->fields.Add(field); |
| 4637 library_.AddObject(field, var_name); | 4661 library_.AddObject(field, var_name); |
| 4638 if (metadata_pos >= 0) { | 4662 if (metadata_pos >= 0) { |
| 4639 library_.AddFieldMetadata(field, metadata_pos); | 4663 library_.AddFieldMetadata(field, metadata_pos); |
| 4640 } | 4664 } |
| 4641 if (CurrentToken() == Token::kASSIGN) { | 4665 if (CurrentToken() == Token::kASSIGN) { |
| 4642 ConsumeToken(); | 4666 ConsumeToken(); |
| 4643 Instance& field_value = Instance::Handle(Object::sentinel().raw()); | 4667 Instance& field_value = Instance::Handle(isolate(), |
| 4668 Object::sentinel().raw()); | |
| 4644 bool has_simple_literal = false; | 4669 bool has_simple_literal = false; |
| 4645 if (LookaheadToken(1) == Token::kSEMICOLON) { | 4670 if (LookaheadToken(1) == Token::kSEMICOLON) { |
| 4646 has_simple_literal = IsSimpleLiteral(type, &field_value); | 4671 has_simple_literal = IsSimpleLiteral(type, &field_value); |
| 4647 } | 4672 } |
| 4648 SkipExpr(); | 4673 SkipExpr(); |
| 4649 field.set_value(field_value); | 4674 field.set_value(field_value); |
| 4650 if (!has_simple_literal) { | 4675 if (!has_simple_literal) { |
| 4651 // Create a static final getter. | 4676 // Create a static final getter. |
| 4652 String& getter_name = String::Handle(Field::GetterSymbol(var_name)); | 4677 String& getter_name = String::Handle(isolate(), |
| 4678 Field::GetterSymbol(var_name)); | |
| 4653 getter = Function::New(getter_name, | 4679 getter = Function::New(getter_name, |
| 4654 RawFunction::kImplicitStaticFinalGetter, | 4680 RawFunction::kImplicitStaticFinalGetter, |
| 4655 is_static, | 4681 is_static, |
| 4656 is_const, | 4682 is_const, |
| 4657 /* is_abstract = */ false, | 4683 /* is_abstract = */ false, |
| 4658 /* is_external = */ false, | 4684 /* is_external = */ false, |
| 4659 /* is_native = */ false, | 4685 /* is_native = */ false, |
| 4660 current_class(), | 4686 current_class(), |
| 4661 name_pos); | 4687 name_pos); |
| 4662 getter.set_result_type(type); | 4688 getter.set_result_type(type); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 4682 ExpectSemicolon(); // Reports error. | 4708 ExpectSemicolon(); // Reports error. |
| 4683 } | 4709 } |
| 4684 } | 4710 } |
| 4685 } | 4711 } |
| 4686 | 4712 |
| 4687 | 4713 |
| 4688 void Parser::ParseTopLevelFunction(TopLevel* top_level, | 4714 void Parser::ParseTopLevelFunction(TopLevel* top_level, |
| 4689 intptr_t metadata_pos) { | 4715 intptr_t metadata_pos) { |
| 4690 TRACE_PARSER("ParseTopLevelFunction"); | 4716 TRACE_PARSER("ParseTopLevelFunction"); |
| 4691 const intptr_t decl_begin_pos = TokenPos(); | 4717 const intptr_t decl_begin_pos = TokenPos(); |
| 4692 AbstractType& result_type = Type::Handle(Type::DynamicType()); | 4718 AbstractType& result_type = Type::Handle(isolate(), Type::DynamicType()); |
| 4693 const bool is_static = true; | 4719 const bool is_static = true; |
| 4694 bool is_external = false; | 4720 bool is_external = false; |
| 4695 bool is_patch = false; | 4721 bool is_patch = false; |
| 4696 if (is_patch_source() && | 4722 if (is_patch_source() && |
| 4697 (CurrentToken() == Token::kIDENT) && | 4723 (CurrentToken() == Token::kIDENT) && |
| 4698 CurrentLiteral()->Equals("patch") && | 4724 CurrentLiteral()->Equals("patch") && |
| 4699 (LookaheadToken(1) != Token::kLPAREN)) { | 4725 (LookaheadToken(1) != Token::kLPAREN)) { |
| 4700 ConsumeToken(); | 4726 ConsumeToken(); |
| 4701 is_patch = true; | 4727 is_patch = true; |
| 4702 } else if (CurrentToken() == Token::kEXTERNAL) { | 4728 } else if (CurrentToken() == Token::kEXTERNAL) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 4715 } | 4741 } |
| 4716 const intptr_t name_pos = TokenPos(); | 4742 const intptr_t name_pos = TokenPos(); |
| 4717 const String& func_name = *ExpectIdentifier("function name expected"); | 4743 const String& func_name = *ExpectIdentifier("function name expected"); |
| 4718 | 4744 |
| 4719 bool found = library_.LookupLocalObject(func_name) != Object::null(); | 4745 bool found = library_.LookupLocalObject(func_name) != Object::null(); |
| 4720 if (found && !is_patch) { | 4746 if (found && !is_patch) { |
| 4721 ErrorMsg(name_pos, "'%s' is already defined", func_name.ToCString()); | 4747 ErrorMsg(name_pos, "'%s' is already defined", func_name.ToCString()); |
| 4722 } else if (!found && is_patch) { | 4748 } else if (!found && is_patch) { |
| 4723 ErrorMsg(name_pos, "missing '%s' cannot be patched", func_name.ToCString()); | 4749 ErrorMsg(name_pos, "missing '%s' cannot be patched", func_name.ToCString()); |
| 4724 } | 4750 } |
| 4725 String& accessor_name = String::Handle(Field::GetterName(func_name)); | 4751 String& accessor_name = String::Handle(isolate(), |
| 4752 Field::GetterName(func_name)); | |
| 4726 if (library_.LookupLocalObject(accessor_name) != Object::null()) { | 4753 if (library_.LookupLocalObject(accessor_name) != Object::null()) { |
| 4727 ErrorMsg(name_pos, "'%s' is already defined as getter", | 4754 ErrorMsg(name_pos, "'%s' is already defined as getter", |
| 4728 func_name.ToCString()); | 4755 func_name.ToCString()); |
| 4729 } | 4756 } |
| 4730 // A setter named x= may co-exist with a function named x, thus we do | 4757 // A setter named x= may co-exist with a function named x, thus we do |
| 4731 // not need to check setters. | 4758 // not need to check setters. |
| 4732 | 4759 |
| 4733 CheckToken(Token::kLPAREN); | 4760 CheckToken(Token::kLPAREN); |
| 4734 const intptr_t function_pos = TokenPos(); | 4761 const intptr_t function_pos = TokenPos(); |
| 4735 ParamList params; | 4762 ParamList params; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 4751 function_end_pos = TokenPos(); | 4778 function_end_pos = TokenPos(); |
| 4752 ExpectSemicolon(); | 4779 ExpectSemicolon(); |
| 4753 } else if (IsLiteral("native")) { | 4780 } else if (IsLiteral("native")) { |
| 4754 ParseNativeDeclaration(); | 4781 ParseNativeDeclaration(); |
| 4755 function_end_pos = TokenPos(); | 4782 function_end_pos = TokenPos(); |
| 4756 ExpectSemicolon(); | 4783 ExpectSemicolon(); |
| 4757 is_native = true; | 4784 is_native = true; |
| 4758 } else { | 4785 } else { |
| 4759 ErrorMsg("function block expected"); | 4786 ErrorMsg("function block expected"); |
| 4760 } | 4787 } |
| 4761 Function& func = Function::Handle( | 4788 Function& func = Function::Handle(isolate(), |
| 4762 Function::New(func_name, | 4789 Function::New(func_name, |
| 4763 RawFunction::kRegularFunction, | 4790 RawFunction::kRegularFunction, |
| 4764 is_static, | 4791 is_static, |
| 4765 /* is_const = */ false, | 4792 /* is_const = */ false, |
| 4766 /* is_abstract = */ false, | 4793 /* is_abstract = */ false, |
| 4767 is_external, | 4794 is_external, |
| 4768 is_native, | 4795 is_native, |
| 4769 current_class(), | 4796 current_class(), |
| 4770 decl_begin_pos)); | 4797 decl_begin_pos)); |
| 4771 func.set_result_type(result_type); | 4798 func.set_result_type(result_type); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 4786 } | 4813 } |
| 4787 | 4814 |
| 4788 | 4815 |
| 4789 void Parser::ParseTopLevelAccessor(TopLevel* top_level, | 4816 void Parser::ParseTopLevelAccessor(TopLevel* top_level, |
| 4790 intptr_t metadata_pos) { | 4817 intptr_t metadata_pos) { |
| 4791 TRACE_PARSER("ParseTopLevelAccessor"); | 4818 TRACE_PARSER("ParseTopLevelAccessor"); |
| 4792 const intptr_t decl_begin_pos = TokenPos(); | 4819 const intptr_t decl_begin_pos = TokenPos(); |
| 4793 const bool is_static = true; | 4820 const bool is_static = true; |
| 4794 bool is_external = false; | 4821 bool is_external = false; |
| 4795 bool is_patch = false; | 4822 bool is_patch = false; |
| 4796 AbstractType& result_type = AbstractType::Handle(); | 4823 AbstractType& result_type = AbstractType::Handle(isolate()); |
| 4797 if (is_patch_source() && | 4824 if (is_patch_source() && |
| 4798 (CurrentToken() == Token::kIDENT) && | 4825 (CurrentToken() == Token::kIDENT) && |
| 4799 CurrentLiteral()->Equals("patch")) { | 4826 CurrentLiteral()->Equals("patch")) { |
| 4800 ConsumeToken(); | 4827 ConsumeToken(); |
| 4801 is_patch = true; | 4828 is_patch = true; |
| 4802 } else if (CurrentToken() == Token::kEXTERNAL) { | 4829 } else if (CurrentToken() == Token::kEXTERNAL) { |
| 4803 ConsumeToken(); | 4830 ConsumeToken(); |
| 4804 is_external = true; | 4831 is_external = true; |
| 4805 } | 4832 } |
| 4806 bool is_getter = (CurrentToken() == Token::kGET); | 4833 bool is_getter = (CurrentToken() == Token::kGET); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4887 accessor_end_pos = TokenPos(); | 4914 accessor_end_pos = TokenPos(); |
| 4888 ExpectSemicolon(); | 4915 ExpectSemicolon(); |
| 4889 } else if (IsLiteral("native")) { | 4916 } else if (IsLiteral("native")) { |
| 4890 ParseNativeDeclaration(); | 4917 ParseNativeDeclaration(); |
| 4891 accessor_end_pos = TokenPos(); | 4918 accessor_end_pos = TokenPos(); |
| 4892 ExpectSemicolon(); | 4919 ExpectSemicolon(); |
| 4893 is_native = true; | 4920 is_native = true; |
| 4894 } else { | 4921 } else { |
| 4895 ErrorMsg("function block expected"); | 4922 ErrorMsg("function block expected"); |
| 4896 } | 4923 } |
| 4897 Function& func = Function::Handle( | 4924 Function& func = Function::Handle(isolate(), |
| 4898 Function::New(accessor_name, | 4925 Function::New(accessor_name, |
| 4899 is_getter ? RawFunction::kGetterFunction : | 4926 is_getter ? RawFunction::kGetterFunction : |
| 4900 RawFunction::kSetterFunction, | 4927 RawFunction::kSetterFunction, |
| 4901 is_static, | 4928 is_static, |
| 4902 /* is_const = */ false, | 4929 /* is_const = */ false, |
| 4903 /* is_abstract = */ false, | 4930 /* is_abstract = */ false, |
| 4904 is_external, | 4931 is_external, |
| 4905 is_native, | 4932 is_native, |
| 4906 current_class(), | 4933 current_class(), |
| 4907 decl_begin_pos)); | 4934 decl_begin_pos)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4941 // tag handler. | 4968 // tag handler. |
| 4942 isolate()->BlockClassFinalization(); | 4969 isolate()->BlockClassFinalization(); |
| 4943 Api::Scope api_scope(isolate()); | 4970 Api::Scope api_scope(isolate()); |
| 4944 Dart_Handle result = handler(tag, | 4971 Dart_Handle result = handler(tag, |
| 4945 Api::NewHandle(isolate(), library_.raw()), | 4972 Api::NewHandle(isolate(), library_.raw()), |
| 4946 Api::NewHandle(isolate(), url.raw())); | 4973 Api::NewHandle(isolate(), url.raw())); |
| 4947 isolate()->UnblockClassFinalization(); | 4974 isolate()->UnblockClassFinalization(); |
| 4948 if (Dart_IsError(result)) { | 4975 if (Dart_IsError(result)) { |
| 4949 // In case of an error we append an explanatory error message to the | 4976 // In case of an error we append an explanatory error message to the |
| 4950 // error obtained from the library tag handler. | 4977 // error obtained from the library tag handler. |
| 4951 Error& prev_error = Error::Handle(); | 4978 Error& prev_error = Error::Handle(isolate()); |
| 4952 prev_error ^= Api::UnwrapHandle(result); | 4979 prev_error ^= Api::UnwrapHandle(result); |
| 4953 AppendErrorMsg(prev_error, token_pos, "library handler failed"); | 4980 AppendErrorMsg(prev_error, token_pos, "library handler failed"); |
| 4954 } | 4981 } |
| 4955 if (tag == Dart_kCanonicalizeUrl) { | 4982 if (tag == Dart_kCanonicalizeUrl) { |
| 4956 if (!Dart_IsString(result)) { | 4983 if (!Dart_IsString(result)) { |
| 4957 ErrorMsg(token_pos, "library handler failed URI canonicalization"); | 4984 ErrorMsg(token_pos, "library handler failed URI canonicalization"); |
| 4958 } | 4985 } |
| 4959 } | 4986 } |
| 4960 return Api::UnwrapHandle(result); | 4987 return Api::UnwrapHandle(result); |
| 4961 } | 4988 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5007 const String& url = String::Cast(url_literal->AsLiteralNode()->literal()); | 5034 const String& url = String::Cast(url_literal->AsLiteralNode()->literal()); |
| 5008 if (url.Length() == 0) { | 5035 if (url.Length() == 0) { |
| 5009 ErrorMsg("library url expected"); | 5036 ErrorMsg("library url expected"); |
| 5010 } | 5037 } |
| 5011 bool is_deferred_import = false; | 5038 bool is_deferred_import = false; |
| 5012 if (is_import && (IsLiteral("deferred"))) { | 5039 if (is_import && (IsLiteral("deferred"))) { |
| 5013 is_deferred_import = true; | 5040 is_deferred_import = true; |
| 5014 ConsumeToken(); | 5041 ConsumeToken(); |
| 5015 CheckToken(Token::kAS, "'as' expected"); | 5042 CheckToken(Token::kAS, "'as' expected"); |
| 5016 } | 5043 } |
| 5017 String& prefix = String::Handle(); | 5044 String& prefix = String::Handle(isolate()); |
| 5018 intptr_t prefix_pos = 0; | 5045 intptr_t prefix_pos = 0; |
| 5019 if (is_import && (CurrentToken() == Token::kAS)) { | 5046 if (is_import && (CurrentToken() == Token::kAS)) { |
| 5020 ConsumeToken(); | 5047 ConsumeToken(); |
| 5021 prefix_pos = TokenPos(); | 5048 prefix_pos = TokenPos(); |
| 5022 prefix = ExpectIdentifier("prefix identifier expected")->raw(); | 5049 prefix = ExpectIdentifier("prefix identifier expected")->raw(); |
| 5023 } | 5050 } |
| 5024 | 5051 |
| 5025 Array& show_names = Array::Handle(); | 5052 Array& show_names = Array::Handle(isolate()); |
| 5026 Array& hide_names = Array::Handle(); | 5053 Array& hide_names = Array::Handle(isolate()); |
| 5027 if (is_deferred_import || IsLiteral("show") || IsLiteral("hide")) { | 5054 if (is_deferred_import || IsLiteral("show") || IsLiteral("hide")) { |
| 5028 GrowableObjectArray& show_list = | 5055 GrowableObjectArray& show_list = |
| 5029 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 5056 GrowableObjectArray::Handle(isolate(), GrowableObjectArray::New()); |
| 5030 GrowableObjectArray& hide_list = | 5057 GrowableObjectArray& hide_list = |
| 5031 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 5058 GrowableObjectArray::Handle(isolate(), GrowableObjectArray::New()); |
| 5032 // Libraries imported through deferred import automatically hide | 5059 // Libraries imported through deferred import automatically hide |
| 5033 // the name 'loadLibrary'. | 5060 // the name 'loadLibrary'. |
| 5034 if (is_deferred_import) { | 5061 if (is_deferred_import) { |
| 5035 hide_list.Add(Symbols::LoadLibrary()); | 5062 hide_list.Add(Symbols::LoadLibrary()); |
| 5036 } | 5063 } |
| 5037 for (;;) { | 5064 for (;;) { |
| 5038 if (IsLiteral("show")) { | 5065 if (IsLiteral("show")) { |
| 5039 ConsumeToken(); | 5066 ConsumeToken(); |
| 5040 ParseIdentList(&show_list); | 5067 ParseIdentList(&show_list); |
| 5041 } else if (IsLiteral("hide")) { | 5068 } else if (IsLiteral("hide")) { |
| 5042 ConsumeToken(); | 5069 ConsumeToken(); |
| 5043 ParseIdentList(&hide_list); | 5070 ParseIdentList(&hide_list); |
| 5044 } else { | 5071 } else { |
| 5045 break; | 5072 break; |
| 5046 } | 5073 } |
| 5047 } | 5074 } |
| 5048 if (show_list.Length() > 0) { | 5075 if (show_list.Length() > 0) { |
| 5049 show_names = Array::MakeArray(show_list); | 5076 show_names = Array::MakeArray(show_list); |
| 5050 } | 5077 } |
| 5051 if (hide_list.Length() > 0) { | 5078 if (hide_list.Length() > 0) { |
| 5052 hide_names = Array::MakeArray(hide_list); | 5079 hide_names = Array::MakeArray(hide_list); |
| 5053 } | 5080 } |
| 5054 } | 5081 } |
| 5055 ExpectSemicolon(); | 5082 ExpectSemicolon(); |
| 5056 | 5083 |
| 5057 // Canonicalize library URL. | 5084 // Canonicalize library URL. |
| 5058 const String& canon_url = String::CheckedHandle( | 5085 const String& canon_url = String::CheckedHandle( |
| 5059 CallLibraryTagHandler(Dart_kCanonicalizeUrl, import_pos, url)); | 5086 CallLibraryTagHandler(Dart_kCanonicalizeUrl, import_pos, url)); |
| 5060 // Lookup the library URL. | 5087 // Lookup the library URL. |
| 5061 Library& library = Library::Handle(Library::LookupLibrary(canon_url)); | 5088 Library& library = Library::Handle(isolate(), |
| 5089 Library::LookupLibrary(canon_url)); | |
| 5062 if (library.IsNull()) { | 5090 if (library.IsNull()) { |
| 5063 // Create an empty library to mark that we have initiated loading of this | 5091 // Create an empty library to mark that we have initiated loading of this |
| 5064 // library. | 5092 // library. |
| 5065 library = Library::New(canon_url); | 5093 library = Library::New(canon_url); |
| 5066 library.Register(); | 5094 library.Register(); |
| 5067 // Call the library tag handler to load the library. | 5095 // Call the library tag handler to load the library. |
| 5068 // TODO(hausner): do not load eagerly if import is deferred. | 5096 // TODO(hausner): do not load eagerly if import is deferred. |
| 5069 CallLibraryTagHandler(Dart_kImportTag, import_pos, canon_url); | 5097 CallLibraryTagHandler(Dart_kImportTag, import_pos, canon_url); |
| 5070 } | 5098 } |
| 5071 | 5099 |
| 5072 Namespace& ns = | 5100 Namespace& ns = Namespace::Handle(isolate(), |
| 5073 Namespace::Handle(Namespace::New(library, show_names, hide_names)); | 5101 Namespace::New(library, show_names, hide_names)); |
| 5074 if (metadata_pos >= 0) { | 5102 if (metadata_pos >= 0) { |
| 5075 ns.AddMetadata(metadata_pos, current_class()); | 5103 ns.AddMetadata(metadata_pos, current_class()); |
| 5076 } | 5104 } |
| 5077 | 5105 |
| 5078 if (is_import) { | 5106 if (is_import) { |
| 5079 // Ensure that private dart:_ libraries are only imported into dart: | 5107 // Ensure that private dart:_ libraries are only imported into dart: |
| 5080 // libraries. | 5108 // libraries. |
| 5081 const String& lib_url = String::Handle(library_.url()); | 5109 const String& lib_url = String::Handle(isolate(), library_.url()); |
| 5082 if (canon_url.StartsWith(Symbols::DartSchemePrivate()) && | 5110 if (canon_url.StartsWith(Symbols::DartSchemePrivate()) && |
| 5083 !lib_url.StartsWith(Symbols::DartScheme())) { | 5111 !lib_url.StartsWith(Symbols::DartScheme())) { |
| 5084 ErrorMsg(import_pos, "private library is not accessible"); | 5112 ErrorMsg(import_pos, "private library is not accessible"); |
| 5085 } | 5113 } |
| 5086 if (prefix.IsNull() || (prefix.Length() == 0)) { | 5114 if (prefix.IsNull() || (prefix.Length() == 0)) { |
| 5087 ASSERT(!is_deferred_import); | 5115 ASSERT(!is_deferred_import); |
| 5088 library_.AddImport(ns); | 5116 library_.AddImport(ns); |
| 5089 } else { | 5117 } else { |
| 5090 LibraryPrefix& library_prefix = LibraryPrefix::Handle(); | 5118 LibraryPrefix& library_prefix = LibraryPrefix::Handle(isolate()); |
| 5091 library_prefix = library_.LookupLocalLibraryPrefix(prefix); | 5119 library_prefix = library_.LookupLocalLibraryPrefix(prefix); |
| 5092 if (!library_prefix.IsNull()) { | 5120 if (!library_prefix.IsNull()) { |
| 5093 // Check that prefix names of deferred import clauses are | 5121 // Check that prefix names of deferred import clauses are |
| 5094 // unique. | 5122 // unique. |
| 5095 if (!is_deferred_import && library_prefix.is_deferred_load()) { | 5123 if (!is_deferred_import && library_prefix.is_deferred_load()) { |
| 5096 ErrorMsg(prefix_pos, | 5124 ErrorMsg(prefix_pos, |
| 5097 "prefix '%s' already used in a deferred import clause", | 5125 "prefix '%s' already used in a deferred import clause", |
| 5098 prefix.ToCString()); | 5126 prefix.ToCString()); |
| 5099 } | 5127 } |
| 5100 if (is_deferred_import) { | 5128 if (is_deferred_import) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5158 } | 5186 } |
| 5159 while ((CurrentToken() == Token::kIMPORT) || | 5187 while ((CurrentToken() == Token::kIMPORT) || |
| 5160 (CurrentToken() == Token::kEXPORT)) { | 5188 (CurrentToken() == Token::kEXPORT)) { |
| 5161 ParseLibraryImportExport(metadata_pos); | 5189 ParseLibraryImportExport(metadata_pos); |
| 5162 rewind_pos = TokenPos(); | 5190 rewind_pos = TokenPos(); |
| 5163 metadata_pos = SkipMetadata(); | 5191 metadata_pos = SkipMetadata(); |
| 5164 } | 5192 } |
| 5165 // Core lib has not been explicitly imported, so we implicitly | 5193 // Core lib has not been explicitly imported, so we implicitly |
| 5166 // import it here. | 5194 // import it here. |
| 5167 if (!library_.ImportsCorelib()) { | 5195 if (!library_.ImportsCorelib()) { |
| 5168 Library& core_lib = Library::Handle(Library::CoreLibrary()); | 5196 Library& core_lib = Library::Handle(isolate(), Library::CoreLibrary()); |
| 5169 ASSERT(!core_lib.IsNull()); | 5197 ASSERT(!core_lib.IsNull()); |
| 5170 const Namespace& core_ns = Namespace::Handle( | 5198 const Namespace& core_ns = Namespace::Handle(isolate(), |
| 5171 Namespace::New(core_lib, Object::null_array(), Object::null_array())); | 5199 Namespace::New(core_lib, Object::null_array(), Object::null_array())); |
| 5172 library_.AddImport(core_ns); | 5200 library_.AddImport(core_ns); |
| 5173 } | 5201 } |
| 5174 while (CurrentToken() == Token::kPART) { | 5202 while (CurrentToken() == Token::kPART) { |
| 5175 ParseLibraryPart(); | 5203 ParseLibraryPart(); |
| 5176 rewind_pos = TokenPos(); | 5204 rewind_pos = TokenPos(); |
| 5177 metadata_pos = SkipMetadata(); | 5205 metadata_pos = SkipMetadata(); |
| 5178 } | 5206 } |
| 5179 SetPosition(rewind_pos); | 5207 SetPosition(rewind_pos); |
| 5180 } | 5208 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 5203 TRACE_PARSER("ParseTopLevel"); | 5231 TRACE_PARSER("ParseTopLevel"); |
| 5204 // Collect the classes found at the top level in this growable array. | 5232 // Collect the classes found at the top level in this growable array. |
| 5205 // They need to be registered with class finalization after parsing | 5233 // They need to be registered with class finalization after parsing |
| 5206 // has been completed. | 5234 // has been completed. |
| 5207 ObjectStore* object_store = isolate()->object_store(); | 5235 ObjectStore* object_store = isolate()->object_store(); |
| 5208 const GrowableObjectArray& pending_classes = | 5236 const GrowableObjectArray& pending_classes = |
| 5209 GrowableObjectArray::Handle(isolate(), object_store->pending_classes()); | 5237 GrowableObjectArray::Handle(isolate(), object_store->pending_classes()); |
| 5210 SetPosition(0); | 5238 SetPosition(0); |
| 5211 is_top_level_ = true; | 5239 is_top_level_ = true; |
| 5212 TopLevel top_level; | 5240 TopLevel top_level; |
| 5213 Class& toplevel_class = Class::Handle( | 5241 Class& toplevel_class = Class::Handle(isolate(), |
| 5214 Class::New(Symbols::TopLevel(), script_, TokenPos())); | 5242 Class::New(Symbols::TopLevel(), script_, TokenPos())); |
| 5215 toplevel_class.set_library(library_); | 5243 toplevel_class.set_library(library_); |
| 5216 | 5244 |
| 5217 if (is_library_source() || is_patch_source()) { | 5245 if (is_library_source() || is_patch_source()) { |
| 5218 set_current_class(toplevel_class); | 5246 set_current_class(toplevel_class); |
| 5219 ParseLibraryDefinition(); | 5247 ParseLibraryDefinition(); |
| 5220 } else if (is_part_source()) { | 5248 } else if (is_part_source()) { |
| 5221 ParsePartHeader(); | 5249 ParsePartHeader(); |
| 5222 } | 5250 } |
| 5223 | 5251 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 5248 } else if (CurrentToken() == Token::kEOS) { | 5276 } else if (CurrentToken() == Token::kEOS) { |
| 5249 break; | 5277 break; |
| 5250 } else { | 5278 } else { |
| 5251 UnexpectedToken(); | 5279 UnexpectedToken(); |
| 5252 } | 5280 } |
| 5253 } | 5281 } |
| 5254 } | 5282 } |
| 5255 if ((top_level.fields.Length() > 0) || (top_level.functions.Length() > 0)) { | 5283 if ((top_level.fields.Length() > 0) || (top_level.functions.Length() > 0)) { |
| 5256 toplevel_class.AddFields(top_level.fields); | 5284 toplevel_class.AddFields(top_level.fields); |
| 5257 | 5285 |
| 5258 const Array& array = Array::Handle(Array::MakeArray(top_level.functions)); | 5286 const Array& array = Array::Handle(isolate(), |
| 5287 Array::MakeArray(top_level.functions)); | |
| 5259 toplevel_class.SetFunctions(array); | 5288 toplevel_class.SetFunctions(array); |
| 5260 | 5289 |
| 5261 library_.AddAnonymousClass(toplevel_class); | 5290 library_.AddAnonymousClass(toplevel_class); |
| 5262 pending_classes.Add(toplevel_class, Heap::kOld); | 5291 pending_classes.Add(toplevel_class, Heap::kOld); |
| 5263 } | 5292 } |
| 5264 } | 5293 } |
| 5265 | 5294 |
| 5266 | 5295 |
| 5267 void Parser::ChainNewBlock(LocalScope* outer_scope) { | 5296 void Parser::ChainNewBlock(LocalScope* outer_scope) { |
| 5268 Block* block = new Block(current_block_, | 5297 Block* block = new(isolate()) Block( |
| 5269 outer_scope, | 5298 current_block_, |
| 5270 new SequenceNode(TokenPos(), outer_scope)); | 5299 outer_scope, |
| 5300 new(isolate()) SequenceNode(TokenPos(), outer_scope)); | |
| 5271 current_block_ = block; | 5301 current_block_ = block; |
| 5272 } | 5302 } |
| 5273 | 5303 |
| 5274 | 5304 |
| 5275 void Parser::OpenBlock() { | 5305 void Parser::OpenBlock() { |
| 5276 ASSERT(current_block_ != NULL); | 5306 ASSERT(current_block_ != NULL); |
| 5277 LocalScope* outer_scope = current_block_->scope; | 5307 LocalScope* outer_scope = current_block_->scope; |
| 5278 ChainNewBlock(new LocalScope(outer_scope, | 5308 ChainNewBlock(new(isolate()) LocalScope( |
| 5279 outer_scope->function_level(), | 5309 outer_scope, outer_scope->function_level(), outer_scope->loop_level())); |
| 5280 outer_scope->loop_level())); | |
| 5281 } | 5310 } |
| 5282 | 5311 |
| 5283 | 5312 |
| 5284 void Parser::OpenLoopBlock() { | 5313 void Parser::OpenLoopBlock() { |
| 5285 ASSERT(current_block_ != NULL); | 5314 ASSERT(current_block_ != NULL); |
| 5286 LocalScope* outer_scope = current_block_->scope; | 5315 LocalScope* outer_scope = current_block_->scope; |
| 5287 ChainNewBlock(new LocalScope(outer_scope, | 5316 ChainNewBlock(new(isolate()) LocalScope( |
| 5288 outer_scope->function_level(), | 5317 outer_scope, |
| 5289 outer_scope->loop_level() + 1)); | 5318 outer_scope->function_level(), |
| 5319 outer_scope->loop_level() + 1)); | |
| 5290 } | 5320 } |
| 5291 | 5321 |
| 5292 | 5322 |
| 5293 void Parser::OpenFunctionBlock(const Function& func) { | 5323 void Parser::OpenFunctionBlock(const Function& func) { |
| 5294 LocalScope* outer_scope; | 5324 LocalScope* outer_scope; |
| 5295 if (current_block_ == NULL) { | 5325 if (current_block_ == NULL) { |
| 5296 if (!func.IsLocalFunction()) { | 5326 if (!func.IsLocalFunction()) { |
| 5297 // We are compiling a non-nested function. | 5327 // We are compiling a non-nested function. |
| 5298 outer_scope = new(isolate()) LocalScope(NULL, 0, 0); | 5328 outer_scope = new(isolate()) LocalScope(NULL, 0, 0); |
| 5299 } else { | 5329 } else { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5383 // Populate local scope with the formal parameters. | 5413 // Populate local scope with the formal parameters. |
| 5384 void Parser::AddFormalParamsToScope(const ParamList* params, | 5414 void Parser::AddFormalParamsToScope(const ParamList* params, |
| 5385 LocalScope* scope) { | 5415 LocalScope* scope) { |
| 5386 ASSERT((params != NULL) && (params->parameters != NULL)); | 5416 ASSERT((params != NULL) && (params->parameters != NULL)); |
| 5387 ASSERT(scope != NULL); | 5417 ASSERT(scope != NULL); |
| 5388 const int num_parameters = params->parameters->length(); | 5418 const int num_parameters = params->parameters->length(); |
| 5389 for (int i = 0; i < num_parameters; i++) { | 5419 for (int i = 0; i < num_parameters; i++) { |
| 5390 ParamDesc& param_desc = (*params->parameters)[i]; | 5420 ParamDesc& param_desc = (*params->parameters)[i]; |
| 5391 ASSERT(!is_top_level_ || param_desc.type->IsResolved()); | 5421 ASSERT(!is_top_level_ || param_desc.type->IsResolved()); |
| 5392 const String* name = param_desc.name; | 5422 const String* name = param_desc.name; |
| 5393 LocalVariable* parameter = new LocalVariable( | 5423 LocalVariable* parameter = new(isolate()) LocalVariable( |
| 5394 param_desc.name_pos, *name, *param_desc.type); | 5424 param_desc.name_pos, *name, *param_desc.type); |
| 5395 if (!scope->InsertParameterAt(i, parameter)) { | 5425 if (!scope->InsertParameterAt(i, parameter)) { |
| 5396 ErrorMsg(param_desc.name_pos, | 5426 ErrorMsg(param_desc.name_pos, |
| 5397 "name '%s' already exists in scope", | 5427 "name '%s' already exists in scope", |
| 5398 param_desc.name->ToCString()); | 5428 param_desc.name->ToCString()); |
| 5399 } | 5429 } |
| 5400 param_desc.var = parameter; | 5430 param_desc.var = parameter; |
| 5401 if (param_desc.is_final) { | 5431 if (param_desc.is_final) { |
| 5402 parameter->set_is_final(); | 5432 parameter->set_is_final(); |
| 5403 } | 5433 } |
| 5404 if (param_desc.is_field_initializer) { | 5434 if (param_desc.is_field_initializer) { |
| 5405 parameter->set_invisible(true); | 5435 parameter->set_invisible(true); |
| 5406 } | 5436 } |
| 5407 } | 5437 } |
| 5408 } | 5438 } |
| 5409 | 5439 |
| 5410 | 5440 |
| 5411 // Builds ReturnNode/NativeBodyNode for a native function. | 5441 // Builds ReturnNode/NativeBodyNode for a native function. |
| 5412 void Parser::ParseNativeFunctionBlock(const ParamList* params, | 5442 void Parser::ParseNativeFunctionBlock(const ParamList* params, |
| 5413 const Function& func) { | 5443 const Function& func) { |
| 5414 ASSERT(func.is_native()); | 5444 ASSERT(func.is_native()); |
| 5415 TRACE_PARSER("ParseNativeFunctionBlock"); | 5445 TRACE_PARSER("ParseNativeFunctionBlock"); |
| 5416 const Class& cls = Class::Handle(func.Owner()); | 5446 const Class& cls = Class::Handle(isolate(), func.Owner()); |
| 5417 const Library& library = Library::Handle(cls.library()); | 5447 const Library& library = Library::Handle(isolate(), cls.library()); |
| 5418 ASSERT(func.NumParameters() == params->parameters->length()); | 5448 ASSERT(func.NumParameters() == params->parameters->length()); |
| 5419 | 5449 |
| 5420 // Parse the function name out. | 5450 // Parse the function name out. |
| 5421 const intptr_t native_pos = TokenPos(); | 5451 const intptr_t native_pos = TokenPos(); |
| 5422 const String& native_name = ParseNativeDeclaration(); | 5452 const String& native_name = ParseNativeDeclaration(); |
| 5423 | 5453 |
| 5424 // Now resolve the native function to the corresponding native entrypoint. | 5454 // Now resolve the native function to the corresponding native entrypoint. |
| 5425 const int num_params = NativeArguments::ParameterCountForResolution(func); | 5455 const int num_params = NativeArguments::ParameterCountForResolution(func); |
| 5426 bool auto_setup_scope = true; | 5456 bool auto_setup_scope = true; |
| 5427 NativeFunction native_function = NativeEntry::ResolveNative( | 5457 NativeFunction native_function = NativeEntry::ResolveNative( |
| 5428 library, native_name, num_params, &auto_setup_scope); | 5458 library, native_name, num_params, &auto_setup_scope); |
| 5429 if (native_function == NULL) { | 5459 if (native_function == NULL) { |
| 5430 ErrorMsg(native_pos, | 5460 ErrorMsg(native_pos, |
| 5431 "native function '%s' (%" Pd " arguments) cannot be found", | 5461 "native function '%s' (%" Pd " arguments) cannot be found", |
| 5432 native_name.ToCString(), func.NumParameters()); | 5462 native_name.ToCString(), func.NumParameters()); |
| 5433 } | 5463 } |
| 5434 func.SetIsNativeAutoSetupScope(auto_setup_scope); | 5464 func.SetIsNativeAutoSetupScope(auto_setup_scope); |
| 5435 | 5465 |
| 5436 // Now add the NativeBodyNode and return statement. | 5466 // Now add the NativeBodyNode and return statement. |
| 5437 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); | 5467 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); |
| 5438 bool is_bootstrap_native = Bootstrap::IsBootstapResolver(resolver); | 5468 bool is_bootstrap_native = Bootstrap::IsBootstapResolver(resolver); |
| 5439 current_block_->statements->Add( | 5469 current_block_->statements->Add(new(isolate()) ReturnNode( |
| 5440 new ReturnNode(TokenPos(), | 5470 TokenPos(), new(isolate()) NativeBodyNode( |
| 5441 new NativeBodyNode(TokenPos(), | 5471 TokenPos(), |
| 5442 Function::ZoneHandle(func.raw()), | 5472 Function::ZoneHandle(func.raw()), |
| 5443 native_name, | 5473 native_name, |
| 5444 native_function, | 5474 native_function, |
| 5445 current_block_->scope, | 5475 current_block_->scope, |
| 5446 is_bootstrap_native))); | 5476 is_bootstrap_native))); |
| 5447 } | 5477 } |
| 5448 | 5478 |
| 5449 | 5479 |
| 5450 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) { | 5480 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) { |
| 5451 ASSERT(!current_function().is_static()); | 5481 ASSERT(!current_function().is_static()); |
| 5452 return from_scope->LookupVariable(Symbols::This(), test_only); | 5482 return from_scope->LookupVariable(Symbols::This(), test_only); |
| 5453 } | 5483 } |
| 5454 | 5484 |
| 5455 | 5485 |
| 5456 LocalVariable* Parser::LookupTypeArgumentsParameter(LocalScope* from_scope, | 5486 LocalVariable* Parser::LookupTypeArgumentsParameter(LocalScope* from_scope, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 5482 | 5512 |
| 5483 | 5513 |
| 5484 AstNode* Parser::LoadReceiver(intptr_t token_pos) { | 5514 AstNode* Parser::LoadReceiver(intptr_t token_pos) { |
| 5485 // A nested function may access 'this', referring to the receiver of the | 5515 // A nested function may access 'this', referring to the receiver of the |
| 5486 // outermost enclosing function. | 5516 // outermost enclosing function. |
| 5487 const bool kTestOnly = false; | 5517 const bool kTestOnly = false; |
| 5488 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); | 5518 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); |
| 5489 if (receiver == NULL) { | 5519 if (receiver == NULL) { |
| 5490 ErrorMsg(token_pos, "illegal implicit access to receiver 'this'"); | 5520 ErrorMsg(token_pos, "illegal implicit access to receiver 'this'"); |
| 5491 } | 5521 } |
| 5492 return new LoadLocalNode(TokenPos(), receiver); | 5522 return new(isolate()) LoadLocalNode(TokenPos(), receiver); |
| 5493 } | 5523 } |
| 5494 | 5524 |
| 5495 | 5525 |
| 5496 AstNode* Parser::LoadTypeArgumentsParameter(intptr_t token_pos) { | 5526 AstNode* Parser::LoadTypeArgumentsParameter(intptr_t token_pos) { |
| 5497 // A nested function may access ':type_arguments' to use as instantiator, | 5527 // A nested function may access ':type_arguments' to use as instantiator, |
| 5498 // referring to the implicit first parameter of the outermost enclosing | 5528 // referring to the implicit first parameter of the outermost enclosing |
| 5499 // factory function. | 5529 // factory function. |
| 5500 const bool kTestOnly = false; | 5530 const bool kTestOnly = false; |
| 5501 LocalVariable* param = LookupTypeArgumentsParameter(current_block_->scope, | 5531 LocalVariable* param = LookupTypeArgumentsParameter(current_block_->scope, |
| 5502 kTestOnly); | 5532 kTestOnly); |
| 5503 ASSERT(param != NULL); | 5533 ASSERT(param != NULL); |
| 5504 return new LoadLocalNode(TokenPos(), param); | 5534 return new(isolate()) LoadLocalNode(TokenPos(), param); |
| 5505 } | 5535 } |
| 5506 | 5536 |
| 5507 | 5537 |
| 5508 AstNode* Parser::CallGetter(intptr_t token_pos, | 5538 AstNode* Parser::CallGetter(intptr_t token_pos, |
| 5509 AstNode* object, | 5539 AstNode* object, |
| 5510 const String& name) { | 5540 const String& name) { |
| 5511 return new InstanceGetterNode(token_pos, object, name); | 5541 return new(isolate()) InstanceGetterNode(token_pos, object, name); |
| 5512 } | 5542 } |
| 5513 | 5543 |
| 5514 | 5544 |
| 5515 // Returns ast nodes of the variable initialization. | 5545 // Returns ast nodes of the variable initialization. |
| 5516 AstNode* Parser::ParseVariableDeclaration(const AbstractType& type, | 5546 AstNode* Parser::ParseVariableDeclaration(const AbstractType& type, |
| 5517 bool is_final, | 5547 bool is_final, |
| 5518 bool is_const) { | 5548 bool is_const) { |
| 5519 TRACE_PARSER("ParseVariableDeclaration"); | 5549 TRACE_PARSER("ParseVariableDeclaration"); |
| 5520 ASSERT(IsIdentifier()); | 5550 ASSERT(IsIdentifier()); |
| 5521 const intptr_t ident_pos = TokenPos(); | 5551 const intptr_t ident_pos = TokenPos(); |
| 5522 const String& ident = *CurrentLiteral(); | 5552 const String& ident = *CurrentLiteral(); |
| 5523 LocalVariable* variable = new LocalVariable(ident_pos, ident, type); | 5553 LocalVariable* variable = new(isolate()) LocalVariable( |
| 5554 ident_pos, ident, type); | |
| 5524 ConsumeToken(); // Variable identifier. | 5555 ConsumeToken(); // Variable identifier. |
| 5525 AstNode* initialization = NULL; | 5556 AstNode* initialization = NULL; |
| 5526 if (CurrentToken() == Token::kASSIGN) { | 5557 if (CurrentToken() == Token::kASSIGN) { |
| 5527 // Variable initialization. | 5558 // Variable initialization. |
| 5528 const intptr_t assign_pos = TokenPos(); | 5559 const intptr_t assign_pos = TokenPos(); |
| 5529 ConsumeToken(); | 5560 ConsumeToken(); |
| 5530 AstNode* expr = ParseExpr(is_const, kConsumeCascades); | 5561 AstNode* expr = ParseExpr(is_const, kConsumeCascades); |
| 5531 initialization = new StoreLocalNode(assign_pos, variable, expr); | 5562 initialization = new(isolate()) StoreLocalNode( |
| 5563 assign_pos, variable, expr); | |
| 5532 if (is_const) { | 5564 if (is_const) { |
| 5533 ASSERT(expr->IsLiteralNode()); | 5565 ASSERT(expr->IsLiteralNode()); |
| 5534 variable->SetConstValue(expr->AsLiteralNode()->literal()); | 5566 variable->SetConstValue(expr->AsLiteralNode()->literal()); |
| 5535 } | 5567 } |
| 5536 } else if (is_final || is_const) { | 5568 } else if (is_final || is_const) { |
| 5537 ErrorMsg(ident_pos, | 5569 ErrorMsg(ident_pos, |
| 5538 "missing initialization of 'final' or 'const' variable"); | 5570 "missing initialization of 'final' or 'const' variable"); |
| 5539 } else { | 5571 } else { |
| 5540 // Initialize variable with null. | 5572 // Initialize variable with null. |
| 5541 AstNode* null_expr = new LiteralNode(ident_pos, Instance::ZoneHandle()); | 5573 AstNode* null_expr = new(isolate()) LiteralNode( |
| 5542 initialization = new StoreLocalNode(ident_pos, variable, null_expr); | 5574 ident_pos, Instance::ZoneHandle()); |
| 5575 initialization = new(isolate()) StoreLocalNode( | |
| 5576 ident_pos, variable, null_expr); | |
| 5543 } | 5577 } |
| 5544 | 5578 |
| 5545 ASSERT(current_block_ != NULL); | 5579 ASSERT(current_block_ != NULL); |
| 5546 const intptr_t previous_pos = | 5580 const intptr_t previous_pos = |
| 5547 current_block_->scope->PreviousReferencePos(ident); | 5581 current_block_->scope->PreviousReferencePos(ident); |
| 5548 if (previous_pos >= 0) { | 5582 if (previous_pos >= 0) { |
| 5549 ASSERT(!script_.IsNull()); | 5583 ASSERT(!script_.IsNull()); |
| 5550 if (previous_pos > ident_pos) { | 5584 if (previous_pos > ident_pos) { |
| 5551 ErrorMsg(ident_pos, | 5585 ErrorMsg(ident_pos, |
| 5552 "initializer of '%s' may not refer to itself", | 5586 "initializer of '%s' may not refer to itself", |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5651 NULL); | 5685 NULL); |
| 5652 sequence->Add(ParseVariableDeclaration(type, is_final, is_const)); | 5686 sequence->Add(ParseVariableDeclaration(type, is_final, is_const)); |
| 5653 initializers = sequence; | 5687 initializers = sequence; |
| 5654 } | 5688 } |
| 5655 return initializers; | 5689 return initializers; |
| 5656 } | 5690 } |
| 5657 | 5691 |
| 5658 | 5692 |
| 5659 AstNode* Parser::ParseFunctionStatement(bool is_literal) { | 5693 AstNode* Parser::ParseFunctionStatement(bool is_literal) { |
| 5660 TRACE_PARSER("ParseFunctionStatement"); | 5694 TRACE_PARSER("ParseFunctionStatement"); |
| 5661 AbstractType& result_type = AbstractType::Handle(); | 5695 AbstractType& result_type = AbstractType::Handle(isolate()); |
| 5662 const String* variable_name = NULL; | 5696 const String* variable_name = NULL; |
| 5663 const String* function_name = NULL; | 5697 const String* function_name = NULL; |
| 5664 | 5698 |
| 5665 result_type = Type::DynamicType(); | 5699 result_type = Type::DynamicType(); |
| 5666 | 5700 |
| 5667 const intptr_t function_pos = TokenPos(); | 5701 const intptr_t function_pos = TokenPos(); |
| 5668 if (is_literal) { | 5702 if (is_literal) { |
| 5669 ASSERT(CurrentToken() == Token::kLPAREN); | 5703 ASSERT(CurrentToken() == Token::kLPAREN); |
| 5670 function_name = &Symbols::AnonymousClosure(); | 5704 function_name = &Symbols::AnonymousClosure(); |
| 5671 } else { | 5705 } else { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5725 // passed as a function argument, or returned as a function result. | 5759 // passed as a function argument, or returned as a function result. |
| 5726 | 5760 |
| 5727 LocalVariable* function_variable = NULL; | 5761 LocalVariable* function_variable = NULL; |
| 5728 Type& function_type = Type::ZoneHandle(); | 5762 Type& function_type = Type::ZoneHandle(); |
| 5729 if (variable_name != NULL) { | 5763 if (variable_name != NULL) { |
| 5730 // Since the function type depends on the signature of the closure function, | 5764 // Since the function type depends on the signature of the closure function, |
| 5731 // it cannot be determined before the formal parameter list of the closure | 5765 // it cannot be determined before the formal parameter list of the closure |
| 5732 // function is parsed. Therefore, we set the function type to a new | 5766 // function is parsed. Therefore, we set the function type to a new |
| 5733 // parameterized type to be patched after the actual type is known. | 5767 // parameterized type to be patched after the actual type is known. |
| 5734 // We temporarily use the class of the Function interface. | 5768 // We temporarily use the class of the Function interface. |
| 5735 const Class& unknown_signature_class = Class::Handle( | 5769 const Class& unknown_signature_class = Class::Handle(isolate(), |
| 5736 Type::Handle(Type::Function()).type_class()); | 5770 Type::Handle(isolate(), Type::Function()).type_class()); |
| 5737 function_type = Type::New( | 5771 function_type = Type::New(unknown_signature_class, |
| 5738 unknown_signature_class, TypeArguments::Handle(), function_pos); | 5772 TypeArguments::Handle(isolate()), function_pos); |
| 5739 function_type.SetIsFinalized(); // No finalization needed. | 5773 function_type.SetIsFinalized(); // No finalization needed. |
| 5740 | 5774 |
| 5741 // Add the function variable to the scope before parsing the function in | 5775 // Add the function variable to the scope before parsing the function in |
| 5742 // order to allow self reference from inside the function. | 5776 // order to allow self reference from inside the function. |
| 5743 function_variable = new LocalVariable(function_pos, | 5777 function_variable = new(isolate()) LocalVariable(function_pos, |
| 5744 *variable_name, | 5778 *variable_name, |
| 5745 function_type); | 5779 function_type); |
| 5746 function_variable->set_is_final(); | 5780 function_variable->set_is_final(); |
| 5747 ASSERT(current_block_ != NULL); | 5781 ASSERT(current_block_ != NULL); |
| 5748 ASSERT(current_block_->scope != NULL); | 5782 ASSERT(current_block_->scope != NULL); |
| 5749 if (!current_block_->scope->AddVariable(function_variable)) { | 5783 if (!current_block_->scope->AddVariable(function_variable)) { |
| 5750 LocalVariable* existing_var = | 5784 LocalVariable* existing_var = |
| 5751 current_block_->scope->LookupVariable(function_variable->name(), | 5785 current_block_->scope->LookupVariable(function_variable->name(), |
| 5752 true); | 5786 true); |
| 5753 ASSERT(existing_var != NULL); | 5787 ASSERT(existing_var != NULL); |
| 5754 if (existing_var->owner() == current_block_->scope) { | 5788 if (existing_var->owner() == current_block_->scope) { |
| 5755 ErrorMsg(function_pos, "identifier '%s' already defined", | 5789 ErrorMsg(function_pos, "identifier '%s' already defined", |
| 5756 function_variable->name().ToCString()); | 5790 function_variable->name().ToCString()); |
| 5757 } else { | 5791 } else { |
| 5758 ErrorMsg(function_pos, | 5792 ErrorMsg(function_pos, |
| 5759 "'%s' from outer scope has already been used, cannot redefine", | 5793 "'%s' from outer scope has already been used, cannot redefine", |
| 5760 function_variable->name().ToCString()); | 5794 function_variable->name().ToCString()); |
| 5761 } | 5795 } |
| 5762 } | 5796 } |
| 5763 } | 5797 } |
| 5764 | 5798 |
| 5765 // Parse the local function. | 5799 // Parse the local function. |
| 5766 Array& default_parameter_values = Array::Handle(); | 5800 Array& default_parameter_values = Array::Handle(isolate()); |
| 5767 SequenceNode* statements = Parser::ParseFunc(function, | 5801 SequenceNode* statements = Parser::ParseFunc(function, |
| 5768 &default_parameter_values); | 5802 &default_parameter_values); |
| 5769 | 5803 |
| 5770 // Now that the local function has formal parameters, lookup the signature | 5804 // Now that the local function has formal parameters, lookup the signature |
| 5771 // class in the current library (but not in its imports) and only create a new | 5805 // class in the current library (but not in its imports) and only create a new |
| 5772 // canonical signature class if it does not exist yet. | 5806 // canonical signature class if it does not exist yet. |
| 5773 const String& signature = String::Handle(function.Signature()); | 5807 const String& signature = String::Handle(isolate(), function.Signature()); |
| 5774 Class& signature_class = Class::ZoneHandle(); | 5808 Class& signature_class = Class::ZoneHandle(); |
| 5775 if (!is_new_closure) { | 5809 if (!is_new_closure) { |
| 5776 signature_class = function.signature_class(); | 5810 signature_class = function.signature_class(); |
| 5777 } | 5811 } |
| 5778 if (signature_class.IsNull()) { | 5812 if (signature_class.IsNull()) { |
| 5779 signature_class = library_.LookupLocalClass(signature); | 5813 signature_class = library_.LookupLocalClass(signature); |
| 5780 } | 5814 } |
| 5781 if (signature_class.IsNull()) { | 5815 if (signature_class.IsNull()) { |
| 5782 // If we don't have a signature class yet, this must be a closure we | 5816 // If we don't have a signature class yet, this must be a closure we |
| 5783 // have not parsed before. | 5817 // have not parsed before. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 5799 ASSERT(current_class().is_finalized()); | 5833 ASSERT(current_class().is_finalized()); |
| 5800 | 5834 |
| 5801 // Make sure that the instantiator is captured. | 5835 // Make sure that the instantiator is captured. |
| 5802 if ((signature_class.NumTypeParameters() > 0) && | 5836 if ((signature_class.NumTypeParameters() > 0) && |
| 5803 (current_block_->scope->function_level() > 0)) { | 5837 (current_block_->scope->function_level() > 0)) { |
| 5804 CaptureInstantiator(); | 5838 CaptureInstantiator(); |
| 5805 } | 5839 } |
| 5806 | 5840 |
| 5807 // Since the signature type is cached by the signature class, it may have | 5841 // Since the signature type is cached by the signature class, it may have |
| 5808 // been finalized already. | 5842 // been finalized already. |
| 5809 Type& signature_type = Type::Handle(signature_class.SignatureType()); | 5843 Type& signature_type = Type::Handle(isolate(), |
| 5810 TypeArguments& signature_type_arguments = | 5844 signature_class.SignatureType()); |
| 5811 TypeArguments::Handle(signature_type.arguments()); | 5845 TypeArguments& signature_type_arguments = TypeArguments::Handle(isolate(), |
| 5846 signature_type.arguments()); | |
| 5812 | 5847 |
| 5813 if (!signature_type.IsFinalized()) { | 5848 if (!signature_type.IsFinalized()) { |
| 5814 signature_type ^= ClassFinalizer::FinalizeType( | 5849 signature_type ^= ClassFinalizer::FinalizeType( |
| 5815 signature_class, signature_type, ClassFinalizer::kCanonicalize); | 5850 signature_class, signature_type, ClassFinalizer::kCanonicalize); |
| 5816 | 5851 |
| 5817 // The call to ClassFinalizer::FinalizeType may have | 5852 // The call to ClassFinalizer::FinalizeType may have |
| 5818 // extended the vector of type arguments. | 5853 // extended the vector of type arguments. |
| 5819 signature_type_arguments = signature_type.arguments(); | 5854 signature_type_arguments = signature_type.arguments(); |
| 5820 ASSERT(signature_type_arguments.IsNull() || | 5855 ASSERT(signature_type_arguments.IsNull() || |
| 5821 (signature_type_arguments.Length() == | 5856 (signature_type_arguments.Length() == |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5856 // captured. The captured variables will be recorded along with their | 5891 // captured. The captured variables will be recorded along with their |
| 5857 // allocation information in a Scope object stored in the function object. | 5892 // allocation information in a Scope object stored in the function object. |
| 5858 // This Scope object is then provided to the compiler when compiling the local | 5893 // This Scope object is then provided to the compiler when compiling the local |
| 5859 // function. It would be too early to record the captured variables here, | 5894 // function. It would be too early to record the captured variables here, |
| 5860 // since further closure functions may capture more variables. | 5895 // since further closure functions may capture more variables. |
| 5861 // This Scope object is constructed after all variables have been allocated. | 5896 // This Scope object is constructed after all variables have been allocated. |
| 5862 // The local scope of the parsed function can be pruned, since contained | 5897 // The local scope of the parsed function can be pruned, since contained |
| 5863 // variables are not relevant for the compilation of the enclosing function. | 5898 // variables are not relevant for the compilation of the enclosing function. |
| 5864 // This pruning is done by omitting to hook the local scope in its parent | 5899 // This pruning is done by omitting to hook the local scope in its parent |
| 5865 // scope in the constructor of LocalScope. | 5900 // scope in the constructor of LocalScope. |
| 5866 AstNode* closure = | 5901 AstNode* closure = new(isolate()) ClosureNode( |
| 5867 new ClosureNode(function_pos, function, NULL, statements->scope()); | 5902 function_pos, function, NULL, statements->scope()); |
| 5868 | 5903 |
| 5869 if (function_variable == NULL) { | 5904 if (function_variable == NULL) { |
| 5870 ASSERT(is_literal); | 5905 ASSERT(is_literal); |
| 5871 return closure; | 5906 return closure; |
| 5872 } else { | 5907 } else { |
| 5873 AstNode* initialization = | 5908 AstNode* initialization = new(isolate()) StoreLocalNode( |
| 5874 new StoreLocalNode(function_pos, function_variable, closure); | 5909 function_pos, function_variable, closure); |
| 5875 return initialization; | 5910 return initialization; |
| 5876 } | 5911 } |
| 5877 } | 5912 } |
| 5878 | 5913 |
| 5879 | 5914 |
| 5880 // Returns true if the current and next tokens can be parsed as type | 5915 // Returns true if the current and next tokens can be parsed as type |
| 5881 // parameters. Current token position is not saved and restored. | 5916 // parameters. Current token position is not saved and restored. |
| 5882 bool Parser::TryParseTypeParameters() { | 5917 bool Parser::TryParseTypeParameters() { |
| 5883 if (CurrentToken() == Token::kLT) { | 5918 if (CurrentToken() == Token::kLT) { |
| 5884 // We are possibly looking at type parameters. Find closing ">". | 5919 // We are possibly looking at type parameters. Find closing ">". |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6249 ExpectToken(Token::kLPAREN); | 6284 ExpectToken(Token::kLPAREN); |
| 6250 AstNode* cond_expr = ParseExpr(kAllowConst, kConsumeCascades); | 6285 AstNode* cond_expr = ParseExpr(kAllowConst, kConsumeCascades); |
| 6251 ExpectToken(Token::kRPAREN); | 6286 ExpectToken(Token::kRPAREN); |
| 6252 const bool parsing_loop_body = false; | 6287 const bool parsing_loop_body = false; |
| 6253 SequenceNode* true_branch = ParseNestedStatement(parsing_loop_body, NULL); | 6288 SequenceNode* true_branch = ParseNestedStatement(parsing_loop_body, NULL); |
| 6254 SequenceNode* false_branch = NULL; | 6289 SequenceNode* false_branch = NULL; |
| 6255 if (CurrentToken() == Token::kELSE) { | 6290 if (CurrentToken() == Token::kELSE) { |
| 6256 ConsumeToken(); | 6291 ConsumeToken(); |
| 6257 false_branch = ParseNestedStatement(parsing_loop_body, NULL); | 6292 false_branch = ParseNestedStatement(parsing_loop_body, NULL); |
| 6258 } | 6293 } |
| 6259 AstNode* if_node = new IfNode(if_pos, cond_expr, true_branch, false_branch); | 6294 AstNode* if_node = new(isolate()) IfNode( |
| 6295 if_pos, cond_expr, true_branch, false_branch); | |
| 6260 if (label != NULL) { | 6296 if (label != NULL) { |
| 6261 current_block_->statements->Add(if_node); | 6297 current_block_->statements->Add(if_node); |
| 6262 SequenceNode* sequence = CloseBlock(); | 6298 SequenceNode* sequence = CloseBlock(); |
| 6263 sequence->set_label(label); | 6299 sequence->set_label(label); |
| 6264 if_node = sequence; | 6300 if_node = sequence; |
| 6265 } | 6301 } |
| 6266 return if_node; | 6302 return if_node; |
| 6267 } | 6303 } |
| 6268 | 6304 |
| 6269 | 6305 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6316 // Check that the type class does not override the == operator. | 6352 // Check that the type class does not override the == operator. |
| 6317 // Check this only in the first loop iteration since all values | 6353 // Check this only in the first loop iteration since all values |
| 6318 // are of the same type, which we check above. | 6354 // are of the same type, which we check above. |
| 6319 if (ImplementsEqualOperator(val)) { | 6355 if (ImplementsEqualOperator(val)) { |
| 6320 ErrorMsg(val_pos, | 6356 ErrorMsg(val_pos, |
| 6321 "type class of case expression must not implement operator =="); | 6357 "type class of case expression must not implement operator =="); |
| 6322 } | 6358 } |
| 6323 } | 6359 } |
| 6324 } | 6360 } |
| 6325 if (first_value.IsInteger()) { | 6361 if (first_value.IsInteger()) { |
| 6326 return Type::Handle(Type::IntType()).type_class(); | 6362 return Type::Handle(isolate(), Type::IntType()).type_class(); |
| 6327 } else if (first_value.IsString()) { | 6363 } else if (first_value.IsString()) { |
| 6328 return Type::Handle(Type::StringType()).type_class(); | 6364 return Type::Handle(isolate(), Type::StringType()).type_class(); |
| 6329 } | 6365 } |
| 6330 return first_value.clazz(); | 6366 return first_value.clazz(); |
| 6331 } | 6367 } |
| 6332 | 6368 |
| 6333 | 6369 |
| 6334 CaseNode* Parser::ParseCaseClause(LocalVariable* switch_expr_value, | 6370 CaseNode* Parser::ParseCaseClause(LocalVariable* switch_expr_value, |
| 6335 GrowableArray<LiteralNode*>* case_expr_values, | 6371 GrowableArray<LiteralNode*>* case_expr_values, |
| 6336 SourceLabel* case_label) { | 6372 SourceLabel* case_label) { |
| 6337 TRACE_PARSER("ParseCaseClause"); | 6373 TRACE_PARSER("ParseCaseClause"); |
| 6338 bool default_seen = false; | 6374 bool default_seen = false; |
| 6339 const intptr_t case_pos = TokenPos(); | 6375 const intptr_t case_pos = TokenPos(); |
| 6340 // The case expressions node sequence does not own the enclosing scope. | 6376 // The case expressions node sequence does not own the enclosing scope. |
| 6341 SequenceNode* case_expressions = new SequenceNode(case_pos, NULL); | 6377 SequenceNode* case_expressions = new(isolate()) SequenceNode(case_pos, NULL); |
| 6342 while (CurrentToken() == Token::kCASE || CurrentToken() == Token::kDEFAULT) { | 6378 while (CurrentToken() == Token::kCASE || CurrentToken() == Token::kDEFAULT) { |
| 6343 if (CurrentToken() == Token::kCASE) { | 6379 if (CurrentToken() == Token::kCASE) { |
| 6344 if (default_seen) { | 6380 if (default_seen) { |
| 6345 ErrorMsg("default clause must be last case"); | 6381 ErrorMsg("default clause must be last case"); |
| 6346 } | 6382 } |
| 6347 ConsumeToken(); // Keyword case. | 6383 ConsumeToken(); // Keyword case. |
| 6348 const intptr_t expr_pos = TokenPos(); | 6384 const intptr_t expr_pos = TokenPos(); |
| 6349 AstNode* expr = ParseExpr(kRequireConst, kConsumeCascades); | 6385 AstNode* expr = ParseExpr(kRequireConst, kConsumeCascades); |
| 6350 ASSERT(expr->IsLiteralNode()); | 6386 ASSERT(expr->IsLiteralNode()); |
| 6351 case_expr_values->Add(expr->AsLiteralNode()); | 6387 case_expr_values->Add(expr->AsLiteralNode()); |
| 6352 | 6388 |
| 6353 AstNode* switch_expr_load = new LoadLocalNode(case_pos, | 6389 AstNode* switch_expr_load = new(isolate()) LoadLocalNode( |
| 6354 switch_expr_value); | 6390 case_pos, switch_expr_value); |
| 6355 AstNode* case_comparison = new ComparisonNode(expr_pos, | 6391 AstNode* case_comparison = new(isolate()) ComparisonNode( |
| 6356 Token::kEQ, | 6392 expr_pos, Token::kEQ, expr, switch_expr_load); |
| 6357 expr, | |
| 6358 switch_expr_load); | |
| 6359 case_expressions->Add(case_comparison); | 6393 case_expressions->Add(case_comparison); |
| 6360 } else { | 6394 } else { |
| 6361 if (default_seen) { | 6395 if (default_seen) { |
| 6362 ErrorMsg("only one default clause is allowed"); | 6396 ErrorMsg("only one default clause is allowed"); |
| 6363 } | 6397 } |
| 6364 ConsumeToken(); // Keyword default. | 6398 ConsumeToken(); // Keyword default. |
| 6365 default_seen = true; | 6399 default_seen = true; |
| 6366 // The default case always succeeds. | 6400 // The default case always succeeds. |
| 6367 } | 6401 } |
| 6368 ExpectToken(Token::kCOLON); | 6402 ExpectToken(Token::kCOLON); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 6381 next_token = CurrentToken(); | 6415 next_token = CurrentToken(); |
| 6382 } | 6416 } |
| 6383 if (next_token == Token::kRBRACE) { | 6417 if (next_token == Token::kRBRACE) { |
| 6384 // End of switch statement. | 6418 // End of switch statement. |
| 6385 break; | 6419 break; |
| 6386 } | 6420 } |
| 6387 if ((next_token == Token::kCASE) || (next_token == Token::kDEFAULT)) { | 6421 if ((next_token == Token::kCASE) || (next_token == Token::kDEFAULT)) { |
| 6388 // End of this case clause. If there is a possible fall-through to | 6422 // End of this case clause. If there is a possible fall-through to |
| 6389 // the next case clause, throw an implicit FallThroughError. | 6423 // the next case clause, throw an implicit FallThroughError. |
| 6390 if (!abrupt_completing_seen) { | 6424 if (!abrupt_completing_seen) { |
| 6391 ArgumentListNode* arguments = new ArgumentListNode(TokenPos()); | 6425 ArgumentListNode* arguments = new(isolate()) ArgumentListNode( |
| 6392 arguments->Add(new LiteralNode( | 6426 TokenPos()); |
| 6427 arguments->Add(new(isolate()) LiteralNode( | |
| 6393 TokenPos(), Integer::ZoneHandle(Integer::New(TokenPos())))); | 6428 TokenPos(), Integer::ZoneHandle(Integer::New(TokenPos())))); |
| 6394 current_block_->statements->Add( | 6429 current_block_->statements->Add( |
| 6395 MakeStaticCall(Symbols::FallThroughError(), | 6430 MakeStaticCall(Symbols::FallThroughError(), |
| 6396 Library::PrivateCoreLibName(Symbols::ThrowNew()), | 6431 Library::PrivateCoreLibName(Symbols::ThrowNew()), |
| 6397 arguments)); | 6432 arguments)); |
| 6398 } | 6433 } |
| 6399 break; | 6434 break; |
| 6400 } | 6435 } |
| 6401 // The next statement still belongs to this case. | 6436 // The next statement still belongs to this case. |
| 6402 AstNode* statement = ParseStatement(); | 6437 AstNode* statement = ParseStatement(); |
| 6403 if (statement != NULL) { | 6438 if (statement != NULL) { |
| 6404 current_block_->statements->Add(statement); | 6439 current_block_->statements->Add(statement); |
| 6405 abrupt_completing_seen |= IsAbruptCompleting(statement); | 6440 abrupt_completing_seen |= IsAbruptCompleting(statement); |
| 6406 } | 6441 } |
| 6407 } | 6442 } |
| 6408 SequenceNode* statements = CloseBlock(); | 6443 SequenceNode* statements = CloseBlock(); |
| 6409 return new CaseNode(case_pos, case_label, | 6444 return new(isolate()) CaseNode(case_pos, case_label, |
| 6410 case_expressions, default_seen, switch_expr_value, statements); | 6445 case_expressions, default_seen, switch_expr_value, statements); |
| 6411 } | 6446 } |
| 6412 | 6447 |
| 6413 | 6448 |
| 6414 AstNode* Parser::ParseSwitchStatement(String* label_name) { | 6449 AstNode* Parser::ParseSwitchStatement(String* label_name) { |
| 6415 TRACE_PARSER("ParseSwitchStatement"); | 6450 TRACE_PARSER("ParseSwitchStatement"); |
| 6416 ASSERT(CurrentToken() == Token::kSWITCH); | 6451 ASSERT(CurrentToken() == Token::kSWITCH); |
| 6417 const intptr_t switch_pos = TokenPos(); | 6452 const intptr_t switch_pos = TokenPos(); |
| 6418 SourceLabel* label = | 6453 SourceLabel* label = |
| 6419 SourceLabel::New(switch_pos, label_name, SourceLabel::kSwitch); | 6454 SourceLabel::New(switch_pos, label_name, SourceLabel::kSwitch); |
| 6420 ConsumeToken(); | 6455 ConsumeToken(); |
| 6421 ExpectToken(Token::kLPAREN); | 6456 ExpectToken(Token::kLPAREN); |
| 6422 const intptr_t expr_pos = TokenPos(); | 6457 const intptr_t expr_pos = TokenPos(); |
| 6423 AstNode* switch_expr = ParseExpr(kAllowConst, kConsumeCascades); | 6458 AstNode* switch_expr = ParseExpr(kAllowConst, kConsumeCascades); |
| 6424 ExpectToken(Token::kRPAREN); | 6459 ExpectToken(Token::kRPAREN); |
| 6425 ExpectToken(Token::kLBRACE); | 6460 ExpectToken(Token::kLBRACE); |
| 6426 OpenBlock(); | 6461 OpenBlock(); |
| 6427 current_block_->scope->AddLabel(label); | 6462 current_block_->scope->AddLabel(label); |
| 6428 | 6463 |
| 6429 // Store switch expression in temporary local variable. The type of the | 6464 // Store switch expression in temporary local variable. The type of the |
| 6430 // variable is set to dynamic. It will later be patched to match the | 6465 // variable is set to dynamic. It will later be patched to match the |
| 6431 // type of the case clause expressions. Therefore, we have to allocate | 6466 // type of the case clause expressions. Therefore, we have to allocate |
| 6432 // a new type representing dynamic and can't reuse the canonical | 6467 // a new type representing dynamic and can't reuse the canonical |
| 6433 // type object for dynamic. | 6468 // type object for dynamic. |
| 6434 const Type& temp_var_type = | 6469 const Type& temp_var_type = Type::ZoneHandle(isolate(), |
| 6435 Type::ZoneHandle(Type::New(Class::Handle(Object::dynamic_class()), | 6470 Type::New(Class::Handle(isolate(), Object::dynamic_class()), |
| 6436 TypeArguments::Handle(), | 6471 TypeArguments::Handle(isolate()), |
| 6437 expr_pos)); | 6472 expr_pos)); |
| 6438 temp_var_type.SetIsFinalized(); | 6473 temp_var_type.SetIsFinalized(); |
| 6439 LocalVariable* temp_variable = | 6474 LocalVariable* temp_variable = new(isolate()) LocalVariable( |
| 6440 new LocalVariable(expr_pos, Symbols::SwitchExpr(), temp_var_type); | 6475 expr_pos, Symbols::SwitchExpr(), temp_var_type); |
| 6441 current_block_->scope->AddVariable(temp_variable); | 6476 current_block_->scope->AddVariable(temp_variable); |
| 6442 AstNode* save_switch_expr = | 6477 AstNode* save_switch_expr = new(isolate()) StoreLocalNode( |
| 6443 new StoreLocalNode(expr_pos, temp_variable, switch_expr); | 6478 expr_pos, temp_variable, switch_expr); |
| 6444 current_block_->statements->Add(save_switch_expr); | 6479 current_block_->statements->Add(save_switch_expr); |
| 6445 | 6480 |
| 6446 // Parse case clauses | 6481 // Parse case clauses |
| 6447 bool default_seen = false; | 6482 bool default_seen = false; |
| 6448 GrowableArray<LiteralNode*> case_expr_values; | 6483 GrowableArray<LiteralNode*> case_expr_values; |
| 6449 while (true) { | 6484 while (true) { |
| 6450 // Check for statement label | 6485 // Check for statement label |
| 6451 SourceLabel* case_label = NULL; | 6486 SourceLabel* case_label = NULL; |
| 6452 if (IsIdentifier() && LookaheadToken(1) == Token::kCOLON) { | 6487 if (IsIdentifier() && LookaheadToken(1) == Token::kCOLON) { |
| 6453 // Case statements start with a label. | 6488 // Case statements start with a label. |
| 6454 String* label_name = CurrentLiteral(); | 6489 String* label_name = CurrentLiteral(); |
| 6455 const intptr_t label_pos = TokenPos(); | 6490 const intptr_t label_pos = TokenPos(); |
| 6456 ConsumeToken(); // Consume label identifier. | 6491 ConsumeToken(); // Consume label identifier. |
| 6457 ConsumeToken(); // Consume colon. | 6492 ConsumeToken(); // Consume colon. |
| 6458 case_label = current_block_->scope->LocalLookupLabel(*label_name); | 6493 case_label = current_block_->scope->LocalLookupLabel(*label_name); |
| 6459 if (case_label == NULL) { | 6494 if (case_label == NULL) { |
| 6460 // Label does not exist yet. Add it to scope of switch statement. | 6495 // Label does not exist yet. Add it to scope of switch statement. |
| 6461 case_label = | 6496 case_label = new(isolate()) SourceLabel( |
| 6462 new SourceLabel(label_pos, *label_name, SourceLabel::kCase); | 6497 label_pos, *label_name, SourceLabel::kCase); |
| 6463 current_block_->scope->AddLabel(case_label); | 6498 current_block_->scope->AddLabel(case_label); |
| 6464 } else if (case_label->kind() == SourceLabel::kForward) { | 6499 } else if (case_label->kind() == SourceLabel::kForward) { |
| 6465 // We have seen a 'continue' with this label name. Resolve | 6500 // We have seen a 'continue' with this label name. Resolve |
| 6466 // the forward reference. | 6501 // the forward reference. |
| 6467 case_label->ResolveForwardReference(); | 6502 case_label->ResolveForwardReference(); |
| 6468 } else { | 6503 } else { |
| 6469 ErrorMsg(label_pos, "label '%s' already exists in scope", | 6504 ErrorMsg(label_pos, "label '%s' already exists in scope", |
| 6470 label_name->ToCString()); | 6505 label_name->ToCString()); |
| 6471 } | 6506 } |
| 6472 ASSERT(case_label->kind() == SourceLabel::kCase); | 6507 ASSERT(case_label->kind() == SourceLabel::kCase); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 6487 } else { | 6522 } else { |
| 6488 break; | 6523 break; |
| 6489 } | 6524 } |
| 6490 } | 6525 } |
| 6491 | 6526 |
| 6492 // Check that all expressions in case clauses are of the same class, | 6527 // Check that all expressions in case clauses are of the same class, |
| 6493 // or implement int, double or String. Patch the type of the temporary | 6528 // or implement int, double or String. Patch the type of the temporary |
| 6494 // variable holding the switch expression to match the type of the | 6529 // variable holding the switch expression to match the type of the |
| 6495 // case clause constants. | 6530 // case clause constants. |
| 6496 temp_var_type.set_type_class( | 6531 temp_var_type.set_type_class( |
| 6497 Class::Handle(CheckCaseExpressions(case_expr_values))); | 6532 Class::Handle(isolate(), CheckCaseExpressions(case_expr_values))); |
| 6498 | 6533 |
| 6499 // Check for unresolved label references. | 6534 // Check for unresolved label references. |
| 6500 SourceLabel* unresolved_label = | 6535 SourceLabel* unresolved_label = |
| 6501 current_block_->scope->CheckUnresolvedLabels(); | 6536 current_block_->scope->CheckUnresolvedLabels(); |
| 6502 if (unresolved_label != NULL) { | 6537 if (unresolved_label != NULL) { |
| 6503 ErrorMsg("unresolved reference to label '%s'", | 6538 ErrorMsg("unresolved reference to label '%s'", |
| 6504 unresolved_label->name().ToCString()); | 6539 unresolved_label->name().ToCString()); |
| 6505 } | 6540 } |
| 6506 | 6541 |
| 6507 SequenceNode* switch_body = CloseBlock(); | 6542 SequenceNode* switch_body = CloseBlock(); |
| 6508 ExpectToken(Token::kRBRACE); | 6543 ExpectToken(Token::kRBRACE); |
| 6509 return new SwitchNode(switch_pos, label, switch_body); | 6544 return new(isolate()) SwitchNode(switch_pos, label, switch_body); |
| 6510 } | 6545 } |
| 6511 | 6546 |
| 6512 | 6547 |
| 6513 AstNode* Parser::ParseWhileStatement(String* label_name) { | 6548 AstNode* Parser::ParseWhileStatement(String* label_name) { |
| 6514 TRACE_PARSER("ParseWhileStatement"); | 6549 TRACE_PARSER("ParseWhileStatement"); |
| 6515 const intptr_t while_pos = TokenPos(); | 6550 const intptr_t while_pos = TokenPos(); |
| 6516 SourceLabel* label = | 6551 SourceLabel* label = |
| 6517 SourceLabel::New(while_pos, label_name, SourceLabel::kWhile); | 6552 SourceLabel::New(while_pos, label_name, SourceLabel::kWhile); |
| 6518 ConsumeToken(); | 6553 ConsumeToken(); |
| 6519 ExpectToken(Token::kLPAREN); | 6554 ExpectToken(Token::kLPAREN); |
| 6520 AstNode* cond_expr = ParseExpr(kAllowConst, kConsumeCascades); | 6555 AstNode* cond_expr = ParseExpr(kAllowConst, kConsumeCascades); |
| 6521 ExpectToken(Token::kRPAREN); | 6556 ExpectToken(Token::kRPAREN); |
| 6522 const bool parsing_loop_body = true; | 6557 const bool parsing_loop_body = true; |
| 6523 SequenceNode* while_body = ParseNestedStatement(parsing_loop_body, label); | 6558 SequenceNode* while_body = ParseNestedStatement(parsing_loop_body, label); |
| 6524 return new WhileNode(while_pos, label, cond_expr, while_body); | 6559 return new(isolate()) WhileNode(while_pos, label, cond_expr, while_body); |
| 6525 } | 6560 } |
| 6526 | 6561 |
| 6527 | 6562 |
| 6528 AstNode* Parser::ParseDoWhileStatement(String* label_name) { | 6563 AstNode* Parser::ParseDoWhileStatement(String* label_name) { |
| 6529 TRACE_PARSER("ParseDoWhileStatement"); | 6564 TRACE_PARSER("ParseDoWhileStatement"); |
| 6530 const intptr_t do_pos = TokenPos(); | 6565 const intptr_t do_pos = TokenPos(); |
| 6531 SourceLabel* label = | 6566 SourceLabel* label = |
| 6532 SourceLabel::New(do_pos, label_name, SourceLabel::kDoWhile); | 6567 SourceLabel::New(do_pos, label_name, SourceLabel::kDoWhile); |
| 6533 ConsumeToken(); | 6568 ConsumeToken(); |
| 6534 const bool parsing_loop_body = true; | 6569 const bool parsing_loop_body = true; |
| 6535 SequenceNode* dowhile_body = ParseNestedStatement(parsing_loop_body, label); | 6570 SequenceNode* dowhile_body = ParseNestedStatement(parsing_loop_body, label); |
| 6536 ExpectToken(Token::kWHILE); | 6571 ExpectToken(Token::kWHILE); |
| 6537 ExpectToken(Token::kLPAREN); | 6572 ExpectToken(Token::kLPAREN); |
| 6538 AstNode* cond_expr = ParseExpr(kAllowConst, kConsumeCascades); | 6573 AstNode* cond_expr = ParseExpr(kAllowConst, kConsumeCascades); |
| 6539 ExpectToken(Token::kRPAREN); | 6574 ExpectToken(Token::kRPAREN); |
| 6540 ExpectSemicolon(); | 6575 ExpectSemicolon(); |
| 6541 return new DoWhileNode(do_pos, label, cond_expr, dowhile_body); | 6576 return new(isolate()) DoWhileNode(do_pos, label, cond_expr, dowhile_body); |
| 6542 } | 6577 } |
| 6543 | 6578 |
| 6544 | 6579 |
| 6545 AstNode* Parser::ParseForInStatement(intptr_t forin_pos, | 6580 AstNode* Parser::ParseForInStatement(intptr_t forin_pos, |
| 6546 SourceLabel* label) { | 6581 SourceLabel* label) { |
| 6547 TRACE_PARSER("ParseForInStatement"); | 6582 TRACE_PARSER("ParseForInStatement"); |
| 6548 bool is_final = (CurrentToken() == Token::kFINAL); | 6583 bool is_final = (CurrentToken() == Token::kFINAL); |
| 6549 if (CurrentToken() == Token::kCONST) { | 6584 if (CurrentToken() == Token::kCONST) { |
| 6550 ErrorMsg("Loop variable cannot be 'const'"); | 6585 ErrorMsg("Loop variable cannot be 'const'"); |
| 6551 } | 6586 } |
| 6552 const String* loop_var_name = NULL; | 6587 const String* loop_var_name = NULL; |
| 6553 LocalVariable* loop_var = NULL; | 6588 LocalVariable* loop_var = NULL; |
| 6554 intptr_t loop_var_pos = 0; | 6589 intptr_t loop_var_pos = 0; |
| 6555 if (LookaheadToken(1) == Token::kIN) { | 6590 if (LookaheadToken(1) == Token::kIN) { |
| 6556 loop_var_pos = TokenPos(); | 6591 loop_var_pos = TokenPos(); |
| 6557 loop_var_name = ExpectIdentifier("variable name expected"); | 6592 loop_var_name = ExpectIdentifier("variable name expected"); |
| 6558 } else { | 6593 } else { |
| 6559 // The case without a type is handled above, so require a type here. | 6594 // The case without a type is handled above, so require a type here. |
| 6560 const AbstractType& type = | 6595 const AbstractType& type = |
| 6561 AbstractType::ZoneHandle(ParseConstFinalVarOrType( | 6596 AbstractType::ZoneHandle(ParseConstFinalVarOrType( |
| 6562 FLAG_enable_type_checks ? ClassFinalizer::kCanonicalize : | 6597 FLAG_enable_type_checks ? ClassFinalizer::kCanonicalize : |
| 6563 ClassFinalizer::kIgnore)); | 6598 ClassFinalizer::kIgnore)); |
| 6564 loop_var_pos = TokenPos(); | 6599 loop_var_pos = TokenPos(); |
| 6565 loop_var_name = ExpectIdentifier("variable name expected"); | 6600 loop_var_name = ExpectIdentifier("variable name expected"); |
| 6566 loop_var = new LocalVariable(loop_var_pos, *loop_var_name, type); | 6601 loop_var = new(isolate()) LocalVariable(loop_var_pos, *loop_var_name, type); |
| 6567 if (is_final) { | 6602 if (is_final) { |
| 6568 loop_var->set_is_final(); | 6603 loop_var->set_is_final(); |
| 6569 } | 6604 } |
| 6570 } | 6605 } |
| 6571 ExpectToken(Token::kIN); | 6606 ExpectToken(Token::kIN); |
| 6572 const intptr_t collection_pos = TokenPos(); | 6607 const intptr_t collection_pos = TokenPos(); |
| 6573 AstNode* collection_expr = ParseExpr(kAllowConst, kConsumeCascades); | 6608 AstNode* collection_expr = ParseExpr(kAllowConst, kConsumeCascades); |
| 6574 ExpectToken(Token::kRPAREN); | 6609 ExpectToken(Token::kRPAREN); |
| 6575 | 6610 |
| 6576 OpenBlock(); // Implicit block around while loop. | 6611 OpenBlock(); // Implicit block around while loop. |
| 6577 | 6612 |
| 6578 // Generate implicit iterator variable and add to scope. | 6613 // Generate implicit iterator variable and add to scope. |
| 6579 // We could set the type of the implicit iterator variable to Iterator<T> | 6614 // We could set the type of the implicit iterator variable to Iterator<T> |
| 6580 // where T is the type of the for loop variable. However, the type error | 6615 // where T is the type of the for loop variable. However, the type error |
| 6581 // would refer to the compiler generated iterator and could confuse the user. | 6616 // would refer to the compiler generated iterator and could confuse the user. |
| 6582 // It is better to leave the iterator untyped and postpone the type error | 6617 // It is better to leave the iterator untyped and postpone the type error |
| 6583 // until the loop variable is assigned to. | 6618 // until the loop variable is assigned to. |
| 6584 const AbstractType& iterator_type = Type::ZoneHandle(Type::DynamicType()); | 6619 const AbstractType& iterator_type = Type::ZoneHandle(Type::DynamicType()); |
| 6585 LocalVariable* iterator_var = | 6620 LocalVariable* iterator_var = new(isolate()) LocalVariable( |
| 6586 new LocalVariable(collection_pos, Symbols::ForInIter(), iterator_type); | 6621 collection_pos, Symbols::ForInIter(), iterator_type); |
| 6587 current_block_->scope->AddVariable(iterator_var); | 6622 current_block_->scope->AddVariable(iterator_var); |
| 6588 | 6623 |
| 6589 // Generate initialization of iterator variable. | 6624 // Generate initialization of iterator variable. |
| 6590 ArgumentListNode* no_args = new ArgumentListNode(collection_pos); | 6625 ArgumentListNode* no_args = new(isolate()) ArgumentListNode(collection_pos); |
| 6591 AstNode* get_iterator = new InstanceGetterNode( | 6626 AstNode* get_iterator = new(isolate()) InstanceGetterNode( |
| 6592 collection_pos, collection_expr, Symbols::GetIterator()); | 6627 collection_pos, collection_expr, Symbols::GetIterator()); |
| 6593 AstNode* iterator_init = | 6628 AstNode* iterator_init = |
| 6594 new StoreLocalNode(collection_pos, iterator_var, get_iterator); | 6629 new(isolate()) StoreLocalNode(collection_pos, iterator_var, get_iterator); |
| 6595 current_block_->statements->Add(iterator_init); | 6630 current_block_->statements->Add(iterator_init); |
| 6596 | 6631 |
| 6597 // Generate while loop condition. | 6632 // Generate while loop condition. |
| 6598 AstNode* iterator_moveNext = new InstanceCallNode( | 6633 AstNode* iterator_moveNext = new(isolate()) InstanceCallNode( |
| 6599 collection_pos, | 6634 collection_pos, |
| 6600 new LoadLocalNode(collection_pos, iterator_var), | 6635 new(isolate()) LoadLocalNode(collection_pos, iterator_var), |
| 6601 Symbols::MoveNext(), | 6636 Symbols::MoveNext(), |
| 6602 no_args); | 6637 no_args); |
| 6603 | 6638 |
| 6604 // Parse the for loop body. Ideally, we would use ParseNestedStatement() | 6639 // Parse the for loop body. Ideally, we would use ParseNestedStatement() |
| 6605 // here, but that does not work well because we have to insert an implicit | 6640 // here, but that does not work well because we have to insert an implicit |
| 6606 // variable assignment and potentially a variable declaration in the | 6641 // variable assignment and potentially a variable declaration in the |
| 6607 // loop body. | 6642 // loop body. |
| 6608 OpenLoopBlock(); | 6643 OpenLoopBlock(); |
| 6609 current_block_->scope->AddLabel(label); | 6644 current_block_->scope->AddLabel(label); |
| 6610 | 6645 |
| 6611 AstNode* iterator_current = new InstanceGetterNode( | 6646 AstNode* iterator_current = new(isolate()) InstanceGetterNode( |
| 6612 collection_pos, | 6647 collection_pos, |
| 6613 new LoadLocalNode(collection_pos, iterator_var), | 6648 new(isolate()) LoadLocalNode(collection_pos, iterator_var), |
| 6614 Symbols::Current()); | 6649 Symbols::Current()); |
| 6615 | 6650 |
| 6616 // Generate assignment of next iterator value to loop variable. | 6651 // Generate assignment of next iterator value to loop variable. |
| 6617 AstNode* loop_var_assignment = NULL; | 6652 AstNode* loop_var_assignment = NULL; |
| 6618 if (loop_var != NULL) { | 6653 if (loop_var != NULL) { |
| 6619 // The for loop declares a new variable. Add it to the loop body scope. | 6654 // The for loop declares a new variable. Add it to the loop body scope. |
| 6620 current_block_->scope->AddVariable(loop_var); | 6655 current_block_->scope->AddVariable(loop_var); |
| 6621 loop_var_assignment = | 6656 loop_var_assignment = |
| 6622 new StoreLocalNode(loop_var_pos, loop_var, iterator_current); | 6657 new(isolate()) StoreLocalNode(loop_var_pos, loop_var, iterator_current); |
| 6623 } else { | 6658 } else { |
| 6624 AstNode* loop_var_primary = | 6659 AstNode* loop_var_primary = |
| 6625 ResolveIdent(loop_var_pos, *loop_var_name, false); | 6660 ResolveIdent(loop_var_pos, *loop_var_name, false); |
| 6626 ASSERT(!loop_var_primary->IsPrimaryNode()); | 6661 ASSERT(!loop_var_primary->IsPrimaryNode()); |
| 6627 loop_var_assignment = CreateAssignmentNode( | 6662 loop_var_assignment = CreateAssignmentNode( |
| 6628 loop_var_primary, iterator_current, loop_var_name, loop_var_pos); | 6663 loop_var_primary, iterator_current, loop_var_name, loop_var_pos); |
| 6629 ASSERT(loop_var_assignment != NULL); | 6664 ASSERT(loop_var_assignment != NULL); |
| 6630 } | 6665 } |
| 6631 current_block_->statements->Add(loop_var_assignment); | 6666 current_block_->statements->Add(loop_var_assignment); |
| 6632 | 6667 |
| 6633 // Now parse the for-in loop statement or block. | 6668 // Now parse the for-in loop statement or block. |
| 6634 if (CurrentToken() == Token::kLBRACE) { | 6669 if (CurrentToken() == Token::kLBRACE) { |
| 6635 ConsumeToken(); | 6670 ConsumeToken(); |
| 6636 ParseStatementSequence(); | 6671 ParseStatementSequence(); |
| 6637 ExpectToken(Token::kRBRACE); | 6672 ExpectToken(Token::kRBRACE); |
| 6638 } else { | 6673 } else { |
| 6639 AstNode* statement = ParseStatement(); | 6674 AstNode* statement = ParseStatement(); |
| 6640 if (statement != NULL) { | 6675 if (statement != NULL) { |
| 6641 current_block_->statements->Add(statement); | 6676 current_block_->statements->Add(statement); |
| 6642 } | 6677 } |
| 6643 } | 6678 } |
| 6644 | 6679 |
| 6645 SequenceNode* for_loop_statement = CloseBlock(); | 6680 SequenceNode* for_loop_statement = CloseBlock(); |
| 6646 | 6681 |
| 6647 AstNode* while_statement = | 6682 AstNode* while_statement = new(isolate()) WhileNode( |
| 6648 new WhileNode(forin_pos, label, iterator_moveNext, for_loop_statement); | 6683 forin_pos, label, iterator_moveNext, for_loop_statement); |
| 6649 current_block_->statements->Add(while_statement); | 6684 current_block_->statements->Add(while_statement); |
| 6650 | 6685 |
| 6651 return CloseBlock(); // Implicit block around while loop. | 6686 return CloseBlock(); // Implicit block around while loop. |
| 6652 } | 6687 } |
| 6653 | 6688 |
| 6654 | 6689 |
| 6655 AstNode* Parser::ParseForStatement(String* label_name) { | 6690 AstNode* Parser::ParseForStatement(String* label_name) { |
| 6656 TRACE_PARSER("ParseForStatement"); | 6691 TRACE_PARSER("ParseForStatement"); |
| 6657 const intptr_t for_pos = TokenPos(); | 6692 const intptr_t for_pos = TokenPos(); |
| 6658 ConsumeToken(); | 6693 ConsumeToken(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 6689 const bool parsing_loop_body = true; | 6724 const bool parsing_loop_body = true; |
| 6690 SequenceNode* body = ParseNestedStatement(parsing_loop_body, label); | 6725 SequenceNode* body = ParseNestedStatement(parsing_loop_body, label); |
| 6691 | 6726 |
| 6692 // Check whether any of the variables in the initializer part of | 6727 // Check whether any of the variables in the initializer part of |
| 6693 // the for statement are captured by a closure. If so, we insert a | 6728 // the for statement are captured by a closure. If so, we insert a |
| 6694 // node that creates a new Context for the loop variable before | 6729 // node that creates a new Context for the loop variable before |
| 6695 // the increment expression is evaluated. | 6730 // the increment expression is evaluated. |
| 6696 for (int i = 0; i < init_scope->num_variables(); i++) { | 6731 for (int i = 0; i < init_scope->num_variables(); i++) { |
| 6697 if (init_scope->VariableAt(i)->is_captured() && | 6732 if (init_scope->VariableAt(i)->is_captured() && |
| 6698 (init_scope->VariableAt(i)->owner() == init_scope)) { | 6733 (init_scope->VariableAt(i)->owner() == init_scope)) { |
| 6699 SequenceNode* incr_sequence = new SequenceNode(incr_pos, NULL); | 6734 SequenceNode* incr_sequence = new(isolate()) SequenceNode(incr_pos, NULL); |
| 6700 incr_sequence->Add(new CloneContextNode(for_pos)); | 6735 incr_sequence->Add(new(isolate()) CloneContextNode(for_pos)); |
| 6701 if (increment != NULL) { | 6736 if (increment != NULL) { |
| 6702 incr_sequence->Add(increment); | 6737 incr_sequence->Add(increment); |
| 6703 } | 6738 } |
| 6704 increment = incr_sequence; | 6739 increment = incr_sequence; |
| 6705 break; | 6740 break; |
| 6706 } | 6741 } |
| 6707 } | 6742 } |
| 6708 AstNode* for_node = | 6743 AstNode* for_node = |
| 6709 new ForNode(for_pos, | 6744 new(isolate()) ForNode(for_pos, |
| 6710 label, | 6745 label, |
| 6711 NodeAsSequenceNode(init_pos, initializer, NULL), | 6746 NodeAsSequenceNode(init_pos, initializer, NULL), |
| 6712 condition, | 6747 condition, |
| 6713 NodeAsSequenceNode(incr_pos, increment, NULL), | 6748 NodeAsSequenceNode(incr_pos, increment, NULL), |
| 6714 body); | 6749 body); |
| 6715 current_block_->statements->Add(for_node); | 6750 current_block_->statements->Add(for_node); |
| 6716 return CloseBlock(); | 6751 return CloseBlock(); |
| 6717 } | 6752 } |
| 6718 | 6753 |
| 6719 | 6754 |
| 6720 // Calling VM-internal helpers, uses implementation core library. | 6755 // Calling VM-internal helpers, uses implementation core library. |
| 6721 AstNode* Parser::MakeStaticCall(const String& cls_name, | 6756 AstNode* Parser::MakeStaticCall(const String& cls_name, |
| 6722 const String& func_name, | 6757 const String& func_name, |
| 6723 ArgumentListNode* arguments) { | 6758 ArgumentListNode* arguments) { |
| 6724 const Class& cls = Class::Handle(Library::LookupCoreClass(cls_name)); | 6759 const Class& cls = Class::Handle(isolate(), |
| 6760 Library::LookupCoreClass(cls_name)); | |
| 6725 ASSERT(!cls.IsNull()); | 6761 ASSERT(!cls.IsNull()); |
| 6726 const Function& func = Function::ZoneHandle( | 6762 const Function& func = Function::ZoneHandle( |
| 6727 Resolver::ResolveStatic(cls, | 6763 Resolver::ResolveStatic(cls, |
| 6728 func_name, | 6764 func_name, |
| 6729 arguments->length(), | 6765 arguments->length(), |
| 6730 arguments->names())); | 6766 arguments->names())); |
| 6731 ASSERT(!func.IsNull()); | 6767 ASSERT(!func.IsNull()); |
| 6732 return new StaticCallNode(arguments->token_pos(), func, arguments); | 6768 return new(isolate()) StaticCallNode(arguments->token_pos(), func, arguments); |
| 6733 } | 6769 } |
| 6734 | 6770 |
| 6735 | 6771 |
| 6736 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end) { | 6772 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end) { |
| 6737 ArgumentListNode* arguments = new ArgumentListNode(begin); | 6773 ArgumentListNode* arguments = new(isolate()) ArgumentListNode(begin); |
| 6738 arguments->Add(new LiteralNode(begin, | 6774 arguments->Add(new(isolate()) LiteralNode(begin, |
| 6739 Integer::ZoneHandle(Integer::New(begin)))); | 6775 Integer::ZoneHandle(Integer::New(begin)))); |
| 6740 arguments->Add(new LiteralNode(end, | 6776 arguments->Add(new(isolate()) LiteralNode(end, |
| 6741 Integer::ZoneHandle(Integer::New(end)))); | 6777 Integer::ZoneHandle(Integer::New(end)))); |
| 6742 return MakeStaticCall(Symbols::AssertionError(), | 6778 return MakeStaticCall(Symbols::AssertionError(), |
| 6743 Library::PrivateCoreLibName(Symbols::ThrowNew()), | 6779 Library::PrivateCoreLibName(Symbols::ThrowNew()), |
| 6744 arguments); | 6780 arguments); |
| 6745 } | 6781 } |
| 6746 | 6782 |
| 6747 | 6783 |
| 6748 AstNode* Parser::InsertClosureCallNodes(AstNode* condition) { | 6784 AstNode* Parser::InsertClosureCallNodes(AstNode* condition) { |
| 6749 if (condition->IsClosureNode() || | 6785 if (condition->IsClosureNode() || |
| 6750 (condition->IsStoreLocalNode() && | 6786 (condition->IsStoreLocalNode() && |
| 6751 condition->AsStoreLocalNode()->value()->IsClosureNode())) { | 6787 condition->AsStoreLocalNode()->value()->IsClosureNode())) { |
| 6752 // Function literal in assert implies a call. | 6788 // Function literal in assert implies a call. |
| 6753 const intptr_t pos = condition->token_pos(); | 6789 const intptr_t pos = condition->token_pos(); |
| 6754 condition = BuildClosureCall(pos, condition, new ArgumentListNode(pos)); | 6790 condition = BuildClosureCall(pos, |
| 6791 condition, | |
| 6792 new(isolate()) ArgumentListNode(pos)); | |
| 6755 } else if (condition->IsConditionalExprNode()) { | 6793 } else if (condition->IsConditionalExprNode()) { |
| 6756 ConditionalExprNode* cond_expr = condition->AsConditionalExprNode(); | 6794 ConditionalExprNode* cond_expr = condition->AsConditionalExprNode(); |
| 6757 cond_expr->set_true_expr(InsertClosureCallNodes(cond_expr->true_expr())); | 6795 cond_expr->set_true_expr(InsertClosureCallNodes(cond_expr->true_expr())); |
| 6758 cond_expr->set_false_expr(InsertClosureCallNodes(cond_expr->false_expr())); | 6796 cond_expr->set_false_expr(InsertClosureCallNodes(cond_expr->false_expr())); |
| 6759 } | 6797 } |
| 6760 return condition; | 6798 return condition; |
| 6761 } | 6799 } |
| 6762 | 6800 |
| 6763 | 6801 |
| 6764 AstNode* Parser::ParseAssertStatement() { | 6802 AstNode* Parser::ParseAssertStatement() { |
| 6765 TRACE_PARSER("ParseAssertStatement"); | 6803 TRACE_PARSER("ParseAssertStatement"); |
| 6766 ConsumeToken(); // Consume assert keyword. | 6804 ConsumeToken(); // Consume assert keyword. |
| 6767 ExpectToken(Token::kLPAREN); | 6805 ExpectToken(Token::kLPAREN); |
| 6768 const intptr_t condition_pos = TokenPos(); | 6806 const intptr_t condition_pos = TokenPos(); |
| 6769 if (!FLAG_enable_asserts && !FLAG_enable_type_checks) { | 6807 if (!FLAG_enable_asserts && !FLAG_enable_type_checks) { |
| 6770 SkipExpr(); | 6808 SkipExpr(); |
| 6771 ExpectToken(Token::kRPAREN); | 6809 ExpectToken(Token::kRPAREN); |
| 6772 return NULL; | 6810 return NULL; |
| 6773 } | 6811 } |
| 6774 AstNode* condition = ParseExpr(kAllowConst, kConsumeCascades); | 6812 AstNode* condition = ParseExpr(kAllowConst, kConsumeCascades); |
| 6775 const intptr_t condition_end = TokenPos(); | 6813 const intptr_t condition_end = TokenPos(); |
| 6776 ExpectToken(Token::kRPAREN); | 6814 ExpectToken(Token::kRPAREN); |
| 6777 condition = InsertClosureCallNodes(condition); | 6815 condition = InsertClosureCallNodes(condition); |
| 6778 condition = new UnaryOpNode(condition_pos, Token::kNOT, condition); | 6816 condition = new(isolate()) UnaryOpNode(condition_pos, Token::kNOT, condition); |
| 6779 AstNode* assert_throw = MakeAssertCall(condition_pos, condition_end); | 6817 AstNode* assert_throw = MakeAssertCall(condition_pos, condition_end); |
| 6780 return new IfNode(condition_pos, | 6818 return new(isolate()) IfNode( |
| 6781 condition, | 6819 condition_pos, |
| 6782 NodeAsSequenceNode(condition_pos, assert_throw, NULL), | 6820 condition, |
| 6783 NULL); | 6821 NodeAsSequenceNode(condition_pos, assert_throw, NULL), |
| 6822 NULL); | |
| 6784 } | 6823 } |
| 6785 | 6824 |
| 6786 | 6825 |
| 6787 struct CatchParamDesc { | 6826 struct CatchParamDesc { |
| 6788 CatchParamDesc() | 6827 CatchParamDesc() |
| 6789 : token_pos(0), type(NULL), name(NULL), var(NULL) { } | 6828 : token_pos(0), type(NULL), name(NULL), var(NULL) { } |
| 6790 intptr_t token_pos; | 6829 intptr_t token_pos; |
| 6791 const AbstractType* type; | 6830 const AbstractType* type; |
| 6792 const String* name; | 6831 const String* name; |
| 6793 LocalVariable* var; | 6832 LocalVariable* var; |
| 6794 }; | 6833 }; |
| 6795 | 6834 |
| 6796 | 6835 |
| 6797 // Populate local scope of the catch block with the catch parameters. | 6836 // Populate local scope of the catch block with the catch parameters. |
| 6798 void Parser::AddCatchParamsToScope(CatchParamDesc* exception_param, | 6837 void Parser::AddCatchParamsToScope(CatchParamDesc* exception_param, |
| 6799 CatchParamDesc* stack_trace_param, | 6838 CatchParamDesc* stack_trace_param, |
| 6800 LocalScope* scope) { | 6839 LocalScope* scope) { |
| 6801 if (exception_param->name != NULL) { | 6840 if (exception_param->name != NULL) { |
| 6802 LocalVariable* var = new LocalVariable(exception_param->token_pos, | 6841 LocalVariable* var = new(isolate()) LocalVariable( |
| 6803 *exception_param->name, | 6842 exception_param->token_pos, |
| 6804 *exception_param->type); | 6843 *exception_param->name, |
| 6844 *exception_param->type); | |
| 6805 var->set_is_final(); | 6845 var->set_is_final(); |
| 6806 bool added_to_scope = scope->AddVariable(var); | 6846 bool added_to_scope = scope->AddVariable(var); |
| 6807 ASSERT(added_to_scope); | 6847 ASSERT(added_to_scope); |
| 6808 exception_param->var = var; | 6848 exception_param->var = var; |
| 6809 } | 6849 } |
| 6810 if (stack_trace_param->name != NULL) { | 6850 if (stack_trace_param->name != NULL) { |
| 6811 LocalVariable* var = new LocalVariable(stack_trace_param->token_pos, | 6851 LocalVariable* var = new(isolate()) LocalVariable( |
| 6812 *stack_trace_param->name, | 6852 stack_trace_param->token_pos, |
| 6813 *stack_trace_param->type); | 6853 *stack_trace_param->name, |
| 6854 *stack_trace_param->type); | |
| 6814 var->set_is_final(); | 6855 var->set_is_final(); |
| 6815 bool added_to_scope = scope->AddVariable(var); | 6856 bool added_to_scope = scope->AddVariable(var); |
| 6816 if (!added_to_scope) { | 6857 if (!added_to_scope) { |
| 6817 ErrorMsg(stack_trace_param->token_pos, | 6858 ErrorMsg(stack_trace_param->token_pos, |
| 6818 "name '%s' already exists in scope", | 6859 "name '%s' already exists in scope", |
| 6819 stack_trace_param->name->ToCString()); | 6860 stack_trace_param->name->ToCString()); |
| 6820 } | 6861 } |
| 6821 stack_trace_param->var = var; | 6862 stack_trace_param->var = var; |
| 6822 } | 6863 } |
| 6823 } | 6864 } |
| 6824 | 6865 |
| 6825 | 6866 |
| 6826 SequenceNode* Parser::ParseFinallyBlock() { | 6867 SequenceNode* Parser::ParseFinallyBlock() { |
| 6827 TRACE_PARSER("ParseFinallyBlock"); | 6868 TRACE_PARSER("ParseFinallyBlock"); |
| 6828 OpenBlock(); | 6869 OpenBlock(); |
| 6829 ExpectToken(Token::kLBRACE); | 6870 ExpectToken(Token::kLBRACE); |
| 6830 ParseStatementSequence(); | 6871 ParseStatementSequence(); |
| 6831 ExpectToken(Token::kRBRACE); | 6872 ExpectToken(Token::kRBRACE); |
| 6832 SequenceNode* finally_block = CloseBlock(); | 6873 SequenceNode* finally_block = CloseBlock(); |
| 6833 return finally_block; | 6874 return finally_block; |
| 6834 } | 6875 } |
| 6835 | 6876 |
| 6836 | 6877 |
| 6837 void Parser::PushTryBlock(Block* try_block) { | 6878 void Parser::PushTryBlock(Block* try_block) { |
| 6838 intptr_t try_index = AllocateTryIndex(); | 6879 intptr_t try_index = AllocateTryIndex(); |
| 6839 TryBlocks* block = new TryBlocks(try_block, try_blocks_list_, try_index); | 6880 TryBlocks* block = new(isolate()) TryBlocks( |
| 6881 try_block, try_blocks_list_, try_index); | |
| 6840 try_blocks_list_ = block; | 6882 try_blocks_list_ = block; |
| 6841 } | 6883 } |
| 6842 | 6884 |
| 6843 | 6885 |
| 6844 Parser::TryBlocks* Parser::PopTryBlock() { | 6886 Parser::TryBlocks* Parser::PopTryBlock() { |
| 6845 TryBlocks* innermost_try_block = try_blocks_list_; | 6887 TryBlocks* innermost_try_block = try_blocks_list_; |
| 6846 try_blocks_list_ = try_blocks_list_->outer_try_block(); | 6888 try_blocks_list_ = try_blocks_list_->outer_try_block(); |
| 6847 return innermost_try_block; | 6889 return innermost_try_block; |
| 6848 } | 6890 } |
| 6849 | 6891 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6944 // variables (as needed). | 6986 // variables (as needed). |
| 6945 // 2) Nested block with source code from catch clause block. | 6987 // 2) Nested block with source code from catch clause block. |
| 6946 OpenBlock(); | 6988 OpenBlock(); |
| 6947 AddCatchParamsToScope(&exception_param, &stack_trace_param, | 6989 AddCatchParamsToScope(&exception_param, &stack_trace_param, |
| 6948 current_block_->scope); | 6990 current_block_->scope); |
| 6949 | 6991 |
| 6950 if (exception_param.var != NULL) { | 6992 if (exception_param.var != NULL) { |
| 6951 // Generate code to load the exception object (:exception_var) into | 6993 // Generate code to load the exception object (:exception_var) into |
| 6952 // the exception variable specified in this block. | 6994 // the exception variable specified in this block. |
| 6953 ASSERT(exception_var != NULL); | 6995 ASSERT(exception_var != NULL); |
| 6954 current_block_->statements->Add( | 6996 current_block_->statements->Add(new(isolate()) StoreLocalNode( |
| 6955 new StoreLocalNode(catch_pos, exception_param.var, | 6997 catch_pos, exception_param.var, new(isolate()) LoadLocalNode( |
| 6956 new LoadLocalNode(catch_pos, exception_var))); | 6998 catch_pos, exception_var))); |
| 6957 } | 6999 } |
| 6958 if (stack_trace_param.var != NULL) { | 7000 if (stack_trace_param.var != NULL) { |
| 6959 // A stack trace variable is specified in this block, so generate code | 7001 // A stack trace variable is specified in this block, so generate code |
| 6960 // to load the stack trace object (:stack_trace_var) into the stack | 7002 // to load the stack trace object (:stack_trace_var) into the stack |
| 6961 // trace variable specified in this block. | 7003 // trace variable specified in this block. |
| 6962 *needs_stack_trace = true; | 7004 *needs_stack_trace = true; |
| 6963 ArgumentListNode* no_args = new ArgumentListNode(catch_pos); | 7005 ArgumentListNode* no_args = new(isolate()) ArgumentListNode(catch_pos); |
| 6964 ASSERT(stack_trace_var != NULL); | 7006 ASSERT(stack_trace_var != NULL); |
| 6965 current_block_->statements->Add( | 7007 current_block_->statements->Add(new(isolate()) StoreLocalNode( |
| 6966 new StoreLocalNode(catch_pos, stack_trace_param.var, | 7008 catch_pos, stack_trace_param.var, new(isolate()) LoadLocalNode( |
| 6967 new LoadLocalNode(catch_pos, stack_trace_var))); | 7009 catch_pos, stack_trace_var))); |
| 6968 current_block_->statements->Add( | 7010 current_block_->statements->Add(new(isolate()) InstanceCallNode( |
| 6969 new InstanceCallNode( | 7011 catch_pos, |
| 6970 catch_pos, | 7012 new(isolate()) LoadLocalNode(catch_pos, stack_trace_param.var), |
| 6971 new LoadLocalNode(catch_pos, stack_trace_param.var), | 7013 Library::PrivateCoreLibName(Symbols::_setupFullStackTrace()), |
| 6972 Library::PrivateCoreLibName(Symbols::_setupFullStackTrace()), | 7014 no_args)); |
| 6973 no_args)); | |
| 6974 } | 7015 } |
| 6975 | 7016 |
| 6976 // Add nested block with user-defined code. This blocks allows | 7017 // Add nested block with user-defined code. This blocks allows |
| 6977 // declarations in the body to shadow the catch parameters. | 7018 // declarations in the body to shadow the catch parameters. |
| 6978 CheckToken(Token::kLBRACE); | 7019 CheckToken(Token::kLBRACE); |
| 6979 current_block_->statements->Add(ParseNestedStatement(false, NULL)); | 7020 current_block_->statements->Add(ParseNestedStatement(false, NULL)); |
| 6980 catch_blocks.Add(CloseBlock()); | 7021 catch_blocks.Add(CloseBlock()); |
| 6981 | 7022 |
| 6982 const bool is_bad_type = | 7023 const bool is_bad_type = |
| 6983 exception_param.type->IsMalformed() || | 7024 exception_param.type->IsMalformed() || |
| 6984 exception_param.type->IsMalbounded(); | 7025 exception_param.type->IsMalbounded(); |
| 6985 if (exception_param.type->IsDynamicType() || is_bad_type) { | 7026 if (exception_param.type->IsDynamicType() || is_bad_type) { |
| 6986 // There is no exception type or else it is malformed or malbounded. | 7027 // There is no exception type or else it is malformed or malbounded. |
| 6987 // In the first case, unconditionally execute the catch body. In the | 7028 // In the first case, unconditionally execute the catch body. In the |
| 6988 // second case, unconditionally throw. | 7029 // second case, unconditionally throw. |
| 6989 generic_catch_seen = true; | 7030 generic_catch_seen = true; |
| 6990 type_tests.Add(new LiteralNode(catch_pos, Bool::True())); | 7031 type_tests.Add(new(isolate()) LiteralNode(catch_pos, Bool::True())); |
| 6991 if (is_bad_type) { | 7032 if (is_bad_type) { |
| 6992 // Replace the body with one that throws. | 7033 // Replace the body with one that throws. |
| 6993 SequenceNode* block = new SequenceNode(catch_pos, NULL); | 7034 SequenceNode* block = new(isolate()) SequenceNode(catch_pos, NULL); |
| 6994 block->Add(ThrowTypeError(catch_pos, *exception_param.type)); | 7035 block->Add(ThrowTypeError(catch_pos, *exception_param.type)); |
| 6995 catch_blocks.Last() = block; | 7036 catch_blocks.Last() = block; |
| 6996 } | 7037 } |
| 6997 // This catch clause will handle all exceptions. We can safely forget | 7038 // This catch clause will handle all exceptions. We can safely forget |
| 6998 // all previous catch clause types. | 7039 // all previous catch clause types. |
| 6999 handler_types.SetLength(0); | 7040 handler_types.SetLength(0); |
| 7000 handler_types.Add(*exception_param.type); | 7041 handler_types.Add(*exception_param.type); |
| 7001 } else { | 7042 } else { |
| 7002 // Has a type specification that is not malformed or malbounded. Now | 7043 // Has a type specification that is not malformed or malbounded. Now |
| 7003 // form an 'if type check' to guard the catch handler code. | 7044 // form an 'if type check' to guard the catch handler code. |
| 7004 if (!exception_param.type->IsInstantiated() && | 7045 if (!exception_param.type->IsInstantiated() && |
| 7005 (current_block_->scope->function_level() > 0)) { | 7046 (current_block_->scope->function_level() > 0)) { |
| 7006 // Make sure that the instantiator is captured. | 7047 // Make sure that the instantiator is captured. |
| 7007 CaptureInstantiator(); | 7048 CaptureInstantiator(); |
| 7008 } | 7049 } |
| 7009 TypeNode* exception_type = new TypeNode(catch_pos, *exception_param.type); | 7050 TypeNode* exception_type = new(isolate()) TypeNode( |
| 7010 AstNode* exception_value = new LoadLocalNode(catch_pos, exception_var); | 7051 catch_pos, *exception_param.type); |
| 7052 AstNode* exception_value = new(isolate()) LoadLocalNode( | |
| 7053 catch_pos, exception_var); | |
| 7011 if (!exception_type->type().IsInstantiated()) { | 7054 if (!exception_type->type().IsInstantiated()) { |
| 7012 EnsureExpressionTemp(); | 7055 EnsureExpressionTemp(); |
| 7013 } | 7056 } |
| 7014 type_tests.Add(new ComparisonNode(catch_pos, Token::kIS, exception_value, | 7057 type_tests.Add(new(isolate()) ComparisonNode( |
| 7015 exception_type)); | 7058 catch_pos, Token::kIS, exception_value, exception_type)); |
| 7016 | 7059 |
| 7017 // Do not add uninstantiated types (e.g. type parameter T or generic | 7060 // Do not add uninstantiated types (e.g. type parameter T or generic |
| 7018 // type List<T>), since the debugger won't be able to instantiate it | 7061 // type List<T>), since the debugger won't be able to instantiate it |
| 7019 // when walking the stack. | 7062 // when walking the stack. |
| 7020 // | 7063 // |
| 7021 // This means that the debugger is not able to determine whether an | 7064 // This means that the debugger is not able to determine whether an |
| 7022 // exception is caught if the catch clause uses generic types. It | 7065 // exception is caught if the catch clause uses generic types. It |
| 7023 // will report the exception as uncaught when in fact it might be | 7066 // will report the exception as uncaught when in fact it might be |
| 7024 // caught and handled when we unwind the stack. | 7067 // caught and handled when we unwind the stack. |
| 7025 if (!generic_catch_seen && exception_param.type->IsInstantiated()) { | 7068 if (!generic_catch_seen && exception_param.type->IsInstantiated()) { |
| 7026 handler_types.Add(*exception_param.type); | 7069 handler_types.Add(*exception_param.type); |
| 7027 } | 7070 } |
| 7028 } | 7071 } |
| 7029 | 7072 |
| 7030 ASSERT(type_tests.length() == catch_blocks.length()); | 7073 ASSERT(type_tests.length() == catch_blocks.length()); |
| 7031 } | 7074 } |
| 7032 | 7075 |
| 7033 // Build the if/then/else nest from the inside out. Keep the AST simple | 7076 // Build the if/then/else nest from the inside out. Keep the AST simple |
| 7034 // for the case of a single generic catch clause. The initial value of | 7077 // for the case of a single generic catch clause. The initial value of |
| 7035 // current is the last (innermost) else block if there were any catch | 7078 // current is the last (innermost) else block if there were any catch |
| 7036 // clauses. | 7079 // clauses. |
| 7037 SequenceNode* current = NULL; | 7080 SequenceNode* current = NULL; |
| 7038 if (!generic_catch_seen) { | 7081 if (!generic_catch_seen) { |
| 7039 // There isn't a generic catch clause so create a clause body that | 7082 // There isn't a generic catch clause so create a clause body that |
| 7040 // rethrows the exception. This includes the case that there were no | 7083 // rethrows the exception. This includes the case that there were no |
| 7041 // catch clauses. | 7084 // catch clauses. |
| 7042 current = new SequenceNode(handler_pos, NULL); | 7085 current = new(isolate()) SequenceNode(handler_pos, NULL); |
| 7043 current->Add( | 7086 current->Add(new(isolate()) ThrowNode( |
| 7044 new ThrowNode(handler_pos, | 7087 handler_pos, |
| 7045 new LoadLocalNode(handler_pos, exception_var), | 7088 new(isolate()) LoadLocalNode(handler_pos, exception_var), |
| 7046 new LoadLocalNode(handler_pos, stack_trace_var))); | 7089 new(isolate()) LoadLocalNode(handler_pos, stack_trace_var))); |
| 7047 } else if (type_tests.Last()->IsLiteralNode()) { | 7090 } else if (type_tests.Last()->IsLiteralNode()) { |
| 7048 ASSERT(type_tests.Last()->AsLiteralNode()->literal().raw() == | 7091 ASSERT(type_tests.Last()->AsLiteralNode()->literal().raw() == |
| 7049 Bool::True().raw()); | 7092 Bool::True().raw()); |
| 7050 // The last body is entered unconditionally. Start building the | 7093 // The last body is entered unconditionally. Start building the |
| 7051 // if/then/else nest with that body as the innermost else block. | 7094 // if/then/else nest with that body as the innermost else block. |
| 7052 // Note that it is nested inside an extra block which we opened | 7095 // Note that it is nested inside an extra block which we opened |
| 7053 // before we knew the body was entered unconditionally. | 7096 // before we knew the body was entered unconditionally. |
| 7054 type_tests.RemoveLast(); | 7097 type_tests.RemoveLast(); |
| 7055 current_block_->statements->Add(catch_blocks.RemoveLast()); | 7098 current_block_->statements->Add(catch_blocks.RemoveLast()); |
| 7056 current = CloseBlock(); | 7099 current = CloseBlock(); |
| 7057 } | 7100 } |
| 7058 // If the last body was entered conditionally and there is no need to add | 7101 // If the last body was entered conditionally and there is no need to add |
| 7059 // a rethrow, use an empty else body (current = NULL above). | 7102 // a rethrow, use an empty else body (current = NULL above). |
| 7060 | 7103 |
| 7061 while (!type_tests.is_empty()) { | 7104 while (!type_tests.is_empty()) { |
| 7062 AstNode* type_test = type_tests.RemoveLast(); | 7105 AstNode* type_test = type_tests.RemoveLast(); |
| 7063 SequenceNode* catch_block = catch_blocks.RemoveLast(); | 7106 SequenceNode* catch_block = catch_blocks.RemoveLast(); |
| 7064 current_block_->statements->Add( | 7107 current_block_->statements->Add(new(isolate()) IfNode( |
| 7065 new IfNode(type_test->token_pos(), type_test, catch_block, current)); | 7108 type_test->token_pos(), type_test, catch_block, current)); |
| 7066 current = CloseBlock(); | 7109 current = CloseBlock(); |
| 7067 } | 7110 } |
| 7068 return current; | 7111 return current; |
| 7069 } | 7112 } |
| 7070 | 7113 |
| 7071 | 7114 |
| 7072 AstNode* Parser::ParseTryStatement(String* label_name) { | 7115 AstNode* Parser::ParseTryStatement(String* label_name) { |
| 7073 TRACE_PARSER("ParseTryStatement"); | 7116 TRACE_PARSER("ParseTryStatement"); |
| 7074 | 7117 |
| 7075 // We create three variables for exceptions here: | 7118 // We create three variables for exceptions here: |
| 7076 // ':saved_try_context_var' - Used to save the context before the start of | 7119 // ':saved_try_context_var' - Used to save the context before the start of |
| 7077 // the try block. The context register is | 7120 // the try block. The context register is |
| 7078 // restored from this variable before | 7121 // restored from this variable before |
| 7079 // processing the catch block handler. | 7122 // processing the catch block handler. |
| 7080 // ':exception_var' - Used to save the current exception object that was | 7123 // ':exception_var' - Used to save the current exception object that was |
| 7081 // thrown. | 7124 // thrown. |
| 7082 // ':stack_trace_var' - Used to save the current stack trace object which | 7125 // ':stack_trace_var' - Used to save the current stack trace object which |
| 7083 // the stack trace was copied into when an exception | 7126 // the stack trace was copied into when an exception |
| 7084 // was thrown. | 7127 // was thrown. |
| 7085 // :exception_var and :stack_trace_var get set with the exception object | 7128 // :exception_var and :stack_trace_var get set with the exception object |
| 7086 // and the stack trace object when an exception is thrown. These three | 7129 // and the stack trace object when an exception is thrown. These three |
| 7087 // implicit variables can never be captured. | 7130 // implicit variables can never be captured. |
| 7088 LocalVariable* context_var = | 7131 LocalVariable* context_var = |
| 7089 current_block_->scope->LocalLookupVariable(Symbols::SavedTryContextVar()); | 7132 current_block_->scope->LocalLookupVariable(Symbols::SavedTryContextVar()); |
| 7090 if (context_var == NULL) { | 7133 if (context_var == NULL) { |
| 7091 context_var = new LocalVariable(TokenPos(), | 7134 context_var = new(isolate()) LocalVariable( |
| 7092 Symbols::SavedTryContextVar(), | 7135 TokenPos(), |
| 7093 Type::ZoneHandle(Type::DynamicType())); | 7136 Symbols::SavedTryContextVar(), |
| 7137 Type::ZoneHandle(Type::DynamicType())); | |
| 7094 current_block_->scope->AddVariable(context_var); | 7138 current_block_->scope->AddVariable(context_var); |
| 7095 } | 7139 } |
| 7096 LocalVariable* exception_var = | 7140 LocalVariable* exception_var = |
| 7097 current_block_->scope->LocalLookupVariable(Symbols::ExceptionVar()); | 7141 current_block_->scope->LocalLookupVariable(Symbols::ExceptionVar()); |
| 7098 if (exception_var == NULL) { | 7142 if (exception_var == NULL) { |
| 7099 exception_var = new LocalVariable(TokenPos(), | 7143 exception_var = new(isolate()) LocalVariable( |
| 7100 Symbols::ExceptionVar(), | 7144 TokenPos(), |
| 7101 Type::ZoneHandle(Type::DynamicType())); | 7145 Symbols::ExceptionVar(), |
| 7146 Type::ZoneHandle(Type::DynamicType())); | |
| 7102 current_block_->scope->AddVariable(exception_var); | 7147 current_block_->scope->AddVariable(exception_var); |
| 7103 } | 7148 } |
| 7104 LocalVariable* stack_trace_var = | 7149 LocalVariable* stack_trace_var = |
| 7105 current_block_->scope->LocalLookupVariable(Symbols::StackTraceVar()); | 7150 current_block_->scope->LocalLookupVariable(Symbols::StackTraceVar()); |
| 7106 if (stack_trace_var == NULL) { | 7151 if (stack_trace_var == NULL) { |
| 7107 stack_trace_var = new LocalVariable(TokenPos(), | 7152 stack_trace_var = new(isolate()) LocalVariable( |
| 7108 Symbols::StackTraceVar(), | 7153 TokenPos(), |
| 7109 Type::ZoneHandle(Type::DynamicType())); | 7154 Symbols::StackTraceVar(), |
| 7155 Type::ZoneHandle(Type::DynamicType())); | |
| 7110 current_block_->scope->AddVariable(stack_trace_var); | 7156 current_block_->scope->AddVariable(stack_trace_var); |
| 7111 } | 7157 } |
| 7112 | 7158 |
| 7113 const intptr_t try_pos = TokenPos(); | 7159 const intptr_t try_pos = TokenPos(); |
| 7114 ConsumeToken(); // Consume the 'try'. | 7160 ConsumeToken(); // Consume the 'try'. |
| 7115 | 7161 |
| 7116 SourceLabel* try_label = NULL; | 7162 SourceLabel* try_label = NULL; |
| 7117 if (label_name != NULL) { | 7163 if (label_name != NULL) { |
| 7118 try_label = SourceLabel::New(try_pos, label_name, SourceLabel::kStatement); | 7164 try_label = SourceLabel::New(try_pos, label_name, SourceLabel::kStatement); |
| 7119 OpenBlock(); | 7165 OpenBlock(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 7130 | 7176 |
| 7131 if ((CurrentToken() != Token::kCATCH) && !IsLiteral("on") && | 7177 if ((CurrentToken() != Token::kCATCH) && !IsLiteral("on") && |
| 7132 (CurrentToken() != Token::kFINALLY)) { | 7178 (CurrentToken() != Token::kFINALLY)) { |
| 7133 ErrorMsg("catch or finally clause expected"); | 7179 ErrorMsg("catch or finally clause expected"); |
| 7134 } | 7180 } |
| 7135 | 7181 |
| 7136 // Now parse the 'catch' blocks if any. | 7182 // Now parse the 'catch' blocks if any. |
| 7137 try_blocks_list_->enter_catch(); | 7183 try_blocks_list_->enter_catch(); |
| 7138 const intptr_t handler_pos = TokenPos(); | 7184 const intptr_t handler_pos = TokenPos(); |
| 7139 const GrowableObjectArray& handler_types = | 7185 const GrowableObjectArray& handler_types = |
| 7140 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 7186 GrowableObjectArray::Handle(isolate(), GrowableObjectArray::New()); |
| 7141 bool needs_stack_trace = false; | 7187 bool needs_stack_trace = false; |
| 7142 SequenceNode* catch_handler_list = | 7188 SequenceNode* catch_handler_list = |
| 7143 ParseCatchClauses(handler_pos, exception_var, stack_trace_var, | 7189 ParseCatchClauses(handler_pos, exception_var, stack_trace_var, |
| 7144 handler_types, &needs_stack_trace); | 7190 handler_types, &needs_stack_trace); |
| 7145 | 7191 |
| 7146 TryBlocks* inner_try_block = PopTryBlock(); | 7192 TryBlocks* inner_try_block = PopTryBlock(); |
| 7147 const intptr_t try_index = inner_try_block->try_index(); | 7193 const intptr_t try_index = inner_try_block->try_index(); |
| 7148 TryBlocks* outer_try_block = try_blocks_list_; | 7194 TryBlocks* outer_try_block = try_blocks_list_; |
| 7149 const intptr_t outer_try_index = (outer_try_block != NULL) | 7195 const intptr_t outer_try_index = (outer_try_block != NULL) |
| 7150 ? outer_try_block->try_index() | 7196 ? outer_try_block->try_index() |
| 7151 : CatchClauseNode::kInvalidTryIndex; | 7197 : CatchClauseNode::kInvalidTryIndex; |
| 7152 | 7198 |
| 7153 // Finally parse the 'finally' block. | 7199 // Finally parse the 'finally' block. |
| 7154 SequenceNode* finally_block = NULL; | 7200 SequenceNode* finally_block = NULL; |
| 7155 if (CurrentToken() == Token::kFINALLY) { | 7201 if (CurrentToken() == Token::kFINALLY) { |
| 7156 ConsumeToken(); // Consume the 'finally'. | 7202 ConsumeToken(); // Consume the 'finally'. |
| 7157 const intptr_t finally_pos = TokenPos(); | 7203 const intptr_t finally_pos = TokenPos(); |
| 7158 // Add the finally block to the exit points recorded so far. | 7204 // Add the finally block to the exit points recorded so far. |
| 7159 intptr_t node_index = 0; | 7205 intptr_t node_index = 0; |
| 7160 AstNode* node_to_inline = | 7206 AstNode* node_to_inline = |
| 7161 inner_try_block->GetNodeToInlineFinally(node_index); | 7207 inner_try_block->GetNodeToInlineFinally(node_index); |
| 7162 while (node_to_inline != NULL) { | 7208 while (node_to_inline != NULL) { |
| 7163 finally_block = ParseFinallyBlock(); | 7209 finally_block = ParseFinallyBlock(); |
| 7164 InlinedFinallyNode* node = new InlinedFinallyNode(finally_pos, | 7210 InlinedFinallyNode* node = new(isolate()) InlinedFinallyNode(finally_pos, |
| 7165 finally_block, | 7211 finally_block, |
| 7166 context_var, | 7212 context_var, |
| 7167 outer_try_index); | 7213 outer_try_index); |
| 7168 AddFinallyBlockToNode(node_to_inline, node); | 7214 AddFinallyBlockToNode(node_to_inline, node); |
| 7169 node_index += 1; | 7215 node_index += 1; |
| 7170 node_to_inline = inner_try_block->GetNodeToInlineFinally(node_index); | 7216 node_to_inline = inner_try_block->GetNodeToInlineFinally(node_index); |
| 7171 tokens_iterator_.SetCurrentPosition(finally_pos); | 7217 tokens_iterator_.SetCurrentPosition(finally_pos); |
| 7172 } | 7218 } |
| 7173 finally_block = ParseFinallyBlock(); | 7219 finally_block = ParseFinallyBlock(); |
| 7174 } | 7220 } |
| 7175 | 7221 |
| 7176 CatchClauseNode* catch_clause = | 7222 CatchClauseNode* catch_clause = new(isolate()) CatchClauseNode( |
| 7177 new CatchClauseNode(handler_pos, | 7223 handler_pos, |
| 7178 catch_handler_list, | 7224 catch_handler_list, |
| 7179 Array::ZoneHandle(Array::MakeArray(handler_types)), | 7225 Array::ZoneHandle(Array::MakeArray(handler_types)), |
| 7180 context_var, | 7226 context_var, |
| 7181 exception_var, | 7227 exception_var, |
| 7182 stack_trace_var, | 7228 stack_trace_var, |
| 7183 (finally_block != NULL) | 7229 (finally_block != NULL) ? |
| 7184 ? AllocateTryIndex() | 7230 AllocateTryIndex() : CatchClauseNode::kInvalidTryIndex, |
| 7185 : CatchClauseNode::kInvalidTryIndex, | 7231 needs_stack_trace); |
| 7186 needs_stack_trace); | |
| 7187 | 7232 |
| 7188 // Now create the try/catch ast node and return it. If there is a label | 7233 // Now create the try/catch ast node and return it. If there is a label |
| 7189 // on the try/catch, close the block that's embedding the try statement | 7234 // on the try/catch, close the block that's embedding the try statement |
| 7190 // and attach the label to it. | 7235 // and attach the label to it. |
| 7191 AstNode* try_catch_node = | 7236 AstNode* try_catch_node = new(isolate()) TryCatchNode( |
| 7192 new TryCatchNode(try_pos, try_block, context_var, catch_clause, | 7237 try_pos, try_block, context_var, catch_clause, finally_block, try_index); |
| 7193 finally_block, try_index); | |
| 7194 | 7238 |
| 7195 if (try_label != NULL) { | 7239 if (try_label != NULL) { |
| 7196 current_block_->statements->Add(try_catch_node); | 7240 current_block_->statements->Add(try_catch_node); |
| 7197 SequenceNode* sequence = CloseBlock(); | 7241 SequenceNode* sequence = CloseBlock(); |
| 7198 sequence->set_label(try_label); | 7242 sequence->set_label(try_label); |
| 7199 try_catch_node = sequence; | 7243 try_catch_node = sequence; |
| 7200 } | 7244 } |
| 7201 return try_catch_node; | 7245 return try_catch_node; |
| 7202 } | 7246 } |
| 7203 | 7247 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 7224 } | 7268 } |
| 7225 target = current_block_->scope->LookupLabel(target_name); | 7269 target = current_block_->scope->LookupLabel(target_name); |
| 7226 if (target == NULL && jump_kind == Token::kCONTINUE) { | 7270 if (target == NULL && jump_kind == Token::kCONTINUE) { |
| 7227 // Either a reference to a non-existent label, or a forward reference | 7271 // Either a reference to a non-existent label, or a forward reference |
| 7228 // to a case label that we haven't seen yet. If we are inside a switch | 7272 // to a case label that we haven't seen yet. If we are inside a switch |
| 7229 // statement, create a "forward reference" label in the scope of | 7273 // statement, create a "forward reference" label in the scope of |
| 7230 // the switch statement. | 7274 // the switch statement. |
| 7231 LocalScope* switch_scope = current_block_->scope->LookupSwitchScope(); | 7275 LocalScope* switch_scope = current_block_->scope->LookupSwitchScope(); |
| 7232 if (switch_scope != NULL) { | 7276 if (switch_scope != NULL) { |
| 7233 // We found a switch scope. Enter a forward reference to the label. | 7277 // We found a switch scope. Enter a forward reference to the label. |
| 7234 target = new SourceLabel( | 7278 target = new(isolate()) SourceLabel( |
| 7235 TokenPos(), target_name, SourceLabel::kForward); | 7279 TokenPos(), target_name, SourceLabel::kForward); |
| 7236 switch_scope->AddLabel(target); | 7280 switch_scope->AddLabel(target); |
| 7237 } | 7281 } |
| 7238 } | 7282 } |
| 7239 if (target == NULL) { | 7283 if (target == NULL) { |
| 7240 ErrorMsg(jump_pos, "label '%s' not found", target_name.ToCString()); | 7284 ErrorMsg(jump_pos, "label '%s' not found", target_name.ToCString()); |
| 7241 } | 7285 } |
| 7242 } else { | 7286 } else { |
| 7243 target = current_block_->scope->LookupInnermostLabel(jump_kind); | 7287 target = current_block_->scope->LookupInnermostLabel(jump_kind); |
| 7244 if (target == NULL) { | 7288 if (target == NULL) { |
| 7245 ErrorMsg(jump_pos, "'%s' is illegal here", Token::Str(jump_kind)); | 7289 ErrorMsg(jump_pos, "'%s' is illegal here", Token::Str(jump_kind)); |
| 7246 } | 7290 } |
| 7247 } | 7291 } |
| 7248 ASSERT(target != NULL); | 7292 ASSERT(target != NULL); |
| 7249 if (jump_kind == Token::kCONTINUE) { | 7293 if (jump_kind == Token::kCONTINUE) { |
| 7250 if (target->kind() == SourceLabel::kSwitch) { | 7294 if (target->kind() == SourceLabel::kSwitch) { |
| 7251 ErrorMsg(jump_pos, "'continue' jump to switch statement is illegal"); | 7295 ErrorMsg(jump_pos, "'continue' jump to switch statement is illegal"); |
| 7252 } else if (target->kind() == SourceLabel::kStatement) { | 7296 } else if (target->kind() == SourceLabel::kStatement) { |
| 7253 ErrorMsg(jump_pos, "'continue' jump to label '%s' is illegal", | 7297 ErrorMsg(jump_pos, "'continue' jump to label '%s' is illegal", |
| 7254 target->name().ToCString()); | 7298 target->name().ToCString()); |
| 7255 } | 7299 } |
| 7256 } | 7300 } |
| 7257 if (jump_kind == Token::kBREAK && target->kind() == SourceLabel::kCase) { | 7301 if (jump_kind == Token::kBREAK && target->kind() == SourceLabel::kCase) { |
| 7258 ErrorMsg(jump_pos, "'break' to case clause label is illegal"); | 7302 ErrorMsg(jump_pos, "'break' to case clause label is illegal"); |
| 7259 } | 7303 } |
| 7260 if (target->FunctionLevel() != current_block_->scope->function_level()) { | 7304 if (target->FunctionLevel() != current_block_->scope->function_level()) { |
| 7261 ErrorMsg(jump_pos, "'%s' target must be in same function context", | 7305 ErrorMsg(jump_pos, "'%s' target must be in same function context", |
| 7262 Token::Str(jump_kind)); | 7306 Token::Str(jump_kind)); |
| 7263 } | 7307 } |
| 7264 return new JumpNode(jump_pos, jump_kind, target); | 7308 return new(isolate()) JumpNode(jump_pos, jump_kind, target); |
| 7265 } | 7309 } |
| 7266 | 7310 |
| 7267 | 7311 |
| 7268 AstNode* Parser::ParseStatement() { | 7312 AstNode* Parser::ParseStatement() { |
| 7269 TRACE_PARSER("ParseStatement"); | 7313 TRACE_PARSER("ParseStatement"); |
| 7270 AstNode* statement = NULL; | 7314 AstNode* statement = NULL; |
| 7271 intptr_t label_pos = 0; | 7315 intptr_t label_pos = 0; |
| 7272 String* label_name = NULL; | 7316 String* label_name = NULL; |
| 7273 if (IsIdentifier()) { | 7317 if (IsIdentifier()) { |
| 7274 if (LookaheadToken(1) == Token::kCOLON) { | 7318 if (LookaheadToken(1) == Token::kCOLON) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 7294 statement = ParseTryStatement(label_name); | 7338 statement = ParseTryStatement(label_name); |
| 7295 } else if (CurrentToken() == Token::kRETURN) { | 7339 } else if (CurrentToken() == Token::kRETURN) { |
| 7296 const intptr_t return_pos = TokenPos(); | 7340 const intptr_t return_pos = TokenPos(); |
| 7297 ConsumeToken(); | 7341 ConsumeToken(); |
| 7298 if (CurrentToken() != Token::kSEMICOLON) { | 7342 if (CurrentToken() != Token::kSEMICOLON) { |
| 7299 if (current_function().IsConstructor() && | 7343 if (current_function().IsConstructor() && |
| 7300 (current_block_->scope->function_level() == 0)) { | 7344 (current_block_->scope->function_level() == 0)) { |
| 7301 ErrorMsg(return_pos, "return of a value not allowed in constructors"); | 7345 ErrorMsg(return_pos, "return of a value not allowed in constructors"); |
| 7302 } | 7346 } |
| 7303 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades); | 7347 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades); |
| 7304 statement = new ReturnNode(statement_pos, expr); | 7348 statement = new(isolate()) ReturnNode(statement_pos, expr); |
| 7305 } else { | 7349 } else { |
| 7306 statement = new ReturnNode(statement_pos); | 7350 statement = new(isolate()) ReturnNode(statement_pos); |
| 7307 } | 7351 } |
| 7308 AddNodeForFinallyInlining(statement); | 7352 AddNodeForFinallyInlining(statement); |
| 7309 ExpectSemicolon(); | 7353 ExpectSemicolon(); |
| 7310 } else if (CurrentToken() == Token::kIF) { | 7354 } else if (CurrentToken() == Token::kIF) { |
| 7311 statement = ParseIfStatement(label_name); | 7355 statement = ParseIfStatement(label_name); |
| 7312 } else if (CurrentToken() == Token::kASSERT) { | 7356 } else if (CurrentToken() == Token::kASSERT) { |
| 7313 statement = ParseAssertStatement(); | 7357 statement = ParseAssertStatement(); |
| 7314 ExpectSemicolon(); | 7358 ExpectSemicolon(); |
| 7315 } else if (IsVariableDeclaration()) { | 7359 } else if (IsVariableDeclaration()) { |
| 7316 statement = ParseVariableDeclarationList(); | 7360 statement = ParseVariableDeclarationList(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7353 // The exception and stack trace variables are bound in the block | 7397 // The exception and stack trace variables are bound in the block |
| 7354 // containing the try. | 7398 // containing the try. |
| 7355 LocalScope* scope = try_blocks_list_->try_block()->scope->parent(); | 7399 LocalScope* scope = try_blocks_list_->try_block()->scope->parent(); |
| 7356 ASSERT(scope != NULL); | 7400 ASSERT(scope != NULL); |
| 7357 LocalVariable* excp_var = | 7401 LocalVariable* excp_var = |
| 7358 scope->LocalLookupVariable(Symbols::ExceptionVar()); | 7402 scope->LocalLookupVariable(Symbols::ExceptionVar()); |
| 7359 ASSERT(excp_var != NULL); | 7403 ASSERT(excp_var != NULL); |
| 7360 LocalVariable* trace_var = | 7404 LocalVariable* trace_var = |
| 7361 scope->LocalLookupVariable(Symbols::StackTraceVar()); | 7405 scope->LocalLookupVariable(Symbols::StackTraceVar()); |
| 7362 ASSERT(trace_var != NULL); | 7406 ASSERT(trace_var != NULL); |
| 7363 statement = new ThrowNode(statement_pos, | 7407 statement = new(isolate()) ThrowNode( |
| 7364 new LoadLocalNode(statement_pos, excp_var), | 7408 statement_pos, |
| 7365 new LoadLocalNode(statement_pos, trace_var)); | 7409 new(isolate()) LoadLocalNode(statement_pos, excp_var), |
| 7410 new(isolate()) LoadLocalNode(statement_pos, trace_var)); | |
| 7366 } else { | 7411 } else { |
| 7367 statement = ParseExpr(kAllowConst, kConsumeCascades); | 7412 statement = ParseExpr(kAllowConst, kConsumeCascades); |
| 7368 ExpectSemicolon(); | 7413 ExpectSemicolon(); |
| 7369 } | 7414 } |
| 7370 return statement; | 7415 return statement; |
| 7371 } | 7416 } |
| 7372 | 7417 |
| 7373 | 7418 |
| 7374 void Parser::ErrorMsg(intptr_t token_pos, const char* format, ...) const { | 7419 void Parser::ErrorMsg(intptr_t token_pos, const char* format, ...) const { |
| 7375 va_list args; | 7420 va_list args; |
| 7376 va_start(args, format); | 7421 va_start(args, format); |
| 7377 const Error& error = Error::Handle(LanguageError::NewFormattedV( | 7422 const Error& error = Error::Handle(isolate(), LanguageError::NewFormattedV( |
| 7378 Error::Handle(), script_, token_pos, | 7423 Error::Handle(isolate()), script_, token_pos, |
| 7379 LanguageError::kError, Heap::kNew, format, args)); | 7424 LanguageError::kError, Heap::kNew, format, args)); |
| 7380 va_end(args); | 7425 va_end(args); |
| 7381 isolate()->long_jump_base()->Jump(1, error); | 7426 isolate()->long_jump_base()->Jump(1, error); |
| 7382 UNREACHABLE(); | 7427 UNREACHABLE(); |
| 7383 } | 7428 } |
| 7384 | 7429 |
| 7385 | 7430 |
| 7386 void Parser::ErrorMsg(const char* format, ...) { | 7431 void Parser::ErrorMsg(const char* format, ...) { |
| 7387 va_list args; | 7432 va_list args; |
| 7388 va_start(args, format); | 7433 va_start(args, format); |
| 7389 const Error& error = Error::Handle(LanguageError::NewFormattedV( | 7434 const Error& error = Error::Handle(isolate(), LanguageError::NewFormattedV( |
| 7390 Error::Handle(), script_, TokenPos(), | 7435 Error::Handle(isolate()), script_, TokenPos(), |
| 7391 LanguageError::kError, Heap::kNew, format, args)); | 7436 LanguageError::kError, Heap::kNew, format, args)); |
| 7392 va_end(args); | 7437 va_end(args); |
| 7393 isolate()->long_jump_base()->Jump(1, error); | 7438 isolate()->long_jump_base()->Jump(1, error); |
| 7394 UNREACHABLE(); | 7439 UNREACHABLE(); |
| 7395 } | 7440 } |
| 7396 | 7441 |
| 7397 | 7442 |
| 7398 void Parser::ErrorMsg(const Error& error) { | 7443 void Parser::ErrorMsg(const Error& error) { |
| 7399 Isolate::Current()->long_jump_base()->Jump(1, error); | 7444 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 7400 UNREACHABLE(); | 7445 UNREACHABLE(); |
| 7401 } | 7446 } |
| 7402 | 7447 |
| 7403 | 7448 |
| 7404 void Parser::AppendErrorMsg( | 7449 void Parser::AppendErrorMsg( |
| 7405 const Error& prev_error, intptr_t token_pos, const char* format, ...) { | 7450 const Error& prev_error, intptr_t token_pos, const char* format, ...) { |
| 7406 va_list args; | 7451 va_list args; |
| 7407 va_start(args, format); | 7452 va_start(args, format); |
| 7408 const Error& error = Error::Handle( | 7453 const Error& error = Error::Handle(isolate(), LanguageError::NewFormattedV( |
| 7409 LanguageError::NewFormattedV( | 7454 prev_error, script_, token_pos, |
| 7410 prev_error, script_, token_pos, | 7455 LanguageError::kError, Heap::kNew, |
| 7411 LanguageError::kError, Heap::kNew, | 7456 format, args)); |
| 7412 format, args)); | |
| 7413 va_end(args); | 7457 va_end(args); |
| 7414 isolate()->long_jump_base()->Jump(1, error); | 7458 isolate()->long_jump_base()->Jump(1, error); |
| 7415 UNREACHABLE(); | 7459 UNREACHABLE(); |
| 7416 } | 7460 } |
| 7417 | 7461 |
| 7418 | 7462 |
| 7419 void Parser::Warning(intptr_t token_pos, const char* format, ...) { | 7463 void Parser::Warning(intptr_t token_pos, const char* format, ...) { |
| 7420 if (FLAG_silent_warnings) return; | 7464 if (FLAG_silent_warnings) return; |
| 7421 va_list args; | 7465 va_list args; |
| 7422 va_start(args, format); | 7466 va_start(args, format); |
| 7423 const Error& error = Error::Handle( | 7467 const Error& error = Error::Handle(isolate(), LanguageError::NewFormattedV( |
| 7424 LanguageError::NewFormattedV( | 7468 Error::Handle(isolate()), script_, token_pos, |
| 7425 Error::Handle(), script_, token_pos, | 7469 LanguageError::kWarning, Heap::kNew, |
| 7426 LanguageError::kWarning, Heap::kNew, | 7470 format, args)); |
| 7427 format, args)); | |
| 7428 va_end(args); | 7471 va_end(args); |
| 7429 if (FLAG_warning_as_error) { | 7472 if (FLAG_warning_as_error) { |
| 7430 isolate()->long_jump_base()->Jump(1, error); | 7473 isolate()->long_jump_base()->Jump(1, error); |
| 7431 UNREACHABLE(); | 7474 UNREACHABLE(); |
| 7432 } else { | 7475 } else { |
| 7433 OS::Print("%s", error.ToErrorCString()); | 7476 OS::Print("%s", error.ToErrorCString()); |
| 7434 } | 7477 } |
| 7435 } | 7478 } |
| 7436 | 7479 |
| 7437 | 7480 |
| 7438 void Parser::Warning(const char* format, ...) { | 7481 void Parser::Warning(const char* format, ...) { |
| 7439 if (FLAG_silent_warnings) return; | 7482 if (FLAG_silent_warnings) return; |
| 7440 va_list args; | 7483 va_list args; |
| 7441 va_start(args, format); | 7484 va_start(args, format); |
| 7442 const Error& error = Error::Handle( | 7485 const Error& error = Error::Handle(isolate(), LanguageError::NewFormattedV( |
| 7443 LanguageError::NewFormattedV( | 7486 Error::Handle(isolate()), script_, TokenPos(), |
| 7444 Error::Handle(), script_, TokenPos(), | 7487 LanguageError::kWarning, Heap::kNew, |
| 7445 LanguageError::kWarning, Heap::kNew, | 7488 format, args)); |
| 7446 format, args)); | |
| 7447 va_end(args); | 7489 va_end(args); |
| 7448 if (FLAG_warning_as_error) { | 7490 if (FLAG_warning_as_error) { |
| 7449 isolate()->long_jump_base()->Jump(1, error); | 7491 isolate()->long_jump_base()->Jump(1, error); |
| 7450 UNREACHABLE(); | 7492 UNREACHABLE(); |
| 7451 } else { | 7493 } else { |
| 7452 OS::Print("%s", error.ToErrorCString()); | 7494 OS::Print("%s", error.ToErrorCString()); |
| 7453 } | 7495 } |
| 7454 } | 7496 } |
| 7455 | 7497 |
| 7456 | 7498 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7542 if (node != NULL) { | 7584 if (node != NULL) { |
| 7543 sequence->Add(node); | 7585 sequence->Add(node); |
| 7544 } | 7586 } |
| 7545 return sequence; | 7587 return sequence; |
| 7546 } | 7588 } |
| 7547 return node->AsSequenceNode(); | 7589 return node->AsSequenceNode(); |
| 7548 } | 7590 } |
| 7549 | 7591 |
| 7550 | 7592 |
| 7551 AstNode* Parser::ThrowTypeError(intptr_t type_pos, const AbstractType& type) { | 7593 AstNode* Parser::ThrowTypeError(intptr_t type_pos, const AbstractType& type) { |
| 7552 ArgumentListNode* arguments = new ArgumentListNode(type_pos); | 7594 ArgumentListNode* arguments = new(isolate()) ArgumentListNode(type_pos); |
| 7553 // Location argument. | 7595 // Location argument. |
| 7554 arguments->Add(new LiteralNode( | 7596 arguments->Add(new(isolate()) LiteralNode( |
| 7555 type_pos, Integer::ZoneHandle(Integer::New(type_pos)))); | 7597 type_pos, Integer::ZoneHandle(Integer::New(type_pos)))); |
| 7556 // Src value argument. | 7598 // Src value argument. |
| 7557 arguments->Add(new LiteralNode(type_pos, Instance::ZoneHandle())); | 7599 arguments->Add(new(isolate()) LiteralNode(type_pos, Instance::ZoneHandle())); |
| 7558 // Dst type name argument. | 7600 // Dst type name argument. |
| 7559 arguments->Add(new LiteralNode(type_pos, Symbols::Malformed())); | 7601 arguments->Add(new(isolate()) LiteralNode(type_pos, Symbols::Malformed())); |
| 7560 // Dst name argument. | 7602 // Dst name argument. |
| 7561 arguments->Add(new LiteralNode(type_pos, Symbols::Empty())); | 7603 arguments->Add(new(isolate()) LiteralNode(type_pos, Symbols::Empty())); |
| 7562 // Malformed type error or malbounded type error. | 7604 // Malformed type error or malbounded type error. |
| 7563 const Error& error = Error::Handle(type.error()); | 7605 const Error& error = Error::Handle(isolate(), type.error()); |
| 7564 ASSERT(!error.IsNull()); | 7606 ASSERT(!error.IsNull()); |
| 7565 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( | 7607 arguments->Add(new(isolate()) LiteralNode(type_pos, String::ZoneHandle( |
| 7566 Symbols::New(error.ToErrorCString())))); | 7608 Symbols::New(error.ToErrorCString())))); |
| 7567 return MakeStaticCall(Symbols::TypeError(), | 7609 return MakeStaticCall(Symbols::TypeError(), |
| 7568 Library::PrivateCoreLibName(Symbols::ThrowNew()), | 7610 Library::PrivateCoreLibName(Symbols::ThrowNew()), |
| 7569 arguments); | 7611 arguments); |
| 7570 } | 7612 } |
| 7571 | 7613 |
| 7572 | 7614 |
| 7573 AstNode* Parser::ThrowNoSuchMethodError(intptr_t call_pos, | 7615 AstNode* Parser::ThrowNoSuchMethodError(intptr_t call_pos, |
| 7574 const Class& cls, | 7616 const Class& cls, |
| 7575 const String& function_name, | 7617 const String& function_name, |
| 7576 ArgumentListNode* function_arguments, | 7618 ArgumentListNode* function_arguments, |
| 7577 InvocationMirror::Call im_call, | 7619 InvocationMirror::Call im_call, |
| 7578 InvocationMirror::Type im_type, | 7620 InvocationMirror::Type im_type, |
| 7579 Function* func) { | 7621 Function* func) { |
| 7580 ArgumentListNode* arguments = new ArgumentListNode(call_pos); | 7622 ArgumentListNode* arguments = new(isolate()) ArgumentListNode(call_pos); |
| 7581 // Object receiver. | 7623 // Object receiver. |
| 7582 // TODO(regis): For now, we pass a class literal of the unresolved | 7624 // TODO(regis): For now, we pass a class literal of the unresolved |
| 7583 // method's owner, but this is not specified and will probably change. | 7625 // method's owner, but this is not specified and will probably change. |
| 7584 Type& type = Type::ZoneHandle( | 7626 Type& type = Type::ZoneHandle( |
| 7585 Type::New(cls, TypeArguments::Handle(), call_pos, Heap::kOld)); | 7627 Type::New(cls, TypeArguments::Handle(isolate()), call_pos, Heap::kOld)); |
| 7586 type ^= ClassFinalizer::FinalizeType( | 7628 type ^= ClassFinalizer::FinalizeType( |
| 7587 current_class(), type, ClassFinalizer::kCanonicalize); | 7629 current_class(), type, ClassFinalizer::kCanonicalize); |
| 7588 arguments->Add(new LiteralNode(call_pos, type)); | 7630 arguments->Add(new(isolate()) LiteralNode(call_pos, type)); |
| 7589 // String memberName. | 7631 // String memberName. |
| 7590 arguments->Add(new LiteralNode( | 7632 arguments->Add(new(isolate()) LiteralNode( |
| 7591 call_pos, String::ZoneHandle(Symbols::New(function_name)))); | 7633 call_pos, String::ZoneHandle(Symbols::New(function_name)))); |
| 7592 // Smi invocation_type. | 7634 // Smi invocation_type. |
| 7593 if (cls.IsTopLevel()) { | 7635 if (cls.IsTopLevel()) { |
| 7594 ASSERT(im_call == InvocationMirror::kStatic || | 7636 ASSERT(im_call == InvocationMirror::kStatic || |
| 7595 im_call == InvocationMirror::kTopLevel); | 7637 im_call == InvocationMirror::kTopLevel); |
| 7596 im_call = InvocationMirror::kTopLevel; | 7638 im_call = InvocationMirror::kTopLevel; |
| 7597 } | 7639 } |
| 7598 arguments->Add(new LiteralNode(call_pos, Smi::ZoneHandle( | 7640 arguments->Add(new(isolate()) LiteralNode(call_pos, Smi::ZoneHandle( |
| 7599 Smi::New(InvocationMirror::EncodeType(im_call, im_type))))); | 7641 Smi::New(InvocationMirror::EncodeType(im_call, im_type))))); |
| 7600 // List arguments. | 7642 // List arguments. |
| 7601 if (function_arguments == NULL) { | 7643 if (function_arguments == NULL) { |
| 7602 arguments->Add(new LiteralNode(call_pos, Array::ZoneHandle())); | 7644 arguments->Add(new(isolate()) LiteralNode(call_pos, Array::ZoneHandle())); |
| 7603 } else { | 7645 } else { |
| 7604 ArrayNode* array = new ArrayNode(call_pos, | 7646 ArrayNode* array = new(isolate()) ArrayNode( |
| 7605 Type::ZoneHandle(Type::ArrayType()), | 7647 call_pos, |
| 7606 function_arguments->nodes()); | 7648 Type::ZoneHandle(Type::ArrayType()), |
| 7649 function_arguments->nodes()); | |
| 7607 arguments->Add(array); | 7650 arguments->Add(array); |
| 7608 } | 7651 } |
| 7609 // List argumentNames. | 7652 // List argumentNames. |
| 7610 if (function_arguments == NULL) { | 7653 if (function_arguments == NULL) { |
| 7611 arguments->Add(new LiteralNode(call_pos, Array::ZoneHandle())); | 7654 arguments->Add(new(isolate()) LiteralNode(call_pos, Array::ZoneHandle())); |
| 7612 } else { | 7655 } else { |
| 7613 arguments->Add(new LiteralNode(call_pos, function_arguments->names())); | 7656 arguments->Add(new(isolate()) LiteralNode( |
| 7657 call_pos, function_arguments->names())); | |
| 7614 } | 7658 } |
| 7615 | 7659 |
| 7616 // List existingArgumentNames. | 7660 // List existingArgumentNames. |
| 7617 // Check if there exists a function with the same name unless caller | 7661 // Check if there exists a function with the same name unless caller |
| 7618 // has done the lookup already. If there is a function with the same | 7662 // has done the lookup already. If there is a function with the same |
| 7619 // name but incompatible parameters, inform the NoSuchMethodError what the | 7663 // name but incompatible parameters, inform the NoSuchMethodError what the |
| 7620 // expected parameters are. | 7664 // expected parameters are. |
| 7621 Function& function = Function::Handle(); | 7665 Function& function = Function::Handle(isolate()); |
| 7622 if (func != NULL) { | 7666 if (func != NULL) { |
| 7623 function = func->raw(); | 7667 function = func->raw(); |
| 7624 } else { | 7668 } else { |
| 7625 function = cls.LookupStaticFunction(function_name); | 7669 function = cls.LookupStaticFunction(function_name); |
| 7626 } | 7670 } |
| 7627 Array& array = Array::ZoneHandle(); | 7671 Array& array = Array::ZoneHandle(); |
| 7628 if (!function.IsNull()) { | 7672 if (!function.IsNull()) { |
| 7629 // The constructor for NoSuchMethodError takes a list of existing | 7673 // The constructor for NoSuchMethodError takes a list of existing |
| 7630 // parameter names to produce a descriptive error message explaining | 7674 // parameter names to produce a descriptive error message explaining |
| 7631 // the parameter mismatch. The problem is that the array of names | 7675 // the parameter mismatch. The problem is that the array of names |
| 7632 // does not describe which parameters are optional positional or | 7676 // does not describe which parameters are optional positional or |
| 7633 // named, which can lead to confusing error messages. | 7677 // named, which can lead to confusing error messages. |
| 7634 // Since the NoSuchMethodError class only uses the list to produce | 7678 // Since the NoSuchMethodError class only uses the list to produce |
| 7635 // a string describing the expected parameters, we construct a more | 7679 // a string describing the expected parameters, we construct a more |
| 7636 // descriptive string here and pass it as the only element of the | 7680 // descriptive string here and pass it as the only element of the |
| 7637 // "existingArgumentNames" array of the NoSuchMethodError constructor. | 7681 // "existingArgumentNames" array of the NoSuchMethodError constructor. |
| 7638 // TODO(13471): Separate the implementations of NoSuchMethodError | 7682 // TODO(13471): Separate the implementations of NoSuchMethodError |
| 7639 // between dart2js and VM. Update the constructor to accept a string | 7683 // between dart2js and VM. Update the constructor to accept a string |
| 7640 // describing the formal parameters of an incompatible call target. | 7684 // describing the formal parameters of an incompatible call target. |
| 7641 array = Array::New(1, Heap::kOld); | 7685 array = Array::New(1, Heap::kOld); |
| 7642 array.SetAt(0, String::Handle(function.UserVisibleFormalParameters())); | 7686 array.SetAt(0, String::Handle(isolate(), |
| 7687 function.UserVisibleFormalParameters())); | |
| 7643 } | 7688 } |
| 7644 arguments->Add(new LiteralNode(call_pos, array)); | 7689 arguments->Add(new(isolate()) LiteralNode(call_pos, array)); |
| 7645 | 7690 |
| 7646 return MakeStaticCall(Symbols::NoSuchMethodError(), | 7691 return MakeStaticCall(Symbols::NoSuchMethodError(), |
| 7647 Library::PrivateCoreLibName(Symbols::ThrowNew()), | 7692 Library::PrivateCoreLibName(Symbols::ThrowNew()), |
| 7648 arguments); | 7693 arguments); |
| 7649 } | 7694 } |
| 7650 | 7695 |
| 7651 | 7696 |
| 7652 AstNode* Parser::ParseBinaryExpr(int min_preced) { | 7697 AstNode* Parser::ParseBinaryExpr(int min_preced) { |
| 7653 TRACE_PARSER("ParseBinaryExpr"); | 7698 TRACE_PARSER("ParseBinaryExpr"); |
| 7654 ASSERT(min_preced >= Token::Precedence(Token::kOR)); | 7699 ASSERT(min_preced >= Token::Precedence(Token::kOR)); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 7673 op_kind = Token::kISNOT; | 7718 op_kind = Token::kISNOT; |
| 7674 } | 7719 } |
| 7675 const intptr_t type_pos = TokenPos(); | 7720 const intptr_t type_pos = TokenPos(); |
| 7676 const AbstractType& type = AbstractType::ZoneHandle( | 7721 const AbstractType& type = AbstractType::ZoneHandle( |
| 7677 ParseType(ClassFinalizer::kCanonicalize)); | 7722 ParseType(ClassFinalizer::kCanonicalize)); |
| 7678 if (!type.IsInstantiated() && | 7723 if (!type.IsInstantiated() && |
| 7679 (current_block_->scope->function_level() > 0)) { | 7724 (current_block_->scope->function_level() > 0)) { |
| 7680 // Make sure that the instantiator is captured. | 7725 // Make sure that the instantiator is captured. |
| 7681 CaptureInstantiator(); | 7726 CaptureInstantiator(); |
| 7682 } | 7727 } |
| 7683 right_operand = new TypeNode(type_pos, type); | 7728 right_operand = new(isolate()) TypeNode(type_pos, type); |
| 7684 // In production mode, the type may be malformed. | 7729 // In production mode, the type may be malformed. |
| 7685 // In checked mode, the type may be malformed or malbounded. | 7730 // In checked mode, the type may be malformed or malbounded. |
| 7686 if (((op_kind == Token::kIS) || (op_kind == Token::kISNOT) || | 7731 if (((op_kind == Token::kIS) || (op_kind == Token::kISNOT) || |
| 7687 (op_kind == Token::kAS)) && | 7732 (op_kind == Token::kAS)) && |
| 7688 type.IsMalformedOrMalbounded()) { | 7733 type.IsMalformedOrMalbounded()) { |
| 7689 // Note that a type error is thrown in a type test or in | 7734 // Note that a type error is thrown in a type test or in |
| 7690 // a type cast even if the tested value is null. | 7735 // a type cast even if the tested value is null. |
| 7691 // We need to evaluate the left operand for potential | 7736 // We need to evaluate the left operand for potential |
| 7692 // side effects. | 7737 // side effects. |
| 7693 LetNode* let = new LetNode(left_operand->token_pos()); | 7738 LetNode* let = new(isolate()) LetNode(left_operand->token_pos()); |
| 7694 let->AddNode(left_operand); | 7739 let->AddNode(left_operand); |
| 7695 let->AddNode(ThrowTypeError(type_pos, type)); | 7740 let->AddNode(ThrowTypeError(type_pos, type)); |
| 7696 left_operand = let; | 7741 left_operand = let; |
| 7697 break; // Type checks and casts can't be chained. | 7742 break; // Type checks and casts can't be chained. |
| 7698 } | 7743 } |
| 7699 } | 7744 } |
| 7700 if (Token::IsRelationalOperator(op_kind) | 7745 if (Token::IsRelationalOperator(op_kind) |
| 7701 || Token::IsTypeTestOperator(op_kind) | 7746 || Token::IsTypeTestOperator(op_kind) |
| 7702 || Token::IsTypeCastOperator(op_kind) | 7747 || Token::IsTypeCastOperator(op_kind) |
| 7703 || Token::IsEqualityOperator(op_kind)) { | 7748 || Token::IsEqualityOperator(op_kind)) { |
| 7704 if (Token::IsTypeTestOperator(op_kind) || | 7749 if (Token::IsTypeTestOperator(op_kind) || |
| 7705 Token::IsTypeCastOperator(op_kind)) { | 7750 Token::IsTypeCastOperator(op_kind)) { |
| 7706 if (!right_operand->AsTypeNode()->type().IsInstantiated()) { | 7751 if (!right_operand->AsTypeNode()->type().IsInstantiated()) { |
| 7707 EnsureExpressionTemp(); | 7752 EnsureExpressionTemp(); |
| 7708 } | 7753 } |
| 7709 } | 7754 } |
| 7710 left_operand = new ComparisonNode( | 7755 left_operand = new(isolate()) ComparisonNode( |
| 7711 op_pos, op_kind, left_operand, right_operand); | 7756 op_pos, op_kind, left_operand, right_operand); |
| 7712 break; // Equality and relational operators cannot be chained. | 7757 break; // Equality and relational operators cannot be chained. |
| 7713 } else { | 7758 } else { |
| 7714 left_operand = OptimizeBinaryOpNode( | 7759 left_operand = OptimizeBinaryOpNode( |
| 7715 op_pos, op_kind, left_operand, right_operand); | 7760 op_pos, op_kind, left_operand, right_operand); |
| 7716 } | 7761 } |
| 7717 } | 7762 } |
| 7718 current_preced--; | 7763 current_preced--; |
| 7719 } | 7764 } |
| 7720 return left_operand; | 7765 return left_operand; |
| 7721 } | 7766 } |
| 7722 | 7767 |
| 7723 | 7768 |
| 7724 AstNode* Parser::ParseExprList() { | 7769 AstNode* Parser::ParseExprList() { |
| 7725 TRACE_PARSER("ParseExprList"); | 7770 TRACE_PARSER("ParseExprList"); |
| 7726 AstNode* expressions = ParseExpr(kAllowConst, kConsumeCascades); | 7771 AstNode* expressions = ParseExpr(kAllowConst, kConsumeCascades); |
| 7727 if (CurrentToken() == Token::kCOMMA) { | 7772 if (CurrentToken() == Token::kCOMMA) { |
| 7728 // Collect comma-separated expressions in a non scope owning sequence node. | 7773 // Collect comma-separated expressions in a non scope owning sequence node. |
| 7729 SequenceNode* list = new SequenceNode(TokenPos(), NULL); | 7774 SequenceNode* list = new(isolate()) SequenceNode(TokenPos(), NULL); |
| 7730 list->Add(expressions); | 7775 list->Add(expressions); |
| 7731 while (CurrentToken() == Token::kCOMMA) { | 7776 while (CurrentToken() == Token::kCOMMA) { |
| 7732 ConsumeToken(); | 7777 ConsumeToken(); |
| 7733 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades); | 7778 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades); |
| 7734 list->Add(expr); | 7779 list->Add(expr); |
| 7735 } | 7780 } |
| 7736 expressions = list; | 7781 expressions = list; |
| 7737 } | 7782 } |
| 7738 return expressions; | 7783 return expressions; |
| 7739 } | 7784 } |
| 7740 | 7785 |
| 7741 | 7786 |
| 7742 void Parser::EnsureExpressionTemp() { | 7787 void Parser::EnsureExpressionTemp() { |
| 7743 // Temporary used later by the flow_graph_builder. | 7788 // Temporary used later by the flow_graph_builder. |
| 7744 parsed_function()->EnsureExpressionTemp(); | 7789 parsed_function()->EnsureExpressionTemp(); |
| 7745 } | 7790 } |
| 7746 | 7791 |
| 7747 | 7792 |
| 7748 void Parser::EnsureSavedCurrentContext() { | 7793 void Parser::EnsureSavedCurrentContext() { |
| 7749 // Used later by the flow_graph_builder to save current context. | 7794 // Used later by the flow_graph_builder to save current context. |
| 7750 if (!parsed_function()->has_saved_current_context_var()) { | 7795 if (!parsed_function()->has_saved_current_context_var()) { |
| 7751 LocalVariable* temp = | 7796 LocalVariable* temp = new(isolate()) LocalVariable( |
| 7752 new LocalVariable(current_function().token_pos(), | 7797 current_function().token_pos(), |
| 7753 Symbols::SavedCurrentContextVar(), | 7798 Symbols::SavedCurrentContextVar(), |
| 7754 Type::ZoneHandle(Type::DynamicType())); | 7799 Type::ZoneHandle(Type::DynamicType())); |
| 7755 ASSERT(temp != NULL); | 7800 ASSERT(temp != NULL); |
| 7756 parsed_function()->set_saved_current_context_var(temp); | 7801 parsed_function()->set_saved_current_context_var(temp); |
| 7757 } | 7802 } |
| 7758 } | 7803 } |
| 7759 | 7804 |
| 7760 | 7805 |
| 7761 LocalVariable* Parser::CreateTempConstVariable(intptr_t token_pos, | 7806 LocalVariable* Parser::CreateTempConstVariable(intptr_t token_pos, |
| 7762 const char* s) { | 7807 const char* s) { |
| 7763 char name[64]; | 7808 char name[64]; |
| 7764 OS::SNPrint(name, 64, ":%s%" Pd, s, token_pos); | 7809 OS::SNPrint(name, 64, ":%s%" Pd, s, token_pos); |
| 7765 LocalVariable* temp = | 7810 LocalVariable* temp = new(isolate()) LocalVariable( |
| 7766 new LocalVariable(token_pos, | 7811 token_pos, |
| 7767 String::ZoneHandle(Symbols::New(name)), | 7812 String::ZoneHandle(Symbols::New(name)), |
| 7768 Type::ZoneHandle(Type::DynamicType())); | 7813 Type::ZoneHandle(Type::DynamicType())); |
| 7769 temp->set_is_final(); | 7814 temp->set_is_final(); |
| 7770 current_block_->scope->AddVariable(temp); | 7815 current_block_->scope->AddVariable(temp); |
| 7771 return temp; | 7816 return temp; |
| 7772 } | 7817 } |
| 7773 | 7818 |
| 7774 | 7819 |
| 7775 // TODO(srdjan): Implement other optimizations. | 7820 // TODO(srdjan): Implement other optimizations. |
| 7776 AstNode* Parser::OptimizeBinaryOpNode(intptr_t op_pos, | 7821 AstNode* Parser::OptimizeBinaryOpNode(intptr_t op_pos, |
| 7777 Token::Kind binary_op, | 7822 Token::Kind binary_op, |
| 7778 AstNode* lhs, | 7823 AstNode* lhs, |
| 7779 AstNode* rhs) { | 7824 AstNode* rhs) { |
| 7780 LiteralNode* lhs_literal = lhs->AsLiteralNode(); | 7825 LiteralNode* lhs_literal = lhs->AsLiteralNode(); |
| 7781 LiteralNode* rhs_literal = rhs->AsLiteralNode(); | 7826 LiteralNode* rhs_literal = rhs->AsLiteralNode(); |
| 7782 if ((lhs_literal != NULL) && (rhs_literal != NULL)) { | 7827 if ((lhs_literal != NULL) && (rhs_literal != NULL)) { |
| 7783 if (lhs_literal->literal().IsDouble() && | 7828 if (lhs_literal->literal().IsDouble() && |
| 7784 rhs_literal->literal().IsDouble()) { | 7829 rhs_literal->literal().IsDouble()) { |
| 7785 double left_double = Double::Cast(lhs_literal->literal()).value(); | 7830 double left_double = Double::Cast(lhs_literal->literal()).value(); |
| 7786 double right_double = Double::Cast(rhs_literal->literal()).value(); | 7831 double right_double = Double::Cast(rhs_literal->literal()).value(); |
| 7787 if (binary_op == Token::kDIV) { | 7832 if (binary_op == Token::kDIV) { |
| 7788 const Double& dbl_obj = Double::ZoneHandle( | 7833 const Double& dbl_obj = Double::ZoneHandle( |
| 7789 Double::NewCanonical((left_double / right_double))); | 7834 Double::NewCanonical((left_double / right_double))); |
| 7790 return new LiteralNode(op_pos, dbl_obj); | 7835 return new(isolate()) LiteralNode(op_pos, dbl_obj); |
| 7791 } | 7836 } |
| 7792 } | 7837 } |
| 7793 } | 7838 } |
| 7794 if ((binary_op == Token::kAND) || (binary_op == Token::kOR)) { | 7839 if ((binary_op == Token::kAND) || (binary_op == Token::kOR)) { |
| 7795 EnsureExpressionTemp(); | 7840 EnsureExpressionTemp(); |
| 7796 } | 7841 } |
| 7797 if (binary_op == Token::kBIT_AND) { | 7842 if (binary_op == Token::kBIT_AND) { |
| 7798 // Normalize so that rhs is a literal if any is. | 7843 // Normalize so that rhs is a literal if any is. |
| 7799 if ((rhs_literal == NULL) && (lhs_literal != NULL)) { | 7844 if ((rhs_literal == NULL) && (lhs_literal != NULL)) { |
| 7800 // Swap. | 7845 // Swap. |
| 7801 LiteralNode* temp = rhs_literal; | 7846 LiteralNode* temp = rhs_literal; |
| 7802 rhs_literal = lhs_literal; | 7847 rhs_literal = lhs_literal; |
| 7803 lhs_literal = temp; | 7848 lhs_literal = temp; |
| 7804 } | 7849 } |
| 7805 if ((rhs_literal != NULL) && | 7850 if ((rhs_literal != NULL) && |
| 7806 (rhs_literal->literal().IsSmi() || rhs_literal->literal().IsMint())) { | 7851 (rhs_literal->literal().IsSmi() || rhs_literal->literal().IsMint())) { |
| 7807 const int64_t val = Integer::Cast(rhs_literal->literal()).AsInt64Value(); | 7852 const int64_t val = Integer::Cast(rhs_literal->literal()).AsInt64Value(); |
| 7808 if ((0 <= val) && (Utils::IsUint(32, val))) { | 7853 if ((0 <= val) && (Utils::IsUint(32, val))) { |
| 7809 if (lhs->IsBinaryOpNode() && | 7854 if (lhs->IsBinaryOpNode() && |
| 7810 (lhs->AsBinaryOpNode()->kind() == Token::kSHL)) { | 7855 (lhs->AsBinaryOpNode()->kind() == Token::kSHL)) { |
| 7811 // Merge SHL and BIT_AND into one "SHL with mask" node. | 7856 // Merge SHL and BIT_AND into one "SHL with mask" node. |
| 7812 BinaryOpNode* old = lhs->AsBinaryOpNode(); | 7857 BinaryOpNode* old = lhs->AsBinaryOpNode(); |
| 7813 BinaryOpWithMask32Node* binop = new BinaryOpWithMask32Node( | 7858 BinaryOpWithMask32Node* binop = new(isolate()) BinaryOpWithMask32Node( |
| 7814 old->token_pos(), old->kind(), old->left(), old->right(), val); | 7859 old->token_pos(), old->kind(), old->left(), old->right(), val); |
| 7815 return binop; | 7860 return binop; |
| 7816 } | 7861 } |
| 7817 } | 7862 } |
| 7818 } | 7863 } |
| 7819 } | 7864 } |
| 7820 return new BinaryOpNode(op_pos, binary_op, lhs, rhs); | 7865 return new(isolate()) BinaryOpNode(op_pos, binary_op, lhs, rhs); |
| 7821 } | 7866 } |
| 7822 | 7867 |
| 7823 | 7868 |
| 7824 AstNode* Parser::ExpandAssignableOp(intptr_t op_pos, | 7869 AstNode* Parser::ExpandAssignableOp(intptr_t op_pos, |
| 7825 Token::Kind assignment_op, | 7870 Token::Kind assignment_op, |
| 7826 AstNode* lhs, | 7871 AstNode* lhs, |
| 7827 AstNode* rhs) { | 7872 AstNode* rhs) { |
| 7828 TRACE_PARSER("ExpandAssignableOp"); | 7873 TRACE_PARSER("ExpandAssignableOp"); |
| 7829 switch (assignment_op) { | 7874 switch (assignment_op) { |
| 7830 case Token::kASSIGN: | 7875 case Token::kASSIGN: |
| 7831 return rhs; | 7876 return rhs; |
| 7832 case Token::kASSIGN_ADD: | 7877 case Token::kASSIGN_ADD: |
| 7833 return new BinaryOpNode(op_pos, Token::kADD, lhs, rhs); | 7878 return new(isolate()) BinaryOpNode(op_pos, Token::kADD, lhs, rhs); |
| 7834 case Token::kASSIGN_SUB: | 7879 case Token::kASSIGN_SUB: |
| 7835 return new BinaryOpNode(op_pos, Token::kSUB, lhs, rhs); | 7880 return new(isolate()) BinaryOpNode(op_pos, Token::kSUB, lhs, rhs); |
| 7836 case Token::kASSIGN_MUL: | 7881 case Token::kASSIGN_MUL: |
| 7837 return new BinaryOpNode(op_pos, Token::kMUL, lhs, rhs); | 7882 return new(isolate()) BinaryOpNode(op_pos, Token::kMUL, lhs, rhs); |
| 7838 case Token::kASSIGN_TRUNCDIV: | 7883 case Token::kASSIGN_TRUNCDIV: |
| 7839 return new BinaryOpNode(op_pos, Token::kTRUNCDIV, lhs, rhs); | 7884 return new(isolate()) BinaryOpNode(op_pos, Token::kTRUNCDIV, lhs, rhs); |
| 7840 case Token::kASSIGN_DIV: | 7885 case Token::kASSIGN_DIV: |
| 7841 return new BinaryOpNode(op_pos, Token::kDIV, lhs, rhs); | 7886 return new(isolate()) BinaryOpNode(op_pos, Token::kDIV, lhs, rhs); |
| 7842 case Token::kASSIGN_MOD: | 7887 case Token::kASSIGN_MOD: |
| 7843 return new BinaryOpNode(op_pos, Token::kMOD, lhs, rhs); | 7888 return new(isolate()) BinaryOpNode(op_pos, Token::kMOD, lhs, rhs); |
| 7844 case Token::kASSIGN_SHR: | 7889 case Token::kASSIGN_SHR: |
| 7845 return new BinaryOpNode(op_pos, Token::kSHR, lhs, rhs); | 7890 return new(isolate()) BinaryOpNode(op_pos, Token::kSHR, lhs, rhs); |
| 7846 case Token::kASSIGN_SHL: | 7891 case Token::kASSIGN_SHL: |
| 7847 return new BinaryOpNode(op_pos, Token::kSHL, lhs, rhs); | 7892 return new(isolate()) BinaryOpNode(op_pos, Token::kSHL, lhs, rhs); |
| 7848 case Token::kASSIGN_OR: | 7893 case Token::kASSIGN_OR: |
| 7849 return new BinaryOpNode(op_pos, Token::kBIT_OR, lhs, rhs); | 7894 return new(isolate()) BinaryOpNode(op_pos, Token::kBIT_OR, lhs, rhs); |
| 7850 case Token::kASSIGN_AND: | 7895 case Token::kASSIGN_AND: |
| 7851 return new BinaryOpNode(op_pos, Token::kBIT_AND, lhs, rhs); | 7896 return new(isolate()) BinaryOpNode(op_pos, Token::kBIT_AND, lhs, rhs); |
| 7852 case Token::kASSIGN_XOR: | 7897 case Token::kASSIGN_XOR: |
| 7853 return new BinaryOpNode(op_pos, Token::kBIT_XOR, lhs, rhs); | 7898 return new(isolate()) BinaryOpNode(op_pos, Token::kBIT_XOR, lhs, rhs); |
| 7854 default: | 7899 default: |
| 7855 ErrorMsg(op_pos, "internal error: ExpandAssignableOp '%s' unimplemented", | 7900 ErrorMsg(op_pos, "internal error: ExpandAssignableOp '%s' unimplemented", |
| 7856 Token::Name(assignment_op)); | 7901 Token::Name(assignment_op)); |
| 7857 UNIMPLEMENTED(); | 7902 UNIMPLEMENTED(); |
| 7858 return NULL; | 7903 return NULL; |
| 7859 } | 7904 } |
| 7860 } | 7905 } |
| 7861 | 7906 |
| 7862 | 7907 |
| 7863 // Evaluates the value of the compile time constant expression | 7908 // Evaluates the value of the compile time constant expression |
| 7864 // and returns a literal node for the value. | 7909 // and returns a literal node for the value. |
| 7865 AstNode* Parser::FoldConstExpr(intptr_t expr_pos, AstNode* expr) { | 7910 AstNode* Parser::FoldConstExpr(intptr_t expr_pos, AstNode* expr) { |
| 7866 if (expr->IsLiteralNode()) { | 7911 if (expr->IsLiteralNode()) { |
| 7867 return expr; | 7912 return expr; |
| 7868 } | 7913 } |
| 7869 if (expr->EvalConstExpr() == NULL) { | 7914 if (expr->EvalConstExpr() == NULL) { |
| 7870 ErrorMsg(expr_pos, "expression is not a valid compile-time constant"); | 7915 ErrorMsg(expr_pos, "expression is not a valid compile-time constant"); |
| 7871 } | 7916 } |
| 7872 return new LiteralNode(expr_pos, EvaluateConstExpr(expr_pos, expr)); | 7917 return new(isolate()) LiteralNode( |
| 7918 expr_pos, EvaluateConstExpr(expr_pos, expr)); | |
| 7873 } | 7919 } |
| 7874 | 7920 |
| 7875 | 7921 |
| 7876 LetNode* Parser::PrepareCompoundAssignmentNodes(AstNode** expr) { | 7922 LetNode* Parser::PrepareCompoundAssignmentNodes(AstNode** expr) { |
| 7877 AstNode* node = *expr; | 7923 AstNode* node = *expr; |
| 7878 intptr_t token_pos = node->token_pos(); | 7924 intptr_t token_pos = node->token_pos(); |
| 7879 LetNode* result = new LetNode(token_pos); | 7925 LetNode* result = new(isolate()) LetNode(token_pos); |
| 7880 if (node->IsLoadIndexedNode()) { | 7926 if (node->IsLoadIndexedNode()) { |
| 7881 LoadIndexedNode* load_indexed = node->AsLoadIndexedNode(); | 7927 LoadIndexedNode* load_indexed = node->AsLoadIndexedNode(); |
| 7882 AstNode* array = load_indexed->array(); | 7928 AstNode* array = load_indexed->array(); |
| 7883 AstNode* index = load_indexed->index_expr(); | 7929 AstNode* index = load_indexed->index_expr(); |
| 7884 if (!IsSimpleLocalOrLiteralNode(load_indexed->array())) { | 7930 if (!IsSimpleLocalOrLiteralNode(load_indexed->array())) { |
| 7885 LocalVariable* t0 = result->AddInitializer(load_indexed->array()); | 7931 LocalVariable* t0 = result->AddInitializer(load_indexed->array()); |
| 7886 array = new LoadLocalNode(token_pos, t0); | 7932 array = new(isolate()) LoadLocalNode(token_pos, t0); |
| 7887 } | 7933 } |
| 7888 if (!IsSimpleLocalOrLiteralNode(load_indexed->index_expr())) { | 7934 if (!IsSimpleLocalOrLiteralNode(load_indexed->index_expr())) { |
| 7889 LocalVariable* t1 = result->AddInitializer( | 7935 LocalVariable* t1 = result->AddInitializer( |
| 7890 load_indexed->index_expr()); | 7936 load_indexed->index_expr()); |
| 7891 index = new LoadLocalNode(token_pos, t1); | 7937 index = new(isolate()) LoadLocalNode(token_pos, t1); |
| 7892 } | 7938 } |
| 7893 *expr = new LoadIndexedNode(token_pos, | 7939 *expr = new(isolate()) LoadIndexedNode(token_pos, |
| 7894 array, | 7940 array, |
| 7895 index, | 7941 index, |
| 7896 load_indexed->super_class()); | 7942 load_indexed->super_class()); |
| 7897 return result; | 7943 return result; |
| 7898 } | 7944 } |
| 7899 if (node->IsInstanceGetterNode()) { | 7945 if (node->IsInstanceGetterNode()) { |
| 7900 InstanceGetterNode* getter = node->AsInstanceGetterNode(); | 7946 InstanceGetterNode* getter = node->AsInstanceGetterNode(); |
| 7901 AstNode* receiver = getter->receiver(); | 7947 AstNode* receiver = getter->receiver(); |
| 7902 if (!IsSimpleLocalOrLiteralNode(getter->receiver())) { | 7948 if (!IsSimpleLocalOrLiteralNode(getter->receiver())) { |
| 7903 LocalVariable* t0 = result->AddInitializer(getter->receiver()); | 7949 LocalVariable* t0 = result->AddInitializer(getter->receiver()); |
| 7904 receiver = new LoadLocalNode(token_pos, t0); | 7950 receiver = new(isolate()) LoadLocalNode(token_pos, t0); |
| 7905 } | 7951 } |
| 7906 *expr = new InstanceGetterNode(token_pos, | 7952 *expr = new(isolate()) InstanceGetterNode(token_pos, |
| 7907 receiver, | 7953 receiver, |
| 7908 getter->field_name()); | 7954 getter->field_name()); |
| 7909 return result; | 7955 return result; |
| 7910 } | 7956 } |
| 7911 return result; | 7957 return result; |
| 7912 } | 7958 } |
| 7913 | 7959 |
| 7914 | 7960 |
| 7915 // Check whether the syntax of expression expr is a grammatically legal | 7961 // Check whether the syntax of expression expr is a grammatically legal |
| 7916 // assignable expression. This check is used to detect situations where | 7962 // assignable expression. This check is used to detect situations where |
| 7917 // the expression itself is assignable, but the source is grammatically | 7963 // the expression itself is assignable, but the source is grammatically |
| 7918 // wrong. The AST representation of an expression cannot distinguish | 7964 // wrong. The AST representation of an expression cannot distinguish |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 7939 const String* left_ident, | 7985 const String* left_ident, |
| 7940 intptr_t left_pos) { | 7986 intptr_t left_pos) { |
| 7941 AstNode* result = original->MakeAssignmentNode(rhs); | 7987 AstNode* result = original->MakeAssignmentNode(rhs); |
| 7942 if (result == NULL) { | 7988 if (result == NULL) { |
| 7943 String& name = String::ZoneHandle(); | 7989 String& name = String::ZoneHandle(); |
| 7944 const Class* target_cls = ¤t_class(); | 7990 const Class* target_cls = ¤t_class(); |
| 7945 if (original->IsTypeNode()) { | 7991 if (original->IsTypeNode()) { |
| 7946 name = Symbols::New(original->AsTypeNode()->TypeName()); | 7992 name = Symbols::New(original->AsTypeNode()->TypeName()); |
| 7947 } else if (original->IsLoadStaticFieldNode()) { | 7993 } else if (original->IsLoadStaticFieldNode()) { |
| 7948 name = original->AsLoadStaticFieldNode()->field().name(); | 7994 name = original->AsLoadStaticFieldNode()->field().name(); |
| 7949 target_cls = | 7995 target_cls = &Class::Handle(isolate(), |
| 7950 &Class::Handle(original->AsLoadStaticFieldNode()->field().owner()); | 7996 original->AsLoadStaticFieldNode()->field().owner()); |
| 7951 } else if ((left_ident != NULL) && | 7997 } else if ((left_ident != NULL) && |
| 7952 (original->IsLiteralNode() || | 7998 (original->IsLiteralNode() || |
| 7953 original->IsLoadLocalNode())) { | 7999 original->IsLoadLocalNode())) { |
| 7954 name = left_ident->raw(); | 8000 name = left_ident->raw(); |
| 7955 } | 8001 } |
| 7956 if (name.IsNull()) { | 8002 if (name.IsNull()) { |
| 7957 ErrorMsg(left_pos, "expression is not assignable"); | 8003 ErrorMsg(left_pos, "expression is not assignable"); |
| 7958 } | 8004 } |
| 7959 result = ThrowNoSuchMethodError( | 8005 result = ThrowNoSuchMethodError( |
| 7960 original->token_pos(), | 8006 original->token_pos(), |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 7972 result->IsStoreLocalNode()) { | 8018 result->IsStoreLocalNode()) { |
| 7973 // Ensure that the expression temp is allocated for nodes that may need it. | 8019 // Ensure that the expression temp is allocated for nodes that may need it. |
| 7974 EnsureExpressionTemp(); | 8020 EnsureExpressionTemp(); |
| 7975 } | 8021 } |
| 7976 return result; | 8022 return result; |
| 7977 } | 8023 } |
| 7978 | 8024 |
| 7979 | 8025 |
| 7980 AstNode* Parser::ParseCascades(AstNode* expr) { | 8026 AstNode* Parser::ParseCascades(AstNode* expr) { |
| 7981 intptr_t cascade_pos = TokenPos(); | 8027 intptr_t cascade_pos = TokenPos(); |
| 7982 LetNode* cascade = new LetNode(cascade_pos); | 8028 LetNode* cascade = new(isolate()) LetNode(cascade_pos); |
| 7983 LocalVariable* cascade_receiver_var = cascade->AddInitializer(expr); | 8029 LocalVariable* cascade_receiver_var = cascade->AddInitializer(expr); |
| 7984 while (CurrentToken() == Token::kCASCADE) { | 8030 while (CurrentToken() == Token::kCASCADE) { |
| 7985 cascade_pos = TokenPos(); | 8031 cascade_pos = TokenPos(); |
| 7986 LoadLocalNode* load_cascade_receiver = | 8032 LoadLocalNode* load_cascade_receiver = |
| 7987 new LoadLocalNode(cascade_pos, cascade_receiver_var); | 8033 new(isolate()) LoadLocalNode(cascade_pos, cascade_receiver_var); |
| 7988 if (Token::IsIdentifier(LookaheadToken(1))) { | 8034 if (Token::IsIdentifier(LookaheadToken(1))) { |
| 7989 // Replace .. with . for ParseSelectors(). | 8035 // Replace .. with . for ParseSelectors(). |
| 7990 token_kind_ = Token::kPERIOD; | 8036 token_kind_ = Token::kPERIOD; |
| 7991 } else if (LookaheadToken(1) == Token::kLBRACK) { | 8037 } else if (LookaheadToken(1) == Token::kLBRACK) { |
| 7992 ConsumeToken(); | 8038 ConsumeToken(); |
| 7993 } else { | 8039 } else { |
| 7994 ErrorMsg("identifier or [ expected after .."); | 8040 ErrorMsg("identifier or [ expected after .."); |
| 7995 } | 8041 } |
| 7996 String* expr_ident = | 8042 String* expr_ident = |
| 7997 Token::IsIdentifier(CurrentToken()) ? CurrentLiteral() : NULL; | 8043 Token::IsIdentifier(CurrentToken()) ? CurrentLiteral() : NULL; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 8022 AstNode* assign_expr = | 8068 AstNode* assign_expr = |
| 8023 CreateAssignmentNode(expr, right_expr, expr_ident, expr_pos); | 8069 CreateAssignmentNode(expr, right_expr, expr_ident, expr_pos); |
| 8024 ASSERT(assign_expr != NULL); | 8070 ASSERT(assign_expr != NULL); |
| 8025 expr = assign_expr; | 8071 expr = assign_expr; |
| 8026 } | 8072 } |
| 8027 } | 8073 } |
| 8028 cascade->AddNode(expr); | 8074 cascade->AddNode(expr); |
| 8029 } | 8075 } |
| 8030 // The result is an expression with the (side effects of the) cascade | 8076 // The result is an expression with the (side effects of the) cascade |
| 8031 // sequence followed by the (value of the) receiver temp variable load. | 8077 // sequence followed by the (value of the) receiver temp variable load. |
| 8032 cascade->AddNode(new LoadLocalNode(cascade_pos, cascade_receiver_var)); | 8078 cascade->AddNode(new(isolate()) LoadLocalNode( |
| 8079 cascade_pos, cascade_receiver_var)); | |
| 8033 return cascade; | 8080 return cascade; |
| 8034 } | 8081 } |
| 8035 | 8082 |
| 8036 | 8083 |
| 8037 // Convert loading of a static const field into a literal node. | 8084 // Convert loading of a static const field into a literal node. |
| 8038 static AstNode* LiteralIfStaticConst(AstNode* expr) { | 8085 static AstNode* LiteralIfStaticConst(AstNode* expr) { |
| 8039 if (expr->IsLoadStaticFieldNode()) { | 8086 if (expr->IsLoadStaticFieldNode()) { |
| 8040 const Field& field = expr->AsLoadStaticFieldNode()->field(); | 8087 const Field& field = expr->AsLoadStaticFieldNode()->field(); |
| 8041 if (field.is_const()) { | 8088 if (field.is_const()) { |
| 8042 ASSERT(field.value() != Object::sentinel().raw()); | 8089 ASSERT(field.value() != Object::sentinel().raw()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 8055 String* expr_ident = | 8102 String* expr_ident = |
| 8056 Token::IsIdentifier(CurrentToken()) ? CurrentLiteral() : NULL; | 8103 Token::IsIdentifier(CurrentToken()) ? CurrentLiteral() : NULL; |
| 8057 const intptr_t expr_pos = TokenPos(); | 8104 const intptr_t expr_pos = TokenPos(); |
| 8058 | 8105 |
| 8059 if (CurrentToken() == Token::kTHROW) { | 8106 if (CurrentToken() == Token::kTHROW) { |
| 8060 ConsumeToken(); | 8107 ConsumeToken(); |
| 8061 if (CurrentToken() == Token::kSEMICOLON) { | 8108 if (CurrentToken() == Token::kSEMICOLON) { |
| 8062 ErrorMsg("expression expected after throw"); | 8109 ErrorMsg("expression expected after throw"); |
| 8063 } | 8110 } |
| 8064 AstNode* expr = ParseExpr(require_compiletime_const, consume_cascades); | 8111 AstNode* expr = ParseExpr(require_compiletime_const, consume_cascades); |
| 8065 return new ThrowNode(expr_pos, expr, NULL); | 8112 return new(isolate()) ThrowNode(expr_pos, expr, NULL); |
| 8066 } | 8113 } |
| 8067 AstNode* expr = ParseConditionalExpr(); | 8114 AstNode* expr = ParseConditionalExpr(); |
| 8068 if (!Token::IsAssignmentOperator(CurrentToken())) { | 8115 if (!Token::IsAssignmentOperator(CurrentToken())) { |
| 8069 if ((CurrentToken() == Token::kCASCADE) && consume_cascades) { | 8116 if ((CurrentToken() == Token::kCASCADE) && consume_cascades) { |
| 8070 return ParseCascades(expr); | 8117 return ParseCascades(expr); |
| 8071 } | 8118 } |
| 8072 if (require_compiletime_const) { | 8119 if (require_compiletime_const) { |
| 8073 expr = FoldConstExpr(expr_pos, expr); | 8120 expr = FoldConstExpr(expr_pos, expr); |
| 8074 } else { | 8121 } else { |
| 8075 expr = LiteralIfStaticConst(expr); | 8122 expr = LiteralIfStaticConst(expr); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8122 AstNode* Parser::ParseConditionalExpr() { | 8169 AstNode* Parser::ParseConditionalExpr() { |
| 8123 TRACE_PARSER("ParseConditionalExpr"); | 8170 TRACE_PARSER("ParseConditionalExpr"); |
| 8124 const intptr_t expr_pos = TokenPos(); | 8171 const intptr_t expr_pos = TokenPos(); |
| 8125 AstNode* expr = ParseBinaryExpr(Token::Precedence(Token::kOR)); | 8172 AstNode* expr = ParseBinaryExpr(Token::Precedence(Token::kOR)); |
| 8126 if (CurrentToken() == Token::kCONDITIONAL) { | 8173 if (CurrentToken() == Token::kCONDITIONAL) { |
| 8127 EnsureExpressionTemp(); | 8174 EnsureExpressionTemp(); |
| 8128 ConsumeToken(); | 8175 ConsumeToken(); |
| 8129 AstNode* expr1 = ParseExpr(kAllowConst, kNoCascades); | 8176 AstNode* expr1 = ParseExpr(kAllowConst, kNoCascades); |
| 8130 ExpectToken(Token::kCOLON); | 8177 ExpectToken(Token::kCOLON); |
| 8131 AstNode* expr2 = ParseExpr(kAllowConst, kNoCascades); | 8178 AstNode* expr2 = ParseExpr(kAllowConst, kNoCascades); |
| 8132 expr = new ConditionalExprNode(expr_pos, expr, expr1, expr2); | 8179 expr = new(isolate()) ConditionalExprNode(expr_pos, expr, expr1, expr2); |
| 8133 } | 8180 } |
| 8134 return expr; | 8181 return expr; |
| 8135 } | 8182 } |
| 8136 | 8183 |
| 8137 | 8184 |
| 8138 AstNode* Parser::ParseUnaryExpr() { | 8185 AstNode* Parser::ParseUnaryExpr() { |
| 8139 TRACE_PARSER("ParseUnaryExpr"); | 8186 TRACE_PARSER("ParseUnaryExpr"); |
| 8140 AstNode* expr = NULL; | 8187 AstNode* expr = NULL; |
| 8141 const intptr_t op_pos = TokenPos(); | 8188 const intptr_t op_pos = TokenPos(); |
| 8142 if (IsPrefixOperator(CurrentToken())) { | 8189 if (IsPrefixOperator(CurrentToken())) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 8158 Token::IsIdentifier(CurrentToken()) ? CurrentLiteral() : NULL; | 8205 Token::IsIdentifier(CurrentToken()) ? CurrentLiteral() : NULL; |
| 8159 const intptr_t expr_pos = TokenPos(); | 8206 const intptr_t expr_pos = TokenPos(); |
| 8160 expr = ParseUnaryExpr(); | 8207 expr = ParseUnaryExpr(); |
| 8161 if (!IsLegalAssignableSyntax(expr, TokenPos())) { | 8208 if (!IsLegalAssignableSyntax(expr, TokenPos())) { |
| 8162 ErrorMsg(expr_pos, "expression is not assignable"); | 8209 ErrorMsg(expr_pos, "expression is not assignable"); |
| 8163 } | 8210 } |
| 8164 // Is prefix. | 8211 // Is prefix. |
| 8165 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr); | 8212 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr); |
| 8166 Token::Kind binary_op = | 8213 Token::Kind binary_op = |
| 8167 (incr_op == Token::kINCR) ? Token::kADD : Token::kSUB; | 8214 (incr_op == Token::kINCR) ? Token::kADD : Token::kSUB; |
| 8168 BinaryOpNode* add = new BinaryOpNode( | 8215 BinaryOpNode* add = new(isolate()) BinaryOpNode( |
| 8169 op_pos, | 8216 op_pos, |
| 8170 binary_op, | 8217 binary_op, |
| 8171 expr, | 8218 expr, |
| 8172 new LiteralNode(op_pos, Smi::ZoneHandle(Smi::New(1)))); | 8219 new(isolate()) LiteralNode(op_pos, Smi::ZoneHandle(Smi::New(1)))); |
| 8173 AstNode* store = CreateAssignmentNode(expr, add, expr_ident, expr_pos); | 8220 AstNode* store = CreateAssignmentNode(expr, add, expr_ident, expr_pos); |
| 8174 ASSERT(store != NULL); | 8221 ASSERT(store != NULL); |
| 8175 let_expr->AddNode(store); | 8222 let_expr->AddNode(store); |
| 8176 expr = let_expr; | 8223 expr = let_expr; |
| 8177 } else { | 8224 } else { |
| 8178 expr = ParsePostfixExpr(); | 8225 expr = ParsePostfixExpr(); |
| 8179 } | 8226 } |
| 8180 return expr; | 8227 return expr; |
| 8181 } | 8228 } |
| 8182 | 8229 |
| 8183 | 8230 |
| 8184 ArgumentListNode* Parser::ParseActualParameters( | 8231 ArgumentListNode* Parser::ParseActualParameters( |
| 8185 ArgumentListNode* implicit_arguments, | 8232 ArgumentListNode* implicit_arguments, |
| 8186 bool require_const) { | 8233 bool require_const) { |
| 8187 TRACE_PARSER("ParseActualParameters"); | 8234 TRACE_PARSER("ParseActualParameters"); |
| 8188 ASSERT(CurrentToken() == Token::kLPAREN); | 8235 ASSERT(CurrentToken() == Token::kLPAREN); |
| 8189 const bool saved_mode = SetAllowFunctionLiterals(true); | 8236 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 8190 ArgumentListNode* arguments; | 8237 ArgumentListNode* arguments; |
| 8191 if (implicit_arguments == NULL) { | 8238 if (implicit_arguments == NULL) { |
| 8192 arguments = new ArgumentListNode(TokenPos()); | 8239 arguments = new(isolate()) ArgumentListNode(TokenPos()); |
| 8193 } else { | 8240 } else { |
| 8194 arguments = implicit_arguments; | 8241 arguments = implicit_arguments; |
| 8195 } | 8242 } |
| 8196 const GrowableObjectArray& names = | 8243 const GrowableObjectArray& names = GrowableObjectArray::Handle(isolate(), |
| 8197 GrowableObjectArray::Handle(GrowableObjectArray::New(Heap::kOld)); | 8244 GrowableObjectArray::New(Heap::kOld)); |
| 8198 bool named_argument_seen = false; | 8245 bool named_argument_seen = false; |
| 8199 if (LookaheadToken(1) != Token::kRPAREN) { | 8246 if (LookaheadToken(1) != Token::kRPAREN) { |
| 8200 String& arg_name = String::Handle(); | 8247 String& arg_name = String::Handle(isolate()); |
| 8201 do { | 8248 do { |
| 8202 ASSERT((CurrentToken() == Token::kLPAREN) || | 8249 ASSERT((CurrentToken() == Token::kLPAREN) || |
| 8203 (CurrentToken() == Token::kCOMMA)); | 8250 (CurrentToken() == Token::kCOMMA)); |
| 8204 ConsumeToken(); | 8251 ConsumeToken(); |
| 8205 if (IsIdentifier() && (LookaheadToken(1) == Token::kCOLON)) { | 8252 if (IsIdentifier() && (LookaheadToken(1) == Token::kCOLON)) { |
| 8206 named_argument_seen = true; | 8253 named_argument_seen = true; |
| 8207 // The canonicalization of the arguments descriptor array built in | 8254 // The canonicalization of the arguments descriptor array built in |
| 8208 // the code generator requires that the names are symbols, i.e. | 8255 // the code generator requires that the names are symbols, i.e. |
| 8209 // canonicalized strings. | 8256 // canonicalized strings. |
| 8210 ASSERT(CurrentLiteral()->IsSymbol()); | 8257 ASSERT(CurrentLiteral()->IsSymbol()); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 8221 ErrorMsg("named argument expected"); | 8268 ErrorMsg("named argument expected"); |
| 8222 } | 8269 } |
| 8223 arguments->Add(ParseExpr(require_const, kConsumeCascades)); | 8270 arguments->Add(ParseExpr(require_const, kConsumeCascades)); |
| 8224 } while (CurrentToken() == Token::kCOMMA); | 8271 } while (CurrentToken() == Token::kCOMMA); |
| 8225 } else { | 8272 } else { |
| 8226 ConsumeToken(); | 8273 ConsumeToken(); |
| 8227 } | 8274 } |
| 8228 ExpectToken(Token::kRPAREN); | 8275 ExpectToken(Token::kRPAREN); |
| 8229 SetAllowFunctionLiterals(saved_mode); | 8276 SetAllowFunctionLiterals(saved_mode); |
| 8230 if (named_argument_seen) { | 8277 if (named_argument_seen) { |
| 8231 arguments->set_names(Array::Handle(Array::MakeArray(names))); | 8278 arguments->set_names(Array::Handle(isolate(), Array::MakeArray(names))); |
| 8232 } | 8279 } |
| 8233 return arguments; | 8280 return arguments; |
| 8234 } | 8281 } |
| 8235 | 8282 |
| 8236 | 8283 |
| 8237 AstNode* Parser::ParseStaticCall(const Class& cls, | 8284 AstNode* Parser::ParseStaticCall(const Class& cls, |
| 8238 const String& func_name, | 8285 const String& func_name, |
| 8239 intptr_t ident_pos) { | 8286 intptr_t ident_pos) { |
| 8240 TRACE_PARSER("ParseStaticCall"); | 8287 TRACE_PARSER("ParseStaticCall"); |
| 8241 const intptr_t call_pos = TokenPos(); | 8288 const intptr_t call_pos = TokenPos(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 8257 // No field, check if we have an explicit getter function. | 8304 // No field, check if we have an explicit getter function. |
| 8258 const String& getter_name = | 8305 const String& getter_name = |
| 8259 String::ZoneHandle(Field::GetterName(func_name)); | 8306 String::ZoneHandle(Field::GetterName(func_name)); |
| 8260 const int kNumArguments = 0; // no arguments. | 8307 const int kNumArguments = 0; // no arguments. |
| 8261 func = Resolver::ResolveStatic(cls, | 8308 func = Resolver::ResolveStatic(cls, |
| 8262 getter_name, | 8309 getter_name, |
| 8263 kNumArguments, | 8310 kNumArguments, |
| 8264 Object::empty_array()); | 8311 Object::empty_array()); |
| 8265 if (!func.IsNull()) { | 8312 if (!func.IsNull()) { |
| 8266 ASSERT(func.kind() != RawFunction::kImplicitStaticFinalGetter); | 8313 ASSERT(func.kind() != RawFunction::kImplicitStaticFinalGetter); |
| 8267 closure = new StaticGetterNode(call_pos, | 8314 closure = new(isolate()) StaticGetterNode(call_pos, |
| 8268 NULL, | 8315 NULL, |
| 8269 false, | 8316 false, |
| 8270 Class::ZoneHandle(cls.raw()), | 8317 Class::ZoneHandle(cls.raw()), |
| 8271 func_name); | 8318 func_name); |
| 8272 return BuildClosureCall(call_pos, closure, arguments); | 8319 return BuildClosureCall(call_pos, closure, arguments); |
| 8273 } | 8320 } |
| 8274 } else { | 8321 } else { |
| 8275 closure = GenerateStaticFieldLookup(field, call_pos); | 8322 closure = GenerateStaticFieldLookup(field, call_pos); |
| 8276 return BuildClosureCall(call_pos, closure, arguments); | 8323 return BuildClosureCall(call_pos, closure, arguments); |
| 8277 } | 8324 } |
| 8278 // Could not resolve static method: throw a NoSuchMethodError. | 8325 // Could not resolve static method: throw a NoSuchMethodError. |
| 8279 return ThrowNoSuchMethodError(ident_pos, | 8326 return ThrowNoSuchMethodError(ident_pos, |
| 8280 cls, | 8327 cls, |
| 8281 func_name, | 8328 func_name, |
| 8282 arguments, | 8329 arguments, |
| 8283 InvocationMirror::kStatic, | 8330 InvocationMirror::kStatic, |
| 8284 InvocationMirror::kMethod, | 8331 InvocationMirror::kMethod, |
| 8285 NULL); // No existing function. | 8332 NULL); // No existing function. |
| 8286 } else if (cls.IsTopLevel() && | 8333 } else if (cls.IsTopLevel() && |
| 8287 (cls.library() == Library::CoreLibrary()) && | 8334 (cls.library() == Library::CoreLibrary()) && |
| 8288 (func.name() == Symbols::Identical().raw())) { | 8335 (func.name() == Symbols::Identical().raw())) { |
| 8289 // This is the predefined toplevel function identical(a,b). Create | 8336 // This is the predefined toplevel function identical(a,b). Create |
| 8290 // a comparison node instead. | 8337 // a comparison node instead. |
| 8291 ASSERT(num_arguments == 2); | 8338 ASSERT(num_arguments == 2); |
| 8292 return new ComparisonNode(ident_pos, | 8339 return new(isolate()) ComparisonNode(ident_pos, |
| 8293 Token::kEQ_STRICT, | 8340 Token::kEQ_STRICT, |
| 8294 arguments->NodeAt(0), | 8341 arguments->NodeAt(0), |
| 8295 arguments->NodeAt(1)); | 8342 arguments->NodeAt(1)); |
| 8296 } | 8343 } |
| 8297 return new StaticCallNode(call_pos, func, arguments); | 8344 return new(isolate()) StaticCallNode(call_pos, func, arguments); |
| 8298 } | 8345 } |
| 8299 | 8346 |
| 8300 | 8347 |
| 8301 AstNode* Parser::ParseInstanceCall(AstNode* receiver, const String& func_name) { | 8348 AstNode* Parser::ParseInstanceCall(AstNode* receiver, const String& func_name) { |
| 8302 TRACE_PARSER("ParseInstanceCall"); | 8349 TRACE_PARSER("ParseInstanceCall"); |
| 8303 const intptr_t call_pos = TokenPos(); | 8350 const intptr_t call_pos = TokenPos(); |
| 8304 CheckToken(Token::kLPAREN); | 8351 CheckToken(Token::kLPAREN); |
| 8305 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); | 8352 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); |
| 8306 return new InstanceCallNode(call_pos, receiver, func_name, arguments); | 8353 return new(isolate()) InstanceCallNode( |
| 8354 call_pos, receiver, func_name, arguments); | |
| 8307 } | 8355 } |
| 8308 | 8356 |
| 8309 | 8357 |
| 8310 AstNode* Parser::ParseClosureCall(AstNode* closure) { | 8358 AstNode* Parser::ParseClosureCall(AstNode* closure) { |
| 8311 TRACE_PARSER("ParseClosureCall"); | 8359 TRACE_PARSER("ParseClosureCall"); |
| 8312 const intptr_t call_pos = TokenPos(); | 8360 const intptr_t call_pos = TokenPos(); |
| 8313 ASSERT(CurrentToken() == Token::kLPAREN); | 8361 ASSERT(CurrentToken() == Token::kLPAREN); |
| 8314 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); | 8362 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); |
| 8315 return BuildClosureCall(call_pos, closure, arguments); | 8363 return BuildClosureCall(call_pos, closure, arguments); |
| 8316 } | 8364 } |
| 8317 | 8365 |
| 8318 | 8366 |
| 8319 AstNode* Parser::GenerateStaticFieldLookup(const Field& field, | 8367 AstNode* Parser::GenerateStaticFieldLookup(const Field& field, |
| 8320 intptr_t ident_pos) { | 8368 intptr_t ident_pos) { |
| 8321 // If the static field has an initializer, initialize the field at compile | 8369 // If the static field has an initializer, initialize the field at compile |
| 8322 // time, which is only possible if the field is const. | 8370 // time, which is only possible if the field is const. |
| 8323 AstNode* initializing_getter = RunStaticFieldInitializer(field, ident_pos); | 8371 AstNode* initializing_getter = RunStaticFieldInitializer(field, ident_pos); |
| 8324 if (initializing_getter != NULL) { | 8372 if (initializing_getter != NULL) { |
| 8325 // The field is not yet initialized and could not be initialized at compile | 8373 // The field is not yet initialized and could not be initialized at compile |
| 8326 // time. The getter will initialize the field. | 8374 // time. The getter will initialize the field. |
| 8327 return initializing_getter; | 8375 return initializing_getter; |
| 8328 } | 8376 } |
| 8329 // The field is initialized. | 8377 // The field is initialized. |
| 8330 ASSERT(field.is_static()); | 8378 ASSERT(field.is_static()); |
| 8331 const Class& field_owner = Class::ZoneHandle(field.owner()); | 8379 const Class& field_owner = Class::ZoneHandle(field.owner()); |
| 8332 const String& field_name = String::ZoneHandle(field.name()); | 8380 const String& field_name = String::ZoneHandle(field.name()); |
| 8333 const String& getter_name = String::Handle(Field::GetterName(field_name)); | 8381 const String& getter_name = String::Handle(isolate(), |
| 8334 const Function& getter = | 8382 Field::GetterName(field_name)); |
| 8335 Function::Handle(field_owner.LookupStaticFunction(getter_name)); | 8383 const Function& getter = Function::Handle(isolate(), |
| 8384 field_owner.LookupStaticFunction(getter_name)); | |
| 8336 // Never load field directly if there is a getter (deterministic AST). | 8385 // Never load field directly if there is a getter (deterministic AST). |
| 8337 if (getter.IsNull() || field.is_const()) { | 8386 if (getter.IsNull() || field.is_const()) { |
| 8338 return new LoadStaticFieldNode(ident_pos, Field::ZoneHandle(field.raw())); | 8387 return new(isolate()) LoadStaticFieldNode( |
| 8388 ident_pos, Field::ZoneHandle(field.raw())); | |
| 8339 } else { | 8389 } else { |
| 8340 ASSERT(getter.kind() == RawFunction::kImplicitStaticFinalGetter); | 8390 ASSERT(getter.kind() == RawFunction::kImplicitStaticFinalGetter); |
| 8341 return new StaticGetterNode(ident_pos, | 8391 return new(isolate()) StaticGetterNode(ident_pos, |
| 8342 NULL, // Receiver. | 8392 NULL, // Receiver. |
| 8343 false, // is_super_getter. | 8393 false, // is_super_getter. |
| 8344 field_owner, | 8394 field_owner, |
| 8345 field_name); | 8395 field_name); |
| 8346 } | 8396 } |
| 8347 } | 8397 } |
| 8348 | 8398 |
| 8349 | 8399 |
| 8350 AstNode* Parser::ParseStaticFieldAccess(const Class& cls, | 8400 AstNode* Parser::ParseStaticFieldAccess(const Class& cls, |
| 8351 const String& field_name, | 8401 const String& field_name, |
| 8352 intptr_t ident_pos, | 8402 intptr_t ident_pos, |
| 8353 bool consume_cascades) { | 8403 bool consume_cascades) { |
| 8354 TRACE_PARSER("ParseStaticFieldAccess"); | 8404 TRACE_PARSER("ParseStaticFieldAccess"); |
| 8355 AstNode* access = NULL; | 8405 AstNode* access = NULL; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 8369 // there is a function of the same name. | 8419 // there is a function of the same name. |
| 8370 func = cls.LookupStaticFunction(field_name); | 8420 func = cls.LookupStaticFunction(field_name); |
| 8371 if (!func.IsNull()) { | 8421 if (!func.IsNull()) { |
| 8372 access = CreateImplicitClosureNode(func, ident_pos, NULL); | 8422 access = CreateImplicitClosureNode(func, ident_pos, NULL); |
| 8373 } else { | 8423 } else { |
| 8374 // No function to closurize found found. | 8424 // No function to closurize found found. |
| 8375 // This field access may turn out to be a call to the setter. | 8425 // This field access may turn out to be a call to the setter. |
| 8376 // Create a getter call, which may later be turned into | 8426 // Create a getter call, which may later be turned into |
| 8377 // a setter call, or else the backend will generate | 8427 // a setter call, or else the backend will generate |
| 8378 // a throw NoSuchMethodError(). | 8428 // a throw NoSuchMethodError(). |
| 8379 access = new StaticGetterNode(ident_pos, | 8429 access = new(isolate()) StaticGetterNode( |
| 8380 NULL, | 8430 ident_pos, NULL, false, Class::ZoneHandle(cls.raw()), field_name); |
| 8381 false, | |
| 8382 Class::ZoneHandle(cls.raw()), | |
| 8383 field_name); | |
| 8384 } | 8431 } |
| 8385 } else { | 8432 } else { |
| 8386 ASSERT(func.kind() != RawFunction::kImplicitStaticFinalGetter); | 8433 ASSERT(func.kind() != RawFunction::kImplicitStaticFinalGetter); |
| 8387 access = new StaticGetterNode(ident_pos, | 8434 access = new(isolate()) StaticGetterNode( |
| 8388 NULL, | 8435 ident_pos, NULL, false, Class::ZoneHandle(cls.raw()), field_name); |
| 8389 false, | |
| 8390 Class::ZoneHandle(cls.raw()), | |
| 8391 field_name); | |
| 8392 } | 8436 } |
| 8393 } else { | 8437 } else { |
| 8394 access = GenerateStaticFieldLookup(field, ident_pos); | 8438 access = GenerateStaticFieldLookup(field, ident_pos); |
| 8395 } | 8439 } |
| 8396 return access; | 8440 return access; |
| 8397 } | 8441 } |
| 8398 | 8442 |
| 8399 | 8443 |
| 8400 AstNode* Parser::LoadFieldIfUnresolved(AstNode* node) { | 8444 AstNode* Parser::LoadFieldIfUnresolved(AstNode* node) { |
| 8401 if (!node->IsPrimaryNode()) { | 8445 if (!node->IsPrimaryNode()) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 8413 // In metadata, an unresolved identifier cannot be a compile-time constant. | 8457 // In metadata, an unresolved identifier cannot be a compile-time constant. |
| 8414 String& name = String::CheckedZoneHandle(primary->primary().raw()); | 8458 String& name = String::CheckedZoneHandle(primary->primary().raw()); |
| 8415 if (parsing_metadata_) { | 8459 if (parsing_metadata_) { |
| 8416 ErrorMsg(primary->token_pos(), | 8460 ErrorMsg(primary->token_pos(), |
| 8417 "unresolved identifier '%s' is not a compile-time constant", | 8461 "unresolved identifier '%s' is not a compile-time constant", |
| 8418 name.ToCString()); | 8462 name.ToCString()); |
| 8419 } | 8463 } |
| 8420 if (current_function().is_static() || | 8464 if (current_function().is_static() || |
| 8421 current_function().IsInFactoryScope()) { | 8465 current_function().IsInFactoryScope()) { |
| 8422 StaticGetterNode* getter = | 8466 StaticGetterNode* getter = |
| 8423 new StaticGetterNode(primary->token_pos(), | 8467 new(isolate()) StaticGetterNode( |
| 8424 NULL, // No receiver. | 8468 primary->token_pos(), |
| 8425 false, // Not a super getter. | 8469 NULL, // No receiver. |
| 8426 Class::ZoneHandle(current_class().raw()), | 8470 false, // Not a super getter. |
| 8427 name); | 8471 Class::ZoneHandle(current_class().raw()), |
| 8472 name); | |
| 8428 getter->set_is_deferred(primary->is_deferred_reference()); | 8473 getter->set_is_deferred(primary->is_deferred_reference()); |
| 8429 return getter; | 8474 return getter; |
| 8430 } else { | 8475 } else { |
| 8431 AstNode* receiver = LoadReceiver(primary->token_pos()); | 8476 AstNode* receiver = LoadReceiver(primary->token_pos()); |
| 8432 return CallGetter(node->token_pos(), receiver, name); | 8477 return CallGetter(node->token_pos(), receiver, name); |
| 8433 } | 8478 } |
| 8434 } | 8479 } |
| 8435 return primary; | 8480 return primary; |
| 8436 } | 8481 } |
| 8437 | 8482 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8490 if (current_block_->scope->function_level() > 0) { | 8535 if (current_block_->scope->function_level() > 0) { |
| 8491 // Make sure that the instantiator is captured. | 8536 // Make sure that the instantiator is captured. |
| 8492 CaptureInstantiator(); | 8537 CaptureInstantiator(); |
| 8493 } | 8538 } |
| 8494 TypeParameter& type_parameter = TypeParameter::ZoneHandle(); | 8539 TypeParameter& type_parameter = TypeParameter::ZoneHandle(); |
| 8495 type_parameter ^= ClassFinalizer::FinalizeType( | 8540 type_parameter ^= ClassFinalizer::FinalizeType( |
| 8496 current_class(), | 8541 current_class(), |
| 8497 TypeParameter::Cast(primary_node->primary()), | 8542 TypeParameter::Cast(primary_node->primary()), |
| 8498 ClassFinalizer::kCanonicalize); | 8543 ClassFinalizer::kCanonicalize); |
| 8499 ASSERT(!type_parameter.IsMalformed()); | 8544 ASSERT(!type_parameter.IsMalformed()); |
| 8500 left = new TypeNode(primary->token_pos(), type_parameter); | 8545 left = new(isolate()) TypeNode(primary->token_pos(), type_parameter); |
| 8501 } else { | 8546 } else { |
| 8502 // Super field access handled in ParseSuperFieldAccess(), | 8547 // Super field access handled in ParseSuperFieldAccess(), |
| 8503 // super calls handled in ParseSuperCall(). | 8548 // super calls handled in ParseSuperCall(). |
| 8504 ASSERT(!primary_node->IsSuper()); | 8549 ASSERT(!primary_node->IsSuper()); |
| 8505 left = LoadFieldIfUnresolved(left); | 8550 left = LoadFieldIfUnresolved(left); |
| 8506 } | 8551 } |
| 8507 } | 8552 } |
| 8508 const intptr_t ident_pos = TokenPos(); | 8553 const intptr_t ident_pos = TokenPos(); |
| 8509 String* ident = ExpectIdentifier("identifier expected"); | 8554 String* ident = ExpectIdentifier("identifier expected"); |
| 8510 if (CurrentToken() == Token::kLPAREN) { | 8555 if (CurrentToken() == Token::kLPAREN) { |
| 8511 // Identifier followed by a opening paren: method call. | 8556 // Identifier followed by a opening paren: method call. |
| 8512 if (left->IsPrimaryNode() && | 8557 if (left->IsPrimaryNode() && |
| 8513 left->AsPrimaryNode()->primary().IsClass()) { | 8558 left->AsPrimaryNode()->primary().IsClass()) { |
| 8514 // Static method call prefixed with class name. | 8559 // Static method call prefixed with class name. |
| 8515 const Class& cls = Class::Cast(left->AsPrimaryNode()->primary()); | 8560 const Class& cls = Class::Cast(left->AsPrimaryNode()->primary()); |
| 8516 selector = ParseStaticCall(cls, *ident, ident_pos); | 8561 selector = ParseStaticCall(cls, *ident, ident_pos); |
| 8517 } else { | 8562 } else { |
| 8518 selector = ParseInstanceCall(left, *ident); | 8563 selector = ParseInstanceCall(left, *ident); |
| 8519 } | 8564 } |
| 8520 } else { | 8565 } else { |
| 8521 // Field access. | 8566 // Field access. |
| 8522 Class& cls = Class::Handle(); | 8567 Class& cls = Class::Handle(isolate()); |
| 8523 if (left->IsPrimaryNode()) { | 8568 if (left->IsPrimaryNode()) { |
| 8524 PrimaryNode* primary_node = left->AsPrimaryNode(); | 8569 PrimaryNode* primary_node = left->AsPrimaryNode(); |
| 8525 if (primary_node->primary().IsClass()) { | 8570 if (primary_node->primary().IsClass()) { |
| 8526 // If the primary node referred to a class we are loading a | 8571 // If the primary node referred to a class we are loading a |
| 8527 // qualified static field. | 8572 // qualified static field. |
| 8528 cls ^= primary_node->primary().raw(); | 8573 cls ^= primary_node->primary().raw(); |
| 8529 } | 8574 } |
| 8530 } | 8575 } |
| 8531 if (cls.IsNull()) { | 8576 if (cls.IsNull()) { |
| 8532 // Instance field access. | 8577 // Instance field access. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 8550 ExpectToken(Token::kRBRACK); | 8595 ExpectToken(Token::kRBRACK); |
| 8551 AstNode* array = left; | 8596 AstNode* array = left; |
| 8552 if (left->IsPrimaryNode()) { | 8597 if (left->IsPrimaryNode()) { |
| 8553 PrimaryNode* primary_node = left->AsPrimaryNode(); | 8598 PrimaryNode* primary_node = left->AsPrimaryNode(); |
| 8554 const intptr_t primary_pos = primary_node->token_pos(); | 8599 const intptr_t primary_pos = primary_node->token_pos(); |
| 8555 if (primary_node->primary().IsFunction()) { | 8600 if (primary_node->primary().IsFunction()) { |
| 8556 array = LoadClosure(primary_node); | 8601 array = LoadClosure(primary_node); |
| 8557 } else if (primary_node->primary().IsClass()) { | 8602 } else if (primary_node->primary().IsClass()) { |
| 8558 const Class& type_class = Class::Cast(primary_node->primary()); | 8603 const Class& type_class = Class::Cast(primary_node->primary()); |
| 8559 AbstractType& type = Type::ZoneHandle( | 8604 AbstractType& type = Type::ZoneHandle( |
| 8560 Type::New(type_class, TypeArguments::Handle(), | 8605 Type::New(type_class, TypeArguments::Handle(isolate()), |
| 8561 primary_pos, Heap::kOld)); | 8606 primary_pos, Heap::kOld)); |
| 8562 type ^= ClassFinalizer::FinalizeType( | 8607 type ^= ClassFinalizer::FinalizeType( |
| 8563 current_class(), type, ClassFinalizer::kCanonicalize); | 8608 current_class(), type, ClassFinalizer::kCanonicalize); |
| 8564 // Type may be malbounded, but not malformed. | 8609 // Type may be malbounded, but not malformed. |
| 8565 ASSERT(!type.IsMalformed()); | 8610 ASSERT(!type.IsMalformed()); |
| 8566 array = new TypeNode(primary_pos, type); | 8611 array = new(isolate()) TypeNode(primary_pos, type); |
| 8567 } else if (primary_node->primary().IsTypeParameter()) { | 8612 } else if (primary_node->primary().IsTypeParameter()) { |
| 8568 if (current_function().is_static()) { | 8613 if (current_function().is_static()) { |
| 8569 const String& name = String::ZoneHandle( | 8614 const String& name = String::ZoneHandle( |
| 8570 TypeParameter::Cast(primary_node->primary()).name()); | 8615 TypeParameter::Cast(primary_node->primary()).name()); |
| 8571 ErrorMsg(primary_pos, | 8616 ErrorMsg(primary_pos, |
| 8572 "cannot access type parameter '%s' from static function", | 8617 "cannot access type parameter '%s' from static function", |
| 8573 name.ToCString()); | 8618 name.ToCString()); |
| 8574 } | 8619 } |
| 8575 if (current_block_->scope->function_level() > 0) { | 8620 if (current_block_->scope->function_level() > 0) { |
| 8576 // Make sure that the instantiator is captured. | 8621 // Make sure that the instantiator is captured. |
| 8577 CaptureInstantiator(); | 8622 CaptureInstantiator(); |
| 8578 } | 8623 } |
| 8579 TypeParameter& type_parameter = TypeParameter::ZoneHandle(); | 8624 TypeParameter& type_parameter = TypeParameter::ZoneHandle(); |
| 8580 type_parameter ^= ClassFinalizer::FinalizeType( | 8625 type_parameter ^= ClassFinalizer::FinalizeType( |
| 8581 current_class(), | 8626 current_class(), |
| 8582 TypeParameter::Cast(primary_node->primary()), | 8627 TypeParameter::Cast(primary_node->primary()), |
| 8583 ClassFinalizer::kCanonicalize); | 8628 ClassFinalizer::kCanonicalize); |
| 8584 ASSERT(!type_parameter.IsMalformed()); | 8629 ASSERT(!type_parameter.IsMalformed()); |
| 8585 array = new TypeNode(primary_pos, type_parameter); | 8630 array = new(isolate()) TypeNode(primary_pos, type_parameter); |
| 8586 } else { | 8631 } else { |
| 8587 UNREACHABLE(); // Internal parser error. | 8632 UNREACHABLE(); // Internal parser error. |
| 8588 } | 8633 } |
| 8589 } | 8634 } |
| 8590 selector = new LoadIndexedNode(bracket_pos, | 8635 selector = new(isolate()) LoadIndexedNode( |
| 8591 array, | 8636 bracket_pos, array, index, Class::ZoneHandle()); |
| 8592 index, | |
| 8593 Class::ZoneHandle()); | |
| 8594 } else if (CurrentToken() == Token::kLPAREN) { | 8637 } else if (CurrentToken() == Token::kLPAREN) { |
| 8595 if (left->IsPrimaryNode()) { | 8638 if (left->IsPrimaryNode()) { |
| 8596 PrimaryNode* primary_node = left->AsPrimaryNode(); | 8639 PrimaryNode* primary_node = left->AsPrimaryNode(); |
| 8597 const intptr_t primary_pos = primary_node->token_pos(); | 8640 const intptr_t primary_pos = primary_node->token_pos(); |
| 8598 if (primary_node->primary().IsFunction()) { | 8641 if (primary_node->primary().IsFunction()) { |
| 8599 const Function& func = Function::Cast(primary_node->primary()); | 8642 const Function& func = Function::Cast(primary_node->primary()); |
| 8600 const String& func_name = String::ZoneHandle(func.name()); | 8643 const String& func_name = String::ZoneHandle(func.name()); |
| 8601 if (func.is_static()) { | 8644 if (func.is_static()) { |
| 8602 // Parse static function call. | 8645 // Parse static function call. |
| 8603 Class& cls = Class::Handle(func.Owner()); | 8646 Class& cls = Class::Handle(isolate(), func.Owner()); |
| 8604 selector = ParseStaticCall(cls, func_name, primary_pos); | 8647 selector = ParseStaticCall(cls, func_name, primary_pos); |
| 8605 } else { | 8648 } else { |
| 8606 // Dynamic function call on implicit "this" parameter. | 8649 // Dynamic function call on implicit "this" parameter. |
| 8607 if (current_function().is_static()) { | 8650 if (current_function().is_static()) { |
| 8608 ErrorMsg(primary_pos, | 8651 ErrorMsg(primary_pos, |
| 8609 "cannot access instance method '%s' " | 8652 "cannot access instance method '%s' " |
| 8610 "from static function", | 8653 "from static function", |
| 8611 func_name.ToCString()); | 8654 func_name.ToCString()); |
| 8612 } | 8655 } |
| 8613 selector = ParseInstanceCall(LoadReceiver(primary_pos), func_name); | 8656 selector = ParseInstanceCall(LoadReceiver(primary_pos), func_name); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 8639 ErrorMsg(primary_pos, | 8682 ErrorMsg(primary_pos, |
| 8640 "cannot access type parameter '%s' from static function", | 8683 "cannot access type parameter '%s' from static function", |
| 8641 name.ToCString()); | 8684 name.ToCString()); |
| 8642 } else { | 8685 } else { |
| 8643 // Treat as call to unresolved (instance) method. | 8686 // Treat as call to unresolved (instance) method. |
| 8644 selector = ParseInstanceCall(LoadReceiver(primary_pos), name); | 8687 selector = ParseInstanceCall(LoadReceiver(primary_pos), name); |
| 8645 } | 8688 } |
| 8646 } else if (primary_node->primary().IsClass()) { | 8689 } else if (primary_node->primary().IsClass()) { |
| 8647 const Class& type_class = Class::Cast(primary_node->primary()); | 8690 const Class& type_class = Class::Cast(primary_node->primary()); |
| 8648 AbstractType& type = Type::ZoneHandle(Type::New( | 8691 AbstractType& type = Type::ZoneHandle(Type::New( |
| 8649 type_class, TypeArguments::Handle(), primary_pos)); | 8692 type_class, TypeArguments::Handle(isolate()), primary_pos)); |
| 8650 type ^= ClassFinalizer::FinalizeType( | 8693 type ^= ClassFinalizer::FinalizeType( |
| 8651 current_class(), type, ClassFinalizer::kCanonicalize); | 8694 current_class(), type, ClassFinalizer::kCanonicalize); |
| 8652 // Type may be malbounded, but not malformed. | 8695 // Type may be malbounded, but not malformed. |
| 8653 ASSERT(!type.IsMalformed()); | 8696 ASSERT(!type.IsMalformed()); |
| 8654 selector = new TypeNode(primary_pos, type); | 8697 selector = new(isolate()) TypeNode(primary_pos, type); |
| 8655 } else { | 8698 } else { |
| 8656 UNREACHABLE(); // Internal parser error. | 8699 UNREACHABLE(); // Internal parser error. |
| 8657 } | 8700 } |
| 8658 } else { | 8701 } else { |
| 8659 // Left is not a primary node; this must be a closure call. | 8702 // Left is not a primary node; this must be a closure call. |
| 8660 AstNode* closure = left; | 8703 AstNode* closure = left; |
| 8661 if (parsing_metadata_) { | 8704 if (parsing_metadata_) { |
| 8662 // Compiling closure calls involves saving the current context based | 8705 // Compiling closure calls involves saving the current context based |
| 8663 // on the current function, and metadata has no current function. | 8706 // on the current function, and metadata has no current function. |
| 8664 // Fail early rather than limping along only to discover later that | 8707 // Fail early rather than limping along only to discover later that |
| 8665 // we parsed something that isn't a compile-time constant. | 8708 // we parsed something that isn't a compile-time constant. |
| 8666 ErrorMsg(closure->token_pos(), | 8709 ErrorMsg(closure->token_pos(), |
| 8667 "expression is not a valid compile-time constant"); | 8710 "expression is not a valid compile-time constant"); |
| 8668 } | 8711 } |
| 8669 selector = ParseClosureCall(closure); | 8712 selector = ParseClosureCall(closure); |
| 8670 } | 8713 } |
| 8671 } else { | 8714 } else { |
| 8672 // No (more) selectors to parse. | 8715 // No (more) selectors to parse. |
| 8673 left = LoadFieldIfUnresolved(left); | 8716 left = LoadFieldIfUnresolved(left); |
| 8674 if (left->IsPrimaryNode()) { | 8717 if (left->IsPrimaryNode()) { |
| 8675 PrimaryNode* primary_node = left->AsPrimaryNode(); | 8718 PrimaryNode* primary_node = left->AsPrimaryNode(); |
| 8676 const intptr_t primary_pos = primary->token_pos(); | 8719 const intptr_t primary_pos = primary->token_pos(); |
| 8677 if (primary_node->primary().IsFunction()) { | 8720 if (primary_node->primary().IsFunction()) { |
| 8678 // Treat as implicit closure. | 8721 // Treat as implicit closure. |
| 8679 left = LoadClosure(primary_node); | 8722 left = LoadClosure(primary_node); |
| 8680 } else if (primary_node->primary().IsClass()) { | 8723 } else if (primary_node->primary().IsClass()) { |
| 8681 const Class& type_class = Class::Cast(primary_node->primary()); | 8724 const Class& type_class = Class::Cast(primary_node->primary()); |
| 8682 AbstractType& type = Type::ZoneHandle(Type::New( | 8725 AbstractType& type = Type::ZoneHandle(Type::New( |
| 8683 type_class, TypeArguments::Handle(), primary_pos)); | 8726 type_class, TypeArguments::Handle(isolate()), primary_pos)); |
| 8684 type = ClassFinalizer::FinalizeType( | 8727 type = ClassFinalizer::FinalizeType( |
| 8685 current_class(), type, ClassFinalizer::kCanonicalize); | 8728 current_class(), type, ClassFinalizer::kCanonicalize); |
| 8686 // Type may be malbounded, but not malformed. | 8729 // Type may be malbounded, but not malformed. |
| 8687 ASSERT(!type.IsMalformed()); | 8730 ASSERT(!type.IsMalformed()); |
| 8688 left = new TypeNode(primary_pos, type); | 8731 left = new(isolate()) TypeNode(primary_pos, type); |
| 8689 } else if (primary_node->primary().IsTypeParameter()) { | 8732 } else if (primary_node->primary().IsTypeParameter()) { |
| 8690 if (current_function().is_static()) { | 8733 if (current_function().is_static()) { |
| 8691 const String& name = String::ZoneHandle( | 8734 const String& name = String::ZoneHandle( |
| 8692 TypeParameter::Cast(primary_node->primary()).name()); | 8735 TypeParameter::Cast(primary_node->primary()).name()); |
| 8693 ErrorMsg(primary_pos, | 8736 ErrorMsg(primary_pos, |
| 8694 "cannot access type parameter '%s' from static function", | 8737 "cannot access type parameter '%s' from static function", |
| 8695 name.ToCString()); | 8738 name.ToCString()); |
| 8696 } | 8739 } |
| 8697 if (current_block_->scope->function_level() > 0) { | 8740 if (current_block_->scope->function_level() > 0) { |
| 8698 // Make sure that the instantiator is captured. | 8741 // Make sure that the instantiator is captured. |
| 8699 CaptureInstantiator(); | 8742 CaptureInstantiator(); |
| 8700 } | 8743 } |
| 8701 TypeParameter& type_parameter = TypeParameter::ZoneHandle(); | 8744 TypeParameter& type_parameter = TypeParameter::ZoneHandle(); |
| 8702 type_parameter ^= ClassFinalizer::FinalizeType( | 8745 type_parameter ^= ClassFinalizer::FinalizeType( |
| 8703 current_class(), | 8746 current_class(), |
| 8704 TypeParameter::Cast(primary_node->primary()), | 8747 TypeParameter::Cast(primary_node->primary()), |
| 8705 ClassFinalizer::kCanonicalize); | 8748 ClassFinalizer::kCanonicalize); |
| 8706 ASSERT(!type_parameter.IsMalformed()); | 8749 ASSERT(!type_parameter.IsMalformed()); |
| 8707 left = new TypeNode(primary_pos, type_parameter); | 8750 left = new(isolate()) TypeNode(primary_pos, type_parameter); |
| 8708 } else if (primary_node->IsSuper()) { | 8751 } else if (primary_node->IsSuper()) { |
| 8709 // Return "super" to handle unary super operator calls, | 8752 // Return "super" to handle unary super operator calls, |
| 8710 // or to report illegal use of "super" otherwise. | 8753 // or to report illegal use of "super" otherwise. |
| 8711 left = primary_node; | 8754 left = primary_node; |
| 8712 } else { | 8755 } else { |
| 8713 UNREACHABLE(); // Internal parser error. | 8756 UNREACHABLE(); // Internal parser error. |
| 8714 } | 8757 } |
| 8715 } | 8758 } |
| 8716 // Done parsing selectors. | 8759 // Done parsing selectors. |
| 8717 return left; | 8760 return left; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 8734 if (!IsLegalAssignableSyntax(expr, TokenPos())) { | 8777 if (!IsLegalAssignableSyntax(expr, TokenPos())) { |
| 8735 ErrorMsg(expr_pos, "expression is not assignable"); | 8778 ErrorMsg(expr_pos, "expression is not assignable"); |
| 8736 } | 8779 } |
| 8737 Token::Kind incr_op = CurrentToken(); | 8780 Token::Kind incr_op = CurrentToken(); |
| 8738 ConsumeToken(); | 8781 ConsumeToken(); |
| 8739 // Not prefix. | 8782 // Not prefix. |
| 8740 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr); | 8783 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr); |
| 8741 LocalVariable* temp = let_expr->AddInitializer(expr); | 8784 LocalVariable* temp = let_expr->AddInitializer(expr); |
| 8742 Token::Kind binary_op = | 8785 Token::Kind binary_op = |
| 8743 (incr_op == Token::kINCR) ? Token::kADD : Token::kSUB; | 8786 (incr_op == Token::kINCR) ? Token::kADD : Token::kSUB; |
| 8744 BinaryOpNode* add = new BinaryOpNode( | 8787 BinaryOpNode* add = new(isolate()) BinaryOpNode( |
| 8745 expr_pos, | 8788 expr_pos, |
| 8746 binary_op, | 8789 binary_op, |
| 8747 new LoadLocalNode(expr_pos, temp), | 8790 new(isolate()) LoadLocalNode(expr_pos, temp), |
| 8748 new LiteralNode(expr_pos, Smi::ZoneHandle(Smi::New(1)))); | 8791 new(isolate()) LiteralNode(expr_pos, Smi::ZoneHandle(Smi::New(1)))); |
| 8749 AstNode* store = CreateAssignmentNode(expr, add, expr_ident, expr_pos); | 8792 AstNode* store = CreateAssignmentNode(expr, add, expr_ident, expr_pos); |
| 8750 ASSERT(store != NULL); | 8793 ASSERT(store != NULL); |
| 8751 // The result is a pair of the (side effects of the) store followed by | 8794 // The result is a pair of the (side effects of the) store followed by |
| 8752 // the (value of the) initial value temp variable load. | 8795 // the (value of the) initial value temp variable load. |
| 8753 let_expr->AddNode(store); | 8796 let_expr->AddNode(store); |
| 8754 let_expr->AddNode(new LoadLocalNode(expr_pos, temp)); | 8797 let_expr->AddNode(new(isolate()) LoadLocalNode(expr_pos, temp)); |
| 8755 return let_expr; | 8798 return let_expr; |
| 8756 } | 8799 } |
| 8757 return expr; | 8800 return expr; |
| 8758 } | 8801 } |
| 8759 | 8802 |
| 8760 | 8803 |
| 8761 // Resolve the given type and its type arguments from the given scope class | 8804 // Resolve the given type and its type arguments from the given scope class |
| 8762 // according to the given type finalization mode. | 8805 // according to the given type finalization mode. |
| 8763 // If the given scope class is null, use the current library, but do not try to | 8806 // If the given scope class is null, use the current library, but do not try to |
| 8764 // resolve type parameters. | 8807 // resolve type parameters. |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8926 } | 8969 } |
| 8927 | 8970 |
| 8928 | 8971 |
| 8929 RawInstance* Parser::TryCanonicalize(const Instance& instance, | 8972 RawInstance* Parser::TryCanonicalize(const Instance& instance, |
| 8930 intptr_t token_pos) { | 8973 intptr_t token_pos) { |
| 8931 if (instance.IsNull()) { | 8974 if (instance.IsNull()) { |
| 8932 return instance.raw(); | 8975 return instance.raw(); |
| 8933 } | 8976 } |
| 8934 const char* error_str = NULL; | 8977 const char* error_str = NULL; |
| 8935 Instance& result = | 8978 Instance& result = |
| 8936 Instance::Handle(instance.CheckAndCanonicalize(&error_str)); | 8979 Instance::Handle(isolate(), instance.CheckAndCanonicalize(&error_str)); |
| 8937 if (result.IsNull()) { | 8980 if (result.IsNull()) { |
| 8938 ErrorMsg(token_pos, "Invalid const object %s", error_str); | 8981 ErrorMsg(token_pos, "Invalid const object %s", error_str); |
| 8939 } | 8982 } |
| 8940 return result.raw(); | 8983 return result.raw(); |
| 8941 } | 8984 } |
| 8942 | 8985 |
| 8943 | 8986 |
| 8944 // If the field is already initialized, return no ast (NULL). | 8987 // If the field is already initialized, return no ast (NULL). |
| 8945 // Otherwise, if the field is constant, initialize the field and return no ast. | 8988 // Otherwise, if the field is constant, initialize the field and return no ast. |
| 8946 // If the field is not initialized and not const, return the ast for the getter. | 8989 // If the field is not initialized and not const, return the ast for the getter. |
| 8947 AstNode* Parser::RunStaticFieldInitializer(const Field& field, | 8990 AstNode* Parser::RunStaticFieldInitializer(const Field& field, |
| 8948 intptr_t field_ref_pos) { | 8991 intptr_t field_ref_pos) { |
| 8949 ASSERT(field.is_static()); | 8992 ASSERT(field.is_static()); |
| 8950 const Class& field_owner = Class::ZoneHandle(isolate(), field.owner()); | 8993 const Class& field_owner = Class::ZoneHandle(isolate(), field.owner()); |
| 8951 const String& field_name = String::ZoneHandle(isolate(), field.name()); | 8994 const String& field_name = String::ZoneHandle(isolate(), field.name()); |
| 8952 const String& getter_name = String::Handle(isolate(), | 8995 const String& getter_name = String::Handle(isolate(), |
| 8953 Field::GetterName(field_name)); | 8996 Field::GetterName(field_name)); |
| 8954 const Function& getter = Function::Handle( | 8997 const Function& getter = Function::Handle( |
| 8955 isolate(), field_owner.LookupStaticFunction(getter_name)); | 8998 isolate(), field_owner.LookupStaticFunction(getter_name)); |
| 8956 const Instance& value = Instance::Handle(isolate(), field.value()); | 8999 const Instance& value = Instance::Handle(isolate(), field.value()); |
| 8957 if (value.raw() == Object::transition_sentinel().raw()) { | 9000 if (value.raw() == Object::transition_sentinel().raw()) { |
| 8958 if (field.is_const()) { | 9001 if (field.is_const()) { |
| 8959 ErrorMsg("circular dependency while initializing static field '%s'", | 9002 ErrorMsg("circular dependency while initializing static field '%s'", |
| 8960 field_name.ToCString()); | 9003 field_name.ToCString()); |
| 8961 } else { | 9004 } else { |
| 8962 // The implicit static getter will throw the exception if necessary. | 9005 // The implicit static getter will throw the exception if necessary. |
| 8963 return new StaticGetterNode(field_ref_pos, | 9006 return new(isolate()) StaticGetterNode( |
| 8964 NULL, | 9007 field_ref_pos, NULL, false, field_owner, field_name); |
| 8965 false, | |
| 8966 field_owner, | |
| 8967 field_name); | |
| 8968 } | 9008 } |
| 8969 } else if (value.raw() == Object::sentinel().raw()) { | 9009 } else if (value.raw() == Object::sentinel().raw()) { |
| 8970 // This field has not been referenced yet and thus the value has | 9010 // This field has not been referenced yet and thus the value has |
| 8971 // not been evaluated. If the field is const, call the static getter method | 9011 // not been evaluated. If the field is const, call the static getter method |
| 8972 // to evaluate the expression and canonicalize the value. | 9012 // to evaluate the expression and canonicalize the value. |
| 8973 if (field.is_const()) { | 9013 if (field.is_const()) { |
| 8974 field.set_value(Object::transition_sentinel()); | 9014 field.set_value(Object::transition_sentinel()); |
| 8975 const int kNumArguments = 0; // no arguments. | 9015 const int kNumArguments = 0; // no arguments. |
| 8976 const Function& func = Function::Handle( | 9016 const Function& func = Function::Handle(isolate(), |
| 8977 isolate(), Resolver::ResolveStatic(field_owner, | 9017 Resolver::ResolveStatic(field_owner, |
| 8978 getter_name, | 9018 getter_name, |
| 8979 kNumArguments, | 9019 kNumArguments, |
| 8980 Object::empty_array())); | 9020 Object::empty_array())); |
| 8981 ASSERT(!func.IsNull()); | 9021 ASSERT(!func.IsNull()); |
| 8982 ASSERT(func.kind() == RawFunction::kImplicitStaticFinalGetter); | 9022 ASSERT(func.kind() == RawFunction::kImplicitStaticFinalGetter); |
| 8983 Object& const_value = Object::Handle(isolate()); | 9023 Object& const_value = Object::Handle(isolate()); |
| 8984 { | 9024 { |
| 8985 PAUSETIMERSCOPE(isolate(), time_compilation); | 9025 PAUSETIMERSCOPE(isolate(), time_compilation); |
| 8986 const_value = DartEntry::InvokeFunction(func, Object::empty_array()); | 9026 const_value = DartEntry::InvokeFunction(func, Object::empty_array()); |
| 8987 } | 9027 } |
| 8988 if (const_value.IsError()) { | 9028 if (const_value.IsError()) { |
| 8989 const Error& error = Error::Cast(const_value); | 9029 const Error& error = Error::Cast(const_value); |
| 8990 if (error.IsUnhandledException()) { | 9030 if (error.IsUnhandledException()) { |
| 8991 // An exception may not occur in every parse attempt, i.e., the | 9031 // An exception may not occur in every parse attempt, i.e., the |
| 8992 // generated AST is not deterministic. Therefore mark the function as | 9032 // generated AST is not deterministic. Therefore mark the function as |
| 8993 // not optimizable. | 9033 // not optimizable. |
| 8994 current_function().SetIsOptimizable(false); | 9034 current_function().SetIsOptimizable(false); |
| 8995 field.set_value(Object::null_instance()); | 9035 field.set_value(Object::null_instance()); |
| 8996 // It is a compile-time error if evaluation of a compile-time constant | 9036 // It is a compile-time error if evaluation of a compile-time constant |
| 8997 // would raise an exception. | 9037 // would raise an exception. |
| 8998 AppendErrorMsg(error, field_ref_pos, | 9038 AppendErrorMsg(error, field_ref_pos, |
| 8999 "error initializing const field '%s'", | 9039 "error initializing const field '%s'", |
| 9000 String::Handle(field.name()).ToCString()); | 9040 String::Handle(isolate(), field.name()).ToCString()); |
| 9001 } else { | 9041 } else { |
| 9002 isolate()->long_jump_base()->Jump(1, error); | 9042 isolate()->long_jump_base()->Jump(1, error); |
| 9003 UNREACHABLE(); | 9043 UNREACHABLE(); |
| 9004 } | 9044 } |
| 9005 } | 9045 } |
| 9006 ASSERT(const_value.IsNull() || const_value.IsInstance()); | 9046 ASSERT(const_value.IsNull() || const_value.IsInstance()); |
| 9007 Instance& instance = Instance::Handle(); | 9047 Instance& instance = Instance::Handle(isolate()); |
| 9008 instance ^= const_value.raw(); | 9048 instance ^= const_value.raw(); |
| 9009 instance = TryCanonicalize(instance, field_ref_pos); | 9049 instance = TryCanonicalize(instance, field_ref_pos); |
| 9010 field.set_value(instance); | 9050 field.set_value(instance); |
| 9011 return NULL; // Constant | 9051 return NULL; // Constant |
| 9012 } else { | 9052 } else { |
| 9013 return new StaticGetterNode(field_ref_pos, | 9053 return new(isolate()) StaticGetterNode( |
| 9014 NULL, | 9054 field_ref_pos, NULL, false, field_owner, field_name); |
| 9015 false, | |
| 9016 field_owner, | |
| 9017 field_name); | |
| 9018 } | 9055 } |
| 9019 } | 9056 } |
| 9020 if (getter.IsNull() || | 9057 if (getter.IsNull() || |
| 9021 (getter.kind() == RawFunction::kImplicitStaticFinalGetter)) { | 9058 (getter.kind() == RawFunction::kImplicitStaticFinalGetter)) { |
| 9022 return NULL; | 9059 return NULL; |
| 9023 } | 9060 } |
| 9024 ASSERT(getter.kind() == RawFunction::kImplicitGetter); | 9061 ASSERT(getter.kind() == RawFunction::kImplicitGetter); |
| 9025 return new StaticGetterNode(field_ref_pos, | 9062 return new(isolate()) StaticGetterNode( |
| 9026 NULL, | 9063 field_ref_pos, NULL, false, field_owner, field_name); |
| 9027 false, | |
| 9028 field_owner, | |
| 9029 field_name); | |
| 9030 } | 9064 } |
| 9031 | 9065 |
| 9032 | 9066 |
| 9033 RawObject* Parser::EvaluateConstConstructorCall( | 9067 RawObject* Parser::EvaluateConstConstructorCall( |
| 9034 const Class& type_class, | 9068 const Class& type_class, |
| 9035 const TypeArguments& type_arguments, | 9069 const TypeArguments& type_arguments, |
| 9036 const Function& constructor, | 9070 const Function& constructor, |
| 9037 ArgumentListNode* arguments) { | 9071 ArgumentListNode* arguments) { |
| 9038 // Factories have one extra argument: the type arguments. | 9072 // Factories have one extra argument: the type arguments. |
| 9039 // Constructors have 2 extra arguments: rcvr and construction phase. | 9073 // Constructors have 2 extra arguments: rcvr and construction phase. |
| 9040 const int kNumExtraArgs = constructor.IsFactory() ? 1 : 2; | 9074 const int kNumExtraArgs = constructor.IsFactory() ? 1 : 2; |
| 9041 const int num_arguments = arguments->length() + kNumExtraArgs; | 9075 const int num_arguments = arguments->length() + kNumExtraArgs; |
| 9042 const Array& arg_values = Array::Handle(isolate(), | 9076 const Array& arg_values = Array::Handle(isolate(), |
| 9043 Array::New(num_arguments)); | 9077 Array::New(num_arguments)); |
| 9044 Instance& instance = Instance::Handle(isolate()); | 9078 Instance& instance = Instance::Handle(isolate()); |
| 9045 if (!constructor.IsFactory()) { | 9079 if (!constructor.IsFactory()) { |
| 9046 instance = Instance::New(type_class, Heap::kOld); | 9080 instance = Instance::New(type_class, Heap::kOld); |
| 9047 if (!type_arguments.IsNull()) { | 9081 if (!type_arguments.IsNull()) { |
| 9048 if (!type_arguments.IsInstantiated()) { | 9082 if (!type_arguments.IsInstantiated()) { |
| 9049 ErrorMsg("type must be constant in const constructor"); | 9083 ErrorMsg("type must be constant in const constructor"); |
| 9050 } | 9084 } |
| 9051 instance.SetTypeArguments( | 9085 instance.SetTypeArguments( |
| 9052 TypeArguments::Handle(type_arguments.Canonicalize())); | 9086 TypeArguments::Handle(isolate(), type_arguments.Canonicalize())); |
| 9053 } | 9087 } |
| 9054 arg_values.SetAt(0, instance); | 9088 arg_values.SetAt(0, instance); |
| 9055 arg_values.SetAt(1, Smi::Handle(Smi::New(Function::kCtorPhaseAll))); | 9089 arg_values.SetAt(1, Smi::Handle(isolate(), |
| 9090 Smi::New(Function::kCtorPhaseAll))); | |
| 9056 } else { | 9091 } else { |
| 9057 // Prepend type_arguments to list of arguments to factory. | 9092 // Prepend type_arguments to list of arguments to factory. |
| 9058 ASSERT(type_arguments.IsZoneHandle()); | 9093 ASSERT(type_arguments.IsZoneHandle()); |
| 9059 arg_values.SetAt(0, type_arguments); | 9094 arg_values.SetAt(0, type_arguments); |
| 9060 } | 9095 } |
| 9061 for (int i = 0; i < arguments->length(); i++) { | 9096 for (int i = 0; i < arguments->length(); i++) { |
| 9062 AstNode* arg = arguments->NodeAt(i); | 9097 AstNode* arg = arguments->NodeAt(i); |
| 9063 // Arguments have been evaluated to a literal value already. | 9098 // Arguments have been evaluated to a literal value already. |
| 9064 ASSERT(arg->IsLiteralNode()); | 9099 ASSERT(arg->IsLiteralNode()); |
| 9065 arg_values.SetAt((i + kNumExtraArgs), arg->AsLiteralNode()->literal()); | 9100 arg_values.SetAt((i + kNumExtraArgs), arg->AsLiteralNode()->literal()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9104 const String &ident, | 9139 const String &ident, |
| 9105 AstNode** node) { | 9140 AstNode** node) { |
| 9106 TRACE_PARSER("ResolveIdentInLocalScope"); | 9141 TRACE_PARSER("ResolveIdentInLocalScope"); |
| 9107 // First try to find the identifier in the nested local scopes. | 9142 // First try to find the identifier in the nested local scopes. |
| 9108 LocalVariable* local = LookupLocalScope(ident); | 9143 LocalVariable* local = LookupLocalScope(ident); |
| 9109 if (current_block_ != NULL) { | 9144 if (current_block_ != NULL) { |
| 9110 current_block_->scope->AddReferencedName(ident_pos, ident); | 9145 current_block_->scope->AddReferencedName(ident_pos, ident); |
| 9111 } | 9146 } |
| 9112 if (local != NULL) { | 9147 if (local != NULL) { |
| 9113 if (node != NULL) { | 9148 if (node != NULL) { |
| 9114 *node = new LoadLocalNode(ident_pos, local); | 9149 *node = new(isolate()) LoadLocalNode(ident_pos, local); |
| 9115 } | 9150 } |
| 9116 return true; | 9151 return true; |
| 9117 } | 9152 } |
| 9118 | 9153 |
| 9119 // Try to find the identifier in the class scope of the current class. | 9154 // Try to find the identifier in the class scope of the current class. |
| 9120 // If the current class is the result of a mixin application, we must | 9155 // If the current class is the result of a mixin application, we must |
| 9121 // use the class scope of the class from which the function originates. | 9156 // use the class scope of the class from which the function originates. |
| 9122 Class& cls = Class::Handle(isolate()); | 9157 Class& cls = Class::Handle(isolate()); |
| 9123 if (!current_class().IsMixinApplication()) { | 9158 if (!current_class().IsMixinApplication()) { |
| 9124 cls = current_class().raw(); | 9159 cls = current_class().raw(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 9142 return true; | 9177 return true; |
| 9143 } | 9178 } |
| 9144 | 9179 |
| 9145 // Check if an instance/static function exists. | 9180 // Check if an instance/static function exists. |
| 9146 func = cls.LookupFunction(ident); | 9181 func = cls.LookupFunction(ident); |
| 9147 if (!func.IsNull() && | 9182 if (!func.IsNull() && |
| 9148 (func.IsDynamicFunction() || | 9183 (func.IsDynamicFunction() || |
| 9149 func.IsStaticFunction() || | 9184 func.IsStaticFunction() || |
| 9150 func.is_abstract())) { | 9185 func.is_abstract())) { |
| 9151 if (node != NULL) { | 9186 if (node != NULL) { |
| 9152 *node = new PrimaryNode(ident_pos, | 9187 *node = new(isolate()) PrimaryNode( |
| 9153 Function::ZoneHandle(isolate(), func.raw())); | 9188 ident_pos, Function::ZoneHandle(isolate(), func.raw())); |
| 9154 } | 9189 } |
| 9155 return true; | 9190 return true; |
| 9156 } | 9191 } |
| 9157 | 9192 |
| 9158 // Now check if a getter/setter method exists for it in which case | 9193 // Now check if a getter/setter method exists for it in which case |
| 9159 // it is still a field. | 9194 // it is still a field. |
| 9160 func = cls.LookupGetterFunction(ident); | 9195 func = cls.LookupGetterFunction(ident); |
| 9161 if (!func.IsNull()) { | 9196 if (!func.IsNull()) { |
| 9162 if (func.IsDynamicFunction() || func.is_abstract()) { | 9197 if (func.IsDynamicFunction() || func.is_abstract()) { |
| 9163 if (node != NULL) { | 9198 if (node != NULL) { |
| 9164 CheckInstanceFieldAccess(ident_pos, ident); | 9199 CheckInstanceFieldAccess(ident_pos, ident); |
| 9165 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 9200 ASSERT(AbstractType::Handle(isolate(), |
| 9201 func.result_type()).IsResolved()); | |
| 9166 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | 9202 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); |
| 9167 } | 9203 } |
| 9168 return true; | 9204 return true; |
| 9169 } else if (func.IsStaticFunction()) { | 9205 } else if (func.IsStaticFunction()) { |
| 9170 if (node != NULL) { | 9206 if (node != NULL) { |
| 9171 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 9207 ASSERT(AbstractType::Handle(isolate(), |
| 9208 func.result_type()).IsResolved()); | |
| 9172 // The static getter may later be changed into a dynamically | 9209 // The static getter may later be changed into a dynamically |
| 9173 // resolved instance setter if no static setter can | 9210 // resolved instance setter if no static setter can |
| 9174 // be found. | 9211 // be found. |
| 9175 AstNode* receiver = NULL; | 9212 AstNode* receiver = NULL; |
| 9176 const bool kTestOnly = true; | 9213 const bool kTestOnly = true; |
| 9177 if (parsing_metadata_) { | 9214 if (parsing_metadata_) { |
| 9178 ErrorMsg(ident_pos, | 9215 ErrorMsg(ident_pos, |
| 9179 "'%s' is not a compile-time constant", | 9216 "'%s' is not a compile-time constant", |
| 9180 ident.ToCString()); | 9217 ident.ToCString()); |
| 9181 } | 9218 } |
| 9182 if (!current_function().is_static() && | 9219 if (!current_function().is_static() && |
| 9183 (LookupReceiver(current_block_->scope, kTestOnly) != NULL)) { | 9220 (LookupReceiver(current_block_->scope, kTestOnly) != NULL)) { |
| 9184 receiver = LoadReceiver(ident_pos); | 9221 receiver = LoadReceiver(ident_pos); |
| 9185 } | 9222 } |
| 9186 *node = new StaticGetterNode(ident_pos, | 9223 *node = new(isolate()) StaticGetterNode(ident_pos, |
| 9187 receiver, | 9224 receiver, |
| 9188 false, | 9225 false, |
| 9189 Class::ZoneHandle(isolate(), cls.raw()), | 9226 Class::ZoneHandle(isolate(), cls.raw()), |
| 9190 ident); | 9227 ident); |
| 9191 } | 9228 } |
| 9192 return true; | 9229 return true; |
| 9193 } | 9230 } |
| 9194 } | 9231 } |
| 9195 func = cls.LookupSetterFunction(ident); | 9232 func = cls.LookupSetterFunction(ident); |
| 9196 if (!func.IsNull()) { | 9233 if (!func.IsNull()) { |
| 9197 if (func.IsDynamicFunction() || func.is_abstract()) { | 9234 if (func.IsDynamicFunction() || func.is_abstract()) { |
| 9198 if (node != NULL) { | 9235 if (node != NULL) { |
| 9199 // We create a getter node even though a getter doesn't exist as | 9236 // We create a getter node even though a getter doesn't exist as |
| 9200 // it could be followed by an assignment which will convert it to | 9237 // it could be followed by an assignment which will convert it to |
| 9201 // a setter node. If there is no assignment we will get an error | 9238 // a setter node. If there is no assignment we will get an error |
| 9202 // when we try to invoke the getter. | 9239 // when we try to invoke the getter. |
| 9203 CheckInstanceFieldAccess(ident_pos, ident); | 9240 CheckInstanceFieldAccess(ident_pos, ident); |
| 9204 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 9241 ASSERT(AbstractType::Handle(isolate(), |
| 9242 func.result_type()).IsResolved()); | |
| 9205 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | 9243 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); |
| 9206 } | 9244 } |
| 9207 return true; | 9245 return true; |
| 9208 } else if (func.IsStaticFunction()) { | 9246 } else if (func.IsStaticFunction()) { |
| 9209 if (node != NULL) { | 9247 if (node != NULL) { |
| 9210 // We create a getter node even though a getter doesn't exist as | 9248 // We create a getter node even though a getter doesn't exist as |
| 9211 // it could be followed by an assignment which will convert it to | 9249 // it could be followed by an assignment which will convert it to |
| 9212 // a setter node. If there is no assignment we will get an error | 9250 // a setter node. If there is no assignment we will get an error |
| 9213 // when we try to invoke the getter. | 9251 // when we try to invoke the getter. |
| 9214 *node = new StaticGetterNode(ident_pos, | 9252 *node = new(isolate()) StaticGetterNode( |
| 9215 NULL, | 9253 ident_pos, |
| 9216 false, | 9254 NULL, |
| 9217 Class::ZoneHandle(isolate(), cls.raw()), | 9255 false, |
| 9218 ident); | 9256 Class::ZoneHandle(isolate(), cls.raw()), |
| 9257 ident); | |
| 9219 } | 9258 } |
| 9220 return true; | 9259 return true; |
| 9221 } | 9260 } |
| 9222 } | 9261 } |
| 9223 | 9262 |
| 9224 // Nothing found in scope of current class. | 9263 // Nothing found in scope of current class. |
| 9225 if (node != NULL) { | 9264 if (node != NULL) { |
| 9226 *node = NULL; | 9265 *node = NULL; |
| 9227 } | 9266 } |
| 9228 return false; // Not an unqualified identifier. | 9267 return false; // Not an unqualified identifier. |
| 9229 } | 9268 } |
| 9230 | 9269 |
| 9231 | 9270 |
| 9232 RawClass* Parser::ResolveClassInCurrentLibraryScope(const String& name) { | 9271 RawClass* Parser::ResolveClassInCurrentLibraryScope(const String& name) { |
| 9233 HANDLESCOPE(isolate()); | 9272 HANDLESCOPE(isolate()); |
| 9234 const Object& obj = Object::Handle(library_.ResolveName(name)); | 9273 const Object& obj = Object::Handle(isolate(), library_.ResolveName(name)); |
| 9235 if (obj.IsClass()) { | 9274 if (obj.IsClass()) { |
| 9236 return Class::Cast(obj).raw(); | 9275 return Class::Cast(obj).raw(); |
| 9237 } | 9276 } |
| 9238 return Class::null(); | 9277 return Class::null(); |
| 9239 } | 9278 } |
| 9240 | 9279 |
| 9241 | 9280 |
| 9242 // Resolve an identifier by checking the global scope of the current | 9281 // Resolve an identifier by checking the global scope of the current |
| 9243 // library. If not found in the current library, then look in the scopes | 9282 // library. If not found in the current library, then look in the scopes |
| 9244 // of all libraries that are imported without a library prefix. | 9283 // of all libraries that are imported without a library prefix. |
| 9245 AstNode* Parser::ResolveIdentInCurrentLibraryScope(intptr_t ident_pos, | 9284 AstNode* Parser::ResolveIdentInCurrentLibraryScope(intptr_t ident_pos, |
| 9246 const String& ident) { | 9285 const String& ident) { |
| 9247 TRACE_PARSER("ResolveIdentInCurrentLibraryScope"); | 9286 TRACE_PARSER("ResolveIdentInCurrentLibraryScope"); |
| 9248 HANDLESCOPE(isolate()); | 9287 HANDLESCOPE(isolate()); |
| 9249 const Object& obj = Object::Handle(library_.ResolveName(ident)); | 9288 const Object& obj = Object::Handle(isolate(), library_.ResolveName(ident)); |
| 9250 if (obj.IsClass()) { | 9289 if (obj.IsClass()) { |
| 9251 const Class& cls = Class::Cast(obj); | 9290 const Class& cls = Class::Cast(obj); |
| 9252 return new PrimaryNode(ident_pos, Class::ZoneHandle(cls.raw())); | 9291 return new(isolate()) PrimaryNode(ident_pos, Class::ZoneHandle(cls.raw())); |
| 9253 } else if (obj.IsField()) { | 9292 } else if (obj.IsField()) { |
| 9254 const Field& field = Field::Cast(obj); | 9293 const Field& field = Field::Cast(obj); |
| 9255 ASSERT(field.is_static()); | 9294 ASSERT(field.is_static()); |
| 9256 return GenerateStaticFieldLookup(field, ident_pos); | 9295 return GenerateStaticFieldLookup(field, ident_pos); |
| 9257 } else if (obj.IsFunction()) { | 9296 } else if (obj.IsFunction()) { |
| 9258 const Function& func = Function::Cast(obj); | 9297 const Function& func = Function::Cast(obj); |
| 9259 ASSERT(func.is_static()); | 9298 ASSERT(func.is_static()); |
| 9260 if (func.IsGetterFunction() || func.IsSetterFunction()) { | 9299 if (func.IsGetterFunction() || func.IsSetterFunction()) { |
| 9261 return new StaticGetterNode(ident_pos, | 9300 return new(isolate()) StaticGetterNode(ident_pos, |
| 9262 /* receiver */ NULL, | 9301 /* receiver */ NULL, |
| 9263 /* is_super_getter */ false, | 9302 /* is_super_getter */ false, |
| 9264 Class::ZoneHandle(func.Owner()), | 9303 Class::ZoneHandle(func.Owner()), |
| 9265 ident); | 9304 ident); |
| 9266 | 9305 |
| 9267 } else { | 9306 } else { |
| 9268 return new PrimaryNode(ident_pos, Function::ZoneHandle(func.raw())); | 9307 return new(isolate()) PrimaryNode(ident_pos, |
| 9308 Function::ZoneHandle(func.raw())); | |
| 9269 } | 9309 } |
| 9270 } else { | 9310 } else { |
| 9271 ASSERT(obj.IsNull() || obj.IsLibraryPrefix()); | 9311 ASSERT(obj.IsNull() || obj.IsLibraryPrefix()); |
| 9272 } | 9312 } |
| 9273 // Lexically unresolved primary identifiers are referenced by their name. | 9313 // Lexically unresolved primary identifiers are referenced by their name. |
| 9274 return new PrimaryNode(ident_pos, ident); | 9314 return new(isolate()) PrimaryNode(ident_pos, ident); |
| 9275 } | 9315 } |
| 9276 | 9316 |
| 9277 | 9317 |
| 9278 RawClass* Parser::ResolveClassInPrefixScope(const LibraryPrefix& prefix, | 9318 RawClass* Parser::ResolveClassInPrefixScope(const LibraryPrefix& prefix, |
| 9279 const String& name) { | 9319 const String& name) { |
| 9280 HANDLESCOPE(isolate()); | 9320 HANDLESCOPE(isolate()); |
| 9281 const Object& obj = Object::Handle(prefix.LookupObject(name)); | 9321 const Object& obj = Object::Handle(isolate(), prefix.LookupObject(name)); |
| 9282 if (obj.IsClass()) { | 9322 if (obj.IsClass()) { |
| 9283 return Class::Cast(obj).raw(); | 9323 return Class::Cast(obj).raw(); |
| 9284 } | 9324 } |
| 9285 return Class::null(); | 9325 return Class::null(); |
| 9286 } | 9326 } |
| 9287 | 9327 |
| 9288 | 9328 |
| 9289 // Do a lookup for the identifier in the scope of the specified | 9329 // Do a lookup for the identifier in the scope of the specified |
| 9290 // library prefix. This means trying to resolve it locally in all of the | 9330 // library prefix. This means trying to resolve it locally in all of the |
| 9291 // libraries present in the library prefix. | 9331 // libraries present in the library prefix. |
| 9292 AstNode* Parser::ResolveIdentInPrefixScope(intptr_t ident_pos, | 9332 AstNode* Parser::ResolveIdentInPrefixScope(intptr_t ident_pos, |
| 9293 const LibraryPrefix& prefix, | 9333 const LibraryPrefix& prefix, |
| 9294 const String& ident) { | 9334 const String& ident) { |
| 9295 TRACE_PARSER("ResolveIdentInPrefixScope"); | 9335 TRACE_PARSER("ResolveIdentInPrefixScope"); |
| 9296 HANDLESCOPE(isolate()); | 9336 HANDLESCOPE(isolate()); |
| 9297 Object& obj = Object::Handle(); | 9337 Object& obj = Object::Handle(isolate()); |
| 9298 if (prefix.is_loaded()) { | 9338 if (prefix.is_loaded()) { |
| 9299 obj = prefix.LookupObject(ident); | 9339 obj = prefix.LookupObject(ident); |
| 9300 } else { | 9340 } else { |
| 9301 // Remember that this function depends on an import prefix of an | 9341 // Remember that this function depends on an import prefix of an |
| 9302 // unloaded deferred library. Note that parsed_function() can be | 9342 // unloaded deferred library. Note that parsed_function() can be |
| 9303 // NULL when parsing expressions outside the scope of a function. | 9343 // NULL when parsing expressions outside the scope of a function. |
| 9304 if (parsed_function() != NULL) { | 9344 if (parsed_function() != NULL) { |
| 9305 parsed_function()->AddDeferredPrefix(prefix); | 9345 parsed_function()->AddDeferredPrefix(prefix); |
| 9306 } | 9346 } |
| 9307 } | 9347 } |
| 9308 const bool is_deferred = prefix.is_deferred_load(); | 9348 const bool is_deferred = prefix.is_deferred_load(); |
| 9309 if (obj.IsNull()) { | 9349 if (obj.IsNull()) { |
| 9310 // Unresolved prefixed primary identifier. | 9350 // Unresolved prefixed primary identifier. |
| 9311 return NULL; | 9351 return NULL; |
| 9312 } else if (obj.IsClass()) { | 9352 } else if (obj.IsClass()) { |
| 9313 const Class& cls = Class::Cast(obj); | 9353 const Class& cls = Class::Cast(obj); |
| 9314 PrimaryNode* primary = | 9354 PrimaryNode* primary = |
| 9315 new PrimaryNode(ident_pos, Class::ZoneHandle(cls.raw())); | 9355 new(isolate()) PrimaryNode(ident_pos, Class::ZoneHandle(cls.raw())); |
| 9316 primary->set_is_deferred(is_deferred); | 9356 primary->set_is_deferred(is_deferred); |
| 9317 return primary; | 9357 return primary; |
| 9318 } else if (obj.IsField()) { | 9358 } else if (obj.IsField()) { |
| 9319 const Field& field = Field::Cast(obj); | 9359 const Field& field = Field::Cast(obj); |
| 9320 ASSERT(field.is_static()); | 9360 ASSERT(field.is_static()); |
| 9321 AstNode* get_field = GenerateStaticFieldLookup(field, ident_pos); | 9361 AstNode* get_field = GenerateStaticFieldLookup(field, ident_pos); |
| 9322 ASSERT(get_field != NULL); | 9362 ASSERT(get_field != NULL); |
| 9323 ASSERT(get_field->IsLoadStaticFieldNode() || | 9363 ASSERT(get_field->IsLoadStaticFieldNode() || |
| 9324 get_field->IsStaticGetterNode()); | 9364 get_field->IsStaticGetterNode()); |
| 9325 if (get_field->IsLoadStaticFieldNode()) { | 9365 if (get_field->IsLoadStaticFieldNode()) { |
| 9326 get_field->AsLoadStaticFieldNode()->set_is_deferred(is_deferred); | 9366 get_field->AsLoadStaticFieldNode()->set_is_deferred(is_deferred); |
| 9327 } else if (get_field->IsStaticGetterNode()) { | 9367 } else if (get_field->IsStaticGetterNode()) { |
| 9328 get_field->AsStaticGetterNode()->set_is_deferred(is_deferred); | 9368 get_field->AsStaticGetterNode()->set_is_deferred(is_deferred); |
| 9329 } | 9369 } |
| 9330 return get_field; | 9370 return get_field; |
| 9331 } else if (obj.IsFunction()) { | 9371 } else if (obj.IsFunction()) { |
| 9332 const Function& func = Function::Cast(obj); | 9372 const Function& func = Function::Cast(obj); |
| 9333 ASSERT(func.is_static()); | 9373 ASSERT(func.is_static()); |
| 9334 if (func.IsGetterFunction() || func.IsSetterFunction()) { | 9374 if (func.IsGetterFunction() || func.IsSetterFunction()) { |
| 9335 StaticGetterNode* getter = | 9375 StaticGetterNode* getter = |
| 9336 new StaticGetterNode(ident_pos, | 9376 new(isolate()) StaticGetterNode(ident_pos, |
| 9337 /* receiver */ NULL, | 9377 /* receiver */ NULL, |
| 9338 /* is_super_getter */ false, | 9378 /* is_super_getter */ false, |
| 9339 Class::ZoneHandle(func.Owner()), | 9379 Class::ZoneHandle(isolate(), func.Owner()), |
| 9340 ident); | 9380 ident); |
| 9341 getter->set_is_deferred(is_deferred); | 9381 getter->set_is_deferred(is_deferred); |
| 9342 return getter; | 9382 return getter; |
| 9343 } else { | 9383 } else { |
| 9344 PrimaryNode* primary = | 9384 PrimaryNode* primary = new(isolate()) PrimaryNode( |
| 9345 new PrimaryNode(ident_pos, Function::ZoneHandle(func.raw())); | 9385 ident_pos, Function::ZoneHandle(isolate(), func.raw())); |
| 9346 primary->set_is_deferred(is_deferred); | 9386 primary->set_is_deferred(is_deferred); |
| 9347 return primary; | 9387 return primary; |
| 9348 } | 9388 } |
| 9349 } | 9389 } |
| 9350 // All possible object types are handled above. | 9390 // All possible object types are handled above. |
| 9351 UNREACHABLE(); | 9391 UNREACHABLE(); |
| 9352 return NULL; | 9392 return NULL; |
| 9353 } | 9393 } |
| 9354 | 9394 |
| 9355 | 9395 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 9372 TypeParameter& type_parameter = TypeParameter::ZoneHandle( | 9412 TypeParameter& type_parameter = TypeParameter::ZoneHandle( |
| 9373 current_class().LookupTypeParameter(ident)); | 9413 current_class().LookupTypeParameter(ident)); |
| 9374 if (!type_parameter.IsNull()) { | 9414 if (!type_parameter.IsNull()) { |
| 9375 if (current_block_->scope->function_level() > 0) { | 9415 if (current_block_->scope->function_level() > 0) { |
| 9376 // Make sure that the instantiator is captured. | 9416 // Make sure that the instantiator is captured. |
| 9377 CaptureInstantiator(); | 9417 CaptureInstantiator(); |
| 9378 } | 9418 } |
| 9379 type_parameter ^= ClassFinalizer::FinalizeType( | 9419 type_parameter ^= ClassFinalizer::FinalizeType( |
| 9380 current_class(), type_parameter, ClassFinalizer::kCanonicalize); | 9420 current_class(), type_parameter, ClassFinalizer::kCanonicalize); |
| 9381 ASSERT(!type_parameter.IsMalformed()); | 9421 ASSERT(!type_parameter.IsMalformed()); |
| 9382 return new TypeNode(ident_pos, type_parameter); | 9422 return new(isolate()) TypeNode(ident_pos, type_parameter); |
| 9383 } | 9423 } |
| 9384 } | 9424 } |
| 9385 // Not found in the local scope, and the name is not a type parameter. | 9425 // Not found in the local scope, and the name is not a type parameter. |
| 9386 // Try finding the variable in the library scope (current library | 9426 // Try finding the variable in the library scope (current library |
| 9387 // and all libraries imported by it without a library prefix). | 9427 // and all libraries imported by it without a library prefix). |
| 9388 resolved = ResolveIdentInCurrentLibraryScope(ident_pos, ident); | 9428 resolved = ResolveIdentInCurrentLibraryScope(ident_pos, ident); |
| 9389 } | 9429 } |
| 9390 if (resolved->IsPrimaryNode()) { | 9430 if (resolved->IsPrimaryNode()) { |
| 9391 PrimaryNode* primary = resolved->AsPrimaryNode(); | 9431 PrimaryNode* primary = resolved->AsPrimaryNode(); |
| 9392 const intptr_t primary_pos = primary->token_pos(); | 9432 const intptr_t primary_pos = primary->token_pos(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 9411 } else if (primary->primary().IsFunction()) { | 9451 } else if (primary->primary().IsFunction()) { |
| 9412 if (allow_closure_names) { | 9452 if (allow_closure_names) { |
| 9413 resolved = LoadClosure(primary); | 9453 resolved = LoadClosure(primary); |
| 9414 } else { | 9454 } else { |
| 9415 ErrorMsg(ident_pos, "illegal reference to method '%s'", | 9455 ErrorMsg(ident_pos, "illegal reference to method '%s'", |
| 9416 ident.ToCString()); | 9456 ident.ToCString()); |
| 9417 } | 9457 } |
| 9418 } else if (primary->primary().IsClass()) { | 9458 } else if (primary->primary().IsClass()) { |
| 9419 const Class& type_class = Class::Cast(primary->primary()); | 9459 const Class& type_class = Class::Cast(primary->primary()); |
| 9420 AbstractType& type = Type::ZoneHandle( | 9460 AbstractType& type = Type::ZoneHandle( |
| 9421 Type::New(type_class, TypeArguments::Handle(), primary_pos)); | 9461 Type::New(type_class, TypeArguments::Handle(isolate()), primary_pos)); |
| 9422 type ^= ClassFinalizer::FinalizeType( | 9462 type ^= ClassFinalizer::FinalizeType( |
| 9423 current_class(), type, ClassFinalizer::kCanonicalize); | 9463 current_class(), type, ClassFinalizer::kCanonicalize); |
| 9424 // Type may be malbounded, but not malformed. | 9464 // Type may be malbounded, but not malformed. |
| 9425 ASSERT(!type.IsMalformed()); | 9465 ASSERT(!type.IsMalformed()); |
| 9426 resolved = new TypeNode(primary_pos, type); | 9466 resolved = new(isolate()) TypeNode(primary_pos, type); |
| 9427 } | 9467 } |
| 9428 } | 9468 } |
| 9429 return resolved; | 9469 return resolved; |
| 9430 } | 9470 } |
| 9431 | 9471 |
| 9432 | 9472 |
| 9433 // Parses type = [ident "."] ident ["<" type { "," type } ">"], then resolve and | 9473 // Parses type = [ident "."] ident ["<" type { "," type } ">"], then resolve and |
| 9434 // finalize it according to the given type finalization mode. | 9474 // finalize it according to the given type finalization mode. |
| 9435 RawAbstractType* Parser::ParseType( | 9475 RawAbstractType* Parser::ParseType( |
| 9436 ClassFinalizer::FinalizationKind finalization, | 9476 ClassFinalizer::FinalizationKind finalization, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 9447 SkipQualIdent(); | 9487 SkipQualIdent(); |
| 9448 } else { | 9488 } else { |
| 9449 ParseQualIdent(&type_name); | 9489 ParseQualIdent(&type_name); |
| 9450 // An identifier cannot be resolved in a local scope when top level parsing. | 9490 // An identifier cannot be resolved in a local scope when top level parsing. |
| 9451 if (!is_top_level_ && | 9491 if (!is_top_level_ && |
| 9452 (type_name.lib_prefix == NULL) && | 9492 (type_name.lib_prefix == NULL) && |
| 9453 ResolveIdentInLocalScope(type_name.ident_pos, *type_name.ident, NULL)) { | 9493 ResolveIdentInLocalScope(type_name.ident_pos, *type_name.ident, NULL)) { |
| 9454 // The type is malformed. Skip over its type arguments. | 9494 // The type is malformed. Skip over its type arguments. |
| 9455 ParseTypeArguments(ClassFinalizer::kIgnore); | 9495 ParseTypeArguments(ClassFinalizer::kIgnore); |
| 9456 return ClassFinalizer::NewFinalizedMalformedType( | 9496 return ClassFinalizer::NewFinalizedMalformedType( |
| 9457 Error::Handle(), // No previous error. | 9497 Error::Handle(isolate()), // No previous error. |
| 9458 script_, | 9498 script_, |
| 9459 type_name.ident_pos, | 9499 type_name.ident_pos, |
| 9460 "using '%s' in this context is invalid", | 9500 "using '%s' in this context is invalid", |
| 9461 type_name.ident->ToCString()); | 9501 type_name.ident->ToCString()); |
| 9462 } | 9502 } |
| 9463 if ((type_name.lib_prefix != NULL) && | 9503 if ((type_name.lib_prefix != NULL) && |
| 9464 type_name.lib_prefix->is_deferred_load() && | 9504 type_name.lib_prefix->is_deferred_load() && |
| 9465 !allow_deferred_type) { | 9505 !allow_deferred_type) { |
| 9466 ParseTypeArguments(ClassFinalizer::kIgnore); | 9506 ParseTypeArguments(ClassFinalizer::kIgnore); |
| 9467 return ClassFinalizer::NewFinalizedMalformedType( | 9507 return ClassFinalizer::NewFinalizedMalformedType( |
| 9468 Error::Handle(), // No previous error. | 9508 Error::Handle(isolate()), // No previous error. |
| 9469 script_, | 9509 script_, |
| 9470 type_name.ident_pos, | 9510 type_name.ident_pos, |
| 9471 "using deferred type '%s.%s' is invalid", | 9511 "using deferred type '%s.%s' is invalid", |
| 9472 String::Handle(type_name.lib_prefix->name()).ToCString(), | 9512 String::Handle(isolate(), type_name.lib_prefix->name()).ToCString(), |
| 9473 type_name.ident->ToCString()); | 9513 type_name.ident->ToCString()); |
| 9474 } | 9514 } |
| 9475 } | 9515 } |
| 9476 Object& type_class = Object::Handle(isolate()); | 9516 Object& type_class = Object::Handle(isolate()); |
| 9477 // Leave type_class as null if type finalization mode is kIgnore. | 9517 // Leave type_class as null if type finalization mode is kIgnore. |
| 9478 if (finalization != ClassFinalizer::kIgnore) { | 9518 if (finalization != ClassFinalizer::kIgnore) { |
| 9479 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(isolate()); | 9519 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(isolate()); |
| 9480 if (type_name.lib_prefix != NULL) { | 9520 if (type_name.lib_prefix != NULL) { |
| 9481 lib_prefix = type_name.lib_prefix->raw(); | 9521 lib_prefix = type_name.lib_prefix->raw(); |
| 9482 } | 9522 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 9498 } | 9538 } |
| 9499 } | 9539 } |
| 9500 return type.raw(); | 9540 return type.raw(); |
| 9501 } | 9541 } |
| 9502 | 9542 |
| 9503 | 9543 |
| 9504 void Parser::CheckConstructorCallTypeArguments( | 9544 void Parser::CheckConstructorCallTypeArguments( |
| 9505 intptr_t pos, const Function& constructor, | 9545 intptr_t pos, const Function& constructor, |
| 9506 const TypeArguments& type_arguments) { | 9546 const TypeArguments& type_arguments) { |
| 9507 if (!type_arguments.IsNull()) { | 9547 if (!type_arguments.IsNull()) { |
| 9508 const Class& constructor_class = Class::Handle(constructor.Owner()); | 9548 const Class& constructor_class = Class::Handle(isolate(), |
| 9549 constructor.Owner()); | |
| 9509 ASSERT(!constructor_class.IsNull()); | 9550 ASSERT(!constructor_class.IsNull()); |
| 9510 ASSERT(constructor_class.is_finalized()); | 9551 ASSERT(constructor_class.is_finalized()); |
| 9511 ASSERT(type_arguments.IsCanonical()); | 9552 ASSERT(type_arguments.IsCanonical()); |
| 9512 // Do not report the expected vs. actual number of type arguments, because | 9553 // Do not report the expected vs. actual number of type arguments, because |
| 9513 // the type argument vector is flattened and raw types are allowed. | 9554 // the type argument vector is flattened and raw types are allowed. |
| 9514 if (type_arguments.Length() != constructor_class.NumTypeArguments()) { | 9555 if (type_arguments.Length() != constructor_class.NumTypeArguments()) { |
| 9515 ErrorMsg(pos, "wrong number of type arguments passed to constructor"); | 9556 ErrorMsg(pos, "wrong number of type arguments passed to constructor"); |
| 9516 } | 9557 } |
| 9517 } | 9558 } |
| 9518 } | 9559 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9555 if (FLAG_error_on_bad_type) { | 9596 if (FLAG_error_on_bad_type) { |
| 9556 ErrorMsg(type_pos, | 9597 ErrorMsg(type_pos, |
| 9557 "a list literal takes one type argument specifying " | 9598 "a list literal takes one type argument specifying " |
| 9558 "the element type"); | 9599 "the element type"); |
| 9559 } | 9600 } |
| 9560 // Ignore type arguments. | 9601 // Ignore type arguments. |
| 9561 list_type_arguments = TypeArguments::null(); | 9602 list_type_arguments = TypeArguments::null(); |
| 9562 } | 9603 } |
| 9563 } | 9604 } |
| 9564 ASSERT(list_type_arguments.IsNull() || (list_type_arguments.Length() == 1)); | 9605 ASSERT(list_type_arguments.IsNull() || (list_type_arguments.Length() == 1)); |
| 9565 const Class& array_class = Class::Handle( | 9606 const Class& array_class = Class::Handle(isolate(), |
| 9566 isolate()->object_store()->array_class()); | 9607 isolate()->object_store()->array_class()); |
| 9567 Type& type = Type::ZoneHandle( | 9608 Type& type = Type::ZoneHandle( |
| 9568 Type::New(array_class, list_type_arguments, type_pos)); | 9609 Type::New(array_class, list_type_arguments, type_pos)); |
| 9569 type ^= ClassFinalizer::FinalizeType( | 9610 type ^= ClassFinalizer::FinalizeType( |
| 9570 current_class(), type, ClassFinalizer::kCanonicalize); | 9611 current_class(), type, ClassFinalizer::kCanonicalize); |
| 9571 GrowableArray<AstNode*> element_list; | 9612 GrowableArray<AstNode*> element_list; |
| 9572 // Parse the list elements. Note: there may be an optional extra | 9613 // Parse the list elements. Note: there may be an optional extra |
| 9573 // comma after the last element. | 9614 // comma after the last element. |
| 9574 if (!is_empty_literal) { | 9615 if (!is_empty_literal) { |
| 9575 const bool saved_mode = SetAllowFunctionLiterals(true); | 9616 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 9576 while (CurrentToken() != Token::kRBRACK) { | 9617 while (CurrentToken() != Token::kRBRACK) { |
| 9577 const intptr_t element_pos = TokenPos(); | 9618 const intptr_t element_pos = TokenPos(); |
| 9578 AstNode* element = ParseExpr(is_const, kConsumeCascades); | 9619 AstNode* element = ParseExpr(is_const, kConsumeCascades); |
| 9579 if (FLAG_enable_type_checks && | 9620 if (FLAG_enable_type_checks && |
| 9580 !is_const && | 9621 !is_const && |
| 9581 !element_type.IsDynamicType()) { | 9622 !element_type.IsDynamicType()) { |
| 9582 element = new AssignableNode(element_pos, | 9623 element = new(isolate()) AssignableNode(element_pos, |
| 9583 element, | 9624 element, |
| 9584 element_type, | 9625 element_type, |
| 9585 Symbols::ListLiteralElement()); | 9626 Symbols::ListLiteralElement()); |
| 9586 } | 9627 } |
| 9587 element_list.Add(element); | 9628 element_list.Add(element); |
| 9588 if (CurrentToken() == Token::kCOMMA) { | 9629 if (CurrentToken() == Token::kCOMMA) { |
| 9589 ConsumeToken(); | 9630 ConsumeToken(); |
| 9590 } else if (CurrentToken() != Token::kRBRACK) { | 9631 } else if (CurrentToken() != Token::kRBRACK) { |
| 9591 ErrorMsg("comma or ']' expected"); | 9632 ErrorMsg("comma or ']' expected"); |
| 9592 } | 9633 } |
| 9593 } | 9634 } |
| 9594 ExpectToken(Token::kRBRACK); | 9635 ExpectToken(Token::kRBRACK); |
| 9595 SetAllowFunctionLiterals(saved_mode); | 9636 SetAllowFunctionLiterals(saved_mode); |
| 9596 } | 9637 } |
| 9597 | 9638 |
| 9598 if (is_const) { | 9639 if (is_const) { |
| 9599 // Allocate and initialize the const list at compile time. | 9640 // Allocate and initialize the const list at compile time. |
| 9600 Array& const_list = | 9641 Array& const_list = |
| 9601 Array::ZoneHandle(Array::New(element_list.length(), Heap::kOld)); | 9642 Array::ZoneHandle(Array::New(element_list.length(), Heap::kOld)); |
| 9602 const_list.SetTypeArguments( | 9643 const_list.SetTypeArguments( |
| 9603 TypeArguments::Handle(list_type_arguments.Canonicalize())); | 9644 TypeArguments::Handle(isolate(), list_type_arguments.Canonicalize())); |
| 9604 Error& malformed_error = Error::Handle(); | 9645 Error& malformed_error = Error::Handle(isolate()); |
| 9605 for (int i = 0; i < element_list.length(); i++) { | 9646 for (int i = 0; i < element_list.length(); i++) { |
| 9606 AstNode* elem = element_list[i]; | 9647 AstNode* elem = element_list[i]; |
| 9607 // Arguments have been evaluated to a literal value already. | 9648 // Arguments have been evaluated to a literal value already. |
| 9608 ASSERT(elem->IsLiteralNode()); | 9649 ASSERT(elem->IsLiteralNode()); |
| 9609 ASSERT(!is_top_level_); // We cannot check unresolved types. | 9650 ASSERT(!is_top_level_); // We cannot check unresolved types. |
| 9610 if (FLAG_enable_type_checks && | 9651 if (FLAG_enable_type_checks && |
| 9611 !element_type.IsDynamicType() && | 9652 !element_type.IsDynamicType() && |
| 9612 (!elem->AsLiteralNode()->literal().IsNull() && | 9653 (!elem->AsLiteralNode()->literal().IsNull() && |
| 9613 !elem->AsLiteralNode()->literal().IsInstanceOf( | 9654 !elem->AsLiteralNode()->literal().IsInstanceOf( |
| 9614 element_type, TypeArguments::Handle(), &malformed_error))) { | 9655 element_type, |
| 9656 TypeArguments::Handle(isolate()), | |
| 9657 &malformed_error))) { | |
| 9615 // If the failure is due to a malformed type error, display it instead. | 9658 // If the failure is due to a malformed type error, display it instead. |
| 9616 if (!malformed_error.IsNull()) { | 9659 if (!malformed_error.IsNull()) { |
| 9617 ErrorMsg(malformed_error); | 9660 ErrorMsg(malformed_error); |
| 9618 } else { | 9661 } else { |
| 9619 ErrorMsg(elem->AsLiteralNode()->token_pos(), | 9662 ErrorMsg(elem->AsLiteralNode()->token_pos(), |
| 9620 "list literal element at index %d must be " | 9663 "list literal element at index %d must be " |
| 9621 "a constant of type '%s'", | 9664 "a constant of type '%s'", |
| 9622 i, | 9665 i, |
| 9623 String::Handle(element_type.UserVisibleName()).ToCString()); | 9666 String::Handle(isolate(), |
| 9667 element_type.UserVisibleName()).ToCString()); | |
| 9624 } | 9668 } |
| 9625 } | 9669 } |
| 9626 const_list.SetAt(i, elem->AsLiteralNode()->literal()); | 9670 const_list.SetAt(i, elem->AsLiteralNode()->literal()); |
| 9627 } | 9671 } |
| 9628 const_list ^= TryCanonicalize(const_list, literal_pos); | 9672 const_list ^= TryCanonicalize(const_list, literal_pos); |
| 9629 const_list.MakeImmutable(); | 9673 const_list.MakeImmutable(); |
| 9630 return new LiteralNode(literal_pos, const_list); | 9674 return new(isolate()) LiteralNode(literal_pos, const_list); |
| 9631 } else { | 9675 } else { |
| 9632 // Factory call at runtime. | 9676 // Factory call at runtime. |
| 9633 const Class& factory_class = | 9677 const Class& factory_class = |
| 9634 Class::Handle(Library::LookupCoreClass(Symbols::List())); | 9678 Class::Handle(isolate(), Library::LookupCoreClass(Symbols::List())); |
| 9635 ASSERT(!factory_class.IsNull()); | 9679 ASSERT(!factory_class.IsNull()); |
| 9636 const Function& factory_method = Function::ZoneHandle( | 9680 const Function& factory_method = Function::ZoneHandle( |
| 9637 factory_class.LookupFactory( | 9681 factory_class.LookupFactory( |
| 9638 Library::PrivateCoreLibName(Symbols::ListLiteralFactory()))); | 9682 Library::PrivateCoreLibName(Symbols::ListLiteralFactory()))); |
| 9639 ASSERT(!factory_method.IsNull()); | 9683 ASSERT(!factory_method.IsNull()); |
| 9640 if (!list_type_arguments.IsNull() && | 9684 if (!list_type_arguments.IsNull() && |
| 9641 !list_type_arguments.IsInstantiated() && | 9685 !list_type_arguments.IsInstantiated() && |
| 9642 (current_block_->scope->function_level() > 0)) { | 9686 (current_block_->scope->function_level() > 0)) { |
| 9643 // Make sure that the instantiator is captured. | 9687 // Make sure that the instantiator is captured. |
| 9644 CaptureInstantiator(); | 9688 CaptureInstantiator(); |
| 9645 } | 9689 } |
| 9646 TypeArguments& factory_type_args = | 9690 TypeArguments& factory_type_args = |
| 9647 TypeArguments::ZoneHandle(list_type_arguments.raw()); | 9691 TypeArguments::ZoneHandle(list_type_arguments.raw()); |
| 9648 // If the factory class extends other parameterized classes, adjust the | 9692 // If the factory class extends other parameterized classes, adjust the |
| 9649 // type argument vector. | 9693 // type argument vector. |
| 9650 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 1)) { | 9694 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 1)) { |
| 9651 ASSERT(factory_type_args.Length() == 1); | 9695 ASSERT(factory_type_args.Length() == 1); |
| 9652 Type& factory_type = Type::Handle(Type::New( | 9696 Type& factory_type = Type::Handle(isolate(), Type::New( |
| 9653 factory_class, factory_type_args, type_pos, Heap::kNew)); | 9697 factory_class, factory_type_args, type_pos, Heap::kNew)); |
| 9654 factory_type ^= ClassFinalizer::FinalizeType( | 9698 factory_type ^= ClassFinalizer::FinalizeType( |
| 9655 current_class(), factory_type, ClassFinalizer::kFinalize); | 9699 current_class(), factory_type, ClassFinalizer::kFinalize); |
| 9656 factory_type_args = factory_type.arguments(); | 9700 factory_type_args = factory_type.arguments(); |
| 9657 ASSERT(factory_type_args.Length() == factory_class.NumTypeArguments()); | 9701 ASSERT(factory_type_args.Length() == factory_class.NumTypeArguments()); |
| 9658 } | 9702 } |
| 9659 factory_type_args = factory_type_args.Canonicalize(); | 9703 factory_type_args = factory_type_args.Canonicalize(); |
| 9660 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); | 9704 ArgumentListNode* factory_param = new(isolate()) ArgumentListNode( |
| 9705 literal_pos); | |
| 9661 if (element_list.length() == 0) { | 9706 if (element_list.length() == 0) { |
| 9662 // TODO(srdjan): Use Object::empty_array once issue 9871 has been fixed. | 9707 // TODO(srdjan): Use Object::empty_array once issue 9871 has been fixed. |
| 9663 Array& empty_array = Array::ZoneHandle(Object::empty_array().raw()); | 9708 Array& empty_array = Array::ZoneHandle(Object::empty_array().raw()); |
| 9664 LiteralNode* empty_array_literal = | 9709 LiteralNode* empty_array_literal = |
| 9665 new LiteralNode(TokenPos(), empty_array); | 9710 new(isolate()) LiteralNode(TokenPos(), empty_array); |
| 9666 factory_param->Add(empty_array_literal); | 9711 factory_param->Add(empty_array_literal); |
| 9667 } else { | 9712 } else { |
| 9668 ArrayNode* list = new ArrayNode(TokenPos(), type, element_list); | 9713 ArrayNode* list = new(isolate()) ArrayNode( |
| 9714 TokenPos(), type, element_list); | |
| 9669 factory_param->Add(list); | 9715 factory_param->Add(list); |
| 9670 } | 9716 } |
| 9671 return CreateConstructorCallNode(literal_pos, | 9717 return CreateConstructorCallNode(literal_pos, |
| 9672 factory_type_args, | 9718 factory_type_args, |
| 9673 factory_method, | 9719 factory_method, |
| 9674 factory_param); | 9720 factory_param); |
| 9675 } | 9721 } |
| 9676 } | 9722 } |
| 9677 | 9723 |
| 9678 | 9724 |
| 9679 ConstructorCallNode* Parser::CreateConstructorCallNode( | 9725 ConstructorCallNode* Parser::CreateConstructorCallNode( |
| 9680 intptr_t token_pos, | 9726 intptr_t token_pos, |
| 9681 const TypeArguments& type_arguments, | 9727 const TypeArguments& type_arguments, |
| 9682 const Function& constructor, | 9728 const Function& constructor, |
| 9683 ArgumentListNode* arguments) { | 9729 ArgumentListNode* arguments) { |
| 9684 if (!type_arguments.IsNull() && !type_arguments.IsInstantiated()) { | 9730 if (!type_arguments.IsNull() && !type_arguments.IsInstantiated()) { |
| 9685 EnsureExpressionTemp(); | 9731 EnsureExpressionTemp(); |
| 9686 } | 9732 } |
| 9687 return new ConstructorCallNode(token_pos, | 9733 return new(isolate()) ConstructorCallNode( |
| 9688 type_arguments, | 9734 token_pos, type_arguments, constructor, arguments); |
| 9689 constructor, | |
| 9690 arguments); | |
| 9691 } | 9735 } |
| 9692 | 9736 |
| 9693 | 9737 |
| 9694 static void AddKeyValuePair(GrowableArray<AstNode*>* pairs, | 9738 static void AddKeyValuePair(GrowableArray<AstNode*>* pairs, |
| 9695 bool is_const, | 9739 bool is_const, |
| 9696 AstNode* key, | 9740 AstNode* key, |
| 9697 AstNode* value) { | 9741 AstNode* value) { |
| 9698 if (is_const) { | 9742 if (is_const) { |
| 9699 ASSERT(key->IsLiteralNode()); | 9743 ASSERT(key->IsLiteralNode()); |
| 9700 const Instance& new_key = key->AsLiteralNode()->literal(); | 9744 const Instance& new_key = key->AsLiteralNode()->literal(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9765 GrowableArray<AstNode*> kv_pairs_list; | 9809 GrowableArray<AstNode*> kv_pairs_list; |
| 9766 // Parse the map entries. Note: there may be an optional extra | 9810 // Parse the map entries. Note: there may be an optional extra |
| 9767 // comma after the last entry. | 9811 // comma after the last entry. |
| 9768 while (CurrentToken() != Token::kRBRACE) { | 9812 while (CurrentToken() != Token::kRBRACE) { |
| 9769 const bool saved_mode = SetAllowFunctionLiterals(true); | 9813 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 9770 const intptr_t key_pos = TokenPos(); | 9814 const intptr_t key_pos = TokenPos(); |
| 9771 AstNode* key = ParseExpr(is_const, kConsumeCascades); | 9815 AstNode* key = ParseExpr(is_const, kConsumeCascades); |
| 9772 if (FLAG_enable_type_checks && | 9816 if (FLAG_enable_type_checks && |
| 9773 !is_const && | 9817 !is_const && |
| 9774 !key_type.IsDynamicType()) { | 9818 !key_type.IsDynamicType()) { |
| 9775 key = new AssignableNode(key_pos, | 9819 key = new(isolate()) AssignableNode( |
| 9776 key, | 9820 key_pos, key, key_type, Symbols::ListLiteralElement()); |
| 9777 key_type, | |
| 9778 Symbols::ListLiteralElement()); | |
| 9779 } | 9821 } |
| 9780 if (is_const) { | 9822 if (is_const) { |
| 9781 ASSERT(key->IsLiteralNode()); | 9823 ASSERT(key->IsLiteralNode()); |
| 9782 const Instance& key_value = key->AsLiteralNode()->literal(); | 9824 const Instance& key_value = key->AsLiteralNode()->literal(); |
| 9783 if (key_value.IsDouble()) { | 9825 if (key_value.IsDouble()) { |
| 9784 ErrorMsg(key_pos, "key value must not be of type double"); | 9826 ErrorMsg(key_pos, "key value must not be of type double"); |
| 9785 } | 9827 } |
| 9786 if (!key_value.IsInteger() && | 9828 if (!key_value.IsInteger() && |
| 9787 !key_value.IsString() && | 9829 !key_value.IsString() && |
| 9788 ImplementsEqualOperator(key_value)) { | 9830 ImplementsEqualOperator(key_value)) { |
| 9789 ErrorMsg(key_pos, "key value must not implement operator =="); | 9831 ErrorMsg(key_pos, "key value must not implement operator =="); |
| 9790 } | 9832 } |
| 9791 } | 9833 } |
| 9792 ExpectToken(Token::kCOLON); | 9834 ExpectToken(Token::kCOLON); |
| 9793 const intptr_t value_pos = TokenPos(); | 9835 const intptr_t value_pos = TokenPos(); |
| 9794 AstNode* value = ParseExpr(is_const, kConsumeCascades); | 9836 AstNode* value = ParseExpr(is_const, kConsumeCascades); |
| 9795 SetAllowFunctionLiterals(saved_mode); | 9837 SetAllowFunctionLiterals(saved_mode); |
| 9796 if (FLAG_enable_type_checks && | 9838 if (FLAG_enable_type_checks && |
| 9797 !is_const && | 9839 !is_const && |
| 9798 !value_type.IsDynamicType()) { | 9840 !value_type.IsDynamicType()) { |
| 9799 value = new AssignableNode(value_pos, | 9841 value = new(isolate()) AssignableNode( |
| 9800 value, | 9842 value_pos, value, value_type, Symbols::ListLiteralElement()); |
| 9801 value_type, | |
| 9802 Symbols::ListLiteralElement()); | |
| 9803 } | 9843 } |
| 9804 AddKeyValuePair(&kv_pairs_list, is_const, key, value); | 9844 AddKeyValuePair(&kv_pairs_list, is_const, key, value); |
| 9805 | 9845 |
| 9806 if (CurrentToken() == Token::kCOMMA) { | 9846 if (CurrentToken() == Token::kCOMMA) { |
| 9807 ConsumeToken(); | 9847 ConsumeToken(); |
| 9808 } else if (CurrentToken() != Token::kRBRACE) { | 9848 } else if (CurrentToken() != Token::kRBRACE) { |
| 9809 ErrorMsg("comma or '}' expected"); | 9849 ErrorMsg("comma or '}' expected"); |
| 9810 } | 9850 } |
| 9811 } | 9851 } |
| 9812 ASSERT(kv_pairs_list.length() % 2 == 0); | 9852 ASSERT(kv_pairs_list.length() % 2 == 0); |
| 9813 ExpectToken(Token::kRBRACE); | 9853 ExpectToken(Token::kRBRACE); |
| 9814 | 9854 |
| 9815 if (is_const) { | 9855 if (is_const) { |
| 9816 // Create the key-value pair array, canonicalize it and then create | 9856 // Create the key-value pair array, canonicalize it and then create |
| 9817 // the immutable map object with it. This all happens at compile time. | 9857 // the immutable map object with it. This all happens at compile time. |
| 9818 // The resulting immutable map object is returned as a literal. | 9858 // The resulting immutable map object is returned as a literal. |
| 9819 | 9859 |
| 9820 // First, create the canonicalized key-value pair array. | 9860 // First, create the canonicalized key-value pair array. |
| 9821 Array& key_value_array = | 9861 Array& key_value_array = |
| 9822 Array::ZoneHandle(Array::New(kv_pairs_list.length(), Heap::kOld)); | 9862 Array::ZoneHandle(Array::New(kv_pairs_list.length(), Heap::kOld)); |
| 9823 AbstractType& arg_type = Type::Handle(); | 9863 AbstractType& arg_type = Type::Handle(isolate()); |
| 9824 Error& malformed_error = Error::Handle(); | 9864 Error& malformed_error = Error::Handle(isolate()); |
| 9825 for (int i = 0; i < kv_pairs_list.length(); i++) { | 9865 for (int i = 0; i < kv_pairs_list.length(); i++) { |
| 9826 AstNode* arg = kv_pairs_list[i]; | 9866 AstNode* arg = kv_pairs_list[i]; |
| 9827 // Arguments have been evaluated to a literal value already. | 9867 // Arguments have been evaluated to a literal value already. |
| 9828 ASSERT(arg->IsLiteralNode()); | 9868 ASSERT(arg->IsLiteralNode()); |
| 9829 ASSERT(!is_top_level_); // We cannot check unresolved types. | 9869 ASSERT(!is_top_level_); // We cannot check unresolved types. |
| 9830 if (FLAG_enable_type_checks) { | 9870 if (FLAG_enable_type_checks) { |
| 9831 if ((i % 2) == 0) { | 9871 if ((i % 2) == 0) { |
| 9832 // Check key type. | 9872 // Check key type. |
| 9833 arg_type = key_type.raw(); | 9873 arg_type = key_type.raw(); |
| 9834 } else { | 9874 } else { |
| 9835 // Check value type. | 9875 // Check value type. |
| 9836 arg_type = value_type.raw(); | 9876 arg_type = value_type.raw(); |
| 9837 } | 9877 } |
| 9838 if (!arg_type.IsDynamicType() && | 9878 if (!arg_type.IsDynamicType() && |
| 9839 (!arg->AsLiteralNode()->literal().IsNull() && | 9879 (!arg->AsLiteralNode()->literal().IsNull() && |
| 9840 !arg->AsLiteralNode()->literal().IsInstanceOf( | 9880 !arg->AsLiteralNode()->literal().IsInstanceOf( |
| 9841 arg_type, | 9881 arg_type, |
| 9842 Object::null_type_arguments(), | 9882 Object::null_type_arguments(), |
| 9843 &malformed_error))) { | 9883 &malformed_error))) { |
| 9844 // If the failure is due to a malformed type error, display it. | 9884 // If the failure is due to a malformed type error, display it. |
| 9845 if (!malformed_error.IsNull()) { | 9885 if (!malformed_error.IsNull()) { |
| 9846 ErrorMsg(malformed_error); | 9886 ErrorMsg(malformed_error); |
| 9847 } else { | 9887 } else { |
| 9848 ErrorMsg(arg->AsLiteralNode()->token_pos(), | 9888 ErrorMsg(arg->AsLiteralNode()->token_pos(), |
| 9849 "map literal %s at index %d must be " | 9889 "map literal %s at index %d must be " |
| 9850 "a constant of type '%s'", | 9890 "a constant of type '%s'", |
| 9851 ((i % 2) == 0) ? "key" : "value", | 9891 ((i % 2) == 0) ? "key" : "value", |
| 9852 i >> 1, | 9892 i >> 1, |
| 9853 String::Handle(arg_type.UserVisibleName()).ToCString()); | 9893 String::Handle(isolate(), |
| 9894 arg_type.UserVisibleName()).ToCString()); | |
| 9854 } | 9895 } |
| 9855 } | 9896 } |
| 9856 } | 9897 } |
| 9857 key_value_array.SetAt(i, arg->AsLiteralNode()->literal()); | 9898 key_value_array.SetAt(i, arg->AsLiteralNode()->literal()); |
| 9858 } | 9899 } |
| 9859 key_value_array ^= TryCanonicalize(key_value_array, TokenPos()); | 9900 key_value_array ^= TryCanonicalize(key_value_array, TokenPos()); |
| 9860 key_value_array.MakeImmutable(); | 9901 key_value_array.MakeImmutable(); |
| 9861 | 9902 |
| 9862 // Construct the map object. | 9903 // Construct the map object. |
| 9863 const Class& immutable_map_class = | 9904 const Class& immutable_map_class = Class::Handle(isolate(), |
| 9864 Class::Handle(Library::LookupCoreClass(Symbols::ImmutableMap())); | 9905 Library::LookupCoreClass(Symbols::ImmutableMap())); |
| 9865 ASSERT(!immutable_map_class.IsNull()); | 9906 ASSERT(!immutable_map_class.IsNull()); |
| 9866 // If the immutable map class extends other parameterized classes, we need | 9907 // If the immutable map class extends other parameterized classes, we need |
| 9867 // to adjust the type argument vector. This is currently not the case. | 9908 // to adjust the type argument vector. This is currently not the case. |
| 9868 ASSERT(immutable_map_class.NumTypeArguments() == 2); | 9909 ASSERT(immutable_map_class.NumTypeArguments() == 2); |
| 9869 ArgumentListNode* constr_args = new ArgumentListNode(TokenPos()); | 9910 ArgumentListNode* constr_args = new(isolate()) ArgumentListNode(TokenPos()); |
| 9870 constr_args->Add(new LiteralNode(literal_pos, key_value_array)); | 9911 constr_args->Add(new(isolate()) LiteralNode(literal_pos, key_value_array)); |
| 9871 const Function& map_constr = | 9912 const Function& map_constr = |
| 9872 Function::ZoneHandle(immutable_map_class.LookupConstructor( | 9913 Function::ZoneHandle(immutable_map_class.LookupConstructor( |
| 9873 Library::PrivateCoreLibName(Symbols::ImmutableMapConstructor()))); | 9914 Library::PrivateCoreLibName(Symbols::ImmutableMapConstructor()))); |
| 9874 ASSERT(!map_constr.IsNull()); | 9915 ASSERT(!map_constr.IsNull()); |
| 9875 const Object& constructor_result = Object::Handle( | 9916 const Object& constructor_result = Object::Handle(isolate(), |
| 9876 EvaluateConstConstructorCall(immutable_map_class, | 9917 EvaluateConstConstructorCall(immutable_map_class, |
| 9877 map_type_arguments, | 9918 map_type_arguments, |
| 9878 map_constr, | 9919 map_constr, |
| 9879 constr_args)); | 9920 constr_args)); |
| 9880 if (constructor_result.IsUnhandledException()) { | 9921 if (constructor_result.IsUnhandledException()) { |
| 9881 AppendErrorMsg(Error::Cast(constructor_result), | 9922 AppendErrorMsg(Error::Cast(constructor_result), |
| 9882 literal_pos, | 9923 literal_pos, |
| 9883 "error executing const Map constructor"); | 9924 "error executing const Map constructor"); |
| 9884 } else { | 9925 } else { |
| 9885 const Instance& const_instance = Instance::Cast(constructor_result); | 9926 const Instance& const_instance = Instance::Cast(constructor_result); |
| 9886 return new LiteralNode(literal_pos, | 9927 return new(isolate()) LiteralNode( |
| 9887 Instance::ZoneHandle(const_instance.raw())); | 9928 literal_pos, Instance::ZoneHandle(const_instance.raw())); |
| 9888 } | 9929 } |
| 9889 } else { | 9930 } else { |
| 9890 // Factory call at runtime. | 9931 // Factory call at runtime. |
| 9891 const Class& factory_class = | 9932 const Class& factory_class = |
| 9892 Class::Handle(Library::LookupCoreClass(Symbols::Map())); | 9933 Class::Handle(isolate(), Library::LookupCoreClass(Symbols::Map())); |
| 9893 ASSERT(!factory_class.IsNull()); | 9934 ASSERT(!factory_class.IsNull()); |
| 9894 const Function& factory_method = Function::ZoneHandle( | 9935 const Function& factory_method = Function::ZoneHandle( |
| 9895 factory_class.LookupFactory( | 9936 factory_class.LookupFactory( |
| 9896 Library::PrivateCoreLibName(Symbols::MapLiteralFactory()))); | 9937 Library::PrivateCoreLibName(Symbols::MapLiteralFactory()))); |
| 9897 ASSERT(!factory_method.IsNull()); | 9938 ASSERT(!factory_method.IsNull()); |
| 9898 if (!map_type_arguments.IsNull() && | 9939 if (!map_type_arguments.IsNull() && |
| 9899 !map_type_arguments.IsInstantiated() && | 9940 !map_type_arguments.IsInstantiated() && |
| 9900 (current_block_->scope->function_level() > 0)) { | 9941 (current_block_->scope->function_level() > 0)) { |
| 9901 // Make sure that the instantiator is captured. | 9942 // Make sure that the instantiator is captured. |
| 9902 CaptureInstantiator(); | 9943 CaptureInstantiator(); |
| 9903 } | 9944 } |
| 9904 TypeArguments& factory_type_args = | 9945 TypeArguments& factory_type_args = |
| 9905 TypeArguments::ZoneHandle(map_type_arguments.raw()); | 9946 TypeArguments::ZoneHandle(map_type_arguments.raw()); |
| 9906 // If the factory class extends other parameterized classes, adjust the | 9947 // If the factory class extends other parameterized classes, adjust the |
| 9907 // type argument vector. | 9948 // type argument vector. |
| 9908 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 2)) { | 9949 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 2)) { |
| 9909 ASSERT(factory_type_args.Length() == 2); | 9950 ASSERT(factory_type_args.Length() == 2); |
| 9910 Type& factory_type = Type::Handle(Type::New( | 9951 Type& factory_type = Type::Handle(isolate(), Type::New( |
| 9911 factory_class, factory_type_args, type_pos, Heap::kNew)); | 9952 factory_class, factory_type_args, type_pos, Heap::kNew)); |
| 9912 factory_type ^= ClassFinalizer::FinalizeType( | 9953 factory_type ^= ClassFinalizer::FinalizeType( |
| 9913 current_class(), factory_type, ClassFinalizer::kFinalize); | 9954 current_class(), factory_type, ClassFinalizer::kFinalize); |
| 9914 factory_type_args = factory_type.arguments(); | 9955 factory_type_args = factory_type.arguments(); |
| 9915 ASSERT(factory_type_args.Length() == factory_class.NumTypeArguments()); | 9956 ASSERT(factory_type_args.Length() == factory_class.NumTypeArguments()); |
| 9916 } | 9957 } |
| 9917 factory_type_args = factory_type_args.Canonicalize(); | 9958 factory_type_args = factory_type_args.Canonicalize(); |
| 9918 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); | 9959 ArgumentListNode* factory_param = |
| 9960 new(isolate()) ArgumentListNode(literal_pos); | |
| 9919 // The kv_pair array is temporary and of element type dynamic. It is passed | 9961 // The kv_pair array is temporary and of element type dynamic. It is passed |
| 9920 // to the factory to initialize a properly typed map. | 9962 // to the factory to initialize a properly typed map. |
| 9921 ArrayNode* kv_pairs = new ArrayNode( | 9963 ArrayNode* kv_pairs = new(isolate()) ArrayNode( |
| 9922 TokenPos(), | 9964 TokenPos(), |
| 9923 Type::ZoneHandle(Type::ArrayType()), | 9965 Type::ZoneHandle(Type::ArrayType()), |
| 9924 kv_pairs_list); | 9966 kv_pairs_list); |
| 9925 factory_param->Add(kv_pairs); | 9967 factory_param->Add(kv_pairs); |
| 9926 return CreateConstructorCallNode(literal_pos, | 9968 return CreateConstructorCallNode(literal_pos, |
| 9927 factory_type_args, | 9969 factory_type_args, |
| 9928 factory_method, | 9970 factory_method, |
| 9929 factory_param); | 9971 factory_param); |
| 9930 } | 9972 } |
| 9931 UNREACHABLE(); | 9973 UNREACHABLE(); |
| 9932 return NULL; | 9974 return NULL; |
| 9933 } | 9975 } |
| 9934 | 9976 |
| 9935 | 9977 |
| 9936 AstNode* Parser::ParseCompoundLiteral() { | 9978 AstNode* Parser::ParseCompoundLiteral() { |
| 9937 TRACE_PARSER("ParseCompoundLiteral"); | 9979 TRACE_PARSER("ParseCompoundLiteral"); |
| 9938 bool is_const = false; | 9980 bool is_const = false; |
| 9939 if (CurrentToken() == Token::kCONST) { | 9981 if (CurrentToken() == Token::kCONST) { |
| 9940 is_const = true; | 9982 is_const = true; |
| 9941 ConsumeToken(); | 9983 ConsumeToken(); |
| 9942 } | 9984 } |
| 9943 const intptr_t type_pos = TokenPos(); | 9985 const intptr_t type_pos = TokenPos(); |
| 9944 TypeArguments& type_arguments = TypeArguments::Handle( | 9986 TypeArguments& type_arguments = TypeArguments::Handle(isolate(), |
| 9945 ParseTypeArguments(ClassFinalizer::kCanonicalize)); | 9987 ParseTypeArguments(ClassFinalizer::kCanonicalize)); |
| 9946 // Malformed type arguments are mapped to dynamic, so we will not encounter | 9988 // Malformed type arguments are mapped to dynamic, so we will not encounter |
| 9947 // them here. | 9989 // them here. |
| 9948 // Map and List interfaces do not declare bounds on their type parameters, so | 9990 // Map and List interfaces do not declare bounds on their type parameters, so |
| 9949 // we will not see malbounded type arguments here. | 9991 // we will not see malbounded type arguments here. |
| 9950 AstNode* primary = NULL; | 9992 AstNode* primary = NULL; |
| 9951 if ((CurrentToken() == Token::kLBRACK) || | 9993 if ((CurrentToken() == Token::kLBRACK) || |
| 9952 (CurrentToken() == Token::kINDEX)) { | 9994 (CurrentToken() == Token::kINDEX)) { |
| 9953 primary = ParseListLiteral(type_pos, is_const, type_arguments); | 9995 primary = ParseListLiteral(type_pos, is_const, type_arguments); |
| 9954 } else if (CurrentToken() == Token::kLBRACE) { | 9996 } else if (CurrentToken() == Token::kLBRACE) { |
| 9955 primary = ParseMapLiteral(type_pos, is_const, type_arguments); | 9997 primary = ParseMapLiteral(type_pos, is_const, type_arguments); |
| 9956 } else { | 9998 } else { |
| 9957 ErrorMsg("unexpected token %s", Token::Str(CurrentToken())); | 9999 ErrorMsg("unexpected token %s", Token::Str(CurrentToken())); |
| 9958 } | 10000 } |
| 9959 return primary; | 10001 return primary; |
| 9960 } | 10002 } |
| 9961 | 10003 |
| 9962 | 10004 |
| 9963 AstNode* Parser::ParseSymbolLiteral() { | 10005 AstNode* Parser::ParseSymbolLiteral() { |
| 9964 ASSERT(CurrentToken() == Token::kHASH); | 10006 ASSERT(CurrentToken() == Token::kHASH); |
| 9965 ConsumeToken(); | 10007 ConsumeToken(); |
| 9966 intptr_t symbol_pos = TokenPos(); | 10008 intptr_t symbol_pos = TokenPos(); |
| 9967 String& symbol = String::Handle(); | 10009 String& symbol = String::Handle(isolate()); |
| 9968 if (IsIdentifier()) { | 10010 if (IsIdentifier()) { |
| 9969 symbol = CurrentLiteral()->raw(); | 10011 symbol = CurrentLiteral()->raw(); |
| 9970 ConsumeToken(); | 10012 ConsumeToken(); |
| 9971 while (CurrentToken() == Token::kPERIOD) { | 10013 while (CurrentToken() == Token::kPERIOD) { |
| 9972 symbol = String::Concat(symbol, Symbols::Dot()); | 10014 symbol = String::Concat(symbol, Symbols::Dot()); |
| 9973 ConsumeToken(); | 10015 ConsumeToken(); |
| 9974 symbol = String::Concat(symbol, | 10016 symbol = String::Concat(symbol, |
| 9975 *ExpectIdentifier("identifier expected")); | 10017 *ExpectIdentifier("identifier expected")); |
| 9976 } | 10018 } |
| 9977 } else if (Token::CanBeOverloaded(CurrentToken())) { | 10019 } else if (Token::CanBeOverloaded(CurrentToken())) { |
| 9978 symbol = String::New(Token::Str(CurrentToken())); | 10020 symbol = String::New(Token::Str(CurrentToken())); |
| 9979 ConsumeToken(); | 10021 ConsumeToken(); |
| 9980 } else { | 10022 } else { |
| 9981 ErrorMsg("illegal symbol literal"); | 10023 ErrorMsg("illegal symbol literal"); |
| 9982 } | 10024 } |
| 9983 // Lookup class Symbol from internal library and call the | 10025 // Lookup class Symbol from internal library and call the |
| 9984 // constructor to create a symbol instance. | 10026 // constructor to create a symbol instance. |
| 9985 const Library& lib = Library::Handle(Library::InternalLibrary()); | 10027 const Library& lib = Library::Handle(isolate(), Library::InternalLibrary()); |
| 9986 const Class& symbol_class = Class::Handle(lib.LookupClass(Symbols::Symbol())); | 10028 const Class& symbol_class = Class::Handle(isolate(), |
| 10029 lib.LookupClass(Symbols::Symbol())); | |
| 9987 ASSERT(!symbol_class.IsNull()); | 10030 ASSERT(!symbol_class.IsNull()); |
| 9988 ArgumentListNode* constr_args = new ArgumentListNode(symbol_pos); | 10031 ArgumentListNode* constr_args = new(isolate()) ArgumentListNode(symbol_pos); |
| 9989 constr_args->Add(new LiteralNode( | 10032 constr_args->Add(new(isolate()) LiteralNode( |
| 9990 symbol_pos, String::ZoneHandle(Symbols::New(symbol)))); | 10033 symbol_pos, String::ZoneHandle(Symbols::New(symbol)))); |
| 9991 const Function& constr = Function::ZoneHandle( | 10034 const Function& constr = Function::ZoneHandle( |
| 9992 symbol_class.LookupConstructor(Symbols::SymbolCtor())); | 10035 symbol_class.LookupConstructor(Symbols::SymbolCtor())); |
| 9993 ASSERT(!constr.IsNull()); | 10036 ASSERT(!constr.IsNull()); |
| 9994 const Object& result = Object::Handle( | 10037 const Object& result = Object::Handle(isolate(), |
| 9995 EvaluateConstConstructorCall(symbol_class, | 10038 EvaluateConstConstructorCall(symbol_class, |
| 9996 TypeArguments::Handle(), | 10039 TypeArguments::Handle(isolate()), |
| 9997 constr, | 10040 constr, |
| 9998 constr_args)); | 10041 constr_args)); |
| 9999 if (result.IsUnhandledException()) { | 10042 if (result.IsUnhandledException()) { |
| 10000 AppendErrorMsg(Error::Cast(result), | 10043 AppendErrorMsg(Error::Cast(result), |
| 10001 symbol_pos, | 10044 symbol_pos, |
| 10002 "error executing const Symbol constructor"); | 10045 "error executing const Symbol constructor"); |
| 10003 } | 10046 } |
| 10004 const Instance& instance = Instance::Cast(result); | 10047 const Instance& instance = Instance::Cast(result); |
| 10005 return new LiteralNode(symbol_pos, Instance::ZoneHandle(instance.raw())); | 10048 return new(isolate()) LiteralNode(symbol_pos, |
| 10049 Instance::ZoneHandle(instance.raw())); | |
| 10006 } | 10050 } |
| 10007 | 10051 |
| 10008 | 10052 |
| 10009 static String& BuildConstructorName(const String& type_class_name, | 10053 static String& BuildConstructorName(const String& type_class_name, |
| 10010 const String* named_constructor) { | 10054 const String* named_constructor) { |
| 10011 // By convention, the static function implementing a named constructor 'C' | 10055 // By convention, the static function implementing a named constructor 'C' |
| 10012 // for class 'A' is labeled 'A.C', and the static function implementing the | 10056 // for class 'A' is labeled 'A.C', and the static function implementing the |
| 10013 // unnamed constructor for class 'A' is labeled 'A.'. | 10057 // unnamed constructor for class 'A' is labeled 'A.'. |
| 10014 // This convention prevents users from explicitly calling constructors. | 10058 // This convention prevents users from explicitly calling constructors. |
| 10015 String& constructor_name = | 10059 String& constructor_name = |
| 10016 String::Handle(String::Concat(type_class_name, Symbols::Dot())); | 10060 String::Handle(String::Concat(type_class_name, Symbols::Dot())); |
| 10017 if (named_constructor != NULL) { | 10061 if (named_constructor != NULL) { |
| 10018 constructor_name = String::Concat(constructor_name, *named_constructor); | 10062 constructor_name = String::Concat(constructor_name, *named_constructor); |
| 10019 } | 10063 } |
| 10020 return constructor_name; | 10064 return constructor_name; |
| 10021 } | 10065 } |
| 10022 | 10066 |
| 10023 | 10067 |
| 10024 AstNode* Parser::ParseNewOperator(Token::Kind op_kind) { | 10068 AstNode* Parser::ParseNewOperator(Token::Kind op_kind) { |
| 10025 TRACE_PARSER("ParseNewOperator"); | 10069 TRACE_PARSER("ParseNewOperator"); |
| 10026 const intptr_t new_pos = TokenPos(); | 10070 const intptr_t new_pos = TokenPos(); |
| 10027 ASSERT((op_kind == Token::kNEW) || (op_kind == Token::kCONST)); | 10071 ASSERT((op_kind == Token::kNEW) || (op_kind == Token::kCONST)); |
| 10028 bool is_const = (op_kind == Token::kCONST); | 10072 bool is_const = (op_kind == Token::kCONST); |
| 10029 if (!IsIdentifier()) { | 10073 if (!IsIdentifier()) { |
| 10030 ErrorMsg("type name expected"); | 10074 ErrorMsg("type name expected"); |
| 10031 } | 10075 } |
| 10032 intptr_t type_pos = TokenPos(); | 10076 intptr_t type_pos = TokenPos(); |
| 10033 // Can't allocate const objects of a deferred type. | 10077 // Can't allocate const objects of a deferred type. |
| 10034 const bool allow_deferred_type = !is_const; | 10078 const bool allow_deferred_type = !is_const; |
| 10035 AbstractType& type = AbstractType::Handle( | 10079 AbstractType& type = AbstractType::Handle(isolate(), |
| 10036 ParseType(ClassFinalizer::kCanonicalizeWellFormed, allow_deferred_type)); | 10080 ParseType(ClassFinalizer::kCanonicalizeWellFormed, allow_deferred_type)); |
| 10037 // In case the type is malformed, throw a dynamic type error after finishing | 10081 // In case the type is malformed, throw a dynamic type error after finishing |
| 10038 // parsing the instance creation expression. | 10082 // parsing the instance creation expression. |
| 10039 if (!type.IsMalformed() && (type.IsTypeParameter() || type.IsDynamicType())) { | 10083 if (!type.IsMalformed() && (type.IsTypeParameter() || type.IsDynamicType())) { |
| 10040 // Replace the type with a malformed type. | 10084 // Replace the type with a malformed type. |
| 10041 type = ClassFinalizer::NewFinalizedMalformedType( | 10085 type = ClassFinalizer::NewFinalizedMalformedType( |
| 10042 Error::Handle(), // No previous error. | 10086 Error::Handle(isolate()), // No previous error. |
| 10043 script_, | 10087 script_, |
| 10044 type_pos, | 10088 type_pos, |
| 10045 "%s'%s' cannot be instantiated", | 10089 "%s'%s' cannot be instantiated", |
| 10046 type.IsTypeParameter() ? "type parameter " : "", | 10090 type.IsTypeParameter() ? "type parameter " : "", |
| 10047 type.IsTypeParameter() ? | 10091 type.IsTypeParameter() ? |
| 10048 String::Handle(type.UserVisibleName()).ToCString() : "dynamic"); | 10092 String::Handle(isolate(), type.UserVisibleName()).ToCString() : |
| 10093 "dynamic"); | |
| 10049 } | 10094 } |
| 10050 | 10095 |
| 10051 // The grammar allows for an optional ('.' identifier)? after the type, which | 10096 // The grammar allows for an optional ('.' identifier)? after the type, which |
| 10052 // is a named constructor. Note that ParseType() above will not consume it as | 10097 // is a named constructor. Note that ParseType() above will not consume it as |
| 10053 // part of a misinterpreted qualified identifier, because only a valid library | 10098 // part of a misinterpreted qualified identifier, because only a valid library |
| 10054 // prefix is accepted as qualifier. | 10099 // prefix is accepted as qualifier. |
| 10055 String* named_constructor = NULL; | 10100 String* named_constructor = NULL; |
| 10056 if (CurrentToken() == Token::kPERIOD) { | 10101 if (CurrentToken() == Token::kPERIOD) { |
| 10057 ConsumeToken(); | 10102 ConsumeToken(); |
| 10058 named_constructor = ExpectIdentifier("name of constructor expected"); | 10103 named_constructor = ExpectIdentifier("name of constructor expected"); |
| 10059 } | 10104 } |
| 10060 | 10105 |
| 10061 // Parse constructor parameters. | 10106 // Parse constructor parameters. |
| 10062 CheckToken(Token::kLPAREN); | 10107 CheckToken(Token::kLPAREN); |
| 10063 intptr_t call_pos = TokenPos(); | 10108 intptr_t call_pos = TokenPos(); |
| 10064 ArgumentListNode* arguments = ParseActualParameters(NULL, is_const); | 10109 ArgumentListNode* arguments = ParseActualParameters(NULL, is_const); |
| 10065 | 10110 |
| 10066 // Parsing is complete, so we can return a throw in case of a malformed or | 10111 // Parsing is complete, so we can return a throw in case of a malformed or |
| 10067 // malbounded type or report a compile-time error if the constructor is const. | 10112 // malbounded type or report a compile-time error if the constructor is const. |
| 10068 if (type.IsMalformedOrMalbounded()) { | 10113 if (type.IsMalformedOrMalbounded()) { |
| 10069 if (is_const) { | 10114 if (is_const) { |
| 10070 const Error& error = Error::Handle(type.error()); | 10115 const Error& error = Error::Handle(isolate(), type.error()); |
| 10071 ErrorMsg(error); | 10116 ErrorMsg(error); |
| 10072 } | 10117 } |
| 10073 return ThrowTypeError(type_pos, type); | 10118 return ThrowTypeError(type_pos, type); |
| 10074 } | 10119 } |
| 10075 | 10120 |
| 10076 // Resolve the type and optional identifier to a constructor or factory. | 10121 // Resolve the type and optional identifier to a constructor or factory. |
| 10077 Class& type_class = Class::Handle(type.type_class()); | 10122 Class& type_class = Class::Handle(isolate(), type.type_class()); |
| 10078 String& type_class_name = String::Handle(type_class.Name()); | 10123 String& type_class_name = String::Handle(isolate(), type_class.Name()); |
| 10079 TypeArguments& type_arguments = | 10124 TypeArguments& type_arguments = |
| 10080 TypeArguments::ZoneHandle(type.arguments()); | 10125 TypeArguments::ZoneHandle(type.arguments()); |
| 10081 | 10126 |
| 10082 // A constructor has an implicit 'this' parameter (instance to construct) | 10127 // A constructor has an implicit 'this' parameter (instance to construct) |
| 10083 // and a factory has an implicit 'this' parameter (type_arguments). | 10128 // and a factory has an implicit 'this' parameter (type_arguments). |
| 10084 // A constructor has a second implicit 'phase' parameter. | 10129 // A constructor has a second implicit 'phase' parameter. |
| 10085 intptr_t arguments_length = arguments->length() + 2; | 10130 intptr_t arguments_length = arguments->length() + 2; |
| 10086 | 10131 |
| 10087 // An additional type check of the result of a redirecting factory may be | 10132 // An additional type check of the result of a redirecting factory may be |
| 10088 // required. | 10133 // required. |
| 10089 AbstractType& type_bound = AbstractType::ZoneHandle(); | 10134 AbstractType& type_bound = AbstractType::ZoneHandle(); |
| 10090 | 10135 |
| 10091 // Make sure that an appropriate constructor exists. | 10136 // Make sure that an appropriate constructor exists. |
| 10092 String& constructor_name = | 10137 String& constructor_name = |
| 10093 BuildConstructorName(type_class_name, named_constructor); | 10138 BuildConstructorName(type_class_name, named_constructor); |
| 10094 Function& constructor = Function::ZoneHandle( | 10139 Function& constructor = Function::ZoneHandle( |
| 10095 type_class.LookupConstructor(constructor_name)); | 10140 type_class.LookupConstructor(constructor_name)); |
| 10096 if (constructor.IsNull()) { | 10141 if (constructor.IsNull()) { |
| 10097 constructor = type_class.LookupFactory(constructor_name); | 10142 constructor = type_class.LookupFactory(constructor_name); |
| 10098 if (constructor.IsNull()) { | 10143 if (constructor.IsNull()) { |
| 10099 const String& external_constructor_name = | 10144 const String& external_constructor_name = |
| 10100 (named_constructor ? constructor_name : type_class_name); | 10145 (named_constructor ? constructor_name : type_class_name); |
| 10101 // Replace the type with a malformed type and compile a throw or report a | 10146 // Replace the type with a malformed type and compile a throw or report a |
| 10102 // compile-time error if the constructor is const. | 10147 // compile-time error if the constructor is const. |
| 10103 if (is_const) { | 10148 if (is_const) { |
| 10104 type = ClassFinalizer::NewFinalizedMalformedType( | 10149 type = ClassFinalizer::NewFinalizedMalformedType( |
| 10105 Error::Handle(), // No previous error. | 10150 Error::Handle(isolate()), // No previous error. |
| 10106 script_, | 10151 script_, |
| 10107 call_pos, | 10152 call_pos, |
| 10108 "class '%s' has no constructor or factory named '%s'", | 10153 "class '%s' has no constructor or factory named '%s'", |
| 10109 String::Handle(type_class.Name()).ToCString(), | 10154 String::Handle(isolate(), type_class.Name()).ToCString(), |
| 10110 external_constructor_name.ToCString()); | 10155 external_constructor_name.ToCString()); |
| 10111 ErrorMsg(Error::Handle(type.error())); | 10156 ErrorMsg(Error::Handle(isolate(), type.error())); |
| 10112 } | 10157 } |
| 10113 return ThrowNoSuchMethodError(call_pos, | 10158 return ThrowNoSuchMethodError(call_pos, |
| 10114 type_class, | 10159 type_class, |
| 10115 external_constructor_name, | 10160 external_constructor_name, |
| 10116 arguments, | 10161 arguments, |
| 10117 InvocationMirror::kConstructor, | 10162 InvocationMirror::kConstructor, |
| 10118 InvocationMirror::kMethod, | 10163 InvocationMirror::kMethod, |
| 10119 &constructor); | 10164 &constructor); |
| 10120 } else if (constructor.IsRedirectingFactory()) { | 10165 } else if (constructor.IsRedirectingFactory()) { |
| 10121 ClassFinalizer::ResolveRedirectingFactory(type_class, constructor); | 10166 ClassFinalizer::ResolveRedirectingFactory(type_class, constructor); |
| 10122 Type& redirect_type = Type::Handle(constructor.RedirectionType()); | 10167 Type& redirect_type = Type::Handle(isolate(), |
| 10168 constructor.RedirectionType()); | |
| 10123 if (!redirect_type.IsMalformedOrMalbounded() && | 10169 if (!redirect_type.IsMalformedOrMalbounded() && |
| 10124 !redirect_type.IsInstantiated()) { | 10170 !redirect_type.IsInstantiated()) { |
| 10125 // The type arguments of the redirection type are instantiated from the | 10171 // The type arguments of the redirection type are instantiated from the |
| 10126 // type arguments of the parsed type of the 'new' or 'const' expression. | 10172 // type arguments of the parsed type of the 'new' or 'const' expression. |
| 10127 Error& error = Error::Handle(); | 10173 Error& error = Error::Handle(isolate()); |
| 10128 redirect_type ^= redirect_type.InstantiateFrom(type_arguments, &error); | 10174 redirect_type ^= redirect_type.InstantiateFrom(type_arguments, &error); |
| 10129 if (!error.IsNull()) { | 10175 if (!error.IsNull()) { |
| 10130 redirect_type = ClassFinalizer::NewFinalizedMalformedType( | 10176 redirect_type = ClassFinalizer::NewFinalizedMalformedType( |
| 10131 error, | 10177 error, |
| 10132 script_, | 10178 script_, |
| 10133 call_pos, | 10179 call_pos, |
| 10134 "redirecting factory type '%s' cannot be instantiated", | 10180 "redirecting factory type '%s' cannot be instantiated", |
| 10135 String::Handle(redirect_type.UserVisibleName()).ToCString()); | 10181 String::Handle(isolate(), |
| 10182 redirect_type.UserVisibleName()).ToCString()); | |
| 10136 } | 10183 } |
| 10137 } | 10184 } |
| 10138 if (redirect_type.IsMalformedOrMalbounded()) { | 10185 if (redirect_type.IsMalformedOrMalbounded()) { |
| 10139 if (is_const) { | 10186 if (is_const) { |
| 10140 ErrorMsg(Error::Handle(redirect_type.error())); | 10187 ErrorMsg(Error::Handle(isolate(), redirect_type.error())); |
| 10141 } | 10188 } |
| 10142 return ThrowTypeError(redirect_type.token_pos(), redirect_type); | 10189 return ThrowTypeError(redirect_type.token_pos(), redirect_type); |
| 10143 } | 10190 } |
| 10144 if (FLAG_enable_type_checks && !redirect_type.IsSubtypeOf(type, NULL)) { | 10191 if (FLAG_enable_type_checks && !redirect_type.IsSubtypeOf(type, NULL)) { |
| 10145 // Additional type checking of the result is necessary. | 10192 // Additional type checking of the result is necessary. |
| 10146 type_bound = type.raw(); | 10193 type_bound = type.raw(); |
| 10147 } | 10194 } |
| 10148 type = redirect_type.raw(); | 10195 type = redirect_type.raw(); |
| 10149 type_class = type.type_class(); | 10196 type_class = type.type_class(); |
| 10150 type_class_name = type_class.Name(); | 10197 type_class_name = type_class.Name(); |
| 10151 type_arguments = type.arguments(); | 10198 type_arguments = type.arguments(); |
| 10152 constructor = constructor.RedirectionTarget(); | 10199 constructor = constructor.RedirectionTarget(); |
| 10153 constructor_name = constructor.name(); | 10200 constructor_name = constructor.name(); |
| 10154 ASSERT(!constructor.IsNull()); | 10201 ASSERT(!constructor.IsNull()); |
| 10155 } | 10202 } |
| 10156 if (constructor.IsFactory()) { | 10203 if (constructor.IsFactory()) { |
| 10157 // A factory does not have the implicit 'phase' parameter. | 10204 // A factory does not have the implicit 'phase' parameter. |
| 10158 arguments_length -= 1; | 10205 arguments_length -= 1; |
| 10159 } | 10206 } |
| 10160 } | 10207 } |
| 10161 | 10208 |
| 10162 // It is ok to call a factory method of an abstract class, but it is | 10209 // It is ok to call a factory method of an abstract class, but it is |
| 10163 // a dynamic error to instantiate an abstract class. | 10210 // a dynamic error to instantiate an abstract class. |
| 10164 ASSERT(!constructor.IsNull()); | 10211 ASSERT(!constructor.IsNull()); |
| 10165 if (type_class.is_abstract() && !constructor.IsFactory()) { | 10212 if (type_class.is_abstract() && !constructor.IsFactory()) { |
| 10166 // Evaluate arguments before throwing. | 10213 // Evaluate arguments before throwing. |
| 10167 LetNode* result = new LetNode(call_pos); | 10214 LetNode* result = new(isolate()) LetNode(call_pos); |
| 10168 for (intptr_t i = 0; i < arguments->length(); ++i) { | 10215 for (intptr_t i = 0; i < arguments->length(); ++i) { |
| 10169 result->AddNode(arguments->NodeAt(i)); | 10216 result->AddNode(arguments->NodeAt(i)); |
| 10170 } | 10217 } |
| 10171 ArgumentListNode* error_arguments = new ArgumentListNode(type_pos); | 10218 ArgumentListNode* error_arguments = |
| 10172 error_arguments->Add(new LiteralNode( | 10219 new(isolate()) ArgumentListNode(type_pos); |
| 10220 error_arguments->Add(new(isolate()) LiteralNode( | |
| 10173 TokenPos(), Integer::ZoneHandle(Integer::New(type_pos)))); | 10221 TokenPos(), Integer::ZoneHandle(Integer::New(type_pos)))); |
| 10174 error_arguments->Add(new LiteralNode( | 10222 error_arguments->Add(new(isolate()) LiteralNode( |
| 10175 TokenPos(), String::ZoneHandle(type_class_name.raw()))); | 10223 TokenPos(), String::ZoneHandle(type_class_name.raw()))); |
| 10176 result->AddNode( | 10224 result->AddNode( |
| 10177 MakeStaticCall(Symbols::AbstractClassInstantiationError(), | 10225 MakeStaticCall(Symbols::AbstractClassInstantiationError(), |
| 10178 Library::PrivateCoreLibName(Symbols::ThrowNew()), | 10226 Library::PrivateCoreLibName(Symbols::ThrowNew()), |
| 10179 error_arguments)); | 10227 error_arguments)); |
| 10180 return result; | 10228 return result; |
| 10181 } | 10229 } |
| 10182 String& error_message = String::Handle(); | 10230 String& error_message = String::Handle(isolate()); |
| 10183 if (!constructor.AreValidArguments(arguments_length, | 10231 if (!constructor.AreValidArguments(arguments_length, |
| 10184 arguments->names(), | 10232 arguments->names(), |
| 10185 &error_message)) { | 10233 &error_message)) { |
| 10186 const String& external_constructor_name = | 10234 const String& external_constructor_name = |
| 10187 (named_constructor ? constructor_name : type_class_name); | 10235 (named_constructor ? constructor_name : type_class_name); |
| 10188 if (is_const) { | 10236 if (is_const) { |
| 10189 ErrorMsg(call_pos, | 10237 ErrorMsg(call_pos, |
| 10190 "invalid arguments passed to constructor '%s' " | 10238 "invalid arguments passed to constructor '%s' " |
| 10191 "for class '%s': %s", | 10239 "for class '%s': %s", |
| 10192 external_constructor_name.ToCString(), | 10240 external_constructor_name.ToCString(), |
| 10193 String::Handle(type_class.Name()).ToCString(), | 10241 String::Handle(isolate(), type_class.Name()).ToCString(), |
| 10194 error_message.ToCString()); | 10242 error_message.ToCString()); |
| 10195 } | 10243 } |
| 10196 return ThrowNoSuchMethodError(call_pos, | 10244 return ThrowNoSuchMethodError(call_pos, |
| 10197 type_class, | 10245 type_class, |
| 10198 external_constructor_name, | 10246 external_constructor_name, |
| 10199 arguments, | 10247 arguments, |
| 10200 InvocationMirror::kConstructor, | 10248 InvocationMirror::kConstructor, |
| 10201 InvocationMirror::kMethod, | 10249 InvocationMirror::kMethod, |
| 10202 &constructor); | 10250 &constructor); |
| 10203 } | 10251 } |
| 10204 | 10252 |
| 10205 // Return a throw in case of a malformed or malbounded type or report a | 10253 // Return a throw in case of a malformed or malbounded type or report a |
| 10206 // compile-time error if the constructor is const. | 10254 // compile-time error if the constructor is const. |
| 10207 if (type.IsMalformedOrMalbounded()) { | 10255 if (type.IsMalformedOrMalbounded()) { |
| 10208 if (is_const) { | 10256 if (is_const) { |
| 10209 ErrorMsg(Error::Handle(type.error())); | 10257 ErrorMsg(Error::Handle(isolate(), type.error())); |
| 10210 } | 10258 } |
| 10211 return ThrowTypeError(type_pos, type); | 10259 return ThrowTypeError(type_pos, type); |
| 10212 } | 10260 } |
| 10213 type_arguments ^= type_arguments.Canonicalize(); | 10261 type_arguments ^= type_arguments.Canonicalize(); |
| 10214 // Make the constructor call. | 10262 // Make the constructor call. |
| 10215 AstNode* new_object = NULL; | 10263 AstNode* new_object = NULL; |
| 10216 if (is_const) { | 10264 if (is_const) { |
| 10217 if (!constructor.is_const()) { | 10265 if (!constructor.is_const()) { |
| 10218 const String& external_constructor_name = | 10266 const String& external_constructor_name = |
| 10219 (named_constructor ? constructor_name : type_class_name); | 10267 (named_constructor ? constructor_name : type_class_name); |
| 10220 ErrorMsg("non-const constructor '%s' cannot be used in " | 10268 ErrorMsg("non-const constructor '%s' cannot be used in " |
| 10221 "const object creation", | 10269 "const object creation", |
| 10222 external_constructor_name.ToCString()); | 10270 external_constructor_name.ToCString()); |
| 10223 } | 10271 } |
| 10224 const Object& constructor_result = Object::Handle( | 10272 const Object& constructor_result = Object::Handle(isolate(), |
| 10225 EvaluateConstConstructorCall(type_class, | 10273 EvaluateConstConstructorCall(type_class, |
| 10226 type_arguments, | 10274 type_arguments, |
| 10227 constructor, | 10275 constructor, |
| 10228 arguments)); | 10276 arguments)); |
| 10229 if (constructor_result.IsUnhandledException()) { | 10277 if (constructor_result.IsUnhandledException()) { |
| 10230 // It's a compile-time error if invocation of a const constructor | 10278 // It's a compile-time error if invocation of a const constructor |
| 10231 // call fails. | 10279 // call fails. |
| 10232 AppendErrorMsg(Error::Cast(constructor_result), | 10280 AppendErrorMsg(Error::Cast(constructor_result), |
| 10233 new_pos, | 10281 new_pos, |
| 10234 "error while evaluating const constructor"); | 10282 "error while evaluating const constructor"); |
| 10235 } else { | 10283 } else { |
| 10236 // Const constructors can return null in the case where a const native | 10284 // Const constructors can return null in the case where a const native |
| 10237 // factory returns a null value. Thus we cannot use a Instance::Cast here. | 10285 // factory returns a null value. Thus we cannot use a Instance::Cast here. |
| 10238 Instance& const_instance = Instance::Handle(); | 10286 Instance& const_instance = Instance::Handle(isolate()); |
| 10239 const_instance ^= constructor_result.raw(); | 10287 const_instance ^= constructor_result.raw(); |
| 10240 new_object = new LiteralNode(new_pos, | 10288 new_object = new(isolate()) LiteralNode(new_pos, |
| 10241 Instance::ZoneHandle(const_instance.raw())); | 10289 Instance::ZoneHandle(const_instance.raw())); |
| 10242 if (!type_bound.IsNull()) { | 10290 if (!type_bound.IsNull()) { |
| 10243 ASSERT(!type_bound.IsMalformed()); | 10291 ASSERT(!type_bound.IsMalformed()); |
| 10244 Error& malformed_error = Error::Handle(); | 10292 Error& malformed_error = Error::Handle(isolate()); |
| 10245 ASSERT(!is_top_level_); // We cannot check unresolved types. | 10293 ASSERT(!is_top_level_); // We cannot check unresolved types. |
| 10246 if (!const_instance.IsInstanceOf(type_bound, | 10294 if (!const_instance.IsInstanceOf(type_bound, |
| 10247 TypeArguments::Handle(), | 10295 TypeArguments::Handle(isolate()), |
| 10248 &malformed_error)) { | 10296 &malformed_error)) { |
| 10249 type_bound = ClassFinalizer::NewFinalizedMalformedType( | 10297 type_bound = ClassFinalizer::NewFinalizedMalformedType( |
| 10250 malformed_error, | 10298 malformed_error, |
| 10251 script_, | 10299 script_, |
| 10252 new_pos, | 10300 new_pos, |
| 10253 "const factory result is not an instance of '%s'", | 10301 "const factory result is not an instance of '%s'", |
| 10254 String::Handle(type_bound.UserVisibleName()).ToCString()); | 10302 String::Handle(isolate(), |
| 10303 type_bound.UserVisibleName()).ToCString()); | |
| 10255 new_object = ThrowTypeError(new_pos, type_bound); | 10304 new_object = ThrowTypeError(new_pos, type_bound); |
| 10256 } | 10305 } |
| 10257 type_bound = AbstractType::null(); | 10306 type_bound = AbstractType::null(); |
| 10258 } | 10307 } |
| 10259 } | 10308 } |
| 10260 } else { | 10309 } else { |
| 10261 CheckConstructorCallTypeArguments(new_pos, constructor, type_arguments); | 10310 CheckConstructorCallTypeArguments(new_pos, constructor, type_arguments); |
| 10262 if (!type_arguments.IsNull() && | 10311 if (!type_arguments.IsNull() && |
| 10263 !type_arguments.IsInstantiated() && | 10312 !type_arguments.IsInstantiated() && |
| 10264 (current_block_->scope->function_level() > 0)) { | 10313 (current_block_->scope->function_level() > 0)) { |
| 10265 // Make sure that the instantiator is captured. | 10314 // Make sure that the instantiator is captured. |
| 10266 CaptureInstantiator(); | 10315 CaptureInstantiator(); |
| 10267 } | 10316 } |
| 10268 // If the type argument vector is not instantiated, we verify in checked | 10317 // If the type argument vector is not instantiated, we verify in checked |
| 10269 // mode at runtime that it is within its declared bounds. | 10318 // mode at runtime that it is within its declared bounds. |
| 10270 new_object = CreateConstructorCallNode( | 10319 new_object = CreateConstructorCallNode( |
| 10271 new_pos, type_arguments, constructor, arguments); | 10320 new_pos, type_arguments, constructor, arguments); |
| 10272 } | 10321 } |
| 10273 if (!type_bound.IsNull()) { | 10322 if (!type_bound.IsNull()) { |
| 10274 new_object = new AssignableNode(new_pos, | 10323 new_object = new(isolate()) AssignableNode( |
| 10275 new_object, | 10324 new_pos, new_object, type_bound, Symbols::FactoryResult()); |
| 10276 type_bound, | |
| 10277 Symbols::FactoryResult()); | |
| 10278 } | 10325 } |
| 10279 return new_object; | 10326 return new_object; |
| 10280 } | 10327 } |
| 10281 | 10328 |
| 10282 | 10329 |
| 10283 String& Parser::Interpolate(const GrowableArray<AstNode*>& values) { | 10330 String& Parser::Interpolate(const GrowableArray<AstNode*>& values) { |
| 10284 const Class& cls = Class::Handle( | 10331 const Class& cls = Class::Handle( |
| 10285 isolate(), Library::LookupCoreClass(Symbols::StringBase())); | 10332 isolate(), Library::LookupCoreClass(Symbols::StringBase())); |
| 10286 ASSERT(!cls.IsNull()); | 10333 ASSERT(!cls.IsNull()); |
| 10287 const Function& func = Function::Handle(isolate(), cls.LookupStaticFunction( | 10334 const Function& func = Function::Handle(isolate(), cls.LookupStaticFunction( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10325 AstNode* Parser::ParseStringLiteral(bool allow_interpolation) { | 10372 AstNode* Parser::ParseStringLiteral(bool allow_interpolation) { |
| 10326 TRACE_PARSER("ParseStringLiteral"); | 10373 TRACE_PARSER("ParseStringLiteral"); |
| 10327 AstNode* primary = NULL; | 10374 AstNode* primary = NULL; |
| 10328 const intptr_t literal_start = TokenPos(); | 10375 const intptr_t literal_start = TokenPos(); |
| 10329 ASSERT(CurrentToken() == Token::kSTRING); | 10376 ASSERT(CurrentToken() == Token::kSTRING); |
| 10330 Token::Kind l1_token = LookaheadToken(1); | 10377 Token::Kind l1_token = LookaheadToken(1); |
| 10331 if ((l1_token != Token::kSTRING) && | 10378 if ((l1_token != Token::kSTRING) && |
| 10332 (l1_token != Token::kINTERPOL_VAR) && | 10379 (l1_token != Token::kINTERPOL_VAR) && |
| 10333 (l1_token != Token::kINTERPOL_START)) { | 10380 (l1_token != Token::kINTERPOL_START)) { |
| 10334 // Common case: no interpolation. | 10381 // Common case: no interpolation. |
| 10335 primary = new LiteralNode(literal_start, *CurrentLiteral()); | 10382 primary = new(isolate()) LiteralNode(literal_start, *CurrentLiteral()); |
| 10336 ConsumeToken(); | 10383 ConsumeToken(); |
| 10337 return primary; | 10384 return primary; |
| 10338 } | 10385 } |
| 10339 // String interpolation needed. | 10386 // String interpolation needed. |
| 10340 bool is_compiletime_const = true; | 10387 bool is_compiletime_const = true; |
| 10341 bool has_interpolation = false; | 10388 bool has_interpolation = false; |
| 10342 GrowableArray<AstNode*> values_list; | 10389 GrowableArray<AstNode*> values_list; |
| 10343 while (CurrentToken() == Token::kSTRING) { | 10390 while (CurrentToken() == Token::kSTRING) { |
| 10344 if (CurrentLiteral()->Length() > 0) { | 10391 if (CurrentLiteral()->Length() > 0) { |
| 10345 // Only add non-empty string sections to the values list | 10392 // Only add non-empty string sections to the values list |
| 10346 // that will be concatenated. | 10393 // that will be concatenated. |
| 10347 values_list.Add(new LiteralNode(TokenPos(), *CurrentLiteral())); | 10394 values_list.Add(new(isolate()) LiteralNode(TokenPos(), |
| 10395 *CurrentLiteral())); | |
| 10348 } | 10396 } |
| 10349 ConsumeToken(); | 10397 ConsumeToken(); |
| 10350 while ((CurrentToken() == Token::kINTERPOL_VAR) || | 10398 while ((CurrentToken() == Token::kINTERPOL_VAR) || |
| 10351 (CurrentToken() == Token::kINTERPOL_START)) { | 10399 (CurrentToken() == Token::kINTERPOL_START)) { |
| 10352 if (!allow_interpolation) { | 10400 if (!allow_interpolation) { |
| 10353 ErrorMsg("string interpolation not allowed in this context"); | 10401 ErrorMsg("string interpolation not allowed in this context"); |
| 10354 } | 10402 } |
| 10355 has_interpolation = true; | 10403 has_interpolation = true; |
| 10356 AstNode* expr = NULL; | 10404 AstNode* expr = NULL; |
| 10357 const intptr_t expr_pos = TokenPos(); | 10405 const intptr_t expr_pos = TokenPos(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 10371 // a constant or not. Only strings, numbers, booleans and null values | 10419 // a constant or not. Only strings, numbers, booleans and null values |
| 10372 // are allowed in compile time const interpolations. | 10420 // are allowed in compile time const interpolations. |
| 10373 if (is_compiletime_const) { | 10421 if (is_compiletime_const) { |
| 10374 const Object* const_expr = expr->EvalConstExpr(); | 10422 const Object* const_expr = expr->EvalConstExpr(); |
| 10375 if ((const_expr != NULL) && | 10423 if ((const_expr != NULL) && |
| 10376 (const_expr->IsNumber() || | 10424 (const_expr->IsNumber() || |
| 10377 const_expr->IsString() || | 10425 const_expr->IsString() || |
| 10378 const_expr->IsBool() || | 10426 const_expr->IsBool() || |
| 10379 const_expr->IsNull())) { | 10427 const_expr->IsNull())) { |
| 10380 // Change expr into a literal. | 10428 // Change expr into a literal. |
| 10381 expr = new LiteralNode(expr_pos, EvaluateConstExpr(expr_pos, expr)); | 10429 expr = new(isolate()) LiteralNode(expr_pos, |
| 10430 EvaluateConstExpr(expr_pos, expr)); | |
| 10382 } else { | 10431 } else { |
| 10383 is_compiletime_const = false; | 10432 is_compiletime_const = false; |
| 10384 } | 10433 } |
| 10385 } | 10434 } |
| 10386 values_list.Add(expr); | 10435 values_list.Add(expr); |
| 10387 } | 10436 } |
| 10388 } | 10437 } |
| 10389 if (is_compiletime_const) { | 10438 if (is_compiletime_const) { |
| 10390 if (has_interpolation) { | 10439 if (has_interpolation) { |
| 10391 primary = new LiteralNode(literal_start, Interpolate(values_list)); | 10440 primary = new(isolate()) LiteralNode( |
| 10441 literal_start, Interpolate(values_list)); | |
| 10392 } else { | 10442 } else { |
| 10393 const Array& strings = Array::Handle(Array::New(values_list.length())); | 10443 const Array& strings = Array::Handle(isolate(), |
| 10444 Array::New(values_list.length())); | |
| 10394 for (int i = 0; i < values_list.length(); i++) { | 10445 for (int i = 0; i < values_list.length(); i++) { |
| 10395 const Instance& part = values_list[i]->AsLiteralNode()->literal(); | 10446 const Instance& part = values_list[i]->AsLiteralNode()->literal(); |
| 10396 ASSERT(part.IsString()); | 10447 ASSERT(part.IsString()); |
| 10397 strings.SetAt(i, String::Cast(part)); | 10448 strings.SetAt(i, String::Cast(part)); |
| 10398 } | 10449 } |
| 10399 String& lit = String::ZoneHandle(String::ConcatAll(strings, Heap::kOld)); | 10450 String& lit = String::ZoneHandle(String::ConcatAll(strings, Heap::kOld)); |
| 10400 lit = Symbols::New(lit); | 10451 lit = Symbols::New(lit); |
| 10401 primary = new LiteralNode(literal_start, lit); | 10452 primary = new(isolate()) LiteralNode(literal_start, lit); |
| 10402 } | 10453 } |
| 10403 } else { | 10454 } else { |
| 10404 ArrayNode* values = new ArrayNode( | 10455 ArrayNode* values = new(isolate()) ArrayNode( |
| 10405 TokenPos(), | 10456 TokenPos(), |
| 10406 Type::ZoneHandle(Type::ArrayType()), | 10457 Type::ZoneHandle(Type::ArrayType()), |
| 10407 values_list); | 10458 values_list); |
| 10408 primary = new StringInterpolateNode(TokenPos(), values); | 10459 primary = new(isolate()) StringInterpolateNode(TokenPos(), values); |
| 10409 } | 10460 } |
| 10410 return primary; | 10461 return primary; |
| 10411 } | 10462 } |
| 10412 | 10463 |
| 10413 | 10464 |
| 10414 AstNode* Parser::ParsePrimary() { | 10465 AstNode* Parser::ParsePrimary() { |
| 10415 TRACE_PARSER("ParsePrimary"); | 10466 TRACE_PARSER("ParsePrimary"); |
| 10416 ASSERT(!is_top_level_); | 10467 ASSERT(!is_top_level_); |
| 10417 AstNode* primary = NULL; | 10468 AstNode* primary = NULL; |
| 10418 if (IsFunctionLiteral()) { | 10469 if (IsFunctionLiteral()) { |
| 10419 // The name of a literal function is visible from inside the function, but | 10470 // The name of a literal function is visible from inside the function, but |
| 10420 // must not collide with names in the scope declaring the literal. | 10471 // must not collide with names in the scope declaring the literal. |
| 10421 OpenBlock(); | 10472 OpenBlock(); |
| 10422 primary = ParseFunctionStatement(true); | 10473 primary = ParseFunctionStatement(true); |
| 10423 CloseBlock(); | 10474 CloseBlock(); |
| 10424 } else if (IsIdentifier()) { | 10475 } else if (IsIdentifier()) { |
| 10425 QualIdent qual_ident; | 10476 QualIdent qual_ident; |
| 10426 intptr_t qual_ident_pos = TokenPos(); | 10477 intptr_t qual_ident_pos = TokenPos(); |
| 10427 ParseQualIdent(&qual_ident); | 10478 ParseQualIdent(&qual_ident); |
| 10428 if (qual_ident.lib_prefix == NULL) { | 10479 if (qual_ident.lib_prefix == NULL) { |
| 10429 if (!ResolveIdentInLocalScope(qual_ident.ident_pos, | 10480 if (!ResolveIdentInLocalScope(qual_ident.ident_pos, |
| 10430 *qual_ident.ident, | 10481 *qual_ident.ident, |
| 10431 &primary)) { | 10482 &primary)) { |
| 10432 // Check whether the identifier is a type parameter. | 10483 // Check whether the identifier is a type parameter. |
| 10433 if (!current_class().IsNull()) { | 10484 if (!current_class().IsNull()) { |
| 10434 TypeParameter& type_param = TypeParameter::ZoneHandle( | 10485 TypeParameter& type_param = TypeParameter::ZoneHandle( |
| 10435 current_class().LookupTypeParameter(*(qual_ident.ident))); | 10486 current_class().LookupTypeParameter(*(qual_ident.ident))); |
| 10436 if (!type_param.IsNull()) { | 10487 if (!type_param.IsNull()) { |
| 10437 return new PrimaryNode(qual_ident.ident_pos, type_param); | 10488 return new(isolate()) PrimaryNode(qual_ident.ident_pos, type_param); |
| 10438 } | 10489 } |
| 10439 } | 10490 } |
| 10440 // This is a non-local unqualified identifier so resolve the | 10491 // This is a non-local unqualified identifier so resolve the |
| 10441 // identifier locally in the main app library and all libraries | 10492 // identifier locally in the main app library and all libraries |
| 10442 // imported by it. | 10493 // imported by it. |
| 10443 primary = ResolveIdentInCurrentLibraryScope(qual_ident.ident_pos, | 10494 primary = ResolveIdentInCurrentLibraryScope(qual_ident.ident_pos, |
| 10444 *qual_ident.ident); | 10495 *qual_ident.ident); |
| 10445 } | 10496 } |
| 10446 } else { | 10497 } else { |
| 10447 // This is a qualified identifier with a library prefix so resolve | 10498 // This is a qualified identifier with a library prefix so resolve |
| 10448 // the identifier locally in that library (we do not include the | 10499 // the identifier locally in that library (we do not include the |
| 10449 // libraries imported by that library). | 10500 // libraries imported by that library). |
| 10450 primary = ResolveIdentInPrefixScope(qual_ident.ident_pos, | 10501 primary = ResolveIdentInPrefixScope(qual_ident.ident_pos, |
| 10451 *qual_ident.lib_prefix, | 10502 *qual_ident.lib_prefix, |
| 10452 *qual_ident.ident); | 10503 *qual_ident.ident); |
| 10453 // If the identifier could not be resolved, throw a NoSuchMethodError. | 10504 // If the identifier could not be resolved, throw a NoSuchMethodError. |
| 10454 // Note: unlike in the case of an unqualified identifier, do not | 10505 // Note: unlike in the case of an unqualified identifier, do not |
| 10455 // interpret the unresolved identifier as an instance method or | 10506 // interpret the unresolved identifier as an instance method or |
| 10456 // instance getter call when compiling an instance method. | 10507 // instance getter call when compiling an instance method. |
| 10457 if (primary == NULL) { | 10508 if (primary == NULL) { |
| 10458 if (qual_ident.lib_prefix->is_deferred_load() && | 10509 if (qual_ident.lib_prefix->is_deferred_load() && |
| 10459 qual_ident.ident->Equals(Symbols::LoadLibrary())) { | 10510 qual_ident.ident->Equals(Symbols::LoadLibrary())) { |
| 10460 // Hack Alert: recognize special 'loadLibrary' call on the | 10511 // Hack Alert: recognize special 'loadLibrary' call on the |
| 10461 // prefix object. The prefix is the primary. Rewind parser and | 10512 // prefix object. The prefix is the primary. Rewind parser and |
| 10462 // let ParseSelectors() handle the loadLibrary call. | 10513 // let ParseSelectors() handle the loadLibrary call. |
| 10463 SetPosition(qual_ident_pos); | 10514 SetPosition(qual_ident_pos); |
| 10464 ConsumeToken(); // Prefix name. | 10515 ConsumeToken(); // Prefix name. |
| 10465 primary = new LiteralNode(qual_ident_pos, *qual_ident.lib_prefix); | 10516 primary = new(isolate()) LiteralNode( |
| 10517 qual_ident_pos, *qual_ident.lib_prefix); | |
| 10466 } else { | 10518 } else { |
| 10467 // TODO(hausner): Ideally we should generate the NoSuchMethodError | 10519 // TODO(hausner): Ideally we should generate the NoSuchMethodError |
| 10468 // later, when we know more about how the unresolved name is used. | 10520 // later, when we know more about how the unresolved name is used. |
| 10469 // For example, we don't know yet whether the unresolved name | 10521 // For example, we don't know yet whether the unresolved name |
| 10470 // refers to a getter or a setter. However, it is more awkward | 10522 // refers to a getter or a setter. However, it is more awkward |
| 10471 // to distinuish four NoSuchMethodError cases all over the place | 10523 // to distinuish four NoSuchMethodError cases all over the place |
| 10472 // in the parser. The four cases are: prefixed vs non-prefixed | 10524 // in the parser. The four cases are: prefixed vs non-prefixed |
| 10473 // name, static vs dynamic context in which the unresolved name | 10525 // name, static vs dynamic context in which the unresolved name |
| 10474 // is used. We cheat a little here by looking at the next token | 10526 // is used. We cheat a little here by looking at the next token |
| 10475 // to determine whether we have an unresolved method call or | 10527 // to determine whether we have an unresolved method call or |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 10491 NULL); // No existing function. | 10543 NULL); // No existing function. |
| 10492 } | 10544 } |
| 10493 } | 10545 } |
| 10494 } | 10546 } |
| 10495 ASSERT(primary != NULL); | 10547 ASSERT(primary != NULL); |
| 10496 } else if (CurrentToken() == Token::kTHIS) { | 10548 } else if (CurrentToken() == Token::kTHIS) { |
| 10497 LocalVariable* local = LookupLocalScope(Symbols::This()); | 10549 LocalVariable* local = LookupLocalScope(Symbols::This()); |
| 10498 if (local == NULL) { | 10550 if (local == NULL) { |
| 10499 ErrorMsg("receiver 'this' is not in scope"); | 10551 ErrorMsg("receiver 'this' is not in scope"); |
| 10500 } | 10552 } |
| 10501 primary = new LoadLocalNode(TokenPos(), local); | 10553 primary = new(isolate()) LoadLocalNode(TokenPos(), local); |
| 10502 ConsumeToken(); | 10554 ConsumeToken(); |
| 10503 } else if (CurrentToken() == Token::kINTEGER) { | 10555 } else if (CurrentToken() == Token::kINTEGER) { |
| 10504 const Integer& literal = Integer::ZoneHandle(CurrentIntegerLiteral()); | 10556 const Integer& literal = Integer::ZoneHandle(CurrentIntegerLiteral()); |
| 10505 primary = new LiteralNode(TokenPos(), literal); | 10557 primary = new(isolate()) LiteralNode(TokenPos(), literal); |
| 10506 ConsumeToken(); | 10558 ConsumeToken(); |
| 10507 } else if (CurrentToken() == Token::kTRUE) { | 10559 } else if (CurrentToken() == Token::kTRUE) { |
| 10508 primary = new LiteralNode(TokenPos(), Bool::True()); | 10560 primary = new(isolate()) LiteralNode(TokenPos(), Bool::True()); |
| 10509 ConsumeToken(); | 10561 ConsumeToken(); |
| 10510 } else if (CurrentToken() == Token::kFALSE) { | 10562 } else if (CurrentToken() == Token::kFALSE) { |
| 10511 primary = new LiteralNode(TokenPos(), Bool::False()); | 10563 primary = new(isolate()) LiteralNode(TokenPos(), Bool::False()); |
| 10512 ConsumeToken(); | 10564 ConsumeToken(); |
| 10513 } else if (CurrentToken() == Token::kNULL) { | 10565 } else if (CurrentToken() == Token::kNULL) { |
| 10514 primary = new LiteralNode(TokenPos(), Instance::ZoneHandle()); | 10566 primary = new(isolate()) LiteralNode(TokenPos(), Instance::ZoneHandle()); |
| 10515 ConsumeToken(); | 10567 ConsumeToken(); |
| 10516 } else if (CurrentToken() == Token::kLPAREN) { | 10568 } else if (CurrentToken() == Token::kLPAREN) { |
| 10517 ConsumeToken(); | 10569 ConsumeToken(); |
| 10518 const bool saved_mode = SetAllowFunctionLiterals(true); | 10570 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 10519 primary = ParseExpr(kAllowConst, kConsumeCascades); | 10571 primary = ParseExpr(kAllowConst, kConsumeCascades); |
| 10520 SetAllowFunctionLiterals(saved_mode); | 10572 SetAllowFunctionLiterals(saved_mode); |
| 10521 ExpectToken(Token::kRPAREN); | 10573 ExpectToken(Token::kRPAREN); |
| 10522 } else if (CurrentToken() == Token::kDOUBLE) { | 10574 } else if (CurrentToken() == Token::kDOUBLE) { |
| 10523 Double& double_value = Double::ZoneHandle(CurrentDoubleLiteral()); | 10575 Double& double_value = Double::ZoneHandle(CurrentDoubleLiteral()); |
| 10524 if (double_value.IsNull()) { | 10576 if (double_value.IsNull()) { |
| 10525 ErrorMsg("invalid double literal"); | 10577 ErrorMsg("invalid double literal"); |
| 10526 } | 10578 } |
| 10527 primary = new LiteralNode(TokenPos(), double_value); | 10579 primary = new(isolate()) LiteralNode(TokenPos(), double_value); |
| 10528 ConsumeToken(); | 10580 ConsumeToken(); |
| 10529 } else if (CurrentToken() == Token::kSTRING) { | 10581 } else if (CurrentToken() == Token::kSTRING) { |
| 10530 primary = ParseStringLiteral(true); | 10582 primary = ParseStringLiteral(true); |
| 10531 } else if (CurrentToken() == Token::kNEW) { | 10583 } else if (CurrentToken() == Token::kNEW) { |
| 10532 ConsumeToken(); | 10584 ConsumeToken(); |
| 10533 primary = ParseNewOperator(Token::kNEW); | 10585 primary = ParseNewOperator(Token::kNEW); |
| 10534 } else if (CurrentToken() == Token::kCONST) { | 10586 } else if (CurrentToken() == Token::kCONST) { |
| 10535 if ((LookaheadToken(1) == Token::kLT) || | 10587 if ((LookaheadToken(1) == Token::kLT) || |
| 10536 (LookaheadToken(1) == Token::kLBRACK) || | 10588 (LookaheadToken(1) == Token::kLBRACK) || |
| 10537 (LookaheadToken(1) == Token::kINDEX) || | 10589 (LookaheadToken(1) == Token::kINDEX) || |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 10550 primary = ParseSymbolLiteral(); | 10602 primary = ParseSymbolLiteral(); |
| 10551 } else if (CurrentToken() == Token::kSUPER) { | 10603 } else if (CurrentToken() == Token::kSUPER) { |
| 10552 if (parsing_metadata_) { | 10604 if (parsing_metadata_) { |
| 10553 ErrorMsg("cannot access superclass from metadata"); | 10605 ErrorMsg("cannot access superclass from metadata"); |
| 10554 } | 10606 } |
| 10555 if (current_function().is_static()) { | 10607 if (current_function().is_static()) { |
| 10556 ErrorMsg("cannot access superclass from static method"); | 10608 ErrorMsg("cannot access superclass from static method"); |
| 10557 } | 10609 } |
| 10558 if (current_class().SuperClass() == Class::null()) { | 10610 if (current_class().SuperClass() == Class::null()) { |
| 10559 ErrorMsg("class '%s' does not have a superclass", | 10611 ErrorMsg("class '%s' does not have a superclass", |
| 10560 String::Handle(current_class().Name()).ToCString()); | 10612 String::Handle(isolate(), current_class().Name()).ToCString()); |
| 10561 } | 10613 } |
| 10562 if (current_class().IsMixinApplication()) { | 10614 if (current_class().IsMixinApplication()) { |
| 10563 const Type& mixin_type = Type::Handle(current_class().mixin()); | 10615 const Type& mixin_type = Type::Handle(isolate(), current_class().mixin()); |
| 10564 if (mixin_type.type_class() == current_function().origin()) { | 10616 if (mixin_type.type_class() == current_function().origin()) { |
| 10565 ErrorMsg("method of mixin class '%s' may not refer to 'super'", | 10617 ErrorMsg("method of mixin class '%s' may not refer to 'super'", |
| 10566 String::Handle(Class::Handle( | 10618 String::Handle(isolate(), Class::Handle(isolate(), |
| 10567 current_function().origin()).Name()).ToCString()); | 10619 current_function().origin()).Name()).ToCString()); |
| 10568 } | 10620 } |
| 10569 } | 10621 } |
| 10570 const intptr_t super_pos = TokenPos(); | 10622 const intptr_t super_pos = TokenPos(); |
| 10571 ConsumeToken(); | 10623 ConsumeToken(); |
| 10572 if (CurrentToken() == Token::kPERIOD) { | 10624 if (CurrentToken() == Token::kPERIOD) { |
| 10573 ConsumeToken(); | 10625 ConsumeToken(); |
| 10574 const intptr_t ident_pos = TokenPos(); | 10626 const intptr_t ident_pos = TokenPos(); |
| 10575 const String& ident = *ExpectIdentifier("identifier expected"); | 10627 const String& ident = *ExpectIdentifier("identifier expected"); |
| 10576 if (CurrentToken() == Token::kLPAREN) { | 10628 if (CurrentToken() == Token::kLPAREN) { |
| 10577 primary = ParseSuperCall(ident); | 10629 primary = ParseSuperCall(ident); |
| 10578 } else { | 10630 } else { |
| 10579 primary = ParseSuperFieldAccess(ident, ident_pos); | 10631 primary = ParseSuperFieldAccess(ident, ident_pos); |
| 10580 } | 10632 } |
| 10581 } else if ((CurrentToken() == Token::kLBRACK) || | 10633 } else if ((CurrentToken() == Token::kLBRACK) || |
| 10582 Token::CanBeOverloaded(CurrentToken()) || | 10634 Token::CanBeOverloaded(CurrentToken()) || |
| 10583 (CurrentToken() == Token::kNE)) { | 10635 (CurrentToken() == Token::kNE)) { |
| 10584 primary = ParseSuperOperator(); | 10636 primary = ParseSuperOperator(); |
| 10585 } else { | 10637 } else { |
| 10586 primary = new PrimaryNode(super_pos, Symbols::Super()); | 10638 primary = new(isolate()) PrimaryNode(super_pos, Symbols::Super()); |
| 10587 } | 10639 } |
| 10588 } else { | 10640 } else { |
| 10589 UnexpectedToken(); | 10641 UnexpectedToken(); |
| 10590 } | 10642 } |
| 10591 return primary; | 10643 return primary; |
| 10592 } | 10644 } |
| 10593 | 10645 |
| 10594 | 10646 |
| 10595 // Evaluate expression in expr and return the value. The expression must | 10647 // Evaluate expression in expr and return the value. The expression must |
| 10596 // be a compile time constant. | 10648 // be a compile time constant. |
| 10597 const Instance& Parser::EvaluateConstExpr(intptr_t expr_pos, AstNode* expr) { | 10649 const Instance& Parser::EvaluateConstExpr(intptr_t expr_pos, AstNode* expr) { |
| 10598 if (expr->IsLiteralNode()) { | 10650 if (expr->IsLiteralNode()) { |
| 10599 return expr->AsLiteralNode()->literal(); | 10651 return expr->AsLiteralNode()->literal(); |
| 10600 } else if (expr->IsLoadLocalNode() && | 10652 } else if (expr->IsLoadLocalNode() && |
| 10601 expr->AsLoadLocalNode()->local().IsConst()) { | 10653 expr->AsLoadLocalNode()->local().IsConst()) { |
| 10602 return *expr->AsLoadLocalNode()->local().ConstValue(); | 10654 return *expr->AsLoadLocalNode()->local().ConstValue(); |
| 10603 } else if (expr->IsLoadStaticFieldNode()) { | 10655 } else if (expr->IsLoadStaticFieldNode()) { |
| 10604 const Field& field = expr->AsLoadStaticFieldNode()->field(); | 10656 const Field& field = expr->AsLoadStaticFieldNode()->field(); |
| 10605 // We already checked that this field is const and has been | 10657 // We already checked that this field is const and has been |
| 10606 // initialized. | 10658 // initialized. |
| 10607 ASSERT(field.is_const()); | 10659 ASSERT(field.is_const()); |
| 10608 ASSERT(field.value() != Object::sentinel().raw()); | 10660 ASSERT(field.value() != Object::sentinel().raw()); |
| 10609 ASSERT(field.value() != Object::transition_sentinel().raw()); | 10661 ASSERT(field.value() != Object::transition_sentinel().raw()); |
| 10610 return Instance::ZoneHandle(field.value()); | 10662 return Instance::ZoneHandle(field.value()); |
| 10611 } else { | 10663 } else { |
| 10612 ASSERT(expr->EvalConstExpr() != NULL); | 10664 ASSERT(expr->EvalConstExpr() != NULL); |
| 10613 ReturnNode* ret = new ReturnNode(expr->token_pos(), expr); | 10665 ReturnNode* ret = new(isolate()) ReturnNode(expr->token_pos(), expr); |
| 10614 // Compile time constant expressions cannot reference anything from a | 10666 // Compile time constant expressions cannot reference anything from a |
| 10615 // local scope. | 10667 // local scope. |
| 10616 LocalScope* empty_scope = new LocalScope(NULL, 0, 0); | 10668 LocalScope* empty_scope = new(isolate()) LocalScope(NULL, 0, 0); |
| 10617 SequenceNode* seq = new SequenceNode(expr->token_pos(), empty_scope); | 10669 SequenceNode* seq = new(isolate()) SequenceNode(expr->token_pos(), |
| 10670 empty_scope); | |
| 10618 seq->Add(ret); | 10671 seq->Add(ret); |
| 10619 | 10672 |
| 10620 Object& result = Object::Handle(Compiler::ExecuteOnce(seq)); | 10673 Object& result = Object::Handle(isolate(), Compiler::ExecuteOnce(seq)); |
| 10621 if (result.IsError()) { | 10674 if (result.IsError()) { |
| 10622 AppendErrorMsg(Error::Cast(result), | 10675 AppendErrorMsg(Error::Cast(result), |
| 10623 expr_pos, | 10676 expr_pos, |
| 10624 "error evaluating constant expression"); | 10677 "error evaluating constant expression"); |
| 10625 } | 10678 } |
| 10626 ASSERT(result.IsInstance()); | 10679 ASSERT(result.IsInstance()); |
| 10627 Instance& value = Instance::ZoneHandle(); | 10680 Instance& value = Instance::ZoneHandle(); |
| 10628 value ^= result.raw(); | 10681 value ^= result.raw(); |
| 10629 value = TryCanonicalize(value, TokenPos()); | 10682 value = TryCanonicalize(value, TokenPos()); |
| 10630 return value; | 10683 return value; |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10957 void Parser::SkipQualIdent() { | 11010 void Parser::SkipQualIdent() { |
| 10958 ASSERT(IsIdentifier()); | 11011 ASSERT(IsIdentifier()); |
| 10959 ConsumeToken(); | 11012 ConsumeToken(); |
| 10960 if (CurrentToken() == Token::kPERIOD) { | 11013 if (CurrentToken() == Token::kPERIOD) { |
| 10961 ConsumeToken(); // Consume the kPERIOD token. | 11014 ConsumeToken(); // Consume the kPERIOD token. |
| 10962 ExpectIdentifier("identifier expected after '.'"); | 11015 ExpectIdentifier("identifier expected after '.'"); |
| 10963 } | 11016 } |
| 10964 } | 11017 } |
| 10965 | 11018 |
| 10966 } // namespace dart | 11019 } // namespace dart |
| OLD | NEW |