DeclarationHandler
This class is a CXXHandler which takes care of translating C/C++ declarations into Declaration nodes. It heavily relies on its sibling handler, the DeclaratorHandler.
In the C/C++ language, the meaning of a declaration depends on two major factors: First, a list of so-called declaration specifiers, which specify the type of declaration. Prominent examples include class
or enum
. Second, a list of declarators, which describe the actual "content" of the declaration, such as its name or parameters (in case of a function).
Since the logic behind a declarator is quite complex, this logic is extracted into its own handler. In fact, in most cases the DeclaratorHandler actually creates the CPG Declaration and the DeclarationHandler modifies the declaration depending on the declaration specifiers.
Functions
We intentionally override the logic of Handler.handle because we do not want the map-based logic, but rather want to make use of the Kotlin-when syntax.