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

gir: Generate method params

parent aee266c9
Pipeline #29658 passed with stages
in 9 minutes and 16 seconds
......@@ -4,7 +4,7 @@ use quote::ToTokens;
use xml::writer::{EmitterConfig, XmlEvent};
use xml::EventWriter;
use hir::{Program, Class, Slot, Method, Ty};
use hir::{Program, Class, Slot, Method, Ty, FnArg};
use glib_utils::*;
use gen::names::Names;
......@@ -37,21 +37,38 @@ pub fn generate_gir(class: &Class) -> Result<()> {
let lower_name = lower_case_instance_name(&name).to_string();
let names = Names::new(&class.name, "Class");
// TODO: Get the version and shared-library from Cargo.toml?
let version = "1.0.0";
let slib = format!("lib{}.so", lower_name);
// TODO: Find the parent namespace and class
let parent_name = "GObject.Object";
// TODO: include deps like GLib, etc
// the dep should be `("GLib", "2.0")` lib and version
let deps: Vec<(&str, &str)> = vec![];
w.write(XmlEvent::start_element("repository")
.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"))?;
// TODO: include deps like
// <include name="GLib" version="2.0"/>
for (name, version) in deps {
w.write(XmlEvent::start_element("include")
.attr("name", name)
.attr("version", version)
)?;
w.write(XmlEvent::end_element())?;
}
w.write(XmlEvent::start_element("namespace")
.attr("name", &name)
.attr("c:identifier-prefixes", &name)
.attr("c:symbol-prefixes", &lower_name)
// TODO: Get the version and shared-library from Cargo.toml?
//.attr("version", "1.0.0")
//.attr("shared-library", "lib.so.0")
.attr("version", &version)
.attr("shared-library", &slib)
)?;
w.write(XmlEvent::start_element("class")
......@@ -61,14 +78,13 @@ pub fn generate_gir(class: &Class) -> Result<()> {
.attr("c:symbol-prefix", &lower_name)
.attr("glib:type-struct", &names.vtable().to_string())
.attr("glib:get-type", &names.get_type_fn().to_string())
// TODO: Find the parent namespace and class
//.attr("parent", "GObject.Object")
.attr("parent", &parent_name)
)?;
gen_constructor_xml(&mut w, &names)?;
for slot in class.slots.iter() {
let _ = gen_slot_xml(&mut w, &names, slot);
gen_slot_xml(&mut w, &names, slot)?;
}
// closing class
......@@ -124,6 +140,25 @@ fn gen_slot_xml(w: &mut EventWriter<&mut File>, names: &Names, slot: &Slot) -> R
w.write(XmlEvent::end_element())?; // closing return-value
// TODO: add parameters here
w.write(XmlEvent::start_element("parameters"))?;
for param in sig.inputs.iter() {
if let FnArg::Arg { ref name, ref ty, .. } = param {
let ownership = "none";
let ctype = type_to_ctype(ty);
w.write(XmlEvent::start_element("parameter")
.attr("name", &name.to_string())
.attr("transfer-ownership", ownership))?;
w.write(XmlEvent::start_element("type")
.attr("name", &ctype).attr("c:type", &ctype))?;
w.write(XmlEvent::end_element())?; // closing type
w.write(XmlEvent::end_element())?; // closing parameter
}
}
w.write(XmlEvent::end_element())?; // closing parameters
// TODO: add doc here?
w.write(XmlEvent::end_element())?;
......@@ -168,7 +203,7 @@ fn type_to_ctype(type_: &Ty) -> String {
Ty::Unit => "void".to_string(),
Ty::Char(_) => "gchar*".to_string(),
Ty::Bool(_) => "gboolean".to_string(),
// These two need to be correctly implemented when support
// FIXME: These two need to be correctly implemented when support
Ty::Borrowed(ref t) => format!("{}*", &type_to_ctype(t.as_ref())),
Ty::Owned(ref t) => t.into_token_stream().to_string(),
}
......
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