Go to the documentation of this file.
10 #ifndef CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_LANGUAGE_H
11 #define CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_LANGUAGE_H
31 #define JAVA_BYTECODE_LANGUAGE_OPTIONS \
32 "(disable-uncaught-exception-check)" \
33 "(throw-assertion-error)" \
34 "(assert-no-exceptions-thrown)" \
35 "(java-assume-inputs-non-null)" \
36 "(java-assume-inputs-interval):" \
37 "(java-assume-inputs-integral)" \
38 "(throw-runtime-exceptions)" \
39 "(max-nondet-array-length):" \
40 "(max-nondet-tree-depth):" \
41 "(java-max-vla-length):" \
42 "(java-cp-include-files):" \
43 "(ignore-manifest-main-class)" \
44 "(context-include):" \
45 "(context-exclude):" \
47 "(lazy-methods-extra-entry-point):" \
48 "(java-load-class):" \
49 "(java-no-load-class):" \
51 "(java-lift-clinit-calls)"
53 #define JAVA_BYTECODE_LANGUAGE_OPTIONS_HELP \
54 " --disable-uncaught-exception-check\n" \
55 " ignore uncaught exceptions and errors\n" \
56 " --throw-assertion-error throw java.lang.AssertionError on violated\n" \
57 " assert statements instead of failing\n" \
58 " at the location of the assert statement\n" \
59 " --throw-runtime-exceptions make implicit runtime exceptions explicit\n" \
60 " --assert-no-exceptions-thrown\n"\
61 " transform `throw` instructions into `assert FALSE`\n" \
62 " followed by `assume FALSE`.\n" \
63 " --max-nondet-array-length N limit nondet (e.g. input) array size to <= N\n" \
64 " --max-nondet-tree-depth N limit size of nondet (e.g. input) object tree;\n" \
65 " at level N references are set to null\n" \
66 " --java-assume-inputs-non-null\n" \
67 " never initialize reference-typed parameter to the\n" \
68 " entry point with null\n" \
69 " --java-assume-inputs-interval [L:U] or [L:] or [:U]\n" \
70 " force numerical primitive-typed inputs\n" \
71 " (byte, short, int, long, float, double) to be\n" \
72 " initialized within the given range; lower bound\n" \
73 " L and upper bound U must be integers;\n" \
74 " does not work for arrays;\n" \
75 " --java-assume-inputs-integral\n" \
76 " force float and double inputs to have integer values;\n" \
77 " does not work for arrays;\n" \
78 " --java-max-vla-length N limit the length of user-code-created arrays\n" \
79 " --java-cp-include-files r regexp or JSON list of files to load\n" \
80 " (with '@' prefix)\n" \
81 " --java-load-class CLASS also load code from class CLASS\n" \
82 " --java-no-load-class CLASS never load code from class CLASS\n" \
83 " --ignore-manifest-main-class ignore Main-Class entries in JAR manifest files.\n" \
84 " If this option is specified and the options\n" \
85 " --function and --main-class are not, we can be\n" \
86 " certain that all classes in the JAR file are\n" \
88 " --context-include i only analyze code matching specification i that\n" \
89 " --context-exclude e does not match specification e.\n" \
90 " All other methods are excluded, i.e. we load their\n" \
91 " signatures and meta-information, but not their\n" \
93 " A specification is any prefix of a package, class\n" \
94 " or method name, e.g. \"org.cprover.\" or\n" \
95 " \"org.cprover.MyClass.\" or\n" \
96 " \"org.cprover.MyClass.methodToStub:(I)Z\".\n" \
97 " These options can be given multiple times.\n" \
98 " The default for context-include is 'all\n" \
99 " included'; default for context-exclude is\n" \
100 " 'nothing excluded'.\n" \
101 " --no-lazy-methods load and translate all methods given on\n" \
102 " the command line and in --classpath\n" \
103 " Default is to load methods that appear to be\n" \
104 " reachable from the --function entry point\n" \
106 " Note that --show-symbol-table, --show-goto-functions\n" \
107 " and --show-properties output are restricted to\n" \
108 " loaded methods by default.\n" \
109 " --lazy-methods-extra-entry-point METHODNAME\n" \
110 " treat METHODNAME as a possible program entry\n" \
111 " point for the purpose of lazy method loading\n" \
112 " METHODNAME can be a regex that will be matched\n" \
113 " against all symbols. If missing a java:: prefix\n" \
114 " will be added. If no descriptor is found, all\n" \
115 " overloads of a method will also be added.\n" \
116 " --static-values f Load initial values of static fields from the given\n" \
117 " JSON file. We assign static fields to these values\n" \
118 " instead of calling the normal static initializer\n" \
119 " (clinit) method.\n" \
120 " The argument can be a relative or absolute path to\n" \
122 " --java-lift-clinit-calls Lifts clinit calls in function bodies to the top of the\n" \
123 " function. This may reduce the overall cost of static\n" \
124 " initialisation, but may be unsound if there are\n" \
125 " cyclic dependencies between static initializers due\n" \
126 " to potentially changing their order of execution,\n" \
127 " or if static initializers have side-effects such as\n" \
128 " updating another class' static field.\n"
131 #define JAVA_CLASSPATH_SEPARATOR ";"
133 #define JAVA_CLASSPATH_SEPARATOR ":"
136 #define HELP_JAVA_CLASSPATH \
137 " -classpath dirs/jars\n" \
139 " --classpath dirs/jars set class search path of directories and\n" \
141 " A " JAVA_CLASSPATH_SEPARATOR \
142 " separated list of directories and JAR\n" \
143 " archives to search for class files.\n" \
144 " --main-class class-name set the name of the main class\n"
146 #define HELP_JAVA_METHOD_NAME \
147 " method-name fully qualified name of method\n" \
148 " used as entry point, e.g.\n" \
149 " mypackage.Myclass.foo:(I)Z\n"
151 #define HELP_JAVA_CLASS_NAME \
152 " class-name name of class\n" \
153 " The entry point is the method specified by\n" \
154 " --function, or otherwise, the\n" \
155 " public static void main(String[])\n" \
156 " method of the given class.\n"
158 #define OPT_JAVA_JAR \
161 #define HELP_JAVA_JAR \
162 " -jar jarfile JAR file to be checked\n" \
163 " The entry point is the method specified by\n" \
164 " --function or otherwise, the\n" \
165 " public static void main(String[]) method\n" \
166 " of the class specified by --main-class or the main\n" \
167 " class specified in the JAR manifest\n" \
168 " (checked in this order).\n"
170 #define OPT_JAVA_GOTO_BINARY \
173 #define HELP_JAVA_GOTO_BINARY \
174 " --gb goto-binary goto-binary file to be checked\n" \
175 " The entry point is the method specified by\n" \
176 " --function, or otherwise, the\n" \
177 " public static void main(String[])\n" \
178 " of the class specified by --main-class\n" \
179 " (checked in this order).\n"
206 std::unordered_multimap<irep_idt, symbolt> &
213 std::unordered_multimap<irep_idt, symbolt>
map;
272 #define JAVA_CLASS_MODEL_SUFFIX "@class_model"
282 std::istream &instream,
283 const std::string &path,
284 std::ostream &outstream)
override;
290 virtual bool parse();
293 std::istream &instream,
294 const std::string &path)
override;
301 const std::string &module)
override;
332 const std::string &code,
333 const std::string &module,
338 {
return util_make_unique<java_bytecode_languaget>(); }
340 std::string
id()
const override {
return "java"; }
341 std::string
description()
const override {
return "Java Bytecode"; }
342 std::set<std::string>
extensions()
const override;
386 virtual std::vector<load_extra_methodst>
401 std::unordered_map<std::string, object_creation_referencet>
references;
413 #endif // CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_LANGUAGE_H
Class that provides messages with a built-in verbosity 'level'.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
method_bytecodet method_bytecode
bool convert_single_method_code(const irep_idt &function_id, symbol_table_baset &symbol_table, optionalt< ci_lazy_methods_neededt > needed_lazy_methods, lazy_class_to_declared_symbols_mapt &class_to_declared_symbols)
Convert a method (one whose type is known but whose body hasn't been converted) but don't run typeche...
std::set< std::string > extensions() const override
@ LAZY_METHODS_MODE_EAGER
optionalt< prefix_filtert > method_context
If set, method bodies are only elaborated if they pass the filter.
Non-graph-based representation of the class hierarchy.
const std::unique_ptr< const select_pointer_typet > pointer_type_selector
Provides filtering of strings vai inclusion/exclusion lists of prefixes.
bool should_lift_clinit_calls
Should we lift clinit calls in function bodies to the top? For example, turning if(x) A....
synthetic_methods_mapt synthetic_methods
Maps synthetic method names on to the particular type of synthetic method (static initializer,...
bool to_expr(const std::string &code, const std::string &module, exprt &expr, const namespacet &ns) override
Parses the given string into an expression.
The type of an expression, extends irept.
java_bytecode_language_optionst()=default
virtual void methods_provided(std::unordered_set< irep_idt > &methods) const override
Provide feedback to language_filest so that when asked for a lazy method, it can delegate to this ins...
optionalt< java_bytecode_language_optionst > language_options
void parse_java_language_options(const cmdlinet &cmd, optionst &options)
Parse options that are java bytecode specific.
Base class for all expressions.
std::unordered_map< std::string, object_creation_referencet > references
Map used in all calls to functions that deterministically create objects (currently only assign_from_...
bool from_type(const typet &type, std::string &code, const namespacet &ns) override
Formats the given type in a language-specific way.
java_bytecode_languaget()
std::unordered_map< irep_idt, synthetic_method_typet > synthetic_methods_mapt
Maps method names on to a synthetic method kind.
std::unordered_multimap< irep_idt, symbolt > class_to_declared_symbols(const symbol_tablet &symbol_table)
stub_global_initializer_factoryt stub_global_initializer_factory
lazy_methods_modet lazy_methods_mode
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
void set_language_options(const optionst &) override
Consume options that are java bytecode specific.
virtual std::vector< load_extra_methodst > build_extra_entry_points(const optionst &) const
This method should be overloaded to provide alternative approaches for specifying extra entry points.
std::vector< irep_idt > main_jar_classes
virtual ~java_bytecode_languaget()
java_class_loadert java_class_loader
bool ignore_manifest_main_class
The symbol table base class interface.
bool do_ci_lazy_method_conversion(symbol_tablet &)
Uses a simple context-insensitive ('ci') analysis to determine which methods may be reachable from th...
void show_parse(std::ostream &out) override
std::vector< irep_idt > java_load_classes
list of classes to force load even without reference from the entry point
bool generate_support_functions(symbol_tablet &symbol_table) override
Create language-specific support functions, such as __CPROVER_start, __CPROVER_initialize and languag...
std::unique_ptr< languaget > new_language() override
void initialize_class_loader()
virtual void convert_lazy_method(const irep_idt &function_id, symbol_table_baset &symbol_table) override
Promote a lazy-converted method (one whose type is known but whose body hasn't been converted) into a...
virtual bool parse()
We set the main class (i.e. class to start the class loading analysis, see java_class_loadert) when w...
std::string java_cp_include_files
void modules_provided(std::set< std::string > &modules) override
java_string_library_preprocesst string_preprocess
bool assert_no_exceptions_thrown
Transform athrow bytecode instructions into assert FALSE followed by assume FALSE.
nonstd::optional< T > optionalt
std::unordered_multimap< irep_idt, symbolt > & get(const symbol_tablet &symbol_table)
bool assume_inputs_non_null
assume inputs variables to be non-null
Class responsible to load .class files.
prefix_filtert get_context(const optionst &options)
bool from_expr(const exprt &expr, std::string &code, const namespacet &ns) override
Formats the given expression in a language-specific way.
class_hierarchyt class_hierarchy
const select_pointer_typet & get_pointer_type_selector() const
message_handlert * message_handler
bool typecheck(symbol_tablet &context, const std::string &module) override
lazy_class_to_declared_symbols_mapt()=default
optionalt< json_objectt > static_values_json
JSON which contains initial values of static fields (right after the static initializer of the class ...
void set_message_handler(message_handlert &message_handler) override
std::string id() const override
bool throw_runtime_exceptions
std::vector< load_extra_methodst > extra_methods
bool assert_uncaught_exceptions
bool throw_assertion_error
@ LAZY_METHODS_MODE_CONTEXT_INSENSITIVE
java_object_factory_parameterst object_factory_parameters
Map classes to the symbols they declare but is only computed once it is needed and the map is then ke...
void parse_from_main_class()
std::unordered_set< std::string > no_load_classes
List of classes to never load.
void convert_single_method(const irep_idt &function_id, symbol_table_baset &symbol_table, lazy_class_to_declared_symbols_mapt &class_to_declared_symbols)
java_bytecode_languaget(std::unique_ptr< select_pointer_typet > pointer_type_selector)
std::unique_ptr< languaget > new_java_bytecode_language()
bool string_refinement_enabled
optionalt< std::string > main_jar
If set then a JAR file has been given via the -jar option.
@ LAZY_METHODS_MODE_EXTERNAL_DRIVER
virtual bool preprocess(std::istream &instream, const std::string &path, std::ostream &outstream) override
ANSI-C preprocessing.
std::unordered_multimap< irep_idt, symbolt > map
size_t max_user_array_length
max size for user code created arrays
std::string description() const override