1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- mode: C++ -*-
3 //
4 // Copyright (C) 2013-2021 Red Hat, Inc.
5 
6 /// @file
7 
8 #include "config.h"
9 
10 #include <algorithm>
11 #include <cassert>
12 #include <cstdio>
13 #include <cstring>
14 #include <stdexcept>
15 #include <unordered_map>
16 
17 #include "abg-internal.h"
18 
19 // <headers defining libabigail's API go under here>
20 ABG_BEGIN_EXPORT_DECLARATIONS
21 
22 #include "abg-corpus.h"
23 #include "abg-ir.h"
24 #include "abg-reader.h"
25 #include "abg-sptr-utils.h"
26 #include "abg-symtab-reader.h"
27 #include "abg-tools-utils.h"
28 #include "abg-writer.h"
29 
30 ABG_END_EXPORT_DECLARATIONS
31 // </headers defining libabigail's API>
32 
33 #include "abg-corpus-priv.h"
34 #include "abg-ir-priv.h"
35 
36 namespace abigail
37 {
38 
39 namespace ir
40 {
41 
42 using std::ostringstream;
43 using std::unordered_map;
44 using std::list;
45 using std::vector;
46 
47 using regex::regex_t_sptr;
48 
49 /// Constructor of @ref corpus::exported_decls_builder.
50 ///
51 /// @param fns a reference to the vector of exported functions.
52 ///
53 /// @param vars a reference to the vector of exported variables.
54 ///
55 /// @param fns_suppress_regexps the regular expressions that designate
56 /// the functions to suppress from the exported functions set.
57 ///
58 /// @param vars_suppress_regexps the regular expressions that designate
59 /// the variables to suppress from the exported variables set.
60 ///
61 /// @param fns_keep_regexps the regular expressions that designate the
62 /// functions to keep in the exported functions set.
63 ///
64 /// @param fns_keep_regexps the regular expressions that designate the
65 /// functions to keep in the exported functions set.
66 ///
67 /// @param vars_keep_regexps the regular expressions that designate
68 /// the variables to keep in the exported variables set.
69 ///
70 /// @param sym_id_of_fns_to_keep the IDs of the functions to keep in
71 /// the exported functions set.
72 ///
73 /// @param sym_id_of_vars_to_keep the IDs of the variables to keep in
74 /// the exported variables set.
75 corpus::exported_decls_builder
exported_decls_builder(functions & fns,variables & vars,strings_type & fns_suppress_regexps,strings_type & vars_suppress_regexps,strings_type & fns_keep_regexps,strings_type & vars_keep_regexps,strings_type & sym_id_of_fns_to_keep,strings_type & sym_id_of_vars_to_keep)76 ::exported_decls_builder(functions&	fns,
77 			 variables&	vars,
78 			 strings_type&	fns_suppress_regexps,
79 			 strings_type&	vars_suppress_regexps,
80 			 strings_type&	fns_keep_regexps,
81 			 strings_type&	vars_keep_regexps,
82 			 strings_type&	sym_id_of_fns_to_keep,
83 			 strings_type&	sym_id_of_vars_to_keep)
84   : priv_(new priv(fns, vars,
85 		   fns_suppress_regexps,
86 		   vars_suppress_regexps,
87 		   fns_keep_regexps,
88 		   vars_keep_regexps,
89 		   sym_id_of_fns_to_keep,
90 		   sym_id_of_vars_to_keep))
91 {
92 }
93 
94 /// Getter for the reference to the vector of exported functions.
95 /// This vector is shared with with the @ref corpus.  It's where the
96 /// set of exported function is ultimately stored.
97 ///
98 /// @return a reference to the vector of exported functions.
99 const corpus::functions&
exported_functions() const100 corpus::exported_decls_builder::exported_functions() const
101 {return priv_->fns_;}
102 
103 /// Getter for the reference to the vector of exported functions.
104 /// This vector is shared with with the @ref corpus.  It's where the
105 /// set of exported function is ultimately stored.
106 ///
107 /// @return a reference to the vector of exported functions.
108 corpus::functions&
exported_functions()109 corpus::exported_decls_builder::exported_functions()
110 {return priv_->fns_;}
111 
112 /// Getter for the reference to the vector of exported variables.
113 /// This vector is shared with with the @ref corpus.  It's where the
114 /// set of exported variable is ultimately stored.
115 ///
116 /// @return a reference to the vector of exported variables.
117 const corpus::variables&
exported_variables() const118 corpus::exported_decls_builder::exported_variables() const
119 {return priv_->vars_;}
120 
121 /// Getter for the reference to the vector of exported variables.
122 /// This vector is shared with with the @ref corpus.  It's where the
123 /// set of exported variable is ultimately stored.
124 ///
125 /// @return a reference to the vector of exported variables.
126 corpus::variables&
exported_variables()127 corpus::exported_decls_builder::exported_variables()
128 {return priv_->vars_;}
129 
130 /// Consider at all the tunables that control wether a function should
131 /// be added to the set of exported function and if it fits in, add
132 /// the function to that set.
133 ///
134 /// @param fn the function to add the set of exported functions.
135 void
maybe_add_fn_to_exported_fns(function_decl * fn)136 corpus::exported_decls_builder::maybe_add_fn_to_exported_fns(function_decl* fn)
137 {
138   if (!fn->get_is_in_public_symbol_table())
139     return;
140 
141   const string& fn_id = priv_->get_id(*fn);
142   ABG_ASSERT(!fn_id.empty());
143 
144   if (priv_->fn_is_in_id_fns_map(fn))
145     return;
146 
147   if (priv_->keep_wrt_id_of_fns_to_keep(fn)
148       && priv_->keep_wrt_regex_of_fns_to_suppress(fn)
149       && priv_->keep_wrt_regex_of_fns_to_keep(fn))
150     priv_->add_fn_to_exported(fn);
151 }
152 
153 /// Consider at all the tunables that control wether a variable should
154 /// be added to the set of exported variable and if it fits in, add
155 /// the variable to that set.
156 ///
157 /// @param fn the variable to add the set of exported variables.
158 void
maybe_add_var_to_exported_vars(var_decl * var)159 corpus::exported_decls_builder::maybe_add_var_to_exported_vars(var_decl* var)
160 {
161   if (!var->get_is_in_public_symbol_table())
162     return;
163 
164   const string& var_id = priv_->get_id(*var);
165   ABG_ASSERT(!var_id.empty());
166 
167   if (priv_->var_id_is_in_id_var_map(var_id))
168     return;
169 
170   if (priv_->keep_wrt_id_of_vars_to_keep(var)
171       && priv_->keep_wrt_regex_of_vars_to_suppress(var)
172       && priv_->keep_wrt_regex_of_vars_to_keep(var))
173     priv_->add_var_to_exported(var);
174 }
175 
176 // </corpus::exported_decls_builder>
177 
178 /// Convenience typedef for a hash map of pointer to function_decl and
179 /// boolean.
180 typedef unordered_map<const function_decl*,
181 		      bool,
182 		      function_decl::hash,
183 		      function_decl::ptr_equal> fn_ptr_map_type;
184 
185 /// Convenience typedef for a hash map of string and pointer to
186 /// function_decl.
187 typedef unordered_map<string, const function_decl*> str_fn_ptr_map_type;
188 
189 /// Convenience typedef for a hash map of pointer to var_decl and boolean.
190 typedef unordered_map<const var_decl*,
191 		      bool,
192 		      var_decl::hash,
193 		      var_decl::ptr_equal> var_ptr_map_type;
194 
195 /// This is a comparison functor for comparing pointers to @ref
196 /// function_decl.
197 struct func_comp
198 {
199   /// The comparisong operator for pointers to @ref function_decl.  It
200   /// performs a string comparison of the mangled names of the
201   /// functions.  If the functions don't have mangled names, it
202   /// compares their names instead.
203   ///
204   /// @param first the first function to consider in the comparison.
205   ///
206   /// @param second the second function to consider in the comparison.
207   ///
208   /// @return true if the (mangled) name of the first function is less
209   /// than the (mangled)name of the second one, false otherwise.
210   bool
operator ()abigail::ir::func_comp211   operator()(const function_decl* first,
212 	     const function_decl* second) const
213   {
214     ABG_ASSERT(first != 0 && second != 0);
215 
216     string first_name, second_name;
217     first_name = first->get_linkage_name();
218     if (first_name.empty())
219       first_name = first->get_name();
220     ABG_ASSERT(!first_name.empty());
221 
222     second_name = second->get_linkage_name();
223     if (second_name.empty())
224       second_name = second->get_name();
225     ABG_ASSERT(!second_name.empty());
226 
227     return first_name < second_name;
228   }
229 };
230 
231 /// This is a comparison functor for comparing pointers to @ref
232 /// var_decl.
233 struct var_comp
234 {
235   /// The comparison operator for pointers to @ref var_decl.
236   ///
237   /// It perform a string comparison on the names of the variables.
238   ///
239   /// @param first the first variable to consider for the comparison.
240   ///
241   /// @param second the second variable to consider for the comparison.
242   ///
243   /// @return true if first is less than second, false otherwise.
244   bool
operator ()abigail::ir::var_comp245   operator()(const var_decl* first,
246 	     const var_decl* second) const
247   {
248     ABG_ASSERT(first != 0 && second != 0);
249 
250     string first_name, second_name;
251     first_name = first->get_linkage_name();
252     if (first_name.empty())
253       {
254 	first_name = first->get_pretty_representation();
255 	second_name = second->get_pretty_representation();
256 	ABG_ASSERT(!second_name.empty());
257       }
258     ABG_ASSERT(!first_name.empty());
259 
260     if (second_name.empty())
261       second_name = second->get_linkage_name();
262 
263     if (second_name.empty())
264       {
265 	second_name = second->get_pretty_representation();
266 	first_name = first->get_pretty_representation();
267 	ABG_ASSERT(!first_name.empty());
268       }
269     ABG_ASSERT(!second_name.empty());
270 
271     return first_name < second_name;
272   }
273 };
274 
275 
276 /// A comparison functor to compare elf_symbols for the purpose of
277 /// sorting.
278 struct comp_elf_symbols_functor
279 {
280   bool
operator ()abigail::ir::comp_elf_symbols_functor281   operator()(const elf_symbol& l,
282 	     const elf_symbol& r) const
283   {return l.get_id_string() < r.get_id_string();}
284 
285   bool
operator ()abigail::ir::comp_elf_symbols_functor286   operator()(const elf_symbol_sptr l,
287 	     const elf_symbol_sptr r) const
288   {return operator()(*l, *r);}
289 }; // end struct comp_elf_symbols_functor
290 
291 
292 // <corpus stuff>
293 
294 /// Get the maps that associate a name to a certain kind of type.
295 type_maps&
get_types()296 corpus::priv::get_types()
297 {return types_;}
298 
299 /// Get the maps that associate a name to a certain kind of type.
300 const type_maps&
get_types() const301 corpus::priv::get_types() const
302 {return types_;}
303 
304 /// Return a sorted vector of function symbols for this corpus.
305 ///
306 /// Note that the first time this function is called, the symbols are
307 /// sorted and cached.  Subsequent invocations of this function return
308 /// the cached vector that was built previously.
309 ///
310 /// @return the sorted list of function symbols.
311 const elf_symbols&
get_sorted_fun_symbols() const312 corpus::priv::get_sorted_fun_symbols() const
313 {
314   if (!sorted_fun_symbols)
315     {
316       auto filter = symtab_->make_filter();
317       filter.set_functions();
318       sorted_fun_symbols = elf_symbols(symtab_->begin(filter), symtab_->end());
319     }
320   return *sorted_fun_symbols;
321 }
322 
323 /// Return a map from name to function symbol for this corpus.
324 ///
325 /// Note that the first time this function is called, the map is built.
326 /// Subsequent invocations of this function return the cached map that was
327 /// built previously.
328 ///
329 /// @return the name function symbol map
330 const string_elf_symbols_map_type&
get_fun_symbol_map() const331 corpus::priv::get_fun_symbol_map() const
332 {
333   if (!fun_symbol_map)
334     {
335       fun_symbol_map = string_elf_symbols_map_type();
336       for (const auto& symbol : get_sorted_fun_symbols())
337 	(*fun_symbol_map)[symbol->get_name()].push_back(symbol);
338     }
339   return *fun_symbol_map;
340 }
341 
342 /// Getter for a sorted vector of the function symbols undefined in
343 /// this corpus.
344 ///
345 /// @return a vector of the function symbols undefined in this corpus,
346 /// sorted by name and then version.
347 const elf_symbols&
get_sorted_undefined_fun_symbols() const348 corpus::priv::get_sorted_undefined_fun_symbols() const
349 {
350   if (!sorted_undefined_fun_symbols)
351     {
352       auto filter = symtab_->make_filter();
353       filter.set_functions();
354       filter.set_undefined_symbols();
355       filter.set_public_symbols(false);
356 
357       sorted_undefined_fun_symbols =
358 	elf_symbols(symtab_->begin(filter), symtab_->end());
359     }
360   return *sorted_undefined_fun_symbols;
361 }
362 
363 /// Return a map from name to undefined function symbol for this corpus.
364 ///
365 /// Note that the first time this function is called, the map is built.
366 /// Subsequent invocations of this function return the cached map that was
367 /// built previously.
368 ///
369 /// @return the name function symbol map for undefined symbols
370 const string_elf_symbols_map_type&
get_undefined_fun_symbol_map() const371 corpus::priv::get_undefined_fun_symbol_map() const
372 {
373   if (!undefined_fun_symbol_map)
374     {
375       undefined_fun_symbol_map = string_elf_symbols_map_type();
376       for (const auto& symbol : get_sorted_undefined_fun_symbols())
377 	(*undefined_fun_symbol_map)[symbol->get_name()].push_back(symbol);
378     }
379   return *undefined_fun_symbol_map;
380 }
381 
382 /// Return a list of symbols that are not referenced by any function of
383 /// corpus::get_functions().
384 ///
385 /// Note that this function considers the list of function symbols to keep,
386 /// that is provided by corpus::get_sym_ids_of_fns_to_keep(). If a given
387 /// unreferenced function symbol is not in the list of functions to keep, then
388 /// that symbol is dropped and will not be part of the resulting table of
389 /// unreferenced symbol that is built.
390 ///
391 /// @return list of symbols that are not referenced by any function
392 const elf_symbols&
get_unreferenced_function_symbols() const393 corpus::priv::get_unreferenced_function_symbols() const
394 {
395   if (!unrefed_fun_symbols)
396     {
397       unrefed_fun_symbols = elf_symbols();
398       if (symtab_)
399 	{
400 	  unordered_map<string, bool> refed_funs;
401 
402 	  for (const auto& function : fns)
403 	    if (elf_symbol_sptr sym = function->get_symbol())
404 	      {
405 		refed_funs[sym->get_id_string()] = true;
406 		for (elf_symbol_sptr a = sym->get_next_alias();
407 		     a && !a->is_main_symbol(); a = a->get_next_alias())
408 		  refed_funs[a->get_id_string()] = true;
409 	      }
410 
411 	  auto filter = symtab_->make_filter();
412 	  filter.set_functions();
413 	  for (const auto& symbol :
414 	       symtab_reader::filtered_symtab(*symtab_, filter))
415 	    {
416 	      const std::string sym_id = symbol->get_id_string();
417 	      if (refed_funs.find(sym_id) == refed_funs.end())
418 		{
419 		  bool keep = sym_id_fns_to_keep.empty();
420 		  for (const auto& id : sym_id_fns_to_keep)
421 		    {
422 		      if (id == sym_id)
423 			{
424 			  keep = true;
425 			  break;
426 			}
427 		    }
428 		  if (keep)
429 		    unrefed_fun_symbols->push_back(symbol);
430 		}
431 	    }
432 	}
433     }
434   return *unrefed_fun_symbols;
435 }
436 
437 /// Getter for the sorted vector of variable symbols for this corpus.
438 ///
439 /// Note that the first time this function is called, it computes the
440 /// sorted vector, caches the result and returns it.  Subsequent
441 /// invocations of this function just return the cached vector.
442 ///
443 /// @return the sorted vector of variable symbols for this corpus.
444 const elf_symbols&
get_sorted_var_symbols() const445 corpus::priv::get_sorted_var_symbols() const
446 {
447   if (!sorted_var_symbols)
448     {
449       auto filter = symtab_->make_filter();
450       filter.set_variables();
451 
452       sorted_var_symbols = elf_symbols(symtab_->begin(filter), symtab_->end());
453     }
454   return *sorted_var_symbols;
455 }
456 
457 /// Return a map from name to variable symbol for this corpus.
458 ///
459 /// Note that the first time this function is called, the map is built.
460 /// Subsequent invocations of this function return the cached map that was
461 /// built previously.
462 ///
463 /// @return the name variable symbol map
464 const string_elf_symbols_map_type&
get_var_symbol_map() const465 corpus::priv::get_var_symbol_map() const
466 {
467   if (!var_symbol_map)
468     {
469       var_symbol_map = string_elf_symbols_map_type();
470       for (const auto& symbol : get_sorted_var_symbols())
471 	(*var_symbol_map)[symbol->get_name()].push_back(symbol);
472     }
473   return *var_symbol_map;
474 }
475 
476 /// Getter for a sorted vector of the variable symbols undefined in
477 /// this corpus.
478 ///
479 /// @return a vector of the variable symbols undefined in this corpus,
480 /// sorted by name and then version.
481 const elf_symbols&
get_sorted_undefined_var_symbols() const482 corpus::priv::get_sorted_undefined_var_symbols() const
483 {
484   if (!sorted_undefined_var_symbols)
485     {
486       auto filter = symtab_->make_filter();
487       filter.set_variables();
488       filter.set_undefined_symbols();
489       filter.set_public_symbols(false);
490 
491       sorted_undefined_var_symbols =
492 	  elf_symbols(symtab_->begin(filter), symtab_->end());
493     }
494   return *sorted_undefined_var_symbols;
495 }
496 
497 /// Return a map from name to undefined variable symbol for this corpus.
498 ///
499 /// Note that the first time this function is called, the map is built.
500 /// Subsequent invocations of this function return the cached map that was
501 /// built previously.
502 ///
503 /// @return the name undefined variable symbol map
504 const string_elf_symbols_map_type&
get_undefined_var_symbol_map() const505 corpus::priv::get_undefined_var_symbol_map() const
506 {
507   if (!undefined_var_symbol_map)
508     {
509       undefined_var_symbol_map = string_elf_symbols_map_type();
510       for (const auto& symbol : get_sorted_undefined_var_symbols())
511 	(*undefined_var_symbol_map)[symbol->get_name()].push_back(symbol);
512     }
513   return *undefined_var_symbol_map;
514 }
515 
516 /// Return a list of symbols that are not referenced by any variable of
517 /// corpus::get_variables().
518 ///
519 /// Note that this function considers the list of variable symbols to keep,
520 /// that is provided by corpus::get_sym_ids_of_vars_to_keep(). If a given
521 /// unreferenced variable symbol is not in the list of variable to keep, then
522 /// that symbol is dropped and will not be part of the resulting table of
523 /// unreferenced symbol that is built.
524 ///
525 /// @return list of symbols that are not referenced by any variable
526 const elf_symbols&
get_unreferenced_variable_symbols() const527 corpus::priv::get_unreferenced_variable_symbols() const
528 {
529   if (!unrefed_var_symbols)
530     {
531       unrefed_var_symbols = elf_symbols();
532       if (symtab_)
533 	{
534 	  unordered_map<string, bool> refed_vars;
535 	  for (const auto& variable : vars)
536 	    if (elf_symbol_sptr sym = variable->get_symbol())
537 	      {
538 		refed_vars[sym->get_id_string()] = true;
539 		for (elf_symbol_sptr a = sym->get_next_alias();
540 		     a && !a->is_main_symbol(); a = a->get_next_alias())
541 		  refed_vars[a->get_id_string()] = true;
542 	      }
543 
544 	  auto filter = symtab_->make_filter();
545 	  filter.set_variables();
546 	  for (const auto& symbol :
547 	       symtab_reader::filtered_symtab(*symtab_, filter))
548 	    {
549 	      const std::string sym_id = symbol->get_id_string();
550 	      if (refed_vars.find(sym_id) == refed_vars.end())
551 		{
552 		  bool keep = sym_id_vars_to_keep.empty();
553 		  for (const auto& id : sym_id_vars_to_keep)
554 		    {
555 		      if (id == sym_id)
556 			{
557 			  keep = true;
558 			  break;
559 			}
560 		    }
561 		  if (keep)
562 		    unrefed_var_symbols->push_back(symbol);
563 		}
564 	    }
565 	}
566     }
567   return *unrefed_var_symbols;
568 }
569 
570 
571 /// Getter of the set of pretty representation of types that are
572 /// reachable from public interfaces (global functions and variables).
573 ///
574 /// @return the set of pretty representation of types that are
575 /// reachable from public interfaces (global functions and variables).
576 unordered_set<interned_string, hash_interned_string>*
get_public_types_pretty_representations()577 corpus::priv::get_public_types_pretty_representations()
578 {
579   if (group)
580     return group->get_public_types_pretty_representations();
581 
582   if (pub_type_pretty_reprs_ == 0)
583     pub_type_pretty_reprs_ =
584 	new unordered_set<interned_string, hash_interned_string>;
585   return pub_type_pretty_reprs_;
586 }
587 
588 /// Destructor of the @ref corpus::priv type.
~priv()589 corpus::priv::~priv()
590 {
591   delete pub_type_pretty_reprs_;
592 }
593 
594 /// Constructor of the @ref corpus type.
595 ///
596 /// @param env the environment of the corpus.
597 ///
598 /// @param path the path to the file containing the ABI corpus.
corpus(ir::environment * env,const string & path)599 corpus::corpus(ir::environment* env, const string& path)
600 {
601   priv_.reset(new priv(path, env));
602   init_format_version();
603 }
604 
605 /// Getter of the enviroment of the corpus.
606 ///
607 /// @return the environment of this corpus.
608 const environment*
get_environment() const609 corpus::get_environment() const
610 {return priv_->env;}
611 
612 /// Getter of the enviroment of the corpus.
613 ///
614 /// @return the environment of this corpus.
615 environment*
get_environment()616 corpus::get_environment()
617 {return priv_->env;}
618 
619 /// Setter of the environment of this corpus.
620 ///
621 /// @param e the new environment.
622 void
set_environment(environment * e)623 corpus::set_environment(environment* e)
624 {
625   priv_->env = e;
626   init_format_version();
627 }
628 
629 /// Add a translation unit to the current ABI Corpus. Next time
630 /// corpus::save is called, all the translation unit that got added to
631 /// the corpus are going to be serialized on disk in the file
632 /// associated to the current corpus.
633 ///
634 /// Note that two translation units with the same path (as returned by
635 /// translation_unit::get_path) cannot be added to the same @ref
636 /// corpus.  If that happens, the library aborts.
637 ///
638 /// @param tu the new translation unit to add.
639 void
add(const translation_unit_sptr tu)640 corpus::add(const translation_unit_sptr tu)
641 {
642   if (!tu->get_environment())
643     tu->set_environment(get_environment());
644 
645   ABG_ASSERT(tu->get_environment() == get_environment());
646 
647   ABG_ASSERT(priv_->members.insert(tu).second);
648 
649   if (!tu->get_absolute_path().empty())
650     {
651       // Update the path -> translation_unit map.
652       string_tu_map_type::const_iterator i =
653 	priv_->path_tu_map.find(tu->get_absolute_path());
654       ABG_ASSERT(i == priv_->path_tu_map.end());
655       priv_->path_tu_map[tu->get_absolute_path()] = tu;
656     }
657 
658   tu->set_corpus(this);
659 }
660 
661 /// Return the list of translation units of the current corpus.
662 ///
663 /// @return the list of translation units of the current corpus.
664 const translation_units&
get_translation_units() const665 corpus::get_translation_units() const
666 {return priv_->members;}
667 
668 /// Find the translation unit that has a given path.
669 ///
670 /// @param path the path of the translation unit to look for.
671 ///
672 /// @return the translation unit found, if any.  Otherwise, return
673 /// nil.
674 const translation_unit_sptr
find_translation_unit(const string & path) const675 corpus::find_translation_unit(const string &path) const
676 {
677   string_tu_map_type::const_iterator i =
678     priv_->path_tu_map.find(path);
679 
680   if (i == priv_->path_tu_map.end())
681     return translation_unit_sptr();
682   return i->second;
683 }
684 
685 /// Erase the translation units contained in this in-memory object.
686 ///
687 /// Note that the on-disk archive file that contains the serialized
688 /// representation of this object is not modified.
689 void
drop_translation_units()690 corpus::drop_translation_units()
691 {priv_->members.clear();}
692 
693 /// Get the maps that associate a name to a certain kind of type.
694 ///
695 /// @return the maps that associate a name to a certain kind of type.
696 type_maps&
get_types()697 corpus::get_types()
698 {return priv_->types_;}
699 
700 /// Get the maps that associate a name to a certain kind of type.
701 ///
702 /// @return the maps that associate a name to a certain kind of
703 /// type.
704 const type_maps&
get_types() const705 corpus::get_types() const
706 {return priv_->types_;}
707 
708 /// Get the maps that associate a location string to a certain kind of
709 /// type.
710 ///
711 /// The location string is the result of the invocation to the
712 /// function abigail::ir::location::expand().  It has the form
713 /// "file.c:4:1", with 'file.c' being the file name, '4' being the
714 /// line number and '1' being the column number.
715 ///
716 /// @return the maps.
717 const type_maps&
get_type_per_loc_map() const718 corpus::get_type_per_loc_map() const
719 {return priv_->type_per_loc_map_;}
720 
721 /// Test if the recording of reachable types (and thus, indirectly,
722 /// the recording of non-reachable types) is activated for the
723 /// current @ref corpus.
724 ///
725 /// @return true iff the recording of reachable types is activated for
726 /// the current @ref corpus.
727 bool
recording_types_reachable_from_public_interface_supported()728 corpus::recording_types_reachable_from_public_interface_supported()
729 {
730   return (priv_->get_public_types_pretty_representations()
731 	  && !priv_->get_public_types_pretty_representations()->empty());
732 }
733 
734 /// Record a type as being reachable from public interfaces (global
735 /// functions and variables).
736 ///
737 /// @param t the type to record as reachable.
738 void
record_type_as_reachable_from_public_interfaces(const type_base & t)739 corpus::record_type_as_reachable_from_public_interfaces(const type_base& t)
740 {
741   string repr = get_pretty_representation(&t, /*internal=*/true);
742   interned_string s = t.get_environment()->intern(repr);
743   priv_->get_public_types_pretty_representations()->insert(s);
744 }
745 
746 /// Test if a type is reachable from public interfaces (global
747 /// functions and variables).
748 ///
749 /// For a type to be considered reachable from public interfaces, it
750 /// must have been previously marked as such by calling
751 /// corpus::record_type_as_reachable_from_public_interfaces.
752 ///
753 /// @param t the type to test for.
754 ///
755 /// @return true iff @p t is reachable from public interfaces.
756 bool
type_is_reachable_from_public_interfaces(const type_base & t) const757 corpus::type_is_reachable_from_public_interfaces(const type_base& t) const
758 {
759   string repr = get_pretty_representation(&t, /*internal=*/true);
760   interned_string s = t.get_environment()->intern(repr);
761 
762   return (priv_->get_public_types_pretty_representations()->find(s)
763 	  !=  priv_->get_public_types_pretty_representations()->end());
764 }
765 
766 /// Getter of a sorted vector of the types that are *NOT* reachable
767 /// from public interfaces.
768 ///
769 /// Note that for this to be non-empty, the libabigail reader that
770 /// analyzed the input (be it a binary or an abixml file) must have be
771 /// configured to load types that are not reachable from public
772 /// interfaces.
773 ///
774 /// @return a reference to a vector of sorted types NON reachable from
775 /// public interfaces.
776 const vector<type_base_wptr>&
get_types_not_reachable_from_public_interfaces() const777 corpus::get_types_not_reachable_from_public_interfaces() const
778 {
779   if (priv_->types_not_reachable_from_pub_ifaces_.empty())
780     {
781       const type_maps& types = get_types();
782       for (vector<type_base_wptr>::const_iterator it =
783 	     types.get_types_sorted_by_name().begin();
784 	   it != types.get_types_sorted_by_name().end();
785 	   ++it)
786 	{
787 	  type_base_sptr t(*it);
788 	  if (!type_is_reachable_from_public_interfaces(*t))
789 	    priv_->types_not_reachable_from_pub_ifaces_.push_back(t);
790 	}
791     }
792 
793   return priv_->types_not_reachable_from_pub_ifaces_;
794 }
795 
796 /// Get the maps that associate a location string to a certain kind of
797 /// type.
798 ///
799 /// The location string is the result of the invocation to the
800 /// function abigail::ir::location::expand().  It has the form
801 /// "file.c:4:1", with 'file.c' being the file name, '4' being the
802 /// line number and '1' being the column number.
803 ///
804 /// @return the maps.
805 type_maps&
get_type_per_loc_map()806 corpus::get_type_per_loc_map()
807 {return priv_->type_per_loc_map_;}
808 
809 /// Getter of the group this corpus is a member of.
810 ///
811 /// @return the group this corpus is a member of, or nil if it's not
812 /// part of any @ref corpus_group.
813 const corpus_group*
get_group() const814 corpus::get_group() const
815 {return priv_->group;}
816 
817 /// Getter of the group this corpus belongs to.
818 ///
819 /// @return the group this corpus belong to, or nil if it's not part
820 /// of any @ref corpus_group.
821 corpus_group*
get_group()822 corpus::get_group()
823 {return priv_->group;}
824 
825 /// Setter of the group this corpus belongs to.
826 ///
827 /// @param g the new group.
828 void
set_group(corpus_group * g)829 corpus::set_group(corpus_group* g)
830 {priv_->group = g;}
831 
832 /// Initialize the abixml serialization format version number of the
833 /// corpus.
834 ///
835 /// This function sets the format version number ot the default one
836 /// supported by the current version of Libabigail.
837 void
init_format_version()838 corpus::init_format_version()
839 {
840   if (priv_->env)
841     {
842       set_format_major_version_number
843 	(priv_->env->get_config().get_format_major_version_number());
844       set_format_minor_version_number
845 	(priv_->env->get_config().get_format_minor_version_number());
846     }
847 }
848 
849 /// Getter for the origin of the corpus.
850 ///
851 /// @return the origin of the corpus.
852 corpus::origin
get_origin() const853 corpus::get_origin() const
854 {return priv_->origin_;}
855 
856 /// Setter for the origin of the corpus.
857 ///
858 /// @param o the new origin for the corpus.
859 void
set_origin(origin o)860 corpus::set_origin(origin o)
861 {priv_->origin_ = o;}
862 
863 /// Getter of the major version number of the abixml serialization
864 /// format.
865 ///
866 /// @return the major version number of the abixml format.
867 string&
get_format_major_version_number() const868 corpus::get_format_major_version_number() const
869 {return priv_->format_major_version_number_;}
870 
871 /// Setter of the major version number of the abixml serialization
872 /// format.
873 ///
874 /// @param maj the new major version numberof the abixml format.
875 void
set_format_major_version_number(const string & maj)876 corpus::set_format_major_version_number(const string& maj)
877 {priv_->format_major_version_number_ = maj;}
878 
879 /// Getter of the minor version number of the abixml serialization
880 /// format.
881 ///
882 /// @return the minor version number of the abixml serialization
883 /// format.
884 string&
get_format_minor_version_number() const885 corpus::get_format_minor_version_number() const
886 {return priv_->format_minor_version_number_;}
887 
888 /// Setter of the minor version number of the abixml serialization
889 /// format.
890 ///
891 /// @param min the new minor version number of the abixml
892 /// serialization format.
893 void
set_format_minor_version_number(const string & min)894 corpus::set_format_minor_version_number(const string& min)
895 {priv_->format_minor_version_number_ = min;}
896 
897 /// Get the file path associated to the corpus file.
898 ///
899 /// A subsequent call to corpus::read will deserialize the content of
900 /// the abi file expected at this path; likewise, a call to
901 /// corpus::write will serialize the translation units contained in
902 /// the corpus object into the on-disk file at this path.
903 ///
904 /// @return the file path associated to the current corpus.
905 string&
get_path() const906 corpus::get_path() const
907 {return priv_->path;}
908 
909 /// Set the file path associated to the corpus file.
910 ///
911 /// A subsequent call to corpus::read will deserialize the content of
912 /// the abi file expected at this path; likewise, a call to
913 /// corpus::write will serialize the translation units contained in
914 /// the corpus object into the on-disk file at this path.
915 ///
916 /// @param path the new file path to assciate to the current corpus.
917 void
set_path(const string & path)918 corpus::set_path(const string& path)
919 {priv_->path = path;}
920 
921 /// Getter of the needed property of the corpus.
922 ///
923 /// This property is meaningful for, e.g, corpora built from ELF
924 /// shared library files.  In that case, this is a vector of names of
925 /// dependencies of the ELF shared library file.
926 ///
927 /// @return the vector of dependencies needed by this corpus.
928 const vector<string>&
get_needed() const929 corpus::get_needed() const
930 {return priv_->needed;}
931 
932 /// Setter of the needed property of the corpus.
933 ///
934 /// This property is meaningful for, e.g, corpora built from ELF
935 /// shared library files.  In that case, this is a vector of names of
936 /// dependencies of the ELF shared library file.
937 ///
938 /// @param needed the new vector of dependencies needed by this
939 /// corpus.
940 void
set_needed(const vector<string> & needed)941 corpus::set_needed(const vector<string>& needed)
942 {priv_->needed = needed;}
943 
944 /// Getter for the soname property of the corpus.
945 ///
946 /// This property is meaningful for, e.g, corpora built from ELF
947 /// shared library files.  In that case, this is the shared object
948 /// name exported by the shared library.
949 ///
950 /// @return the soname property of the corpus.
951 const string&
get_soname()952 corpus::get_soname()
953 {return priv_->soname;}
954 
955 /// Setter for the soname property of the corpus.
956 ///
957 /// This property is meaningful for, e.g, corpora built from ELF
958 /// shared library files.  In that case, this is the shared object
959 /// name exported by the shared library.
960 ///
961 /// @param soname the new soname property of the corpus.
962 void
set_soname(const string & soname)963 corpus::set_soname(const string& soname)
964 {priv_->soname = soname;}
965 
966 /// Getter for the architecture name of the corpus.
967 ///
968 /// This property is meaningful for e.g, corpora built from ELF shared
969 /// library files.  In that case, this is a string representation of
970 /// the Elf{32,64}_Ehdr::e_machine field.
971 ///
972 /// @return the architecture name string.
973 const string&
get_architecture_name() const974 corpus::get_architecture_name() const
975 {return priv_->architecture_name;}
976 
977 /// Setter for the architecture name of the corpus.
978 ///
979 /// This property is meaningful for e.g, corpora built from ELF shared
980 /// library files.  In that case, this is a string representation of
981 /// the Elf{32,64}_Ehdr::e_machine field.
982 ///
983 /// @param arch the architecture name string.
984 void
set_architecture_name(const string & arch)985 corpus::set_architecture_name(const string& arch)
986 {priv_->architecture_name = arch;}
987 
988 /// Tests if the corpus is empty from an ABI surface perspective. I.e. if all
989 /// of these criteria are true:
990 ///  - all translation units (members) are empty
991 ///  - the maps function and variable symbols are not having entries
992 ///  - for shared libraries:
993 ///    - the soname is empty
994 ///    - there are no DT_NEEDED entries
995 ///
996 /// @return true if the corpus contains no translation unit.
997 bool
is_empty() const998 corpus::is_empty() const
999 {
1000   bool members_empty = true;
1001   for (translation_units::const_iterator i = priv_->members.begin(),
1002 					 e = priv_->members.end();
1003        i != e; ++i)
1004     {
1005       if (!(*i)->is_empty())
1006 	{
1007 	  members_empty = false;
1008 	  break;
1009 	}
1010     }
1011   return (members_empty
1012 	  && !get_symtab()->has_symbols()
1013 	  && priv_->soname.empty()
1014 	  && priv_->needed.empty());
1015 }
1016 
1017 /// Compare the current @ref corpus against another one.
1018 ///
1019 /// @param other the other corpus to compare against.
1020 ///
1021 /// @return true if the two corpus are equal, false otherwise.
1022 bool
operator ==(const corpus & other) const1023 corpus::operator==(const corpus& other) const
1024 {
1025   translation_units::const_iterator i, j;
1026   for (i = get_translation_units().begin(),
1027 	 j = other.get_translation_units().begin();
1028        (i != get_translation_units().end()
1029 	&& j != other.get_translation_units().end());
1030        ++i, ++j)
1031     if ((**i) != (**j))
1032       return false;
1033 
1034   return (i == get_translation_units().end()
1035 	  && j == other.get_translation_units().end());
1036 }
1037 
1038 /// Setter for the symtab object.
1039 ///
1040 /// @param symtab a shared pointer to the new symtab object
1041 void
set_symtab(symtab_reader::symtab_sptr symtab)1042 corpus::set_symtab(symtab_reader::symtab_sptr symtab)
1043 {priv_->symtab_ = symtab;}
1044 
1045 /// Getter for the symtab object.
1046 ///
1047 /// @return a shared pointer to the symtab object
1048 const symtab_reader::symtab_sptr&
get_symtab() const1049 corpus::get_symtab() const
1050 {return priv_->symtab_;}
1051 
1052 /// Getter for the function symbols map.
1053 ///
1054 /// @return a reference to the function symbols map.
1055 const string_elf_symbols_map_type&
get_fun_symbol_map() const1056 corpus::get_fun_symbol_map() const
1057 {return priv_->get_fun_symbol_map();}
1058 
1059 /// Getter for the map of function symbols that are undefined in this
1060 /// corpus.
1061 ///
1062 /// @return the map of function symbols not defined in this corpus.
1063 /// The key of the map is the name of the function symbol.  The value
1064 /// is a vector of all the function symbols that have the same name.
1065 const string_elf_symbols_map_type&
get_undefined_fun_symbol_map() const1066 corpus::get_undefined_fun_symbol_map() const
1067 {return priv_->get_undefined_fun_symbol_map();}
1068 
1069 /// Return a sorted vector of function symbols for this corpus.
1070 ///
1071 /// Note that the first time this function is called, the symbols are
1072 /// sorted and cached.  Subsequent invocations of this function return
1073 /// the cached vector that was built previously.
1074 ///
1075 /// @return the sorted list of function symbols.
1076 const elf_symbols&
get_sorted_fun_symbols() const1077 corpus::get_sorted_fun_symbols() const
1078 {return priv_->get_sorted_fun_symbols();}
1079 
1080 /// Getter for a sorted vector of the function symbols undefined in
1081 /// this corpus.
1082 ///
1083 /// @return a vector of the function symbols undefined in this corpus,
1084 /// sorted by name and then version.
1085 const elf_symbols&
get_sorted_undefined_fun_symbols() const1086 corpus::get_sorted_undefined_fun_symbols() const
1087 {return priv_->get_sorted_undefined_fun_symbols();}
1088 
1089 /// Getter for the sorted vector of variable symbols for this corpus.
1090 ///
1091 /// Note that the first time this function is called, it computes the
1092 /// sorted vector, caches the result and returns it.  Subsequent
1093 /// invocations of this function just return the cached vector.
1094 ///
1095 /// @return the sorted vector of variable symbols for this corpus.
1096 const elf_symbols&
get_sorted_var_symbols() const1097 corpus::get_sorted_var_symbols() const
1098 {return priv_->get_sorted_var_symbols();}
1099 
1100 /// Getter for a sorted vector of the variable symbols undefined in
1101 /// this corpus.
1102 ///
1103 /// @return a vector of the variable symbols undefined in this corpus,
1104 /// sorted by name and then version.
1105 const elf_symbols&
get_sorted_undefined_var_symbols() const1106 corpus::get_sorted_undefined_var_symbols() const
1107 {return priv_->get_sorted_undefined_var_symbols();}
1108 
1109 /// Getter for the variable symbols map.
1110 ///
1111 /// @return a reference to the variabl symbols map.
1112 const string_elf_symbols_map_type&
get_var_symbol_map() const1113 corpus::get_var_symbol_map() const
1114 {return priv_->get_var_symbol_map();}
1115 
1116 /// Getter for the map of variable symbols that are undefined in this
1117 /// corpus.
1118 ///
1119 /// @return the map of variable symbols not defined in this corpus.
1120 /// The key of the map is the name of the variable symbol.  The value
1121 /// is a vector of all the variable symbols that have the same name.
1122 const string_elf_symbols_map_type&
get_undefined_var_symbol_map() const1123 corpus::get_undefined_var_symbol_map() const
1124 {return priv_->get_undefined_var_symbol_map();}
1125 
1126 /// Look in the function symbols map for a symbol with a given name.
1127 ///
1128 /// @param n the name of the symbol to look for.
1129 ///
1130 /// return the first symbol with the name @p n.
1131 const elf_symbol_sptr
lookup_function_symbol(const string & n) const1132 corpus::lookup_function_symbol(const string& n) const
1133 {
1134   if (get_fun_symbol_map().empty())
1135     return elf_symbol_sptr();
1136 
1137   string_elf_symbols_map_type::const_iterator it =
1138     get_fun_symbol_map().find(n);
1139   if ( it == get_fun_symbol_map().end())
1140     return elf_symbol_sptr();
1141   return it->second[0];
1142 }
1143 
1144 /// Look into a set of symbols and look for a symbol that has a given
1145 /// version.
1146 ///
1147 /// This is a sub-routine for corpus::lookup_function_symbol() and
1148 /// corpus::lookup_variable_symbol().
1149 ///
1150 /// @param version the version of the symbol to look for.
1151 ///
1152 /// @param symbols the set of symbols to consider.
1153 ///
1154 /// @return the symbol found, or nil if none was found.
1155 static const elf_symbol_sptr
find_symbol_by_version(const elf_symbol::version & version,const vector<elf_symbol_sptr> & symbols)1156 find_symbol_by_version(const elf_symbol::version& version,
1157 		       const vector<elf_symbol_sptr>& symbols)
1158 {
1159   if (version.is_empty())
1160     {
1161       // We are looing for a symbol with no version.
1162 
1163       // So first look for possible aliases with no version
1164       for (elf_symbols::const_iterator s = symbols.begin();
1165 	   s != symbols.end();
1166 	   ++s)
1167 	if ((*s)->get_version().is_empty())
1168 	  return *s;
1169 
1170       // Or, look for a version that is a default one!
1171       for (elf_symbols::const_iterator s = symbols.begin();
1172 	   s != symbols.end();
1173 	   ++s)
1174 	if ((*s)->get_version().is_default())
1175 	  return *s;
1176     }
1177   else
1178     // We are looking for a symbol with a particular defined version.
1179     for (elf_symbols::const_iterator s = symbols.begin();
1180 	 s != symbols.end();
1181 	 ++s)
1182       if ((*s)->get_version().str() == version.str())
1183 	return *s;
1184 
1185   return elf_symbol_sptr();
1186 }
1187 
1188 /// Look in the function symbols map for a symbol with a given name.
1189 ///
1190 /// @param symbol_name the name of the symbol to look for.
1191 ///
1192 /// @param version the version of the symbol to look for.
1193 ///
1194 /// return the symbol with name @p symbol_name and with version @p
1195 /// version, or nil if no symbol has been found with that name and
1196 /// version.
1197 const elf_symbol_sptr
lookup_function_symbol(const string & symbol_name,const elf_symbol::version & version) const1198 corpus::lookup_function_symbol(const string& symbol_name,
1199 			       const elf_symbol::version& version) const
1200 {
1201   if (get_fun_symbol_map().empty())
1202     return elf_symbol_sptr();
1203 
1204   string_elf_symbols_map_type::const_iterator it =
1205     get_fun_symbol_map().find(symbol_name);
1206   if ( it == get_fun_symbol_map().end())
1207     return elf_symbol_sptr();
1208 
1209   return find_symbol_by_version(version, it->second);
1210 }
1211 
1212 /// Look in the function symbols map for a symbol with the same name
1213 /// and version as a given symbol.
1214 ///
1215 /// @param symbol the symbol to look for.
1216 ///
1217 /// return the symbol with the same name and version as @p symbol.
1218 const elf_symbol_sptr
lookup_function_symbol(const elf_symbol & symbol) const1219 corpus::lookup_function_symbol(const elf_symbol& symbol) const
1220 {return lookup_function_symbol(symbol.get_name(), symbol.get_version());}
1221 
1222 /// Look in the variable symbols map for a symbol with a given name.
1223 ///
1224 /// @param n the name of the symbol to look for.
1225 ///
1226 /// return the first symbol with the name @p n.
1227 const elf_symbol_sptr
lookup_variable_symbol(const string & n) const1228 corpus::lookup_variable_symbol(const string& n) const
1229 {
1230   if (get_var_symbol_map().empty())
1231     return elf_symbol_sptr();
1232 
1233   string_elf_symbols_map_type::const_iterator it =
1234     get_var_symbol_map().find(n);
1235   if ( it == get_var_symbol_map().end())
1236     return elf_symbol_sptr();
1237   return it->second[0];
1238 }
1239 
1240 /// Look in the variable symbols map for a symbol with a given name.
1241 ///
1242 /// @param symbol_name the name of the symbol to look for.
1243 ///
1244 /// @param symbol_version the version of the symbol to look for.
1245 ///
1246 /// return the first symbol with the name @p symbol_name and with
1247 /// version @p version.
1248 const elf_symbol_sptr
lookup_variable_symbol(const string & symbol_name,const elf_symbol::version & version) const1249 corpus::lookup_variable_symbol(const string& symbol_name,
1250 			       const elf_symbol::version& version) const
1251 {
1252   if (get_var_symbol_map().empty())
1253     return elf_symbol_sptr();
1254 
1255   string_elf_symbols_map_type::const_iterator it =
1256     get_var_symbol_map().find(symbol_name);
1257   if ( it == get_var_symbol_map().end())
1258     return elf_symbol_sptr();
1259 
1260   return find_symbol_by_version(version, it->second);
1261 }
1262 
1263 /// Look in the variable symbols map for a symbol with the same name
1264 /// and version as a given symbol.
1265 ///
1266 /// @param symbol the symbol to look for.
1267 ///
1268 /// return the symbol with the same name and version as @p symbol.
1269 const elf_symbol_sptr
lookup_variable_symbol(const elf_symbol & symbol) const1270 corpus::lookup_variable_symbol(const elf_symbol& symbol) const
1271 {return lookup_variable_symbol(symbol.get_name(), symbol.get_version());}
1272 
1273 /// Return the functions public decl table of the current corpus.
1274 ///
1275 /// The function public decl tables is a vector of all the functions
1276 /// and member functions found in the current corpus.
1277 ///
1278 /// Note that the caller can suppress some functions from the vector
1279 /// supplying regular expressions describing the set of functions she
1280 /// want to see removed from the public decl table by populating the
1281 /// vector of regular expressions returned by
1282 /// corpus::get_regex_patterns_of_fns_to_suppress().
1283 ///
1284 /// @return the vector of functions of the public decl table.  The
1285 /// functions are sorted using their mangled name or name if they
1286 /// don't have mangle names.
1287 const corpus::functions&
get_functions() const1288 corpus::get_functions() const
1289 {return priv_->fns;}
1290 
1291 /// Lookup the function which has a given function ID.
1292 ///
1293 /// Note that there can have been several functions with the same ID.
1294 /// This is because debug info can declare the same function in
1295 /// several different translation units.  Normally, all these function
1296 /// should be equal.  But still, this function returns all these
1297 /// functions.
1298 ///
1299 /// @param id the ID of the function to lookup.  This ID must be
1300 /// either the result of invoking function::get_id() of
1301 /// elf_symbol::get_id_string().
1302 ///
1303 /// @return the vector functions which ID is @p id, or nil if no
1304 /// function with that ID was found.
1305 const vector<function_decl*>*
lookup_functions(const string & id) const1306 corpus::lookup_functions(const string& id) const
1307 {
1308   exported_decls_builder_sptr b = get_exported_decls_builder();
1309   str_fn_ptrs_map_type::const_iterator i =
1310     b->priv_->id_fns_map_.find(id);
1311   if (i == b->priv_->id_fns_map_.end())
1312     return 0;
1313   return &i->second;
1314 }
1315 
1316 /// Sort the set of functions exported by this corpus.
1317 ///
1318 /// Normally, you shouldn't be calling this as the code that creates
1319 /// the corpus for you should do it for you too.
1320 void
sort_functions()1321 corpus::sort_functions()
1322 {
1323   func_comp fc;
1324   std::sort(priv_->fns.begin(), priv_->fns.end(), fc);
1325 }
1326 
1327 /// Return the public decl table of the global variables of the
1328 /// current corpus.
1329 ///
1330 /// The variable public decls table is a vector of all the public
1331 /// global variables and static member variables found in the current
1332 /// corpus.
1333 ///
1334 /// Note that the caller can suppress some variables from the vector
1335 /// supplying regular expressions describing the set of variables she
1336 /// wants to see removed from the public decl table by populating the
1337 /// vector of regular expressions returned by
1338 /// corpus::get_regex_patterns_of_fns_to_suppress().
1339 ///
1340 /// @return the vector of variables of the public decl table.  The
1341 /// variables are sorted using their name.
1342 const corpus::variables&
get_variables() const1343 corpus::get_variables() const
1344 {return priv_->vars;}
1345 
1346 /// Sort the set of variables exported by this corpus.
1347 ///
1348 /// Normally, you shouldn't be calling this as the code that creates
1349 /// the corpus for you should do it for you too.
1350 void
sort_variables()1351 corpus::sort_variables()
1352 {
1353   var_comp vc;
1354   std::sort(priv_->vars.begin(), priv_->vars.end(), vc);
1355 }
1356 
1357 /// Getter of the set of function symbols that are not referenced by
1358 /// any function exported by the current corpus.
1359 ///
1360 /// When the corpus has been created from an ELF library or program,
1361 /// this function returns the set of function symbols not referenced
1362 /// by any debug information.
1363 ///
1364 /// @return the vector of function symbols not referenced by any
1365 /// function exported by the current corpus.
1366 const elf_symbols&
get_unreferenced_function_symbols() const1367 corpus::get_unreferenced_function_symbols() const
1368 {return priv_->get_unreferenced_function_symbols();}
1369 
1370 /// Getter of the set of variable symbols that are not referenced by
1371 /// any variable exported by the current corpus.
1372 ///
1373 /// When the corpus has been created from an ELF library or program,
1374 /// this function returns the set of variable symbols not referenced
1375 /// by any debug information.
1376 ///
1377 /// @return the vector of variable symbols not referenced by any
1378 /// variable exported by the current corpus.
1379 const elf_symbols&
get_unreferenced_variable_symbols() const1380 corpus::get_unreferenced_variable_symbols() const
1381 {return priv_->get_unreferenced_variable_symbols();}
1382 
1383 /// Accessor for the regex patterns describing the functions to drop
1384 /// from the public decl table.
1385 ///
1386 /// @return the regex patterns describing the functions to drop from
1387 /// the public decl table.
1388 vector<string>&
get_regex_patterns_of_fns_to_suppress()1389 corpus::get_regex_patterns_of_fns_to_suppress()
1390 {return priv_->regex_patterns_fns_to_suppress;}
1391 
1392 /// Accessor for the regex patterns describing the functions to drop
1393 /// from the public decl table.
1394 ///
1395 /// @return the regex patterns describing the functions to drop from
1396 /// the public decl table.
1397 const vector<string>&
get_regex_patterns_of_fns_to_suppress() const1398 corpus::get_regex_patterns_of_fns_to_suppress() const
1399 {return priv_->regex_patterns_fns_to_suppress;}
1400 
1401 /// Accessor for the regex patterns describing the variables to drop
1402 /// from the public decl table.
1403 ///
1404 /// @return the regex patterns describing the variables to drop from
1405 /// the public decl table.
1406 vector<string>&
get_regex_patterns_of_vars_to_suppress()1407 corpus::get_regex_patterns_of_vars_to_suppress()
1408 {return priv_->regex_patterns_vars_to_suppress;}
1409 
1410 /// Accessor for the regex patterns describing the variables to drop
1411 /// from the public decl table.
1412 ///
1413 /// @return the regex patterns describing the variables to drop from
1414 /// the public decl table.
1415 const vector<string>&
get_regex_patterns_of_vars_to_suppress() const1416 corpus::get_regex_patterns_of_vars_to_suppress() const
1417 {return priv_->regex_patterns_vars_to_suppress;}
1418 
1419 /// Accessor for the regex patterns describing the functions to keep
1420 /// into the public decl table.  The other functions not matches by these
1421 /// regexes are dropped from the public decl table.
1422 ///
1423 /// @return the regex patterns describing the functions to keep into
1424 /// the public decl table.
1425 vector<string>&
get_regex_patterns_of_fns_to_keep()1426 corpus::get_regex_patterns_of_fns_to_keep()
1427 {return priv_->regex_patterns_fns_to_keep;}
1428 
1429 /// Accessor for the regex patterns describing the functions to keep
1430 /// into the public decl table.  The other functions not matches by these
1431 /// regexes are dropped from the public decl table.
1432 ///
1433 /// @return the regex patterns describing the functions to keep into
1434 /// the public decl table.
1435 const vector<string>&
get_regex_patterns_of_fns_to_keep() const1436 corpus::get_regex_patterns_of_fns_to_keep() const
1437 {return priv_->regex_patterns_fns_to_keep;}
1438 
1439 /// Getter for the vector of function symbol IDs to keep.
1440 ///
1441 /// A symbol ID is a string made of the name of the symbol and its
1442 /// version, separated by one or two '@'.
1443 ///
1444 /// @return a vector of IDs of function symbols to keep.
1445 vector<string>&
get_sym_ids_of_fns_to_keep()1446 corpus::get_sym_ids_of_fns_to_keep()
1447 {return priv_->sym_id_fns_to_keep;}
1448 
1449 /// Getter for the vector of function symbol IDs to keep.
1450 ///
1451 /// A symbol ID is a string made of the name of the symbol and its
1452 /// version, separated by one or two '@'.
1453 ///
1454 /// @return a vector of IDs of function symbols to keep.
1455 const vector<string>&
get_sym_ids_of_fns_to_keep() const1456 corpus::get_sym_ids_of_fns_to_keep() const
1457 {return priv_->sym_id_fns_to_keep;}
1458 
1459 /// Accessor for the regex patterns describing the variables to keep
1460 /// into the public decl table.  The other variables not matches by these
1461 /// regexes are dropped from the public decl table.
1462 ///
1463 /// @return the regex patterns describing the variables to keep into
1464 /// the public decl table.
1465 vector<string>&
get_regex_patterns_of_vars_to_keep()1466 corpus::get_regex_patterns_of_vars_to_keep()
1467 {return priv_->regex_patterns_vars_to_keep;}
1468 
1469 /// Accessor for the regex patterns describing the variables to keep
1470 /// into the public decl table.  The other variables not matches by these
1471 /// regexes are dropped from the public decl table.
1472 ///
1473 /// @return the regex patterns describing the variables to keep into
1474 /// the public decl table.
1475 const vector<string>&
get_regex_patterns_of_vars_to_keep() const1476 corpus::get_regex_patterns_of_vars_to_keep() const
1477 {return priv_->regex_patterns_vars_to_keep;}
1478 
1479 /// Getter for the vector of variable symbol IDs to keep.
1480 ///
1481 /// A symbol ID is a string made of the name of the symbol and its
1482 /// version, separated by one or two '@'.
1483 ///
1484 /// @return a vector of IDs of variable symbols to keep.
1485 vector<string>&
get_sym_ids_of_vars_to_keep()1486 corpus::get_sym_ids_of_vars_to_keep()
1487 {return priv_->sym_id_vars_to_keep;}
1488 
1489 /// Getter for the vector of variable symbol IDs to keep.
1490 ///
1491 /// A symbol ID is a string made of the name of the symbol and its
1492 /// version, separated by one or two '@'.
1493 ///
1494 /// @return a vector of IDs of variable symbols to keep.
1495 const vector<string>&
get_sym_ids_of_vars_to_keep() const1496 corpus::get_sym_ids_of_vars_to_keep() const
1497 {return priv_->sym_id_vars_to_keep;}
1498 
1499 /// After the set of exported functions and variables have been built,
1500 /// consider all the tunables that control that set and see if some
1501 /// functions need to be removed from that set; if so, remove them.
1502 void
maybe_drop_some_exported_decls()1503 corpus::maybe_drop_some_exported_decls()
1504 {
1505   string sym_name, sym_version;
1506 
1507   vector<function_decl*> fns_to_keep;
1508   exported_decls_builder* b = get_exported_decls_builder().get();
1509   for (vector<function_decl*>::iterator f = priv_->fns.begin();
1510        f != priv_->fns.end();
1511        ++f)
1512     {
1513       if (b->priv_->keep_wrt_id_of_fns_to_keep(*f)
1514 	  && b->priv_->keep_wrt_regex_of_fns_to_suppress(*f)
1515 	  && b->priv_->keep_wrt_regex_of_fns_to_keep(*f))
1516 	fns_to_keep.push_back(*f);
1517     }
1518   priv_->fns = fns_to_keep;
1519 
1520   vector<var_decl*> vars_to_keep;
1521   for (vector<var_decl*>::iterator v = priv_->vars.begin();
1522        v != priv_->vars.end();
1523        ++v)
1524     {
1525       if (b->priv_->keep_wrt_id_of_vars_to_keep(*v)
1526 	  && b->priv_->keep_wrt_regex_of_vars_to_suppress(*v)
1527 	  && b->priv_->keep_wrt_regex_of_vars_to_keep(*v))
1528 	vars_to_keep.push_back(*v);
1529     }
1530   priv_->vars = vars_to_keep;
1531 }
1532 
1533 ///  Getter for the object that is responsible for determining what
1534 ///  decls ought to be in the set of exported decls.
1535 ///
1536 ///  The object does have methods to add the decls to the set of
1537 ///  exported decls, right at the place where the corpus expects it,
1538 ///  so that there is no unnecessary copying involved.
1539 ///
1540 ///  @return a (smart) pointer to the instance of @ref
1541 ///  corpus::exported_decls_builder that is responsible for determine
1542 ///  what decls ought to be in the set of exported decls.
1543 corpus::exported_decls_builder_sptr
get_exported_decls_builder() const1544 corpus::get_exported_decls_builder() const
1545 {
1546   if (!priv_->exported_decls_builder)
1547     {
1548       priv_->exported_decls_builder.reset
1549 	(new exported_decls_builder(priv_->fns,
1550 				    priv_->vars,
1551 				    priv_->regex_patterns_fns_to_suppress,
1552 				    priv_->regex_patterns_vars_to_suppress,
1553 				    priv_->regex_patterns_fns_to_keep,
1554 				    priv_->regex_patterns_vars_to_keep,
1555 				    priv_->sym_id_fns_to_keep,
1556 				    priv_->sym_id_vars_to_keep));
1557     }
1558   return priv_->exported_decls_builder;
1559 }
1560 
1561 // </corpus stuff>
1562 
1563 // <corpus_group stuff>
1564 
1565 /// Type of the private data of @ref corpus_group
1566 struct corpus_group::priv
1567 {
1568   corpora_type			corpora;
1569   istring_function_decl_ptr_map_type fns_map;
1570   vector<function_decl*>	fns;
1571   istring_var_decl_ptr_map_type vars_map;
1572   vector<var_decl*>		vars;
1573   string_elf_symbols_map_type	var_symbol_map;
1574   string_elf_symbols_map_type	fun_symbol_map;
1575   elf_symbols			sorted_var_symbols;
1576   elf_symbols			sorted_fun_symbols;
1577   unordered_map<string, elf_symbol_sptr> unrefed_fun_symbol_map;
1578   elf_symbols			unrefed_fun_symbols;
1579   bool				unrefed_fun_symbols_built;
1580   unordered_map<string, elf_symbol_sptr> unrefed_var_symbol_map;
1581   elf_symbols			unrefed_var_symbols;
1582   bool				unrefed_var_symbols_built;
1583   unordered_set<interned_string, hash_interned_string> pub_type_pretty_reprs_;
1584 
privabigail::ir::corpus_group::priv1585   priv()
1586     : unrefed_fun_symbols_built(),
1587       unrefed_var_symbols_built()
1588   {}
1589 
1590   /// Add symbols to the set of corpus group function symbols that are
1591   /// *NOT* referenced by debug info.
1592   ///
1593   /// @param syms the set the symbols to add.
1594   void
add_unref_fun_symbolsabigail::ir::corpus_group::priv1595   add_unref_fun_symbols(const elf_symbols& syms)
1596   {
1597     for (elf_symbols::const_iterator e =
1598 	   syms.begin(); e != syms.end(); ++e)
1599       {
1600 	string sym_id = (*e)->get_id_string();
1601 	unordered_map<string, elf_symbol_sptr>::const_iterator j =
1602 	  unrefed_fun_symbol_map.find(sym_id);
1603 	if (j != unrefed_fun_symbol_map.end())
1604 	  continue;
1605 
1606 	unrefed_fun_symbol_map[sym_id] = *e;
1607 	unrefed_fun_symbols.push_back(*e);
1608       }
1609     unrefed_fun_symbols_built = true;
1610   }
1611 
1612   /// Add symbols to the set of corpus group variable symbols that are
1613   /// *NOT* referenced by debug info.
1614   ///
1615   /// @param syms the set the symbols to add.
1616   void
add_unref_var_symbolsabigail::ir::corpus_group::priv1617   add_unref_var_symbols(const elf_symbols& syms)
1618   {
1619     for (elf_symbols::const_iterator e =
1620 	   syms.begin(); e != syms.end(); ++e)
1621       {
1622 	string sym_id = (*e)->get_id_string();
1623 	unordered_map<string, elf_symbol_sptr>::const_iterator j =
1624 	  unrefed_var_symbol_map.find(sym_id);
1625 	if (j != unrefed_var_symbol_map.end())
1626 	  continue;
1627 
1628 	unrefed_var_symbol_map[sym_id] = *e;
1629 	unrefed_var_symbols.push_back(*e);
1630       }
1631     unrefed_var_symbols_built = true;
1632   }
1633 }; // end corpus_group::priv
1634 
1635 /// Default constructor of the @ref corpus_group type.
corpus_group(environment * env,const string & path="")1636 corpus_group::corpus_group(environment* env, const string& path = "")
1637   : corpus(env, path), priv_(new priv)
1638 {}
1639 
1640 /// Desctructor of the @ref corpus_group type.
~corpus_group()1641 corpus_group::~corpus_group()
1642 {}
1643 
1644 /// Add a new corpus to the current instance of @ref corpus_group.
1645 ///
1646 /// @param corp the new corpus to add.
1647 void
add_corpus(const corpus_sptr & corp)1648 corpus_group::add_corpus(const corpus_sptr& corp)
1649 {
1650   if (!corp)
1651     return;
1652 
1653   // Ensure the new environment patches the current one.
1654   if (const environment* cur_env = get_environment())
1655     {
1656       if (environment* corp_env = corp->get_environment())
1657 	ABG_ASSERT(cur_env == corp_env);
1658     }
1659   else
1660     set_environment(corp->get_environment());
1661 
1662   // Ensure the new architecture name matches the current one.
1663   string cur_arch = get_architecture_name(),
1664     corp_arch = corp->get_architecture_name();
1665   if (cur_arch.empty())
1666     set_architecture_name(corp_arch);
1667   else if (cur_arch != corp_arch)
1668     {
1669       std::cerr << "corpus '" << corp->get_path() << "'"
1670 		<< " has architecture '" << corp_arch << "'"
1671 		<< " but expected '" << cur_arch << "'\n";
1672       ABG_ASSERT_NOT_REACHED;
1673     }
1674 
1675   priv_->corpora.push_back(corp);
1676   corp->set_group(this);
1677 
1678   /// Add the unreferenced function and variable symbols of this
1679   /// corpus to the unreferenced symbols of the current corpus group.
1680   priv_->add_unref_fun_symbols(get_unreferenced_function_symbols());
1681   priv_->add_unref_var_symbols(get_unreferenced_variable_symbols());
1682 }
1683 
1684 /// Getter of the vector of corpora held by the current @ref
1685 /// corpus_group.
1686 ///
1687 /// @return the vector corpora.
1688 const corpus_group::corpora_type&
get_corpora() const1689 corpus_group::get_corpora() const
1690 {return priv_->corpora;}
1691 
1692 /// Getter of the first corpus added to this Group.
1693 ///
1694 /// @return the first corpus added to this Group.
1695 const corpus_sptr
get_main_corpus() const1696 corpus_group::get_main_corpus() const
1697 {return const_cast<corpus_group*>(this)->get_main_corpus();}
1698 
1699 /// Getter of the first corpus added to this Group.
1700 ///
1701 /// @return the first corpus added to this Group.
1702 corpus_sptr
get_main_corpus()1703 corpus_group::get_main_corpus()
1704 {
1705   if (!get_corpora().empty())
1706     return get_corpora().front();
1707   return corpus_sptr();
1708 }
1709 
1710 /// Test if the current corpus group is empty.
1711 ///
1712 /// @return true iff the current corpus group is empty.
1713 bool
is_empty() const1714 corpus_group::is_empty() const
1715 {return get_corpora().empty();}
1716 
1717 /// Get the functions exported by the corpora of the current corpus
1718 /// group.
1719 ///
1720 /// Upon its first invocation, this function walks the corpora
1721 /// contained in the corpus group and caches the functions they exported.
1722 ///
1723 /// Subsequent invocations just return the cached functions.
1724 ///
1725 /// @return the exported functions.
1726 const corpus::functions&
get_functions() const1727 corpus_group::get_functions() const
1728 {
1729   if (priv_->fns.empty())
1730     for (corpora_type::const_iterator i = get_corpora().begin();
1731 	 i != get_corpora().end();
1732 	 ++i)
1733       {
1734 	corpus_sptr c = *i;
1735 	for (corpus::functions::const_iterator f = c->get_functions().begin();
1736 	     f != c->get_functions().end();
1737 	     ++f)
1738 	  {
1739 	    interned_string fid = (*f)->get_id();
1740 	    istring_function_decl_ptr_map_type::const_iterator j =
1741 	      priv_->fns_map.find(fid);
1742 
1743 	    if (j != priv_->fns_map.end())
1744 	      // Don't cache the same function twice ...
1745 	      continue;
1746 
1747 	    priv_->fns_map[fid] = *f;
1748 	    // really cache the function now.
1749 	    priv_->fns.push_back(*f);
1750 	  }
1751       }
1752 
1753   return priv_->fns;
1754 }
1755 
1756 /// Get the global variables exported by the corpora of the current
1757 /// corpus group.
1758 ///
1759 /// Upon its first invocation, this function walks the corpora
1760 /// contained in the corpus group and caches the variables they
1761 /// export.
1762 ///
1763 /// @return the exported variables.
1764 const corpus::variables&
get_variables() const1765 corpus_group::get_variables() const
1766 {
1767   if (priv_->vars.empty())
1768     for (corpora_type::const_iterator i = get_corpora().begin();
1769 	 i != get_corpora().end();
1770 	 ++i)
1771       {
1772 	corpus_sptr c = *i;
1773 	for (corpus::variables::const_iterator v = c->get_variables().begin();
1774 	     v != c->get_variables().end();
1775 	     ++v)
1776 	  {
1777 	    interned_string vid = (*v)->get_id();
1778 	    istring_var_decl_ptr_map_type::const_iterator j =
1779 	      priv_->vars_map.find(vid);
1780 
1781 	    if (j != priv_->vars_map.end())
1782 	      // Don't cache the same variable twice ...
1783 	      continue;
1784 
1785 	    priv_->vars_map[vid] = *v;
1786 	    // Really cache the variable now.
1787 	    priv_->vars.push_back(*v);
1788 	  }
1789       }
1790 
1791   return priv_->vars;
1792 }
1793 
1794 /// Get the symbols of the global variables exported by the corpora of
1795 /// the current @ref corpus_group.
1796 ///
1797 /// @return the symbols of the global variables exported by the corpora
1798 const string_elf_symbols_map_type&
get_var_symbol_map() const1799 corpus_group::get_var_symbol_map() const
1800 {
1801   if (priv_->var_symbol_map.empty())
1802     for (corpora_type::const_iterator i = get_corpora().begin();
1803 	 i != get_corpora().end();
1804 	 ++i)
1805       priv_->var_symbol_map.insert((*i)->get_var_symbol_map().begin(),
1806 				     (*i)->get_var_symbol_map().end());
1807 
1808   return priv_->var_symbol_map;
1809 }
1810 
1811 /// Get the symbols of the global functions exported by the corpora of
1812 /// the current @ref corpus_group.
1813 ///
1814 /// @return the symbols of the global functions exported by the corpora
1815 const string_elf_symbols_map_type&
get_fun_symbol_map() const1816 corpus_group::get_fun_symbol_map() const
1817 {
1818   if (priv_->fun_symbol_map.empty())
1819     for (corpora_type::const_iterator i = get_corpora().begin();
1820 	 i != get_corpora().end();
1821 	 ++i)
1822       priv_->fun_symbol_map.insert((*i)->get_fun_symbol_map().begin(),
1823 				   (*i)->get_fun_symbol_map().end());
1824 
1825   return priv_->fun_symbol_map;
1826 }
1827 
1828 /// Get a sorted vector of the symbols of the functions exported by
1829 /// the corpora of the current group.
1830 ///
1831 /// @return the sorted vectors of the exported function symbols.
1832 const elf_symbols&
get_sorted_fun_symbols() const1833 corpus_group::get_sorted_fun_symbols() const
1834 {
1835   if (priv_->sorted_fun_symbols.empty()
1836       && !get_fun_symbol_map().empty())
1837     {
1838       for (corpora_type::const_iterator i = get_corpora().begin();
1839 	   i != get_corpora().end();
1840 	   ++i)
1841 	{
1842 	  corpus_sptr c = *i;
1843 	  for (string_elf_symbols_map_type::const_iterator j =
1844 		 c->get_fun_symbol_map().begin();
1845 	       j != c->get_fun_symbol_map().begin();
1846 	       ++j)
1847 	    priv_->sorted_fun_symbols.insert(priv_->sorted_fun_symbols.end(),
1848 					     j->second.begin(),
1849 					     j->second.end());
1850 	}
1851       comp_elf_symbols_functor comp;
1852       std::sort(priv_->sorted_fun_symbols.begin(),
1853 		priv_->sorted_fun_symbols.end(),
1854 		comp);
1855     }
1856 
1857   return priv_->sorted_fun_symbols;
1858 }
1859 
1860 /// Get a sorted vector of the symbols of the variables exported by
1861 /// the corpora of the current group.
1862 ///
1863 /// @return the sorted vectors of the exported variable symbols.
1864 const elf_symbols&
get_sorted_var_symbols() const1865 corpus_group::get_sorted_var_symbols() const
1866 {
1867   if (priv_->sorted_var_symbols.empty()
1868       && !get_var_symbol_map().empty())
1869     {
1870       for (corpora_type::const_iterator i = get_corpora().begin();
1871 	   i != get_corpora().end();
1872 	   ++i)
1873 	{
1874 	  corpus_sptr c = *i;
1875 	  for (string_elf_symbols_map_type::const_iterator j =
1876 		 c->get_var_symbol_map().begin();
1877 	       j != c->get_var_symbol_map().begin();
1878 	       ++j)
1879 	    priv_->sorted_var_symbols.insert(priv_->sorted_var_symbols.end(),
1880 					     j->second.begin(),
1881 					     j->second.end());
1882 	}
1883       comp_elf_symbols_functor comp;
1884       std::sort(priv_->sorted_var_symbols.begin(),
1885 		priv_->sorted_var_symbols.end(),
1886 		comp);
1887     }
1888 
1889   return priv_->sorted_var_symbols;
1890 }
1891 
1892 /// Get the set of function symbols not referenced by any debug info,
1893 /// from all the corpora of the current corpus group.
1894 ///
1895 /// Upon its first invocation, this function possibly walks all the
1896 /// copora of this corpus group and caches the unreferenced symbols
1897 /// they export.  The function then returns the cache.
1898 ///
1899 /// Upon subsequent invocations, this functions just returns the
1900 /// cached symbols.
1901 ///
1902 /// @return the unreferenced symbols.
1903 const elf_symbols&
get_unreferenced_function_symbols() const1904 corpus_group::get_unreferenced_function_symbols() const
1905 {
1906   if (!priv_->unrefed_fun_symbols_built)
1907     if (priv_->unrefed_fun_symbols.empty())
1908       {
1909 	for (corpora_type::const_iterator i = get_corpora().begin();
1910 	     i != get_corpora().end();
1911 	     ++i)
1912 	  {
1913 	    corpus_sptr c = *i;
1914 	    for (elf_symbols::const_iterator e =
1915 		   c->get_unreferenced_function_symbols().begin();
1916 		 e != c->get_unreferenced_function_symbols().end();
1917 		 ++e)
1918 	      {
1919 		string sym_id = (*e)->get_id_string();
1920 		unordered_map<string, elf_symbol_sptr>::const_iterator j =
1921 		  priv_->unrefed_fun_symbol_map.find(sym_id);
1922 		if (j != priv_->unrefed_fun_symbol_map.end())
1923 		  continue;
1924 
1925 		priv_->unrefed_fun_symbol_map[sym_id] = *e;
1926 		priv_->unrefed_fun_symbols.push_back(*e);
1927 	      }
1928 	  }
1929 	priv_->unrefed_fun_symbols_built = true;
1930       }
1931 
1932   return priv_->unrefed_fun_symbols;
1933 }
1934 
1935 /// Get the set of variable symbols not referenced by any debug info,
1936 /// from all the corpora of the current corpus group.
1937 ///
1938 /// Upon its first invocation, this function possibly walks all the
1939 /// copora of this corpus group and caches the unreferenced symbols
1940 /// they export.  The function then returns the cache.
1941 ///
1942 /// Upon subsequent invocations, this functions just returns the
1943 /// cached symbols.
1944 ///
1945 /// @return the unreferenced symbols.
1946 const elf_symbols&
get_unreferenced_variable_symbols() const1947 corpus_group::get_unreferenced_variable_symbols() const
1948 {
1949   if (!priv_->unrefed_var_symbols_built)
1950     if (priv_->unrefed_var_symbols.empty())
1951       {
1952 	for (corpora_type::const_iterator i = get_corpora().begin();
1953 	     i != get_corpora().end();
1954 	     ++i)
1955 	  {
1956 	    corpus_sptr c = *i;
1957 	    for (elf_symbols::const_iterator e =
1958 		   c->get_unreferenced_variable_symbols().begin();
1959 		 e != c->get_unreferenced_variable_symbols().end();
1960 		 ++e)
1961 	      {
1962 		string sym_id = (*e)->get_id_string();
1963 		unordered_map<string, elf_symbol_sptr>::const_iterator j =
1964 		  priv_->unrefed_var_symbol_map.find(sym_id);
1965 		if (j != priv_->unrefed_var_symbol_map.end())
1966 		  continue;
1967 
1968 		priv_->unrefed_var_symbol_map[sym_id] = *e;
1969 		priv_->unrefed_var_symbols.push_back(*e);
1970 	      }
1971 	  }
1972 	priv_->unrefed_var_symbols_built = true;
1973       }
1974 
1975   return priv_->unrefed_var_symbols;
1976 }
1977 
1978 /// Getter of a pointer to the set of types reachable from public
1979 /// interfaces of a given corpus group.
1980 unordered_set<interned_string, hash_interned_string>*
get_public_types_pretty_representations()1981 corpus_group::get_public_types_pretty_representations()
1982 {return &priv_->pub_type_pretty_reprs_;}
1983 
1984 /// Test if the recording of reachable types (and thus, indirectly,
1985 /// the recording of non-reachable types) is activated for the
1986 /// current @ref corpus_group.
1987 ///
1988 /// @return true iff the recording of reachable types is activated for
1989 /// the current @ref corpus_group.
1990 bool
recording_types_reachable_from_public_interface_supported()1991 corpus_group::recording_types_reachable_from_public_interface_supported()
1992 {return !get_public_types_pretty_representations()->empty();}
1993 
1994 // </corpus_group stuff>
1995 
1996 }// end namespace ir
1997 }// end namespace abigail
1998