handle_expr_statement.cpp 1.1 KB

123456789101112131415161718192021222324252627282930
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "toolchain/check/context.h"
  5. #include "toolchain/check/convert.h"
  6. #include "toolchain/sem_ir/inst.h"
  7. namespace Carbon::Check {
  8. // TODO: Find a better home for this. We'll likely need it for more than just
  9. // expression statements.
  10. static auto HandleDiscardedExpr(Context& context, SemIR::InstId expr_id)
  11. -> void {
  12. // If we discard an initializing expression, convert it to a value or
  13. // reference so that it has something to initialize.
  14. auto expr = context.insts().Get(expr_id);
  15. Convert(context, expr.parse_node(), expr_id,
  16. {.kind = ConversionTarget::Discarded, .type_id = expr.type_id()});
  17. // TODO: This will eventually need to do some "do not discard" analysis.
  18. }
  19. auto HandleExprStatement(Context& context,
  20. Parse::ExprStatementId /*parse_node*/) -> bool {
  21. HandleDiscardedExpr(context, context.node_stack().PopExpr());
  22. return true;
  23. }
  24. } // namespace Carbon::Check