raesl.compile.instantiating.node_building#

Methods for casting ESL AST into ragraph.node.Node objects.

Module Contents#

Classes#

NodeStore

Node storage with multiple catagories for quicker access to specific subsets.

NodeFactory

Node factory. Creates Node objects from a Specification.

Functions#

make_variable_instmap(...)

Construct instance nodes for the provided variable.

make_parameter_instmap(...)

Construct an inst node map for a parameter of a child component instance.

make_type_node(→ ragraph.node.Node)

Node creation for a type definition.

_make_type_annotations(→ Dict[str, Dict[str, Any]])

Creating dictionary to annotate variable_type nodes.

make_variable_node(→ ragraph.node.Node)

Node creation for a variable.

_make_variable_annotations(→ Dict[str, Dict[str, Any]])

Creating dictionary for variable annotations.

make_component_node(→ ragraph.node.Node)

Node creation for a component.

_make_component_annotations(→ Dict[str, Dict[str, Any]])

Component annotation creation.

make_need_node(→ ragraph.node.Node)

Node creation for a component.

_make_need_annotations(→ Dict[str, Dict[str, Any]])

Need annotation creation.

make_goal_node(→ ragraph.node.Node)

Goal node creation.

_make_goal_annotations(→ Dict[str, Dict[str, Any]])

Goal annotation creation.

make_transform_node(→ ragraph.node.Node)

Transformation node creation.

_unfold_compound_var(...)

Unfolding CompoundVarNode into a list of ElementartyVarNode

_get_variable_inst_names(→ List[str])

Converting list of Flow objects into a list of instantiated variable names.

_make_transform_annotations(→ Dict[str, Dict[str, Any]])

Transform annotation creation.

make_design_node(→ ragraph.node.Node)

Design spec node creation.

_make_design_annotations(→ Dict[str, Dict[str, any]])

Design spec annotation creation.

_make_subclause_annotations(→ List[Dict[str, Any]])

Subclause spec annotation creation.

_make_design_rule_annotation(→ List[Dict[str, Any]])

Design rule spec annotation creation.

make_behavior_node(→ ragraph.node.Node)

Behavior spec node creation.

_make_behavior_annotations(→ Dict[str, Dict[str, Any]])

Behavior spec annotation creation.

_make_case_annotations(→ Dict[str, Any])

Case spec annotation creation.

make_relation_node(→ ragraph.node.Node)

Relation spec node creation.

_get_arg_inst_names(→ List[str])

Converting list of InstanceArgument objects into a list of instantiated variable names.

_make_relation_annotations(→ Dict[str, Dict[str, Any]])

Relation spec annotation creation.

_make_bound_annotation(→ Dict[str, str])

Bound annotation creation

post_process_comments(→ None)

Post-processing comments attached to nodes.

Attributes#

comparison_dict

aux_dict

TAG_COMMENT_PAT

class raesl.compile.instantiating.node_building.NodeStore#

Node storage with multiple catagories for quicker access to specific subsets.

categories = ['nodes', 'types', 'components', 'variables', 'needs', 'goals', 'transforms', 'designs',...#
clear()#

Clear all node categories.

add(node: ragraph.node.Node, *args)#

Add node to self.nodes and any other specified categories in args.

class raesl.compile.instantiating.node_building.NodeFactory(diag_store: raesl.compile.diagnostics.DiagnosticStore, spec: raesl.compile.ast.specification.Specification | None = None)#

Node factory. Creates Node objects from a Specification.

_add(node: ragraph.node.Node | None, *args)#

Proxy for NodeStore.add.

make_nodes(spec: raesl.compile.ast.specification.Specification | None = None) Dict[str, ragraph.node.Node]#

Instantiate AST and create Node objects accordingly.

_instantiate_component(comp_def: raesl.compile.ast.components.ComponentDefinition, inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode], inst_name: str)#

Instantiate a component definition.

Arguments

comp_def: Component definition to instantiate. inst_map: Mapping of parameter VarNodes of the component definition

to InstNodes of the parent. Is not used by the parent afterwards.

inst_name: Dotted name of the component instance.

raesl.compile.instantiating.node_building.make_variable_instmap(var: raesl.compile.ast.components.VarParam, varname: List[str], node: raesl.compile.ast.nodes.VarNode) Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]#

Construct instance nodes for the provided variable.

Parameters:
  • var – Variable represented by the node.

  • varname – Collected prefixes of the dotted name so far.

  • node – Node to associate with one or more inst nodes.

Returns:

Map of the elementary variable nodes to their associated instance nodes.

raesl.compile.instantiating.node_building.make_parameter_instmap(param: raesl.compile.ast.components.VarParam, param_node: raesl.compile.ast.nodes.VarNode, arg_node: raesl.compile.ast.nodes.VarNode, parent_inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]#

Construct an inst node map for a parameter of a child component instance.

Parameters:
  • param – Parameter definition in the child component definition.

  • param_node – VarNode within the parameter in the child component definition. Note these are like variables in the child.

  • arg_node – Node in the parent that must match with param_node. These nodes exist in the parent component, and may contain part of a variable group.

  • parent_inst_map – Variable instance map of the parent. As component instantiation is recursive, this may also include nodes from the grand-parent or higher. Should not be modified.

Returns:

Instance node map for a parameter.

raesl.compile.instantiating.node_building.make_type_node(tdef: raesl.compile.ast.types.TypeDef) ragraph.node.Node#

Node creation for a type definition.

Parameters:

tdef – Type definition for which a node most be created.

Returns:

Node of kind variabel_type

raesl.compile.instantiating.node_building._make_type_annotations(tdef: raesl.compile.ast.types.TypeDef) Dict[str, Dict[str, Any]]#

Creating dictionary to annotate variable_type nodes.

Parameters:

tdef – The type definition for which an annotation dictionary most be created.

Returns:

See YAML output spec /components/schemas/VariableTypeAnnotation

raesl.compile.instantiating.node_building.make_variable_node(v: raesl.compile.instantiating.graph_data.InstNode, type_inst_map: Dict[raesl.compile.ast.types.ElementaryType, raesl.compile.ast.types.TypeDef]) ragraph.node.Node#

Node creation for a variable.

Parameters:

v – The variable for which a nodes must be created.

Returns:

Node of kind “variable”.

raesl.compile.instantiating.node_building._make_variable_annotations(v: raesl.compile.instantiating.graph_data.InstNode, type_inst_map: Dict[raesl.compile.ast.types.ElementaryType, raesl.compile.ast.types.TypeDef], comments: List[str] | None = []) Dict[str, Dict[str, Any]]#

Creating dictionary for variable annotations.

Parameters:
  • v – The variable for which the annotation dict must be created.

  • comments – List of comments attached to the nodes.

Returns:

See YAML output spec /components/schemas/VariableAnnotation

raesl.compile.instantiating.node_building.make_component_node(c: raesl.compile.ast.components.ComponentInstance, inst_name: str, params: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) ragraph.node.Node#

Node creation for a component.

Parameters:
  • c – The component for which a node is created.

  • name – The instantiation name of the node.

  • params – List of parameters of the component.

Returns:

Node of kind “component”

raesl.compile.instantiating.node_building._make_component_annotations(c: raesl.compile.ast.components.ComponentInstance, params: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) Dict[str, Dict[str, Any]]#

Component annotation creation.

Parameters:
  • c – The component for which the annotations must be created.

  • params – List of parameters of the component.

Returns:

See YAML output spec /components/schemas/ComponentAnnotation

raesl.compile.instantiating.node_building.make_need_node(n: raesl.compile.ast.components.Need, inst_name: str) ragraph.node.Node#

Node creation for a component.

Parameters:
  • n – The need for which a node must be created.

  • name – The instation name of the need.

  • inst_prefix – Instantiation prefix

Returns:

Node of kind “need”

raesl.compile.instantiating.node_building._make_need_annotations(n: raesl.compile.ast.components.Need, inst_prefix: str) Dict[str, Dict[str, Any]]#

Need annotation creation.

Parameters:
  • n – The need for which the annotations dict must be created.

  • inst_prefix – The instantiation prefix.

Returns:

See YAML output spec /components/schemas/ComponentAnnotation.

raesl.compile.instantiating.node_building.make_goal_node(g: raesl.compile.ast.components.Goal, inst_name: str, inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) ragraph.node.Node#

Goal node creation.

Parameters:
  • g – The goal for which a node must be created.

  • inst_name – The instantiation name of the component.

  • inst_map – Dictionary containing the instantiated variables.

Returns:

Node of kind “function”.

raesl.compile.instantiating.node_building._make_goal_annotations(g: raesl.compile.ast.components.Goal, inst_name: str, inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) Dict[str, Dict[str, Any]]#

Goal annotation creation.

Parameters:
  • g – The goal for which a node must be created.

  • inst_name – The instantiation name of the component.

  • inst_map – Dictionary containing the instantiated variables.

Returns:

See YAML output spec /components/schemas/FunctionSpecAnnotation.

raesl.compile.instantiating.node_building.make_transform_node(t: raesl.compile.ast.components.Transformation, inst_name: str, inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) ragraph.node.Node#

Transformation node creation.

Parameters:
  • t – The transformation for which a node must be created.

  • inst_name – The instantiation name of the component.

  • inst_map – Dictionary containing the instantiated variables.

Returns:

Node of kind “function_spec”.

raesl.compile.instantiating.node_building._unfold_compound_var(v: raesl.compile.ast.nodes.CompoundVarNode) List[raesl.compile.ast.nodes.ElementaryVarNode]#

Unfolding CompoundVarNode into a list of ElementartyVarNode

raesl.compile.instantiating.node_building._get_variable_inst_names(inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode], flows: List[raesl.compile.ast.components.Flow]) List[str]#

Converting list of Flow objects into a list of instantiated variable names.

raesl.compile.instantiating.node_building._make_transform_annotations(t: raesl.compile.ast.components.Transformation, inst_name: str, inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) Dict[str, Dict[str, Any]]#

Transform annotation creation.

Parameters:
  • t – The transformation for which a node must be created.

  • inst_name – The instantiation name of the component.

  • inst_map – Dictionary containing the instantiated variables.

Returns:

See YAML output spec /components/schemas/FunctionSpecAnnotation.

raesl.compile.instantiating.node_building.make_design_node(d: raesl.compile.ast.components.Design, inst_name: str, inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) ragraph.node.Node#

Design spec node creation.

Parameters:
  • d – The design specification for which a node must be created.

  • inst_name – The instantiation name of the component.

  • inst_map – Dictionary containing the instantiated variables.

Returns:

Node of kind “design_spec”.

raesl.compile.instantiating.node_building._make_design_annotations(d: raesl.compile.ast.components.Design, inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) Dict[str, Dict[str, any]]#

Design spec annotation creation.

Parameters:
  • d – The design spec for which a node must be created.

  • inst_map – Dictionary containing the instantiated variables.

Returns:

See YAML output spec /components/schemas/DesignSpecAnotation.

raesl.compile.instantiating.node_building._make_subclause_annotations(e: raesl.compile.ast.components.Goal | raesl.compile.ast.components.Transformation | raesl.compile.ast.components.Design, inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) List[Dict[str, Any]]#

Subclause spec annotation creation.

Parameters:
  • e – The relation for which annotations must be created.

  • inst_map – Dictionary containing the instantiated variables.

Returns:

List of YAML output spec /components/schemas/SubclauseSpecAnnotation.

raesl.compile.instantiating.node_building.comparison_dict#
raesl.compile.instantiating.node_building.aux_dict#
raesl.compile.instantiating.node_building._make_design_rule_annotation(expr: raesl.compile.ast.exprs.RelationComparison | raesl.compile.ast.exprs.Disjunction | raesl.compile.ast.exprs.ObjectiveComparison, inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) List[Dict[str, Any]]#

Design rule spec annotation creation.

Parameters:
  • expr – The the expression for which the annotations must be created.

  • inst_map – Dictionary containing the instantiated variables.

Returns:

See YAML output spec /components/schemas/DesignRuleSpecArray.

raesl.compile.instantiating.node_building.make_behavior_node(b: raesl.compile.ast.components.BehaviorFunction, inst_name: str, inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) ragraph.node.Node#

Behavior spec node creation.

Parameters:
  • d – The behavior specification for which a node must be created.

  • inst_name – The instantiation name of the component.

  • inst_map – Dictionary containing the instantiated variables.

Returns:

Node of kind “behavior_spec”.

raesl.compile.instantiating.node_building._make_behavior_annotations(b: raesl.compile.ast.components.BehaviorFunction, inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) Dict[str, Dict[str, Any]]#

Behavior spec annotation creation.

Parameters:
  • h – The behavior spec for which the annotations must be created.

  • inst_map – Dictionary containing the instantiated variables.

Returns:

See YAML output spec /components/schemas/BehaviorSpecAnnotation.

raesl.compile.instantiating.node_building._make_case_annotations(c: raesl.compile.ast.components.BehaviorFunction, inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) Dict[str, Any]#

Case spec annotation creation.

Parameters:
  • r – The behavior specication for which the case annotations must be created.

  • inst_map – Dictionary containing the instantiated variables.

Returns:

See YAML output spec /components/schemas/CaseSpec.

raesl.compile.instantiating.node_building.make_relation_node(r: raesl.compile.ast.components.RelationInstance, inst_name: str, inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) ragraph.node.Node#

Relation spec node creation.

Parameters:
  • d – The relation specification for which a node must be created.

  • inst_name – The instantiation name of the component.

  • inst_map – Dictionary containing the instantiated variables.

Returns:

Node of kind “relation_spec”.

raesl.compile.instantiating.node_building._get_arg_inst_names(inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode], args: List[raesl.compile.ast.components.InstanceArgument]) List[str]#

Converting list of InstanceArgument objects into a list of instantiated variable names.

raesl.compile.instantiating.node_building._make_relation_annotations(r: raesl.compile.ast.components.RelationInstance, inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) Dict[str, Dict[str, Any]]#

Relation spec annotation creation.

Parameters:
  • r – The relation for which a node must be created.

  • inst_map – Dictionary containing the instantiated variables.

Returns:

See YAML output spec /components/schemas/RelationSpecAnnotation.

raesl.compile.instantiating.node_building._make_bound_annotation(varval: raesl.compile.ast.exprs.Value | raesl.compile.ast.exprs.VariableValue, inst_map: Dict[raesl.compile.ast.nodes.ElementaryVarNode, raesl.compile.instantiating.graph_data.InstNode]) Dict[str, str]#

Bound annotation creation

Parameters:
  • varval – The value or variable that denotes the bound.

  • inst_map – Dictionary containing the instantiated variables.

Returns:

See YAML output spec /components/schemas/Bound.

raesl.compile.instantiating.node_building.TAG_COMMENT_PAT#
raesl.compile.instantiating.node_building.post_process_comments(nodes: List[ragraph.node.Node]) None#

Post-processing comments attached to nodes.

Parameters:

nodes – List of nodes for which the comments must be post-processed.

Note

This is a simple implementation to process documentation tags as described in LEP0008.