Verified Commit 0a0b7837 authored by Daniel García Moreno's avatar Daniel García Moreno Committed by Jordan Petridis

gir: Managing gir generation errors

parent ba23813e
......@@ -13,5 +13,10 @@ error_chain! {
foreign_links {
Io(::std::io::Error) #[cfg(unix)];
Parse(ParseError);
GIR(::gen::gir::Error);
}
errors {
}
}
use std::fs::File;
use std::io::prelude::*;
use xml::writer::{EventWriter, EmitterConfig, XmlEvent, Result};
use xml::writer::{EmitterConfig, XmlEvent};
use hir::{Program, Class};
use glib_utils::*;
use gen::names::Names;
// TODO: manage errors
use xml::writer::Error as EmitterError;
pub fn generate(program: &Program) {
error_chain! {
foreign_links {
Io(::std::io::Error) #[cfg(unix)];
GIR(EmitterError);
}
}
pub fn generate(program: &Program) -> Result<()> {
for class in program.classes.iter() {
generate_gir(class);
generate_gir(class)?;
}
Ok(())
}
pub fn generate_gir(class: &Class) {
pub fn generate_gir(class: &Class) -> Result<()> {
if let Some(ref s) = class.gir {
let mut f = File::create(&s.value()).unwrap();
let mut f = File::create(&s.value())?;
let mut w = EmitterConfig::new()
.perform_indent(true)
......@@ -31,7 +39,7 @@ pub fn generate_gir(class: &Class) {
.attr("version", "1.2")
.attr("xmlns", "http://www.gtk.org/introspection/core/1.0")
.attr("xmlns:c", "http://www.gtk.org/introspection/c/1.0")
.attr("xmlns:glib", "http://www.gtk.org/introspection/glib/1.0"));
.attr("xmlns:glib", "http://www.gtk.org/introspection/glib/1.0"))?;
// TODO: include deps like
// <include name="GLib" version="2.0"/>
......@@ -41,7 +49,7 @@ pub fn generate_gir(class: &Class) {
.attr("c:symbol-prefixes", &lower_name)
//.attr("version", "1.0.0")
//.attr("shared-library", "lib.so.0")
);
)?;
w.write(XmlEvent::start_element("class")
.attr("name", &name)
......@@ -51,16 +59,18 @@ pub fn generate_gir(class: &Class) {
.attr("glib:type-struct", &names.vtable().to_string())
.attr("glib:get-type", &names.get_type_fn().to_string())
//.attr("parent", "GObject.Object")
);
)?;
// TODO: add methods here
// closing class
w.write(XmlEvent::end_element());
w.write(XmlEvent::end_element())?;
// closing namespace
w.write(XmlEvent::end_element());
w.write(XmlEvent::end_element())?;
// closing repository
w.write(XmlEvent::end_element());
w.write(XmlEvent::end_element())?;
}
Ok(())
}
......@@ -154,7 +154,7 @@ pub fn gobject_gen(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let result: Result<proc_macro2::TokenStream> =
hir::Program::from_ast_program(&ast_program)
.and_then(|program| {
gen::gir::generate(&program);
gen::gir::generate(&program)?;
Ok(gen::codegen(&program))
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment