CodeSonar C++ API
[For improved navigation, enable JavaScript.]
Public Member Functions | Friends | Related Functions | List of all members
cs::ast_field Class Reference

A field (child or attribute) of an Abstract Syntax Tree (class ast). More...

Public Member Functions

 ast_field (ast_ordinal ord, ast val)
 Constructor for ast_field of type ast_field_type::AST. More...
 
 ast_field (ast_ordinal ord, ast_class val)
 Constructor for ast_field of type ast_field_type::AST_CLASS. More...
 
 ast_field (ast_ordinal ord, bool val)
 Constructor for ast_field of type ast_field_type::BOOLEAN. More...
 
 ast_field (ast_ordinal ord, csint8 val)
 Constructor for ast_field of type ast_field_type::INT8. More...
 
 ast_field (ast_ordinal ord, csuint8 val)
 Constructor for ast_field of type ast_field_type::UINT8. More...
 
 ast_field (ast_ordinal ord, csint16 val)
 Constructor for ast_field of type ast_field_type::INT16. More...
 
 ast_field (ast_ordinal ord, csuint16 val)
 Constructor for ast_field of type ast_field_type::UINT16. More...
 
 ast_field (ast_ordinal ord, csint32 val)
 Constructor for ast_field of type ast_field_type::INT32 or ast_field_type::ENUMERATION. More...
 
 ast_field (ast_ordinal ord, csuint32 val)
 Constructor for ast_field of type ast_field_type::UINT32. More...
 
 ast_field (ast_ordinal ord, csint64 val)
 Constructor for ast_field of type ast_field_type::INT64. More...
 
 ast_field (ast_ordinal ord, csuint64 val)
 Constructor for ast_field of type ast_field_type::UINT64. More...
 
 ast_field (ast_ordinal ord, float val)
 Constructor for ast_field of type ast_field_type::FLT32. More...
 
 ast_field (ast_ordinal ord, double val)
 Constructor for ast_field of type ast_field_type::FLT64. More...
 
 ast_field (ast_ordinal ord, const std::string &val)
 Constructor for ast_field of type ast_field_type::CONST_STR, ast_field_type::CONST_STR64, ast_field_type::BYTES, or ast_field_type::ENUMERATION. More...
 
 ast_field (ast_ordinal ord, symbol val)
 Constructor for ast_field of type ast_field_type::ABS_LOC. More...
 
 ast_field (ast_ordinal ord, const ast_field &f)
 Just like the copy constructor, except the ordinal is overridden.
 
 ast_field (ast_ordinal ord, sfileinst val)
 Constructor for ast_field of type ast_field_type::SFID.
 
 ast_field (const ast_field &f)
 Copy constructor. More...
 
ast as_ast () const
 Get the value from an ast_field of type ast_field_type::AST. More...
 
ast_class as_ast_class () const
 Get the value from an ast_field of type ast_field_type::AST_CLASS. More...
 
bool as_boolean () const
 Get the value from an ast_field of type ast_field_type::BOOLEAN. More...
 
csint32 as_enum_value_int32 () const
 Get the integer value from an ast_field of type ast_field_type::ENUMERATION. More...
 
std::string as_enum_value_string () const
 Get the string representation from an ast_field of type ast_field_type::ENUMERATION. More...
 
float as_flt32 () const
 Get the value from an ast_field of type ast_field_type::FLT32. More...
 
double as_flt64 () const
 Get the value from an ast_field of type ast_field_type::FLT64. More...
 
csint16 as_int16 () const
 Get the value from an ast_field of type ast_field_type::INT16. More...
 
csint32 as_int32 () const
 Get the value from an ast_field of type ast_field_type::INT32. More...
 
csint64 as_int64 () const
 Get the value from an ast_field of type ast_field_type::INT64. More...
 
csint8 as_int8 () const
 Get the value from an ast_field of type ast_field_type::INT8. More...
 
std::string as_repr () const
 Get a representation of a ast_field object that includes information useful for debugging. More...
 
sfileinst as_sfileinst () const
 Get the value from an ast_field whose type is ast_field_type::SFID. More...
 
std::string as_str () const
 Get a string representation of an ast_field. More...
 
std::string as_string () const
 Get a simple string representation of a ast_field object. More...
 
symbol as_symbol () const
 Get the value from an ast_field whose type is ast_field_type::ABS_LOC. More...
 
csuint16 as_uint16 () const
 Get the value from an ast_field of type ast_field_type::UINT16. More...
 
csuint32 as_uint32 () const
 Get the value from an ast_field of type ast_field_type::UINT32. More...
 
csuint64 as_uint64 () const
 Get the value from an ast_field of type ast_field_type::UINT64. More...
 
csuint8 as_uint8 () const
 Get the value from an ast_field of type ast_field_type::UINT8. More...
 
int cmp (const ast_field &other) const
 Comparison function for ast_field. More...
 
int fast_cmp (const ast_field &other) const
 If this is ast-typed, applies ast::fast_cmp() to this.as_ast(); otherwise behaves just like cmp(). More...
 
cs_hash_t fast_hash () const
 If this is ast-typed, applies ast::fast_hash() to this.as_ast(); otherwise behaves just like hash(). More...
 
ast_field_type get_type () const
 Get the ast_field_type associated with an ast_field. More...
 
bool has_field (ast_ordinal ord) const
 For an ast_field of type ast_field_type::AST, check whether the represented ast contains the designated field. More...
 
bool has_field (size_t ord) const
 For an ast_field of type ast_field_type::AST, check whether the represented ast contains the designated field. More...
 
cs_hash_t hash () const
 Get a hash value for a ast_field. More...
 
size_t num_fields () const
 For an ast_field of type ast_field_type::AST, get the number of fields contained in the represented ast. More...
 
 operator ast () const
 Get the value from an ast_field of type ast_field_type::AST. More...
 
ast operator* () const
 Get the value from an ast_field of type ast_field_type::AST. More...
 
ast_field operator[] (ast_ordinal ord) const
 For an ast_field of type ast_field_type::AST, get the designated field of the represented ast. More...
 
ast_field operator[] (size_t ord) const
 For an ast_field of type ast_field_type::AST, get the designated field of the represented ast. More...
 
ast_ordinal ordinal () const
 Get the ast_ordinal associated with an ast_field. More...
 
int stable_cmp (const ast_field &other) const
 Compare with another ast_field, with stable results across sufficiently-similar analyses. More...
 

Friends

std::ostream & operator<< (std::ostream &out, const ast_field &a)
 

Related Functions

(Note that these are not member functions.)

bool operator!= (const ast_field &a, const ast_field &b)
 Inequality operator for ast_field. More...
 
bool operator< (const ast_field &a, const ast_field &b)
 Less-than operator for ast_field. More...
 
std::ostream & operator<< (std::ostream &out, const ast_field &a)
 Print a representation of an ast_field object to the specified stream. More...
 
bool operator<= (const ast_field &a, const ast_field &b)
 Less-than-or-equal operator for ast_field. More...
 
bool operator== (const ast_field &a, const ast_field &b)
 Equality operator for ast_field. More...
 
bool operator> (const ast_field &a, const ast_field &b)
 Greater-than operator for ast_field. More...
 
bool operator>= (const ast_field &a, const ast_field &b)
 Greater-than-or-equal operator for ast_field. More...
 

Detailed Description

A field (child or attribute) of an Abstract Syntax Tree (class ast).

Represents a pair (ord, val), where

Constructor & Destructor Documentation

◆ ast_field() [1/16]

cs::ast_field::ast_field ( ast_ordinal  ord,
ast  val 
)
inline

Constructor for ast_field of type ast_field_type::AST.

Parameters
[in]ordThe field ordinal.
[in]valThe field value.

◆ ast_field() [2/16]

cs::ast_field::ast_field ( ast_ordinal  ord,
ast_class  val 
)
inline

Constructor for ast_field of type ast_field_type::AST_CLASS.

Parameters
[in]ordThe field ordinal.
[in]valThe field value.

◆ ast_field() [3/16]

cs::ast_field::ast_field ( ast_ordinal  ord,
bool  val 
)
inline

Constructor for ast_field of type ast_field_type::BOOLEAN.

Parameters
[in]ordThe field ordinal.
[in]valThe field value.

◆ ast_field() [4/16]

cs::ast_field::ast_field ( ast_ordinal  ord,
csint8  val 
)
inline

Constructor for ast_field of type ast_field_type::INT8.

Parameters
[in]ordThe field ordinal.
[in]valThe field value.

◆ ast_field() [5/16]

cs::ast_field::ast_field ( ast_ordinal  ord,
csuint8  val 
)
inline

Constructor for ast_field of type ast_field_type::UINT8.

Parameters
[in]ordThe field ordinal.
[in]valThe field value.

◆ ast_field() [6/16]

cs::ast_field::ast_field ( ast_ordinal  ord,
csint16  val 
)
inline

Constructor for ast_field of type ast_field_type::INT16.

Parameters
[in]ordThe field ordinal.
[in]valThe field value.

◆ ast_field() [7/16]

cs::ast_field::ast_field ( ast_ordinal  ord,
csuint16  val 
)
inline

Constructor for ast_field of type ast_field_type::UINT16.

Parameters
[in]ordThe field ordinal.
[in]valThe field value.

◆ ast_field() [8/16]

cs::ast_field::ast_field ( ast_ordinal  ord,
csint32  val 
)
inline

Constructor for ast_field of type ast_field_type::INT32 or ast_field_type::ENUMERATION.

Parameters
[in]ordThe field ordinal.
[in]valThe field value.

◆ ast_field() [9/16]

cs::ast_field::ast_field ( ast_ordinal  ord,
csuint32  val 
)
inline

Constructor for ast_field of type ast_field_type::UINT32.

Parameters
[in]ordThe field ordinal.
[in]valThe field value.

◆ ast_field() [10/16]

cs::ast_field::ast_field ( ast_ordinal  ord,
csint64  val 
)
inline

Constructor for ast_field of type ast_field_type::INT64.

Parameters
[in]ordThe field ordinal.
[in]valThe field value.

◆ ast_field() [11/16]

cs::ast_field::ast_field ( ast_ordinal  ord,
csuint64  val 
)
inline

Constructor for ast_field of type ast_field_type::UINT64.

Parameters
[in]ordThe field ordinal.
[in]valThe field value.

◆ ast_field() [12/16]

cs::ast_field::ast_field ( ast_ordinal  ord,
float  val 
)
inline

Constructor for ast_field of type ast_field_type::FLT32.

Parameters
[in]ordThe field ordinal.
[in]valThe field value.

◆ ast_field() [13/16]

cs::ast_field::ast_field ( ast_ordinal  ord,
double  val 
)
inline

Constructor for ast_field of type ast_field_type::FLT64.

Parameters
[in]ordThe field ordinal.
[in]valThe field value.

◆ ast_field() [14/16]

cs::ast_field::ast_field ( ast_ordinal  ord,
const std::string &  val 
)
inline

Constructor for ast_field of type ast_field_type::CONST_STR, ast_field_type::CONST_STR64, ast_field_type::BYTES, or ast_field_type::ENUMERATION.

Parameters
[in]ordThe field ordinal.
[in]valThe field value.

◆ ast_field() [15/16]

cs::ast_field::ast_field ( ast_ordinal  ord,
symbol  val 
)
inline

Constructor for ast_field of type ast_field_type::ABS_LOC.

Parameters
[in]ordThe field ordinal.
[in]valThe field value.

◆ ast_field() [16/16]

cs::ast_field::ast_field ( const ast_field f)
inline

Copy constructor.

Member Function Documentation

◆ as_ast()

ast cs::ast_field::as_ast ( ) const
inline

Get the value from an ast_field of type ast_field_type::AST.

Returns
The ast represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::AST.

◆ as_ast_class()

ast_class cs::ast_field::as_ast_class ( ) const
inline

Get the value from an ast_field of type ast_field_type::AST_CLASS.

Returns
The ast_class represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::AST_CLASS.

◆ as_boolean()

bool cs::ast_field::as_boolean ( ) const
inline

Get the value from an ast_field of type ast_field_type::BOOLEAN.

Returns
The bool represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::BOOLEAN.

◆ as_enum_value_int32()

csint32 cs::ast_field::as_enum_value_int32 ( ) const
inline

Get the integer value from an ast_field of type ast_field_type::ENUMERATION.

Returns
The integer value of the enum element represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::ENUMERATION.

◆ as_enum_value_string()

std::string cs::ast_field::as_enum_value_string ( ) const
inline

Get the string representation from an ast_field of type ast_field_type::ENUMERATION.

Returns
A string representation of the enum element represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::ENUMERATION.

◆ as_flt32()

float cs::ast_field::as_flt32 ( ) const
inline

Get the value from an ast_field of type ast_field_type::FLT32.

Returns
The value represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::FLT32.

◆ as_flt64()

double cs::ast_field::as_flt64 ( ) const
inline

Get the value from an ast_field of type ast_field_type::FLT64.

Returns
The value represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::FLT64.

◆ as_int16()

csint16 cs::ast_field::as_int16 ( ) const
inline

Get the value from an ast_field of type ast_field_type::INT16.

Returns
The value represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::INT16.

◆ as_int32()

csint32 cs::ast_field::as_int32 ( ) const
inline

Get the value from an ast_field of type ast_field_type::INT32.

Returns
The value represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::INT32.

◆ as_int64()

csint64 cs::ast_field::as_int64 ( ) const
inline

Get the value from an ast_field of type ast_field_type::INT64.

Returns
The value represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::INT64.

◆ as_int8()

csint8 cs::ast_field::as_int8 ( ) const
inline

Get the value from an ast_field of type ast_field_type::INT8.

Returns
The value represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::INT8.

◆ as_repr()

std::string cs::ast_field::as_repr ( ) const
inline

Get a representation of a ast_field object that includes information useful for debugging.

Returns
The string representation.

◆ as_sfileinst()

sfileinst cs::ast_field::as_sfileinst ( ) const
inline

Get the value from an ast_field whose type is ast_field_type::SFID.

Returns
The sfileinst represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field type is not ast_field_type::SFID.

◆ as_str()

std::string cs::ast_field::as_str ( ) const
inline

Get a string representation of an ast_field.

Returns
A std::string, depending on the type of the invoking ast_field:
Exceptions
result::ERROR_INVALID_TYPEif called on an ast_field of invalid type.

◆ as_string()

std::string cs::ast_field::as_string ( ) const
inline

Get a simple string representation of a ast_field object.

Returns
The string representation.

◆ as_symbol()

symbol cs::ast_field::as_symbol ( ) const
inline

Get the value from an ast_field whose type is ast_field_type::ABS_LOC.

Returns
The symbol represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field type is not ast_field_type::ABS_LOC.

◆ as_uint16()

csuint16 cs::ast_field::as_uint16 ( ) const
inline

Get the value from an ast_field of type ast_field_type::UINT16.

Returns
The value represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::UINT16.

◆ as_uint32()

csuint32 cs::ast_field::as_uint32 ( ) const
inline

Get the value from an ast_field of type ast_field_type::UINT32.

Returns
The value represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::UINT32.

◆ as_uint64()

csuint64 cs::ast_field::as_uint64 ( ) const
inline

Get the value from an ast_field of type ast_field_type::UINT64.

Returns
The value represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::UINT64.

◆ as_uint8()

csuint8 cs::ast_field::as_uint8 ( ) const
inline

Get the value from an ast_field of type ast_field_type::UINT8.

Returns
The value represented by the ast_field.
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::UINT8.

◆ cmp()

int cs::ast_field::cmp ( const ast_field other) const
inline

Comparison function for ast_field.

Parameters
otherThe ast_field object to compare against.
Returns
An integer N such that:
  • N==0 if the two objects compare equal
  • N<0 if this < other
  • N>0 if this > other

◆ fast_cmp()

int cs::ast_field::fast_cmp ( const ast_field other) const
inline

If this is ast-typed, applies ast::fast_cmp() to this.as_ast(); otherwise behaves just like cmp().

Returns
An integer N, such that:
  • N<0 if this considered less than other
  • N==0 if this considered equal to other
  • N>0 if this considered greater than other

◆ fast_hash()

cs_hash_t cs::ast_field::fast_hash ( ) const
inline

If this is ast-typed, applies ast::fast_hash() to this.as_ast(); otherwise behaves just like hash().

Returns
The hash value.

◆ get_type()

ast_field_type cs::ast_field::get_type ( ) const
inline

Get the ast_field_type associated with an ast_field.

Returns
The ast_field_type.

◆ has_field() [1/2]

bool cs::ast_field::has_field ( ast_ordinal  ord) const
inline

For an ast_field of type ast_field_type::AST, check whether the represented ast contains the designated field.

Parameters
ordAn ast_ordinal denoting the field to check.
Returns
true if the field denoted by ord is present in the represented ast, false otherwise.

Use this form for fields with named ordinals.

For

See also
has_field(size_t) const
Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::AST.

◆ has_field() [2/2]

bool cs::ast_field::has_field ( size_t  ord) const
inline

For an ast_field of type ast_field_type::AST, check whether the represented ast contains the designated field.

Parameters
ordThe numeric ordinal of the field to check.
Returns
true if the field denoted by ord is present in the represented ast, false otherwise.
Exceptions
result::ERROR_INVALID_ARGUMENTif ord <= 0
result::ERROR_INVALID_TYPEif this is not of type ast_field_type::AST.

Use this form for fields with numeric ordinals.

For

See also
has_field(ast_ordinal ord) const

◆ hash()

cs_hash_t cs::ast_field::hash ( ) const
inline

Get a hash value for a ast_field.

◆ num_fields()

size_t cs::ast_field::num_fields ( ) const
inline

For an ast_field of type ast_field_type::AST, get the number of fields contained in the represented ast.

Returns
The number of fields (that is, the number of children plus the number of attributes) contained in the represented ast.

For ast_field myfield, myfield.num_fields() is equivalent to myfield.as_ast().num_fields().

Exceptions
result::ERROR_INVALID_TYPEif this is not of type ast_field_type::AST.

◆ operator ast()

cs::ast_field::operator ast ( ) const
inline

Get the value from an ast_field of type ast_field_type::AST.

For ast_field myfield, ast myfield is equivalent to myfield.as_ast().

◆ operator*()

ast cs::ast_field::operator* ( ) const
inline

Get the value from an ast_field of type ast_field_type::AST.

For ast_field myfield, *myfield is equivalent to myfield.as_ast().

Exceptions
result::ERROR_INVALID_TYPEif the ast_field's type is not ast_field_type::AST.

◆ operator[]() [1/2]

ast_field cs::ast_field::operator[] ( ast_ordinal  ord) const
inline

For an ast_field of type ast_field_type::AST, get the designated field of the represented ast.

Parameters
ordAn ast_ordinal denoting the field to retrieve.
Returns
The ast_field corresponding to ord. Throws an exception if there is no such field.

Use this form for fields with named ordinals.

myfield[myord] is equivalent to myfield.as_ast()[myord].

See also
operator[](size_t ord) const
Exceptions
result::ERROR_INVALID_TYPEif this is not of type ast_field_type::AST.
ast_field_not_found_errorif there is no such field.

◆ operator[]() [2/2]

ast_field cs::ast_field::operator[] ( size_t  ord) const
inline

For an ast_field of type ast_field_type::AST, get the designated field of the represented ast.

Parameters
ordThe numeric ordinal of the field to retrieve.
Returns
The ast_field corresponding to ord. Throws an exception if there is no such field.

Use this form for fields with numeric ordinals.

myfield[myint] is equivalent to myfield.as_ast()[myint].

See also
operator[](ast_ordinal ord) const
Exceptions
result::ERROR_INVALID_TYPEif this is not of type ast_field_type::AST.
result::ERROR_INVALID_ARGUMENTif ord<=0.
ast_field_not_found_errorif there is no such field.

◆ ordinal()

ast_ordinal cs::ast_field::ordinal ( ) const
inline

Get the ast_ordinal associated with an ast_field.

Returns
The ast_ordinal.
Exceptions
result::ERROR_INVALID_ARGUMENTif the ast_field does not have a valid ast_ordinal associated with it.

◆ stable_cmp()

int cs::ast_field::stable_cmp ( const ast_field other) const
inline

Compare with another ast_field, with stable results across sufficiently-similar analyses.

Parameters
[in]otherThe ast_field to compare against.
Returns
An integer N, such that:
  • N<0 if this considered less than other
  • N==0 if this considered equal to other
  • N>0 if this considered greater than other

The comparison is stable in the following sense. Suppose there are two analyses A1 and A2 generated with exactly the same inputs (including identical analyzed code, underlying build commands and ordering, command line and configuration settings, increment order and contents). Let a1 and b1 be two ast_field objects in A1, and a2 and b2 be the ast_field objects in A2 that correspond to a1 and b1 respectively. Then a1.stable_cmp(b1)==a2.stable_cmp(b2).

If you don't need comparison relationships to be stable across analyses, use cmp(): it has better performance.

Friends And Related Function Documentation

◆ operator!=()

bool operator!= ( const ast_field a,
const ast_field b 
)
related

Inequality operator for ast_field.

Parameters
[in]aThe ast_field to compare.
[in]bThe ast_field to compare against.
Returns
false if a and b are equal according to ast_field::cmp(), true otherwise.

◆ operator<()

bool operator< ( const ast_field a,
const ast_field b 
)
related

Less-than operator for ast_field.

Parameters
[in]aThe ast_field to compare.
[in]bThe ast_field to compare against.
Returns
true if a < b according to ast_field::cmp() , false otherwise.

◆ operator<<()

std::ostream & operator<< ( std::ostream &  out,
const ast_field a 
)
related

Print a representation of an ast_field object to the specified stream.

Parameters
[in]outThe stream to print to.
[in]aThe ast_field object to print.
Returns
void

◆ operator<=()

bool operator<= ( const ast_field a,
const ast_field b 
)
related

Less-than-or-equal operator for ast_field.

Parameters
[in]aThe ast_field to compare.
[in]bThe ast_field to compare against.
Returns
true if a <= b according to ast_field::cmp() , false otherwise.

◆ operator==()

bool operator== ( const ast_field a,
const ast_field b 
)
related

Equality operator for ast_field.

Parameters
[in]aThe ast_field to compare.
[in]bThe ast_field to compare against.
Returns
true if a and b are equal according to ast_field::cmp(), false otherwise.

◆ operator>()

bool operator> ( const ast_field a,
const ast_field b 
)
related

Greater-than operator for ast_field.

Parameters
[in]aThe ast_field to compare.
[in]bThe ast_field to compare against.
Returns
true if a > b according to ast_field::cmp() , false otherwise.

◆ operator>=()

bool operator>= ( const ast_field a,
const ast_field b 
)
related

Greater-than-or-equal operator for ast_field.

Parameters
[in]aThe ast_field to compare.
[in]bThe ast_field to compare against.
Returns
true if a >= b according to ast_field::cmp() , false otherwise.

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