cprover
printf_formatter.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: printf Formatting
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_GOTO_PROGRAMS_PRINTF_FORMATTER_H
13 #define CPROVER_GOTO_PROGRAMS_PRINTF_FORMATTER_H
14 
15 #include <util/expr.h>
16 #include <util/namespace.h>
17 
18 #include <list>
19 
21 {
22 public:
23  void operator()(
24  const std::string &format,
25  const std::list<exprt> &_operands);
26 
27  void print(std::ostream &out);
28  std::string as_string();
29 
30  explicit printf_formattert(const namespacet &_ns):
31  ns(_ns),
32  format_pos(0)
33  {
34  }
35 
36 protected:
37  const namespacet &ns;
38  std::string format;
39  std::list<exprt> operands;
40  std::list<exprt>::const_iterator next_operand;
41  unsigned format_pos;
42  bool eol() const { return format_pos>=format.size(); }
43 
44  class eol_exceptiont { };
45 
46  char next()
47  {
48  if(eol())
49  throw eol_exceptiont();
50  return format[format_pos++];
51  }
52 
53  void process_char(std::ostream &out);
54  void process_format(std::ostream &out);
55 
56  const exprt make_type(const exprt &src, const typet &dest);
57 };
58 
59 #endif // CPROVER_GOTO_PROGRAMS_PRINTF_FORMATTER_H
printf_formattert::as_string
std::string as_string()
Definition: printf_formatter.cpp:52
printf_formattert
Definition: printf_formatter.h:21
printf_formattert::next
char next()
Definition: printf_formatter.h:46
typet
The type of an expression, extends irept.
Definition: type.h:29
exprt
Base class for all expressions.
Definition: expr.h:53
namespace.h
printf_formattert::printf_formattert
printf_formattert(const namespacet &_ns)
Definition: printf_formatter.h:30
printf_formattert::eol
bool eol() const
Definition: printf_formatter.h:42
printf_formattert::make_type
const exprt make_type(const exprt &src, const typet &dest)
Definition: printf_formatter.cpp:21
expr.h
printf_formattert::print
void print(std::ostream &out)
Definition: printf_formatter.cpp:37
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:92
printf_formattert::operator()
void operator()(const std::string &format, const std::list< exprt > &_operands)
Definition: printf_formatter.cpp:29
printf_formattert::ns
const namespacet & ns
Definition: printf_formatter.h:37
printf_formattert::operands
std::list< exprt > operands
Definition: printf_formatter.h:39
printf_formattert::format
std::string format
Definition: printf_formatter.h:38
printf_formattert::next_operand
std::list< exprt >::const_iterator next_operand
Definition: printf_formatter.h:40
printf_formattert::process_char
void process_char(std::ostream &out)
Definition: printf_formatter.cpp:182
printf_formattert::eol_exceptiont
Definition: printf_formatter.h:44
printf_formattert::format_pos
unsigned format_pos
Definition: printf_formatter.h:41
printf_formattert::process_format
void process_format(std::ostream &out)
Definition: printf_formatter.cpp:59