Commit 9c7928f1 authored by Lauri Alanko's avatar Lauri Alanko

Fixed the parser and lexer a bit, changed naming conventions here and there.

parent d2e59873
1999-01-05 Lauri Alanko <la@iki.fi>
* Fixed the parser and lexer a bit, changed naming conventions
here and there.
Mon Dec 21 21:56:58 PST 1998 Manish Singh <yosh@gimp.org> Mon Dec 21 21:56:58 PST 1998 Manish Singh <yosh@gimp.org>
* fixed up ex for latest glib/gtk+ * fixed up ex for latest glib/gtk+
......
...@@ -42,7 +42,7 @@ Module* get_mod(Package* pkg, Id modname){ ...@@ -42,7 +42,7 @@ Module* get_mod(Package* pkg, Id modname){
} }
void put_mod(Module* m){ void put_mod(Module* m){
if(m->package) if(m->package && m->name)
g_hash_table_insert(m->package->mod_hash, (gpointer)m->name, m); g_hash_table_insert(m->package->mod_hash, (gpointer)m->name, m);
} }
......
GEN_CODE = ostream_s.c file_ostream_s.c GEN_CODE = ostream.c file_ostream.c
# actual automake variables # actual automake variables
...@@ -19,26 +19,27 @@ strtest_LDADD = libgcgexample.a -lgtk -lgdk -lgmodule -lglib ...@@ -19,26 +19,27 @@ strtest_LDADD = libgcgexample.a -lgtk -lgdk -lgmodule -lglib
GCG = ../gcg GCG = ../gcg
SED = sed SED = sed
MAKEDEPEND = sh -c '$(CC) -M -x c $$* | $(SED) -e "s/.gc.o/_s.c/g"' makedepend MAKEDEPEND = ../gcgmakedepend
# dependencies and other rules for the def files # dependencies and other rules for the def files
GCG_DEFS = $(subst _s.c,.gc,$(GEN_CODE)) GCG_DEFS = $(subst .c,.gc,$(GEN_CODE))
# automake uses .P for .c files, we use .d for .gc files, should # automake uses .P for .c files, we use .d for .gc files, should
# be no conflict.. # be no conflict..
DEF_DEPS = $(patsubst %.gc,.deps/%.d,$(GCG_DEFS)) DEF_DEPS = $(patsubst %.gc,.deps/%.d,$(GCG_DEFS))
GEN_HEADER = $(subst .gc,_t.h,$(GCG_DEFS)) \ GEN_HEADER =$(subst .gc,.t.h,$(GCG_DEFS)) \
$(subst .gc,_p.h,$(GCG_DEFS)) \ $(subst .gc,.p.h,$(GCG_DEFS)) \
$(subst .gc,.h,$(GCG_DEFS)) $(subst .gc,.i.h,$(GCG_DEFS)) \
$(subst .gc,.h,$(GCG_DEFS))
# gcg include path # gcg include path
DEF_INC = -I . -I ../gh DEF_INC = -I ../gh
$(GEN_CODE): %_s.c: %.gc $(GEN_CODE): %.c: %.gc
$(GCG) -o $@ $(DEF_INC) $< $(GCG) -o $@ $(DEF_INC) $<
$(DEF_DEPS): .deps/%.d: %.gc $(DEF_DEPS): .deps/%.d: %.gc
......
#include <stdio.h> #include <stdio.h>
static void ex_file_ostream_init_real(ExFileOstream* str){ #define FILE_OSTREAM_INIT fo_init
static void fo_init(ExFileOstream* str){
str->file = NULL; str->file = NULL;
} }
static void put_char(ExOstream* s, gchar c){ static void fo_putchar(ExOstream* s, gchar c){
ExFileOstream* str = EX_FILE_OSTREAM(s); ExFileOstream* str = EX_FILE_OSTREAM(s);
fputc(c, str->file); fputc(c, str->file);
} }
static void close(ExOstream* s){ static void fo_close(ExOstream* s){
ExFileOstream* str = EX_FILE_OSTREAM(s); ExFileOstream* str = EX_FILE_OSTREAM(s);
fclose(str->file); fclose(str->file);
str->file = NULL; str->file = NULL;
} }
static void ex_file_ostream_class_init_real(ExFileOstreamClass* klass){ #define FILE_OSTREAM_CLASS_INIT fo_cinit
((ExOstreamClass*)klass)->putchar = put_char;
((ExOstreamClass*)klass)->close = close; static void fo_cinit(ExFileOstreamClass* klass){
((ExOstreamClass*)klass)->putchar = fo_putchar;
((ExOstreamClass*)klass)->close = fo_close;
} }
static ExFileOstream* file_ostream_open_real(gchar* filename){
#define FILE_OSTREAM_OPEN fo_open
static ExFileOstream* fo_open(gchar* filename){
ExFileOstream* str; ExFileOstream* str;
FILE* f = fopen(filename, "w+"); FILE* f = fopen(filename, "w+");
if(!f) if(!f)
...@@ -29,3 +36,5 @@ static ExFileOstream* file_ostream_open_real(gchar* filename){ ...@@ -29,3 +36,5 @@ static ExFileOstream* file_ostream_open_real(gchar* filename){
str->file = f; str->file = f;
return str; return str;
} }
...@@ -6,11 +6,8 @@ static void putstring(ExOstream* str, gchar* string){ ...@@ -6,11 +6,8 @@ static void putstring(ExOstream* str, gchar* string){
ex_ostream_putchar(str, string[i]); ex_ostream_putchar(str, string[i]);
} }
#define OSTREAM_CLASS_INIT ostream_class_init
static void ex_ostream_init_real(ExOstream* str){ static void ostream_class_init(ExOstreamClass* klass){
}
static void ex_ostream_class_init_real(ExOstreamClass* klass){
klass->putstring = putstring; klass->putstring = putstring;
} }
...@@ -11,9 +11,8 @@ ...@@ -11,9 +11,8 @@
#define CPP "cpp" #define CPP "cpp"
#endif #endif
Id header_root = ".."; Id header_root = NULL;
Id source_name = NULL; Id source_name = NULL;
Id impl_name = NULL;
gboolean collect_marshall = FALSE; gboolean collect_marshall = FALSE;
...@@ -32,9 +31,6 @@ void get_options(int argc, char* argv[]){ ...@@ -32,9 +31,6 @@ void get_options(int argc, char* argv[]){
g_string_append(cpp_cmd, " -I "); g_string_append(cpp_cmd, " -I ");
g_string_append(cpp_cmd, optarg); g_string_append(cpp_cmd, optarg);
break; break;
case 'i':
impl_name=optarg;
break;
case 'd': case 'd':
if(!yydebug) if(!yydebug)
yydebug = TRUE; yydebug = TRUE;
...@@ -109,29 +105,37 @@ int main(int argc, char* argv[]){ ...@@ -109,29 +105,37 @@ int main(int argc, char* argv[]){
g_assert(yyin); g_assert(yyin);
yyparse(); yyparse();
if(!impl_name)
impl_name = p_to_str(p_fmt("~.c",
p_c_ident(current_module->name)),
NULL);
if(!source_name) if(!source_name)
source_name = p_to_str(p_fmt("~_s.c", source_name = p_to_str(p_fmt("~.c",
p_c_ident(current_module->name)), p_c_ident(current_module->name)),
NULL); NULL);
if(!header_root)
if(!current_module->package->headerbase
|| current_module->package->headerbase[0])
header_root = "..";
else
header_root = ".";
foreach_def(output_cb, out); foreach_def(output_cb, out);
f=fopen(source_name, "w+"); f=fopen(source_name, "w+");
if(!f) if(!f)
g_error("Unable to open file %s: %s", g_error("Unable to open file %s: %s",
source_name, strerror(errno)); source_name, strerror(errno));
p_write(p_fmt("~~~~~" p_write(p_fmt("~~~~"
"#include \"~\"\n", "#ifdef GCG_IMPL\n"
"#\tinclude GCG_IMPL\n"
"#else\n"
"#\tinclude \"~\"\n"
"#endif\n"
"~",
p_col("source_prot_depends", p_prot_include), p_col("source_prot_depends", p_prot_include),
p_col("source_head", NULL), p_col("source_head", NULL),
p_col("source_sigtypes", p_sigdemarsh_decl), p_col("source_sigtypes", p_sigdemarsh_decl),
p_col("source", NULL),
p_col("source_sigtypes", p_demarshaller), p_col("source_sigtypes", p_demarshaller),
p_str(impl_name)), p_fmt("~.i.c",
p_c_ident(current_module->name)),
p_col("source", NULL)),
f, out); f, out);
fclose(f); fclose(f);
......
#!/bin/sh
gcc -M -I . -x c $* | sed -e "s/.gc.o/.c/g"
package Gtk{ package Gtk{
module <gtk/gtksignal.h>{ module <gtksignal.h>{
class Object; class Object;
} }
} }
......
package g { package g <> {
module <glib.h> { module <glib.h> {
integer int; integer int;
integer uint; integer uint;
...@@ -8,7 +8,7 @@ package g { ...@@ -8,7 +8,7 @@ package g {
} }
} }
package G { package G <> {
module <glib.h> { module <glib.h> {
boxed List; boxed List;
boxed SList; boxed SList;
......
package Gtk {
module <gtkwidget.h> {
class Widget;
}
module <gtkdialog.h> {
class Dialog;
}
module <gtkoptionmenu.h>{
class OptionMenu;
}
module <gtkpreview.h>{
class Preview;
}
module <gtkentry.h>{
class Entry;
}
}
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
ident [A-Za-z][A-Za-z0-9-]* ident [A-Za-z][A-Za-z0-9-]*
header <[[:alnum:]/.]+> header <[[:alnum:]_/.]*>
ws [ \n\t\r] ws [ \n\t\r]
comment \/\/[^\n]*\n comment \/\/[^\n]*\n
string \"(([^\"]*)|\\\"|\\\\)*\" string \"(([^\"]*)|\\\"|\\\\)*\"
......
...@@ -244,17 +244,20 @@ PNode* p_arg_marsh(gpointer p, gpointer d){ ...@@ -244,17 +244,20 @@ PNode* p_arg_marsh(gpointer p, gpointer d){
PNode* p_sig_marshalling(Method* m){ PNode* p_sig_marshalling(Method* m){
gint idx=-1; gint idx=-1;
gboolean ret=marshalling_type(&m->ret_type)!=MARSHALL_VOID; gint nargs = g_slist_length(m->params);
gboolean ret = marshalling_type(&m->ret_type)!=MARSHALL_VOID;
return p_fmt("\t{\n" return p_fmt("\t{\n"
"\tGtkArg args[~];\n"
"~" "~"
"~" "~"
"~" "~"
"\tgtk_signal_emitv((GtkObject*)~, ~, args);\n" "~"
"\tgtk_signal_emitv((GtkObject*)~, ~, ~);\n"
"~" "~"
"\t}\n", "\t}\n",
p_prf("%d", nargs > 0
g_slist_length(m->params)+ret), ? p_fmt("\tGtkArg args[~];\n",
p_prf("%d", nargs+ret))
: p_nil,
ret ret
?p_fmt("\t~ retval;\n", ?p_fmt("\t~ retval;\n",
p_type(&m->ret_type)) p_type(&m->ret_type))
...@@ -263,10 +266,13 @@ PNode* p_sig_marshalling(Method* m){ ...@@ -263,10 +266,13 @@ PNode* p_sig_marshalling(Method* m){
ret ret
/* cannot use retloc here, ansi forbids casted lvalues */ /* cannot use retloc here, ansi forbids casted lvalues */
?p_fmt("\tGTK_VALUE_POINTER(args[~]) = &retval;\n", ?p_fmt("\tGTK_VALUE_POINTER(args[~]) = &retval;\n",
p_prf("%d", g_slist_length(m->params))) p_prf("%d", nargs))
:p_nil, :p_nil,
p_c_ident(DEF(MEMBER(m)->my_class)->type->name), p_c_ident(DEF(MEMBER(m)->my_class)->type->name),
p_signal_id(m), p_signal_id(m),
nargs > 0
? p_str("args")
: p_str("NULL"),
ret ret
?p_str("\treturn retval;\n") ?p_str("\treturn retval;\n")
:p_nil); :p_nil);
......
...@@ -35,58 +35,53 @@ PNode* p_c_macro(Id id){ ...@@ -35,58 +35,53 @@ PNode* p_c_macro(Id id){
return n; return n;
} }
PNode* p_param(FunParams* p, ParamOptions* opt){ PNode* p_param(FunParams* p, ParamOptions* o){
return p_fmt("~~~~~~", return p_fmt("~~~~~~",
opt->first ? p_nil : p_str(","), o->first ? p_nil : p_str(","),
!opt->first && !opt->types ? p_str(" ") : p_nil, !o->first && !(o->types && o->names) ? p_str(" ") : p_nil,
opt->types ? p_str("\n\t") : p_nil, (o->types && o->names) ? p_str("\n\t") : p_nil,
opt->types ? p_type(&p->type) : p_nil, o->types ? p_type(&p->type) : p_nil,
opt->types && opt->names ? p_str(" ") : p_nil, o->types && o->names ? p_str(" ") : p_nil,
opt->names ? p->name : p_nil); o->names ? p->name : p_nil);
}
PNode* p_header(Module* m, Id suffix){
Id base = m->package->headerbase;
Id hdr = m->header;
Id name = m->package->name;
return p_fmt("~~",
base
? (base[0]
? p_fmt("~/", p_str(base))
: p_nil)
: ((name && name[0])
? p_fmt("~/", p_c_ident(name))
: p_nil),
hdr
? p_str(hdr)
: p_fmt("~~",
p_c_ident(m->name),
p_str(suffix)));
} }
PNode* p_prot_header(Module* m){ PNode* p_prot_header(Module* m){
if(m->header) return p_header(m, ".p.h");
return p_str(m->header);
else
return p_fmt("~/~_p.h",
m->package->headerbase
? p_str(m->package->headerbase)
: p_c_ident(m->package->name),
p_c_ident(m->name));
} }
PNode* p_type_header(Module* m){ PNode* p_type_header(Module* m){
if(m->header) return p_header(m, ".t.h");
return p_str(m->header);
else
return p_fmt("~/~_t.h",
m->package->headerbase
? p_str(m->package->headerbase)
: p_c_ident(m->package->name),
p_c_ident(m->name));
} }
PNode* p_func_header(Module* m){ PNode* p_func_header(Module* m){
if(m->header) return p_header(m, ".h");
return p_str(m->header);
else
return p_fmt("~/~.h",
m->package->headerbase
? p_str(m->package->headerbase)
: p_c_ident(m->package->name),
p_c_ident(m->name));
} }
PNode* p_import_header(Module* m){ PNode* p_import_header(Module* m){
if(m->header) if(m->header)
return p_nil; return p_nil;
else else
return p_fmt("~/~_i.h", return p_header(m, ".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){ PNode* p_type_include(Module* m){
......
...@@ -147,6 +147,7 @@ void output_method(PRoot* out, Method* m){ ...@@ -147,6 +147,7 @@ void output_method(PRoot* out, Method* m){
ParamOptions o={TRUE, TRUE, FALSE}; ParamOptions o={TRUE, TRUE, FALSE};
FunParams* par; FunParams* par;
PNode* dispatch; PNode* dispatch;
GSList* params;
if(k == METH_STATIC) if(k == METH_STATIC)
par = fparams("p", m->params); par = fparams("p", m->params);
...@@ -210,24 +211,32 @@ void output_method(PRoot* out, Method* m){ ...@@ -210,24 +211,32 @@ void output_method(PRoot* out, Method* m){
dispatch=p_sig_marshalling(m); dispatch=p_sig_marshalling(m);
break; break;
case METH_STATIC: case METH_STATIC:
case METH_DIRECT: case METH_DIRECT:{
PNode* impl_name;
o.names=TRUE; o.names=TRUE;
o.types=TRUE;
pr_put(out, "source_head",
p_fmt("static ~ ~_~_real (~);\n",
p_type(&m->ret_type),
p_c_ident(t->name),
name,
p_params(par, &o)));
o.types=FALSE; o.types=FALSE;
dispatch=p_fmt("\t~~_~_real (~);\n",
m->ret_type.prim? impl_name=p_fmt("~_~",
p_str("return "): p_c_macro(t->name),
p_nil, p_c_macro(MEMBER(m)->name));
p_c_ident(t->name),
name, dispatch=p_fmt("#ifdef ~\n"
p_params(par, &o)); "\t~~ (~);\n"
"#else\n"
"\tg_error(\"Not implemented: ~.~.~\");\n"
"#endif\n",
impl_name,
m->ret_type.prim
? p_str("return ")
: p_nil,
impl_name,
p_params(par, &o),
p_str(t->module->package->name),
p_str(t->name),
p_str(MEMBER(m)->name));
break; break;
}
case METH_VIRTUAL: case METH_VIRTUAL:
dispatch=p_fmt("\t~((~*)((GtkObject*) ~)->klass)->~ (~);\n", dispatch=p_fmt("\t~((~*)((GtkObject*) ~)->klass)->~ (~);\n",
m->ret_type.prim? m->ret_type.prim?
...@@ -249,6 +258,14 @@ void output_method(PRoot* out, Method* m){ ...@@ -249,6 +258,14 @@ void output_method(PRoot* out, Method* m){
dispatch); dispatch);
output_var_import(out, t, name); output_var_import(out, t, name);
for(params = m->params; params; params = params->next)
pr_put(out,
m->prot==METH_PUBLIC?"func_depends":"prot_depends",
((Param*)(params->data))->type.prim->module);
fparams_free(par); fparams_free(par);
} }
...@@ -392,43 +409,44 @@ void output_object_type_init(PRoot* out, ObjectDef* o){ ...@@ -392,43 +409,44 @@ void output_object_type_init(PRoot* out, ObjectDef* o){
void output_object_init(PRoot* out, ObjectDef* o){ void output_object_init(PRoot* out, ObjectDef* o){
pr_put(out, "source_head", PrimType* t = DEF(o)->type;
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)));
output_func(out, NULL, output_func(out, NULL,
NULL, NULL,
p_varname(DEF(o)->type, p_str("init")), p_varname(t, p_str("init")),
p_fmt("~ ~", p_fmt("~ ~",
p_type(&o->self_type[FALSE]), p_type(&o->self_type[FALSE]),
p_c_ident(DEF(o)->type->name)), p_c_ident(t->name)),
NULL, NULL,
p_fmt("\t~ (~);\n", p_fmt("\t(void) ~;\n"
p_varname(DEF(o)->type, p_str("init_real")), "#ifdef ~_INIT\n"
p_c_ident(DEF(o)->type->name))); "\t~_INIT (~);\n"
"#endif\n",
p_c_ident(t->name),
p_c_macro(t->name),
p_c_macro(t->name),
p_c_ident(t->name)));
} }
void output_class_init(PRoot* out, ObjectDef* o){ void output_class_init(PRoot* out, ObjectDef* o){
pr_put(out, "source_head", PrimType* t = DEF(o)->type;
p_fmt("static void ~ (~* klass);\n",
p_varname(DEF(o)->type, p_str("class_init_real")),
p_class_name(DEF(o)->type)));
output_func(out, NULL, output_func(out, NULL,
NULL, NULL,
p_varname(DEF(o)->type, p_str("class_init")), p_varname(t, p_str("class_init")),
p_fmt("~* klass", p_fmt("~* klass",
p_class_name(DEF(o)->type)), p_class_name(t)),
NULL, NULL,
p_fmt("\tGtkObjectClass* obklass = " p_fmt("\tGtkObjectClass* obklass = "
"(GtkObjectClass*) klass;\n" "(GtkObjectClass*) klass;\n"
"~" "~"
"\t(void) obklass;\n" "\t(void) obklass;\n"
"~" "~"
"\t~ (klass);\n", "#ifdef ~_CLASS_INIT\n"
"\t~_CLASS_INIT (klass);\n"
"#endif\n",