Skip to content

Commit 1e9afae

Browse files
Call expr/type to json via languaget
1 parent 95ea29a commit 1e9afae

25 files changed

+345
-118
lines changed

src/analyses/dependence_graph.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ jsont dep_graph_domaint::output_json(
272272
const namespacet &ns) const
273273
{
274274
json_arrayt graph;
275+
json_exprt json;
275276

276277
for(const auto &cd : control_deps)
277278
{

src/cbmc/bmc_cover.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ bool bmc_covert::operator()()
359359
json_result["description"] = json_stringt(goal.description);
360360

361361
if(goal.source_location.is_not_nil())
362-
json_result["sourceLocation"] = json(goal.source_location);
362+
json_result["sourceLocation"] = json(
363+
bmc.ns, goal.source_location.get_function(), goal.source_location);
363364
}
364365
json_result["totalGoals"]=json_numbert(std::to_string(goal_map.size()));
365366
json_result["goalsCovered"]=json_numbert(std::to_string(goals_covered));
@@ -384,8 +385,8 @@ bool bmc_covert::operator()()
384385
json_objectt json_input;
385386
json_input["id"]=json_stringt(id2string(step.io_id));
386387
if(step.io_args.size()==1)
387-
json_input["value"]=
388-
json(step.io_args.front(), bmc.ns, ID_unknown);
388+
json_input["value"] =
389+
json(bmc.ns, step.pc->function, step.io_args.front());
389390
json_test.push_back(json_input);
390391
}
391392
}

src/cbmc/show_vcc.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ void bmct::show_vcc_json(std::ostream &out)
9797

9898
const source_locationt &source_location=s_it->source.pc->source_location;
9999
if(source_location.is_not_nil())
100-
object["sourceLocation"]=json(source_location);
100+
object["sourceLocation"] =
101+
json(ns, s_it->source.pc->function, source_location);
101102

102103
const std::string &s=s_it->comment;
103104
if(!s.empty())

src/goto-analyzer/static_verifier.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Author: Martin Brain, [email protected]
1111
#include <util/xml.h>
1212
#include <util/xml_expr.h>
1313
#include <util/json.h>
14-
#include <util/json_expr.h>
1514

15+
#include <langapi/language_util.h>
1616

1717
/// Runs the analyzer and then prints out the domain
1818
/// \param goto_model: the program analyzed
@@ -78,7 +78,7 @@ bool static_verifier(
7878
++unknown;
7979
}
8080

81-
j["sourceLocation"]=json(i_it->source_location);
81+
j["sourceLocation"] = json(ns, i_it->function, i_it->source_location);
8282
}
8383
}
8484
m.status() << "Writing JSON report" << messaget::eom;

src/goto-analyzer/unreachable_instructions.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ Date: April 2016
1616
#include <sstream>
1717

1818
#include <util/json.h>
19-
#include <util/json_expr.h>
2019
#include <util/file_util.h>
2120
#include <util/xml.h>
2221

22+
#include <langapi/language_util.h>
23+
2324
#include <analyses/cfg_dominators.h>
2425

2526
#include <goto-programs/goto_model.h>
@@ -157,7 +158,7 @@ static void add_to_json(
157158
// print info for file actually with full path
158159
json_objectt &i_entry=dead_ins.push_back().make_object();
159160
const source_locationt &l=it->second->source_location;
160-
i_entry["sourceLocation"]=json(l);
161+
i_entry["sourceLocation"] = json(ns, it->second->function, l);
161162
i_entry["statement"]=json_stringt(s);
162163
}
163164
}

src/goto-diff/goto_diff_base.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ Author: Peter Schrammel
1313

1414
#include <goto-programs/show_properties.h>
1515

16-
#include <util/json_expr.h>
1716
#include <util/options.h>
1817

18+
#include <langapi/language_util.h>
19+
1920
/// Output diff result
2021
void goto_difft::output_functions() const
2122
{
@@ -136,7 +137,7 @@ void goto_difft::convert_function_json(
136137
const symbolt &symbol = ns.lookup(function_name);
137138

138139
result["name"] = json_stringt(id2string(function_name));
139-
result["sourceLocation"] = json(symbol.location);
140+
result["sourceLocation"] = json(ns, function_name, symbol.location);
140141

141142
if(options.get_bool_option("show-properties"))
142143
{

src/goto-programs/json_goto_trace.cpp

+22-39
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Author: Daniel Kroening
2323
#include <util/simplify_expr.h>
2424
#include <util/json_irep.h>
2525
#include <langapi/language_util.h>
26+
#include <langapi/mode.h>
2627

2728
/// Convert an ASSERT goto_trace step.
2829
/// \param [out] json_failure: The JSON object that
@@ -123,30 +124,18 @@ void convert_decl(
123124

124125
full_lhs_string = from_expr(ns, identifier, simplified);
125126

126-
const symbolt *symbol;
127127
irep_idt base_name, display_name;
128128

129-
if(!ns.lookup(identifier, symbol))
130-
{
131-
base_name = symbol->base_name;
132-
display_name = symbol->display_name();
133-
if(type_string == "")
134-
type_string = from_type(ns, identifier, symbol->type);
135-
136-
json_assignment["mode"] = json_stringt(id2string(symbol->mode));
137-
exprt simplified = simplify_expr(step.full_lhs_value, ns);
129+
const symbolt *symbol;
130+
bool not_found = ns.lookup(identifier, symbol);
131+
CHECK_RETURN(!not_found);
132+
base_name = symbol->base_name;
133+
display_name = symbol->display_name();
138134

139-
full_lhs_value = json(simplified, ns, symbol->mode);
140-
}
141-
else
142-
{
143-
DATA_INVARIANT(
144-
step.full_lhs_value.is_not_nil(),
145-
"full_lhs_value in assignment must not be nil");
146-
full_lhs_value = json(step.full_lhs_value, ns, ID_unknown);
147-
}
135+
json_assignment["mode"] = json_stringt(id2string(symbol->mode));
148136

149-
json_assignment["value"] = full_lhs_value;
137+
const exprt value_simplified = simplify_expr(step.full_lhs_value, ns);
138+
json_assignment["value"] = json(ns, identifier, value_simplified);
150139
json_assignment["lhs"] = json_stringt(full_lhs_string);
151140
if(trace_options.json_full_lhs)
152141
{
@@ -186,20 +175,17 @@ void convert_output(
186175
json_output["outputID"] = json_stringt(id2string(step.io_id));
187176

188177
// Recovering the mode from the function
189-
irep_idt mode;
190-
const symbolt *function_name;
191-
if(ns.lookup(source_location.get_function(), function_name))
192-
// Failed to find symbol
193-
mode = ID_unknown;
194-
else
195-
mode = function_name->mode;
178+
const irep_idt mode =
179+
get_mode_from_identifier(ns, source_location.get_function());
196180
json_output["mode"] = json_stringt(id2string(mode));
197181
json_arrayt &json_values = json_output["values"].make_array();
198182

199183
for(const auto &arg : step.io_args)
200184
{
201-
arg.is_nil() ? json_values.push_back(json_stringt(""))
202-
: json_values.push_back(json(arg, ns, mode));
185+
if(arg.is_nil())
186+
json_values.push_back(json_stringt(""));
187+
else
188+
json_values.push_back(json(ns, source_location.get_function(), arg));
203189
}
204190

205191
if(!location.is_null())
@@ -229,20 +215,17 @@ void convert_input(
229215
json_input["inputID"] = json_stringt(id2string(step.io_id));
230216

231217
// Recovering the mode from the function
232-
irep_idt mode;
233-
const symbolt *function_name;
234-
if(ns.lookup(source_location.get_function(), function_name))
235-
// Failed to find symbol
236-
mode = ID_unknown;
237-
else
238-
mode = function_name->mode;
218+
const irep_idt mode =
219+
get_mode_from_identifier(ns, source_location.get_function());
239220
json_input["mode"] = json_stringt(id2string(mode));
240221
json_arrayt &json_values = json_input["values"].make_array();
241222

242223
for(const auto &arg : step.io_args)
243224
{
244-
arg.is_nil() ? json_values.push_back(json_stringt(""))
245-
: json_values.push_back(json(arg, ns, mode));
225+
if(arg.is_nil())
226+
json_values.push_back(json_stringt(""));
227+
else
228+
json_values.push_back(json(ns, source_location.get_function(), arg));
246229
}
247230

248231
if(!location.is_null())
@@ -277,7 +260,7 @@ void convert_return(
277260
json_objectt &json_function = json_call_return["function"].make_object();
278261
json_function["displayName"] = json_stringt(id2string(symbol.display_name()));
279262
json_function["identifier"] = json_stringt(id2string(step.identifier));
280-
json_function["sourceLocation"] = json(symbol.location);
263+
json_function["sourceLocation"] = json(ns, step.identifier, symbol.location);
281264

282265
if(!location.is_null())
283266
json_call_return["sourceLocation"] = location;

src/goto-programs/json_goto_trace.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Date: November 2005
2121
#include <util/json_expr.h>
2222
#include <util/invariant.h>
2323

24+
#include <langapi/mode.h>
25+
#include <langapi/language_util.h>
26+
2427
/// This is structure is here to facilitate
2528
/// passing arguments to the conversion
2629
/// functions.
@@ -127,8 +130,10 @@ void convert(
127130

128131
jsont json_location;
129132

130-
source_location.is_not_nil() && !source_location.get_file().empty()
131-
? json_location = json(source_location)
133+
source_location.is_not_nil() && !source_location.get_file().empty() &&
134+
!source_location.get_function().empty()
135+
? json_location =
136+
json(ns, source_location.get_function(), source_location)
132137
: json_location = json_nullt();
133138

134139
// NOLINTNEXTLINE(whitespace/braces)

src/goto-programs/loop_ids.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void show_loop_ids_json(
8787

8888
json_objectt &loop=loops.push_back().make_object();
8989
loop["name"]=json_stringt(id);
90-
loop["sourceLocation"]=json(it->source_location);
90+
loop["sourceLocation"] = json_exprt()(it->source_location);
9191
}
9292
}
9393
}
@@ -110,6 +110,7 @@ void show_loop_ids(
110110
forall_goto_functions(it, goto_functions)
111111
show_loop_ids_json(ui, it->second.body, loops);
112112

113+
// TODO: this needs clean up
113114
std::cout << ",\n" << json_result;
114115
break;
115116
}

src/goto-programs/show_goto_functions_json.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ json_objectt show_goto_functions_jsont::convert(
7575

7676
if(instruction.code.source_location().is_not_nil())
7777
{
78-
instruction_entry["sourceLocation"]=
79-
json(instruction.code.source_location());
78+
instruction_entry["sourceLocation"] =
79+
json(ns, instruction.function, instruction.code.source_location());
8080
}
8181

8282
std::ostringstream instruction_builder;

src/goto-programs/show_properties.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void convert_properties_json(
137137
json_property["coveredLines"]=
138138
json_stringt(
139139
id2string(source_location.get_basic_block_covered_lines()));
140-
json_property["sourceLocation"]=json(source_location);
140+
json_property["sourceLocation"] = json(ns, identifier, source_location);
141141
json_property["description"]=json_stringt(id2string(description));
142142
json_property["expression"]=
143143
json_stringt(from_expr(ns, identifier, ins.guard));

src/java_bytecode/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ SRC = bytecode_info.cpp \
2020
java_class_loader_limit.cpp \
2121
java_enum_static_init_unwind_handler.cpp \
2222
java_entry_point.cpp \
23+
java_json_expr.cpp \
2324
java_local_variable_table.cpp \
2425
java_object_factory.cpp \
2526
java_pointer_casts.cpp \

src/java_bytecode/java_bytecode_language.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Author: Daniel Kroening, [email protected]
3434
#include "java_static_initializers.h"
3535
#include "java_utils.h"
3636
#include <java_bytecode/ci_lazy_methods.h>
37+
#include "java_json_expr.h"
3738

3839
#include "expr2java.h"
3940

@@ -1087,6 +1088,24 @@ bool java_bytecode_languaget::to_expr(
10871088
return true; // fail for now
10881089
}
10891090

1091+
json_objectt
1092+
java_bytecode_languaget::json(const exprt &expr, const namespacet &ns)
1093+
{
1094+
return java_json_exprt()(expr, ns);
1095+
}
1096+
1097+
json_objectt
1098+
java_bytecode_languaget::json(const typet &type, const namespacet &ns)
1099+
{
1100+
return java_json_exprt()(type, ns);
1101+
}
1102+
1103+
json_objectt
1104+
java_bytecode_languaget::json(const source_locationt &source_location)
1105+
{
1106+
return java_json_exprt()(source_location);
1107+
}
1108+
10901109
java_bytecode_languaget::~java_bytecode_languaget()
10911110
{
10921111
}

src/java_bytecode/java_bytecode_language.h

+6
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ class java_bytecode_languaget:public languaget
127127
exprt &expr,
128128
const namespacet &ns) override;
129129

130+
json_objectt json(const exprt &, const namespacet &) override;
131+
132+
json_objectt json(const typet &, const namespacet &) override;
133+
134+
json_objectt json(const source_locationt &) override;
135+
130136
std::unique_ptr<languaget> new_language() override
131137
{ return util_make_unique<java_bytecode_languaget>(); }
132138

src/java_bytecode/java_json_expr.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*******************************************************************\
2+
3+
Module: Expressions in JSON for Java
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Expressions in JSON for Java
11+
12+
#include "java_json_expr.h"
13+
14+
#include <util/std_expr.h>
15+
16+
#include <langapi/language.h>
17+
18+
/// Output a Java source location in json.
19+
/// \param location: a source location
20+
/// \return a json object
21+
json_objectt java_json_exprt::operator()(const source_locationt &location)
22+
{
23+
json_objectt result = json_exprt()(location);
24+
25+
if(!location.get_java_bytecode_index().empty())
26+
result["bytecodeIndex"] =
27+
json_stringt(id2string(location.get_java_bytecode_index()));
28+
29+
return result;
30+
}
31+
32+
/// Output a Java constant expression as a string.
33+
/// \param ns: a namespace
34+
/// \param expr: a constant expression
35+
/// \return a string
36+
std::string
37+
java_json_exprt::from_constant(const namespacet &ns, const constant_exprt &expr)
38+
{
39+
std::string result;
40+
language->from_expr(expr, result, ns);
41+
return result;
42+
}
43+
44+
/// Output a Java type as a string.
45+
/// \param ns: a namespace
46+
/// \param type: an type
47+
/// \return a string
48+
std::string java_json_exprt::from_type(const namespacet &ns, const typet &type)
49+
{
50+
std::string result;
51+
language->from_type(type, result, ns);
52+
return result;
53+
}

0 commit comments

Comments
 (0)