| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 default_parameter_values_(Array::ZoneHandle(zone(), Array::null())), | 50 default_parameter_values_(Array::ZoneHandle(zone(), Array::null())), |
| 51 current_context_var_(NULL), | 51 current_context_var_(NULL), |
| 52 expression_temp_var_(NULL), | 52 expression_temp_var_(NULL), |
| 53 finally_return_temp_var_(NULL), | 53 finally_return_temp_var_(NULL), |
| 54 deferred_prefixes_(new ZoneGrowableArray<const LibraryPrefix*>()), | 54 deferred_prefixes_(new ZoneGrowableArray<const LibraryPrefix*>()), |
| 55 guarded_fields_(new ZoneGrowableArray<const Field*>()), | 55 guarded_fields_(new ZoneGrowableArray<const Field*>()), |
| 56 first_parameter_index_(0), | 56 first_parameter_index_(0), |
| 57 first_stack_local_index_(0), | 57 first_stack_local_index_(0), |
| 58 num_copied_params_(0), | 58 num_copied_params_(0), |
| 59 num_stack_locals_(0), | 59 num_stack_locals_(0), |
| 60 have_seen_await_expr_(false), | 60 have_seen_await_expr_(false) { |
| 61 saved_try_ctx_(NULL), | |
| 62 async_saved_try_ctx_name_(String::ZoneHandle(zone(), String::null())) { | |
| 63 ASSERT(function.IsZoneHandle()); | 61 ASSERT(function.IsZoneHandle()); |
| 64 // Every function has a local variable for the current context. | 62 // Every function has a local variable for the current context. |
| 65 LocalVariable* temp = new(zone()) LocalVariable( | 63 LocalVariable* temp = new(zone()) LocalVariable( |
| 66 function.token_pos(), | 64 function.token_pos(), |
| 67 Symbols::CurrentContextVar(), | 65 Symbols::CurrentContextVar(), |
| 68 Type::ZoneHandle(zone(), Type::DynamicType())); | 66 Type::ZoneHandle(zone(), Type::DynamicType())); |
| 69 ASSERT(temp != NULL); | 67 ASSERT(temp != NULL); |
| 70 current_context_var_ = temp; | 68 current_context_var_ = temp; |
| 71 } | 69 } |
| 72 | 70 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 return (num_copied_params_ == 0) | 143 return (num_copied_params_ == 0) |
| 146 ? function().num_fixed_parameters() : 0; | 144 ? function().num_fixed_parameters() : 0; |
| 147 } | 145 } |
| 148 | 146 |
| 149 void AllocateVariables(); | 147 void AllocateVariables(); |
| 150 void AllocateIrregexpVariables(intptr_t num_stack_locals); | 148 void AllocateIrregexpVariables(intptr_t num_stack_locals); |
| 151 | 149 |
| 152 void record_await() { have_seen_await_expr_ = true; } | 150 void record_await() { have_seen_await_expr_ = true; } |
| 153 bool have_seen_await() const { return have_seen_await_expr_; } | 151 bool have_seen_await() const { return have_seen_await_expr_; } |
| 154 | 152 |
| 155 void set_saved_try_ctx(LocalVariable* saved_try_ctx) { | |
| 156 ASSERT((saved_try_ctx == NULL) || !saved_try_ctx->is_captured()); | |
| 157 saved_try_ctx_ = saved_try_ctx; | |
| 158 } | |
| 159 LocalVariable* saved_try_ctx() const { return saved_try_ctx_; } | |
| 160 | |
| 161 void set_async_saved_try_ctx_name(const String& async_saved_try_ctx_name) { | |
| 162 async_saved_try_ctx_name_ = async_saved_try_ctx_name.raw(); | |
| 163 } | |
| 164 RawString* async_saved_try_ctx_name() const { | |
| 165 return async_saved_try_ctx_name_.raw(); | |
| 166 } | |
| 167 | |
| 168 void reset_saved_try_ctx_vars() { | |
| 169 saved_try_ctx_ = NULL; | |
| 170 async_saved_try_ctx_name_ = String::null(); | |
| 171 } | |
| 172 | |
| 173 Thread* thread() const { return thread_; } | 153 Thread* thread() const { return thread_; } |
| 174 Isolate* isolate() const { return thread()->isolate(); } | 154 Isolate* isolate() const { return thread()->isolate(); } |
| 175 Zone* zone() const { return thread()->zone(); } | 155 Zone* zone() const { return thread()->zone(); } |
| 176 | 156 |
| 177 private: | 157 private: |
| 178 Thread* thread_; | 158 Thread* thread_; |
| 179 const Function& function_; | 159 const Function& function_; |
| 180 Code& code_; | 160 Code& code_; |
| 181 SequenceNode* node_sequence_; | 161 SequenceNode* node_sequence_; |
| 182 RegExpCompileData* regexp_compile_data_; | 162 RegExpCompileData* regexp_compile_data_; |
| 183 LocalVariable* instantiator_; | 163 LocalVariable* instantiator_; |
| 184 Array& default_parameter_values_; | 164 Array& default_parameter_values_; |
| 185 LocalVariable* current_context_var_; | 165 LocalVariable* current_context_var_; |
| 186 LocalVariable* expression_temp_var_; | 166 LocalVariable* expression_temp_var_; |
| 187 LocalVariable* finally_return_temp_var_; | 167 LocalVariable* finally_return_temp_var_; |
| 188 ZoneGrowableArray<const LibraryPrefix*>* deferred_prefixes_; | 168 ZoneGrowableArray<const LibraryPrefix*>* deferred_prefixes_; |
| 189 ZoneGrowableArray<const Field*>* guarded_fields_; | 169 ZoneGrowableArray<const Field*>* guarded_fields_; |
| 190 | 170 |
| 191 int first_parameter_index_; | 171 int first_parameter_index_; |
| 192 int first_stack_local_index_; | 172 int first_stack_local_index_; |
| 193 int num_copied_params_; | 173 int num_copied_params_; |
| 194 int num_stack_locals_; | 174 int num_stack_locals_; |
| 195 bool have_seen_await_expr_; | 175 bool have_seen_await_expr_; |
| 196 LocalVariable* saved_try_ctx_; | |
| 197 String& async_saved_try_ctx_name_; | |
| 198 | 176 |
| 199 friend class Parser; | 177 friend class Parser; |
| 200 DISALLOW_COPY_AND_ASSIGN(ParsedFunction); | 178 DISALLOW_COPY_AND_ASSIGN(ParsedFunction); |
| 201 }; | 179 }; |
| 202 | 180 |
| 203 | 181 |
| 204 class Parser : public ValueObject { | 182 class Parser : public ValueObject { |
| 205 public: | 183 public: |
| 206 // Parse the top level of a whole script file and register declared classes | 184 // Parse the top level of a whole script file and register declared classes |
| 207 // in the given library. | 185 // in the given library. |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 RawClass* CheckCaseExpressions(const GrowableArray<LiteralNode*>& values); | 573 RawClass* CheckCaseExpressions(const GrowableArray<LiteralNode*>& values); |
| 596 CaseNode* ParseCaseClause(LocalVariable* switch_expr_value, | 574 CaseNode* ParseCaseClause(LocalVariable* switch_expr_value, |
| 597 GrowableArray<LiteralNode*>* case_expr_values, | 575 GrowableArray<LiteralNode*>* case_expr_values, |
| 598 SourceLabel* case_label); | 576 SourceLabel* case_label); |
| 599 AstNode* ParseSwitchStatement(String* label_name); | 577 AstNode* ParseSwitchStatement(String* label_name); |
| 600 | 578 |
| 601 // try/catch/finally parsing. | 579 // try/catch/finally parsing. |
| 602 void AddCatchParamsToScope(CatchParamDesc* exception_param, | 580 void AddCatchParamsToScope(CatchParamDesc* exception_param, |
| 603 CatchParamDesc* stack_trace_param, | 581 CatchParamDesc* stack_trace_param, |
| 604 LocalScope* scope); | 582 LocalScope* scope); |
| 605 void AddSavedExceptionAndStacktraceToScope(LocalVariable* exception_var, | 583 void SetupSavedExceptionAndStacktrace(); |
| 606 LocalVariable* stack_trace_var, | 584 void SaveExceptionAndStacktrace(LocalVariable* exception_var, |
| 607 LocalScope* scope); | 585 LocalVariable* stack_trace_var); |
| 608 // Parse all the catch clause of a try. | 586 // Parse all the catch clause of a try. |
| 609 SequenceNode* ParseCatchClauses(intptr_t handler_pos, | 587 SequenceNode* ParseCatchClauses(intptr_t handler_pos, |
| 610 LocalVariable* exception_var, | 588 LocalVariable* exception_var, |
| 611 LocalVariable* stack_trace_var, | 589 LocalVariable* stack_trace_var, |
| 612 const GrowableObjectArray& handler_types, | 590 const GrowableObjectArray& handler_types, |
| 613 bool* needs_stack_trace); | 591 bool* needs_stack_trace); |
| 614 // Parse finally block and create an AST for it. | 592 // Parse finally block and create an AST for it. |
| 615 SequenceNode* ParseFinallyBlock(); | 593 SequenceNode* ParseFinallyBlock(); |
| 616 // Adds try block to the list of try blocks seen so far. | 594 // Adds try block to the list of try blocks seen so far. |
| 617 void PushTryBlock(Block* try_block); | 595 void PushTryBlock(Block* try_block); |
| 618 // Pops the inner most try block from the list. | 596 // Pops the inner most try block from the list. |
| 619 TryBlocks* PopTryBlock(); | 597 TryBlocks* PopTryBlock(); |
| 598 // Collect try block scopes and indices if await or yield is in try block. |
| 599 void CheckAsyncOpInTryBlock(LocalScope** try_scope, |
| 600 int16_t* try_index, |
| 601 LocalScope** outer_try_scope, |
| 602 int16_t* outer_try_index) const; |
| 620 // Add specified node to try block list so that it can be patched with | 603 // Add specified node to try block list so that it can be patched with |
| 621 // inlined finally code if needed. | 604 // inlined finally code if needed. |
| 622 void AddNodeForFinallyInlining(AstNode* node); | 605 void AddNodeForFinallyInlining(AstNode* node); |
| 623 // Add the inlined finally block to the specified node. | 606 // Add the inlined finally block to the specified node. |
| 624 void AddFinallyBlockToNode(AstNode* node, InlinedFinallyNode* finally_node); | 607 void AddFinallyBlockToNode(AstNode* node, InlinedFinallyNode* finally_node); |
| 625 AstNode* ParseTryStatement(String* label_name); | 608 AstNode* ParseTryStatement(String* label_name); |
| 626 RawAbstractType* ParseConstFinalVarOrType( | 609 RawAbstractType* ParseConstFinalVarOrType( |
| 627 ClassFinalizer::FinalizationKind finalization); | 610 ClassFinalizer::FinalizationKind finalization); |
| 628 AstNode* ParseVariableDeclaration(const AbstractType& type, | 611 AstNode* ParseVariableDeclaration(const AbstractType& type, |
| 629 bool is_final, | 612 bool is_final, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 AstNode* ThrowTypeError(intptr_t type_pos, const AbstractType& type); | 728 AstNode* ThrowTypeError(intptr_t type_pos, const AbstractType& type); |
| 746 AstNode* ThrowNoSuchMethodError(intptr_t call_pos, | 729 AstNode* ThrowNoSuchMethodError(intptr_t call_pos, |
| 747 const Class& cls, | 730 const Class& cls, |
| 748 const String& function_name, | 731 const String& function_name, |
| 749 ArgumentListNode* function_arguments, | 732 ArgumentListNode* function_arguments, |
| 750 InvocationMirror::Call call, | 733 InvocationMirror::Call call, |
| 751 InvocationMirror::Type type, | 734 InvocationMirror::Type type, |
| 752 const Function* func); | 735 const Function* func); |
| 753 | 736 |
| 754 void SetupSavedTryContext(LocalVariable* saved_try_context); | 737 void SetupSavedTryContext(LocalVariable* saved_try_context); |
| 755 void RestoreSavedTryContext(LocalScope* saved_try_context_scope, | |
| 756 int16_t try_index, | |
| 757 SequenceNode* target); | |
| 758 | 738 |
| 759 void CheckOperatorArity(const MemberDesc& member); | 739 void CheckOperatorArity(const MemberDesc& member); |
| 760 | 740 |
| 761 void EnsureExpressionTemp(); | 741 void EnsureExpressionTemp(); |
| 762 bool IsLegalAssignableSyntax(AstNode* expr, intptr_t end_pos); | 742 bool IsLegalAssignableSyntax(AstNode* expr, intptr_t end_pos); |
| 763 AstNode* CreateAssignmentNode(AstNode* original, | 743 AstNode* CreateAssignmentNode(AstNode* original, |
| 764 AstNode* rhs, | 744 AstNode* rhs, |
| 765 const String* left_ident, | 745 const String* left_ident, |
| 766 intptr_t left_pos); | 746 intptr_t left_pos); |
| 767 AstNode* InsertClosureCallNodes(AstNode* condition); | 747 AstNode* InsertClosureCallNodes(AstNode* condition); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 | 824 |
| 845 // Indentation of parser trace. | 825 // Indentation of parser trace. |
| 846 intptr_t trace_indent_; | 826 intptr_t trace_indent_; |
| 847 | 827 |
| 848 DISALLOW_COPY_AND_ASSIGN(Parser); | 828 DISALLOW_COPY_AND_ASSIGN(Parser); |
| 849 }; | 829 }; |
| 850 | 830 |
| 851 } // namespace dart | 831 } // namespace dart |
| 852 | 832 |
| 853 #endif // VM_PARSER_H_ | 833 #endif // VM_PARSER_H_ |
| OLD | NEW |