| 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 2051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2062 } | 2062 } |
| 2063 SkipToMatchingParenthesis(); | 2063 SkipToMatchingParenthesis(); |
| 2064 } else { | 2064 } else { |
| 2065 SkipInitializers(); | 2065 SkipInitializers(); |
| 2066 } | 2066 } |
| 2067 } | 2067 } |
| 2068 | 2068 |
| 2069 // Only constructors can redirect to another method. | 2069 // Only constructors can redirect to another method. |
| 2070 ASSERT((method->redirect_name == NULL) || method->IsConstructor()); | 2070 ASSERT((method->redirect_name == NULL) || method->IsConstructor()); |
| 2071 | 2071 |
| 2072 intptr_t method_end_pos = method_pos; |
| 2072 if ((CurrentToken() == Token::kLBRACE) || | 2073 if ((CurrentToken() == Token::kLBRACE) || |
| 2073 (CurrentToken() == Token::kARROW)) { | 2074 (CurrentToken() == Token::kARROW)) { |
| 2074 if (method->has_abstract) { | 2075 if (method->has_abstract) { |
| 2075 ErrorMsg(method->name_pos, | 2076 ErrorMsg(method->name_pos, |
| 2076 "abstract method '%s' may not have function body", | 2077 "abstract method '%s' may not have function body", |
| 2077 method->name->ToCString()); | 2078 method->name->ToCString()); |
| 2078 } else if (method->IsConstructor() && method->has_const) { | 2079 } else if (method->IsConstructor() && method->has_const) { |
| 2079 ErrorMsg(method->name_pos, | 2080 ErrorMsg(method->name_pos, |
| 2080 "const constructor '%s' may not have function body", | 2081 "const constructor '%s' may not have function body", |
| 2081 method->name->ToCString()); | 2082 method->name->ToCString()); |
| 2082 } else if (method->IsFactory() && method->has_const) { | 2083 } else if (method->IsFactory() && method->has_const) { |
| 2083 ErrorMsg(method->name_pos, | 2084 ErrorMsg(method->name_pos, |
| 2084 "const factory '%s' may not have function body", | 2085 "const factory '%s' may not have function body", |
| 2085 method->name->ToCString()); | 2086 method->name->ToCString()); |
| 2086 } else if (members->is_interface()) { | 2087 } else if (members->is_interface()) { |
| 2087 ErrorMsg(method->name_pos, | 2088 ErrorMsg(method->name_pos, |
| 2088 "function body not allowed in interface declaration"); | 2089 "function body not allowed in interface declaration"); |
| 2089 } | 2090 } |
| 2090 if (CurrentToken() == Token::kLBRACE) { | 2091 if (CurrentToken() == Token::kLBRACE) { |
| 2091 SkipBlock(); | 2092 SkipBlock(); |
| 2092 } else { | 2093 } else { |
| 2093 ConsumeToken(); | 2094 ConsumeToken(); |
| 2094 SkipExpr(); | 2095 SkipExpr(); |
| 2095 ExpectSemicolon(); | 2096 ExpectSemicolon(); |
| 2096 } | 2097 } |
| 2098 method_end_pos = token_index_; |
| 2097 } else if (IsLiteral("native")) { | 2099 } else if (IsLiteral("native")) { |
| 2098 if (method->has_abstract) { | 2100 if (method->has_abstract) { |
| 2099 ErrorMsg(method->name_pos, | 2101 ErrorMsg(method->name_pos, |
| 2100 "abstract method '%s' may not have function body", | 2102 "abstract method '%s' may not have function body", |
| 2101 method->name->ToCString()); | 2103 method->name->ToCString()); |
| 2102 } else if (members->is_interface()) { | 2104 } else if (members->is_interface()) { |
| 2103 ErrorMsg(method->name_pos, | 2105 ErrorMsg(method->name_pos, |
| 2104 "function body not allowed in interface declaration"); | 2106 "function body not allowed in interface declaration"); |
| 2105 } else if (method->IsConstructor() && method->has_const) { | 2107 } else if (method->IsConstructor() && method->has_const) { |
| 2106 ErrorMsg(method->name_pos, | 2108 ErrorMsg(method->name_pos, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2144 } else { | 2146 } else { |
| 2145 function_kind = RawFunction::kFunction; | 2147 function_kind = RawFunction::kFunction; |
| 2146 } | 2148 } |
| 2147 Function& func = Function::ZoneHandle( | 2149 Function& func = Function::ZoneHandle( |
| 2148 Function::New(*method->name, | 2150 Function::New(*method->name, |
| 2149 function_kind, | 2151 function_kind, |
| 2150 method->has_static, | 2152 method->has_static, |
| 2151 method->has_const, | 2153 method->has_const, |
| 2152 method_pos)); | 2154 method_pos)); |
| 2153 func.set_result_type(*method->type); | 2155 func.set_result_type(*method->type); |
| 2156 func.set_end_token_index(method_end_pos); |
| 2154 | 2157 |
| 2155 // No need to resolve parameter types yet, or add parameters to local scope. | 2158 // No need to resolve parameter types yet, or add parameters to local scope. |
| 2156 ASSERT(is_top_level_); | 2159 ASSERT(is_top_level_); |
| 2157 AddFormalParamsToFunction(&method->params, func); | 2160 AddFormalParamsToFunction(&method->params, func); |
| 2158 members->AddFunction(&func); | 2161 members->AddFunction(&func); |
| 2159 } | 2162 } |
| 2160 | 2163 |
| 2161 | 2164 |
| 2162 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) { | 2165 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) { |
| 2163 // The parser has read the first field name and is now at the token | 2166 // The parser has read the first field name and is now at the token |
| (...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3125 } | 3128 } |
| 3126 | 3129 |
| 3127 if (CurrentToken() != Token::kLPAREN) { | 3130 if (CurrentToken() != Token::kLPAREN) { |
| 3128 ErrorMsg("'(' expected"); | 3131 ErrorMsg("'(' expected"); |
| 3129 } | 3132 } |
| 3130 const intptr_t function_pos = token_index_; | 3133 const intptr_t function_pos = token_index_; |
| 3131 ParamList params; | 3134 ParamList params; |
| 3132 const bool allow_explicit_default_values = true; | 3135 const bool allow_explicit_default_values = true; |
| 3133 ParseFormalParameterList(allow_explicit_default_values, ¶ms); | 3136 ParseFormalParameterList(allow_explicit_default_values, ¶ms); |
| 3134 | 3137 |
| 3138 intptr_t function_end_pos = function_pos; |
| 3135 if (CurrentToken() == Token::kLBRACE) { | 3139 if (CurrentToken() == Token::kLBRACE) { |
| 3136 SkipBlock(); | 3140 SkipBlock(); |
| 3141 function_end_pos = token_index_; |
| 3137 } else if (CurrentToken() == Token::kARROW) { | 3142 } else if (CurrentToken() == Token::kARROW) { |
| 3138 ConsumeToken(); | 3143 ConsumeToken(); |
| 3139 SkipExpr(); | 3144 SkipExpr(); |
| 3140 ExpectSemicolon(); | 3145 ExpectSemicolon(); |
| 3146 function_end_pos = token_index_; |
| 3141 } else if (IsLiteral("native")) { | 3147 } else if (IsLiteral("native")) { |
| 3142 ParseNativeDeclaration(); | 3148 ParseNativeDeclaration(); |
| 3143 } else { | 3149 } else { |
| 3144 ErrorMsg("function block expected"); | 3150 ErrorMsg("function block expected"); |
| 3145 } | 3151 } |
| 3146 Function& func = Function::ZoneHandle( | 3152 Function& func = Function::ZoneHandle( |
| 3147 Function::New(func_name, RawFunction::kFunction, | 3153 Function::New(func_name, RawFunction::kFunction, |
| 3148 is_static, false, function_pos)); | 3154 is_static, false, function_pos)); |
| 3149 func.set_result_type(result_type); | 3155 func.set_result_type(result_type); |
| 3156 func.set_end_token_index(function_end_pos); |
| 3150 AddFormalParamsToFunction(¶ms, func); | 3157 AddFormalParamsToFunction(¶ms, func); |
| 3151 top_level->functions.Add(&func); | 3158 top_level->functions.Add(&func); |
| 3152 library_.AddObject(func, func_name); | 3159 library_.AddObject(func, func_name); |
| 3153 } | 3160 } |
| 3154 | 3161 |
| 3155 | 3162 |
| 3156 void Parser::ParseTopLevelAccessor(TopLevel* top_level) { | 3163 void Parser::ParseTopLevelAccessor(TopLevel* top_level) { |
| 3157 const bool is_static = true; | 3164 const bool is_static = true; |
| 3158 AbstractType& result_type = AbstractType::Handle(); | 3165 AbstractType& result_type = AbstractType::Handle(); |
| 3159 bool is_getter = (CurrentToken() == Token::kGET); | 3166 bool is_getter = (CurrentToken() == Token::kGET); |
| (...skipping 4579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7739 } | 7746 } |
| 7740 | 7747 |
| 7741 | 7748 |
| 7742 void Parser::SkipNestedExpr() { | 7749 void Parser::SkipNestedExpr() { |
| 7743 const bool saved_mode = SetAllowFunctionLiterals(true); | 7750 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7744 SkipExpr(); | 7751 SkipExpr(); |
| 7745 SetAllowFunctionLiterals(saved_mode); | 7752 SetAllowFunctionLiterals(saved_mode); |
| 7746 } | 7753 } |
| 7747 | 7754 |
| 7748 } // namespace dart | 7755 } // namespace dart |
| OLD | NEW |