|
|
@@ -21,7 +21,7 @@ namespace Carbon::SemIR {
|
|
|
// of a category inst type:
|
|
|
//
|
|
|
// struct MyCategory {
|
|
|
-// using CategoryInfo = CategoryOf<X, Y, Z>;
|
|
|
+// using CategoryInfo = CARBON_INST_CATEGORY_INFO(MyCategory);
|
|
|
// InstKind kind;
|
|
|
// ...
|
|
|
// }
|
|
|
@@ -31,11 +31,31 @@ struct CategoryOf {
|
|
|
static constexpr InstKind Kinds[] = {TypedInsts::Kind...};
|
|
|
};
|
|
|
|
|
|
+// For each category, we provide `CategoryName_CARBON_INST_CATEGORY` for the
|
|
|
+// `CARBON_KIND_ANY` macro. This macro uses the same expansion to provide a
|
|
|
+// `CategoryOf` for the category.
|
|
|
+#define CARBON_INST_CATEGORY_INFO(Name) \
|
|
|
+ CategoryOf<Name##_CARBON_INST_CATEGORY( \
|
|
|
+ CARBON_INST_CATEGORY_INFO_INTERNAL_NAME, \
|
|
|
+ CARBON_INST_CATEGORY_INFO_INTERNAL_COMMA)>
|
|
|
+#define CARBON_INST_CATEGORY_INFO_INTERNAL_NAME(Name) Name
|
|
|
+#define CARBON_INST_CATEGORY_INFO_INTERNAL_COMMA ,
|
|
|
+
|
|
|
+// clang-format off
|
|
|
+#define AnyAggregateAccess_CARBON_INST_CATEGORY(X, Sep) \
|
|
|
+ X(::Carbon::SemIR::ClassElementAccess) Sep \
|
|
|
+ X(::Carbon::SemIR::StructAccess) Sep \
|
|
|
+ X(::Carbon::SemIR::TupleAccess)
|
|
|
+// clang-format on
|
|
|
+
|
|
|
+#define AnyAggregateAccess_CARBON_KIND_ANY_EXPAND \
|
|
|
+ CARBON_KIND_ANY_EXPAND_BEGIN AnyAggregateAccess_CARBON_INST_CATEGORY( \
|
|
|
+ CARBON_KIND_ANY_EXPAND_CASE, CARBON_KIND_ANY_EXPAND_SEP)
|
|
|
+
|
|
|
// Common representation for aggregate access nodes, which access a fixed
|
|
|
// element of an aggregate.
|
|
|
struct AnyAggregateAccess {
|
|
|
- using CategoryInfo =
|
|
|
- CategoryOf<ClassElementAccess, StructAccess, TupleAccess>;
|
|
|
+ using CategoryInfo = CARBON_INST_CATEGORY_INFO(AnyAggregateAccess);
|
|
|
|
|
|
InstKind kind;
|
|
|
TypeId type_id;
|
|
|
@@ -43,9 +63,21 @@ struct AnyAggregateAccess {
|
|
|
ElementIndex index;
|
|
|
};
|
|
|
|
|
|
+// clang-format off
|
|
|
+#define AnyAggregateInit_CARBON_INST_CATEGORY(X, Sep) \
|
|
|
+ X(::Carbon::SemIR::ArrayInit) Sep \
|
|
|
+ X(::Carbon::SemIR::ClassInit) Sep \
|
|
|
+ X(::Carbon::SemIR::StructInit) Sep \
|
|
|
+ X(::Carbon::SemIR::TupleInit)
|
|
|
+// clang-format on
|
|
|
+
|
|
|
+#define AnyAggregateInit_CARBON_KIND_ANY_EXPAND \
|
|
|
+ CARBON_KIND_ANY_EXPAND_BEGIN AnyAggregateInit_CARBON_INST_CATEGORY( \
|
|
|
+ CARBON_KIND_ANY_EXPAND_CASE, CARBON_KIND_ANY_EXPAND_SEP)
|
|
|
+
|
|
|
// Common representation for all kinds of aggregate initialization.
|
|
|
struct AnyAggregateInit {
|
|
|
- using CategoryInfo = CategoryOf<ArrayInit, ClassInit, StructInit, TupleInit>;
|
|
|
+ using CategoryInfo = CARBON_INST_CATEGORY_INFO(AnyAggregateInit);
|
|
|
|
|
|
InstKind kind;
|
|
|
TypeId type_id;
|
|
|
@@ -53,20 +85,41 @@ struct AnyAggregateInit {
|
|
|
DestInstId dest_id;
|
|
|
};
|
|
|
|
|
|
+// clang-format off
|
|
|
+#define AnyAggregateValue_CARBON_INST_CATEGORY(X, Sep) \
|
|
|
+ X(::Carbon::SemIR::StructValue) Sep \
|
|
|
+ X(::Carbon::SemIR::TupleValue)
|
|
|
+// clang-format on
|
|
|
+
|
|
|
+#define AnyAggregateValue_CARBON_KIND_ANY_EXPAND \
|
|
|
+ CARBON_KIND_ANY_EXPAND_BEGIN AnyAggregateValue_CARBON_INST_CATEGORY( \
|
|
|
+ CARBON_KIND_ANY_EXPAND_CASE, CARBON_KIND_ANY_EXPAND_SEP)
|
|
|
+
|
|
|
// Common representation for all kinds of aggregate value.
|
|
|
struct AnyAggregateValue {
|
|
|
- using CategoryInfo = CategoryOf<StructValue, TupleValue>;
|
|
|
+ using CategoryInfo = CARBON_INST_CATEGORY_INFO(AnyAggregateValue);
|
|
|
|
|
|
InstKind kind;
|
|
|
TypeId type_id;
|
|
|
InstBlockId elements_id;
|
|
|
};
|
|
|
|
|
|
+// clang-format off
|
|
|
+#define AnyBindingPattern_CARBON_INST_CATEGORY(X, Sep) \
|
|
|
+ X(::Carbon::SemIR::FormBindingPattern) Sep \
|
|
|
+ X(::Carbon::SemIR::RefBindingPattern) Sep \
|
|
|
+ X(::Carbon::SemIR::SymbolicBindingPattern) Sep \
|
|
|
+ X(::Carbon::SemIR::ValueBindingPattern)
|
|
|
+// clang-format on
|
|
|
+
|
|
|
+#define AnyBindingPattern_CARBON_KIND_ANY_EXPAND \
|
|
|
+ CARBON_KIND_ANY_EXPAND_BEGIN AnyBindingPattern_CARBON_INST_CATEGORY( \
|
|
|
+ CARBON_KIND_ANY_EXPAND_CASE, CARBON_KIND_ANY_EXPAND_SEP)
|
|
|
+
|
|
|
// Common representation for various `*binding_pattern` nodes.
|
|
|
struct AnyBindingPattern {
|
|
|
// TODO: Also handle TemplateBindingPattern once it exists.
|
|
|
- using CategoryInfo = CategoryOf<FormBindingPattern, RefBindingPattern,
|
|
|
- SymbolicBindingPattern, ValueBindingPattern>;
|
|
|
+ using CategoryInfo = CARBON_INST_CATEGORY_INFO(AnyBindingPattern);
|
|
|
|
|
|
InstKind kind;
|
|
|
|
|
|
@@ -80,11 +133,23 @@ struct AnyBindingPattern {
|
|
|
EntityNameId entity_name_id;
|
|
|
};
|
|
|
|
|
|
+// clang-format off
|
|
|
+#define AnyBinding_CARBON_INST_CATEGORY(X, Sep) \
|
|
|
+ X(::Carbon::SemIR::AliasBinding) Sep \
|
|
|
+ X(::Carbon::SemIR::FormBinding) Sep \
|
|
|
+ X(::Carbon::SemIR::RefBinding) Sep \
|
|
|
+ X(::Carbon::SemIR::SymbolicBinding) Sep \
|
|
|
+ X(::Carbon::SemIR::ValueBinding)
|
|
|
+// clang-format on
|
|
|
+
|
|
|
+#define AnyBinding_CARBON_KIND_ANY_EXPAND \
|
|
|
+ CARBON_KIND_ANY_EXPAND_BEGIN AnyBinding_CARBON_INST_CATEGORY( \
|
|
|
+ CARBON_KIND_ANY_EXPAND_CASE, CARBON_KIND_ANY_EXPAND_SEP)
|
|
|
+
|
|
|
// Common representation for various `bind*` nodes.
|
|
|
struct AnyBinding {
|
|
|
// TODO: Also handle BindTemplateName once it exists.
|
|
|
- using CategoryInfo = CategoryOf<AliasBinding, FormBinding, RefBinding,
|
|
|
- SymbolicBinding, ValueBinding>;
|
|
|
+ using CategoryInfo = CARBON_INST_CATEGORY_INFO(AnyBinding);
|
|
|
|
|
|
InstKind kind;
|
|
|
TypeId type_id;
|
|
|
@@ -95,11 +160,24 @@ struct AnyBinding {
|
|
|
InstId value_id;
|
|
|
};
|
|
|
|
|
|
+// clang-format off
|
|
|
+#define AnyBindingOrExportDecl_CARBON_INST_CATEGORY(X, Sep) \
|
|
|
+ X(::Carbon::SemIR::AliasBinding) Sep \
|
|
|
+ X(::Carbon::SemIR::FormBinding) Sep \
|
|
|
+ X(::Carbon::SemIR::RefBinding) Sep \
|
|
|
+ X(::Carbon::SemIR::SymbolicBinding) Sep \
|
|
|
+ X(::Carbon::SemIR::ValueBinding) Sep \
|
|
|
+ X(::Carbon::SemIR::ExportDecl)
|
|
|
+// clang-format on
|
|
|
+
|
|
|
+#define AnyBindingOrExportDecl_CARBON_KIND_ANY_EXPAND \
|
|
|
+ CARBON_KIND_ANY_EXPAND_BEGIN AnyBindingOrExportDecl_CARBON_INST_CATEGORY( \
|
|
|
+ CARBON_KIND_ANY_EXPAND_CASE, CARBON_KIND_ANY_EXPAND_SEP)
|
|
|
+
|
|
|
// Common representation for various `bind*` nodes, and `export name`.
|
|
|
struct AnyBindingOrExportDecl {
|
|
|
// TODO: Also handle BindTemplateName once it exists.
|
|
|
- using CategoryInfo = CategoryOf<AliasBinding, FormBinding, RefBinding,
|
|
|
- SymbolicBinding, ValueBinding, ExportDecl>;
|
|
|
+ using CategoryInfo = CARBON_INST_CATEGORY_INFO(AnyBindingOrExportDecl);
|
|
|
|
|
|
InstKind kind;
|
|
|
TypeId type_id;
|
|
|
@@ -107,9 +185,20 @@ struct AnyBindingOrExportDecl {
|
|
|
InstId value_id;
|
|
|
};
|
|
|
|
|
|
+// clang-format off
|
|
|
+#define AnyBranch_CARBON_INST_CATEGORY(X, Sep) \
|
|
|
+ X(::Carbon::SemIR::Branch) Sep \
|
|
|
+ X(::Carbon::SemIR::BranchIf) Sep \
|
|
|
+ X(::Carbon::SemIR::BranchWithArg)
|
|
|
+// clang-format on
|
|
|
+
|
|
|
+#define AnyBranch_CARBON_KIND_ANY_EXPAND \
|
|
|
+ CARBON_KIND_ANY_EXPAND_BEGIN AnyBranch_CARBON_INST_CATEGORY( \
|
|
|
+ CARBON_KIND_ANY_EXPAND_CASE, CARBON_KIND_ANY_EXPAND_SEP)
|
|
|
+
|
|
|
// Common representation for all kinds of `Branch*` node.
|
|
|
struct AnyBranch {
|
|
|
- using CategoryInfo = CategoryOf<Branch, BranchIf, BranchWithArg>;
|
|
|
+ using CategoryInfo = CARBON_INST_CATEGORY_INFO(AnyBranch);
|
|
|
|
|
|
InstKind kind;
|
|
|
// Branches don't produce a value, so have no type.
|
|
|
@@ -118,10 +207,20 @@ struct AnyBranch {
|
|
|
AnyRawId arg1;
|
|
|
};
|
|
|
|
|
|
+// clang-format off
|
|
|
+#define AnyFoundationDecl_CARBON_INST_CATEGORY(X, Sep) \
|
|
|
+ X(::Carbon::SemIR::AdaptDecl) Sep \
|
|
|
+ X(::Carbon::SemIR::BaseDecl)
|
|
|
+// clang-format on
|
|
|
+
|
|
|
+#define AnyFoundationDecl_CARBON_KIND_ANY_EXPAND \
|
|
|
+ CARBON_KIND_ANY_EXPAND_BEGIN AnyFoundationDecl_CARBON_INST_CATEGORY( \
|
|
|
+ CARBON_KIND_ANY_EXPAND_CASE, CARBON_KIND_ANY_EXPAND_SEP)
|
|
|
+
|
|
|
// Common representation for declarations describing the foundation type of a
|
|
|
// class -- either its adapted type or its base class.
|
|
|
struct AnyFoundationDecl {
|
|
|
- using CategoryInfo = CategoryOf<AdaptDecl, BaseDecl>;
|
|
|
+ using CategoryInfo = CARBON_INST_CATEGORY_INFO(AnyFoundationDecl);
|
|
|
|
|
|
InstKind kind;
|
|
|
TypeId type_id;
|
|
|
@@ -130,9 +229,19 @@ struct AnyFoundationDecl {
|
|
|
AnyRawId arg1;
|
|
|
};
|
|
|
|
|
|
+// clang-format off
|
|
|
+#define AnyImportRef_CARBON_INST_CATEGORY(X, Sep) \
|
|
|
+ X(::Carbon::SemIR::ImportRefLoaded) Sep \
|
|
|
+ X(::Carbon::SemIR::ImportRefUnloaded)
|
|
|
+// clang-format on
|
|
|
+
|
|
|
+#define AnyImportRef_CARBON_KIND_ANY_EXPAND \
|
|
|
+ CARBON_KIND_ANY_EXPAND_BEGIN AnyImportRef_CARBON_INST_CATEGORY( \
|
|
|
+ CARBON_KIND_ANY_EXPAND_CASE, CARBON_KIND_ANY_EXPAND_SEP)
|
|
|
+
|
|
|
// Common representation for all kinds of `ImportRef*` node.
|
|
|
struct AnyImportRef {
|
|
|
- using CategoryInfo = CategoryOf<ImportRefUnloaded, ImportRefLoaded>;
|
|
|
+ using CategoryInfo = CARBON_INST_CATEGORY_INFO(AnyImportRef);
|
|
|
|
|
|
InstKind kind;
|
|
|
TypeId type_id;
|
|
|
@@ -142,9 +251,20 @@ struct AnyImportRef {
|
|
|
EntityNameId entity_name_id;
|
|
|
};
|
|
|
|
|
|
+// clang-format off
|
|
|
+#define AnyParam_CARBON_INST_CATEGORY(X, Sep) \
|
|
|
+ X(::Carbon::SemIR::OutParam) Sep \
|
|
|
+ X(::Carbon::SemIR::RefParam) Sep \
|
|
|
+ X(::Carbon::SemIR::ValueParam)
|
|
|
+// clang-format on
|
|
|
+
|
|
|
+#define AnyParam_CARBON_KIND_ANY_EXPAND \
|
|
|
+ CARBON_KIND_ANY_EXPAND_BEGIN AnyParam_CARBON_INST_CATEGORY( \
|
|
|
+ CARBON_KIND_ANY_EXPAND_CASE, CARBON_KIND_ANY_EXPAND_SEP)
|
|
|
+
|
|
|
// A `Call` parameter for a function or other parameterized block.
|
|
|
struct AnyParam {
|
|
|
- using CategoryInfo = CategoryOf<OutParam, RefParam, ValueParam>;
|
|
|
+ using CategoryInfo = CARBON_INST_CATEGORY_INFO(AnyParam);
|
|
|
|
|
|
InstKind kind;
|
|
|
TypeId type_id;
|
|
|
@@ -156,12 +276,23 @@ struct AnyParam {
|
|
|
NameId pretty_name_id;
|
|
|
};
|
|
|
|
|
|
+// clang-format off
|
|
|
+#define AnyParamPattern_CARBON_INST_CATEGORY(X, Sep) \
|
|
|
+ X(::Carbon::SemIR::FormParamPattern) Sep \
|
|
|
+ X(::Carbon::SemIR::OutParamPattern) Sep \
|
|
|
+ X(::Carbon::SemIR::RefParamPattern) Sep \
|
|
|
+ X(::Carbon::SemIR::ValueParamPattern) Sep \
|
|
|
+ X(::Carbon::SemIR::VarParamPattern)
|
|
|
+// clang-format on
|
|
|
+
|
|
|
+#define AnyParamPattern_CARBON_KIND_ANY_EXPAND \
|
|
|
+ CARBON_KIND_ANY_EXPAND_BEGIN AnyParamPattern_CARBON_INST_CATEGORY( \
|
|
|
+ CARBON_KIND_ANY_EXPAND_CASE, CARBON_KIND_ANY_EXPAND_SEP)
|
|
|
+
|
|
|
// A pattern that represents a `Call` parameter. It delegates to subpattern_id
|
|
|
// in pattern matching.
|
|
|
struct AnyParamPattern {
|
|
|
- using CategoryInfo =
|
|
|
- CategoryOf<FormParamPattern, OutParamPattern, RefParamPattern,
|
|
|
- ValueParamPattern, VarParamPattern>;
|
|
|
+ using CategoryInfo = CARBON_INST_CATEGORY_INFO(AnyParamPattern);
|
|
|
|
|
|
InstKind kind;
|
|
|
|
|
|
@@ -171,9 +302,20 @@ struct AnyParamPattern {
|
|
|
InstId subpattern_id;
|
|
|
};
|
|
|
|
|
|
+// clang-format off
|
|
|
+#define AnyPrimitiveForm_CARBON_INST_CATEGORY(X, Sep) \
|
|
|
+ X(::Carbon::SemIR::InitForm) Sep \
|
|
|
+ X(::Carbon::SemIR::RefForm) Sep \
|
|
|
+ X(::Carbon::SemIR::ValueForm)
|
|
|
+// clang-format on
|
|
|
+
|
|
|
+#define AnyPrimitiveForm_CARBON_KIND_ANY_EXPAND \
|
|
|
+ CARBON_KIND_ANY_EXPAND_BEGIN AnyPrimitiveForm_CARBON_INST_CATEGORY( \
|
|
|
+ CARBON_KIND_ANY_EXPAND_CASE, CARBON_KIND_ANY_EXPAND_SEP)
|
|
|
+
|
|
|
// An inst that represents a primitive form.
|
|
|
struct AnyPrimitiveForm {
|
|
|
- using CategoryInfo = CategoryOf<InitForm, RefForm, ValueForm>;
|
|
|
+ using CategoryInfo = CARBON_INST_CATEGORY_INFO(AnyPrimitiveForm);
|
|
|
|
|
|
InstKind kind;
|
|
|
|
|
|
@@ -186,11 +328,22 @@ struct AnyPrimitiveForm {
|
|
|
AnyRawId arg1;
|
|
|
};
|
|
|
|
|
|
+// clang-format off
|
|
|
+#define AnyQualifiedType_CARBON_INST_CATEGORY(X, Sep) \
|
|
|
+ X(::Carbon::SemIR::ConstType) Sep \
|
|
|
+ X(::Carbon::SemIR::MaybeUnformedType) Sep \
|
|
|
+ X(::Carbon::SemIR::PartialType)
|
|
|
+// clang-format on
|
|
|
+
|
|
|
+#define AnyQualifiedType_CARBON_KIND_ANY_EXPAND \
|
|
|
+ CARBON_KIND_ANY_EXPAND_BEGIN AnyQualifiedType_CARBON_INST_CATEGORY( \
|
|
|
+ CARBON_KIND_ANY_EXPAND_CASE, CARBON_KIND_ANY_EXPAND_SEP)
|
|
|
+
|
|
|
// A type qualifier that wraps another type and has the same object
|
|
|
// representation. Qualifiers are arranged so that adding a qualifier is
|
|
|
// generally safe, and removing a qualifier is not necessarily safe or correct.
|
|
|
struct AnyQualifiedType {
|
|
|
- using CategoryInfo = CategoryOf<ConstType, PartialType, MaybeUnformedType>;
|
|
|
+ using CategoryInfo = CARBON_INST_CATEGORY_INFO(AnyQualifiedType);
|
|
|
|
|
|
InstKind kind;
|
|
|
|
|
|
@@ -198,9 +351,19 @@ struct AnyQualifiedType {
|
|
|
TypeInstId inner_id;
|
|
|
};
|
|
|
|
|
|
+// clang-format off
|
|
|
+#define AnyStructType_CARBON_INST_CATEGORY(X, Sep) \
|
|
|
+ X(::Carbon::SemIR::CustomLayoutType) Sep \
|
|
|
+ X(::Carbon::SemIR::StructType)
|
|
|
+// clang-format on
|
|
|
+
|
|
|
+#define AnyStructType_CARBON_KIND_ANY_EXPAND \
|
|
|
+ CARBON_KIND_ANY_EXPAND_BEGIN AnyStructType_CARBON_INST_CATEGORY( \
|
|
|
+ CARBON_KIND_ANY_EXPAND_CASE, CARBON_KIND_ANY_EXPAND_SEP)
|
|
|
+
|
|
|
// A struct-like type with a list of named fields.
|
|
|
struct AnyStructType {
|
|
|
- using CategoryInfo = CategoryOf<StructType, CustomLayoutType>;
|
|
|
+ using CategoryInfo = CARBON_INST_CATEGORY_INFO(AnyStructType);
|
|
|
|
|
|
InstKind kind;
|
|
|
|