1 //===--- SemaFixItUtils.h - Sema FixIts -----------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines helper classes for generation of Sema FixItHints.
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_SEMA_FIXITUTILS_H
14 #define LLVM_CLANG_SEMA_FIXITUTILS_H
16 #include "clang/AST/Expr.h"
20 enum OverloadFixItKind {
24 OFIK_RemoveDereference,
25 OFIK_RemoveTakeAddress
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.
33 struct ConversionFixItGenerator {
34 /// Performs a simple check to see if From type can be converted to To type.
35 static bool compareTypesSimple(CanQualType From,
39 ExprValueKind FromVK);
41 /// The list of Hints generated so far.
42 std::vector<FixItHint> Hints;
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.
46 unsigned NumConversionsFixed;
48 /// The type of fix applied. If multiple conversions are fixed, corresponds
49 /// to the kid of the very first conversion.
50 OverloadFixItKind Kind;
52 typedef bool (*TypeComparisonFuncTy) (const CanQualType FromTy,
53 const CanQualType ToTy,
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.
60 TypeComparisonFuncTy CompareTypes;
62 ConversionFixItGenerator(TypeComparisonFuncTy Foo): NumConversionsFixed(0),
66 ConversionFixItGenerator(): NumConversionsFixed(0),
68 CompareTypes(compareTypesSimple) {}
70 /// Resets the default conversion checker method.
71 void setConversionChecker(TypeComparisonFuncTy Foo) {
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,
82 NumConversionsFixed = 0;
86 return (NumConversionsFixed == 0);
90 } // endof namespace clang
91 #endif // LLVM_CLANG_SEMA_FIXITUTILS_H