1/**
2 * Copyright (c) 2021-2022 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
22namespace panda::es2panda::ir {
23class YieldExpression;
24}  // namespace panda::es2panda::ir
25
26namespace panda::es2panda::compiler {
27
28class PandaGen;
29
30enum class GeneratorState {
31    UNDEFINED = 0,
32    SUSPENDED_START,
33    SUSPENDED_YIELD,
34    EXECUTING,
35    COMPLETED,
36    AWAITING_RETURN,
37};
38
39class GeneratorFunctionBuilder : public FunctionBuilder {
40public:
41    explicit GeneratorFunctionBuilder(PandaGen *pg, CatchTable *catchTable) : FunctionBuilder(pg, catchTable) {}
42
43    ~GeneratorFunctionBuilder() override = default;
44    NO_COPY_SEMANTIC(GeneratorFunctionBuilder);
45    NO_MOVE_SEMANTIC(GeneratorFunctionBuilder);
46
47    void Prepare(const ir::ScriptFunction *node) override;
48    void CleanUp(const ir::ScriptFunction *node) const override;
49
50    void DirectReturn(const ir::AstNode *node) const override;
51    void ImplicitReturn(const ir::AstNode *node) const override;
52    void ExplicitReturn(const ir::AstNode *node) const override;
53
54    void Yield(const ir::AstNode *node) override;
55
56protected:
57    BuilderType BuilderKind() const override
58    {
59        return BuilderType::GENERATOR;
60    }
61};
62
63}  // namespace panda::es2panda::compiler
64
65#endif
66