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_HDI_C_CUSTOM_TYPES_CODE_EMITTER_H 17 #define OHOS_IDL_HDI_C_CUSTOM_TYPES_CODE_EMITTER_H 18 19 #include <vector> 20 21 #include "hdi_c_code_emitter.h" 22 23 namespace OHOS { 24 namespace Idl { 25 class CCustomTypesCodeEmitter : public HDICCodeEmitter { 26 public: CCustomTypesCodeEmitter()27 CCustomTypesCodeEmitter() : HDICCodeEmitter() {} 28 29 ~CCustomTypesCodeEmitter() override = default; 30 31 private: 32 bool ResolveDirectory(const std::string &targetDirectory) override; 33 34 void EmitCode() override; 35 36 void EmitPassthroughCustomTypesHeaderFile(); 37 38 void EmitPassthroughHeaderInclusions(StringBuilder &sb); 39 40 void EmitCustomTypesHeaderFile(); 41 42 void EmitHeaderInclusions(StringBuilder &sb); 43 44 void EmitForwardDeclaration(StringBuilder &sb) const; 45 46 void EmitCustomTypeDecls(StringBuilder &sb) const; 47 48 void EmitCustomTypeFuncDecl(StringBuilder &sb) const; 49 50 void EmitCustomTypeMarshallFuncDecl(StringBuilder &sb, const AutoPtr<ASTType> &type) const; 51 52 void EmitCustomTypesSourceFile(); 53 54 void EmitSoucreInclusions(StringBuilder &sb); 55 56 void GetSourceOtherLibInclusions(HeaderFile::HeaderFileSet &headerFiles) const; 57 58 void EmitCustomTypeDataProcess(StringBuilder &sb); 59 60 void EmitCustomTypeMarshallingImpl(StringBuilder &sb, const AutoPtr<ASTStructType> &type); 61 62 void EmitCustomTypeUnmarshallingImpl(StringBuilder &sb, const AutoPtr<ASTStructType> &type); 63 64 void EmitMarshallingVarDecl(const AutoPtr<ASTStructType> &type, 65 const std::string &name, StringBuilder &sb, const std::string &prefix) const; 66 67 void EmitUnmarshallingVarDecl(const AutoPtr<ASTStructType> &type, 68 const std::string &name, StringBuilder &sb, const std::string &prefix) const; 69 70 void EmitParamCheck(const std::string &name, StringBuilder &sb, const std::string &prefix) const; 71 72 void EmitPodTypeUnmarshalling(const std::string &typeName, 73 const std::string &name, StringBuilder &sb, const std::string &prefix) const; 74 75 void EmitMemberUnmarshalling(const AutoPtr<ASTType> &type, const std::string &name, const std::string &memberName, 76 StringBuilder &sb, const std::string &prefix); 77 78 void EmitStringMemberUnmarshalling(const AutoPtr<HdiTypeEmitter> &typeEmitter, const std::string &memberName, 79 const std::string &varName, StringBuilder &sb, const std::string &prefix); 80 81 void EmitArrayMemberUnmarshalling(const AutoPtr<ASTType> &type, const std::string &memberName, 82 const std::string &varName, StringBuilder &sb, const std::string &prefix); 83 84 void EmitCustomTypeFreeImpl(StringBuilder &sb, const AutoPtr<ASTStructType> &type) const; 85 86 bool NeedEmitInitVar(const AutoPtr<ASTType> &type, bool needFree); 87 88 void EmitCustomTypeMemoryRecycle(const AutoPtr<ASTStructType> &type, 89 const std::string &name, StringBuilder &sb, const std::string &prefix) const; 90 91 void EmitUtilMethods(StringBuilder &sb, bool isDecl) override; 92 93 std::vector<std::string> freeObjStatements_; 94 }; 95 } // namespace Idl 96 } // namespace OHOS 97 98 #endif // OHOS_IDL_HDI_C_CUSTOM_TYPES_CODE_EMITTER_H