raesl.compile.typechecking.compdef_relinst_builder#

Relation instance type-checking in a component definition.

Module Contents#

Classes#

RelInstArgsBlock

A 'block' of arguments of a relation instance. The kind of arguments, and a list

RelInst

Relation instance while collecting.

RelInstArgGroup

Temporary data storage of parameters and arguments of a single kind.

CompDefRelInstBuilder

Collect and check relation instances in a component definition.

class raesl.compile.typechecking.compdef_relinst_builder.RelInstArgsBlock(argkind_tok: raesl.compile.scanner.Token, arg_name_toks: List[raesl.compile.scanner.Token] | None = None)#

A ‘block’ of arguments of a relation instance. The kind of arguments, and a list of argument lines.

Parameters:
  • argkind_tok – Token indicating the kind of arguments specified in the block.

  • arg_name_toks – Arguments of the block.

class raesl.compile.typechecking.compdef_relinst_builder.RelInst(inst_name_tok: raesl.compile.scanner.Token, def_name_tok: raesl.compile.scanner.Token, arg_blocks: List[RelInstArgsBlock] | None = None)#

Relation instance while collecting.

Parameters:
  • inst_name_tok – Instance name.

  • def_name_tok – Definition name.

  • arg_blocks – Blocks with arguments.

class raesl.compile.typechecking.compdef_relinst_builder.RelInstArgGroup(argkind: str, parameters: List[raesl.compile.ast.relations.RelationDefParameter], arguments: List[raesl.compile.scanner.Token])#

Temporary data storage of parameters and arguments of a single kind.

class raesl.compile.typechecking.compdef_relinst_builder.CompDefRelInstBuilder(comp_child_builders: raesl.compile.typechecking.compdef_builder.CompDefChildBuilders)#

Collect and check relation instances in a component definition.

Parameters:

comp_child_builders – Storage of child builders for a component definition.

relinsts#

Collected relation instances in the component.

last_relinst#

Link to last added instance to allow adding instance arguments.

new_relinst(inst_name_tok: raesl.compile.scanner.Token, def_name_tok: raesl.compile.scanner.Token)#

Parser found a new relation instance, store it for future extending by the parser, and eventual type checking and adding to the surrounding component definition.

relinst_argheader(argkind_tok: raesl.compile.scanner.Token)#

Parser found a new direction block for a relation instance, collect it.

add_relinst_arguments(name_toks: List[raesl.compile.scanner.Token])#

Parser found an argument of a direction-block in a relation instance, store it for future checking.

finish_comp(comp_def: raesl.compile.ast.components.ComponentDefinition, spec: raesl.compile.ast.specification.Specification)#

Check the collected relation instances, report errors, and add the instances to the given component.

Parameters:
  • comp_def – Component definition to extend with the found relation instances. Also a source of available variables, parameters, and variable groups.

  • spec – Specification being constructed. Source for types and relation definitions processed previously.

_add_relation_instance_names()#

Check whether the relation instances all have unique instance names, else report an error.

static _split_definition_parameters_by_kind(reldef: raesl.compile.ast.relations.RelationDefinition) Dict[str, List[raesl.compile.ast.relations.RelationDefParameter]]#

Split the parameters of the definition in 3 groups, ‘requiring’, ‘returning’, and ‘relating’.

Parameters:

reldef – Relation definition to use.

Returns:

Mapping of the parameters in the mentioned 3 groups.

_split_instance_arguments_by_kind(relinst: RelInst, reldef: raesl.compile.ast.relations.RelationDefinition, def_parameters: Dict[str, List[raesl.compile.ast.relations.RelationDefParameter]]) List[RelInstArgGroup] | None#

Split the argument blocks, and check whether instance and definition agree with each other. Report errors if discrepancies are found, and merge argument blocks.

Arguments

relinst: Relation instance to check. def_parameters: Parameters of the definition grouped by argument kind.

Returns:

Triplets (kind, parameter-defs, argument tokens) wrapped in RelInstArgGroup

instances, or None if a fatal error was found.

_group_param_args(argkind: str, parameters: List[raesl.compile.ast.relations.RelationDefParameter], arguments: List[raesl.compile.scanner.Token], relinst: RelInst, reldef: raesl.compile.ast.relations.RelationDefinition) List[List[raesl.compile.scanner.Token]] | None#

Group the arguments into pieces such that each parameter has exactly one piece. Mostly this means that the first multi-value parameter takes up all slack.

Parameters:
  • argkind – Kind of parameters, one of (‘requiring’, ‘returning’, ‘relating’)

  • parameters – Parameters of the definition for the argkind.

  • arguments – Arguments of the instance for the argkind.

  • relinst – Relation instance.

  • reldef – Relation definition.

Returns:

None if a fatal error occurred, else grouped arguments.