raesl.compile.typechecking.type_builder#

Class for constructing types.

Module Contents#

Classes#

TempTypeDef

Temporary storage of a type definition.

TempFieldDef

Temporary storage of a field in a bundle.

TempBundleDef

Temporary storage of a bundle definition.

TypeBuilder

Builder to construct types of the specification.

Attributes#

STANDARD_TYPE_NAMES

raesl.compile.typechecking.type_builder.STANDARD_TYPE_NAMES = ('real', 'integer', 'string', 'boolean')#
class raesl.compile.typechecking.type_builder.TempTypeDef(type_name: raesl.compile.scanner.Token, parent_name: raesl.compile.scanner.Token | None, enum_spec: List[raesl.compile.ast.exprs.Value] | None, unit_spec: List[raesl.compile.scanner.Token] | None, ival_spec: List[Tuple[raesl.compile.ast.exprs.Value | None, raesl.compile.ast.exprs.Value | None]] | None, cons_spec: raesl.compile.ast.exprs.Value | None)#

Temporary storage of a type definition.

class raesl.compile.typechecking.type_builder.TempFieldDef(field_name: raesl.compile.scanner.Token, type_name: raesl.compile.scanner.Token | None)#

Temporary storage of a field in a bundle.

class raesl.compile.typechecking.type_builder.TempBundleDef(bundle_name: raesl.compile.scanner.Token)#

Temporary storage of a bundle definition.

class raesl.compile.typechecking.type_builder.TypeBuilder(ast_builder: raesl.compile.typechecking.ast_builder.AstBuilder)#

Builder to construct types of the specification.

Parameters:

ast_builder – AST builder instance.

diag_store#

Storage for found diagnostics.

type_defs#

Found type definitions in the specification, temporarily stored until all type information is available.

bundle_defs#

Found bundle definitions in the specification, temporarily stored until all type information is available.

current_bundle#

If not None, reference to the last opened bundle definition for adding additional fields to it.

notify_new_section(_new_top_section: bool)#

Notification that type additions have finished.

static get_entry_location(entry: raesl.compile.typechecking.orderer.OrdererEntry) raesl.types.Location#

Retrieve position information from a type entry.

Parameters:

entry – Entry to use.

Returns:

Position information of the entry.

static add_standard_types(resolved_types: Dict[str, raesl.compile.ast.types.TypeDef])#

Add all standard types to the resolved types.

finish(spec)#

Check the collected types and bundles, report any errors, and add them to the specification.

Parameters:

spec – Specification to extend with the found types.

_construct_type(parent_name: raesl.compile.scanner.Token | None, enum_spec: List[raesl.compile.ast.exprs.Value] | None, unit_spec: List[raesl.compile.scanner.Token] | None, ival_spec: List[Tuple[raesl.compile.ast.exprs.Value | None, raesl.compile.ast.exprs.Value | None]] | None, cons_spec: raesl.compile.ast.exprs.Value | None, prefer_parent: bool, resolved_types: Dict[str, raesl.compile.ast.types.TypeDef]) raesl.compile.ast.types.BaseType | None#

Construct a new type from the given parameters.

Parameters:

prefer_parent – If possible, don’t make a new type.

Returns:

The parent type if nothing changed, the constructed ElementaryType if

something was extended, or None if construction failed.

_check_override_standard_type(type_name: raesl.compile.scanner.Token) bool#

Check whether the new type tries to override a standard type. Give an error if it does.

Returns:

True if the new type is a standard type, else False.

_make_typedef(tdef: TempTypeDef, resolved_types: Dict[str, raesl.compile.ast.types.TypeDef])#

Add the type definition to the resolved collection. It is assumed the dependencies are already available (as ensured by the Orderer).

_make_bundledef(bdef: TempBundleDef, resolved_types: Dict[str, raesl.compile.ast.types.TypeDef])#

Add the bundle definition to the resolved collection. It is assumed the dependencies are already available (as ensured by the Orderer).

add_typedef(type_name: raesl.compile.scanner.Token, parent_name: raesl.compile.scanner.Token | None, enum_spec: List[raesl.compile.ast.exprs.Value] | None, unit_spec: List[raesl.compile.scanner.Token] | None, ival_spec: List[Tuple[raesl.compile.ast.exprs.Value | None, raesl.compile.ast.exprs.Value | None]] | None, cons_spec: raesl.compile.ast.exprs.Value | None)#

The parser found a new type definition entry, store it.

new_bundle_type(bundle_name: raesl.compile.scanner.Token)#

The parser found a new bundle in the source code, create it.

add_bundle_field(field_name: raesl.compile.scanner.Token, type_name: raesl.compile.scanner.Token | None)#

A new field in the current bundle has been found by the parser, add it.

check_unit(value: raesl.compile.ast.exprs.Value | None, available_units: Dict[str, raesl.compile.scanner.Token]) None#

Check whether the unit possibly specified in ‘value’ is available for use. Report an error if it is not available.