CBMC
c_typecheck_typecast.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 #include "c_typecheck_base.h"
10 
11 #include "c_typecast.h"
12 
14  exprt &expr,
15  const typet &dest_type)
16 {
17  c_typecastt c_typecast(*this);
18 
19  typet src_type=expr.type();
20 
21  c_typecast.implicit_typecast(expr, dest_type);
22 
23  for(const auto &tc_error : c_typecast.errors)
24  {
26  error() << "in expression '" << to_string(expr) << "':\n"
27  << "conversion from '" << to_string(src_type) << "' to '"
28  << to_string(dest_type) << "': " << tc_error << eom;
29  }
30 
31  if(!c_typecast.errors.empty())
32  throw 0; // give up
33 
34  for(const auto &tc_warning : c_typecast.warnings)
35  {
37  warning() << "conversion from '" << to_string(src_type) << "' to '"
38  << to_string(dest_type) << "': " << tc_warning << eom;
39  }
40 }
41 
43  exprt &expr1,
44  exprt &expr2)
45 {
46  c_typecastt c_typecast(*this);
47  c_typecast.implicit_typecast_arithmetic(expr1, expr2);
48 
49  for(const auto &tc_error : c_typecast.errors)
50  {
52  error() << "in expression '" << to_string(expr1) << "':\n"
53  << "conversion from '" << to_string(expr1.type()) << "' to '"
54  << to_string(expr2.type()) << "': " << tc_error << eom;
55  }
56 
57  if(!c_typecast.errors.empty())
58  throw 0; // give up
59 
60  for(const auto &tc_warning : c_typecast.warnings)
61  {
63  warning() << "conversion from '" << to_string(expr1.type()) << "' to '"
64  << to_string(expr2.type()) << "': " << tc_warning << eom;
65  }
66 }
67 
69 {
70  c_typecastt c_typecast(*this);
71  c_typecast.implicit_typecast_arithmetic(expr);
72 
73  for(const auto &tc_error : c_typecast.errors)
74  {
76  error() << tc_error << eom;
77  }
78 
79  if(!c_typecast.errors.empty())
80  throw 0; // give up
81 
82  for(const auto &tc_warning : c_typecast.warnings)
83  {
85  warning() << tc_warning << eom;
86  }
87 }
ANSI-C Language Type Checking.
virtual void implicit_typecast(exprt &expr, const typet &type)
Definition: c_typecast.cpp:508
virtual void implicit_typecast_arithmetic(exprt &expr)
Definition: c_typecast.cpp:502
std::list< std::string > warnings
Definition: c_typecast.h:67
std::list< std::string > errors
Definition: c_typecast.h:66
virtual void implicit_typecast(exprt &expr, const typet &type)
virtual void implicit_typecast_arithmetic(exprt &expr)
virtual std::string to_string(const exprt &expr)
Base class for all expressions.
Definition: expr.h:56
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
Definition: expr.cpp:147
typet & type()
Return the type of the expression.
Definition: expr.h:84
source_locationt source_location
Definition: message.h:247
mstreamt & error() const
Definition: message.h:399
mstreamt & warning() const
Definition: message.h:404
static eomt eom
Definition: message.h:297
The type of an expression, extends irept.
Definition: type.h:29