cprover
java_entry_point.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_entry_point.h"
10 
11 #include <util/config.h>
12 #include <util/expr_initializer.h>
14 #include <util/string_constant.h>
15 #include <util/suffix.h>
16 
19 
21 
23 #include "java_object_factory.h"
24 #include "java_string_literals.h"
25 #include "java_utils.h"
26 #include <util/fresh_symbol.h>
27 #include <util/nondet.h>
28 
29 #define JAVA_MAIN_METHOD "main:([Ljava/lang/String;)V"
30 
32  const symbolt &function,
33  const symbol_table_baset &symbol_table);
34 
36  const symbolt &function,
37  const std::vector<exprt> &arguments,
38  const symbol_table_baset &symbol_table);
39 
40 static codet record_exception(
41  const symbolt &function,
42  const symbol_table_baset &symbol_table);
43 
45 {
46  // If __CPROVER_initialize already exists, replace it. It may already exist
47  // if a GOTO binary provided it. This behaviour mirrors the ANSI-C frontend.
48  symbol_table.remove(INITIALIZE_FUNCTION);
49 
50  symbolt initialize;
51  initialize.name=INITIALIZE_FUNCTION;
52  initialize.base_name=INITIALIZE_FUNCTION;
53  initialize.mode=ID_java;
54 
55  initialize.type = java_method_typet({}, java_void_type());
56  symbol_table.add(initialize);
57 }
58 
59 static bool should_init_symbol(const symbolt &sym)
60 {
61  if(sym.type.id()!=ID_code &&
62  sym.is_lvalue &&
63  sym.is_state_var &&
64  sym.is_static_lifetime &&
65  sym.mode==ID_java)
66  {
67  // Consider some sort of annotation indicating a global variable that
68  // doesn't require initialisation?
69  return !sym.type.get_bool(ID_C_no_initialization_required);
70  }
71 
72  return is_java_string_literal_id(sym.name);
73 }
74 
76 {
77  static irep_idt signature =
78  "java::java.lang.Class.cproverInitializeClassLiteral:"
79  "(Ljava/lang/String;ZZZZZZZ)V";
80  return signature;
81 }
82 
89  const symbolt &symbol,
90  const symbol_table_baset &symbol_table)
91 {
92  if(symbol.value.is_not_nil())
93  return nullptr;
94  if(symbol.type != struct_tag_typet("java::java.lang.Class"))
95  return nullptr;
97  return nullptr;
99 }
100 
102 {
103  return from_integer(val ? 1 : 0, java_boolean_type());
104 }
105 
107  symbol_table_baset &symbol_table,
108  const source_locationt &source_location,
109  bool assume_init_pointers_not_null,
110  java_object_factory_parameterst object_factory_parameters,
111  const select_pointer_typet &pointer_type_selector,
112  bool string_refinement_enabled,
113  message_handlert &message_handler)
114 {
115  symbolt &initialize_symbol =
117  PRECONDITION(initialize_symbol.value.is_nil());
118  code_blockt code_block;
119 
120  const symbol_exprt rounding_mode =
121  symbol_table.lookup_ref(CPROVER_PREFIX "rounding_mode").symbol_expr();
122  code_block.add(
123  code_assignt{rounding_mode, from_integer(0, rounding_mode.type())});
124 
125  object_factory_parameters.function_id = initialize_symbol.name;
126 
127  // If there are strings given using --string-input-value, we need to add
128  // them to the symbol table now, so that they appear in __CPROVER_initialize
129  // and we can refer to them later when we initialize input values.
130  for(const auto &val : object_factory_parameters.string_input_values)
131  {
132  // We ignore the return value of the following call, we just need to
133  // make sure the string is in the symbol table.
135  val, symbol_table, string_refinement_enabled);
136  }
137 
138  // We need to zero out all static variables, or nondet-initialize if they're
139  // external. Iterate over a copy of the symtab, as its iterators are
140  // invalidated by object_factory:
141 
142  std::list<irep_idt> symbol_names;
143  for(const auto &entry : symbol_table.symbols)
144  symbol_names.push_back(entry.first);
145 
146  // Don't use a for-each loop here because the loop extends the list, and the
147  // for-each loop may only read `.end()` once.
148  for(
149  auto symbol_it = symbol_names.begin();
150  symbol_it != symbol_names.end();
151  ++symbol_it)
152  {
153  const auto &symname = *symbol_it;
154  const symbolt &sym = symbol_table.lookup_ref(symname);
155  if(should_init_symbol(sym))
156  {
157  if(const symbolt *class_literal_init_method =
158  get_class_literal_initializer(sym, symbol_table))
159  {
160  const std::string &name_str = id2string(sym.name);
161  irep_idt class_name =
162  name_str.substr(0, name_str.size() - strlen(JAVA_CLASS_MODEL_SUFFIX));
163  const symbolt &class_symbol = symbol_table.lookup_ref(class_name);
164 
165  bool class_is_array = is_java_array_tag(sym.name);
166 
167  journalling_symbol_tablet journalling_table =
168  journalling_symbol_tablet::wrap(symbol_table);
169 
171  to_class_type(class_symbol.type).get_tag(),
172  journalling_table,
173  string_refinement_enabled);
174 
175  // If that created any new symbols make sure we initialise those too:
176  const auto &new_symbols = journalling_table.get_inserted();
177  symbol_names.insert(
178  symbol_names.end(), new_symbols.begin(), new_symbols.end());
179 
180  // Call the literal initializer method instead of a nondet initializer:
181 
182  // For arguments we can't parse yet:
184 
185  const auto &java_class_type = to_java_class_type(class_symbol.type);
186 
187  // Argument order is: name, isAnnotation, isArray, isInterface,
188  // isSynthetic, isLocalClass, isMemberClass, isEnum
189 
190  code_function_callt initializer_call(
191  class_literal_init_method->symbol_expr(),
192  {// this:
193  address_of_exprt(sym.symbol_expr()),
194  // name:
195  address_of_exprt(class_name_literal),
196  // isAnnotation:
197  constant_bool(java_class_type.get_is_annotation()),
198  // isArray:
199  constant_bool(class_is_array),
200  // isInterface:
201  constant_bool(java_class_type.get_interface()),
202  // isSynthetic:
203  constant_bool(java_class_type.get_synthetic()),
204  // isLocalClass:
205  nondet_bool,
206  // isMemberClass:
207  nondet_bool,
208  // isEnum:
209  constant_bool(java_class_type.get_is_enumeration())});
210 
211  // First initialize the object as prior to a constructor:
212  namespacet ns(symbol_table);
213 
214  auto zero_object = zero_initializer(sym.type, source_locationt(), ns);
215  if(!zero_object.has_value())
216  {
217  messaget message(message_handler);
218  message.error() << "failed to zero-initialize " << sym.name
219  << messaget::eom;
220  throw 0;
221  }
223  to_struct_expr(*zero_object), ns, to_struct_tag_type(sym.type));
224 
225  code_block.add(
226  std::move(code_assignt(sym.symbol_expr(), *zero_object)));
227 
228  // Then call the init function:
229  code_block.add(std::move(initializer_call));
230  }
231  else if(sym.value.is_nil() && sym.type != java_void_type())
232  {
233  const bool is_class_model =
234  has_suffix(id2string(sym.name), "@class_model");
235  const bool not_allow_null = is_java_string_literal_id(sym.name) ||
237  assume_init_pointers_not_null;
238 
239  java_object_factory_parameterst parameters = object_factory_parameters;
240  if(not_allow_null && !is_class_model)
241  parameters.min_null_tree_depth = 1;
242 
244  sym.symbol_expr(),
245  code_block,
246  symbol_table,
247  source_location,
248  false,
250  parameters,
251  pointer_type_selector,
253  message_handler);
254  }
255  else if(sym.value.is_not_nil())
256  {
257  code_assignt assignment(sym.symbol_expr(), sym.value);
258  assignment.add_source_location()=source_location;
259  code_block.add(assignment);
260  }
261  }
262  }
263  initialize_symbol.value = std::move(code_block);
264 }
265 
271 bool is_java_main(const symbolt &function)
272 {
273  bool named_main = has_suffix(id2string(function.name), JAVA_MAIN_METHOD);
274  const java_method_typet &function_type = to_java_method_type(function.type);
275  const auto string_array_type = java_type_from_string("[Ljava/lang/String;");
276  // checks whether the function is static and has a single String[] parameter
277  bool is_static = !function_type.has_this();
278  // this should be implied by the signature
279  const java_method_typet::parameterst &parameters = function_type.parameters();
280  bool has_correct_type = function_type.return_type().id() == ID_empty &&
281  parameters.size() == 1 &&
282  parameters[0].type().full_eq(*string_array_type);
283  bool public_access = function_type.get(ID_access) == ID_public;
284  return named_main && is_static && has_correct_type && public_access;
285 }
286 
287 std::pair<code_blockt, std::vector<exprt>> java_build_arguments(
288  const symbolt &function,
289  symbol_table_baset &symbol_table,
290  bool assume_init_pointers_not_null,
291  java_object_factory_parameterst object_factory_parameters,
292  const select_pointer_typet &pointer_type_selector,
293  message_handlert &message_handler)
294 {
295  const java_method_typet &function_type = to_java_method_type(function.type);
296  const java_method_typet::parameterst &parameters = function_type.parameters();
297 
298  code_blockt init_code;
299  exprt::operandst main_arguments;
300  main_arguments.resize(parameters.size());
301 
302  // certain method arguments cannot be allowed to be null, we set the following
303  // variable to true iff the method under test is the "main" method, which will
304  // be called (by the jvm) with arguments that are never null
305  bool is_main = is_java_main(function);
306 
307  // we iterate through all the parameters of the function under test, allocate
308  // an object for that parameter (recursively allocating other objects
309  // necessary to initialize it), and mark such object using `code_inputt`.
310  for(std::size_t param_number=0;
311  param_number<parameters.size();
312  param_number++)
313  {
314  const java_method_typet::parametert &p = parameters[param_number];
315  const irep_idt base_name=p.get_base_name().empty()?
316  ("argument#"+std::to_string(param_number)):p.get_base_name();
317 
318  // true iff this parameter is the `this` pointer of the method, which cannot
319  // be null
320  bool is_this=(param_number==0) && parameters[param_number].get_this();
321 
322  if(is_this && function_type.get_is_constructor())
323  {
324  const symbol_exprt result = fresh_java_symbol(
325  p.type(),
326  "this_parameter",
327  function.location,
328  function.name,
329  symbol_table)
330  .symbol_expr();
331  main_arguments[param_number] = result;
332  init_code.add(code_declt{result});
333  init_code.add(
334  code_assignt{result, side_effect_exprt(ID_java_new, p.type())});
335  continue;
336  }
337 
338  java_object_factory_parameterst factory_parameters =
339  object_factory_parameters;
340  // only pointer must be non-null
341  if(assume_init_pointers_not_null || is_this)
342  factory_parameters.min_null_tree_depth = 1;
343  // in main() also the array elements of the argument must be non-null
344  if(is_main)
345  factory_parameters.min_null_tree_depth = 2;
346 
347  factory_parameters.function_id = goto_functionst::entry_point();
348 
349  namespacet ns(symbol_table);
350 
351  // Generate code to allocate and non-deterministicaly initialize the
352  // argument, if the argument has different possible object types (e.g., from
353  // casts in the function body), then choose one in a non-deterministic way.
354  const auto alternatives =
355  pointer_type_selector.get_parameter_alternative_types(
356  function.name, p.get_identifier(), ns);
357  if(alternatives.empty())
358  {
359  main_arguments[param_number] = object_factory(
360  p.type(),
361  base_name,
362  init_code,
363  symbol_table,
364  factory_parameters,
366  function.location,
367  pointer_type_selector,
368  message_handler);
369  }
370  else
371  {
372  INVARIANT(!is_this, "We cannot have different types for `this` here");
373  // create a non-deterministic switch between all possible values for the
374  // type of the parameter.
375 
376  // the idea is to get a new symbol for the parameter value `tmp`
377 
378  // then add a non-deterministic switch over all possible input types,
379  // construct the object type at hand and assign to `tmp`
380 
381  // switch(...)
382  // {
383  // case obj1:
384  // tmp_expr = object_factory(...)
385  // param = tmp_expr
386  // break
387  // ...
388  // }
389  // method(..., param, ...)
390  //
391 
393  p.type(),
394  "nondet_parameter_" + std::to_string(param_number),
395  function.location,
396  function.name,
397  symbol_table);
398  main_arguments[param_number] = result_symbol.symbol_expr();
399 
400  std::vector<codet> cases;
401  cases.reserve(alternatives.size());
402  for(const auto &type : alternatives)
403  {
404  code_blockt init_code_for_type;
405  exprt init_expr_for_parameter = object_factory(
406  java_reference_type(type),
407  id2string(base_name) + "_alternative_" +
408  id2string(type.get_identifier()),
409  init_code_for_type,
410  symbol_table,
411  factory_parameters,
413  function.location,
414  pointer_type_selector,
415  message_handler);
416  init_code_for_type.add(
417  code_assignt(
419  typecast_exprt(init_expr_for_parameter, p.type())));
420  cases.push_back(init_code_for_type);
421  }
422 
423  init_code.add(
425  id2string(function.name) + "_" + std::to_string(param_number),
426  cases,
427  java_int_type(),
428  ID_java,
429  function.location,
430  symbol_table));
431  }
432 
433  // record as an input
434  init_code.add(
435  code_inputt{base_name, main_arguments[param_number], function.location});
436  }
437 
438  return make_pair(init_code, main_arguments);
439 }
440 
443  const symbolt &function,
444  const exprt::operandst &main_arguments,
445  symbol_table_baset &symbol_table)
446 {
447  code_blockt init_code;
448 
449  if(auto return_value = record_return_value(function, symbol_table))
450  {
451  init_code.add(std::move(*return_value));
452  }
453 
454  init_code.append(
455  record_pointer_parameters(function, main_arguments, symbol_table));
456 
457  init_code.add(record_exception(function, symbol_table));
458 
459  return init_code;
460 }
461 
463  const symbolt &function,
464  const symbol_table_baset &symbol_table)
465 {
466  if(to_java_method_type(function.type).return_type() == java_void_type())
467  return {};
468 
469  const symbolt &return_symbol =
471 
472  return code_outputt{
473  return_symbol.base_name, return_symbol.symbol_expr(), function.location};
474 }
475 
477  const symbolt &function,
478  const std::vector<exprt> &arguments,
479  const symbol_table_baset &symbol_table)
480 {
481  const java_method_typet::parameterst &parameters =
482  to_java_method_type(function.type).parameters();
483 
484  code_blockt init_code;
485 
486  for(std::size_t param_number = 0; param_number < parameters.size();
487  param_number++)
488  {
489  const symbolt &p_symbol =
490  symbol_table.lookup_ref(parameters[param_number].get_identifier());
491 
492  if(!can_cast_type<pointer_typet>(p_symbol.type))
493  continue;
494 
495  init_code.add(code_outputt{
496  p_symbol.base_name, arguments[param_number], function.location});
497  }
498  return init_code;
499 }
500 
502  const symbolt &function,
503  const symbol_table_baset &symbol_table)
504 {
505  // retrieve the exception variable
506  const symbolt &exc_symbol =
508 
509  // record exceptional return variable as output
510  return code_outputt{
511  exc_symbol.base_name, exc_symbol.symbol_expr(), function.location};
512 }
513 
515  const symbol_table_baset &symbol_table,
516  const irep_idt &main_class,
517  message_handlert &message_handler)
518 {
519  messaget message(message_handler);
520 
521  // find main symbol
522  if(config.main.has_value())
523  {
524  std::string error_message;
525  irep_idt main_symbol_id = resolve_friendly_method_name(
526  config.main.value(), symbol_table, error_message);
527 
528  if(main_symbol_id.empty())
529  {
530  message.error()
531  << "main symbol resolution failed: " << error_message << messaget::eom;
533  }
534 
535  const symbolt *symbol = symbol_table.lookup(main_symbol_id);
536  INVARIANT(
537  symbol != nullptr,
538  "resolve_friendly_method_name should return a symbol-table identifier");
539 
540  return *symbol; // Return found function
541  }
542  else
543  {
544  // are we given a main class?
545  if(main_class.empty())
546  {
547  // no, but we allow this situation to output symbol table,
548  // goto functions, etc
550  }
551 
552  std::string entry_method =
553  "java::" + id2string(main_class) + "." + JAVA_MAIN_METHOD;
554  const symbolt *symbol = symbol_table.lookup(entry_method);
555 
556  // has the class a correct main method?
557  if(!symbol || !is_java_main(*symbol))
558  {
559  // no, but we allow this situation to output symbol table,
560  // goto functions, etc
562  }
563 
564  return *symbol;
565  }
566 }
567 
569  symbol_table_baset &symbol_table,
570  const irep_idt &main_class,
571  message_handlert &message_handler,
572  bool assume_init_pointers_not_null,
573  bool assert_uncaught_exceptions,
574  const java_object_factory_parameterst &object_factory_parameters,
575  const select_pointer_typet &pointer_type_selector,
576  bool string_refinement_enabled,
577  const build_argumentst &build_arguments)
578 {
579  // check if the entry point is already there
580  if(symbol_table.symbols.find(goto_functionst::entry_point())!=
581  symbol_table.symbols.end())
582  return false; // silently ignore
583 
584  messaget message(message_handler);
586  get_main_symbol(symbol_table, main_class, message_handler);
587  if(!res.is_success())
588  return true;
589  symbolt symbol=res.main_function;
590 
591  assert(symbol.type.id()==ID_code);
592 
594  symbol,
595  symbol_table,
596  message_handler,
597  assert_uncaught_exceptions,
598  object_factory_parameters,
599  pointer_type_selector,
600  build_arguments);
601 }
602 
604  const symbolt &symbol,
605  symbol_table_baset &symbol_table,
606  message_handlert &message_handler,
607  bool assert_uncaught_exceptions,
608  const java_object_factory_parameterst &object_factory_parameters,
609  const select_pointer_typet &pointer_type_selector,
610  const build_argumentst &build_arguments)
611 {
612  messaget message(message_handler);
613  code_blockt init_code;
614 
615  // build call to initialization function
616  {
617  symbol_tablet::symbolst::const_iterator init_it=
618  symbol_table.symbols.find(INITIALIZE_FUNCTION);
619 
620  if(init_it==symbol_table.symbols.end())
621  {
622  message.error() << "failed to find " INITIALIZE_FUNCTION " symbol"
623  << messaget::eom;
624  return true; // give up with error
625  }
626 
627  code_function_callt call_init(init_it->second.symbol_expr());
628  call_init.add_source_location()=symbol.location;
629 
630  init_code.add(std::move(call_init));
631  }
632 
633  // build call to the main method, of the form
634  // return = main_method(arg1, arg2, ..., argn)
635  // where return is a new variable
636  // and arg1 ... argn are constructed below as well
637 
638  source_locationt loc=symbol.location;
639  loc.set_function(symbol.name);
640  source_locationt &dloc=loc;
641 
642  // function to call
643  code_function_callt call_main(symbol.symbol_expr());
644  call_main.add_source_location()=dloc;
645  call_main.function().add_source_location()=dloc;
646 
647  // if the method return type is not void, store return value in a new variable
648  // named 'return'
650  {
651  auxiliary_symbolt return_symbol;
652  return_symbol.mode=ID_java;
653  return_symbol.is_static_lifetime=false;
654  return_symbol.name=JAVA_ENTRY_POINT_RETURN_SYMBOL;
655  return_symbol.base_name = "return'";
656  return_symbol.type = to_java_method_type(symbol.type).return_type();
657 
658  symbol_table.add(return_symbol);
659  call_main.lhs()=return_symbol.symbol_expr();
660  }
661 
662  // add the exceptional return value
663  auxiliary_symbolt exc_symbol;
664  exc_symbol.mode=ID_java;
666  exc_symbol.base_name=exc_symbol.name;
667  exc_symbol.type = java_reference_type(java_void_type());
668  symbol_table.add(exc_symbol);
669 
670  // Zero-initialise the top-level exception catch variable:
671  init_code.add(code_assignt(
672  exc_symbol.symbol_expr(),
673  null_pointer_exprt(to_pointer_type(exc_symbol.type))));
674 
675  // create code that allocates the objects used as test arguments and
676  // non-deterministically initializes them
677  const std::pair<code_blockt, std::vector<exprt>> main_arguments =
678  build_arguments(symbol, symbol_table);
679  init_code.append(main_arguments.first);
680  call_main.arguments() = main_arguments.second;
681 
682  // Create target labels for the toplevel exception handler:
683  code_labelt toplevel_catch("toplevel_catch", code_skipt());
684  code_labelt after_catch("after_catch", code_skipt());
685 
686  code_blockt call_block;
687 
688  // Push a universal exception handler:
689  // Catch all exceptions:
690  // This is equivalent to catching Throwable, but also works if some of
691  // the class hierarchy is missing so that we can't determine that
692  // the thrown instance is an indirect child of Throwable
693  code_push_catcht push_universal_handler(
694  irep_idt(), toplevel_catch.get_label());
695  irept catch_type_list(ID_exception_list);
696  irept catch_target_list(ID_label);
697 
698  call_block.add(std::move(push_universal_handler));
699 
700  // we insert the call to the method AFTER the argument initialization code
701  call_block.add(std::move(call_main));
702 
703  // Pop the handler:
704  code_pop_catcht pop_handler;
705  call_block.add(std::move(pop_handler));
706  init_code.add(std::move(call_block));
707 
708  // Normal return: skip the exception handler:
709  init_code.add(code_gotot(after_catch.get_label()));
710 
711  // Exceptional return: catch and assign to exc_symbol.
712  code_landingpadt landingpad(exc_symbol.symbol_expr());
713  init_code.add(std::move(toplevel_catch));
714  init_code.add(std::move(landingpad));
715 
716  // Converge normal and exceptional return:
717  init_code.add(std::move(after_catch));
718 
719  // Mark return value, pointer type parameters and the exception as outputs.
720  init_code.append(
721  java_record_outputs(symbol, main_arguments.second, symbol_table));
722 
723  // add uncaught-exception check if requested
724  if(assert_uncaught_exceptions)
725  {
727  init_code, exc_symbol, symbol.location);
728  }
729 
730  // create a symbol for the __CPROVER__start function, associate the code that
731  // we just built and register it in the symbol table
732  symbolt new_symbol;
733 
734  new_symbol.name=goto_functionst::entry_point();
735  new_symbol.type = java_method_typet({}, java_void_type());
736  new_symbol.value.swap(init_code);
737  new_symbol.mode=ID_java;
738 
739  if(!symbol_table.insert(std::move(new_symbol)).second)
740  {
741  message.error() << "failed to move main symbol" << messaget::eom;
742  return true;
743  }
744 
745  return false;
746 }
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:155
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
code_blockt
A codet representing sequential composition of program statements.
Definition: std_code.h:170
JAVA_CLASS_MODEL_SUFFIX
#define JAVA_CLASS_MODEL_SUFFIX
Definition: java_bytecode_language.h:272
symbolt::is_state_var
bool is_state_var
Definition: symbol.h:62
generate_nondet_switch
code_blockt generate_nondet_switch(const irep_idt &name_prefix, const alternate_casest &switch_cases, const typet &int_type, const irep_idt &mode, const source_locationt &source_location, symbol_table_baset &symbol_table)
Pick nondeterministically between imperative actions 'switch_cases'.
Definition: nondet.cpp:93
record_pointer_parameters
static code_blockt record_pointer_parameters(const symbolt &function, const std::vector< exprt > &arguments, const symbol_table_baset &symbol_table)
Definition: java_entry_point.cpp:476
symbol_table_baset::lookup_ref
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
Definition: symbol_table_base.h:104
journalling_symbol_tablet::wrap
static journalling_symbol_tablet wrap(symbol_table_baset &base_symbol_table)
Definition: journalling_symbol_table.h:80
java_reference_type
reference_typet java_reference_type(const typet &subtype)
Definition: java_types.cpp:89
source_locationt::set_function
void set_function(const irep_idt &function)
Definition: source_location.h:126
JAVA_ENTRY_POINT_RETURN_SYMBOL
#define JAVA_ENTRY_POINT_RETURN_SYMBOL
Definition: java_entry_point.h:19
is_java_string_literal_id
bool is_java_string_literal_id(const irep_idt &id)
Definition: java_utils.cpp:216
main_function_resultt::main_function
symbolt main_function
Definition: java_entry_point.h:94
java_string_literals.h
fresh_symbol.h
Fresh auxiliary symbol creation.
to_class_type
const class_typet & to_class_type(const typet &type)
Cast a typet to a class_typet.
Definition: std_types.h:376
get_main_symbol
main_function_resultt get_main_symbol(const symbol_table_baset &symbol_table, const irep_idt &main_class, message_handlert &message_handler)
Figures out the entry point of the code to verify.
Definition: java_entry_point.cpp:514
symbolt::type
typet type
Type of symbol.
Definition: symbol.h:31
object_factory_parameterst::function_id
irep_idt function_id
Function id, used as a prefix for identifiers of temporaries.
Definition: object_factory_parameters.h:82
JAVA_MAIN_METHOD
#define JAVA_MAIN_METHOD
Definition: java_entry_point.cpp:29
configt::main
optionalt< std::string > main
Definition: config.h:181
code_declt
A codet representing the declaration of a local variable.
Definition: std_code.h:402
java_method_typet::parameterst
std::vector< parametert > parameterst
Definition: std_types.h:738
string_constant.h
object_factory_parameterst::string_input_values
std::list< std::string > string_input_values
Force one of finitely many explicitly given input strings.
Definition: object_factory_parameters.h:79
exprt
Base class for all expressions.
Definition: expr.h:53
journalling_symbol_table.h
Author: Diffblue Ltd.
is_java_array_tag
bool is_java_array_tag(const irep_idt &tag)
See above.
Definition: java_types.cpp:232
build_argumentst
std::function< std::pair< code_blockt, std::vector< exprt > >(const symbolt &function, symbol_table_baset &symbol_table)> build_argumentst
Definition: java_entry_point.h:25
symbolt::base_name
irep_idt base_name
Base (non-scoped) name.
Definition: symbol.h:46
code_push_catcht
Pushes an exception handler, of the form: exception_tag1 -> label1 exception_tag2 -> label2 ....
Definition: std_code.h:2248
struct_tag_typet
A struct tag type, i.e., struct_typet with an identifier.
Definition: std_types.h:490
select_pointer_typet::get_parameter_alternative_types
virtual std::set< struct_tag_typet > get_parameter_alternative_types(const irep_idt &function_name, const irep_idt &parameter_name, const namespacet &ns) const
Get alternative types for a method parameter, e.g., based on the casts in the function body.
Definition: select_pointer_type.cpp:81
irep_idt
dstringt irep_idt
Definition: irep.h:32
main_function_resultt::NotFound
@ NotFound
Definition: java_entry_point.h:92
to_string
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
Definition: string_constraint.cpp:55
messaget::eom
static eomt eom
Definition: message.h:297
auxiliary_symbolt
Internally generated symbol table entryThis is a symbol generated as part of translation to or modifi...
Definition: symbol.h:160
symbol_exprt
Expression to hold a symbol (variable)
Definition: std_expr.h:82
get_or_create_string_literal_symbol
symbol_exprt get_or_create_string_literal_symbol(const java_string_literal_exprt &string_expr, symbol_table_baset &symbol_table, bool string_refinement_enabled)
Creates or gets an existing constant global symbol for a given string literal.
Definition: java_string_literals.cpp:38
code_pop_catcht
Pops an exception handler from the stack of active handlers (i.e.
Definition: std_code.h:2342
has_suffix
bool has_suffix(const std::string &s, const std::string &suffix)
Definition: suffix.h:17
code_function_callt::lhs
exprt & lhs()
Definition: std_code.h:1208
record_exception
static codet record_exception(const symbolt &function, const symbol_table_baset &symbol_table)
Definition: java_entry_point.cpp:501
code_typet::get_is_constructor
bool get_is_constructor() const
Definition: std_types.h:887
zero_initializer
optionalt< exprt > zero_initializer(const typet &type, const source_locationt &source_location, const namespacet &ns)
Create the equivalent of zero for type type.
Definition: expr_initializer.cpp:318
main_function_resultt::is_success
bool is_success() const
Definition: java_entry_point.h:109
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:92
code_outputt
A codet representing the declaration that an output of a particular description has a value which cor...
Definition: std_code.h:692
message
static const char * message(const static_verifier_resultt::statust &status)
Makes a status message string from a status.
Definition: static_verifier.cpp:74
exprt::type
typet & type()
Return the type of the expression.
Definition: expr.h:81
code_function_callt
codet representation of a function call statement.
Definition: std_code.h:1183
irept::get_bool
bool get_bool(const irep_namet &name) const
Definition: irep.cpp:64
irept::is_not_nil
bool is_not_nil() const
Definition: irep.h:402
struct_union_typet::get_tag
irep_idt get_tag() const
Definition: std_types.h:163
set_class_identifier
void set_class_identifier(struct_exprt &expr, const namespacet &ns, const struct_tag_typet &class_type)
If expr has its components filled in then sets the @class_identifier member of the struct.
Definition: class_identifier.cpp:82
result_symbol
static symbolt result_symbol(const irep_idt &identifier, const typet &type, const source_locationt &source_location, symbol_tablet &symbol_table)
Definition: c_typecheck_gcc_polymorphic_builtins.cpp:597
expr_initializer.h
Expression Initialization.
symbolt::mode
irep_idt mode
Language mode.
Definition: symbol.h:49
java_object_factory.h
This module is responsible for the synthesis of code (in the form of a sequence of codet statements) ...
code_typet::parametert::get_base_name
const irep_idt & get_base_name() const
Definition: std_types.h:797
get_java_class_literal_initializer_signature
irep_idt get_java_class_literal_initializer_signature()
Get the symbol name of java.lang.Class' initializer method.
Definition: java_entry_point.cpp:75
record_return_value
static optionalt< codet > record_return_value(const symbolt &function, const symbol_table_baset &symbol_table)
Definition: java_entry_point.cpp:462
null_pointer_exprt
The null pointer constant.
Definition: std_expr.h:3989
symbol_table_baset::get_writeable_ref
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
Definition: symbol_table_base.h:121
id2string
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
java_static_lifetime_init
void java_static_lifetime_init(symbol_table_baset &symbol_table, const source_locationt &source_location, bool assume_init_pointers_not_null, java_object_factory_parameterst object_factory_parameters, const select_pointer_typet &pointer_type_selector, bool string_refinement_enabled, message_handlert &message_handler)
Adds the body to __CPROVER_initialize.
Definition: java_entry_point.cpp:106
code_gotot
codet representation of a goto statement.
Definition: std_code.h:1127
code_labelt
codet representation of a label for branch targets.
Definition: std_code.h:1375
PRECONDITION
#define PRECONDITION(CONDITION)
Definition: invariant.h:464
symbol_table_baset
The symbol table base class interface.
Definition: symbol_table_base.h:22
symbolt::symbol_expr
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
Definition: symbol.cpp:122
INITIALIZE_FUNCTION
#define INITIALIZE_FUNCTION
Definition: static_lifetime_init.h:23
java_entry_point.h
resolve_friendly_method_name
irep_idt resolve_friendly_method_name(const std::string &friendly_name, const symbol_table_baset &symbol_table, std::string &error)
Resolves a user-friendly method name (like packagename.Class.method) into an internal name (like java...
Definition: java_utils.cpp:221
object_factory
exprt object_factory(const typet &type, const irep_idt base_name, code_blockt &init_code, symbol_table_baset &symbol_table, java_object_factory_parameterst parameters, lifetimet lifetime, const source_locationt &loc, const select_pointer_typet &pointer_type_selector, message_handlert &log)
Similar to gen_nondet_init below, but instead of allocating and non-deterministically initializing th...
Definition: java_object_factory.cpp:1537
is_non_null_library_global
bool is_non_null_library_global(const irep_idt &symbolid)
Check if a symbol is a well-known non-null global.
Definition: java_utils.cpp:529
select_pointer_typet
Definition: select_pointer_type.h:26
is_java_main
bool is_java_main(const symbolt &function)
Checks whether the given symbol is a valid java main method i.e.
Definition: java_entry_point.cpp:271
irept::swap
void swap(irept &irep)
Definition: irep.h:463
gen_nondet_init
void gen_nondet_init(const exprt &expr, code_blockt &init_code, symbol_table_baset &symbol_table, const source_locationt &loc, bool skip_classid, lifetimet lifetime, const java_object_factory_parameterst &object_factory_parameters, const select_pointer_typet &pointer_type_selector, update_in_placet update_in_place, message_handlert &log)
Initializes a primitive-typed or reference-typed object tree rooted at expr, allocating child objects...
Definition: java_object_factory.cpp:1624
irept::is_nil
bool is_nil() const
Definition: irep.h:398
irept::id
const irep_idt & id() const
Definition: irep.h:418
message_handlert
Definition: message.h:28
to_struct_tag_type
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
Definition: std_types.h:515
exprt::operandst
std::vector< exprt > operandst
Definition: expr.h:55
dstringt::empty
bool empty() const
Definition: dstring.h:88
code_blockt::add
void add(const codet &code)
Definition: std_code.h:208
java_int_type
signedbv_typet java_int_type()
Definition: java_types.cpp:32
code_typet::parameters
const parameterst & parameters() const
Definition: std_types.h:857
to_pointer_type
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
Definition: std_types.h:1526
symbol_table_baset::remove
bool remove(const irep_idt &name)
Remove a symbol from the symbol table.
Definition: symbol_table_base.cpp:27
constant_bool
static constant_exprt constant_bool(bool val)
Definition: java_entry_point.cpp:101
code_function_callt::arguments
argumentst & arguments()
Definition: std_code.h:1228
fresh_java_symbol
symbolt & fresh_java_symbol(const typet &type, const std::string &basename_prefix, const source_locationt &source_location, const irep_idt &function_name, symbol_table_baset &symbol_table)
Definition: java_utils.cpp:566
optionalt
nonstd::optional< T > optionalt
Definition: optional.h:35
java_type_from_string
optionalt< typet > java_type_from_string(const std::string &src, const std::string &class_name_prefix)
Transforms a string representation of a Java type into an internal type representation thereof.
Definition: java_types.cpp:560
java_entry_point
bool java_entry_point(symbol_table_baset &symbol_table, const irep_idt &main_class, message_handlert &message_handler, bool assume_init_pointers_not_null, bool assert_uncaught_exceptions, const java_object_factory_parameterst &object_factory_parameters, const select_pointer_typet &pointer_type_selector, bool string_refinement_enabled, const build_argumentst &build_arguments)
Given the symbol_table and the main_class to test, this function generates a new function __CPROVER__...
Definition: java_entry_point.cpp:568
main_function_resultt
Definition: java_entry_point.h:87
java_build_arguments
std::pair< code_blockt, std::vector< exprt > > java_build_arguments(const symbolt &function, symbol_table_baset &symbol_table, bool assume_init_pointers_not_null, java_object_factory_parameterst object_factory_parameters, const select_pointer_typet &pointer_type_selector, message_handlert &message_handler)
Definition: java_entry_point.cpp:287
code_typet::has_this
bool has_this() const
Definition: std_types.h:818
java_bytecode_instrument_uncaught_exceptions
void java_bytecode_instrument_uncaught_exceptions(code_blockt &init_code, const symbolt &exc_symbol, const source_locationt &source_location)
Instruments the start function with an assertion that checks whether an exception has escaped the ent...
Definition: java_bytecode_instrument.cpp:568
config
configt config
Definition: config.cpp:24
object_factory_parameterst::min_null_tree_depth
size_t min_null_tree_depth
To force a certain depth of non-null objects.
Definition: object_factory_parameters.h:73
source_locationt
Definition: source_location.h:20
side_effect_expr_nondett
A side_effect_exprt that returns a non-deterministically chosen value.
Definition: std_code.h:1945
code_labelt::get_label
const irep_idt & get_label() const
Definition: std_code.h:1383
can_cast_type< pointer_typet >
bool can_cast_type< pointer_typet >(const typet &type)
Check whether a reference to a typet is a pointer_typet.
Definition: std_types.h:1513
symbol_table_baset::add
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
Definition: symbol_table_base.cpp:18
get_class_literal_initializer
static const symbolt * get_class_literal_initializer(const symbolt &symbol, const symbol_table_baset &symbol_table)
If symbol is a class literal, and an appropriate initializer method exists, return a pointer to its s...
Definition: java_entry_point.cpp:88
symbolt::value
exprt value
Initial value of symbol.
Definition: symbol.h:34
code_skipt
A codet representing a skip statement.
Definition: std_code.h:270
code_landingpadt
A statement that catches an exception, assigning the exception in flight to an expression (e....
Definition: std_code.h:2379
create_java_initialize
void create_java_initialize(symbol_table_baset &symbol_table)
Adds __cprover_initialize to the symbol_table but does not generate code for it yet.
Definition: java_entry_point.cpp:44
suffix.h
irept::get
const irep_idt & get(const irep_namet &name) const
Definition: irep.cpp:51
symbolt::location
source_locationt location
Source code location of definition of symbol.
Definition: symbol.h:37
code_inputt
A codet representing the declaration that an input of a particular description has a value which corr...
Definition: std_code.h:645
nondet.h
symbolt
Symbol table entry.
Definition: symbol.h:28
from_integer
constant_exprt from_integer(const mp_integer &int_value, const typet &type)
Definition: arith_tools.cpp:99
code_blockt::append
void append(const code_blockt &extra_block)
Add all the codets from extra_block to the current code_blockt.
Definition: std_code.cpp:87
symbol_table_baset::symbols
const symbolst & symbols
Read-only field, used to look up symbols given their names.
Definition: symbol_table_base.h:30
code_typet::parametert::get_identifier
const irep_idt & get_identifier() const
Definition: std_types.h:792
lifetimet::STATIC_GLOBAL
@ STATIC_GLOBAL
Allocate global objects with static lifetime.
CPROVER_PREFIX
#define CPROVER_PREFIX
Definition: cprover_prefix.h:14
update_in_placet::NO_UPDATE_IN_PLACE
@ NO_UPDATE_IN_PLACE
code_typet::parametert
Definition: std_types.h:753
main_function_resultt::Error
@ Error
Definition: java_entry_point.h:91
symbolt::is_static_lifetime
bool is_static_lifetime
Definition: symbol.h:65
goto_functions.h
Goto Programs with Functions.
should_init_symbol
static bool should_init_symbol(const symbolt &sym)
Definition: java_entry_point.cpp:59
config.h
class_identifier.h
Extract class identifier.
java_boolean_type
c_bool_typet java_boolean_type()
Definition: java_types.cpp:80
symbol_table_baset::insert
virtual std::pair< symbolt &, bool > insert(symbolt symbol)=0
Move or copy a new symbol to the symbol table.
lifetimet::DYNAMIC
@ DYNAMIC
Allocate dynamic objects (using ALLOCATE)
symbol_table_baset::lookup
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
Definition: symbol_table_base.h:95
code_typet::return_type
const typet & return_type() const
Definition: std_types.h:847
irept
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition: irep.h:394
symbolt::is_lvalue
bool is_lvalue
Definition: symbol.h:66
to_java_class_type
const java_class_typet & to_java_class_type(const typet &type)
Definition: java_types.h:584
goto_functionst::entry_point
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
Definition: goto_functions.h:90
journalling_symbol_tablet::get_inserted
const changesett & get_inserted() const
Definition: journalling_symbol_table.h:146
static_lifetime_init.h
INVARIANT
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition: invariant.h:424
exprt::add_source_location
source_locationt & add_source_location()
Definition: expr.h:259
java_record_outputs
static code_blockt java_record_outputs(const symbolt &function, const exprt::operandst &main_arguments, symbol_table_baset &symbol_table)
Mark return value, pointer type parameters and the exception as outputs.
Definition: java_entry_point.cpp:442
to_java_method_type
const java_method_typet & to_java_method_type(const typet &type)
Definition: java_types.h:186
java_bytecode_instrument.h
typecast_exprt
Semantic type conversion.
Definition: std_expr.h:2013
java_void_type
empty_typet java_void_type()
Definition: java_types.cpp:38
code_assignt
A codet representing an assignment in the program.
Definition: std_code.h:295
java_utils.h
constant_exprt
A constant literal expression.
Definition: std_expr.h:3906
generate_java_start_function
bool generate_java_start_function(const symbolt &symbol, symbol_table_baset &symbol_table, message_handlert &message_handler, bool assert_uncaught_exceptions, const java_object_factory_parameterst &object_factory_parameters, const select_pointer_typet &pointer_type_selector, const build_argumentst &build_arguments)
Generate a _start function for a specific function.
Definition: java_entry_point.cpp:603
journalling_symbol_tablet
A symbol table wrapper that records which entries have been updated/removedA caller can pass a journa...
Definition: journalling_symbol_table.h:36
java_method_typet
Definition: java_types.h:103
JAVA_ENTRY_POINT_EXCEPTION_SYMBOL
#define JAVA_ENTRY_POINT_EXCEPTION_SYMBOL
Definition: java_entry_point.h:20
java_object_factory_parameterst
Definition: java_object_factory_parameters.h:16
symbolt::name
irep_idt name
The unique identifier.
Definition: symbol.h:40
code_function_callt::function
exprt & function()
Definition: std_code.h:1218
side_effect_exprt
An expression containing a side effect.
Definition: std_code.h:1866
dstringt::size
size_t size() const
Definition: dstring.h:104
to_struct_expr
const struct_exprt & to_struct_expr(const exprt &expr)
Cast an exprt to a struct_exprt.
Definition: std_expr.h:1656
codet
Data structure for representing an arbitrary statement in a program.
Definition: std_code.h:35