<div dir="ltr"><div>Hello,</div><div><br></div><div>I'm trying to parse a file to do some minor source to source transformations using clang's rewriter. I want to re-use the same compiler instance within a parse function but atm I'm triggering this assertion when I repeat call parseAST: </div><div><br></div><div>Assertion failed: NumEnteredSourceFiles == 0 && "Cannot reenter the main file!",</div><div> file F:\Clanggit\clang\lib\Lex\Preprocessor.cpp, line 483</div><div><br></div><div><div>So I have this in my parsing function, what I want to know is how to reset all the parts of the compiler (without deleting/releasing them) so that I can repeatedly call ParseAST from the same compiler instance within a function without triggering any asserts or having any other issues.</div><div><br></div><div><span class="" style="white-space:pre"> </span>// Set the main file handled by the source manager to the input file.</div><div><span class="" style="white-space:pre">      </span>const FileEntry *FileIn = m_compilerParseInstance->getFileManager().getFile(srcFilePath);</div><div><span class="" style="white-space:pre">       </span>m_compilerParseInstance->getSourceManager().setMainFileID(</div><div><span class="" style="white-space:pre">              </span>m_compilerParseInstance->getSourceManager().createFileID(FileIn, SourceLocation(), SrcMgr::C_User));</div><div><br></div><div><span class="" style="white-space:pre">   </span>// Create an AST consumer instance which is going to get called by</div><div><span class="" style="white-space:pre"> </span>// ParseAST.</div><div><span class="" style="white-space:pre">       </span>MyASTConsumer TheConsumer(m_rewriter);</div><div><br></div><div><span class="" style="white-space:pre">    </span>// Parse the file to AST, registering our consumer as the AST consumer.</div><div><span class="" style="white-space:pre">    </span>ParseAST(m_compilerParseInstance->getPreprocessor(), &TheConsumer,</div><div><span class="" style="white-space:pre">          </span>m_compilerParseInstance->getASTContext());</div></div><div><br></div><div>Thanks and best regards,</div><div>Gabe</div></div>