Commit 6bc0ad42 authored by Lauri Alanko's avatar Lauri Alanko

Enhanced the method generation a bit.

parent e5728105
1998-10-22 Lauri Alanko <la@iki.fi>
* A bit more method generation
1998-10-21 Lauri Alanko <la@iki.fi>
* Added vfunc wrappers and accessors
......
......@@ -18,12 +18,15 @@ Id type_hdr_name;
Id prot_hdr_name;
Id source_name;
Id impl_name;
extern int yydebug;
extern FILE* yyin;
extern int yyparse(void);
void get_options(int argc, char* argv[]){
gint x=0;
do{
x=getopt(argc, argv, "f:t:p:s:i:");
x=getopt(argc, argv, "f:t:p:s:i:d");
switch(x){
case 'f':
func_hdr_name=optarg;
......@@ -40,6 +43,9 @@ void get_options(int argc, char* argv[]){
case 'i':
impl_name=optarg;
break;
case 'd':
yydebug=1;
break;
case '?':
case ':':
g_error("Bad option %c!\n", x);
......@@ -63,8 +69,6 @@ void output_type(TypeName* t, Def* def, gpointer foo){
}
int main(int argc, char* argv[]){
extern int yydebug;
extern FILE* yyin;
/* target=stdout;*/
decl_hash=g_hash_table_new(type_name_hash, type_name_cmp);
......
......@@ -14,24 +14,43 @@ module Gtk {
};
module Gimp{
header <gimp/gimpobject.h> {
header <gimpobject.h> {
class Object;
};
header <gimp/gimpimage.h> {
header <gimplayer.h> {
class Layer;
};
header <gimpdrawable.h> {
class Drawable;
};
header <gimpimage.h> {
class Image;
type ImageType;
type Thingy;
type ChannelType;
type BaseType;
};
enum ImageType{
rgb, gray, indexed, rgb-alpha };
flags Thingy{
foo, bar, baz, quux
};
class Image : Gimp.Object{
read-write g.int x;
read-only g.int y;
public abstract g.int foo(g.int bar);
abstract g.int name;
public abstract g.int baz(Object* o, Image*& i) const;
rgb, rgba, gray, graya, indexed, indexeda
};
enum ChannelType{
red, green, blue, gray, indexed, auxillary
};
enum BaseType{
rgb, gray, indexed
};
class Image : Object{
read-only g.int width;
read-only g.int height;
g.int num-cols;
read-only BaseType base-type;
Layer* active-layer;
Layer* floating-sel;
public static Image* new(g.int width,
g.int height,
BaseType base-type);
};
};
......@@ -3,11 +3,11 @@
#include <stdarg.h>
void pr_param(File* s, Param* p, ParamOptions* opt){
pr(s, "%?s%?1%?s%?s",
pr(s, "%?s%?1%?s%?1",
!(*opt & PARAMS_FIRST), ", ",
!!(*opt & PARAMS_TYPES), pr_type, &p->type,
(*opt & PARAMS_TYPES) && (*opt & PARAMS_NAMES), " ",
!!(*opt & PARAMS_NAMES), p->name);
!!(*opt & PARAMS_NAMES), pr_low, p->name);
}
void pr_params(File* s, GSList* args, ParamOptions* opt){
......@@ -74,30 +74,21 @@ void pr_prototype(File* s, PrimType* type, Id funcname,
pr_params, params, &o);
}
void pr_gtype(File* s, Type* t){
if((t->indirection==0 && t->prim->kind==TYPE_TRANSPARENT)
|| (t->indirection==1 && t->prim->kind==TYPE_CLASS))
pr_macro_name(s, t->prim, "TYPE", NULL);
else if(t->indirection)
pr(s, "GTK_TYPE_POINTER");
else
g_error("Illegal non-pointer type %s%s\n",
t->prim->name.module,
t->prim->name.type);
}
void pr_type_guard(File* s, Param* p){
Type* t=&p->type;
if(t->indirection && t->notnull)
pr(s, "\tg_assert (%s);\n", p->name);
if(t->indirection==1 && t->prim->kind == TYPE_CLASS)
/* A direct object pointer is checked for its type */
pr(s, "\tg_assert(%?2%3(%s));\n",
!t->notnull, pr, "!%s || ", p->name,
pr_macro_name, t->prim, "IS", NULL,
p->name);
else if(t->indirection && t->notnull)
/* Other pointers are just possibly checked for nullness */
pr(s, "\tg_assert(%s);\n",
p->name);
if(t->notnull)
pr(s, "\tg_assert (%3(%s));\n",
pr_macro_name, t->prim, "IS", NULL,
p->name);
else
pr(s, "\tg_assert (!%s || %3(%s));\n",
p->name,
pr_macro_name, t->prim, "IS", NULL,
p->name);
/* todo (low priority): range checks for enums */
}
......@@ -125,7 +116,7 @@ void output_func(PrimType* type, Id funcname, GSList* params, Type* rettype,
"%?s%5{\n"
"%3"
"%v"
"}\n",
"}\n\n",
!hdr, "static ",
pr_prototype, type, funcname, params, rettype, internal,
pr_list_foreach, params, pr_type_guard, no_data,
......
......@@ -59,9 +59,13 @@ void pr_class_body(File* s, ObjectDef* c);
void pr_class_decl(File* s, ObjectDef* c);
void pr_prototype(File* s, PrimType* type, Id funcname,
GSList* params, Type* rettype, gboolean internal);
void output_func(PrimType* type, Id funcname, GSList* params, Type* rettype,
File* hdr, ObjectDef* self, gboolean self_const,
gboolean internal, const gchar* body, ...);
void output_var(Def* d, Type* t, Id varname, File* hdr, gboolean internal);
void pr_func(ObjectDef* self, Id funcname, GSList* params, Type* rettype,
VarProt prot, gboolean with_self, const gchar* body, ...);
void output_def(Def* d);
void pr_macro_name(File* s, PrimType* t, Id mid, Id post);
void pr_class_macros(File* s, ObjectDef* c );
......
......@@ -83,7 +83,7 @@ void write_dep(gpointer key, gpointer value, gpointer user_data){
void file_flush(File* f){
File* root;
File* old;
static const gint bufsize=1024;
static const size_t bufsize=1024;
FILE* real;
guint8 buf[bufsize];
size_t i;
......
......@@ -7,12 +7,17 @@ void pr_enum_member(File* s, Id id, PrimType* t){
}
void pr_enum_decl(File* s, EnumDef* e){
PrimType* t=DEF(e)->type;
pr(s,
"typedef enum {\n"
"%3"
"} %1;\n",
pr_list_foreach, e->alternatives, pr_enum_member, DEF(e)->type,
pr_primtype, DEF(e)->type);
"} %1;\n"
"const %1 %3 = %3;\n",
pr_list_foreach, e->alternatives, pr_enum_member, t,
pr_primtype, t,
pr_primtype, t,
pr_macro_name, t, NULL, "LAST",
pr_macro_name, t, NULL, g_slist_last(e->alternatives)->data);
}
void pr_enum_value(File* s, Id i, PrimType* t){
......
......@@ -21,9 +21,13 @@ void pr_flags_decl(File* s, FlagsDef* e){
pr(s,
"typedef enum {\n"
"%3"
"} %1;\n",
"} %1;\n"
"const %1 %3 = %3;\n",
pr_list_foreach, e->flags, pr_flags_member, &d,
pr_primtype, d.t);
pr_primtype, d.t,
pr_primtype, d.t,
pr_macro_name, d.t, NULL, "LAST",
pr_macro_name, d.t, NULL, g_slist_last(e->flags)->data);
}
void pr_flags_value(File* s, Id i, PrimType* t){
......
......@@ -54,9 +54,6 @@ void pr_class_member(File* s, Member* m){
}
}
void pr_class_name(File* s, PrimType* o){
pr(s, "%1Class",
pr_primtype, o);
......@@ -86,23 +83,35 @@ void pr_class_decl(File* s, ObjectDef* o){
pr_class_name, DEF(o)->type);
}
void output_abstract_method(Method* m){
void pr_abstract_member(File* s, PrimType* t, Id name){
pr(s, "%3(GTK_OBJECT(self)->klass)->%s",
pr_macro_name, t, NULL, "CLASS",
name);
}
void pr_real_varname(File* s, PrimType* t, Id name){
pr(s, "%2_real",
pr_varname, t, name);
}
void output_method(Method* m){
PrimType* t=DEF(MEMBER(m)->my_class)->type;
Id name=MEMBER(m)->name;
ParamOptions o=PARAMS_NAMES;
MemberKind k=MEMBER(m)->kind;
ParamOptions o=PARAMS_NAMES | ((k==KIND_STATIC)?PARAMS_FIRST : 0);
output_func
(t,
name,
m->params,
&m->ret_type,
m->prot==METH_PUBLIC?func_hdr:prot_hdr,
MEMBER(m)->my_class,
k==KIND_STATIC?NULL:MEMBER(m)->my_class,
m->self_const,
FALSE,
"\t%?s%3(GTK_OBJECT(self)->klass)->%s(self%2);\n",
"\t%?s%2(%?s%2);\n",
!!m->ret_type.prim, "return ",
pr_macro_name, t, NULL, "CLASS",
name,
(k==KIND_ABSTRACT?pr_abstract_member:pr_real_varname), t, name,
MEMBER(m)->kind!=KIND_STATIC, "self",
pr_params, m->params, &o);
}
......@@ -115,7 +124,7 @@ void output_data_member(DataMember* m){
Param p;
GSList l;
p.type=m->type;
p.name="value";
p.name=name;
l.data=&p;
l.next=NULL;
output_func(t,
......@@ -126,7 +135,8 @@ void output_data_member(DataMember* m){
MEMBER(m)->my_class,
FALSE,
FALSE,
"\tself->%s=value;\n",
"\tself->%s = 1%s;\n",
name,
name);
g_free(set_name);
}
......@@ -149,8 +159,7 @@ void output_data_member(DataMember* m){
void output_member(Member* m, gpointer dummy){
switch(m->membertype){
case MEMBER_METHOD:
if(m->kind==KIND_ABSTRACT)
output_abstract_method((Method*)m);
output_method((Method*)m);
break;
case MEMBER_DATA:
if(m->kind==KIND_DIRECT)
......@@ -207,7 +216,17 @@ void output_object(ObjectDef* o){
g_slist_foreach(o->members, output_member, NULL);
}
void pr_gtype(File* s, Type* t){
if((t->indirection==0 && t->prim->kind==TYPE_TRANSPARENT)
|| (t->indirection==1 && t->prim->kind==TYPE_CLASS))
pr_macro_name(s, t->prim, "TYPE", NULL);
else if(t->indirection)
pr(s, "GTK_TYPE_POINTER");
else
g_error("Illegal non-pointer type %s%s\n",
t->prim->name.module,
t->prim->name.type);
}
DefClass object_class={
output_object
......
......@@ -3,6 +3,11 @@
void output_def(Def* d){
TypeName* t=&d->type->name;
/* GTK_TYPE_FOO macro */
pr(type_hdr, "\n\n");
pr(source, "\n");
pr(prot_hdr, "\n\n");
pr(source_head, "\n");
pr(type_hdr,
"#define %3 \\\n"
" (%2 ? %2 : %2())\n",
......
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