/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
|*                                                                            *|
|* Enum Utility Definitions                                                   *|
|*                                                                            *|
|* Automatically generated file, do not edit!                                 *|
|* From: FIRAttr.td                                                           *|
|*                                                                            *|
\*===----------------------------------------------------------------------===*/

namespace fir {
::llvm::StringRef stringifyBoxFieldAttr(BoxFieldAttr val) {
  switch (val) {
    case BoxFieldAttr::base_addr: return "base_addr";
    case BoxFieldAttr::derived_type: return "derived_type";
  }
  return "";
}

::std::optional<BoxFieldAttr> symbolizeBoxFieldAttr(::llvm::StringRef str) {
  return ::llvm::StringSwitch<::std::optional<BoxFieldAttr>>(str)
      .Case("base_addr", BoxFieldAttr::base_addr)
      .Case("derived_type", BoxFieldAttr::derived_type)
      .Default(::std::nullopt);
}
::std::optional<BoxFieldAttr> symbolizeBoxFieldAttr(uint32_t value) {
  switch (value) {
  case 0: return BoxFieldAttr::base_addr;
  case 1: return BoxFieldAttr::derived_type;
  default: return ::std::nullopt;
  }
}

bool BoxFieldAttrAttr::classof(::mlir::Attribute attr) {
  return (((::llvm::isa<::mlir::IntegerAttr>(attr))) && ((::llvm::cast<::mlir::IntegerAttr>(attr).getType().isSignlessInteger(32)))) && (((::llvm::cast<::mlir::IntegerAttr>(attr).getInt() == 0)) || ((::llvm::cast<::mlir::IntegerAttr>(attr).getInt() == 1)));
}
BoxFieldAttrAttr BoxFieldAttrAttr::get(::mlir::MLIRContext *context, BoxFieldAttr val) {
  ::mlir::IntegerType intType = ::mlir::IntegerType::get(context, 32);
  ::mlir::IntegerAttr baseAttr = ::mlir::IntegerAttr::get(intType, static_cast<uint32_t>(val));
  return ::llvm::cast<BoxFieldAttrAttr>(baseAttr);
}
BoxFieldAttr BoxFieldAttrAttr::getValue() const {
  return static_cast<BoxFieldAttr>(::mlir::IntegerAttr::getInt());
}
} // namespace fir

namespace fir {
::llvm::StringRef stringifyCUDADataAttribute(CUDADataAttribute val) {
  switch (val) {
    case CUDADataAttribute::Constant: return "constant";
    case CUDADataAttribute::Device: return "device";
    case CUDADataAttribute::Managed: return "managed";
    case CUDADataAttribute::Pinned: return "pinned";
    case CUDADataAttribute::Shared: return "shared";
    case CUDADataAttribute::Unified: return "unified";
  }
  return "";
}

::std::optional<CUDADataAttribute> symbolizeCUDADataAttribute(::llvm::StringRef str) {
  return ::llvm::StringSwitch<::std::optional<CUDADataAttribute>>(str)
      .Case("constant", CUDADataAttribute::Constant)
      .Case("device", CUDADataAttribute::Device)
      .Case("managed", CUDADataAttribute::Managed)
      .Case("pinned", CUDADataAttribute::Pinned)
      .Case("shared", CUDADataAttribute::Shared)
      .Case("unified", CUDADataAttribute::Unified)
      .Default(::std::nullopt);
}
::std::optional<CUDADataAttribute> symbolizeCUDADataAttribute(uint32_t value) {
  switch (value) {
  case 0: return CUDADataAttribute::Constant;
  case 1: return CUDADataAttribute::Device;
  case 2: return CUDADataAttribute::Managed;
  case 3: return CUDADataAttribute::Pinned;
  case 4: return CUDADataAttribute::Shared;
  case 5: return CUDADataAttribute::Unified;
  default: return ::std::nullopt;
  }
}

} // namespace fir

namespace fir {
::llvm::StringRef stringifyCUDAProcAttribute(CUDAProcAttribute val) {
  switch (val) {
    case CUDAProcAttribute::Host: return "host";
    case CUDAProcAttribute::Device: return "device";
    case CUDAProcAttribute::HostDevice: return "host_device";
    case CUDAProcAttribute::Global: return "global";
    case CUDAProcAttribute::GridGlobal: return "grid_global";
  }
  return "";
}

::std::optional<CUDAProcAttribute> symbolizeCUDAProcAttribute(::llvm::StringRef str) {
  return ::llvm::StringSwitch<::std::optional<CUDAProcAttribute>>(str)
      .Case("host", CUDAProcAttribute::Host)
      .Case("device", CUDAProcAttribute::Device)
      .Case("host_device", CUDAProcAttribute::HostDevice)
      .Case("global", CUDAProcAttribute::Global)
      .Case("grid_global", CUDAProcAttribute::GridGlobal)
      .Default(::std::nullopt);
}
::std::optional<CUDAProcAttribute> symbolizeCUDAProcAttribute(uint32_t value) {
  switch (value) {
  case 0: return CUDAProcAttribute::Host;
  case 1: return CUDAProcAttribute::Device;
  case 2: return CUDAProcAttribute::HostDevice;
  case 3: return CUDAProcAttribute::Global;
  case 4: return CUDAProcAttribute::GridGlobal;
  default: return ::std::nullopt;
  }
}

} // namespace fir

namespace fir {
std::string stringifyFortranVariableFlagsEnum(FortranVariableFlagsEnum symbol) {
  auto val = static_cast<uint32_t>(symbol);
  assert(16383u == (16383u | val) && "invalid bits set in bit enum");
  // Special case for all bits unset.
  if (val == 0) return "None";

  ::llvm::SmallVector<::llvm::StringRef, 2> strs;
  // Print bit enum groups before individual bits

  if (1u == (1u & val))
    strs.push_back("allocatable");

  if (2u == (2u & val))
    strs.push_back("asynchronous");

  if (4u == (4u & val))
    strs.push_back("bind_c");

  if (8u == (8u & val))
    strs.push_back("contiguous");

  if (16u == (16u & val))
    strs.push_back("intent_in");

  if (32u == (32u & val))
    strs.push_back("intent_inout");

  if (64u == (64u & val))
    strs.push_back("intent_out");

  if (128u == (128u & val))
    strs.push_back("optional");

  if (256u == (256u & val))
    strs.push_back("parameter");

  if (512u == (512u & val))
    strs.push_back("pointer");

  if (1024u == (1024u & val))
    strs.push_back("target");

  if (2048u == (2048u & val))
    strs.push_back("value");

  if (4096u == (4096u & val))
    strs.push_back("volatile");

  if (8192u == (8192u & val))
    strs.push_back("host_assoc");
  return ::llvm::join(strs, ", ");
}

::std::optional<FortranVariableFlagsEnum> symbolizeFortranVariableFlagsEnum(::llvm::StringRef str) {
  // Special case for all bits unset.
  if (str == "None") return FortranVariableFlagsEnum::None;

  ::llvm::SmallVector<::llvm::StringRef, 2> symbols;
  str.split(symbols, ",");

  uint32_t val = 0;
  for (auto symbol : symbols) {
    auto bit = llvm::StringSwitch<::std::optional<uint32_t>>(symbol.trim())
      .Case("allocatable", 1)
      .Case("asynchronous", 2)
      .Case("bind_c", 4)
      .Case("contiguous", 8)
      .Case("intent_in", 16)
      .Case("intent_inout", 32)
      .Case("intent_out", 64)
      .Case("optional", 128)
      .Case("parameter", 256)
      .Case("pointer", 512)
      .Case("target", 1024)
      .Case("value", 2048)
      .Case("volatile", 4096)
      .Case("host_assoc", 8192)
      .Default(::std::nullopt);
    if (bit) { val |= *bit; } else { return ::std::nullopt; }
  }
  return static_cast<FortranVariableFlagsEnum>(val);
}

::std::optional<FortranVariableFlagsEnum> symbolizeFortranVariableFlagsEnum(uint32_t value) {
  // Special case for all bits unset.
  if (value == 0) return FortranVariableFlagsEnum::None;

  if (value & ~static_cast<uint32_t>(16383u)) return std::nullopt;
  return static_cast<FortranVariableFlagsEnum>(value);
}
bool FortranVariableFlagsEnumAttr::classof(::mlir::Attribute attr) {
  return (((::llvm::isa<::mlir::IntegerAttr>(attr))) && ((::llvm::cast<::mlir::IntegerAttr>(attr).getType().isSignlessInteger(32)))) && ((!(::llvm::cast<::mlir::IntegerAttr>(attr).getValue().getZExtValue() & (~(0u|1u|2u|4u|8u|16u|32u|64u|128u|256u|512u|1024u|2048u|4096u|8192u)))));
}
FortranVariableFlagsEnumAttr FortranVariableFlagsEnumAttr::get(::mlir::MLIRContext *context, FortranVariableFlagsEnum val) {
  ::mlir::IntegerType intType = ::mlir::IntegerType::get(context, 32);
  ::mlir::IntegerAttr baseAttr = ::mlir::IntegerAttr::get(intType, static_cast<uint32_t>(val));
  return ::llvm::cast<FortranVariableFlagsEnumAttr>(baseAttr);
}
FortranVariableFlagsEnum FortranVariableFlagsEnumAttr::getValue() const {
  return static_cast<FortranVariableFlagsEnum>(::mlir::IntegerAttr::getInt());
}
} // namespace fir

