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