CBMC
Loading...
Searching...
No Matches
gcc_conditional_expression.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Lowering of GCC's `a ? : b` conditional expression
4
5Author: Michael Tautschnig
6
7\*******************************************************************/
8
13
14#ifndef CPROVER_ANSI_C_GCC_CONDITIONAL_EXPRESSION_H
15#define CPROVER_ANSI_C_GCC_CONDITIONAL_EXPRESSION_H
16
17#include <util/invariant.h>
18#include <util/std_code.h>
19#include <util/std_expr.h>
20#include <util/std_types.h>
21
33{
34 PRECONDITION(expr.get_statement() == ID_gcc_conditional_expression);
35 const binary_exprt &binary = to_binary_expr(expr);
36 if_exprt if_expr{
38 binary.op0(),
39 binary.op1(),
40 expr.type()};
41 if_expr.add_source_location() = expr.source_location();
42 return if_expr;
43}
44
53{
54 for(auto &op : expr.operands())
56
57 if(
58 expr.id() == ID_side_effect &&
59 to_side_effect_expr(expr).get_statement() ==
60 ID_gcc_conditional_expression &&
61 expr.operands().size() == 2)
62 {
63 if_exprt if_expr =
65 expr.swap(if_expr);
66 }
67}
68
69#endif // CPROVER_ANSI_C_GCC_CONDITIONAL_EXPRESSION_H
A base class for binary expressions.
Definition std_expr.h:649
The Boolean type.
Definition std_types.h:35
Base class for all expressions.
Definition expr.h:57
typet & type()
Return the type of the expression.
Definition expr.h:85
operandst & operands()
Definition expr.h:95
const source_locationt & source_location() const
Definition expr.h:236
source_locationt & add_source_location()
Definition expr.h:241
The trinary if-then-else operator.
Definition std_expr.h:2426
void swap(irept &irep)
Definition irep.h:436
const irep_idt & id() const
Definition irep.h:390
An expression containing a side effect.
Definition std_code.h:1450
const irep_idt & get_statement() const
Definition std_code.h:1472
static exprt conditional_cast(const exprt &expr, const typet &type)
Definition std_expr.h:2003
if_exprt lower_gcc_conditional_expression(const side_effect_exprt &expr)
Lower a single GCC conditional expression with omitted middle operand.
void lower_gcc_conditional_expressions(exprt &expr)
Recursively lower all GCC conditional expressions with omitted middle operand in expr.
static std::string binary(const constant_exprt &src)
#define PRECONDITION(CONDITION)
Definition invariant.h:463
side_effect_exprt & to_side_effect_expr(exprt &expr)
Definition std_code.h:1506
API to expression classes.
const binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_exprt.
Definition std_expr.h:721
Pre-defined types.