• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 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 panda::verifier {
26 class AbstractValue {
27 public:
28     struct None {
29     };
30     using ContentsData = std::variant<None, Variables::Var>;
31     AbstractValue() = default;
32     AbstractValue(const AbstractValue &) = default;
33     AbstractValue(AbstractValue &&) = default;
34     AbstractValue &operator=(const AbstractValue &) = default;
35     AbstractValue &operator=(AbstractValue &&) = default;
36     ~AbstractValue() = default;
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 &)
44     {
45         Contents_ = None {};
46         return *this;
47     }
48     AbstractValue &operator=(Variables::Var 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 panda::verifier
76 
77 #endif  // !_PANDA_VERIFIER_ABSTRACT_VALUE_HPP
78