IDL compiler front-end library
Loading...
Searching...
No Matches
ScopedName.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_SCOPEDNAME_H_
28#define IDLFE_AST_SCOPEDNAME_H_
29#pragma once
30
31#include "Identifier.h"
32#include "Location.h"
33#include <vector>
34#include <forward_list>
35
36namespace AST {
37
39struct ScopedName :
40 std::vector <Identifier>,
42{
45
47 std::string stringize () const;
48
51 from_root (false)
52 {}
53
57 ScopedName (const Location& loc) :
58 Location (loc),
59 from_root (false)
60 {}
61
67 ScopedName (const Location& loc, bool root, const Identifier& name);
68
74 ScopedName (const Location& loc, bool root, Identifier&& name) noexcept;
75
81 ScopedName (const Location& loc, bool root, std::initializer_list <const char*> names) :
82 Location (loc),
83 from_root (root)
84 {
85 reserve (names.size ());
86 for (auto n : names) {
87 emplace_back (n);
88 }
89 }
90
92 ScopedName (const ScopedName&) = default;
93
95 ScopedName (ScopedName&&) = default;
96
98 ScopedName& operator = (const ScopedName&) = default;
99
102
107 bool operator == (const ScopedName& rhs) const noexcept
108 {
109 return from_root == rhs.from_root &&
110 static_cast <const std::vector <Identifier>&> (*this) == (rhs);
111 }
112};
113
115typedef std::forward_list <ScopedName> ScopedNames;
116
117}
118
119#endif
An identifier.
Definition Identifier.h:37
Stores the location information.
Definition Location.h:43
Abstract Syntax Tree namespace.
Definition Array.h:34
std::forward_list< ScopedName > ScopedNames
Sequence of scoped names.
Definition ScopedName.h:115
A scoped name: sequence of identifiers.
Definition ScopedName.h:42
ScopedName(ScopedName &&)=default
Move constructor.
std::string stringize() const
ScopedName(const Location &loc, bool root, std::initializer_list< const char * > names)
Create multi-element name.
Definition ScopedName.h:81
bool operator==(const ScopedName &rhs) const noexcept
Test for equality.
Definition ScopedName.h:107
ScopedName(const Location &loc, bool root, Identifier &&name) noexcept
Create single-element name.
ScopedName()
Create empty name.
Definition ScopedName.h:50
bool from_root
true if it is a root-scoped name, i.e. started from "::".
Definition ScopedName.h:44
ScopedName & operator=(const ScopedName &)=default
Assignment.
ScopedName(const ScopedName &)=default
Copy constructor.
ScopedName(const Location &loc)
Create empty name with location.
Definition ScopedName.h:57
ScopedName(const Location &loc, bool root, const Identifier &name)
Create single-element name.