| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 RUNTIME_VM_KERNEL_TO_IL_H_ | 5 #ifndef RUNTIME_VM_KERNEL_TO_IL_H_ |
| 6 #define RUNTIME_VM_KERNEL_TO_IL_H_ | 6 #define RUNTIME_VM_KERNEL_TO_IL_H_ |
| 7 | 7 |
| 8 #if !defined(DART_PRECOMPILED_RUNTIME) | 8 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 9 | 9 |
| 10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 189 |
| 190 Fragment operator+(const Fragment& first, const Fragment& second); | 190 Fragment operator+(const Fragment& first, const Fragment& second); |
| 191 Fragment operator<<(const Fragment& fragment, Instruction* next); | 191 Fragment operator<<(const Fragment& fragment, Instruction* next); |
| 192 | 192 |
| 193 typedef ZoneGrowableArray<PushArgumentInstr*>* ArgumentArray; | 193 typedef ZoneGrowableArray<PushArgumentInstr*>* ArgumentArray; |
| 194 | 194 |
| 195 | 195 |
| 196 class ActiveClass { | 196 class ActiveClass { |
| 197 public: | 197 public: |
| 198 ActiveClass() | 198 ActiveClass() |
| 199 : kernel_class(NULL), klass(NULL), member(NULL), kernel_function(NULL) {} | 199 : kernel_class(NULL), |
| 200 class_type_parameters(0), |
| 201 class_type_parameters_offset_start(-1), |
| 202 klass(NULL), |
| 203 member(NULL), |
| 204 member_is_procedure(false), |
| 205 member_is_factory_procedure(false), |
| 206 member_type_parameters(0), |
| 207 member_type_parameters_offset_start(-1) {} |
| 200 | 208 |
| 201 // The current enclosing kernel class (if available, otherwise NULL). | 209 // The current enclosing kernel class (if available, otherwise NULL). |
| 202 Class* kernel_class; | 210 Class* kernel_class; |
| 211 intptr_t class_type_parameters; |
| 212 intptr_t class_type_parameters_offset_start; |
| 203 | 213 |
| 204 // The current enclosing class (or the library top-level class). When this is | 214 // The current enclosing class (or the library top-level class). When this is |
| 205 // a library's top-level class, the kernel_class will be NULL. | 215 // a library's top-level class, the kernel_class will be NULL. |
| 206 const dart::Class* klass; | 216 const dart::Class* klass; |
| 207 | 217 |
| 208 // The enclosing member (e.g., Constructor, Procedure, or Field) if there | 218 // The enclosing member (e.g., Constructor, Procedure, or Field) if there |
| 209 // is one. | 219 // is one. |
| 210 Member* member; | 220 Member* member; |
| 211 | 221 bool member_is_procedure; |
| 212 // The current function. | 222 bool member_is_factory_procedure; |
| 213 FunctionNode* kernel_function; | 223 intptr_t member_type_parameters; |
| 224 intptr_t member_type_parameters_offset_start; |
| 214 }; | 225 }; |
| 215 | 226 |
| 216 | 227 |
| 217 class ActiveClassScope { | 228 class ActiveClassScope { |
| 218 public: | 229 public: |
| 219 ActiveClassScope(ActiveClass* active_class, | 230 ActiveClassScope(ActiveClass* active_class, |
| 231 intptr_t class_type_parameters, |
| 232 intptr_t class_type_parameters_offset_start, |
| 233 const dart::Class* klass) |
| 234 : active_class_(active_class), saved_(*active_class) { |
| 235 active_class_->kernel_class = NULL; |
| 236 active_class_->class_type_parameters = class_type_parameters; |
| 237 active_class_->class_type_parameters_offset_start = |
| 238 class_type_parameters_offset_start; |
| 239 active_class_->klass = klass; |
| 240 active_class_->member = NULL; |
| 241 } |
| 242 |
| 243 |
| 244 ActiveClassScope(ActiveClass* active_class, |
| 220 Class* kernel_class, | 245 Class* kernel_class, |
| 221 const dart::Class* klass) | 246 const dart::Class* klass) |
| 222 : active_class_(active_class), saved_(*active_class) { | 247 : active_class_(active_class), saved_(*active_class) { |
| 223 active_class_->kernel_class = kernel_class; | 248 active_class_->kernel_class = kernel_class; |
| 224 active_class_->klass = klass; | 249 active_class_->klass = klass; |
| 225 active_class_->member = NULL; | 250 active_class_->member = NULL; |
| 226 active_class_->kernel_function = NULL; | 251 |
| 252 if (kernel_class != NULL) { |
| 253 List<TypeParameter>& type_parameters = kernel_class->type_parameters(); |
| 254 active_class_->class_type_parameters = type_parameters.length(); |
| 255 active_class_->class_type_parameters_offset_start = |
| 256 active_class_->class_type_parameters > 0 |
| 257 ? type_parameters[0]->kernel_offset() |
| 258 : -1; |
| 259 } |
| 227 } | 260 } |
| 228 | 261 |
| 229 ~ActiveClassScope() { *active_class_ = saved_; } | 262 ~ActiveClassScope() { *active_class_ = saved_; } |
| 230 | 263 |
| 231 private: | 264 private: |
| 232 ActiveClass* active_class_; | 265 ActiveClass* active_class_; |
| 233 ActiveClass saved_; | 266 ActiveClass saved_; |
| 234 }; | 267 }; |
| 235 | 268 |
| 236 | 269 |
| 237 class ActiveMemberScope { | 270 class ActiveMemberScope { |
| 238 public: | 271 public: |
| 272 ActiveMemberScope(ActiveClass* active_class, |
| 273 bool member_is_procedure, |
| 274 bool member_is_factory_procedure, |
| 275 intptr_t member_type_parameters, |
| 276 intptr_t member_type_parameters_offset_start) |
| 277 : active_class_(active_class), saved_(*active_class) { |
| 278 // The class and kernel_class is inherited. |
| 279 active_class_->member = NULL; |
| 280 active_class_->member_is_procedure = member_is_procedure; |
| 281 active_class_->member_is_factory_procedure = member_is_factory_procedure; |
| 282 active_class_->member_type_parameters = member_type_parameters; |
| 283 active_class_->member_type_parameters_offset_start = |
| 284 member_type_parameters_offset_start; |
| 285 } |
| 286 |
| 239 ActiveMemberScope(ActiveClass* active_class, Member* member) | 287 ActiveMemberScope(ActiveClass* active_class, Member* member) |
| 240 : active_class_(active_class), saved_(*active_class) { | 288 : active_class_(active_class), saved_(*active_class) { |
| 241 // The class and kernel_class is inherited. | 289 // The class and kernel_class is inherited. |
| 242 active_class_->member = member; | 290 active_class_->member = member; |
| 243 active_class_->kernel_function = NULL; | 291 |
| 292 active_class_->member_is_procedure = false; |
| 293 active_class_->member_is_factory_procedure = false; |
| 294 active_class_->member_type_parameters = 0; |
| 295 active_class_->member_type_parameters_offset_start = -1; |
| 296 |
| 297 if (member == NULL || !member->IsProcedure()) { |
| 298 return; |
| 299 } |
| 300 |
| 301 Procedure* procedure = Procedure::Cast(member); |
| 302 active_class_->member_is_procedure = true; |
| 303 active_class->member_is_factory_procedure = |
| 304 procedure->kind() == Procedure::kFactory; |
| 305 if (procedure->function() != NULL) { |
| 306 TypeParameterList& type_parameters = |
| 307 procedure->function()->type_parameters(); |
| 308 if (type_parameters.length() > 0) { |
| 309 active_class_->member_type_parameters = type_parameters.length(); |
| 310 active_class_->member_type_parameters_offset_start = |
| 311 type_parameters.first_offset; |
| 312 } |
| 313 } |
| 244 } | 314 } |
| 245 | 315 |
| 246 ~ActiveMemberScope() { *active_class_ = saved_; } | 316 ~ActiveMemberScope() { *active_class_ = saved_; } |
| 247 | 317 |
| 248 private: | 318 private: |
| 249 ActiveClass* active_class_; | 319 ActiveClass* active_class_; |
| 250 ActiveClass saved_; | |
| 251 }; | |
| 252 | |
| 253 | |
| 254 class ActiveFunctionScope { | |
| 255 public: | |
| 256 ActiveFunctionScope(ActiveClass* active_class, FunctionNode* kernel_function) | |
| 257 : active_class_(active_class), saved_(*active_class) { | |
| 258 // The class, kernel_class, and member are inherited. | |
| 259 active_class_->kernel_function = kernel_function; | |
| 260 } | |
| 261 | |
| 262 ~ActiveFunctionScope() { *active_class_ = saved_; } | |
| 263 | |
| 264 private: | |
| 265 ActiveClass* active_class_; | |
| 266 ActiveClass saved_; | 320 ActiveClass saved_; |
| 267 }; | 321 }; |
| 268 | 322 |
| 269 | 323 |
| 270 class TranslationHelper { | 324 class TranslationHelper { |
| 271 public: | 325 public: |
| 272 explicit TranslationHelper(dart::Thread* thread); | 326 explicit TranslationHelper(dart::Thread* thread); |
| 273 virtual ~TranslationHelper() {} | 327 virtual ~TranslationHelper() {} |
| 274 | 328 |
| 275 Thread* thread() { return thread_; } | 329 Thread* thread() { return thread_; } |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 // level. | 710 // level. |
| 657 GrowableArray<LocalVariable*> exception_variables; | 711 GrowableArray<LocalVariable*> exception_variables; |
| 658 GrowableArray<LocalVariable*> stack_trace_variables; | 712 GrowableArray<LocalVariable*> stack_trace_variables; |
| 659 GrowableArray<LocalVariable*> catch_context_variables; | 713 GrowableArray<LocalVariable*> catch_context_variables; |
| 660 | 714 |
| 661 // For-in iterators, one per for-in nesting level. | 715 // For-in iterators, one per for-in nesting level. |
| 662 GrowableArray<LocalVariable*> iterator_variables; | 716 GrowableArray<LocalVariable*> iterator_variables; |
| 663 }; | 717 }; |
| 664 | 718 |
| 665 | 719 |
| 666 class ScopeBuilder : public RecursiveVisitor { | |
| 667 public: | |
| 668 ScopeBuilder(ParsedFunction* parsed_function, TreeNode* node); | |
| 669 | |
| 670 virtual ~ScopeBuilder() {} | |
| 671 | |
| 672 ScopeBuildingResult* BuildScopes(); | |
| 673 | |
| 674 virtual void VisitName(Name* node) { /* NOP */ | |
| 675 } | |
| 676 | |
| 677 virtual void VisitThisExpression(ThisExpression* node); | |
| 678 virtual void VisitTypeParameterType(TypeParameterType* node); | |
| 679 virtual void VisitVariableGet(VariableGet* node); | |
| 680 virtual void VisitVariableSet(VariableSet* node); | |
| 681 virtual void VisitConditionalExpression(ConditionalExpression* node); | |
| 682 virtual void VisitLogicalExpression(LogicalExpression* node); | |
| 683 virtual void VisitFunctionExpression(FunctionExpression* node); | |
| 684 virtual void VisitLet(Let* node); | |
| 685 virtual void VisitBlock(Block* node); | |
| 686 virtual void VisitVariableDeclaration(VariableDeclaration* node); | |
| 687 virtual void VisitFunctionDeclaration(FunctionDeclaration* node); | |
| 688 virtual void VisitWhileStatement(WhileStatement* node); | |
| 689 virtual void VisitDoStatement(DoStatement* node); | |
| 690 virtual void VisitForStatement(ForStatement* node); | |
| 691 virtual void VisitForInStatement(ForInStatement* node); | |
| 692 virtual void VisitSwitchStatement(SwitchStatement* node); | |
| 693 virtual void VisitReturnStatement(ReturnStatement* node); | |
| 694 virtual void VisitTryCatch(TryCatch* node); | |
| 695 virtual void VisitTryFinally(TryFinally* node); | |
| 696 virtual void VisitYieldStatement(YieldStatement* node); | |
| 697 virtual void VisitAssertStatement(AssertStatement* node); | |
| 698 | |
| 699 virtual void VisitFunctionNode(FunctionNode* node); | |
| 700 | |
| 701 virtual void VisitConstructor(Constructor* node); | |
| 702 | |
| 703 private: | |
| 704 void EnterScope(TreeNode* node, TokenPosition start_position); | |
| 705 void ExitScope(TokenPosition end_position); | |
| 706 | |
| 707 const Type& TranslateVariableType(VariableDeclaration* variable); | |
| 708 LocalVariable* MakeVariable(TokenPosition declaration_pos, | |
| 709 TokenPosition token_pos, | |
| 710 const dart::String& name, | |
| 711 const AbstractType& type); | |
| 712 | |
| 713 void AddParameters(FunctionNode* function, intptr_t pos = 0); | |
| 714 void AddParameter(VariableDeclaration* declaration, intptr_t pos); | |
| 715 void AddVariable(VariableDeclaration* declaration); | |
| 716 void AddExceptionVariable(GrowableArray<LocalVariable*>* variables, | |
| 717 const char* prefix, | |
| 718 intptr_t nesting_depth); | |
| 719 void AddTryVariables(); | |
| 720 void AddCatchVariables(); | |
| 721 void AddIteratorVariable(); | |
| 722 void AddSwitchVariable(); | |
| 723 | |
| 724 // Record an assignment or reference to a variable. If the occurrence is | |
| 725 // in a nested function, ensure that the variable is handled properly as a | |
| 726 // captured variable. | |
| 727 void LookupVariable(VariableDeclaration* declaration); | |
| 728 | |
| 729 const dart::String& GenerateName(const char* prefix, intptr_t suffix); | |
| 730 | |
| 731 void HandleLocalFunction(TreeNode* parent, FunctionNode* function); | |
| 732 void HandleSpecialLoad(LocalVariable** variable, const dart::String& symbol); | |
| 733 void LookupCapturedVariableByName(LocalVariable** variable, | |
| 734 const dart::String& name); | |
| 735 | |
| 736 struct DepthState { | |
| 737 explicit DepthState(intptr_t function) | |
| 738 : loop_(0), | |
| 739 function_(function), | |
| 740 try_(0), | |
| 741 catch_(0), | |
| 742 finally_(0), | |
| 743 for_in_(0) {} | |
| 744 | |
| 745 intptr_t loop_; | |
| 746 intptr_t function_; | |
| 747 intptr_t try_; | |
| 748 intptr_t catch_; | |
| 749 intptr_t finally_; | |
| 750 intptr_t for_in_; | |
| 751 }; | |
| 752 | |
| 753 ScopeBuildingResult* result_; | |
| 754 ParsedFunction* parsed_function_; | |
| 755 TreeNode* node_; | |
| 756 | |
| 757 ActiveClass active_class_; | |
| 758 | |
| 759 TranslationHelper translation_helper_; | |
| 760 Zone* zone_; | |
| 761 DartTypeTranslator type_translator_; | |
| 762 | |
| 763 FunctionNode* current_function_node_; | |
| 764 LocalScope* current_function_scope_; | |
| 765 LocalScope* scope_; | |
| 766 DepthState depth_; | |
| 767 | |
| 768 intptr_t name_index_; | |
| 769 | |
| 770 bool needs_expr_temp_; | |
| 771 }; | |
| 772 | |
| 773 struct YieldContinuation { | 720 struct YieldContinuation { |
| 774 Instruction* entry; | 721 Instruction* entry; |
| 775 intptr_t try_index; | 722 intptr_t try_index; |
| 776 | 723 |
| 777 YieldContinuation(Instruction* entry, intptr_t try_index) | 724 YieldContinuation(Instruction* entry, intptr_t try_index) |
| 778 : entry(entry), try_index(try_index) {} | 725 : entry(entry), try_index(try_index) {} |
| 779 | 726 |
| 780 YieldContinuation() | 727 YieldContinuation() |
| 781 : entry(NULL), try_index(CatchClauseNode::kInvalidTryIndex) {} | 728 : entry(NULL), try_index(CatchClauseNode::kInvalidTryIndex) {} |
| 782 }; | 729 }; |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 namespace kernel { | 1308 namespace kernel { |
| 1362 | 1309 |
| 1363 RawObject* EvaluateMetadata(const dart::Field& metadata_field); | 1310 RawObject* EvaluateMetadata(const dart::Field& metadata_field); |
| 1364 RawObject* BuildParameterDescriptor(const Function& function); | 1311 RawObject* BuildParameterDescriptor(const Function& function); |
| 1365 | 1312 |
| 1366 } // namespace kernel | 1313 } // namespace kernel |
| 1367 } // namespace dart | 1314 } // namespace dart |
| 1368 | 1315 |
| 1369 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1316 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| 1370 #endif // RUNTIME_VM_KERNEL_TO_IL_H_ | 1317 #endif // RUNTIME_VM_KERNEL_TO_IL_H_ |
| OLD | NEW |