Skip to content

Commit 7cbb983

Browse files
committed
mathematical_expr.h: move can_cast and validate_expr above to_*_expr
This is the layout that std_code.h uses and it will facilitate re-use of validate_expr. No code changes, just text motion.
1 parent ea1bc3a commit 7cbb983

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
/// \brief Application of (mathematical) function
190193
class function_application_exprt : public binary_exprt
191194
{
@@ -222,6 +225,17 @@ class function_application_exprt : public binary_exprt
222225
}
223226
};
224227

228+
template <>
229+
inline bool can_cast_expr<function_application_exprt>(const exprt &base)
230+
{
231+
return base.id() == ID_function_application;
232+
}
233+
234+
inline void validate_expr(const function_application_exprt &value)
235+
{
236+
validate_operands(value, 2, "Function application must have two operands");
237+
}
238+
225239
/// \brief Cast an exprt to a \ref function_application_exprt
226240
///
227241
/// \a expr must be known to be \ref function_application_exprt.
@@ -246,16 +260,6 @@ inline function_application_exprt &to_function_application_expr(exprt &expr)
246260
return static_cast<function_application_exprt &>(expr);
247261
}
248262

249-
template <>
250-
inline bool can_cast_expr<function_application_exprt>(const exprt &base)
251-
{
252-
return base.id() == ID_function_application;
253-
}
254-
inline void validate_expr(const function_application_exprt &value)
255-
{
256-
validate_operands(value, 2, "Function application must have two operands");
257-
}
258-
259263
/// \brief A base class for quantifier expressions
260264
class quantifier_exprt : public binary_predicate_exprt
261265
{
@@ -289,6 +293,17 @@ class quantifier_exprt : public binary_predicate_exprt
289293
}
290294
};
291295

296+
template <>
297+
inline bool can_cast_expr<quantifier_exprt>(const exprt &base)
298+
{
299+
return base.id() == ID_forall || base.id() == ID_exists;
300+
}
301+
302+
inline void validate_expr(const quantifier_exprt &value)
303+
{
304+
validate_operands(value, 2, "quantifier expressions must have two operands");
305+
}
306+
292307
/// \brief Cast an exprt to a \ref quantifier_exprt
293308
///
294309
/// \a expr must be known to be \ref quantifier_exprt.
@@ -316,17 +331,6 @@ inline quantifier_exprt &to_quantifier_expr(exprt &expr)
316331
return static_cast<quantifier_exprt &>(expr);
317332
}
318333

319-
template <>
320-
inline bool can_cast_expr<quantifier_exprt>(const exprt &base)
321-
{
322-
return base.id() == ID_forall || base.id() == ID_exists;
323-
}
324-
325-
inline void validate_expr(const quantifier_exprt &value)
326-
{
327-
validate_operands(value, 2, "quantifier expressions must have two operands");
328-
}
329-
330334
/// \brief A forall expression
331335
class forall_exprt : public quantifier_exprt
332336
{

0 commit comments

Comments
 (0)