22#include "absl/strings/str_cat.h"
23#include "absl/strings/string_view.h"
24#include "absl/types/span.h"
33class NamedType :
public Type {
35 explicit NamedType(std::string name) : name_(std::move(name)) {}
37 void Print(absl::string_view, std::string* out)
const final {
38 absl::StrAppend(out, name_);
45class PointerType :
public Type {
47 explicit PointerType(std::shared_ptr<Type> pointee)
48 : pointee_(std::move(pointee)) {}
50 void Print(absl::string_view attr_value_type, std::string* out)
const final {
51 pointee_->Print(attr_value_type, out);
52 absl::StrAppend(out,
"*");
56 std::shared_ptr<Type> pointee_;
59class AttrValueTypeType :
public Type {
61 void Print(absl::string_view attr_value_type, std::string* out)
const final {
62 absl::StrAppend(out, attr_value_type);
69 return std::make_shared<NamedType>(std::move(name));
73 return std::make_shared<PointerType>(std::move(pointee));
77 return std::make_shared<AttrValueTypeType>();
94template <ElementType element_type>
100template <
typename Descriptor>
104 descriptor.
name = Descriptor::kName;
106 descriptor.
symmetry = Descriptor::Symmetry::GetName();
109 for (
const auto& attr_descriptor : Descriptor::kAttrDescriptors) {
116 "Get",
"Set",
"IsNonDefault",
"NumNonDefaults",
"GetNonDefaults"};
118void CodeGenerator::EmitAttrType(
const CodegenAttrTypeDescriptor& descriptor,
119 std::string* out)
const {
122 const AttrOpFunctionInfo& op_info = attr_op_function_infos_[op];
128 absl::Span<const CodegenAttrTypeDescriptor> descriptors,
129 std::string* out)
const {
130 for (
const auto& descriptor : descriptors) {
146 std::vector<CodegenAttrTypeDescriptor> attr_type_descriptors;
148 [&attr_type_descriptors](
auto type_descriptor) {
149 attr_type_descriptors.push_back(
std::string GenerateCode() const
virtual void EmitElements(absl::Span< const absl::string_view > elements, std::string *out) const
virtual void StartAttrType(const CodegenAttrTypeDescriptor &descriptor, std::string *out) const
virtual void EmitAttributes(absl::Span< const CodegenAttrTypeDescriptor > descriptors, std::string *out) const
virtual void EmitAttrOp(absl::string_view op_name, const CodegenAttrTypeDescriptor &descriptor, const AttrOpFunctionInfo &info, std::string *out) const
virtual void EmitHeader(std::string *out) const
static std::shared_ptr< Type > Named(std::string name)
static std::shared_ptr< Type > Pointer(std::shared_ptr< Type > pointee)
static std::shared_ptr< Type > AttrValueType()
CodegenAttrTypeDescriptor MakeAttrTypeDescriptor()
CodegenAttrTypeDescriptor::ValueType GetValueType(bool)
static constexpr int kNumAttrOps
constexpr absl::string_view kOpNames[static_cast< int >(AttrOp::kNumOps)]
std::tuple< BoolAttr0TypeDescriptor, BoolAttr1TypeDescriptor, IntAttr0TypeDescriptor, IntAttr1TypeDescriptor, DoubleAttr0TypeDescriptor, DoubleAttr1TypeDescriptor, DoubleAttr2TypeDescriptor, SymmetricDoubleAttr2TypeDescriptor, SymmetricDoubleAttr3TypeDescriptor, VariableAttr1TypeDescriptor > AllAttrTypeDescriptors
TaggedId< element_type > ElementId
constexpr absl::string_view kElementNames[kNumElements]
constexpr decltype(auto) ForEach(Fn &&fn, Tuple &&tuple)
std::vector< absl::string_view > attribute_names