clang  6.0.0svn
SemaFixItUtils.h
Go to the documentation of this file.
1 //===--- SemaFixItUtils.h - Sema FixIts -----------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines helper classes for generation of Sema FixItHints.
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_SEMA_SEMAFIXITUTILS_H
14 #define LLVM_CLANG_SEMA_SEMAFIXITUTILS_H
15 
16 #include "clang/AST/Expr.h"
17 
18 namespace clang {
19 
26 };
27 
28 class Sema;
29 
30 /// The class facilities generation and storage of conversion FixIts. Hints for
31 /// new conversions are added using TryToFixConversion method. The default type
32 /// conversion checker can be reset.
34  /// Performs a simple check to see if From type can be converted to To type.
35  static bool compareTypesSimple(CanQualType From,
36  CanQualType To,
37  Sema &S,
38  SourceLocation Loc,
39  ExprValueKind FromVK);
40 
41  /// The list of Hints generated so far.
42  std::vector<FixItHint> Hints;
43 
44  /// The number of Conversions fixed. This can be different from the size
45  /// of the Hints vector since we allow multiple FixIts per conversion.
47 
48  /// The type of fix applied. If multiple conversions are fixed, corresponds
49  /// to the kid of the very first conversion.
51 
52  typedef bool (*TypeComparisonFuncTy) (const CanQualType FromTy,
53  const CanQualType ToTy,
54  Sema &S,
55  SourceLocation Loc,
56  ExprValueKind FromVK);
57  /// The type comparison function used to decide if expression FromExpr of
58  /// type FromTy can be converted to ToTy. For example, one could check if
59  /// an implicit conversion exists. Returns true if comparison exists.
61 
62  ConversionFixItGenerator(TypeComparisonFuncTy Foo): NumConversionsFixed(0),
63  Kind(OFIK_Undefined),
64  CompareTypes(Foo) {}
65 
66  ConversionFixItGenerator(): NumConversionsFixed(0),
67  Kind(OFIK_Undefined),
68  CompareTypes(compareTypesSimple) {}
69 
70  /// Resets the default conversion checker method.
72  CompareTypes = Foo;
73  }
74 
75  /// If possible, generates and stores a fix for the given conversion.
76  bool tryToFixConversion(const Expr *FromExpr,
77  const QualType FromQTy, const QualType ToQTy,
78  Sema &S);
79 
80  void clear() {
81  Hints.clear();
82  NumConversionsFixed = 0;
83  }
84 
85  bool isNull() {
86  return (NumConversionsFixed == 0);
87  }
88 };
89 
90 } // endof namespace clang
91 #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:653
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:274
Expr - This represents one expression.
Definition: Expr.h:106
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:104
#define bool
Definition: stdbool.h:31
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.