1 /* 2 * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ES2PANDA_COMPILER_FUNCTION_GENERATOR_FUNCTION_BUILDER_H 17 #define ES2PANDA_COMPILER_FUNCTION_GENERATOR_FUNCTION_BUILDER_H 18 19 #include "ir/irnode.h" 20 #include "compiler/function/functionBuilder.h" 21 22 namespace panda::es2panda::ir { 23 class YieldExpression; 24 } // namespace panda::es2panda::ir 25 26 namespace panda::es2panda::compiler { 27 class PandaGen; 28 29 enum class GeneratorState { 30 UNDEFINED = 0, 31 SUSPENDED_START, 32 SUSPENDED_YIELD, 33 EXECUTING, 34 COMPLETED, 35 AWAITING_RETURN, 36 }; 37 38 class GeneratorFunctionBuilder : public FunctionBuilder { 39 public: GeneratorFunctionBuilder(PandaGen * pg,CatchTable * catchTable)40 explicit GeneratorFunctionBuilder(PandaGen *pg, CatchTable *catchTable) : FunctionBuilder(pg, catchTable) {} 41 42 ~GeneratorFunctionBuilder() override = default; 43 NO_COPY_SEMANTIC(GeneratorFunctionBuilder); 44 NO_MOVE_SEMANTIC(GeneratorFunctionBuilder); 45 46 void Prepare(const ir::ScriptFunction *node) const override; 47 void CleanUp(const ir::ScriptFunction *node) const override; 48 49 void DirectReturn(const ir::AstNode *node) const override; 50 void ImplicitReturn(const ir::AstNode *node) const override; 51 52 void Yield(const ir::AstNode *node) override; 53 54 protected: BuilderKind()55 BuilderType BuilderKind() const override 56 { 57 return BuilderType::GENERATOR; 58 } 59 }; 60 } // namespace panda::es2panda::compiler 61 62 #endif 63