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_ASTINTERFACETYPE_H 10 #define OHOS_HDI_ASTINTERFACETYPE_H 11 12 #include <vector> 13 #include "ast/ast_method.h" 14 #include "ast/ast_type.h" 15 #include "util/autoptr.h" 16 17 namespace OHOS { 18 namespace HDI { 19 class ASTInterfaceType : public ASTType { 20 public: 21 void SetNamespace(const AutoPtr<ASTNamespace>& nspace) override; 22 SetLicense(const String & license)23 inline void SetLicense(const String& license) 24 { 25 license_ = license; 26 } 27 GetLicense()28 inline String GetLicense() const 29 { 30 return license_; 31 } 32 SetOneWay(bool oneway)33 inline void SetOneWay(bool oneway) 34 { 35 isOneWay_ = oneway; 36 } 37 IsOneWay()38 inline bool IsOneWay() 39 { 40 return isOneWay_; 41 } 42 SetCallback(bool callback)43 inline void SetCallback(bool callback) 44 { 45 isCallback_ = callback; 46 SetSerializable(callback); 47 } 48 IsCallback()49 inline bool IsCallback() 50 { 51 return isCallback_; 52 } 53 SetSerializable(bool isSerializable)54 inline void SetSerializable(bool isSerializable) 55 { 56 isSerializable_ = isSerializable; 57 } 58 IsSerializable()59 inline bool IsSerializable() 60 { 61 return isSerializable_; 62 } 63 SetFull(bool full)64 inline void SetFull(bool full) 65 { 66 isFull_ = full; 67 } 68 IsFull()69 inline bool IsFull() 70 { 71 return isFull_; 72 } 73 SetLite(bool lite)74 inline void SetLite(bool lite) 75 { 76 isLite_ = lite; 77 } 78 IsLite()79 inline bool IsLite() 80 { 81 return isLite_; 82 } 83 84 void AddMethod(const AutoPtr<ASTMethod>& method); 85 86 AutoPtr<ASTMethod> GetMethod(size_t index); 87 GetMethodNumber()88 inline size_t GetMethodNumber() 89 { 90 return methods_.size(); 91 } 92 AddVersionMethod(const AutoPtr<ASTMethod> & method)93 void AddVersionMethod(const AutoPtr<ASTMethod>& method) 94 { 95 getVerMethod_ = method; 96 } 97 GetVersionMethod()98 AutoPtr<ASTMethod> GetVersionMethod() 99 { 100 return getVerMethod_; 101 } 102 103 bool IsInterfaceType() override; 104 105 String ToString() override; 106 107 String Dump(const String& prefix) override; 108 109 TypeKind GetTypeKind() override; 110 111 String GetFullName() const; 112 113 String EmitCType(TypeMode mode = TypeMode::NO_MODE) const override; 114 115 String EmitCppType(TypeMode mode = TypeMode::NO_MODE) const override; 116 117 String EmitJavaType(TypeMode mode, bool isInnerType = false) const override; 118 119 void EmitCWriteVar(const String& parcelName, const String& name, const String& ecName, 120 const String& gotoLabel, StringBuilder& sb, const String& prefix) const override; 121 122 void EmitCProxyReadVar(const String& parcelName, const String& name, bool isInnerType, const String& ecName, 123 const String& gotoLabel, StringBuilder& sb, const String& prefix) const override; 124 125 void EmitCStubReadVar(const String& parcelName, const String& name, const String& ecName, 126 const String& gotoLabel, StringBuilder& sb, const String& prefix) const override; 127 128 void EmitCppWriteVar(const String& parcelName, const String& name, StringBuilder& sb, 129 const String& prefix, unsigned int innerLevel = 0) const override; 130 131 void EmitCppReadVar(const String& parcelName, const String& name, StringBuilder& sb, 132 const String& prefix, bool initVariable, unsigned int innerLevel = 0) const override; 133 134 void EmitJavaWriteVar(const String& parcelName, const String& name, StringBuilder& sb, 135 const String& prefix) const override; 136 137 void EmitJavaReadVar(const String& parcelName, const String& name, StringBuilder& sb, 138 const String& prefix) const override; 139 140 void EmitJavaReadInnerVar(const String& parcelName, const String& name, bool isInner, StringBuilder& sb, 141 const String& prefix) const override; 142 private: 143 String license_; 144 bool isOneWay_ = false; 145 bool isCallback_ = false; 146 bool isSerializable_ = false; 147 bool isFull_ = false; 148 bool isLite_ = false; 149 std::vector<AutoPtr<ASTMethod>> methods_; 150 AutoPtr<ASTMethod> getVerMethod_; 151 }; 152 } // namespace HDI 153 } // namespace OHOS 154 155 #endif // OHOS_HDI_ASTINTERFACETYPE_H