IDL compiler front-end library
Location.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_LOCATION_H_
28 #define IDLFE_AST_LOCATION_H_
29 #pragma once
30 
31 #include <filesystem>
32 #include <assert.h>
33 
34 // Support for the Bison location.
35 namespace yy {
36 class location;
37 }
38 
39 namespace AST {
40 
42 class Location
43 {
44 public:
46  const std::filesystem::path& file () const noexcept
47  {
48  assert (file_);
49  return *file_;
50  }
51 
53  unsigned line () const noexcept
54  {
55  return line_;
56  }
57 
58  Location () noexcept :
59  file_ (nullptr),
60  line_ (0)
61  {}
62 
63  Location (const std::filesystem::path* file, unsigned line) noexcept :
64  file_ (file),
65  line_ (line)
66  {}
67 
68  Location (const yy::location&) noexcept;
69 
70  operator bool () const noexcept
71  {
72  return file_ != nullptr;
73  }
74 
75 private:
76  const std::filesystem::path* file_;
77  unsigned line_;
78 };
79 
80 }
81 
82 #endif
Stores the location information.
Definition: Location.h:43
unsigned line() const noexcept
Definition: Location.h:53
const std::filesystem::path & file() const noexcept
Definition: Location.h:46
Abstract Syntax Tree namespace.
Definition: Array.h:34