|
10 | 10 | #include "java_object_factory.h"
|
11 | 11 | #include "java_utils.h"
|
12 | 12 | #include <goto-programs/class_hierarchy.h>
|
13 |
| -#include <util/std_types.h> |
14 |
| -#include <util/std_expr.h> |
| 13 | +#include <json/json_parser.h> |
| 14 | +#include <util/arith_tools.h> |
15 | 15 | #include <util/std_code.h>
|
| 16 | +#include <util/std_expr.h> |
| 17 | +#include <util/std_types.h> |
16 | 18 | #include <util/suffix.h>
|
17 |
| -#include <util/arith_tools.h> |
18 | 19 |
|
19 | 20 | /// The three states in which a `<clinit>` method for a class can be before,
|
20 | 21 | /// after, and during static class initialization. These states are only used
|
@@ -750,6 +751,61 @@ code_ifthenelset get_clinit_wrapper_body(
|
750 | 751 | return code_ifthenelset(std::move(check_already_run), std::move(init_body));
|
751 | 752 | }
|
752 | 753 |
|
| 754 | +code_blockt get_user_specified_clinit_body( |
| 755 | + const irep_idt &class_id, |
| 756 | + const std::string &static_values_file, |
| 757 | + symbol_table_baset &symbol_table, |
| 758 | + message_handlert &message_handler) |
| 759 | +{ |
| 760 | + jsont json; |
| 761 | + if( |
| 762 | + !static_values_file.empty() && |
| 763 | + !parse_json(static_values_file, message_handler, json) && json.is_object()) |
| 764 | + { |
| 765 | + const auto &json_object = to_json_object(json); |
| 766 | + const auto class_entry = |
| 767 | + json_object.find(id2string(strip_java_namespace_prefix(class_id))); |
| 768 | + if(class_entry != json_object.end()) |
| 769 | + { |
| 770 | + const auto &class_json_value = class_entry->second; |
| 771 | + if(class_json_value.is_object()) |
| 772 | + { |
| 773 | + const auto &class_json_object = to_json_object(class_json_value); |
| 774 | + std::map<symbol_exprt, jsont> static_field_values; |
| 775 | + for(const auto &symbol_pair : symbol_table) |
| 776 | + { |
| 777 | + const symbolt &symbol = symbol_pair.second; |
| 778 | + if( |
| 779 | + declaring_class(symbol) && *declaring_class(symbol) == class_id && |
| 780 | + symbol.is_static_lifetime) |
| 781 | + { |
| 782 | + const symbol_exprt &static_field_expr = symbol.symbol_expr(); |
| 783 | + const auto &static_field_entry = |
| 784 | + class_json_object.find(id2string(symbol.base_name)); |
| 785 | + if(static_field_entry != class_json_object.end()) |
| 786 | + { |
| 787 | + static_field_values.insert( |
| 788 | + {static_field_expr, static_field_entry->second}); |
| 789 | + } |
| 790 | + } |
| 791 | + } |
| 792 | + code_blockt body; |
| 793 | + for(const auto &value_pair : static_field_values) |
| 794 | + { |
| 795 | + // TODO append code to `body` to assign value_pair.first to |
| 796 | + // TODO value_pair.second |
| 797 | + (void)value_pair; |
| 798 | + } |
| 799 | + return body; |
| 800 | + } |
| 801 | + } |
| 802 | + } |
| 803 | + const irep_idt &real_clinit_name = clinit_function_name(class_id); |
| 804 | + if(const auto clinit_func = symbol_table.lookup(real_clinit_name)) |
| 805 | + return code_blockt{{code_function_callt{clinit_func->symbol_expr()}}}; |
| 806 | + return code_blockt{}; |
| 807 | +} |
| 808 | + |
753 | 809 | /// Create static initializer wrappers and possibly user-specified functions for
|
754 | 810 | /// initial static field value assignments for all classes that need them.
|
755 | 811 | /// For each class that will require a static initializer wrapper, create a
|
|
0 commit comments