diff --git a/language_server/language_server.cpp b/language_server/language_server.cpp index b7e1854bc438..e4d4b82a2cf7 100644 --- a/language_server/language_server.cpp +++ b/language_server/language_server.cpp @@ -79,7 +79,7 @@ auto LanguageServer::onReply(llvm::json::Value /*id*/, // Returns the text of first child of kind Parse::NodeKind::Name. static auto GetName(const SharedValueStores& value_stores, const Lex::TokenizedBuffer& tokens, const Parse::Tree& p, - Parse::Node node) -> std::optional { + Parse::NodeId node) -> std::optional { for (auto ch : p.children(node)) { if (p.node_kind(ch) == Parse::NodeKind::Name) { return value_stores.identifiers().Get( diff --git a/toolchain/check/check.cpp b/toolchain/check/check.cpp index 9eb56e5153a5..4c16de27b7e1 100644 --- a/toolchain/check/check.cpp +++ b/toolchain/check/check.cpp @@ -26,12 +26,12 @@ struct UnitInfo { struct PackageImports { // Use the constructor so that the SmallVector is only constructed // as-needed. - explicit PackageImports(Parse::Node node) : node(node) {} + explicit PackageImports(Parse::NodeId node) : node(node) {} // The first `import` directive in the file, which declared the package's // identifier (even if the import failed). Used for associating diagnostics // not specific to a single import. - Parse::Node node; + Parse::NodeId node; // Whether there's an import that failed to load. bool has_load_error = false; // The list of valid imports. @@ -50,7 +50,7 @@ struct UnitInfo { // Emitter information. Parse::NodeLocationTranslator translator; ErrorTrackingDiagnosticConsumer err_tracker; - DiagnosticEmitter emitter; + DiagnosticEmitter emitter; // A map of package names to outgoing imports. If the // import's target isn't available, the unit will be nullptr to assist with @@ -175,7 +175,7 @@ static constexpr llvm::StringLiteral ExplicitMainName = "Main"; // come from the same file. static auto TrackImport( llvm::DenseMap& api_map, - llvm::DenseMap* explicit_import_map, + llvm::DenseMap* explicit_import_map, UnitInfo& unit_info, Parse::Tree::PackagingNames import) -> void { const auto& packaging = unit_info.unit->parse_tree->packaging_directive(); @@ -347,7 +347,7 @@ static auto BuildApiMapAndDiagnosePackaging( "Main//default previously provided by `{0}`.", std::string); // Use the invalid node because there's no node to associate with. - unit_info.emitter.Emit(Parse::Node::Invalid, DuplicateMainApi, + unit_info.emitter.Emit(Parse::NodeId::Invalid, DuplicateMainApi, prev_filename.str()); } } @@ -367,14 +367,14 @@ static auto BuildApiMapAndDiagnosePackaging( "File extension of `{0}` required for `{1}`.", llvm::StringLiteral, Lex::TokenKind); auto diag = unit_info.emitter.Build( - packaging ? packaging->names.node : Parse::Node::Invalid, + packaging ? packaging->names.node : Parse::NodeId::Invalid, IncorrectExtension, want_ext, is_impl ? Lex::TokenKind::Impl : Lex::TokenKind::Api); if (is_api_with_impl_ext) { CARBON_DIAGNOSTIC(IncorrectExtensionImplNote, Note, "File extension of `{0}` only allowed for `{1}`.", llvm::StringLiteral, Lex::TokenKind); - diag.Note(Parse::Node::Invalid, IncorrectExtensionImplNote, ImplExt, + diag.Note(Parse::NodeId::Invalid, IncorrectExtensionImplNote, ImplExt, Lex::TokenKind::Impl); } diag.Emit(); @@ -412,7 +412,7 @@ auto CheckParseTrees(const SemIR::File& builtin_ir, } } - llvm::DenseMap explicit_import_map; + llvm::DenseMap explicit_import_map; for (const auto& import : unit_info.unit->parse_tree->imports()) { TrackImport(api_map, &explicit_import_map, unit_info, import); } diff --git a/toolchain/check/context.cpp b/toolchain/check/context.cpp index 583e6f5c9aef..c963505c7bcb 100644 --- a/toolchain/check/context.cpp +++ b/toolchain/check/context.cpp @@ -42,7 +42,7 @@ Context::Context(const Lex::TokenizedBuffer& tokens, DiagnosticEmitter& emitter, {SemIR::InstId::BuiltinTypeType, SemIR::TypeId::TypeType}); } -auto Context::TODO(Parse::Node parse_node, std::string label) -> bool { +auto Context::TODO(Parse::NodeId parse_node, std::string label) -> bool { CARBON_DIAGNOSTIC(SemanticsTodo, Error, "Semantics TODO: `{0}`.", std::string); emitter_->Emit(parse_node, SemanticsTodo, std::move(label)); @@ -73,12 +73,13 @@ auto Context::AddConstantInst(SemIR::Inst inst) -> SemIR::InstId { return inst_id; } -auto Context::AddInstAndPush(Parse::Node parse_node, SemIR::Inst inst) -> void { +auto Context::AddInstAndPush(Parse::NodeId parse_node, SemIR::Inst inst) + -> void { auto inst_id = AddInst(inst); node_stack_.Push(parse_node, inst_id); } -auto Context::DiagnoseDuplicateName(Parse::Node parse_node, +auto Context::DiagnoseDuplicateName(Parse::NodeId parse_node, SemIR::InstId prev_def_id) -> void { CARBON_DIAGNOSTIC(NameDeclDuplicate, Error, "Duplicate name being declared in the same scope."); @@ -90,7 +91,7 @@ auto Context::DiagnoseDuplicateName(Parse::Node parse_node, .Emit(); } -auto Context::DiagnoseNameNotFound(Parse::Node parse_node, +auto Context::DiagnoseNameNotFound(Parse::NodeId parse_node, SemIR::NameId name_id) -> void { CARBON_DIAGNOSTIC(NameNotFound, Error, "Name `{0}` not found.", std::string); emitter_->Emit(parse_node, NameNotFound, names().GetFormatted(name_id).str()); @@ -113,7 +114,7 @@ auto Context::NoteIncompleteClass(SemIR::ClassId class_id, } } -auto Context::AddPackageImports(Parse::Node import_node, +auto Context::AddPackageImports(Parse::NodeId import_node, IdentifierId package_id, llvm::ArrayRef sem_irs, bool has_load_error) -> void { @@ -152,7 +153,7 @@ auto Context::AddPackageImports(Parse::Node import_node, } } -auto Context::AddNameToLookup(Parse::Node name_node, SemIR::NameId name_id, +auto Context::AddNameToLookup(Parse::NodeId name_node, SemIR::NameId name_id, SemIR::InstId target_id) -> void { if (current_scope().names.insert(name_id).second) { // TODO: Reject if we previously performed a failed lookup for this name in @@ -168,7 +169,7 @@ auto Context::AddNameToLookup(Parse::Node name_node, SemIR::NameId name_id, } } -auto Context::LookupNameInDecl(Parse::Node parse_node, SemIR::NameId name_id, +auto Context::LookupNameInDecl(Parse::NodeId parse_node, SemIR::NameId name_id, SemIR::NameScopeId scope_id) -> SemIR::InstId { if (scope_id == SemIR::NameScopeId::Invalid) { // Look for a name in the current scope only. There are two cases where the @@ -212,7 +213,7 @@ auto Context::LookupNameInDecl(Parse::Node parse_node, SemIR::NameId name_id, } } -auto Context::LookupUnqualifiedName(Parse::Node parse_node, +auto Context::LookupUnqualifiedName(Parse::NodeId parse_node, SemIR::NameId name_id) -> SemIR::InstId { // TODO: Check for shadowed lookup results. @@ -252,7 +253,8 @@ auto Context::LookupUnqualifiedName(Parse::Node parse_node, return SemIR::InstId::BuiltinError; } -auto Context::LookupQualifiedName(Parse::Node parse_node, SemIR::NameId name_id, +auto Context::LookupQualifiedName(Parse::NodeId parse_node, + SemIR::NameId name_id, SemIR::NameScopeId scope_id, bool required) -> SemIR::InstId { CARBON_CHECK(scope_id.is_valid()) << "No scope to perform lookup into"; @@ -371,8 +373,8 @@ auto Context::GetConstantValue(SemIR::InstId inst_id) -> SemIR::InstId { template static auto AddDominatedBlockAndBranchImpl(Context& context, - Parse::Node parse_node, Args... args) - -> SemIR::InstBlockId { + Parse::NodeId parse_node, + Args... args) -> SemIR::InstBlockId { if (!context.inst_block_stack().is_current_block_reachable()) { return SemIR::InstBlockId::Unreachable; } @@ -381,27 +383,27 @@ static auto AddDominatedBlockAndBranchImpl(Context& context, return block_id; } -auto Context::AddDominatedBlockAndBranch(Parse::Node parse_node) +auto Context::AddDominatedBlockAndBranch(Parse::NodeId parse_node) -> SemIR::InstBlockId { return AddDominatedBlockAndBranchImpl(*this, parse_node); } -auto Context::AddDominatedBlockAndBranchWithArg(Parse::Node parse_node, +auto Context::AddDominatedBlockAndBranchWithArg(Parse::NodeId parse_node, SemIR::InstId arg_id) -> SemIR::InstBlockId { return AddDominatedBlockAndBranchImpl(*this, parse_node, arg_id); } -auto Context::AddDominatedBlockAndBranchIf(Parse::Node parse_node, +auto Context::AddDominatedBlockAndBranchIf(Parse::NodeId parse_node, SemIR::InstId cond_id) -> SemIR::InstBlockId { return AddDominatedBlockAndBranchImpl(*this, parse_node, cond_id); } -auto Context::AddConvergenceBlockAndPush(Parse::Node parse_node, int num_blocks) - -> void { +auto Context::AddConvergenceBlockAndPush(Parse::NodeId parse_node, + int num_blocks) -> void { CARBON_CHECK(num_blocks >= 2) << "no convergence"; SemIR::InstBlockId new_block_id = SemIR::InstBlockId::Unreachable; @@ -418,7 +420,7 @@ auto Context::AddConvergenceBlockAndPush(Parse::Node parse_node, int num_blocks) } auto Context::AddConvergenceBlockWithArgAndPush( - Parse::Node parse_node, std::initializer_list block_args) + Parse::NodeId parse_node, std::initializer_list block_args) -> SemIR::InstId { CARBON_CHECK(block_args.size() >= 2) << "no convergence"; @@ -440,7 +442,7 @@ auto Context::AddConvergenceBlockWithArgAndPush( } // Add the current code block to the enclosing function. -auto Context::AddCurrentCodeBlockToFunction(Parse::Node parse_node) -> void { +auto Context::AddCurrentCodeBlockToFunction(Parse::NodeId parse_node) -> void { CARBON_CHECK(!inst_block_stack().empty()) << "no current code block"; if (return_scope_stack().empty()) { @@ -653,7 +655,7 @@ class TypeCompleter { // Makes an empty value representation, which is used for types that have no // state, such as empty structs and tuples. - auto MakeEmptyRepresentation(Parse::Node parse_node) const + auto MakeEmptyRepresentation(Parse::NodeId parse_node) const -> SemIR::ValueRepresentation { return {.kind = SemIR::ValueRepresentation::None, .type_id = context_.CanonicalizeTupleType(parse_node, {})}; @@ -674,7 +676,7 @@ class TypeCompleter { // Makes a value representation that uses pass-by-address with the given // pointee type. auto MakePointerRepresentation( - Parse::Node parse_node, SemIR::TypeId pointee_id, + Parse::NodeId parse_node, SemIR::TypeId pointee_id, SemIR::ValueRepresentation::AggregateKind aggregate_kind = SemIR::ValueRepresentation::NotAggregate) const -> SemIR::ValueRepresentation { @@ -726,12 +728,12 @@ class TypeCompleter { // TODO: Decide on string value semantics. This should probably be a // custom value representation carrying a pointer and size or // similar. - return MakePointerRepresentation(Parse::Node::Invalid, type_id); + return MakePointerRepresentation(Parse::NodeId::Invalid, type_id); } llvm_unreachable("All builtin kinds were handled above"); } - auto BuildStructOrTupleValueRepresentation(Parse::Node parse_node, + auto BuildStructOrTupleValueRepresentation(Parse::NodeId parse_node, std::size_t num_elements, SemIR::TypeId elementwise_rep, bool same_as_object_rep) const @@ -1098,14 +1100,14 @@ auto Context::CanonicalizeType(SemIR::InstId inst_id) -> SemIR::TypeId { return CanonicalizeTypeImpl(inst.kind(), profile_node, make_inst); } -auto Context::CanonicalizeStructType(Parse::Node parse_node, +auto Context::CanonicalizeStructType(Parse::NodeId parse_node, SemIR::InstBlockId refs_id) -> SemIR::TypeId { return CanonicalizeTypeAndAddInstIfNew( SemIR::StructType{parse_node, SemIR::TypeId::TypeType, refs_id}); } -auto Context::CanonicalizeTupleType(Parse::Node parse_node, +auto Context::CanonicalizeTupleType(Parse::NodeId parse_node, llvm::ArrayRef type_ids) -> SemIR::TypeId { // Defer allocating a SemIR::TypeBlockId until we know this is a new type. @@ -1130,7 +1132,7 @@ auto Context::GetBuiltinType(SemIR::BuiltinKind kind) -> SemIR::TypeId { return type_id; } -auto Context::GetPointerType(Parse::Node parse_node, +auto Context::GetPointerType(Parse::NodeId parse_node, SemIR::TypeId pointee_type_id) -> SemIR::TypeId { return CanonicalizeTypeAndAddInstIfNew( SemIR::PointerType{parse_node, SemIR::TypeId::TypeType, pointee_type_id}); diff --git a/toolchain/check/context.h b/toolchain/check/context.h index 918cb09454ea..63e20b636bf6 100644 --- a/toolchain/check/context.h +++ b/toolchain/check/context.h @@ -22,7 +22,7 @@ namespace Carbon::Check { // Context and shared functionality for semantics handlers. class Context { public: - using DiagnosticEmitter = Carbon::DiagnosticEmitter; + using DiagnosticEmitter = Carbon::DiagnosticEmitter; using DiagnosticBuilder = DiagnosticEmitter::DiagnosticBuilder; // A scope in which `break` and `continue` can be used. @@ -48,7 +48,7 @@ class Context { SemIR::File& semantics, llvm::raw_ostream* vlog_stream); // Marks an implementation TODO. Always returns false. - auto TODO(Parse::Node parse_node, std::string label) -> bool; + auto TODO(Parse::NodeId parse_node, std::string label) -> bool; // Runs verification that the processing cleanly finished. auto VerifyOnFinish() -> void; @@ -61,40 +61,40 @@ class Context { // Pushes a parse tree node onto the stack, storing the SemIR::Inst as the // result. - auto AddInstAndPush(Parse::Node parse_node, SemIR::Inst inst) -> void; + auto AddInstAndPush(Parse::NodeId parse_node, SemIR::Inst inst) -> void; // Adds a package's imports to name lookup, with all libraries together. // sem_irs will all be non-null; has_load_error must be used for any errors. - auto AddPackageImports(Parse::Node import_node, IdentifierId package_id, + auto AddPackageImports(Parse::NodeId import_node, IdentifierId package_id, llvm::ArrayRef sem_irs, bool has_load_error) -> void; // Adds a name to name lookup. Prints a diagnostic for name conflicts. - auto AddNameToLookup(Parse::Node name_node, SemIR::NameId name_id, + auto AddNameToLookup(Parse::NodeId name_node, SemIR::NameId name_id, SemIR::InstId target_id) -> void; // Performs name lookup in a specified scope for a name appearing in a // declaration, returning the referenced instruction. If scope_id is invalid, // uses the current contextual scope. - auto LookupNameInDecl(Parse::Node parse_node, SemIR::NameId name_id, + auto LookupNameInDecl(Parse::NodeId parse_node, SemIR::NameId name_id, SemIR::NameScopeId scope_id) -> SemIR::InstId; // Performs an unqualified name lookup, returning the referenced instruction. - auto LookupUnqualifiedName(Parse::Node parse_node, SemIR::NameId name_id) + auto LookupUnqualifiedName(Parse::NodeId parse_node, SemIR::NameId name_id) -> SemIR::InstId; // Performs a qualified name lookup in a specified scope and in scopes that // it extends, returning the referenced instruction. - auto LookupQualifiedName(Parse::Node parse_node, SemIR::NameId name_id, + auto LookupQualifiedName(Parse::NodeId parse_node, SemIR::NameId name_id, SemIR::NameScopeId scope_id, bool required = true) -> SemIR::InstId; // Prints a diagnostic for a duplicate name. - auto DiagnoseDuplicateName(Parse::Node parse_node, SemIR::InstId prev_def_id) - -> void; + auto DiagnoseDuplicateName(Parse::NodeId parse_node, + SemIR::InstId prev_def_id) -> void; // Prints a diagnostic for a missing name. - auto DiagnoseNameNotFound(Parse::Node parse_node, SemIR::NameId name_id) + auto DiagnoseNameNotFound(Parse::NodeId parse_node, SemIR::NameId name_id) -> void; // Adds a note to a diagnostic explaining that a class is incomplete. @@ -148,26 +148,27 @@ class Context { // Adds a `Branch` instruction branching to a new instruction block, and // returns the ID of the new block. All paths to the branch target must go // through the current block, though not necessarily through this branch. - auto AddDominatedBlockAndBranch(Parse::Node parse_node) -> SemIR::InstBlockId; + auto AddDominatedBlockAndBranch(Parse::NodeId parse_node) + -> SemIR::InstBlockId; // Adds a `Branch` instruction branching to a new instruction block with a // value, and returns the ID of the new block. All paths to the branch target // must go through the current block. - auto AddDominatedBlockAndBranchWithArg(Parse::Node parse_node, + auto AddDominatedBlockAndBranchWithArg(Parse::NodeId parse_node, SemIR::InstId arg_id) -> SemIR::InstBlockId; // Adds a `BranchIf` instruction branching to a new instruction block, and // returns the ID of the new block. All paths to the branch target must go // through the current block. - auto AddDominatedBlockAndBranchIf(Parse::Node parse_node, + auto AddDominatedBlockAndBranchIf(Parse::NodeId parse_node, SemIR::InstId cond_id) -> SemIR::InstBlockId; // Handles recovergence of control flow. Adds branches from the top // `num_blocks` on the instruction block stack to a new block, pops the // existing blocks, and pushes the new block onto the instruction block stack. - auto AddConvergenceBlockAndPush(Parse::Node parse_node, int num_blocks) + auto AddConvergenceBlockAndPush(Parse::NodeId parse_node, int num_blocks) -> void; // Handles recovergence of control flow with a result value. Adds branches @@ -177,7 +178,7 @@ class Context { // corresponding result values are the elements of `block_args`. Returns an // instruction referring to the result value. auto AddConvergenceBlockWithArgAndPush( - Parse::Node parse_node, + Parse::NodeId parse_node, std::initializer_list blocks_and_args) -> SemIR::InstId; // Add the current code block to the enclosing function. @@ -185,7 +186,7 @@ class Context { // non-function contexts. This should be refactored to support non-function // contexts, and parse_node removed. auto AddCurrentCodeBlockToFunction( - Parse::Node parse_node = Parse::Node::Invalid) -> void; + Parse::NodeId parse_node = Parse::NodeId::Invalid) -> void; // Returns whether the current position in the current block is reachable. auto is_current_position_reachable() -> bool; @@ -200,12 +201,12 @@ class Context { // Individual struct type fields aren't canonicalized because they may have // name conflicts or other diagnostics during creation, which can use the // parse node. - auto CanonicalizeStructType(Parse::Node parse_node, + auto CanonicalizeStructType(Parse::NodeId parse_node, SemIR::InstBlockId refs_id) -> SemIR::TypeId; // Handles canonicalization of tuple types. This may create a new tuple type // if the `type_ids` doesn't match an existing tuple type. - auto CanonicalizeTupleType(Parse::Node parse_node, + auto CanonicalizeTupleType(Parse::NodeId parse_node, llvm::ArrayRef type_ids) -> SemIR::TypeId; @@ -225,7 +226,7 @@ class Context { auto GetBuiltinType(SemIR::BuiltinKind kind) -> SemIR::TypeId; // Returns a pointer type whose pointee type is `pointee_type_id`. - auto GetPointerType(Parse::Node parse_node, SemIR::TypeId pointee_type_id) + auto GetPointerType(Parse::NodeId parse_node, SemIR::TypeId pointee_type_id) -> SemIR::TypeId; // Removes any top-level `const` qualifiers from a type. @@ -480,7 +481,7 @@ class Context { // Parse node handlers. Returns false for unrecoverable errors. #define CARBON_PARSE_NODE_KIND(Name) \ - auto Handle##Name(Context& context, Parse::Node parse_node)->bool; + auto Handle##Name(Context& context, Parse::NodeId parse_node)->bool; #include "toolchain/parse/node_kind.def" } // namespace Carbon::Check diff --git a/toolchain/check/convert.cpp b/toolchain/check/convert.cpp index 19efea5094e0..f1cd3f4891ed 100644 --- a/toolchain/check/convert.cpp +++ b/toolchain/check/convert.cpp @@ -128,7 +128,7 @@ static auto MaterializeIfInitializing(Context& context, SemIR::InstId expr_id) // Creates and adds an instruction to perform element access into an aggregate. template -static auto MakeElementAccessInst(Context& context, Parse::Node parse_node, +static auto MakeElementAccessInst(Context& context, Parse::NodeId parse_node, SemIR::InstId aggregate_id, SemIR::TypeId elem_type_id, InstBlockT& block, std::size_t i) { @@ -162,7 +162,7 @@ static auto MakeElementAccessInst(Context& context, Parse::Node parse_node, // instruction used to access the destination element. template static auto ConvertAggregateElement( - Context& context, Parse::Node parse_node, SemIR::InstId src_id, + Context& context, Parse::NodeId parse_node, SemIR::InstId src_id, SemIR::TypeId src_elem_type, llvm::ArrayRef src_literal_elems, ConversionTarget::Kind kind, SemIR::InstId target_id, @@ -598,7 +598,7 @@ static bool IsValidExprCategoryForConversionTarget( } } -static auto PerformBuiltinConversion(Context& context, Parse::Node parse_node, +static auto PerformBuiltinConversion(Context& context, Parse::NodeId parse_node, SemIR::InstId value_id, ConversionTarget target) -> SemIR::InstId { auto& sem_ir = context.sem_ir(); @@ -769,7 +769,7 @@ static auto PerformCopy(Context& context, SemIR::InstId expr_id) return SemIR::InstId::BuiltinError; } -auto Convert(Context& context, Parse::Node parse_node, SemIR::InstId expr_id, +auto Convert(Context& context, Parse::NodeId parse_node, SemIR::InstId expr_id, ConversionTarget target) -> SemIR::InstId { auto& sem_ir = context.sem_ir(); auto orig_expr_id = expr_id; @@ -921,7 +921,7 @@ auto Convert(Context& context, Parse::Node parse_node, SemIR::InstId expr_id, return expr_id; } -auto Initialize(Context& context, Parse::Node parse_node, +auto Initialize(Context& context, Parse::NodeId parse_node, SemIR::InstId target_id, SemIR::InstId value_id) -> SemIR::InstId { PendingBlock target_block(context); @@ -947,21 +947,21 @@ auto ConvertToValueOrRefExpr(Context& context, SemIR::InstId expr_id) {.kind = ConversionTarget::ValueOrRef, .type_id = expr.type_id()}); } -auto ConvertToValueOfType(Context& context, Parse::Node parse_node, +auto ConvertToValueOfType(Context& context, Parse::NodeId parse_node, SemIR::InstId value_id, SemIR::TypeId type_id) -> SemIR::InstId { return Convert(context, parse_node, value_id, {.kind = ConversionTarget::Value, .type_id = type_id}); } -auto ConvertToBoolValue(Context& context, Parse::Node parse_node, +auto ConvertToBoolValue(Context& context, Parse::NodeId parse_node, SemIR::InstId value_id) -> SemIR::InstId { return ConvertToValueOfType( context, parse_node, value_id, context.GetBuiltinType(SemIR::BuiltinKind::BoolType)); } -auto ConvertForExplicitAs(Context& context, Parse::Node as_node, +auto ConvertForExplicitAs(Context& context, Parse::NodeId as_node, SemIR::InstId value_id, SemIR::TypeId type_id) -> SemIR::InstId { return Convert(context, as_node, value_id, @@ -971,8 +971,8 @@ auto ConvertForExplicitAs(Context& context, Parse::Node as_node, CARBON_DIAGNOSTIC(InCallToFunction, Note, "Calling function declared here."); // Convert the object argument in a method call to match the `self` parameter. -static auto ConvertSelf(Context& context, Parse::Node call_parse_node, - Parse::Node callee_parse_node, +static auto ConvertSelf(Context& context, Parse::NodeId call_parse_node, + Parse::NodeId callee_parse_node, SemIR::SelfParam self_param, SemIR::InstId self_id) -> SemIR::InstId { if (!self_id.is_valid()) { @@ -1023,11 +1023,11 @@ static auto ConvertSelf(Context& context, Parse::Node call_parse_node, self_param.type_id); } -auto ConvertCallArgs(Context& context, Parse::Node call_parse_node, +auto ConvertCallArgs(Context& context, Parse::NodeId call_parse_node, SemIR::InstId self_id, llvm::ArrayRef arg_refs, SemIR::InstId return_storage_id, - Parse::Node callee_parse_node, + Parse::NodeId callee_parse_node, SemIR::InstBlockId implicit_param_refs_id, SemIR::InstBlockId param_refs_id) -> SemIR::InstBlockId { auto implicit_param_refs = @@ -1104,7 +1104,7 @@ auto ConvertCallArgs(Context& context, Parse::Node call_parse_node, return context.inst_blocks().Add(args); } -auto ExprAsType(Context& context, Parse::Node parse_node, +auto ExprAsType(Context& context, Parse::NodeId parse_node, SemIR::InstId value_id) -> SemIR::TypeId { auto type_inst_id = ConvertToValueOfType(context, parse_node, value_id, SemIR::TypeId::TypeType); diff --git a/toolchain/check/convert.h b/toolchain/check/convert.h index fe51f3fc5e14..1f0e6642e91e 100644 --- a/toolchain/check/convert.h +++ b/toolchain/check/convert.h @@ -52,13 +52,13 @@ struct ConversionTarget { }; // Convert a value to another type and expression category. -auto Convert(Context& context, Parse::Node parse_node, SemIR::InstId value_id, +auto Convert(Context& context, Parse::NodeId parse_node, SemIR::InstId value_id, ConversionTarget target) -> SemIR::InstId; // Performs initialization of `target_id` from `value_id`. Returns the // possibly-converted initializing expression, which should be assigned to the // target using a suitable node for the kind of initialization. -auto Initialize(Context& context, Parse::Node parse_node, +auto Initialize(Context& context, Parse::NodeId parse_node, SemIR::InstId target_id, SemIR::InstId value_id) -> SemIR::InstId; @@ -72,32 +72,32 @@ auto ConvertToValueOrRefExpr(Context& context, SemIR::InstId expr_id) -> SemIR::InstId; // Converts `value_id` to a value expression of type `type_id`. -auto ConvertToValueOfType(Context& context, Parse::Node parse_node, +auto ConvertToValueOfType(Context& context, Parse::NodeId parse_node, SemIR::InstId value_id, SemIR::TypeId type_id) -> SemIR::InstId; // Converts `value_id` to a value expression of type `bool`. -auto ConvertToBoolValue(Context& context, Parse::Node parse_node, +auto ConvertToBoolValue(Context& context, Parse::NodeId parse_node, SemIR::InstId value_id) -> SemIR::InstId; // Converts `value_id` to type `type_id` for an `as` expression. -auto ConvertForExplicitAs(Context& context, Parse::Node as_node, +auto ConvertForExplicitAs(Context& context, Parse::NodeId as_node, SemIR::InstId value_id, SemIR::TypeId type_id) -> SemIR::InstId; // Implicitly converts a set of arguments to match the parameter types in a // function call. Returns a block containing the converted implicit and explicit // argument values. -auto ConvertCallArgs(Context& context, Parse::Node call_parse_node, +auto ConvertCallArgs(Context& context, Parse::NodeId call_parse_node, SemIR::InstId self_id, llvm::ArrayRef arg_refs, SemIR::InstId return_storage_id, - Parse::Node callee_parse_node, + Parse::NodeId callee_parse_node, SemIR::InstBlockId implicit_param_refs_id, SemIR::InstBlockId param_refs_id) -> SemIR::InstBlockId; // Converts an expression for use as a type. -auto ExprAsType(Context& context, Parse::Node parse_node, +auto ExprAsType(Context& context, Parse::NodeId parse_node, SemIR::InstId value_id) -> SemIR::TypeId; } // namespace Carbon::Check diff --git a/toolchain/check/decl_name_stack.cpp b/toolchain/check/decl_name_stack.cpp index 9bc3a7f8f776..cb2a0d452a2a 100644 --- a/toolchain/check/decl_name_stack.cpp +++ b/toolchain/check/decl_name_stack.cpp @@ -13,7 +13,7 @@ auto DeclNameStack::MakeEmptyNameContext() -> NameContext { .target_scope_id = context_->current_scope_id()}; } -auto DeclNameStack::MakeUnqualifiedName(Parse::Node parse_node, +auto DeclNameStack::MakeUnqualifiedName(Parse::NodeId parse_node, SemIR::NameId name_id) -> NameContext { NameContext context = MakeEmptyNameContext(); ApplyNameQualifierTo(context, parse_node, name_id); @@ -98,13 +98,13 @@ auto DeclNameStack::AddNameToLookup(NameContext name_context, } } -auto DeclNameStack::ApplyNameQualifier(Parse::Node parse_node, +auto DeclNameStack::ApplyNameQualifier(Parse::NodeId parse_node, SemIR::NameId name_id) -> void { ApplyNameQualifierTo(decl_name_stack_.back(), parse_node, name_id); } auto DeclNameStack::ApplyNameQualifierTo(NameContext& name_context, - Parse::Node parse_node, + Parse::NodeId parse_node, SemIR::NameId name_id) -> void { if (CanResolveQualifier(name_context, parse_node)) { // For identifier nodes, we need to perform a lookup on the identifier. @@ -156,7 +156,7 @@ auto DeclNameStack::UpdateScopeIfNeeded(NameContext& name_context) -> void { } auto DeclNameStack::CanResolveQualifier(NameContext& name_context, - Parse::Node parse_node) -> bool { + Parse::NodeId parse_node) -> bool { switch (name_context.state) { case NameContext::State::Error: // Already in an error state, so return without examining. diff --git a/toolchain/check/decl_name_stack.h b/toolchain/check/decl_name_stack.h index aab00939a7cd..e60aa5291ada 100644 --- a/toolchain/check/decl_name_stack.h +++ b/toolchain/check/decl_name_stack.h @@ -116,7 +116,7 @@ class DeclNameStack { SemIR::NameScopeId target_scope_id; // The last parse node used. - Parse::Node parse_node = Parse::Node::Invalid; + Parse::NodeId parse_node = Parse::NodeId::Invalid; union { // The ID of a resolved qualifier, including both identifiers and @@ -154,13 +154,13 @@ class DeclNameStack { // unqualified name in the current context. This is suitable for adding to // name lookup in situations where a qualified name is not permitted, such as // a pattern binding. - auto MakeUnqualifiedName(Parse::Node parse_node, SemIR::NameId name_id) + auto MakeUnqualifiedName(Parse::NodeId parse_node, SemIR::NameId name_id) -> NameContext; // Applies a Name from the name stack to the top of the declaration name // stack. This will enter the scope corresponding to the name if the name // describes an existing scope, such as a namespace or a defined class. - auto ApplyNameQualifier(Parse::Node parse_node, SemIR::NameId name_id) + auto ApplyNameQualifier(Parse::NodeId parse_node, SemIR::NameId name_id) -> void; // Adds a name to name lookup. Prints a diagnostic for name conflicts. @@ -177,12 +177,12 @@ class DeclNameStack { auto MakeEmptyNameContext() -> NameContext; // Applies a Name from the name stack to given name context. - auto ApplyNameQualifierTo(NameContext& name_context, Parse::Node parse_node, + auto ApplyNameQualifierTo(NameContext& name_context, Parse::NodeId parse_node, SemIR::NameId name_id) -> void; // Returns true if the context is in a state where it can resolve qualifiers. // Updates name_context as needed. - auto CanResolveQualifier(NameContext& name_context, Parse::Node parse_node) + auto CanResolveQualifier(NameContext& name_context, Parse::NodeId parse_node) -> bool; // Updates the scope on name_context as needed. This is called after diff --git a/toolchain/check/handle_array.cpp b/toolchain/check/handle_array.cpp index 0a82cb9217c6..d7e79513524f 100644 --- a/toolchain/check/handle_array.cpp +++ b/toolchain/check/handle_array.cpp @@ -10,17 +10,17 @@ namespace Carbon::Check { -auto HandleArrayExprStart(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandleArrayExprStart(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } -auto HandleArrayExprSemi(Context& context, Parse::Node parse_node) -> bool { +auto HandleArrayExprSemi(Context& context, Parse::NodeId parse_node) -> bool { context.node_stack().Push(parse_node); return true; } -auto HandleArrayExpr(Context& context, Parse::Node parse_node) -> bool { +auto HandleArrayExpr(Context& context, Parse::NodeId parse_node) -> bool { // TODO: Handle array type with undefined bound. if (context.parse_tree().node_kind(context.node_stack().PeekParseNode()) == Parse::NodeKind::ArrayExprSemi) { diff --git a/toolchain/check/handle_call_expr.cpp b/toolchain/check/handle_call_expr.cpp index b1a0fe728f49..ced607f21ea4 100644 --- a/toolchain/check/handle_call_expr.cpp +++ b/toolchain/check/handle_call_expr.cpp @@ -9,7 +9,7 @@ namespace Carbon::Check { -auto HandleCallExpr(Context& context, Parse::Node parse_node) -> bool { +auto HandleCallExpr(Context& context, Parse::NodeId parse_node) -> bool { // Process the final explicit call argument now, but leave the arguments // block on the stack until the end of this function. context.ParamOrArgEndNoPop(Parse::NodeKind::CallExprStart); @@ -84,12 +84,13 @@ auto HandleCallExpr(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleCallExprComma(Context& context, Parse::Node /*parse_node*/) -> bool { +auto HandleCallExprComma(Context& context, Parse::NodeId /*parse_node*/) + -> bool { context.ParamOrArgComma(); return true; } -auto HandleCallExprStart(Context& context, Parse::Node parse_node) -> bool { +auto HandleCallExprStart(Context& context, Parse::NodeId parse_node) -> bool { auto name_id = context.node_stack().PopExpr(); context.node_stack().Push(parse_node, name_id); context.ParamOrArgStart(); diff --git a/toolchain/check/handle_class.cpp b/toolchain/check/handle_class.cpp index 54bde1c2280a..83fc2e69b40a 100644 --- a/toolchain/check/handle_class.cpp +++ b/toolchain/check/handle_class.cpp @@ -7,7 +7,7 @@ namespace Carbon::Check { -auto HandleClassIntroducer(Context& context, Parse::Node parse_node) -> bool { +auto HandleClassIntroducer(Context& context, Parse::NodeId parse_node) -> bool { // Create an instruction block to hold the instructions created as part of the // class signature, such as generic parameters. context.inst_block_stack().Push(); @@ -18,12 +18,13 @@ auto HandleClassIntroducer(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleAbstractModifier(Context& context, Parse::Node parse_node) -> bool { +auto HandleAbstractModifier(Context& context, Parse::NodeId parse_node) + -> bool { context.node_stack().Push(parse_node); return true; } -auto HandleBaseModifier(Context& context, Parse::Node parse_node) -> bool { +auto HandleBaseModifier(Context& context, Parse::NodeId parse_node) -> bool { context.node_stack().Push(parse_node); return true; } @@ -113,13 +114,13 @@ static auto BuildClassDecl(Context& context) return {class_decl.class_id, class_decl_id}; } -auto HandleClassDecl(Context& context, Parse::Node /*parse_node*/) -> bool { +auto HandleClassDecl(Context& context, Parse::NodeId /*parse_node*/) -> bool { BuildClassDecl(context); context.decl_name_stack().PopScope(); return true; } -auto HandleClassDefinitionStart(Context& context, Parse::Node parse_node) +auto HandleClassDefinitionStart(Context& context, Parse::NodeId parse_node) -> bool { auto [class_id, class_decl_id] = BuildClassDecl(context); auto& class_info = context.classes().Get(class_id); @@ -166,7 +167,7 @@ auto HandleClassDefinitionStart(Context& context, Parse::Node parse_node) return true; } -auto HandleClassDefinition(Context& context, Parse::Node parse_node) -> bool { +auto HandleClassDefinition(Context& context, Parse::NodeId parse_node) -> bool { auto fields_id = context.args_type_info_stack().Pop(); auto class_id = context.node_stack().Pop(); diff --git a/toolchain/check/handle_codeblock.cpp b/toolchain/check/handle_codeblock.cpp index 717bdc1db1c1..c8d369fdbb42 100644 --- a/toolchain/check/handle_codeblock.cpp +++ b/toolchain/check/handle_codeblock.cpp @@ -6,13 +6,13 @@ namespace Carbon::Check { -auto HandleCodeBlockStart(Context& context, Parse::Node parse_node) -> bool { +auto HandleCodeBlockStart(Context& context, Parse::NodeId parse_node) -> bool { context.node_stack().Push(parse_node); context.PushScope(); return true; } -auto HandleCodeBlock(Context& context, Parse::Node /*parse_node*/) -> bool { +auto HandleCodeBlock(Context& context, Parse::NodeId /*parse_node*/) -> bool { context.PopScope(); context.node_stack().PopForSoloParseNode(); return true; diff --git a/toolchain/check/handle_expr_statement.cpp b/toolchain/check/handle_expr_statement.cpp index d7d39c6688df..7e1e54aca626 100644 --- a/toolchain/check/handle_expr_statement.cpp +++ b/toolchain/check/handle_expr_statement.cpp @@ -21,7 +21,8 @@ static auto HandleDiscardedExpr(Context& context, SemIR::InstId expr_id) // TODO: This will eventually need to do some "do not discard" analysis. } -auto HandleExprStatement(Context& context, Parse::Node /*parse_node*/) -> bool { +auto HandleExprStatement(Context& context, Parse::NodeId /*parse_node*/) + -> bool { HandleDiscardedExpr(context, context.node_stack().PopExpr()); return true; } diff --git a/toolchain/check/handle_file.cpp b/toolchain/check/handle_file.cpp index 7868dcba34f6..db5eb2913348 100644 --- a/toolchain/check/handle_file.cpp +++ b/toolchain/check/handle_file.cpp @@ -6,14 +6,15 @@ namespace Carbon::Check { -auto HandleFileStart(Context& /*context*/, Parse::Node /*parse_node*/) -> bool { +auto HandleFileStart(Context& /*context*/, Parse::NodeId /*parse_node*/) + -> bool { // No action to perform. // TODO: We may want to push `FileStart` as a sentinel so that `Peek`s can't // fail. return true; } -auto HandleFileEnd(Context& /*context*/, Parse::Node /*parse_node*/) -> bool { +auto HandleFileEnd(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { // No action to perform. return true; } diff --git a/toolchain/check/handle_function.cpp b/toolchain/check/handle_function.cpp index a1c4d274d80b..3b816f00d0e1 100644 --- a/toolchain/check/handle_function.cpp +++ b/toolchain/check/handle_function.cpp @@ -127,13 +127,14 @@ static auto BuildFunctionDecl(Context& context, bool is_definition) return {function_decl.function_id, function_decl_id}; } -auto HandleFunctionDecl(Context& context, Parse::Node /*parse_node*/) -> bool { +auto HandleFunctionDecl(Context& context, Parse::NodeId /*parse_node*/) + -> bool { BuildFunctionDecl(context, /*is_definition=*/false); context.decl_name_stack().PopScope(); return true; } -auto HandleFunctionDefinition(Context& context, Parse::Node parse_node) +auto HandleFunctionDefinition(Context& context, Parse::NodeId parse_node) -> bool { SemIR::FunctionId function_id = context.node_stack().Pop(); @@ -158,7 +159,7 @@ auto HandleFunctionDefinition(Context& context, Parse::Node parse_node) return true; } -auto HandleFunctionDefinitionStart(Context& context, Parse::Node parse_node) +auto HandleFunctionDefinitionStart(Context& context, Parse::NodeId parse_node) -> bool { // Process the declaration portion of the function. auto [function_id, decl_id] = @@ -220,7 +221,7 @@ auto HandleFunctionDefinitionStart(Context& context, Parse::Node parse_node) return true; } -auto HandleFunctionIntroducer(Context& context, Parse::Node parse_node) +auto HandleFunctionIntroducer(Context& context, Parse::NodeId parse_node) -> bool { // Create an instruction block to hold the instructions created as part of the // function signature, such as parameter and return types. @@ -232,7 +233,7 @@ auto HandleFunctionIntroducer(Context& context, Parse::Node parse_node) return true; } -auto HandleReturnType(Context& context, Parse::Node parse_node) -> bool { +auto HandleReturnType(Context& context, Parse::NodeId parse_node) -> bool { // Propagate the type expression. auto [type_parse_node, type_inst_id] = context.node_stack().PopExprWithParseNode(); diff --git a/toolchain/check/handle_if_expr.cpp b/toolchain/check/handle_if_expr.cpp index 81394cfea242..9a4edb2e186d 100644 --- a/toolchain/check/handle_if_expr.cpp +++ b/toolchain/check/handle_if_expr.cpp @@ -7,7 +7,7 @@ namespace Carbon::Check { -auto HandleIfExprIf(Context& context, Parse::Node parse_node) -> bool { +auto HandleIfExprIf(Context& context, Parse::NodeId parse_node) -> bool { // Alias parse_node for if/then/else consistency. auto& if_node = parse_node; @@ -28,7 +28,7 @@ auto HandleIfExprIf(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleIfExprThen(Context& context, Parse::Node parse_node) -> bool { +auto HandleIfExprThen(Context& context, Parse::NodeId parse_node) -> bool { auto then_value_id = context.node_stack().PopExpr(); auto else_block_id = context.node_stack().Peek(); @@ -43,7 +43,7 @@ auto HandleIfExprThen(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleIfExprElse(Context& context, Parse::Node parse_node) -> bool { +auto HandleIfExprElse(Context& context, Parse::NodeId parse_node) -> bool { // Alias parse_node for if/then/else consistency. auto& else_node = parse_node; diff --git a/toolchain/check/handle_if_statement.cpp b/toolchain/check/handle_if_statement.cpp index ef921b604350..46c3261b4e94 100644 --- a/toolchain/check/handle_if_statement.cpp +++ b/toolchain/check/handle_if_statement.cpp @@ -8,12 +8,12 @@ namespace Carbon::Check { -auto HandleIfConditionStart(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandleIfConditionStart(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } -auto HandleIfCondition(Context& context, Parse::Node parse_node) -> bool { +auto HandleIfCondition(Context& context, Parse::NodeId parse_node) -> bool { // Convert the condition to `bool`. auto cond_value_id = context.node_stack().PopExpr(); cond_value_id = ConvertToBoolValue(context, parse_node, cond_value_id); @@ -34,7 +34,7 @@ auto HandleIfCondition(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleIfStatementElse(Context& context, Parse::Node parse_node) -> bool { +auto HandleIfStatementElse(Context& context, Parse::NodeId parse_node) -> bool { auto else_block_id = context.node_stack().Pop(); // Switch to emitting the `else` block. @@ -45,7 +45,7 @@ auto HandleIfStatementElse(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleIfStatement(Context& context, Parse::Node parse_node) -> bool { +auto HandleIfStatement(Context& context, Parse::NodeId parse_node) -> bool { switch (auto kind = context.parse_tree().node_kind( context.node_stack().PeekParseNode())) { case Parse::NodeKind::IfCondition: { diff --git a/toolchain/check/handle_import_and_package.cpp b/toolchain/check/handle_import_and_package.cpp index 40a7ef01281d..e66f2364b078 100644 --- a/toolchain/check/handle_import_and_package.cpp +++ b/toolchain/check/handle_import_and_package.cpp @@ -9,62 +9,62 @@ namespace Carbon::Check { // `import` and `package` are structured by parsing. As a consequence, no // checking logic is needed here. -auto HandleImportIntroducer(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandleImportIntroducer(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } -auto HandleImportDirective(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandleImportDirective(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } -auto HandleLibraryIntroducer(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandleLibraryIntroducer(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } -auto HandleLibraryDirective(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandleLibraryDirective(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } -auto HandlePackageIntroducer(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandlePackageIntroducer(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } -auto HandlePackageDirective(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandlePackageDirective(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } -auto HandleLibrarySpecifier(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandleLibrarySpecifier(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } -auto HandlePackageName(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandlePackageName(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } -auto HandleLibraryName(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandleLibraryName(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } -auto HandleDefaultLibrary(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandleDefaultLibrary(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } -auto HandlePackageApi(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandlePackageApi(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } -auto HandlePackageImpl(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandlePackageImpl(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } diff --git a/toolchain/check/handle_index.cpp b/toolchain/check/handle_index.cpp index 239fe900052f..287c7d66e0ca 100644 --- a/toolchain/check/handle_index.cpp +++ b/toolchain/check/handle_index.cpp @@ -10,7 +10,7 @@ namespace Carbon::Check { -auto HandleIndexExprStart(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandleIndexExprStart(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { // Leave the expression on the stack for IndexExpr. return true; @@ -19,7 +19,7 @@ auto HandleIndexExprStart(Context& /*context*/, Parse::Node /*parse_node*/) // Validates that the index (required to be an IntegerLiteral) is valid within // the array or tuple size. Returns the index on success, or nullptr on failure. static auto ValidateIntegerLiteralBound(Context& context, - Parse::Node parse_node, + Parse::NodeId parse_node, SemIR::Inst operand_inst, SemIR::IntegerLiteral index_inst, int size) -> const llvm::APInt* { @@ -37,7 +37,7 @@ static auto ValidateIntegerLiteralBound(Context& context, return &index_val; } -auto HandleIndexExpr(Context& context, Parse::Node parse_node) -> bool { +auto HandleIndexExpr(Context& context, Parse::NodeId parse_node) -> bool { auto index_inst_id = context.node_stack().PopExpr(); auto index_inst = context.insts().Get(index_inst_id); auto operand_inst_id = context.node_stack().PopExpr(); diff --git a/toolchain/check/handle_interface.cpp b/toolchain/check/handle_interface.cpp index edb4615430f7..6d943d3d927e 100644 --- a/toolchain/check/handle_interface.cpp +++ b/toolchain/check/handle_interface.cpp @@ -6,21 +6,21 @@ namespace Carbon::Check { -auto HandleInterfaceDecl(Context& context, Parse::Node parse_node) -> bool { +auto HandleInterfaceDecl(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandleInterfaceDecl"); } -auto HandleInterfaceDefinition(Context& context, Parse::Node parse_node) +auto HandleInterfaceDefinition(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandleInterfaceDefinition"); } -auto HandleInterfaceDefinitionStart(Context& context, Parse::Node parse_node) +auto HandleInterfaceDefinitionStart(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandleInterfaceDefinitionStart"); } -auto HandleInterfaceIntroducer(Context& context, Parse::Node parse_node) +auto HandleInterfaceIntroducer(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandleInterfaceIntroducer"); } diff --git a/toolchain/check/handle_let.cpp b/toolchain/check/handle_let.cpp index 1c8fd6d26c29..2139aea35d47 100644 --- a/toolchain/check/handle_let.cpp +++ b/toolchain/check/handle_let.cpp @@ -8,7 +8,7 @@ namespace Carbon::Check { -auto HandleLetDecl(Context& context, Parse::Node parse_node) -> bool { +auto HandleLetDecl(Context& context, Parse::NodeId parse_node) -> bool { auto value_id = context.node_stack().PopExpr(); SemIR::InstId pattern_id = context.node_stack().Pop(); @@ -35,13 +35,13 @@ auto HandleLetDecl(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleLetIntroducer(Context& context, Parse::Node parse_node) -> bool { +auto HandleLetIntroducer(Context& context, Parse::NodeId parse_node) -> bool { // Push a bracketing node to establish the pattern context. context.node_stack().Push(parse_node); return true; } -auto HandleLetInitializer(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandleLetInitializer(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } diff --git a/toolchain/check/handle_literal.cpp b/toolchain/check/handle_literal.cpp index 556bd04adb3d..1e31eac929c1 100644 --- a/toolchain/check/handle_literal.cpp +++ b/toolchain/check/handle_literal.cpp @@ -6,7 +6,8 @@ namespace Carbon::Check { -auto HandleBoolLiteralFalse(Context& context, Parse::Node parse_node) -> bool { +auto HandleBoolLiteralFalse(Context& context, Parse::NodeId parse_node) + -> bool { context.AddInstAndPush( parse_node, SemIR::BoolLiteral{parse_node, @@ -15,7 +16,7 @@ auto HandleBoolLiteralFalse(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleBoolLiteralTrue(Context& context, Parse::Node parse_node) -> bool { +auto HandleBoolLiteralTrue(Context& context, Parse::NodeId parse_node) -> bool { context.AddInstAndPush( parse_node, SemIR::BoolLiteral{parse_node, @@ -24,7 +25,7 @@ auto HandleBoolLiteralTrue(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleIntegerLiteral(Context& context, Parse::Node parse_node) -> bool { +auto HandleIntegerLiteral(Context& context, Parse::NodeId parse_node) -> bool { context.AddInstAndPush( parse_node, SemIR::IntegerLiteral{ @@ -34,7 +35,7 @@ auto HandleIntegerLiteral(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleRealLiteral(Context& context, Parse::Node parse_node) -> bool { +auto HandleRealLiteral(Context& context, Parse::NodeId parse_node) -> bool { context.AddInstAndPush( parse_node, SemIR::RealLiteral{ @@ -45,7 +46,7 @@ auto HandleRealLiteral(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleStringLiteral(Context& context, Parse::Node parse_node) -> bool { +auto HandleStringLiteral(Context& context, Parse::NodeId parse_node) -> bool { context.AddInstAndPush( parse_node, SemIR::StringLiteral{ @@ -55,12 +56,12 @@ auto HandleStringLiteral(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleBoolTypeLiteral(Context& context, Parse::Node parse_node) -> bool { +auto HandleBoolTypeLiteral(Context& context, Parse::NodeId parse_node) -> bool { context.node_stack().Push(parse_node, SemIR::InstId::BuiltinBoolType); return true; } -auto HandleIntegerTypeLiteral(Context& context, Parse::Node parse_node) +auto HandleIntegerTypeLiteral(Context& context, Parse::NodeId parse_node) -> bool { auto text = context.tokens().GetTokenText( context.parse_tree().node_token(parse_node)); @@ -71,12 +72,12 @@ auto HandleIntegerTypeLiteral(Context& context, Parse::Node parse_node) return true; } -auto HandleUnsignedIntegerTypeLiteral(Context& context, Parse::Node parse_node) - -> bool { +auto HandleUnsignedIntegerTypeLiteral(Context& context, + Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "Need to support unsigned type literals"); } -auto HandleFloatingPointTypeLiteral(Context& context, Parse::Node parse_node) +auto HandleFloatingPointTypeLiteral(Context& context, Parse::NodeId parse_node) -> bool { auto text = context.tokens().GetTokenText( context.parse_tree().node_token(parse_node)); @@ -88,12 +89,13 @@ auto HandleFloatingPointTypeLiteral(Context& context, Parse::Node parse_node) return true; } -auto HandleStringTypeLiteral(Context& context, Parse::Node parse_node) -> bool { +auto HandleStringTypeLiteral(Context& context, Parse::NodeId parse_node) + -> bool { context.node_stack().Push(parse_node, SemIR::InstId::BuiltinStringType); return true; } -auto HandleTypeTypeLiteral(Context& context, Parse::Node parse_node) -> bool { +auto HandleTypeTypeLiteral(Context& context, Parse::NodeId parse_node) -> bool { context.node_stack().Push(parse_node, SemIR::InstId::BuiltinTypeType); return true; } diff --git a/toolchain/check/handle_loop_statement.cpp b/toolchain/check/handle_loop_statement.cpp index a98e963e5509..0abcd2684261 100644 --- a/toolchain/check/handle_loop_statement.cpp +++ b/toolchain/check/handle_loop_statement.cpp @@ -7,12 +7,12 @@ namespace Carbon::Check { -auto HandleBreakStatement(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandleBreakStatement(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } -auto HandleBreakStatementStart(Context& context, Parse::Node parse_node) +auto HandleBreakStatementStart(Context& context, Parse::NodeId parse_node) -> bool { auto& stack = context.break_continue_stack(); if (stack.empty()) { @@ -28,12 +28,12 @@ auto HandleBreakStatementStart(Context& context, Parse::Node parse_node) return true; } -auto HandleContinueStatement(Context& /*context*/, Parse::Node /*parse_node*/) +auto HandleContinueStatement(Context& /*context*/, Parse::NodeId /*parse_node*/) -> bool { return true; } -auto HandleContinueStatementStart(Context& context, Parse::Node parse_node) +auto HandleContinueStatementStart(Context& context, Parse::NodeId parse_node) -> bool { auto& stack = context.break_continue_stack(); if (stack.empty()) { @@ -49,23 +49,23 @@ auto HandleContinueStatementStart(Context& context, Parse::Node parse_node) return true; } -auto HandleForHeader(Context& context, Parse::Node parse_node) -> bool { +auto HandleForHeader(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandleForHeader"); } -auto HandleForHeaderStart(Context& context, Parse::Node parse_node) -> bool { +auto HandleForHeaderStart(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandleForHeaderStart"); } -auto HandleForIn(Context& context, Parse::Node parse_node) -> bool { +auto HandleForIn(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandleForIn"); } -auto HandleForStatement(Context& context, Parse::Node parse_node) -> bool { +auto HandleForStatement(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandleForStatement"); } -auto HandleWhileConditionStart(Context& context, Parse::Node parse_node) +auto HandleWhileConditionStart(Context& context, Parse::NodeId parse_node) -> bool { // Branch to the loop header block. Note that we create a new block here even // if the current block is empty; this ensures that the loop always has a @@ -81,7 +81,7 @@ auto HandleWhileConditionStart(Context& context, Parse::Node parse_node) return true; } -auto HandleWhileCondition(Context& context, Parse::Node parse_node) -> bool { +auto HandleWhileCondition(Context& context, Parse::NodeId parse_node) -> bool { auto cond_value_id = context.node_stack().PopExpr(); auto loop_header_id = context.node_stack().Peek(); @@ -103,7 +103,7 @@ auto HandleWhileCondition(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleWhileStatement(Context& context, Parse::Node parse_node) -> bool { +auto HandleWhileStatement(Context& context, Parse::NodeId parse_node) -> bool { auto loop_exit_id = context.node_stack().Pop(); auto loop_header_id = diff --git a/toolchain/check/handle_name.cpp b/toolchain/check/handle_name.cpp index d7ccaef1491e..9669f9d91d29 100644 --- a/toolchain/check/handle_name.cpp +++ b/toolchain/check/handle_name.cpp @@ -54,7 +54,8 @@ static auto GetExprValueForLookupResult(Context& context, return lookup_result_id; } -auto HandleMemberAccessExpr(Context& context, Parse::Node parse_node) -> bool { +auto HandleMemberAccessExpr(Context& context, Parse::NodeId parse_node) + -> bool { SemIR::NameId name_id = context.node_stack().Pop(); auto base_id = context.node_stack().PopExpr(); @@ -216,12 +217,12 @@ auto HandleMemberAccessExpr(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandlePointerMemberAccessExpr(Context& context, Parse::Node parse_node) +auto HandlePointerMemberAccessExpr(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandlePointerMemberAccessExpr"); } -auto HandleName(Context& context, Parse::Node parse_node) -> bool { +auto HandleName(Context& context, Parse::NodeId parse_node) -> bool { auto name_id = SemIR::NameId::ForIdentifier(context.tokens().GetIdentifier( context.parse_tree().node_token(parse_node))); // The parent is responsible for binding the name. @@ -229,7 +230,7 @@ auto HandleName(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleNameExpr(Context& context, Parse::Node parse_node) -> bool { +auto HandleNameExpr(Context& context, Parse::NodeId parse_node) -> bool { auto name_id = SemIR::NameId::ForIdentifier(context.tokens().GetIdentifier( context.parse_tree().node_token(parse_node))); auto value_id = context.LookupUnqualifiedName(parse_node, name_id); @@ -240,11 +241,11 @@ auto HandleNameExpr(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleQualifiedDecl(Context& context, Parse::Node parse_node) -> bool { +auto HandleQualifiedDecl(Context& context, Parse::NodeId parse_node) -> bool { auto [parse_node2, name_id2] = context.node_stack().PopWithParseNode(); - Parse::Node parse_node1 = context.node_stack().PeekParseNode(); + Parse::NodeId parse_node1 = context.node_stack().PeekParseNode(); switch (context.parse_tree().node_kind(parse_node1)) { case Parse::NodeKind::QualifiedDecl: // This is the second or subsequent QualifiedDecl in a chain. @@ -271,7 +272,8 @@ auto HandleQualifiedDecl(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleSelfTypeNameExpr(Context& context, Parse::Node parse_node) -> bool { +auto HandleSelfTypeNameExpr(Context& context, Parse::NodeId parse_node) + -> bool { auto name_id = SemIR::NameId::SelfType; auto value_id = context.LookupUnqualifiedName(parse_node, name_id); auto value = context.insts().Get(value_id); @@ -280,12 +282,13 @@ auto HandleSelfTypeNameExpr(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleSelfValueName(Context& context, Parse::Node parse_node) -> bool { +auto HandleSelfValueName(Context& context, Parse::NodeId parse_node) -> bool { context.node_stack().Push(parse_node); return true; } -auto HandleSelfValueNameExpr(Context& context, Parse::Node parse_node) -> bool { +auto HandleSelfValueNameExpr(Context& context, Parse::NodeId parse_node) + -> bool { auto name_id = SemIR::NameId::SelfValue; auto value_id = context.LookupUnqualifiedName(parse_node, name_id); auto value = context.insts().Get(value_id); diff --git a/toolchain/check/handle_named_constraint.cpp b/toolchain/check/handle_named_constraint.cpp index 02ff814ddaac..0b6a23ad6560 100644 --- a/toolchain/check/handle_named_constraint.cpp +++ b/toolchain/check/handle_named_constraint.cpp @@ -6,22 +6,22 @@ namespace Carbon::Check { -auto HandleNamedConstraintDecl(Context& context, Parse::Node parse_node) +auto HandleNamedConstraintDecl(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandleNamedConstraintDecl"); } -auto HandleNamedConstraintDefinition(Context& context, Parse::Node parse_node) +auto HandleNamedConstraintDefinition(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandleNamedConstraintDefinition"); } auto HandleNamedConstraintDefinitionStart(Context& context, - Parse::Node parse_node) -> bool { + Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandleNamedConstraintDefinitionStart"); } -auto HandleNamedConstraintIntroducer(Context& context, Parse::Node parse_node) +auto HandleNamedConstraintIntroducer(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandleNamedConstraintIntroducer"); } diff --git a/toolchain/check/handle_namespace.cpp b/toolchain/check/handle_namespace.cpp index 9dbec400361d..39d5229edf0a 100644 --- a/toolchain/check/handle_namespace.cpp +++ b/toolchain/check/handle_namespace.cpp @@ -7,13 +7,13 @@ namespace Carbon::Check { -auto HandleNamespaceStart(Context& context, Parse::Node /*parse_node*/) +auto HandleNamespaceStart(Context& context, Parse::NodeId /*parse_node*/) -> bool { context.decl_name_stack().PushScopeAndStartName(); return true; } -auto HandleNamespace(Context& context, Parse::Node parse_node) -> bool { +auto HandleNamespace(Context& context, Parse::NodeId parse_node) -> bool { auto name_context = context.decl_name_stack().FinishName(); auto namespace_id = context.AddInst(SemIR::Namespace{ parse_node, context.GetBuiltinType(SemIR::BuiltinKind::NamespaceType), diff --git a/toolchain/check/handle_noop.cpp b/toolchain/check/handle_noop.cpp index 96ac4dfe00f8..89c03e15a6a1 100644 --- a/toolchain/check/handle_noop.cpp +++ b/toolchain/check/handle_noop.cpp @@ -6,12 +6,13 @@ namespace Carbon::Check { -auto HandleEmptyDecl(Context& /*context*/, Parse::Node /*parse_node*/) -> bool { +auto HandleEmptyDecl(Context& /*context*/, Parse::NodeId /*parse_node*/) + -> bool { // Empty declarations have no actions associated. return true; } -auto HandleInvalidParse(Context& context, Parse::Node parse_node) -> bool { +auto HandleInvalidParse(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandleInvalidParse"); } diff --git a/toolchain/check/handle_operator.cpp b/toolchain/check/handle_operator.cpp index ae9a788b695b..4ead6167bd87 100644 --- a/toolchain/check/handle_operator.cpp +++ b/toolchain/check/handle_operator.cpp @@ -7,7 +7,7 @@ namespace Carbon::Check { -auto HandleInfixOperator(Context& context, Parse::Node parse_node) -> bool { +auto HandleInfixOperator(Context& context, Parse::NodeId parse_node) -> bool { auto [rhs_node, rhs_id] = context.node_stack().PopExprWithParseNode(); auto [lhs_node, lhs_id] = context.node_stack().PopExprWithParseNode(); @@ -81,7 +81,7 @@ auto HandleInfixOperator(Context& context, Parse::Node parse_node) -> bool { } } -auto HandlePostfixOperator(Context& context, Parse::Node parse_node) -> bool { +auto HandlePostfixOperator(Context& context, Parse::NodeId parse_node) -> bool { auto value_id = context.node_stack().PopExpr(); // Figure out the operator for the token. @@ -100,7 +100,7 @@ auto HandlePostfixOperator(Context& context, Parse::Node parse_node) -> bool { } } -auto HandlePrefixOperator(Context& context, Parse::Node parse_node) -> bool { +auto HandlePrefixOperator(Context& context, Parse::NodeId parse_node) -> bool { auto value_id = context.node_stack().PopExpr(); // Figure out the operator for the token. @@ -195,7 +195,7 @@ auto HandlePrefixOperator(Context& context, Parse::Node parse_node) -> bool { } } -auto HandleShortCircuitOperand(Context& context, Parse::Node parse_node) +auto HandleShortCircuitOperand(Context& context, Parse::NodeId parse_node) -> bool { // Convert the condition to `bool`. auto cond_value_id = context.node_stack().PopExpr(); diff --git a/toolchain/check/handle_param_list.cpp b/toolchain/check/handle_param_list.cpp index 737496656b50..d3caa519b0d8 100644 --- a/toolchain/check/handle_param_list.cpp +++ b/toolchain/check/handle_param_list.cpp @@ -6,7 +6,8 @@ namespace Carbon::Check { -auto HandleImplicitParamList(Context& context, Parse::Node parse_node) -> bool { +auto HandleImplicitParamList(Context& context, Parse::NodeId parse_node) + -> bool { auto refs_id = context.ParamOrArgEnd(Parse::NodeKind::ImplicitParamListStart); context.node_stack() .PopAndDiscardSoloParseNode(); @@ -16,7 +17,7 @@ auto HandleImplicitParamList(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleImplicitParamListStart(Context& context, Parse::Node parse_node) +auto HandleImplicitParamListStart(Context& context, Parse::NodeId parse_node) -> bool { context.PushScope(); context.node_stack().Push(parse_node); @@ -24,7 +25,7 @@ auto HandleImplicitParamListStart(Context& context, Parse::Node parse_node) return true; } -auto HandleParamList(Context& context, Parse::Node parse_node) -> bool { +auto HandleParamList(Context& context, Parse::NodeId parse_node) -> bool { auto refs_id = context.ParamOrArgEnd(Parse::NodeKind::ParamListStart); context.PopScope(); context.node_stack() @@ -33,13 +34,13 @@ auto HandleParamList(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleParamListComma(Context& context, Parse::Node /*parse_node*/) +auto HandleParamListComma(Context& context, Parse::NodeId /*parse_node*/) -> bool { context.ParamOrArgComma(); return true; } -auto HandleParamListStart(Context& context, Parse::Node parse_node) -> bool { +auto HandleParamListStart(Context& context, Parse::NodeId parse_node) -> bool { // A parameter list following an implicit parameter list shares the same // scope. // diff --git a/toolchain/check/handle_paren.cpp b/toolchain/check/handle_paren.cpp index 0f085aaf4f0d..bd767185aa08 100644 --- a/toolchain/check/handle_paren.cpp +++ b/toolchain/check/handle_paren.cpp @@ -8,7 +8,7 @@ namespace Carbon::Check { -auto HandleParenExpr(Context& context, Parse::Node parse_node) -> bool { +auto HandleParenExpr(Context& context, Parse::NodeId parse_node) -> bool { auto value_id = context.node_stack().PopExpr(); // ParamOrArgStart was called for tuple handling; clean up the ParamOrArg // support for non-tuple cases. @@ -21,19 +21,19 @@ auto HandleParenExpr(Context& context, Parse::Node parse_node) -> bool { } auto HandleParenExprOrTupleLiteralStart(Context& context, - Parse::Node parse_node) -> bool { + Parse::NodeId parse_node) -> bool { context.node_stack().Push(parse_node); context.ParamOrArgStart(); return true; } -auto HandleTupleLiteralComma(Context& context, Parse::Node /*parse_node*/) +auto HandleTupleLiteralComma(Context& context, Parse::NodeId /*parse_node*/) -> bool { context.ParamOrArgComma(); return true; } -auto HandleTupleLiteral(Context& context, Parse::Node parse_node) -> bool { +auto HandleTupleLiteral(Context& context, Parse::NodeId parse_node) -> bool { auto refs_id = context.ParamOrArgEnd(Parse::NodeKind::ParenExprOrTupleLiteralStart); diff --git a/toolchain/check/handle_pattern_binding.cpp b/toolchain/check/handle_pattern_binding.cpp index e258ad617041..6c08b353bb51 100644 --- a/toolchain/check/handle_pattern_binding.cpp +++ b/toolchain/check/handle_pattern_binding.cpp @@ -9,7 +9,7 @@ namespace Carbon::Check { -auto HandleAddress(Context& context, Parse::Node parse_node) -> bool { +auto HandleAddress(Context& context, Parse::NodeId parse_node) -> bool { auto self_param_id = context.node_stack().Peek(); if (auto self_param = @@ -24,12 +24,12 @@ auto HandleAddress(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleGenericPatternBinding(Context& context, Parse::Node parse_node) +auto HandleGenericPatternBinding(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "GenericPatternBinding"); } -auto HandlePatternBinding(Context& context, Parse::Node parse_node) -> bool { +auto HandlePatternBinding(Context& context, Parse::NodeId parse_node) -> bool { auto [type_node, parsed_type_id] = context.node_stack().PopExprWithParseNode(); auto type_node_copy = type_node; @@ -152,7 +152,7 @@ auto HandlePatternBinding(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleTemplate(Context& context, Parse::Node parse_node) -> bool { +auto HandleTemplate(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandleTemplate"); } diff --git a/toolchain/check/handle_return_statement.cpp b/toolchain/check/handle_return_statement.cpp index 9cf3e2d83deb..d2687447ebe0 100644 --- a/toolchain/check/handle_return_statement.cpp +++ b/toolchain/check/handle_return_statement.cpp @@ -7,20 +7,21 @@ namespace Carbon::Check { -auto HandleReturnStatementStart(Context& context, Parse::Node parse_node) +auto HandleReturnStatementStart(Context& context, Parse::NodeId parse_node) -> bool { // No action, just a bracketing node. context.node_stack().Push(parse_node); return true; } -auto HandleReturnVarModifier(Context& context, Parse::Node parse_node) -> bool { +auto HandleReturnVarModifier(Context& context, Parse::NodeId parse_node) + -> bool { // No action, just a bracketing node. context.node_stack().Push(parse_node); return true; } -auto HandleReturnStatement(Context& context, Parse::Node parse_node) -> bool { +auto HandleReturnStatement(Context& context, Parse::NodeId parse_node) -> bool { switch ( context.parse_tree().node_kind(context.node_stack().PeekParseNode())) { case Parse::NodeKind::ReturnStatementStart: diff --git a/toolchain/check/handle_struct.cpp b/toolchain/check/handle_struct.cpp index cbb55ff3af7f..5bf9a0e4265b 100644 --- a/toolchain/check/handle_struct.cpp +++ b/toolchain/check/handle_struct.cpp @@ -7,12 +7,12 @@ namespace Carbon::Check { -auto HandleStructComma(Context& context, Parse::Node /*parse_node*/) -> bool { +auto HandleStructComma(Context& context, Parse::NodeId /*parse_node*/) -> bool { context.ParamOrArgComma(); return true; } -auto HandleStructFieldDesignator(Context& context, Parse::Node /*parse_node*/) +auto HandleStructFieldDesignator(Context& context, Parse::NodeId /*parse_node*/) -> bool { // This leaves the designated name on top because the `.` isn't interesting. CARBON_CHECK( @@ -21,7 +21,7 @@ auto HandleStructFieldDesignator(Context& context, Parse::Node /*parse_node*/) return true; } -auto HandleStructFieldType(Context& context, Parse::Node parse_node) -> bool { +auto HandleStructFieldType(Context& context, Parse::NodeId parse_node) -> bool { auto [type_node, type_id] = context.node_stack().PopExprWithParseNode(); SemIR::TypeId cast_type_id = ExprAsType(context, type_node, type_id); @@ -33,12 +33,13 @@ auto HandleStructFieldType(Context& context, Parse::Node parse_node) -> bool { return true; } -auto HandleStructFieldUnknown(Context& context, Parse::Node parse_node) +auto HandleStructFieldUnknown(Context& context, Parse::NodeId parse_node) -> bool { return context.TODO(parse_node, "HandleStructFieldUnknown"); } -auto HandleStructFieldValue(Context& context, Parse::Node parse_node) -> bool { +auto HandleStructFieldValue(Context& context, Parse::NodeId parse_node) + -> bool { auto value_inst_id = context.node_stack().PopExpr(); auto [name_node, name_id] = context.node_stack().PopWithParseNode(); @@ -57,7 +58,7 @@ static auto DiagnoseDuplicateNames(Context& context, llvm::StringRef construct) -> bool { auto& sem_ir = context.sem_ir(); auto fields = sem_ir.inst_blocks().Get(type_block_id); - llvm::SmallDenseMap names; + llvm::SmallDenseMap names; auto& insts = sem_ir.insts(); for (SemIR::InstId field_inst_id : fields) { auto field_inst = insts.GetAs(field_inst_id); @@ -80,7 +81,7 @@ static auto DiagnoseDuplicateNames(Context& context, return false; } -auto HandleStructLiteral(Context& context, Parse::Node parse_node) -> bool { +auto HandleStructLiteral(Context& context, Parse::NodeId parse_node) -> bool { auto refs_id = context.ParamOrArgEnd( Parse::NodeKind::StructLiteralOrStructTypeLiteralStart); @@ -103,7 +104,7 @@ auto HandleStructLiteral(Context& context, Parse::Node parse_node) -> bool { } auto HandleStructLiteralOrStructTypeLiteralStart(Context& context, - Parse::Node parse_node) + Parse::NodeId parse_node) -> bool { context.PushScope(); context.node_stack().Push(parse_node); @@ -115,7 +116,8 @@ auto HandleStructLiteralOrStructTypeLiteralStart(Context& context, return true; } -auto HandleStructTypeLiteral(Context& context, Parse::Node parse_node) -> bool { +auto HandleStructTypeLiteral(Context& context, Parse::NodeId parse_node) + -> bool { auto refs_id = context.ParamOrArgEnd( Parse::NodeKind::StructLiteralOrStructTypeLiteralStart); diff --git a/toolchain/check/handle_variable.cpp b/toolchain/check/handle_variable.cpp index 2ffe808de87e..20726ec8be76 100644 --- a/toolchain/check/handle_variable.cpp +++ b/toolchain/check/handle_variable.cpp @@ -8,27 +8,28 @@ namespace Carbon::Check { -auto HandleVariableIntroducer(Context& context, Parse::Node parse_node) +auto HandleVariableIntroducer(Context& context, Parse::NodeId parse_node) -> bool { // No action, just a bracketing node. context.node_stack().Push(parse_node); return true; } -auto HandleReturnedModifier(Context& context, Parse::Node parse_node) -> bool { - // No action, just a bracketing node. - context.node_stack().Push(parse_node); - return true; -} - -auto HandleVariableInitializer(Context& context, Parse::Node parse_node) +auto HandleReturnedModifier(Context& context, Parse::NodeId parse_node) -> bool { // No action, just a bracketing node. context.node_stack().Push(parse_node); return true; } -auto HandleVariableDecl(Context& context, Parse::Node parse_node) -> bool { +auto HandleVariableInitializer(Context& context, Parse::NodeId parse_node) + -> bool { + // No action, just a bracketing node. + context.node_stack().Push(parse_node); + return true; +} + +auto HandleVariableDecl(Context& context, Parse::NodeId parse_node) -> bool { // Handle the optional initializer. auto init_id = SemIR::InstId::Invalid; bool has_init = diff --git a/toolchain/check/node_stack.h b/toolchain/check/node_stack.h index 3c15fae6818c..e44d543a6b77 100644 --- a/toolchain/check/node_stack.h +++ b/toolchain/check/node_stack.h @@ -38,7 +38,7 @@ class NodeStack { // Pushes a solo parse tree node onto the stack. Used when there is no // IR generated by the node. - auto Push(Parse::Node parse_node) -> void { + auto Push(Parse::NodeId parse_node) -> void { CARBON_CHECK(ParseNodeKindToIdKind(parse_tree_->node_kind(parse_node)) == IdKind::SoloParseNode) << "Parse kind expects an Id: " << parse_tree_->node_kind(parse_node); @@ -51,7 +51,7 @@ class NodeStack { // Pushes a parse tree node onto the stack with an ID. template - auto Push(Parse::Node parse_node, IdT id) -> void { + auto Push(Parse::NodeId parse_node, IdT id) -> void { CARBON_CHECK(ParseNodeKindToIdKind(parse_tree_->node_kind(parse_node)) == IdTypeToIdKind()) << "Parse kind expected a different IdT: " @@ -76,7 +76,7 @@ class NodeStack { // Pops the top of the stack and returns the parse_node. template - auto PopForSoloParseNode() -> Parse::Node { + auto PopForSoloParseNode() -> Parse::NodeId { Entry back = PopEntry(); RequireIdKind(Parse::NodeKind::Create(RequiredParseKind), IdKind::SoloParseNode); @@ -87,7 +87,7 @@ class NodeStack { // Pops the top of the stack if it is the given kind, and returns the // parse_node. Otherwise, returns std::nullopt. template - auto PopForSoloParseNodeIf() -> std::optional { + auto PopForSoloParseNodeIf() -> std::optional { if (PeekIs()) { return PopForSoloParseNode(); } @@ -113,7 +113,7 @@ class NodeStack { // Pops an expression from the top of the stack and returns the parse_node and // the ID. - auto PopExprWithParseNode() -> std::pair { + auto PopExprWithParseNode() -> std::pair { return PopWithParseNode(); } @@ -178,7 +178,9 @@ class NodeStack { } // Peeks at the parse node of the top of the name stack. - auto PeekParseNode() const -> Parse::Node { return stack_.back().parse_node; } + auto PeekParseNode() const -> Parse::NodeId { + return stack_.back().parse_node; + } // Peeks at the ID associated with the top of the name stack. template @@ -233,17 +235,17 @@ class NodeStack { // An entry in stack_. struct Entry { - explicit Entry(Parse::Node parse_node, SemIR::InstId inst_id) + explicit Entry(Parse::NodeId parse_node, SemIR::InstId inst_id) : parse_node(parse_node), inst_id(inst_id) {} - explicit Entry(Parse::Node parse_node, SemIR::InstBlockId inst_block_id) + explicit Entry(Parse::NodeId parse_node, SemIR::InstBlockId inst_block_id) : parse_node(parse_node), inst_block_id(inst_block_id) {} - explicit Entry(Parse::Node parse_node, SemIR::FunctionId function_id) + explicit Entry(Parse::NodeId parse_node, SemIR::FunctionId function_id) : parse_node(parse_node), function_id(function_id) {} - explicit Entry(Parse::Node parse_node, SemIR::ClassId class_id) + explicit Entry(Parse::NodeId parse_node, SemIR::ClassId class_id) : parse_node(parse_node), class_id(class_id) {} - explicit Entry(Parse::Node parse_node, SemIR::NameId name_id) + explicit Entry(Parse::NodeId parse_node, SemIR::NameId name_id) : parse_node(parse_node), name_id(name_id) {} - explicit Entry(Parse::Node parse_node, SemIR::TypeId type_id) + explicit Entry(Parse::NodeId parse_node, SemIR::TypeId type_id) : parse_node(parse_node), type_id(type_id) {} // Returns the appropriate ID basaed on type. @@ -270,7 +272,7 @@ class NodeStack { } // The parse node associated with the stack entry. - Parse::Node parse_node; + Parse::NodeId parse_node; // The entries will evaluate as invalid if and only if they're a solo // parse_node. Invalid is used instead of optional to save space. @@ -393,7 +395,7 @@ class NodeStack { // Pops the top of the stack and returns the parse_node and the ID. template - auto PopWithParseNode() -> std::pair { + auto PopWithParseNode() -> std::pair { Entry back = PopEntry(); RequireIdKind(parse_tree_->node_kind(back.parse_node), IdTypeToIdKind()); @@ -408,7 +410,7 @@ class NodeStack { // Require an entry to have the given Parse::NodeKind. template - auto RequireParseKind(Parse::Node parse_node) const -> void { + auto RequireParseKind(Parse::NodeId parse_node) const -> void { auto actual_kind = parse_tree_->node_kind(parse_node); CARBON_CHECK(RequiredParseKind == actual_kind) << "Expected " << Parse::NodeKind::Create(RequiredParseKind) diff --git a/toolchain/check/return.cpp b/toolchain/check/return.cpp index e3ec548d86e4..6ea9b3387116 100644 --- a/toolchain/check/return.cpp +++ b/toolchain/check/return.cpp @@ -57,9 +57,9 @@ static auto NoteReturnedVar(Context& context, Context::DiagnosticBuilder& diag, diag.Note(context.insts().Get(returned_var_id).parse_node(), ReturnedVarHere); } -auto CheckReturnedVar(Context& context, Parse::Node returned_node, - Parse::Node name_node, SemIR::NameId name_id, - Parse::Node type_node, SemIR::TypeId type_id) +auto CheckReturnedVar(Context& context, Parse::NodeId returned_node, + Parse::NodeId name_node, SemIR::NameId name_id, + Parse::NodeId type_node, SemIR::TypeId type_id) -> SemIR::InstId { // A `returned var` requires an explicit return type. auto& function = GetCurrentFunction(context); @@ -108,7 +108,7 @@ auto RegisterReturnedVar(Context& context, SemIR::InstId bind_id) -> void { } } -auto BuildReturnWithNoExpr(Context& context, Parse::Node parse_node) -> void { +auto BuildReturnWithNoExpr(Context& context, Parse::NodeId parse_node) -> void { const auto& function = GetCurrentFunction(context); if (function.return_type_id.is_valid()) { @@ -124,7 +124,7 @@ auto BuildReturnWithNoExpr(Context& context, Parse::Node parse_node) -> void { context.AddInst(SemIR::Return{parse_node}); } -auto BuildReturnWithExpr(Context& context, Parse::Node parse_node, +auto BuildReturnWithExpr(Context& context, Parse::NodeId parse_node, SemIR::InstId expr_id) -> void { const auto& function = GetCurrentFunction(context); auto returned_var_id = GetCurrentReturnedVar(context); @@ -156,7 +156,7 @@ auto BuildReturnWithExpr(Context& context, Parse::Node parse_node, context.AddInst(SemIR::ReturnExpr{parse_node, expr_id}); } -auto BuildReturnVar(Context& context, Parse::Node parse_node) -> void { +auto BuildReturnVar(Context& context, Parse::NodeId parse_node) -> void { const auto& function = GetCurrentFunction(context); auto returned_var_id = GetCurrentReturnedVar(context); diff --git a/toolchain/check/return.h b/toolchain/check/return.h index b00306d7eb1b..94201d288ed6 100644 --- a/toolchain/check/return.h +++ b/toolchain/check/return.h @@ -13,23 +13,23 @@ namespace Carbon::Check { // Checks a `returned var` binding and returns the location of the return // value storage that the name should bind to. -auto CheckReturnedVar(Context& context, Parse::Node returned_node, - Parse::Node name_node, SemIR::NameId name_id, - Parse::Node type_node, SemIR::TypeId type_id) +auto CheckReturnedVar(Context& context, Parse::NodeId returned_node, + Parse::NodeId name_node, SemIR::NameId name_id, + Parse::NodeId type_node, SemIR::TypeId type_id) -> SemIR::InstId; // Registers the given binding as the current `returned var` in this scope. auto RegisterReturnedVar(Context& context, SemIR::InstId bind_id) -> void; // Checks and builds SemIR for a `return;` statement. -auto BuildReturnWithNoExpr(Context& context, Parse::Node parse_node) -> void; +auto BuildReturnWithNoExpr(Context& context, Parse::NodeId parse_node) -> void; // Checks and builds SemIR for a `return ;` statement. -auto BuildReturnWithExpr(Context& context, Parse::Node parse_node, +auto BuildReturnWithExpr(Context& context, Parse::NodeId parse_node, SemIR::InstId expr_id) -> void; // Checks and builds SemIR for a `return var;` statement. -auto BuildReturnVar(Context& context, Parse::Node parse_node) -> void; +auto BuildReturnVar(Context& context, Parse::NodeId parse_node) -> void; } // namespace Carbon::Check diff --git a/toolchain/parse/handle_import_and_package.cpp b/toolchain/parse/handle_import_and_package.cpp index 583d07caaaca..dfc408581cbc 100644 --- a/toolchain/parse/handle_import_and_package.cpp +++ b/toolchain/parse/handle_import_and_package.cpp @@ -77,7 +77,7 @@ static auto HandleDirectiveContent(Context& context, NodeKind directive, llvm::function_ref on_parse_error) -> void { - Tree::PackagingNames names{.node = Node(state.subtree_start)}; + Tree::PackagingNames names{.node = NodeId(state.subtree_start)}; if (directive != NodeKind::LibraryDirective) { if (auto package_name_token = context.ConsumeIf(Lex::TokenKind::Identifier)) { diff --git a/toolchain/parse/tree.cpp b/toolchain/parse/tree.cpp index 15dc5cde90d2..645d4f23bf74 100644 --- a/toolchain/parse/tree.cpp +++ b/toolchain/parse/tree.cpp @@ -55,54 +55,55 @@ auto Tree::Parse(Lex::TokenizedBuffer& tokens, DiagnosticConsumer& consumer, } auto Tree::postorder() const -> llvm::iterator_range { - return {PostorderIterator(Node(0)), - PostorderIterator(Node(node_impls_.size()))}; + return {PostorderIterator(NodeId(0)), + PostorderIterator(NodeId(node_impls_.size()))}; } -auto Tree::postorder(Node n) const -> llvm::iterator_range { +auto Tree::postorder(NodeId n) const + -> llvm::iterator_range { CARBON_CHECK(n.is_valid()); // The postorder ends after this node, the root, and begins at the start of // its subtree. int end_index = n.index + 1; int start_index = end_index - node_impls_[n.index].subtree_size; - return {PostorderIterator(Node(start_index)), - PostorderIterator(Node(end_index))}; + return {PostorderIterator(NodeId(start_index)), + PostorderIterator(NodeId(end_index))}; } -auto Tree::children(Node n) const -> llvm::iterator_range { +auto Tree::children(NodeId n) const -> llvm::iterator_range { CARBON_CHECK(n.is_valid()); int end_index = n.index - node_impls_[n.index].subtree_size; - return {SiblingIterator(*this, Node(n.index - 1)), - SiblingIterator(*this, Node(end_index))}; + return {SiblingIterator(*this, NodeId(n.index - 1)), + SiblingIterator(*this, NodeId(end_index))}; } auto Tree::roots() const -> llvm::iterator_range { return { - SiblingIterator(*this, Node(static_cast(node_impls_.size()) - 1)), - SiblingIterator(*this, Node(-1))}; + SiblingIterator(*this, NodeId(static_cast(node_impls_.size()) - 1)), + SiblingIterator(*this, NodeId(-1))}; } -auto Tree::node_has_error(Node n) const -> bool { +auto Tree::node_has_error(NodeId n) const -> bool { CARBON_CHECK(n.is_valid()); return node_impls_[n.index].has_error; } -auto Tree::node_kind(Node n) const -> NodeKind { +auto Tree::node_kind(NodeId n) const -> NodeKind { CARBON_CHECK(n.is_valid()); return node_impls_[n.index].kind; } -auto Tree::node_token(Node n) const -> Lex::Token { +auto Tree::node_token(NodeId n) const -> Lex::Token { CARBON_CHECK(n.is_valid()); return node_impls_[n.index].token; } -auto Tree::node_subtree_size(Node n) const -> int32_t { +auto Tree::node_subtree_size(NodeId n) const -> int32_t { CARBON_CHECK(n.is_valid()); return node_impls_[n.index].subtree_size; } -auto Tree::PrintNode(llvm::raw_ostream& output, Node n, int depth, +auto Tree::PrintNode(llvm::raw_ostream& output, NodeId n, int depth, bool preorder) const -> bool { const auto& n_impl = node_impls_[n.index]; output.indent(2 * (depth + 2)); @@ -138,22 +139,22 @@ auto Tree::Print(llvm::raw_ostream& output) const -> void { llvm::SmallVector indents; indents.append(size(), 0); - llvm::SmallVector, 16> node_stack; - for (Node n : roots()) { + llvm::SmallVector, 16> node_stack; + for (NodeId n : roots()) { node_stack.push_back({n, 0}); } while (!node_stack.empty()) { - Node n = Node::Invalid; + NodeId n = NodeId::Invalid; int depth; std::tie(n, depth) = node_stack.pop_back_val(); - for (Node sibling_n : children(n)) { + for (NodeId sibling_n : children(n)) { indents[sibling_n.index] = depth + 1; node_stack.push_back({sibling_n, depth + 1}); } } - for (Node n : postorder()) { + for (NodeId n : postorder()) { PrintNode(output, n, indents[n.index], /*preorder=*/false); output << ",\n"; } @@ -176,20 +177,20 @@ auto Tree::Print(llvm::raw_ostream& output, bool preorder) const -> void { // The roots, like siblings, are in RPO (so reversed), but we add them in // order here because we'll pop off the stack effectively reversing then. - llvm::SmallVector, 16> node_stack; - for (Node n : roots()) { + llvm::SmallVector, 16> node_stack; + for (NodeId n : roots()) { node_stack.push_back({n, 0}); } while (!node_stack.empty()) { - Node n = Node::Invalid; + NodeId n = NodeId::Invalid; int depth; std::tie(n, depth) = node_stack.pop_back_val(); if (PrintNode(output, n, depth, /*preorder=*/true)) { // Has children, so we descend. We append the children in order here as // well because they will get reversed when popped off the stack. - for (Node sibling_n : children(n)) { + for (NodeId sibling_n : children(n)) { node_stack.push_back({sibling_n, depth + 1}); } continue; @@ -210,14 +211,14 @@ auto Tree::Print(llvm::raw_ostream& output, bool preorder) const -> void { } auto Tree::Verify() const -> ErrorOr { - llvm::SmallVector nodes; + llvm::SmallVector nodes; // Traverse the tree in postorder. - for (Node n : postorder()) { + for (NodeId n : postorder()) { const auto& n_impl = node_impls_[n.index]; if (n_impl.has_error && !has_errors_) { return Error(llvm::formatv( - "Node #{0} has errors, but the tree is not marked as having any.", + "NodeId #{0} has errors, but the tree is not marked as having any.", n.index)); } @@ -226,7 +227,7 @@ auto Tree::Verify() const -> ErrorOr { while (true) { if (nodes.empty()) { return Error( - llvm::formatv("Node #{0} is a {1} with bracket {2}, but didn't " + llvm::formatv("NodeId #{0} is a {1} with bracket {2}, but didn't " "find the bracket.", n, n_impl.kind, n_impl.kind.bracket())); } @@ -240,7 +241,7 @@ auto Tree::Verify() const -> ErrorOr { for (int i : llvm::seq(n_impl.kind.child_count())) { if (nodes.empty()) { return Error(llvm::formatv( - "Node #{0} is a {1} with child_count {2}, but only had {3} " + "NodeId #{0} is a {1} with child_count {2}, but only had {3} " "nodes to consume.", n, n_impl.kind, n_impl.kind.child_count(), i)); } @@ -250,8 +251,8 @@ auto Tree::Verify() const -> ErrorOr { } if (n_impl.subtree_size != subtree_size) { return Error(llvm::formatv( - "Node #{0} is a {1} with subtree_size of {2}, but calculated {3}.", n, - n_impl.kind, n_impl.subtree_size, subtree_size)); + "NodeId #{0} is a {1} with subtree_size of {2}, but calculated {3}.", + n, n_impl.kind, n_impl.subtree_size, subtree_size)); } nodes.push_back(n); } @@ -266,7 +267,7 @@ auto Tree::Verify() const -> ErrorOr { if (n.index - n_impl.subtree_size != prev_index) { return Error( - llvm::formatv("Node #{0} is a root {1} with subtree_size {2}, but " + llvm::formatv("NodeId #{0} is a root {1} with subtree_size {2}, but " "previous root was at #{3}.", n, n_impl.kind, n_impl.subtree_size, prev_index)); } diff --git a/toolchain/parse/tree.h b/toolchain/parse/tree.h index 520cc1f26189..de4844f8d745 100644 --- a/toolchain/parse/tree.h +++ b/toolchain/parse/tree.h @@ -26,14 +26,14 @@ namespace Carbon::Parse { // // That said, nodes can be compared and are part of a depth-first pre-order // sequence across all nodes in the parse tree. -struct Node : public ComparableIndexBase { +struct NodeId : public ComparableIndexBase { // An explicitly invalid instance. - static const Node Invalid; + static const NodeId Invalid; using ComparableIndexBase::ComparableIndexBase; }; -constexpr Node Node::Invalid = Node(Node::InvalidIndex); +constexpr NodeId NodeId::Invalid = NodeId(NodeId::InvalidIndex); // A tree of parsed tokens based on the language grammar. // @@ -70,7 +70,7 @@ class Tree : public Printable { // Names in packaging, whether the file's packaging or an import. Links back // to the node for diagnostics. struct PackagingNames { - Node node; + NodeId node; IdentifierId package_id = IdentifierId::Invalid; StringLiteralId library_id = StringLiteralId::Invalid; }; @@ -99,12 +99,12 @@ class Tree : public Printable { // Returns an iterable range over the parse tree node and all of its // descendants in depth-first postorder. - auto postorder(Node n) const -> llvm::iterator_range; + auto postorder(NodeId n) const -> llvm::iterator_range; // Returns an iterable range over the direct children of a node in the parse // tree. This is a forward range, but is constant time to increment. The order // of children is the same as would be found in a reverse postorder traversal. - auto children(Node n) const -> llvm::iterator_range; + auto children(NodeId n) const -> llvm::iterator_range; // Returns an iterable range over the roots of the parse tree. This is a // forward range, but is constant time to increment. The order of roots is the @@ -113,15 +113,15 @@ class Tree : public Printable { // Tests whether a particular node contains an error and may not match the // full expected structure of the grammar. - auto node_has_error(Node n) const -> bool; + auto node_has_error(NodeId n) const -> bool; // Returns the kind of the given parse tree node. - auto node_kind(Node n) const -> NodeKind; + auto node_kind(NodeId n) const -> NodeKind; // Returns the token the given parse tree node models. - auto node_token(Node n) const -> Lex::Token; + auto node_token(NodeId n) const -> Lex::Token; - auto node_subtree_size(Node n) const -> int32_t; + auto node_subtree_size(NodeId n) const -> int32_t; auto packaging_directive() const -> const std::optional& { return packaging_directive_; @@ -245,7 +245,7 @@ class Tree : public Printable { // Prints a single node for Print(). Returns true when preorder and there are // children. - auto PrintNode(llvm::raw_ostream& output, Node n, int depth, + auto PrintNode(llvm::raw_ostream& output, NodeId n, int depth, bool preorder) const -> bool; // Depth-first postorder sequence of node implementation data. @@ -268,12 +268,12 @@ class Tree : public Printable { }; // A random-access iterator to the depth-first postorder sequence of parse nodes -// in the parse tree. It produces `Tree::Node` objects which are opaque +// in the parse tree. It produces `Tree::NodeId` objects which are opaque // handles and must be used in conjunction with the `Tree` itself. class Tree::PostorderIterator : public llvm::iterator_facade_base, + std::random_access_iterator_tag, NodeId, + int, NodeId*, NodeId>, public Printable { public: PostorderIterator() = delete; @@ -285,7 +285,7 @@ class Tree::PostorderIterator return node_ < rhs.node_; } - auto operator*() const -> Node { return node_; } + auto operator*() const -> NodeId { return node_; } auto operator-(const PostorderIterator& rhs) const -> int { return node_.index - rhs.node_.index; @@ -306,13 +306,13 @@ class Tree::PostorderIterator private: friend class Tree; - explicit PostorderIterator(Node n) : node_(n) {} + explicit PostorderIterator(NodeId n) : node_(n) {} - Node node_; + NodeId node_; }; // A forward iterator across the siblings at a particular level in the parse -// tree. It produces `Tree::Node` objects which are opaque handles and must +// tree. It produces `Tree::NodeId` objects which are opaque handles and must // be used in conjunction with the `Tree` itself. // // While this is a forward iterator and may not have good locality within the @@ -323,8 +323,9 @@ class Tree::PostorderIterator // (which is made constant time through cached distance information), and so the // relative order of siblings matches their RPO order. class Tree::SiblingIterator - : public llvm::iterator_facade_base< - SiblingIterator, std::forward_iterator_tag, Node, int, Node*, Node>, + : public llvm::iterator_facade_base, public Printable { public: explicit SiblingIterator() = delete; @@ -338,7 +339,7 @@ class Tree::SiblingIterator return node_ > rhs.node_; } - auto operator*() const -> Node { return node_; } + auto operator*() const -> NodeId { return node_; } using iterator_facade_base::operator++; auto operator++() -> SiblingIterator& { @@ -352,12 +353,12 @@ class Tree::SiblingIterator private: friend class Tree; - explicit SiblingIterator(const Tree& tree_arg, Node n) + explicit SiblingIterator(const Tree& tree_arg, NodeId n) : tree_(&tree_arg), node_(n) {} const Tree* tree_; - Node node_; + NodeId node_; }; } // namespace Carbon::Parse diff --git a/toolchain/parse/tree_node_location_translator.h b/toolchain/parse/tree_node_location_translator.h index 0ad0eab5c038..2e760c1785ac 100644 --- a/toolchain/parse/tree_node_location_translator.h +++ b/toolchain/parse/tree_node_location_translator.h @@ -9,7 +9,7 @@ namespace Carbon::Parse { -class NodeLocationTranslator : public DiagnosticLocationTranslator { +class NodeLocationTranslator : public DiagnosticLocationTranslator { public: explicit NodeLocationTranslator(const Lex::TokenizedBuffer* tokens, llvm::StringRef filename, @@ -19,7 +19,7 @@ class NodeLocationTranslator : public DiagnosticLocationTranslator { parse_tree_(parse_tree) {} // Map the given token into a diagnostic location. - auto GetLocation(Node node) -> DiagnosticLocation override { + auto GetLocation(NodeId node) -> DiagnosticLocation override { // Support the invalid token as a way to emit only the filename, when there // is no line association. if (!node.is_valid()) { diff --git a/toolchain/sem_ir/formatter.cpp b/toolchain/sem_ir/formatter.cpp index 9da5630bfc91..7133d7492aa8 100644 --- a/toolchain/sem_ir/formatter.cpp +++ b/toolchain/sem_ir/formatter.cpp @@ -60,7 +60,7 @@ class InstNamer { auto fn_scope = GetScopeFor(fn_id); // TODO: Provide a location for the function for use as a // disambiguator. - auto fn_loc = Parse::Node::Invalid; + auto fn_loc = Parse::NodeId::Invalid; GetScopeInfo(fn_scope).name = globals.AllocateName( *this, fn_loc, sem_ir.names().GetIRBaseName(fn.name_id).str()); CollectNamesInBlock(fn_scope, fn.implicit_param_refs_id); @@ -89,7 +89,7 @@ class InstNamer { auto class_scope = GetScopeFor(class_id); // TODO: Provide a location for the class for use as a // disambiguator. - auto class_loc = Parse::Node::Invalid; + auto class_loc = Parse::NodeId::Invalid; GetScopeInfo(class_scope).name = globals.AllocateName( *this, class_loc, sem_ir.names().GetIRBaseName(class_info.name_id).str()); @@ -218,7 +218,7 @@ class InstNamer { return Name(allocated.insert({name, NameResult()}).first); } - auto AllocateName(const InstNamer& namer, Parse::Node node, + auto AllocateName(const InstNamer& namer, Parse::NodeId node, std::string name = "") -> Name { // The best (shortest) name for this instruction so far, and the current // name for it. @@ -294,12 +294,13 @@ class InstNamer { auto AddBlockLabel(ScopeIndex scope_idx, InstBlockId block_id, std::string name = "", - Parse::Node parse_node = Parse::Node::Invalid) -> void { + Parse::NodeId parse_node = Parse::NodeId::Invalid) + -> void { if (!block_id.is_valid() || labels[block_id.index].second) { return; } - if (parse_node == Parse::Node::Invalid) { + if (parse_node == Parse::NodeId::Invalid) { if (const auto& block = sem_ir_.inst_blocks().Get(block_id); !block.empty()) { parse_node = sem_ir_.insts().Get(block.front()).parse_node(); diff --git a/toolchain/sem_ir/inst.h b/toolchain/sem_ir/inst.h index 282d52b905b0..2000fd4bd363 100644 --- a/toolchain/sem_ir/inst.h +++ b/toolchain/sem_ir/inst.h @@ -68,7 +68,7 @@ class Inst : public Printable { template > // NOLINTNEXTLINE(google-explicit-constructor) Inst(TypedInst typed_inst) - : parse_node_(Parse::Node::Invalid), + : parse_node_(Parse::NodeId::Invalid), kind_(TypedInst::Kind), type_id_(TypeId::Invalid), arg0_(InstId::InvalidIndex), @@ -138,7 +138,7 @@ class Inst : public Printable { } } - auto parse_node() const -> Parse::Node { return parse_node_; } + auto parse_node() const -> Parse::NodeId { return parse_node_; } auto kind() const -> InstKind { return kind_; } // Gets the type of the value produced by evaluating this instruction. @@ -150,7 +150,7 @@ class Inst : public Printable { friend class InstTestHelper; // Raw constructor, used for testing. - explicit Inst(InstKind kind, Parse::Node parse_node, TypeId type_id, + explicit Inst(InstKind kind, Parse::NodeId parse_node, TypeId type_id, int32_t arg0, int32_t arg1) : parse_node_(parse_node), kind_(kind), @@ -174,7 +174,7 @@ class Inst : public Printable { return BuiltinKind::FromInt(raw); } - Parse::Node parse_node_; + Parse::NodeId parse_node_; InstKind kind_; TypeId type_id_; diff --git a/toolchain/sem_ir/typed_insts.h b/toolchain/sem_ir/typed_insts.h index 95e97a12d104..6919fc9438cd 100644 --- a/toolchain/sem_ir/typed_insts.h +++ b/toolchain/sem_ir/typed_insts.h @@ -14,7 +14,7 @@ // // Each type should be a struct with up to four members: // -// - Optionally, a `Parse::Node parse_node;` member, for instructions with an +// - Optionally, a `Parse::NodeId parse_node;` member, for instructions with an // associated location. Almost all instructions should have this, with // exceptions being things that are generated internally, without any relation // to source syntax, such as predeclared builtins. @@ -39,7 +39,7 @@ namespace Carbon::SemIR { struct AddressOf { static constexpr auto Kind = InstKind::AddressOf.Define("address_of"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId lvalue_id; }; @@ -47,7 +47,7 @@ struct AddressOf { struct ArrayIndex { static constexpr auto Kind = InstKind::ArrayIndex.Define("array_index"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId array_id; InstId index_id; @@ -59,7 +59,7 @@ struct ArrayIndex { struct ArrayInit { static constexpr auto Kind = InstKind::ArrayInit.Define("array_init"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstBlockId inits_id; InstId dest_id; @@ -68,7 +68,7 @@ struct ArrayInit { struct ArrayType { static constexpr auto Kind = InstKind::ArrayType.Define("array_type"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId bound_id; TypeId element_type_id; @@ -80,7 +80,7 @@ struct ArrayType { struct Assign { static constexpr auto Kind = InstKind::Assign.Define("assign"); - Parse::Node parse_node; + Parse::NodeId parse_node; // Assignments are statements, and so have no type. InstId lhs_id; InstId rhs_id; @@ -89,7 +89,7 @@ struct Assign { struct BinaryOperatorAdd { static constexpr auto Kind = InstKind::BinaryOperatorAdd.Define("add"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId lhs_id; InstId rhs_id; @@ -98,7 +98,7 @@ struct BinaryOperatorAdd { struct BindName { static constexpr auto Kind = InstKind::BindName.Define("bind_name"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; NameId name_id; InstId value_id; @@ -107,7 +107,7 @@ struct BindName { struct BindValue { static constexpr auto Kind = InstKind::BindValue.Define("bind_value"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId value_id; }; @@ -115,7 +115,7 @@ struct BindValue { struct BlockArg { static constexpr auto Kind = InstKind::BlockArg.Define("block_arg"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstBlockId block_id; }; @@ -123,7 +123,7 @@ struct BlockArg { struct BoolLiteral { static constexpr auto Kind = InstKind::BoolLiteral.Define("bool_literal"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; BoolValue value; }; @@ -133,7 +133,7 @@ struct BoolLiteral { struct BoundMethod { static constexpr auto Kind = InstKind::BoundMethod.Define("bound_method"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; // The object argument in the bound method, which will be used to initialize // `self`, or whose address will be used to initialize `self` for an `addr @@ -146,7 +146,7 @@ struct Branch { static constexpr auto Kind = InstKind::Branch.Define("br", TerminatorKind::Terminator); - Parse::Node parse_node; + Parse::NodeId parse_node; // Branches don't produce a value, so have no type. InstBlockId target_id; }; @@ -155,7 +155,7 @@ struct BranchIf { static constexpr auto Kind = InstKind::BranchIf.Define("br", TerminatorKind::TerminatorSequence); - Parse::Node parse_node; + Parse::NodeId parse_node; // Branches don't produce a value, so have no type. InstBlockId target_id; InstId cond_id; @@ -165,7 +165,7 @@ struct BranchWithArg { static constexpr auto Kind = InstKind::BranchWithArg.Define("br", TerminatorKind::Terminator); - Parse::Node parse_node; + Parse::NodeId parse_node; // Branches don't produce a value, so have no type. InstBlockId target_id; InstId arg_id; @@ -182,7 +182,7 @@ struct Builtin { struct Call { static constexpr auto Kind = InstKind::Call.Define("call"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId callee_id; // The arguments block contains IDs for the following arguments, in order: @@ -195,7 +195,7 @@ struct Call { struct ClassDecl { static constexpr auto Kind = InstKind::ClassDecl.Define("class_decl"); - Parse::Node parse_node; + Parse::NodeId 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 @@ -210,7 +210,7 @@ struct ClassFieldAccess { static constexpr auto Kind = InstKind::ClassFieldAccess.Define("class_field_access"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId base_id; MemberIndex index; @@ -219,7 +219,7 @@ struct ClassFieldAccess { struct ClassInit { static constexpr auto Kind = InstKind::ClassInit.Define("class_init"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstBlockId elements_id; InstId dest_id; @@ -228,7 +228,7 @@ struct ClassInit { struct ClassType { static constexpr auto Kind = InstKind::ClassType.Define("class_type"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; ClassId class_id; // TODO: Once we support generic classes, include the class's arguments here. @@ -237,7 +237,7 @@ struct ClassType { struct ConstType { static constexpr auto Kind = InstKind::ConstType.Define("const_type"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; TypeId inner_id; }; @@ -245,7 +245,7 @@ struct ConstType { struct Converted { static constexpr auto Kind = InstKind::Converted.Define("converted"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId original_id; InstId result_id; @@ -266,7 +266,7 @@ struct CrossRef { struct Deref { static constexpr auto Kind = InstKind::Deref.Define("deref"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId pointer_id; }; @@ -276,7 +276,7 @@ struct Deref { struct Field { static constexpr auto Kind = InstKind::Field.Define("field"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; NameId name_id; MemberIndex index; @@ -285,7 +285,7 @@ struct Field { struct FunctionDecl { static constexpr auto Kind = InstKind::FunctionDecl.Define("fn_decl"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; FunctionId function_id; }; @@ -297,7 +297,7 @@ struct FunctionDecl { struct Import { static constexpr auto Kind = InstKind::Import.Define("import"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; CrossRefIRId first_cross_ref_ir_id; CrossRefIRId last_cross_ref_ir_id; @@ -310,7 +310,7 @@ struct InitializeFrom { static constexpr auto Kind = InstKind::InitializeFrom.Define("initialize_from"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId src_id; InstId dest_id; @@ -319,7 +319,7 @@ struct InitializeFrom { struct IntegerLiteral { static constexpr auto Kind = InstKind::IntegerLiteral.Define("int_literal"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; IntegerId integer_id; }; @@ -327,7 +327,7 @@ struct IntegerLiteral { struct NameRef { static constexpr auto Kind = InstKind::NameRef.Define("name_ref"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; NameId name_id; InstId value_id; @@ -336,7 +336,7 @@ struct NameRef { struct Namespace { static constexpr auto Kind = InstKind::Namespace.Define("namespace"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; NameScopeId name_scope_id; }; @@ -344,14 +344,14 @@ struct Namespace { struct NoOp { static constexpr auto Kind = InstKind::NoOp.Define("no_op"); - Parse::Node parse_node; + Parse::NodeId parse_node; // This instruction doesn't produce a value, so has no type. }; struct Param { static constexpr auto Kind = InstKind::Param.Define("param"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; NameId name_id; }; @@ -359,7 +359,7 @@ struct Param { struct PointerType { static constexpr auto Kind = InstKind::PointerType.Define("ptr_type"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; TypeId pointee_id; }; @@ -367,7 +367,7 @@ struct PointerType { struct RealLiteral { static constexpr auto Kind = InstKind::RealLiteral.Define("real_literal"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; RealId real_id; }; @@ -376,7 +376,7 @@ struct Return { static constexpr auto Kind = InstKind::Return.Define("return", TerminatorKind::Terminator); - Parse::Node parse_node; + Parse::NodeId parse_node; // This is a statement, so has no type. }; @@ -384,7 +384,7 @@ struct ReturnExpr { static constexpr auto Kind = InstKind::ReturnExpr.Define("return", TerminatorKind::Terminator); - Parse::Node parse_node; + Parse::NodeId parse_node; // This is a statement, so has no type. InstId expr_id; }; @@ -393,7 +393,7 @@ struct SelfParam { static constexpr auto Kind = InstKind::SelfParam.Define("self_param"); static constexpr llvm::StringLiteral Name = "self"; - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; BoolValue is_addr_self; }; @@ -401,7 +401,7 @@ struct SelfParam { struct SpliceBlock { static constexpr auto Kind = InstKind::SpliceBlock.Define("splice_block"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstBlockId block_id; InstId result_id; @@ -410,7 +410,7 @@ struct SpliceBlock { struct StringLiteral { static constexpr auto Kind = InstKind::StringLiteral.Define("string_literal"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; StringLiteralId string_literal_id; }; @@ -418,7 +418,7 @@ struct StringLiteral { struct StructAccess { static constexpr auto Kind = InstKind::StructAccess.Define("struct_access"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId struct_id; MemberIndex index; @@ -427,7 +427,7 @@ struct StructAccess { struct StructInit { static constexpr auto Kind = InstKind::StructInit.Define("struct_init"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstBlockId elements_id; InstId dest_id; @@ -436,7 +436,7 @@ struct StructInit { struct StructLiteral { static constexpr auto Kind = InstKind::StructLiteral.Define("struct_literal"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstBlockId elements_id; }; @@ -444,7 +444,7 @@ struct StructLiteral { struct StructType { static constexpr auto Kind = InstKind::StructType.Define("struct_type"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstBlockId fields_id; }; @@ -453,7 +453,7 @@ struct StructTypeField { static constexpr auto Kind = InstKind::StructTypeField.Define("struct_type_field"); - Parse::Node parse_node; + Parse::NodeId parse_node; // This instruction is an implementation detail of `StructType`, and doesn't // produce a value, so has no type, even though it declares a field with a // type. @@ -464,7 +464,7 @@ struct StructTypeField { struct StructValue { static constexpr auto Kind = InstKind::StructValue.Define("struct_value"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstBlockId elements_id; }; @@ -472,7 +472,7 @@ struct StructValue { struct Temporary { static constexpr auto Kind = InstKind::Temporary.Define("temporary"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId storage_id; InstId init_id; @@ -482,14 +482,14 @@ struct TemporaryStorage { static constexpr auto Kind = InstKind::TemporaryStorage.Define("temporary_storage"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; }; struct TupleAccess { static constexpr auto Kind = InstKind::TupleAccess.Define("tuple_access"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId tuple_id; MemberIndex index; @@ -498,7 +498,7 @@ struct TupleAccess { struct TupleIndex { static constexpr auto Kind = InstKind::TupleIndex.Define("tuple_index"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId tuple_id; InstId index_id; @@ -507,7 +507,7 @@ struct TupleIndex { struct TupleInit { static constexpr auto Kind = InstKind::TupleInit.Define("tuple_init"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstBlockId elements_id; InstId dest_id; @@ -516,7 +516,7 @@ struct TupleInit { struct TupleLiteral { static constexpr auto Kind = InstKind::TupleLiteral.Define("tuple_literal"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstBlockId elements_id; }; @@ -524,7 +524,7 @@ struct TupleLiteral { struct TupleType { static constexpr auto Kind = InstKind::TupleType.Define("tuple_type"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; TypeBlockId elements_id; }; @@ -532,7 +532,7 @@ struct TupleType { struct TupleValue { static constexpr auto Kind = InstKind::TupleValue.Define("tuple_value"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstBlockId elements_id; }; @@ -540,7 +540,7 @@ struct TupleValue { struct UnaryOperatorNot { static constexpr auto Kind = InstKind::UnaryOperatorNot.Define("not"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId operand_id; }; @@ -552,7 +552,7 @@ struct UnboundFieldType { static constexpr auto Kind = InstKind::UnboundFieldType.Define("unbound_field_type"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; // The class of which the field is a member. TypeId class_type_id; @@ -563,7 +563,7 @@ struct UnboundFieldType { struct ValueAsRef { static constexpr auto Kind = InstKind::ValueAsRef.Define("value_as_ref"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId value_id; }; @@ -572,7 +572,7 @@ struct ValueOfInitializer { static constexpr auto Kind = InstKind::ValueOfInitializer.Define("value_of_initializer"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; InstId init_id; }; @@ -580,13 +580,13 @@ struct ValueOfInitializer { struct VarStorage { static constexpr auto Kind = InstKind::VarStorage.Define("var"); - Parse::Node parse_node; + Parse::NodeId parse_node; TypeId type_id; NameId name_id; }; -// HasParseNode is true if T has a `Parse::Node parse_node` field. -template +// HasParseNode is true if T has a `Parse::NodeId parse_node` field. +template constexpr bool HasParseNode = false; template constexpr bool HasParseNode = true; diff --git a/toolchain/sem_ir/typed_insts_test.cpp b/toolchain/sem_ir/typed_insts_test.cpp index 9356a4df1122..54232353747c 100644 --- a/toolchain/sem_ir/typed_insts_test.cpp +++ b/toolchain/sem_ir/typed_insts_test.cpp @@ -14,7 +14,7 @@ namespace Carbon::SemIR { // A friend of `SemIR::Inst` that is used to pierce the abstraction. class InstTestHelper { public: - static auto MakeInst(InstKind inst_kind, Parse::Node parse_node, + static auto MakeInst(InstKind inst_kind, Parse::NodeId parse_node, TypeId type_id, int32_t arg0, int32_t arg1) -> Inst { return Inst(inst_kind, parse_node, type_id, arg0, arg1); } @@ -32,9 +32,9 @@ namespace { #include "toolchain/sem_ir/inst_kind.def" auto MakeInstWithNumberedFields(InstKind kind) -> Inst { - Inst inst = InstTestHelper::MakeInst(kind, Parse::Node(1), TypeId(2), 3, 4); + Inst inst = InstTestHelper::MakeInst(kind, Parse::NodeId(1), TypeId(2), 3, 4); EXPECT_EQ(inst.kind(), kind); - EXPECT_EQ(inst.parse_node(), Parse::Node(1)); + EXPECT_EQ(inst.parse_node(), Parse::NodeId(1)); EXPECT_EQ(inst.type_id(), TypeId(2)); return inst; } @@ -44,7 +44,7 @@ auto CommonFieldOrder() -> void { Inst inst = MakeInstWithNumberedFields(TypedInst::Kind); TypedInst typed = inst.As(); if constexpr (HasParseNode) { - EXPECT_EQ(typed.parse_node, Parse::Node(1)); + EXPECT_EQ(typed.parse_node, Parse::NodeId(1)); } if constexpr (HasTypeId) { EXPECT_EQ(typed.type_id, TypeId(2));