clang  14.0.0git
SemaFixItUtils.h
Go to the documentation of this file.
1 //===--- SemaFixItUtils.h - Sema FixIts -------------------------*- 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 // This file defines helper classes for generation of Sema FixItHints.
10 //
11 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_CLANG_SEMA_SEMAFIXITUTILS_H
13 #define LLVM_CLANG_SEMA_SEMAFIXITUTILS_H
14 
15 #include "clang/AST/Expr.h"
16 
17 namespace clang {
18 
25 };
26 
27 class Sema;
28 
29 /// The class facilities generation and storage of conversion FixIts. Hints for
30 /// new conversions are added using TryToFixConversion method. The default type
31 /// conversion checker can be reset.
33  /// Performs a simple check to see if From type can be converted to To type.
34  static bool compareTypesSimple(CanQualType From,
35  CanQualType To,
36  Sema &S,
37  SourceLocation Loc,
38  ExprValueKind FromVK);
39 
40  /// The list of Hints generated so far.
41  std::vector<FixItHint> Hints;
42 
43  /// The number of Conversions fixed. This can be different from the size
44  /// of the Hints vector since we allow multiple FixIts per conversion.
46 
47  /// The type of fix applied. If multiple conversions are fixed, corresponds
48  /// to the kid of the very first conversion.
50 
51  typedef bool (*TypeComparisonFuncTy) (const CanQualType FromTy,
52  const CanQualType ToTy,
53  Sema &S,
54  SourceLocation Loc,
55  ExprValueKind FromVK);
56  /// The type comparison function used to decide if expression FromExpr of
57  /// type FromTy can be converted to ToTy. For example, one could check if
58  /// an implicit conversion exists. Returns true if comparison exists.
60 
63  CompareTypes(Foo) {}
64 
68 
69  /// Resets the default conversion checker method.
71  CompareTypes = Foo;
72  }
73 
74  /// If possible, generates and stores a fix for the given conversion.
75  bool tryToFixConversion(const Expr *FromExpr,
76  const QualType FromQTy, const QualType ToQTy,
77  Sema &S);
78 
79  void clear() {
80  Hints.clear();
82  }
83 
84  bool isNull() {
85  return (NumConversionsFixed == 0);
86  }
87 };
88 
89 } // endof namespace clang
90 #endif
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
clang::ConversionFixItGenerator
The class facilities generation and storage of conversion FixIts.
Definition: SemaFixItUtils.h:32
clang::ConversionFixItGenerator::setConversionChecker
void setConversionChecker(TypeComparisonFuncTy Foo)
Resets the default conversion checker method.
Definition: SemaFixItUtils.h:70
clang::ConversionFixItGenerator::tryToFixConversion
bool tryToFixConversion(const Expr *FromExpr, const QualType FromQTy, const QualType ToQTy, Sema &S)
If possible, generates and stores a fix for the given conversion.
Definition: SemaFixItUtils.cpp:50
clang::ConversionFixItGenerator::Hints
std::vector< FixItHint > Hints
The list of Hints generated so far.
Definition: SemaFixItUtils.h:41
clang::ConversionFixItGenerator::NumConversionsFixed
unsigned NumConversionsFixed
The number of Conversions fixed.
Definition: SemaFixItUtils.h:45
Expr.h
bool
#define bool
Definition: stdbool.h:15
clang::ConversionFixItGenerator::compareTypesSimple
static bool compareTypesSimple(CanQualType From, CanQualType To, Sema &S, SourceLocation Loc, ExprValueKind FromVK)
Performs a simple check to see if From type can be converted to To type.
Definition: SemaFixItUtils.cpp:22
clang::CanQual< Type >
clang::ConversionFixItGenerator::clear
void clear()
Definition: SemaFixItUtils.h:79
clang::ConversionFixItGenerator::TypeComparisonFuncTy
bool(* TypeComparisonFuncTy)(const CanQualType FromTy, const CanQualType ToTy, Sema &S, SourceLocation Loc, ExprValueKind FromVK)
Definition: SemaFixItUtils.h:51
clang::ConversionFixItGenerator::Kind
OverloadFixItKind Kind
The type of fix applied.
Definition: SemaFixItUtils.h:49
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:355
clang::ExprValueKind
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:117
clang::OFIK_TakeAddress
@ OFIK_TakeAddress
Definition: SemaFixItUtils.h:22
clang
Definition: CalledOnceCheck.h:17
clang::ConversionFixItGenerator::ConversionFixItGenerator
ConversionFixItGenerator(TypeComparisonFuncTy Foo)
Definition: SemaFixItUtils.h:61
clang::ConversionFixItGenerator::CompareTypes
TypeComparisonFuncTy CompareTypes
The type comparison function used to decide if expression FromExpr of type FromTy can be converted to...
Definition: SemaFixItUtils.h:59
clang::ConversionFixItGenerator::isNull
bool isNull()
Definition: SemaFixItUtils.h:84
clang::ConversionFixItGenerator::ConversionFixItGenerator
ConversionFixItGenerator()
Definition: SemaFixItUtils.h:65
clang::OFIK_Undefined
@ OFIK_Undefined
Definition: SemaFixItUtils.h:20
clang::OFIK_RemoveDereference
@ OFIK_RemoveDereference
Definition: SemaFixItUtils.h:23
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::OFIK_RemoveTakeAddress
@ OFIK_RemoveTakeAddress
Definition: SemaFixItUtils.h:24
clang::OFIK_Dereference
@ OFIK_Dereference
Definition: SemaFixItUtils.h:21
clang::OverloadFixItKind
OverloadFixItKind
Definition: SemaFixItUtils.h:19