Open jszymonek opened 7 months ago
I should also point out that clang 18.1.1 on Compiler Explorer dumps the AST as I would expect - exposing the annotation no matter what method is used. Please refer to the following example.
I can confirm I ran into the same issue.
I don't have a good explanation of why but removing clang_Location_isFromMainFile
check makes you code work in all cases:
-- ClassDecl 'Test01' <Test01> [HAS_ATTR]
---- attribute(annotate) 'ann' <> [IS_ATTR] [HAS_ATTR]
-- ClassDecl 'Test02' <Test02> [HAS_ATTR]
---- attribute(annotate) 'ann' <> [IS_ATTR] [HAS_ATTR]
-- ClassDecl 'Test03' <Test03> [HAS_ATTR]
---- attribute(annotate) 'ann' <> [IS_ATTR] [HAS_ATTR]
-- ClassDecl 'Test04' <Test04> [HAS_ATTR]
---- attribute(annotate) 'ann' <> [IS_ATTR] [HAS_ATTR]
-- ClassDecl 'Test05' <Test05> [HAS_ATTR]
---- attribute(annotate) 'ann' <> [IS_ATTR] [HAS_ATTR]
-- ClassDecl 'Test06' <Test06> [HAS_ATTR]
---- attribute(annotate) 'ann' <> [IS_ATTR] [HAS_ATTR]
The source code I am parsing uses
[[clang::annotate]]
on a class declaration, however that annotation is not always visible in the AST. In the following source, onlyTest01
andTest02
ClassDecls have aattribute(annotate)
child in the AST. The expected behavior would be for all of the class declarations have theattribute(annotate)
child.Here's the code I am running:
Here's the output it produces:
If you set PRETTY_PRINTED to true, the output will contain the pretty printed source representation of each node. As you can observe, that representation contains the annotation, which suggests that it is not lost during the parsing, just not properly exposed in the AST.
Further testing indicates that the same applies to annotations attached to class methods.