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
The type of an expression, extends irept.
Definition: type.h:27
void process_char(std::ostream &out)
std::list< exprt >::const_iterator next_operand
printf_formattert(const namespacet &_ns)
std::list< exprt > operands
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:93
const namespacet & ns
Base class for all expressions.
Definition: expr.h:54
void process_format(std::ostream &out)
void print(std::ostream &out)
void operator()(const std::string &format, const std::list< exprt > &_operands)
std::string as_string()
const exprt make_type(const exprt &src, const typet &dest)