CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
c_typecheck_typecast.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: 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{
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{
47 c_typecast.implicit_typecast_arithmetic(expr1, expr2);
48
49 for(const auto &tc_error : c_typecast.errors)
50 {
51 error().source_location = expr1.find_source_location();
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 {
62 warning().source_location = expr1.find_source_location();
63 warning() << "conversion from '" << to_string(expr1.type()) << "' to '"
64 << to_string(expr2.type()) << "': " << tc_warning << eom;
65 }
66}
67
69{
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.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
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:239
mstreamt & error() const
Definition message.h:391
mstreamt & warning() const
Definition message.h:396
static eomt eom
Definition message.h:289
The type of an expression, extends irept.
Definition type.h:29