1/*
2 * Copyright (c) 2021 - 2024 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_CORE_COMPILE_JOB_H
17#define ES2PANDA_COMPILER_CORE_COMPILE_JOB_H
18
19#include "macros.h"
20#include "es2panda.h"
21#include "compiler/core/programElement.h"
22
23#include <condition_variable>
24#include <mutex>
25
26namespace ark::es2panda::varbinder {
27class FunctionScope;
28}  // namespace ark::es2panda::varbinder
29
30namespace ark::es2panda::public_lib {
31struct Context;
32}  // namespace ark::es2panda::public_lib
33
34namespace ark::es2panda::compiler {
35class ProgramElement;
36
37class CompileJob {
38public:
39    CompileJob() = default;
40    NO_COPY_SEMANTIC(CompileJob);
41    NO_MOVE_SEMANTIC(CompileJob);
42    ~CompileJob() = default;
43
44    const ProgramElement *GetProgramElement() const
45    {
46        return &programElement_;
47    }
48
49    ProgramElement *GetProgramElement()
50    {
51        return &programElement_;
52    }
53
54    void SetContext(public_lib::Context *context, varbinder::FunctionScope *scope)
55    {
56        context_ = context;
57        scope_ = scope;
58    }
59
60    void Run();
61    void DependsOn(CompileJob *job);
62    void Signal();
63
64private:
65    std::mutex m_;
66    std::condition_variable cond_;
67    public_lib::Context *context_ {};
68    varbinder::FunctionScope *scope_ {};
69    ProgramElement programElement_;
70    CompileJob *dependant_ {};
71    size_t dependencies_ {0};
72};
73}  // namespace ark::es2panda::compiler
74
75#endif
76