cprover
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(std::list<std::string>::const_iterator
24  it=c_typecast.errors.begin();
25  it!=c_typecast.errors.end();
26  it++)
27  {
29  error() << "in expression `" << to_string(expr) << "':\n"
30  << "conversion from `"
31  << to_string(src_type) << "' to `"
32  << to_string(dest_type) << "': "
33  << *it << eom;
34  }
35 
36  if(!c_typecast.errors.empty())
37  throw 0; // give up
38 
39  for(std::list<std::string>::const_iterator
40  it=c_typecast.warnings.begin();
41  it!=c_typecast.warnings.end();
42  it++)
43  {
45  warning() << "warning: conversion from `"
46  << to_string(src_type)
47  << "' to `"
48  << to_string(dest_type)
49  << "': " << *it << eom;
50  }
51 }
52 
54  exprt &expr1,
55  exprt &expr2)
56 {
57  c_typecastt c_typecast(*this);
58  c_typecast.implicit_typecast_arithmetic(expr1, expr2);
59 }
60 
62 {
63  c_typecastt c_typecast(*this);
64  c_typecast.implicit_typecast_arithmetic(expr);
65 }
The type of an expression.
Definition: type.h:22
typet & type()
Definition: expr.h:56
static mstreamt & eom(mstreamt &m)
Definition: message.h:272
virtual std::string to_string(const exprt &expr)
mstreamt & warning() const
Definition: message.h:307
ANSI-C Language Type Checking.
const source_locationt & find_source_location() const
Definition: expr.cpp:246
source_locationt source_location
Definition: message.h:214
std::list< std::string > warnings
Definition: c_typecast.h:64
mstreamt & error() const
Definition: message.h:302
std::list< std::string > errors
Definition: c_typecast.h:63
virtual void implicit_typecast(exprt &expr, const typet &type)
virtual void implicit_typecast_arithmetic(exprt &expr)
Definition: c_typecast.cpp:439
Base class for all expressions.
Definition: expr.h:42
virtual void implicit_typecast(exprt &expr, const typet &type)
Definition: c_typecast.cpp:445
virtual void implicit_typecast_arithmetic(exprt &expr)