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 #include "vm/flags.h" | 6 #include "vm/flags.h" |
7 | 7 |
8 #ifndef DART_PRECOMPILED | 8 #ifndef DART_PRECOMPILED |
9 | 9 |
10 #include "lib/invocation_mirror.h" | 10 #include "lib/invocation_mirror.h" |
(...skipping 2510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2521 initializers->NodeAt(i)->AsStoreInstanceFieldNode(); | 2521 initializers->NodeAt(i)->AsStoreInstanceFieldNode(); |
2522 if (initializer->field().raw() == field.raw()) { | 2522 if (initializer->field().raw() == field.raw()) { |
2523 found = true; | 2523 found = true; |
2524 break; | 2524 break; |
2525 } | 2525 } |
2526 } | 2526 } |
2527 } | 2527 } |
2528 | 2528 |
2529 if (found) continue; | 2529 if (found) continue; |
2530 | 2530 |
2531 field.RecordStore(Object::Handle(Z)); | 2531 field.RecordStore(Object::null_object()); |
2532 } | 2532 } |
2533 } | 2533 } |
2534 | 2534 |
2535 | 2535 |
2536 AstNode* Parser::ParseExternalInitializedField(const Field& field) { | 2536 AstNode* Parser::ParseExternalInitializedField(const Field& field) { |
2537 // Only use this function if the initialized field originates | 2537 // Only use this function if the initialized field originates |
2538 // from a different class. We need to save and restore current | 2538 // from a different class. We need to save and restore current |
2539 // class, library, and token stream (script). | 2539 // class, library, and token stream (script). |
2540 ASSERT(current_class().raw() != field.origin()); | 2540 ASSERT(current_class().raw() != field.origin()); |
2541 const Class& saved_class = Class::Handle(Z, current_class().raw()); | 2541 const Class& saved_class = Class::Handle(Z, current_class().raw()); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2688 GrowableArray<AstNode*> setter_args; | 2688 GrowableArray<AstNode*> setter_args; |
2689 setter_args.Add(init_value); | 2689 setter_args.Add(init_value); |
2690 ArrayNode* setter_args_array = new(Z) ArrayNode( | 2690 ArrayNode* setter_args_array = new(Z) ArrayNode( |
2691 init_pos, | 2691 init_pos, |
2692 Type::ZoneHandle(Z, Type::ArrayType()), | 2692 Type::ZoneHandle(Z, Type::ArrayType()), |
2693 setter_args); | 2693 setter_args); |
2694 nsm_args->Add(setter_args_array); | 2694 nsm_args->Add(setter_args_array); |
2695 | 2695 |
2696 // List argumentNames. | 2696 // List argumentNames. |
2697 // The missing implicit setter of the field has no argument names. | 2697 // The missing implicit setter of the field has no argument names. |
2698 nsm_args->Add(new(Z) LiteralNode(init_pos, Array::ZoneHandle(Z))); | 2698 nsm_args->Add(new(Z) LiteralNode(init_pos, Object::null_array())); |
2699 | 2699 |
2700 // List existingArgumentNames. | 2700 // List existingArgumentNames. |
2701 // There is no setter for the final field, thus there are | 2701 // There is no setter for the final field, thus there are |
2702 // no existing names. | 2702 // no existing names. |
2703 nsm_args->Add(new(Z) LiteralNode(init_pos, Array::ZoneHandle(Z))); | 2703 nsm_args->Add(new(Z) LiteralNode(init_pos, Object::null_array())); |
2704 | 2704 |
2705 AstNode* nsm_call = | 2705 AstNode* nsm_call = |
2706 MakeStaticCall(Symbols::NoSuchMethodError(), | 2706 MakeStaticCall(Symbols::NoSuchMethodError(), |
2707 Library::PrivateCoreLibName(Symbols::ThrowNew()), | 2707 Library::PrivateCoreLibName(Symbols::ThrowNew()), |
2708 nsm_args); | 2708 nsm_args); |
2709 | 2709 |
2710 LetNode* let = new(Z) LetNode(init_pos); | 2710 LetNode* let = new(Z) LetNode(init_pos); |
2711 let->AddNode(init_value); | 2711 let->AddNode(init_value); |
2712 let->AddNode(nsm_call); | 2712 let->AddNode(nsm_call); |
2713 result = let; | 2713 result = let; |
(...skipping 4725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7439 ASSERT(expr->IsLiteralNode()); | 7439 ASSERT(expr->IsLiteralNode()); |
7440 variable->SetConstValue(expr->AsLiteralNode()->literal()); | 7440 variable->SetConstValue(expr->AsLiteralNode()->literal()); |
7441 } | 7441 } |
7442 } else if (is_final || is_const) { | 7442 } else if (is_final || is_const) { |
7443 ReportError(ident_pos, | 7443 ReportError(ident_pos, |
7444 "missing initialization of 'final' or 'const' variable"); | 7444 "missing initialization of 'final' or 'const' variable"); |
7445 } else { | 7445 } else { |
7446 // Initialize variable with null. | 7446 // Initialize variable with null. |
7447 variable = new(Z) LocalVariable( | 7447 variable = new(Z) LocalVariable( |
7448 assign_pos, ident, type); | 7448 assign_pos, ident, type); |
7449 AstNode* null_expr = new(Z) LiteralNode(ident_pos, Instance::ZoneHandle(Z)); | 7449 AstNode* null_expr = new(Z) LiteralNode(ident_pos, Object::null_instance()); |
7450 initialization = new(Z) StoreLocalNode( | 7450 initialization = new(Z) StoreLocalNode( |
7451 ident_pos, variable, null_expr); | 7451 ident_pos, variable, null_expr); |
7452 } | 7452 } |
7453 | 7453 |
7454 ASSERT(current_block_ != NULL); | 7454 ASSERT(current_block_ != NULL); |
7455 const intptr_t previous_pos = | 7455 const intptr_t previous_pos = |
7456 current_block_->scope->PreviousReferencePos(ident); | 7456 current_block_->scope->PreviousReferencePos(ident); |
7457 if (previous_pos >= 0) { | 7457 if (previous_pos >= 0) { |
7458 ASSERT(!script_.IsNull()); | 7458 ASSERT(!script_.IsNull()); |
7459 if (previous_pos > ident_pos) { | 7459 if (previous_pos > ident_pos) { |
(...skipping 2821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10281 method_name = Library::PrivateCoreLibName(Symbols::ThrowNew()).raw(); | 10281 method_name = Library::PrivateCoreLibName(Symbols::ThrowNew()).raw(); |
10282 } else { | 10282 } else { |
10283 arguments->Add(new(Z) LiteralNode(type_pos, *prefix)); | 10283 arguments->Add(new(Z) LiteralNode(type_pos, *prefix)); |
10284 method_name = Library::PrivateCoreLibName( | 10284 method_name = Library::PrivateCoreLibName( |
10285 Symbols::ThrowNewIfNotLoaded()).raw(); | 10285 Symbols::ThrowNewIfNotLoaded()).raw(); |
10286 } | 10286 } |
10287 // Location argument. | 10287 // Location argument. |
10288 arguments->Add(new(Z) LiteralNode( | 10288 arguments->Add(new(Z) LiteralNode( |
10289 type_pos, Integer::ZoneHandle(Z, Integer::New(type_pos)))); | 10289 type_pos, Integer::ZoneHandle(Z, Integer::New(type_pos)))); |
10290 // Src value argument. | 10290 // Src value argument. |
10291 arguments->Add(new(Z) LiteralNode(type_pos, Instance::ZoneHandle(Z))); | 10291 arguments->Add(new(Z) LiteralNode(type_pos, Object::null_instance())); |
10292 // Dst type name argument. | 10292 // Dst type name argument. |
10293 arguments->Add(new(Z) LiteralNode(type_pos, Symbols::Malformed())); | 10293 arguments->Add(new(Z) LiteralNode(type_pos, Symbols::Malformed())); |
10294 // Dst name argument. | 10294 // Dst name argument. |
10295 arguments->Add(new(Z) LiteralNode(type_pos, Symbols::Empty())); | 10295 arguments->Add(new(Z) LiteralNode(type_pos, Symbols::Empty())); |
10296 // Malformed type error or malbounded type error. | 10296 // Malformed type error or malbounded type error. |
10297 const Error& error = Error::Handle(Z, type.error()); | 10297 const Error& error = Error::Handle(Z, type.error()); |
10298 ASSERT(!error.IsNull()); | 10298 ASSERT(!error.IsNull()); |
10299 arguments->Add(new(Z) LiteralNode(type_pos, String::ZoneHandle(Z, | 10299 arguments->Add(new(Z) LiteralNode(type_pos, String::ZoneHandle(Z, |
10300 Symbols::New(error.ToErrorCString())))); | 10300 Symbols::New(error.ToErrorCString())))); |
10301 return MakeStaticCall(Symbols::TypeError(), method_name, arguments); | 10301 return MakeStaticCall(Symbols::TypeError(), method_name, arguments); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10340 // Smi invocation_type. | 10340 // Smi invocation_type. |
10341 if (cls.IsTopLevel()) { | 10341 if (cls.IsTopLevel()) { |
10342 ASSERT(im_call == InvocationMirror::kStatic || | 10342 ASSERT(im_call == InvocationMirror::kStatic || |
10343 im_call == InvocationMirror::kTopLevel); | 10343 im_call == InvocationMirror::kTopLevel); |
10344 im_call = InvocationMirror::kTopLevel; | 10344 im_call = InvocationMirror::kTopLevel; |
10345 } | 10345 } |
10346 arguments->Add(new(Z) LiteralNode(call_pos, Smi::ZoneHandle(Z, | 10346 arguments->Add(new(Z) LiteralNode(call_pos, Smi::ZoneHandle(Z, |
10347 Smi::New(InvocationMirror::EncodeType(im_call, im_type))))); | 10347 Smi::New(InvocationMirror::EncodeType(im_call, im_type))))); |
10348 // List arguments. | 10348 // List arguments. |
10349 if (function_arguments == NULL) { | 10349 if (function_arguments == NULL) { |
10350 arguments->Add(new(Z) LiteralNode(call_pos, Array::ZoneHandle(Z))); | 10350 arguments->Add(new(Z) LiteralNode(call_pos, Object::null_array())); |
10351 } else { | 10351 } else { |
10352 ArrayNode* array = new(Z) ArrayNode( | 10352 ArrayNode* array = new(Z) ArrayNode( |
10353 call_pos, | 10353 call_pos, |
10354 Type::ZoneHandle(Z, Type::ArrayType()), | 10354 Type::ZoneHandle(Z, Type::ArrayType()), |
10355 function_arguments->nodes()); | 10355 function_arguments->nodes()); |
10356 arguments->Add(array); | 10356 arguments->Add(array); |
10357 } | 10357 } |
10358 // List argumentNames. | 10358 // List argumentNames. |
10359 if (function_arguments == NULL) { | 10359 if (function_arguments == NULL) { |
10360 arguments->Add(new(Z) LiteralNode(call_pos, Array::ZoneHandle(Z))); | 10360 arguments->Add(new(Z) LiteralNode(call_pos, Object::null_array())); |
10361 } else { | 10361 } else { |
10362 arguments->Add(new(Z) LiteralNode(call_pos, function_arguments->names())); | 10362 arguments->Add(new(Z) LiteralNode(call_pos, function_arguments->names())); |
10363 } | 10363 } |
10364 | 10364 |
10365 // List existingArgumentNames. | 10365 // List existingArgumentNames. |
10366 // Check if there exists a function with the same name unless caller | 10366 // Check if there exists a function with the same name unless caller |
10367 // has done the lookup already. If there is a function with the same | 10367 // has done the lookup already. If there is a function with the same |
10368 // name but incompatible parameters, inform the NoSuchMethodError what the | 10368 // name but incompatible parameters, inform the NoSuchMethodError what the |
10369 // expected parameters are. | 10369 // expected parameters are. |
10370 Function& function = Function::Handle(Z); | 10370 Function& function = Function::Handle(Z); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10553 } | 10553 } |
10554 } | 10554 } |
10555 } | 10555 } |
10556 } | 10556 } |
10557 if (binary_op == Token::kIFNULL) { | 10557 if (binary_op == Token::kIFNULL) { |
10558 // Handle a ?? b. | 10558 // Handle a ?? b. |
10559 LetNode* result = new(Z) LetNode(op_pos); | 10559 LetNode* result = new(Z) LetNode(op_pos); |
10560 LocalVariable* left_temp = result->AddInitializer(lhs); | 10560 LocalVariable* left_temp = result->AddInitializer(lhs); |
10561 const intptr_t no_pos = Scanner::kNoSourcePos; | 10561 const intptr_t no_pos = Scanner::kNoSourcePos; |
10562 LiteralNode* null_operand = | 10562 LiteralNode* null_operand = |
10563 new(Z) LiteralNode(no_pos, Instance::ZoneHandle(Z)); | 10563 new(Z) LiteralNode(no_pos, Object::null_instance()); |
10564 LoadLocalNode* load_left_temp = new(Z) LoadLocalNode(no_pos, left_temp); | 10564 LoadLocalNode* load_left_temp = new(Z) LoadLocalNode(no_pos, left_temp); |
10565 ComparisonNode* null_compare = | 10565 ComparisonNode* null_compare = |
10566 new(Z) ComparisonNode(no_pos, | 10566 new(Z) ComparisonNode(no_pos, |
10567 Token::kNE_STRICT, | 10567 Token::kNE_STRICT, |
10568 load_left_temp, | 10568 load_left_temp, |
10569 null_operand); | 10569 null_operand); |
10570 result->AddNode(new(Z) ConditionalExprNode(op_pos, | 10570 result->AddNode(new(Z) ConditionalExprNode(op_pos, |
10571 null_compare, | 10571 null_compare, |
10572 load_left_temp, | 10572 load_left_temp, |
10573 rhs)); | 10573 rhs)); |
(...skipping 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12129 arg_values.SetAt(0, type_arguments); | 12129 arg_values.SetAt(0, type_arguments); |
12130 } | 12130 } |
12131 for (int i = 0; i < arguments->length(); i++) { | 12131 for (int i = 0; i < arguments->length(); i++) { |
12132 AstNode* arg = arguments->NodeAt(i); | 12132 AstNode* arg = arguments->NodeAt(i); |
12133 // Arguments have been evaluated to a literal value already. | 12133 // Arguments have been evaluated to a literal value already. |
12134 ASSERT(arg->IsLiteralNode()); | 12134 ASSERT(arg->IsLiteralNode()); |
12135 arg_values.SetAt((i + kNumExtraArgs), arg->AsLiteralNode()->literal()); | 12135 arg_values.SetAt((i + kNumExtraArgs), arg->AsLiteralNode()->literal()); |
12136 } | 12136 } |
12137 const Array& args_descriptor = Array::Handle(Z, | 12137 const Array& args_descriptor = Array::Handle(Z, |
12138 ArgumentsDescriptor::New(num_arguments, arguments->names())); | 12138 ArgumentsDescriptor::New(num_arguments, arguments->names())); |
12139 Object& result = Object::Handle(Z); | 12139 const Object& result = Object::Handle(Z, |
12140 result = DartEntry::InvokeFunction(constructor, arg_values, args_descriptor); | 12140 DartEntry::InvokeFunction(constructor, arg_values, args_descriptor)); |
12141 if (result.IsError()) { | 12141 if (result.IsError()) { |
12142 // An exception may not occur in every parse attempt, i.e., the | 12142 // An exception may not occur in every parse attempt, i.e., the |
12143 // generated AST is not deterministic. Therefore mark the function as | 12143 // generated AST is not deterministic. Therefore mark the function as |
12144 // not optimizable. | 12144 // not optimizable. |
12145 current_function().SetIsOptimizable(false); | 12145 current_function().SetIsOptimizable(false); |
12146 if (result.IsUnhandledException()) { | 12146 if (result.IsUnhandledException()) { |
12147 return result.raw(); | 12147 return result.raw(); |
12148 } else { | 12148 } else { |
12149 thread()->long_jump_base()->Jump(1, Error::Cast(result)); | 12149 thread()->long_jump_base()->Jump(1, Error::Cast(result)); |
12150 UNREACHABLE(); | 12150 UNREACHABLE(); |
(...skipping 1716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13867 const Integer& literal = Integer::ZoneHandle(Z, CurrentIntegerLiteral()); | 13867 const Integer& literal = Integer::ZoneHandle(Z, CurrentIntegerLiteral()); |
13868 primary = new(Z) LiteralNode(TokenPos(), literal); | 13868 primary = new(Z) LiteralNode(TokenPos(), literal); |
13869 ConsumeToken(); | 13869 ConsumeToken(); |
13870 } else if (token == Token::kTRUE) { | 13870 } else if (token == Token::kTRUE) { |
13871 primary = new(Z) LiteralNode(TokenPos(), Bool::True()); | 13871 primary = new(Z) LiteralNode(TokenPos(), Bool::True()); |
13872 ConsumeToken(); | 13872 ConsumeToken(); |
13873 } else if (token == Token::kFALSE) { | 13873 } else if (token == Token::kFALSE) { |
13874 primary = new(Z) LiteralNode(TokenPos(), Bool::False()); | 13874 primary = new(Z) LiteralNode(TokenPos(), Bool::False()); |
13875 ConsumeToken(); | 13875 ConsumeToken(); |
13876 } else if (token == Token::kNULL) { | 13876 } else if (token == Token::kNULL) { |
13877 primary = new(Z) LiteralNode(TokenPos(), Instance::ZoneHandle(Z)); | 13877 primary = new(Z) LiteralNode(TokenPos(), Object::null_instance()); |
13878 ConsumeToken(); | 13878 ConsumeToken(); |
13879 } else if (token == Token::kLPAREN) { | 13879 } else if (token == Token::kLPAREN) { |
13880 ConsumeToken(); | 13880 ConsumeToken(); |
13881 const bool saved_mode = SetAllowFunctionLiterals(true); | 13881 const bool saved_mode = SetAllowFunctionLiterals(true); |
13882 primary = ParseExpr(kAllowConst, kConsumeCascades); | 13882 primary = ParseExpr(kAllowConst, kConsumeCascades); |
13883 SetAllowFunctionLiterals(saved_mode); | 13883 SetAllowFunctionLiterals(saved_mode); |
13884 ExpectToken(Token::kRPAREN); | 13884 ExpectToken(Token::kRPAREN); |
13885 } else if (token == Token::kDOUBLE) { | 13885 } else if (token == Token::kDOUBLE) { |
13886 Double& double_value = Double::ZoneHandle(Z, CurrentDoubleLiteral()); | 13886 const Double& double_value = Double::ZoneHandle(Z, CurrentDoubleLiteral()); |
13887 if (double_value.IsNull()) { | 13887 if (double_value.IsNull()) { |
13888 ReportError("invalid double literal"); | 13888 ReportError("invalid double literal"); |
13889 } | 13889 } |
13890 primary = new(Z) LiteralNode(TokenPos(), double_value); | 13890 primary = new(Z) LiteralNode(TokenPos(), double_value); |
13891 ConsumeToken(); | 13891 ConsumeToken(); |
13892 } else if (token == Token::kSTRING) { | 13892 } else if (token == Token::kSTRING) { |
13893 primary = ParseStringLiteral(true); | 13893 primary = ParseStringLiteral(true); |
13894 } else if (token == Token::kNEW) { | 13894 } else if (token == Token::kNEW) { |
13895 ConsumeToken(); | 13895 ConsumeToken(); |
13896 primary = ParseNewOperator(Token::kNEW); | 13896 primary = ParseNewOperator(Token::kNEW); |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14425 const ArgumentListNode& function_args, | 14425 const ArgumentListNode& function_args, |
14426 const LocalVariable* temp_for_last_arg, | 14426 const LocalVariable* temp_for_last_arg, |
14427 bool is_super_invocation) { | 14427 bool is_super_invocation) { |
14428 UNREACHABLE(); | 14428 UNREACHABLE(); |
14429 return NULL; | 14429 return NULL; |
14430 } | 14430 } |
14431 | 14431 |
14432 } // namespace dart | 14432 } // namespace dart |
14433 | 14433 |
14434 #endif // DART_PRECOMPILED | 14434 #endif // DART_PRECOMPILED |
OLD | NEW |