cprover
cpp_typecheck_static_assert.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: C++ Language Type Checking
4 
5 Author: Daniel Kroening, kroening@cs.cmu.edu
6 
7 \*******************************************************************/
8 
11 
12 #include "cpp_typecheck.h"
13 
14 #include <util/std_types.h>
15 
17 {
18  typecheck_expr(cpp_static_assert.op0());
19  typecheck_expr(cpp_static_assert.op1());
20 
21  cpp_static_assert.op0().make_typecast(bool_typet());
22  make_constant(cpp_static_assert.op0());
23 
24  if(cpp_static_assert.op0().is_true())
25  {
26  // ok
27  }
28  else if(cpp_static_assert.op0().is_false())
29  {
30  // failed
31  error().source_location=cpp_static_assert.source_location();
32  error() << "static assertion failed";
33  if(cpp_static_assert.op1().id()==ID_string_constant)
34  error() << ": " << cpp_static_assert.op1().get(ID_value);
35  error() << eom;
36  throw 0;
37  }
38  else
39  {
40  // not true or false
41  error().source_location=cpp_static_assert.source_location();
42  error() << "static assertion is not constant" << eom;
43  throw 0;
44  }
45 }
cpp_typecheckt::convert
void convert(cpp_linkage_spect &)
Definition: cpp_typecheck_linkage_spec.cpp:14
exprt::op0
exprt & op0()
Definition: expr.h:84
bool_typet
The Boolean type.
Definition: std_types.h:28
messaget::eom
static eomt eom
Definition: message.h:284
exprt::is_true
bool is_true() const
Return whether the expression is a constant representing true.
Definition: expr.cpp:90
exprt::is_false
bool is_false() const
Return whether the expression is a constant representing false.
Definition: expr.cpp:99
c_typecheck_baset::make_constant
virtual void make_constant(exprt &expr)
Definition: c_typecheck_expr.cpp:3482
messaget::error
mstreamt & error() const
Definition: message.h:386
messaget::mstreamt::source_location
source_locationt source_location
Definition: message.h:236
std_types.h
exprt::op1
exprt & op1()
Definition: expr.h:87
irept::id
const irep_idt & id() const
Definition: irep.h:259
cpp_typecheck.h
cpp_typecheckt::typecheck_expr
void typecheck_expr(exprt &) override
Definition: cpp_typecheck_expr.cpp:2684
irept::get
const irep_idt & get(const irep_namet &name) const
Definition: irep.cpp:212
cpp_static_assertt
Definition: cpp_static_assert.h:17
exprt::make_typecast
void make_typecast(const typet &_type)
Create a typecast_exprt to the given type.
Definition: expr.cpp:74
exprt::source_location
const source_locationt & source_location() const
Definition: expr.h:228