FixItHintUtils.h 2.1 KB

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