From 1d8cec0fe0159845c0d9549f93def97b22a542d7 Mon Sep 17 00:00:00 2001 From: Gabriel Dos Reis Date: Sun, 15 May 2022 10:05:13 -0700 Subject: [PATCH] Base type of an enum (#263) Provide accessor for the underlying type of an enumeration. Partially addresses #22 . --- include/ipr/impl | 2 ++ include/ipr/interface | 3 +++ 2 files changed, 5 insertions(+) diff --git a/include/ipr/impl b/include/ipr/impl index f484ee6..b702321 100644 --- a/include/ipr/impl +++ b/include/ipr/impl @@ -1857,6 +1857,7 @@ namespace ipr::impl { }; struct Enum : impl::Type { + Optional underlying; homogeneous_region body; Optional id; const Kind enum_kind; @@ -1867,6 +1868,7 @@ namespace ipr::impl { const ipr::Region& region() const final; const Sequence& members() const final; Kind kind() const final; + Optional base() const final { return underlying; } impl::Enumerator* add_member(const ipr::Name&); }; diff --git a/include/ipr/interface b/include/ipr/interface index fc537d5..1d707ac 100644 --- a/include/ipr/interface +++ b/include/ipr/interface @@ -707,12 +707,15 @@ namespace ipr { // An enumeration is an object-type whose members are named constants // the definitions of which as part of the definition of the enumeration // itself. By historical accident, enumerators are not "properly scoped". + // The underlying type of the enumeration is given by `base()`, when explicitly + // specified or inferred from the enumerator list. struct Enum : Category> { enum class Kind : std::uint8_t { // The kind of enum. Legacy, // traditional C-style enum Scoped // scoped enum (C++11) }; virtual Kind kind() const = 0; + virtual Optional base() const = 0; }; // -- Auto --