The Target-Agnostic Core¶
Hashables¶
Theses classes are used for identifying types which have been bound and loaded to theirrepective module.
Base Attributes¶
These AST objects are used to encode base attributes in type definitions, but are not types per-se.
- class IntBase(value: int, base: int)[source]¶
Bases:
objectRepresents an integer in an arbitrary base. Its parser can read:
binary numbers, e.g.,
0b1100base 8 numbers, e.g.,
0o1147base 16 numbers, e.g.,
0x11FFbase 10 numbers, e.g.,
1100arbitrary base numbers from a tuple, e.g.,
(<value>, <base>)
- value: int¶
- base: int¶
Core Data Types¶
These classes encode the target-agnostic type representations.
- class TypeABC(type: str, readonly: bool, _info: dict | None)[source]¶
Bases:
objectAbstract base class for all type representations.
- type: str¶
- readonly: bool¶
- class Boolean(type: str, readonly: bool, _info: dict | None, bit_size: IntBase | None = None)[source]¶
Bases:
TypeABCBoolean type.
- class Integer(type: str, readonly: bool, _info: dict | None, range: Range, endian: Endian | None = None, bit_size: IntBase | None = None)[source]¶
Bases:
TypeABCInteger type. OBS: range attribute is mandatory.
- class Array(type: str, readonly: bool, _info: dict | None, range: Range, element_type: TypeABC, len_field: str | None = None)[source]¶
Bases:
TypeABCArray type. OBS: range and element_type attributes are mandatory.
- len_field: str | None = None¶
- class Structure(type: str, readonly: bool, _info: dict | None, field: Dict[str, TypeABC])[source]¶
Bases:
TypeABCA structure type is represented as a dictionary of other types.
- class TypeRef(type: str, readonly: bool, _info: dict | None, ref: Uid, range_mod: Range | None = None, endian_mod: Endian | None = None, bit_size: IntBase | None = None)[source]¶
Bases:
TypeABCQualified reference to another (defined) type.
The Type Database Handler¶
- class FtnDb(srcs={})[source]¶
This is a singleton handler that takes care of loading and constructing the module dictionaries, populating them with FTN type definitions, and retrieving various information. Its constructor should be called exactly once at the beginning of the program.
- Parameters:
srcs – dictionaries of modules with raw type definitions in AST format (e.g., JSON).
- static clear_instance()[source]¶
Static destructor. Allows the subsequent creation of a new handler.
- add_source(module: str, name: str, src: Dict) None[source]¶
Adds a user-provided raw source in the database.
- parse(src) TypeABC[source]¶
Returns a base FTN type from a raw source expression without adding it to the database.
- schema(base_type_name: str) Schema[source]¶
Returns the JSON schema used to parse a raw source expression into a base type.
- get(what: Uid | str | TypeABC) TypeABC[source]¶
Returns a fully-built and loaded type definition. If not found it searches for its source module, deserializes using a corresponding base type schema and stores it in the database for future use.
- make_entry(name: str | None = None, from_ftn: str | None = None, from_spec: Dict | None = None, value: str | None = None) Entry[source]¶
(Possibly constructs and) stores a FTN data type into the current database and returns an
Entryobject pointing to it.- Parameters:
name – (mutually exclusive with from_ftn, from_spec) qualified name to previously loaded type (calls
get()for good measure)from_ftn – (mutually exclusive with name, from_spec) string with binding or expression in the FTN language.
from_spec – (mutually exclusive with name, from_ftn) string with binding or expression in raw format.
value – initialization value.