privacy: Add ModuleVisibility class

This commit is contained in:
Arthur Cohen 2022-04-21 16:13:05 +02:00
parent 14dbac9a8b
commit bfe8ffef86
3 changed files with 65 additions and 1 deletions

View File

@ -19,7 +19,6 @@
#ifndef RUST_PRIVACY_CHECK_H
#define RUST_PRIVACY_CHECK_H
#include "rust-hir-map.h"
#include "rust-hir.h"
#include "rust-hir-expr.h"
#include "rust-hir-stmt.h"

View File

@ -0,0 +1,61 @@
// Copyright (C) 2020-2022 Free Software Foundation, Inc.
// This file is part of GCC.
// GCC is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 3, or (at your option) any later
// version.
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
// You should have received a copy of the GNU General Public License
// along with GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include "rust-mapping-common.h"
namespace Rust {
namespace Privacy {
/**
* Visibility class related specifically to DefIds. This class allows defining
* the visibility of an item with regard to a specific module.
*/
class ModuleVisibility
{
public:
enum Type
{
Private,
Public,
Restricted,
};
static ModuleVisibility create_restricted (DefId module_id)
{
return ModuleVisibility (Type::Restricted, module_id);
}
static ModuleVisibility create_public ()
{
return ModuleVisibility (Type::Public, UNKNOWN_DEFID);
}
Type get_kind () { return kind; }
DefId &get_module_id () { return module_id; }
private:
ModuleVisibility (Type kind, DefId module_id)
: kind (kind), module_id (module_id)
{}
Type kind;
DefId module_id;
};
} // namespace Privacy
} // namespace Rust

View File

@ -26,6 +26,7 @@
#include "rust-ast-full-decls.h"
#include "rust-hir-full-decls.h"
#include "rust-lang-item.h"
#include "rust-privacy-common.h"
namespace Rust {
namespace Analysis {
@ -353,6 +354,9 @@ private:
// crate names
std::map<CrateNum, std::string> crate_names;
// Low level visibility map for each DefId
std::map<DefId, Privacy::ModuleVisibility> visibility_map;
};
} // namespace Analysis