Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/build/
/build-test/
/prefix/
/linux-build/
/CMakeUserPresets.json
2 changes: 2 additions & 0 deletions include/ifc/dom/node.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ namespace ifc::util {
std::string ref(const symbolic::Identity<NameIndex>& id);

std::set<NodeKey> referenced_nodes;
// Track indices currently being processed to detect cycles
std::set<TypeIndex> processing_types;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why mutable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mutable keyword was unnecessary since processing_types is only accessed through non-const methods. Removed in commit 376ccde.

private:
using NodeMap = std::map<NodeKey, Node>;
Expand Down
16 changes: 13 additions & 3 deletions src/ifc-dom/types.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,19 @@ namespace ifc::util {

std::string get_string_if_possible(Loader& ctx, TypeIndex index)
{
if (not null(index))
return ctx.reader.visit(index, TypeTranslator{ctx});
return "no-type";
if (null(index))
return "no-type";

// Check for cycles to prevent infinite recursion
if (ctx.processing_types.find(index) != ctx.processing_types.end()) {
return "..." + to_string(index); // Return a reference to break the cycle
}

// Track this index while processing
ctx.processing_types.insert(index);
auto result = ctx.reader.visit(index, TypeTranslator{ctx});
ctx.processing_types.erase(index);
return result;
}

// Load types as full blown nodes.
Expand Down