7

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

Thanks.

Dan D.
  • 73,243
  • 15
  • 104
  • 123
marius c
  • 73
  • 1
  • 3
  • sounds like you need to spelunk into the parsing and lexing sections for clang/LLVM and go from there, I suspect you'd probably get better help from the clang mailing list – Necrolis Jan 19 '11 at 15:10
  • i've edited the IdentifierTabe.cpp, and added the new keyword to TokenKinds.def as far as from parsing and lexing I can't find the behavior of main from C as i don't know where it's defined. – marius c Jan 19 '11 at 15:27
  • [One of the disadvantages of Clang versus Elsa](http://clang.llvm.org/comparison.html#elsa) is that Elsa uses a nice parser completely based on grammar rules. I've always wondered why Clang developers didn't choose to write their parser in the same way... – peoro Jan 19 '11 at 16:49
  • @peoro, Elsa is very slow, whereas Clang with its horrible, handrwitten recursive descent parser is faster then GCC. – SK-logic Jan 19 '11 at 16:53

1 Answers1

7

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.

SK-logic
  • 9,605
  • 1
  • 23
  • 35
  • Where do i define its behaviour ? is there any documentation on where is implemented the behaviour, beside the code? – marius c Jan 20 '11 at 09:22
  • 1
    I have not seen any documentation on this particular aspect of Clang, but it's quite easy to just copy and paste similar things - in your case it would be an implementation of 'inline', for example (this one is in AST), or the address space attribute for the second option. – SK-logic Jan 20 '11 at 09:34
  • 1
    In which file we need to do #define your_new_qualifier __attribute__((your_new_attribute)) and where to add "your_new_attribute" – Ginu Jacob Jan 21 '16 at 03:26