1 /* 2 * Copyright (c) 2021-2022 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_ASTMETHOD_H 10 #define OHOS_HDI_ASTMETHOD_H 11 12 #include <vector> 13 14 #include "ast/ast_node.h" 15 #include "ast/ast_parameter.h" 16 #include "util/autoptr.h" 17 18 namespace OHOS { 19 namespace HDI { 20 class ASTMethod : public ASTNode { 21 public: SetName(const std::string & name)22 inline void SetName(const std::string &name) 23 { 24 name_ = name; 25 } 26 GetName()27 inline std::string GetName() 28 { 29 return name_; 30 } 31 SetAttribute(AutoPtr<ASTAttr> attr)32 inline void SetAttribute(AutoPtr<ASTAttr> attr) 33 { 34 if (attr_ != nullptr && attr != nullptr) { 35 attr_->SetValue(attr->GetValue()); 36 } 37 } 38 GetAttribute()39 inline AutoPtr<ASTAttr> GetAttribute() const 40 { 41 return attr_; 42 } 43 IsOneWay()44 inline bool IsOneWay() const 45 { 46 return attr_->HasValue(ASTAttr::ONEWAY); 47 } 48 IsFull()49 inline bool IsFull() const 50 { 51 return attr_->HasValue(ASTAttr::FULL); 52 } 53 IsLite()54 inline bool IsLite() const 55 { 56 return attr_->HasValue(ASTAttr::LITE); 57 } 58 IsMini()59 inline bool IsMini() const 60 { 61 return attr_->HasValue(ASTAttr::MINI); 62 } 63 IsOverload()64 inline bool IsOverload() const 65 { 66 return isOverload_; 67 } 68 69 void CheckOverload(AutoPtr<ASTInterfaceType> interface); 70 71 void AddParameter(const AutoPtr<ASTParameter> ¶meter); 72 73 AutoPtr<ASTParameter> GetParameter(size_t index); 74 GetParameterNumber()75 inline size_t GetParameterNumber() 76 { 77 return parameters_.size(); 78 } 79 SetCmdId(size_t cmdId)80 inline void SetCmdId(size_t cmdId) 81 { 82 cmdId_ = cmdId; 83 } 84 GetCmdId()85 inline size_t GetCmdId() 86 { 87 return cmdId_; 88 } 89 GetMethodIdentifier()90 inline std::string GetMethodIdentifier() 91 { 92 return isOverload_ ? "_" + std::to_string(cmdId_) : ""; 93 } 94 95 std::string Dump(const std::string &prefix) override; 96 97 private: 98 std::string name_; 99 AutoPtr<ASTAttr> attr_ = new ASTAttr(); 100 std::vector<AutoPtr<ASTParameter>> parameters_; 101 bool isOverload_ = false; // used to identify if method is overload 102 size_t cmdId_; // used to identify same name method 103 }; 104 } // namespace HDI 105 } // namespace OHOS 106 107 #endif // OHOS_HDI_ASTMETHOD_H 108