| 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" |
| 14 | #include "clang/Basic/SourceLocation.h" |
| 15 | #include "clang/Lex/Lexer.h" |
| 16 | #include <optional> |
| 17 | #include <string> |
| 18 | |
| 19 | namespace 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`. |
| 26 | std::optional<std::string> |
| 27 | getPointeeTypeText(const DeclaratorDecl *VD, const SourceManager &SM, |
| 28 | const LangOptions &LangOpts, |
| 29 | std::optional<Qualifiers> *QualifiersToAppend); |
| 30 | |
| 31 | // returns text of pointee to pointee (T*&) |
| 32 | std::optional<std::string> |
| 33 | getPointee2TypeText(const DeclaratorDecl *VD, const SourceManager &SM, |
| 34 | const LangOptions &LangOpts, |
| 35 | std::optional<Qualifiers> *QualifiersToAppend); |
| 36 | |
| 37 | SourceLocation getBeginLocOfNestedIdentifier(const DeclaratorDecl *D); |
| 38 | |
| 39 | // Returns the literal text in `SourceRange SR`, if `SR` is a valid range. |
| 40 | std::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. |
| 44 | std::optional<StringRef> getVarDeclIdentifierText(const DeclaratorDecl *VD, |
| 45 | const SourceManager &SM, |
| 46 | const LangOptions &LangOpts); |
| 47 | |
| 48 | // Return text representation of an `Expr`. |
| 49 | std::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`. |
| 53 | template <typename NodeTy> |
| 54 | std::optional<SourceLocation> getPastLoc(const NodeTy *Node, |
| 55 | const SourceManager &SM, |
| 56 | const LangOptions &LangOpts) { |
| 57 | SourceLocation Loc = |
| 58 | Lexer::getLocForEndOfToken(Loc: Node->getEndLoc(), Offset: 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. |
| 66 | SourceLocation getVarDeclIdentifierLoc(const DeclaratorDecl *VD); |
| 67 | |
| 68 | } // end namespace clang |
| 69 | |
| 70 | #endif /* LLVM_CLANG_ANALYSIS_SUPPORT_FIXITUTIL_H */ |
| 71 | |