From 2b407dc49ce9d2e75b41f0cccccf0599f650ef84 Mon Sep 17 00:00:00 2001 From: Pierre-Marie de Rodat Date: Tue, 16 Apr 2019 14:44:16 +0200 Subject: [PATCH] struct_types_ada.mako: refactor prototype for public converter TN: S401-014 --- langkit/templates/struct_types_ada.mako | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/langkit/templates/struct_types_ada.mako b/langkit/templates/struct_types_ada.mako index 406f9e179..dc4437bc6 100644 --- a/langkit/templates/struct_types_ada.mako +++ b/langkit/templates/struct_types_ada.mako @@ -5,21 +5,24 @@ <%def name="create_prototype(cls)"> function Create_${cls.api_name} (${'; '.join('{} : {}{}'.format( f.name, - f.type.api_name, - "'Class" if f.type.is_entity_type or f.type.is_ast_node else '' + f.public_type.api_name, + "'Class" if f.public_type.is_entity_type else '' ) for f in cls.get_fields())}) return ${cls.api_name} +<%def name="accessor_prototype(cls, f)"> + function ${f.name} + (Self : ${cls.api_name}) + return ${f.public_type.api_name}${( + "'Class" if f.public_type.is_entity_type else '')} + + <%def name="public_api_decl(cls)"> type ${cls.api_name} is private; ${ada_doc(cls, 3)} % for f in cls.get_fields(): - function ${f.name} - (Self : ${cls.api_name}) - return ${f.type.api_name}${("'Class" - if f.type.is_entity_type or - f.type.is_ast_node else '')}; + ${accessor_prototype(cls, f)}; ${ada_doc(f, 6)} % endfor @@ -68,12 +71,7 @@ <%def name="public_api_body(cls)"> % for f in cls.get_fields(): - function ${f.name} - (Self : ${cls.api_name}) - return ${f.type.api_name}${("'Class" - if f.type.is_entity_type or - f.type.is_ast_node else '')} - is + ${accessor_prototype(cls, f)} is Record_Ref : constant Boxed_${cls.api_name}.Element_Access := Internal_Access (Self); begin