Urgent.News

What's breaking now, across hundreds of outlets.

World

War of the Worlds: C++ Namespaces vs Doxygen @addtogroup

Five days after we taught our parser to read kind="group" files from Doxygen's XML output (to save the "missing" free functions), our systematic parity check of the AST parser on a real corpus revealed wild architectural anomalies. Doxygen is famous for mixing the visual structure of documentation (how humans want to read it) with the real semantics of C++ code (how the code works). The…

Five days after our parser learned to read files with kind="group" tags from Doxygen's XML output, a systematic parity check of the AST parser on a real corpus revealed architectural anomalies. Doxygen is known for blending the visual structure of documentation with the actual semantics of C++ code. The @addtogroup tag exemplifies this. Our parser fell victim to this mixing on two fronts simultaneously.

First, phantom namespaces emerged due to global functions lacking namespaces. For instance, the cvFloor function, documented within the @addtogroup core_utils group, had no qualifiedname tag. Our parser attempted to determine C++ scope and used a fallback logic: taking the parent compound's name and attaching it to the function.

However, the parent compound was the virtual group core_utils, not a namespace. Consequently, our parser declared that a function named core_utils::cvFloor existed in the project, despite its nonexistence.

The second bug was even more bizarre. Entities, such as typedefs, inside C++ namespaces were also wrapped in @addtogroup tags. Doxygen correctly output the qualifiedname tag in XML for these entities. However, our top-level parser passed this information down to internal functions, which discarded the verified FQN and recalculated it based on the raw name of the compound-group. This overwriting of correct information by the parser led to phantom namespaces being created.

To rectify these issues, we had to strictly separate the realms of visual grouping and physical code architecture. Compounds of type group and file were declared "scopeless," prohibiting their names from being used as C++ prefixes in fallback logic. Additionally, we rewrote the contracts of internal functions to no longer "guess" the correct FQN. The top level would provide a verified scope, and internal functions were mandated to use only that.

This issue with @addtogroup tags is just the beginning. The next challenge will be teaching strict libclang to understand specific legacy tags like @cond and @relates without running Doxygen at all.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in World

More from Friday 27 November →