clang-tools  14.0.0git
UseTrailingReturnTypeCheck.h
Go to the documentation of this file.
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 LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USETRAILINGRETURNTYPECHECK_H
11 
12 #include "../ClangTidyCheck.h"
13 #include "clang/Lex/Token.h"
14 
15 namespace clang {
16 namespace tidy {
17 namespace modernize {
18 
20  Token T;
23 };
24 
25 /// Rewrites function signatures to use a trailing return type.
26 ///
27 /// For the user-facing documentation see:
28 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize-use-trailing-type-return.html
30 public:
32  : ClangTidyCheck(Name, Context) {}
33  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
34  return LangOpts.CPlusPlus11;
35  }
36  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
37  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
38  Preprocessor *ModuleExpanderPP) override;
39  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
40 
41 private:
42  Preprocessor *PP = nullptr;
43 
44  SourceLocation findTrailingReturnTypeSourceLocation(
45  const FunctionDecl &F, const FunctionTypeLoc &FTL, const ASTContext &Ctx,
46  const SourceManager &SM, const LangOptions &LangOpts);
47  llvm::Optional<SmallVector<ClassifiedToken, 8>>
48  classifyTokensBeforeFunctionName(const FunctionDecl &F, const ASTContext &Ctx,
49  const SourceManager &SM,
50  const LangOptions &LangOpts);
51  SourceRange findReturnTypeAndCVSourceRange(const FunctionDecl &F,
52  const TypeLoc &ReturnLoc,
53  const ASTContext &Ctx,
54  const SourceManager &SM,
55  const LangOptions &LangOpts);
56  void keepSpecifiers(std::string &ReturnType, std::string &Auto,
57  SourceRange ReturnTypeCVRange, const FunctionDecl &F,
58  const FriendDecl *Fr, const ASTContext &Ctx,
59  const SourceManager &SM, const LangOptions &LangOpts);
60 };
61 
62 } // namespace modernize
63 } // namespace tidy
64 } // namespace clang
65 
66 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USETRAILINGRETURNTYPECHECK_H
clang::tidy::modernize::ClassifiedToken
Definition: UseTrailingReturnTypeCheck.h:19
clang::tidy::modernize::UseTrailingReturnTypeCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: UseTrailingReturnTypeCheck.cpp:420
clang::tidy::modernize::UseTrailingReturnTypeCheck
Rewrites function signatures to use a trailing return type.
Definition: UseTrailingReturnTypeCheck.h:29
clang::tidy::modernize::ClassifiedToken::IsSpecifier
bool IsSpecifier
Definition: UseTrailingReturnTypeCheck.h:22
Ctx
Context Ctx
Definition: TUScheduler.cpp:460
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:54
clang::tidy::modernize::ClassifiedToken::T
Token T
Definition: UseTrailingReturnTypeCheck.h:20
clang::tidy::modernize::UseTrailingReturnTypeCheck::registerPPCallbacks
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
Definition: UseTrailingReturnTypeCheck.cpp:415
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:72
clang::tidy::modernize::ClassifiedToken::IsQualifier
bool IsQualifier
Definition: UseTrailingReturnTypeCheck.h:21
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::tidy::modernize::UseTrailingReturnTypeCheck::UseTrailingReturnTypeCheck
UseTrailingReturnTypeCheck(StringRef Name, ClangTidyContext *Context)
Definition: UseTrailingReturnTypeCheck.h:31
clang::tidy::modernize::UseTrailingReturnTypeCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: UseTrailingReturnTypeCheck.cpp:405
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::modernize::UseTrailingReturnTypeCheck::isLanguageVersionSupported
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
Definition: UseTrailingReturnTypeCheck.h:33
ReturnType
std::string ReturnType
Definition: CodeComplete.cpp:433