cl-ast: Add syntax support for generics
This commit is contained in:
@@ -232,6 +232,14 @@ pub mod clangify {
|
||||
};
|
||||
}
|
||||
}
|
||||
impl CLangify for Generics {
|
||||
fn print(&self, _y: &mut CLangifier) {
|
||||
let Self { vars } = self;
|
||||
if !vars.is_empty() {
|
||||
panic!("C doesn't have generics, dumbass.")
|
||||
}
|
||||
}
|
||||
}
|
||||
impl CLangify for Alias {
|
||||
fn print(&self, y: &mut CLangifier) {
|
||||
let Self { name, from } = self;
|
||||
@@ -263,7 +271,7 @@ pub mod clangify {
|
||||
}
|
||||
impl CLangify for Function {
|
||||
fn print(&self, y: &mut CLangifier) {
|
||||
let Self { name, sign, bind, body } = self;
|
||||
let Self { name, gens: _, sign, bind, body } = self;
|
||||
let TyFn { args, rety } = sign;
|
||||
let types = match args.as_ref() {
|
||||
TyKind::Tuple(TyTuple { types }) => types.as_slice(),
|
||||
@@ -293,7 +301,7 @@ pub mod clangify {
|
||||
}
|
||||
impl CLangify for Struct {
|
||||
fn print(&self, y: &mut CLangifier) {
|
||||
let Self { name, kind } = self;
|
||||
let Self { name, gens: _, kind } = self;
|
||||
y.p("struct ").p(name).nest(" {").p(kind);
|
||||
y.endl().p("}");
|
||||
}
|
||||
@@ -320,7 +328,7 @@ pub mod clangify {
|
||||
}
|
||||
impl CLangify for Enum {
|
||||
fn print(&self, y: &mut CLangifier) {
|
||||
let Self { name, variants } = self;
|
||||
let Self { name, gens: _, variants } = self;
|
||||
y.nest("enum ").p(name).p(" {").endl();
|
||||
match variants {
|
||||
Some(v) => {
|
||||
|
||||
@@ -214,6 +214,12 @@ pub mod yamlify {
|
||||
};
|
||||
}
|
||||
}
|
||||
impl Yamlify for Generics {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { vars } = self;
|
||||
y.key("Generics").value(vars);
|
||||
}
|
||||
}
|
||||
impl Yamlify for Alias {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { name, from } = self;
|
||||
@@ -243,9 +249,10 @@ pub mod yamlify {
|
||||
}
|
||||
impl Yamlify for Function {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { name, sign, bind, body } = self;
|
||||
let Self { name, gens, sign, bind, body } = self;
|
||||
y.key("Function")
|
||||
.pair("name", name)
|
||||
.pair("gens", gens)
|
||||
.pair("sign", sign)
|
||||
.pair("bind", bind)
|
||||
.pair("body", body);
|
||||
@@ -253,8 +260,11 @@ pub mod yamlify {
|
||||
}
|
||||
impl Yamlify for Struct {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { name, kind } = self;
|
||||
y.key("Struct").pair("name", name).yaml(kind);
|
||||
let Self { name, gens, kind } = self;
|
||||
y.key("Struct")
|
||||
.pair("gens", gens)
|
||||
.pair("name", name)
|
||||
.yaml(kind);
|
||||
}
|
||||
}
|
||||
impl Yamlify for StructKind {
|
||||
@@ -274,8 +284,8 @@ pub mod yamlify {
|
||||
}
|
||||
impl Yamlify for Enum {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { name, variants: kind } = self;
|
||||
y.key("Enum").pair("name", name).yaml(kind);
|
||||
let Self { name,gens, variants: kind } = self;
|
||||
y.key("Enum").pair("gens", gens).pair("name", name).yaml(kind);
|
||||
}
|
||||
}
|
||||
impl Yamlify for Variant {
|
||||
|
||||
Reference in New Issue
Block a user