FreeYourSoul / FSeam

Cpp header only library to manage compile time mock class generated via Python script
MIT License
86 stars 8 forks source link

Usage of __BEGIN_DECL/__END_DECL is not correctly parsed #25

Open solarispika opened 4 years ago

solarispika commented 4 years ago

Describe the bug A simple header with __BEGIN_DECL/__END_DECL is not correctly parsed.

To Reproduce Using latest commit 190e286a66d2d4ab8e9888e6c3bde8ee7d927233.

Just prepare this simple header and put it in one of test header, for example,

diff --git a/test/src/FreeFunctionClass.hh b/test/src/FreeFunctionClass.hh
index a0f8477..b0585b3 100644
--- a/test/src/FreeFunctionClass.hh
+++ b/test/src/FreeFunctionClass.hh
@@ -5,6 +5,13 @@
 #ifndef FSEAM_FREEFUNCTIONCLASS_HH
 #define FSEAM_FREEFUNCTIONCLASS_HH

+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+int test(void);
+
+__END_DECLS

 namespace source {

Then just build the project, the following error occurs:

cd /tmp/build/test && /usr/bin/c++  -DFSEAM_USE_CATCH2 -I/tmp/FSeam/test/src -I/tmp/build/test -I/tmp/FSeam/test/../FSeam -I/tmp/FSeam/FSeam  -std=gnu++17 -o CMakeFiles/testFSeamFreeFunction.dir/FreeFunctionClass.fseam.cc.o
-c /tmp/build/test/FreeFunctionClass.fseam.cc
In file included from /tmp/build/test/FreeFunctionClass.fseam.cc:9:
/tmp/build/test/FSeamMockData.hpp:61:5: error: expected member name or ';' after declaration specifiers
    __BEGIN_DECLS int test_ReturnValue;
    ^~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/sys/cdefs.h:109:31: note: expanded from macro '__BEGIN_DECLS'
# define __BEGIN_DECLS  extern "C" {
                        ~~~~~~ ^

Expected behavior Maybe leave __BEGIN_DECLS/__END_DECLS along?

FreeYourSoul commented 4 years ago

Unfortunately the parser used by FSeam is naive and just get information from a single header file, which means it cannot determine what is or not is a MACRO.

I see some way of fixing this :

As a short term solution the list of MACRO to be defined is certainly a good idea as it may help for quick-fixes for other parsing issue. But in the long term, the best would be to re-write the code generator in C++ and using libclang to parse headers and generate the appropriate source code with all the context (AST) required to not mistage a random character in the header file or an actual macro.