AvailabilityInfo.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ExtractAPI/AvailabilityInfo.h - Availability Info --------*- 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. /// \file
  15. /// This file defines the AvailabilityInfo struct that collects availability
  16. /// attributes of a symbol.
  17. ///
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_CLANG_EXTRACTAPI_AVAILABILITY_INFO_H
  20. #define LLVM_CLANG_EXTRACTAPI_AVAILABILITY_INFO_H
  21. #include "clang/AST/Decl.h"
  22. #include "llvm/ADT/SmallVector.h"
  23. #include "llvm/Support/Error.h"
  24. #include "llvm/Support/VersionTuple.h"
  25. #include "llvm/Support/raw_ostream.h"
  26. using llvm::VersionTuple;
  27. namespace clang {
  28. namespace extractapi {
  29. /// Stores availability attributes of a symbol in a given domain.
  30. struct AvailabilityInfo {
  31. /// The domain for which this availability info item applies
  32. std::string Domain;
  33. VersionTuple Introduced;
  34. VersionTuple Deprecated;
  35. VersionTuple Obsoleted;
  36. AvailabilityInfo() = default;
  37. AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
  38. VersionTuple O)
  39. : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O) {}
  40. };
  41. class AvailabilitySet {
  42. private:
  43. using AvailabilityList = llvm::SmallVector<AvailabilityInfo, 4>;
  44. AvailabilityList Availabilities;
  45. bool UnconditionallyDeprecated = false;
  46. bool UnconditionallyUnavailable = false;
  47. public:
  48. AvailabilitySet(const Decl *Decl);
  49. AvailabilitySet() = default;
  50. AvailabilityList::const_iterator begin() const {
  51. return Availabilities.begin();
  52. }
  53. AvailabilityList::const_iterator end() const { return Availabilities.end(); }
  54. /// Check if the symbol is unconditionally deprecated.
  55. ///
  56. /// i.e. \code __attribute__((deprecated)) \endcode
  57. bool isUnconditionallyDeprecated() const { return UnconditionallyDeprecated; }
  58. /// Check if the symbol is unconditionally unavailable.
  59. ///
  60. /// i.e. \code __attribute__((unavailable)) \endcode
  61. bool isUnconditionallyUnavailable() const {
  62. return UnconditionallyUnavailable;
  63. }
  64. /// Determine if this AvailabilitySet represents default availability.
  65. bool isDefault() const { return Availabilities.empty(); }
  66. };
  67. } // namespace extractapi
  68. } // namespace clang
  69. #endif // LLVM_CLANG_EXTRACTAPI_AVAILABILITY_INFO_H
  70. #ifdef __GNUC__
  71. #pragma GCC diagnostic pop
  72. #endif