libabigail
Classes | Public Types | Public Member Functions | Friends | List of all members
translation_unit Class Reference

This is the abstraction of the set of relevant artefacts (types, variable declarations, functions, templates, etc) bundled together into a translation unit. More...

#include <abg-ir.h>

Inheritance diagram for translation_unit:
[legend]

Classes

struct  priv
 Private type to hold private members of translation_unit. More...
 

Public Types

typedef shared_ptr< scope_declglobal_scope_sptr
 Convenience typedef for a shared pointer on a global_scope. More...
 
enum  language {
  LANG_UNKNOWN , LANG_Cobol74 , LANG_Cobol85 , LANG_C89 ,
  LANG_C99 , LANG_C11 , LANG_C , LANG_C_plus_plus_03 ,
  LANG_C_plus_plus_11 , LANG_C_plus_plus_14 , LANG_C_plus_plus , LANG_ObjC ,
  LANG_ObjC_plus_plus , LANG_Fortran77 , LANG_Fortran90 , LANG_Fortran95 ,
  LANG_Ada83 , LANG_Ada95 , LANG_Pascal83 , LANG_Modula2 ,
  LANG_Java , LANG_PLI , LANG_UPC , LANG_D ,
  LANG_Python , LANG_Go , LANG_Rust , LANG_Mips_Assembler
}
 The language of the translation unit. More...
 

Public Member Functions

 translation_unit (const ir::environment &env, const std::string &path, char address_size=0)
 Constructor of translation_unit. More...
 
void bind_function_type_life_time (function_type_sptr) const
 Ensure that the life time of a function type is bound to the life time of the current translation unit. More...
 
const std::string & get_absolute_path () const
 Get the concatenation of the build directory and the relative path of the translation unit. More...
 
char get_address_size () const
 Getter of the address size in this translation unit. More...
 
const std::string & get_compilation_dir_path () const
 Get the path of the directory that was 'current' when the translation unit was compiled. More...
 
corpusget_corpus ()
 Get the corpus this translation unit is a member of. More...
 
const corpusget_corpus () const
 Get the corpus this translation unit is a member of. More...
 
const environmentget_environment () const
 Getter of the environment of the current translation_unit. More...
 
scope_decl_sptrget_global_scope ()
 Getter of the the global scope of the translation unit. More...
 
const scope_decl_sptrget_global_scope () const
 Getter of the the global scope of the translation unit. More...
 
language get_language () const
 Getter of the language of the source code of the translation unit. More...
 
const vector< function_type_sptr > & get_live_fn_types () const
 Get the vector of function types that are used in the current translation unit. More...
 
location_managerget_loc_mgr ()
 Getter of the location manager for the current translation unit. More...
 
const location_managerget_loc_mgr () const
 const Getter of the location manager. More...
 
const std::string & get_path () const
 Get the path of the current translation unit. More...
 
type_mapsget_types ()
 Getter of the types of the current translation_unit. More...
 
const type_mapsget_types () const
 Getter of the types of the current translation_unit. More...
 
bool is_constructed () const
 Getter of the 'is_constructed" flag. It says if the translation unit is fully constructed or not. More...
 
bool is_empty () const
 Tests whether if the current translation unit contains ABI artifacts or not. More...
 
bool operator!= (const translation_unit &) const
 Inequality operator. More...
 
bool operator== (const translation_unit &) const
 Compare the current translation unit against another one. More...
 
void set_address_size (char)
 Setter of the address size in this translation unit. More...
 
void set_compilation_dir_path (const std::string &)
 Set the path of the directory that was 'current' when the translation unit was compiled. More...
 
void set_corpus (corpus *)
 Set the corpus this translation unit is a member of. More...
 
void set_is_constructed (bool)
 Setter of the 'is_constructed" flag. It says if the translation unit is fully constructed or not. More...
 
void set_language (language l)
 Setter of the language of the source code of the translation unit. More...
 
void set_path (const string &)
 Set the path associated to the current instance of translation_unit. More...
 
virtual bool traverse (ir_node_visitor &v)
 This implements the ir_traversable_base::traverse virtual function. More...
 
- Public Member Functions inherited from traversable_base
virtual ~traversable_base ()
 Destructor of the traversable_base type. More...
 

Friends

function_type_sptr lookup_function_type_in_translation_unit (const function_type &t, const translation_unit &tu)
 
function_type_sptr synthesize_function_type_from_translation_unit (const function_type &fn_type, translation_unit &tu)
 In a translation unit, lookup the sub-types that make up a given function type and if the sub-types are all found, synthesize and return a function_type with them. More...
 
type_base_sptr synthesize_type_from_translation_unit (const type_base_sptr &type, translation_unit &tu)
 In a translation unit, lookup a given type or synthesize it if it's a qualified type. More...
 

Additional Inherited Members

- Protected Member Functions inherited from traversable_base
 traversable_base ()
 Default constructor of the traversable_base type. More...
 
bool visiting () const
 This should returns false before and after the node has been visiting. During the visiting of the node (and of its children) this should return true. More...
 
void visiting (bool f)
 The traversing code should be responsible of calling this, not the user code. More...
 

Detailed Description

This is the abstraction of the set of relevant artefacts (types, variable declarations, functions, templates, etc) bundled together into a translation unit.

Definition at line 685 of file abg-ir.h.

Member Typedef Documentation

◆ global_scope_sptr

typedef shared_ptr<scope_decl> global_scope_sptr

Convenience typedef for a shared pointer on a global_scope.

Definition at line 695 of file abg-ir.h.

Member Enumeration Documentation

◆ language

enum language

The language of the translation unit.

Definition at line 698 of file abg-ir.h.

Constructor & Destructor Documentation

◆ translation_unit()

translation_unit ( const ir::environment env,
const std::string &  path,
char  address_size = 0 
)

Constructor of translation_unit.

Parameters
envthe environment of this translation unit. Please note that the life time of the environment must be greater than the life time of the translation unit because the translation uses resources that are allocated in the environment.
paththe location of the translation unit.
address_sizethe size of addresses in the translation unit, in bits.

Definition at line 1263 of file abg-ir.cc.

Member Function Documentation

◆ bind_function_type_life_time()

void bind_function_type_life_time ( function_type_sptr  ftype) const

Ensure that the life time of a function type is bound to the life time of the current translation unit.

Parameters
ftypethe function time which life time to bind to the life time of the current instance of translation_unit. That is, it's onlyh when the translation unit is destroyed that the function type can be destroyed to.

Definition at line 1551 of file abg-ir.cc.

◆ get_absolute_path()

const std::string & get_absolute_path ( ) const

Get the concatenation of the build directory and the relative path of the translation unit.

Returns
the absolute path of the translation unit.

Definition at line 1398 of file abg-ir.cc.

◆ get_address_size()

char get_address_size ( ) const

Getter of the address size in this translation unit.

Returns
the address size, in bits.

Definition at line 1476 of file abg-ir.cc.

◆ get_compilation_dir_path()

const std::string & get_compilation_dir_path ( ) const

Get the path of the directory that was 'current' when the translation unit was compiled.

Note that the path returned by translation_unit::get_path is relative to the path returned by this function.

Returns
the compilation directory for the current translation unit.

Definition at line 1379 of file abg-ir.cc.

◆ get_corpus() [1/2]

corpus * get_corpus ( )

Get the corpus this translation unit is a member of.

Returns
the parent corpus, or nil if this doesn't belong to any corpus yet.

Definition at line 1433 of file abg-ir.cc.

◆ get_corpus() [2/2]

const corpus * get_corpus ( ) const

Get the corpus this translation unit is a member of.

Returns
the parent corpus, or nil if this doesn't belong to any corpus yet.

Definition at line 1441 of file abg-ir.cc.

◆ get_environment()

const environment & get_environment ( ) const

Getter of the environment of the current translation_unit.

Returns
the translation unit of the current translation unit.

Definition at line 1328 of file abg-ir.cc.

◆ get_global_scope() [1/2]

scope_decl_sptr & get_global_scope ( )

Getter of the the global scope of the translation unit.

Returns
the global scope of the current translation unit. If there is not global scope allocated yet, this function creates one and returns it.

Definition at line 1289 of file abg-ir.cc.

◆ get_global_scope() [2/2]

const scope_decl_sptr & get_global_scope ( ) const

Getter of the the global scope of the translation unit.

Returns
the global scope of the current translation unit. If there is not global scope allocated yet, this function creates one and returns it.

Definition at line 1278 of file abg-ir.cc.

◆ get_language()

translation_unit::language get_language ( ) const

Getter of the language of the source code of the translation unit.

Returns
the language of the source code.

Definition at line 1335 of file abg-ir.cc.

◆ get_live_fn_types()

const vector< function_type_sptr > & get_live_fn_types ( ) const

Get the vector of function types that are used in the current translation unit.

Returns
the vector of function types that are used in the current translation unit.

Definition at line 1321 of file abg-ir.cc.

◆ get_loc_mgr() [1/2]

location_manager & get_loc_mgr ( )

Getter of the location manager for the current translation unit.

Returns
a reference to the location manager for the current translation unit.

Definition at line 1449 of file abg-ir.cc.

◆ get_loc_mgr() [2/2]

const location_manager & get_loc_mgr ( ) const

const Getter of the location manager.

Returns
a const reference to the location manager for the current translation unit.

Definition at line 1457 of file abg-ir.cc.

◆ get_path()

const std::string & get_path ( ) const

Get the path of the current translation unit.

This path is relative to the build directory of the translation unit as returned by translation_unit::get_compilation_dir_path.

Returns
the relative path of the compilation unit associated to the current instance of translation_unit.

Definition at line 1355 of file abg-ir.cc.

◆ get_types() [1/2]

type_maps & get_types ( )

Getter of the types of the current translation_unit.

Returns
the maps of the types of the translation unit.

Definition at line 1312 of file abg-ir.cc.

◆ get_types() [2/2]

const type_maps & get_types ( ) const

Getter of the types of the current translation_unit.

Returns
the maps of the types of the translation unit.

Definition at line 1305 of file abg-ir.cc.

◆ is_constructed()

bool is_constructed ( ) const

Getter of the 'is_constructed" flag. It says if the translation unit is fully constructed or not.

This flag is important for cases when comparison might depend on if the translation unit is fully built or not. For instance, when reading types from DWARF, the virtual methods of a class are not necessarily fully constructed until we have reached the end of the translation unit. In that case, before we've reached the end of the translation unit, we might not take virtual functions into account when comparing classes.

Returns
true if the translation unit is constructed.

Definition at line 1499 of file abg-ir.cc.

◆ is_empty()

bool is_empty ( ) const

Tests whether if the current translation unit contains ABI artifacts or not.

Returns
true iff the current translation unit is empty.

Definition at line 1465 of file abg-ir.cc.

◆ operator!=()

bool operator!= ( const translation_unit o) const

Inequality operator.

Parameters
othe instance of translation_unit to compare the current instance against.
Returns
true iff the current instance is different from o.

Definition at line 1540 of file abg-ir.cc.

◆ operator==()

bool operator== ( const translation_unit other) const

Compare the current translation unit against another one.

Parameters
otherthe other tu to compare against.
Returns
true if the two translation units are equal, false otherwise.

Definition at line 1525 of file abg-ir.cc.

◆ set_address_size()

void set_address_size ( char  a)

Setter of the address size in this translation unit.

Parameters
athe new address size in bits.

Definition at line 1483 of file abg-ir.cc.

◆ set_compilation_dir_path()

void set_compilation_dir_path ( const std::string &  d)

Set the path of the directory that was 'current' when the translation unit was compiled.

Note that the path returned by translation_unit::get_path is relative to the path returned by this function.

Parameters
thecompilation directory for the current translation unit.

Definition at line 1390 of file abg-ir.cc.

◆ set_corpus()

void set_corpus ( corpus c)

Set the corpus this translation unit is a member of.

Note that adding a translation unit to a corpus automatically triggers a call to this member function.

Parameters
corpusthe corpus.

Definition at line 1425 of file abg-ir.cc.

◆ set_is_constructed()

void set_is_constructed ( bool  f)

Setter of the 'is_constructed" flag. It says if the translation unit is fully constructed or not.

This flag is important for cases when comparison might depend on if the translation unit is fully built or not. For instance, when reading types from DWARF, the virtual methods of a class are not necessarily fully constructed until we have reached the end of the translation unit. In that case, before we've reached the end of the translation unit, we might not take virtual functions into account when comparing classes.

Parameters
ftrue if the translation unit is constructed.

Definition at line 1515 of file abg-ir.cc.

◆ set_language()

void set_language ( language  l)

Setter of the language of the source code of the translation unit.

Parameters
lthe new language.

Definition at line 1342 of file abg-ir.cc.

◆ set_path()

void set_path ( const string &  a_path)

Set the path associated to the current instance of translation_unit.

This path is relative to the build directory of the translation unit as returned by translation_unit::get_compilation_dir_path.

Parameters
a_paththe new relative path to set.

Definition at line 1366 of file abg-ir.cc.

◆ traverse()

bool traverse ( ir_node_visitor v)
virtual

This implements the ir_traversable_base::traverse virtual function.

Parameters
vthe visitor used on the member nodes of the translation unit during the traversal.
Returns
true if the entire type IR tree got traversed, false otherwise.

Definition at line 1585 of file abg-ir.cc.

Friends And Related Function Documentation

◆ synthesize_function_type_from_translation_unit

function_type_sptr synthesize_function_type_from_translation_unit ( const function_type fn_type,
translation_unit tu 
)
friend

In a translation unit, lookup the sub-types that make up a given function type and if the sub-types are all found, synthesize and return a function_type with them.

This function is like lookup_function_type_in_translation_unit() execept that it constructs the function type from the sub-types found in the translation, rather than just looking for the function types held by the translation unit. This can be useful if the translation unit doesnt hold the function type we are looking for (i.e, lookup_function_type_in_translation_unit() returned NULL) but we still want to see if the sub-types of the function types are present in the translation unit.

Parameters
fn_typethe function type to consider.
tuthe translation unit to look into.
Returns
the resulting synthesized function type if all its sub-types have been found, NULL otherwise.

Definition at line 15136 of file abg-ir.cc.

◆ synthesize_type_from_translation_unit

type_base_sptr synthesize_type_from_translation_unit ( const type_base_sptr &  type,
translation_unit tu 
)
friend

In a translation unit, lookup a given type or synthesize it if it's a qualified type.

So this function first looks the type up in the translation unit. If it's found, then OK, it's returned. Otherwise, if it's a qualified, reference or pointer or function type (a composite type), lookup the underlying type, synthesize the type we want from it and return it.

If the underlying types is not not found, then give up and return nil.

Returns
the type that was found or the synthesized type.

Definition at line 15053 of file abg-ir.cc.


The documentation for this class was generated from the following files: