Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

Blame | Last modification | View Log | Download | RSS feed

  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.  
  17. namespace clang {
  18.  
  19. enum OverloadFixItKind {
  20.   OFIK_Undefined = 0,
  21.   OFIK_Dereference,
  22.   OFIK_TakeAddress,
  23.   OFIK_RemoveDereference,
  24.   OFIK_RemoveTakeAddress
  25. };
  26.  
  27. class 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.
  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,
  35.                                  CanQualType To,
  36.                                  Sema &S,
  37.                                  SourceLocation Loc,
  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.
  45.   unsigned NumConversionsFixed;
  46.  
  47.   /// The type of fix applied. If multiple conversions are fixed, corresponds
  48.   /// to the kid of the very first conversion.
  49.   OverloadFixItKind Kind;
  50.  
  51.   typedef bool (*TypeComparisonFuncTy) (const CanQualType FromTy,
  52.                                         const CanQualType ToTy,
  53.                                         Sema &S,
  54.                                         SourceLocation Loc,
  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;
  60.  
  61.   ConversionFixItGenerator(TypeComparisonFuncTy Foo): NumConversionsFixed(0),
  62.                                                       Kind(OFIK_Undefined),
  63.                                                       CompareTypes(Foo) {}
  64.  
  65.   ConversionFixItGenerator(): NumConversionsFixed(0),
  66.                               Kind(OFIK_Undefined),
  67.                               CompareTypes(compareTypesSimple) {}
  68.  
  69.   /// Resets the default conversion checker method.
  70.   void setConversionChecker(TypeComparisonFuncTy Foo) {
  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();
  81.     NumConversionsFixed = 0;
  82.   }
  83.  
  84.   bool isNull() {
  85.     return (NumConversionsFixed == 0);
  86.   }
  87. };
  88.  
  89. } // endof namespace clang
  90. #endif
  91.