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