How can you add a new keyword to clang, a keyword

2019-03-27 10:37发布

问题:

How can a new keyword be added to clang? The new keyword should be a function qualifier. Where would the declaration part go?

Thanks.

回答1:

You have to add it to include/clang/Basic/TokenKinds.def, and then add a new case to ParseDeclarationSpecifiers(...).

Probably an easier option would be to define a new attribute, and then use

#define your_new_qualifier __attribute__((your_new_attribute))

Otherwise you'd have to add this qualifier support to the AST, which could be error-prone, whereas attributes are propagated automatically across various declarations of the same function.



标签: c++ c clang