[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/geas/lib/classdefs classdata.c classdata.h...
From: |
Neil Tiffin |
Subject: |
gnue/geas/lib/classdefs classdata.c classdata.h... |
Date: |
Thu, 24 May 2001 11:59:01 -0700 |
CVSROOT: /home/cvs
Module name: gnue
Changes by: Neil Tiffin <address@hidden> 01/05/24 11:59:01
Modified files:
geas/lib/classdefs: classdata.c classdata.h gcdparser.c
gcdparser.h
Log message:
Fix bug where TYPE's containing implicit references and lists were not
being handled correctly.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/lib/classdefs/classdata.c.diff?cvsroot=OldCVS&tr1=1.47&tr2=1.48&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/lib/classdefs/classdata.h.diff?cvsroot=OldCVS&tr1=1.25&tr2=1.26&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/lib/classdefs/gcdparser.c.diff?cvsroot=OldCVS&tr1=1.33&tr2=1.34&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/lib/classdefs/gcdparser.h.diff?cvsroot=OldCVS&tr1=1.22&tr2=1.23&r1=text&r2=text
Patches:
Index: gnue/geas/lib/classdefs/classdata.c
diff -u gnue/geas/lib/classdefs/classdata.c:1.47
gnue/geas/lib/classdefs/classdata.c:1.48
--- gnue/geas/lib/classdefs/classdata.c:1.47 Sat May 19 16:50:47 2001
+++ gnue/geas/lib/classdefs/classdata.c Thu May 24 11:59:00 2001
@@ -22,7 +22,7 @@
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: classdata.c,v 1.47 2001/05/19 23:50:47 ntiffin Exp $
+ $Id: classdata.c,v 1.48 2001/05/24 18:59:00 ntiffin Exp $
*/
@@ -35,12 +35,208 @@
#include "classdata.h"
#include "lparser.h"
-int yyparse(void);
+int yyparse (void);
/* spaces to indent per level */
#define INDENT 2
/* ------------------------------------------------------------------------- *\
+ * Print the contents of the odl base structure
+\* ------------------------------------------------------------------------- */
+void
+odl_dump_base (FILE * out, odl_base * base)
+{
+ g_assert (out != NULL);
+ g_assert (base != NULL);
+ fprintf (out, "\n******* base name: %s, %p\n", base->name, base);
+ fprintf (out, " fullname: %s\n", base->fullname);
+ fprintf (out, " mangled name: %s\n", base->mangledname);
+ fprintf (out, " odl_item_type: %s\n", odl_itemtype_name (base->type));
+ fprintf (out, " access: %s\n", odl_access_name (base->access));
+ fprintf (out, " triggers: %lx\n", base->triggers);
+ fprintf (out, " parent: ");
+ if (base->parent != NULL)
+ {
+ fprintf (out, "%s, ", (base->parent)->name);
+ }
+ fprintf (out, "%p\n", base->tree);
+}
+
+/* ------------------------------------------------------------------------- *\
+ * Print the contents of the odl container structure
+\* ------------------------------------------------------------------------- */
+void
+odl_dump_container (FILE * out, odl_container * container)
+{
+ GList *contents;
+ GList *parents;
+ GList *indexes;
+ odl_base *base;
+ _odl_index *index;
+ g_assert (out != NULL);
+ g_assert (container != NULL);
+ if (container->istype)
+ {
+ fprintf (out, " istype: true\n");
+ }
+ else
+ {
+ fprintf (out, " istype: false\n");
+ }
+ fprintf (out, " order by: %s\n", container->orderby);
+ contents = container->contents;
+ while (contents)
+ {
+ base = (odl_base *) contents->data;
+ fprintf (out, " contents: %s, %p\n", base->name, base);
+ contents = g_list_next (contents);
+ }
+ parents = container->parents;
+ while (parents)
+ {
+ char *name = (char *) parents->data;
+ fprintf (out, " parents: %s\n", name);
+ parents = g_list_next (parents);
+ }
+ indexes = container->indexes;
+ while (indexes)
+ {
+ fprintf (out, " indexes:");
+ index = (_odl_index *) indexes->data;
+ contents = index->fields;
+ while (contents)
+ {
+ fprintf (out, " %s", (char *) contents->data);
+ contents = g_list_next (contents);
+ if (contents != NULL)
+ {
+ fprintf (out, ",");
+ }
+ fprintf (out, " -");
+ }
+ if (index->unique)
+ {
+ fprintf (out, " UNIQUE");
+ }
+ if (index->primary)
+ {
+ fprintf (out, " PRIMARY");
+ }
+ indexes = g_list_next (indexes);
+ fprintf (out, "\n");
+ }
+}
+
+/* ------------------------------------------------------------------------- *\
+ * Print the contents of the odl item structure
+\* ------------------------------------------------------------------------- */
+void
+odl_dump_item (FILE * out, odl_item * item)
+{
+ GList *contents;
+ g_assert (out != NULL);
+ g_assert (item != NULL);
+ fprintf (out, " field type: %s\n",
+ odl_fieldtype_name (item->fieldtype));
+ fprintf (out, " data type: %s\n",
+ odl_datatype_name (item->datatype));
+ fprintf (out, " data type class: %s\n", item->datatypeclass);
+ fprintf (out, " properties: %lu\n", item->properties);
+
+ fprintf (out, " format: %s\n", item->format);
+ fprintf (out, " default value: %s\n", item->defaultval);
+ fprintf (out, " temp default: %s\n", item->tmpdefault);
+
+ fprintf (out, " source field: %s\n", item->sourcefield);
+ fprintf (out, " source class: %s\n", item->sourceclass);
+
+ contents = item->this_fields;
+ fprintf (out, " this fields: ");
+ while (contents)
+ {
+ fprintf (out, "%s ", (char *) contents->data);
+ contents = g_list_next (contents);
+ }
+ fprintf (out, "\n");
+
+ contents = item->source_fields;
+ fprintf (out, " source fields: ");
+ while (contents)
+ {
+ fprintf (out, "%s ", (char *) contents->data);
+ contents = g_list_next (contents);
+ }
+ fprintf (out, "\n");
+ fprintf (out, " bounds: %ld ", item->bounds);
+ if (item->bounds == -1)
+ fprintf (out, "(Reference)\n");
+ if (item->bounds > -1)
+ fprintf (out, "(List)\n");
+ if (item->bounds < -1)
+ fprintf (out, "(Undefined)\n");
+
+ contents = item->arguments;
+ fprintf (out, " arguments: ");
+ while (contents)
+ {
+ fprintf (out, "%s ", (char *) contents->data);
+ contents = g_list_next (contents);
+ }
+ fprintf (out, "\n");
+ fprintf (out, " calculation: %s\n", item->calculation);
+ contents = item->elements;
+ fprintf (out, " enum elements: ");
+ while (contents)
+ {
+ fprintf (out, "%s ", (char *) contents->data);
+ contents = g_list_next (contents);
+ }
+ fprintf (out, "\n");
+}
+
+/* ------------------------------------------------------------------------- *\
+ * Print the contents of the odl structure
+ * recursive = true, means recurse through all children
+\* ------------------------------------------------------------------------- */
+void
+odl_dump1_tree (FILE * out, odl_base * base, gboolean recursive)
+{
+ switch (base->type)
+ {
+ case IT_unknown:
+ printf ("**** ERROR Unknown item type IT_unknown\n");
+ odl_dump_base (out, base);
+ break;
+ case IT_module:
+ case IT_class:
+ /* the only containers */
+ odl_dump_base (out, base);
+ odl_dump_container (out, (odl_container *) base);
+ if (recursive)
+ {
+ GList *contents;
+ contents = ((odl_container *) base)->contents;
+ while (contents)
+ {
+ odl_dump1_tree (out, (odl_base *) (contents->data), recursive);
+ contents = g_list_next (contents);
+ }
+ }
+ break;
+ case IT_field:
+ case IT_enum:
+ case IT_type:
+ odl_dump_base (out, base);
+ odl_dump_item (out, (odl_item *) base);
+ break;
+ case IT_ignore:
+ printf ("**** ERROR Ignore item type IT_ignore\n");
+ odl_dump_base (out, base);
+ break;
+ }
+}
+
+/* ------------------------------------------------------------------------- *\
*
\* ------------------------------------------------------------------------- */
int
@@ -74,8 +270,12 @@
return ("protected");
case ODL_ACCESS_SYSTEM:
return ("system");
+ case ODL_ACCESS_UNCHANGED:
+ return ("unchanged");
+ case ODL_ACCESS_UNKNOWN:
+ return ("unknown");
}
- g_assert_not_reached();
+ g_assert_not_reached ();
return ("(unknown access)");
}
@@ -102,7 +302,7 @@
case IT_enum:
return ("enum");
}
- g_assert_not_reached();
+ g_assert_not_reached ();
return ("unknown");
}
@@ -114,13 +314,19 @@
{
g_assert (name != NULL);
- if (g_strcasecmp (name, "module") == 0) return (IT_module);
- if (g_strcasecmp (name, "class") == 0) return (IT_class);
- if (g_strcasecmp (name, "field") == 0) return (IT_field);
- if (g_strcasecmp (name, "enum") == 0) return (IT_enum);
- if (g_strcasecmp (name, "type") == 0) return (IT_type);
- if (g_strcasecmp (name, "ignore") == 0) return (IT_ignore);
- g_assert_not_reached();
+ if (g_strcasecmp (name, "module") == 0)
+ return (IT_module);
+ if (g_strcasecmp (name, "class") == 0)
+ return (IT_class);
+ if (g_strcasecmp (name, "field") == 0)
+ return (IT_field);
+ if (g_strcasecmp (name, "enum") == 0)
+ return (IT_enum);
+ if (g_strcasecmp (name, "type") == 0)
+ return (IT_type);
+ if (g_strcasecmp (name, "ignore") == 0)
+ return (IT_ignore);
+ g_assert_not_reached ();
return (IT_unknown);
}
@@ -163,7 +369,7 @@
case DT_type:
return ("compound datatype");
}
- g_assert_not_reached();
+ g_assert_not_reached ();
return ("unknown");
}
@@ -176,20 +382,34 @@
#ifdef DEBUG
assert (name != NULL);
#endif
- if (g_strcasecmp (name, "char") == 0) return (DT_char);
- if (g_strcasecmp (name, "int") == 0) return (DT_int);
- if (g_strcasecmp (name, "text") == 0) return (DT_text);
- if (g_strcasecmp (name, "class") == 0) return (DT_class);
- if (g_strcasecmp (name, "date") == 0) return (DT_date);
- if (g_strcasecmp (name, "time") == 0) return (DT_time);
- if (g_strcasecmp (name, "datetime") == 0) return (DT_datetime);
- if (g_strcasecmp (name, "bool") == 0) return (DT_bool);
- if (g_strcasecmp (name, "float") == 0) return (DT_float);
- if (g_strcasecmp (name, "void") == 0) return (DT_void);
- if (g_strcasecmp (name, "object") == 0) return (DT_object);
- if (g_strcasecmp (name, "enum") == 0) return (DT_enum);
- if (g_strcasecmp (name, "unsignedint") == 0) return (DT_unsignedint);
- if (g_strcasecmp (name, "type") == 0) return (DT_type);
+ if (g_strcasecmp (name, "char") == 0)
+ return (DT_char);
+ if (g_strcasecmp (name, "int") == 0)
+ return (DT_int);
+ if (g_strcasecmp (name, "text") == 0)
+ return (DT_text);
+ if (g_strcasecmp (name, "class") == 0)
+ return (DT_class);
+ if (g_strcasecmp (name, "date") == 0)
+ return (DT_date);
+ if (g_strcasecmp (name, "time") == 0)
+ return (DT_time);
+ if (g_strcasecmp (name, "datetime") == 0)
+ return (DT_datetime);
+ if (g_strcasecmp (name, "bool") == 0)
+ return (DT_bool);
+ if (g_strcasecmp (name, "float") == 0)
+ return (DT_float);
+ if (g_strcasecmp (name, "void") == 0)
+ return (DT_void);
+ if (g_strcasecmp (name, "object") == 0)
+ return (DT_object);
+ if (g_strcasecmp (name, "enum") == 0)
+ return (DT_enum);
+ if (g_strcasecmp (name, "unsignedint") == 0)
+ return (DT_unsignedint);
+ if (g_strcasecmp (name, "type") == 0)
+ return (DT_type);
return (DT_unknown);
}
@@ -218,7 +438,7 @@
case FT_unknown:
return ("unknown");
}
- g_assert_not_reached();
+ g_assert_not_reached ();
return ("unknown");
}
@@ -231,14 +451,21 @@
#ifdef DEBUG
assert (name != NULL);
#endif
- if (g_strcasecmp (name, "lookup") == 0) return (FT_lookup);
- if (g_strcasecmp (name, "reference") == 0) return (FT_reference);
- if (g_strcasecmp (name, "list") == 0) return (FT_list);
- if (g_strcasecmp (name, "method") == 0) return (FT_method);
- if (g_strcasecmp (name, "calculated") == 0) return (FT_calculated);
- if (g_strcasecmp (name, "readonly") == 0) return (FT_readonly);
- if (g_strcasecmp (name, "basic") == 0) return (FT_basic);
- g_assert_not_reached();
+ if (g_strcasecmp (name, "lookup") == 0)
+ return (FT_lookup);
+ if (g_strcasecmp (name, "reference") == 0)
+ return (FT_reference);
+ if (g_strcasecmp (name, "list") == 0)
+ return (FT_list);
+ if (g_strcasecmp (name, "method") == 0)
+ return (FT_method);
+ if (g_strcasecmp (name, "calculated") == 0)
+ return (FT_calculated);
+ if (g_strcasecmp (name, "readonly") == 0)
+ return (FT_readonly);
+ if (g_strcasecmp (name, "basic") == 0)
+ return (FT_basic);
+ g_assert_not_reached ();
return (FT_unknown);
}
@@ -252,9 +479,7 @@
void
odl_filenamelist_free (odl_filenamelist * list)
{
-#ifdef DEBUG
- assert (list != NULL);
-#endif
+ g_assert (list != NULL);
odl_namelist_free ((odl_namelist *) list);
}
@@ -265,10 +490,8 @@
odl_filenamelist_add (odl_filenamelist * list, const char *filename)
{
char *f;
-
-#ifdef DEBUG
- assert (filename != NULL);
-#endif
+
+ g_assert (filename != NULL);
if (filename)
{
f = g_strdup (filename);
@@ -334,7 +557,7 @@
gboolean casesensitive)
{
GList *l;
-
+
#ifdef DEBUG
assert (list != NULL);
#endif
@@ -423,7 +646,7 @@
odl_find_class (odl_tree * tree, const char *name, const char *id)
{
struct _odl_base *item;
-
+
#ifdef DEBUG
assert (name != NULL);
assert (tree != NULL);
@@ -448,7 +671,7 @@
odl_find_module (odl_tree * tree, const char *name, const char *id)
{
struct _odl_base *item;
-
+
#ifdef DEBUG
assert (name != NULL);
assert (id != NULL);
@@ -473,7 +696,7 @@
odl_find_field (odl_tree * tree, const char *name, const char *id)
{
struct _odl_base *item;
-
+
#ifdef DEBUG
assert (name != NULL);
assert (id != NULL);
@@ -497,7 +720,7 @@
odl_find_in_container (odl_base * c, const char *name)
{
GList *l;
-
+
#ifdef DEBUG
assert (c != NULL);
assert (name != NULL);
@@ -520,7 +743,7 @@
}
/* ------------------------------------------------------------------------- *\
- * :ocate a named item in the class tree
+ * Locate a named item in the class tree
\* ------------------------------------------------------------------------- */
odl_base *
odl_find_item (odl_tree * tree, const char *name, const char *id)
@@ -530,11 +753,9 @@
odl_base *retval = NULL;
char *tmp;
-#ifdef DEBUG
- assert (name != NULL);
- /* assert (id != NULL); id not used? */
- assert (tree != NULL);
-#endif
+ g_assert (name != NULL);
+ g_assert (tree != NULL);
+
/* cos it's a const input, make a temp. duplicate */
tmp = g_strdup (name);
if (!tmp)
@@ -609,7 +830,7 @@
GList *l;
odl_base *retval;
char *tmp;
-
+
#ifdef DEBUG
assert (start != NULL);
assert (name != NULL);
@@ -652,7 +873,7 @@
odl_find_named_item_type (odl_tree * tree, const char *name)
{
odl_base *i;
-
+
#ifdef DEBUG
assert (tree != NULL);
assert (name != NULL);
@@ -927,7 +1148,7 @@
{
odl_namelist *nl = NULL;
GList *l;
-
+
#ifdef DEBUG
assert (classd != NULL);
#endif
@@ -947,7 +1168,7 @@
odl_class_get_field (odl_class * classd, const char *fieldname)
{
odl_class *c;
-
+
#ifdef DEBUG
assert (classd != NULL);
assert (fieldname != NULL);
@@ -1002,7 +1223,7 @@
odl_fieldlist *fl = NULL;
odl_namelist *parents;
GList *l;
-
+
#ifdef DEBUG
assert (classd != NULL);
#endif
@@ -1045,7 +1266,7 @@
{
odl_namelist *parents;
char *n1, *n2;
-
+
#ifdef DEBUG
assert (classd != NULL);
assert (classname != NULL);
@@ -1207,7 +1428,7 @@
int len;
time_t timep;
struct tm *tm;
-
+
#ifdef DEBUG
assert (field != NULL);
#endif
@@ -1411,7 +1632,7 @@
{
GList *names = NULL;
char *p, *q;
-
+
#ifdef DEBUG
assert (qualifiedname != NULL);
/* printf( "---- odl_split_qualified_name() is splitting: '%s'\n" ,
qualifiedname ); */
@@ -1459,7 +1680,7 @@
{
/* error: "::::" is illegal */
#ifdef DEBUG
- assert( strlen (p) != 0);
+ assert (strlen (p) != 0);
#endif
odl_namelist_free (names);
return (NULL);
@@ -1529,114 +1750,344 @@
}
/* ------------------------------------------------------------------------- *\
- * Scan the data base and replace all fields that are TYPES (not real fields)
- * with the wanted exploded fields from the TYPE definition.
- * TODO move to gcdparser.c
+ * Actually process the type into new fields
+ * Assumes that the field is a field and a type
\* ------------------------------------------------------------------------- */
static void
-odl_process_coumpound_types (odl_container * c)
+odl_process_type_field (odl_container * c, odl_field * f)
{
- odl_field *f;
- odl_class *cl;
- GList *l, *newlist;
+ odl_class *type_class;
+ GList *type_contents;
+ g_assert (c != NULL);
+ g_assert (f != NULL);
+ g_assert (f->base.type == IT_field);
+ g_assert (f->datatype == DT_type);
#ifdef DEBUG
- assert (c != NULL);
+ /* printf( "---- odl_process_type_field(), look for TYPE '%s'\n" ,
f->datatypeclass ); */
#endif
- l = c->contents;
- while (l)
- {
- odl_base *b = l->data;
- /* process sub items */
- if (b->type == IT_class || b->type == IT_module)
- {
- odl_process_coumpound_types ((odl_container *) b);
- }
- if (b->type == IT_field)
- {
- f = (odl_field *) b;
- if (f->datatype == DT_type)
- {
- /* it's a compound type - make new fields */
- b->type = IT_ignore;
-#ifdef DEBUG
- /* printf( "---- odl_process_coumpound_types()\n look for
type '%s'\n" , f->datatypeclass ); */
-#endif
- cl = odl_find_class (b->tree, f->datatypeclass, NULL);
- if (!cl)
- {
+ /* mark existing field as no longer needed */
+ f->base.type = IT_ignore;
+ type_class = odl_find_class (f->base.tree, f->datatypeclass, NULL);
+ if (!type_class)
+ {
+ printf
+ ("**** Error could not find TYPE: %s, in container %s\n",
+ f->datatypeclass, c->base.name);
+ return;
+ }
+ if (!type_class->istype)
+ {
+ printf ("**** Error not a TYPE\n");
+ return;
+ }
+ /* it's a compound type - make new fields */
#ifdef DEBUG
- /* printf( " Couldn't find it!\n" ); */
+ /* printf( " Make field '%s.*'\n" , b->name ); */
#endif
- }
- else
+ type_contents = type_class->contents;
+ while (type_contents) /* go through all contents of type */
+ {
+ odl_field *type_field = type_contents->data;
+ odl_field *n;
+ switch (type_field->base.type)
+ {
+ case IT_field:
+ if (strcmp (type_field->base.name, "objectid") != 0)
+ {
+ switch (type_field->fieldtype)
{
- if (!cl->istype)
+ case FT_basic:
+ n = alloc_odl_item ();
+ g_assert (n != NULL);
+ if (n)
{
+ n->base.type = IT_field;
+ n->base.parent = (odl_base *) c;
+ n->base.name =
+ g_strdup_printf ("%s.%s", f->base.name,
+ type_field->base.name);
+ n->base.access = f->base.access;
+ n->fieldtype = FT_basic;
+ n->datatype = type_field->datatype;
+ if (type_field->datatypeclass)
+ {
+ n->datatypeclass =
+ g_strdup (type_field->datatypeclass);
+ }
+ else
+ {
+ n->datatypeclass = NULL;
+ }
+ n->properties = type_field->properties;
+ c->contents = g_list_append (c->contents, n);
#ifdef DEBUG
- /* printf( " Not a 'type'\n" ); */
+ /* printf( " Made '%s'\n" , n->base.name ); */
#endif
}
else
{
- GList *l;
+ yyerror ("Out of memory");
+ }
+ break;
+ case FT_lookup:
+ case FT_reference:
+ case FT_list:
+ case FT_method:
+ case FT_calculated:
+ case FT_readonly:
+ default:
+ break;
+ }
+ }
+ break;
+ default:
#ifdef DEBUG
- /* printf( " Got it\n" ); */
- /* printf( " Make field '%s.*'\n" , b->name ); */
+ /* printf
+ (" Did not recongize item in TYPE: %s\n",
+ odl_itemtype_name (type_field->base.type)); */
#endif
- l = cl->contents;
- newlist = NULL;
- while (l)
- {
- odl_field *fld = l->data;
- odl_field *n;
+ break;
+ }
+ type_contents = g_list_next (type_contents);
+ }
+}
- if (fld->base.type == IT_field
- && strcmp (fld->base.name, "objectid") != 0)
- {
- n = alloc_odl_item ();
- if (n)
- {
- n->base.type = IT_field;
- n->base.parent = (odl_base *) c;
- n->base.name =
- g_strdup_printf ("%s.%s", b->name,
- fld->base.name);
- n->base.access = b->access;
- n->fieldtype = FT_basic;
- n->datatype = fld->datatype;
- if (fld->datatypeclass)
- {
- n->datatypeclass =
- g_strdup (fld->datatypeclass);
- }
- else
- {
- n->datatypeclass = NULL;
- }
- n->properties = fld->properties;
-
- c->contents =
- g_list_append (c->contents, n);
-#ifdef DEBUG
- /* printf( " Made '%s'\n" , n->base.name
); */
-#endif
- }
- else
- {
- yyerror ("Out of memory");
- }
- }
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
+void
+odl_resolve_implicit_list (odl_item * i)
+{
+ char *name;
+ odl_item *a;
+ odl_field *fl;
+ odl_class *cont;
+ odl_class *load;
+ g_assert (i != NULL);
+
+ fl = (odl_field *) i;
+ cont = (odl_class *) fl->base.parent;
+ load = odl_find_class (((odl_base *) i)->tree, i->datatypeclass, NULL);
+ if (!load)
+ {
+ yyerror ("Could not find class '%s'", i->datatypeclass);
+ return;
+ }
+ name = g_strdup_printf ("_%s_%s", odl_class_get_mangled_name
+ (cont), fl->base.name);
+ a = alloc_odl_item ();
+ g_assert (a != NULL);
+ if (a)
+ {
+ a->base.parent = (odl_base *) load;
+ a->base.name = g_strdup (name);
+ a->base.access = i->base.access;
+ a->base.type = IT_field;
+ a->fieldtype = FT_basic;
+ a->datatype = DT_object;
+ a->properties = ODL_PROP_NONE;
+ load->contents = g_list_append (load->contents, a);
+ }
+ else
+ {
+ yyerror ("Out of memory");
+ }
+ /* turn 'fl' into a list field */
+ a = alloc_odl_item ();
+ g_assert (a != NULL);
+ if (a)
+ {
+ a->base.name = g_strdup (fl->base.name);
+ a->base.access = i->base.access;
+ a->base.type = IT_field;
+ a->fieldtype = FT_list;
+ a->datatype = DT_class;
+ a->properties = ODL_PROP_NONE;
+ a->sourceclass = g_strdup (i->datatypeclass);
+ a->source_fields = g_list_append (NULL, name);
+ a->this_fields = g_list_append (NULL, g_strdup ("objectid"));
+ /* find the 'real' version in the class tree */
+ cont = odl_find_class (((odl_base *) i)->tree,
+ odl_class_get_full_name (cont), NULL);
+ a->base.parent = (odl_base *) cont;
+ cont->contents = g_list_append (cont->contents, a);
+ }
+ else
+ {
+ yyerror ("Out of memory");
+ }
+ fl->fieldtype = FT_list;
+}
- l = g_list_next (l);
- }
- }
+
+/* ------------------------------------------------------------------------- *\
+ * Convert the field (i) into a reference object field and build the (a) field
+ * which is used to store the objectid of the referenced class.
+\* ------------------------------------------------------------------------- */
+void
+odl_resolve_implicit_reference (odl_item * i, GList * append)
+{
+ odl_item *a;
+ odl_field *fl = (odl_field *) i;
+ odl_class *current_container = (odl_class *) fl->base.parent;
+
+ /* convert the existing field to a reference field */
+ i->base.type = IT_field;
+ i->base.access = i->base.access;
+ i->fieldtype = FT_reference;
+ i->source_fields =
+ (odl_namelist *) g_list_append (NULL, g_strdup ("objectid"));
+ i->this_fields =
+ (odl_namelist *) g_list_append (NULL,
+ g_strdup_printf ("_%s", i->base.name));
+ i->sourceclass = g_strdup (i->datatypeclass);
+
+ /* create the new _fieldname objectreference field */
+ a = alloc_odl_item ();
+ g_assert (a != NULL);
+ if (a)
+ {
+ a->base.parent = (odl_base *) current_container;
+ a->base.name = g_strdup_printf ("_%s", i->base.name);
+ a->base.access = i->base.access;
+ a->base.type = IT_field;
+ a->fieldtype = FT_basic;
+ a->datatype = DT_object;
+ a->properties = ODL_PROP_NONE;
+ append = g_list_append (append, a);
+ }
+ else
+ {
+ yyerror ("Out of memory");
+ }
+}
+
+
+/* ------------------------------------------------------------------------- *\
+ * Scan the data base and replace all fields that are TYPES (not real fields)
+ * with the wanted exploded fields from the TYPE definition.
+ * TODO move to gcdparser.c
+\* ------------------------------------------------------------------------- */
+static void
+odl_process_compound_types (odl_container * c)
+{
+ GList *container_contents;
+ g_assert (c != NULL);
+
+ container_contents = c->contents;
+ while (container_contents)
+ {
+ odl_base *b = container_contents->data;
+#ifdef DEBUG
+ /*
+ if (b->type == IT_field)
+ {
+ if (((odl_item *) b)->fieldtype == FT_basic)
+ {
+ if (((odl_item *) b)->datatype == DT_class)
+ {
+ printf
+ ("**** ERROR unresolved field: %s, in container %s\n",
+ b->name, c->base.name);
+ }
+ }
+ }
+ */
+#endif
+ /* process sub items */
+ switch (b->type)
+ {
+ case IT_class:
+ odl_process_compound_types ((odl_container *) b);
+ break;
+ case IT_module:
+ odl_process_compound_types ((odl_container *) b);
+ break;
+ case IT_field:
+ {
+ odl_field *f;
+ f = (odl_field *) b;
+#ifdef DEBUG
+ /*
+ if (f->datatype == DT_class)
+ {
+ printf( "---- odl_process_compound_types(), look for CLASS:
%s\n" , f->datatypeclass );
+ printf( " fieldtype:
%s\n" , odl_fieldtype_name(f->fieldtype) );
+ printf( " container:
%s\n" , c->base.name );
+ }
+ */
+#endif
+ if (f->datatype == DT_type)
+ {
+ odl_process_type_field (c, f);
+ }
+ }
+ break;
+ case IT_unknown:
+ case IT_enum:
+ case IT_type:
+ default:
+ /* these are processed later */
+ break;
+ case IT_ignore:
+ break;
+ }
+ container_contents = g_list_next (container_contents);
+ }
+}
+
+static void
+odl_process_references_lists (odl_container * c)
+{
+ GList *container_contents;
+ g_assert (c != NULL);
+
+ container_contents = c->contents;
+ while (container_contents)
+ {
+ odl_base *b = container_contents->data;
+ switch (b->type)
+ {
+ case IT_class:
+ odl_process_references_lists ((odl_container *) b);
+ break;
+ case IT_module:
+ odl_process_references_lists ((odl_container *) b);
+ break;
+ case IT_field:
+ if ((((odl_item *) b)->datatype == DT_class)
+ && (((odl_item *) b)->fieldtype == FT_basic))
+ {
+ /* if -1 turn it into a reference */
+ /* else 0 or positive a list class */
+ /* else < -1 invalid */
+ g_assert (((odl_item *) b)->bounds > -2);
+ if (((odl_item *) b)->bounds == (-1))
+ {
+ /* do reference field */
+ odl_resolve_implicit_reference ((odl_item *) b,
+ ((odl_container *) (b->
+
parent))->
+ contents);
+ }
+ else
+ {
+ /* do list field */
+ odl_resolve_implicit_list ((odl_item *) b);
}
}
+ break;
+ case IT_unknown:
+ case IT_enum:
+ case IT_type:
+ default:
+ break;
+ case IT_ignore:
+ break;
}
-
- l = g_list_next (l);
+ container_contents = g_list_next (container_contents);
}
}
@@ -1743,12 +2194,12 @@
expecting_fieldprop = 0;
expect_triggertype = 0;
yycurrent_container = odl_tree_get_root (newtree);
- g_assert( yycurrent_container != NULL);
+ g_assert (yycurrent_container != NULL);
l = (GList *) files;
while (l)
{
#ifdef DEBUG
- printf( "++++ Pass 1 Start processing file: %s\n", (char *)l->data);
+ printf ("++++ Pass 1 Start processing file: %s\n", (char *) l->data);
#endif
switch (yystartfile (l->data))
{
@@ -1789,7 +2240,7 @@
while (l)
{
#ifdef DEBUG
- printf( "++++ Pass 2 Start processing file: %s\n", (char *)l->data);
+ printf ("++++ Pass 2 Start processing file: %s\n", (char *) l->data);
#endif
switch (yystartfile (l->data))
{
@@ -1822,7 +2273,10 @@
/* done */
odl_link_all_to_tree ((odl_base *) newtree->root, newtree);
- odl_process_coumpound_types ((odl_container *) newtree->root);
+ odl_process_compound_types ((odl_container *) newtree->root);
+ odl_process_references_lists ((odl_container *) newtree->root);
+
+ odl_link_all_to_tree ((odl_base *) newtree->root, newtree); /* TODO
sloppy, one final time for new entries */
return (newtree);
}
@@ -1830,21 +2284,23 @@
*
\* ------------------------------------------------------------------------- */
static void
-real_odl_display_tree (FILE * out, odl_base * item, int indent,
+real_odl_display_tree (FILE * out, odl_container * item, int indent,
gboolean show_full_name)
{
int i;
- GList *l, *s, *t;
+ GList *l;
+ GList *s;
+ GList *t;
GList *lst;
odl_item *it;
char *buf;
+ g_assert (item != NULL);
+ g_assert (out != NULL);
-#ifdef DEBUG
- assert (item != NULL);
- assert (out != NULL);
-#endif
- if (item->type == IT_ignore)
- return;
+ if (item->base.type == IT_ignore)
+ {
+ return;
+ }
/* indent this item */
for (i = 0; i < indent; i++)
@@ -1852,32 +2308,32 @@
fprintf (out, " ");
}
/* print type and name */
- if (item->type == IT_class)
+ if (item->base.type == IT_class)
{
- if (((odl_class *) item)->istype)
+ if (item->istype)
{
- fprintf (out, "%s %s (%s)", odl_access_name (item->access),
- item->name, "type");
+ fprintf (out, "%s %s (%s)", odl_access_name (item->base.access),
+ item->base.name, "type");
}
else
{
- fprintf (out, "%s %s (%s)", odl_access_name (item->access),
- item->name, "class");
+ fprintf (out, "%s %s (%s)", odl_access_name (item->base.access),
+ item->base.name, "class");
}
}
else
{
- fprintf (out, "%s %s (%s)", odl_access_name (item->access), item->name,
- odl_itemtype_name (item->type));
+ fprintf (out, "%s %s (%s)", odl_access_name (item->base.access),
+ item->base.name, odl_itemtype_name (item->base.type));
}
- switch (item->type)
+ switch (item->base.type)
{
case IT_module:
- buf = (char *) odl_module_get_full_name ((odl_module *) item);
+ buf = (char *) odl_module_get_full_name (item);
break;
case IT_class:
- buf = (char *) odl_class_get_full_name ((odl_class *) item);
+ buf = (char *) odl_class_get_full_name (item);
break;
case IT_field:
buf = (char *) odl_field_get_full_name ((odl_field *) item);
@@ -1897,10 +2353,10 @@
}
/* print children of a module or class */
- switch (item->type)
+ switch (item->base.type)
{
case IT_class:
- l = ((odl_container *) item)->parents;
+ l = item->parents;
if (l)
{
fprintf (out, "\n");
@@ -1911,7 +2367,7 @@
fprintf (out, "Parents:");
while (l)
{
- fprintf (out, " %s", (char *)l->data);
+ fprintf (out, " %s", (char *) l->data);
if (l->next)
{
fprintf (out, ",");
@@ -1919,15 +2375,17 @@
l = g_list_next (l);
}
}
- l = ((odl_container *) item)->indexes;
+ l = item->indexes;
if (l)
{
fprintf (out, "\n");
- for (i = 0; i < indent; i++)
- {
- fprintf (out, " ");
- }
- fprintf (out, "Indexes:\n");
+ /*
+ for (i = 0; i < indent; i++)
+ {
+ fprintf (out, " ");
+ }
+ fprintf (out, "Indexes:\n");
+ */
while (l)
{
_odl_index *idx = l->data;
@@ -1954,7 +2412,7 @@
}
while (l2)
{
- fprintf (out, "%s", (char *)l2->data);
+ fprintf (out, "%s", (char *) l2->data);
if (l2->next)
fprintf (out, ", ");
l2 = g_list_next (l2);
@@ -1963,7 +2421,7 @@
l = g_list_next (l);
}
}
- if (((odl_container *) item)->orderby)
+ if (item->orderby)
{
for (i = 0; i < indent; i++)
{
@@ -1972,7 +2430,7 @@
fprintf (out, "ORDER BY %s", ((odl_container *) item)->orderby);
fprintf (out, "\n");
}
- l = ((odl_container *) item)->contents;
+ l = item->contents;
while (l)
{
real_odl_display_tree (out, l->data, indent + INDENT,
@@ -1983,7 +2441,7 @@
break;
case IT_module:
fprintf (out, "\n");
- l = ((odl_container *) item)->contents;
+ l = item->contents;
while (l)
{
real_odl_display_tree (out, l->data, indent + INDENT,
@@ -2003,7 +2461,7 @@
lst = ((struct _odl_item *) item)->elements;
while (lst)
{
- fprintf (out, " %s", (char *)lst->data);
+ fprintf (out, " %s", (char *) lst->data);
lst = g_list_next (lst);
}
fprintf (out, "\n");
@@ -2043,8 +2501,8 @@
{
fprintf (out, " ");
}
- fprintf (out, " %s.%s = this.%s\n", it->sourceclass, (char *)
s->data,
- (char *) t->data);
+ fprintf (out, " %s.%s = this.%s\n", it->sourceclass,
+ (char *) s->data, (char *) t->data);
s = g_list_next (s);
t = g_list_next (t);
}
@@ -2059,8 +2517,8 @@
{
fprintf (out, " ");
}
- fprintf (out, " %s.%s = this.%s\n", it->sourceclass, (char
*)s->data,
- (char *) t->data);
+ fprintf (out, " %s.%s = this.%s\n", it->sourceclass,
+ (char *) s->data, (char *) t->data);
s = g_list_next (s);
t = g_list_next (t);
}
@@ -2075,8 +2533,8 @@
{
fprintf (out, " ");
}
- fprintf (out, " %s.%s = this.%s\n", it->sourceclass, (char *)
s->data,
- (char *)t->data);
+ fprintf (out, " %s.%s = this.%s\n", it->sourceclass,
+ (char *) s->data, (char *) t->data);
s = g_list_next (s);
t = g_list_next (t);
}
@@ -2128,7 +2586,12 @@
fprintf (out, "\n");
break;
case IT_type:
+ fprintf (out, "Type: (%s)\n", it->base.name);
+ fprintf (out, "\n");
+ break;
case IT_ignore:
+ fprintf (out, "Ignore: (%s)\n", it->base.name);
+ fprintf (out, "\n");
break; /* added to satisfy compiler warning neilt */
}
}
@@ -2139,13 +2602,31 @@
void
odl_display_tree (FILE * out, odl_tree * tree, gboolean show_full_name)
{
-#ifdef DEBUG
- assert (out != NULL);
-#endif
+ g_assert (out != NULL);
+ fprintf (out, "\nCurrent Class Tree\n\n");
+ if (tree)
+ {
+ real_odl_display_tree (out, tree->root, 0, show_full_name);
+ }
+ else
+ {
+ fprintf (out, "No clases found\n");
+ }
+ fprintf (out, "\n");
+}
+
+
+/* ------------------------------------------------------------------------- *\
+ * Dump the current tree for debugging purposes
+\* ------------------------------------------------------------------------- */
+void
+odl_dump_tree (FILE * out, odl_tree * tree, gboolean recursive)
+{
+ g_assert (out != NULL);
fprintf (out, "\nCurrent Class Tree\n\n");
if (tree)
{
- real_odl_display_tree (out, (odl_base *) tree->root, 0, show_full_name);
+ odl_dump1_tree (out, (odl_base *) tree->root, recursive);
}
else
{
Index: gnue/geas/lib/classdefs/classdata.h
diff -u gnue/geas/lib/classdefs/classdata.h:1.25
gnue/geas/lib/classdefs/classdata.h:1.26
--- gnue/geas/lib/classdefs/classdata.h:1.25 Wed Mar 14 20:17:14 2001
+++ gnue/geas/lib/classdefs/classdata.h Thu May 24 11:59:01 2001
@@ -277,8 +277,22 @@
int odl_get_error_count();
int odl_get_warn_count();
+/** \brief Resolve reference field.
+ * \param i The item from the parser that is converted to a reference field.
+ * \param append The items to be added to the container.
+ * \param datatype The datatype from the parser.
+ */
+void odl_resolve_implicit_reference (odl_item * i, GList * append);
+
+/**
+ *
+ */
+void odl_resolve_implicit_list (odl_item * i );
+
odl_tree *odl_load_files(odl_filenamelist * files, odl_tree * tree);
void odl_display_tree(FILE * out, odl_tree * tree, gboolean show_full_name);
+void odl_dump1_tree(FILE * out, odl_base * tree, gboolean recursive);
+void odl_dump_tree(FILE * out, odl_tree * tree, gboolean recursive);
/* Utility functions */
odl_namelist *odl_split_qualified_name(char *qualifiedname);
Index: gnue/geas/lib/classdefs/gcdparser.c
diff -u gnue/geas/lib/classdefs/gcdparser.c:1.33
gnue/geas/lib/classdefs/gcdparser.c:1.34
--- gnue/geas/lib/classdefs/gcdparser.c:1.33 Sat May 19 16:44:42 2001
+++ gnue/geas/lib/classdefs/gcdparser.c Thu May 24 11:59:01 2001
@@ -22,7 +22,7 @@
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: gcdparser.c,v 1.33 2001/05/19 23:44:42 ntiffin Exp $
+ $Id: gcdparser.c,v 1.34 2001/05/24 18:59:01 ntiffin Exp $
*/
@@ -460,19 +460,23 @@
}
}
+
/* ------------------------------------------------------------------------- *\
- * For list and reference fields (i.e. classname * fieldname or
+ * For implicit list and reference fields (i.e. classname * fieldname or
* classname [] fieldname) makes
* actual fields that are used to implement the requested fields.
+ *
+ * For all field types store the datatype.
+ *
+ * For TYPE fields set-up for future processing.
\* ------------------------------------------------------------------------- */
GList *
odl_reprocess_fields (_odl_datatype * datatype, GList * fields)
{
- GList *append = NULL;
+ GList *append = NULL; /* saves new fields until after field list is
*/
+ /* processed. */
GList *f;
odl_item *i;
- odl_item *a;
-
g_assert (datatype != NULL);
g_assert (fields != NULL);
@@ -489,7 +493,7 @@
{
i->datatype = DT_unsignedint;
}
- /* skip 'type' created fields til later */
+ /* set-up 'type' created fields for later processing */
if (datatype->dt == DT_type)
{
i->base.type = IT_field;
@@ -497,121 +501,31 @@
i->datatype = DT_type;
i->datatypeclass = g_strdup (datatype->name);
}
- /* only do the reference and list types on pass 2 */
if ((datatype->dt == DT_class || datatype->dt == DT_enum))
{
if (i->fieldtype == FT_basic && i->datatype == DT_class)
{
+ i->datatypeclass = g_strdup (datatype->name);
+ i->datatype = datatype->dt;
/* if -1 turn it into a reference */
/* else 0 or positive a list class */
/* else < -1 invalid */
- g_assert( i->bounds > -2);
+ g_assert (i->bounds > -2);
if (i->bounds == (-1))
{
- /* reference */
- /* convert this to a reference field */
- i->base.type = IT_field;
- i->base.access = i->base.access;
- i->fieldtype = FT_reference;
- i->source_fields =
- (odl_namelist *) g_list_append (NULL,
- g_strdup ("objectid"));
- i->this_fields =
- (odl_namelist *) g_list_append (NULL,
- g_strdup_printf
- ("_%s", i->base.name));
- i->sourceclass = g_strdup (datatype->name);
-
- /* create the _fieldname objectreference field */
- a = alloc_odl_item ();
- if (a)
- {
- a->base.parent = (odl_base *) yycurrent_container;
- a->base.name = g_strdup_printf ("_%s", i->base.name);
- a->base.access = i->base.access;
- a->base.type = IT_field;
- a->fieldtype = FT_basic;
- a->datatype = DT_object;
- a->properties = ODL_PROP_NONE;
- append = g_list_append (append, a);
- }
- else
- {
- yyerror ("Out of memory");
- }
+ /* convert the existing field to a reference field */
+ /* odl_resolve_implicit_reference (i, append, datatype); */
}
else
{
- /* list */
- /* delayed until full tree is built */
+ /* list, delayed until full tree is built */
if (current_pass == 2)
{
- char *name;
- odl_field *fl = (odl_field *) i;
- odl_class *cont = (odl_class *) fl->base.parent;
- odl_class *load = odl_find_class (yycurrenttree,
- datatype->name, NULL);
- if (!load)
- {
- yyerror ("Could not find class '%s'",
- datatype->name);
- }
- else
- {
- name =
- g_strdup_printf ("_%s_%s",
- odl_class_get_mangled_name
- (cont), fl->base.name);
- a = alloc_odl_item ();
- if (a)
- {
- a->base.parent = (odl_base *) load;
- a->base.name = g_strdup (name);
- a->base.access = i->base.access;
- a->base.type = IT_field;
- a->fieldtype = FT_basic;
- a->datatype = DT_object;
- a->properties = ODL_PROP_NONE;
- load->contents =
- g_list_append (load->contents, a);
- }
- else
- {
- yyerror ("Out of memory");
- }
- /* turn 'fl' into a list field */
- a = alloc_odl_item ();
- if (a)
- {
- a->base.name = g_strdup (fl->base.name);
- a->base.access = i->base.access;
- a->base.type = IT_field;
- a->fieldtype = FT_list;
- a->datatype = DT_class;
- a->properties = ODL_PROP_NONE;
- a->sourceclass = g_strdup (datatype->name);
- a->source_fields = g_list_append (NULL, name);
- a->this_fields =
- g_list_append (NULL, g_strdup ("objectid"));
- /* find the 'real' version in the class tree */
- cont =
- odl_find_class (yycurrenttree,
- odl_class_get_full_name
- (cont), NULL);
- a->base.parent = (odl_base *) cont;
- cont->contents =
- g_list_append (cont->contents, a);
- }
- else
- {
- yyerror ("Out of memory");
- }
- fl->fieldtype = FT_list;
- }
+ /* odl_resolve_implicit_list (i, datatype); */
}
else
{
- ((odl_base *) i)->type = IT_ignore;
+ /* ((odl_base *) i)->type = IT_ignore; */
}
}
}
Index: gnue/geas/lib/classdefs/gcdparser.h
diff -u gnue/geas/lib/classdefs/gcdparser.h:1.22
gnue/geas/lib/classdefs/gcdparser.h:1.23
--- gnue/geas/lib/classdefs/gcdparser.h:1.22 Tue May 15 10:59:07 2001
+++ gnue/geas/lib/classdefs/gcdparser.h Thu May 24 11:59:01 2001
@@ -21,7 +21,7 @@
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: gcdparser.h,v 1.22 2001/05/15 17:59:07 ntiffin Exp $
+ $Id: gcdparser.h,v 1.23 2001/05/24 18:59:01 ntiffin Exp $
*/
@@ -42,6 +42,8 @@
/** \struct _odl_base
* \brief Generic data for an odl object.
+ * Only used in conjuction with _odl_container and
+ * _odl_item.
*/
struct _odl_base
{
@@ -60,14 +62,17 @@
*/
struct _odl_container
{
- struct _odl_base base;
+ struct _odl_base base; /* WARNING: nothing can be put before base
*/
+ /* in structure as the code make heavy
*/
+ /* use of casts that rely on this being
*/
+ /* first item in structure.
*/
/* generic data */
- GList *contents; /* must be an instance of _odl_base */
+ GList *contents; /* list of (struct _odl_base *)
*/
/* business class data */
gboolean istype; /* true if 'type' keyword was used */
char *orderby;
- GList *parents;
- GList *indexes;
+ GList *parents; /* list of (char *) */
+ GList *indexes; /* list of (struct _odl_index *) */
};
/** \struct _odl_item
@@ -75,7 +80,10 @@
*/
struct _odl_item
{
- struct _odl_base base;
+ struct _odl_base base; /* WARNING: nothing can be put before base
*/
+ /* in structure as the code make heavy
*/
+ /* use of casts that rely on this being
*/
+ /* first item in structure.
*/
/* class fields - generic data */
enum odl_fieldtype fieldtype;
enum odl_datatype datatype;
@@ -120,6 +128,7 @@
/** \struct _odl_datatype
* \brief ODL data type structure for passing around in functions.
+ * Used for implicit references and lists only.
*/
typedef struct
{
@@ -142,7 +151,7 @@
_odl_datasource;
/** \struct _odl_index
- * \brief
+ * \brief For indexing the class.
*/
typedef struct
{
@@ -192,6 +201,26 @@
odl_item *odl_new_enum (unsigned long int access,
const char *name);
void odl_enum_add_element (odl_item * e, char *element);
+
+/**
+ * i = pointer to current item to convert
+ *
+ */
+void odl_make_reference(odl_item * i, struct _odl_container *
container);
+
+/**
+ * Anytime a field is processed it comes here. The purpose of
+ * this routine is to expand multiple fields on one line,
+ * and create reference and list structures. Types are
+ * set up for further processing but not expanded.
+ *
+ * for a defintion like:
+ * address home, business, girlfriend;
+ *
+ * \param datatype Is the address _odl_datatype struct
+ * \param fields Is a list of (struct _odl_item *)
+ * fields -> GList[ home, business, girlfriend ]
+ */
GList *odl_reprocess_fields (_odl_datatype * datatype,
GList * fields);
odl_item *set_method_datatype (_odl_datatype * datatype,
- gnue/geas/lib/classdefs classdata.c classdata.h...,
Neil Tiffin <=