Documentation of CSL
variableParent.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
23 #ifndef VARIABLE_PARENT_H_INCLUDED
24 #define VARIABLE_PARENT_H_INCLUDED
25 
26 #include "abstract.h"
27 #include "parent.h"
28 
29 namespace csl {
30 
31 class LiteralParent: public AbstractParent {
32 
33  public:
34 
35  explicit
36  LiteralParent(std::string const& t_name = "");
37 
38  LiteralParent(std::string const& t_name,
39  long double t_value);
40 
41  LiteralParent(std::string const& t_name,
42  Expr const& t_value);
43 
44  // Assignment and copy are forbidden
45  LiteralParent(const LiteralParent&) = delete;
46  LiteralParent& operator=(const LiteralParent&) = delete;
47 
48  ~LiteralParent() {}
49 
51  return cslParent::Literal;
52  }
53 
54  bool isValued() const override;
55 
56  Expr getValue() const;
57 
58  void setValue(long double t_value);
59 
60  void setValue(Expr const &t_value);
61 
62 
63  virtual
64  Expr generateInstance() = 0;
65 
66  private:
67 
68  virtual
69  bool isInstance(Expr_info expr) const = 0;
70 
71  protected:
72 
73  bool valued;
74 
75  Expr value;
76 };
77 
79 
80  public:
81 
82  explicit
83  ConstantParent(std::string const& t_name = "");
84 
85  ConstantParent(std::string const& t_name,
86  long double t_value);
87 
88  ConstantParent(std::string const& t_name,
89  Expr const& t_value);
90 
91  // Assignment and copy are forbidden
92  ConstantParent(const ConstantParent&) = delete;
93 
94  ConstantParent& operator=(const ConstantParent&) = delete;
95 
96  ~ConstantParent() {}
97 
98  cslParent::Type getType() const override {
99  return cslParent::Constant;
100  }
101 
102  void printDefinition(
103  std::ostream &out = std::cout,
104  int indentSize = 4,
105  bool header = false
106  ) const override;
107 
108  Expr generateInstance() override;
109 
110  private:
111 
112  bool isInstance(Expr_info expr) const override;
113 
114 };
115 
117 
118  public:
119 
120  explicit
121  VariableParent(std::string const& t_name = "");
122 
123  VariableParent(std::string const& t_name,
124  long double t_value);
125 
126  VariableParent(std::string const& t_name,
127  Expr const& t_value);
128 
129  // Assignment and copy are forbidden
130  VariableParent(const VariableParent&) = delete;
131  VariableParent& operator=(const VariableParent&) = delete;
132 
133  ~VariableParent() {}
134 
135  cslParent::Type getType() const override {
136  return cslParent::Variable;
137  }
138 
139  void printDefinition(
140  std::ostream &out = std::cout,
141  int indentSize = 4,
142  bool header = false
143  ) const override;
144 
145  bool isElementary() const;
146 
147  bool isAllDependencies() const;
148 
149  void setElementary(bool t_elementary);
150 
151  void setAllDependencies(bool t_allDependencies);
152 
153  void addDependency(Expr_info expr);
154 
155  void removeDependency(Expr_info expr);
156 
157 
158  bool dependsOn(Expr_info expr) const override;
159 
160  bool commutesWith(Expr_info expr,
161  int sign = -1);
162 
163  Expr generateInstance() override;
164 
165  private:
166 
167  bool isInstance(Expr_info expr) const override;
168 
169  private:
170 
171  bool elementary;
172 
173  // If not elementary, the variable can a priori depend on other variables.
174  // If allDependencies = true, dependencies is a list of all variables of
175  // which *this DOES NOT depend, *this depends on all the rest by default.
176  // IF allDependencies = false, dependecies is a list of all variables of
177  // which *this DOES depend, *this is by default independant of all the rest.
178  bool allDependencies;
179 
180  std::vector<unique_Expr_c> dependencies;
181 };
182 
183 
184 } // End of namespace csl;
185 
186 #endif
Namespace for csl library.
Definition: abreviation.h:34
Base classes for parents and elements.
PrimaryType
Definition: parent.h:39
Definition: variableParent.h:31
Root class of the inheritance tree of abstracts.
Definition: abstract.h:76
cslParent::Type getType() const override
Definition: variableParent.h:135
virtual bool dependsOn(Expr_info expr) const
Tells if the parent depends on another expression or not.
Definition: parent.cpp:297
cslParent::Type getType() const override
Definition: variableParent.h:98
Base class for all parents (indicial, fields etc). All parents derive from this class.
Definition: parent.h:81
cslParent::PrimaryType getPrimaryType() const override
Definition: variableParent.h:50
Definition: variableParent.h:78
Type
Definition: parent.h:47
Base classes for all exprs in the program.
Expression type/.
Definition: abstract.h:1573
Definition: variableParent.h:116