3

Is it possible to evaluate expressions and function macros with libclang?

Something like this (expression):

#define SOMETHING 1 | 2 | 4 | 0x10

Or something with a function macro:

#define ADD(a,b) a+b
#define THING ADD(10,5)

I can tokenize the macro or get its raw text but I don't see any way to evaluate it.

sciencectn
  • 1,405
  • 1
  • 16
  • 25
  • Did you ever find a way to do this? – Øystein E. Krog Feb 23 '14 at 22:46
  • Nope...I'm using libclang with Ruby and I ended up just using copious amounts of Ruby's eval() to accomplish this – sciencectn Feb 28 '14 at 23:48
  • This isn't a full answer, but using a python wrapper for libclang, I was able to find the macro by setting `clang.cindex.TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD` for the `options` kwarg. This would get me SOMETHING in the first once, but I made function to get the definition part. I haven't also checked if this works for function macros. – BrockLee Feb 23 '16 at 13:28
  • Any chance, @LeoCHan you still have some portion of your solution to share with the community? – kuza Aug 24 '21 at 09:46

0 Answers0