| 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 "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
| 9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
| 10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 2729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2740 } else if (func.IsFactory()) { | 2740 } else if (func.IsFactory()) { |
| 2741 // The first parameter of a factory is the AbstractTypeArguments vector of | 2741 // The first parameter of a factory is the AbstractTypeArguments vector of |
| 2742 // the type of the instance to be allocated. | 2742 // the type of the instance to be allocated. |
| 2743 params.AddFinalParameter( | 2743 params.AddFinalParameter( |
| 2744 TokenPos(), | 2744 TokenPos(), |
| 2745 &Symbols::TypeArgumentsParameter(), | 2745 &Symbols::TypeArgumentsParameter(), |
| 2746 &Type::ZoneHandle(Type::DynamicType())); | 2746 &Type::ZoneHandle(Type::DynamicType())); |
| 2747 } | 2747 } |
| 2748 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction()); | 2748 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction()); |
| 2749 const bool allow_explicit_default_values = true; | 2749 const bool allow_explicit_default_values = true; |
| 2750 if (!func.IsGetterFunction()) { | 2750 if (func.IsGetterFunction()) { |
| 2751 // Populate function scope with the formal parameters. Since in this case |
| 2752 // we are compiling a getter this will at most populate the receiver. |
| 2753 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 2754 } else { |
| 2751 ParseFormalParameterList(allow_explicit_default_values, ¶ms); | 2755 ParseFormalParameterList(allow_explicit_default_values, ¶ms); |
| 2752 } else { | 2756 |
| 2753 // TODO(hausner): Remove this once we no longer support the old | 2757 // The number of parameters and their type are not yet set in local |
| 2754 // getter syntax with explicit empty parameter list. | 2758 // functions, since they are not 'top-level' parsed. |
| 2755 if (CurrentToken() == Token::kLPAREN) { | 2759 if (func.IsLocalFunction()) { |
| 2756 ConsumeToken(); | 2760 AddFormalParamsToFunction(¶ms, func); |
| 2757 ExpectToken(Token::kRPAREN); | 2761 } |
| 2762 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); |
| 2763 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 2764 ASSERT(func.NumParameters() == params.parameters->length()); |
| 2765 |
| 2766 // Check whether the function has any field initializer formal parameters, |
| 2767 // which are not allowed in non-constructor functions. |
| 2768 if (params.has_field_initializer) { |
| 2769 for (int i = 0; i < params.parameters->length(); i++) { |
| 2770 ParamDesc& param = (*params.parameters)[i]; |
| 2771 if (param.is_field_initializer) { |
| 2772 ErrorMsg(param.name_pos, |
| 2773 "field initializer only allowed in constructors"); |
| 2774 } |
| 2775 } |
| 2776 } |
| 2777 // Populate function scope with the formal parameters. |
| 2778 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 2779 |
| 2780 if (FLAG_enable_type_checks && |
| 2781 (current_block_->scope->function_level() > 0)) { |
| 2782 // We are parsing, but not compiling, a local function. |
| 2783 // The instantiator may be required at run time for generic type checks. |
| 2784 if (IsInstantiatorRequired()) { |
| 2785 // Make sure that the receiver of the enclosing instance function |
| 2786 // (or implicit first parameter of an enclosing factory) is marked as |
| 2787 // captured if type checks are enabled, because they may access it to |
| 2788 // instantiate types. |
| 2789 CaptureInstantiator(); |
| 2790 } |
| 2758 } | 2791 } |
| 2759 } | 2792 } |
| 2760 | 2793 |
| 2761 // The number of parameters and their type are not yet set in local functions, | |
| 2762 // since they are not 'top-level' parsed. | |
| 2763 if (func.IsLocalFunction()) { | |
| 2764 AddFormalParamsToFunction(¶ms, func); | |
| 2765 } | |
| 2766 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); | |
| 2767 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | |
| 2768 ASSERT(func.NumParameters() == params.parameters->length()); | |
| 2769 | |
| 2770 // Check whether the function has any field initializer formal parameters, | |
| 2771 // which are not allowed in non-constructor functions. | |
| 2772 if (params.has_field_initializer) { | |
| 2773 for (int i = 0; i < params.parameters->length(); i++) { | |
| 2774 ParamDesc& param = (*params.parameters)[i]; | |
| 2775 if (param.is_field_initializer) { | |
| 2776 ErrorMsg(param.name_pos, | |
| 2777 "field initializer only allowed in constructors"); | |
| 2778 } | |
| 2779 } | |
| 2780 } | |
| 2781 // Populate function scope with the formal parameters. | |
| 2782 AddFormalParamsToScope(¶ms, current_block_->scope); | |
| 2783 | |
| 2784 if (FLAG_enable_type_checks && | |
| 2785 (current_block_->scope->function_level() > 0)) { | |
| 2786 // We are parsing, but not compiling, a local function. | |
| 2787 // The instantiator may be required at run time for generic type checks. | |
| 2788 if (IsInstantiatorRequired()) { | |
| 2789 // Make sure that the receiver of the enclosing instance function | |
| 2790 // (or implicit first parameter of an enclosing factory) is marked as | |
| 2791 // captured if type checks are enabled, because they may access it to | |
| 2792 // instantiate types. | |
| 2793 CaptureInstantiator(); | |
| 2794 } | |
| 2795 } | |
| 2796 | |
| 2797 OpenBlock(); // Open a nested scope for the outermost function block. | 2794 OpenBlock(); // Open a nested scope for the outermost function block. |
| 2798 intptr_t end_token_pos = 0; | 2795 intptr_t end_token_pos = 0; |
| 2799 if (CurrentToken() == Token::kLBRACE) { | 2796 if (CurrentToken() == Token::kLBRACE) { |
| 2800 ConsumeToken(); | 2797 ConsumeToken(); |
| 2801 ParseStatementSequence(); | 2798 ParseStatementSequence(); |
| 2802 end_token_pos = TokenPos(); | 2799 end_token_pos = TokenPos(); |
| 2803 ExpectToken(Token::kRBRACE); | 2800 ExpectToken(Token::kRBRACE); |
| 2804 } else if (CurrentToken() == Token::kARROW) { | 2801 } else if (CurrentToken() == Token::kARROW) { |
| 2805 ConsumeToken(); | 2802 ConsumeToken(); |
| 2806 const intptr_t expr_pos = TokenPos(); | 2803 const intptr_t expr_pos = TokenPos(); |
| (...skipping 7668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10475 void Parser::SkipQualIdent() { | 10472 void Parser::SkipQualIdent() { |
| 10476 ASSERT(IsIdentifier()); | 10473 ASSERT(IsIdentifier()); |
| 10477 ConsumeToken(); | 10474 ConsumeToken(); |
| 10478 if (CurrentToken() == Token::kPERIOD) { | 10475 if (CurrentToken() == Token::kPERIOD) { |
| 10479 ConsumeToken(); // Consume the kPERIOD token. | 10476 ConsumeToken(); // Consume the kPERIOD token. |
| 10480 ExpectIdentifier("identifier expected after '.'"); | 10477 ExpectIdentifier("identifier expected after '.'"); |
| 10481 } | 10478 } |
| 10482 } | 10479 } |
| 10483 | 10480 |
| 10484 } // namespace dart | 10481 } // namespace dart |
| OLD | NEW |