satya-das / cppparser

A library to parse C/C++ source as AST
Other
278 stars 36 forks source link

segfault on a very large source file #29

Open mmomtchev opened 1 year ago

mmomtchev commented 1 year ago

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
mmomtchev commented 1 year ago

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.

satya-das commented 3 weeks ago

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.