Skip to content

Commit

Permalink
#12 Fix class sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
kwabenantim committed Sep 22, 2024
1 parent fdc44a5 commit 9d5d073
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cppwg/input/class_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def update_from_ns(self, source_ns: "namespace_t") -> None: # noqa: F821

# If class has default args, try to compress the template signature
logger.warning(
f"Could not find declaration for class {class_name}: trying for a partial match."
f"Could not find declaration for class {class_name}: trying a partial match."
)

# Try to find the class without default template args
Expand Down
12 changes: 6 additions & 6 deletions cppwg/input/module_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def sort_classes(self) -> None:

for j in range(i + 1, n):
cls_j = self.class_info_collection[j]
i_requires_j = cls_i.requires(cls_j)
j_requires_i = cls_j.requires(cls_i)
if cls_i.is_child_of(cls_j) or (i_requires_j and not j_requires_i):
i_req_j = cls_i.requires(cls_j)
j_req_i = cls_j.requires(cls_i)
if cls_i.is_child_of(cls_j) or (i_req_j and not j_req_i):
# Position cls_i after all classes it depends on,
# ignoring forward declaration cycles
ii = j
elif cls_j.is_child_of(cls_i) or (j_requires_i and not i_requires_j):
elif cls_j.is_child_of(cls_i) or (j_req_i and not i_req_j):
# Collect positions of cls_i's dependents
j_pos.append(j)

Expand All @@ -115,9 +115,9 @@ def sort_classes(self) -> None:
self.class_info_collection.insert(ii, cls_i)

# Move dependents into positions after ii
for j, idx in enumerate(j_pos):
for idx, j in enumerate(j_pos):
if j > ii:
break # Rest of dependents already positioned after ii
break # Rest of dependents are already positioned after ii
cls_j = self.class_info_collection.pop(j - 1 - idx)
self.class_info_collection.insert(ii + idx, cls_j)

Expand Down

0 comments on commit 9d5d073

Please sign in to comment.