@@ -73,3 +73,74 @@ void remove_functions(
7373 for (const auto &f : names)
7474 remove_function (goto_model, f, message_handler);
7575}
76+
77+ // / Remove functions matching a regular expression pattern
78+ // / \param goto_model: The goto model to modify
79+ // / \param pattern: The regex pattern to match function names against
80+ // / \param message_handler: For status/warning/error messages
81+ static void remove_functions_regex (
82+ goto_modelt &goto_model,
83+ const std::regex &pattern,
84+ message_handlert &message_handler)
85+ {
86+ messaget message{message_handler};
87+
88+ message.debug () << " Removing functions matching pattern: " << pattern
89+ << messaget::eom;
90+
91+ // Collect matching function names first to avoid modifying the map while iterating
92+ std::list<irep_idt> matching_functions;
93+
94+ for (const auto &entry : goto_model.goto_functions .function_map )
95+ {
96+ const std::string &function_name = id2string (entry.first );
97+ if (std::regex_match (function_name, pattern))
98+ {
99+ matching_functions.push_back (entry.first );
100+ }
101+ }
102+
103+ // Now remove all matching functions
104+ for (const auto &func : matching_functions)
105+ {
106+ remove_function (goto_model, func, message_handler);
107+ }
108+
109+ message.debug () << " Removed " << matching_functions.size ()
110+ << " function(s) matching pattern: " << pattern
111+ << messaget::eom;
112+ }
113+
114+ void remove_functions_regex (
115+ goto_modelt &goto_model,
116+ const std::list<std::string> &patterns,
117+ message_handlert &message_handler)
118+ {
119+ std::string combined_pattern;
120+ for (const auto &pattern : patterns)
121+ {
122+ if (pattern.empty ())
123+ continue ;
124+ if (!combined_pattern.empty ())
125+ combined_pattern += ' |' ;
126+ combined_pattern += pattern;
127+ }
128+
129+ if (combined_pattern.empty ())
130+ return ;
131+
132+ messaget message{message_handler};
133+
134+ try
135+ {
136+ std::regex regex_pattern{combined_pattern};
137+
138+ remove_functions_regex (goto_model, regex_pattern, message_handler);
139+ }
140+ catch (const std::regex_error &e)
141+ {
142+ message.error () << " Invalid regular expression pattern: "
143+ << combined_pattern << " (" << e.what () << " )"
144+ << messaget::eom;
145+ }
146+ }
0 commit comments