Emit property registration for interfaces

We don't support property definitions without setters/getters for interfaces yet, but this will come later.
parent 89e56bcd
Pipeline #11287 passed with stages
in 21 minutes 26 seconds
......@@ -14,6 +14,7 @@ use gen::cstringliteral::CStringLiteral;
use gen::imp;
use gen::instance_ext;
use gen::names::Names;
use gen::properties;
use gen::signals;
use gen::slots::SlotDeclarations;
......@@ -74,6 +75,11 @@ impl<'ast> InterfaceContext<'ast> {
let slot_trait_fns = instance_ext::slot_trait_fns(&self.iface.slots);
let slot_trait_impls = instance_ext::slot_trait_impls(&self.names, &self.iface.slots);
// FIXME normalize this function names, I'm sure we can find better names for this
// variables and functions
let properties_enum = properties::properties_enum(&self.iface.properties);
let properties_registration = properties::properties_registration(&self.iface.properties);
quote_cs! {
pub mod #ModuleName {
#![allow(non_snake_case)] // "oddly" named module above
......@@ -123,7 +129,12 @@ impl<'ast> InterfaceContext<'ast> {
#slot_declarations
}
// properties enum
#properties_enum
struct #PrivateClassName {
properties: *const Vec<*const gobject_ffi::GParamSpec>,
// signal ids
#(#signal_id_names: u32,)*
}
......@@ -131,6 +142,7 @@ impl<'ast> InterfaceContext<'ast> {
static mut PRIV: #PrivateClassName = #PrivateClassName {
// we use this instead of "ptr::null()" because using
// function calls to set constants is feature-gated.
properties: 0 as *const _,
// signal ids
#(#signal_id_names: 0,)*
......@@ -166,9 +178,17 @@ impl<'ast> InterfaceContext<'ast> {
) {
#callback_guard
let vtable = &mut *(vtable as *mut #IfaceName);
{
let gobject_class = &mut *(vtable as *mut gobject_ffi::GObjectClass);
#(#slot_assignments)*
#properties_registration
}
{
let vtable = &mut *(vtable as *mut #IfaceName);
#(#slot_assignments)*
}
#(#signal_declarations)*
......
......@@ -60,8 +60,8 @@ pub struct Interface<'ast> {
// The order of these is important; it's the order of the slots in FooIface
pub slots: Vec<Slot<'ast>>,
/* FIXME: properties */
/* pub n_reserved_slots: usize, */
// pub n_reserved_slots: usize,
pub properties: Vec<Property<'ast>>,
}
pub enum Slot<'ast> {
......@@ -566,12 +566,14 @@ impl<'ast> Interfaces<'ast> {
fn add(&mut self, ast_iface: &'ast ast::Interface) -> Result<()> {
let slots = self.translate_slots(ast_iface)?;
let properties = self.translate_properties(ast_iface)?;
let prev = self.items.insert(
ast_iface.name,
Interface {
name: ast_iface.name,
slots,
properties,
},
);
if prev.is_some() {
......@@ -585,7 +587,7 @@ impl<'ast> Interfaces<'ast> {
for item in ast_iface.items.iter() {
match item.node {
ast::ImplItemKind::Prop(_) => unimplemented!(), // FIXME
ast::ImplItemKind::Prop(_) => (),
_ => {
let slot = Slot::translate_from_item(item)?;
......@@ -597,6 +599,23 @@ impl<'ast> Interfaces<'ast> {
Ok(slots)
}
fn translate_properties(&self, ast_iface: &'ast ast::Interface) -> Result<Vec<Property<'ast>>> {
let mut properties = Vec::new();
for item in ast_iface.items.iter() {
match item.node {
ast::ImplItemKind::Prop(_) => {
let property = Property::translate_from_impl_item(item)?;
properties.push(property);
}
_ => (),
}
}
Ok(properties)
}
pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'a Interface> + 'a {
self.items.values()
}
......
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