CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
java_bytecode_parse_tree.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
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
19void java_bytecode_parse_treet::output(std::ostream &out) const
20{
22
23 out << "Class references:\n";
24 for(const auto &class_ref : class_refs)
25 out << " " << class_ref << '\n';
26}
27
28void 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
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 << ", ";
72 }
73
74 out << ')';
75 }
76}
77
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
94std::optional<java_bytecode_parse_treet::annotationt>
96 const annotationst &annotations,
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
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
195void 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}
struct bytecode_infot const bytecode_info[]
virtual void output(const namespacet &ns, const irep_idt &function_id, const goto_programt &goto_program, std::ostream &out) const
Output the abstract states for a single function.
Definition ai.cpp:39
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
bool empty() const
Definition dstring.h:89
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
The symbol table.
std::string type2java(const typet &type, const namespacet &ns)
std::string expr2java(const exprt &expr, const namespacet &ns)
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
std::vector< annotationt > annotationst
static std::optional< annotationt > find_annotation(const annotationst &annotations, const irep_idt &annotation_type_name)
Find an annotation given its name.
void output(std::ostream &out) const
Author: Diffblue Ltd.