1ca0551cfSopenharmony_ci/*
2ca0551cfSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3ca0551cfSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4ca0551cfSopenharmony_ci * you may not use this file except in compliance with the License.
5ca0551cfSopenharmony_ci * You may obtain a copy of the License at
6ca0551cfSopenharmony_ci *
7ca0551cfSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8ca0551cfSopenharmony_ci *
9ca0551cfSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10ca0551cfSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11ca0551cfSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12ca0551cfSopenharmony_ci * See the License for the specific language governing permissions and
13ca0551cfSopenharmony_ci * limitations under the License.
14ca0551cfSopenharmony_ci */
15ca0551cfSopenharmony_ci
16ca0551cfSopenharmony_ci#ifndef OHOS_IDL_AST_ATTRIBUTE_H
17ca0551cfSopenharmony_ci#define OHOS_IDL_AST_ATTRIBUTE_H
18ca0551cfSopenharmony_ci
19ca0551cfSopenharmony_ci#include "ast/ast_node.h"
20ca0551cfSopenharmony_ci
21ca0551cfSopenharmony_cinamespace OHOS {
22ca0551cfSopenharmony_cinamespace Idl {
23ca0551cfSopenharmony_ciclass ASTAttr : public ASTNode {
24ca0551cfSopenharmony_cipublic:
25ca0551cfSopenharmony_ci    using Attribute = uint32_t;
26ca0551cfSopenharmony_ci    static constexpr Attribute NONE = 0U;
27ca0551cfSopenharmony_ci    static constexpr Attribute MINI = 0x1U;
28ca0551cfSopenharmony_ci    static constexpr Attribute LITE = 0x1U << 1;
29ca0551cfSopenharmony_ci    static constexpr Attribute FULL = 0x1U << 2;
30ca0551cfSopenharmony_ci    static constexpr Attribute ONEWAY = 0x1U << 3;
31ca0551cfSopenharmony_ci    static constexpr Attribute CALLBACK = 0x1U << 4;
32ca0551cfSopenharmony_ci    static constexpr Attribute CACHEABLE = 0x1U << 5;
33ca0551cfSopenharmony_ci    static constexpr Attribute FREEZECONTROL = 0x1U << 6;
34ca0551cfSopenharmony_ci
35ca0551cfSopenharmony_ci    explicit ASTAttr(Attribute value = ASTAttr::NONE) : value_(value) {}
36ca0551cfSopenharmony_ci
37ca0551cfSopenharmony_ci    std::string ToString() const override;
38ca0551cfSopenharmony_ci
39ca0551cfSopenharmony_ci    std::string Dump(const std::string &prefix) override;
40ca0551cfSopenharmony_ci
41ca0551cfSopenharmony_ci    inline void SetValue(Attribute value)
42ca0551cfSopenharmony_ci    {
43ca0551cfSopenharmony_ci        value_ |= value;
44ca0551cfSopenharmony_ci    }
45ca0551cfSopenharmony_ci
46ca0551cfSopenharmony_ci    inline Attribute GetValue() const
47ca0551cfSopenharmony_ci    {
48ca0551cfSopenharmony_ci        return value_;
49ca0551cfSopenharmony_ci    }
50ca0551cfSopenharmony_ci
51ca0551cfSopenharmony_ci    bool IsNone() const
52ca0551cfSopenharmony_ci    {
53ca0551cfSopenharmony_ci        return value_  == NONE;
54ca0551cfSopenharmony_ci    }
55ca0551cfSopenharmony_ci
56ca0551cfSopenharmony_ci    bool HasValue(Attribute attr) const
57ca0551cfSopenharmony_ci    {
58ca0551cfSopenharmony_ci        return (value_ & attr) != 0;
59ca0551cfSopenharmony_ci    }
60ca0551cfSopenharmony_ci
61ca0551cfSopenharmony_ci    bool Match(SystemLevel level) const;
62ca0551cfSopenharmony_ci
63ca0551cfSopenharmony_ci    int32_t GetCacheableTime()
64ca0551cfSopenharmony_ci    {
65ca0551cfSopenharmony_ci        return cacheableTime_;
66ca0551cfSopenharmony_ci    }
67ca0551cfSopenharmony_ci
68ca0551cfSopenharmony_ci    std::string& GetCacheableTimeString()
69ca0551cfSopenharmony_ci    {
70ca0551cfSopenharmony_ci        return cacheableTimeString_;
71ca0551cfSopenharmony_ci    }
72ca0551cfSopenharmony_ci
73ca0551cfSopenharmony_ci    void SetCacheableTimeString(const std::string &timeStr)
74ca0551cfSopenharmony_ci    {
75ca0551cfSopenharmony_ci        cacheableTimeString_ = timeStr;
76ca0551cfSopenharmony_ci    }
77ca0551cfSopenharmony_ci
78ca0551cfSopenharmony_ci    bool CacheableStrToInt();
79ca0551cfSopenharmony_ci
80ca0551cfSopenharmony_ciprivate:
81ca0551cfSopenharmony_ci    Attribute value_;
82ca0551cfSopenharmony_ci    int32_t cacheableTime_ = 0;
83ca0551cfSopenharmony_ci    std::string cacheableTimeString_;
84ca0551cfSopenharmony_ci};
85ca0551cfSopenharmony_ci
86ca0551cfSopenharmony_ciclass ASTParamAttr : public ASTNode {
87ca0551cfSopenharmony_cipublic:
88ca0551cfSopenharmony_ci    using ParamAttr = uint32_t;
89ca0551cfSopenharmony_ci    static constexpr ParamAttr PARAM_NONE = 0U;
90ca0551cfSopenharmony_ci    static constexpr ParamAttr PARAM_IN = 0x1U;
91ca0551cfSopenharmony_ci    static constexpr ParamAttr PARAM_OUT = 0x1U << 1;
92ca0551cfSopenharmony_ci    static constexpr ParamAttr PARAM_INOUT = (PARAM_IN | PARAM_OUT);
93ca0551cfSopenharmony_ci
94ca0551cfSopenharmony_ci    explicit ASTParamAttr(ParamAttr value) : ASTNode(), value_(value) {}
95ca0551cfSopenharmony_ci
96ca0551cfSopenharmony_ci    std::string ToString() const override;
97ca0551cfSopenharmony_ci
98ca0551cfSopenharmony_ci    std::string Dump(const std::string &prefix) override;
99ca0551cfSopenharmony_ci
100ca0551cfSopenharmony_cipublic:
101ca0551cfSopenharmony_ci    ParamAttr value_;
102ca0551cfSopenharmony_ci};
103ca0551cfSopenharmony_ci
104ca0551cfSopenharmony_ci} // namespace Idl
105ca0551cfSopenharmony_ci} // namespace OHOS
106ca0551cfSopenharmony_ci
107ca0551cfSopenharmony_ci#endif // OHOS_IDL_AST_ATTRIBUTE_H