mod.rs 1.38 KB
Newer Older
1 2 3
// We give `ClassName` variables an identifier that uses upper-case.
#![allow(non_snake_case)]

4
use proc_macro2::TokenStream;
5

mredlek's avatar
mredlek committed
6
mod ancestorext;
7
mod boilerplate;
8
mod boilerplateext;
9
mod class;
10
mod cstringliteral;
mredlek's avatar
mredlek committed
11
pub mod gir;
12
mod imp;
13
mod instance;
14
mod instance_ext;
15
mod interface;
16
mod privatestatic;
Federico Mena Quintero's avatar
Federico Mena Quintero committed
17
mod properties;
18
mod property_ext;
19
mod public;
20
mod signals;
21
mod signatures;
22
mod slots;
23
mod writer;
24

25
pub use self::boilerplate::Boilerplate;
26
pub use self::boilerplateext::BoilerplateExt;
27
pub use self::class::Class;
28
pub use self::instance::Instance;
29
pub use self::interface::Interface;
30
pub use self::property_ext::PropertyGenExt;
31
use self::writer::RustWriter;
32
use crate::hir::Program;
33

mredlek's avatar
mredlek committed
34 35
pub use self::ancestorext::AncestorRefExt;

36
pub fn codegen(program: &Program<'_>) -> TokenStream {
37 38
    let mut writer = RustWriter::new();

mredlek's avatar
mredlek committed
39
    program.classes.iter().for_each(|class| {
40
        let cx = Class::new(program, class);
mredlek's avatar
mredlek committed
41 42 43 44 45 46
        let tokens = cx.gen_class();
        let mut class_writer = writer.class_writer(&class.attrs);
        class_writer.append(tokens);
    });

    program.interfaces.iter().for_each(|iface| {
47
        let cx = Interface::new(program, iface);
mredlek's avatar
mredlek committed
48
        let mut class_writer = writer.class_writer(&iface.attrs);
49
        class_writer.append(cx.gen_boilerplate());
mredlek's avatar
mredlek committed
50
    });
51

52
    writer.into_tokenstream()
53
}
54

55 56 57 58 59 60 61
pub mod tests {
    use super::*;

    pub fn run() {
        signals::tests::run();
    }
}