IDL compiler front-end library
NamedItem.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_NAMEDITEM_H_
28 #define IDLFE_AST_NAMEDITEM_H_
29 #pragma once
30 
31 #include "Item.h"
32 #include "ScopedName.h"
33 
34 namespace AST {
35 
36 class Builder;
37 class ItemScope;
38 class SimpleDeclarator;
39 class Symbols;
40 
42 class NamedItem :
43  public Item,
44  public Location
45 {
46 public:
48  const Identifier& name () const noexcept
49  {
50  return name_;
51  }
52 
54  const ItemScope* parent () const noexcept;
55 
57  std::string qualified_name () const;
58 
61 
64  const Symbols* parent_scope () const noexcept;
65 
66 protected:
67  NamedItem (Kind kind, Builder& builder, const SimpleDeclarator& name);
68 
69 private:
70  static Identifier unescape (Builder& builder, const SimpleDeclarator& name);
71 
72 private:
73  const Item* parent_;
74  const Identifier name_;
75 };
76 
77 inline
78 bool operator < (const Ptr <NamedItem>& l, const Identifier& r) noexcept
79 {
80  return l->name () < r;
81 }
82 
83 inline
84 bool operator < (const Identifier& l, const Ptr <NamedItem>& r) noexcept
85 {
86  return l < r->name ();
87 }
88 
89 inline
90 bool operator < (const Ptr <NamedItem>& l, const Ptr <NamedItem>& r) noexcept
91 {
92  return l->name () < r->name ();
93 }
94 
95 }
96 
97 #endif
The AST builder.
Definition: Builder.h:60
An identifier.
Definition: Identifier.h:37
An AST item.
Definition: Item.h:41
Kind
The kind of item.
Definition: Item.h:45
Kind kind() const noexcept
Definition: Item.h:75
The named item which defines a scope.
Definition: ItemScope.h:38
Stores the location information.
Definition: Location.h:43
A named AST item.
Definition: NamedItem.h:45
const Symbols * parent_scope() const noexcept
std::string qualified_name() const
const Identifier & name() const noexcept
Definition: NamedItem.h:48
const ItemScope * parent() const noexcept
ScopedName scoped_name() const
AST item smart pointer.
Definition: Item.h:134
The IDL simple declarator.
Definition: Declarators.h:41
Set of the named items.
Definition: Symbols.h:38
Abstract Syntax Tree namespace.
Definition: Array.h:34
bool operator<(const Identifier &l, const char *r) noexcept
Case-insensitive compare.
A scoped name: sequence of identifiers.
Definition: ScopedName.h:42