SemaFixItUtils.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- SemaFixItUtils.h - Sema FixIts -------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines helper classes for generation of Sema FixItHints.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CLANG_SEMA_SEMAFIXITUTILS_H
  18. #define LLVM_CLANG_SEMA_SEMAFIXITUTILS_H
  19. #include "clang/AST/Expr.h"
  20. namespace clang {
  21. enum OverloadFixItKind {
  22. OFIK_Undefined = 0,
  23. OFIK_Dereference,
  24. OFIK_TakeAddress,
  25. OFIK_RemoveDereference,
  26. OFIK_RemoveTakeAddress
  27. };
  28. class Sema;
  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. /// The list of Hints generated so far.
  40. std::vector<FixItHint> Hints;
  41. /// The number of Conversions fixed. This can be different from the size
  42. /// of the Hints vector since we allow multiple FixIts per conversion.
  43. unsigned NumConversionsFixed;
  44. /// The type of fix applied. If multiple conversions are fixed, corresponds
  45. /// to the kid of the very first conversion.
  46. OverloadFixItKind Kind;
  47. typedef bool (*TypeComparisonFuncTy) (const CanQualType FromTy,
  48. const CanQualType ToTy,
  49. Sema &S,
  50. SourceLocation Loc,
  51. ExprValueKind FromVK);
  52. /// The type comparison function used to decide if expression FromExpr of
  53. /// type FromTy can be converted to ToTy. For example, one could check if
  54. /// an implicit conversion exists. Returns true if comparison exists.
  55. TypeComparisonFuncTy CompareTypes;
  56. ConversionFixItGenerator(TypeComparisonFuncTy Foo): NumConversionsFixed(0),
  57. Kind(OFIK_Undefined),
  58. CompareTypes(Foo) {}
  59. ConversionFixItGenerator(): NumConversionsFixed(0),
  60. Kind(OFIK_Undefined),
  61. CompareTypes(compareTypesSimple) {}
  62. /// Resets the default conversion checker method.
  63. void setConversionChecker(TypeComparisonFuncTy Foo) {
  64. CompareTypes = Foo;
  65. }
  66. /// If possible, generates and stores a fix for the given conversion.
  67. bool tryToFixConversion(const Expr *FromExpr,
  68. const QualType FromQTy, const QualType ToQTy,
  69. Sema &S);
  70. void clear() {
  71. Hints.clear();
  72. NumConversionsFixed = 0;
  73. }
  74. bool isNull() {
  75. return (NumConversionsFixed == 0);
  76. }
  77. };
  78. } // endof namespace clang
  79. #endif
  80. #ifdef __GNUC__
  81. #pragma GCC diagnostic pop
  82. #endif