/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
|*                                                                            *|
|* AttrDef Definitions                                                        *|
|*                                                                            *|
|* Automatically generated file, do not edit!                                 *|
|*                                                                            *|
\*===----------------------------------------------------------------------===*/

#ifdef GET_ATTRDEF_LIST
#undef GET_ATTRDEF_LIST

::fir::FortranVariableFlagsAttr,
::fir::ReduceAttr

#endif  // GET_ATTRDEF_LIST

#ifdef GET_ATTRDEF_CLASSES
#undef GET_ATTRDEF_CLASSES

static ::mlir::OptionalParseResult generatedAttributeParser(::mlir::AsmParser &parser, ::llvm::StringRef *mnemonic, ::mlir::Type type, ::mlir::Attribute &value) {
  return ::mlir::AsmParser::KeywordSwitch<::mlir::OptionalParseResult>(parser)
    .Case(::fir::FortranVariableFlagsAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
      value = ::fir::FortranVariableFlagsAttr::parse(parser, type);
      return ::mlir::success(!!value);
    })
    .Case(::fir::ReduceAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
      value = ::fir::ReduceAttr::parse(parser, type);
      return ::mlir::success(!!value);
    })
    .Default([&](llvm::StringRef keyword, llvm::SMLoc) {
      *mnemonic = keyword;
      return std::nullopt;
    });
}

static ::llvm::LogicalResult generatedAttributePrinter(::mlir::Attribute def, ::mlir::AsmPrinter &printer) {
  return ::llvm::TypeSwitch<::mlir::Attribute, ::llvm::LogicalResult>(def)    .Case<::fir::FortranVariableFlagsAttr>([&](auto t) {
      printer << ::fir::FortranVariableFlagsAttr::getMnemonic();
t.print(printer);
      return ::mlir::success();
    })
    .Case<::fir::ReduceAttr>([&](auto t) {
      printer << ::fir::ReduceAttr::getMnemonic();
t.print(printer);
      return ::mlir::success();
    })
    .Default([](auto) { return ::mlir::failure(); });
}

namespace fir {
namespace detail {
struct FortranVariableFlagsAttrStorage : public ::mlir::AttributeStorage {
  using KeyTy = std::tuple<FortranVariableFlagsEnum>;
  FortranVariableFlagsAttrStorage(FortranVariableFlagsEnum flags) : flags(std::move(flags)) {}

  KeyTy getAsKey() const {
    return KeyTy(flags);
  }

  bool operator==(const KeyTy &tblgenKey) const {
    return (flags == std::get<0>(tblgenKey));
  }

  static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
    return ::llvm::hash_combine(std::get<0>(tblgenKey));
  }

  static FortranVariableFlagsAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey) {
    auto flags = std::move(std::get<0>(tblgenKey));
    return new (allocator.allocate<FortranVariableFlagsAttrStorage>()) FortranVariableFlagsAttrStorage(std::move(flags));
  }

  FortranVariableFlagsEnum flags;
};
} // namespace detail
FortranVariableFlagsAttr FortranVariableFlagsAttr::get(::mlir::MLIRContext *context, FortranVariableFlagsEnum flags) {
  return Base::get(context, std::move(flags));
}

FortranVariableFlagsEnum FortranVariableFlagsAttr::getFlags() const {
  return getImpl()->flags;
}

} // namespace fir
MLIR_DEFINE_EXPLICIT_TYPE_ID(::fir::FortranVariableFlagsAttr)
namespace fir {
namespace detail {
struct ReduceAttrStorage : public ::mlir::AttributeStorage {
  using KeyTy = std::tuple<ReduceOperationEnum>;
  ReduceAttrStorage(ReduceOperationEnum reduce_operation) : reduce_operation(std::move(reduce_operation)) {}

  KeyTy getAsKey() const {
    return KeyTy(reduce_operation);
  }

  bool operator==(const KeyTy &tblgenKey) const {
    return (reduce_operation == std::get<0>(tblgenKey));
  }

  static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
    return ::llvm::hash_combine(std::get<0>(tblgenKey));
  }

  static ReduceAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey) {
    auto reduce_operation = std::move(std::get<0>(tblgenKey));
    return new (allocator.allocate<ReduceAttrStorage>()) ReduceAttrStorage(std::move(reduce_operation));
  }

  ReduceOperationEnum reduce_operation;
};
} // namespace detail
ReduceAttr ReduceAttr::get(::mlir::MLIRContext *context, ReduceOperationEnum reduce_operation) {
  return Base::get(context, std::move(reduce_operation));
}

::mlir::Attribute ReduceAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
  ::mlir::Builder odsBuilder(odsParser.getContext());
  ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
  (void) odsLoc;
  ::mlir::FailureOr<ReduceOperationEnum> _result_reduce_operation;
  // Parse literal '<'
  if (odsParser.parseLess()) return {};

  // Parse variable 'reduce_operation'
  _result_reduce_operation = ::mlir::FieldParser<ReduceOperationEnum>::parse(odsParser);
  if (::mlir::failed(_result_reduce_operation)) {
    odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse fir_ReduceAttr parameter 'reduce_operation' which is to be a `ReduceOperationEnum`");
    return {};
  }
  // Parse literal '>'
  if (odsParser.parseGreater()) return {};
  assert(::mlir::succeeded(_result_reduce_operation));
  return ReduceAttr::get(odsParser.getContext(),
      ReduceOperationEnum((*_result_reduce_operation)));
}

void ReduceAttr::print(::mlir::AsmPrinter &odsPrinter) const {
  ::mlir::Builder odsBuilder(getContext());
  odsPrinter << "<";
  odsPrinter.printStrippedAttrOrType(getReduceOperation());
  odsPrinter << ">";
}

ReduceOperationEnum ReduceAttr::getReduceOperation() const {
  return getImpl()->reduce_operation;
}

} // namespace fir
MLIR_DEFINE_EXPLICIT_TYPE_ID(::fir::ReduceAttr)

#endif  // GET_ATTRDEF_CLASSES

