Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:37:04

0001 //===--- SemaFixItUtils.h - Sema FixIts -------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file defines helper classes for generation of Sema FixItHints.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 #ifndef LLVM_CLANG_SEMA_SEMAFIXITUTILS_H
0013 #define LLVM_CLANG_SEMA_SEMAFIXITUTILS_H
0014 
0015 #include "clang/AST/Expr.h"
0016 
0017 namespace clang {
0018 
0019 enum OverloadFixItKind {
0020   OFIK_Undefined = 0,
0021   OFIK_Dereference,
0022   OFIK_TakeAddress,
0023   OFIK_RemoveDereference,
0024   OFIK_RemoveTakeAddress
0025 };
0026 
0027 class Sema;
0028 
0029 /// The class facilities generation and storage of conversion FixIts. Hints for
0030 /// new conversions are added using TryToFixConversion method. The default type
0031 /// conversion checker can be reset.
0032 struct ConversionFixItGenerator {
0033   /// Performs a simple check to see if From type can be converted to To type.
0034   static bool compareTypesSimple(CanQualType From,
0035                                  CanQualType To,
0036                                  Sema &S,
0037                                  SourceLocation Loc,
0038                                  ExprValueKind FromVK);
0039 
0040   /// The list of Hints generated so far.
0041   std::vector<FixItHint> Hints;
0042 
0043   /// The number of Conversions fixed. This can be different from the size
0044   /// of the Hints vector since we allow multiple FixIts per conversion.
0045   unsigned NumConversionsFixed;
0046 
0047   /// The type of fix applied. If multiple conversions are fixed, corresponds
0048   /// to the kid of the very first conversion.
0049   OverloadFixItKind Kind;
0050 
0051   typedef bool (*TypeComparisonFuncTy) (const CanQualType FromTy,
0052                                         const CanQualType ToTy,
0053                                         Sema &S,
0054                                         SourceLocation Loc,
0055                                         ExprValueKind FromVK);
0056   /// The type comparison function used to decide if expression FromExpr of
0057   /// type FromTy can be converted to ToTy. For example, one could check if
0058   /// an implicit conversion exists. Returns true if comparison exists.
0059   TypeComparisonFuncTy CompareTypes;
0060 
0061   ConversionFixItGenerator(TypeComparisonFuncTy Foo): NumConversionsFixed(0),
0062                                                       Kind(OFIK_Undefined),
0063                                                       CompareTypes(Foo) {}
0064 
0065   ConversionFixItGenerator(): NumConversionsFixed(0),
0066                               Kind(OFIK_Undefined),
0067                               CompareTypes(compareTypesSimple) {}
0068 
0069   /// Resets the default conversion checker method.
0070   void setConversionChecker(TypeComparisonFuncTy Foo) {
0071     CompareTypes = Foo;
0072   }
0073 
0074   /// If possible, generates and stores a fix for the given conversion.
0075   bool tryToFixConversion(const Expr *FromExpr,
0076                           const QualType FromQTy, const QualType ToQTy,
0077                           Sema &S);
0078 
0079   void clear() {
0080     Hints.clear();
0081     NumConversionsFixed = 0;
0082   }
0083 
0084   bool isNull() {
0085     return (NumConversionsFixed == 0);
0086   }
0087 };
0088 
0089 } // endof namespace clang
0090 #endif