clang-tools
10.0.0git
clang-tools-extra
clang-tidy
readability
NonConstParameterCheck.h
Go to the documentation of this file.
1
//===--- NonConstParameterCheck.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_READABILITY_NON_CONST_PARAMETER_H
10
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_NON_CONST_PARAMETER_H
11
12
#include "../ClangTidyCheck.h"
13
14
namespace
clang
{
15
namespace
tidy {
16
namespace
readability {
17
18
/// Warn when a pointer function parameter can be const.
19
///
20
/// For the user-facing documentation see:
21
/// http://clang.llvm.org/extra/clang-tidy/checks/readability-non-const-parameter.html
22
class
NonConstParameterCheck
:
public
ClangTidyCheck
{
23
public
:
24
NonConstParameterCheck
(StringRef
Name
,
ClangTidyContext
*Context)
25
:
ClangTidyCheck
(Name, Context) {}
26
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
27
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
28
void
onEndOfTranslationUnit
()
override
;
29
30
private
:
31
/// Parameter info.
32
struct
ParmInfo {
33
/// Is function parameter referenced?
34
bool
IsReferenced;
35
36
/// Can function parameter be const?
37
bool
CanBeConst;
38
};
39
40
/// Track all nonconst integer/float parameters.
41
std::map<const ParmVarDecl *, ParmInfo>
Parameters
;
42
43
/// Add function parameter.
44
void
addParm(
const
ParmVarDecl *Parm);
45
46
/// Set IsReferenced.
47
void
setReferenced(
const
DeclRefExpr *Ref);
48
49
/// Set CanNotBeConst.
50
/// Visits sub expressions recursively. If a DeclRefExpr is found
51
/// and CanNotBeConst is true the Parameter is marked as not-const.
52
/// The CanNotBeConst is updated as sub expressions are visited.
53
void
markCanNotBeConst(
const
Expr *
E
,
bool
CanNotBeConst);
54
55
/// Diagnose non const parameters.
56
void
diagnoseNonConstParameters();
57
};
58
59
}
// namespace readability
60
}
// namespace tidy
61
}
// namespace clang
62
63
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_NON_CONST_PARAMETER_H
clang::tidy::readability::NonConstParameterCheck::NonConstParameterCheck
NonConstParameterCheck(StringRef Name, ClangTidyContext *Context)
Definition:
NonConstParameterCheck.h:24
clang::tidy::readability::NonConstParameterCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
NonConstParameterCheck.cpp:19
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidyCheck.h:47
clang::tidy::readability::NonConstParameterCheck::onEndOfTranslationUnit
void onEndOfTranslationUnit() override
Definition:
NonConstParameterCheck.cpp:123
clang::tidy::readability::NonConstParameterCheck
Warn when a pointer function parameter can be const.
Definition:
NonConstParameterCheck.h:22
Name
static constexpr llvm::StringLiteral Name
Definition:
UppercaseLiteralSuffixCheck.cpp:27
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition:
ApplyReplacements.h:27
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:77
E
const Expr * E
Definition:
AvoidBindCheck.cpp:82
Parameters
std::vector< Parameter > Parameters
Definition:
ExtractFunction.cpp:303
clang::tidy::readability::NonConstParameterCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
NonConstParameterCheck.cpp:40
Generated on Thu Jan 30 2020 19:09:37 for clang-tools by
1.8.13