• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-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 PANDA_VERIFIER_ABSTRACT_VALUE_HPP
17 #define PANDA_VERIFIER_ABSTRACT_VALUE_HPP
18 
19 #include "verification/value/variables.h"
20 
21 #include "macros.h"
22 
23 #include <variant>
24 
25 namespace ark::verifier {
26 class AbstractValue {
27 public:
28     struct None {};
29     using ContentsData = std::variant<None, Variables::Var>;
30     AbstractValue() = default;
31     AbstractValue(const AbstractValue &) = default;
32     AbstractValue(AbstractValue &&) = default;
33     AbstractValue &operator=(const AbstractValue &) = default;
34     AbstractValue &operator=(AbstractValue &&) = default;
35     ~AbstractValue() = default;
36     // NOLINTNEXTLINE(google-explicit-constructor)
AbstractValue(const Variables::Var & var)37     AbstractValue(const Variables::Var &var) : contents_ {var} {}
GetVar()38     Variables::Var GetVar() const
39     {
40         ASSERT(IsVar());
41         return std::get<Variables::Var>(contents_);
42     }
43     AbstractValue &operator=(const None & /* unused */)
44     {
45         contents_ = None {};
46         return *this;
47     }
48     AbstractValue &operator=(Variables::Var const &var)
49     {
50         contents_ = var;
51         return *this;
52     }
IsNone()53     bool IsNone() const
54     {
55         return std::holds_alternative<None>(contents_);
56     }
IsVar()57     bool IsVar() const
58     {
59         return std::holds_alternative<Variables::Var>(contents_);
60     }
Clear()61     void Clear()
62     {
63         contents_ = None {};
64     }
65     AbstractValue operator&([[maybe_unused]] const AbstractValue &rhs) const
66     {
67         // currently only None is supported
68         // ASSERT(IsNone() && rhs.IsNone())
69         return {};
70     }
71 
72 private:
73     ContentsData contents_ {None {}};
74 };
75 }  // namespace ark::verifier
76 
77 #endif  // !PANDA_VERIFIER_ABSTRACT_VALUE_HPP
78