| 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 "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
| (...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 ParamList func_params; | 1062 ParamList func_params; |
| 1063 const bool no_explicit_default_values = false; | 1063 const bool no_explicit_default_values = false; |
| 1064 ParseFormalParameterList(no_explicit_default_values, &func_params); | 1064 ParseFormalParameterList(no_explicit_default_values, &func_params); |
| 1065 | 1065 |
| 1066 // The field 'is_static' has no meaning for signature functions. | 1066 // The field 'is_static' has no meaning for signature functions. |
| 1067 const Function& signature_function = Function::Handle( | 1067 const Function& signature_function = Function::Handle( |
| 1068 Function::New(*parameter.name, | 1068 Function::New(*parameter.name, |
| 1069 RawFunction::kSignatureFunction, | 1069 RawFunction::kSignatureFunction, |
| 1070 /* is_static = */ false, | 1070 /* is_static = */ false, |
| 1071 /* is_const = */ false, | 1071 /* is_const = */ false, |
| 1072 /* is_abstract = */ false, |
| 1072 /* is_external = */ false, | 1073 /* is_external = */ false, |
| 1073 parameter.name_pos)); | 1074 parameter.name_pos)); |
| 1074 signature_function.set_owner(current_class()); | 1075 signature_function.set_owner(current_class()); |
| 1075 signature_function.set_result_type(result_type); | 1076 signature_function.set_result_type(result_type); |
| 1076 AddFormalParamsToFunction(&func_params, signature_function); | 1077 AddFormalParamsToFunction(&func_params, signature_function); |
| 1077 const String& signature = String::Handle(signature_function.Signature()); | 1078 const String& signature = String::Handle(signature_function.Signature()); |
| 1078 // Lookup the signature class, i.e. the class whose name is the signature. | 1079 // Lookup the signature class, i.e. the class whose name is the signature. |
| 1079 // We only lookup in the current library, but not in its imports, and only | 1080 // We only lookup in the current library, but not in its imports, and only |
| 1080 // create a new canonical signature class if it does not exist yet. | 1081 // create a new canonical signature class if it does not exist yet. |
| 1081 Class& signature_class = Class::ZoneHandle( | 1082 Class& signature_class = Class::ZoneHandle( |
| (...skipping 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2468 } else { | 2469 } else { |
| 2469 ErrorMsg(method->name_pos, | 2470 ErrorMsg(method->name_pos, |
| 2470 "function body expected for method '%s'", | 2471 "function body expected for method '%s'", |
| 2471 method->name->ToCString()); | 2472 method->name->ToCString()); |
| 2472 } | 2473 } |
| 2473 } | 2474 } |
| 2474 | 2475 |
| 2475 RawFunction::Kind function_kind; | 2476 RawFunction::Kind function_kind; |
| 2476 if (method->IsFactoryOrConstructor()) { | 2477 if (method->IsFactoryOrConstructor()) { |
| 2477 function_kind = RawFunction::kConstructor; | 2478 function_kind = RawFunction::kConstructor; |
| 2478 } else if (method->has_abstract) { | |
| 2479 function_kind = RawFunction::kAbstract; | |
| 2480 } else if (method->IsGetter()) { | 2479 } else if (method->IsGetter()) { |
| 2481 function_kind = RawFunction::kGetterFunction; | 2480 function_kind = RawFunction::kGetterFunction; |
| 2482 } else if (method->IsSetter()) { | 2481 } else if (method->IsSetter()) { |
| 2483 function_kind = RawFunction::kSetterFunction; | 2482 function_kind = RawFunction::kSetterFunction; |
| 2484 } else { | 2483 } else { |
| 2485 function_kind = RawFunction::kRegularFunction; | 2484 function_kind = RawFunction::kRegularFunction; |
| 2486 } | 2485 } |
| 2487 Function& func = Function::Handle( | 2486 Function& func = Function::Handle( |
| 2488 Function::New(*method->name, | 2487 Function::New(*method->name, |
| 2489 function_kind, | 2488 function_kind, |
| 2490 method->has_static, | 2489 method->has_static, |
| 2491 method->has_const, | 2490 method->has_const, |
| 2491 method->has_abstract, |
| 2492 method->has_external, | 2492 method->has_external, |
| 2493 method_pos)); | 2493 method_pos)); |
| 2494 func.set_result_type(*method->type); | 2494 func.set_result_type(*method->type); |
| 2495 func.set_end_token_pos(method_end_pos); | 2495 func.set_end_token_pos(method_end_pos); |
| 2496 | 2496 |
| 2497 // No need to resolve parameter types yet, or add parameters to local scope. | 2497 // No need to resolve parameter types yet, or add parameters to local scope. |
| 2498 ASSERT(is_top_level_); | 2498 ASSERT(is_top_level_); |
| 2499 AddFormalParamsToFunction(&method->params, func); | 2499 AddFormalParamsToFunction(&method->params, func); |
| 2500 members->AddFunction(func); | 2500 members->AddFunction(func); |
| 2501 } | 2501 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2561 class_field.set_has_initializer(has_initializer); | 2561 class_field.set_has_initializer(has_initializer); |
| 2562 members->AddField(class_field); | 2562 members->AddField(class_field); |
| 2563 | 2563 |
| 2564 // For static final fields, set value to "uninitialized" and | 2564 // For static final fields, set value to "uninitialized" and |
| 2565 // create a kConstImplicitGetter getter method. | 2565 // create a kConstImplicitGetter getter method. |
| 2566 if (field->has_static && has_initializer) { | 2566 if (field->has_static && has_initializer) { |
| 2567 class_field.set_value(Instance::Handle(Object::sentinel())); | 2567 class_field.set_value(Instance::Handle(Object::sentinel())); |
| 2568 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); | 2568 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); |
| 2569 getter = Function::New(getter_name, RawFunction::kConstImplicitGetter, | 2569 getter = Function::New(getter_name, RawFunction::kConstImplicitGetter, |
| 2570 field->has_static, field->has_final, false, | 2570 field->has_static, field->has_final, false, |
| 2571 /* is_abstract */ false, |
| 2571 field->name_pos); | 2572 field->name_pos); |
| 2572 getter.set_result_type(*field->type); | 2573 getter.set_result_type(*field->type); |
| 2573 members->AddFunction(getter); | 2574 members->AddFunction(getter); |
| 2574 } | 2575 } |
| 2575 | 2576 |
| 2576 // For instance fields, we create implicit getter and setter methods. | 2577 // For instance fields, we create implicit getter and setter methods. |
| 2577 if (!field->has_static) { | 2578 if (!field->has_static) { |
| 2578 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); | 2579 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); |
| 2579 getter = Function::New(getter_name, RawFunction::kImplicitGetter, | 2580 getter = Function::New(getter_name, RawFunction::kImplicitGetter, |
| 2580 field->has_static, field->has_final, false, | 2581 field->has_static, field->has_final, false, |
| 2582 /* is_abstract */ false, |
| 2581 field->name_pos); | 2583 field->name_pos); |
| 2582 ParamList params; | 2584 ParamList params; |
| 2583 params.AddReceiver(TokenPos()); | 2585 params.AddReceiver(TokenPos()); |
| 2584 getter.set_result_type(*field->type); | 2586 getter.set_result_type(*field->type); |
| 2585 AddFormalParamsToFunction(¶ms, getter); | 2587 AddFormalParamsToFunction(¶ms, getter); |
| 2586 members->AddFunction(getter); | 2588 members->AddFunction(getter); |
| 2587 if (!field->has_final) { | 2589 if (!field->has_final) { |
| 2588 // Build a setter accessor for non-const fields. | 2590 // Build a setter accessor for non-const fields. |
| 2589 String& setter_name = String::Handle(Field::SetterSymbol(*field->name)); | 2591 String& setter_name = String::Handle(Field::SetterSymbol(*field->name)); |
| 2590 setter = Function::New(setter_name, RawFunction::kImplicitSetter, | 2592 setter = Function::New(setter_name, RawFunction::kImplicitSetter, |
| 2591 field->has_static, field->has_final, false, | 2593 field->has_static, field->has_final, false, |
| 2594 /* is_abstract */ false, |
| 2592 field->name_pos); | 2595 field->name_pos); |
| 2593 ParamList params; | 2596 ParamList params; |
| 2594 params.AddReceiver(TokenPos()); | 2597 params.AddReceiver(TokenPos()); |
| 2595 params.AddFinalParameter(TokenPos(), | 2598 params.AddFinalParameter(TokenPos(), |
| 2596 &String::ZoneHandle(Symbols::Value()), | 2599 &String::ZoneHandle(Symbols::Value()), |
| 2597 field->type); | 2600 field->type); |
| 2598 setter.set_result_type(Type::Handle(Type::VoidType())); | 2601 setter.set_result_type(Type::Handle(Type::VoidType())); |
| 2599 AddFormalParamsToFunction(¶ms, setter); | 2602 AddFormalParamsToFunction(¶ms, setter); |
| 2600 members->AddFunction(setter); | 2603 members->AddFunction(setter); |
| 2601 } | 2604 } |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2961 String::Concat(class_desc->class_name(), | 2964 String::Concat(class_desc->class_name(), |
| 2962 String::Handle(Symbols::Dot()))); | 2965 String::Handle(Symbols::Dot()))); |
| 2963 ctor_name = Symbols::New(ctor_name); | 2966 ctor_name = Symbols::New(ctor_name); |
| 2964 // The token position for the implicit constructor is the 'class' | 2967 // The token position for the implicit constructor is the 'class' |
| 2965 // keyword of the constructor's class. | 2968 // keyword of the constructor's class. |
| 2966 Function& ctor = Function::Handle( | 2969 Function& ctor = Function::Handle( |
| 2967 Function::New(ctor_name, | 2970 Function::New(ctor_name, |
| 2968 RawFunction::kConstructor, | 2971 RawFunction::kConstructor, |
| 2969 /* is_static = */ false, | 2972 /* is_static = */ false, |
| 2970 /* is_const = */ false, | 2973 /* is_const = */ false, |
| 2974 /* is_abstract = */ false, |
| 2971 /* is_external = */ false, | 2975 /* is_external = */ false, |
| 2972 class_desc->token_pos())); | 2976 class_desc->token_pos())); |
| 2973 ParamList params; | 2977 ParamList params; |
| 2974 // Add implicit 'this' parameter. | 2978 // Add implicit 'this' parameter. |
| 2975 params.AddReceiver(TokenPos()); | 2979 params.AddReceiver(TokenPos()); |
| 2976 // Add implicit parameter for construction phase. | 2980 // Add implicit parameter for construction phase. |
| 2977 params.AddFinalParameter( | 2981 params.AddFinalParameter( |
| 2978 TokenPos(), | 2982 TokenPos(), |
| 2979 &String::ZoneHandle(Symbols::PhaseParameter()), | 2983 &String::ZoneHandle(Symbols::PhaseParameter()), |
| 2980 &Type::ZoneHandle(Type::DynamicType())); | 2984 &Type::ZoneHandle(Type::DynamicType())); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3080 } | 3084 } |
| 3081 ParamList func_params; | 3085 ParamList func_params; |
| 3082 const bool no_explicit_default_values = false; | 3086 const bool no_explicit_default_values = false; |
| 3083 ParseFormalParameterList(no_explicit_default_values, &func_params); | 3087 ParseFormalParameterList(no_explicit_default_values, &func_params); |
| 3084 // The field 'is_static' has no meaning for signature functions. | 3088 // The field 'is_static' has no meaning for signature functions. |
| 3085 Function& signature_function = Function::Handle( | 3089 Function& signature_function = Function::Handle( |
| 3086 Function::New(*alias_name, | 3090 Function::New(*alias_name, |
| 3087 RawFunction::kSignatureFunction, | 3091 RawFunction::kSignatureFunction, |
| 3088 /* is_static = */ false, | 3092 /* is_static = */ false, |
| 3089 /* is_const = */ false, | 3093 /* is_const = */ false, |
| 3094 /* is_abstract = */ false, |
| 3090 /* is_external = */ false, | 3095 /* is_external = */ false, |
| 3091 alias_name_pos)); | 3096 alias_name_pos)); |
| 3092 signature_function.set_owner(alias_owner); | 3097 signature_function.set_owner(alias_owner); |
| 3093 signature_function.set_result_type(result_type); | 3098 signature_function.set_result_type(result_type); |
| 3094 AddFormalParamsToFunction(&func_params, signature_function); | 3099 AddFormalParamsToFunction(&func_params, signature_function); |
| 3095 const String& signature = String::Handle(signature_function.Signature()); | 3100 const String& signature = String::Handle(signature_function.Signature()); |
| 3096 if (FLAG_trace_parser) { | 3101 if (FLAG_trace_parser) { |
| 3097 OS::Print("TopLevel parsing function type alias '%s'\n", | 3102 OS::Print("TopLevel parsing function type alias '%s'\n", |
| 3098 signature.ToCString()); | 3103 signature.ToCString()); |
| 3099 } | 3104 } |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3512 field.set_value(Instance::Handle(Instance::null())); | 3517 field.set_value(Instance::Handle(Instance::null())); |
| 3513 top_level->fields.Add(field); | 3518 top_level->fields.Add(field); |
| 3514 library_.AddObject(field, var_name); | 3519 library_.AddObject(field, var_name); |
| 3515 if (CurrentToken() == Token::kASSIGN) { | 3520 if (CurrentToken() == Token::kASSIGN) { |
| 3516 ConsumeToken(); | 3521 ConsumeToken(); |
| 3517 SkipExpr(); | 3522 SkipExpr(); |
| 3518 field.set_value(Instance::Handle(Object::sentinel())); | 3523 field.set_value(Instance::Handle(Object::sentinel())); |
| 3519 // Create a static const getter. | 3524 // Create a static const getter. |
| 3520 String& getter_name = String::ZoneHandle(Field::GetterSymbol(var_name)); | 3525 String& getter_name = String::ZoneHandle(Field::GetterSymbol(var_name)); |
| 3521 getter = Function::New(getter_name, RawFunction::kConstImplicitGetter, | 3526 getter = Function::New(getter_name, RawFunction::kConstImplicitGetter, |
| 3522 is_static, is_final, false, name_pos); | 3527 is_static, is_final, false, false, name_pos); |
| 3523 getter.set_result_type(type); | 3528 getter.set_result_type(type); |
| 3524 top_level->functions.Add(getter); | 3529 top_level->functions.Add(getter); |
| 3525 } else if (is_final || is_const) { | 3530 } else if (is_final || is_const) { |
| 3526 ErrorMsg(name_pos, "missing initializer for final or const variable"); | 3531 ErrorMsg(name_pos, "missing initializer for final or const variable"); |
| 3527 } | 3532 } |
| 3528 | 3533 |
| 3529 if (CurrentToken() == Token::kCOMMA) { | 3534 if (CurrentToken() == Token::kCOMMA) { |
| 3530 ConsumeToken(); | 3535 ConsumeToken(); |
| 3531 } else if (CurrentToken() == Token::kSEMICOLON) { | 3536 } else if (CurrentToken() == Token::kSEMICOLON) { |
| 3532 ConsumeToken(); | 3537 ConsumeToken(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3593 SkipExpr(); | 3598 SkipExpr(); |
| 3594 ExpectSemicolon(); | 3599 ExpectSemicolon(); |
| 3595 function_end_pos = TokenPos(); | 3600 function_end_pos = TokenPos(); |
| 3596 } else if (IsLiteral("native")) { | 3601 } else if (IsLiteral("native")) { |
| 3597 ParseNativeDeclaration(); | 3602 ParseNativeDeclaration(); |
| 3598 } else { | 3603 } else { |
| 3599 ErrorMsg("function block expected"); | 3604 ErrorMsg("function block expected"); |
| 3600 } | 3605 } |
| 3601 Function& func = Function::Handle( | 3606 Function& func = Function::Handle( |
| 3602 Function::New(func_name, RawFunction::kRegularFunction, | 3607 Function::New(func_name, RawFunction::kRegularFunction, |
| 3603 is_static, false, is_external, function_pos)); | 3608 is_static, false, false, is_external, function_pos)); |
| 3604 func.set_result_type(result_type); | 3609 func.set_result_type(result_type); |
| 3605 func.set_end_token_pos(function_end_pos); | 3610 func.set_end_token_pos(function_end_pos); |
| 3606 AddFormalParamsToFunction(¶ms, func); | 3611 AddFormalParamsToFunction(¶ms, func); |
| 3607 top_level->functions.Add(func); | 3612 top_level->functions.Add(func); |
| 3608 library_.AddObject(func, func_name); | 3613 library_.AddObject(func, func_name); |
| 3609 } | 3614 } |
| 3610 | 3615 |
| 3611 | 3616 |
| 3612 void Parser::ParseTopLevelAccessor(TopLevel* top_level) { | 3617 void Parser::ParseTopLevelAccessor(TopLevel* top_level) { |
| 3613 TRACE_PARSER("ParseTopLevelAccessor"); | 3618 TRACE_PARSER("ParseTopLevelAccessor"); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3675 ExpectSemicolon(); | 3680 ExpectSemicolon(); |
| 3676 } else if (IsLiteral("native")) { | 3681 } else if (IsLiteral("native")) { |
| 3677 ParseNativeDeclaration(); | 3682 ParseNativeDeclaration(); |
| 3678 } else { | 3683 } else { |
| 3679 ErrorMsg("function block expected"); | 3684 ErrorMsg("function block expected"); |
| 3680 } | 3685 } |
| 3681 Function& func = Function::Handle( | 3686 Function& func = Function::Handle( |
| 3682 Function::New(accessor_name, | 3687 Function::New(accessor_name, |
| 3683 is_getter? RawFunction::kGetterFunction : | 3688 is_getter? RawFunction::kGetterFunction : |
| 3684 RawFunction::kSetterFunction, | 3689 RawFunction::kSetterFunction, |
| 3685 is_static, false, false, accessor_pos)); | 3690 is_static, false, false, false, accessor_pos)); |
| 3686 func.set_result_type(result_type); | 3691 func.set_result_type(result_type); |
| 3687 AddFormalParamsToFunction(¶ms, func); | 3692 AddFormalParamsToFunction(¶ms, func); |
| 3688 top_level->functions.Add(func); | 3693 top_level->functions.Add(func); |
| 3689 library_.AddObject(func, accessor_name); | 3694 library_.AddObject(func, accessor_name); |
| 3690 } | 3695 } |
| 3691 | 3696 |
| 3692 | 3697 |
| 3693 void Parser::ParseLibraryName() { | 3698 void Parser::ParseLibraryName() { |
| 3694 TRACE_PARSER("ParseLibraryName"); | 3699 TRACE_PARSER("ParseLibraryName"); |
| 3695 if ((script_.kind() == RawScript::kLibraryTag) && | 3700 if ((script_.kind() == RawScript::kLibraryTag) && |
| (...skipping 5088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8784 void Parser::SkipQualIdent() { | 8789 void Parser::SkipQualIdent() { |
| 8785 ASSERT(IsIdentifier()); | 8790 ASSERT(IsIdentifier()); |
| 8786 ConsumeToken(); | 8791 ConsumeToken(); |
| 8787 if (CurrentToken() == Token::kPERIOD) { | 8792 if (CurrentToken() == Token::kPERIOD) { |
| 8788 ConsumeToken(); // Consume the kPERIOD token. | 8793 ConsumeToken(); // Consume the kPERIOD token. |
| 8789 ExpectIdentifier("identifier expected after '.'"); | 8794 ExpectIdentifier("identifier expected after '.'"); |
| 8790 } | 8795 } |
| 8791 } | 8796 } |
| 8792 | 8797 |
| 8793 } // namespace dart | 8798 } // namespace dart |
| OLD | NEW |