• 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_ASTSTRUCTTYPE_H
10 #define OHOS_HDI_ASTSTRUCTTYPE_H
11 
12 #include <vector>
13 #include <tuple>
14 #include "ast/ast_type.h"
15 #include "util/autoptr.h"
16 #include "util/string.h"
17 
18 namespace OHOS {
19 namespace HDI {
20 class ASTStructType : public ASTType {
21 public:
SetName(const String & name)22     inline void SetName(const String& name)
23     {
24         name_ = name;
25     }
26 
GetName()27     inline String GetName()
28     {
29         return name_;
30     }
31 
SetFull(bool full)32     inline void SetFull(bool full)
33     {
34         isFull_ = full;
35     }
36 
IsFull()37     inline bool IsFull()
38     {
39         return isFull_;
40     }
41 
SetLite(bool lite)42     inline void SetLite(bool lite)
43     {
44         isLite_ = lite;
45     }
46 
IsLite()47     inline bool IsLite()
48     {
49         return isLite_;
50     }
51 
52     void AddMember(const AutoPtr<ASTType>& typeName, String name);
53 
GetMemberNumber()54     inline size_t GetMemberNumber()
55     {
56         return members_.size();
57     }
58 
GetMemberName(size_t index)59     inline String GetMemberName(size_t index)
60     {
61         if (index >= members_.size()) {
62             return String("");
63         }
64         return std::get<0>(members_[index]);
65     }
66 
GetMemberType(size_t index)67     inline AutoPtr<ASTType> GetMemberType(size_t index)
68     {
69         if (index >= members_.size()) {
70             return nullptr;
71         }
72         return std::get<1>(members_[index]);
73     }
74 
75     bool IsStructType() override;
76 
77     String ToString() override;
78 
79     String Dump(const String& prefix) override;
80 
81     TypeKind GetTypeKind() override;
82 
83     String EmitCType(TypeMode mode = TypeMode::NO_MODE) const override;
84 
85     String EmitCppType(TypeMode mode = TypeMode::NO_MODE) const override;
86 
87     String EmitJavaType(TypeMode mode, bool isInnerType = false) const override;
88 
89     String EmitCTypeDecl() const;
90 
91     String EmitCppTypeDecl() const;
92 
93     String EmitJavaTypeDecl() const;
94 
95     void EmitCWriteVar(const String& parcelName, const String& name, const String& ecName,
96         const String& gotoLabel, StringBuilder& sb, const String& prefix) const override;
97 
98     void EmitCProxyReadVar(const String& parcelName, const String& name, bool isInnerType, const String& ecName,
99         const String& gotoLabel, StringBuilder& sb, const String& prefix) const override;
100 
101     void EmitCStubReadVar(const String& parcelName, const String& name, const String& ecName,
102         const String& gotoLabel, StringBuilder& sb, const String& prefix) const override;
103 
104     void EmitCStubReadOutVar(const String& parcelName, const String& name, const String& ecName,
105         const String& gotoLabel, StringBuilder& sb, const String& prefix) const override;
106 
107     void EmitCppWriteVar(const String& parcelName, const String& name, StringBuilder& sb,
108         const String& prefix, unsigned int innerLevel = 0) const override;
109 
110     void EmitCppReadVar(const String& parcelName, const String& name, StringBuilder& sb,
111         const String& prefix, bool initVariable, unsigned int innerLevel = 0) const override;
112 
113     void EmitCMarshalling(const String& name, StringBuilder& sb, const String& prefix) const override;
114 
115     void EmitCUnMarshalling(const String& name, const String& gotoLabel, StringBuilder& sb, const String& prefix,
116         std::vector<String>& freeObjStatements) const override;
117 
118     void EmitCppMarshalling(const String& parcelName, const String& name, StringBuilder& sb,
119         const String& prefix, unsigned int innerLevel = 0) const override;
120 
121     void EmitCppUnMarshalling(const String& parcelName, const String& name, StringBuilder& sb,
122         const String& prefix, bool emitType, unsigned int innerLevel = 0) const override;
123 
124     void EmitMemoryRecycle(const String& name, bool isClient, bool ownership, StringBuilder& sb,
125         const String& prefix) const override;
126 private:
127     bool isFull_ = false;
128     bool isLite_ = false;
129     std::vector<std::tuple<String, AutoPtr<ASTType>>> members_;
130 };
131 } // namespace HDI
132 } // namespace OHOS
133 
134 #endif // OHOS_HDI_ASTSTRUCTTYPE_H