Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add 'subclass' mode #604

Open
wants to merge 122 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
7bbfb29
add subclass work mode
vhdirk May 15, 2018
58eb331
add stub subclass codegen module
vhdirk May 15, 2018
628f9ad
subclass generate function
vhdirk May 15, 2018
800895c
add subclass target path
vhdirk May 16, 2018
4ef2915
add subclass target path cli param
vhdirk May 16, 2018
5967ad3
read subclass trait names from config
vhdirk May 16, 2018
dda175a
reuse target path instead of defining a new one
vhdirk May 16, 2018
b6ce8e2
wip: some initial trait generation
vhdirk May 16, 2018
d8a84d3
wip: some more initial trait generation
vhdirk May 16, 2018
d7e1a9a
Generate new variant of the glib_wrapper!() macro that distinguishes …
sdroege Nov 10, 2017
05a8da1
try to figure out how to get the class vfuncs
vhdirk May 16, 2018
2eba7fa
remove subclass_class_trait_name in favour of class_type
vhdirk May 16, 2018
b65b3ed
try to get to class vfuncs
vhdirk May 17, 2018
dac5a41
can we read vfuncs exactly the same as signals?
vhdirk May 17, 2018
320b42b
supply class info to generators
vhdirk May 18, 2018
766bf9e
wip: start generating default impls
vhdirk May 18, 2018
1b0ff1a
wip: beef up analysis for virtual methods. Still panicks somewhere
vhdirk May 20, 2018
2ac1f3c
use name if c_identifier is not specified
vhdirk May 20, 2018
de46e6d
fix virtual methods in Impl trait
vhdirk May 20, 2018
4d0bcc9
impl trait: use real parents and interfaces
vhdirk May 20, 2018
1c6eacb
generate trait-ext impl
vhdirk May 20, 2018
9d49182
start generating base impl
vhdirk May 21, 2018
d96c184
start figuring out how builder works
vhdirk May 21, 2018
f6d5f5a
minor bit of refactoring
vhdirk May 22, 2018
2c6ac91
generate base impl
vhdirk May 23, 2018
935c24c
generate ext trait
vhdirk May 24, 2018
d7087c2
add stubs for generating the remaining items
vhdirk May 25, 2018
7cc5f09
wip: implement glib wrapper and base impl
vhdirk May 25, 2018
e613e57
generate box impl
vhdirk May 25, 2018
adaf643
fix typo in impl classext
vhdirk May 25, 2018
c7cb856
generate objecttype
vhdirk May 26, 2018
c38db46
generate extern c functions
vhdirk May 26, 2018
0d64a7c
fix after rebase on master
vhdirk May 26, 2018
80ea005
add return types for functions
vhdirk May 28, 2018
2b50141
rename self ffi param to 'ptr'
vhdirk May 28, 2018
4b6f0a8
fix 2 typos
vhdirk May 28, 2018
4bb1278
not everything should be called 'ptr'
vhdirk May 28, 2018
6c61001
import libc crate
vhdirk May 29, 2018
81fcbad
move generation of use statements to statics
vhdirk May 29, 2018
a1eb6db
start making stuff specific for interfaces
vhdirk May 29, 2018
31ef375
ignore a lot of generations for interfaces
vhdirk May 30, 2018
c25c473
stubs for generating interfaces
vhdirk May 30, 2018
bb53190
improve argument conversion in base trait
vhdirk May 30, 2018
07e6920
wip: generate the interface type init function
vhdirk May 31, 2018
118b083
generate interface init boilerplate
vhdirk May 31, 2018
bba7f5d
tailor extern c functions for interfaces
vhdirk Jun 1, 2018
543ee17
wip: generate get_type function
vhdirk Jun 1, 2018
dfd0592
fix variable name in interface extern functions
vhdirk Jun 1, 2018
5634796
generate initial mod.rs
vhdirk Jun 2, 2018
6ae1b23
insert subclass dependencies
vhdirk Jun 2, 2018
3bec7d4
generate lib instead of mod
vhdirk Jun 3, 2018
acaa799
remove erroneous commas
vhdirk Jun 4, 2018
c3bea58
fix return type of get_type
vhdirk Jun 4, 2018
ed8b51e
fix format statement
vhdirk Jun 4, 2018
ddfa66b
fix interface function definitions
vhdirk Jun 4, 2018
4ef47ff
change trait to struct
vhdirk Jun 4, 2018
c82401e
fix typo
vhdirk Jun 4, 2018
6b0cfa0
remove faulty closing bracket
vhdirk Jun 4, 2018
4f1e4ed
use gobject-subclass modules
vhdirk Jun 5, 2018
1ba6171
interface impl: use correct type
vhdirk Jun 6, 2018
a4a09c5
use correct ffi type for interface"
vhdirk Jun 6, 2018
eabb443
fix incorrect variable name
vhdirk Jun 6, 2018
1ab854d
various fixes to interface generation
vhdirk Jun 7, 2018
9b839f2
wip: convert trampoline parameters
vhdirk Jun 7, 2018
29ef5e1
call trampoline with correct parameters
vhdirk Jun 7, 2018
ca5985f
convert trampoline return values
vhdirk Jun 7, 2018
76bf2a5
allow libraries to be exported under a different name
vhdirk Jun 7, 2018
889b263
remove unneeded use statement
vhdirk Jun 7, 2018
8d61bb8
use correct ffi crate name for subclass
vhdirk Jun 8, 2018
5287eb1
skip the first interface trampoline parameter
vhdirk Jun 8, 2018
b8db716
most get_type functions seem global
vhdirk Jun 8, 2018
2bde5ff
splice trampoline impl from external file
vhdirk Jun 8, 2018
f7c3aa2
insert toplevel content as well
vhdirk Jun 8, 2018
ec8264f
insert content for other traits
vhdirk Jun 8, 2018
595492e
fix various issues when compiling generated code
vhdirk Jun 8, 2018
cabf8c4
Into -> Pointer
vhdirk Jun 8, 2018
9f86752
I cannot get gir to transform nullable ptrs to Option
vhdirk Jun 8, 2018
8230983
manually transform option into nullptr
vhdirk Jun 9, 2018
96796c2
add missing import statements for application
vhdirk Jun 9, 2018
8191d6d
fix compilation of action interface
vhdirk Jun 10, 2018
b633689
add own ffi type to glib wrapper
vhdirk Jun 10, 2018
a307a27
fix config for vfunc defs
vhdirk Jun 10, 2018
a9e414c
ignore some application vfuncs
vhdirk Jun 10, 2018
6babfc2
implement conversion of nullable types
vhdirk Jun 10, 2018
7d3db07
rename ptr to gptr
vhdirk Jun 10, 2018
73e2e69
fix ptr mutability
vhdirk Jun 10, 2018
a95bf23
generate interface register function
vhdirk Jun 10, 2018
0efb089
fix eager copy/paste error
vhdirk Jun 10, 2018
7d8b12c
generate import statements for subclass modules
vhdirk Jun 11, 2018
5c1ff95
use proper get_type function
vhdirk Jun 11, 2018
c1b3a91
various fixes for object generation
vhdirk Jun 12, 2018
649aea5
fix implementation of gio application
vhdirk Jun 13, 2018
e2b25f7
fix invalid object name
vhdirk Jun 14, 2018
b31b0c5
move custom snippets to target path
vhdirk Jun 15, 2018
8da4b0f
use correct get_type function
vhdirk Jun 22, 2018
a9a5604
don't add template param for interfaces
vhdirk Jun 22, 2018
e893ad3
don't add trait bounds for interfaces
vhdirk Jun 22, 2018
387dc6e
make custom implementation filenames on par with module name
vhdirk Jun 23, 2018
ffe4007
fix import path for subclass parents
vhdirk Jun 23, 2018
90582b7
alias imports from other subclass crates
vhdirk Jun 23, 2018
9f17014
skip InitiallyUnowned in glib_wrapper
vhdirk Jun 24, 2018
22e33eb
callback guard is now deprecated
vhdirk Jun 24, 2018
ef389c4
remove further occurances of callback_guard
vhdirk Jun 24, 2018
2618c70
fix ignoring InitiallyUnowned
vhdirk Jun 25, 2018
e9c7687
support optional types in trampoline parameters and improve lifetime …
vhdirk Jun 27, 2018
630f044
add basic support for default return values in base impl
vhdirk Jul 1, 2018
2d68259
implement destroy function for return parameter
vhdirk Jul 1, 2018
27f18df
transfer full ownership of return types
vhdirk Jul 1, 2018
3b75fcc
fix mutability of trampoline return types
vhdirk Jul 2, 2018
bc71b37
remove 'into' conversions in base impl
vhdirk Jul 2, 2018
4f6ee90
remove insertion of fixme
vhdirk Jul 3, 2018
7980ece
remove another FIXME
vhdirk Jul 3, 2018
c7faed3
write output parameters back to pointers
vhdirk Jul 4, 2018
b7c2a7f
omit brackets when there's only one output variable
vhdirk Jul 4, 2018
e7f3344
also store non-nullable pointers
vhdirk Jul 4, 2018
18f411e
fix some variable name vs module name confusion
vhdirk Jul 4, 2018
d7f5bbd
fix c type of inout params
vhdirk Jul 4, 2018
44b1509
fix optionality of output params vs arrays
vhdirk Jul 4, 2018
71856a8
fix destroy function for container types
vhdirk Jul 5, 2018
53e6bc7
always import ffi library in subclass mode
vhdirk Jul 6, 2018
d8c1dad
fix styling
vhdirk Jul 6, 2018
b9fad8d
fix build after rebase
vhdirk Dec 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/analysis/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ pub fn is_carray_with_direct_elements(env: &Env, typ: library::TypeId) -> bool {
}
}

fn analyze_async(
pub fn analyze_async(
env: &Env,
func: &library::Function,
callback_info: Option<CallbackInfo>,
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/general.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use config::gobjects::*;
use library::*;

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct StatusedTypeId {
pub type_id: TypeId,
pub name: String,
Expand Down
1 change: 1 addition & 0 deletions src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod return_value;
pub mod rust_type;
pub mod safety_assertion_mode;
pub mod signals;
pub mod virtual_methods;
pub mod signatures;
pub mod special_functions;
pub mod supertypes;
Expand Down
85 changes: 83 additions & 2 deletions src/analysis/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,28 @@ use super::imports::Imports;
use super::info_base::InfoBase;
use super::signatures::Signatures;
use traits::*;
use config::WorkMode;

#[derive(Debug, Default)]
pub struct Info {
pub base: InfoBase,
pub is_interface: bool,
pub c_type: String,
pub class_type: Option<String>,
pub c_class_type: Option<String>,
pub rust_class_type: Option<String>,
pub get_type: String,
pub supertypes: Vec<general::StatusedTypeId>,
pub generate_trait: bool,
pub trait_name: String,
pub subclass_impl_trait_name: String,
pub subclass_base_trait_name: String,
pub has_constructors: bool,
pub has_methods: bool,
pub has_functions: bool,
pub signals: Vec<signals::Info>,
pub notify_signals: Vec<signals::Info>,
pub virtual_methods: Vec<virtual_methods::Info>,
pub trampolines: trampolines::Trampolines,
pub properties: Vec<properties::Property>,
pub child_properties: ChildProperties,
Expand All @@ -43,6 +49,17 @@ impl Info {
pub fn has_action_signals(&self) -> bool {
self.signals.iter().any(|s| s.action_emit_name.is_some())
}

pub fn module_name(&self, env: &Env) -> Option<String>{
let obj = &env.config.objects[&self.full_name];
if !obj.status.need_generate() {
return None;
}

Some(obj.module_name.clone().unwrap_or_else(|| {
module_name(split_namespace_name(&self.full_name).1)
}))
}
}

impl Deref for Info {
Expand Down Expand Up @@ -89,10 +106,20 @@ pub fn class(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<Info>

let mut imports = Imports::with_defined(&env.library, &name);
imports.add("glib::translate::*", None);
imports.add("ffi", None);
//imports.add("ffi", None);
if obj.generate_display_trait {
imports.add("std::fmt", None);
}
imports.add("glib_ffi", None);
imports.add("gobject_ffi", None);
imports.add("std::mem", None);
imports.add("std::ptr", None);

if env.config.work_mode != WorkMode::Subclass {
imports.add("ffi", None);
}else{
imports.add(&format!("{}_ffi", env.config.library_name.to_lowercase()), None);
}

let supertypes = supertypes::analyze(env, class_tid, &mut imports);

Expand All @@ -102,6 +129,16 @@ pub fn class(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<Info>
.cloned()
.unwrap_or_else(|| format!("{}Ext", name));

let subclass_impl_trait_name = obj.subclass_impl_trait_name
.as_ref()
.cloned()
.unwrap_or_else(|| format!("{}Impl", name));

let subclass_base_trait_name = obj.subclass_base_trait_name
.as_ref()
.cloned()
.unwrap_or_else(|| format!("{}Base", name));

// Sanity check the user's configuration. It's unlikely that not generating
// a trait is wanted if there are subtypes in this very crate
if !generate_trait && has_known_subtypes(env, class_tid) {
Expand Down Expand Up @@ -149,6 +186,18 @@ pub fn class(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<Info>
obj,
&mut imports,
);

let virtual_methods = virtual_methods::analyze(
env,
&klass.virtual_methods,
class_tid,
generate_trait,
obj,
&mut imports,
Some(&mut signatures),
Some(deps),
);

let (properties, notify_signals) = properties::analyze(
env,
&klass.properties,
Expand Down Expand Up @@ -232,18 +281,23 @@ pub fn class(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<Info>

let info = Info {
base,
is_interface: false,
c_type: klass.c_type.clone(),
class_type: klass.type_struct.clone(),
c_class_type: klass.c_class_type.clone(),
rust_class_type,
get_type: klass.glib_get_type.clone(),
supertypes,
generate_trait,
trait_name,
subclass_impl_trait_name,
subclass_base_trait_name,
has_constructors,
has_methods,
has_functions,
signals,
notify_signals,
virtual_methods,
trampolines,
properties,
child_properties,
Expand Down Expand Up @@ -273,12 +327,18 @@ pub fn interface(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<I

let mut imports = Imports::with_defined(&env.library, &name);
imports.add("glib::translate::*", None);
imports.add("ffi", None);
imports.add("glib::object::IsA", None);
if obj.generate_display_trait {
imports.add("std::fmt", None);
}

if env.config.work_mode == WorkMode::Subclass {
imports.add("glib", None);
imports.add(&format!("{}_ffi", env.config.library_name.to_lowercase()), None);
}else{
imports.add("ffi", None);
}

let supertypes = supertypes::analyze(env, iface_tid, &mut imports);

let trait_name = obj.trait_name
Expand Down Expand Up @@ -309,6 +369,18 @@ pub fn interface(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<I
obj,
&mut imports,
);

let virtual_methods = virtual_methods::analyze(
env,
&iface.virtual_methods,
iface_tid,
true,
obj,
&mut imports,
Some(&mut signatures),
Some(deps)
);

let (properties, notify_signals) = properties::analyze(
env,
&iface.properties,
Expand All @@ -333,6 +405,11 @@ pub fn interface(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<I
imports.add("glib::ObjectExt", None);
}

let subclass_impl_trait_name = obj.subclass_impl_trait_name
.as_ref()
.cloned()
.unwrap_or_else(|| format!("{}Impl", name));

let base = InfoBase {
full_name,
type_id: iface_tid,
Expand All @@ -351,7 +428,9 @@ pub fn interface(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<I

let info = Info {
base,
is_interface: true,
c_type: iface.c_type.clone(),
class_type: iface.type_struct.clone(),
c_class_type: iface.c_class_type.clone(),
rust_class_type: None,
get_type: iface.glib_get_type.clone(),
Expand All @@ -362,9 +441,11 @@ pub fn interface(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<I
has_functions,
signals,
notify_signals,
virtual_methods,
trampolines,
properties,
signatures,
subclass_impl_trait_name,
..Default::default()
};

Expand Down
Loading