dev/pbs (#8)
Co-authored-by: Nilton Constantino <nilton.constantino@visma.com> Reviewed-on: #8
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
use crate::frontends::pbs::symbols::{SymbolKind, Visibility};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
pub enum ExportSurfaceKind {
|
||||
Service,
|
||||
DeclareType, // struct, storage struct, type alias
|
||||
}
|
||||
|
||||
impl ExportSurfaceKind {
|
||||
pub fn from_symbol_kind(kind: SymbolKind) -> Option<Self> {
|
||||
match kind {
|
||||
SymbolKind::Service => Some(ExportSurfaceKind::Service),
|
||||
SymbolKind::Struct | SymbolKind::Contract | SymbolKind::ErrorType => {
|
||||
Some(ExportSurfaceKind::DeclareType)
|
||||
}
|
||||
SymbolKind::Function | SymbolKind::Local => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn validate_visibility(kind: SymbolKind, vis: Visibility) -> Result<(), String> {
|
||||
if vis == Visibility::Pub {
|
||||
if Self::from_symbol_kind(kind).is_none() {
|
||||
let kind_str = match kind {
|
||||
SymbolKind::Function => "Functions",
|
||||
_ => "This declaration",
|
||||
};
|
||||
return Err(format!("{} are not exportable in this version.", kind_str));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn namespace(&self) -> crate::frontends::pbs::symbols::Namespace {
|
||||
match self {
|
||||
ExportSurfaceKind::Service => crate::frontends::pbs::symbols::Namespace::Type,
|
||||
ExportSurfaceKind::DeclareType => crate::frontends::pbs::symbols::Namespace::Type,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod export_surface;
|
||||
Reference in New Issue
Block a user