clang 19.0.0git
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
17namespace clang {
18
25};
26
27class 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,
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,
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
63 CompareTypes(Foo) {}
64
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();
82 }
83
84 bool isNull() {
85 return (NumConversionsFixed == 0);
86 }
87};
88
89} // endof namespace clang
90#endif
This represents one expression.
Definition: Expr.h:110
A (possibly-)qualified type.
Definition: Type.h:738
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:457
Encodes a location in the source.
The JSON file list parser is used to communicate input to InstallAPI.
OverloadFixItKind
@ OFIK_Dereference
@ OFIK_TakeAddress
@ OFIK_RemoveDereference
@ OFIK_RemoveTakeAddress
@ OFIK_Undefined
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:129
#define bool
Definition: stdbool.h:20
The class facilities generation and storage of conversion FixIts.
OverloadFixItKind Kind
The type of fix applied.
unsigned NumConversionsFixed
The number of Conversions fixed.
bool(* TypeComparisonFuncTy)(const CanQualType FromTy, const CanQualType ToTy, Sema &S, SourceLocation Loc, ExprValueKind FromVK)
TypeComparisonFuncTy CompareTypes
The type comparison function used to decide if expression FromExpr of type FromTy can be converted to...
ConversionFixItGenerator(TypeComparisonFuncTy Foo)
void setConversionChecker(TypeComparisonFuncTy Foo)
Resets the default conversion checker method.
bool tryToFixConversion(const Expr *FromExpr, const QualType FromQTy, const QualType ToQTy, Sema &S)
If possible, generates and stores a fix for the given conversion.
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.
std::vector< FixItHint > Hints
The list of Hints generated so far.