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_CPP_CUSTOM_TYPES_CODE_EMITTER_H 17 #define OHOS_IDL_CPP_CUSTOM_TYPES_CODE_EMITTER_H 18 19 #include "hdi_cpp_code_emitter.h" 20 21 namespace OHOS { 22 namespace Idl { 23 class CppCustomTypesCodeEmitter : public HDICppCodeEmitter { 24 public: CppCustomTypesCodeEmitter()25 CppCustomTypesCodeEmitter() : HDICppCodeEmitter() {} 26 27 ~CppCustomTypesCodeEmitter() override = default; 28 29 private: 30 bool ResolveDirectory(const std::string &targetDirectory) override; 31 32 void EmitCode() override; 33 34 void EmitPassthroughCustomTypesHeaderFile(); 35 36 void EmitPassthroughHeaderFileInclusions(StringBuilder& sb); 37 38 void EmitCustomTypesHeaderFile(); 39 40 void EmitHeaderFileInclusions(StringBuilder &sb); 41 42 void EmitForwardDeclaration(StringBuilder &sb) const; 43 44 void EmitUsingNamespace(StringBuilder &sb) override; 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 EmitSourceFileInclusions(StringBuilder &sb); 55 56 void GetSourceOtherLibInclusions(HeaderFile::HeaderFileSet &headerFiles) const; 57 58 void EmitCustomTypeDataProcess(StringBuilder &sb) const; 59 60 void EmitCustomTypeMarshallingImpl(StringBuilder &sb, const AutoPtr<ASTStructType> &type) const; 61 62 void EmitCustomTypeUnmarshallingImpl(StringBuilder &sb, const AutoPtr<ASTStructType> &type) const; 63 64 void EmitBeginNamespace(StringBuilder &sb) override; 65 66 void EmitEndNamespace(StringBuilder &sb) override; 67 68 void EmitUtilMethods(StringBuilder &sb, bool isDecl) override; 69 }; 70 } // namespace Idl 71 } // namespace OHOS 72 73 #endif // OHOS_IDL_CPP_CUSTOM_TYPES_CODE_EMITTER_H