| 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 #ifndef VM_PARSER_H_ | 5 #ifndef VM_PARSER_H_ |
| 6 #define VM_PARSER_H_ | 6 #define VM_PARSER_H_ |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 | 9 |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 ParsedFunction(Isolate* isolate, const Function& function) | 41 ParsedFunction(Isolate* isolate, const Function& function) |
| 42 : function_(function), | 42 : function_(function), |
| 43 code_(Code::Handle(isolate, function.unoptimized_code())), | 43 code_(Code::Handle(isolate, function.unoptimized_code())), |
| 44 node_sequence_(NULL), | 44 node_sequence_(NULL), |
| 45 instantiator_(NULL), | 45 instantiator_(NULL), |
| 46 default_parameter_values_(Array::ZoneHandle(isolate, Array::null())), | 46 default_parameter_values_(Array::ZoneHandle(isolate, Array::null())), |
| 47 saved_current_context_var_(NULL), | 47 saved_current_context_var_(NULL), |
| 48 saved_entry_context_var_(NULL), | 48 saved_entry_context_var_(NULL), |
| 49 expression_temp_var_(NULL), | 49 expression_temp_var_(NULL), |
| 50 finally_return_temp_var_(NULL), | 50 finally_return_temp_var_(NULL), |
| 51 await_temps_scope_(NULL), | |
| 52 deferred_prefixes_(new ZoneGrowableArray<const LibraryPrefix*>()), | 51 deferred_prefixes_(new ZoneGrowableArray<const LibraryPrefix*>()), |
| 53 first_parameter_index_(0), | 52 first_parameter_index_(0), |
| 54 first_stack_local_index_(0), | 53 first_stack_local_index_(0), |
| 55 num_copied_params_(0), | 54 num_copied_params_(0), |
| 56 num_stack_locals_(0), | 55 num_stack_locals_(0), |
| 57 have_seen_await_expr_(false), | 56 have_seen_await_expr_(false), |
| 58 saved_try_ctx_(NULL), | 57 saved_try_ctx_(NULL), |
| 59 async_saved_try_ctx_(NULL), | 58 async_saved_try_ctx_name_(String::ZoneHandle(isolate, String::null())), |
| 60 isolate_(isolate) { | 59 isolate_(isolate) { |
| 61 ASSERT(function.IsZoneHandle()); | 60 ASSERT(function.IsZoneHandle()); |
| 62 } | 61 } |
| 63 | 62 |
| 64 const Function& function() const { return function_; } | 63 const Function& function() const { return function_; } |
| 65 const Code& code() const { return code_; } | 64 const Code& code() const { return code_; } |
| 66 | 65 |
| 67 SequenceNode* node_sequence() const { return node_sequence_; } | 66 SequenceNode* node_sequence() const { return node_sequence_; } |
| 68 void SetNodeSequence(SequenceNode* node_sequence); | 67 void SetNodeSequence(SequenceNode* node_sequence); |
| 69 | 68 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 134 } |
| 136 void AddDeferredPrefix(const LibraryPrefix& prefix); | 135 void AddDeferredPrefix(const LibraryPrefix& prefix); |
| 137 | 136 |
| 138 int first_parameter_index() const { return first_parameter_index_; } | 137 int first_parameter_index() const { return first_parameter_index_; } |
| 139 int first_stack_local_index() const { return first_stack_local_index_; } | 138 int first_stack_local_index() const { return first_stack_local_index_; } |
| 140 int num_copied_params() const { return num_copied_params_; } | 139 int num_copied_params() const { return num_copied_params_; } |
| 141 int num_stack_locals() const { return num_stack_locals_; } | 140 int num_stack_locals() const { return num_stack_locals_; } |
| 142 | 141 |
| 143 void AllocateVariables(); | 142 void AllocateVariables(); |
| 144 | 143 |
| 145 void set_await_temps_scope(LocalScope* scope) { | |
| 146 ASSERT(await_temps_scope_ == NULL); | |
| 147 await_temps_scope_ = scope; | |
| 148 } | |
| 149 LocalScope* await_temps_scope() const { | |
| 150 ASSERT(await_temps_scope_ != NULL); | |
| 151 return await_temps_scope_; | |
| 152 } | |
| 153 | |
| 154 void record_await() { | 144 void record_await() { |
| 155 have_seen_await_expr_ = true; | 145 have_seen_await_expr_ = true; |
| 156 } | 146 } |
| 157 void reset_have_seen_await() { have_seen_await_expr_ = false; } | 147 void reset_have_seen_await() { have_seen_await_expr_ = false; } |
| 158 bool have_seen_await() const { return have_seen_await_expr_; } | 148 bool have_seen_await() const { return have_seen_await_expr_; } |
| 159 | 149 |
| 160 void set_saved_try_ctx(LocalVariable* saved_try_ctx) { | 150 void set_saved_try_ctx(LocalVariable* saved_try_ctx) { |
| 161 ASSERT((saved_try_ctx != NULL) && !saved_try_ctx->is_captured()); | 151 ASSERT((saved_try_ctx == NULL) || !saved_try_ctx->is_captured()); |
| 162 saved_try_ctx_ = saved_try_ctx; | 152 saved_try_ctx_ = saved_try_ctx; |
| 163 } | 153 } |
| 164 LocalVariable* saved_try_ctx() const { return saved_try_ctx_; } | 154 LocalVariable* saved_try_ctx() const { return saved_try_ctx_; } |
| 165 | 155 |
| 166 void set_async_saved_try_ctx(LocalVariable* async_saved_try_ctx) { | 156 void set_async_saved_try_ctx_name(const String& async_saved_try_ctx_name) { |
| 167 ASSERT((async_saved_try_ctx != NULL) && async_saved_try_ctx->is_captured()); | 157 async_saved_try_ctx_name_ = async_saved_try_ctx_name.raw(); |
| 168 async_saved_try_ctx_ = async_saved_try_ctx; | |
| 169 } | 158 } |
| 170 LocalVariable* async_saved_try_ctx() const { return async_saved_try_ctx_; } | 159 RawString* async_saved_try_ctx_name() const { |
| 160 return async_saved_try_ctx_name_.raw(); |
| 161 } |
| 171 | 162 |
| 172 void reset_saved_try_ctx_vars() { | 163 void reset_saved_try_ctx_vars() { |
| 173 saved_try_ctx_ = NULL; | 164 saved_try_ctx_ = NULL; |
| 174 async_saved_try_ctx_ = NULL; | 165 async_saved_try_ctx_name_ = String::null(); |
| 175 } | 166 } |
| 176 | 167 |
| 177 Isolate* isolate() const { return isolate_; } | 168 Isolate* isolate() const { return isolate_; } |
| 178 | 169 |
| 179 private: | 170 private: |
| 180 const Function& function_; | 171 const Function& function_; |
| 181 Code& code_; | 172 Code& code_; |
| 182 SequenceNode* node_sequence_; | 173 SequenceNode* node_sequence_; |
| 183 LocalVariable* instantiator_; | 174 LocalVariable* instantiator_; |
| 184 Array& default_parameter_values_; | 175 Array& default_parameter_values_; |
| 185 LocalVariable* saved_current_context_var_; | 176 LocalVariable* saved_current_context_var_; |
| 186 LocalVariable* saved_entry_context_var_; | 177 LocalVariable* saved_entry_context_var_; |
| 187 LocalVariable* expression_temp_var_; | 178 LocalVariable* expression_temp_var_; |
| 188 LocalVariable* finally_return_temp_var_; | 179 LocalVariable* finally_return_temp_var_; |
| 189 LocalScope* await_temps_scope_; | |
| 190 ZoneGrowableArray<const LibraryPrefix*>* deferred_prefixes_; | 180 ZoneGrowableArray<const LibraryPrefix*>* deferred_prefixes_; |
| 191 | 181 |
| 192 int first_parameter_index_; | 182 int first_parameter_index_; |
| 193 int first_stack_local_index_; | 183 int first_stack_local_index_; |
| 194 int num_copied_params_; | 184 int num_copied_params_; |
| 195 int num_stack_locals_; | 185 int num_stack_locals_; |
| 196 bool have_seen_await_expr_; | 186 bool have_seen_await_expr_; |
| 197 LocalVariable* saved_try_ctx_; | 187 LocalVariable* saved_try_ctx_; |
| 198 LocalVariable* async_saved_try_ctx_; | 188 String& async_saved_try_ctx_name_; |
| 199 | 189 |
| 200 Isolate* isolate_; | 190 Isolate* isolate_; |
| 201 | 191 |
| 202 DISALLOW_COPY_AND_ASSIGN(ParsedFunction); | 192 DISALLOW_COPY_AND_ASSIGN(ParsedFunction); |
| 203 }; | 193 }; |
| 204 | 194 |
| 205 | 195 |
| 206 class Parser : public ValueObject { | 196 class Parser : public ValueObject { |
| 207 public: | 197 public: |
| 208 // Parse the top level of a whole script file and register declared classes | 198 // Parse the top level of a whole script file and register declared classes |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 void ChainNewBlock(LocalScope* outer_scope); | 540 void ChainNewBlock(LocalScope* outer_scope); |
| 551 void OpenBlock(); | 541 void OpenBlock(); |
| 552 void OpenLoopBlock(); | 542 void OpenLoopBlock(); |
| 553 void OpenFunctionBlock(const Function& func); | 543 void OpenFunctionBlock(const Function& func); |
| 554 void OpenAsyncClosure(); | 544 void OpenAsyncClosure(); |
| 555 RawFunction* OpenAsyncFunction(intptr_t formal_param_pos); | 545 RawFunction* OpenAsyncFunction(intptr_t formal_param_pos); |
| 556 SequenceNode* CloseBlock(); | 546 SequenceNode* CloseBlock(); |
| 557 SequenceNode* CloseAsyncFunction(const Function& closure, | 547 SequenceNode* CloseAsyncFunction(const Function& closure, |
| 558 SequenceNode* closure_node); | 548 SequenceNode* closure_node); |
| 559 void CloseAsyncClosure(SequenceNode* body); | 549 void CloseAsyncClosure(SequenceNode* body); |
| 550 void AddAsyncClosureVariables(); |
| 560 | 551 |
| 561 | 552 |
| 562 LocalVariable* LookupPhaseParameter(); | 553 LocalVariable* LookupPhaseParameter(); |
| 563 LocalVariable* LookupReceiver(LocalScope* from_scope, bool test_only); | 554 LocalVariable* LookupReceiver(LocalScope* from_scope, bool test_only); |
| 564 LocalVariable* LookupTypeArgumentsParameter(LocalScope* from_scope, | 555 LocalVariable* LookupTypeArgumentsParameter(LocalScope* from_scope, |
| 565 bool test_only); | 556 bool test_only); |
| 566 void CaptureInstantiator(); | 557 void CaptureInstantiator(); |
| 567 AstNode* LoadReceiver(intptr_t token_pos); | 558 AstNode* LoadReceiver(intptr_t token_pos); |
| 568 AstNode* LoadTypeArgumentsParameter(intptr_t token_pos); | 559 AstNode* LoadTypeArgumentsParameter(intptr_t token_pos); |
| 569 AstNode* LoadFieldIfUnresolved(AstNode* node); | 560 AstNode* LoadFieldIfUnresolved(AstNode* node); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 AstNode* MakeAssertCall(intptr_t begin, intptr_t end); | 715 AstNode* MakeAssertCall(intptr_t begin, intptr_t end); |
| 725 AstNode* ThrowTypeError(intptr_t type_pos, const AbstractType& type); | 716 AstNode* ThrowTypeError(intptr_t type_pos, const AbstractType& type); |
| 726 AstNode* ThrowNoSuchMethodError(intptr_t call_pos, | 717 AstNode* ThrowNoSuchMethodError(intptr_t call_pos, |
| 727 const Class& cls, | 718 const Class& cls, |
| 728 const String& function_name, | 719 const String& function_name, |
| 729 ArgumentListNode* function_arguments, | 720 ArgumentListNode* function_arguments, |
| 730 InvocationMirror::Call call, | 721 InvocationMirror::Call call, |
| 731 InvocationMirror::Type type, | 722 InvocationMirror::Type type, |
| 732 const Function* func); | 723 const Function* func); |
| 733 | 724 |
| 734 void SetupSavedTryContext(LocalScope* saved_try_context_scope, | 725 void SetupSavedTryContext(LocalVariable* saved_try_context); |
| 735 int16_t try_index, | 726 void RestoreSavedTryContext(LocalScope* saved_try_context_scope, |
| 736 SequenceNode* target); | 727 int16_t try_index, |
| 728 SequenceNode* target); |
| 737 | 729 |
| 738 void CheckOperatorArity(const MemberDesc& member); | 730 void CheckOperatorArity(const MemberDesc& member); |
| 739 | 731 |
| 740 void EnsureExpressionTemp(); | 732 void EnsureExpressionTemp(); |
| 741 void EnsureSavedCurrentContext(); | 733 void EnsureSavedCurrentContext(); |
| 742 bool IsLegalAssignableSyntax(AstNode* expr, intptr_t end_pos); | 734 bool IsLegalAssignableSyntax(AstNode* expr, intptr_t end_pos); |
| 743 AstNode* CreateAssignmentNode(AstNode* original, | 735 AstNode* CreateAssignmentNode(AstNode* original, |
| 744 AstNode* rhs, | 736 AstNode* rhs, |
| 745 const String* left_ident, | 737 const String* left_ident, |
| 746 intptr_t left_pos); | 738 intptr_t left_pos); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 // done using 'return', 'break' or 'continue' statements. | 802 // done using 'return', 'break' or 'continue' statements. |
| 811 TryBlocks* try_blocks_list_; | 803 TryBlocks* try_blocks_list_; |
| 812 | 804 |
| 813 // Each try in this function gets its own try index. | 805 // Each try in this function gets its own try index. |
| 814 int16_t AllocateTryIndex(); | 806 int16_t AllocateTryIndex(); |
| 815 | 807 |
| 816 int16_t last_used_try_index_; | 808 int16_t last_used_try_index_; |
| 817 | 809 |
| 818 bool unregister_pending_function_; | 810 bool unregister_pending_function_; |
| 819 | 811 |
| 812 LocalScope* async_temp_scope_; |
| 813 |
| 820 DISALLOW_COPY_AND_ASSIGN(Parser); | 814 DISALLOW_COPY_AND_ASSIGN(Parser); |
| 821 }; | 815 }; |
| 822 | 816 |
| 823 } // namespace dart | 817 } // namespace dart |
| 824 | 818 |
| 825 #endif // VM_PARSER_H_ | 819 #endif // VM_PARSER_H_ |
| OLD | NEW |