cprover
restrict_function_pointers.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Restrict function pointers
4 
5 Author: Diffblue Ltd.
6 
7 \*******************************************************************/
8 
16 
17 #ifndef CPROVER_GOTO_PROGRAMS_RESTRICT_FUNCTION_POINTERS_H
18 #define CPROVER_GOTO_PROGRAMS_RESTRICT_FUNCTION_POINTERS_H
19 
20 #include <unordered_map>
21 #include <unordered_set>
22 
23 #include <util/cmdline.h>
24 #include <util/irep.h>
25 
27 #include <util/options.h>
28 
29 #define RESTRICT_FUNCTION_POINTER_OPT "restrict-function-pointer"
30 #define RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT \
31  "function-pointer-restrictions-file"
32 #define RESTRICT_FUNCTION_POINTER_BY_NAME_OPT \
33  "restrict-function-pointer-by-name"
34 
35 #define OPT_RESTRICT_FUNCTION_POINTER \
36  "(" RESTRICT_FUNCTION_POINTER_OPT \
37  "):" \
38  "(" RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT \
39  "):" \
40  "(" RESTRICT_FUNCTION_POINTER_BY_NAME_OPT "):"
41 
42 #define HELP_RESTRICT_FUNCTION_POINTER \
43  "--" RESTRICT_FUNCTION_POINTER_OPT \
44  " <pointer_name>/<target[,targets]*>\n" \
45  " restrict a function pointer to a set of possible targets\n" \
46  " targets must all exist in the symbol table with a matching " \
47  "type\n" \
48  " works for globals and function parameters right now\n" \
49  "--" RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT \
50  " <file_name>\n" \
51  " add function pointer restrictions from file"
52 
54  const cmdlinet &cmdline,
55  optionst &options);
56 
57 class jsont;
58 class message_handlert;
59 
61 {
62 public:
63  using restrictionst =
64  std::unordered_map<irep_idt, std::unordered_set<irep_idt>>;
65  using restrictiont = restrictionst::value_type;
66 
68 
71  const optionst &options,
72  const goto_modelt &goto_model,
73  message_handlert &message_handler);
74 
75  jsont to_json() const;
77 
79  const std::string &filename,
80  message_handlert &message_handler);
81 
82  void write_to_file(const std::string &filename) const;
83 
84 protected:
86  {
87  public:
89  std::string reason,
90  std::string correct_format = "");
91 
92  std::string what() const override;
93 
94  std::string reason;
95  std::string correct_format;
96  };
97 
99  const goto_modelt &goto_model,
100  const restrictionst &restrictions);
101 
103  restrictionst lhs,
104  const restrictionst &rhs);
105 
107  const std::list<std::string> &filenames,
108  message_handlert &message_handler);
109 
111  const std::list<std::string> &restriction_opts);
112 
114  const std::list<std::string> &restriction_opts,
115  const std::string &option);
116 
118  const std::string &restriction_opt,
119  const std::string &option);
120 
122  const goto_functiont &goto_function,
123  const function_pointer_restrictionst::restrictionst &by_name_restrictions,
124  const goto_programt::const_targett &location);
125 
139  const std::list<std::string> &restriction_name_opts,
140  const goto_modelt &goto_model);
141 };
142 
152  goto_modelt &goto_model,
153  const function_pointer_restrictionst &restrictions);
154 
155 #endif // CPROVER_GOTO_PROGRAMS_RESTRICT_FUNCTION_POINTERS_H
function_pointer_restrictionst::invalid_restriction_exceptiont::reason
std::string reason
Definition: restrict_function_pointers.h:94
function_pointer_restrictionst::read_from_file
static function_pointer_restrictionst read_from_file(const std::string &filename, message_handlert &message_handler)
Definition: restrict_function_pointers.cpp:533
optionst
Definition: options.h:23
function_pointer_restrictionst::to_json
jsont to_json() const
Definition: restrict_function_pointers.cpp:549
goto_model.h
Symbol Table + CFG.
goto_modelt
Definition: goto_model.h:26
options.h
Options.
jsont
Definition: json.h:27
function_pointer_restrictionst::invalid_restriction_exceptiont::what
std::string what() const override
A human readable description of what went wrong.
Definition: restrict_function_pointers.cpp:150
function_pointer_restrictionst::from_options
static function_pointer_restrictionst from_options(const optionst &options, const goto_modelt &goto_model, message_handlert &message_handler)
Parse function pointer restrictions from command line.
Definition: restrict_function_pointers.cpp:437
function_pointer_restrictionst::restrictions
const restrictionst restrictions
Definition: restrict_function_pointers.h:67
function_pointer_restrictionst::get_function_pointer_by_name_restrictions
static restrictionst get_function_pointer_by_name_restrictions(const std::list< std::string > &restriction_name_opts, const goto_modelt &goto_model)
Get function pointer restrictions from restrictions with named pointers.
Definition: restrict_function_pointers.cpp:587
cmdlinet
Definition: cmdline.h:21
function_pointer_restrictionst::parse_function_pointer_restrictions_from_file
static restrictionst parse_function_pointer_restrictions_from_file(const std::list< std::string > &filenames, message_handlert &message_handler)
Definition: restrict_function_pointers.cpp:314
function_pointer_restrictionst::merge_function_pointer_restrictions
static restrictionst merge_function_pointer_restrictions(restrictionst lhs, const restrictionst &rhs)
Definition: restrict_function_pointers.cpp:256
json
static void json(json_objectT &result, const irep_idt &property_id, const property_infot &property_info)
Definition: properties.cpp:114
restrict_function_pointers
void restrict_function_pointers(goto_modelt &goto_model, const function_pointer_restrictionst &restrictions)
Apply function pointer restrictions to a goto_model.
Definition: restrict_function_pointers.cpp:215
function_pointer_restrictionst::restrictionst
std::unordered_map< irep_idt, std::unordered_set< irep_idt > > restrictionst
Definition: restrict_function_pointers.h:64
function_pointer_restrictionst::get_by_name_restriction
static optionalt< restrictiont > get_by_name_restriction(const goto_functiont &goto_function, const function_pointer_restrictionst::restrictionst &by_name_restrictions, const goto_programt::const_targett &location)
Definition: restrict_function_pointers.cpp:392
message_handlert
Definition: message.h:28
goto_functiont
A goto function, consisting of function type (see type), function body (see body),...
Definition: goto_function.h:28
function_pointer_restrictionst::restrictiont
restrictionst::value_type restrictiont
Definition: restrict_function_pointers.h:65
function_pointer_restrictionst
Definition: restrict_function_pointers.h:61
optionalt
nonstd::optional< T > optionalt
Definition: optional.h:35
function_pointer_restrictionst::parse_function_pointer_restrictions_from_command_line
static restrictionst parse_function_pointer_restrictions_from_command_line(const std::list< std::string > &restriction_opts)
Definition: restrict_function_pointers.cpp:306
function_pointer_restrictionst::invalid_restriction_exceptiont::invalid_restriction_exceptiont
invalid_restriction_exceptiont(std::string reason, std::string correct_format="")
Definition: restrict_function_pointers.cpp:144
function_pointer_restrictionst::invalid_restriction_exceptiont::correct_format
std::string correct_format
Definition: restrict_function_pointers.h:95
parse_function_pointer_restriction_options_from_cmdline
void parse_function_pointer_restriction_options_from_cmdline(const cmdlinet &cmdline, optionst &options)
Definition: restrict_function_pointers.cpp:229
cmdline.h
function_pointer_restrictionst::typecheck_function_pointer_restrictions
static void typecheck_function_pointer_restrictions(const goto_modelt &goto_model, const restrictionst &restrictions)
Definition: restrict_function_pointers.cpp:165
function_pointer_restrictionst::write_to_file
void write_to_file(const std::string &filename) const
Definition: restrict_function_pointers.cpp:568
function_pointer_restrictionst::parse_function_pointer_restrictions
static restrictionst parse_function_pointer_restrictions(const std::list< std::string > &restriction_opts, const std::string &option)
Definition: restrict_function_pointers.cpp:278
function_pointer_restrictionst::parse_function_pointer_restriction
static restrictiont parse_function_pointer_restriction(const std::string &restriction_opt, const std::string &option)
Definition: restrict_function_pointers.cpp:332
function_pointer_restrictionst::from_json
static function_pointer_restrictionst from_json(const jsont &json)
Definition: restrict_function_pointers.cpp:494
goto_programt::const_targett
instructionst::const_iterator const_targett
Definition: goto_program.h:580
function_pointer_restrictionst::invalid_restriction_exceptiont
Definition: restrict_function_pointers.h:86
cprover_exception_baset
Base class for exceptions thrown in the cprover project.
Definition: exception_utils.h:25
irep.h