///\brief Adds standard library -I used by whatever compiler is found in PATH. static void AddHostCXXIncludes(std::vector<const char*>& args) { static bool IncludesSet = false; static std::vector<std::string> HostCXXI; if (!IncludesSet) { IncludesSet = true; static const char *CppInclQuery = "echo | " LLVM_CXX " -xc++ -E -v - 2>&1 >/dev/null " "| awk '/^#include </,/^End of search" "/{if (!/^#include </ && !/^End of search/){ print }}' " "| grep -E \"(c|g)\\+\\+\""; if (FILE *pf = ::popen(CppInclQuery, "r")) { HostCXXI.push_back("-nostdinc++"); char buf[2048]; while (fgets(buf, sizeof(buf), pf) && buf[0]) { size_t lenbuf = strlen(buf); buf[lenbuf - 1] = 0; // remove trailing \n // Skip leading whitespace: const char* start = buf; while (start < buf + lenbuf && *start == ' ') ++start; if (*start) { HostCXXI.push_back("-I"); HostCXXI.push_back(start); } } ::pclose(pf); } CheckABICompatibility(); } for (std::vector<std::string>::const_iterator I = HostCXXI.begin(), E = HostCXXI.end(); I != E; ++I) args.push_back(I->c_str()); }
bool IncrementalParser::Initialize(llvm::SmallVectorImpl<ParseResultTransaction>& result, bool isChildInterpreter) { m_TransactionPool.reset(new TransactionPool); if (hasCodeGenerator()) getCodeGenerator()->Initialize(getCI()->getASTContext()); CompilationOptions CO = m_Interpreter->makeDefaultCompilationOpts(); Transaction* CurT = beginTransaction(CO); Preprocessor& PP = m_CI->getPreprocessor(); DiagnosticsEngine& Diags = m_CI->getSema().getDiagnostics(); // Pull in PCH. const std::string& PCHFileName = m_CI->getInvocation().getPreprocessorOpts().ImplicitPCHInclude; if (!PCHFileName.empty()) { Transaction* PchT = beginTransaction(CO); DiagnosticErrorTrap Trap(Diags); m_CI->createPCHExternalASTSource(PCHFileName, true /*DisablePCHValidation*/, true /*AllowPCHWithCompilerErrors*/, 0 /*DeserializationListener*/, true /*OwnsDeserializationListener*/); result.push_back(endTransaction(PchT)); if (Trap.hasErrorOccurred()) { result.push_back(endTransaction(CurT)); return false; } } addClingPragmas(*m_Interpreter); // Must happen after attaching the PCH, else PCH elements will end up // being lexed. PP.EnterMainSourceFile(); Sema* TheSema = &m_CI->getSema(); m_Parser.reset(new Parser(PP, *TheSema, false /*skipFuncBodies*/)); // Initialize the parser after PP has entered the main source file. m_Parser->Initialize(); ExternalASTSource *External = TheSema->getASTContext().getExternalSource(); if (External) External->StartTranslationUnit(m_Consumer); // Start parsing the "main file" to warm up lexing (enter caching lex mode // for ParseInternal()'s call EnterSourceFile() to make sense. while (!m_Parser->ParseTopLevelDecl()) {} // If I belong to the parent Interpreter, am using C++, and -noruntime // wasn't given on command line, then #include <new> and check ABI if (!isChildInterpreter && m_CI->getLangOpts().CPlusPlus && !m_Interpreter->getOptions().NoRuntime) { // <new> is needed by the ValuePrinter so it's a good thing to include it. // We need to include it to determine the version number of the standard // library implementation. ParseInternal("#include <new>"); // That's really C++ ABI compatibility. C has other problems ;-) CheckABICompatibility(*m_Interpreter); } // DO NOT commit the transactions here: static initialization in these // transactions requires gCling through local_cxa_atexit(), but that has not // been defined yet! ParseResultTransaction PRT = endTransaction(CurT); result.push_back(PRT); return true; }