13 #include "clang/AST/DeclBase.h" 14 #include "clang/Basic/SourceLocation.h" 15 #include "llvm/Support/Error.h" 22 void addIfDistinct(
const Range &R, std::vector<Range> &Result) {
23 if (Result.empty() || Result.back() != R) {
31 std::vector<Range> Result;
35 auto FID = SM.getMainFileID();
43 for (
const auto *Node = ST.commonAncestor(); Node !=
nullptr;
44 Node = Node->Parent) {
45 if (
const Decl *D = Node->ASTNode.get<
Decl>()) {
46 if (llvm::isa<TranslationUnitDecl>(D)) {
52 if (!SR.hasValue() || SM.getFileID(SR->getBegin()) != SM.getMainFileID()) {
58 addIfDistinct(R, Result);
const FunctionDecl * Decl
Position start
The range's start position.
const LangOptions & getLangOpts() const
const syntax::TokenBuffer & getTokens() const
Tokens recorded while parsing the main file.
ASTContext & getASTContext()
Note that the returned ast will not contain decls from the preamble that were not deserialized during...
llvm::Expected< size_t > positionToOffset(llvm::StringRef Code, Position P, bool AllowColumnsBeyondLineLength)
Turn a [line, column] pair into an offset in Code.
llvm::Expected< std::vector< Range > > getSemanticRanges(ParsedAST &AST, Position Pos)
Returns the list of all interesting ranges around the Position Pos.
Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc)
Turn a SourceLocation into a [line, column] pair.
Stores and provides access to parsed AST.
llvm::Optional< SourceRange > toHalfOpenFileRange(const SourceManager &SM, const LangOptions &LangOpts, SourceRange R)
Turns a token range into a half-open range and checks its correctness.
SourceManager & getSourceManager()
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
CharSourceRange Range
SourceRange for the file name.
Position end
The range's end position.