| 1 |
// Copyright (C) 2020-2024 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
// This file is part of GCC. |
| 4 |
|
| 5 |
// GCC is free software; you can redistribute it and/or modify it under |
| 6 |
// the terms of the GNU General Public License as published by the Free |
| 7 |
// Software Foundation; either version 3, or (at your option) any later |
| 8 |
// version. |
| 9 |
|
| 10 |
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 |
// for more details. |
| 14 |
|
| 15 |
// You should have received a copy of the GNU General Public License |
| 16 |
// along with GCC; see the file COPYING3. If not see |
| 17 |
// <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
#ifndef RUST_HIR_VISIBILITY_H |
| 20 |
#define RUST_HIR_VISIBILITY_H |
| 21 |
|
| 22 |
#include "rust-hir-simple-path.h" |
| 23 |
|
| 24 |
namespace Rust { |
| 25 |
namespace HIR { |
| 26 |
// Visibility of an item |
| 27 |
struct Visibility |
| 28 |
{ |
| 29 |
public: |
| 30 |
enum VisType |
| 31 |
{ |
| 32 |
PRIVATE, |
| 33 |
PUBLIC, |
| 34 |
RESTRICTED, |
| 35 |
ERROR, |
| 36 |
}; |
| 37 |
|
| 38 |
private: |
| 39 |
VisType vis_type; |
| 40 |
HIR::SimplePath path; |
| 41 |
location_t locus; |
| 42 |
|
| 43 |
// should this store location info? |
| 44 |
|
| 45 |
public: |
| 46 |
Visibility (VisType vis_type, |
| 47 |
HIR::SimplePath path = HIR::SimplePath::create_empty (), |
| 48 |
location_t locus = UNDEF_LOCATION) |
| 49 |
: vis_type (vis_type), path (std::move (path)), locus (locus) |
| 50 |
{} |
| 51 |
|
| 52 |
// Returns whether visibility is in an error state. |
| 53 |
bool is_error () const { return vis_type == ERROR; } |
| 54 |
|
| 55 |
// Does the current visibility refer to a simple `pub <item>` entirely public |
| 56 |
bool is_public () const { return vis_type == PUBLIC; } |
| 57 |
|
| 58 |
// Is the current visibility public restricted to a certain path |
| 59 |
bool is_restricted () const { return vis_type == RESTRICTED; } |
| 60 |
|
| 61 |
// Creates an error visibility. |
| 62 |
static Visibility create_error () |
| 63 |
{ |
| 64 |
return Visibility (ERROR, HIR::SimplePath::create_empty ()); |
| 65 |
} |
| 66 |
|
| 67 |
VisType get_vis_type () const { return vis_type; } |
| 68 |
|
| 69 |
const HIR::SimplePath &get_path () const |
| 70 |
{ |
| 71 |
rust_assert (!is_error ()); |
| 72 |
return path; |
| 73 |
} |
| 74 |
|
| 75 |
std::string as_string () const; |
| 76 |
}; |
| 77 |
} // namespace HIR |
| 78 |
} // namespace Rust |
| 79 |
|
| 80 |
#endif |