|
10 | 10 | #define CPROVER_UTIL_EXPR_H
|
11 | 11 |
|
12 | 12 | #include "type.h"
|
| 13 | +#include "validate.h" |
| 14 | +#include "validate_expressions.h" |
| 15 | +#include "validate_types.h" |
13 | 16 |
|
14 | 17 | #include <functional>
|
15 | 18 | #include <list>
|
@@ -235,6 +238,59 @@ class exprt:public irept
|
235 | 238 | return static_cast<source_locationt &>(add(ID_C_source_location));
|
236 | 239 | }
|
237 | 240 |
|
| 241 | + /// Check that the expression is well-formed (shallow checks only, i.e., |
| 242 | + /// subexpressions and its type are not checked). |
| 243 | + /// |
| 244 | + /// Subclasses may override this method to provide specific well-formedness |
| 245 | + /// checks for the corresponding expressions. |
| 246 | + /// |
| 247 | + /// The validation mode indicates whether well-formedness check failures are |
| 248 | + /// reported via DATA_INVARIANT violations or exceptions. |
| 249 | + void check(const validation_modet vm = validation_modet::INVARIANT) const |
| 250 | + { |
| 251 | + } |
| 252 | + |
| 253 | + /// Check that the expression is well-formed, assuming that its subexpressions |
| 254 | + /// and type have all ready been checked for well-formedness. |
| 255 | + /// |
| 256 | + /// Subclasses may override this method to provide specific well-formedness |
| 257 | + /// checks for the corresponding expressions. |
| 258 | + /// |
| 259 | + /// The validation mode indicates whether well-formedness check failures are |
| 260 | + /// reported via DATA_INVARIANT violations or exceptions. |
| 261 | + void validate( |
| 262 | + const namespacet &ns, |
| 263 | + const validation_modet vm = validation_modet::INVARIANT) const |
| 264 | + { |
| 265 | + check_expr_pick(*this, vm); |
| 266 | + } |
| 267 | + |
| 268 | + /// Check that the expression is well-formed (full check, including checks |
| 269 | + /// of all subexpressions and the type) |
| 270 | + /// |
| 271 | + /// Subclasses may override this method, though in most cases the provided |
| 272 | + /// implementation should be sufficient. |
| 273 | + /// |
| 274 | + /// The validation mode indicates whether well-formedness check failures are |
| 275 | + /// reported via DATA_INVARIANT violations or exceptions. |
| 276 | + void validate_full( |
| 277 | + const namespacet &ns, |
| 278 | + const validation_modet vm = validation_modet::INVARIANT) const |
| 279 | + { |
| 280 | + // first check operands (if any) |
| 281 | + for(const exprt &op : operands()) |
| 282 | + { |
| 283 | + validate_expr_full_pick(op, ns, vm); |
| 284 | + } |
| 285 | + |
| 286 | + // type may be nil |
| 287 | + const typet &t = type(); |
| 288 | + |
| 289 | + validate_type_full_pick(t, ns, vm); |
| 290 | + |
| 291 | + validate_expr_pick(*this, ns, vm); |
| 292 | + } |
| 293 | + |
238 | 294 | protected:
|
239 | 295 | exprt &add_expr(const irep_idt &name)
|
240 | 296 | {
|
|
0 commit comments