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

Abstracts a variable declaration. More...

#include <abg-ir.h>

Inheritance diagram for var_decl:
[legend]

Classes

struct  hash
 A hashing functor for instances and pointers of var_decl. More...
 
struct  ptr_equal
 A comparison functor for pointers to var_decl. More...
 

Public Member Functions

 var_decl (const string &name, type_base_sptr type, const location &locus, const string &mangled_name, visibility vis=VISIBILITY_DEFAULT, binding bind=BINDING_NONE)
 Constructor of the var_decl type. More...
 
var_decl_sptr clone () const
 Create a new var_decl that is a clone of the current one. More...
 
string get_anon_dm_reliable_name (bool qualified=true) const
 Get a name that is valid even for an anonymous data member. More...
 
binding get_binding () const
 Getter of the binding of the variable. More...
 
virtual size_t get_hash () const
 Return the hash value for the current instance. More...
 
interned_string get_id () const
 Return an ID that tries to uniquely identify the variable inside a program or a library. More...
 
const type_baseget_naked_type () const
 Getter of the type of the variable. More...
 
virtual string get_pretty_representation (bool internal=false, bool qualified_name=true) const
 Build and return the pretty representation of this variable. More...
 
virtual const interned_stringget_qualified_name (bool internal=false) const
 Get the qualified name of a given variable or data member. More...
 
const elf_symbol_sptrget_symbol () const
 Gets the the underlying ELF symbol for the current variable, that was set using var_decl::set_symbol(). Please read the documentation for that member function for more information about "underlying ELF symbols". More...
 
const type_base_sptr get_type () const
 Getter of the type of the variable. More...
 
virtual bool operator== (const decl_base &) const
 Comparison operator of var_decl. More...
 
void set_binding (binding b)
 Setter of the binding of the variable. More...
 
void set_symbol (const elf_symbol_sptr &sym)
 Sets the underlying ELF symbol for the current variable. More...
 
void set_type (type_base_sptr &)
 Setter of the type of the variable. More...
 
virtual bool traverse (ir_node_visitor &v)
 This implements the ir_traversable_base::traverse pure virtual function. More...
 
- Public Member Functions inherited from decl_base
 decl_base (const environment &, const location &)
 Constructor for the decl_base type. More...
 
 decl_base (const environment &e, const interned_string &name, const location &locus, const interned_string &mangled_name=interned_string(), visibility vis=VISIBILITY_DEFAULT)
 Constructor. More...
 
 decl_base (const environment &e, const string &name, const location &locus, const string &mangled_name="", visibility vis=VISIBILITY_DEFAULT)
 Constructor for the decl_base type. More...
 
virtual ~decl_base ()
 Destructor of the decl_base type. More...
 
const decl_base_sptr get_definition_of_declaration () const
 If this decl_base is declaration-only, get its definition, if any. More...
 
const decl_base_sptr get_earlier_declaration () const
 If this decl_base is a definition, get its earlier declaration. More...
 
bool get_has_anonymous_parent () const
 Get the "has_anonymous_parent" flag of the current declaration. More...
 
bool get_is_anonymous () const
 Test if the current declaration is anonymous. More...
 
bool get_is_anonymous_or_has_anonymous_parent () const
 
bool get_is_declaration_only () const
 Test if a decl_base is a declaration-only decl. More...
 
bool get_is_in_public_symbol_table () const
 Test if the decl is defined in a ELF symbol table as a public symbol. More...
 
const interned_stringget_linkage_name () const
 Getter for the mangled name. More...
 
const locationget_location () const
 Get the location of a given declaration. More...
 
const decl_baseget_naked_definition_of_declaration () const
 If this decl_base is declaration-only, get its definition, if any. More...
 
const interned_stringget_name () const
 Getter for the name of the current decl. More...
 
typedef_decl_sptr get_naming_typedef () const
 Getter for the naming typedef of the current decl. More...
 
virtual void get_qualified_name (interned_string &qualified_name, bool internal=false) const
 Compute the qualified name of the decl. More...
 
const interned_stringget_qualified_parent_name () const
 Return a copy of the qualified name of the parent of the current decl. More...
 
scope_declget_scope () const
 Return the type containing the current decl, if any. More...
 
virtual const interned_stringget_scoped_name () const
 Return the scoped name of the decl. More...
 
visibility get_visibility () const
 Getter for the visibility of the decl. More...
 
virtual bool operator!= (const decl_base &) const
 Inequality operator. More...
 
void set_definition_of_declaration (const decl_base_sptr &)
 Set the definition of this declaration-only decl_base. More...
 
void set_earlier_declaration (const decl_base_sptr &)
 set the earlier declaration of this decl_base definition. More...
 
void set_is_anonymous (bool)
 Set the "is_anonymous" flag of the current declaration. More...
 
void set_is_declaration_only (bool f)
 Set a flag saying if the enum_type_decl is a declaration-only enum_type_decl. More...
 
void set_is_in_public_symbol_table (bool)
 Set the flag saying if this decl is from a symbol that is in a public symbols table, defined as public (global or weak). More...
 
virtual void set_linkage_name (const string &m)
 Setter for the linkage name. More...
 
void set_location (const location &l)
 Set the location for a given declaration. More...
 
void set_name (const string &n)
 Setter for the name of the decl. More...
 
void set_naming_typedef (const typedef_decl_sptr &)
 Set the naming typedef of the current instance of decl_base. More...
 
void set_visibility (visibility v)
 Setter for the visibility of the decl. More...
 
- Public Member Functions inherited from type_or_decl_base
 type_or_decl_base (const environment &, enum type_or_decl_kind k=ABSTRACT_TYPE_OR_DECL)
 Constructor of type_or_decl_base. More...
 
virtual ~type_or_decl_base ()
 The destructor of the type_or_decl_base type. More...
 
locationget_artificial_location () const
 Getter of the artificial location of the artifact. More...
 
corpusget_corpus ()
 Get the corpus this ABI artifact belongs to. More...
 
const corpusget_corpus () const
 Get the corpus this ABI artifact belongs to. More...
 
const environmentget_environment () const
 Getter of the environment of the current ABI artifact. More...
 
bool get_is_artificial () const
 Getter of the flag that says if the artefact is artificial. More...
 
translation_unitget_translation_unit ()
 Get the translation_unit this ABI artifact belongs to. More...
 
const translation_unitget_translation_unit () const
 Get the translation_unit this ABI artifact belongs to. More...
 
bool has_artificial_location () const
 Test if the current ABI artifact carries an artificial location. More...
 
void set_artificial_location (const location &)
 Setter of the artificial location of the artificat. More...
 
void set_is_artificial (bool)
 Setter of the flag that says if the artefact is artificial. More...
 
void set_translation_unit (translation_unit *)
 Set the translation_unit this ABI artifact belongs to. More...
 
- Public Member Functions inherited from traversable_base
virtual ~traversable_base ()
 Destructor of the traversable_base type. More...
 

Friends

uint64_t get_absolute_data_member_offset (const var_decl &m)
 Get the absolute offset of a data member. More...
 
uint64_t get_absolute_data_member_offset (const var_decl_sptr &m)
 Get the absolute offset of a data member. More...
 
bool get_data_member_is_laid_out (const var_decl &m)
 Test whether a data member is laid out. More...
 
bool get_data_member_is_laid_out (const var_decl_sptr m)
 Test whether a data member is laid out. More...
 
uint64_t get_data_member_offset (const var_decl &m)
 Get the offset of a data member. More...
 
uint64_t get_data_member_offset (const var_decl_sptr m)
 Get the offset of a data member. More...
 
void set_data_member_is_laid_out (var_decl_sptr m, bool l)
 Set a flag saying if a data member is laid out. More...
 
void set_data_member_offset (var_decl_sptr m, uint64_t o)
 Set the offset of a data member into its containing class. More...
 

Additional Inherited Members

- Public Types inherited from decl_base
enum  binding { BINDING_NONE , BINDING_LOCAL , BINDING_GLOBAL , BINDING_WEAK }
 ELF binding. More...
 
enum  visibility {
  VISIBILITY_NONE , VISIBILITY_DEFAULT , VISIBILITY_PROTECTED , VISIBILITY_HIDDEN ,
  VISIBILITY_INTERNAL
}
 ELF visibility. More...
 
- Public Attributes inherited from decl_base
priv * priv_
 
- Protected Types inherited from type_or_decl_base
enum  type_or_decl_kind {
  ABSTRACT_TYPE_OR_DECL , ABSTRACT_DECL_BASE , ABSTRACT_SCOPE_DECL , GLOBAL_SCOPE_DECL ,
  NAMESPACE_DECL , VAR_DECL , FUNCTION_DECL , FUNCTION_PARAMETER_DECL ,
  METHOD_DECL , TEMPLATE_DECL , ABSTRACT_TYPE_BASE , ABSTRACT_SCOPE_TYPE_DECL ,
  BASIC_TYPE , SUBRANGE_TYPE , QUALIFIED_TYPE , POINTER_TYPE ,
  REFERENCE_TYPE , POINTER_TO_MEMBER_TYPE , ARRAY_TYPE , ENUM_TYPE ,
  TYPEDEF_TYPE , CLASS_TYPE , UNION_TYPE , FUNCTION_TYPE ,
  METHOD_TYPE
}
 This is a bitmap type which instance is meant to contain the runtime type of a given ABI artifact. Bits of the identifiers of the type of a given artifact as well as the types it inherits from are to be set to 1. More...
 
- Protected Member Functions inherited from decl_base
 decl_base (const decl_base &)
 
void clear_qualified_name ()
 Clear the qualified name of this decl. More...
 
context_relget_context_rel ()
 Getter for the context relationship. More...
 
const context_relget_context_rel () const
 Getter for the context relationship. More...
 
const interned_stringpeek_qualified_name () const
 Getter for the qualified name. More...
 
const interned_stringpeek_temporary_qualified_name () const
 Getter of the temporary qualified name of the current declaration. More...
 
void set_context_rel (context_rel *c)
 
void set_qualified_name (const interned_string &) const
 Setter for the qualified name. More...
 
void set_temporary_qualified_name (const interned_string &) const
 Setter for the temporary qualified name of the current declaration. More...
 
- Protected Member Functions inherited from type_or_decl_base
bool hashing_started () const
 Getter for the 'hashing_started' property. More...
 
void hashing_started (bool) const
 Setter for the 'hashing_started' property. More...
 
enum type_or_decl_kind kind () const
 Getter for the "kind" property of type_or_decl_base type. More...
 
void kind (enum type_or_decl_kind)
 Setter for the "kind" property of type_or_decl_base type. More...
 
type_or_decl_baseoperator= (const type_or_decl_base &)
 
void * runtime_type_instance ()
 Getter of the pointer to the runtime type sub-object of the current instance. More...
 
const void * runtime_type_instance () const
 Getter of the pointer to the runtime type sub-object of the current instance. More...
 
void runtime_type_instance (void *)
 Setter of the pointer to the runtime type sub-object of the current instance. More...
 
void * type_or_decl_base_pointer ()
 Getter of the pointer to either the type_base sub-object of the current instance if it's a type, or to the decl_base sub-object of the current instance if it's a decl. More...
 
const void * type_or_decl_base_pointer () const
 Getter of the pointer to either the type_base sub-object of the current instance if it's a type, or to the decl_base sub-object of the current instance if it's a decl. More...
 
- 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

Abstracts a variable declaration.

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

Constructor & Destructor Documentation

◆ var_decl()

var_decl ( const string &  name,
type_base_sptr  type,
const location locus,
const string &  linkage_name,
visibility  vis = VISIBILITY_DEFAULT,
binding  bind = BINDING_NONE 
)

Constructor of the var_decl type.

Parameters
namethe name of the variable declaration
typethe type of the variable declaration
locusthe source location where the variable was defined.
linkage_namethe linkage name of the variable.
visthe visibility of of the variable.
bindthe binding kind of the variable.

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

Member Function Documentation

◆ clone()

var_decl_sptr clone ( ) const

Create a new var_decl that is a clone of the current one.

Returns
the cloned var_decl.

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

◆ get_anon_dm_reliable_name()

string get_anon_dm_reliable_name ( bool  qualified = true) const

Get a name that is valid even for an anonymous data member.

If the current var_decl is an anonymous data member, then return its pretty representation. As of now, that pretty representation is actually its flat representation as returned by get_class_or_union_flat_representation().

Otherwise, just return the name of the current var_decl.

Parameters
qualifiedif true, return the qualified name. This doesn't have an effet if the current var_decl represents an anonymous data member.

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

◆ get_binding()

decl_base::binding get_binding ( ) const

Getter of the binding of the variable.

Returns
the biding of the variable.

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

◆ get_hash()

size_t get_hash ( ) const
virtual

Return the hash value for the current instance.

Returns
the hash value.

Reimplemented from decl_base.

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

◆ get_id()

interned_string get_id ( ) const

Return an ID that tries to uniquely identify the variable inside a program or a library.

So if the variable has an underlying elf symbol, the ID is the concatenation of the symbol name and its version. Otherwise, the ID is the linkage name if its non-null. Otherwise, it's the pretty representation of the variable.

Returns
the ID.

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

◆ get_naked_type()

const type_base * get_naked_type ( ) const

Getter of the type of the variable.

This getter returns a bare pointer, as opposed to a smart pointer. It's to be used on performance sensitive code paths identified by careful profiling.

Returns
the type of the variable, as a bare pointer.

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

◆ get_pretty_representation()

string get_pretty_representation ( bool  internal = false,
bool  qualified_name = true 
) const
virtual

Build and return the pretty representation of this variable.

Parameters
internalset to true if the call is intended to get a representation of the decl (or type) for the purpose of canonical type comparison. This is mainly used in the function type_base::get_canonical_type_for().

In other words if the argument for this parameter is true then the call is meant for internal use (for technical use inside the library itself), false otherwise. If you don't know what this is for, then set it to false.

Parameters
qualified_nameif true, names emitted in the pretty representation are fully qualified.
Returns
a copy of the pretty representation of this variable.

Reimplemented from decl_base.

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

◆ get_qualified_name()

const interned_string & get_qualified_name ( bool  internal = false) const
virtual

Get the qualified name of a given variable or data member.

Note that if the current instance of var_decl is an anonymous data member, then the qualified name is actually the flat representation (the definition) of the type of the anonymous data member. We chose the flat representation because otherwise, the name of an *anonymous* data member is empty, by construction, e.g:

struct foo { int a; union { char b; char c; }; // <—- this data member is anonymous. int d; }

The string returned for the anonymous member here is going to be:

"union {char b; char c}"

Parameters
internalif true then this is for a purpose to the library, otherwise, it's for being displayed to users.
Returns
the resulting qualified name.

Reimplemented from decl_base.

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

◆ get_symbol()

const elf_symbol_sptr & get_symbol ( ) const

Gets the the underlying ELF symbol for the current variable, that was set using var_decl::set_symbol(). Please read the documentation for that member function for more information about "underlying ELF symbols".

Returns
sym the underlying ELF symbol for this variable decl, if one exists.

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

◆ get_type()

const type_base_sptr get_type ( ) const

Getter of the type of the variable.

Returns
the type of the variable.

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

◆ operator==()

bool operator== ( const decl_base o) const
virtual

Comparison operator of var_decl.

Parameters
othe instance of var_decl to compare against.
Returns
true iff the current instance of var_decl equals o.

Reimplemented from decl_base.

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

◆ set_binding()

void set_binding ( decl_base::binding  b)

Setter of the binding of the variable.

Parameters
bthe new binding value.

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

◆ set_symbol()

void set_symbol ( const elf_symbol_sptr sym)

Sets the underlying ELF symbol for the current variable.

And underlyin$g ELF symbol for the current variable might exist only if the corpus that this variable originates from was constructed from an ELF binary file.

Note that comparing two variables that have underlying ELF symbols involves comparing their underlying elf symbols. The decl name for the variable thus becomes irrelevant in the comparison.

Parameters
symthe new ELF symbol for this variable decl.

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

◆ set_type()

void set_type ( type_base_sptr &  t)

Setter of the type of the variable.

Parameters
thenew type of the variable.

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

◆ traverse()

bool traverse ( ir_node_visitor v)
virtual

This implements the ir_traversable_base::traverse pure virtual function.

Parameters
vthe visitor used on the current instance.
Returns
true if the entire IR node tree got traversed, false otherwise.

Reimplemented from decl_base.

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

Friends And Related Function Documentation

◆ get_absolute_data_member_offset [1/2]

uint64_t get_absolute_data_member_offset ( const var_decl m)
friend

Get the absolute offset of a data member.

If the data member is part of an anonymous data member then this returns the absolute offset – relative to the beginning of the containing class of the anonymous data member.

Parameters
mthe data member to consider.
Returns
the aboslute offset of the data member m.

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

◆ get_absolute_data_member_offset [2/2]

uint64_t get_absolute_data_member_offset ( const var_decl_sptr m)
friend

Get the absolute offset of a data member.

If the data member is part of an anonymous data member then this returns the absolute offset – relative to the beginning of the containing class of the anonymous data member.

Parameters
mthe data member to consider.
Returns
the aboslute offset of the data member m.

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

◆ get_data_member_is_laid_out [1/2]

bool get_data_member_is_laid_out ( const var_decl m)
friend

Test whether a data member is laid out.

Parameters
mthe data member to consider.
Returns
true if m is laid out, false otherwise.

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

◆ get_data_member_is_laid_out [2/2]

bool get_data_member_is_laid_out ( const var_decl_sptr  m)
friend

Test whether a data member is laid out.

Parameters
mthe data member to consider.
Returns
true if m is laid out, false otherwise.

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

◆ get_data_member_offset [1/2]

uint64_t get_data_member_offset ( const var_decl m)
friend

Get the offset of a data member.

Parameters
mthe data member to consider.
Returns
the offset (in bits) of m in its containing class.

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

◆ get_data_member_offset [2/2]

uint64_t get_data_member_offset ( const var_decl_sptr  m)
friend

Get the offset of a data member.

Parameters
mthe data member to consider.
Returns
the offset (in bits) of m in its containing class.

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

◆ set_data_member_is_laid_out

void set_data_member_is_laid_out ( var_decl_sptr  m,
bool  l 
)
friend

Set a flag saying if a data member is laid out.

Parameters
mthe data member to consider.
ltrue if m is to be considered as laid out.

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

◆ set_data_member_offset

void set_data_member_offset ( var_decl_sptr  m,
uint64_t  o 
)
friend

Set the offset of a data member into its containing class.

Parameters
mthe data member to consider.
othe offset, in bits.

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


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