use std::sync::Arc;
use crate::{
ir::{Path, Ty},
parser::protobuf::WellKnownFileName,
symbol::Ident,
};
#[derive(Clone, Debug)]
pub struct Extendee {
pub name: Ident,
pub index: ExtendeeIndex,
pub extendee_ty: ExtendeeType,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, Copy)]
pub struct ExtendeeIndex {
pub extendee_kind: ExtendeeKind,
pub tag_id: u32,
}
#[derive(Clone, Debug)]
pub struct ExtendeeType {
pub field_ty: FieldType,
pub item_ty: Ty,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FieldType {
Bool,
Int32,
Int64,
UInt32,
UInt64,
Float,
Double,
String,
Bytes,
Message,
Enum,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, Copy)]
pub enum ExtendeeKind {
File,
Message,
Field,
Enum,
EnumValue,
Service,
Method,
Oneof,
}
#[derive(Clone, Debug)]
pub struct UsedOptions(pub Vec<ExtendeeIndex>);
impl UsedOptions {
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub fn from_pb_unknown_fields(
extendee_kind: ExtendeeKind,
unknown_fields: &protobuf::UnknownFields,
) -> Self {
Self(
unknown_fields
.iter()
.map(|(k, _)| ExtendeeIndex {
extendee_kind,
tag_id: k,
})
.collect::<Vec<_>>(),
)
}
}
#[derive(Clone, Debug)]
pub struct Extendees(pub Vec<Arc<Extendee>>);
impl Extendees {
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}
#[derive(Clone, Debug)]
pub struct FileExts {
pub well_known_file_name: WellKnownFileName,
pub extendees: Extendees,
pub used_options: UsedOptions,
}
impl FileExts {
pub fn has_extendees(&self) -> bool {
!self.extendees.is_empty()
}
pub fn has_used_options(&self) -> bool {
!self.used_options.is_empty()
}
}
#[derive(Clone, Debug)]
pub struct ModExts {
pub extendees: Extendees,
}
impl ModExts {
pub fn has_extendees(&self) -> bool {
!self.extendees.is_empty()
}
}
#[derive(Clone, Debug)]
pub struct ItemExts {
pub used_options: UsedOptions,
pub parent: Option<Path>,
}
impl ItemExts {
pub fn has_used_options(&self) -> bool {
!self.used_options.is_empty()
}
}