brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 74608d4 Raw
58 lines · c
1//===----------------------------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FIXITHINTUTILS_H10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FIXITHINTUTILS_H11 12#include "clang/AST/ASTContext.h"13#include "clang/AST/Decl.h"14#include "clang/AST/Type.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. This29/// makes only a difference for pointer-types. Other types behave identical30/// for either value of \c ConstTarget.31enum class QualifierTarget {32  Pointee, /// Transforming a pointer attaches to the pointee and not the33           /// pointer itself. For references and normal values this option has34           /// no effect. `int * p = &i;` -> `const int * p = &i` or `int const35           /// * 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                      Qualifiers::TQ Qualifier,45                      QualifierTarget QualTarget = QualifierTarget::Pointee,46                      QualifierPolicy QualPolicy = QualifierPolicy::Left);47 48// \brief Format a pointer to an expression49std::string formatDereference(const Expr &ExprNode, const ASTContext &Context);50 51// \brief Checks whatever a expression require extra () to be always used in52// safe way in any other expression.53bool areParensNeededForStatement(const Stmt &Node);54 55} // namespace clang::tidy::utils::fixit56 57#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FIXITHINTUTILS_H58