annotate clang-tools-extra/clang-tidy/cppcoreguidelines/NoMallocCheck.h @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===--- NoMallocCheck.h - clang-tidy----------------------------*- C++ -*-===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H
anatofuz
parents:
diff changeset
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 #include "../ClangTidy.h"
anatofuz
parents:
diff changeset
13 #include "clang/AST/ASTContext.h"
anatofuz
parents:
diff changeset
14 #include "clang/ASTMatchers/ASTMatchFinder.h"
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 namespace clang {
anatofuz
parents:
diff changeset
17 namespace tidy {
anatofuz
parents:
diff changeset
18 namespace cppcoreguidelines {
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 /// This checker is concerned with C-style memory management and suggest modern
anatofuz
parents:
diff changeset
21 /// alternatives to it.
anatofuz
parents:
diff changeset
22 /// The check is only enabled in C++. For analyzing malloc calls see Clang
anatofuz
parents:
diff changeset
23 /// Static Analyzer - unix.Malloc.
anatofuz
parents:
diff changeset
24 ///
anatofuz
parents:
diff changeset
25 /// For the user-facing documentation see:
anatofuz
parents:
diff changeset
26 /// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-no-malloc.html
anatofuz
parents:
diff changeset
27 class NoMallocCheck : public ClangTidyCheck {
anatofuz
parents:
diff changeset
28 public:
anatofuz
parents:
diff changeset
29 /// Construct Checker and read in configuration for function names.
anatofuz
parents:
diff changeset
30 NoMallocCheck(StringRef Name, ClangTidyContext *Context)
anatofuz
parents:
diff changeset
31 : ClangTidyCheck(Name, Context),
anatofuz
parents:
diff changeset
32 AllocList(Options.get("Allocations", "::malloc;::calloc")),
anatofuz
parents:
diff changeset
33 ReallocList(Options.get("Reallocations", "::realloc")),
anatofuz
parents:
diff changeset
34 DeallocList(Options.get("Deallocations", "::free")) {}
anatofuz
parents:
diff changeset
35
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
36 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
37 return LangOpts.CPlusPlus;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
38 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
39
150
anatofuz
parents:
diff changeset
40 /// Make configuration of checker discoverable.
anatofuz
parents:
diff changeset
41 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 /// Registering for malloc, calloc, realloc and free calls.
anatofuz
parents:
diff changeset
44 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 /// Checks matched function calls and gives suggestion to modernize the code.
anatofuz
parents:
diff changeset
47 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
anatofuz
parents:
diff changeset
48
anatofuz
parents:
diff changeset
49 private:
anatofuz
parents:
diff changeset
50 /// Semicolon-separated list of fully qualified names of memory allocation
anatofuz
parents:
diff changeset
51 /// functions the check warns about. Defaults to `::malloc;::calloc`.
anatofuz
parents:
diff changeset
52 const std::string AllocList;
anatofuz
parents:
diff changeset
53 /// Semicolon-separated list of fully qualified names of memory reallocation
anatofuz
parents:
diff changeset
54 /// functions the check warns about. Defaults to `::realloc`.
anatofuz
parents:
diff changeset
55 const std::string ReallocList;
anatofuz
parents:
diff changeset
56 /// Semicolon-separated list of fully qualified names of memory deallocation
anatofuz
parents:
diff changeset
57 /// functions the check warns about. Defaults to `::free`.
anatofuz
parents:
diff changeset
58 const std::string DeallocList;
anatofuz
parents:
diff changeset
59 };
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 } // namespace cppcoreguidelines
anatofuz
parents:
diff changeset
62 } // namespace tidy
anatofuz
parents:
diff changeset
63 } // namespace clang
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H