class ast_field

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

Represents a pair (ord, val), where

ast_field Details

class cs.ast_field

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

__init__(ord, val)

Constructor for ast_field of type ast_field_type.AST.

Parameters:
  • ord (ast_ordinal) – The field ordinal.
  • val (ast) – The field value.
>>> v0 = project.current()
>>> v1 = v0.lookup_symbol('foo')
>>> v2 = v1.get_type()
>>> ast_field(ast_ordinal.UC_DISTINCT_TYPE_NAME, v2)
<cs.ast_field distinct-type-name:[c:routine-type] const char* ()>
__init__(ord, val)

Constructor for ast_field of type ast_field_type.AST_CLASS.

Parameters:
>>> ast_field(ast_ordinal.UC_ASSOC_TYPE, ast_class.NC_CSM_NAMED_VALUE)
<cs.ast_field assoc-type:c:csm-named-value>
__init__(ord, val)

Constructor for ast_field of type ast_field_type.BOOLEAN.

Parameters:
  • ord (ast_ordinal) – The field ordinal.
  • val (bool) – The field value.
>>> ast_field(ast_ordinal.NC_DOUBLE, True)
<cs.ast_field double:true>
__init__(ord, f)

Just like the copy constructor, except the ordinal is overridden.

Parameters:
>>> v0 = ast_field(ast_ordinal.UC_ALTERNATIVE, ')')
>>> ast_field(ast_ordinal.UC_IS_CONSTRUCTOR_INIT, v0)
<cs.ast_field is-constructor-init:)>
__init__(ord, 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.

Parameters:
  • ord (ast_ordinal) – The field ordinal.
  • val (str) – The field value.
>>> ast_field(ast_ordinal.UC_PRECISION, 'foo')
<cs.ast_field precision:foo>
__init__(ord, val)

Constructor for ast_field of type ast_field_type.SFID.

Parameters:
>>> v0 = project.current()
>>> v1 = list(v0.sfiles())[0]
>>> v2 = v1.arbitrary_instance()
>>> ast_field(ast_ordinal.UC_ANY_PURE_VIRTUAL_FUNCTIONS, v2)
<cs.ast_field any-pure-virtual-functions:<cs.sfileinst /alex/csurf/src/api/test/test.h>>
__init__(ord, val)

Constructor for ast_field of type ast_field_type.ABS_LOC.

Parameters:
>>> v0 = project.current()
>>> v1 = v0.lookup_symbol('foo')
>>> ast_field(ast_ordinal.NC_SIZE_IS_INCOMPLETE, v1)
<cs.ast_field size-is-incomplete:<cs.symbol foo>>
__init__(f)

Copy constructor.

Parameters:f (ast_field) –
>>> v0 = ast_field(ast_ordinal.UC_PRECISION, 'foo')
>>> ast_field(v0)
<cs.ast_field precision:foo>
static from_double(ord, val)

Create a new ast_field of type ast_field_type.FLT64

Parameters:
Return type:

ast_field

Returns:

The newly-created ast_field.

>>> ast_field.from_double(ast_ordinal.NC_PTR_TO_MEMBER_FUNCTION, -1.0)
<cs.ast_field ptr-to-member-function:-1>
static from_float(ord, val)

Create a new ast_field of type ast_field_type.FLT32

Parameters:
Return type:

ast_field

Returns:

The newly-created ast_field.

>>> ast_field.from_float(ast_ordinal.NC_BOOL, 1.574686754840869)
<cs.ast_field bool:1.57469>
static from_int16(ord, val)

Create a new ast_field of type ast_field_type.INT16

Parameters:
Return type:

ast_field

Returns:

The newly-created ast_field.

Raises:

OverflowError

>>> ast_field.from_int16(ast_ordinal.BASE_ELEMENT_TYPE, 13)
<cs.ast_field element-type:13>
static from_int32(ord, val)

Create a new ast_field of type ast_field_type.INT32

Parameters:
Return type:

ast_field

Returns:

The newly-created ast_field.

Raises:

OverflowError

>>> ast_field.from_int32(ast_ordinal.UC_IS_TEMPLATE_FUNCTION, 4)
<cs.ast_field is-template-function:4>
static from_int64(ord, val)

Create a new ast_field of type ast_field_type.INT64

Parameters:
Return type:

ast_field

Returns:

The newly-created ast_field.

>>> ast_field.from_int64(ast_ordinal.NC_MINIMUM_STRUCT_ALIGNMENT, 101)
<cs.ast_field minimum-struct-alignment:101>
static from_int8(ord, val)

Create a new ast_field of type ast_field_type.INT8

Parameters:
Return type:

ast_field

Returns:

The newly-created ast_field.

Raises:

OverflowError

>>> ast_field.from_int8(ast_ordinal.UC_IS_LAMBDA_CLOSURE_CLASS, 7)
<cs.ast_field is-lambda-closure-class:7>
static from_uint16(ord, val)

Create a new ast_field of type ast_field_type.UINT16

Parameters:
Return type:

ast_field

Returns:

The newly-created ast_field.

Raises:

OverflowError

>>> ast_field.from_uint16(ast_ordinal.UC_FRIEND_ROUTINES, 62)
<cs.ast_field friend-routines:62>
static from_uint32(ord, val)

Create a new ast_field of type ast_field_type.UINT32

Parameters:
Return type:

ast_field

Returns:

The newly-created ast_field.

Raises:

OverflowError

>>> ast_field.from_uint32(ast_ordinal.UC_THROWN_TYPE, 4)
<cs.ast_field thrown-type:4>
static from_uint64(ord, val)

Create a new ast_field of type ast_field_type.UINT64

Parameters:
Return type:

ast_field

Returns:

The newly-created ast_field.

Raises:

OverflowError

>>> ast_field.from_uint64(ast_ordinal.NC_ENUM_BIT_FIELDS_ARE_ALWAYS_UNSIGNED, 31)
<cs.ast_field enum-bit-fields-are-always-unsigned:31>
static from_uint8(ord, val)

Create a new ast_field of type ast_field_type.UINT8

Parameters:
Return type:

ast_field

Returns:

The newly-created ast_field.

Raises:

OverflowError

>>> ast_field.from_uint8(ast_ordinal.UC_MANGLED_NAME, 8)
<cs.ast_field mangled-name:8>
__cmp__(other)

Comparison function for ast_field .

Parameters:other (ast_field) – The ast_field object to compare against.
Return type:int
Returns:An integer N such that:
  • N==0 if the two objects compare equal
  • N<0 if self < other
  • N>0 if self > other
>>> v0 = ast_field(ast_ordinal.UC_ALTERNATIVE, ')')
>>> v1 = ast_field.from_float(ast_ordinal.UC_LENGTH, 0.0)
>>> v0.__cmp__(v1)
1
__contains__(ord)

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

Parameters:ord (ast_ordinal) – An ast_ordinal denoting the field to check.
Return type:bool
Returns:True if the field denoted by ord is present in the represented ast , False otherwise.
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.AST.

Use this form for fields with named ordinals.

For

  • ast_field myfield, and

  • ast_ordinal myord,

    myord in myfield is equivalent to myord in myfield.as_ast().

>>> v0 = project.current()
>>> v1 = v0.lookup_symbol('foo')
>>> v2 = v1.get_ast()
>>> v3 = v2.attributes()
>>> ast_ordinal.UC_ASSOC_NAMESPACE in v3[0]
False
__contains__(ord)

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

Parameters:

ord (int) – The numeric ordinal of the field to check.

Return type:

bool

Returns:

True if the field denoted by ord is present in the represented ast , False otherwise.

Raises:

Use this form for fields with numeric ordinals.

For

  • ast_field myfield, and

  • size_t myint,

    myint in myfield is equivalent to myint in myfield.as_ast().

>>> v0 = project.current()
>>> v1 = v0.lookup_symbol('foo')
>>> v2 = v1.get_type()
>>> v3 = v2.fields()
>>> 36 in v3[0]
False
__eq__(b)

Equality operator for ast_field .

Parameters:b (ast_field) – The ast_field to compare against.
Return type:bool
Returns:True if self and b compare equal, False otherwise.
>>> v0 = ast_field.from_double(ast_ordinal.UC_NATIVE_NULLPTR_KEYWORD, 13.758593782114)
>>> v1 = ast_field.from_uint32(ast_ordinal.BASE_SPECIAL_FUNCTION_KIND, 25)
>>> v1 == v0
False
__ge__(b)

Greater-than-or-equal operator for ast_field .

Parameters:b (ast_field) – The ast_field to compare against.
Return type:bool
Returns:True if self >= b , False otherwise.
>>> v0 = ast_field.from_int8(ast_ordinal.UC_ARRAY, 51)
>>> v1 = ast_field.from_uint8(ast_ordinal.UC_EXPLICIT_RETURN_TYPE, 27)
>>> v1 >= v0
False
__getitem__(ord)

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

Parameters:

ord (ast_ordinal) – An ast_ordinal denoting the field to retrieve.

Return type:

ast | sfileinst | symbol | bool | float | int | str | bytes

Returns:

The ast_field corresponding to ord. Throws an exception if there is no such field.

Raises:

Use this form for fields with named ordinals.

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

myfield[ord] == myfield(ord) when ast_field myfield contains a field with ordinal ord, but they have different behavior when the field is not present:

>>> v0 = project.current()
>>> v1 = v0.lookup_symbol('foo')
>>> v2 = v1.get_type()
>>> v3 = v2.fields()
>>> v3[0][ast_ordinal.NC_IS_UNALIGNED]
False
__getitem__(ord)

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

Parameters:

ord (int) – The numeric ordinal of the field to retrieve.

Return type:

ast | sfileinst | symbol | bool | float | int | str | bytes

Returns:

The ast_field corresponding to ord. Throws an exception if there is no such field.

Raises:

Use this form for fields with numeric ordinals.

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

myfield[ord] == myfield(ord) when ast_field myfield contains a field with numeric ordinal ord, but they have different behavior when the field is not present:

>>> import os.path
>>> f = next(s for s in project.current().compunits() if os.path.basename(s.name())=='apitest.cpp')
>>> abi = f.get_ast()[ast_ordinal.NC_ABI]
>>> abi[ast_ordinal.NC_USER_ENTRIES][2]
<cs.ast [c:csm-type] signed char __attribute__((csm_proxy_type))>
__gt__(b)

Greater-than operator for ast_field .

Parameters:b (ast_field) – The ast_field to compare against.
Return type:bool
Returns:True if self > b , False otherwise.
>>> v0 = ast_field(ast_ordinal.UC_DECLARED_TYPE, ast_class.NC_IMAGINARY)
>>> v1 = ast_field.from_int32(ast_ordinal.UC_IS_INCLUDE_FILE, -867)
>>> v0 > v1
True
__hash__()

Get a hash value for a ast_field .

Return type:int
>>> v0 = ast_field(ast_ordinal.UC_PRECISION, 'foo')
>>> hash(v0)
510694937
__iter__()

For an ast_field of type ast_field_type.AST, get an iterator over the fields (ast_field) in the represented ast.

Return type:tuple_iterator
Returns:An iterator over the fields (ast_field) in the represented ast.
Raises:result.ERROR_INVALID_TYPE if the ast_field’s type is not ast_field_type.AST
>>> v0 = project.current()
>>> foosym = v0.lookup_symbol('foo')
>>> bsym_typeast = b.get_symbol().get_type()
>>> f = next(fld for fld in foosym.get_type().fields() if fld.get_type()==ast_field_type.AST)
>>> print(f)
return-type:[c:pointer] const char*
>>> for subfield in f: # ast_field.__iter__() and tuple_iterator.__next__() underlyingly manage iteration
...    print(subfield)
...
size:4
alignment:4
is-const:false
is-volatile:false
is-near:false
is-far:false
is-unaligned:false
is-restrict:false
is-complete:true
pointed-to:[c:integer] const char
__le__(b)

Less-than-or-equal operator for ast_field .

Parameters:b (ast_field) – The ast_field to compare against.
Return type:bool
Returns:True if self <= b , False otherwise.
>>> v0 = ast_field(ast_ordinal.UC_ALTERNATIVE, ')')
>>> v1 = ast_field.from_uint16(ast_ordinal.BASE_POINTED_TO, 202)
>>> v0 <= v1
True
__len__()

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

Return type:int
Returns:The number of fields (that is, the number of children plus the number of attributes) contained in the represented ast .
Raises:result.ERROR_INVALID_TYPE if self is not of type ast_field_type.AST.

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

>>> v0 = project.current()
>>> v1 = v0.lookup_symbol('foo')
>>> v2 = v1.get_ast()
>>> v3 = v2.fields()
>>> len(v3[1])
13
__lt__(b)

Less-than operator for ast_field .

Parameters:b (ast_field) – The ast_field to compare against.
Return type:bool
Returns:True if self < b , False otherwise.
>>> v0 = ast_field.from_int16(ast_ordinal.UC_IS_TEMPLATE_FUNCTION, 3)
>>> v1 = ast_field.from_uint8(ast_ordinal.UC_EXPLICIT_RETURN_TYPE, 27)
>>> v0 < v1
True
__ne__(b)

Inequality operator for ast_field .

Parameters:b (ast_field) – The ast_field to compare against.
Return type:bool
Returns:False if self and b compare equal, True otherwise.
>>> v0 = ast_field.from_float(ast_ordinal.NC_REAL_VALUE, 0.0)
>>> v1 = ast_field.from_int32(ast_ordinal.UC_IS_INCLUDE_FILE, -867)
>>> v0 != v1
True
__repr__()

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

Return type:str
Returns:The string representation.
>>> v0 = ast_field.from_int16(ast_ordinal.BASE_ELEMENT_TYPE, 13)
>>> repr(v0)
'<cs.ast_field element-type:13>'
__str__()

Get a simple string representation of a ast_field object.

Return type:str
Returns:The string representation.
>>> v0 = ast_field.from_float(ast_ordinal.NC_BOOL, 1.574686754840869)
>>> str(v0)
'bool:1.57469'
as_ast()

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

Return type:ast
Returns:The ast represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.AST.
>>> v0 = project.current()
>>> v1 = v0.lookup_symbol('foo')
>>> v2 = v1.get_ast()
>>> v3 = v2.attributes()
>>> v3[0].as_ast()
<cs.ast [c:routine-type] const char* ()>
as_ast_class()

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

Return type:ast_class
Returns:The ast_class represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.AST_CLASS.
>>> v0 = ast_field(ast_ordinal.UC_ASSOC_TYPE, ast_class.NC_CSM_NAMED_VALUE)
>>> v0.as_ast_class()
<cs.ast_class c:csm-named-value>
as_boolean()

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

Return type:bool
Returns:The bool represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.BOOLEAN.
>>> v0 = ast_field(ast_ordinal.UC_CAPTURE_BY_REFERENCE, False)
>>> v0.as_boolean()
False
as_bytes()

Get a representation of an ast_field as a bytes object.

Return type:bytes
Returns:A bytes object representing the ast_field, with contents depending on the object depend on the ast_field_type as follows. BYTES: the bytes represented by the field; RESERVED: bytes describing the field; otherwise: empty bytes.
Raises:result.ERROR_INVALID_TYPE
>>> v0 = ast_field(ast_ordinal.BASE_VALUE, 'assignment-operator')
>>> v0.as_bytes()
b'assignment-operator'
as_enum_value_int32()

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

Return type:int
Returns:The integer value of the enum element represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.ENUMERATION.
>>> v0 = project.current()
>>> v1 = v0.lookup_symbol('foo')
>>> v2 = v1.get_ast()
>>> v3 = v2.attributes()
>>> v3[1].as_enum_value_int32()
44
as_enum_value_string()

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

Return type:str
Returns:A string representation of the enum element represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.ENUMERATION.
>>> v0 = project.current()
>>> v1 = v0.lookup_symbol('foo')
>>> v2 = v1.get_ast()
>>> v3 = v2.fields()
>>> v3[2].as_enum_value_string()
'unspecified'
as_flt32()

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

Return type:float
Returns:The value represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.FLT32.
>>> v0 = ast_field.from_float(ast_ordinal.NC_ZERO_WIDTH_BIT_FIELD_AFFECTS_STRUCT_ALIGNMENT, 6.859357208338929)
>>> v0.as_flt32()
6.8593573570251465
as_flt64()

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

Return type:float
Returns:The value represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.FLT64.
>>> v0 = ast_field.from_double(ast_ordinal.UC_BEFRIENDING_CLASSES, 1.0)
>>> v0.as_flt64()
1.0
as_int16()

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

Return type:int
Returns:The value represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.INT16.
>>> v0 = ast_field.from_int16(ast_ordinal.NC_IS_FAR, 772)
>>> v0.as_int16()
772
as_int32()

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

Return type:int
Returns:The value represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.INT32.
>>> v0 = ast_field.from_int32(ast_ordinal.UC_IS_TEMPLATE_FUNCTION, 4)
>>> v0.as_int32()
4
as_int64()

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

Return type:int
Returns:The value represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.INT64.
>>> v0 = ast_field.from_int64(ast_ordinal.NC_MINIMUM_STRUCT_ALIGNMENT, 101)
>>> v0.as_int64()
101
as_int8()

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

Return type:int
Returns:The value represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.INT8.
>>> v0 = ast_field.from_int8(ast_ordinal.NC_SIZE_T_MAX_USE_DEFAULT, 0)
>>> v0.as_int8()
0
as_sfileinst()

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

Return type:sfileinst
Returns:The sfileinst represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field type is not ast_field_type.SFID.
>>> import os.path
>>> f = next(s for s in project.current().sfiles() if os.path.basename(s.name())=='apitest.cpp')
>>> fi = f.arbitrary_instance()
>>> af = ast_field(ast_ordinal.BASE_VALUE_RETURNED_BY_CCTOR, fi)
>>> af.as_sfileinst()
<cs.sfileinst /mys0/alex/trunk/cso-tests/regression/functional/apitest.cpp>
as_str()

Get a string representation of an ast_field .

Return type:str
Returns:A string, depending on the type of the invoking ast_field :
Raises:result.ERROR_INVALID_TYPE if called on an ast_field of invalid type.
>>> v0 = ast_field(ast_ordinal.UC_UUID_STRING, '<cs.proceduremetricclass_iterator begin>')
>>> v0.as_str()
'<cs.proceduremetricclass_iterator begin>'
as_symbol()

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

Return type:symbol
Returns:The symbol represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field type is not ast_field_type.ABS_LOC.
>>> v0 = project.current()
>>> v1 = v0.lookup_symbol('foo')
>>> v2 = v1.get_ast()
>>> v3 = v2.attributes()
>>> v3[5].as_symbol()
<cs.symbol foo>
as_uint16()

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

Return type:int
Returns:The value represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.UINT16.
>>> v0 = ast_field.from_uint16(ast_ordinal.BASE_FLOAT_KIND, 12)
>>> v0.as_uint16()
12
as_uint32()

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

Return type:int
Returns:The value represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.UINT32.
>>> v0 = ast_field.from_uint32(ast_ordinal.UC_IS_SPECIALIZED, 2)
>>> v0.as_uint32()
2
as_uint64()

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

Return type:int
Returns:The value represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.UINT64.
>>> v0 = ast_field.from_uint64(ast_ordinal.NC_UNNAMED_BIT_FIELD_AFFECTS_STRUCT_ALIGNMENT, 8)
>>> v0.as_uint64()
8
as_uint8()

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

Return type:int
Returns:The value represented by the ast_field .
Raises:result.ERROR_INVALID_TYPE if the ast_field ‘s type is not ast_field_type.UINT8.
>>> v0 = ast_field.from_uint8(ast_ordinal.NC_RIGHT_SHIFT_IS_ARITHMETIC, 6)
>>> v0.as_uint8()
6
fast_cmp(other)

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

Parameters:other (ast_field) –
Return type:int
Returns:An integer N, such that:
  • N<0 if self considered less than other
  • N==0 if self considered equal to other
  • N>0 if self considered greater than other
>>> v0 = ast_field(ast_ordinal.UC_DECLARED_TYPE, ast_class.NC_IMAGINARY)
>>> v1 = ast_field.from_int64(ast_ordinal.BASE_IS_UNSIGNED, 277)
>>> v0.fast_cmp(v1)
-1
fast_hash()

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

Return type:int
Returns:The hash value.
>>> v0 = ast_field.from_int32(ast_ordinal.UC_IS_INCLUDE_FILE, -867)
>>> v0.fast_hash()
4231664009
get(ord)

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

Parameters:ord (ast_ordinal) – An ast_ordinal denoting the field to retrieve.
Return type:ast | sfileinst | symbol | NoneType | bool | float | int | str | bytes
Raises:result.ERROR_INVALID_TYPE if self is not of type ast_field_type.AST.

Use this form for fields with named ordinals.

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

myfield[ord] == myfield(ord) when ast_field myfield contains a field with ordinal ord, but they have different behavior when the field is not present:

>>> v0 = project.current()
>>> v1 = v0.lookup_symbol('foo')
>>> v2 = v1.get_ast()
>>> v3 = v2.fields()
>>> v3[1].get(ast_ordinal.UC_GNU_ASM_NAME_OR_REG_NAME)
get(ord)

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

Parameters:

ord (int) – The numeric ordinal of the field to retrieve.

Return type:

ast | sfileinst | symbol | NoneType | bool | float | int | str | bytes

Raises:

Use this form for fields with numeric ordinals.

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

myfield[ord] == myfield(ord) when ast_field myfield contains a field with numeric ordinal ord, but they have different behavior when the field is not present:

>>> v0 = project.current()
>>> v1 = v0.lookup_symbol('foo')
>>> v2 = v1.get_ast()
>>> v3 = v2.fields()
>>> v3[1].get(834)
get_type()

Get the ast_field_type associated with an ast_field .

Return type:ast_field_type
Returns:The ast_field_type .
>>> v0 = ast_field.from_int16(ast_ordinal.BASE_ELEMENT_TYPE, 13)
>>> v0.get_type()
<cs.ast_field_type int16>
ordinal()

Get the ast_ordinal associated with an ast_field .

Return type:ast_ordinal
Returns:The ast_ordinal .
Raises:result.ERROR_INVALID_ARGUMENT if the ast_field does not have a valid ast_ordinal associated with it.
>>> v0 = ast_field.from_uint32(ast_ordinal.UC_THROWN_TYPE, 4)
>>> v0.ordinal()
<cs.ast_ordinal thrown-type>
stable_cmp(other)

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

Parameters:other (ast_field) – The ast_field to compare against.
Return type:int
Returns:An integer N, such that:
  • N<0 if self considered less than other
  • N==0 if self considered equal to other
  • N>0 if self 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 ast_field.__cmp__(): it has better performance.

>>> v0 = ast_field.from_double(ast_ordinal.UC_QUALIFIERS, 579.5303233714942)
>>> v1 = ast_field.from_int8(ast_ordinal.NC_PLAIN_INT_BIT_FIELD_IS_UNSIGNED, 28)
>>> v1.stable_cmp(v0)
1
value()

Get the field value.

Return type:ast | ast_class | sfileinst | symbol | bool | float | int | str | bytes
Returns:The value stored in the field.
>>> v0 = ast_field.from_int8(ast_ordinal.UC_IS_LAMBDA_CLOSURE_CLASS, 7)
>>> v0.value()
7