Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:22

0001 //===--- FixItHintUtils.h - clang-tidy---------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FIXITHINTUTILS_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FIXITHINTUTILS_H
0011 
0012 #include "clang/AST/ASTContext.h"
0013 #include "clang/AST/Decl.h"
0014 #include "clang/AST/Type.h"
0015 #include <optional>
0016 
0017 namespace clang::tidy::utils::fixit {
0018 
0019 /// Creates fix to make ``VarDecl`` a reference by adding ``&``.
0020 FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context);
0021 
0022 /// This enum defines where the qualifier shall be preferably added.
0023 enum class QualifierPolicy {
0024   Left,  // Add the qualifier always to the left side, if that is possible.
0025   Right, // Add the qualifier always to the right side.
0026 };
0027 
0028 /// This enum defines which entity is the target for adding the qualifier. This
0029 /// makes only a difference for pointer-types. Other types behave identical
0030 /// for either value of \c ConstTarget.
0031 enum class QualifierTarget {
0032   Pointee, /// Transforming a pointer attaches to the pointee and not the
0033            /// pointer itself. For references and normal values this option has
0034            /// no effect. `int * p = &i;` -> `const int * p = &i` or `int const
0035            /// * p = &i`.
0036   Value,   /// Transforming pointers will consider the pointer itself.
0037            /// `int * p = &i;` -> `int * const = &i`
0038 };
0039 
0040 /// \brief Creates fix to qualify ``VarDecl`` with the specified \c Qualifier.
0041 /// Requires that `Var` is isolated in written code like in `int foo = 42;`.
0042 std::optional<FixItHint>
0043 addQualifierToVarDecl(const VarDecl &Var, const ASTContext &Context,
0044                       Qualifiers::TQ Qualifier,
0045                       QualifierTarget QualTarget = QualifierTarget::Pointee,
0046                       QualifierPolicy QualPolicy = QualifierPolicy::Left);
0047 
0048 // \brief Format a pointer to an expression
0049 std::string formatDereference(const Expr &ExprNode, const ASTContext &Context);
0050 
0051 // \brief Checks whatever a expression require extra () to be always used in
0052 // safe way in any other expression.
0053 bool areParensNeededForStatement(const Stmt &Node);
0054 
0055 } // namespace clang::tidy::utils::fixit
0056 
0057 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FIXITHINTUTILS_H