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