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(code_assignt{
334  result,
335  side_effect_exprt{ID_java_new, {}, p.type(), function.location}});
336  continue;
337  }
338 
339  java_object_factory_parameterst factory_parameters =
340  object_factory_parameters;
341  // only pointer must be non-null
342  if(assume_init_pointers_not_null || is_this)
343  factory_parameters.min_null_tree_depth = 1;
344  // in main() also the array elements of the argument must be non-null
345  if(is_main)
346  factory_parameters.min_null_tree_depth = 2;
347 
348  factory_parameters.function_id = goto_functionst::entry_point();
349 
350  namespacet ns(symbol_table);
351 
352  // Generate code to allocate and non-deterministicaly initialize the
353  // argument, if the argument has different possible object types (e.g., from
354  // casts in the function body), then choose one in a non-deterministic way.
355  const auto alternatives =
356  pointer_type_selector.get_parameter_alternative_types(
357  function.name, p.get_identifier(), ns);
358  if(alternatives.empty())
359  {
360  main_arguments[param_number] = object_factory(
361  p.type(),
362  base_name,
363  init_code,
364  symbol_table,
365  factory_parameters,
367  function.location,
368  pointer_type_selector,
369  message_handler);
370  }
371  else
372  {
373  INVARIANT(!is_this, "We cannot have different types for `this` here");
374  // create a non-deterministic switch between all possible values for the
375  // type of the parameter.
376 
377  // the idea is to get a new symbol for the parameter value `tmp`
378 
379  // then add a non-deterministic switch over all possible input types,
380  // construct the object type at hand and assign to `tmp`
381 
382  // switch(...)
383  // {
384  // case obj1:
385  // tmp_expr = object_factory(...)
386  // param = tmp_expr
387  // break
388  // ...
389  // }
390  // method(..., param, ...)
391  //
392 
394  p.type(),
395  "nondet_parameter_" + std::to_string(param_number),
396  function.location,
397  function.name,
398  symbol_table);
399  main_arguments[param_number] = result_symbol.symbol_expr();
400 
401  std::vector<codet> cases;
402  cases.reserve(alternatives.size());
403  for(const auto &type : alternatives)
404  {
405  code_blockt init_code_for_type;
406  exprt init_expr_for_parameter = object_factory(
407  java_reference_type(type),
408  id2string(base_name) + "_alternative_" +
409  id2string(type.get_identifier()),
410  init_code_for_type,
411  symbol_table,
412  factory_parameters,
414  function.location,
415  pointer_type_selector,
416  message_handler);
417  init_code_for_type.add(
418  code_assignt(
420  typecast_exprt(init_expr_for_parameter, p.type())));
421  cases.push_back(init_code_for_type);
422  }
423 
424  init_code.add(
426  id2string(function.name) + "_" + std::to_string(param_number),
427  cases,
428  java_int_type(),
429  ID_java,
430  function.location,
431  symbol_table));
432  }
433 
434  // record as an input
435  init_code.add(
436  code_inputt{base_name, main_arguments[param_number], function.location});
437  }
438 
439  return make_pair(init_code, main_arguments);
440 }
441 
444  const symbolt &function,
445  const exprt::operandst &main_arguments,
446  symbol_table_baset &symbol_table)
447 {
448  code_blockt init_code;
449 
450  if(auto return_value = record_return_value(function, symbol_table))
451  {
452  init_code.add(std::move(*return_value));
453  }
454 
455  init_code.append(
456  record_pointer_parameters(function, main_arguments, symbol_table));
457 
458  init_code.add(record_exception(function, symbol_table));
459 
460  return init_code;
461 }
462 
464  const symbolt &function,
465  const symbol_table_baset &symbol_table)
466 {
467  if(to_java_method_type(function.type).return_type() == java_void_type())
468  return {};
469 
470  const symbolt &return_symbol =
472 
473  return code_outputt{
474  return_symbol.base_name, return_symbol.symbol_expr(), function.location};
475 }
476 
478  const symbolt &function,
479  const std::vector<exprt> &arguments,
480  const symbol_table_baset &symbol_table)
481 {
482  const java_method_typet::parameterst &parameters =
483  to_java_method_type(function.type).parameters();
484 
485  code_blockt init_code;
486 
487  for(std::size_t param_number = 0; param_number < parameters.size();
488  param_number++)
489  {
490  const symbolt &p_symbol =
491  symbol_table.lookup_ref(parameters[param_number].get_identifier());
492 
493  if(!can_cast_type<pointer_typet>(p_symbol.type))
494  continue;
495 
496  init_code.add(code_outputt{
497  p_symbol.base_name, arguments[param_number], function.location});
498  }
499  return init_code;
500 }
501 
503  const symbolt &function,
504  const symbol_table_baset &symbol_table)
505 {
506  // retrieve the exception variable
507  const symbolt &exc_symbol =
509 
510  // record exceptional return variable as output
511  return code_outputt{
512  exc_symbol.base_name, exc_symbol.symbol_expr(), function.location};
513 }
514 
516  const symbol_table_baset &symbol_table,
517  const irep_idt &main_class,
518  message_handlert &message_handler)
519 {
520  messaget message(message_handler);
521 
522  // find main symbol
523  if(config.main.has_value())
524  {
525  std::string error_message;
526  irep_idt main_symbol_id = resolve_friendly_method_name(
527  config.main.value(), symbol_table, error_message);
528 
529  if(main_symbol_id.empty())
530  {
531  message.error()
532  << "main symbol resolution failed: " << error_message << messaget::eom;
534  }
535 
536  const symbolt *symbol = symbol_table.lookup(main_symbol_id);
537  INVARIANT(
538  symbol != nullptr,
539  "resolve_friendly_method_name should return a symbol-table identifier");
540 
541  return *symbol; // Return found function
542  }
543  else
544  {
545  // are we given a main class?
546  if(main_class.empty())
547  {
548  // no, but we allow this situation to output symbol table,
549  // goto functions, etc
551  }
552 
553  std::string entry_method =
554  "java::" + id2string(main_class) + "." + JAVA_MAIN_METHOD;
555  const symbolt *symbol = symbol_table.lookup(entry_method);
556 
557  // has the class a correct main method?
558  if(!symbol || !is_java_main(*symbol))
559  {
560  // no, but we allow this situation to output symbol table,
561  // goto functions, etc
563  }
564 
565  return *symbol;
566  }
567 }
568 
570  symbol_table_baset &symbol_table,
571  const irep_idt &main_class,
572  message_handlert &message_handler,
573  bool assume_init_pointers_not_null,
574  bool assert_uncaught_exceptions,
575  const java_object_factory_parameterst &object_factory_parameters,
576  const select_pointer_typet &pointer_type_selector,
577  bool string_refinement_enabled,
578  const build_argumentst &build_arguments)
579 {
580  // check if the entry point is already there
581  if(symbol_table.symbols.find(goto_functionst::entry_point())!=
582  symbol_table.symbols.end())
583  return false; // silently ignore
584 
585  messaget message(message_handler);
587  get_main_symbol(symbol_table, main_class, message_handler);
588  if(!res.is_success())
589  return true;
590  symbolt symbol=res.main_function;
591 
592  assert(symbol.type.id()==ID_code);
593 
595  symbol,
596  symbol_table,
597  message_handler,
598  assert_uncaught_exceptions,
599  object_factory_parameters,
600  pointer_type_selector,
601  build_arguments);
602 }
603 
605  const symbolt &symbol,
606  symbol_table_baset &symbol_table,
607  message_handlert &message_handler,
608  bool assert_uncaught_exceptions,
609  const java_object_factory_parameterst &object_factory_parameters,
610  const select_pointer_typet &pointer_type_selector,
611  const build_argumentst &build_arguments)
612 {
613  messaget message(message_handler);
614  code_blockt init_code;
615 
616  // build call to initialization function
617  {
618  symbol_tablet::symbolst::const_iterator init_it=
619  symbol_table.symbols.find(INITIALIZE_FUNCTION);
620 
621  if(init_it==symbol_table.symbols.end())
622  {
623  message.error() << "failed to find " INITIALIZE_FUNCTION " symbol"
624  << messaget::eom;
625  return true; // give up with error
626  }
627 
628  code_function_callt call_init(init_it->second.symbol_expr());
629  call_init.add_source_location()=symbol.location;
630 
631  init_code.add(std::move(call_init));
632  }
633 
634  // build call to the main method, of the form
635  // return = main_method(arg1, arg2, ..., argn)
636  // where return is a new variable
637  // and arg1 ... argn are constructed below as well
638 
639  source_locationt loc=symbol.location;
640  loc.set_function(symbol.name);
641  source_locationt &dloc=loc;
642 
643  // function to call
644  code_function_callt call_main(symbol.symbol_expr());
645  call_main.add_source_location()=dloc;
646  call_main.function().add_source_location()=dloc;
647 
648  // if the method return type is not void, store return value in a new variable
649  // named 'return'
651  {
652  auxiliary_symbolt return_symbol;
653  return_symbol.mode=ID_java;
654  return_symbol.is_static_lifetime=false;
655  return_symbol.name=JAVA_ENTRY_POINT_RETURN_SYMBOL;
656  return_symbol.base_name = "return'";
657  return_symbol.type = to_java_method_type(symbol.type).return_type();
658 
659  symbol_table.add(return_symbol);
660  call_main.lhs()=return_symbol.symbol_expr();
661  }
662 
663  // add the exceptional return value
664  auxiliary_symbolt exc_symbol;
665  exc_symbol.mode=ID_java;
667  exc_symbol.base_name=exc_symbol.name;
668  exc_symbol.type = java_reference_type(java_void_type());
669  symbol_table.add(exc_symbol);
670 
671  // Zero-initialise the top-level exception catch variable:
672  init_code.add(code_assignt(
673  exc_symbol.symbol_expr(),
674  null_pointer_exprt(to_pointer_type(exc_symbol.type))));
675 
676  // create code that allocates the objects used as test arguments and
677  // non-deterministically initializes them
678  const std::pair<code_blockt, std::vector<exprt>> main_arguments =
679  build_arguments(symbol, symbol_table);
680  init_code.append(main_arguments.first);
681  call_main.arguments() = main_arguments.second;
682 
683  // Create target labels for the toplevel exception handler:
684  code_labelt toplevel_catch("toplevel_catch", code_skipt());
685  code_labelt after_catch("after_catch", code_skipt());
686 
687  code_blockt call_block;
688 
689  // Push a universal exception handler:
690  // Catch all exceptions:
691  // This is equivalent to catching Throwable, but also works if some of
692  // the class hierarchy is missing so that we can't determine that
693  // the thrown instance is an indirect child of Throwable
694  code_push_catcht push_universal_handler(
695  irep_idt(), toplevel_catch.get_label());
696  irept catch_type_list(ID_exception_list);
697  irept catch_target_list(ID_label);
698 
699  call_block.add(std::move(push_universal_handler));
700 
701  // we insert the call to the method AFTER the argument initialization code
702  call_block.add(std::move(call_main));
703 
704  // Pop the handler:
705  code_pop_catcht pop_handler;
706  call_block.add(std::move(pop_handler));
707  init_code.add(std::move(call_block));
708 
709  // Normal return: skip the exception handler:
710  init_code.add(code_gotot(after_catch.get_label()));
711 
712  // Exceptional return: catch and assign to exc_symbol.
713  code_landingpadt landingpad(exc_symbol.symbol_expr());
714  init_code.add(std::move(toplevel_catch));
715  init_code.add(std::move(landingpad));
716 
717  // Converge normal and exceptional return:
718  init_code.add(std::move(after_catch));
719 
720  // Mark return value, pointer type parameters and the exception as outputs.
721  init_code.append(
722  java_record_outputs(symbol, main_arguments.second, symbol_table));
723 
724  // add uncaught-exception check if requested
725  if(assert_uncaught_exceptions)
726  {
728  init_code, exc_symbol, symbol.location);
729  }
730 
731  // create a symbol for the __CPROVER__start function, associate the code that
732  // we just built and register it in the symbol table
733  symbolt new_symbol;
734 
735  new_symbol.name=goto_functionst::entry_point();
736  new_symbol.type = java_method_typet({}, java_void_type());
737  new_symbol.value.swap(init_code);
738  new_symbol.mode=ID_java;
739 
740  if(!symbol_table.insert(std::move(new_symbol)).second)
741  {
742  message.error() << "failed to move main symbol" << messaget::eom;
743  return true;
744  }
745 
746  return false;
747 }
@ DYNAMIC
Allocate dynamic objects (using ALLOCATE)
@ STATIC_GLOBAL
Allocate global objects with static lifetime.
constant_exprt from_integer(const mp_integer &int_value, const typet &type)
Definition: arith_tools.cpp:99
static symbolt result_symbol(const irep_idt &identifier, const typet &type, const source_locationt &source_location, symbol_tablet &symbol_table)
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.
Extract class identifier.
Internally generated symbol table entryThis is a symbol generated as part of translation to or modifi...
Definition: symbol.h:147
A codet representing an assignment in the program.
Definition: std_code.h:295
A codet representing sequential composition of program statements.
Definition: std_code.h:170
void append(const code_blockt &extra_block)
Add all the codets from extra_block to the current code_blockt.
Definition: std_code.cpp:88
void add(const codet &code)
Definition: std_code.h:208
A codet representing the declaration of a local variable.
Definition: std_code.h:402
codet representation of a function call statement.
Definition: std_code.h:1215
exprt & function()
Definition: std_code.h:1250
argumentst & arguments()
Definition: std_code.h:1260
codet representation of a goto statement.
Definition: std_code.h:1159
A codet representing the declaration that an input of a particular description has a value which corr...
Definition: std_code.h:677
codet representation of a label for branch targets.
Definition: std_code.h:1407
const irep_idt & get_label() const
Definition: std_code.h:1415
A statement that catches an exception, assigning the exception in flight to an expression (e....
Definition: std_code.h:2384
A codet representing the declaration that an output of a particular description has a value which cor...
Definition: std_code.h:724
Pops an exception handler from the stack of active handlers (i.e.
Definition: std_code.h:2347
Pushes an exception handler, of the form: exception_tag1 -> label1 exception_tag2 -> label2 ....
Definition: std_code.h:2253
A codet representing a skip statement.
Definition: std_code.h:270
const irep_idt & get_base_name() const
Definition: std_types.h:800
const irep_idt & get_identifier() const
Definition: std_types.h:795
const typet & return_type() const
Definition: std_types.h:850
bool has_this() const
Definition: std_types.h:821
bool get_is_constructor() const
Definition: std_types.h:890
const parameterst & parameters() const
Definition: std_types.h:860
Data structure for representing an arbitrary statement in a program.
Definition: std_code.h:35
optionalt< std::string > main
Definition: config.h:261
A constant literal expression.
Definition: std_expr.h:2668
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
bool empty() const
Definition: dstring.h:88
size_t size() const
Definition: dstring.h:104
Base class for all expressions.
Definition: expr.h:54
std::vector< exprt > operandst
Definition: expr.h:56
source_locationt & add_source_location()
Definition: expr.h:239
typet & type()
Return the type of the expression.
Definition: expr.h:82
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition: irep.h:383
bool get_bool(const irep_namet &name) const
Definition: irep.cpp:64
bool is_not_nil() const
Definition: irep.h:391
const irep_idt & id() const
Definition: irep.h:407
void swap(irept &irep)
Definition: irep.h:452
const irep_idt & get(const irep_namet &name) const
Definition: irep.cpp:51
bool is_nil() const
Definition: irep.h:387
std::vector< parametert > parameterst
Definition: std_types.h:746
A symbol table wrapper that records which entries have been updated/removedA caller can pass a journa...
static journalling_symbol_tablet wrap(symbol_table_baset &base_symbol_table)
const changesett & get_inserted() const
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:155
static eomt eom
Definition: message.h:297
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:92
The null pointer constant.
Definition: std_expr.h:2751
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.
A side_effect_exprt that returns a non-deterministically chosen value.
Definition: std_code.h:1968
An expression containing a side effect.
Definition: std_code.h:1898
void set_function(const irep_idt &function)
A struct tag type, i.e., struct_typet with an identifier.
Definition: std_types.h:498
irep_idt get_tag() const
Definition: std_types.h:163
Expression to hold a symbol (variable)
Definition: std_expr.h:81
The symbol table base class interface.
bool remove(const irep_idt &name)
Remove a symbol from the symbol table.
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
virtual std::pair< symbolt &, bool > insert(symbolt symbol)=0
Move or copy a new symbol to the symbol table.
Symbol table entry.
Definition: symbol.h:28
irep_idt base_name
Base (non-scoped) name.
Definition: symbol.h:46
bool is_static_lifetime
Definition: symbol.h:65
source_locationt location
Source code location of definition of symbol.
Definition: symbol.h:37
bool is_state_var
Definition: symbol.h:62
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
Definition: symbol.cpp:122
typet type
Type of symbol.
Definition: symbol.h:31
irep_idt name
The unique identifier.
Definition: symbol.h:40
bool is_lvalue
Definition: symbol.h:66
exprt value
Initial value of symbol.
Definition: symbol.h:34
irep_idt mode
Language mode.
Definition: symbol.h:49
Semantic type conversion.
Definition: std_expr.h:1781
configt config
Definition: config.cpp:24
#define CPROVER_PREFIX
optionalt< exprt > zero_initializer(const typet &type, const source_locationt &source_location, const namespacet &ns)
Create the equivalent of zero for type type.
Expression Initialization.
Fresh auxiliary symbol creation.
Goto Programs with Functions.
dstringt irep_idt
Definition: irep.h:37
const std::string & id2string(const irep_idt &d)
Definition: irep.h:49
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...
#define JAVA_CLASS_MODEL_SUFFIX
static optionalt< codet > record_return_value(const symbolt &function, const symbol_table_baset &symbol_table)
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.
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__...
bool is_java_main(const symbolt &function)
Checks whether the given symbol is a valid java main method i.e.
#define JAVA_MAIN_METHOD
static constant_exprt constant_bool(bool val)
void create_java_initialize(symbol_table_baset &symbol_table)
Adds __cprover_initialize to the symbol_table but does not generate code for it yet.
static bool should_init_symbol(const symbolt &sym)
static codet record_exception(const symbolt &function, const symbol_table_baset &symbol_table)
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.
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.
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)
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...
static code_blockt record_pointer_parameters(const symbolt &function, const std::vector< exprt > &arguments, const symbol_table_baset &symbol_table)
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.
irep_idt get_java_class_literal_initializer_signature()
Get the symbol name of java.lang.Class' initializer method.
#define JAVA_ENTRY_POINT_RETURN_SYMBOL
#define JAVA_ENTRY_POINT_EXCEPTION_SYMBOL
std::function< std::pair< code_blockt, std::vector< exprt > >(const symbolt &function, symbol_table_baset &symbol_table)> build_argumentst
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...
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...
This module is responsible for the synthesis of code (in the form of a sequence of codet statements) ...
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.
signedbv_typet java_int_type()
Definition: java_types.cpp:32
empty_typet java_void_type()
Definition: java_types.cpp:38
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
reference_typet java_reference_type(const typet &subtype)
Definition: java_types.cpp:89
c_bool_typet java_boolean_type()
Definition: java_types.cpp:80
bool is_java_array_tag(const irep_idt &tag)
See above.
Definition: java_types.cpp:232
const java_class_typet & to_java_class_type(const typet &type)
Definition: java_types.h:584
const java_method_typet & to_java_method_type(const typet &type)
Definition: java_types.h:186
bool is_java_string_literal_id(const irep_idt &id)
Definition: java_utils.cpp:209
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:522
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:558
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:214
Author: Diffblue Ltd.
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
nonstd::optional< T > optionalt
Definition: optional.h:35
#define PRECONDITION(CONDITION)
Definition: invariant.h:464
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition: invariant.h:424
#define INITIALIZE_FUNCTION
static const char * message(const statust &status)
Makes a status message string from a status.
const struct_exprt & to_struct_expr(const exprt &expr)
Cast an exprt to a struct_exprt.
Definition: std_expr.h:1606
const class_typet & to_class_type(const typet &type)
Cast a typet to a class_typet.
Definition: std_types.h:376
bool can_cast_type< pointer_typet >(const typet &type)
Check whether a reference to a typet is a pointer_typet.
Definition: std_types.h:1520
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
Definition: std_types.h:1533
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
Definition: std_types.h:523
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
irep_idt function_id
Function id, used as a prefix for identifiers of temporaries.
std::list< std::string > string_input_values
Force one of finitely many explicitly given input strings.
size_t min_null_tree_depth
To force a certain depth of non-null objects.
bool has_suffix(const std::string &s, const std::string &suffix)
Definition: suffix.h:17