| 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 |
| 3213 if (is_library_source()) { | 3218 if (is_library_source()) { |
| 3214 ParseLibraryDefinition(); | 3219 ParseLibraryDefinition(); |
| 3215 } | 3220 } |
| 3216 | 3221 |
| 3217 while (true) { | 3222 while (true) { |
| 3218 set_current_class(Class::Handle()); // No current class. | 3223 set_current_class(Class::Handle()); // No current class. |
| 3219 if (CurrentToken() == Token::kCLASS) { | 3224 if (CurrentToken() == Token::kCLASS) { |
| 3220 ParseClassDefinition(&classes); | 3225 ParseClassDefinition(&classes); |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3672 | 3677 |
| 3673 // Since the signature type is cached by the signature class, it may have | 3678 // Since the signature type is cached by the signature class, it may have |
| 3674 // been finalized already. | 3679 // been finalized already. |
| 3675 if (!signature_type.IsFinalized()) { | 3680 if (!signature_type.IsFinalized()) { |
| 3676 String& errmsg = String::Handle(); | 3681 String& errmsg = String::Handle(); |
| 3677 signature_type = | 3682 signature_type = |
| 3678 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg); | 3683 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg); |
| 3679 if (!errmsg.IsNull()) { | 3684 if (!errmsg.IsNull()) { |
| 3680 ErrorMsg(errmsg.ToCString()); | 3685 ErrorMsg(errmsg.ToCString()); |
| 3681 } | 3686 } |
| 3682 // The call to ClassFinalizer::FinalizeTypeWhileParsing may have extended | 3687 // The call to ClassFinalizer::FinalizeAndCanonicalizeType may have |
| 3683 // the vector of type arguments. | 3688 // extended the vector of type arguments. |
| 3684 ASSERT(signature_type_arguments.IsNull() || | 3689 ASSERT(signature_type_arguments.IsNull() || |
| 3685 (signature_type_arguments.Length() == | 3690 (signature_type_arguments.Length() == |
| 3686 signature_class.NumTypeArguments())); | 3691 signature_class.NumTypeArguments())); |
| 3687 // The signature_class should not have changed. | 3692 // The signature_class should not have changed. |
| 3688 ASSERT(signature_type.type_class() == signature_class.raw()); | 3693 ASSERT(signature_type.type_class() == signature_class.raw()); |
| 3689 } | 3694 } |
| 3690 | 3695 |
| 3691 // Now patch the function type of the variable. | 3696 // Now patch the function type of the variable. |
| 3692 function_type.set_type_class(signature_class); | 3697 function_type.set_type_class(signature_class); |
| 3693 function_type.set_arguments(signature_type_arguments); | 3698 function_type.set_arguments(signature_type_arguments); |
| (...skipping 3591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7285 } | 7290 } |
| 7286 | 7291 |
| 7287 | 7292 |
| 7288 void Parser::SkipNestedExpr() { | 7293 void Parser::SkipNestedExpr() { |
| 7289 const bool saved_mode = SetAllowFunctionLiterals(true); | 7294 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7290 SkipExpr(); | 7295 SkipExpr(); |
| 7291 SetAllowFunctionLiterals(saved_mode); | 7296 SetAllowFunctionLiterals(saved_mode); |
| 7292 } | 7297 } |
| 7293 | 7298 |
| 7294 } // namespace dart | 7299 } // namespace dart |
| OLD | NEW |