Skip to content

Commit efd8e0d

Browse files
committed
Remove java_bytecode::swap and return using optionalt instead.
1 parent 1d0cd01 commit efd8e0d

File tree

6 files changed

+32
-62
lines changed

6 files changed

+32
-62
lines changed

src/java_bytecode/java_bytecode_parse_tree.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,6 @@ Author: Daniel Kroening, [email protected]
1818

1919
#include "expr2java.h"
2020

21-
void java_bytecode_parse_treet::classt::swap(
22-
classt &other)
23-
{
24-
other.name.swap(name);
25-
other.extends.swap(extends);
26-
std::swap(other.is_enum, is_enum);
27-
std::swap(other.enum_elements, enum_elements);
28-
std::swap(other.is_abstract, is_abstract);
29-
std::swap(other.is_public, is_public);
30-
std::swap(other.is_protected, is_protected);
31-
std::swap(other.is_private, is_private);
32-
std::swap(other.signature, signature);
33-
other.implements.swap(implements);
34-
other.fields.swap(fields);
35-
other.methods.swap(methods);
36-
other.annotations.swap(annotations);
37-
std::swap(
38-
other.attribute_bootstrapmethods_read, attribute_bootstrapmethods_read);
39-
std::swap(other.lambda_method_handle_map, lambda_method_handle_map);
40-
}
4121

4222
void java_bytecode_parse_treet::output(std::ostream &out) const
4323
{

src/java_bytecode/java_bytecode_parse_tree.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,17 +260,10 @@ class java_bytecode_parse_treet
260260

261261
void output(std::ostream &out) const;
262262

263-
void swap(classt &other);
264263
};
265264

266265
classt parsed_class;
267266

268-
void swap(java_bytecode_parse_treet &other)
269-
{
270-
other.parsed_class.swap(parsed_class);
271-
other.class_refs.swap(class_refs);
272-
std::swap(loading_successful, other.loading_successful);
273-
}
274267

275268
void output(std::ostream &out) const;
276269

src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,9 +1687,8 @@ void java_bytecode_parsert::rmethod(classt &parsed_class)
16871687
rmethod_attribute(method);
16881688
}
16891689

1690-
bool java_bytecode_parse(
1690+
optionalt<class java_bytecode_parse_treet> java_bytecode_parse(
16911691
std::istream &istream,
1692-
java_bytecode_parse_treet &parse_tree,
16931692
message_handlert &message_handler)
16941693
{
16951694
java_bytecode_parsert java_bytecode_parser;
@@ -1698,14 +1697,16 @@ bool java_bytecode_parse(
16981697

16991698
bool parser_result=java_bytecode_parser.parse();
17001699

1701-
parse_tree.swap(java_bytecode_parser.parse_tree);
1700+
if(parser_result)
1701+
{
1702+
return {};
1703+
}
17021704

1703-
return parser_result;
1705+
return java_bytecode_parser.parse_tree;
17041706
}
17051707

1706-
bool java_bytecode_parse(
1708+
optionalt<class java_bytecode_parse_treet> java_bytecode_parse(
17071709
const std::string &file,
1708-
java_bytecode_parse_treet &parse_tree,
17091710
message_handlert &message_handler)
17101711
{
17111712
std::ifstream in(file, std::ios::binary);
@@ -1715,10 +1716,10 @@ bool java_bytecode_parse(
17151716
messaget message(message_handler);
17161717
message.error() << "failed to open input file `"
17171718
<< file << '\'' << messaget::eom;
1718-
return true;
1719+
return {};
17191720
}
17201721

1721-
return java_bytecode_parse(in, parse_tree, message_handler);
1722+
return java_bytecode_parse(in, message_handler);
17221723
}
17231724

17241725
/// Parses the local variable type table of a method. The LVTT holds generic

src/java_bytecode/java_bytecode_parser.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ Author: Daniel Kroening, [email protected]
1212

1313
#include <iosfwd>
1414
#include <string>
15+
#include <util/optional.h>
1516

16-
bool java_bytecode_parse(
17+
optionalt<class java_bytecode_parse_treet> java_bytecode_parse(
1718
const std::string &file,
18-
class java_bytecode_parse_treet &,
1919
class message_handlert &);
2020

21-
bool java_bytecode_parse(
21+
optionalt<class java_bytecode_parse_treet> java_bytecode_parse(
2222
std::istream &,
23-
class java_bytecode_parse_treet &,
2423
class message_handlert &);
2524

2625
#endif // CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_PARSER_H

src/java_bytecode/java_class_loader.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,8 @@ optionalt<java_bytecode_parse_treet> java_class_loadert::get_class_from_jar(
9797
if(!data.has_value())
9898
return {};
9999

100-
java_bytecode_parse_treet parse_tree;
101100
std::istringstream istream(*data);
102-
if(java_bytecode_parse(istream, parse_tree, get_message_handler()))
103-
return {};
104-
return parse_tree;
101+
return java_bytecode_parse(istream, get_message_handler());
105102
}
106103

107104
static bool is_overlay_class(const java_bytecode_parse_treet::classt &c)
@@ -192,9 +189,9 @@ java_class_loadert::get_parse_tree(
192189
debug()
193190
<< "Getting class `" << class_name << "' from file " << full_path
194191
<< eom;
195-
java_bytecode_parse_treet parse_tree;
196-
if(!java_bytecode_parse(full_path, parse_tree, get_message_handler()))
197-
parse_trees.push_back(std::move(parse_tree));
192+
optionalt<java_bytecode_parse_treet> parse_tree = java_bytecode_parse(full_path, get_message_handler());
193+
if(parse_tree)
194+
parse_trees.push_back(std::move(*parse_tree));
198195
}
199196
}
200197
}

unit/java_bytecode/java_bytecode_parse_lambdas/java_bytecode_parse_lambda_method_table.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ SCENARIO(
3333
GIVEN(
3434
"A class with a static lambda variables from " + compiler + " compiler.")
3535
{
36-
java_bytecode_parse_treet parse_tree;
36+
optionalt<java_bytecode_parse_treet> parse_tree =
3737
java_bytecode_parse(
3838
"./java_bytecode/java_bytecode_parse_lambdas/lambda_examples/" +
3939
compiler + "_classes/StaticLambdas.class",
40-
parse_tree,
4140
message_handler);
4241
WHEN("Parsing that class")
4342
{
44-
REQUIRE(parse_tree.loading_successful);
43+
REQUIRE(parse_tree);
44+
REQUIRE(parse_tree->loading_successful);
4545
const java_bytecode_parse_treet::classt parsed_class =
46-
parse_tree.parsed_class;
46+
parse_tree->parsed_class;
4747
REQUIRE(parsed_class.attribute_bootstrapmethods_read);
4848
REQUIRE(parsed_class.lambda_method_handle_map.size() == 12);
4949

@@ -345,17 +345,17 @@ SCENARIO(
345345
null_message_handlert message_handler;
346346
GIVEN("A method with local lambdas from " + compiler + " compiler.")
347347
{
348-
java_bytecode_parse_treet parse_tree;
348+
optionalt<java_bytecode_parse_treet> parse_tree =
349349
java_bytecode_parse(
350350
"./java_bytecode/java_bytecode_parse_lambdas/lambda_examples/" +
351351
compiler + "_classes/LocalLambdas.class",
352-
parse_tree,
353352
message_handler);
354353
WHEN("Parsing that class")
355354
{
356-
REQUIRE(parse_tree.loading_successful);
355+
REQUIRE(parse_tree);
356+
REQUIRE(parse_tree->loading_successful);
357357
const java_bytecode_parse_treet::classt parsed_class =
358-
parse_tree.parsed_class;
358+
parse_tree->parsed_class;
359359
REQUIRE(parsed_class.attribute_bootstrapmethods_read);
360360
REQUIRE(parsed_class.lambda_method_handle_map.size() == 12);
361361

@@ -655,17 +655,17 @@ SCENARIO(
655655
"A class that has lambdas as member variables from " + compiler +
656656
" compiler.")
657657
{
658-
java_bytecode_parse_treet parse_tree;
658+
optionalt<java_bytecode_parse_treet> parse_tree =
659659
java_bytecode_parse(
660660
"./java_bytecode/java_bytecode_parse_lambdas/lambda_examples/" +
661661
compiler + "_classes/MemberLambdas.class",
662-
parse_tree,
663662
message_handler);
664663
WHEN("Parsing that class")
665664
{
666-
REQUIRE(parse_tree.loading_successful);
665+
REQUIRE(parse_tree);
666+
REQUIRE(parse_tree->loading_successful);
667667
const java_bytecode_parse_treet::classt parsed_class =
668-
parse_tree.parsed_class;
668+
parse_tree->parsed_class;
669669
REQUIRE(parsed_class.attribute_bootstrapmethods_read);
670670
REQUIRE(parsed_class.lambda_method_handle_map.size() == 12);
671671

@@ -991,17 +991,17 @@ SCENARIO(
991991
"variables from " +
992992
compiler + " compiler.")
993993
{
994-
java_bytecode_parse_treet parse_tree;
994+
optionalt<java_bytecode_parse_treet> parse_tree =
995995
java_bytecode_parse(
996996
"./java_bytecode/java_bytecode_parse_lambdas/lambda_examples/" +
997997
compiler + "_classes/OuterMemberLambdas$Inner.class",
998-
parse_tree,
999998
message_handler);
1000999
WHEN("Parsing that class")
10011000
{
1002-
REQUIRE(parse_tree.loading_successful);
1001+
REQUIRE(parse_tree);
1002+
REQUIRE(parse_tree->loading_successful);
10031003
const java_bytecode_parse_treet::classt parsed_class =
1004-
parse_tree.parsed_class;
1004+
parse_tree->parsed_class;
10051005
REQUIRE(parsed_class.attribute_bootstrapmethods_read);
10061006
REQUIRE(parsed_class.lambda_method_handle_map.size() == 3);
10071007

0 commit comments

Comments
 (0)