40 Instantiate a field in a type, given params map between the template parameter and argument,
41 and fields to instantiate
42 Note: nested type is not supported
44 if not isinstance(field, Tree):
46 if isinstance(field, Tree):
47 if is_tree_type(field,
'htype'):
48 if field.children[0]
in types:
49 raise NotImplementedError(
'Nested type support is WIP')
51 for x
in field.children:
53 new_children.append(params[x])
56 field.children = new_children
60 elif is_tree_type(field,
'hdeptype'):
62 type_name = field.children[0]
64 original_type = self.
aliases[type_name]
69 path_to_type = type_name.split(
'::')
70 assert len(path_to_type) == 2,
"Only two levels of dependent type is supported (e.g. FP::expo_t is supported but FP::X::expo_t is not)"
71 for component
in path_to_type[:-1]:
73 assert component
in params,
"{} not found when processing dependent type {}".format(component, type_name)
75 assert t.data ==
'htype',
"Dependent type {} should be an htype (e.g. in FP::expo_t, FP must be htype)".format(component)
76 tname, tparams = t.children[0], t.children[1:]
78 last_path = path_to_type[-1]
79 res = aliases[last_path]
84 assert field.data ==
'htypefield',
"Generated field should be of type hTypeField, got {}".format(field.data)
85 field.children = [self.
_instantiate(x, params, types)
if isinstance(x, Tree)
else x
for x
in field.children]
91 types is the global collected type
92 The type of hTypeField is searched in three scopes if including alias type
94 type parameter's scope,
98 instantiated_fields = deepcopy(self.
fields)
100 instantiated_fields = list(map(
lambda x: self.
_instantiate(x, param_maps, types), instantiated_fields))
102 res = [[f.children[0], f.children[1]]
for f
in instantiated_fields]