1 /* 2 * Copyright (c) 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 OHOS_IDL_SA_CODEGENERATOR_H 17 #define OHOS_IDL_SA_CODEGENERATOR_H 18 19 #include <functional> 20 #include <map> 21 #include <string> 22 23 #include "codegen/code_generator.h" 24 25 namespace OHOS { 26 namespace Idl { 27 class SACodeGenerator : public CodeGenerator { 28 public: 29 using GeneratePolicies = std::map<Language, CodeGenFunc>; 30 bool DoGenerate(const StrAstMap &allAst) override; 31 32 private: 33 static CodeGenFunc GetCodeGenPoilcy(); 34 35 static void GenCppPath(const AutoPtr<AST> &ast, const std::string &outDir); 36 37 static void GenCppCode(const AutoPtr<AST> &ast, const std::string &outDir); 38 39 static void GenRustCode(const AutoPtr<AST> &ast, const std::string &outDir); 40 41 static void GenTsCode(const AutoPtr<AST> &ast, const std::string &outDir); 42 43 static void GeneratorInit() __attribute__((constructor)); 44 45 static void GenCodeInit(); 46 47 static GeneratePolicies policies_; 48 static CodeEmitMap cppCodeEmitters_; 49 static CodeEmitMap tsCodeEmitters_; 50 static CodeEmitMap rustCodeEmitters_; 51 static std::unordered_map<std::string, std::string> genPath_; 52 static std::string mainFilePath_; 53 }; 54 } // namespace Idl 55 } // namespace OHOS 56 57 #endif // OHOS_IDL_CODEGENERATOR_H