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>
* fixed up ex for latest glib/gtk+
......
......@@ -42,7 +42,7 @@ Module* get_mod(Package* pkg, Id modname){
}
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);
}
......
GEN_CODE = ostream_s.c file_ostream_s.c
GEN_CODE = ostream.c file_ostream.c
# actual automake variables
......@@ -19,26 +19,27 @@ strtest_LDADD = libgcgexample.a -lgtk -lgdk -lgmodule -lglib
GCG = ../gcg
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
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
# be no conflict..
DEF_DEPS = $(patsubst %.gc,.deps/%.d,$(GCG_DEFS))
GEN_HEADER = $(subst .gc,_t.h,$(GCG_DEFS)) \
$(subst .gc,_p.h,$(GCG_DEFS)) \
$(subst .gc,.h,$(GCG_DEFS))
GEN_HEADER =$(subst .gc,.t.h,$(GCG_DEFS)) \
$(subst .gc,.p.h,$(GCG_DEFS)) \
$(subst .gc,.i.h,$(GCG_DEFS)) \
$(subst .gc,.h,$(GCG_DEFS))
# 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) $<
$(DEF_DEPS): .deps/%.d: %.gc
......
#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;
}
static void put_char(ExOstream* s, gchar c){
static void fo_putchar(ExOstream* s, gchar c){
ExFileOstream* str = EX_FILE_OSTREAM(s);
fputc(c, str->file);
}
static void close(ExOstream* s){
static void fo_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;
#define FILE_OSTREAM_CLASS_INIT fo_cinit
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;
FILE* f = fopen(filename, "w+");
if(!f)
......@@ -29,3 +36,5 @@ static ExFileOstream* file_ostream_open_real(gchar* filename){
str->file = f;
return str;
}
......@@ -6,11 +6,8 @@ static void putstring(ExOstream* str, gchar* string){
ex_ostream_putchar(str, string[i]);
}
static void ex_ostream_init_real(ExOstream* str){
}
static void ex_ostream_class_init_real(ExOstreamClass* klass){
#define OSTREAM_CLASS_INIT ostream_class_init
static void ostream_class_init(ExOstreamClass* klass){
klass->putstring = putstring;
}
......@@ -11,9 +11,8 @@
#define CPP "cpp"
#endif
Id header_root = "..";
Id header_root = NULL;
Id source_name = NULL;
Id impl_name = NULL;
gboolean collect_marshall = FALSE;
......@@ -32,9 +31,6 @@ void get_options(int argc, char* argv[]){
g_string_append(cpp_cmd, " -I ");
g_string_append(cpp_cmd, optarg);
break;
case 'i':
impl_name=optarg;
break;
case 'd':
if(!yydebug)
yydebug = TRUE;
......@@ -109,29 +105,37 @@ int main(int argc, char* argv[]){
g_assert(yyin);
yyparse();
if(!impl_name)
impl_name = p_to_str(p_fmt("~.c",
p_c_ident(current_module->name)),
NULL);
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)),
NULL);
if(!header_root)
if(!current_module->package->headerbase
|| current_module->package->headerbase[0])
header_root = "..";
else
header_root = ".";
foreach_def(output_cb, out);
f=fopen(source_name, "w+");
if(!f)
g_error("Unable to open file %s: %s",
source_name, strerror(errno));
p_write(p_fmt("~~~~~"
"#include \"~\"\n",
p_write(p_fmt("~~~~"
"#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_head", NULL),
p_col("source_sigtypes", p_sigdemarsh_decl),
p_col("source", NULL),
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);
fclose(f);
......
#!/bin/sh
gcc -M -I . -x c $* | sed -e "s/.gc.o/.c/g"
package Gtk{
module <gtk/gtksignal.h>{
module <gtksignal.h>{
class Object;
}
}
......
package g {
package g <> {
module <glib.h> {
integer int;
integer uint;
......@@ -8,7 +8,7 @@ package g {
}
}
package G {
package G <> {
module <glib.h> {
boxed List;
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 @@
ident [A-Za-z][A-Za-z0-9-]*
header <[[:alnum:]/.]+>
header <[[:alnum:]_/.]*>
ws [ \n\t\r]
comment \/\/[^\n]*\n
string \"(([^\"]*)|\\\"|\\\\)*\"
......
......@@ -244,17 +244,20 @@ PNode* p_arg_marsh(gpointer p, gpointer d){
PNode* p_sig_marshalling(Method* m){
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"
"\tGtkArg args[~];\n"
"~"
"~"
"~"
"\tgtk_signal_emitv((GtkObject*)~, ~, args);\n"
"~"
"\tgtk_signal_emitv((GtkObject*)~, ~, ~);\n"
"~"
"\t}\n",
p_prf("%d",
g_slist_length(m->params)+ret),
nargs > 0
? p_fmt("\tGtkArg args[~];\n",
p_prf("%d", nargs+ret))
: p_nil,
ret
?p_fmt("\t~ retval;\n",
p_type(&m->ret_type))
......@@ -263,10 +266,13 @@ PNode* p_sig_marshalling(Method* m){
ret
/* cannot use retloc here, ansi forbids casted lvalues */
?p_fmt("\tGTK_VALUE_POINTER(args[~]) = &retval;\n",
p_prf("%d", g_slist_length(m->params)))
p_prf("%d", nargs))
:p_nil,
p_c_ident(DEF(MEMBER(m)->my_class)->type->name),
p_signal_id(m),
nargs > 0
? p_str("args")
: p_str("NULL"),
ret
?p_str("\treturn retval;\n")
:p_nil);
......
......@@ -35,58 +35,53 @@ PNode* p_c_macro(Id id){
return n;
}
PNode* p_param(FunParams* p, ParamOptions* opt){
PNode* p_param(FunParams* p, ParamOptions* o){
return p_fmt("~~~~~~",
opt->first ? p_nil : p_str(","),
!opt->first && !opt->types ? p_str(" ") : p_nil,
opt->types ? p_str("\n\t") : p_nil,
opt->types ? p_type(&p->type) : p_nil,
opt->types && opt->names ? p_str(" ") : p_nil,
opt->names ? p->name : p_nil);
o->first ? p_nil : p_str(","),
!o->first && !(o->types && o->names) ? p_str(" ") : p_nil,
(o->types && o->names) ? p_str("\n\t") : p_nil,
o->types ? p_type(&p->type) : p_nil,
o->types && o->names ? p_str(" ") : 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){
if(m->header)
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));
return p_header(m, ".p.h");
}
PNode* p_type_header(Module* m){
if(m->header)
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));
return p_header(m, ".t.h");
}
PNode* p_func_header(Module* m){
if(m->header)
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));
return p_header(m, ".h");
}
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));
return p_header(m, ".i.h");
}
PNode* p_type_include(Module* m){
......
......@@ -147,6 +147,7 @@ void output_method(PRoot* out, Method* m){
ParamOptions o={TRUE, TRUE, FALSE};
FunParams* par;
PNode* dispatch;
GSList* params;
if(k == METH_STATIC)
par = fparams("p", m->params);
......@@ -210,24 +211,32 @@ void output_method(PRoot* out, Method* m){
dispatch=p_sig_marshalling(m);
break;
case METH_STATIC:
case METH_DIRECT:
case METH_DIRECT:{
PNode* impl_name;
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;
dispatch=p_fmt("\t~~_~_real (~);\n",
m->ret_type.prim?
p_str("return "):
p_nil,
p_c_ident(t->name),
name,
p_params(par, &o));
impl_name=p_fmt("~_~",
p_c_macro(t->name),
p_c_macro(MEMBER(m)->name));
dispatch=p_fmt("#ifdef ~\n"
"\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;
}
case METH_VIRTUAL:
dispatch=p_fmt("\t~((~*)((GtkObject*) ~)->klass)->~ (~);\n",
m->ret_type.prim?
......@@ -249,6 +258,14 @@ void output_method(PRoot* out, Method* m){
dispatch);
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);
}
......@@ -392,43 +409,44 @@ 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 void ~ (~ ~);\n",
p_varname(DEF(o)->type, p_str("init_real")),
p_type(&o->self_type[FALSE]),
p_c_ident(DEF(o)->type->name)));
PrimType* t = DEF(o)->type;
output_func(out, NULL,
NULL,
p_varname(DEF(o)->type, p_str("init")),
p_varname(t, p_str("init")),
p_fmt("~ ~",
p_type(&o->self_type[FALSE]),
p_c_ident(DEF(o)->type->name)),
p_c_ident(t->name)),
NULL,
p_fmt("\t~ (~);\n",
p_varname(DEF(o)->type, p_str("init_real")),
p_c_ident(DEF(o)->type->name)));
p_fmt("\t(void) ~;\n"
"#ifdef ~_INIT\n"
"\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){
pr_put(out, "source_head",
p_fmt("static void ~ (~* klass);\n",
p_varname(DEF(o)->type, p_str("class_init_real")),
p_class_name(DEF(o)->type)));
PrimType* t = DEF(o)->type;
output_func(out, NULL,
NULL,
p_varname(DEF(o)->type, p_str("class_init")),
p_varname(t, p_str("class_init")),
p_fmt("~* klass",
p_class_name(DEF(o)->type)),
p_class_name(t)),
NULL,
p_fmt("\tGtkObjectClass* obklass = "
"(GtkObjectClass*) klass;\n"
"~"
"\t(void) obklass;\n"
"~"
"\t~ (klass);\n",
"#ifdef ~_CLASS_INIT\n"
"\t~_CLASS_INIT (klass);\n"
"#endif\n",
p_col("class_init_head", NULL),
p_col("member_class_init", NULL),
p_varname(DEF(o)->type, p_str("class_init_real"))));
p_c_macro(t->name),
p_c_macro(t->name)));
}
void output_object(PRoot* out, Def* d){
......
......@@ -180,7 +180,7 @@ current_module_def: T_MODULE ident T_SCOPE ident T_END {
}
modulelist: /* empty */ | modulelist module;
modulelist: /* empty */ | modulelist simpledecl | modulelist module;
headerdef: /* empty */ {
$$ = NULL;
......@@ -203,7 +203,9 @@ module: T_MODULE maybeident headerdef T_OPEN_B {
put_mod(m);
}
current_module = m;
} decllist T_CLOSE_B;
} decllist T_CLOSE_B {
current_module = NULL;
};
decllist: /* empty */ | decllist decl;
......@@ -228,10 +230,21 @@ fundtype: T_INT {
};
simpledecl: fundtype ident T_END {
PrimType* t = g_new(PrimType, 1);
t->module = current_module;
if(current_module)
t->module = current_module;
else{
Module* m;
g_assert(!get_mod(current_package, $2));
m = g_new(Module, 1);
m->package = current_package;
m->name = $2;
m->header = NULL;
put_mod(m);
t->module = m;
}
t->name = $2;
t->kind = $1;
put_type(t);
......
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