From 770876bbcb81ea00a31431c4503983eb6268090a Mon Sep 17 00:00:00 2001 From: josh11b Date: Wed, 3 Jan 2024 16:03:44 -0800 Subject: [PATCH] Define `Any`...`DeclId` aliases for brevity (#3562) --- toolchain/check/handle_class.cpp | 6 ++---- toolchain/check/handle_function.cpp | 9 ++++----- toolchain/check/handle_interface.cpp | 6 ++---- toolchain/parse/node_ids.h | 6 ++++++ toolchain/sem_ir/typed_insts.h | 12 ++++-------- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/toolchain/check/handle_class.cpp b/toolchain/check/handle_class.cpp index 5c28ba1a8314..4e0ecfe05005 100644 --- a/toolchain/check/handle_class.cpp +++ b/toolchain/check/handle_class.cpp @@ -21,10 +21,8 @@ auto HandleClassIntroducer(Context& context, return true; } -static auto BuildClassDecl( - Context& context, - Parse::NodeIdOneOf - parse_node) -> std::tuple { +static auto BuildClassDecl(Context& context, Parse::AnyClassDeclId parse_node) + -> std::tuple { auto name_context = context.decl_name_stack().FinishName(); context.node_stack() .PopAndDiscardSoloParseNode(); diff --git a/toolchain/check/handle_function.cpp b/toolchain/check/handle_function.cpp index 1c77f90359fc..b202e1ed1595 100644 --- a/toolchain/check/handle_function.cpp +++ b/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_node, - bool is_definition) -> std::pair { +static auto BuildFunctionDecl(Context& context, + Parse::AnyFunctionDeclId parse_node, + bool is_definition) + -> std::pair { // 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 diff --git a/toolchain/check/handle_interface.cpp b/toolchain/check/handle_interface.cpp index 9777dfa7990a..3f4a311973c4 100644 --- a/toolchain/check/handle_interface.cpp +++ b/toolchain/check/handle_interface.cpp @@ -21,10 +21,8 @@ auto HandleInterfaceIntroducer(Context& context, return true; } -static auto BuildInterfaceDecl( - Context& context, Parse::NodeIdOneOf - parse_node) +static auto BuildInterfaceDecl(Context& context, + Parse::AnyInterfaceDeclId parse_node) -> std::tuple { auto name_context = context.decl_name_stack().FinishName(); context.node_stack() diff --git a/toolchain/parse/node_ids.h b/toolchain/parse/node_ids.h index 1098e781ae33..84556b683cbe 100644 --- a/toolchain/parse/node_ids.h +++ b/toolchain/parse/node_ids.h @@ -75,6 +75,12 @@ struct NodeIdOneOf : public NodeId { constexpr NodeIdOneOf(InvalidNodeId) : NodeId(NodeId::InvalidIndex) {} }; +using AnyClassDeclId = NodeIdOneOf; +using AnyFunctionDeclId = + NodeIdOneOf; +using AnyInterfaceDeclId = + NodeIdOneOf; + // NodeId with kind that is anything but T::Kind. template struct NodeIdNot : public NodeId { diff --git a/toolchain/sem_ir/typed_insts.h b/toolchain/sem_ir/typed_insts.h index 653c16c13669..9d34a47f6aa4 100644 --- a/toolchain/sem_ir/typed_insts.h +++ b/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_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_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_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_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