IDL compiler front-end library
ItemWithId.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_ITEMWITHID_H_
28 #define IDLFE_AST_ITEMWITHID_H_
29 #pragma once
30 
31 #include "NamedItem.h"
32 
33 namespace AST {
34 
35 struct Version
36 {
37  uint16_t major, minor;
38 };
39 
41 class ItemWithId : public NamedItem
42 {
43 public:
45  std::string repository_id () const;
46 
49  static const ItemWithId* cast (const NamedItem* item) noexcept
50  {
51  return cast (const_cast <NamedItem*> (item));
52  }
53 
54 protected:
55  ItemWithId (Kind kind, Builder& builder, const SimpleDeclarator& name);
56 
57  virtual bool prefix (Builder& builder, const std::string& pref, const Location& loc);
58 
59 private:
60  friend class Builder;
61 
62  static ItemWithId* cast (NamedItem* item) noexcept;
63 
64  bool check_prefix (Builder& builder, const Location& loc) const noexcept;
65 
66  void type_id (Builder& builder, const std::string& id, const Location& loc);
67 
68  void pragma_version (Builder& builder, const Version v, const Location& loc);
69 
70  void set_id (const ItemWithId& src)
71  {
72  data_ = src.data_;
73  }
74 
75 private:
76  enum
77  {
78  EXPLICIT_ID,
79  EXPLICIT_PREFIX,
80  EXPLICIT_VERSION,
81 
82  EXPLICIT_SPECIFICATIONS
83  };
84 
85  struct Data
86  {
87  Data (const std::string& prefix) :
88  prefix_or_id (prefix)
89  {
90  version.major = 1;
91  version.minor = 0;
92  }
93 
94  std::string prefix_or_id;
95  Version version;
96 
97  Location explicit_ [EXPLICIT_SPECIFICATIONS];
98  }
99  data_;
100 };
101 
102 }
103 
104 #endif
The AST builder.
Definition: Builder.h:60
Kind
The kind of item.
Definition: Item.h:45
Kind kind() const noexcept
Definition: Item.h:75
Items which have repository identifiers derive from this class.
Definition: ItemWithId.h:42
std::string repository_id() const
static const ItemWithId * cast(const NamedItem *item) noexcept
Definition: ItemWithId.h:49
Stores the location information.
Definition: Location.h:43
A named AST item.
Definition: NamedItem.h:45
const Identifier & name() const noexcept
Definition: NamedItem.h:48
The IDL simple declarator.
Definition: Declarators.h:41
Abstract Syntax Tree namespace.
Definition: Array.h:34