cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
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
13
void
c_typecheck_baset::implicit_typecast
(
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
{
25
error
().
source_location
=expr.
find_source_location
();
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
{
36
warning
().
source_location
=expr.
find_source_location
();
37
warning
() <<
"conversion from '"
<<
to_string
(src_type) <<
"' to '"
38
<<
to_string
(dest_type) <<
"': "
<< tc_warning <<
eom
;
39
}
40
}
41
42
void
c_typecheck_baset::implicit_typecast_arithmetic
(
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
{
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
68
void
c_typecheck_baset::implicit_typecast_arithmetic
(
exprt
&expr)
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
{
75
error
().
source_location
= expr.
find_source_location
();
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
{
84
warning
().
source_location
= expr.
find_source_location
();
85
warning
() << tc_warning <<
eom
;
86
}
87
}
c_typecast.h
c_typecheck_base.h
ANSI-C Language Type Checking.
c_typecastt
Definition
c_typecast.h:45
c_typecastt::implicit_typecast
virtual void implicit_typecast(exprt &expr, const typet &type)
Definition
c_typecast.cpp:510
c_typecastt::implicit_typecast_arithmetic
virtual void implicit_typecast_arithmetic(exprt &expr)
Definition
c_typecast.cpp:504
c_typecastt::warnings
std::list< std::string > warnings
Definition
c_typecast.h:67
c_typecastt::errors
std::list< std::string > errors
Definition
c_typecast.h:66
c_typecheck_baset::implicit_typecast
virtual void implicit_typecast(exprt &expr, const typet &type)
Definition
c_typecheck_typecast.cpp:13
c_typecheck_baset::implicit_typecast_arithmetic
virtual void implicit_typecast_arithmetic(exprt &expr)
Definition
c_typecheck_typecast.cpp:68
c_typecheck_baset::to_string
virtual std::string to_string(const exprt &expr)
Definition
c_typecheck_base.cpp:28
exprt
Base class for all expressions.
Definition
expr.h:57
exprt::find_source_location
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
Definition
expr.cpp:68
exprt::type
typet & type()
Return the type of the expression.
Definition
expr.h:85
messaget::mstreamt::source_location
source_locationt source_location
Definition
message.h:239
messaget::error
mstreamt & error() const
Definition
message.h:391
messaget::warning
mstreamt & warning() const
Definition
message.h:396
messaget::eom
static eomt eom
Definition
message.h:289
typet
The type of an expression, extends irept.
Definition
type.h:29
ansi-c
c_typecheck_typecast.cpp
Generated by
1.17.0