cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
java_bytecode_parse_tree.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 "
java_bytecode_parse_tree.h
"
10
11
#include <algorithm>
12
#include <ostream>
13
14
#include <
util/symbol_table.h
>
15
#include <
util/namespace.h
>
16
17
#include "
expr2java.h
"
18
19
void
java_bytecode_parse_treet::output
(std::ostream &out)
const
20
{
21
parsed_class
.output(out);
22
23
out <<
"Class references:\n"
;
24
for
(
const
auto
&class_ref :
class_refs
)
25
out <<
" "
<< class_ref <<
'\n'
;
26
}
27
28
void
java_bytecode_parse_treet::classt::output
(std::ostream &out)
const
29
{
30
for
(
const
auto
&annotation :
annotations
)
31
{
32
annotation.output(out);
33
out <<
'\n'
;
34
}
35
36
out <<
"class "
<<
name
;
37
if
(!
super_class
.empty())
38
out <<
" extends "
<<
super_class
;
39
out <<
" {"
<<
'\n'
;
40
41
for
(
const
auto
&field :
fields
)
42
field.output(out);
43
44
out <<
'\n'
;
45
46
for
(
const
auto
&method :
methods
)
47
method.output(out);
48
49
out <<
'}'
<<
'\n'
;
50
out <<
'\n'
;
51
}
52
53
void
java_bytecode_parse_treet::annotationt::output
(std::ostream &out)
const
54
{
55
symbol_tablet
symbol_table;
56
namespacet
ns(symbol_table);
57
58
out <<
'@'
<<
type2java
(
type
, ns);
59
60
if
(!
element_value_pairs
.empty())
61
{
62
out <<
'('
;
63
64
bool
first=
true
;
65
for
(
const
auto
&element_value_pair :
element_value_pairs
)
66
{
67
if
(first)
68
first=
false
;
69
else
70
out <<
", "
;
71
element_value_pair.output(out);
72
}
73
74
out <<
')'
;
75
}
76
}
77
78
void
java_bytecode_parse_treet::annotationt::element_value_pairt::output
(
79
std::ostream &out)
const
80
{
81
symbol_tablet
symbol_table;
82
namespacet
ns(symbol_table);
83
84
out <<
'"'
<<
element_name
<<
'"'
<<
'='
;
85
out <<
expr2java
(
value
, ns);
86
}
87
94
std::optional<java_bytecode_parse_treet::annotationt>
95
java_bytecode_parse_treet::find_annotation
(
96
const
annotationst
&annotations,
97
const
irep_idt
&annotation_type_name)
98
{
99
const
auto
annotation_it = std::find_if(
100
annotations.begin(),
101
annotations.end(),
102
[&annotation_type_name](
const
annotationt
&annotation) {
103
if(annotation.type.id() != ID_pointer)
104
return false;
105
const typet &type = to_pointer_type(annotation.type).base_type();
106
return type.id() == ID_struct_tag &&
107
to_struct_tag_type(type).get_identifier() == annotation_type_name;
108
});
109
if
(annotation_it == annotations.end())
110
return
{};
111
return
*annotation_it;
112
}
113
114
void
java_bytecode_parse_treet::methodt::output
(std::ostream &out)
const
115
{
116
symbol_tablet
symbol_table;
117
namespacet
ns(symbol_table);
118
119
for
(
const
auto
&annotation :
annotations
)
120
{
121
out <<
" "
;
122
annotation.output(out);
123
out <<
'\n'
;
124
}
125
126
out <<
" "
;
127
128
if
(
is_public
)
129
out <<
"public "
;
130
131
if
(
is_protected
)
132
out <<
"protected "
;
133
134
if
(
is_private
)
135
out <<
"private "
;
136
137
if
(
is_static
)
138
out <<
"static "
;
139
140
if
(
is_final
)
141
out <<
"final "
;
142
143
if
(
is_native
)
144
out <<
"native "
;
145
146
if
(
is_synchronized
)
147
out <<
"synchronized "
;
148
149
out <<
name
;
150
out <<
" : "
<<
descriptor
;
151
152
out <<
'\n'
;
153
154
out <<
" {"
<<
'\n'
;
155
156
for
(
const
auto
&i :
instructions
)
157
{
158
if
(!i.source_location.get_line().empty())
159
out <<
" // "
<< i.source_location <<
'\n'
;
160
161
out <<
" "
<< i.address <<
": "
;
162
out <<
bytecode_info
[i.bytecode].mnemonic;
163
164
bool
first =
true
;
165
for
(
const
auto
&arg : i.args)
166
{
167
if
(first)
168
first =
false
;
169
else
170
out <<
','
;
171
#if 0
172
out <<
' '
<<
from_expr
(arg);
173
#else
174
out <<
' '
<<
expr2java
(arg, ns);
175
#endif
176
}
177
178
out <<
'\n'
;
179
}
180
181
out <<
" }"
<<
'\n'
;
182
183
out <<
'\n'
;
184
185
out <<
" Locals:\n"
;
186
for
(
const
auto
&v :
local_variable_table
)
187
{
188
out <<
" "
<< v.index <<
": "
<< v.name <<
' '
189
<< v.descriptor <<
'\n'
;
190
}
191
192
out <<
'\n'
;
193
}
194
195
void
java_bytecode_parse_treet::fieldt::output
(std::ostream &out)
const
196
{
197
for
(
const
auto
&annotation :
annotations
)
198
{
199
out <<
" "
;
200
annotation.output(out);
201
out <<
'\n'
;
202
}
203
204
out <<
" "
;
205
206
if
(
is_public
)
207
out <<
"public "
;
208
209
if
(
is_static
)
210
out <<
"static "
;
211
212
out <<
name
;
213
out <<
" : "
<<
descriptor
<<
';'
;
214
215
out <<
'\n'
;
216
}
bytecode_info
struct bytecode_infot const bytecode_info[]
Definition
bytecode_info.cpp:16
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition
namespace.h:91
symbol_tablet
The symbol table.
Definition
symbol_table.h:14
type2java
std::string type2java(const typet &type, const namespacet &ns)
Definition
expr2java.cpp:461
expr2java
std::string expr2java(const exprt &expr, const namespacet &ns)
Definition
expr2java.cpp:454
expr2java.h
java_bytecode_parse_tree.h
from_expr
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
Definition
language_util.cpp:39
namespace.h
java_bytecode_parse_treet::annotationt::element_value_pairt::output
void output(std::ostream &) const
Definition
java_bytecode_parse_tree.cpp:78
java_bytecode_parse_treet::annotationt::element_value_pairt::value
exprt value
Definition
java_bytecode_parse_tree.h:39
java_bytecode_parse_treet::annotationt::element_value_pairt::element_name
irep_idt element_name
Definition
java_bytecode_parse_tree.h:38
java_bytecode_parse_treet::annotationt
Definition
java_bytecode_parse_tree.h:33
java_bytecode_parse_treet::annotationt::type
typet type
Definition
java_bytecode_parse_tree.h:34
java_bytecode_parse_treet::annotationt::output
void output(std::ostream &) const
Definition
java_bytecode_parse_tree.cpp:53
java_bytecode_parse_treet::annotationt::element_value_pairs
element_value_pairst element_value_pairs
Definition
java_bytecode_parse_tree.h:44
java_bytecode_parse_treet::classt::methods
methodst methods
Definition
java_bytecode_parse_tree.h:280
java_bytecode_parse_treet::classt::output
void output(std::ostream &out) const
Definition
java_bytecode_parse_tree.cpp:28
java_bytecode_parse_treet::classt::name
irep_idt name
Definition
java_bytecode_parse_tree.h:212
java_bytecode_parse_treet::classt::annotations
annotationst annotations
Definition
java_bytecode_parse_tree.h:281
java_bytecode_parse_treet::classt::fields
fieldst fields
Definition
java_bytecode_parse_tree.h:279
java_bytecode_parse_treet::classt::super_class
irep_idt super_class
Definition
java_bytecode_parse_tree.h:212
java_bytecode_parse_treet::fieldt::output
void output(std::ostream &out) const
Definition
java_bytecode_parse_tree.cpp:195
java_bytecode_parse_treet::membert::annotations
annotationst annotations
Definition
java_bytecode_parse_tree.h:70
java_bytecode_parse_treet::membert::descriptor
std::string descriptor
Definition
java_bytecode_parse_tree.h:66
java_bytecode_parse_treet::membert::is_final
bool is_final
Definition
java_bytecode_parse_tree.h:69
java_bytecode_parse_treet::membert::is_static
bool is_static
Definition
java_bytecode_parse_tree.h:69
java_bytecode_parse_treet::membert::name
irep_idt name
Definition
java_bytecode_parse_tree.h:68
java_bytecode_parse_treet::membert::is_public
bool is_public
Definition
java_bytecode_parse_tree.h:69
java_bytecode_parse_treet::membert::is_private
bool is_private
Definition
java_bytecode_parse_tree.h:69
java_bytecode_parse_treet::membert::is_protected
bool is_protected
Definition
java_bytecode_parse_tree.h:69
java_bytecode_parse_treet::methodt::instructions
instructionst instructions
Definition
java_bytecode_parse_tree.h:92
java_bytecode_parse_treet::methodt::output
void output(std::ostream &out) const
Definition
java_bytecode_parse_tree.cpp:114
java_bytecode_parse_treet::methodt::local_variable_table
local_variable_tablet local_variable_table
Definition
java_bytecode_parse_tree.h:137
java_bytecode_parse_treet::methodt::is_native
bool is_native
Definition
java_bytecode_parse_tree.h:87
java_bytecode_parse_treet::methodt::is_synchronized
bool is_synchronized
Definition
java_bytecode_parse_tree.h:87
java_bytecode_parse_treet::annotationst
std::vector< annotationt > annotationst
Definition
java_bytecode_parse_tree.h:49
java_bytecode_parse_treet::find_annotation
static std::optional< annotationt > find_annotation(const annotationst &annotations, const irep_idt &annotation_type_name)
Find an annotation given its name.
Definition
java_bytecode_parse_tree.cpp:95
java_bytecode_parse_treet::parsed_class
classt parsed_class
Definition
java_bytecode_parse_tree.h:310
java_bytecode_parse_treet::output
void output(std::ostream &out) const
Definition
java_bytecode_parse_tree.cpp:19
java_bytecode_parse_treet::class_refs
class_refst class_refs
Definition
java_bytecode_parse_tree.h:316
symbol_table.h
Author: Diffblue Ltd.
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
jbmc
src
java_bytecode
java_bytecode_parse_tree.cpp
Generated by
1.17.0