<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Mon, Oct 19, 2015 at 8:59 AM Gabe Svenson via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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></div></blockquote><div><br></div><div>I believe the best way to achieve this is to use a completely new CompilerInstance + SourceManager and feed in the changed source files.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><br></div><div><span style="white-space:pre-wrap">   </span>// Set the main file handled by the source manager to the input file.</div><div><span style="white-space:pre-wrap">    </span>const FileEntry *FileIn = m_compilerParseInstance->getFileManager().getFile(srcFilePath);</div><div><span style="white-space:pre-wrap">     </span>m_compilerParseInstance->getSourceManager().setMainFileID(</div><div><span style="white-space:pre-wrap">            </span>m_compilerParseInstance->getSourceManager().createFileID(FileIn, SourceLocation(), SrcMgr::C_User));</div><div><br></div><div><span style="white-space:pre-wrap"> </span>// Create an AST consumer instance which is going to get called by</div><div><span style="white-space:pre-wrap">       </span>// ParseAST.</div><div><span style="white-space:pre-wrap">     </span>MyASTConsumer TheConsumer(m_rewriter);</div><div><br></div><div><span style="white-space:pre-wrap">  </span>// Parse the file to AST, registering our consumer as the AST consumer.</div><div><span style="white-space:pre-wrap">  </span>ParseAST(m_compilerParseInstance->getPreprocessor(), &TheConsumer,</div><div><span style="white-space:pre-wrap">                </span>m_compilerParseInstance->getASTContext());</div></div><div><br></div><div>Thanks and best regards,</div><div>Gabe</div></div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>