1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef OHOS_HDI_C_CUSTOM_TYPES_CODE_EMITTER_H 10 #define OHOS_HDI_C_CUSTOM_TYPES_CODE_EMITTER_H 11 12 #include <vector> 13 14 #include "codegen/c_code_emitter.h" 15 16 namespace OHOS { 17 namespace HDI { 18 class CCustomTypesCodeEmitter : public CCodeEmitter { 19 public: CCustomTypesCodeEmitter()20 CCustomTypesCodeEmitter() : CCodeEmitter() {} 21 22 virtual ~CCustomTypesCodeEmitter() = default; 23 24 private: 25 bool ResolveDirectory(const std::string &targetDirectory) override; 26 27 void EmitCode() override; 28 29 void EmitPassthroughCustomTypesHeaderFile(); 30 31 void EmitPassthroughHeaderInclusions(StringBuilder &sb); 32 33 void EmitCustomTypesHeaderFile(); 34 35 void EmitHeaderInclusions(StringBuilder &sb); 36 37 void GetHeaderOtherLibInclusions(HeaderFile::HeaderFileSet &headerFiles); 38 39 void EmitCustomTypeDecls(StringBuilder &sb); 40 41 void EmitCustomTypeDecl(StringBuilder &sb, const AutoPtr<ASTType> &type); 42 43 void EmitCustomTypeFuncDecl(StringBuilder &sb); 44 45 void EmitCustomTypeMarshallingDecl(StringBuilder &sb, const AutoPtr<ASTStructType> &type); 46 47 void EmitCustomTypeUnmarshallingDecl(StringBuilder &sb, const AutoPtr<ASTStructType> &type); 48 49 void EmitCustomTypeFreeDecl(StringBuilder &sb, const AutoPtr<ASTStructType> &type); 50 51 void EmitCustomTypesSourceFile(); 52 53 void EmitSoucreInclusions(StringBuilder &sb); 54 55 void GetSourceOtherLibInclusions(HeaderFile::HeaderFileSet &headerFiles); 56 57 void EmitCustomTypeDataProcess(StringBuilder &sb); 58 59 void EmitCustomTypeMarshallingImpl(StringBuilder &sb, const AutoPtr<ASTStructType> &type); 60 61 void EmitCustomTypeUnmarshallingImpl(StringBuilder &sb, const AutoPtr<ASTStructType> &type); 62 63 void EmitMarshallingVarDecl( 64 const AutoPtr<ASTStructType> &type, const std::string &name, StringBuilder &sb, const std::string &prefix); 65 66 void EmitUnmarshallingVarDecl( 67 const AutoPtr<ASTStructType> &type, const std::string &name, StringBuilder &sb, const std::string &prefix); 68 69 void EmitParamCheck(const std::string &name, StringBuilder &sb, const std::string &prefix); 70 71 void EmitPodTypeUnmarshalling( 72 const AutoPtr<ASTStructType> &type, const std::string &name, StringBuilder &sb, const std::string &prefix); 73 74 void EmitMemberUnmarshalling(const AutoPtr<ASTType> &type, const std::string &name, const std::string &memberName, 75 StringBuilder &sb, const std::string &prefix); 76 77 void EmitStringMemberUnmarshalling(const AutoPtr<ASTType> &type, const std::string &memberName, 78 const std::string &varName, StringBuilder &sb, const std::string &prefix); 79 80 void EmitArrayMemberUnmarshalling(const AutoPtr<ASTType> &type, const std::string &memberName, 81 const std::string &varName, StringBuilder &sb, const std::string &prefix); 82 83 void EmitCustomTypeFreeImpl(StringBuilder &sb, const AutoPtr<ASTStructType> &type); 84 85 bool NeedEmitInitVar(const AutoPtr<ASTType> &type, bool needFree); 86 87 void EmitCustomTypeMemoryRecycle( 88 const AutoPtr<ASTStructType> &type, const std::string &name, StringBuilder &sb, const std::string &prefix); 89 90 void GetUtilMethods(UtilMethodMap &methods) override; 91 92 std::vector<std::string> freeObjStatements_; 93 }; 94 } // namespace HDI 95 } // namespace OHOS 96 97 #endif // OHOS_HDI_C_CUSTOM_TYPES_CODE_EMITTER_H