| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 tokens_(TokenStream::Handle(script.tokens())), | 167 tokens_(TokenStream::Handle(script.tokens())), |
| 168 token_index_(0), | 168 token_index_(0), |
| 169 current_block_(NULL), | 169 current_block_(NULL), |
| 170 is_top_level_(false), | 170 is_top_level_(false), |
| 171 current_member_(NULL), | 171 current_member_(NULL), |
| 172 allow_function_literals_(true), | 172 allow_function_literals_(true), |
| 173 current_function_(Function::Handle()), | 173 current_function_(Function::Handle()), |
| 174 current_class_(Class::Handle()), | 174 current_class_(Class::Handle()), |
| 175 library_(library), | 175 library_(library), |
| 176 try_blocks_list_(NULL) { | 176 try_blocks_list_(NULL) { |
| 177 ASSERT(!tokens_.IsNull()); |
| 178 ASSERT(!library.IsNull()); |
| 177 SetPosition(0); | 179 SetPosition(0); |
| 178 } | 180 } |
| 179 | 181 |
| 180 | 182 |
| 181 Parser::Parser(const Script& script, | 183 Parser::Parser(const Script& script, |
| 182 const Function& function, | 184 const Function& function, |
| 183 intptr_t token_index) | 185 intptr_t token_index) |
| 184 : script_(script), | 186 : script_(script), |
| 185 tokens_(TokenStream::Handle(script.tokens())), | 187 tokens_(TokenStream::Handle(script.tokens())), |
| 186 token_index_(0), | 188 token_index_(0), |
| 187 current_block_(NULL), | 189 current_block_(NULL), |
| 188 is_top_level_(false), | 190 is_top_level_(false), |
| 189 current_member_(NULL), | 191 current_member_(NULL), |
| 190 allow_function_literals_(true), | 192 allow_function_literals_(true), |
| 191 current_function_(function), | 193 current_function_(function), |
| 192 current_class_(Class::Handle(current_function_.owner())), | 194 current_class_(Class::Handle(current_function_.owner())), |
| 193 library_(Library::Handle(current_class_.library())), | 195 library_(Library::Handle(current_class_.library())), |
| 194 try_blocks_list_(NULL) { | 196 try_blocks_list_(NULL) { |
| 197 ASSERT(!tokens_.IsNull()); |
| 198 ASSERT(!function.IsNull()); |
| 195 SetPosition(token_index); | 199 SetPosition(token_index); |
| 196 } | 200 } |
| 197 | 201 |
| 198 | 202 |
| 199 bool Parser::SetAllowFunctionLiterals(bool value) { | 203 bool Parser::SetAllowFunctionLiterals(bool value) { |
| 200 bool current_value = allow_function_literals_; | 204 bool current_value = allow_function_literals_; |
| 201 allow_function_literals_ = value; | 205 allow_function_literals_ = value; |
| 202 return current_value; | 206 return current_value; |
| 203 } | 207 } |
| 204 | 208 |
| (...skipping 2400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2605 if (CurrentToken() != Token::kIDENT) { | 2609 if (CurrentToken() != Token::kIDENT) { |
| 2606 ErrorMsg("function alias name expected"); | 2610 ErrorMsg("function alias name expected"); |
| 2607 } | 2611 } |
| 2608 const intptr_t alias_name_pos = token_index_; | 2612 const intptr_t alias_name_pos = token_index_; |
| 2609 const String* alias_name = CurrentLiteral(); | 2613 const String* alias_name = CurrentLiteral(); |
| 2610 ConsumeToken(); | 2614 ConsumeToken(); |
| 2611 | 2615 |
| 2612 // Allocate an interface to hold the type parameters and their 'extends' | 2616 // Allocate an interface to hold the type parameters and their 'extends' |
| 2613 // constraints. Make it the owner of the function type descriptor. | 2617 // constraints. Make it the owner of the function type descriptor. |
| 2614 const Class& alias_owner = Class::Handle( | 2618 const Class& alias_owner = Class::Handle( |
| 2615 Class::New(String::Handle(String::NewSymbol("")), Script::Handle())); | 2619 Class::New(String::Handle(String::NewSymbol(":alias_owner")), |
| 2620 Script::Handle())); |
| 2616 alias_owner.set_is_interface(); | 2621 alias_owner.set_is_interface(); |
| 2617 set_current_class(alias_owner); | 2622 set_current_class(alias_owner); |
| 2618 ParseTypeParameters(alias_owner); | 2623 ParseTypeParameters(alias_owner); |
| 2619 if (CurrentToken() != Token::kLPAREN) { | 2624 if (CurrentToken() != Token::kLPAREN) { |
| 2620 ErrorMsg("formal parameter list expected"); | 2625 ErrorMsg("formal parameter list expected"); |
| 2621 } | 2626 } |
| 2622 | 2627 |
| 2623 // At this point, the type parameters have been parsed, so we can resolve the | 2628 // At this point, the type parameters have been parsed, so we can resolve the |
| 2624 // result type. | 2629 // result type. |
| 2625 if (!result_type.IsNull() && !result_type.IsResolved()) { | 2630 if (!result_type.IsNull() && !result_type.IsResolved()) { |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3200 | 3205 |
| 3201 void Parser::ParseTopLevel() { | 3206 void Parser::ParseTopLevel() { |
| 3202 // Collect the classes found at the top level in this growable array. | 3207 // Collect the classes found at the top level in this growable array. |
| 3203 // They need to be registered with class finalization after parsing | 3208 // They need to be registered with class finalization after parsing |
| 3204 // has been completed. | 3209 // has been completed. |
| 3205 GrowableArray<const Class*> classes; | 3210 GrowableArray<const Class*> classes; |
| 3206 SetPosition(0); | 3211 SetPosition(0); |
| 3207 is_top_level_ = true; | 3212 is_top_level_ = true; |
| 3208 TopLevel top_level; | 3213 TopLevel top_level; |
| 3209 Class& toplevel_class = Class::ZoneHandle( | 3214 Class& toplevel_class = Class::ZoneHandle( |
| 3210 Class::New(String::ZoneHandle(String::NewSymbol("")), script_)); | 3215 Class::New(String::ZoneHandle(String::NewSymbol("::")), script_)); |
| 3211 toplevel_class.set_library(library_); | 3216 toplevel_class.set_library(library_); |
| 3212 | 3217 |
| 3218 // TODO(regis): We need a better interface to the class finalizer. |
| 3219 // We notify the class finalizer to expect pending classes. |
| 3220 // This allows signature classes generated at runtime to be properly |
| 3221 // finalized, without finalizing them prematurely at compile time. |
| 3222 ClassFinalizer::ExpectPendingClasses(); |
| 3223 |
| 3213 if (is_library_source()) { | 3224 if (is_library_source()) { |
| 3214 ParseLibraryDefinition(); | 3225 ParseLibraryDefinition(); |
| 3215 } | 3226 } |
| 3216 | 3227 |
| 3217 while (true) { | 3228 while (true) { |
| 3218 set_current_class(Class::Handle()); // No current class. | 3229 set_current_class(Class::Handle()); // No current class. |
| 3219 if (CurrentToken() == Token::kCLASS) { | 3230 if (CurrentToken() == Token::kCLASS) { |
| 3220 ParseClassDefinition(&classes); | 3231 ParseClassDefinition(&classes); |
| 3221 } else if (CurrentToken() == Token::kTYPEDEF) { | 3232 } else if (CurrentToken() == Token::kTYPEDEF) { |
| 3222 ParseFunctionTypeAlias(&classes); | 3233 ParseFunctionTypeAlias(&classes); |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3672 | 3683 |
| 3673 // Since the signature type is cached by the signature class, it may have | 3684 // Since the signature type is cached by the signature class, it may have |
| 3674 // been finalized already. | 3685 // been finalized already. |
| 3675 if (!signature_type.IsFinalized()) { | 3686 if (!signature_type.IsFinalized()) { |
| 3676 String& errmsg = String::Handle(); | 3687 String& errmsg = String::Handle(); |
| 3677 signature_type = | 3688 signature_type = |
| 3678 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg); | 3689 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg); |
| 3679 if (!errmsg.IsNull()) { | 3690 if (!errmsg.IsNull()) { |
| 3680 ErrorMsg(errmsg.ToCString()); | 3691 ErrorMsg(errmsg.ToCString()); |
| 3681 } | 3692 } |
| 3682 // The call to ClassFinalizer::FinalizeTypeWhileParsing may have extended | 3693 // The call to ClassFinalizer::FinalizeAndCanonicalizeType may have |
| 3683 // the vector of type arguments. | 3694 // extended the vector of type arguments. |
| 3684 ASSERT(signature_type_arguments.IsNull() || | 3695 ASSERT(signature_type_arguments.IsNull() || |
| 3685 (signature_type_arguments.Length() == | 3696 (signature_type_arguments.Length() == |
| 3686 signature_class.NumTypeArguments())); | 3697 signature_class.NumTypeArguments())); |
| 3687 // The signature_class should not have changed. | 3698 // The signature_class should not have changed. |
| 3688 ASSERT(signature_type.type_class() == signature_class.raw()); | 3699 ASSERT(signature_type.type_class() == signature_class.raw()); |
| 3689 } | 3700 } |
| 3690 | 3701 |
| 3691 // Now patch the function type of the variable. | 3702 // Now patch the function type of the variable. |
| 3692 function_type.set_type_class(signature_class); | 3703 function_type.set_type_class(signature_class); |
| 3693 function_type.set_arguments(signature_type_arguments); | 3704 function_type.set_arguments(signature_type_arguments); |
| (...skipping 3572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7266 } | 7277 } |
| 7267 | 7278 |
| 7268 | 7279 |
| 7269 void Parser::SkipNestedExpr() { | 7280 void Parser::SkipNestedExpr() { |
| 7270 const bool saved_mode = SetAllowFunctionLiterals(true); | 7281 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7271 SkipExpr(); | 7282 SkipExpr(); |
| 7272 SetAllowFunctionLiterals(saved_mode); | 7283 SetAllowFunctionLiterals(saved_mode); |
| 7273 } | 7284 } |
| 7274 | 7285 |
| 7275 } // namespace dart | 7286 } // namespace dart |
| OLD | NEW |