standardese / cppast

Library to parse and work with the C++ AST
Other
1.7k stars 164 forks source link

Is possible to get the #if defined directives information through cppast? #131

Closed littleGnAl closed 2 years ago

littleGnAl commented 2 years ago

Thanks for this awesome library!

I'm trying to generate a gmock file by using cppast, I have a class like below:

class Engine {
 public:
   virtual int setAppType1(int app_type) = 0;

  #if (defined(TARGET_OS_IOS))
   virtual int setAppType2(int app_type) = 0;
  #endif
};

The generated file content should like:

class MockEngine {
 public:
  MOCK_METHOD(int, setAppType1, (int app_type), (override));

  #if (defined(TARGET_OS_IOS))
  MOCK_METHOD(int, setAppType2, (int app_type), (override));
  #endif
}

Is possible to get the #if (defined(TARGET_OS_IOS)) directives information through cppast? Any suggestion for this?

foonathan commented 2 years ago

No, that is not possible, and I don't think it ever will be possible, unfortunately. libclang works on the input after it has been preprocessed. Getting macro definitions is already a hack on their end, and I need to do extra work to hide declarations from header files, etc.