Skip to content

Commit 10d61b2

Browse files
committed
mathematical_expr.h: move can_cast and validate_expr
Placing them above to_*_expr is the layout that std_code.h uses. Furthermore it will facilitate re-use of validate_expr. No code changes, just text motion.
1 parent 8a21dea commit 10d61b2

File tree

1 file changed

+55
-51
lines changed

1 file changed

+55
-51
lines changed

src/util/mathematical_expr.h

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ class transt : public ternary_exprt
6161
}
6262
};
6363

64+
template <>
65+
inline bool can_cast_expr<transt>(const exprt &base)
66+
{
67+
return base.id() == ID_trans;
68+
}
69+
70+
inline void validate_expr(const transt &value)
71+
{
72+
validate_operands(value, 3, "Transition systems must have three operands");
73+
}
74+
6475
/// Cast an exprt to a \ref transt
6576
/// \a expr must be known to be \ref transt.
6677
/// \param expr: Source expression
@@ -82,16 +93,6 @@ inline transt &to_trans_expr(exprt &expr)
8293
return static_cast<transt &>(expr);
8394
}
8495

85-
template <>
86-
inline bool can_cast_expr<transt>(const exprt &base)
87-
{
88-
return base.id() == ID_trans;
89-
}
90-
inline void validate_expr(const transt &value)
91-
{
92-
validate_operands(value, 3, "Transition systems must have three operands");
93-
}
94-
9596
/// \brief Exponentiation
9697
class power_exprt : public binary_exprt
9798
{
@@ -107,6 +108,17 @@ class power_exprt : public binary_exprt
107108
}
108109
};
109110

111+
template <>
112+
inline bool can_cast_expr<power_exprt>(const exprt &base)
113+
{
114+
return base.id() == ID_power;
115+
}
116+
117+
inline void validate_expr(const power_exprt &value)
118+
{
119+
validate_operands(value, 2, "Power must have two operands");
120+
}
121+
110122
/// \brief Cast an exprt to a \ref power_exprt
111123
///
112124
/// \a expr must be known to be \ref power_exprt.
@@ -128,16 +140,6 @@ inline power_exprt &to_power_expr(exprt &expr)
128140
return static_cast<power_exprt &>(expr);
129141
}
130142

131-
template <>
132-
inline bool can_cast_expr<power_exprt>(const exprt &base)
133-
{
134-
return base.id() == ID_power;
135-
}
136-
inline void validate_expr(const power_exprt &value)
137-
{
138-
validate_operands(value, 2, "Power must have two operands");
139-
}
140-
141143
/// \brief Falling factorial power
142144
class factorial_power_exprt : public binary_exprt
143145
{
@@ -153,6 +155,17 @@ class factorial_power_exprt : public binary_exprt
153155
}
154156
};
155157

158+
template <>
159+
inline bool can_cast_expr<factorial_power_exprt>(const exprt &base)
160+
{
161+
return base.id() == ID_factorial_power;
162+
}
163+
164+
inline void validate_expr(const factorial_power_exprt &value)
165+
{
166+
validate_operands(value, 2, "Factorial power must have two operands");
167+
}
168+
156169
/// \brief Cast an exprt to a \ref factorial_power_exprt
157170
///
158171
/// \a expr must be known to be \ref factorial_power_exprt.
@@ -176,16 +189,6 @@ inline factorial_power_exprt &to_factorial_expr(exprt &expr)
176189
return static_cast<factorial_power_exprt &>(expr);
177190
}
178191

179-
template <>
180-
inline bool can_cast_expr<factorial_power_exprt>(const exprt &base)
181-
{
182-
return base.id() == ID_factorial_power;
183-
}
184-
inline void validate_expr(const factorial_power_exprt &value)
185-
{
186-
validate_operands(value, 2, "Factorial power must have two operands");
187-
}
188-
189192
class tuple_exprt : public multi_ary_exprt
190193
{
191194
public:
@@ -239,6 +242,17 @@ class function_application_exprt : public binary_exprt
239242
}
240243
};
241244

245+
template <>
246+
inline bool can_cast_expr<function_application_exprt>(const exprt &base)
247+
{
248+
return base.id() == ID_function_application;
249+
}
250+
251+
inline void validate_expr(const function_application_exprt &value)
252+
{
253+
validate_operands(value, 2, "Function application must have two operands");
254+
}
255+
242256
/// \brief Cast an exprt to a \ref function_application_exprt
243257
///
244258
/// \a expr must be known to be \ref function_application_exprt.
@@ -263,16 +277,6 @@ inline function_application_exprt &to_function_application_expr(exprt &expr)
263277
return static_cast<function_application_exprt &>(expr);
264278
}
265279

266-
template <>
267-
inline bool can_cast_expr<function_application_exprt>(const exprt &base)
268-
{
269-
return base.id() == ID_function_application;
270-
}
271-
inline void validate_expr(const function_application_exprt &value)
272-
{
273-
validate_operands(value, 2, "Function application must have two operands");
274-
}
275-
276280
/// \brief A base class for quantifier expressions
277281
class quantifier_exprt : public binary_predicate_exprt
278282
{
@@ -306,6 +310,17 @@ class quantifier_exprt : public binary_predicate_exprt
306310
}
307311
};
308312

313+
template <>
314+
inline bool can_cast_expr<quantifier_exprt>(const exprt &base)
315+
{
316+
return base.id() == ID_forall || base.id() == ID_exists;
317+
}
318+
319+
inline void validate_expr(const quantifier_exprt &value)
320+
{
321+
validate_operands(value, 2, "quantifier expressions must have two operands");
322+
}
323+
309324
/// \brief Cast an exprt to a \ref quantifier_exprt
310325
///
311326
/// \a expr must be known to be \ref quantifier_exprt.
@@ -333,17 +348,6 @@ inline quantifier_exprt &to_quantifier_expr(exprt &expr)
333348
return static_cast<quantifier_exprt &>(expr);
334349
}
335350

336-
template <>
337-
inline bool can_cast_expr<quantifier_exprt>(const exprt &base)
338-
{
339-
return base.id() == ID_forall || base.id() == ID_exists;
340-
}
341-
342-
inline void validate_expr(const quantifier_exprt &value)
343-
{
344-
validate_operands(value, 2, "quantifier expressions must have two operands");
345-
}
346-
347351
/// \brief A forall expression
348352
class forall_exprt : public quantifier_exprt
349353
{

0 commit comments

Comments
 (0)