Repository: carbon-language/carbon-lang
File: toolchain/check/context.h (C/C++)

Code before:
  // Runs verification that the processing cleanly finished.
  auto VerifyOnFinish() const -> void;

  // Prints information for a stack dump.
  auto PrintForStackDump(llvm::raw_ostream& output) const -> void;

  // Get the Lex::TokenKind of a node for diagnostics.
  auto token_kind(Parse::NodeId node_id) -> Lex::TokenKind {
    return tokens().GetKind(parse_tree().node_token(node_id));
  }

  auto emitter() -> DiagnosticEmitterBase& { return *emitter_; }

  auto parse_tree_and_subtrees() -> const Parse::TreeAndSubtrees& {
    return tree_and_subtrees_getter_();
  }

  auto sem_ir() -> SemIR::File& { return *sem_ir_; }
  auto sem_ir() const -> const SemIR::File& { return *sem_ir_; }

  auto cpp_context() -> CppContext* { return cpp_context_.get(); }

  // TODO: Remove this and pass the C++ context to the constructor.
  auto set_cpp_context(std::unique_ptr<CppContext> cpp_context) {
    CARBON_CHECK(!cpp_context_ || !cpp_context,
                 "C++ context set more than once");
    cpp_context_ = std::move(cpp_context);
  }

  // Convenience functions for major phase data.
  auto parse_tree() const -> const Parse::Tree& {
    return sem_ir_->parse_tree();
  }
  auto tokens() const -> const Lex::TokenizedBuffer& {
    return parse_tree().tokens();
  }

  auto vlog_stream() -> llvm::raw_ostream* { return vlog_stream_; }

  auto node_stack() -> NodeStack& { return node_stack_; }

  auto inst_block_stack() -> InstBlockStack& { return inst_block_stack_; }
  auto pattern_block_stack() -> InstBlockStack& { return pattern_block_stack_; }

  auto param_and_arg_refs_stack() -> ParamAndArgRefsStack& {
    return param_and_arg_refs_stack_;
  }

  auto args_type_info_stack() -> InstBlockStack& {
    return args_type_info_stack_;
  }

Review comment (bug):
```suggestion
                 "Already have a C++ context");
```

The message sounds odd to me because this is making valid:

```
  set_cpp_context(foo);
  set_cpp_context(nullptr);
  set_cpp_context(bar);
```

Of course the prior message I'm realizing was also wrong, since it was actually requiring to be called without nullptr. I admit this is a nit though so feel free to ignore it (or just remove the message, and I probably wouldn't have commented).

Code after:
  // Runs verification that the processing cleanly finished.
  auto VerifyOnFinish() const -> void;

  // Prints information for a stack dump.
  auto PrintForStackDump(llvm::raw_ostream& output) const -> void;

  // Get the Lex::TokenKind of a node for diagnostics.
  auto token_kind(Parse::NodeId node_id) -> Lex::TokenKind {
    return tokens().GetKind(parse_tree().node_token(node_id));
  }

  auto emitter() -> DiagnosticEmitterBase& { return *emitter_; }

  auto parse_tree_and_subtrees() -> const Parse::TreeAndSubtrees& {
    return tree_and_subtrees_getter_();
  }

  auto sem_ir() -> SemIR::File& { return *sem_ir_; }
  auto sem_ir() const -> const SemIR::File& { return *sem_ir_; }

  auto cpp_context() -> CppContext* { return cpp_context_.get(); }

  // TODO: Remove this and pass the C++ context to the constructor.
  auto set_cpp_context(std::unique_ptr<CppContext> cpp_context) {
    CARBON_CHECK(!cpp_context_ || !cpp_context, "Already have a C++ context");
    cpp_context_ = std::move(cpp_context);
  }

  // Convenience functions for major phase data.
  auto parse_tree() const -> const Parse::Tree& {
    return sem_ir_->parse_tree();
  }
  auto tokens() const -> const Lex::TokenizedBuffer& {
    return parse_tree().tokens();
  }

  auto vlog_stream() -> llvm::raw_ostream* { return vlog_stream_; }

  auto node_stack() -> NodeStack& { return node_stack_; }

  auto inst_block_stack() -> InstBlockStack& { return inst_block_stack_; }
  auto pattern_block_stack() -> InstBlockStack& { return pattern_block_stack_; }

  auto param_and_arg_refs_stack() -> ParamAndArgRefsStack& {
    return param_and_arg_refs_stack_;
  }

  auto args_type_info_stack() -> InstBlockStack& {
    return args_type_info_stack_;
  }