cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
smt2irep.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 "
smt2irep.h
"
10
11
#include <
util/message.h
>
12
13
#include <stack>
14
15
#include "
smt2_tokenizer.h
"
16
17
class
smt2irept
:
public
smt2_tokenizert
18
{
19
public
:
20
smt2irept
(std::istream &_in,
message_handlert
&message_handler)
21
:
smt2_tokenizert
(_in),
log
(message_handler)
22
{
23
}
24
25
std::optional<irept>
operator()
();
26
27
protected
:
28
messaget
log
;
29
};
30
31
std::optional<irept>
smt2irept::operator()
()
32
{
33
try
34
{
35
std::stack<irept> stack;
36
37
while
(
true
)
38
{
39
switch
(
next_token
())
40
{
41
case
END_OF_FILE:
42
if
(stack.empty())
43
return
{};
44
else
45
throw
error
(
"unexpected end of file"
);
46
47
case
STRING_LITERAL:
48
case
NUMERAL:
49
case
SYMBOL:
50
if
(stack.empty())
51
return
irept
(
buffer
);
// all done!
52
else
53
stack.top().get_sub().push_back(
irept
(
buffer
));
54
break
;
55
56
case
OPEN:
// '('
57
// produce sub-irep
58
stack.push(
irept
());
59
break
;
60
61
case
CLOSE:
// ')'
62
// done with sub-irep
63
if
(stack.empty())
64
throw
error
(
"unexpected ')'"
);
65
else
66
{
67
irept
tmp = stack.top();
68
stack.pop();
69
70
if
(stack.empty())
71
return
tmp;
// all done!
72
73
stack.top().get_sub().push_back(tmp);
74
break
;
75
}
76
77
case
NONE
:
78
case
KEYWORD:
79
throw
error
(
"unexpected token"
);
80
}
81
}
82
}
83
catch
(
const
smt2_errort
&e)
84
{
85
log
.error().source_location.set_line(e.
get_line_no
());
86
log
.error() << e.
what
() <<
messaget::eom
;
87
return
{};
88
}
89
}
90
91
std::optional<irept>
92
smt2irep
(std::istream &in,
message_handlert
&message_handler)
93
{
94
return
smt2irept
(in, message_handler)();
95
}
irept
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition
irep.h:364
message_handlert
Definition
message.h:27
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition
message.h:154
messaget::eom
static eomt eom
Definition
message.h:289
smt2_tokenizert::smt2_errort
Definition
smt2_tokenizer.h:25
smt2_tokenizert::smt2_errort::get_line_no
unsigned get_line_no() const
Definition
smt2_tokenizer.h:51
smt2_tokenizert::smt2_errort::what
std::string what() const
Definition
smt2_tokenizer.h:46
smt2_tokenizert::next_token
tokent next_token()
Definition
smt2_tokenizer.cpp:201
smt2_tokenizert::smt2_tokenizert
smt2_tokenizert(std::istream &_in)
Definition
smt2_tokenizer.h:18
smt2_tokenizert::error
smt2_errort error() const
generate an error exception
Definition
smt2_tokenizer.h:108
smt2_tokenizert::buffer
std::string buffer
Definition
smt2_tokenizer.h:116
smt2irept
Definition
smt2irep.cpp:18
smt2irept::log
messaget log
Definition
smt2irep.cpp:28
smt2irept::operator()
std::optional< irept > operator()()
Definition
smt2irep.cpp:31
smt2irept::smt2irept
smt2irept(std::istream &_in, message_handlert &message_handler)
Definition
smt2irep.cpp:20
complexity_violationt::NONE
@ NONE
Definition
complexity_violation.h:19
smt2_tokenizer.h
smt2irep
std::optional< irept > smt2irep(std::istream &in, message_handlert &message_handler)
returns an irep for an SMT-LIB2 expression read from a given stream returns {} when EOF is encountere...
Definition
smt2irep.cpp:92
smt2irep.h
message.h
solvers
smt2
smt2irep.cpp
Generated by
1.17.0