cprover
require_parse_tree.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3  Module: Unit test utilities
4 
5  Author: Diffblue Ltd.
6 
7 \*******************************************************************/
8 
9 #include "require_parse_tree.h"
10 
11 #include <iterator>
12 
23  const java_bytecode_parse_treet::classt &parsed_class,
24  const std::string &lambda_method_ref,
25  const std::string &method_type)
26 {
27  typedef java_bytecode_parse_treet::classt::lambda_method_handle_mapt::
28  value_type lambda_method_entryt;
29 
30  INFO(
31  "Looking for entry with lambda_method_ref: " << lambda_method_ref
32  << " and method_type: "
33  << method_type);
34  std::vector<lambda_method_entryt> matches;
35  std::copy_if(
36  parsed_class.lambda_method_handle_map.begin(),
37  parsed_class.lambda_method_handle_map.end(),
38  back_inserter(matches),
39  [&method_type,
40  &lambda_method_ref](const lambda_method_entryt &entry) { //NOLINT
41  return (
42  entry.second.method_type == method_type &&
43  entry.second.lambda_method_ref == lambda_method_ref);
44  });
45  REQUIRE(matches.size() == 1);
46  return matches.at(0).second;
47 }
48 
54  const java_bytecode_parse_treet::classt &parsed_class,
55  const irep_idt &method_name)
56 {
57  const auto method = std::find_if(
58  parsed_class.methods.begin(),
59  parsed_class.methods.end(),
60  [&method_name](const java_bytecode_parse_treet::methodt &method) {
61  return method.name == method_name;
62  });
63 
64  INFO("Looking for method: " << method_name);
65  std::ostringstream found_methods;
66  for(const auto entry : parsed_class.methods)
67  {
68  found_methods << id2string(entry.name) << std::endl;
69  }
70  INFO("Found methods:\n" << found_methods.str());
71 
72  REQUIRE(method != parsed_class.methods.end());
73 
74  return *method;
75 }
76 
81  const expected_instructionst &expected_instructions,
83 {
84  REQUIRE(instructions.size() == expected_instructions.size());
85  auto actual_instruction_it = instructions.begin();
86  for(const auto expected_instruction : expected_instructions)
87  {
88  expected_instruction.require_instructions_equal(*actual_instruction_it);
89  ++actual_instruction_it;
90  }
91 }
92 
96  java_bytecode_parse_treet::instructiont actual_instruction) const
97 {
98  REQUIRE(actual_instruction.statement == instruction_mnemoic);
99  REQUIRE(actual_instruction.args.size() == instruction_arguments.size());
100  auto actual_arg_it = actual_instruction.args.begin();
101  for(const exprt &expected_arg : actual_instruction.args)
102  {
103  INFO("Expected argument" << expected_arg.pretty());
104  INFO("Actual argument" << actual_arg_it->pretty());
105  REQUIRE(*actual_arg_it == expected_arg);
106  ++actual_arg_it;
107  }
108 }
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
Definition: irep.cpp:640
void require_instructions_equal(java_bytecode_parse_treet::instructiont actual_instruction) const
Check whether a given instruction matches an expectation of the instruction.
std::vector< instructiont > instructionst
const methodt require_method(const java_bytecode_parse_treet::classt &parsed_class, const irep_idt &method_name)
Finds a specific method in the parsed class with a matching name.
void require_instructions_match_expectation(const expected_instructionst &expected_instructions, const java_bytecode_parse_treet::methodt::instructionst instructions)
Verify whether a given methods instructions match an expectation.
lambda_method_handlet require_lambda_entry_for_descriptor(const java_bytecode_parse_treet::classt &parsed_class, const std::string &lambda_method_ref, const std::string &method_type)
Find in the parsed class a specific entry within the lambda_method_handle_map with a matching descrip...
std::vector< expected_instructiont > expected_instructionst
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Definition: dstring.h:35
lambda_method_handle_mapt lambda_method_handle_map
Base class for all expressions.
Definition: expr.h:54
Utilties for inspecting java_parse_treet.