IDL compiler front-end library
Loading...
Searching...
No Matches
Union.h
Go to the documentation of this file.
1
2/*
3* Nirvana IDL front-end library.
4*
5* This is a part of the Nirvana project.
6*
7* Author: Igor Popov
8*
9* Copyright (c) 2021 Igor Popov.
10*
11* This program is free software; you can redistribute it and/or modify
12* it under the terms of the GNU Lesser General Public License as published by
13* the Free Software Foundation; either version 3 of the License, or
14* (at your option) any later version.
15*
16* This program is distributed in the hope that it will be useful,
17* but WITHOUT ANY WARRANTY; without even the implied warranty of
18* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19* GNU General Public License for more details.
20*
21* You should have received a copy of the GNU Lesser General Public
22* License along with this library. If not, see <http://www.gnu.org/licenses/>.
23*
24* Send comments and/or bug reports to:
25* popov.nirvana@gmail.com
26*/
27#ifndef IDLFE_AST_UNION_H_
28#define IDLFE_AST_UNION_H_
29#pragma once
30
31#include "StructBase.h"
32#include "ForwardDeclarable.h"
33#include "UnionElement.h"
34
35namespace AST {
36
37class Union;
38
43class UnionDecl :
44 public ItemWithId
45{
46public:
48 const Union& definition () const
49 {
50 assert (definition_);
51 return *definition_;
52 }
53
54private:
55 template <class T> friend class Ptr;
56 friend class Builder;
57
58 UnionDecl (Builder& builder, const SimpleDeclarator& name) :
59 ItemWithId (Item::Kind::UNION_DECL, builder, name),
60 definition_ (nullptr)
61 {}
62
63private:
64 const Union* definition_;
65};
66
71class Union :
72 public ItemWithId,
73 public ContainerT <UnionElement>,
75{
76public:
78 const Type& discriminator_type () const noexcept
79 {
80 return discriminator_type_;
81 }
82
88 const Variant& default_label () const noexcept
89 {
90 return default_label_;
91 }
92
95 const UnionElement* default_element () const noexcept
96 {
97 return default_element_;
98 }
99
103 operator const StructBase& () const noexcept
104 {
105 return reinterpret_cast <const StructBase&> (*this);
106 }
107
108private:
109 template <class T> friend class Ptr;
110 friend class Builder;
111
112 Union (Builder& builder, const SimpleDeclarator& name,
113 const Type& discriminator_type) :
114 ItemWithId (Item::Kind::UNION, builder, name),
115 discriminator_type_ (discriminator_type),
116 default_element_ (nullptr)
117 {}
118
119private:
120 Type discriminator_type_;
121 const UnionElement* default_element_;
122 Variant default_label_;
123};
124
125}
126
127#endif
The AST builder.
Definition Builder.h:60
Sequential container of the AST items.
Definition Container.h:40
The item that can be forward declared.
An AST item.
Definition Item.h:41
Kind
The kind of item.
Definition Item.h:45
@ UNION_DECL
class UnionDecl
@ UNION
class Union
Items which have repository identifiers derive from this class.
Definition ItemWithId.h:42
const Identifier & name() const noexcept
Definition NamedItem.h:48
AST item smart pointer.
Definition Item.h:134
The IDL simple declarator.
Definition Declarators.h:41
The common base for Struct and Exception.
Definition StructBase.h:41
An IDL type.
Definition Type.h:47
union forward declaration.
Definition Union.h:45
const Union & definition() const
Definition Union.h:48
union element definition.
union definition.
Definition Union.h:75
const Type & discriminator_type() const noexcept
Definition Union.h:78
const Variant & default_label() const noexcept
Definition Union.h:88
const UnionElement * default_element() const noexcept
Definition Union.h:95
Stores the constant value.
Definition Variant.h:42
Abstract Syntax Tree namespace.
Definition Array.h:34