1 | //===--- UseTrailingReturnTypeCheck.h - clang-tidy---------------*- 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_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USETRAILINGRETURNTYPECHECK_H |
10 | #define |
11 | |
12 | #include "../ClangTidyCheck.h" |
13 | #include "clang/Lex/Token.h" |
14 | #include <optional> |
15 | |
16 | namespace clang::tidy::modernize { |
17 | |
18 | struct ClassifiedToken { |
19 | Token T; |
20 | bool IsQualifier; |
21 | bool IsSpecifier; |
22 | }; |
23 | |
24 | /// Rewrites function signatures to use a trailing return type. |
25 | /// |
26 | /// For the user-facing documentation see: |
27 | /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-trailing-return-type.html |
28 | class UseTrailingReturnTypeCheck : public ClangTidyCheck { |
29 | public: |
30 | UseTrailingReturnTypeCheck(StringRef Name, ClangTidyContext *Context) |
31 | : ClangTidyCheck(Name, Context) {} |
32 | bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { |
33 | return LangOpts.CPlusPlus11; |
34 | } |
35 | void registerMatchers(ast_matchers::MatchFinder *Finder) override; |
36 | void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, |
37 | Preprocessor *ModuleExpanderPP) override; |
38 | void check(const ast_matchers::MatchFinder::MatchResult &Result) override; |
39 | |
40 | private: |
41 | Preprocessor *PP = nullptr; |
42 | |
43 | SourceLocation findTrailingReturnTypeSourceLocation( |
44 | const FunctionDecl &F, const FunctionTypeLoc &FTL, const ASTContext &Ctx, |
45 | const SourceManager &SM, const LangOptions &LangOpts); |
46 | std::optional<SmallVector<ClassifiedToken, 8>> |
47 | classifyTokensBeforeFunctionName(const FunctionDecl &F, const ASTContext &Ctx, |
48 | const SourceManager &SM, |
49 | const LangOptions &LangOpts); |
50 | SourceRange findReturnTypeAndCVSourceRange(const FunctionDecl &F, |
51 | const TypeLoc &ReturnLoc, |
52 | const ASTContext &Ctx, |
53 | const SourceManager &SM, |
54 | const LangOptions &LangOpts); |
55 | void keepSpecifiers(std::string &ReturnType, std::string &Auto, |
56 | SourceRange ReturnTypeCVRange, const FunctionDecl &F, |
57 | const FriendDecl *Fr, const ASTContext &Ctx, |
58 | const SourceManager &SM, const LangOptions &LangOpts); |
59 | }; |
60 | |
61 | } // namespace clang::tidy::modernize |
62 | |
63 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USETRAILINGRETURNTYPECHECK_H |
64 | |