Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit bf54383

Browse files
committed
[REALIGN-FEATURE]: edge_ref filter by class instead of instance
1 parent a1f032b commit bf54383

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

jaclang/compiler/passes/main/pyast_gen_pass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3443,7 +3443,7 @@ def translate_edge_op_ref(
34433443
keywords=[
34443444
self.sync(
34453445
ast3.keyword(
3446-
arg="target_obj",
3446+
arg="target_cls",
34473447
value=(
34483448
targ if targ else self.sync(ast3.Constant(value=None))
34493449
),

jaclang/core/architype.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
ClassVar,
1414
Iterable,
1515
Optional,
16+
Type,
1617
TypeVar,
1718
cast,
1819
)
@@ -376,7 +377,7 @@ def get_edges(
376377
self,
377378
dir: EdgeDir,
378379
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
379-
target_obj: Optional[list[NodeArchitype]],
380+
target_cls: Optional[list[Type[NodeArchitype]]],
380381
) -> list[EdgeArchitype]:
381382
"""Get edges connected to this node."""
382383
ret_edges: list[EdgeArchitype] = []
@@ -394,15 +395,15 @@ def get_edges(
394395
dir in [EdgeDir.OUT, EdgeDir.ANY]
395396
and self == source
396397
and trg_arch
397-
and (not target_obj or trg_arch in target_obj)
398+
and (not target_cls or trg_arch.__class__ in target_cls)
398399
and source.has_read_access(target)
399400
):
400401
ret_edges.append(architype)
401402
if (
402403
dir in [EdgeDir.IN, EdgeDir.ANY]
403404
and self == target
404405
and src_arch
405-
and (not target_obj or src_arch in target_obj)
406+
and (not target_cls or src_arch.__class__ in target_cls)
406407
and target.has_read_access(source)
407408
):
408409
ret_edges.append(architype)
@@ -412,7 +413,7 @@ def edges_to_nodes(
412413
self,
413414
dir: EdgeDir,
414415
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
415-
target_obj: Optional[list[NodeArchitype]],
416+
target_cls: Optional[list[Type[NodeArchitype]]],
416417
) -> list[NodeArchitype]:
417418
"""Get set of nodes connected to this node."""
418419
ret_edges: list[NodeArchitype] = []
@@ -430,15 +431,15 @@ def edges_to_nodes(
430431
dir in [EdgeDir.OUT, EdgeDir.ANY]
431432
and self == source
432433
and trg_arch
433-
and (not target_obj or trg_arch in target_obj)
434+
and (not target_cls or trg_arch.__class__ in target_cls)
434435
and source.has_read_access(target)
435436
):
436437
ret_edges.append(trg_arch)
437438
if (
438439
dir in [EdgeDir.IN, EdgeDir.ANY]
439440
and self == target
440441
and src_arch
441-
and (not target_obj or src_arch in target_obj)
442+
and (not target_cls or src_arch.__class__ in target_cls)
442443
and target.has_read_access(source)
443444
):
444445
ret_edges.append(src_arch)

jaclang/plugin/default.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -365,32 +365,30 @@ def disengage(walker: WalkerArchitype) -> bool: # noqa: ANN401
365365
@hookimpl
366366
def edge_ref(
367367
node_obj: NodeArchitype | list[NodeArchitype],
368-
target_obj: Optional[NodeArchitype | list[NodeArchitype]],
368+
target_cls: Optional[Type[NodeArchitype] | list[Type[NodeArchitype]]],
369369
dir: EdgeDir,
370370
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
371371
edges_only: bool,
372372
) -> list[NodeArchitype] | list[EdgeArchitype]:
373373
"""Jac's apply_dir stmt feature."""
374374
if isinstance(node_obj, NodeArchitype):
375375
node_obj = [node_obj]
376-
targ_obj_set: Optional[list[NodeArchitype]] = (
377-
[target_obj]
378-
if isinstance(target_obj, NodeArchitype)
379-
else target_obj if target_obj else None
376+
targ_cls_set: Optional[list[Type[NodeArchitype]]] = (
377+
[target_cls] if isinstance(target_cls, type) else target_cls
380378
)
381379
if edges_only:
382380
connected_edges: list[EdgeArchitype] = []
383381
for node in node_obj:
384382
connected_edges += node.__jac__.get_edges(
385-
dir, filter_func, target_obj=targ_obj_set
383+
dir, filter_func, target_cls=targ_cls_set
386384
)
387385
return list(set(connected_edges))
388386
else:
389387
connected_nodes: list[NodeArchitype] = []
390388
for node in node_obj:
391389
connected_nodes.extend(
392390
node.__jac__.edges_to_nodes(
393-
dir, filter_func, target_obj=targ_obj_set
391+
dir, filter_func, target_cls=targ_cls_set
394392
)
395393
)
396394
return list(set(connected_nodes))

jaclang/plugin/feature.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,15 @@ def disengage(walker: WalkerArchitype) -> bool: # noqa: ANN401
188188
@staticmethod
189189
def edge_ref(
190190
node_obj: NodeArchitype | list[NodeArchitype],
191-
target_obj: Optional[NodeArchitype | list[NodeArchitype]],
191+
target_cls: Optional[Type[NodeArchitype] | list[Type[NodeArchitype]]],
192192
dir: EdgeDir,
193193
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
194194
edges_only: bool = False,
195195
) -> list[NodeArchitype] | list[EdgeArchitype]:
196196
"""Jac's apply_dir stmt feature."""
197197
return pm.hook.edge_ref(
198198
node_obj=node_obj,
199-
target_obj=target_obj,
199+
target_cls=target_cls,
200200
dir=dir,
201201
filter_func=filter_func,
202202
edges_only=edges_only,

jaclang/plugin/spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def disengage(walker: WalkerArchitype) -> bool: # noqa: ANN401
173173
@hookspec(firstresult=True)
174174
def edge_ref(
175175
node_obj: NodeArchitype | list[NodeArchitype],
176-
target_obj: Optional[NodeArchitype | list[NodeArchitype]],
176+
target_cls: Optional[Type[NodeArchitype] | list[Type[NodeArchitype]]],
177177
dir: EdgeDir,
178178
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
179179
edges_only: bool,

jaclang/tests/fixtures/disconn.jac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ with entry{
2020
y++>z;
2121
apple: int;
2222
# print(x -:aaa:-> );
23-
print([x-->y-->z]);
23+
print([x-->b-->c]);
2424
print([x -->]);
2525
print(x del--> y);
2626
print([x -->]);
2727
print([i.__class__.__name__ for i in (x ++> y)]);
28-
print([i.__class__.__name__ for i in (:e:[x[0] --> y])]);
28+
print([i.__class__.__name__ for i in (:e:[x[0] --> b])]);
2929
}

0 commit comments

Comments
 (0)