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 ~CCustomTypesCodeEmitter() override = 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 EmitForwardDeclaration(StringBuilder &sb) const; 38 39 void EmitCustomTypeDecls(StringBuilder &sb) const; 40 41 void EmitCustomTypeDecl(StringBuilder &sb, const AutoPtr<ASTType> &type) const; 42 43 void EmitCustomTypeFuncDecl(StringBuilder &sb) const; 44 45 void EmitCustomTypeMarshallingDecl(StringBuilder &sb, const AutoPtr<ASTStructType> &type) const; 46 47 void EmitCustomTypeUnmarshallingDecl(StringBuilder &sb, const AutoPtr<ASTStructType> &type) const; 48 49 void EmitCustomTypeFreeDecl(StringBuilder &sb, const AutoPtr<ASTStructType> &type) const; 50 51 void EmitCustomTypesSourceFile(); 52 53 void EmitSoucreInclusions(StringBuilder &sb); 54 55 void GetSourceOtherLibInclusions(HeaderFile::HeaderFileSet &headerFiles) const; 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(const AutoPtr<ASTStructType> &type, 64 const std::string &name, StringBuilder &sb, const std::string &prefix) const; 65 66 void EmitUnmarshallingVarDecl(const AutoPtr<ASTStructType> &type, 67 const std::string &name, StringBuilder &sb, const std::string &prefix) const; 68 69 void EmitParamCheck(const std::string &name, StringBuilder &sb, const std::string &prefix) const; 70 71 void EmitPodTypeUnmarshalling(const AutoPtr<ASTStructType> &type, 72 const std::string &name, StringBuilder &sb, const std::string &prefix) const; 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) const; 84 85 bool NeedEmitInitVar(const AutoPtr<ASTType> &type, bool needFree); 86 87 void EmitCustomTypeMemoryRecycle(const AutoPtr<ASTStructType> &type, 88 const std::string &name, StringBuilder &sb, const std::string &prefix) const; 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