def record_typer(comp_typer): """ :param types.Typer[lal.ComponentDecl | lal.DiscriminantSpec] comp_typer: A typer for components of products. :return: A typer for record types. :rtype: types.Typer[lal.AdaNode] """ @Transformer.as_transformer def get_elements(hint): """ :param lal.AdaNode hint: the lal type. :return: The components of the record type, if relevant. :rtype: list[lal.AdaNode] """ if hint.is_a(lal.TypeDecl): if hint.f_type_def.is_a(lal.RecordTypeDef): return [field.decl for field in record_fields(hint)] to_product = Transformer.as_transformer(types.Product) # Get the elements -> type them all -> generate the product type. return get_elements >> comp_typer.lifted() >> to_product
@Transformer.as_transformer def _eval_as_int(x): """ Given an arbitrary Ada node, tries to evaluate it to an integer. :param lal.AdaNode x: The node to evaluate :rtype: int | None """ try: return x.p_eval_as_int except (lal.PropertyError, lal.NativeException, OSError): return None _eval_as_real = ( Transformer.as_transformer(eval_as_real).catch(NotImplementedError) ) @types.delegating_typer def int_range_typer(): """ :return: A typer for int ranges. :rtype: types.Typer[lal.AdaNode] """ @Transformer.as_transformer def get_operands(hint): if hint.is_a(lal.TypeDecl): if hint.f_type_def.is_a(lal.SignedIntTypeDef): rng = hint.f_type_def.f_range.f_range