clang 22.0.0git
FixitUtil.h
Go to the documentation of this file.
1//===- FixitUtil.h ----------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_ANALYSIS_SUPPORT_FIXITUTIL_H
10#define LLVM_CLANG_ANALYSIS_SUPPORT_FIXITUTIL_H
11
12#include "clang/AST/Decl.h"
13#include "clang/AST/Expr.h"
15#include "clang/Lex/Lexer.h"
16#include <optional>
17#include <string>
18
19namespace clang {
20
21// Returns the text of the pointee type of `T` from a `VarDecl` of a pointer
22// type. The text is obtained through from `TypeLoc`s. Since `TypeLoc` does not
23// have source ranges of qualifiers ( The `QualTypeLoc` looks hacky too me
24// :( ), `Qualifiers` of the pointee type is returned separately through the
25// output parameter `QualifiersToAppend`.
26std::optional<std::string>
27getPointeeTypeText(const DeclaratorDecl *VD, const SourceManager &SM,
28 const LangOptions &LangOpts,
29 std::optional<Qualifiers> *QualifiersToAppend);
30
31// returns text of pointee to pointee (T*&)
32std::optional<std::string>
34 const LangOptions &LangOpts,
35 std::optional<Qualifiers> *QualifiersToAppend);
36
38
39// Returns the literal text in `SourceRange SR`, if `SR` is a valid range.
40std::optional<StringRef> getRangeText(SourceRange SR, const SourceManager &SM,
41 const LangOptions &LangOpts);
42
43// Returns the literal text of the identifier of the given variable declaration.
44std::optional<StringRef> getVarDeclIdentifierText(const DeclaratorDecl *VD,
45 const SourceManager &SM,
46 const LangOptions &LangOpts);
47
48// Return text representation of an `Expr`.
49std::optional<StringRef> getExprText(const Expr *E, const SourceManager &SM,
50 const LangOptions &LangOpts);
51
52// Return the source location just past the last character of the AST `Node`.
53template <typename NodeTy>
54std::optional<SourceLocation> getPastLoc(const NodeTy *Node,
55 const SourceManager &SM,
56 const LangOptions &LangOpts) {
58 Lexer::getLocForEndOfToken(Node->getEndLoc(), 0, SM, LangOpts);
59 if (Loc.isValid())
60 return Loc;
61 return std::nullopt;
62}
63
64// Returns the begin location of the identifier of the given variable
65// declaration.
66SourceLocation getVarDeclIdentifierLoc(const DeclaratorDecl *VD);
67
68} // end namespace clang
69
70#endif /* LLVM_CLANG_ANALYSIS_SUPPORT_FIXITUTIL_H */
DynTypedNode Node
const Decl * D
Expr * E
#define SM(sm)
Definition: OffloadArch.cpp:16
SourceLocation Loc
Definition: SemaObjC.cpp:754
Defines the clang::SourceLocation class and associated facilities.
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:779
This represents one expression.
Definition: Expr.h:112
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:434
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
Definition: Lexer.cpp:848
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
The JSON file list parser is used to communicate input to InstallAPI.
SourceLocation getVarDeclIdentifierLoc(const DeclaratorDecl *VD)
Definition: FixitUtil.cpp:232
SourceLocation getBeginLocOfNestedIdentifier(const DeclaratorDecl *D)
Definition: FixitUtil.cpp:177
std::optional< StringRef > getExprText(const Expr *E, const SourceManager &SM, const LangOptions &LangOpts)
Definition: FixitUtil.cpp:217
std::optional< std::string > getPointeeTypeText(const DeclaratorDecl *VD, const SourceManager &SM, const LangOptions &LangOpts, std::optional< Qualifiers > *QualifiersToAppend)
Definition: FixitUtil.cpp:22
std::optional< std::string > getPointee2TypeText(const DeclaratorDecl *VD, const SourceManager &SM, const LangOptions &LangOpts, std::optional< Qualifiers > *QualifiersToAppend)
std::optional< StringRef > getRangeText(SourceRange SR, const SourceManager &SM, const LangOptions &LangOpts)
Definition: FixitUtil.cpp:185
std::optional< StringRef > getVarDeclIdentifierText(const DeclaratorDecl *VD, const SourceManager &SM, const LangOptions &LangOpts)
Definition: FixitUtil.cpp:199
std::optional< SourceLocation > getPastLoc(const NodeTy *Node, const SourceManager &SM, const LangOptions &LangOpts)
Definition: FixitUtil.h:54