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 21 matching lines...) Expand all Loading... | |
| 32 #include "vm/tags.h" | 32 #include "vm/tags.h" |
| 33 #include "vm/timer.h" | 33 #include "vm/timer.h" |
| 34 #include "vm/zone.h" | 34 #include "vm/zone.h" |
| 35 | 35 |
| 36 namespace dart { | 36 namespace dart { |
| 37 | 37 |
| 38 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements."); | 38 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements."); |
| 39 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks."); | 39 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks."); |
| 40 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); | 40 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); |
| 41 DEFINE_FLAG(bool, warn_mixin_typedef, true, "Warning on legacy mixin typedef."); | 41 DEFINE_FLAG(bool, warn_mixin_typedef, true, "Warning on legacy mixin typedef."); |
| 42 DEFINE_FLAG(bool, enable_async, false, "Enable async operations."); | |
| 42 DECLARE_FLAG(bool, error_on_bad_type); | 43 DECLARE_FLAG(bool, error_on_bad_type); |
| 43 DECLARE_FLAG(bool, throw_on_javascript_int_overflow); | 44 DECLARE_FLAG(bool, throw_on_javascript_int_overflow); |
| 44 DECLARE_FLAG(bool, warn_on_javascript_compatibility); | 45 DECLARE_FLAG(bool, warn_on_javascript_compatibility); |
| 45 | 46 |
| 46 static void CheckedModeHandler(bool value) { | 47 static void CheckedModeHandler(bool value) { |
| 47 FLAG_enable_asserts = value; | 48 FLAG_enable_asserts = value; |
| 48 FLAG_enable_type_checks = value; | 49 FLAG_enable_type_checks = value; |
| 49 } | 50 } |
| 50 | 51 |
| 51 // --enable-checked-mode and --checked both enable checked mode which is | 52 // --enable-checked-mode and --checked both enable checked mode which is |
| (...skipping 2818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2870 AstNode* guarded_block_statements = | 2871 AstNode* guarded_block_statements = |
| 2871 new IfNode(Scanner::kNoSourcePos, comparison, ctor_block, NULL); | 2872 new IfNode(Scanner::kNoSourcePos, comparison, ctor_block, NULL); |
| 2872 current_block_->statements->Add(guarded_block_statements); | 2873 current_block_->statements->Add(guarded_block_statements); |
| 2873 } | 2874 } |
| 2874 current_block_->statements->Add(new ReturnNode(func.end_token_pos())); | 2875 current_block_->statements->Add(new ReturnNode(func.end_token_pos())); |
| 2875 SequenceNode* statements = CloseBlock(); | 2876 SequenceNode* statements = CloseBlock(); |
| 2876 return statements; | 2877 return statements; |
| 2877 } | 2878 } |
| 2878 | 2879 |
| 2879 | 2880 |
| 2881 // TODO(mlippautz): Once we know where Future should come from, adjust how we | |
| 2882 // get it's definition. | |
|
hausner
2014/07/12 00:05:24
its
Michael Lippautz (Google)
2014/07/14 20:22:48
Done.
| |
| 2883 RawClass* Parser::GetFutureClass() { | |
| 2884 const Class& cls = Class::Handle(library_.LookupClass(Symbols::Future())); | |
| 2885 if (cls.IsNull()) { | |
| 2886 ReportError("async modifier requires dart:async to be imported"); | |
| 2887 } | |
| 2888 return cls.raw(); | |
| 2889 } | |
| 2890 | |
| 2891 | |
| 2892 SequenceNode* Parser::BuildAsyncFuture(const Function& outer, | |
| 2893 SequenceNode* parsed_body, | |
| 2894 ParamList* params, | |
| 2895 intptr_t saved_pos) { | |
| 2896 const Class& future = Class::ZoneHandle(I, GetFutureClass()); | |
| 2897 ASSERT(!future.IsNull()); | |
| 2898 const Function& constructor = Function::ZoneHandle(I, | |
| 2899 future.LookupFunction(Symbols::FutureConstructor())); | |
| 2900 ASSERT(!constructor.IsNull()); | |
| 2901 // Create the closure containing the parsed_body of this function. | |
| 2902 Class& sig_cls = Class::ZoneHandle(I); | |
| 2903 Type& sig_type = Type::ZoneHandle(I); | |
| 2904 Function& closure = Function::ZoneHandle(I); | |
| 2905 String& sig = String::ZoneHandle(I); | |
| 2906 ParamList closure_params; | |
| 2907 closure_params.AddFinalParameter( | |
| 2908 saved_pos, | |
| 2909 &Symbols::ClosureParameter(), | |
| 2910 &Type::ZoneHandle(I, Type::DynamicType())); | |
| 2911 closure = Function::NewClosureFunction( | |
| 2912 Symbols::AnonymousClosure(), | |
| 2913 innermost_function(), | |
| 2914 saved_pos); | |
| 2915 AddFormalParamsToFunction(&closure_params, closure); | |
| 2916 closure.set_is_synthetic_container(true); | |
| 2917 // TODO(mlippautz): For an async outer function declared with Future<T> the | |
| 2918 // result type of the synthesized closure should be T. | |
| 2919 closure.set_result_type(AbstractType::Handle(Type::DynamicType())); | |
| 2920 sig = closure.Signature(); | |
| 2921 sig_cls = library_.LookupLocalClass(sig); | |
| 2922 if (sig_cls.IsNull()) { | |
| 2923 sig_cls = Class::NewSignatureClass(sig, closure, script_, saved_pos); | |
| 2924 library_.AddClass(sig_cls); | |
| 2925 } | |
| 2926 closure.set_signature_class(sig_cls); | |
| 2927 sig_type = sig_cls.SignatureType(); | |
| 2928 if (!sig_type.IsFinalized()) { | |
| 2929 ClassFinalizer::FinalizeType( | |
| 2930 sig_cls, sig_type, ClassFinalizer::kCanonicalize); | |
| 2931 } | |
| 2932 ASSERT(AbstractType::Handle(I, closure.result_type()).IsResolved()); | |
| 2933 ASSERT(closure.NumParameters() == closure_params.parameters->length()); | |
| 2934 OpenFunctionBlock(closure); | |
| 2935 AddFormalParamsToScope(&closure_params, current_block_->scope); | |
| 2936 LocalScope* cur_scope = current_block_->scope; | |
| 2937 String& var_name = String::ZoneHandle(I); | |
| 2938 bool var_captured = false; | |
| 2939 // Capture parameters of the enclosing function. | |
| 2940 for (intptr_t i = 0; i < params->parameters->length(); i++) { | |
| 2941 ParamDesc& param_desc = (*params->parameters)[i]; | |
| 2942 var_name = param_desc.var->name().raw(); | |
| 2943 // Ignore implicit closure parameter, but capture 'this' from any enclosing | |
| 2944 // methods. | |
| 2945 if (var_name.Equals(Symbols::ClosureParameter())) { | |
| 2946 continue; | |
| 2947 } | |
| 2948 var_captured = cur_scope->CaptureVariable(var_name); | |
| 2949 ASSERT(var_captured); | |
| 2950 } | |
| 2951 LocalScope* parsed_body_scope = parsed_body->scope(); | |
| 2952 // Capture all variables that have already been captured by the enclosing | |
| 2953 // function. | |
| 2954 for (intptr_t j = 0; j < parsed_body->scope()->num_variables(); j++) { | |
| 2955 if (parsed_body_scope->VariableAt(j)->is_captured()) { | |
| 2956 var_captured = | |
| 2957 cur_scope->CaptureVariable(parsed_body_scope->VariableAt(j)->name()); | |
| 2958 ASSERT(var_captured); | |
| 2959 } | |
| 2960 } | |
| 2961 ClosureNode* cn = new(I) ClosureNode( | |
| 2962 Scanner::kNoSourcePos, closure, NULL, cur_scope); | |
| 2963 ArgumentListNode* arguments = new (I) ArgumentListNode(saved_pos); | |
| 2964 arguments->Add(cn); | |
| 2965 ConstructorCallNode* ccn = new (I) ConstructorCallNode( | |
| 2966 Scanner::kNoSourcePos, TypeArguments::ZoneHandle(I), constructor, | |
| 2967 arguments); | |
| 2968 ReturnNode* rn = new (I) ReturnNode(Scanner::kNoSourcePos, ccn); | |
| 2969 current_block_->statements->Add(rn); | |
| 2970 return CloseBlock(); | |
| 2971 } | |
| 2972 | |
| 2973 | |
| 2880 // Parser is at the opening parenthesis of the formal parameter | 2974 // Parser is at the opening parenthesis of the formal parameter |
| 2881 // declaration of the function or constructor. | 2975 // declaration of the function or constructor. |
| 2882 // Parse the formal parameters and code. | 2976 // Parse the formal parameters and code. |
| 2883 SequenceNode* Parser::ParseFunc(const Function& func, | 2977 SequenceNode* Parser::ParseFunc(const Function& func, |
| 2884 Array* default_parameter_values) { | 2978 Array* default_parameter_values) { |
| 2885 TRACE_PARSER("ParseFunc"); | 2979 TRACE_PARSER("ParseFunc"); |
| 2886 Function& saved_innermost_function = | 2980 Function& saved_innermost_function = |
| 2887 Function::Handle(I, innermost_function().raw()); | 2981 Function::Handle(I, innermost_function().raw()); |
| 2888 innermost_function_ = func.raw(); | 2982 innermost_function_ = func.raw(); |
| 2889 | 2983 |
| 2890 // Save current try index. Try index starts at zero for each function. | 2984 // Save current try index. Try index starts at zero for each function. |
| 2891 intptr_t saved_try_index = last_used_try_index_; | 2985 intptr_t saved_try_index = last_used_try_index_; |
| 2892 last_used_try_index_ = 0; | 2986 last_used_try_index_ = 0; |
| 2893 | 2987 |
| 2988 intptr_t formal_params_pos = TokenPos(); | |
| 2894 // TODO(12455) : Need better validation mechanism. | 2989 // TODO(12455) : Need better validation mechanism. |
| 2895 | 2990 |
| 2896 if (func.IsConstructor()) { | 2991 if (func.IsConstructor()) { |
| 2897 SequenceNode* statements = ParseConstructor(func, default_parameter_values); | 2992 SequenceNode* statements = ParseConstructor(func, default_parameter_values); |
| 2898 innermost_function_ = saved_innermost_function.raw(); | 2993 innermost_function_ = saved_innermost_function.raw(); |
| 2899 last_used_try_index_ = saved_try_index; | 2994 last_used_try_index_ = saved_try_index; |
| 2900 return statements; | 2995 return statements; |
| 2901 } | 2996 } |
| 2902 | 2997 |
| 2903 ASSERT(!func.IsConstructor()); | 2998 ASSERT(!func.IsConstructor()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2918 ASSERT(current_class().raw() == func.Owner()); | 3013 ASSERT(current_class().raw() == func.Owner()); |
| 2919 params.AddReceiver(ReceiverType(current_class()), func.token_pos()); | 3014 params.AddReceiver(ReceiverType(current_class()), func.token_pos()); |
| 2920 } else if (func.IsFactory()) { | 3015 } else if (func.IsFactory()) { |
| 2921 // The first parameter of a factory is the TypeArguments vector of | 3016 // The first parameter of a factory is the TypeArguments vector of |
| 2922 // the type of the instance to be allocated. | 3017 // the type of the instance to be allocated. |
| 2923 params.AddFinalParameter( | 3018 params.AddFinalParameter( |
| 2924 TokenPos(), | 3019 TokenPos(), |
| 2925 &Symbols::TypeArgumentsParameter(), | 3020 &Symbols::TypeArgumentsParameter(), |
| 2926 &Type::ZoneHandle(I, Type::DynamicType())); | 3021 &Type::ZoneHandle(I, Type::DynamicType())); |
| 2927 } | 3022 } |
| 2928 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction()); | 3023 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction() || |
| 3024 func.is_synthetic_container()); | |
| 2929 const bool allow_explicit_default_values = true; | 3025 const bool allow_explicit_default_values = true; |
| 2930 if (func.IsGetterFunction()) { | 3026 if (func.IsGetterFunction()) { |
| 2931 // Populate function scope with the formal parameters. Since in this case | 3027 // Populate function scope with the formal parameters. Since in this case |
| 2932 // we are compiling a getter this will at most populate the receiver. | 3028 // we are compiling a getter this will at most populate the receiver. |
| 2933 AddFormalParamsToScope(¶ms, current_block_->scope); | 3029 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 3030 } else if (func.is_synthetic_container() && Function::Handle( | |
| 3031 func.parent_function()).IsGetterFunction()) { | |
| 3032 AddFormalParamsToScope(¶ms, current_block_->scope); | |
| 3033 ASSERT(AbstractType::Handle(I, func.result_type()).IsResolved()); | |
| 3034 ASSERT(func.NumParameters() == params.parameters->length()); | |
| 3035 } else if (func.is_synthetic_container()) { | |
| 3036 AddFormalParamsToScope(¶ms, current_block_->scope); | |
| 3037 ASSERT(AbstractType::Handle(I, func.result_type()).IsResolved()); | |
| 3038 ASSERT(func.NumParameters() == params.parameters->length()); | |
| 3039 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); | |
| 3040 // Parse them away. | |
| 2934 } else { | 3041 } else { |
| 2935 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); | 3042 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); |
| 2936 | 3043 |
| 2937 // The number of parameters and their type are not yet set in local | 3044 // The number of parameters and their type are not yet set in local |
| 2938 // functions, since they are not 'top-level' parsed. | 3045 // functions, since they are not 'top-level' parsed. |
| 2939 if (func.IsLocalFunction()) { | 3046 if (func.IsLocalFunction()) { |
| 2940 AddFormalParamsToFunction(¶ms, func); | 3047 AddFormalParamsToFunction(¶ms, func); |
| 2941 } | 3048 } |
| 2942 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); | 3049 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); |
| 2943 ASSERT(AbstractType::Handle(I, func.result_type()).IsResolved()); | 3050 ASSERT(AbstractType::Handle(I, func.result_type()).IsResolved()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 2964 if (IsInstantiatorRequired()) { | 3071 if (IsInstantiatorRequired()) { |
| 2965 // Make sure that the receiver of the enclosing instance function | 3072 // Make sure that the receiver of the enclosing instance function |
| 2966 // (or implicit first parameter of an enclosing factory) is marked as | 3073 // (or implicit first parameter of an enclosing factory) is marked as |
| 2967 // captured if type checks are enabled, because they may access it to | 3074 // captured if type checks are enabled, because they may access it to |
| 2968 // instantiate types. | 3075 // instantiate types. |
| 2969 CaptureInstantiator(); | 3076 CaptureInstantiator(); |
| 2970 } | 3077 } |
| 2971 } | 3078 } |
| 2972 } | 3079 } |
| 2973 | 3080 |
| 3081 RawFunction::Modifier func_modifier = ParseFunctionModifier(); | |
| 3082 func.set_modifier(func_modifier); | |
| 3083 | |
| 2974 OpenBlock(); // Open a nested scope for the outermost function block. | 3084 OpenBlock(); // Open a nested scope for the outermost function block. |
| 2975 intptr_t end_token_pos = 0; | 3085 intptr_t end_token_pos = 0; |
| 2976 if (CurrentToken() == Token::kLBRACE) { | 3086 if (CurrentToken() == Token::kLBRACE) { |
| 2977 ConsumeToken(); | 3087 ConsumeToken(); |
| 2978 if (String::Handle(I, func.name()).Equals( | 3088 if (String::Handle(I, func.name()).Equals( |
| 2979 Symbols::EqualOperator())) { | 3089 Symbols::EqualOperator())) { |
| 2980 const Class& owner = Class::Handle(I, func.Owner()); | 3090 const Class& owner = Class::Handle(I, func.Owner()); |
| 2981 if (!owner.IsObjectClass()) { | 3091 if (!owner.IsObjectClass()) { |
| 2982 AddEqualityNullCheck(); | 3092 AddEqualityNullCheck(); |
| 2983 } | 3093 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3025 &func)); // Unpatched external function. | 3135 &func)); // Unpatched external function. |
| 3026 end_token_pos = TokenPos(); | 3136 end_token_pos = TokenPos(); |
| 3027 } else { | 3137 } else { |
| 3028 UnexpectedToken(); | 3138 UnexpectedToken(); |
| 3029 } | 3139 } |
| 3030 | 3140 |
| 3031 ASSERT(func.end_token_pos() == func.token_pos() || | 3141 ASSERT(func.end_token_pos() == func.token_pos() || |
| 3032 func.end_token_pos() == end_token_pos); | 3142 func.end_token_pos() == end_token_pos); |
| 3033 func.set_end_token_pos(end_token_pos); | 3143 func.set_end_token_pos(end_token_pos); |
| 3034 SequenceNode* body = CloseBlock(); | 3144 SequenceNode* body = CloseBlock(); |
| 3145 if (func.IsAsyncFunction() && !func.is_synthetic_container()) { | |
| 3146 body = BuildAsyncFuture(func, body, ¶ms, formal_params_pos); | |
| 3147 } | |
| 3035 current_block_->statements->Add(body); | 3148 current_block_->statements->Add(body); |
| 3036 innermost_function_ = saved_innermost_function.raw(); | 3149 innermost_function_ = saved_innermost_function.raw(); |
| 3037 last_used_try_index_ = saved_try_index; | 3150 last_used_try_index_ = saved_try_index; |
| 3038 return CloseBlock(); | 3151 return CloseBlock(); |
| 3039 } | 3152 } |
| 3040 | 3153 |
| 3041 | 3154 |
| 3042 void Parser::AddEqualityNullCheck() { | 3155 void Parser::AddEqualityNullCheck() { |
| 3043 AstNode* argument = | 3156 AstNode* argument = |
| 3044 new LoadLocalNode(Scanner::kNoSourcePos, | 3157 new LoadLocalNode(Scanner::kNoSourcePos, |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3338 ASSERT((method->redirect_name == NULL) || method->IsConstructor()); | 3451 ASSERT((method->redirect_name == NULL) || method->IsConstructor()); |
| 3339 | 3452 |
| 3340 if (method->IsConstructor() && | 3453 if (method->IsConstructor() && |
| 3341 method->has_external && | 3454 method->has_external && |
| 3342 method->params.has_field_initializer) { | 3455 method->params.has_field_initializer) { |
| 3343 ReportError(method->name_pos, | 3456 ReportError(method->name_pos, |
| 3344 "external constructor '%s' may not have field initializers", | 3457 "external constructor '%s' may not have field initializers", |
| 3345 method->name->ToCString()); | 3458 method->name->ToCString()); |
| 3346 } | 3459 } |
| 3347 | 3460 |
| 3461 ParseFunctionModifier(); | |
| 3462 | |
| 3348 intptr_t method_end_pos = TokenPos(); | 3463 intptr_t method_end_pos = TokenPos(); |
| 3349 if ((CurrentToken() == Token::kLBRACE) || | 3464 if ((CurrentToken() == Token::kLBRACE) || |
| 3350 (CurrentToken() == Token::kARROW)) { | 3465 (CurrentToken() == Token::kARROW)) { |
| 3351 if (method->has_abstract) { | 3466 if (method->has_abstract) { |
| 3352 ReportError(TokenPos(), | 3467 ReportError(TokenPos(), |
| 3353 "abstract method '%s' may not have a function body", | 3468 "abstract method '%s' may not have a function body", |
| 3354 method->name->ToCString()); | 3469 method->name->ToCString()); |
| 3355 } else if (method->has_external) { | 3470 } else if (method->has_external) { |
| 3356 ReportError(TokenPos(), | 3471 ReportError(TokenPos(), |
| 3357 "external %s '%s' may not have a function body", | 3472 "external %s '%s' may not have a function body", |
| (...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4772 } else if (CurrentToken() == Token::kSEMICOLON) { | 4887 } else if (CurrentToken() == Token::kSEMICOLON) { |
| 4773 ConsumeToken(); | 4888 ConsumeToken(); |
| 4774 break; | 4889 break; |
| 4775 } else { | 4890 } else { |
| 4776 ExpectSemicolon(); // Reports error. | 4891 ExpectSemicolon(); // Reports error. |
| 4777 } | 4892 } |
| 4778 } | 4893 } |
| 4779 } | 4894 } |
| 4780 | 4895 |
| 4781 | 4896 |
| 4897 RawFunction::Modifier Parser::ParseFunctionModifier() { | |
| 4898 if (FLAG_enable_async) { | |
| 4899 if (CurrentLiteral()->raw() == Symbols::Async().raw()) { | |
| 4900 ConsumeToken(); | |
| 4901 return RawFunction::kAsync; | |
| 4902 } | |
| 4903 } | |
| 4904 return RawFunction::kNoModifier; | |
| 4905 } | |
| 4906 | |
| 4907 | |
| 4782 void Parser::ParseTopLevelFunction(TopLevel* top_level, | 4908 void Parser::ParseTopLevelFunction(TopLevel* top_level, |
| 4783 intptr_t metadata_pos) { | 4909 intptr_t metadata_pos) { |
| 4784 TRACE_PARSER("ParseTopLevelFunction"); | 4910 TRACE_PARSER("ParseTopLevelFunction"); |
| 4785 const intptr_t decl_begin_pos = TokenPos(); | 4911 const intptr_t decl_begin_pos = TokenPos(); |
| 4786 AbstractType& result_type = Type::Handle(I, Type::DynamicType()); | 4912 AbstractType& result_type = Type::Handle(I, Type::DynamicType()); |
| 4787 const bool is_static = true; | 4913 const bool is_static = true; |
| 4788 bool is_external = false; | 4914 bool is_external = false; |
| 4789 bool is_patch = false; | 4915 bool is_patch = false; |
| 4790 if (is_patch_source() && | 4916 if (is_patch_source() && |
| 4791 (CurrentToken() == Token::kIDENT) && | 4917 (CurrentToken() == Token::kIDENT) && |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4825 } | 4951 } |
| 4826 // A setter named x= may co-exist with a function named x, thus we do | 4952 // A setter named x= may co-exist with a function named x, thus we do |
| 4827 // not need to check setters. | 4953 // not need to check setters. |
| 4828 | 4954 |
| 4829 CheckToken(Token::kLPAREN); | 4955 CheckToken(Token::kLPAREN); |
| 4830 const intptr_t function_pos = TokenPos(); | 4956 const intptr_t function_pos = TokenPos(); |
| 4831 ParamList params; | 4957 ParamList params; |
| 4832 const bool allow_explicit_default_values = true; | 4958 const bool allow_explicit_default_values = true; |
| 4833 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); | 4959 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); |
| 4834 | 4960 |
| 4961 RawFunction::Modifier func_modifier = ParseFunctionModifier(); | |
| 4962 | |
| 4835 intptr_t function_end_pos = function_pos; | 4963 intptr_t function_end_pos = function_pos; |
| 4836 bool is_native = false; | 4964 bool is_native = false; |
| 4837 if (is_external) { | 4965 if (is_external) { |
| 4838 function_end_pos = TokenPos(); | 4966 function_end_pos = TokenPos(); |
| 4839 ExpectSemicolon(); | 4967 ExpectSemicolon(); |
| 4840 } else if (CurrentToken() == Token::kLBRACE) { | 4968 } else if (CurrentToken() == Token::kLBRACE) { |
| 4841 SkipBlock(); | 4969 SkipBlock(); |
| 4842 function_end_pos = TokenPos(); | 4970 function_end_pos = TokenPos(); |
| 4843 ExpectToken(Token::kRBRACE); | 4971 ExpectToken(Token::kRBRACE); |
| 4844 } else if (CurrentToken() == Token::kARROW) { | 4972 } else if (CurrentToken() == Token::kARROW) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 4859 RawFunction::kRegularFunction, | 4987 RawFunction::kRegularFunction, |
| 4860 is_static, | 4988 is_static, |
| 4861 /* is_const = */ false, | 4989 /* is_const = */ false, |
| 4862 /* is_abstract = */ false, | 4990 /* is_abstract = */ false, |
| 4863 is_external, | 4991 is_external, |
| 4864 is_native, | 4992 is_native, |
| 4865 current_class(), | 4993 current_class(), |
| 4866 decl_begin_pos)); | 4994 decl_begin_pos)); |
| 4867 func.set_result_type(result_type); | 4995 func.set_result_type(result_type); |
| 4868 func.set_end_token_pos(function_end_pos); | 4996 func.set_end_token_pos(function_end_pos); |
| 4997 func.set_modifier(func_modifier); | |
| 4869 if (is_native && library_.is_dart_scheme() && library_.IsPrivate(func_name)) { | 4998 if (is_native && library_.is_dart_scheme() && library_.IsPrivate(func_name)) { |
| 4870 func.set_is_visible(false); | 4999 func.set_is_visible(false); |
| 4871 } | 5000 } |
| 4872 AddFormalParamsToFunction(¶ms, func); | 5001 AddFormalParamsToFunction(¶ms, func); |
| 4873 top_level->functions.Add(func); | 5002 top_level->functions.Add(func); |
| 4874 if (!is_patch) { | 5003 if (!is_patch) { |
| 4875 library_.AddObject(func, func_name); | 5004 library_.AddObject(func, func_name); |
| 4876 } else { | 5005 } else { |
| 4877 library_.ReplaceObject(func, func_name); | 5006 library_.ReplaceObject(func, func_name); |
| 4878 } | 5007 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4961 if (found && !is_patch) { | 5090 if (found && !is_patch) { |
| 4962 ReportError(name_pos, "%s for '%s' is already defined", | 5091 ReportError(name_pos, "%s for '%s' is already defined", |
| 4963 is_getter ? "getter" : "setter", | 5092 is_getter ? "getter" : "setter", |
| 4964 field_name->ToCString()); | 5093 field_name->ToCString()); |
| 4965 } else if (!found && is_patch) { | 5094 } else if (!found && is_patch) { |
| 4966 ReportError(name_pos, "missing %s for '%s' cannot be patched", | 5095 ReportError(name_pos, "missing %s for '%s' cannot be patched", |
| 4967 is_getter ? "getter" : "setter", | 5096 is_getter ? "getter" : "setter", |
| 4968 field_name->ToCString()); | 5097 field_name->ToCString()); |
| 4969 } | 5098 } |
| 4970 | 5099 |
| 5100 RawFunction::Modifier func_modifier = ParseFunctionModifier(); | |
| 5101 | |
| 4971 intptr_t accessor_end_pos = accessor_pos; | 5102 intptr_t accessor_end_pos = accessor_pos; |
| 4972 bool is_native = false; | 5103 bool is_native = false; |
| 4973 if (is_external) { | 5104 if (is_external) { |
| 4974 accessor_end_pos = TokenPos(); | 5105 accessor_end_pos = TokenPos(); |
| 4975 ExpectSemicolon(); | 5106 ExpectSemicolon(); |
| 4976 } else if (CurrentToken() == Token::kLBRACE) { | 5107 } else if (CurrentToken() == Token::kLBRACE) { |
| 4977 SkipBlock(); | 5108 SkipBlock(); |
| 4978 accessor_end_pos = TokenPos(); | 5109 accessor_end_pos = TokenPos(); |
| 4979 ExpectToken(Token::kRBRACE); | 5110 ExpectToken(Token::kRBRACE); |
| 4980 } else if (CurrentToken() == Token::kARROW) { | 5111 } else if (CurrentToken() == Token::kARROW) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 4996 RawFunction::kSetterFunction, | 5127 RawFunction::kSetterFunction, |
| 4997 is_static, | 5128 is_static, |
| 4998 /* is_const = */ false, | 5129 /* is_const = */ false, |
| 4999 /* is_abstract = */ false, | 5130 /* is_abstract = */ false, |
| 5000 is_external, | 5131 is_external, |
| 5001 is_native, | 5132 is_native, |
| 5002 current_class(), | 5133 current_class(), |
| 5003 decl_begin_pos)); | 5134 decl_begin_pos)); |
| 5004 func.set_result_type(result_type); | 5135 func.set_result_type(result_type); |
| 5005 func.set_end_token_pos(accessor_end_pos); | 5136 func.set_end_token_pos(accessor_end_pos); |
| 5137 func.set_modifier(func_modifier); | |
| 5006 if (is_native && library_.is_dart_scheme() && | 5138 if (is_native && library_.is_dart_scheme() && |
| 5007 library_.IsPrivate(accessor_name)) { | 5139 library_.IsPrivate(accessor_name)) { |
| 5008 func.set_is_visible(false); | 5140 func.set_is_visible(false); |
| 5009 } | 5141 } |
| 5010 AddFormalParamsToFunction(¶ms, func); | 5142 AddFormalParamsToFunction(¶ms, func); |
| 5011 top_level->functions.Add(func); | 5143 top_level->functions.Add(func); |
| 5012 if (!is_patch) { | 5144 if (!is_patch) { |
| 5013 library_.AddObject(func, accessor_name); | 5145 library_.AddObject(func, accessor_name); |
| 5014 } else { | 5146 } else { |
| 5015 library_.ReplaceObject(func, accessor_name); | 5147 library_.ReplaceObject(func, accessor_name); |
| (...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6200 } else { | 6332 } else { |
| 6201 SetPosition(saved_pos); | 6333 SetPosition(saved_pos); |
| 6202 return false; | 6334 return false; |
| 6203 } | 6335 } |
| 6204 // Check parameter list and the following token. | 6336 // Check parameter list and the following token. |
| 6205 if (CurrentToken() == Token::kLPAREN) { | 6337 if (CurrentToken() == Token::kLPAREN) { |
| 6206 SkipToMatchingParenthesis(); | 6338 SkipToMatchingParenthesis(); |
| 6207 if ((CurrentToken() == Token::kLBRACE) || | 6339 if ((CurrentToken() == Token::kLBRACE) || |
| 6208 (CurrentToken() == Token::kARROW) || | 6340 (CurrentToken() == Token::kARROW) || |
| 6209 (is_top_level_ && IsLiteral("native")) || | 6341 (is_top_level_ && IsLiteral("native")) || |
| 6210 is_external) { | 6342 is_external || |
| 6343 (FLAG_enable_async && | |
| 6344 CurrentLiteral()->raw() == Symbols::Async().raw())) { | |
| 6211 SetPosition(saved_pos); | 6345 SetPosition(saved_pos); |
| 6212 return true; | 6346 return true; |
| 6213 } | 6347 } |
| 6214 } | 6348 } |
| 6215 SetPosition(saved_pos); | 6349 SetPosition(saved_pos); |
| 6216 return false; | 6350 return false; |
| 6217 } | 6351 } |
| 6218 | 6352 |
| 6219 | 6353 |
| 6220 bool Parser::IsTopLevelAccessor() { | 6354 bool Parser::IsTopLevelAccessor() { |
| (...skipping 4518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10739 SkipType(true); | 10873 SkipType(true); |
| 10740 } | 10874 } |
| 10741 ExpectIdentifier("function name expected"); | 10875 ExpectIdentifier("function name expected"); |
| 10742 } | 10876 } |
| 10743 if (CurrentToken() == Token::kLPAREN) { | 10877 if (CurrentToken() == Token::kLPAREN) { |
| 10744 const bool allow_explicit_default_values = true; | 10878 const bool allow_explicit_default_values = true; |
| 10745 ParamList params; | 10879 ParamList params; |
| 10746 params.skipped = true; | 10880 params.skipped = true; |
| 10747 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); | 10881 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); |
| 10748 } | 10882 } |
| 10883 ParseFunctionModifier(); | |
| 10749 if (CurrentToken() == Token::kLBRACE) { | 10884 if (CurrentToken() == Token::kLBRACE) { |
| 10750 SkipBlock(); | 10885 SkipBlock(); |
| 10751 ExpectToken(Token::kRBRACE); | 10886 ExpectToken(Token::kRBRACE); |
| 10752 } else if (CurrentToken() == Token::kARROW) { | 10887 } else if (CurrentToken() == Token::kARROW) { |
| 10753 ConsumeToken(); | 10888 ConsumeToken(); |
| 10754 SkipExpr(); | 10889 SkipExpr(); |
| 10755 } | 10890 } |
| 10756 } | 10891 } |
| 10757 | 10892 |
| 10758 | 10893 |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11059 void Parser::SkipQualIdent() { | 11194 void Parser::SkipQualIdent() { |
| 11060 ASSERT(IsIdentifier()); | 11195 ASSERT(IsIdentifier()); |
| 11061 ConsumeToken(); | 11196 ConsumeToken(); |
| 11062 if (CurrentToken() == Token::kPERIOD) { | 11197 if (CurrentToken() == Token::kPERIOD) { |
| 11063 ConsumeToken(); // Consume the kPERIOD token. | 11198 ConsumeToken(); // Consume the kPERIOD token. |
| 11064 ExpectIdentifier("identifier expected after '.'"); | 11199 ExpectIdentifier("identifier expected after '.'"); |
| 11065 } | 11200 } |
| 11066 } | 11201 } |
| 11067 | 11202 |
| 11068 } // namespace dart | 11203 } // namespace dart |
| OLD | NEW |