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

gir: Add initial method gir generation

parent 0a0b7837
use std::fs::File;
use xml::writer::{EmitterConfig, XmlEvent};
use xml::EventWriter;
use hir::{Program, Class};
use hir::{Program, Class, Slot};
use glib_utils::*;
use gen::names::Names;
......@@ -61,7 +62,9 @@ pub fn generate_gir(class: &Class) -> Result<()> {
//.attr("parent", "GObject.Object")
)?;
// TODO: add methods here
for slot in class.slots.iter() {
let _ = gen_slot_xml(&mut w, &names, slot);
}
// closing class
w.write(XmlEvent::end_element())?;
......@@ -74,3 +77,41 @@ pub fn generate_gir(class: &Class) -> Result<()> {
Ok(())
}
fn gen_slot_xml(w: &mut EventWriter<&mut File>, names: &Names, slot: &Slot) -> Result<()> {
// <method name="get_margin" c:identifier="gepub_widget_get_margin">
// <doc xml:space="preserve">Gets the widget left and right margin</doc>
// <return-value transfer-ownership="none">
// <type name="gint" c:type="gint"/>
// </return-value>
// <parameters>
// <instance-parameter name="widget" transfer-ownership="none">
// <doc xml:space="preserve">a #GepubWidget</doc>
// <type name="Widget" c:type="GepubWidget*"/>
// </instance-parameter>
// </parameters>
// </method>
match slot {
Slot::Method(ref m) => {
let name = m.sig.name.to_string();
let identifier = names.exported_fn(&m.sig.name).to_string();
w.write(XmlEvent::start_element("method")
.attr("name", &name)
.attr("c:identifier", &identifier)
)?;
// TODO: add return-value here
// TODO: add parameters here
// TODO: add doc here?
w.write(XmlEvent::end_element())?;
},
_ => {
// VirtualMethod or Signal
}
};
Ok(())
}
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