literal.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #ifndef CARBON_TOOLCHAIN_CHECK_LITERAL_H_
  5. #define CARBON_TOOLCHAIN_CHECK_LITERAL_H_
  6. #include "toolchain/base/value_ids.h"
  7. #include "toolchain/check/context.h"
  8. #include "toolchain/check/convert.h"
  9. #include "toolchain/lex/token_info.h"
  10. #include "toolchain/sem_ir/ids.h"
  11. namespace Carbon::Check {
  12. // Forms a TypeType for a `type` literal.
  13. auto MakeTypeTypeLiteral(Context& context, Parse::NodeId node_id)
  14. -> SemIR::TypeInstId;
  15. // Forms a boolean type for a `bool` literal.
  16. auto MakeBoolTypeLiteral(Context& context, Parse::NodeId node_id)
  17. -> SemIR::TypeInstId;
  18. // Forms a BoolLiteral instruction with the given value and returns it.
  19. auto MakeBoolLiteral(Context& context, SemIR::LocId loc_id,
  20. SemIR::BoolValue value) -> SemIR::InstId;
  21. // Forms an IntValue instruction with type `IntLiteral` for a given literal
  22. // integer value, which is assumed to be unsigned.
  23. auto MakeIntLiteral(Context& context, Parse::NodeId node_id, IntId int_id)
  24. -> SemIR::InstId;
  25. // Forms a char type expression for `char` literal.
  26. auto MakeCharTypeLiteral(Context& context, Parse::NodeId node_id)
  27. -> SemIR::TypeInstId;
  28. // Forms an integer type expression for either an `iN` or `uN` literal.
  29. auto MakeIntTypeLiteral(Context& context, Parse::NodeId node_id,
  30. SemIR::IntKind int_kind, IntId size_id)
  31. -> SemIR::TypeInstId;
  32. // Forms an integer type of the specified kind and bit-width.
  33. auto MakeIntType(Context& context, Parse::NodeId node_id,
  34. SemIR::IntKind int_kind, IntId size_id) -> SemIR::TypeId;
  35. // Forms a floating point type expression for `fN` literal.
  36. auto MakeFloatTypeLiteral(Context& context, Parse::NodeId node_id,
  37. IntId size_id) -> SemIR::TypeInstId;
  38. // Forms a string literal value instruction for a given string literal.
  39. auto MakeStringLiteral(Context& context, Parse::StringLiteralId node_id,
  40. StringLiteralValueId value_id) -> SemIR::InstId;
  41. // Forms a string literal type expression for a `str` literal.
  42. auto MakeStringTypeLiteral(Context& context, Parse::StringTypeLiteralId node_id)
  43. -> SemIR::TypeInstId;
  44. // Forms a string type.
  45. auto MakeStringType(Context& context, SemIR::LocId loc_id) -> TypeExpr;
  46. } // namespace Carbon::Check
  47. #endif // CARBON_TOOLCHAIN_CHECK_LITERAL_H_