mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-12-22 20:35:44 +01:00
adapt the generator to populate string attributes
This commit is contained in:
parent
535d7ed019
commit
a39784dc51
@ -63,6 +63,6 @@ for fname in files_todo['dset_str']:
|
|||||||
|
|
||||||
# populate group-related functions with mixed (iterative+recursive) scheme [text backend]
|
# populate group-related functions with mixed (iterative+recursive) scheme [text backend]
|
||||||
for fname in files_todo['group']:
|
for fname in files_todo['group']:
|
||||||
special_populate_text_group(fname, template_paths, group_dict, detailed_dsets, detailed_nums)
|
special_populate_text_group(fname, template_paths, group_dict, detailed_dsets, detailed_nums, detailed_strs)
|
||||||
|
|
||||||
# --------------------------------------------------------------------------- #
|
# --------------------------------------------------------------------------- #
|
||||||
|
@ -261,7 +261,7 @@ def check_triggers (input_line: str, triggers: list) -> int:
|
|||||||
return out_id
|
return out_id
|
||||||
|
|
||||||
|
|
||||||
def special_populate_text_group(fname: str, paths: dict, group_dict: dict, detailed_dset: dict, detailed_numbers: dict) -> None:
|
def special_populate_text_group(fname: str, paths: dict, group_dict: dict, detailed_dset: dict, detailed_numbers: dict, detailed_strings: dict) -> None:
|
||||||
"""
|
"""
|
||||||
Special population for group-related functions in the TEXT back end.
|
Special population for group-related functions in the TEXT back end.
|
||||||
|
|
||||||
@ -271,6 +271,7 @@ def special_populate_text_group(fname: str, paths: dict, group_dict: dict, detai
|
|||||||
group_dict (dict) : dictionary of groups
|
group_dict (dict) : dictionary of groups
|
||||||
detailed_dset (dict) : dictionary of datasets with substitution details
|
detailed_dset (dict) : dictionary of datasets with substitution details
|
||||||
detailed_numbers (dict) : dictionary of numbers with substitution details
|
detailed_numbers (dict) : dictionary of numbers with substitution details
|
||||||
|
detailed_strings (dict) : dictionary of string attributes with substitution details
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
None
|
None
|
||||||
@ -279,7 +280,7 @@ def special_populate_text_group(fname: str, paths: dict, group_dict: dict, detai
|
|||||||
templ_path = get_template_path(fname, paths)
|
templ_path = get_template_path(fname, paths)
|
||||||
|
|
||||||
triggers = ['group_dset_dtype', 'group_dset_std_dtype_out', 'group_dset_std_dtype_in',
|
triggers = ['group_dset_dtype', 'group_dset_std_dtype_out', 'group_dset_std_dtype_in',
|
||||||
'group_dset', 'group_num', 'group']
|
'group_dset', 'group_num', 'group_str', 'group']
|
||||||
|
|
||||||
for group in group_dict.keys():
|
for group in group_dict.keys():
|
||||||
|
|
||||||
@ -290,13 +291,15 @@ def special_populate_text_group(fname: str, paths: dict, group_dict: dict, detai
|
|||||||
subloop_num = False
|
subloop_num = False
|
||||||
loop_body = ''
|
loop_body = ''
|
||||||
dset_allocated = []
|
dset_allocated = []
|
||||||
|
str_allocated = []
|
||||||
|
|
||||||
for line in f_in :
|
for line in f_in :
|
||||||
|
|
||||||
if 'START REPEAT GROUP_DSET' in line:
|
if 'START REPEAT GROUP_DSET' in line:
|
||||||
subloop_dset = True
|
subloop_dset = True
|
||||||
continue
|
continue
|
||||||
elif 'START REPEAT GROUP_NUM' in line:
|
# this can be merged in one later using something like START REPEAT GROUP_ATTR in line
|
||||||
|
elif 'START REPEAT GROUP_NUM' in line or 'START REPEAT GROUP_ATTR_STR' in line:
|
||||||
subloop_num = True
|
subloop_num = True
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -345,6 +348,33 @@ def special_populate_text_group(fname: str, paths: dict, group_dict: dict, detai
|
|||||||
loop_body = ''
|
loop_body = ''
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
elif 'END REPEAT GROUP_ATTR_STR' in line:
|
||||||
|
for str in detailed_strings.keys():
|
||||||
|
if group != detailed_strings[str]['group']:
|
||||||
|
continue
|
||||||
|
|
||||||
|
str_allocated.append(str)
|
||||||
|
|
||||||
|
if 'FREE($group$->$group_str$)' in loop_body:
|
||||||
|
tmp_string = ''
|
||||||
|
for str_alloc in str_allocated:
|
||||||
|
tmp_string += f'FREE({group}->{str_alloc});\n '
|
||||||
|
|
||||||
|
tmp_body = loop_body.replace('FREE($group$->$group_str$);', tmp_string)
|
||||||
|
|
||||||
|
populated_body = recursive_replace_line(tmp_body, triggers, detailed_strings[str])
|
||||||
|
f_out.write(populated_body)
|
||||||
|
else:
|
||||||
|
save_body = loop_body
|
||||||
|
populated_body = recursive_replace_line(save_body, triggers, detailed_strings[str])
|
||||||
|
f_out.write(populated_body)
|
||||||
|
|
||||||
|
subloop_num = False
|
||||||
|
loop_body = ''
|
||||||
|
str_allocated = []
|
||||||
|
|
||||||
|
continue
|
||||||
|
|
||||||
if not subloop_num and not subloop_dset:
|
if not subloop_num and not subloop_dset:
|
||||||
# NORMAL CASE WITHOUT SUBLOOPS
|
# NORMAL CASE WITHOUT SUBLOOPS
|
||||||
if '$group_dset' in line:
|
if '$group_dset' in line:
|
||||||
@ -353,6 +383,12 @@ def special_populate_text_group(fname: str, paths: dict, group_dict: dict, detai
|
|||||||
continue
|
continue
|
||||||
populated_line = recursive_replace_line(line, triggers, detailed_dset[dset])
|
populated_line = recursive_replace_line(line, triggers, detailed_dset[dset])
|
||||||
f_out.write(populated_line)
|
f_out.write(populated_line)
|
||||||
|
elif '$group_str' in line:
|
||||||
|
for str in detailed_strings.keys():
|
||||||
|
if group != detailed_strings[str]['group']:
|
||||||
|
continue
|
||||||
|
populated_line = recursive_replace_line(line, triggers, detailed_strings[str])
|
||||||
|
f_out.write(populated_line)
|
||||||
elif '$group_num$' in line:
|
elif '$group_num$' in line:
|
||||||
for dim in detailed_numbers.keys():
|
for dim in detailed_numbers.keys():
|
||||||
if group != detailed_numbers[dim]['group']:
|
if group != detailed_numbers[dim]['group']:
|
||||||
|
Loading…
Reference in New Issue
Block a user