cppparser
cppparser copied to clipboard
segfault on a very large source file
I get a segfault when trying to analyze this file: https://github.com/mmomtchev/node-magickwand/raw/84e1cdff82aae838233202e76b9ca01815e9ebec/Magick%2B%2B.cxx
I am using a very basic walking of the outermost members:
#include "cppparser/pub/cppparser.h"
#include <stdio.h>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
int main() {
CppParser parser;
const auto testFilePath = fs::path(__FILE__).parent_path() / "Magick++.cxx";
const auto ast = parser.parseFile(testFilePath.string());
const auto& members = ast->members();
for (const auto &m : members) {
if (m->objType_ == CppObjType::kFunction)
printf("%s\n", ((CppFunctionEPtr)m)->name_.c_str());
}
}
The output is:
Error: Unexpected 'SWIG_AddCast', while in context=ctxGeneral(1), found at line#383
SWIGINTERNINLINE int SWIG_AddCast
^
Segmentation fault
I am trying to use the library to write a simple splitter that extracts all declarations in a single .h file and then splits the code definitions in multiple source files in order to bring down this huge codebase that has been generated by SWIG down to manageable levels.
I don't see a seg fault with the latest code but I do get a parsing error. The file uses macros to its extreme. The goal of cppparser is to allow parsing of all valid C++ files, but as of now handling of macros like this, which will need to do limited preprocessing before parsing, is not the priority.
One question: is it possible to add a custom text replacement rule which acts like a macro expansion before the lexer?
I mean, if I need to have "#define AAA 100" for all the codes, I would like to run this text replacement rule on every "AAA" token.
int a = AAA;
is actually
int a = 100;
Yes, SWIG has C preprocessor macro support.
Yes, SWIG has C preprocessor macro support.
Maybe the text replacement rule can be implemented in the lexer level. I'm not sure whether the flex tool support this.
One question: is it possible to add a custom text replacement rule which acts like a macro expansion before the lexer?
I had a plan to support a limited preprocessing before parsing to create an AST. But I never came around to do that.