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 " --ignore-manifest-main-class ignore Main-Class entries in JAR manifest files.\n"
\
82 " If this option is specified and the options\n" \
83 " --function and --main-class are not, we can be\n" \
84 " certain that all classes in the JAR file are\n" \
86 " --context-include i only analyze code matching specification i that\n"
\
87 " --context-exclude e does not match specification e.\n" \
88 " All other methods are excluded, i.e. we load their\n"
\
89 " signatures and meta-information, but not their\n" \
91 " A specification is any prefix of a package, class\n"
\
92 " or method name, e.g. \"org.cprover.\" or\n" \
93 " \"org.cprover.MyClass.\" or\n" \
94 " \"org.cprover.MyClass.methodToStub:(I)Z\".\n" \
95 " These options can be given multiple times.\n" \
96 " The default for context-include is 'all\n" \
97 " included'; default for context-exclude is\n" \
98 " 'nothing excluded'.\n" \
99 " --no-lazy-methods load and translate all methods given on\n" \
100 " the command line and in --classpath\n" \
101 " Default is to load methods that appear to be\n"
\
102 " reachable from the --function entry point\n" \
104 " Note that --show-symbol-table, --show-goto-functions\n"
\
105 " and --show-properties output are restricted to\n" \
106 " loaded methods by default.\n" \
107 " --lazy-methods-extra-entry-point METHODNAME\n" \
108 " treat METHODNAME as a possible program entry\n"
\
109 " point for the purpose of lazy method loading\n" \
110 " METHODNAME can be a regex that will be matched\n" \
111 " against all symbols. If missing a java:: prefix\n" \
112 " will be added. If no descriptor is found, all\n" \
113 " overloads of a method will also be added.\n" \
114 " --static-values f Load initial values of static fields from the given\n"
\
115 " JSON file. We assign static fields to these values\n" \
116 " instead of calling the normal static initializer\n" \
117 " (clinit) method.\n" \
118 " The argument can be a relative or absolute path to\n"
\
120 " --java-lift-clinit-calls Lifts clinit calls in function bodies to the top of the\n"
\
121 " function. This may reduce the overall cost of static\n" \
122 " initialisation, but may be unsound if there are\n" \
123 " cyclic dependencies between static initializers due\n" \
124 " to potentially changing their order of execution,\n" \
125 " or if static initializers have side-effects such as\n" \
126 " updating another class' static field.\n"
129 #define JAVA_CLASSPATH_SEPARATOR ";"
131 #define JAVA_CLASSPATH_SEPARATOR ":"
134 #define HELP_JAVA_CLASSPATH \
135 " -classpath dirs/jars\n" \
137 " --classpath dirs/jars set class search path of directories and\n" \
139 " A " JAVA_CLASSPATH_SEPARATOR \
140 " separated list of directories and JAR\n" \
141 " archives to search for class files.\n" \
142 " --main-class class-name set the name of the main class\n"
144 #define HELP_JAVA_METHOD_NAME \
145 " method-name fully qualified name of method\n" \
146 " used as entry point, e.g.\n" \
147 " mypackage.Myclass.foo:(I)Z\n"
149 #define HELP_JAVA_CLASS_NAME \
150 " class-name name of class\n" \
151 " The entry point is the method specified by\n" \
152 " --function, or otherwise, the\n" \
153 " public static void main(String[])\n" \
154 " method of the given class.\n"
156 #define OPT_JAVA_JAR \
159 #define HELP_JAVA_JAR \
160 " -jar jarfile JAR file to be checked\n" \
161 " The entry point is the method specified by\n" \
162 " --function or otherwise, the\n" \
163 " public static void main(String[]) method\n" \
164 " of the class specified by --main-class or the main\n"
\
165 " class specified in the JAR manifest\n" \
166 " (checked in this order).\n"
168 #define OPT_JAVA_GOTO_BINARY \
171 #define HELP_JAVA_GOTO_BINARY \
172 " --gb goto-binary goto-binary file to be checked\n" \
173 " The entry point is the method specified by\n" \
174 " --function, or otherwise, the\n" \
175 " public static void main(String[])\n" \
176 " of the class specified by --main-class\n" \
177 " (checked in this order).\n"
204 std::unordered_multimap<irep_idt, symbolt> &
211 std::unordered_multimap<irep_idt, symbolt>
map;
270 #define JAVA_CLASS_MODEL_SUFFIX "@class_model"
280 std::istream &instream,
281 const std::string &path,
282 std::ostream &outstream)
override;
288 virtual bool parse();
291 std::istream &instream,
292 const std::string &path)
override;
299 const std::string &module)
override;
330 const std::string &code,
331 const std::string &module,
336 {
return util_make_unique<java_bytecode_languaget>(); }
338 std::string
id()
const override {
return "java"; }
339 std::string
description()
const override {
return "Java Bytecode"; }
340 std::set<std::string>
extensions()
const override;
384 virtual std::vector<load_extra_methodst>
399 std::unordered_map<std::string, object_creation_referencet>
references;
Collect methods needed to be loaded using the lazy method.
Context-insensitive lazy methods container.
Non-graph-based representation of the class hierarchy.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
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...
void show_parse(std::ostream &out) override
synthetic_methods_mapt synthetic_methods
Maps synthetic method names on to the particular type of synthetic method (static initializer,...
std::vector< irep_idt > main_jar_classes
virtual bool preprocess(std::istream &instream, const std::string &path, std::ostream &outstream) override
ANSI-C preprocessing.
std::string id() const override
stub_global_initializer_factoryt stub_global_initializer_factory
std::set< std::string > extensions() const override
virtual ~java_bytecode_languaget()
void set_message_handler(message_handlert &message_handler) override
void set_language_options(const optionst &) override
Consume options that are java bytecode specific.
void initialize_class_loader()
bool from_type(const typet &type, std::string &code, const namespacet &ns) override
Formats the given type in a language-specific way.
std::unique_ptr< languaget > new_language() override
java_bytecode_languaget()
bool to_expr(const std::string &code, const std::string &module, exprt &expr, const namespacet &ns) override
Parses the given string into an expression.
method_bytecodet method_bytecode
java_bytecode_languaget(std::unique_ptr< select_pointer_typet > pointer_type_selector)
std::string description() const override
const std::unique_ptr< const select_pointer_typet > pointer_type_selector
bool do_ci_lazy_method_conversion(symbol_tablet &)
Uses a simple context-insensitive ('ci') analysis to determine which methods may be reachable from th...
class_hierarchyt class_hierarchy
bool generate_support_functions(symbol_tablet &symbol_table) override
Create language-specific support functions, such as __CPROVER_start, __CPROVER_initialize and languag...
void parse_from_main_class()
java_object_factory_parameterst object_factory_parameters
optionalt< java_bytecode_language_optionst > language_options
java_string_library_preprocesst string_preprocess
void modules_provided(std::set< std::string > &modules) override
java_class_loadert java_class_loader
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...
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.
virtual bool parse()
We set the main class (i.e. class to start the class loading analysis, see java_class_loadert) when w...
const select_pointer_typet & get_pointer_type_selector() const
bool typecheck(symbol_tablet &context, const std::string &module) override
bool from_expr(const exprt &expr, std::string &code, const namespacet &ns) override
Formats the given expression in a language-specific way.
std::unordered_map< std::string, object_creation_referencet > references
Map used in all calls to functions that deterministically create objects (currently only assign_from_...
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...
void convert_single_method(const irep_idt &function_id, symbol_table_baset &symbol_table, lazy_class_to_declared_symbols_mapt &class_to_declared_symbols)
Class responsible to load .class files.
Map classes to the symbols they declare but is only computed once it is needed and the map is then ke...
lazy_class_to_declared_symbols_mapt()=default
std::unordered_multimap< irep_idt, symbolt > & get(const symbol_tablet &symbol_table)
std::unordered_multimap< irep_idt, symbolt > map
Class that provides messages with a built-in verbosity 'level'.
message_handlert * message_handler
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Provides filtering of strings vai inclusion/exclusion lists of prefixes.
The symbol table base class interface.
The type of an expression, extends irept.
void parse_java_language_options(const cmdlinet &cmd, optionst &options)
Parse options that are java bytecode specific.
@ LAZY_METHODS_MODE_EAGER
@ LAZY_METHODS_MODE_EXTERNAL_DRIVER
@ LAZY_METHODS_MODE_CONTEXT_INSENSITIVE
prefix_filtert get_context(const optionst &options)
std::unique_ptr< languaget > new_java_bytecode_language()
std::unordered_multimap< irep_idt, symbolt > class_to_declared_symbols(const symbol_tablet &symbol_table)
Produce code for simple implementation of String Java libraries.
Abstract interface to support a programming language.
nonstd::optional< T > optionalt
Handle selection of correct pointer type (for example changing abstract classes to concrete versions)...
bool assert_uncaught_exceptions
bool assert_no_exceptions_thrown
Transform athrow bytecode instructions into assert FALSE followed by assume FALSE.
bool throw_runtime_exceptions
bool should_lift_clinit_calls
Should we lift clinit calls in function bodies to the top? For example, turning if(x) A....
std::string java_cp_include_files
optionalt< std::string > main_jar
If set then a JAR file has been given via the -jar option.
optionalt< prefix_filtert > method_context
If set, method bodies are only elaborated if they pass the filter.
optionalt< json_objectt > static_values_json
JSON which contains initial values of static fields (right after the static initializer of the class ...
lazy_methods_modet lazy_methods_mode
bool string_refinement_enabled
bool throw_assertion_error
bool assume_inputs_non_null
assume inputs variables to be non-null
bool ignore_manifest_main_class
size_t max_user_array_length
max size for user code created arrays
java_bytecode_language_optionst()=default
std::vector< irep_idt > java_load_classes
list of classes to force load even without reference from the entry point
std::unordered_set< std::string > no_load_classes
List of classes to never load.
std::vector< load_extra_methodst > extra_methods
Synthetic methods are particular methods internally generated by the Java frontend,...
std::unordered_map< irep_idt, synthetic_method_typet > synthetic_methods_mapt
Maps method names on to a synthetic method kind.