cprover
Loading...
Searching...
No Matches
java_entry_point.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9#include "java_entry_point.h"
10
11#include <util/config.h>
14#include <util/suffix.h>
15
19
21
24#include "java_object_factory.h"
26#include "java_types.h"
27#include "java_utils.h"
28#include "nondet.h"
29
30#include <cstring>
31
32#define JAVA_MAIN_METHOD "main:([Ljava/lang/String;)V"
33
35 const symbolt &function,
36 const symbol_table_baset &symbol_table);
37
39 const symbolt &function,
40 const std::vector<exprt> &arguments,
41 const symbol_table_baset &symbol_table);
42
44 const symbolt &function,
45 const symbol_table_baset &symbol_table);
46
48{
49 // If __CPROVER_initialize already exists, replace it. It may already exist
50 // if a GOTO binary provided it. This behaviour mirrors the ANSI-C frontend.
51 symbol_table.remove(INITIALIZE_FUNCTION);
52
53 symbolt initialize{
55 initialize.base_name=INITIALIZE_FUNCTION;
56
57 symbol_table.add(initialize);
58}
59
60static bool should_init_symbol(const symbolt &sym)
61{
62 if(sym.type.id()!=ID_code &&
63 sym.is_lvalue &&
64 sym.is_state_var &&
65 sym.is_static_lifetime &&
66 sym.mode==ID_java)
67 {
68 // Consider some sort of annotation indicating a global variable that
69 // doesn't require initialisation?
70 return !sym.type.get_bool(ID_C_no_initialization_required);
71 }
72
73 return is_java_string_literal_id(sym.name);
74}
75
77{
78 static irep_idt signature =
79 "java::java.lang.Class.cproverInitializeClassLiteral:"
80 "(Ljava/lang/String;ZZZZZZZ)V";
81 return signature;
82}
83
90 const symbolt &symbol,
91 const symbol_table_baset &symbol_table)
92{
93 if(symbol.value.is_not_nil())
94 return nullptr;
95 if(symbol.type != struct_tag_typet("java::java.lang.Class"))
96 return nullptr;
98 return nullptr;
100}
101
103{
104 return from_integer(val ? 1 : 0, java_boolean_type());
105}
106
107static std::unordered_set<irep_idt> init_symbol(
108 const symbolt &sym,
110 symbol_table_baset &symbol_table,
111 const source_locationt &source_location,
113 const java_object_factory_parameterst &object_factory_parameters,
114 const select_pointer_typet &pointer_type_selector,
115 bool string_refinement_enabled,
116 message_handlert &message_handler)
117{
118 std::unordered_set<irep_idt> additional_symbols;
119
120 if(
122 get_class_literal_initializer(sym, symbol_table))
123 {
124 const std::string &name_str = id2string(sym.name);
125 irep_idt class_name =
126 name_str.substr(0, name_str.size() - strlen(JAVA_CLASS_MODEL_SUFFIX));
127 const symbolt &class_symbol = symbol_table.lookup_ref(class_name);
128
130
133
135 to_class_type(class_symbol.type).get_tag(),
137 string_refinement_enabled);
138
139 // If that created any new symbols make sure we initialise those too:
140 additional_symbols = journalling_table.get_inserted();
141
142 // Call the literal initializer method instead of a nondet initializer:
143
144 // For arguments we can't parse yet:
146
148
149 // Argument order is: name, isAnnotation, isArray, isInterface,
150 // isSynthetic, isLocalClass, isMemberClass, isEnum
151
153 class_literal_init_method->symbol_expr(),
154 {// this:
155 address_of_exprt(sym.symbol_expr()),
156 // name:
157 address_of_exprt(class_name_literal),
158 // isAnnotation:
159 constant_bool(java_class_type.get_is_annotation()),
160 // isArray:
161 constant_bool(class_is_array),
162 // isInterface:
163 constant_bool(java_class_type.get_interface()),
164 // isSynthetic:
165 constant_bool(java_class_type.get_synthetic()),
166 // isLocalClass:
167 nondet_bool,
168 // isMemberClass:
169 nondet_bool,
170 // isEnum:
171 constant_bool(java_class_type.get_is_enumeration())});
172
173 // First initialize the object as prior to a constructor:
174 namespacet ns(symbol_table);
175
177 if(!zero_object.has_value())
178 {
179 messaget message(message_handler);
180 message.error() << "failed to zero-initialize " << sym.name
181 << messaget::eom;
182 throw 0;
183 }
186
187 code_block.add(
188 std::move(code_frontend_assignt(sym.symbol_expr(), *zero_object)));
189
190 // Then call the init function:
191 code_block.add(std::move(initializer_call));
192 }
193 else if(sym.value.is_nil() && sym.type != java_void_type())
194 {
195 const bool is_class_model = has_suffix(id2string(sym.name), "@class_model");
196 const bool not_allow_null = is_java_string_literal_id(sym.name) ||
199
200 java_object_factory_parameterst parameters = object_factory_parameters;
202 parameters.min_null_tree_depth = 1;
203
205 sym.symbol_expr(),
207 symbol_table,
208 source_location,
209 false,
211 parameters,
212 pointer_type_selector,
214 message_handler);
215 }
216 else if(sym.value.is_not_nil())
217 {
218 code_frontend_assignt assignment(sym.symbol_expr(), sym.value);
219 assignment.add_source_location() = source_location;
220 code_block.add(assignment);
221 }
222
223 return additional_symbols;
224}
225
227 symbol_table_baset &symbol_table,
228 const source_locationt &source_location,
230 java_object_factory_parameterst object_factory_parameters,
231 const select_pointer_typet &pointer_type_selector,
232 bool string_refinement_enabled,
233 message_handlert &message_handler)
234{
237 PRECONDITION(initialize_symbol.value.is_nil());
239
240 const symbol_exprt rounding_mode =
241 symbol_table.lookup_ref(rounding_mode_identifier()).symbol_expr();
242 code_block.add(code_frontend_assignt{rounding_mode,
243 from_integer(0, rounding_mode.type())});
244
245 object_factory_parameters.function_id = initialize_symbol.name;
246
247 // If there are strings given using --string-input-value, we need to add
248 // them to the symbol table now, so that they appear in __CPROVER_initialize
249 // and we can refer to them later when we initialize input values.
250 for(const auto &val : object_factory_parameters.string_input_values)
251 {
252 // We ignore the return value of the following call, we just need to
253 // make sure the string is in the symbol table.
255 val, symbol_table, string_refinement_enabled);
256 }
257
258 // We need to zero out all static variables, or nondet-initialize if they're
259 // external. Iterate over a copy of the symtab, as its iterators are
260 // invalidated by object_factory:
261
262 // sort alphabetically for reproducible results
263 std::set<std::string> symbol_names;
264 for(const auto &entry : symbol_table.symbols)
265 symbol_names.insert(id2string(entry.first));
266
267 std::set<std::string> additional_symbols;
268 while(!symbol_names.empty() || !additional_symbols.empty())
269 {
270 if(!additional_symbols.empty())
272
273 for(const auto &symbol_name : symbol_names)
274 {
275 const symbolt &sym = symbol_table.lookup_ref(symbol_name);
277 {
279 sym,
281 symbol_table,
282 source_location,
284 object_factory_parameters,
285 pointer_type_selector,
286 string_refinement_enabled,
287 message_handler);
288 for(const auto &new_symbol_name : new_symbols)
290 }
291 }
292
294 }
295
296 initialize_symbol.value = std::move(code_block);
297}
298
304bool is_java_main(const symbolt &function)
305{
307 const java_method_typet &function_type = to_java_method_type(function.type);
308 const auto string_array_type = java_type_from_string("[Ljava/lang/String;");
309 // checks whether the function is static and has a single String[] parameter
310 bool is_static = !function_type.has_this();
311 // this should be implied by the signature
312 const java_method_typet::parameterst &parameters = function_type.parameters();
313 bool has_correct_type = function_type.return_type().id() == ID_empty &&
314 parameters.size() == 1 &&
315 parameters[0].type().full_eq(*string_array_type);
316 bool public_access = function_type.get(ID_access) == ID_public;
317 return named_main && is_static && has_correct_type && public_access;
318}
319
320std::pair<code_blockt, std::vector<exprt>> java_build_arguments(
321 const symbolt &function,
322 symbol_table_baset &symbol_table,
324 java_object_factory_parameterst object_factory_parameters,
325 const select_pointer_typet &pointer_type_selector,
326 message_handlert &message_handler)
327{
328 const java_method_typet &function_type = to_java_method_type(function.type);
329 const java_method_typet::parameterst &parameters = function_type.parameters();
330
333 main_arguments.resize(parameters.size());
334
335 // certain method arguments cannot be allowed to be null, we set the following
336 // variable to true iff the method under test is the "main" method, which will
337 // be called (by the jvm) with arguments that are never null
338 bool is_main = is_java_main(function);
339
340 // we iterate through all the parameters of the function under test, allocate
341 // an object for that parameter (recursively allocating other objects
342 // necessary to initialize it), and mark such object using `code_inputt`.
343 for(std::size_t param_number=0;
344 param_number<parameters.size();
345 param_number++)
346 {
347 const java_method_typet::parametert &p = parameters[param_number];
348 const irep_idt base_name=p.get_base_name().empty()?
349 ("argument#"+std::to_string(param_number)):p.get_base_name();
350
351 // true iff this parameter is the `this` pointer of the method, which cannot
352 // be null
353 bool is_this=(param_number==0) && parameters[param_number].get_this();
354
355 if(is_this && function_type.get_is_constructor())
356 {
357 const symbol_exprt result = fresh_java_symbol(
358 p.type(),
359 "this_parameter",
360 function.location,
361 function.name,
362 symbol_table)
363 .symbol_expr();
365 init_code.add(code_declt{result});
367 result,
368 side_effect_exprt{ID_java_new, {}, p.type(), function.location}});
369 continue;
370 }
371
373 object_factory_parameters;
374 // only pointer must be non-null
376 factory_parameters.min_null_tree_depth = 1;
377 // in main() also the array elements of the argument must be non-null
378 if(is_main)
379 factory_parameters.min_null_tree_depth = 2;
380
382
383 namespacet ns(symbol_table);
384
385 // Generate code to allocate and non-deterministicaly initialize the
386 // argument, if the argument has different possible object types (e.g., from
387 // casts in the function body), then choose one in a non-deterministic way.
388 const auto alternatives =
389 pointer_type_selector.get_parameter_alternative_types(
390 function.name, p.get_identifier(), ns);
391 if(alternatives.empty())
392 {
394 p.type(),
395 base_name,
396 init_code,
397 symbol_table,
400 function.location,
401 pointer_type_selector,
402 message_handler);
403 }
404 else
405 {
406 INVARIANT(!is_this, "We cannot have different types for `this` here");
407 // create a non-deterministic switch between all possible values for the
408 // type of the parameter.
409
410 // the idea is to get a new symbol for the parameter value `tmp`
411
412 // then add a non-deterministic switch over all possible input types,
413 // construct the object type at hand and assign to `tmp`
414
415 // switch(...)
416 // {
417 // case obj1:
418 // tmp_expr = object_factory(...)
419 // param = tmp_expr
420 // break
421 // ...
422 // }
423 // method(..., param, ...)
424 //
425
427 p.type(),
428 "nondet_parameter_" + std::to_string(param_number),
429 function.location,
430 function.name,
431 symbol_table);
433
434 std::vector<codet> cases;
435 cases.reserve(alternatives.size());
436 for(const auto &type : alternatives)
437 {
441 id2string(base_name) + "_alternative_" +
442 id2string(type.get_identifier()),
444 symbol_table,
447 function.location,
448 pointer_type_selector,
449 message_handler);
451 result_symbol.symbol_expr(),
453 cases.push_back(init_code_for_type);
454 }
455
456 init_code.add(
458 id2string(function.name) + "_" + std::to_string(param_number),
459 cases,
461 ID_java,
462 function.location,
463 symbol_table));
464 }
465
466 // record as an input
467 init_code.add(
468 code_inputt{base_name, main_arguments[param_number], function.location});
469 }
470
472}
473
476 const symbolt &function,
478 symbol_table_baset &symbol_table)
479{
481
482 if(auto return_value = record_return_value(function, symbol_table))
483 {
484 init_code.add(std::move(*return_value));
485 }
486
487 init_code.append(
488 record_pointer_parameters(function, main_arguments, symbol_table));
489
490 init_code.add(record_exception(function, symbol_table));
491
492 return init_code;
493}
494
496 const symbolt &function,
497 const symbol_table_baset &symbol_table)
498{
499 if(to_java_method_type(function.type).return_type() == java_void_type())
500 return {};
501
502 const symbolt &return_symbol =
504
505 return code_outputt{
506 return_symbol.base_name, return_symbol.symbol_expr(), function.location};
507}
508
510 const symbolt &function,
511 const std::vector<exprt> &arguments,
512 const symbol_table_baset &symbol_table)
513{
514 const java_method_typet::parameterst &parameters =
515 to_java_method_type(function.type).parameters();
516
518
519 for(std::size_t param_number = 0; param_number < parameters.size();
520 param_number++)
521 {
522 const symbolt &p_symbol =
523 symbol_table.lookup_ref(parameters[param_number].get_identifier());
524
526 continue;
527
529 p_symbol.base_name, arguments[param_number], function.location});
530 }
531 return init_code;
532}
533
535 const symbolt &function,
536 const symbol_table_baset &symbol_table)
537{
538 // retrieve the exception variable
539 const symbolt &exc_symbol =
541
542 // record exceptional return variable as output
543 return code_outputt{
544 exc_symbol.base_name, exc_symbol.symbol_expr(), function.location};
545}
546
548 const symbol_table_baset &symbol_table,
549 const irep_idt &main_class,
550 message_handlert &message_handler)
551{
552 messaget message(message_handler);
553
554 // find main symbol
555 if(config.main.has_value())
556 {
557 std::string error_message;
559 config.main.value(), symbol_table, error_message);
560
561 if(main_symbol_id.empty())
562 {
563 message.error()
564 << "main symbol resolution failed: " << error_message << messaget::eom;
566 }
567
568 const symbolt *symbol = symbol_table.lookup(main_symbol_id);
569 INVARIANT(
570 symbol != nullptr,
571 "resolve_friendly_method_name should return a symbol-table identifier");
572
573 return *symbol; // Return found function
574 }
575 else
576 {
577 // are we given a main class?
578 if(main_class.empty())
579 {
580 // no, but we allow this situation to output symbol table,
581 // goto functions, etc
583 }
584
585 std::string entry_method =
586 "java::" + id2string(main_class) + "." + JAVA_MAIN_METHOD;
587 const symbolt *symbol = symbol_table.lookup(entry_method);
588
589 // has the class a correct main method?
590 if(!symbol || !is_java_main(*symbol))
591 {
592 // no, but we allow this situation to output symbol table,
593 // goto functions, etc
595 }
596
597 return *symbol;
598 }
599}
600
602 symbol_table_baset &symbol_table,
603 const irep_idt &main_class,
604 message_handlert &message_handler,
606 bool assert_uncaught_exceptions,
607 const java_object_factory_parameterst &object_factory_parameters,
608 const select_pointer_typet &pointer_type_selector,
609 bool string_refinement_enabled,
611{
612 // check if the entry point is already there
613 if(symbol_table.symbols.find(goto_functionst::entry_point())!=
614 symbol_table.symbols.end())
615 return false; // silently ignore
616
617 messaget message(message_handler);
619 get_main_symbol(symbol_table, main_class, message_handler);
620 if(!res.is_success())
621 return true;
622 symbolt symbol=res.main_function;
623
624 DATA_INVARIANT(symbol.type.id() == ID_code, "expected code-typed symbol");
625
627 symbol,
628 symbol_table,
629 message_handler,
630 assert_uncaught_exceptions,
631 object_factory_parameters,
632 pointer_type_selector,
634}
635
637 const symbolt &symbol,
638 symbol_table_baset &symbol_table,
639 message_handlert &message_handler,
640 bool assert_uncaught_exceptions,
641 const java_object_factory_parameterst &object_factory_parameters,
642 const select_pointer_typet &pointer_type_selector,
644{
645 messaget message(message_handler);
647
648 // build call to initialization function
649 {
650 symbol_table_baset::symbolst::const_iterator init_it =
651 symbol_table.symbols.find(INITIALIZE_FUNCTION);
652
653 if(init_it==symbol_table.symbols.end())
654 {
655 message.error() << "failed to find " INITIALIZE_FUNCTION " symbol"
656 << messaget::eom;
657 return true; // give up with error
658 }
659
660 code_function_callt call_init(init_it->second.symbol_expr());
661 call_init.add_source_location()=symbol.location;
662
663 init_code.add(std::move(call_init));
664 }
665
666 // build call to the main method, of the form
667 // return = main_method(arg1, arg2, ..., argn)
668 // where return is a new variable
669 // and arg1 ... argn are constructed below as well
670
671 source_locationt loc=symbol.location;
672 loc.set_function(symbol.name);
674
675 // function to call
677 call_main.add_source_location()=dloc;
678 call_main.function().add_source_location()=dloc;
679
680 // if the method return type is not void, store return value in a new variable
681 // named 'return'
682 if(to_java_method_type(symbol.type).return_type() != java_void_type())
683 {
686 return_symbol.is_static_lifetime=false;
688 return_symbol.base_name = "return'";
689 return_symbol.type = to_java_method_type(symbol.type).return_type();
690
691 symbol_table.add(return_symbol);
692 call_main.lhs()=return_symbol.symbol_expr();
693 }
694
695 // add the exceptional return value
697 exc_symbol.mode=ID_java;
699 exc_symbol.base_name=exc_symbol.name;
701 symbol_table.add(exc_symbol);
702
703 // Zero-initialise the top-level exception catch variable:
705 exc_symbol.symbol_expr(),
707
708 // create code that allocates the objects used as test arguments and
709 // non-deterministically initializes them
710 const std::pair<code_blockt, std::vector<exprt>> main_arguments =
711 build_arguments(symbol, symbol_table);
712 init_code.append(main_arguments.first);
713 call_main.arguments() = main_arguments.second;
714
715 // Create target labels for the toplevel exception handler:
716 code_labelt toplevel_catch("toplevel_catch", code_skipt());
717 code_labelt after_catch("after_catch", code_skipt());
718
720
721 // Push a universal exception handler:
722 // Catch all exceptions:
723 // This is equivalent to catching Throwable, but also works if some of
724 // the class hierarchy is missing so that we can't determine that
725 // the thrown instance is an indirect child of Throwable
727 irep_idt(), toplevel_catch.get_label());
730
731 call_block.add(std::move(push_universal_handler));
732
733 // we insert the call to the method AFTER the argument initialization code
734 call_block.add(std::move(call_main));
735
736 // Pop the handler:
738 call_block.add(std::move(pop_handler));
739 init_code.add(std::move(call_block));
740
741 // Normal return: skip the exception handler:
742 init_code.add(code_gotot(after_catch.get_label()));
743
744 // Exceptional return: catch and assign to exc_symbol.
746 init_code.add(std::move(toplevel_catch));
747 init_code.add(std::move(landingpad));
748
749 // Converge normal and exceptional return:
750 init_code.add(std::move(after_catch));
751
752 // Mark return value, pointer type parameters and the exception as outputs.
753 init_code.append(
754 java_record_outputs(symbol, main_arguments.second, symbol_table));
755
756 // add uncaught-exception check if requested
757 if(assert_uncaught_exceptions)
758 {
760 init_code, exc_symbol, symbol.location);
761 }
762
763 // create a symbol for the __CPROVER__start function, associate the code that
764 // we just built and register it in the symbol table
765 symbolt new_symbol{
768 ID_java};
769 new_symbol.base_name = goto_functionst::entry_point();
770 new_symbol.value.swap(init_code);
771
772 if(!symbol_table.insert(std::move(new_symbol)).second)
773 {
774 message.error() << "failed to move main symbol" << messaget::eom;
775 return true;
776 }
777
778 return false;
779}
irep_idt rounding_mode_identifier()
Return the identifier of the program symbol used to store the current rounding mode.
Symbolic Execution.
@ DYNAMIC
Allocate dynamic objects (using ALLOCATE)
@ STATIC_GLOBAL
Allocate global objects with static lifetime.
configt config
Definition config.cpp:25
constant_exprt from_integer(const mp_integer &int_value, const typet &type)
static symbolt result_symbol(const irep_idt &identifier, const typet &type, const source_locationt &source_location, symbol_table_baset &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.
virtual void clear()
Reset the abstract state.
Definition ai.h:266
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:563
Internally generated symbol table entryThis is a symbol generated as part of translation to or modifi...
Definition symbol.h:153
A codet representing sequential composition of program statements.
Definition std_code.h:130
A goto_instruction_codet representing the declaration of a local variable.
A codet representing an assignment in the program.
Definition std_code.h:24
goto_instruction_codet representation of a function call statement.
codet representation of a goto statement.
Definition std_code.h:841
A goto_instruction_codet representing the declaration that an input of a particular description has a...
codet representation of a label for branch targets.
Definition std_code.h:959
A statement that catches an exception, assigning the exception in flight to an expression (e....
Definition std_code.h:1936
A goto_instruction_codet representing the declaration that an output of a particular description has ...
Pops an exception handler from the stack of active handlers (i.e.
Definition std_code.h:1899
Pushes an exception handler, of the form: exception_tag1 -> label1 exception_tag2 -> label2 ....
Definition std_code.h:1805
A codet representing a skip statement.
Definition std_code.h:322
const irep_idt & get_base_name() const
Definition std_types.h:595
const irep_idt & get_identifier() const
Definition std_types.h:590
bool has_this() const
Definition std_types.h:616
const parameterst & parameters() const
Definition std_types.h:655
const typet & return_type() const
Definition std_types.h:645
bool get_is_constructor() const
Definition std_types.h:685
Data structure for representing an arbitrary statement in a program.
optionalt< std::string > main
Definition config.h:353
A constant literal expression.
Definition std_expr.h:2942
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:39
bool empty() const
Definition dstring.h:90
Base class for all expressions.
Definition expr.h:56
std::vector< exprt > operandst
Definition expr.h:58
typet & type()
Return the type of the expression.
Definition expr.h:84
source_locationt & add_source_location()
Definition expr.h:228
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:372
const irep_idt & get(const irep_idt &name) const
Definition irep.cpp:44
bool is_not_nil() const
Definition irep.h:380
const irep_idt & id() const
Definition irep.h:396
std::vector< parametert > parameterst
Definition std_types.h:542
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)
Class that provides messages with a built-in verbosity 'level'.
Definition message.h:155
mstreamt & error() const
Definition message.h:399
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:91
The null pointer constant.
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:1520
An expression containing a side effect.
Definition std_code.h:1450
void set_function(const irep_idt &function)
A struct tag type, i.e., struct_typet with an identifier.
Definition std_types.h:449
Expression to hold a symbol (variable)
Definition std_expr.h:113
The symbol table base class interface.
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
bool remove(const irep_idt &name)
Remove a symbol from the symbol table.
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
virtual std::pair< symbolt &, bool > insert(symbolt symbol)=0
Move or copy a new symbol to the symbol table.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
Symbol table entry.
Definition symbol.h:28
source_locationt location
Source code location of definition of symbol.
Definition symbol.h:37
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
Definition symbol.cpp:121
typet type
Type of symbol.
Definition symbol.h:31
irep_idt name
The unique identifier.
Definition symbol.h:40
exprt value
Initial value of symbol.
Definition symbol.h:34
Semantic type conversion.
Definition std_expr.h:2017
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.
Goto Programs with Functions.
const std::string & id2string(const irep_idt &d)
Definition irep.h:47
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.
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.
static std::unordered_set< irep_idt > init_symbol(const symbolt &sym, code_blockt &code_block, symbol_table_baset &symbol_table, const source_locationt &source_location, bool assume_init_pointers_not_null, const java_object_factory_parameterst &object_factory_parameters, const select_pointer_typet &pointer_type_selector, bool string_refinement_enabled, message_handlert &message_handler)
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...
std::function< std::pair< code_blockt, std::vector< exprt > >( const symbolt &function, symbol_table_baset &symbol_table)> build_argumentst
#define JAVA_ENTRY_POINT_RETURN_SYMBOL
#define JAVA_ENTRY_POINT_EXCEPTION_SYMBOL
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()
empty_typet java_void_type()
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.
reference_typet java_reference_type(const typet &subtype)
c_bool_typet java_boolean_type()
bool is_java_array_tag(const irep_idt &tag)
See above.
const java_method_typet & to_java_method_type(const typet &type)
Definition java_types.h:184
const java_class_typet & to_java_class_type(const typet &type)
Definition java_types.h:582
bool is_java_string_literal_id(const irep_idt &id)
bool is_non_null_library_global(const irep_idt &symbolid)
Check if a symbol is a well-known non-null global.
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...
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)
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:91
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition invariant.h:534
#define PRECONDITION(CONDITION)
Definition invariant.h:463
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423
#define INITIALIZE_FUNCTION
const struct_exprt & to_struct_expr(const exprt &expr)
Cast an exprt to a struct_exprt.
Definition std_expr.h:1842
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
Definition std_types.h:474
const class_typet & to_class_type(const typet &type)
Cast a typet to a class_typet.
Definition std_types.h:381
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
dstringt irep_idt