CBMC
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/exception_utils.h>
24 #include <util/irep.h>
25 #include <util/optional.h>
26 
27 #include "goto_program.h"
28 
29 class cmdlinet;
30 class goto_functiont;
31 class goto_modelt;
32 class jsont;
33 class message_handlert;
34 class optionst;
35 
36 #define RESTRICT_FUNCTION_POINTER_OPT "restrict-function-pointer"
37 #define RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT \
38  "function-pointer-restrictions-file"
39 #define RESTRICT_FUNCTION_POINTER_BY_NAME_OPT \
40  "restrict-function-pointer-by-name"
41 
42 #define OPT_RESTRICT_FUNCTION_POINTER \
43  "(" RESTRICT_FUNCTION_POINTER_OPT \
44  "):" \
45  "(" RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT \
46  "):" \
47  "(" RESTRICT_FUNCTION_POINTER_BY_NAME_OPT "):"
48 
49 #define HELP_RESTRICT_FUNCTION_POINTER \
50  " --" RESTRICT_FUNCTION_POINTER_OPT \
51  " <pointer_name>/<target[,targets]*>\n" \
52  " restrict a function pointer to a set of " \
53  "possible targets\n" \
54  " targets must all exist in the symbol table" \
55  " with a matching type\n" \
56  " works for globals and function parameters" \
57  " right now\n" \
58  " --" RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT \
59  " <file_name>\n" \
60  " add function pointer restrictions from " \
61  "file\n" \
62  " --" RESTRICT_FUNCTION_POINTER_BY_NAME_OPT \
63  " <symbol_name>/target[targets]*>\n" \
64  " restrict a function pointer where " \
65  " <symbol_name>\n" \
66  " is the unmangled name, before labelling " \
67  "function pointers\n"
68 
70  const cmdlinet &cmdline,
71  optionst &options);
72 
74 {
75 public:
77  std::string reason,
78  std::string correct_format = "");
79 
80  std::string what() const override;
81 
82  std::string correct_format;
83 };
84 
86 {
87 public:
88  using restrictionst =
89  std::unordered_map<irep_idt, std::unordered_set<irep_idt>>;
90  using restrictiont = restrictionst::value_type;
91 
93 
96  const optionst &options,
97  const goto_modelt &goto_model,
98  message_handlert &message_handler);
99 
100  jsont to_json() const;
102  from_json(const jsont &json, const goto_modelt &goto_model);
103 
105  const std::string &filename,
106  const goto_modelt &goto_model,
107  message_handlert &message_handler);
108 
109  void write_to_file(const std::string &filename) const;
110 
111 protected:
113  const goto_modelt &goto_model,
114  const restrictionst &restrictions);
115 
117  restrictionst lhs,
118  const restrictionst &rhs);
119 
121  const std::list<std::string> &filenames,
122  const goto_modelt &goto_model,
123  message_handlert &message_handler);
124 
126  const std::list<std::string> &restriction_opts,
127  const goto_modelt &goto_model);
128 
130  const std::list<std::string> &restriction_opts,
131  const std::string &option,
132  const goto_modelt &goto_model);
133 
135  const std::string &restriction_opt,
136  const std::string &option,
137  const goto_modelt &goto_model);
138 
140  const goto_functiont &goto_function,
141  const function_pointer_restrictionst::restrictionst &by_name_restrictions,
142  const goto_programt::const_targett &location);
143 
157  const std::list<std::string> &restriction_name_opts,
158  const goto_modelt &goto_model);
159 };
160 
170  message_handlert &message_handler,
171  goto_modelt &goto_model,
172  const optionst &options);
173 
174 #endif // CPROVER_GOTO_PROGRAMS_RESTRICT_FUNCTION_POINTERS_H
exception_utils.h
invalid_restriction_exceptiont
Definition: restrict_function_pointers.h:73
invalid_restriction_exceptiont::correct_format
std::string correct_format
Definition: restrict_function_pointers.h:82
function_pointer_restrictionst::parse_function_pointer_restriction
static restrictiont parse_function_pointer_restriction(const std::string &restriction_opt, const std::string &option, const goto_modelt &goto_model)
Definition: restrict_function_pointers.cpp:362
optionst
Definition: options.h:22
optional.h
function_pointer_restrictionst::to_json
jsont to_json() const
Definition: restrict_function_pointers.cpp:589
goto_modelt
Definition: goto_model.h:25
jsont
Definition: json.h:26
restrict_function_pointers
void restrict_function_pointers(message_handlert &message_handler, goto_modelt &goto_model, const optionst &options)
Apply function pointer restrictions to a goto_model.
Definition: restrict_function_pointers.cpp:169
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:468
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, const goto_modelt &goto_model)
Definition: restrict_function_pointers.cpp:273
function_pointer_restrictionst::parse_function_pointer_restrictions
static restrictionst parse_function_pointer_restrictions(const std::list< std::string > &restriction_opts, const std::string &option, const goto_modelt &goto_model)
Definition: restrict_function_pointers.cpp:244
function_pointer_restrictionst::restrictions
const restrictionst restrictions
Definition: restrict_function_pointers.h:92
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:627
cmdlinet
Definition: cmdline.h:20
function_pointer_restrictionst::merge_function_pointer_restrictions
static restrictionst merge_function_pointer_restrictions(restrictionst lhs, const restrictionst &rhs)
Definition: restrict_function_pointers.cpp:222
json
static void json(json_objectT &result, const irep_idt &property_id, const property_infot &property_info)
Definition: properties.cpp:120
function_pointer_restrictionst::restrictionst
std::unordered_map< irep_idt, std::unordered_set< irep_idt > > restrictionst
Definition: restrict_function_pointers.h:89
function_pointer_restrictionst::read_from_file
static function_pointer_restrictionst read_from_file(const std::string &filename, const goto_modelt &goto_model, message_handlert &message_handler)
Definition: restrict_function_pointers.cpp:572
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:425
message_handlert
Definition: message.h:27
goto_functiont
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
Definition: goto_function.h:23
function_pointer_restrictionst::restrictiont
restrictionst::value_type restrictiont
Definition: restrict_function_pointers.h:90
function_pointer_restrictionst
Definition: restrict_function_pointers.h:85
optionalt
nonstd::optional< T > optionalt
Definition: optional.h:35
function_pointer_restrictionst::from_json
static function_pointer_restrictionst from_json(const jsont &json, const goto_modelt &goto_model)
Definition: restrict_function_pointers.cpp:529
invalid_restriction_exceptiont::what
std::string what() const override
A human readable description of what went wrong.
Definition: restrict_function_pointers.cpp:94
goto_program.h
invalid_restriction_exceptiont::invalid_restriction_exceptiont
invalid_restriction_exceptiont(std::string reason, std::string correct_format="")
Definition: restrict_function_pointers.cpp:86
function_pointer_restrictionst::parse_function_pointer_restrictions_from_file
static restrictionst parse_function_pointer_restrictions_from_file(const std::list< std::string > &filenames, const goto_modelt &goto_model, message_handlert &message_handler)
Definition: restrict_function_pointers.cpp:282
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:195
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:109
function_pointer_restrictionst::write_to_file
void write_to_file(const std::string &filename) const
Definition: restrict_function_pointers.cpp:608
goto_programt::const_targett
instructionst::const_iterator const_targett
Definition: goto_program.h:587
cprover_exception_baset::reason
std::string reason
The reason this exception was generated.
Definition: exception_utils.h:44
cprover_exception_baset
Base class for exceptions thrown in the cprover project.
Definition: exception_utils.h:24
irep.h