[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/geas/src/classdef classdef.c classdef.h pa...
From: |
Reinhard Mueller |
Subject: |
gnue/geas/src/classdef classdef.c classdef.h pa... |
Date: |
Thu, 29 Nov 2001 15:56:56 -0500 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: Reinhard Mueller <address@hidden> 01/11/29 15:56:56
Modified files:
geas/src/classdef: classdef.c classdef.h parse.y
Log message:
Implemented basic method support.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/classdef/classdef.c.diff?tr1=1.25&tr2=1.26&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/classdef/classdef.h.diff?tr1=1.22&tr2=1.23&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/classdef/parse.y.diff?tr1=1.27&tr2=1.28&r1=text&r2=text
Patches:
Index: gnue/geas/src/classdef/classdef.c
diff -c gnue/geas/src/classdef/classdef.c:1.25
gnue/geas/src/classdef/classdef.c:1.26
*** gnue/geas/src/classdef/classdef.c:1.25 Sun Nov 25 16:11:22 2001
--- gnue/geas/src/classdef/classdef.c Thu Nov 29 15:56:56 2001
***************
*** 19,25 ****
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: classdef.c,v 1.25 2001/11/25 21:11:22 reinhard Exp $
*/
#include "config.h"
--- 19,25 ----
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: classdef.c,v 1.26 2001/11/29 20:56:56 reinhard Exp $
*/
#include "config.h"
***************
*** 53,58 ****
--- 53,59 ----
char *name_db; /* table name for database */
char *filename;
GList *fields;
+ GList *methods;
};
struct _geas_cd_type
***************
*** 65,70 ****
--- 66,72 ----
int format; /* only for char types */
geas_cd_class *otherclass; /* only for reference and list types
*/
GList *fields; /* only for compound types */
+ GList *methods; /* only for compound types */
};
struct _geas_cd_fieldlist
***************
*** 93,98 ****
--- 95,114 ----
int property;
};
+ struct _geas_cd_method
+ {
+ GList **parent; /* list containing this method */
+ geas_cd_module *module; /* module has defined this method */
+ char *name; /* without module */
+ char *name_full; /* with module */
+ geas_cd_type *type; /* type of result */
+ geas_cd_datatype datatype; /* plain datatype of result */
+ int format; /* format of result (for char) */
+ geas_cd_class *resultclass; /* only for reference or list result
*/
+ /* TODO: GList *arguments; the arguments */
+ int argcount;
+ };
+
/* =========================================================================
*\
* Global variables
\* =========================================================================
*/
***************
*** 741,746 ****
--- 757,818 ----
}
/* -------------------------------------------------------------------------
*\
+ * Allocate a new method as a member of a class, giving the type of the
+ * return value
+ \* -------------------------------------------------------------------------
*/
+ geas_cd_method *
+ geas_cd_class_method_new (geas_cd_class *c, geas_cd_module *module,
+ const char *name, geas_cd_type *type)
+ {
+ geas_cd_method *m;
+
+ g_return_val_if_fail (c, NULL);
+ g_return_val_if_fail (module, NULL);
+ g_return_val_if_fail (name, NULL);
+ g_return_val_if_fail (type, NULL);
+ g_return_val_if_fail (!geas_cd_class_find_method (c, module, name), NULL);
+
+ m = g_new0 (geas_cd_method, 1);
+ m->parent = &(c->methods);
+ m->module = module;
+ m->name = g_strdup (name);
+ m->type = type;
+ m->datatype = type->datatype;
+ m->format = type->format;
+ m->resultclass = type->otherclass;
+
+ c->methods = g_list_append (c->methods, m);
+
+ return (m);
+ }
+
+ /* -------------------------------------------------------------------------
*\
+ * Find an existing method in a class by name
+ \* -------------------------------------------------------------------------
*/
+ geas_cd_method *
+ geas_cd_class_find_method (const geas_cd_class *c, const geas_cd_module *m,
+ const char *name)
+ {
+ GList *l;
+
+ g_return_val_if_fail (c, NULL);
+ g_return_val_if_fail (m, NULL);
+ g_return_val_if_fail (name, NULL);
+
+ l = g_list_first (c->methods);
+ while (l)
+ {
+ if (!strcmp ((((geas_cd_method *)l->data)->name), name)
+ && (((geas_cd_method *)l->data)->module == m))
+ {
+ return ((geas_cd_method *)(l->data));
+ }
+ l = g_list_next (l);
+ }
+ return (NULL);
+ }
+
+ /* -------------------------------------------------------------------------
*\
* Free the memory allocated for a class
\* -------------------------------------------------------------------------
*/
static void
***************
*** 848,853 ****
--- 920,936 ----
}
/* -------------------------------------------------------------------------
*\
+ * Get the datatype of a type
+ \* -------------------------------------------------------------------------
*/
+ geas_cd_datatype
+ geas_cd_type_get_datatype (const geas_cd_type *t)
+ {
+ g_return_val_if_fail (t, GEAS_CD_DATATYPE_UNKNOWN);
+
+ return (t->datatype);
+ }
+
+ /* -------------------------------------------------------------------------
*\
* Get the format of a type (only for char types)
\* -------------------------------------------------------------------------
*/
int
***************
*** 940,946 ****
}
/* -------------------------------------------------------------------------
*\
! * Find an existing field in a class by name
\* -------------------------------------------------------------------------
*/
geas_cd_field *
geas_cd_type_find_field (const geas_cd_type *t, const char *name)
--- 1023,1029 ----
}
/* -------------------------------------------------------------------------
*\
! * Find an existing field in a type by name
\* -------------------------------------------------------------------------
*/
geas_cd_field *
geas_cd_type_find_field (const geas_cd_type *t, const char *name)
***************
*** 963,968 ****
--- 1046,1103 ----
}
/* -------------------------------------------------------------------------
*\
+ * Allocate a new method as a member of a type, giving the type of the
+ * return value
+ \* -------------------------------------------------------------------------
*/
+ geas_cd_method *
+ geas_cd_type_method_new (geas_cd_type *t, const char *name,
+ geas_cd_type *type)
+ {
+ geas_cd_method *m;
+
+ g_return_val_if_fail (t, NULL);
+ g_return_val_if_fail (name, NULL);
+ g_return_val_if_fail (type, NULL);
+ g_return_val_if_fail (!geas_cd_type_find_method (t, name), NULL);
+
+ m = g_new0 (geas_cd_method, 1);
+
+ m->parent = &(t->methods);
+ m->name = g_strdup (name);
+ m->type = type;
+ m->datatype = type->datatype;
+ m->format = type->format;
+ m->resultclass = type->otherclass;
+
+ t->methods = g_list_append (t->methods, m);
+
+ return (m);
+ }
+
+ /* -------------------------------------------------------------------------
*\
+ * Find an existing method in a type by name
+ \* -------------------------------------------------------------------------
*/
+ geas_cd_method *
+ geas_cd_type_find_method (const geas_cd_type *t, const char *name)
+ {
+ GList *l;
+
+ g_return_val_if_fail (t, NULL);
+ g_return_val_if_fail (name, NULL);
+
+ l = g_list_first (t->methods);
+ while (l)
+ {
+ if (!strcmp ((((geas_cd_method *)l->data)->name), name))
+ {
+ return ((geas_cd_method *)(l->data));
+ }
+ l = g_list_next (l);
+ }
+ return (NULL);
+ }
+
+ /* -------------------------------------------------------------------------
*\
* Free the memory allocated for a type
\* -------------------------------------------------------------------------
*/
static void
***************
*** 1295,1298 ****
--- 1430,1465 ----
*(f->parent) = g_list_remove (*(f->parent), f);
_free_field (f);
+ }
+
+ /* =========================================================================
*\
+ * Methods
+ \* =========================================================================
*/
+
+ /* -------------------------------------------------------------------------
*\
+ * Add a new argument to a method
+ \* -------------------------------------------------------------------------
*/
+ void
+ geas_cd_method_argument_new (geas_cd_method *m, const char *name,
+ const geas_cd_type *type)
+ {
+ g_return_if_fail (m);
+ g_return_if_fail (name);
+ g_return_if_fail (type);
+
+ /* TODO: Should store the argument in a list */
+ m->argcount++;
+ }
+
+ /* -------------------------------------------------------------------------
*\
+ * Get the argument count of a method
+ \* -------------------------------------------------------------------------
*/
+ int
+ geas_cd_method_get_argcount (geas_cd_method *m)
+ {
+ g_return_val_if_fail (m, 0);
+
+ /* TODO: Remove the member "argcount" and return the number of items in the
+ argument list here */
+ return (m->argcount);
}
Index: gnue/geas/src/classdef/classdef.h
diff -c gnue/geas/src/classdef/classdef.h:1.22
gnue/geas/src/classdef/classdef.h:1.23
*** gnue/geas/src/classdef/classdef.h:1.22 Sun Nov 25 16:11:22 2001
--- gnue/geas/src/classdef/classdef.h Thu Nov 29 15:56:56 2001
***************
*** 19,25 ****
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: classdef.h,v 1.22 2001/11/25 21:11:22 reinhard Exp $
*/
/* -------------------------------------------------------------------------
*\
--- 19,25 ----
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: classdef.h,v 1.23 2001/11/29 20:56:56 reinhard Exp $
*/
/* -------------------------------------------------------------------------
*\
***************
*** 51,56 ****
--- 51,57 ----
typedef struct _geas_cd_type geas_cd_type;
typedef struct _geas_cd_fieldlist geas_cd_fieldlist;
typedef struct _geas_cd_field geas_cd_field;
+ typedef struct _geas_cd_method geas_cd_method;
/* -------------------------------------------------------------------------
*\
* General functions
***************
*** 112,140 ****
const geas_cd_module *m,
const char *name);
geas_cd_fieldlist *geas_cd_class_fieldlist_new (const geas_cd_class *c);
void geas_cd_class_free (geas_cd_class *c);
/* -------------------------------------------------------------------------
*\
* Types (can be plain type or structured type)
\* -------------------------------------------------------------------------
*/
! void geas_cd_type_set_filename (geas_cd_type *t,
! const char *filename);
! void geas_cd_type_set_format (geas_cd_type *t, int format);
! const char *geas_cd_type_get_name (const geas_cd_type *t);
! const char *geas_cd_type_get_name_full (const geas_cd_type *t);
! const char *geas_cd_type_get_filename (const geas_cd_type *t);
! int geas_cd_type_get_format (const geas_cd_type *t);
! geas_cd_field *geas_cd_type_field_new (geas_cd_type *t, const char *name,
! geas_cd_type *type);
! geas_cd_field *geas_cd_type_reference_new (geas_cd_type *t,
! const char *name,
! geas_cd_class *otherclass);
! geas_cd_field *geas_cd_type_list_new (geas_cd_type *t, const char *name,
! geas_cd_class *otherclass);
! geas_cd_field *geas_cd_type_find_field (const geas_cd_type *t,
! const char *name);
! void geas_cd_type_free (geas_cd_type *t);
/* -------------------------------------------------------------------------
*\
* Fieldlists
--- 113,153 ----
const geas_cd_module *m,
const char *name);
geas_cd_fieldlist *geas_cd_class_fieldlist_new (const geas_cd_class *c);
+ geas_cd_method *geas_cd_class_method_new (geas_cd_class *c,
+ geas_cd_module *m,
+ const char *name,
+ geas_cd_type *type);
+ geas_cd_method *geas_cd_class_find_method (const geas_cd_class *c,
+ const geas_cd_module *m,
+ const char *name);
void geas_cd_class_free (geas_cd_class *c);
/* -------------------------------------------------------------------------
*\
* Types (can be plain type or structured type)
\* -------------------------------------------------------------------------
*/
! void geas_cd_type_set_filename (geas_cd_type *t,
! const char *filename);
! void geas_cd_type_set_format (geas_cd_type *t, int format);
! const char *geas_cd_type_get_name (const geas_cd_type *t);
! const char *geas_cd_type_get_name_full (const geas_cd_type *t);
! const char *geas_cd_type_get_filename (const geas_cd_type *t);
! geas_cd_datatype geas_cd_type_get_datatype (const geas_cd_type *t);
! int geas_cd_type_get_format (const geas_cd_type *t);
! geas_cd_field *geas_cd_type_field_new (geas_cd_type *t, const char *name,
! geas_cd_type *type);
! geas_cd_field *geas_cd_type_reference_new (geas_cd_type *t,
! const char *name,
! geas_cd_class *otherclass);
! geas_cd_field *geas_cd_type_list_new (geas_cd_type *t, const char *name,
! geas_cd_class *otherclass);
! geas_cd_field *geas_cd_type_find_field (const geas_cd_type *t,
! const char *name);
! geas_cd_method *geas_cd_type_method_new (geas_cd_type *t, const char *name,
! geas_cd_type *type);
! geas_cd_method *geas_cd_type_find_method (const geas_cd_type *t,
! const char *name);
! void geas_cd_type_free (geas_cd_type *t);
/* -------------------------------------------------------------------------
*\
* Fieldlists
***************
*** 167,169 ****
--- 180,203 ----
void geas_cd_field_prop_clr (geas_cd_field *f, int property);
int geas_cd_field_prop_get (geas_cd_field *f, int property);
void geas_cd_field_free (geas_cd_field *f);
+
+ /* -------------------------------------------------------------------------
*\
+ * Methodlists
+ \* -------------------------------------------------------------------------
*/
+
+ /* TODO */
+
+ /* -------------------------------------------------------------------------
*\
+ * Methods
+ \* -------------------------------------------------------------------------
*/
+
+ void geas_cd_method_argument_new (geas_cd_method *m, const char *name,
+ const geas_cd_type *type);
+ int geas_cd_method_get_argcount (geas_cd_method *m);
+ /* TODO: need more functions here */
+
+ /* -------------------------------------------------------------------------
*\
+ * Argumentlists
+ \* -------------------------------------------------------------------------
*/
+
+ /* TODO */
Index: gnue/geas/src/classdef/parse.y
diff -c gnue/geas/src/classdef/parse.y:1.27 gnue/geas/src/classdef/parse.y:1.28
*** gnue/geas/src/classdef/parse.y:1.27 Sun Nov 25 16:11:22 2001
--- gnue/geas/src/classdef/parse.y Thu Nov 29 15:56:56 2001
***************
*** 19,25 ****
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: parse.y,v 1.27 2001/11/25 21:11:22 reinhard Exp $
*/
%{
--- 19,25 ----
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: parse.y,v 1.28 2001/11/29 20:56:56 reinhard Exp $
*/
%{
***************
*** 93,98 ****
--- 93,101 ----
static gboolean _set_field_default_floating (gdouble floating);
static void _set_field_prop (int property);
+ static gboolean _new_method (const gchar *name);
+ static gboolean _new_argument (const gchar *name);
+
%}
/* =========================================================================
*\
***************
*** 378,392 ****
* Methods
\* -------------------------------------------------------------------------
*/
! method: elemname '(' arguments ')' { g_free ($1); /* TODO */ }
;
! arguments: /* */ { /* TODO */ }
! | argument { /* TODO */ }
! | arguments ',' argument { /* TODO */ }
;
! argument: datatype SYMBOL { g_free ($2); /* TODO */ }
;
/* -------------------------------------------------------------------------
*\
--- 381,406 ----
* Methods
\* -------------------------------------------------------------------------
*/
! method: elemname {
! gboolean result;
! result = _new_method ($1);
! g_free ($1);
! if (!result) YYERROR;
! }
! /* continued */ '(' arguments ')'
;
! arguments: /* */
! | argument
! | arguments ',' argument
;
! argument: datatype SYMBOL {
! gboolean result;
! result = _new_argument ($2);
! g_free ($2);
! if (!result) YYERROR;
! }
;
/* -------------------------------------------------------------------------
*\
***************
*** 434,439 ****
--- 448,454 ----
static geas_cd_class *_datatype_list;
static geas_cd_field *_current_field;
+ static geas_cd_method *_current_method;
/* -------------------------------------------------------------------------
*\
* Run the parser on a specific file for a specific pass
***************
*** 950,956 ****
}
if (_current_is_class)
{
! if (geas_cd_class_find_field (_current_class, _current_module,
name))
{
yyerror ("duplicate field or method name");
return (FALSE);
--- 965,973 ----
}
if (_current_is_class)
{
! if (geas_cd_class_find_field (_current_class, _current_module, name)
! || geas_cd_class_find_method (_current_class, _current_module,
! name))
{
yyerror ("duplicate field or method name");
return (FALSE);
***************
*** 962,970 ****
}
else
{
! if (geas_cd_type_find_field (_current_type, name))
{
! yyerror ("duplicate field name");
return (FALSE);
}
else
--- 979,988 ----
}
else
{
! if (geas_cd_type_find_field (_current_type, name)
! || geas_cd_type_find_method (_current_type, name))
{
! yyerror ("duplicate field or method name");
return (FALSE);
}
else
***************
*** 1298,1302 ****
--- 1316,1456 ----
default:
g_assert_not_reached ();
return;
+ }
+ }
+
+ /* -------------------------------------------------------------------------
*\
+ * Found a new method
+ \* -------------------------------------------------------------------------
*/
+ static gboolean
+ _new_method (const gchar *name)
+ {
+ switch (_current_pass)
+ {
+ case 1:
+ return (TRUE);
+ break;
+
+ case 2:
+ if (_current_is_class)
+ {
+ /* We are in a class definition */
+ if (_datatype_type)
+ {
+ /* This method has a predefined type of return value */
+ if (geas_cd_type_get_datatype (_datatype_type)
+ == GEAS_CD_DATATYPE_COMPOUND)
+ {
+ yyerror ("compound types are not allowed as method result");
+ return (FALSE);
+ }
+ _current_method = geas_cd_class_method_new (_current_class,
+ _current_module,
name,
+ _datatype_type);
+ }
+ else if (_datatype_reference)
+ {
+ /* Implicit reference not allowed for methods currently */
+ _current_method = NULL;
+ yyerror ("implicit references are not allowed for methods");
+ return (FALSE);
+ }
+ else if (_datatype_list)
+ {
+ /* Implicit lists are not allowed for methods currently */
+ _current_method = NULL;
+ yyerror ("implicit lists are not allowed for methods");
+ return (FALSE);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ }
+ else
+ {
+ /* We are in a compound type definition */
+ if (_datatype_type)
+ {
+ /* This method has a predefined type of return value */
+ if (geas_cd_type_get_datatype (_datatype_type)
+ == GEAS_CD_DATATYPE_COMPOUND)
+ {
+ yyerror ("compound types are not allowed as method result");
+ return (FALSE);
+ }
+ _current_method = geas_cd_type_method_new (_current_type, name,
+ _datatype_type);
+ }
+ else if (_datatype_reference)
+ {
+ /* Implicit reference not allowed for methods currently */
+ _current_method = NULL;
+ yyerror ("implicit references are not allowed for methods");
+ return (FALSE);
+ }
+ else if (_datatype_list)
+ {
+ /* Implicit lists are not allowed for methods currently */
+ _current_method = NULL;
+ yyerror ("implicit lists are not allowed for methods");
+ return (FALSE);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ }
+ return (TRUE);
+ break;
+
+ default:
+ g_assert_not_reached ();
+ return (FALSE);
+ }
+ }
+
+ /* -------------------------------------------------------------------------
*\
+ * Add a new argument to the current method
+ \* -------------------------------------------------------------------------
*/
+ static gboolean
+ _new_argument (const gchar *name)
+ {
+ switch (_current_pass)
+ {
+ case 1:
+ return (TRUE);
+ break;
+
+ case 2:
+ if (_datatype_type)
+ {
+ /* This method has a predefined type of return value */
+ geas_cd_method_argument_new (_current_method, name, _datatype_type);
+ }
+ else if (_datatype_reference)
+ {
+ /* Implicit reference not allowed for methods currently */
+ _current_method = NULL;
+ yyerror ("implicit references are not allowed for methods");
+ return (FALSE);
+ }
+ else if (_datatype_list)
+ {
+ /* Implicit lists are not allowed for methods currently */
+ _current_method = NULL;
+ yyerror ("implicit lists are not allowed for methods");
+ return (FALSE);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ return (TRUE);
+ break;
+
+ default:
+ g_assert_not_reached ();
+ return (FALSE);
}
}