parse_yaml.py

class parse_yaml.FieldEntry(field_name: str, field_props: dict | None, root_struct: str, allow_prohibited=False, recursion_level=0)

A class to store a particle field entry from the yaml input files.

__init__(field_name: str, field_props: dict | None, root_struct: str, allow_prohibited=False, recursion_level=0)
Parameters:
  • field_name (str) – name of the particle field to be extracted.

  • field_props (dict or None) – a dict of the read-in yaml file specifications for this field. None if none were found.

  • root_struct (str) – name of “root” or “top level” struct this field is assigned to

  • allow_prohibited (bool) – Allow the creation of prohibited/reserved field names.

  • recursion_level (int) – Current recursion level. Used when handling structs defined within the parent struct and unions as an emergency exit in case something goes wrong. Also used to determine the indentation level of the contents of the sub-struct/union contents.

_extract_field_data()

Extracts the field data from the field_props dict.

_get_field_dict(parent_struct: str | None = None, indent_level: int = 0, id_checks: bool = True, explicit_var_accessors: bool = False, global_var_accessors: bool = False, part_struct_accessors: bool = False, root_struct_override: str | None = None, root_struct_special_name: str | None = None) → dict

Generate a dict with this field’s properties for the jinja templates.

Parameters:
  • parent_struct (None or str) – If not None, name of the struct this field is internal to.

  • indent_level (int) – Increment the indent level of the declaration. Each indent_level indents the line by 2 whitespaces.

  • id_checks (bool) – If True, add debugging checks whether the struct’s accessor IDs align

  • explicit_var_accessors (bool) – if True, generate getters/setters which use explicitly passed pointer as an argument

  • global_var_accessors (bool) – if True, generate getters/setters which use global variable pointer

  • part_struct_accessors (bool) – if True, generate getters/setters which use part structs

  • root_struct_override (None or str) – specify which root struct to use. This is needed in cases like for src/hydro_part.h, which doesn’t host the struct timestep_limiter itself, but needs to know which struct to use within the API. If not None, this implies to use the specialised API template (“use_struct”), not the default particle one.

  • root_struct_special_name (None or str) – specialised root struct name, to be used for APIs in files outside of src/hydro/<flavour>/. If not None, this implies to use the specialised API template, not the default particle one.

Returns:

d – dict containing field properties prepared for use in jinja templates

Return type:

dict

generate_API(parent_struct: str | None = None, swift_header: bool = False, explicit_var_accessors: bool = False, global_var_accessors: bool = False, part_struct_accessors: bool = False, root_struct_override: str | None = None, root_struct_special_name: str | None = None, id_checks: bool = True) → str

Generate the getters and setters C code.

Note: For SWIFTGPUPACKSIM, we want to allow the simultaneous co-existence of all 3 accessor variants, so all of explicit_var_accessors, global_var_accessors, and part_struct_accessors may be True simultaneously.

Parameters:
  • parent_struct (str or None) – If not None, this denoted that field is a sub-field contained within the given parent struct.

  • swift_header (bool) – If True, generate API for swift, not swiftgpupacksim

  • explicit_var_accessors (bool) – if True, also generate getters/setters which use explicitly passed pointer as an argument

  • global_var_accessors (bool) – if True, generate getters/setters which use global variable pointer

  • part_struct_accessors (bool) – if True, generate getters/setters which use part structs

  • root_struct_override (None or str) – specify which root struct to use. This is needed in cases like for src/hydro_part.h, which doesn’t host the struct timestep_limiter itself, but needs to know which struct to use within the API. If not None, this implies to use the specialised API template (“use_struct”), not the default particle one.

  • root_struct_special_name (None or str) – specialised root struct name, to be used for APIs in files outside of src/hydro/<flavour>/, in particular API which uses a struct as the argument and accesses members of that struct. If not None, this implies to use the specialised API template (“nonpart”), not the default particle one.

  • id_checks (bool) – If True, add debugging checks whether the struct’s accessor IDs align

Returns:

api – generated API C-code as a string

Return type:

str

generate_declaration(indent_level: int = 1) → str

Generate the field declaration

Parameters:

indent_level (int) – Increment the indent level of the declaration. Each indent_level indents the line by 2 whitespaces.

Returns:

decl – string containing c-code of member declarations

Return type:

str

jinja_env = <jinja2.environment.Environment object>
prohibited_name() → bool

Check whether a field name is prohibited/reserved.