clang 8.0.0

Classes | Typedefs | Functions | Variables
ASTUnit.cpp File Reference
`#include "clang/Frontend/ASTUnit.h"`
`#include "clang/AST/ASTConsumer.h"`
`#include "clang/AST/ASTContext.h"`
`#include "clang/AST/CommentCommandTraits.h"`
`#include "clang/AST/Decl.h"`
`#include "clang/AST/DeclBase.h"`
`#include "clang/AST/DeclCXX.h"`
`#include "clang/AST/DeclGroup.h"`
`#include "clang/AST/DeclObjC.h"`
`#include "clang/AST/DeclTemplate.h"`
`#include "clang/AST/DeclarationName.h"`
`#include "clang/AST/ExternalASTSource.h"`
`#include "clang/AST/PrettyPrinter.h"`
`#include "clang/AST/Type.h"`
`#include "clang/AST/TypeOrdering.h"`
`#include "clang/Basic/Diagnostic.h"`
`#include "clang/Basic/FileManager.h"`
`#include "clang/Basic/IdentifierTable.h"`
`#include "clang/Basic/LLVM.h"`
`#include "clang/Basic/LangOptions.h"`
`#include "clang/Basic/MemoryBufferCache.h"`
`#include "clang/Basic/Module.h"`
`#include "clang/Basic/SourceLocation.h"`
`#include "clang/Basic/SourceManager.h"`
`#include "clang/Basic/TargetInfo.h"`
`#include "clang/Basic/TargetOptions.h"`
`#include "clang/Frontend/CompilerInstance.h"`
`#include "clang/Frontend/CompilerInvocation.h"`
`#include "clang/Frontend/FrontendAction.h"`
`#include "clang/Frontend/FrontendActions.h"`
`#include "clang/Frontend/FrontendDiagnostic.h"`
`#include "clang/Frontend/FrontendOptions.h"`
`#include "clang/Frontend/MultiplexConsumer.h"`
`#include "clang/Frontend/PrecompiledPreamble.h"`
`#include "clang/Frontend/Utils.h"`
`#include "clang/Lex/HeaderSearch.h"`
`#include "clang/Lex/HeaderSearchOptions.h"`
`#include "clang/Lex/Lexer.h"`
`#include "clang/Lex/PPCallbacks.h"`
`#include "clang/Lex/PreprocessingRecord.h"`
`#include "clang/Lex/Preprocessor.h"`
`#include "clang/Lex/PreprocessorOptions.h"`
`#include "clang/Lex/Token.h"`
`#include "clang/Sema/CodeCompleteConsumer.h"`
`#include "clang/Sema/CodeCompleteOptions.h"`
`#include "clang/Sema/Sema.h"`
`#include "clang/Serialization/ASTBitCodes.h"`
`#include "clang/Serialization/ASTReader.h"`
`#include "clang/Serialization/ASTWriter.h"`
`#include "clang/Serialization/ContinuousRangeMap.h"`
`#include "clang/Serialization/Module.h"`
`#include "clang/Serialization/PCHContainerOperations.h"`
`#include "llvm/ADT/ArrayRef.h"`
`#include "llvm/ADT/DenseMap.h"`
`#include "llvm/ADT/IntrusiveRefCntPtr.h"`
`#include "llvm/ADT/None.h"`
`#include "llvm/ADT/Optional.h"`
`#include "llvm/ADT/STLExtras.h"`
`#include "llvm/ADT/SmallString.h"`
`#include "llvm/ADT/SmallVector.h"`
`#include "llvm/ADT/StringMap.h"`
`#include "llvm/ADT/StringRef.h"`
`#include "llvm/ADT/StringSet.h"`
`#include "llvm/ADT/Twine.h"`
`#include "llvm/ADT/iterator_range.h"`
`#include "llvm/Bitcode/BitstreamWriter.h"`
`#include "llvm/Support/Allocator.h"`
`#include "llvm/Support/Casting.h"`
`#include "llvm/Support/CrashRecoveryContext.h"`
`#include "llvm/Support/DJB.h"`
`#include "llvm/Support/ErrorHandling.h"`
`#include "llvm/Support/ErrorOr.h"`
`#include "llvm/Support/FileSystem.h"`
`#include "llvm/Support/MemoryBuffer.h"`
`#include "llvm/Support/Mutex.h"`
`#include "llvm/Support/Timer.h"`
`#include "llvm/Support/VirtualFileSystem.h"`
`#include "llvm/Support/raw_ostream.h"`
`#include <algorithm>`
`#include <atomic>`
`#include <cassert>`
`#include <cstdint>`
`#include <cstdio>`
`#include <cstdlib>`
`#include <memory>`
`#include <string>`
`#include <tuple>`
`#include <utility>`
`#include <vector>`

Go to the source code of this file.

## Classes
struct | clang::ASTUnit::ASTWriterData

## Typedefs
using | SLocRemap = ContinuousRangeMap< unsigned, int, 2 >

## Functions
template<class T >
static std::unique_ptr< T > | valueOrNull (llvm::ErrorOr< std::unique_ptr< T >> Val)
template<class T >
static bool | moveOnNoError (llvm::ErrorOr< T > Val, T &Output)
static std::unique_ptr< llvm::MemoryBuffer > | getBufferForFileHandlingRemapping (const CompilerInvocation &Invocation, llvm::vfs::FileSystem *VFS, StringRef FilePath, bool isVolatile)
| Get a source buffer for `MainFilePath`, handling all file-to-file and file-to-buffer remappings inside `Invocation`. More...
static uint64_t | getDeclShowContexts (const NamedDecl *ND, const LangOptions &LangOpts, bool &IsNestedNameSpecifier)
| Determine the set of code-completion contexts in which this declaration should be shown. More...
static ASTUnit::StandaloneDiagnostic | makeStandaloneDiagnostic (const LangOptions &LangOpts, const StoredDiagnostic &InDiag)
static void | AddDefinedMacroToHash (const Token &MacroNameTok, unsigned &Hash)
| Add the given macro to the hash of all top-level entities. More...
static void | AddTopLevelDeclarationToHash (Decl *D, unsigned &Hash)
| Add the given declaration to the hash of all top-level entities. More...
static bool | isNonDriverDiag (const StoredDiagnostic &StoredDiag)
static void | checkAndRemoveNonDriverDiags (SmallVectorImpl< StoredDiagnostic > &StoredDiags)
static void | checkAndSanitizeDiags (SmallVectorImpl< StoredDiagnostic > &StoredDiagnostics, SourceManager &SM)
static std::pair< unsigned, unsigned > | makeStandaloneRange (CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts)
static ASTUnit::StandaloneFixIt | makeStandaloneFixIt (const SourceManager &SM, const LangOptions &LangOpts, const FixItHint &InFix)
static void | CalculateHiddenNames (const CodeCompletionContext &Context, CodeCompletionResult *Results, unsigned NumResults, ASTContext &Ctx, llvm::StringSet< llvm::BumpPtrAllocator > &HiddenNames)
| Helper function that computes which global names are hidden by the local code-completion results. More...
static bool | serializeUnit (ASTWriter &Writer, SmallVectorImpl< char > &Buffer, Sema &S, bool hasErrors, raw_ostream &OS)

## Variables
const unsigned | DefaultPreambleRebuildInterval = 5
| After failing to build a precompiled preamble (due to errors in the source that occurs in the preamble), the number of reparses during which we'll skip even trying to precompile the preamble. More...
static std::atomic< unsigned > | ActiveASTUnitObjects
| Tracks the number of ASTUnit objects that are currently active. More...

## Typedef Documentation

## ◆ SLocRemap

using SLocRemap = ContinuousRangeMap<unsigned, int, 2>

Definition at line 2326 of file ASTUnit.cpp.

## Function Documentation

## ◆ AddDefinedMacroToHash()

static void AddDefinedMacroToHash | ( | const Token & | MacroNameTok,
|  | unsigned & | Hash
| ) |  |
| static

Add the given macro to the hash of all top-level entities.

Definition at line 849 of file ASTUnit.cpp.

References clang::Token::getIdentifierInfo(), and clang::IdentifierInfo::getName().

## ◆ AddTopLevelDeclarationToHash()

static void AddTopLevelDeclarationToHash | ( | Decl * | D,
|  | unsigned & | Hash
| ) |  |
| static

Add the given declaration to the hash of all top-level entities.

Definition at line 872 of file ASTUnit.cpp.

References clang::Decl::getDeclContext(), clang::DeclContext::getLookupParent(), and clang::DeclContext::isTranslationUnit().

## ◆ CalculateHiddenNames()

static void CalculateHiddenNames | ( | const CodeCompletionContext & | Context,
|  | CodeCompletionResult * | Results,
|  | unsigned | NumResults,
|  | ASTContext & | Ctx,
|  | llvm::StringSet< llvm::BumpPtrAllocator > & | HiddenNames
| ) |  |
| static

Helper function that computes which global names are hidden by the local code-completion results.

Definition at line 1934 of file ASTUnit.cpp.

## ◆ checkAndRemoveNonDriverDiags()

static void checkAndRemoveNonDriverDiags | ( | SmallVectorImpl< StoredDiagnostic > & | StoredDiags | ) |
| static

Definition at line 1047 of file ASTUnit.cpp.

References isNonDriverDiag().

Referenced by checkAndSanitizeDiags(), and makeStandaloneDiagnostic().

## ◆ checkAndSanitizeDiags()

static void checkAndSanitizeDiags | ( | SmallVectorImpl< StoredDiagnostic > & | StoredDiagnostics,
|  | SourceManager & | SM
| ) |  |
| static

Definition at line 1055 of file ASTUnit.cpp.

References checkAndRemoveNonDriverDiags(), clang::TargetInfo::CreateTargetInfo(), clang::ASTUnit::getDiagnostics(), clang::ASTUnit::getFileManager(), clang::ASTUnit::getSourceManager(), clang::InputKind::LLVM_IR, clang::Preamble, clang::ASTUnit::ResetForParse(), SM, and clang::InputKind::Source.

## ◆ getBufferForFileHandlingRemapping()

static std::unique_ptr<llvm::MemoryBuffer> getBufferForFileHandlingRemapping | ( | const CompilerInvocation & | Invocation,
|  | llvm::vfs::FileSystem * | VFS,
|  | StringRef | FilePath,
|  | bool | isVolatile
| ) |  |
| static

Get a source buffer for `MainFilePath`, handling all file-to-file and file-to-buffer remappings inside `Invocation`.

Definition at line 157 of file ASTUnit.cpp.

References clang::CompilerInvocationBase::getPreprocessorOpts(), and valueOrNull().

Referenced by makeStandaloneDiagnostic().

## ◆ getDeclShowContexts()

static uint64_t getDeclShowContexts | ( | const NamedDecl * | ND,
|  | const LangOptions & | LangOpts,
|  | bool & | IsNestedNameSpecifier
| ) |  |
| static

Determine the set of code-completion contexts in which this declaration should be shown.

Definition at line 285 of file ASTUnit.cpp.

References clang::NamedDecl::getUnderlyingDecl().

## ◆ isNonDriverDiag()

static bool isNonDriverDiag | ( | const StoredDiagnostic & | StoredDiag | ) |
| static

Definition at line 1042 of file ASTUnit.cpp.

References clang::StoredDiagnostic::getLocation(), and clang::SourceLocation::isValid().

Referenced by checkAndRemoveNonDriverDiags().

## ◆ makeStandaloneDiagnostic()

static ASTUnit::StandaloneDiagnostic makeStandaloneDiagnostic | ( | const LangOptions & | LangOpts,
|  | const StoredDiagnostic & | InDiag
| ) |  |
| static

Definition at line 1236 of file ASTUnit.cpp.

References clang::BeginSourceFileFailed, clang::PrecompiledPreamble::Build(), checkAndRemoveNonDriverDiags(), clang::ComputePreambleBounds(), clang::CouldntCreateTargetInfo, clang::CouldntCreateTempFile, clang::CouldntEmitPCH, DefaultPreambleRebuildInterval, clang::ASTUnit::StandaloneDiagnostic::Filename, clang::frontend::FixIt, clang::ASTUnit::StandaloneDiagnostic::FixIts, clang::ASTUnit::getASTContext(), clang::CompilerInstance::getASTContext(), getBufferForFileHandlingRemapping(), clang::CompilerInvocationBase::getDiagnosticOpts(), clang::ASTUnit::getDiagnostics(), clang::ExternalASTSource::GetExternalDecl(), clang::ASTContext::getExternalSource(), clang::SourceManager::getFileLoc(), clang::SourceManager::getFilename(), clang::SourceManager::getFileOffset(), clang::StoredDiagnostic::getFixIts(), clang::CompilerInvocation::getFrontendOpts(), clang::StoredDiagnostic::getID(), clang::CompilerInstance::getInvocation(), clang::CompilerInvocationBase::getLangOpts(), clang::StoredDiagnostic::getLevel(), clang::StoredDiagnostic::getLocation(), clang::FullSourceLoc::getManager(), clang::StoredDiagnostic::getMessage(), clang::CompilerInstance::getModuleManager(), clang::DiagnosticsEngine::getNumWarnings(), clang::CompilerInstance::getPreprocessorPtr(), clang::StoredDiagnostic::getRanges(), clang::CompilerInstance::getTarget(), clang::CompilerInstance::hadModuleLoaderFatalFailure(), clang::CompilerInstance::hasASTContext(), clang::CompilerInstance::hasInvocation(), clang::CompilerInstance::hasPreprocessor(), clang::CompilerInstance::hasTarget(), clang::ASTUnit::StandaloneDiagnostic::ID, clang::FrontendOptions::Inputs, clang::SourceLocation::isInvalid(), clang::CompilerInvocationBase::LangOpts, clang::ASTUnit::StandaloneDiagnostic::Level, clang::ASTUnit::StandaloneDiagnostic::LocOffset, makeStandaloneFixIt(), makeStandaloneRange(), clang::ASTUnit::StandaloneDiagnostic::Message, clang::Preamble, clang::ProcessWarningOptions(), clang::ASTUnit::StandaloneDiagnostic::Ranges, clang::DiagnosticsEngine::Reset(), clang::CompilerInstance::setFileManager(), clang::DiagnosticsEngine::setNumWarnings(), clang::CompilerInstance::setSourceManager(), clang::PreambleBounds::Size, clang::FrontendOptions::SkipFunctionBodies, SM, clang::CompilerInstance::takeASTConsumer(), clang::CompilerInstance::takeSema(), and clang::Target.

## ◆ makeStandaloneFixIt()

static ASTUnit::StandaloneFixIt makeStandaloneFixIt | ( | const SourceManager & | SM,
|  | const LangOptions & | LangOpts,
|  | const FixItHint & | InFix
| ) |  |
| static

Definition at line 1223 of file ASTUnit.cpp.

References clang::FixItHint::BeforePreviousInsertions, clang::ASTUnit::StandaloneFixIt::BeforePreviousInsertions, clang::FixItHint::CodeToInsert, clang::ASTUnit::StandaloneFixIt::CodeToInsert, clang::FixItHint::InsertFromRange, clang::ASTUnit::StandaloneFixIt::InsertFromRange, makeStandaloneRange(), clang::FixItHint::RemoveRange, and clang::ASTUnit::StandaloneFixIt::RemoveRange.

Referenced by makeStandaloneDiagnostic().

## ◆ makeStandaloneRange()

static std::pair<unsigned, unsigned> makeStandaloneRange | ( | CharSourceRange | Range,
|  | const SourceManager & | SM,
|  | const LangOptions & | LangOpts
| ) |  |
| static

Definition at line 1215 of file ASTUnit.cpp.

References clang::CharSourceRange::getBegin(), clang::CharSourceRange::getEnd(), clang::SourceManager::getFileOffset(), clang::Lexer::makeFileCharRange(), and Offset.

Referenced by makeStandaloneDiagnostic(), and makeStandaloneFixIt().

## ◆ moveOnNoError()

template<class T >

static bool moveOnNoError | ( | llvm::ErrorOr< T > | Val,
|  | T & | Output
| ) |  |
| static

Definition at line 147 of file ASTUnit.cpp.

## ◆ serializeUnit()

static bool serializeUnit | ( | ASTWriter & | Writer,
|  | SmallVectorImpl< char > & | Buffer,
|  | Sema & | S,
|  | bool | hasErrors,
|  | raw_ostream & | OS
| ) |  |
| static

Definition at line 2297 of file ASTUnit.cpp.

References clang::ASTWriter::WriteAST().

Referenced by clang::ASTUnit::serialize().

## ◆ valueOrNull()

template<class T >

static std::unique_ptr<T> valueOrNull | ( | llvm::ErrorOr< std::unique_ptr< T >> | Val | ) |
| static

Definition at line 140 of file ASTUnit.cpp.

Referenced by getBufferForFileHandlingRemapping().

## Variable Documentation

## ◆ ActiveASTUnitObjects

std::atomic<unsigned> ActiveASTUnitObjects
| static

Tracks the number of ASTUnit objects that are currently active.

Used for debugging purposes only.

Definition at line 238 of file ASTUnit.cpp.

## ◆ DefaultPreambleRebuildInterval

const unsigned DefaultPreambleRebuildInterval = 5

After failing to build a precompiled preamble (due to errors in the source that occurs in the preamble), the number of reparses during which we'll skip even trying to precompile the preamble.

Definition at line 233 of file ASTUnit.cpp.

Referenced by makeStandaloneDiagnostic().