Swig -include everything except ...

I have a big project where using the Swig -includeall-flag seems to make sense. However, there are certain files that I would not want to expand, especially the STL libraries (for example, vector and list). Is it possible to use the -includeall flag, but to blacklist specific files from the extension (for example, vector and list)?

+5
source share
1 answer

I am not an expert at SWIG, but I look at both the documentation for the latest version and the source code (in particular, at Source/Modules/main.cxx , where command line arguments are read), it is clear that such a parameter does not exist (not even hidden).

On the other hand, if you feel that you can easily change the source code to do this.

You can add a new command line option to the main.cxx file to add file names for exclusion, and then compare those names to find a match. You can add a global function to the Source/Preprocessor/preprocessor.h file, which is already included in main.cxx .

The code for the -includeall parameter is in Source/Preprocessor/cpp.c This file also has a global variable called include_all , which is set to 1 when the analog argument is given on the command line (it will help you find where such an option is executed).

Now in the Preprocessor_parse(...) function you can find where the header files are analyzed (starting from line 1715 for version 3.0.12):

 s1 = cpp_include(fn, sysfile); if (s1) { /* ....... */ } 

You will be interested in the String *Swig_last_file(void) function, which will return the file name of the header line just processed.

 s1 = cpp_include(fn, sysfile); if (s1) { int found = 0; String* filename = Swig_last_file(); /* Here find for a match in the exclusion list */ if (!found) { /* keep working as usual */ /* ....... */ } /* if found, just ignore the include directive for that file */ Delete(s1); } 

I know this is not a complete solution, but hope can help you achieve your desired behavior.

+2
source

Source: https://habr.com/ru/post/1271995/


All Articles