• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CORE_COMPILER_CONTEXT_H
17 #define ES2PANDA_COMPILER_CORE_COMPILER_CONTEXT_H
18 
19 #include <macros.h>
20 #include <mem/arena_allocator.h>
21 
22 #include <binder/variable.h>
23 #include <ir/astNode.h>
24 #include <util/patchFix.h>
25 #include <util/ustring.h>
26 
27 #include <cstdint>
28 #include <mutex>
29 
30 namespace panda::es2panda::binder {
31 class Binder;
32 }  // namespace panda::es2panda::binder
33 
34 namespace panda::es2panda::extractor {
35 class TypeRecorder;
36 class TypeExtractor;
37 }  // namespace panda::es2panda::extractor
38 
39 namespace panda::es2panda::compiler {
40 
41 class DebugInfo;
42 class Emitter;
43 
44 class CompilerContext {
45 public:
46     CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode,
47                     bool isMergeAbc, bool isTypeExtractorEnabled, bool isJsonInputFile, std::string sourceFile,
48                     std::string pkgName, util::StringView recordName, util::PatchFix *patchFixHelper);
49     NO_COPY_SEMANTIC(CompilerContext);
50     NO_MOVE_SEMANTIC(CompilerContext);
51     ~CompilerContext() = default;
52 
Binder()53     binder::Binder *Binder() const
54     {
55         return binder_;
56     }
57 
GetEmitter()58     Emitter *GetEmitter() const
59     {
60         return emitter_.get();
61     }
62 
LiteralCount()63     int32_t LiteralCount() const
64     {
65         return literalBufferIdx_;
66     }
67 
NewLiteralIndex()68     int32_t NewLiteralIndex()
69     {
70         std::lock_guard lock(m_);
71         return literalBufferIdx_++;
72     }
73 
Mutex()74     std::mutex &Mutex()
75     {
76         return m_;
77     }
78 
IsDebug()79     bool IsDebug() const
80     {
81         return isDebug_;
82     }
83 
isDebuggerEvaluateExpressionMode()84     bool isDebuggerEvaluateExpressionMode() const
85     {
86         return isDebuggerEvaluateExpressionMode_;
87     }
88 
IsMergeAbc()89     bool IsMergeAbc() const
90     {
91         return isMergeAbc_;
92     }
93 
SourceFile()94     std::string SourceFile() const
95     {
96         return sourceFile_;
97     }
98 
PkgName()99     std::string PkgName() const
100     {
101         return pkgName_;
102     }
103 
PatchFixHelper()104     util::PatchFix *PatchFixHelper() const
105     {
106         return patchFixHelper_;
107     }
108 
RecordName()109     const util::StringView &RecordName() const
110     {
111         return recordName_;
112     }
113 
IsTypeExtractorEnabled()114     bool IsTypeExtractorEnabled() const
115     {
116         return isTypeExtractorEnabled_;
117     }
118 
TypeRecorder()119     extractor::TypeRecorder *TypeRecorder() const
120     {
121         return recorder_;
122     }
123 
TypeExtractor()124     extractor::TypeExtractor *TypeExtractor() const
125     {
126         return extractor_;
127     }
128 
129     void SetTypeRecorder(extractor::TypeRecorder *recorder);
130     void SetTypeExtractor(extractor::TypeExtractor *extractor);
131 
IsJsonInputFile()132     bool IsJsonInputFile() const
133     {
134         return isJsonInputFile_;
135     }
136 
137 private:
138     binder::Binder *binder_;
139     int32_t literalBufferIdx_ {0};
140     std::mutex m_;
141     bool isDebug_;
142     bool isDebuggerEvaluateExpressionMode_;
143     bool isMergeAbc_;
144     // For Type Extractor
145     bool isTypeExtractorEnabled_;
146     // true when input file is json file
147     bool isJsonInputFile_;
148     extractor::TypeRecorder *recorder_ {};
149     extractor::TypeExtractor *extractor_ {};
150     std::string sourceFile_;
151     std::string pkgName_;
152     util::StringView recordName_;
153     util::PatchFix *patchFixHelper_ {nullptr};
154     std::unique_ptr<Emitter> emitter_;
155 };
156 
157 }  // namespace panda::es2panda::compiler
158 
159 #endif
160