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