• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
21 namespace OHOS {
22 namespace Idl {
23 class ASTAttr : public ASTNode {
24 public:
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     static constexpr Attribute IPCCODE = 0x1U << 7;
35     static constexpr Attribute IPC_IN_CAPACITY = 0x1U << 8;
36     static constexpr Attribute IPC_OUT_CAPACITY = 0x1U << 9;
37     static constexpr Attribute CUSTOM_MSG_OPTION = 0x1U << 10;
38     static constexpr Attribute MACRO = 0x1U << 11;
39 
value_(value)40     explicit ASTAttr(Attribute value = ASTAttr::NONE) : value_(value) {}
41 
42     std::string ToString() const override;
43 
44     std::string Dump(const std::string &prefix) override;
45 
SetValue(Attribute value)46     inline void SetValue(Attribute value)
47     {
48         value_ |= value;
49     }
50 
GetValue()51     inline Attribute GetValue() const
52     {
53         return value_;
54     }
55 
IsNone()56     bool IsNone() const
57     {
58         return value_  == NONE;
59     }
60 
HasValue(Attribute attr)61     bool HasValue(Attribute attr) const
62     {
63         return (value_ & attr) != 0;
64     }
65 
66     bool Match(SystemLevel level) const;
67 
GetCacheableTime()68     int32_t GetCacheableTime()
69     {
70         return cacheableTime_;
71     }
72 
GetCacheableTimeString()73     std::string& GetCacheableTimeString()
74     {
75         return cacheableTimeString_;
76     }
77 
SetCacheableTimeString(const std::string & timeStr)78     void SetCacheableTimeString(const std::string &timeStr)
79     {
80         cacheableTimeString_ = timeStr;
81     }
82 
83     bool CacheableStrToInt();
84 
GetIpcCodeStr()85     std::string& GetIpcCodeStr()
86     {
87         return ipcCodeStr_;
88     }
89 
SetIpcCodeStr(const std::string & ipcCodeStr)90     void SetIpcCodeStr(const std::string &ipcCodeStr)
91     {
92         ipcCodeStr_ = ipcCodeStr;
93     }
94 
GetIpcInCapacity()95     std::string &GetIpcInCapacity()
96     {
97         return ipcInCapacity_;
98     }
99 
SetIpcInCapacity(const std::string & capacity)100     void SetIpcInCapacity(const std::string &capacity)
101     {
102         ipcInCapacity_ = capacity;
103     }
104 
GetIpcOutCapacity()105     std::string &GetIpcOutCapacity()
106     {
107         return ipcOutCapacity_;
108     }
109 
SetIpcOutCapacity(const std::string & capacity)110     void SetIpcOutCapacity(const std::string &capacity)
111     {
112         ipcOutCapacity_ = capacity;
113     }
114 
115 private:
116     Attribute value_;
117     int32_t cacheableTime_ = 0;
118     std::string cacheableTimeString_;
119     std::string ipcCodeStr_;
120     std::string ipcInCapacity_;
121     std::string ipcOutCapacity_;
122 };
123 
124 class ASTParamAttr : public ASTNode {
125 public:
126     using ParamAttr = uint32_t;
127     static constexpr ParamAttr PARAM_NONE = 0U;
128     static constexpr ParamAttr PARAM_IN = 0x1U;
129     static constexpr ParamAttr PARAM_OUT = 0x1U << 1;
130     static constexpr ParamAttr PARAM_INOUT = (PARAM_IN | PARAM_OUT);
131 
ASTParamAttr(ParamAttr value)132     explicit ASTParamAttr(ParamAttr value) : ASTNode(), value_(value) {}
133 
134     std::string ToString() const override;
135 
136     std::string Dump(const std::string &prefix) override;
137 
138 public:
139     ParamAttr value_;
140 };
141 
142 } // namespace Idl
143 } // namespace OHOS
144 
145 #endif // OHOS_IDL_AST_ATTRIBUTE_H