cl-ast: allow TyRef to be mutable
yaml.rs: Print AddrOf and TyRef the same way
This commit is contained in:
parent
75adbd6473
commit
98868d3960
@ -299,11 +299,11 @@ mod display {
|
||||
}
|
||||
impl Display for TyRef {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { count: _, to } = self;
|
||||
for _ in 0..self.count {
|
||||
let &Self { count, mutable, ref to } = self;
|
||||
for _ in 0..count {
|
||||
f.write_char('&')?;
|
||||
}
|
||||
write!(f, "{to}")
|
||||
write!(f, "{mutable}{to}")
|
||||
}
|
||||
}
|
||||
impl Display for TyFn {
|
||||
@ -632,7 +632,7 @@ mod convert {
|
||||
}
|
||||
impl From for VariantKind {
|
||||
u128 => VariantKind::CLike,
|
||||
Vec<Ty> => VariantKind::Tuple,
|
||||
Ty => VariantKind::Tuple,
|
||||
// TODO: enum struct variants
|
||||
}
|
||||
impl From for TyKind {
|
||||
|
@ -243,6 +243,7 @@ pub struct TyTuple {
|
||||
/// A [Ty]pe-reference expression as (number of `&`, [Path])
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct TyRef {
|
||||
pub mutable: Mutability,
|
||||
pub count: u16,
|
||||
pub to: Path,
|
||||
}
|
||||
|
@ -671,7 +671,7 @@ impl<'t> Parser<'t> {
|
||||
}
|
||||
self.consume_peeked();
|
||||
}
|
||||
Ok(TyRef { count, to: self.path()? })
|
||||
Ok(TyRef { count, mutable: self.mutability()?, to: self.path()? })
|
||||
}
|
||||
/// [TyFn] = `fn` [TyTuple] (-> [Ty])?
|
||||
pub fn tyfn(&mut self) -> PResult<TyFn> {
|
||||
|
@ -461,8 +461,8 @@ pub mod yamlify {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { count, mutable, expr } = self;
|
||||
y.key("AddrOf")
|
||||
.yaml(mutable)
|
||||
.pair("count", count)
|
||||
.yaml(mutable)
|
||||
.pair("expr", expr);
|
||||
}
|
||||
}
|
||||
@ -588,8 +588,11 @@ pub mod yamlify {
|
||||
}
|
||||
impl Yamlify for TyRef {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { count, to } = self;
|
||||
y.key("TyRef").pair("count", count).pair("to", to);
|
||||
let Self { count, mutable, to } = self;
|
||||
y.key("TyRef")
|
||||
.pair("count", count)
|
||||
.yaml(mutable)
|
||||
.pair("to", to);
|
||||
}
|
||||
}
|
||||
impl Yamlify for TyFn {
|
||||
|
Loading…
Reference in New Issue
Block a user