class ast_field¶
A field (child or attribute) of an Abstract Syntax Tree (class ast ).
Represents a pair (ord, val), where
ordis anast_ordinalvalis a value whose type is described by anast_field_type
ast_field Members¶
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_fieldof typeast_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* ()>
- ord (
-
__init__(ord, val)¶ Constructor for
ast_fieldof typeast_field_type.AST_CLASS.Parameters: - ord (
ast_ordinal) – The field ordinal. - val (
ast_class) – The field value.
>>> ast_field(ast_ordinal.UC_ASSOC_TYPE, ast_class.NC_CSM_NAMED_VALUE) <cs.ast_field assoc-type:c:csm-named-value>
- ord (
-
__init__(ord, val)¶ Constructor for
ast_fieldof typeast_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>
- ord (
-
__init__(ord, f)¶ Just like the copy constructor, except the ordinal is overridden.
Parameters: - ord (
ast_ordinal) – - f (
ast_field) –
>>> v0 = ast_field(ast_ordinal.UC_ALTERNATIVE, ')') >>> ast_field(ast_ordinal.UC_IS_CONSTRUCTOR_INIT, v0) <cs.ast_field is-constructor-init:)>
- ord (
-
__init__(ord, val)¶ Constructor for
ast_fieldof typeast_field_type.CONST_STR,ast_field_type.CONST_STR64,ast_field_type.BYTES, orast_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>
- ord (
-
__init__(ord, val)¶ Constructor for
ast_fieldof typeast_field_type.SFID.Parameters: - ord (
ast_ordinal) – - val (
sfileinst) –
>>> 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>>
- ord (
-
__init__(ord, val)¶ Constructor for
ast_fieldof typeast_field_type.ABS_LOC.Parameters: - ord (
ast_ordinal) – The field ordinal. - val (
symbol) – The field value.
>>> 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>>
- ord (
-
__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_fieldof typeast_field_type.FLT64Parameters: - ord (
ast_ordinal) – The field ordinal: anast_ordinal. - val (float) – The field value.
Return type: 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>
- ord (
-
static
from_float(ord, val)¶ Create a new
ast_fieldof typeast_field_type.FLT32Parameters: - ord (
ast_ordinal) – The field ordinal: anast_ordinal. - val (float) – The field value.
Return type: Returns: The newly-created
ast_field.>>> ast_field.from_float(ast_ordinal.NC_BOOL, 1.574686754840869) <cs.ast_field bool:1.57469>
- ord (
-
static
from_int16(ord, val)¶ Create a new
ast_fieldof typeast_field_type.INT16Parameters: - ord (
ast_ordinal) – The field ordinal: anast_ordinal. - val (int) – The field value.
Return type: Returns: The newly-created
ast_field.Raises: OverflowError>>> ast_field.from_int16(ast_ordinal.BASE_ELEMENT_TYPE, 13) <cs.ast_field element-type:13>
- ord (
-
static
from_int32(ord, val)¶ Create a new
ast_fieldof typeast_field_type.INT32Parameters: - ord (
ast_ordinal) – The field ordinal: anast_ordinal. - val (int) – The field value.
Return type: 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>
- ord (
-
static
from_int64(ord, val)¶ Create a new
ast_fieldof typeast_field_type.INT64Parameters: - ord (
ast_ordinal) – The field ordinal: anast_ordinal. - val (int) – The field value.
Return type: Returns: The newly-created
ast_field.>>> ast_field.from_int64(ast_ordinal.NC_MINIMUM_STRUCT_ALIGNMENT, 101) <cs.ast_field minimum-struct-alignment:101>
- ord (
-
static
from_int8(ord, val)¶ Create a new
ast_fieldof typeast_field_type.INT8Parameters: - ord (
ast_ordinal) – The field ordinal: anast_ordinal. - val (int) – The field value.
Return type: 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>
- ord (
-
static
from_uint16(ord, val)¶ Create a new
ast_fieldof typeast_field_type.UINT16Parameters: - ord (
ast_ordinal) – The field ordinal: anast_ordinal. - val (int) – The field value.
Return type: Returns: The newly-created
ast_field.Raises: OverflowError>>> ast_field.from_uint16(ast_ordinal.UC_FRIEND_ROUTINES, 62) <cs.ast_field friend-routines:62>
- ord (
-
static
from_uint32(ord, val)¶ Create a new
ast_fieldof typeast_field_type.UINT32Parameters: - ord (
ast_ordinal) – The field ordinal: anast_ordinal. - val (int) – The field value.
Return type: Returns: The newly-created
ast_field.Raises: OverflowError>>> ast_field.from_uint32(ast_ordinal.UC_THROWN_TYPE, 4) <cs.ast_field thrown-type:4>
- ord (
-
static
from_uint64(ord, val)¶ Create a new
ast_fieldof typeast_field_type.UINT64Parameters: - ord (
ast_ordinal) – The field ordinal: anast_ordinal. - val (int) – The field value.
Return type: 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>
- ord (
-
static
from_uint8(ord, val)¶ Create a new
ast_fieldof typeast_field_type.UINT8Parameters: - ord (
ast_ordinal) – The field ordinal: anast_ordinal. - val (int) – The field value.
Return type: Returns: The newly-created
ast_field.Raises: OverflowError>>> ast_field.from_uint8(ast_ordinal.UC_MANGLED_NAME, 8) <cs.ast_field mangled-name:8>
- ord (
-
__cmp__(other)¶ Comparison function for
ast_field.Parameters: other ( ast_field) – Theast_fieldobject 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_fieldof typeast_field_type.AST, check whether the representedastcontains the designated field.Parameters: ord ( ast_ordinal) – Anast_ordinaldenoting the field to check.Return type: bool Returns: Trueif the field denoted byordis present in the representedast,Falseotherwise.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_field_type.AST.Use this form for fields with named ordinals.
For
ast_fieldmyfield, andast_ordinalmyord,myord in myfieldis equivalent tomyord 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_fieldof typeast_field_type.AST, check whether the representedastcontains the designated field.Parameters: ord (int) – The numeric ordinal of the field to check.
Return type: bool
Returns: Trueif the field denoted by ord is present in the representedast,Falseotherwise.Raises: result.ERROR_INVALID_ARGUMENTiford<= 0result.ERROR_INVALID_TYPEifselfis not of typeast_field_type.AST.
Use this form for fields with numeric ordinals.
For
ast_fieldmyfield, andsize_tmyint,myint in myfieldis equivalent tomyint 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) – Theast_fieldto compare against.Return type: bool Returns: Trueifselfandbcompare equal,Falseotherwise.>>> 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) – Theast_fieldto compare against.Return type: bool Returns: Trueifself>=b,Falseotherwise.>>> 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_fieldof typeast_field_type.AST, get the designated field of the representedast.Parameters: ord (
ast_ordinal) – Anast_ordinaldenoting the field to retrieve.Return type: Returns: The
ast_fieldcorresponding to ord. Throws an exception if there is no such field.Raises: result.ERROR_INVALID_TYPEifselfis not of typeast_field_type.AST.ast_field_not_found_errorif there is no such field.
Use this form for fields with named ordinals.
myfield[myord]is equivalent tomyfield.as_ast()[myord].myfield[ord] == myfield(ord)whenast_fieldmyfieldcontains a field with ordinalord, but they have different behavior when the field is not present:myfield[ord](ast_field.__getitem__()) raises aKeyError.myfield.get(ord)(ast_field.get()) returnsNone.
>>> 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_fieldof typeast_field_type.AST, get the designated field of the representedast.Parameters: ord (int) – The numeric ordinal of the field to retrieve.
Return type: Returns: The
ast_fieldcorresponding to ord. Throws an exception if there is no such field.Raises: result.ERROR_INVALID_ARGUMENTiford<=0.result.ERROR_INVALID_TYPEifselfis not of typeast_field_type.AST.ast_field_not_found_errorif there is no such field.
Use this form for fields with numeric ordinals.
myfield[myint]is equivalent tomyfield.as_ast()[myint].myfield.get(myint)is equivalent tomyfield.as_ast().get(myint).
myfield[ord] == myfield(ord)whenast_fieldmyfieldcontains a field with numeric ordinalord, but they have different behavior when the field is not present:myfield[ord](ast_field.__getitem__()) raises aKeyError.myfield.get(ord)(ast_field.get()) returnsNone.
>>> 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) – Theast_fieldto compare against.Return type: bool Returns: Trueifself>b,Falseotherwise.>>> 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 representedast.Return type: tuple_iterator Returns: An iterator over the fields ( ast_field) in the representedast.Raises: result.ERROR_INVALID_TYPEif the ast_field’s type is notast_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) – Theast_fieldto compare against.Return type: bool Returns: Trueifself<=b,Falseotherwise.>>> 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_fieldof typeast_field_type.AST, get the number of fields contained in the representedast.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_TYPEifselfis not of typeast_field_type.AST.For
ast_fieldmyfield,len(myfield)is equivalent tolen(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) – Theast_fieldto compare against.Return type: bool Returns: Trueifself<b,Falseotherwise.>>> 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) – Theast_fieldto compare against.Return type: bool Returns: Falseifselfandbcompare equal,Trueotherwise.>>> 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_fieldobject 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_fieldobject.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_fieldof typeast_field_type.AST.Return type: astReturns: The astrepresented by theast_field.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_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_fieldof typeast_field_type.AST_CLASS.Return type: ast_classReturns: The ast_classrepresented by theast_field.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_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_fieldof typeast_field_type.BOOLEAN.Return type: bool Returns: The bool represented by the ast_field.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_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_fieldas a bytes object.Return type: bytes Returns: A bytes object representing the ast_field, with contents depending on the object depend on theast_field_typeas 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_fieldof typeast_field_type.ENUMERATION.Return type: int Returns: The integer value of the enum element represented by the ast_field.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_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_fieldof typeast_field_type.ENUMERATION.Return type: str Returns: A string representation of the enum element represented by the ast_field.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_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_fieldof typeast_field_type.FLT32.Return type: float Returns: The value represented by the ast_field.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_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_fieldof typeast_field_type.FLT64.Return type: float Returns: The value represented by the ast_field.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_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_fieldof typeast_field_type.INT16.Return type: int Returns: The value represented by the ast_field.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_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_fieldof typeast_field_type.INT32.Return type: int Returns: The value represented by the ast_field.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_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_fieldof typeast_field_type.INT64.Return type: int Returns: The value represented by the ast_field.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_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_fieldof typeast_field_type.INT8.Return type: int Returns: The value represented by the ast_field.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_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_fieldwhose type isast_field_type.SFID.Return type: sfileinstReturns: The sfileinstrepresented by theast_field.Raises: result.ERROR_INVALID_TYPEif theast_fieldtype is notast_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:ast_field_type.CONST_STR64orast_field_type.CONST_STR: the string represented by theast_field,ast_field_type.RESERVED: a string describing theast_field,- otherwise: the empty string.
Raises: result.ERROR_INVALID_TYPEif called on anast_fieldof 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_fieldwhose type isast_field_type.ABS_LOC.Return type: symbolReturns: The symbolrepresented by theast_field.Raises: result.ERROR_INVALID_TYPEif theast_fieldtype is notast_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_fieldof typeast_field_type.UINT16.Return type: int Returns: The value represented by the ast_field.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_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_fieldof typeast_field_type.UINT32.Return type: int Returns: The value represented by the ast_field.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_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_fieldof typeast_field_type.UINT64.Return type: int Returns: The value represented by the ast_field.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_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_fieldof typeast_field_type.UINT8.Return type: int Returns: The value represented by the ast_field.Raises: result.ERROR_INVALID_TYPEif theast_field‘s type is notast_field_type.UINT8.>>> v0 = ast_field.from_uint8(ast_ordinal.NC_RIGHT_SHIFT_IS_ARITHMETIC, 6) >>> v0.as_uint8() 6
-
fast_cmp(other)¶ If
selfis ast-typed, applies ast::fast_cmp() to this.as_ast(); otherwise behaves just likeast_field.__cmp__().Parameters: other ( ast_field) –Return type: int Returns: An integer N, such that: - N<0 if
selfconsidered less thanother - N==0 if
selfconsidered equal toother - N>0 if
selfconsidered greater thanother
>>> 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
- N<0 if
-
fast_hash()¶ If
selfis ast-typed, applies ast::fast_hash() to this.as_ast(); otherwise behaves just likeast_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_fieldof typeast_field_type.AST, get the designated field of the representedast.Parameters: ord ( ast_ordinal) – Anast_ordinaldenoting the field to retrieve.Return type: ast|sfileinst|symbol| NoneType | bool | float | int | str | bytesRaises: result.ERROR_INVALID_TYPEifselfis not of typeast_field_type.AST.Use this form for fields with named ordinals.
myfield[myord]is equivalent tomyfield.as_ast()[myord].myfield[ord] == myfield(ord)whenast_fieldmyfieldcontains a field with ordinalord, but they have different behavior when the field is not present:myfield[ord](ast_field.__getitem__()) raises aKeyError.myfield.get(ord)(ast_field.get()) returnsNone.
>>> 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_fieldof typeast_field_type.AST, get the designated field of the representedast.Parameters: ord (int) – The numeric ordinal of the field to retrieve.
Return type: ast|sfileinst|symbol| NoneType | bool | float | int | str | bytesRaises: result.ERROR_INVALID_ARGUMENTiford<=0.result.ERROR_INVALID_TYPEifselfis not of typeast_field_type.AST.
Use this form for fields with numeric ordinals.
myfield[myint]is equivalent tomyfield.as_ast()[myint].myfield.get(myint)is equivalent tomyfield.as_ast().get(myint).
myfield[ord] == myfield(ord)whenast_fieldmyfieldcontains a field with numeric ordinalord, but they have different behavior when the field is not present:myfield[ord](ast_field.__getitem__()) raises aKeyError.myfield.get(ord)(ast_field.get()) returnsNone.
>>> 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_typeassociated with anast_field.Return type: ast_field_typeReturns: 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_ordinalassociated with anast_field.Return type: ast_ordinalReturns: The ast_ordinal.Raises: result.ERROR_INVALID_ARGUMENTif theast_fielddoes not have a validast_ordinalassociated 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) – Theast_fieldto compare against.Return type: int Returns: An integer N, such that: - N<0 if
selfconsidered less thanother - N==0 if
selfconsidered equal toother - N>0 if
selfconsidered greater thanother
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
a1andb1be twoast_fieldobjects in A1, anda2andb2be theast_fieldobjects in A2 that correspond toa1andb1respectively. Thena1.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
- N<0 if
-