| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
- // Exceptions. See /LICENSE for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- #ifndef CARBON_TOOLCHAIN_BASE_VALUE_IDS_H_
- #define CARBON_TOOLCHAIN_BASE_VALUE_IDS_H_
- #include "common/ostream.h"
- #include "llvm/ADT/APFloat.h"
- #include "llvm/ADT/APInt.h"
- #include "llvm/ADT/StringExtras.h"
- #include "llvm/Support/YAMLParser.h"
- #include "toolchain/base/index_base.h"
- namespace Carbon {
- // The value of a real literal token.
- //
- // This is either a dyadic fraction (mantissa * 2^exponent) or a decadic
- // fraction (mantissa * 10^exponent).
- //
- // These values are not canonicalized, because we don't expect them to repeat
- // and don't use them in SemIR values.
- struct Real : public Printable<Real> {
- auto Print(llvm::raw_ostream& output_stream) const -> void {
- mantissa.print(output_stream, /*isSigned=*/false);
- output_stream << "*" << (is_decimal ? "10" : "2") << "^" << exponent;
- }
- // The mantissa, represented as an unsigned integer.
- llvm::APInt mantissa;
- // The exponent, represented as a signed integer.
- llvm::APInt exponent;
- // If false, the value is mantissa * 2^exponent.
- // If true, the value is mantissa * 10^exponent.
- // TODO: This field increases Real from 32 bytes to 40 bytes. Consider
- // changing how it's tracked for space savings.
- bool is_decimal;
- };
- // Corresponds to a float value represented by an APFloat. This is used for
- // floating-point values in SemIR.
- struct FloatId : public IdBase<FloatId> {
- static constexpr llvm::StringLiteral Label = "float";
- using ValueType = llvm::APFloat;
- static const FloatId None;
- using IdBase::IdBase;
- };
- constexpr FloatId FloatId::None(FloatId::NoneIndex);
- // Corresponds to a Real value.
- struct RealId : public IdBase<RealId> {
- static constexpr llvm::StringLiteral Label = "real";
- using ValueType = Real;
- static const RealId None;
- using IdBase::IdBase;
- };
- constexpr RealId RealId::None(RealId::NoneIndex);
- // Corresponds to StringRefs for identifiers.
- //
- // `NameId` relies on the values of this type other than `None` all being
- // non-negative.
- struct IdentifierId : public IdBase<IdentifierId> {
- static constexpr llvm::StringLiteral Label = "identifier";
- using ValueType = llvm::StringRef;
- static const IdentifierId None;
- using IdBase::IdBase;
- };
- constexpr IdentifierId IdentifierId::None(IdentifierId::NoneIndex);
- // Corresponds to StringRefs for string literals.
- struct StringLiteralValueId : public IdBase<StringLiteralValueId> {
- static constexpr llvm::StringLiteral Label = "string";
- using ValueType = llvm::StringRef;
- static const StringLiteralValueId None;
- using IdBase::IdBase;
- };
- constexpr StringLiteralValueId StringLiteralValueId::None(
- StringLiteralValueId::NoneIndex);
- } // namespace Carbon
- #endif // CARBON_TOOLCHAIN_BASE_VALUE_IDS_H_
|