150
|
1 //===--- FixItHintUtils.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_UTILS_FIXITHINTUTILS_H
|
|
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FIXITHINTUTILS_H
|
|
11
|
|
12 #include "clang/AST/ASTContext.h"
|
|
13 #include "clang/AST/Decl.h"
|
|
14 #include "clang/Sema/DeclSpec.h"
|
|
15
|
|
16 namespace clang {
|
|
17 namespace tidy {
|
|
18 namespace utils {
|
|
19 namespace fixit {
|
|
20
|
|
21 /// Creates fix to make ``VarDecl`` a reference by adding ``&``.
|
|
22 FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context);
|
|
23
|
|
24 /// Creates fix to make ``VarDecl`` const qualified.
|
|
25 FixItHint changeVarDeclToConst(const VarDecl &Var);
|
|
26
|
|
27 /// This enum defines where the qualifier shall be preferably added.
|
|
28 enum class QualifierPolicy {
|
|
29 Left, // Add the qualifier always to the left side, if that is possible.
|
|
30 Right, // Add the qualifier always to the right side.
|
|
31 };
|
|
32
|
|
33 /// This enum defines which entity is the target for adding the qualifier. This
|
|
34 /// makes only a difference for pointer-types. Other types behave identical
|
|
35 /// for either value of \c ConstTarget.
|
|
36 enum class QualifierTarget {
|
|
37 Pointee, /// Transforming a pointer attaches to the pointee and not the
|
|
38 /// pointer itself. For references and normal values this option has
|
|
39 /// no effect. `int * p = &i;` -> `const int * p = &i` or `int const
|
|
40 /// * p = &i`.
|
|
41 Value, /// Transforming pointers will consider the pointer itself.
|
|
42 /// `int * p = &i;` -> `int * const = &i`
|
|
43 };
|
|
44
|
|
45 /// \brief Creates fix to qualify ``VarDecl`` with the specified \c Qualifier.
|
|
46 /// Requires that `Var` is isolated in written code like in `int foo = 42;`.
|
|
47 Optional<FixItHint>
|
|
48 addQualifierToVarDecl(const VarDecl &Var, const ASTContext &Context,
|
|
49 DeclSpec::TQ Qualifier,
|
|
50 QualifierTarget CT = QualifierTarget::Pointee,
|
|
51 QualifierPolicy CP = QualifierPolicy::Left);
|
|
52 } // namespace fixit
|
|
53 } // namespace utils
|
|
54 } // namespace tidy
|
|
55 } // namespace clang
|
|
56
|
|
57 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FIXITHINTUTILS_H
|