@@ -198,7 +198,6 @@ def construct_propagate(
198
198
# the support library and the other is generated), they have the
199
199
# same structure, so we cast the given one to the expected type.
200
200
assert len (arg_vars ) == 1
201
- constructor_name = "Solver.Create_N_Propagate"
202
201
var_array_expr = SavedExpr ("Logic_Vars" , arg_vars [0 ])
203
202
saved_exprs .append (var_array_expr )
204
203
var_array = LiteralExpr (
@@ -208,34 +207,44 @@ def construct_propagate(
208
207
var_length = LiteralExpr (
209
208
"{}.N" , None , [var_array_expr .result_var_expr ]
210
209
)
210
+ constructor_name = "Solver.Create_N_Propagate"
211
211
constructor_args = [
212
+ # "To" argument
212
213
dest_var ,
214
+ # "Comb" argument
213
215
cls .functor_expr (
214
216
f"Logic_Functor_{ prop .uid } " , prop , var_length
215
217
)
216
218
if prop else
217
219
"Solver_Ifc.No_Combiner" ,
220
+ # "Logic_Vars" argument
218
221
var_array ,
219
222
]
220
223
elif len (arg_vars ) == 1 :
221
224
constructor_name = "Solver.Create_Propagate"
222
225
constructor_args = [
223
- dest_var ,
226
+ # "From" argument
224
227
arg_vars [0 ],
228
+ # "To" argument
229
+ dest_var ,
230
+ # "Conv" argument
225
231
cls .functor_expr (f"Logic_Functor_{ prop .uid } " , prop )
226
232
if prop else
227
233
"Solver_Ifc.No_Converter" ,
228
234
]
229
235
else :
230
236
constructor_name = "Solver.Create_N_Propagate"
231
237
constructor_args = [
238
+ # "To" argument
232
239
dest_var ,
240
+ # "Comb" argument
233
241
cls .functor_expr (
234
242
f"Logic_Functor_{ prop .uid } " , prop ,
235
243
IntegerLiteralExpr (len (arg_vars ))
236
244
)
237
245
if prop else
238
246
"Solver_Ifc.No_Combiner" ,
247
+ # "Logic_Vars" argument
239
248
aggregate_expr (
240
249
type = None ,
241
250
assocs = [(str (i ), v ) for i , v in enumerate (arg_vars , 1 )],
@@ -314,12 +323,12 @@ class Bind(AbstractExpression):
314
323
Bind(A, B, conv_prop=T.TypeOfA.some_property)
315
324
"""
316
325
317
- def __init__ (self , from_expr , to_expr , conv_prop = None , logic_ctx = None ):
326
+ def __init__ (self , to_expr , from_expr , conv_prop = None , logic_ctx = None ):
318
327
"""
319
- :param AbstractExpression from_expr: An expression resolving to a
320
- logical variable that is the source of the bind.
321
328
:param AbstractExpression to_expr: An expression resolving to a
322
329
logical variable that is the destination of the bind.
330
+ :param AbstractExpression from_expr: An expression resolving to a
331
+ logical variable that is the source of the bind.
323
332
:param PropertyDef|None conv_prop: The property to apply on the
324
333
value of from_expr that will yield the value to give to to_expr.
325
334
For convenience, it can be a property on any subclass of the root
@@ -329,8 +338,8 @@ def __init__(self, from_expr, to_expr, conv_prop=None, logic_ctx=None):
329
338
LogicContext.
330
339
"""
331
340
super ().__init__ ()
332
- self .from_expr = from_expr
333
341
self .to_expr = to_expr
342
+ self .from_expr = from_expr
334
343
self .conv_prop = conv_prop
335
344
self .logic_ctx = logic_ctx
336
345
@@ -442,20 +451,20 @@ def _construct_logic_var(var_expr) -> ResolvedExpression:
442
451
"""
443
452
return ResetLogicVar (construct (var_expr , T .LogicVar ))
444
453
445
- def construct (self ):
454
+ def construct (self ) -> ResolvedExpression :
446
455
# Resolve the converter property, make sure it has an acceptable
447
456
# signature and generate a functor for it.
448
457
self .conv_prop = self ._resolve_property (
449
458
"Bind's conv_prop" , self .conv_prop , 1
450
459
)
451
460
452
- # Left operand must be a logic variable. Make sure the resulting
461
+ # The "to" operand must be a logic variable. Make sure the resulting
453
462
# equation will work on a clean logic variable.
454
- lhs = self ._construct_logic_var (self .from_expr )
463
+ to_expr = self ._construct_logic_var (self .to_expr )
455
464
456
- # Second one can be either a logic variable or an entity (or an AST
465
+ # The "from" one can be either a logic variable or an entity (or a bare
457
466
# node that is promoted to an entity).
458
- rhs = construct (self .to_expr )
467
+ from_expr = construct (self .from_expr )
459
468
460
469
logic_ctx = None
461
470
if self .logic_ctx :
@@ -465,45 +474,54 @@ def construct(self):
465
474
f"Expected LogicContext, got { logic_ctx .type .dsl_name } "
466
475
)
467
476
468
- if rhs .type .matches (T .LogicVar ):
477
+ if from_expr .type .matches (T .LogicVar ):
469
478
# The second operand is a logic variable: this is a Propagate or a
470
479
# Unify equation depending on whether we have a conversion
471
480
# property.
472
481
473
482
# For this operand too, make sure it will work on a clean logic
474
483
# variable.
475
- rhs = ResetLogicVar (rhs )
484
+ from_expr = ResetLogicVar (from_expr )
476
485
477
486
return (
478
487
PropagateExpr .construct_propagate (
479
- lhs , [rhs ], self .conv_prop , logic_ctx , abstract_expr = self
488
+ to_expr ,
489
+ [from_expr ],
490
+ self .conv_prop ,
491
+ logic_ctx ,
492
+ abstract_expr = self ,
480
493
)
481
494
if self .conv_prop else
482
- UnifyExpr (lhs , rhs , logic_ctx , abstract_expr = self )
495
+ UnifyExpr (to_expr , from_expr , logic_ctx , abstract_expr = self )
483
496
)
484
497
485
498
else :
486
499
# The second operand is a value: this is an Assign equation
487
500
488
- if rhs .type .matches (T .root_node ):
501
+ if from_expr .type .matches (T .root_node ):
489
502
from langkit .expressions import make_as_entity
490
- rhs = make_as_entity (rhs )
503
+ from_expr = make_as_entity (from_expr )
491
504
else :
492
505
check_source_language (
493
- rhs .type .matches (T .root_node .entity )
494
- or rhs .type .matches (T .LogicVar ),
506
+ from_expr .type .matches (T .root_node .entity )
507
+ or from_expr .type .matches (T .LogicVar ),
495
508
"Right operand must be either a logic variable or an"
496
- f" entity, got { rhs .type .dsl_name } "
509
+ f" entity, got { from_expr .type .dsl_name } "
497
510
)
498
511
499
512
# Because of Ada OOP typing rules, for code generation to work
500
- # properly, make sure the type of `rhs` is the root node entity.
501
- if rhs .type is not T .root_node .entity :
513
+ # properly, make sure the type of `from_expr` is the root node
514
+ # entity.
515
+ if from_expr .type is not T .root_node .entity :
502
516
from langkit .expressions import Cast
503
- rhs = Cast .Expr (rhs , T .root_node .entity )
517
+ from_expr = Cast .Expr (from_expr , T .root_node .entity )
504
518
505
519
return AssignExpr (
506
- lhs , rhs , self .conv_prop , logic_ctx , abstract_expr = self
520
+ to_expr ,
521
+ from_expr ,
522
+ self .conv_prop ,
523
+ logic_ctx ,
524
+ abstract_expr = self ,
507
525
)
508
526
509
527
0 commit comments