clang  3.7.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
clang::ASTUnit Class Reference

Utility class for loading a ASTContext from an AST file. More...

#include <ASTUnit.h>

Inheritance diagram for clang::ASTUnit:
[legend]
Collaboration diagram for clang::ASTUnit:
[legend]

Classes

struct  ASTWriterData
 
struct  CachedCodeCompletionResult
 A cached code-completion result, which may be introduced in one of many different contexts. More...
 
class  ConcurrencyCheck
 
class  PreambleData
 
struct  PreambleFileHash
 Data used to determine if a file used in the preamble has been changed. More...
 
struct  StandaloneDiagnostic
 
struct  StandaloneFixIt
 

Public Types

typedef std::vector< Decl * >
::iterator 
top_level_iterator
 
typedef StoredDiagnosticstored_diag_iterator
 
typedef const StoredDiagnosticstored_diag_const_iterator
 
typedef std::vector
< CachedCodeCompletionResult >
::iterator 
cached_completion_iterator
 
typedef bool(* DeclVisitorFn )(void *context, const Decl *D)
 Type for a function iterating over a number of declarations. More...
 
typedef std::pair< std::string,
llvm::MemoryBuffer * > 
RemappedFile
 A mapping from a file name to the memory buffer that stores the remapped contents of that file. More...
 

Public Member Functions

const PreambleDatagetPreambleData () const
 
llvm::StringMap< unsigned > & getCachedCompletionTypes ()
 Retrieve the mapping from formatted type names to unique type identifiers. More...
 
IntrusiveRefCntPtr
< GlobalCodeCompletionAllocator
getCachedCompletionAllocator ()
 Retrieve the allocator used to cache global code completions. More...
 
CodeCompletionTUInfogetCodeCompletionTUInfo ()
 
 ~ASTUnit () override
 
bool isMainFileAST () const
 
bool isUnsafeToFree () const
 
void setUnsafeToFree (bool Value)
 
const DiagnosticsEnginegetDiagnostics () const
 
DiagnosticsEnginegetDiagnostics ()
 
const SourceManagergetSourceManager () const
 
SourceManagergetSourceManager ()
 
const PreprocessorgetPreprocessor () const
 
PreprocessorgetPreprocessor ()
 
const ASTContextgetASTContext () const
 
ASTContextgetASTContext ()
 
void setASTContext (ASTContext *ctx)
 
void setPreprocessor (Preprocessor *pp)
 
bool hasSema () const
 
SemagetSema () const
 
const LangOptionsgetLangOpts () const
 
const FileManagergetFileManager () const
 
FileManagergetFileManager ()
 
const FileSystemOptionsgetFileSystemOpts () const
 
StringRef getOriginalSourceFileName ()
 
ASTMutationListenergetASTMutationListener ()
 
ASTDeserializationListenergetDeserializationListener ()
 
void addTemporaryFile (StringRef TempFile)
 Add a temporary file that the ASTUnit depends on. More...
 
bool getOnlyLocalDecls () const
 
bool getOwnsRemappedFileBuffers () const
 
void setOwnsRemappedFileBuffers (bool val)
 
StringRef getMainFileName () const
 
StringRef getASTFileName () const
 If this ASTUnit came from an AST file, returns the filename for it. More...
 
top_level_iterator top_level_begin ()
 
top_level_iterator top_level_end ()
 
std::size_t top_level_size () const
 
bool top_level_empty () const
 
void addTopLevelDecl (Decl *D)
 Add a new top-level declaration. More...
 
void addFileLevelDecl (Decl *D)
 Add a new local file-level declaration. More...
 
void findFileRegionDecls (FileID File, unsigned Offset, unsigned Length, SmallVectorImpl< Decl * > &Decls)
 Get the decls that are contained in a file in the Offset/Length range. Length can be 0 to indicate a point at Offset instead of a range. More...
 
void addTopLevelDeclFromPreamble (serialization::DeclID D)
 Add a new top-level declaration, identified by its ID in the precompiled preamble. More...
 
unsignedgetCurrentTopLevelHashValue ()
 Retrieve a reference to the current top-level name hash value. More...
 
SourceLocation getLocation (const FileEntry *File, unsigned Line, unsigned Col) const
 Get the source location for the given file:line:col triplet. More...
 
SourceLocation getLocation (const FileEntry *File, unsigned Offset) const
 Get the source location for the given file:offset pair. More...
 
SourceLocation mapLocationFromPreamble (SourceLocation Loc)
 If Loc is a loaded location from the preamble, returns the corresponding local location of the main file, otherwise it returns Loc. More...
 
SourceLocation mapLocationToPreamble (SourceLocation Loc)
 If Loc is a local location of the main file but inside the preamble chunk, returns the corresponding loaded location from the preamble, otherwise it returns Loc. More...
 
bool isInPreambleFileID (SourceLocation Loc)
 
bool isInMainFileID (SourceLocation Loc)
 
SourceLocation getStartOfMainFileID ()
 
SourceLocation getEndOfPreambleFileID ()
 
SourceRange mapRangeFromPreamble (SourceRange R)
 
SourceRange mapRangeToPreamble (SourceRange R)
 
stored_diag_const_iterator stored_diag_begin () const
 
stored_diag_iterator stored_diag_begin ()
 
stored_diag_const_iterator stored_diag_end () const
 
stored_diag_iterator stored_diag_end ()
 
unsigned stored_diag_size () const
 
stored_diag_iterator stored_diag_afterDriver_begin ()
 
cached_completion_iterator cached_completion_begin ()
 
cached_completion_iterator cached_completion_end ()
 
unsigned cached_completion_size () const
 
llvm::iterator_range
< PreprocessingRecord::iterator
getLocalPreprocessingEntities () const
 Returns an iterator range for the local preprocessing entities of the local Preprocessor, if this is a parsed source file, or the loaded preprocessing entities of the primary module if this is an AST file. More...
 
bool visitLocalTopLevelDecls (void *context, DeclVisitorFn Fn)
 Iterate over local declarations (locally parsed if this is a parsed source file or the loaded declarations of the primary module if this is an AST file). More...
 
const FileEntrygetPCHFile ()
 Get the PCH file if one was included. More...
 
bool isModuleFile ()
 Returns true if the ASTUnit was constructed from a serialized module file. More...
 
std::unique_ptr
< llvm::MemoryBuffer > 
getBufferForFile (StringRef Filename, std::string *ErrorStr=nullptr)
 
TranslationUnitKind getTranslationUnitKind () const
 Determine what kind of translation unit this AST represents. More...
 
bool Reparse (std::shared_ptr< PCHContainerOperations > PCHContainerOps, ArrayRef< RemappedFile > RemappedFiles=None)
 Reparse the source files using the same command-line options that were originally used to produce this translation unit. More...
 
void CodeComplete (StringRef File, unsigned Line, unsigned Column, ArrayRef< RemappedFile > RemappedFiles, bool IncludeMacros, bool IncludeCodePatterns, bool IncludeBriefComments, CodeCompleteConsumer &Consumer, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticsEngine &Diag, LangOptions &LangOpts, SourceManager &SourceMgr, FileManager &FileMgr, SmallVectorImpl< StoredDiagnostic > &StoredDiagnostics, SmallVectorImpl< const llvm::MemoryBuffer * > &OwnedBuffers)
 Perform code completion at the given file, line, and column within this translation unit. More...
 
bool Save (StringRef File)
 Save this translation unit to a file with the given name. More...
 
bool serialize (raw_ostream &OS)
 Serialize this translation unit with the given output stream. More...
 
ModuleLoadResult loadModule (SourceLocation ImportLoc, ModuleIdPath Path, Module::NameVisibilityKind Visibility, bool IsInclusionDirective) override
 Attempt to load the given module. More...
 
void makeModuleVisible (Module *Mod, Module::NameVisibilityKind Visibility, SourceLocation ImportLoc) override
 Make the given module visible. More...
 
GlobalModuleIndexloadGlobalModuleIndex (SourceLocation TriggerLoc) override
 Load, create, or return global module. This function returns an existing global module index, if one had already been loaded or created, or loads one if it exists, or creates one if it doesn't exist. Also, importantly, if the index doesn't cover all the modules in the module map, it will be update to do so here, because of its use in searching for needed module imports and associated fixit messages. More...
 
bool lookupMissingImports (StringRef Name, SourceLocation TriggerLoc) override
 
- Public Member Functions inherited from clang::ModuleLoader
 ModuleLoader (bool BuildingModule=false)
 
virtual ~ModuleLoader ()
 
bool buildingModule () const
 Returns true if this instance is building a module. More...
 
void setBuildingModule (bool BuildingModuleFlag)
 Flag indicating whether this instance is building a module. More...
 

Static Public Member Functions

static ASTUnitcreate (CompilerInvocation *CI, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, bool CaptureDiagnostics, bool UserFilesAreVolatile)
 Create a ASTUnit. Gets ownership of the passed CompilerInvocation. More...
 
static std::unique_ptr< ASTUnitLoadFromASTFile (const std::string &Filename, const PCHContainerReader &PCHContainerRdr, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, const FileSystemOptions &FileSystemOpts, bool OnlyLocalDecls=false, ArrayRef< RemappedFile > RemappedFiles=None, bool CaptureDiagnostics=false, bool AllowPCHWithCompilerErrors=false, bool UserFilesAreVolatile=false)
 Create a ASTUnit from an AST file. More...
 
static ASTUnitLoadFromCompilerInvocationAction (CompilerInvocation *CI, std::shared_ptr< PCHContainerOperations > PCHContainerOps, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, ASTFrontendAction *Action=nullptr, ASTUnit *Unit=nullptr, bool Persistent=true, StringRef ResourceFilesPath=StringRef(), bool OnlyLocalDecls=false, bool CaptureDiagnostics=false, bool PrecompilePreamble=false, bool CacheCodeCompletionResults=false, bool IncludeBriefCommentsInCodeCompletion=false, bool UserFilesAreVolatile=false, std::unique_ptr< ASTUnit > *ErrAST=nullptr)
 Create an ASTUnit from a source file, via a CompilerInvocation object, by invoking the optionally provided ASTFrontendAction. More...
 
static std::unique_ptr< ASTUnitLoadFromCompilerInvocation (CompilerInvocation *CI, std::shared_ptr< PCHContainerOperations > PCHContainerOps, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, bool OnlyLocalDecls=false, bool CaptureDiagnostics=false, bool PrecompilePreamble=false, TranslationUnitKind TUKind=TU_Complete, bool CacheCodeCompletionResults=false, bool IncludeBriefCommentsInCodeCompletion=false, bool UserFilesAreVolatile=false)
 
static ASTUnitLoadFromCommandLine (const char **ArgBegin, const char **ArgEnd, std::shared_ptr< PCHContainerOperations > PCHContainerOps, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, StringRef ResourceFilesPath, bool OnlyLocalDecls=false, bool CaptureDiagnostics=false, ArrayRef< RemappedFile > RemappedFiles=None, bool RemappedFilesKeepOriginalName=true, bool PrecompilePreamble=false, TranslationUnitKind TUKind=TU_Complete, bool CacheCodeCompletionResults=false, bool IncludeBriefCommentsInCodeCompletion=false, bool AllowPCHWithCompilerErrors=false, bool SkipFunctionBodies=false, bool UserFilesAreVolatile=false, bool ForSerialization=false, std::unique_ptr< ASTUnit > *ErrAST=nullptr)
 

Friends

class ConcurrencyCheck
 

Additional Inherited Members

- Public Attributes inherited from clang::ModuleLoader
bool HadFatalFailure
 

Detailed Description

Utility class for loading a ASTContext from an AST file.

Definition at line 68 of file ASTUnit.h.

Member Typedef Documentation

Definition at line 665 of file ASTUnit.h.

typedef bool(* clang::ASTUnit::DeclVisitorFn)(void *context, const Decl *D)

Type for a function iterating over a number of declarations.

Returns
true to continue iteration and false to abort.

Definition at line 687 of file ASTUnit.h.

typedef std::pair<std::string, llvm::MemoryBuffer *> clang::ASTUnit::RemappedFile

A mapping from a file name to the memory buffer that stores the remapped contents of that file.

Definition at line 710 of file ASTUnit.h.

Definition at line 643 of file ASTUnit.h.

Definition at line 642 of file ASTUnit.h.

typedef std::vector<Decl *>::iterator clang::ASTUnit::top_level_iterator

Definition at line 552 of file ASTUnit.h.

Constructor & Destructor Documentation

ASTUnit::~ASTUnit ( )
override

Member Function Documentation

void ASTUnit::addFileLevelDecl ( Decl D)
void ASTUnit::addTemporaryFile ( StringRef  TempFile)

Add a temporary file that the ASTUnit depends on.

This file will be erased when the ASTUnit is destroyed.

Definition at line 199 of file ASTUnit.cpp.

References getOnDiskData().

void clang::ASTUnit::addTopLevelDecl ( Decl D)
inline

Add a new top-level declaration.

Definition at line 579 of file ASTUnit.h.

void clang::ASTUnit::addTopLevelDeclFromPreamble ( serialization::DeclID  D)
inline

Add a new top-level declaration, identified by its ID in the precompiled preamble.

Definition at line 594 of file ASTUnit.h.

cached_completion_iterator clang::ASTUnit::cached_completion_begin ( )
inline

Definition at line 667 of file ASTUnit.h.

cached_completion_iterator clang::ASTUnit::cached_completion_end ( )
inline

Definition at line 671 of file ASTUnit.h.

unsigned clang::ASTUnit::cached_completion_size ( ) const
inline

Definition at line 675 of file ASTUnit.h.

void ASTUnit::CodeComplete ( StringRef  File,
unsigned  Line,
unsigned  Column,
ArrayRef< RemappedFile RemappedFiles,
bool  IncludeMacros,
bool  IncludeCodePatterns,
bool  IncludeBriefComments,
CodeCompleteConsumer Consumer,
std::shared_ptr< PCHContainerOperations PCHContainerOps,
DiagnosticsEngine Diag,
LangOptions LangOpts,
SourceManager SourceMgr,
FileManager FileMgr,
SmallVectorImpl< StoredDiagnostic > &  StoredDiagnostics,
SmallVectorImpl< const llvm::MemoryBuffer * > &  OwnedBuffers 
)

Perform code completion at the given file, line, and column within this translation unit.

Parameters
FileThe file in which code completion will occur.
LineThe line at which code completion will occur.
ColumnThe column at which code completion will occur.
IncludeMacrosWhether to include macros in the code-completion results.
IncludeCodePatternsWhether to include code patterns (such as a for loop) in the code-completion results.
IncludeBriefCommentsWhether to include brief documentation within the set of code completions returned.

FIXME: The Diag, LangOpts, SourceMgr, FileMgr, StoredDiagnostics, and OwnedBuffers parameters are all disgusting hacks. They will go away.

Definition at line 2304 of file ASTUnit.cpp.

References clang::PreprocessorOptions::addRemappedFile(), clang::PreprocessorOptions::clearRemappedFiles(), clang::FrontendOptions::CodeCompleteOpts, clang::FrontendOptions::CodeCompletionAt, clang::ParsedSourceLocation::Column, Column, clang::TargetInfo::CreateTargetInfo(), clang::PreprocessorOptions::DetailedRecord, clang::PreprocessorOptions::DisablePCHValidation, clang::ParsedSourceLocation::FileName, getPreambleFile(), clang::IK_AST, clang::IK_LLVM_IR, clang::PreprocessorOptions::ImplicitPCHInclude, CodeCompleteOptions::IncludeBriefComments, CodeCompleteOptions::IncludeCodePatterns, CodeCompleteOptions::IncludeGlobals, CodeCompleteOptions::IncludeMacros, clang::ParsedSourceLocation::Line, Line, clang::PreprocessorOptions::PrecompiledPreambleBytes, clang::ProcessWarningOptions(), clang::PreprocessorOptions::RetainRemappedFileBuffers, and clang::ASTUnit::PreambleData::size().

ASTUnit * ASTUnit::create ( CompilerInvocation CI,
IntrusiveRefCntPtr< DiagnosticsEngine Diags,
bool  CaptureDiagnostics,
bool  UserFilesAreVolatile 
)
static

Create a ASTUnit. Gets ownership of the passed CompilerInvocation.

Definition at line 1700 of file ASTUnit.cpp.

References clang::createVFSFromCompilerInvocation(), and clang::CompilerInvocation::getFileSystemOpts().

Referenced by LoadFromCompilerInvocationAction().

void ASTUnit::findFileRegionDecls ( FileID  File,
unsigned  Offset,
unsigned  Length,
SmallVectorImpl< Decl * > &  Decls 
)

Get the decls that are contained in a file in the Offset/Length range. Length can be 0 to indicate a point at Offset instead of a range.

Definition at line 2605 of file ASTUnit.cpp.

References clang::ExternalASTSource::FindFileRegionDecls(), clang::ASTContext::getExternalSource(), clang::FileID::isInvalid(), and clang::SourceManager::isLoadedFileID().

const ASTContext& clang::ASTUnit::getASTContext ( ) const
inline

Definition at line 508 of file ASTUnit.h.

ASTContext& clang::ASTUnit::getASTContext ( )
inline

Definition at line 509 of file ASTUnit.h.

StringRef ASTUnit::getASTFileName ( ) const

If this ASTUnit came from an AST file, returns the filename for it.

Definition at line 1691 of file ASTUnit.cpp.

References clang::serialization::ModuleFile::FileName, and isMainFileAST().

ASTMutationListener * ASTUnit::getASTMutationListener ( )

Definition at line 620 of file ASTUnit.cpp.

std::unique_ptr< llvm::MemoryBuffer > ASTUnit::getBufferForFile ( StringRef  Filename,
std::string *  ErrorStr = nullptr 
)

Definition at line 633 of file ASTUnit.cpp.

IntrusiveRefCntPtr<GlobalCodeCompletionAllocator> clang::ASTUnit::getCachedCompletionAllocator ( )
inline

Retrieve the allocator used to cache global code completions.

Definition at line 367 of file ASTUnit.h.

llvm::StringMap<unsigned>& clang::ASTUnit::getCachedCompletionTypes ( )
inline

Retrieve the mapping from formatted type names to unique type identifiers.

Definition at line 361 of file ASTUnit.h.

CodeCompletionTUInfo& clang::ASTUnit::getCodeCompletionTUInfo ( )
inline

Definition at line 371 of file ASTUnit.h.

unsigned& clang::ASTUnit::getCurrentTopLevelHashValue ( )
inline

Retrieve a reference to the current top-level name hash value.

Note: This is used internally by the top-level tracking action

Definition at line 601 of file ASTUnit.h.

Referenced by LoadFromCompilerInvocationAction().

ASTDeserializationListener * ASTUnit::getDeserializationListener ( )

Definition at line 626 of file ASTUnit.cpp.

const DiagnosticsEngine& clang::ASTUnit::getDiagnostics ( ) const
inline

Definition at line 499 of file ASTUnit.h.

Referenced by LoadFromCompilerInvocationAction(), Reparse(), serialize(), and ~ASTUnit().

DiagnosticsEngine& clang::ASTUnit::getDiagnostics ( )
inline

Definition at line 500 of file ASTUnit.h.

SourceLocation ASTUnit::getEndOfPreambleFileID ( )
const FileManager& clang::ASTUnit::getFileManager ( ) const
inline

Definition at line 525 of file ASTUnit.h.

Referenced by LoadFromCompilerInvocationAction().

FileManager& clang::ASTUnit::getFileManager ( )
inline

Definition at line 526 of file ASTUnit.h.

const FileSystemOptions& clang::ASTUnit::getFileSystemOpts ( ) const
inline

Definition at line 528 of file ASTUnit.h.

const LangOptions& clang::ASTUnit::getLangOpts ( ) const
inline

Definition at line 520 of file ASTUnit.h.

llvm::iterator_range< PreprocessingRecord::iterator > ASTUnit::getLocalPreprocessingEntities ( ) const

Returns an iterator range for the local preprocessing entities of the local Preprocessor, if this is a parsed source file, or the loaded preprocessing entities of the primary module if this is an AST file.

Definition at line 2749 of file ASTUnit.cpp.

References isMainFileAST().

SourceLocation ASTUnit::getLocation ( const FileEntry File,
unsigned  Line,
unsigned  Col 
) const

Get the source location for the given file:line:col triplet.

The difference with SourceManager::getLocation is that this method checks whether the requested location points inside the precompiled preamble in which case the returned source location will be a "loaded" one.

Definition at line 2648 of file ASTUnit.cpp.

References clang::SourceManager::getMacroArgExpandedLocation(), getSourceManager(), SM, and clang::SourceManager::translateFileLineCol().

SourceLocation ASTUnit::getLocation ( const FileEntry File,
unsigned  Offset 
) const
StringRef ASTUnit::getMainFileName ( ) const
bool clang::ASTUnit::getOnlyLocalDecls ( ) const
inline

Definition at line 542 of file ASTUnit.h.

StringRef clang::ASTUnit::getOriginalSourceFileName ( )
inline

Definition at line 530 of file ASTUnit.h.

bool clang::ASTUnit::getOwnsRemappedFileBuffers ( ) const
inline

Definition at line 544 of file ASTUnit.h.

const FileEntry * ASTUnit::getPCHFile ( )

Get the PCH file if one was included.

Definition at line 2810 of file ASTUnit.cpp.

References PCHLocator().

const PreambleData& clang::ASTUnit::getPreambleData ( ) const
inline

Definition at line 225 of file ASTUnit.h.

const Preprocessor& clang::ASTUnit::getPreprocessor ( ) const
inline

Definition at line 505 of file ASTUnit.h.

Preprocessor& clang::ASTUnit::getPreprocessor ( )
inline

Definition at line 506 of file ASTUnit.h.

Sema& clang::ASTUnit::getSema ( ) const
inline

Definition at line 515 of file ASTUnit.h.

Referenced by serialize().

const SourceManager& clang::ASTUnit::getSourceManager ( ) const
inline

Definition at line 502 of file ASTUnit.h.

References SourceMgr.

Referenced by getLocation(), and LoadFromCompilerInvocationAction().

SourceManager& clang::ASTUnit::getSourceManager ( )
inline

Definition at line 503 of file ASTUnit.h.

References SourceMgr.

SourceLocation ASTUnit::getStartOfMainFileID ( )
TranslationUnitKind clang::ASTUnit::getTranslationUnitKind ( ) const
inline

Determine what kind of translation unit this AST represents.

Definition at line 706 of file ASTUnit.h.

bool clang::ASTUnit::hasSema ( ) const
inline

Definition at line 514 of file ASTUnit.h.

bool ASTUnit::isInMainFileID ( SourceLocation  Loc)
bool ASTUnit::isInPreambleFileID ( SourceLocation  Loc)
bool clang::ASTUnit::isMainFileAST ( ) const
inline
bool ASTUnit::isModuleFile ( )

Returns true if the ASTUnit was constructed from a serialized module file.

Definition at line 2822 of file ASTUnit.cpp.

References clang::LangOptions::CurrentModule, and isMainFileAST().

bool clang::ASTUnit::isUnsafeToFree ( ) const
inline

Definition at line 496 of file ASTUnit.h.

std::unique_ptr< ASTUnit > ASTUnit::LoadFromASTFile ( const std::string &  Filename,
const PCHContainerReader PCHContainerRdr,
IntrusiveRefCntPtr< DiagnosticsEngine Diags,
const FileSystemOptions FileSystemOpts,
bool  OnlyLocalDecls = false,
ArrayRef< RemappedFile RemappedFiles = None,
bool  CaptureDiagnostics = false,
bool  AllowPCHWithCompilerErrors = false,
bool  UserFilesAreVolatile = false 
)
static

Create a ASTUnit from an AST file.

Parameters
Filename- The AST file to load.
PCHContainerOps- The PCHContainerOperations to use for loading and creating modules.
Diags- The diagnostics engine to use for reporting errors; its lifetime is expected to extend past that of the returned ASTUnit.
Returns
- The initialized ASTUnit or null if the AST failed to load.

Definition at line 651 of file ASTUnit.cpp.

References clang::PreprocessorOptions::addRemappedFile(), clang::ASTReader::ARR_None, clang::ASTReader::ConfigurationMismatch, Context, clang::ASTReader::Failure, clang::PCHContainerReader::getFormat(), clang::vfs::getRealFileSystem(), clang::ASTReader::HadErrors, clang::ASTReader::Missing, clang::serialization::MK_MainFile, clang::ASTReader::OutOfDate, clang::ASTReader::Success, and clang::ASTReader::VersionMismatch.

Referenced by clang::FrontendAction::BeginSourceFile(), and clang::ASTMergeAction::ExecuteAction().

ASTUnit * ASTUnit::LoadFromCommandLine ( const char **  ArgBegin,
const char **  ArgEnd,
std::shared_ptr< PCHContainerOperations PCHContainerOps,
IntrusiveRefCntPtr< DiagnosticsEngine Diags,
StringRef  ResourceFilesPath,
bool  OnlyLocalDecls = false,
bool  CaptureDiagnostics = false,
ArrayRef< RemappedFile RemappedFiles = None,
bool  RemappedFilesKeepOriginalName = true,
bool  PrecompilePreamble = false,
TranslationUnitKind  TUKind = TU_Complete,
bool  CacheCodeCompletionResults = false,
bool  IncludeBriefCommentsInCodeCompletion = false,
bool  AllowPCHWithCompilerErrors = false,
bool  SkipFunctionBodies = false,
bool  UserFilesAreVolatile = false,
bool  ForSerialization = false,
std::unique_ptr< ASTUnit > *  ErrAST = nullptr 
)
static

LoadFromCommandLine - Create an ASTUnit from a vector of command line arguments, which must specify exactly one source file.

Parameters
ArgBegin- The beginning of the argument vector.
ArgEnd- The end of the argument vector.
PCHContainerOps- The PCHContainerOperations to use for loading and creating modules.
Diags- The diagnostics engine to use for reporting errors; its lifetime is expected to extend past that of the returned ASTUnit.
ResourceFilesPath- The path to the compiler resource files.
ErrAST- If non-null and parsing failed without any AST to return (e.g. because the PCH could not be loaded), this accepts the ASTUnit mainly to allow the caller to see the diagnostics.

Definition at line 1930 of file ASTUnit.cpp.

References clang::PreprocessorOptions::AllowPCHWithCompilerErrors, clang::createInvocationFromCommandLine(), clang::createVFSFromCompilerInvocation(), and clang::PreprocessorOptions::RemappedFilesKeepOriginalName.

std::unique_ptr< ASTUnit > ASTUnit::LoadFromCompilerInvocation ( CompilerInvocation CI,
std::shared_ptr< PCHContainerOperations PCHContainerOps,
IntrusiveRefCntPtr< DiagnosticsEngine Diags,
bool  OnlyLocalDecls = false,
bool  CaptureDiagnostics = false,
bool  PrecompilePreamble = false,
TranslationUnitKind  TUKind = TU_Complete,
bool  CacheCodeCompletionResults = false,
bool  IncludeBriefCommentsInCodeCompletion = false,
bool  UserFilesAreVolatile = false 
)
static

LoadFromCompilerInvocation - Create an ASTUnit from a source file, via a CompilerInvocation object.

Parameters
CI- The compiler invocation to use; it must have exactly one input source file. The ASTUnit takes ownership of the CompilerInvocation object.
PCHContainerOps- The PCHContainerOperations to use for loading and creating modules.
Diags- The diagnostics engine to use for reporting errors; its lifetime is expected to extend past that of the returned ASTUnit.

Definition at line 1892 of file ASTUnit.cpp.

References clang::createVFSFromCompilerInvocation(), and clang::CompilerInvocation::getFileSystemOpts().

ASTUnit * ASTUnit::LoadFromCompilerInvocationAction ( CompilerInvocation CI,
std::shared_ptr< PCHContainerOperations PCHContainerOps,
IntrusiveRefCntPtr< DiagnosticsEngine Diags,
ASTFrontendAction Action = nullptr,
ASTUnit Unit = nullptr,
bool  Persistent = true,
StringRef  ResourceFilesPath = StringRef(),
bool  OnlyLocalDecls = false,
bool  CaptureDiagnostics = false,
bool  PrecompilePreamble = false,
bool  CacheCodeCompletionResults = false,
bool  IncludeBriefCommentsInCodeCompletion = false,
bool  UserFilesAreVolatile = false,
std::unique_ptr< ASTUnit > *  ErrAST = nullptr 
)
static

Create an ASTUnit from a source file, via a CompilerInvocation object, by invoking the optionally provided ASTFrontendAction.

Parameters
CI- The compiler invocation to use; it must have exactly one input source file. The ASTUnit takes ownership of the CompilerInvocation object.
PCHContainerOps- The PCHContainerOperations to use for loading and creating modules.
Diags- The diagnostics engine to use for reporting errors; its lifetime is expected to extend past that of the returned ASTUnit.
Action- The ASTFrontendAction to invoke. Its ownership is not transferred.
Unit- optionally an already created ASTUnit. Its ownership is not transferred.
Persistent- if true the returned ASTUnit will be complete. false means the caller is only interested in getting info through the provided
See Also
Action.
Parameters
ErrAST- If non-null and parsing failed without any AST to return (e.g. because the PCH could not be loaded), this accepts the ASTUnit mainly to allow the caller to see the diagnostics. This will only receive an ASTUnit if a new one was created. If an already created ASTUnit was passed in Unit then the caller can check that.

Definition at line 1722 of file ASTUnit.cpp.

References Action, clang::FrontendAction::BeginSourceFile(), create(), clang::TargetInfo::CreateTargetInfo(), clang::FrontendOptions::DisableFree, clang::FrontendAction::EndSourceFile(), clang::FrontendAction::Execute(), getCurrentTopLevelHashValue(), clang::CompilerInvocationBase::getDiagnosticOpts(), getDiagnostics(), getFileManager(), clang::CompilerInvocation::getFrontendOpts(), clang::CompilerInvocationBase::getHeaderSearchOpts(), clang::CompilerInvocationBase::getPreprocessorOpts(), getSourceManager(), clang::FrontendAction::getTranslationUnitKind(), clang::IK_AST, clang::IK_LLVM_IR, clang::ProcessWarningOptions(), clang::HeaderSearchOptions::ResourceDir, clang::PreprocessorOptions::RetainRemappedFileBuffers, and clang::TU_Complete.

Referenced by clang::arcmt::MigrationProcess::applyTransform(), and clang::arcmt::checkForManualIssues().

GlobalModuleIndex* clang::ASTUnit::loadGlobalModuleIndex ( SourceLocation  TriggerLoc)
inlineoverridevirtual

Load, create, or return global module. This function returns an existing global module index, if one had already been loaded or created, or loads one if it exists, or creates one if it doesn't exist. Also, importantly, if the index doesn't cover all the modules in the module map, it will be update to do so here, because of its use in searching for needed module imports and associated fixit messages.

Parameters
TriggerLocThe location for what triggered the load.
Returns
Returns null if load failed.

Implements clang::ModuleLoader.

Definition at line 909 of file ASTUnit.h.

ModuleLoadResult clang::ASTUnit::loadModule ( SourceLocation  ImportLoc,
ModuleIdPath  Path,
Module::NameVisibilityKind  Visibility,
bool  IsInclusionDirective 
)
inlineoverridevirtual

Attempt to load the given module.

This routine attempts to load the module described by the given parameters.

Parameters
ImportLocThe location of the 'import' keyword.
PathThe identifiers (and their locations) of the module "path", e.g., "std.vector" would be split into "std" and "vector".
VisibilityThe visibility provided for the names in the loaded module.
IsInclusionDirectiveIndicates that this module is being loaded implicitly, due to the presence of an inclusion directive. Otherwise, it is being loaded due to an import declaration.
Returns
If successful, returns the loaded module. Otherwise, returns NULL to indicate that the module could not be loaded.

Implements clang::ModuleLoader.

Definition at line 899 of file ASTUnit.h.

bool clang::ASTUnit::lookupMissingImports ( StringRef  Name,
SourceLocation  TriggerLoc 
)
inlineoverridevirtual

Check global module index for missing imports.

Parameters
NameThe symbol name to look for.
TriggerLocThe location for what triggered the load.
Returns
Returns true if any modules with that symbol found.

Implements clang::ModuleLoader.

Definition at line 911 of file ASTUnit.h.

void clang::ASTUnit::makeModuleVisible ( Module Mod,
Module::NameVisibilityKind  Visibility,
SourceLocation  ImportLoc 
)
inlineoverridevirtual

Make the given module visible.

Implements clang::ModuleLoader.

Definition at line 906 of file ASTUnit.h.

SourceLocation ASTUnit::mapLocationFromPreamble ( SourceLocation  Loc)

If Loc is a loaded location from the preamble, returns the corresponding local location of the main file, otherwise it returns Loc.

If.

  • Loc is a loaded location from the preamble, returns the corresponding local location of the main file, otherwise it returns
  • Loc.

Definition at line 2665 of file ASTUnit.cpp.

References clang::ASTUnit::PreambleData::empty(), clang::SourceManager::getLocForStartOfFile(), clang::SourceLocation::getLocWithOffset(), clang::SourceManager::getMainFileID(), clang::SourceManager::getPreambleFileID(), clang::SourceManager::isInFileID(), clang::FileID::isInvalid(), clang::SourceLocation::isInvalid(), and clang::ASTUnit::PreambleData::size().

Referenced by mapRangeFromPreamble().

SourceLocation ASTUnit::mapLocationToPreamble ( SourceLocation  Loc)

If Loc is a local location of the main file but inside the preamble chunk, returns the corresponding loaded location from the preamble, otherwise it returns Loc.

If.

  • Loc is a local location of the main file but inside the preamble chunk, returns the corresponding loaded location from the preamble, otherwise it returns
  • Loc.

Definition at line 2686 of file ASTUnit.cpp.

References clang::ASTUnit::PreambleData::empty(), clang::SourceManager::getLocForStartOfFile(), clang::SourceLocation::getLocWithOffset(), clang::SourceManager::getMainFileID(), clang::SourceManager::getPreambleFileID(), clang::SourceManager::isInFileID(), clang::FileID::isInvalid(), clang::SourceLocation::isInvalid(), and clang::ASTUnit::PreambleData::size().

Referenced by mapRangeToPreamble().

SourceRange clang::ASTUnit::mapRangeFromPreamble ( SourceRange  R)
inline
SourceRange clang::ASTUnit::mapRangeToPreamble ( SourceRange  R)
inline
bool ASTUnit::Reparse ( std::shared_ptr< PCHContainerOperations PCHContainerOps,
ArrayRef< RemappedFile RemappedFiles = None 
)

Reparse the source files using the same command-line options that were originally used to produce this translation unit.

Returns
True if a failure occurred that causes the ASTUnit not to contain any translation-unit information, false otherwise.

Definition at line 2017 of file ASTUnit.cpp.

References clang::PreprocessorOptions::addRemappedFile(), clang::PreprocessorOptions::clearRemappedFiles(), clang::CompilerInvocationBase::getDiagnosticOpts(), getDiagnostics(), getMainFileName(), getPreambleFile(), clang::CompilerInvocationBase::getPreprocessorOpts(), clang::ProcessWarningOptions(), clang::PreprocessorOptions::RemappedFileBuffers, clang::DiagnosticsEngine::Reset(), clang::Result, and clang::DiagnosticsEngine::setNumWarnings().

bool ASTUnit::Save ( StringRef  File)

Save this translation unit to a file with the given name.

Returns
true if there was a file error or false if the save was successful.

Definition at line 2452 of file ASTUnit.cpp.

References serialize().

bool ASTUnit::serialize ( raw_ostream &  OS)

Serialize this translation unit with the given output stream.

Returns
True if an error occurred, false otherwise.

Definition at line 2498 of file ASTUnit.cpp.

References getDiagnostics(), getSema(), clang::DiagnosticsEngine::hasErrorOccurred(), and serializeUnit().

Referenced by Save().

void clang::ASTUnit::setASTContext ( ASTContext ctx)
inline

Definition at line 511 of file ASTUnit.h.

void clang::ASTUnit::setOwnsRemappedFileBuffers ( bool  val)
inline

Definition at line 545 of file ASTUnit.h.

void ASTUnit::setPreprocessor ( Preprocessor pp)

Definition at line 260 of file ASTUnit.cpp.

void clang::ASTUnit::setUnsafeToFree ( bool  Value)
inline

Definition at line 497 of file ASTUnit.h.

stored_diag_iterator clang::ASTUnit::stored_diag_afterDriver_begin ( )
inline

Definition at line 658 of file ASTUnit.h.

stored_diag_const_iterator clang::ASTUnit::stored_diag_begin ( ) const
inline

Definition at line 644 of file ASTUnit.h.

stored_diag_iterator clang::ASTUnit::stored_diag_begin ( )
inline

Definition at line 647 of file ASTUnit.h.

stored_diag_const_iterator clang::ASTUnit::stored_diag_end ( ) const
inline

Definition at line 650 of file ASTUnit.h.

stored_diag_iterator clang::ASTUnit::stored_diag_end ( )
inline

Definition at line 653 of file ASTUnit.h.

unsigned clang::ASTUnit::stored_diag_size ( ) const
inline

Definition at line 656 of file ASTUnit.h.

top_level_iterator clang::ASTUnit::top_level_begin ( )
inline

Definition at line 554 of file ASTUnit.h.

References isMainFileAST().

Referenced by visitLocalTopLevelDecls().

bool clang::ASTUnit::top_level_empty ( ) const
inline

Definition at line 573 of file ASTUnit.h.

References isMainFileAST().

top_level_iterator clang::ASTUnit::top_level_end ( )
inline

Definition at line 561 of file ASTUnit.h.

References isMainFileAST().

Referenced by visitLocalTopLevelDecls().

std::size_t clang::ASTUnit::top_level_size ( ) const
inline

Definition at line 568 of file ASTUnit.h.

References isMainFileAST().

bool ASTUnit::visitLocalTopLevelDecls ( void *  context,
DeclVisitorFn  Fn 
)

Iterate over local declarations (locally parsed if this is a parsed source file or the loaded declarations of the primary module if this is an AST file).

Returns
true if the iteration was complete or false if it was aborted.

Definition at line 2763 of file ASTUnit.cpp.

References isMainFileAST(), top_level_begin(), and top_level_end().

Friends And Related Function Documentation

friend class ConcurrencyCheck
friend

Definition at line 490 of file ASTUnit.h.


The documentation for this class was generated from the following files: