unsigned MaxLines, bool &CreatedBuffer);
llvm::MemoryBuffer *getMainBufferWithPrecompiledPreamble(
+ CompilerInvocation PreambleInvocation,
bool AllowRebuild = true,
unsigned MaxLines = 0);
void RealizeTopLevelDeclsFromPreamble();
/// \param IncludeCodePatterns Whether to include code patterns (such as a
/// for loop) in the code-completion results.
///
- /// FIXME: The Diag, LangOpts, SourceMgr, FileMgr, and
- /// StoredDiagnostics parameters are all disgusting hacks. They will
- /// go away.
+ /// FIXME: The Diag, LangOpts, SourceMgr, FileMgr, StoredDiagnostics, and
+ /// OwnedBuffers parameters are all disgusting hacks. They will go away.
void CodeComplete(llvm::StringRef File, unsigned Line, unsigned Column,
RemappedFile *RemappedFiles, unsigned NumRemappedFiles,
bool IncludeMacros, bool IncludeCodePatterns,
CodeCompleteConsumer &Consumer,
Diagnostic &Diag, LangOptions &LangOpts,
SourceManager &SourceMgr, FileManager &FileMgr,
- llvm::SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics);
+ llvm::SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics,
+ llvm::SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers);
/// \brief Save this translation unit to a file with the given name.
///
/// buffer that should be used in place of the main file when doing so.
/// Otherwise, returns a NULL pointer.
llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
+ CompilerInvocation PreambleInvocation,
bool AllowRebuild,
unsigned MaxLines) {
- CompilerInvocation PreambleInvocation(*Invocation);
FrontendOptions &FrontendOpts = PreambleInvocation.getFrontendOpts();
PreprocessorOptions &PreprocessorOpts
= PreambleInvocation.getPreprocessorOpts();
// FIXME: When C++ PCH is ready, allow use of it for a precompiled preamble.
if (PrecompilePreamble && !CI->getLangOpts().CPlusPlus) {
AST->PreambleRebuildCounter = 1;
- OverrideMainBuffer = AST->getMainBufferWithPrecompiledPreamble();
+ OverrideMainBuffer
+ = AST->getMainBufferWithPrecompiledPreamble(*AST->Invocation);
}
llvm::Timer *ParsingTimer = 0;
// build a precompiled preamble, do so now.
llvm::MemoryBuffer *OverrideMainBuffer = 0;
if (!PreambleFile.empty() || PreambleRebuildCounter > 0)
- OverrideMainBuffer = getMainBufferWithPrecompiledPreamble();
+ OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(*Invocation);
// Clear out the diagnostics state.
if (!OverrideMainBuffer)
CodeCompleteConsumer &Consumer,
Diagnostic &Diag, LangOptions &LangOpts,
SourceManager &SourceMgr, FileManager &FileMgr,
- llvm::SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics) {
+ llvm::SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics,
+ llvm::SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers) {
if (!Invocation.get())
return;
// Remap files.
PreprocessorOpts.clearRemappedFiles();
PreprocessorOpts.RetainRemappedFileBuffers = true;
- for (unsigned I = 0; I != NumRemappedFiles; ++I)
+ for (unsigned I = 0; I != NumRemappedFiles; ++I) {
PreprocessorOpts.addRemappedFile(RemappedFiles[I].first,
RemappedFiles[I].second);
+ OwnedBuffers.push_back(RemappedFiles[I].second);
+ }
// Use the code completion consumer we were given, but adding any cached
// code-completion results.
if (const FileStatus *CompleteFileStatus = CompleteFilePath.getFileStatus())
if (const FileStatus *MainStatus = MainPath.getFileStatus())
if (CompleteFileStatus->getUniqueID() == MainStatus->getUniqueID())
- OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(false,
- Line);
+ OverrideMainBuffer
+ = getMainBufferWithPrecompiledPreamble(CCInvocation, false, Line);
}
// If the main file has been overridden due to the use of a preamble,
FullSourceLoc Loc(StoredDiagnostics[I].getLocation(), SourceMgr);
StoredDiagnostics[I].setLocation(Loc);
}
+
+ OwnedBuffers.push_back(OverrideMainBuffer);
} else {
PreprocessorOpts.PrecompiledPreambleBytes.first = 0;
PreprocessorOpts.PrecompiledPreambleBytes.second = false;
CompletionTimer->stopTimer();
// Steal back our resources.
- delete OverrideMainBuffer;
Clang.takeFileManager();
Clang.takeSourceManager();
Clang.takeInvocation();
// Create a code-completion consumer to capture the results.
CaptureCompletionResults Capture(*Results);
- // Make sure that we free the temporary buffers when the
- // code-completion constructor is freed.
- for (unsigned I = 0, N = RemappedFiles.size(); I != N; ++I)
- Results->TemporaryBuffers.push_back(RemappedFiles[I].second);
-
// Perform completion.
AST->CodeComplete(complete_filename, complete_line, complete_column,
RemappedFiles.data(), RemappedFiles.size(),
(options & CXCodeComplete_IncludeCodePatterns),
Capture,
*Results->Diag, Results->LangOpts, Results->SourceMgr,
- Results->FileMgr, Results->Diagnostics);
+ Results->FileMgr, Results->Diagnostics,
+ Results->TemporaryBuffers);