clang  3.7.0
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 
64  CompareTypes(Foo) {}
65 
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();
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.
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.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:258
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:92
#define bool
Definition: stdbool.h:31
OverloadFixItKind
ConversionFixItGenerator(TypeComparisonFuncTy Foo)
TypeComparisonFuncTy CompareTypes
Kind
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
bool(* TypeComparisonFuncTy)(const CanQualType FromTy, const CanQualType ToTy, Sema &S, SourceLocation Loc, ExprValueKind FromVK)
void setConversionChecker(TypeComparisonFuncTy Foo)
Resets the default conversion checker method.