Allow custom Go wrapper struct defs. Suppress the autogenerated go struct type definition, so that a custom defined one won't clash.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/3acdc85f Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/3acdc85f Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/3acdc85f Branch: refs/heads/master Commit: 3acdc85fb1b0318569b7d4f288d57501f3f739cd Parents: 905b30a Author: Marvin Humphrey <[email protected]> Authored: Sun May 3 11:17:46 2015 -0700 Committer: Marvin Humphrey <[email protected]> Committed: Wed May 6 14:28:16 2015 -0700 ---------------------------------------------------------------------- compiler/go/cfc/cfc.go | 8 ++++++++ compiler/src/CFCGoClass.c | 26 ++++++++++++++++++++------ compiler/src/CFCGoClass.h | 3 +++ 3 files changed, 31 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3acdc85f/compiler/go/cfc/cfc.go ---------------------------------------------------------------------- diff --git a/compiler/go/cfc/cfc.go b/compiler/go/cfc/cfc.go index fa9b8d7..1b47beb 100644 --- a/compiler/go/cfc/cfc.go +++ b/compiler/go/cfc/cfc.go @@ -280,3 +280,11 @@ func (obj *BindGoClass) SpecMethod(name, sig string) { } C.CFCGoClass_spec_method(obj.ref, nameC, sigC) } + +func (obj *BindGoClass) SetSuppressStruct(suppressStruct bool) { + if suppressStruct { + C.CFCGoClass_set_suppress_struct(obj.ref, C.int(1)) + } else { + C.CFCGoClass_set_suppress_struct(obj.ref, C.int(0)) + } +} http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3acdc85f/compiler/src/CFCGoClass.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCGoClass.c b/compiler/src/CFCGoClass.c index 6e32f68..79fa880 100644 --- a/compiler/src/CFCGoClass.c +++ b/compiler/src/CFCGoClass.c @@ -39,6 +39,7 @@ struct CFCGoClass { CFCClass *client; CFCGoMethod **method_bindings; size_t num_bound; + int suppress_struct; }; static CFCGoClass **registry = NULL; @@ -163,12 +164,10 @@ CFCGoClass_go_typing(CFCGoClass *self) { const char *full_struct = CFCClass_full_struct_sym(self->client); CFCClass *parent = CFCClass_get_parent(self->client); - char *parent_iface; - char *go_struct_def; + char *parent_type_str = NULL; if (parent) { const char *parent_struct = CFCClass_get_struct_sym(parent); CFCParcel *parent_parcel = CFCClass_get_parcel(parent); - char *parent_type_str; if (parent_parcel == self->parcel) { parent_type_str = CFCUtil_strdup(parent_struct); } @@ -179,17 +178,26 @@ CFCGoClass_go_typing(CFCGoClass *self) { parent_struct); FREEMEM(parent_package); } - parent_iface = CFCUtil_sprintf("\t%s\n", parent_type_str); + } + + char *go_struct_def; + if (parent && !self->suppress_struct) { go_struct_def = CFCUtil_sprintf("type %sIMP struct {\n\t%sIMP\n}\n", short_struct, parent_type_str); - FREEMEM(parent_type_str); } else { - parent_iface = CFCUtil_strdup(""); go_struct_def = CFCUtil_strdup(""); } + char *parent_iface; + if (parent) { + parent_iface = CFCUtil_sprintf("\t%s\n", parent_type_str); + } + else { + parent_iface = CFCUtil_strdup(""); + } + char *novel_iface = CFCUtil_strdup(""); S_lazy_init_method_bindings(self); for (int i = 0; self->method_bindings[i] != NULL; i++) { @@ -219,6 +227,7 @@ CFCGoClass_go_typing(CFCGoClass *self) { ; content = CFCUtil_sprintf(pattern, short_struct, parent_iface, novel_iface, go_struct_def); + FREEMEM(parent_type_str); FREEMEM(go_struct_def); FREEMEM(parent_iface); } @@ -345,3 +354,8 @@ CFCGoClass_spec_method(CFCGoClass *self, const char *name, const char *sig) { } } +void +CFCGoClass_set_suppress_struct(CFCGoClass *self, int suppress_struct) { + self->suppress_struct = !!suppress_struct; +} + http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3acdc85f/compiler/src/CFCGoClass.h ---------------------------------------------------------------------- diff --git a/compiler/src/CFCGoClass.h b/compiler/src/CFCGoClass.h index b074a4f..2791179 100644 --- a/compiler/src/CFCGoClass.h +++ b/compiler/src/CFCGoClass.h @@ -76,6 +76,9 @@ CFCGoClass_gen_meth_glue(CFCGoClass *self); void CFCGoClass_spec_method(CFCGoClass *self, const char *name, const char *sig); +void +CFCGoClass_set_suppress_struct(CFCGoClass *self, int suppress_struct); + #ifdef __cplusplus } #endif
