• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <vector>
12 #include "codegen/c_code_emitter.h"
13 
14 namespace OHOS {
15 namespace HDI {
16 class CCustomTypesCodeEmitter : public CCodeEmitter {
17 public:
CCustomTypesCodeEmitter()18     CCustomTypesCodeEmitter() : CCodeEmitter() {}
19 
20     virtual ~CCustomTypesCodeEmitter() = default;
21 private:
22     bool ResolveDirectory(const String& targetDirectory) override;
23 
24     void EmitCode() override;
25 
26     void EmitCustomTypesHeaderFile();
27 
28     void EmitHeaderInclusions(StringBuilder& sb);
29 
30     void GetHeaderOtherLibInclusions(HeaderFile::HeaderFileSet& headerFiles);
31 
32     void EmitCustomTypeDecls(StringBuilder& sb);
33 
34     void EmitCustomTypeDecl(StringBuilder& sb, const AutoPtr<ASTType>& type);
35 
36     void EmitCustomTypeFuncDecl(StringBuilder& sb);
37 
38     void EmitCustomTypeMarshallingDecl(StringBuilder& sb, const AutoPtr<ASTStructType>& type);
39 
40     void EmitCustomTypeUnmarshallingDecl(StringBuilder& sb, const AutoPtr<ASTStructType>& type);
41 
42     void EmitCustomTypeFreeDecl(StringBuilder& sb, const AutoPtr<ASTStructType>& type);
43 
44     void EmitCustomTypesSourceFile();
45 
46     void EmitSoucreIncludsions(StringBuilder& sb);
47 
48     void GetSourceOtherLibInclusions(HeaderFile::HeaderFileSet& headerFiles);
49 
50     void EmitCustomTypeDataProcess(StringBuilder& sb);
51 
52     void EmitCustomTypeMarshallingImpl(StringBuilder& sb, const AutoPtr<ASTStructType>& type);
53 
54     void EmitCustomTypeUnmarshallingImpl(StringBuilder& sb, const AutoPtr<ASTStructType>& type);
55 
56     void EmitMemberUnmarshalling(const AutoPtr<ASTType>& type, const String& name, const String& memberName,
57         StringBuilder& sb, const String& prefix);
58 
59     void EmitArrayMemberUnmarshalling(const AutoPtr<ASTType>& type, const String& memberName, const String& varName,
60         StringBuilder& sb, const String& prefix);
61 
62     void EmitCustomTypeFreeImpl(StringBuilder& sb, const AutoPtr<ASTStructType>& type);
63 
64     bool NeedEmitInitVar(const AutoPtr<ASTType>& type);
65 
66     void EmitCustomTypeMemoryRecycle(const AutoPtr<ASTStructType>& type, const String& name, StringBuilder& sb,
67         const String& prefix);
68 
69     std::vector<String> freeObjStatements_;
70 };
71 } // namespace HDI
72 } // namespace OHOS
73 
74 #endif // OHOS_HDI_C_CUSTOM_TYPES_CODE_EMITTER_H