Skip to content

Commit b86f000

Browse files
pmderodatraph-amiard
authored andcommitted
Properties DSL: add support for N_Predicate equations
TN: SB20-024 For libadalang/langkit#618
1 parent 16679b4 commit b86f000

File tree

15 files changed

+542
-122
lines changed

15 files changed

+542
-122
lines changed

langkit/compile_context.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,11 @@ def __init__(self,
660660
List of path for file names to include in the generated library.
661661
"""
662662

663-
self.logic_converter_props: Set[PropertyDef] = set()
663+
self.logic_functor_props: Set[Tuple[PropertyDef, int]] = set()
664664
"""
665-
Set of properties used as converters in logic equations.
665+
Set of properties (and the corresponding arity for entity args) used as
666+
converters/combiners in logic equations. We generate functors for them,
667+
so that equations can refer to them.
666668
"""
667669

668670
self.default_unit_provider = default_unit_provider
@@ -968,9 +970,10 @@ def add_with_clause(self, from_pkg, source_kind, to_pkg, use_clause=False,
968970
(to_pkg, use_clause, is_private))
969971

970972
@property
971-
def sorted_logic_converters(self):
972-
return sorted(self.logic_converter_props,
973-
key=lambda x: x.name.camel)
973+
def sorted_logic_functors(self) -> List[Tuple[PropertyDef, int]]:
974+
return sorted(
975+
self.logic_functor_props, key=lambda x: x[0].name.camel
976+
)
974977

975978
def sorted_types(self, type_set):
976979
"""
@@ -995,17 +998,21 @@ def sorted_exception_types(self) -> List[GeneratedException]:
995998
return sorted(self.exception_types.values(),
996999
key=lambda e: e.doc_entity)
9971000

998-
def do_generate_logic_functors(self, convert_property=None):
1001+
def do_generate_logic_functors(self,
1002+
prop: Optional[PropertyDef],
1003+
arity: int) -> None:
9991004
"""
1000-
Generate a logic binder with the given conversion property.
1005+
Generate a logic binder with the given convert/combine property.
10011006
10021007
If you call this function several times for the same property, only one
1003-
binder will be generaed.
1008+
binder will be generated.
10041009
1005-
:param PropertyDef convert_property: The conversion property.
1010+
:param prop: The convert/combine property.
1011+
:param arity: Number of entity arguments this property takes ("Self"
1012+
included).
10061013
"""
1007-
if convert_property:
1008-
self.logic_converter_props.add(convert_property)
1014+
if prop:
1015+
self.logic_functor_props.add((prop, arity))
10091016

10101017
@staticmethod
10111018
def grammar_rule_api_name(rule):

langkit/dsl_unparse.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ def emit_expr(expr, **ctx):
658658
No, Cond, New, CollectionSingleton, Concat, EnumLiteral, EnvGet,
659659
ArrayLiteral, Arithmetic, PropertyError, CharacterLiteral, Predicate,
660660
StructUpdate, BigIntLiteral, RefCategories, Bind, Try, Block, Contains,
661-
PropertyDef, DynamicLexicalEnv, Super, Join, String
661+
PropertyDef, DynamicLexicalEnv, Super, Join, String, NPropagate
662662
)
663663

664664
def is_a(*names):
@@ -1224,6 +1224,12 @@ def handle_designated_env_macro():
12241224
"conv_prop={}".format(fqn(expr.conv_prop)) if expr.conv_prop else ""
12251225
])))
12261226

1227+
elif isinstance(expr, NPropagate):
1228+
return "%propagate({})".format(", ".join(keep([
1229+
ee(expr.dest_var),
1230+
fqn(expr.comb_prop),
1231+
] + [ee(v) for v in expr.arg_vars])))
1232+
12271233
elif isinstance(expr, DynamicLexicalEnv):
12281234
return "DynamicLexicalEnv({})".format(", ".join(keep([
12291235
fqn(expr.assocs_getter),

0 commit comments

Comments
 (0)