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#include <optional>
16
17namespace clang::tidy::utils::fixit {
18
19/// Creates fix to make ``VarDecl`` a reference by adding ``&``.
20FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context);
21
22/// This enum defines where the qualifier shall be preferably added.
23enum 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.
26};
27
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.
31enum 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
35 /// * p = &i`.
36 Value, /// Transforming pointers will consider the pointer itself.
37 /// `int * p = &i;` -> `int * const = &i`
38};
39
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;`.
42std::optional<FixItHint>
43addQualifierToVarDecl(const VarDecl &Var, const ASTContext &Context,
44 DeclSpec::TQ Qualifier,
45 QualifierTarget QualTarget = QualifierTarget::Pointee,
46 QualifierPolicy QualPolicy = QualifierPolicy::Left);
47
48// \brief Format a pointer to an expression
49std::string formatDereference(const Expr &ExprNode, const ASTContext &Context);
50
51// \brief Checks whatever a expression require extra () to be always used in
52// safe way in any other expression.
53bool areParensNeededForStatement(const Stmt &Node);
54
55} // namespace clang::tidy::utils::fixit
56
57#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FIXITHINTUTILS_H
58

source code of clang-tools-extra/clang-tidy/utils/FixItHintUtils.h