handle_expr_statement.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031
  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/check/handle.h"
  7. #include "toolchain/sem_ir/inst.h"
  8. namespace Carbon::Check {
  9. // TODO: Find a better home for this. We'll likely need it for more than just
  10. // expression statements.
  11. static auto HandleDiscardedExpr(Context& context, SemIR::InstId expr_id)
  12. -> void {
  13. // If we discard an initializing expression, convert it to a value or
  14. // reference so that it has something to initialize.
  15. auto expr = context.insts().Get(expr_id);
  16. Convert(context, context.insts().GetLocId(expr_id), expr_id,
  17. {.kind = ConversionTarget::Discarded, .type_id = expr.type_id()});
  18. // TODO: This will eventually need to do some "do not discard" analysis.
  19. }
  20. auto HandleParseNode(Context& context, Parse::ExprStatementId /*node_id*/)
  21. -> bool {
  22. HandleDiscardedExpr(context, context.node_stack().PopExpr());
  23. return true;
  24. }
  25. } // namespace Carbon::Check