clang-tools 22.0.0git
clang::clangd::ParsedAST Class Reference

Stores and provides access to parsed AST. More...

#include <ParsedAST.h>

Public Member Functions

 ParsedAST (ParsedAST &&Other)
ParsedASToperator= (ParsedAST &&Other)
 ~ParsedAST ()
 ParsedAST (const ParsedAST &Other)=delete
ParsedASToperator= (const ParsedAST &Other)=delete
ASTContext & getASTContext ()
 Note that the returned ast will not contain decls from the preamble that were not deserialized during parsing.
const ASTContext & getASTContext () const
Sema & getSema ()
Preprocessor & getPreprocessor ()
std::shared_ptr< Preprocessor > getPreprocessorPtr ()
const Preprocessor & getPreprocessor () const
SourceManager & getSourceManager ()
const SourceManager & getSourceManager () const
const LangOptions & getLangOpts () const
ArrayRef< Decl * > getLocalTopLevelDecls ()
 This function returns top-level decls present in the main file of the AST.
ArrayRef< const Decl * > getLocalTopLevelDecls () const
llvm::ArrayRef< DiaggetDiagnostics () const
std::size_t getUsedBytes () const
 Returns the estimated size of the AST and the accessory structures, in bytes.
const IncludeStructuregetIncludeStructure () const
const MainFileMacrosgetMacros () const
 Gets all macro references (definition, expansions) present in the main file, including those in the preamble region.
const std::vector< PragmaMark > & getMarks () const
 Gets all pragma marks in the main file.
const syntax::TokenBuffer & getTokens () const
 Tokens recorded while parsing the main file.
const include_cleaner::PragmaIncludes & getPragmaIncludes () const
 Returns the PramaIncludes for preamble + main file includes.
llvm::StringRef version () const
 Returns the version of the ParseInputs this AST was built from.
PathRef tuPath () const
 Returns the path passed by the caller when building this AST.
std::optional< llvm::StringRef > preambleVersion () const
 Returns the version of the ParseInputs used to build Preamble part of this AST.
const HeuristicResolver * getHeuristicResolver () const

Static Public Member Functions

static std::optional< ParsedASTbuild (llvm::StringRef Filename, const ParseInputs &Inputs, std::unique_ptr< clang::CompilerInvocation > CI, llvm::ArrayRef< Diag > CompilerInvocationDiags, std::shared_ptr< const PreambleData > Preamble)
 Attempts to run Clang and store the parsed AST.

Detailed Description

Stores and provides access to parsed AST.

Definition at line 46 of file ParsedAST.h.

Constructor & Destructor Documentation

◆ ParsedAST() [1/2]

clang::clangd::ParsedAST::ParsedAST ( ParsedAST && Other)
default

References ParsedAST().

Referenced by build(), operator=(), operator=(), ParsedAST(), and ParsedAST().

◆ ~ParsedAST()

clang::clangd::ParsedAST::~ParsedAST ( )

Definition at line 773 of file ParsedAST.cpp.

◆ ParsedAST() [2/2]

clang::clangd::ParsedAST::ParsedAST ( const ParsedAST & Other)
delete

References ParsedAST().

Member Function Documentation

◆ build()

std::optional< ParsedAST > clang::clangd::ParsedAST::build ( llvm::StringRef Filename,
const ParseInputs & Inputs,
std::unique_ptr< clang::CompilerInvocation > CI,
llvm::ArrayRef< Diag > CompilerInvocationDiags,
std::shared_ptr< const PreambleData > Preamble )
static

Attempts to run Clang and store the parsed AST.

If Preamble is non-null it is reused during parsing. This function does not check if preamble is valid to reuse.

Definition at line 406 of file ParsedAST.cpp.

References clang::clangd::Config::AngledHeaders, clang::tidy::ClangTidyOptions::Checks, clang::clangd::Config::ClangTidy, clang::clangd::ParseInputs::ClangTidyProvider, clang::clangd::IncludeStructure::collect(), clang::clangd::collectPragmaMarksCallback(), clang::clangd::ParseInputs::CompileCommand, clang::tidy::configurationAsText(), clang::clangd::ParseInputs::Contents, clang::clangd::StoreDiags::contributeFixes(), clang::tidy::ClangTidyCheckFactories::createChecksForLanguage(), clang::clangd::PreamblePatch::createFullPatch(), clang::clangd::Config::current(), clang::clangd::Config::Diagnostics, dlog, clang::clangd::elog(), clang::clangd::StoreDiags::EndSourceFile(), clang::tidy::ClangTidyOptions::ExtraArgs, clang::tidy::ClangTidyOptions::ExtraArgsBefore, clang::clangd::Config::FastCheckFilter, clang::clangd::ParseInputs::FeatureModules, clang::clangd::getFormatStyleForFile(), clang::clangd::getTidyOptionsForFile(), clang::clangd::ParseOptions::ImportInsertions, clang::clangd::Symbol::Include, clang::clangd::ParseInputs::Index, clang::clangd::Info, clang::clangd::isDiagnosticSuppressed(), clang::clangd::isInsideMainFile(), clang::clangd::log(), clang::clangd::DiagBase::Message, clang::clangd::ParseInputs::Opts, ParsedAST(), clang::clangd::preferredIncludeDirective(), clang::clangd::prepareCompilerInstance(), clang::clangd::Config::QuotedHeaders, clang::clangd::StoreDiags::setDiagCallback(), clang::clangd::StoreDiags::setLevelAdjuster(), SPAN_ATTACH, clang::clangd::Config::Style, clang::clangd::Config::Suppress, clang::clangd::Config::SuppressAll, clang::clangd::StoreDiags::take(), clang::clangd::ParseInputs::TFS, clang::clangd::toString(), clang::clangd::ParseInputs::Version, and clang::clangd::ThreadsafeFS::view().

Referenced by clang::clangd::TestTU::build(), and clang::clangd::TestWorkspace::index().

◆ getASTContext() [1/2]

ASTContext & clang::clangd::ParsedAST::getASTContext ( )

Note that the returned ast will not contain decls from the preamble that were not deserialized during parsing.

Clients should expect only decls from the main file to be in the AST.

Definition at line 784 of file ParsedAST.cpp.

References getASTContext().

Referenced by getASTContext(), getLangOpts(), getSourceManager(), getSourceManager(), and getUsedBytes().

◆ getASTContext() [2/2]

const ASTContext & clang::clangd::ParsedAST::getASTContext ( ) const

Definition at line 786 of file ParsedAST.cpp.

◆ getDiagnostics()

llvm::ArrayRef< Diag > clang::clangd::ParsedAST::getDiagnostics ( ) const

Definition at line 879 of file ParsedAST.cpp.

◆ getHeuristicResolver()

const HeuristicResolver * clang::clangd::ParsedAST::getHeuristicResolver ( ) const
inline

Definition at line 122 of file ParsedAST.h.

◆ getIncludeStructure()

const IncludeStructure & clang::clangd::ParsedAST::getIncludeStructure ( ) const

Definition at line 845 of file ParsedAST.cpp.

◆ getLangOpts()

const LangOptions & clang::clangd::ParsedAST::getLangOpts ( ) const
inline

Definition at line 84 of file ParsedAST.h.

References getASTContext().

◆ getLocalTopLevelDecls() [1/2]

llvm::ArrayRef< Decl * > clang::clangd::ParsedAST::getLocalTopLevelDecls ( )

This function returns top-level decls present in the main file of the AST.

The result does not include the decls that come from the preamble. (These should be const, but RecursiveASTVisitor requires Decl*).

Definition at line 802 of file ParsedAST.cpp.

◆ getLocalTopLevelDecls() [2/2]

llvm::ArrayRef< const Decl * > clang::clangd::ParsedAST::getLocalTopLevelDecls ( ) const

Definition at line 806 of file ParsedAST.cpp.

◆ getMacros()

const MainFileMacros & clang::clangd::ParsedAST::getMacros ( ) const

Gets all macro references (definition, expansions) present in the main file, including those in the preamble region.

Definition at line 810 of file ParsedAST.cpp.

◆ getMarks()

const std::vector< PragmaMark > & clang::clangd::ParsedAST::getMarks ( ) const

Gets all pragma marks in the main file.

Definition at line 811 of file ParsedAST.cpp.

◆ getPragmaIncludes()

const include_cleaner::PragmaIncludes & clang::clangd::ParsedAST::getPragmaIncludes ( ) const

Returns the PramaIncludes for preamble + main file includes.

Definition at line 869 of file ParsedAST.cpp.

◆ getPreprocessor() [1/2]

Preprocessor & clang::clangd::ParsedAST::getPreprocessor ( )

Definition at line 792 of file ParsedAST.cpp.

Referenced by getUsedBytes().

◆ getPreprocessor() [2/2]

const Preprocessor & clang::clangd::ParsedAST::getPreprocessor ( ) const

Definition at line 798 of file ParsedAST.cpp.

◆ getPreprocessorPtr()

std::shared_ptr< Preprocessor > clang::clangd::ParsedAST::getPreprocessorPtr ( )

Definition at line 794 of file ParsedAST.cpp.

◆ getSema()

Sema & clang::clangd::ParsedAST::getSema ( )

Definition at line 790 of file ParsedAST.cpp.

◆ getSourceManager() [1/2]

SourceManager & clang::clangd::ParsedAST::getSourceManager ( )
inline

Definition at line 77 of file ParsedAST.h.

References getASTContext().

◆ getSourceManager() [2/2]

const SourceManager & clang::clangd::ParsedAST::getSourceManager ( ) const
inline

Definition at line 80 of file ParsedAST.h.

References getASTContext().

◆ getTokens()

const syntax::TokenBuffer & clang::clangd::ParsedAST::getTokens ( ) const
inline

Tokens recorded while parsing the main file.

(!) does not have tokens from the preamble.

Definition at line 108 of file ParsedAST.h.

◆ getUsedBytes()

std::size_t clang::clangd::ParsedAST::getUsedBytes ( ) const

Returns the estimated size of the AST and the accessory structures, in bytes.

Does not include the size of the preamble.

Definition at line 813 of file ParsedAST.cpp.

References clang::clangd::AST, getASTContext(), and getPreprocessor().

◆ operator=() [1/2]

ParsedAST & clang::clangd::ParsedAST::operator= ( const ParsedAST & Other)
delete

References ParsedAST().

◆ operator=() [2/2]

ParsedAST & clang::clangd::ParsedAST::operator= ( ParsedAST && Other)
default

References ParsedAST().

◆ preambleVersion()

std::optional< llvm::StringRef > clang::clangd::ParsedAST::preambleVersion ( ) const

Returns the version of the ParseInputs used to build Preamble part of this AST.

Might be std::nullopt if no Preamble is used.

Definition at line 873 of file ParsedAST.cpp.

◆ tuPath()

PathRef clang::clangd::ParsedAST::tuPath ( ) const
inline

Returns the path passed by the caller when building this AST.

Definition at line 116 of file ParsedAST.h.

◆ version()

llvm::StringRef clang::clangd::ParsedAST::version ( ) const
inline

Returns the version of the ParseInputs this AST was built from.

Definition at line 113 of file ParsedAST.h.


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