diff --git a/tools/gcg/ChangeLog b/tools/gcg/ChangeLog index db1573957d..cdac77baa7 100644 --- a/tools/gcg/ChangeLog +++ b/tools/gcg/ChangeLog @@ -1,5 +1,7 @@ 1998-11-21 Lauri Alanko + * Added import headers and some more example stuff. + * It actually runs now, with a zillion caveats, but anyway.. Still have to do lotsa things for serious use.. diff --git a/tools/gcg/TODO b/tools/gcg/TODO index 4587a02b26..2c3bef1cfb 100644 --- a/tools/gcg/TODO +++ b/tools/gcg/TODO @@ -1,9 +1,8 @@ Not in any order: - fix memory leaks (no significance in practice, but...) -- gtkarg wrappers for data members +- gtkarg wrappers for data members, with a more generic "attribute" concept - Pretty formatted comments from doc strings - HTML doc output - IDL output - Demarshallers -- package-prefixless import headers diff --git a/tools/gcg/ex/Makefile.am b/tools/gcg/ex/Makefile.am index bd3b285e52..748d4a4112 100644 --- a/tools/gcg/ex/Makefile.am +++ b/tools/gcg/ex/Makefile.am @@ -3,15 +3,17 @@ GEN_CODE = ostream_s.c file_ostream_s.c # actual automake variables noinst_LIBRARIES = libgcgexample.a +noinst_PROGRAMS = strtest CFLAGS = -g -Wall -W -I.. SUFFIXES = .gc .gh - - libgcgexample_a_SOURCES = $(GEN_CODE) +strtest_SOURCES = strtest.c +strtest_LDADD = libgcgexample.a -lgtk -lgdk -lgmodule -lglib + # tools @@ -21,8 +23,6 @@ MAKEDEPEND = sh -c '$(CC) -M -x c $$* | $(SED) -e "s/.gc.o/_s.c/g"' makedepend # dependencies and other rules for the def files -# these use gmake functions, so automake variables -# cannot depend on these GCG_DEFS = $(subst _s.c,.gc,$(GEN_CODE)) diff --git a/tools/gcg/ex/file_ostream.c b/tools/gcg/ex/file_ostream.c index cf40f7005a..336473f47a 100644 --- a/tools/gcg/ex/file_ostream.c +++ b/tools/gcg/ex/file_ostream.c @@ -9,8 +9,15 @@ static void put_char(ExOstream* s, gchar c){ fputc(c, str->file); } +static void close(ExOstream* s){ + ExFileOstream* str = EX_FILE_OSTREAM(s); + fclose(str->file); + str->file = NULL; +} + static void ex_file_ostream_class_init_real(ExFileOstreamClass* klass){ ((ExOstreamClass*)klass)->putchar = put_char; + ((ExOstreamClass*)klass)->close = close; } static ExFileOstream* file_ostream_open_real(gchar* filename){ diff --git a/tools/gcg/ex/strtest.c b/tools/gcg/ex/strtest.c new file mode 100644 index 0000000000..c15ad6a4fd --- /dev/null +++ b/tools/gcg/ex/strtest.c @@ -0,0 +1,8 @@ +#include + +int main(void){ + Ostream* x = OSTREAM(file_ostream_open("foo")); + ostream_putstring(x, "Whammo!\n"); + ostream_close(x); + return 0; +} diff --git a/tools/gcg/gcg.c b/tools/gcg/gcg.c index d038cdaea1..1bb6f43708 100644 --- a/tools/gcg/gcg.c +++ b/tools/gcg/gcg.c @@ -14,13 +14,15 @@ Id header_root = ".."; Id source_name = NULL; Id impl_name = NULL; +gboolean collect_marshall = FALSE; + GString* cpp_cmd; void get_options(int argc, char* argv[]){ gint x=0; yydebug = yy_flex_debug = FALSE; do{ - x=getopt(argc, argv, "D:i:dI:o:"); + x=getopt(argc, argv, "D:i:dI:o:m"); switch(x){ case 'D': header_root=optarg; @@ -41,6 +43,8 @@ void get_options(int argc, char* argv[]){ case 'o': source_name = optarg; break; + case 'm': + collect_marshall = TRUE; case '?': case ':': g_error("Bad option %c!\n", x); @@ -148,7 +152,14 @@ int main(int argc, char* argv[]){ p_col("prot_depends", p_type_include), p_col("protected", NULL)), out); - return 0; + + open_out(p_import_header, "import", + p_fmt("~~~", + p_func_include(current_module), + p_col("import_depends", p_import_include), + p_col("import_alias", NULL)), + out); +return 0; } diff --git a/tools/gcg/output.c b/tools/gcg/output.c index 2351d7cbe8..564e7f3a57 100644 --- a/tools/gcg/output.c +++ b/tools/gcg/output.c @@ -78,6 +78,17 @@ PNode* p_func_header(Module* m){ p_c_ident(m->name)); } +PNode* p_import_header(Module* m){ + if(m->header) + return p_nil; + else + return p_fmt("~/~_i.h", + m->package->headerbase + ? p_str(m->package->headerbase) + : p_c_ident(m->package->name), + p_c_ident(m->name)); +} + PNode* p_type_include(Module* m){ return p_fmt("#include <~>\n", p_type_header(m)); @@ -93,6 +104,14 @@ PNode* p_func_include(Module* m){ p_func_header(m)); } +PNode* p_import_include(Module* m){ + PNode* hdr = p_import_header(m); + if(hdr == p_nil) + return p_nil; + else + return p_fmt("#include <~>\n", hdr); +} + PNode* p_params(FunParams* args, ParamOptions* opt){ ParamOptions o=*opt; @@ -298,11 +317,13 @@ void output_def(PRoot* out, Def* d){ pr_put(out, "protected", p_str("\n\n")); pr_put(out, "source_head", p_str("\n")); pr_put(out, "type", p_fmt("#define ~ \\\n" - " (~ ? ~() : (void)0, ~)\n", + " (~ ? (void)0 : ~ (), ~)\n", p_macro_name(t, "type", NULL), type_var, p_internal_varname(t, p_str("init_type")), type_var)); + output_macro_import(out, t, "type", NULL); + output_type_import(out, t->module->package, p_str(t->name)); output_var(out, "type", p_str("GtkType"), type_var); @@ -322,6 +343,40 @@ void output_def(PRoot* out, Def* d){ } +void output_type_import(PRoot* out, Package* pkg, PNode* body){ +#if 1 + pr_put(out, "import_alias", + p_fmt("#define ~ ~~\n", + body, + p_str(pkg->name), + body)); +#else + pr_put(out, "import_alias", + p_fmt("typedef ~~ ~;\n", + p_str(pkg->name), + body, + body)); +#endif +} + +void output_macro_import(PRoot* out, PrimType* t, Id mid, Id post){ + pr_put(out, "import_alias", + p_fmt("#define ~~~ ~\n", + mid ? p_fmt("~_", p_c_macro(mid)) : p_nil, + p_c_macro(t->name), + post ? p_fmt("_~", p_c_macro(post)) : p_nil, + p_macro_name(t, mid, post))); +} + +void output_var_import(PRoot* out, PrimType* t, PNode* body){ + pr_put(out, "import_alias", + p_fmt("#define ~_~ ~\n", + p_c_ident(t->name), + body, + p_varname(t, body))); +} + + /* void add_dep(PRoot* out, Id tag, PrimType* type){ diff --git a/tools/gcg/output.h b/tools/gcg/output.h index 6f27e0e381..f95b213ee4 100644 --- a/tools/gcg/output.h +++ b/tools/gcg/output.h @@ -61,6 +61,7 @@ PNode* p_c_macro(Id id); PNode* p_prot_header(Module* m); PNode* p_type_header(Module* m); PNode* p_func_header(Module* m); +PNode* p_import_header(Module* m); @@ -81,8 +82,11 @@ void output_flags(PRoot* out, Def* d); PNode* p_type_include(Module* m); PNode* p_prot_include(Module* m); PNode* p_func_include(Module* m); +PNode* p_import_include(Module* m); - +void output_type_import(PRoot* out, Package* pkg, PNode* body); +void output_macro_import(PRoot* out, PrimType* t, Id mid, Id post); +void output_var_import(PRoot* out, PrimType* t, PNode* body); diff --git a/tools/gcg/output_object.c b/tools/gcg/output_object.c index e8fb39f79f..50da2b3a01 100644 --- a/tools/gcg/output_object.c +++ b/tools/gcg/output_object.c @@ -128,6 +128,9 @@ void output_connector(PRoot* out, Method* m){ m->ret_type.prim?p_str("return "):p_nil, p_self_name(MEMBER(m)), p_str(MEMBER(m)->name))); + output_var_import(out, m->ret_type.prim, + p_fmt("connect_~", + p_c_ident(MEMBER(m)->name))); } PNode* p_param_marshtype(gpointer p){ @@ -248,6 +251,8 @@ void output_method(PRoot* out, Method* m){ p_nil, par, dispatch); + + output_var_import(out, t, name); fparams_free(par); } @@ -267,6 +272,7 @@ void output_data_member(PRoot* out, DataMember* m){ &m->type, name, p_nil); + output_var_import(out, t, p_fmt("set_~", name)); output_func(out, "functions", NULL, @@ -309,6 +315,7 @@ void output_data_member(PRoot* out, DataMember* m){ par=fparams("t", &MEMBER(m)->my_class->self_type[TRUE], self, p_nil); + output_var_import(out, t, name); output_func(out, "functions", &m->type, @@ -341,15 +348,18 @@ void output_member_cb(gpointer a, gpointer b){ output_member(b, a); } -PNode* p_class_macros(ObjectDef* o ){ +void output_class_macros(PRoot* out, ObjectDef* o){ PrimType* t=DEF(o)->type; - return p_fmt("#define ~(o) GTK_CHECK_TYPE(o, ~)\n" + pr_put(out, "type", + p_fmt("#define ~(o) GTK_CHECK_TYPE(o, ~)\n" "#define ~(o) GTK_CHECK_CAST(o, ~, ~)\n", p_macro_name(t, "is", NULL), p_macro_name(t, "type", NULL), p_macro_name(t, NULL, NULL), p_macro_name(t, "type", NULL), - p_primtype(t)); + p_primtype(t))); + output_macro_import(out, t, "is", NULL); + output_macro_import(out, t, NULL, NULL); } void output_object_type_init(PRoot* out, ObjectDef* o){ @@ -387,7 +397,7 @@ void output_object_type_init(PRoot* out, ObjectDef* o){ void output_object_init(PRoot* out, ObjectDef* o){ pr_put(out, "source_head", - p_fmt("static inline void ~ (~ ~);\n", + p_fmt("static void ~ (~ ~);\n", p_varname(DEF(o)->type, p_str("init_real")), p_type(&o->self_type[FALSE]), p_c_ident(DEF(o)->type->name))); @@ -427,17 +437,19 @@ void output_class_init(PRoot* out, ObjectDef* o){ void output_object(PRoot* out, Def* d){ ObjectDef* o = (ObjectDef*)d; + pr_put(out, "func_depends", d->type->module); pr_put(out, "func_parent_depends", o->parent->module); pr_put(out, "prot_depends", d->type->module); pr_put(out, "prot_parent_depends", o->parent->module); pr_put(out, "source_prot_depends", d->type->module); + pr_put(out, "import_depends", o->parent->module); output_object_type_init(out, o); output_class_init(out, o); output_object_init(out, o); pr_put(out, "protected", p_class_decl(o)); pr_put(out, "protected", p_class_body(o)); pr_put(out, "type", p_object_decl(o)); - pr_put(out, "type", p_class_macros(o)); + output_class_macros(out, o); pr_put(out, "protected", p_object_body(o)); g_slist_foreach(o->members, output_member_cb, out); }