CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
smt2_parser.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9#ifndef CPROVER_SOLVERS_SMT2_SMT2_PARSER_H
10#define CPROVER_SOLVERS_SMT2_SMT2_PARSER_H
11
12#include <map>
13#include <unordered_map>
14
16#include <util/std_expr.h>
17
18#include "smt2_tokenizer.h"
19
21{
22public:
23 explicit smt2_parsert(std::istream &_in)
25 {
29 }
30
31 void parse()
32 {
34 }
35
36 struct idt
37 {
38 using kindt = enum { VARIABLE, BINDING, PARAMETER };
39
40 idt(kindt _kind, const exprt &expr)
41 : kind(_kind), type(expr.type()), definition(expr)
42 {
43 }
44
49
52
53 // this is a lambda when the symbol is a function
55 };
56
57 using id_mapt=std::map<irep_idt, idt>;
59
72
73 using named_termst = std::map<irep_idt, named_termt>;
75
76 bool exit;
77
78 smt2_tokenizert::smt2_errort error(const std::string &message) const
79 {
80 return smt2_tokenizer.error(message);
81 }
82
87
90
91protected:
93 // we extend next_token to track the parenthesis level
94 std::size_t parenthesis_level;
96
97 // add the given identifier to the id_map but
98 // complain if that identifier is used already
100
102 {
104 std::vector<irep_idt> parameters;
105
106 explicit signature_with_parameter_idst(const typet &_type) : type(_type)
107 {
108 }
109
111 const typet &_type,
112 const std::vector<irep_idt> &_parameters)
113 : type(_type), parameters(_parameters)
114 {
116 (_type.id() == ID_mathematical_function &&
117 to_mathematical_function_type(_type).domain().size() ==
118 _parameters.size()) ||
119 (_type.id() != ID_mathematical_function && _parameters.empty()));
120 }
121
122 // a convenience helper for iterating over identifiers and types
123 std::vector<std::pair<irep_idt, typet>> ids_and_types() const
124 {
125 if(parameters.empty())
126 return {};
127 else
128 {
129 std::vector<std::pair<irep_idt, typet>> result;
130 result.reserve(parameters.size());
131 const auto &domain = to_mathematical_function_type(type).domain();
132 for(std::size_t i = 0; i < parameters.size(); i++)
133 result.emplace_back(parameters[i], domain[i]);
134 return result;
135 }
136 }
137
138 // convenience helper for constructing a binding
140 {
142 for(auto &pair : ids_and_types())
143 result.emplace_back(pair.first, pair.second);
144 return result;
145 }
146 };
147
148 // expressions
149 std::unordered_map<std::string, std::function<exprt()>> expressions;
150 void setup_expressions();
154 const irep_idt &,
155 const exprt::operandst &);
167 exprt bv_mod(const exprt::operandst &, bool is_signed);
168
169 std::pair<binding_exprt::variablest, exprt> binding(irep_idt);
174 const symbol_exprt &function,
175 const exprt::operandst &op);
176
179
182
183 // sorts
184 typet sort();
186 std::unordered_map<std::string, std::function<typet()>> sorts;
187 void setup_sorts();
188
189 // hashtable for all commands
190 std::unordered_map<std::string, std::function<void()>> commands;
191
192 void command_sequence();
193 void command(const std::string &);
194 void ignore_command();
195 void setup_commands();
196};
197
198#endif // CPROVER_SOLVERS_SMT2_SMT2_PARSER_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
std::vector< symbol_exprt > variablest
Definition std_expr.h:3236
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
Base class for all expressions.
Definition expr.h:56
std::vector< exprt > operandst
Definition expr.h:58
const irep_idt & id() const
Definition irep.h:388
The NIL expression.
Definition std_expr.h:3208
exprt function_application_ieee_float_op(const irep_idt &, const exprt::operandst &)
std::size_t parenthesis_level
Definition smt2_parser.h:94
void command(const std::string &)
std::map< irep_idt, named_termt > named_termst
Definition smt2_parser.h:73
exprt::operandst operands()
void command_sequence()
exprt bv_mod(const exprt::operandst &, bool is_signed)
exprt binary(irep_idt, const exprt::operandst &)
exprt bv_division(const exprt::operandst &, bool is_signed)
void skip_to_end_of_list()
This skips tokens until all bracketed expressions are closed.
std::unordered_map< std::string, std::function< exprt()> > expressions
smt2_parsert(std::istream &_in)
Definition smt2_parser.h:23
exprt lambda_expression()
typet function_signature_declaration()
named_termst named_terms
Definition smt2_parser.h:74
id_mapt id_map
Definition smt2_parser.h:58
std::unordered_map< std::string, std::function< void()> > commands
smt2_tokenizert::smt2_errort error(const std::string &message) const
Definition smt2_parser.h:78
exprt function_application()
void add_unique_id(irep_idt, exprt)
exprt cast_bv_to_unsigned(const exprt &)
Apply typecast to unsignedbv to given expression.
exprt::operandst cast_bv_to_signed(const exprt::operandst &)
Apply typecast to signedbv to expressions in vector.
exprt multi_ary(irep_idt, const exprt::operandst &)
std::map< irep_idt, idt > id_mapt
Definition smt2_parser.h:57
void ignore_command()
exprt quantifier_expression(irep_idt)
std::pair< binding_exprt::variablest, exprt > binding(irep_idt)
exprt function_application_ieee_float_eq(const exprt::operandst &)
exprt let_expression()
void check_matching_operand_types(const exprt::operandst &) const
signature_with_parameter_idst function_signature_definition()
exprt function_application_fp(const exprt::operandst &)
typet function_sort()
smt2_tokenizert::smt2_errort error() const
Definition smt2_parser.h:83
void setup_expressions()
exprt binary_predicate(irep_idt, const exprt::operandst &)
smt2_tokenizert::tokent next_token()
std::unordered_map< std::string, std::function< typet()> > sorts
smt2_tokenizert smt2_tokenizer
Definition smt2_parser.h:92
exprt unary(irep_idt, const exprt::operandst &)
void setup_commands()
smt2_errort error(const std::string &message) const
generate an error exception, pre-filled with a message
Expression to hold a symbol (variable)
Definition std_expr.h:131
The type of an expression, extends irept.
Definition type.h:29
Mathematical types.
const mathematical_function_typet & to_mathematical_function_type(const typet &type)
Cast a typet to a mathematical_function_typet.
STL namespace.
#define PRECONDITION(CONDITION)
Definition invariant.h:463
API to expression classes.
idt(kindt _kind, typet __type)
Definition smt2_parser.h:45
idt(kindt _kind, const exprt &expr)
Definition smt2_parser.h:40
named_termt(const exprt &_term, const symbol_exprt &_name)
Default-constructing a symbol_exprt is deprecated, thus make sure we always construct a named_termt f...
Definition smt2_parser.h:64
std::vector< std::pair< irep_idt, typet > > ids_and_types() const
binding_exprt::variablest binding_variables() const
signature_with_parameter_idst(const typet &_type, const std::vector< irep_idt > &_parameters)
bool is_signed(const typet &t)
Convenience function – is the type signed?
Definition util.cpp:45