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_AST_ATTRIBUTE_H 17#define OHOS_IDL_AST_ATTRIBUTE_H 18 19#include "ast/ast_node.h" 20 21namespace OHOS { 22namespace Idl { 23class ASTAttr : public ASTNode { 24public: 25 using Attribute = uint32_t; 26 static constexpr Attribute NONE = 0U; 27 static constexpr Attribute MINI = 0x1U; 28 static constexpr Attribute LITE = 0x1U << 1; 29 static constexpr Attribute FULL = 0x1U << 2; 30 static constexpr Attribute ONEWAY = 0x1U << 3; 31 static constexpr Attribute CALLBACK = 0x1U << 4; 32 static constexpr Attribute CACHEABLE = 0x1U << 5; 33 static constexpr Attribute FREEZECONTROL = 0x1U << 6; 34 35 explicit ASTAttr(Attribute value = ASTAttr::NONE) : value_(value) {} 36 37 std::string ToString() const override; 38 39 std::string Dump(const std::string &prefix) override; 40 41 inline void SetValue(Attribute value) 42 { 43 value_ |= value; 44 } 45 46 inline Attribute GetValue() const 47 { 48 return value_; 49 } 50 51 bool IsNone() const 52 { 53 return value_ == NONE; 54 } 55 56 bool HasValue(Attribute attr) const 57 { 58 return (value_ & attr) != 0; 59 } 60 61 bool Match(SystemLevel level) const; 62 63 int32_t GetCacheableTime() 64 { 65 return cacheableTime_; 66 } 67 68 std::string& GetCacheableTimeString() 69 { 70 return cacheableTimeString_; 71 } 72 73 void SetCacheableTimeString(const std::string &timeStr) 74 { 75 cacheableTimeString_ = timeStr; 76 } 77 78 bool CacheableStrToInt(); 79 80private: 81 Attribute value_; 82 int32_t cacheableTime_ = 0; 83 std::string cacheableTimeString_; 84}; 85 86class ASTParamAttr : public ASTNode { 87public: 88 using ParamAttr = uint32_t; 89 static constexpr ParamAttr PARAM_NONE = 0U; 90 static constexpr ParamAttr PARAM_IN = 0x1U; 91 static constexpr ParamAttr PARAM_OUT = 0x1U << 1; 92 static constexpr ParamAttr PARAM_INOUT = (PARAM_IN | PARAM_OUT); 93 94 explicit ASTParamAttr(ParamAttr value) : ASTNode(), value_(value) {} 95 96 std::string ToString() const override; 97 98 std::string Dump(const std::string &prefix) override; 99 100public: 101 ParamAttr value_; 102}; 103 104} // namespace Idl 105} // namespace OHOS 106 107#endif // OHOS_IDL_AST_ATTRIBUTE_H