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(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() << "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 
51 {
52  c_typecastt c_typecast(*this);
53  c_typecast.implicit_typecast_arithmetic(expr);
54 }
c_typecheck_baset::implicit_typecast_arithmetic
virtual void implicit_typecast_arithmetic(exprt &expr)
Definition: c_typecheck_typecast.cpp:50
c_typecastt
Definition: c_typecast.h:42
typet
The type of an expression, extends irept.
Definition: type.h:29
c_typecheck_base.h
ANSI-C Language Type Checking.
c_typecheck_baset::to_string
virtual std::string to_string(const exprt &expr)
Definition: c_typecheck_base.cpp:24
exprt
Base class for all expressions.
Definition: expr.h:53
messaget::eom
static eomt eom
Definition: message.h:297
exprt::type
typet & type()
Return the type of the expression.
Definition: expr.h:81
c_typecastt::warnings
std::list< std::string > warnings
Definition: c_typecast.h:64
messaget::error
mstreamt & error() const
Definition: message.h:399
messaget::mstreamt::source_location
source_locationt source_location
Definition: message.h:247
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:231
c_typecastt::implicit_typecast_arithmetic
virtual void implicit_typecast_arithmetic(exprt &expr)
Definition: c_typecast.cpp:470
c_typecast.h
c_typecastt::errors
std::list< std::string > errors
Definition: c_typecast.h:63
c_typecastt::implicit_typecast
virtual void implicit_typecast(exprt &expr, const typet &type)
Definition: c_typecast.cpp:476
messaget::warning
mstreamt & warning() const
Definition: message.h:404
c_typecheck_baset::implicit_typecast
virtual void implicit_typecast(exprt &expr, const typet &type)
Definition: c_typecheck_typecast.cpp:13