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/hotfix.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 } // namespace panda::es2panda::extractor 37 38 namespace panda::es2panda::compiler { 39 40 class DebugInfo; 41 class Emitter; 42 43 class CompilerContext { 44 public: 45 CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode, 46 bool isMergeAbc, bool isTypeExtractorEnabled, bool isJsonInputFile, std::string sourceFile, 47 std::string pkgName, util::StringView recordName, util::Hotfix *hotfixHelper); 48 NO_COPY_SEMANTIC(CompilerContext); 49 NO_MOVE_SEMANTIC(CompilerContext); 50 ~CompilerContext() = default; 51 Binder()52 binder::Binder *Binder() const 53 { 54 return binder_; 55 } 56 GetEmitter()57 Emitter *GetEmitter() const 58 { 59 return emitter_.get(); 60 } 61 LiteralCount()62 int32_t LiteralCount() const 63 { 64 return literalBufferIdx_; 65 } 66 NewLiteralIndex()67 int32_t NewLiteralIndex() 68 { 69 std::lock_guard lock(m_); 70 return literalBufferIdx_++; 71 } 72 Mutex()73 std::mutex &Mutex() 74 { 75 return m_; 76 } 77 IsDebug()78 bool IsDebug() const 79 { 80 return isDebug_; 81 } 82 isDebuggerEvaluateExpressionMode()83 bool isDebuggerEvaluateExpressionMode() const 84 { 85 return isDebuggerEvaluateExpressionMode_; 86 } 87 IsMergeAbc()88 bool IsMergeAbc() const 89 { 90 return isMergeAbc_; 91 } 92 SourceFile()93 std::string SourceFile() const 94 { 95 return sourceFile_; 96 } 97 PkgName()98 std::string PkgName() const 99 { 100 return pkgName_; 101 } 102 HotfixHelper()103 util::Hotfix *HotfixHelper() const 104 { 105 return hotfixHelper_; 106 } 107 RecordName()108 const util::StringView &RecordName() const 109 { 110 return recordName_; 111 } 112 IsTypeExtractorEnabled()113 bool IsTypeExtractorEnabled() const 114 { 115 return isTypeExtractorEnabled_; 116 } 117 TypeRecorder()118 extractor::TypeRecorder *TypeRecorder() const 119 { 120 return recorder_; 121 } 122 123 void SetTypeRecorder(extractor::TypeRecorder *recorder); 124 IsJsonInputFile()125 bool IsJsonInputFile() const 126 { 127 return isJsonInputFile_; 128 } 129 130 private: 131 binder::Binder *binder_; 132 int32_t literalBufferIdx_ {0}; 133 std::mutex m_; 134 bool isDebug_; 135 bool isDebuggerEvaluateExpressionMode_; 136 bool isMergeAbc_; 137 // For Type Extractor 138 bool isTypeExtractorEnabled_; 139 // true when input file is json file 140 bool isJsonInputFile_; 141 extractor::TypeRecorder *recorder_ {}; 142 std::string sourceFile_; 143 std::string pkgName_; 144 util::StringView recordName_; 145 util::Hotfix *hotfixHelper_ {nullptr}; 146 std::unique_ptr<Emitter> emitter_; 147 }; 148 149 } // namespace panda::es2panda::compiler 150 151 #endif 152