clang  10.0.0svn
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 
61  ConversionFixItGenerator(TypeComparisonFuncTy Foo): NumConversionsFixed(0),
62  Kind(OFIK_Undefined),
63  CompareTypes(Foo) {}
64 
65  ConversionFixItGenerator(): NumConversionsFixed(0),
66  Kind(OFIK_Undefined),
67  CompareTypes(compareTypesSimple) {}
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();
81  NumConversionsFixed = 0;
82  }
83 
84  bool isNull() {
85  return (NumConversionsFixed == 0);
86  }
87 };
88 
89 } // endof namespace clang
90 #endif
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.
A (possibly-)qualified type.
Definition: Type.h:643
bool tryToFixConversion(const Expr *FromExpr, const QualType FromQTy, const QualType ToQTy, Sema &S)
If possible, generates and stores a fix for the given conversion.
std::vector< FixItHint > Hints
The list of Hints generated so far.
bool(* TypeComparisonFuncTy)(const CanQualType FromTy, const CanQualType ToTy, Sema &S, SourceLocation Loc, ExprValueKind FromVK)
OverloadFixItKind Kind
The type of fix applied.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:331
This represents one expression.
Definition: Expr.h:108
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:122
#define bool
Definition: stdbool.h:15
OverloadFixItKind
ConversionFixItGenerator(TypeComparisonFuncTy Foo)
TypeComparisonFuncTy CompareTypes
The type comparison function used to decide if expression FromExpr of type FromTy can be converted to...
Encodes a location in the source.
Dataflow Directional Tag Classes.
void setConversionChecker(TypeComparisonFuncTy Foo)
Resets the default conversion checker method.
The class facilities generation and storage of conversion FixIts.
unsigned NumConversionsFixed
The number of Conversions fixed.