IDL compiler front-end library
UnionElement.h
Go to the documentation of this file.
1 /*
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_UNIONELEMENT_H_
28 #define IDLFE_AST_UNIONELEMENT_H_
29 #pragma once
30 
31 #include "Member.h"
32 #include "Variant.h"
33 #include <vector>
34 
35 namespace AST {
36 
41 class UnionElement :
42  public Member
43 {
44 public:
46  typedef std::vector <Variant> Labels;
47 
49  const Labels& labels () const noexcept
50  {
51  return labels_;
52  }
53 
55  bool is_default () const noexcept
56  {
57  return labels_.empty ();
58  }
59 
60 private:
61  template <class T> friend class Ptr;
62 
63  UnionElement (Builder& builder, std::vector <Variant>&& labels, Type&& t, const SimpleDeclarator& name) :
64  Member (builder, std::move (t), name, Item::Kind::UNION_ELEMENT),
65  labels_ (std::move (labels))
66  {}
67 
68 private:
69  const std::vector <Variant> labels_;
70 };
71 
72 }
73 
74 #endif
The AST builder.
Definition: Builder.h:60
An AST item.
Definition: Item.h:41
The item with name and type.
Definition: Member.h:43
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
An IDL type.
Definition: Type.h:47
Kind
The kind of type.
Definition: Type.h:51
union element definition.
Definition: UnionElement.h:43
bool is_default() const noexcept
Definition: UnionElement.h:55
std::vector< Variant > Labels
The vector of case labels.
Definition: UnionElement.h:46
const Labels & labels() const noexcept
Definition: UnionElement.h:49
Abstract Syntax Tree namespace.
Definition: Array.h:34