1 //===--- SemaFixItUtils.h - Sema FixIts -------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines helper classes for generation of Sema FixItHints.
11 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_CLANG_SEMA_SEMAFIXITUTILS_H
13 #define LLVM_CLANG_SEMA_SEMAFIXITUTILS_H
15 #include "clang/AST/Expr.h"
19 enum OverloadFixItKind {
23 OFIK_RemoveDereference,
24 OFIK_RemoveTakeAddress
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.
32 struct ConversionFixItGenerator {
33 /// Performs a simple check to see if From type can be converted to To type.
34 static bool compareTypesSimple(CanQualType From,
38 ExprValueKind FromVK);
40 /// The list of Hints generated so far.
41 std::vector<FixItHint> Hints;
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.
45 unsigned NumConversionsFixed;
47 /// The type of fix applied. If multiple conversions are fixed, corresponds
48 /// to the kid of the very first conversion.
49 OverloadFixItKind Kind;
51 typedef bool (*TypeComparisonFuncTy) (const CanQualType FromTy,
52 const CanQualType ToTy,
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.
59 TypeComparisonFuncTy CompareTypes;
61 ConversionFixItGenerator(TypeComparisonFuncTy Foo): NumConversionsFixed(0),
65 ConversionFixItGenerator(): NumConversionsFixed(0),
67 CompareTypes(compareTypesSimple) {}
69 /// Resets the default conversion checker method.
70 void setConversionChecker(TypeComparisonFuncTy Foo) {
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,
81 NumConversionsFixed = 0;
85 return (NumConversionsFixed == 0);
89 } // endof namespace clang