Quellcode durchsuchen

Define `Any`...`DeclId` aliases for brevity (#3562)

josh11b vor 2 Jahren
Ursprung
Commit
770876bbcb

+ 2 - 4
toolchain/check/handle_class.cpp

@@ -21,10 +21,8 @@ auto HandleClassIntroducer(Context& context,
   return true;
 }
 
-static auto BuildClassDecl(
-    Context& context,
-    Parse::NodeIdOneOf<Parse::ClassDeclId, Parse::ClassDefinitionStartId>
-        parse_node) -> std::tuple<SemIR::ClassId, SemIR::InstId> {
+static auto BuildClassDecl(Context& context, Parse::AnyClassDeclId parse_node)
+    -> std::tuple<SemIR::ClassId, SemIR::InstId> {
   auto name_context = context.decl_name_stack().FinishName();
   context.node_stack()
       .PopAndDiscardSoloParseNode<Parse::NodeKind::ClassIntroducer>();

+ 4 - 5
toolchain/check/handle_function.cpp

@@ -43,11 +43,10 @@ static auto DiagnoseModifiers(Context& context) -> KeywordModifierSet {
 // Build a FunctionDecl describing the signature of a function. This
 // handles the common logic shared by function declaration syntax and function
 // definition syntax.
-static auto BuildFunctionDecl(
-    Context& context,
-    Parse::NodeIdOneOf<Parse::FunctionDeclId, Parse::FunctionDefinitionStartId>
-        parse_node,
-    bool is_definition) -> std::pair<SemIR::FunctionId, SemIR::InstId> {
+static auto BuildFunctionDecl(Context& context,
+                              Parse::AnyFunctionDeclId parse_node,
+                              bool is_definition)
+    -> std::pair<SemIR::FunctionId, SemIR::InstId> {
   // TODO: This contains the IR block for the parameters and return type. At
   // present, it's just loose, but it's not strictly required for parameter
   // refs; we should either stop constructing it completely or, if it turns out

+ 2 - 4
toolchain/check/handle_interface.cpp

@@ -21,10 +21,8 @@ auto HandleInterfaceIntroducer(Context& context,
   return true;
 }
 
-static auto BuildInterfaceDecl(
-    Context& context, Parse::NodeIdOneOf<Parse::InterfaceDeclId,
-                                         Parse::InterfaceDefinitionStartId>
-                          parse_node)
+static auto BuildInterfaceDecl(Context& context,
+                               Parse::AnyInterfaceDeclId parse_node)
     -> std::tuple<SemIR::InterfaceId, SemIR::InstId> {
   auto name_context = context.decl_name_stack().FinishName();
   context.node_stack()

+ 6 - 0
toolchain/parse/node_ids.h

@@ -75,6 +75,12 @@ struct NodeIdOneOf : public NodeId {
   constexpr NodeIdOneOf(InvalidNodeId) : NodeId(NodeId::InvalidIndex) {}
 };
 
+using AnyClassDeclId = NodeIdOneOf<ClassDeclId, ClassDefinitionStartId>;
+using AnyFunctionDeclId =
+    NodeIdOneOf<FunctionDeclId, FunctionDefinitionStartId>;
+using AnyInterfaceDeclId =
+    NodeIdOneOf<InterfaceDeclId, InterfaceDefinitionStartId>;
+
 // NodeId with kind that is anything but T::Kind.
 template <typename T>
 struct NodeIdNot : public NodeId {

+ 4 - 8
toolchain/sem_ir/typed_insts.h

@@ -220,8 +220,7 @@ struct Call {
 struct ClassDecl {
   static constexpr auto Kind = InstKind::ClassDecl.Define("class_decl");
 
-  Parse::NodeIdOneOf<Parse::ClassDeclId, Parse::ClassDefinitionStartId>
-      parse_node;
+  Parse::AnyClassDeclId parse_node;
   // No type: a class declaration is not itself a value. The name of a class
   // declaration becomes a class type value.
   // TODO: For a generic class declaration, the name of the class declaration
@@ -256,8 +255,7 @@ struct ClassInit {
 struct ClassType {
   static constexpr auto Kind = InstKind::ClassType.Define("class_type");
 
-  Parse::NodeIdOneOf<Parse::ClassDeclId, Parse::ClassDefinitionStartId>
-      parse_node;
+  Parse::AnyClassDeclId parse_node;
   TypeId type_id;
   ClassId class_id;
   // TODO: Once we support generic classes, include the class's arguments here.
@@ -316,8 +314,7 @@ struct FieldDecl {
 struct FunctionDecl {
   static constexpr auto Kind = InstKind::FunctionDecl.Define("fn_decl");
 
-  Parse::NodeIdOneOf<Parse::FunctionDeclId, Parse::FunctionDefinitionStartId>
-      parse_node;
+  Parse::AnyFunctionDeclId parse_node;
   TypeId type_id;
   FunctionId function_id;
 };
@@ -353,8 +350,7 @@ struct InitializeFrom {
 struct InterfaceDecl {
   static constexpr auto Kind = InstKind::InterfaceDecl.Define("interface_decl");
 
-  Parse::NodeIdOneOf<Parse::InterfaceDeclId, Parse::InterfaceDefinitionStartId>
-      parse_node;
+  Parse::AnyInterfaceDeclId parse_node;
   // No type: an interface declaration is not itself a value. The name of an
   // interface declaration becomes a facet type value.
   // TODO: For a generic interface declaration, the name of the interface