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:
object
Represents an integer in an arbitrary base. Its parser can read:
binary numbers, e.g.,
0b1100
base 8 numbers, e.g.,
0o1147
base 16 numbers, e.g.,
0x11FF
base 10 numbers, e.g.,
1100
arbitrary 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:
object
Abstract 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:
TypeABC
Boolean type.
- class Integer(type: str, readonly: bool, _info: dict | None, range: Range, endian: Endian | None = None, bit_size: IntBase | None = None)[source]¶
Bases:
TypeABC
Integer 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:
TypeABC
Array 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:
TypeABC
A 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:
TypeABC
Qualified 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
Entry
object 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.