commit-gnue
[Top][All Lists]
Advanced

[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: Sat, 26 May 2001 15:13:59 -0700

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Neil Tiffin <address@hidden>    01/05/26 15:13:57

Modified files:
        geas/lib/classdefs: classdata.c classdata.h gcdparser.c 
                            yparser.y 

Log message:
        Add error checking for implicit reference to TYPE, implicit list
        reference to TYPE, and duplicate class names.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/lib/classdefs/classdata.c.diff?cvsroot=OldCVS&tr1=1.52&tr2=1.53&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/lib/classdefs/classdata.h.diff?cvsroot=OldCVS&tr1=1.27&tr2=1.28&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/lib/classdefs/gcdparser.c.diff?cvsroot=OldCVS&tr1=1.34&tr2=1.35&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/lib/classdefs/yparser.y.diff?cvsroot=OldCVS&tr1=1.27&tr2=1.28&r1=text&r2=text

Patches:
Index: gnue/geas/lib/classdefs/classdata.c
diff -u gnue/geas/lib/classdefs/classdata.c:1.52 
gnue/geas/lib/classdefs/classdata.c:1.53
--- gnue/geas/lib/classdefs/classdata.c:1.52    Sat May 26 07:24:23 2001
+++ gnue/geas/lib/classdefs/classdata.c Sat May 26 15:13:57 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.52 2001/05/26 14:24:23 ntiffin Exp $
+   $Id: classdata.c,v 1.53 2001/05/26 22:13:57 ntiffin Exp $
    
 */
 
@@ -1743,6 +1743,30 @@
 }
 
 /* ------------------------------------------------------------------------- *\
+ * Given an item make a fullname with all of the parents.
+\* ------------------------------------------------------------------------- */
+char *
+odl_make_fullname( odl_base * base )
+{
+  GString * name = g_string_new(NULL);
+  odl_base * b = NULL;
+  char * result;
+  g_assert( base );
+  
+  name = g_string_append( name, base->name );
+  b = base->parent;
+  while (b)
+    {
+      name = g_string_prepend(name, "::");
+      name = g_string_prepend(name, b->name);
+      b = b->parent;
+    }
+  result = name->str;
+  g_string_free( name, FALSE);
+  return result;
+}
+
+/* ------------------------------------------------------------------------- *\
  * Actually process the type into new fields
  * Assumes that the field is a field and a type
 \* ------------------------------------------------------------------------- */
@@ -1802,6 +1826,7 @@
                         g_strdup_printf ("%s.%s", f->base.name,
                                          type_field->base.name);
                       n->base.access = f->base.access;
+                      n->base.tree = c->base.tree;
                       n->fieldtype = FT_basic;
                       n->datatype = type_field->datatype;
                       if (type_field->datatypeclass)
@@ -1869,7 +1894,10 @@
   load = odl_find_class (((odl_base *) i)->tree, i->datatypeclass, NULL);
   if (!load)
     {
-      yyerror ("Could not find class '%s'", i->datatypeclass);
+    printf( "\n**** Error field reference to CLASS %s could not be found. (In 
CLASS %s)\n",
+           i->datatypeclass, cont->base.name);
+      printf( "     Make sure that %s is not a TYPE or is defined as a CLASS 
in a .gcd file.\n", i->datatypeclass);
+      yyerrorcount++;
       return;
     }
   name = g_strdup_printf ("_%s_%s", odl_class_get_mangled_name
@@ -1882,6 +1910,7 @@
       a->base.name = g_strdup (name);
       a->base.access = i->base.access;
       a->base.type = IT_field;
+      a->base.tree = i->base.tree;
       a->fieldtype = FT_basic;
       a->datatype = DT_object;
       a->properties = ODL_PROP_NONE;
@@ -1899,6 +1928,7 @@
       a->base.name = g_strdup (fl->base.name);
       a->base.access = i->base.access;
       a->base.type = IT_field;
+      a->base.tree = i->base.tree;
       a->fieldtype = FT_list;
       a->datatype = DT_class;
       a->properties = ODL_PROP_NONE;
@@ -1910,6 +1940,7 @@
                              odl_class_get_full_name (cont), NULL);
       a->base.parent = (odl_base *) cont;
       cont->contents = g_list_append (cont->contents, a);
+      /* verify that the list referres to a class and not a type */
     }
   else
     {
@@ -1929,7 +1960,10 @@
   odl_item *a;
   odl_field *fl = (odl_field *) i;
   odl_class *current_container = (odl_class *) fl->base.parent;
-
+  odl_class *target_class = NULL;
+  g_assert( i != NULL);
+  g_assert( append != NULL);
+  
   /* convert the existing field to a reference field */
   i->base.type = IT_field;
   i->base.access = i->base.access;
@@ -1940,7 +1974,16 @@
     (odl_namelist *) g_list_append (NULL,
                                     g_strdup_printf ("_%s", i->base.name));
   i->sourceclass = g_strdup (i->datatypeclass);
-
+  /* verify that the reference is to a class and not a type */
+  target_class = odl_find_class(  i->base.tree, i->datatypeclass, NULL);
+  if (target_class == NULL)
+    {
+    printf( "\n**** Error field reference to CLASS %s could not be found. (In 
CLASS %s)\n",
+           i->datatypeclass, current_container->base.name);
+    printf( "     Make sure that %s is not a TYPE or is defined as a CLASS in 
a .gcd file.\n", i->datatypeclass);
+    yyerrorcount++;
+    return;
+    }
   /* create the new _fieldname objectreference field */
   a = alloc_odl_item ();
   g_assert (a != NULL);
@@ -1950,6 +1993,7 @@
       a->base.name = g_strdup_printf ("_%s", i->base.name);
       a->base.access = i->base.access;
       a->base.type = IT_field;
+      a->base.tree = i->base.tree;
       a->fieldtype = FT_basic;
       a->datatype = DT_object;
       a->properties = ODL_PROP_NONE;
@@ -2196,7 +2240,7 @@
   while (l)
     {
 #ifdef DEBUG
-      printf ("++++ Pass 1 Start processing file: %s\n", (char *) l->data);
+      printf ("++++ Pass 1 File: %s\n", (char *) l->data);
 #endif
       switch (yystartfile (l->data))
         {
@@ -2237,7 +2281,7 @@
   while (l)
     {
 #ifdef DEBUG
-      printf ("++++ Pass 2 Start processing file: %s\n", (char *) l->data);
+      printf ("++++ Pass 2 File: %s\n", (char *) l->data);
 #endif
       switch (yystartfile (l->data))
         {
@@ -2264,14 +2308,20 @@
 
   if (yyerrorcount > max_errors)
     {
-      yymessage ("Too many errors. File load failed.");
+      yymessage ("Too many errors in parsing. File load failed.");
       return (NULL);
     }
 
-  /* done */
+  /* done, but these may generate more errors */
   odl_link_all_to_tree ((odl_base *) newtree->root, newtree);
   odl_process_compound_types ((odl_container *) newtree->root);
   odl_process_references_lists ((odl_container *) newtree->root);
+  
+  if (yyerrorcount > max_errors)
+    {
+      yymessage ("Too many errors in post processing. File load failed.");
+      return (NULL);
+    }
 
   odl_link_all_to_tree ((odl_base *) newtree->root, newtree);   /* TODO 
sloppy, one final time for new entries */
   return (newtree);
Index: gnue/geas/lib/classdefs/classdata.h
diff -u gnue/geas/lib/classdefs/classdata.h:1.27 
gnue/geas/lib/classdefs/classdata.h:1.28
--- gnue/geas/lib/classdefs/classdata.h:1.27    Fri May 25 12:34:52 2001
+++ gnue/geas/lib/classdefs/classdata.h Sat May 26 15:13:57 2001
@@ -291,6 +291,7 @@
  *
  */
 void odl_resolve_implicit_list (odl_item * i );
+char * odl_make_fullname( odl_base * base );
 
 odl_tree *odl_load_files(odl_filenamelist * files, odl_tree * tree);
 void odl_display_tree(FILE * out, odl_tree * tree, gboolean show_full_name);
Index: gnue/geas/lib/classdefs/gcdparser.c
diff -u gnue/geas/lib/classdefs/gcdparser.c:1.34 
gnue/geas/lib/classdefs/gcdparser.c:1.35
--- gnue/geas/lib/classdefs/gcdparser.c:1.34    Thu May 24 11:59:01 2001
+++ gnue/geas/lib/classdefs/gcdparser.c Sat May 26 15:13:57 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.34 2001/05/24 18:59:01 ntiffin Exp $
+   $Id: gcdparser.c,v 1.35 2001/05/26 22:13:57 ntiffin Exp $
    
 */
 
@@ -344,6 +344,7 @@
 
       /* add the objectid field */
       f = alloc_odl_item ();
+      g_assert( f != NULL );
       f->base.parent = (odl_base *) c;
       f->base.access = ODL_ACCESS_SYSTEM;
       f->base.name = g_strdup ("objectid");
Index: gnue/geas/lib/classdefs/yparser.y
diff -u gnue/geas/lib/classdefs/yparser.y:1.27 
gnue/geas/lib/classdefs/yparser.y:1.28
--- gnue/geas/lib/classdefs/yparser.y:1.27      Fri May 25 12:34:52 2001
+++ gnue/geas/lib/classdefs/yparser.y   Sat May 26 15:13:57 2001
@@ -128,22 +128,25 @@
 push_class:  /* */   {
                        if( current_pass == 1 )
                          {
-                           odl_class *newone;
+                           odl_class *newone = NULL;
+                           char * fullname = NULL;
+                           odl_class *check_class = NULL;
                            /* printf( "push_class name: %s\n", $<list>-0); */
-                            /*  TODO start hack to stop duplicate classes
-                           odl_class *check_class;
-                           check_class = odl_find_class(yycurrenttree, 
$<string>0, NULL);
+                           newone = odl_new_class($<uint>-4,$<string>0);
+                           g_assert( newone );
+                           newone->base.parent = (odl_base 
*)yycurrent_container;
+                           /* try to find a class with the same name   */
+                           fullname = odl_make_fullname( (odl_base*) newone );
+                           check_class = odl_find_class(yycurrenttree, 
fullname, NULL);
                            if (check_class != NULL)
                              {
-                               yyerror( "duplicate class name found" );
+                               yyerror( "Duplicate class name found." );
                              }
-                           */
-                           newone = odl_new_class($<uint>-4,$<string>0);
+                           /* continue with creating class */
                            odl_container_insert_container( yycurrent_container 
,
                                                          (odl_container 
*)newone );
-                           newone->base.parent = (odl_base 
*)yycurrent_container;
                            yycurrent_container = newone;
-                           /* doindent(); printf( "push class\n" ); indent += 
4; */
+                          /* doindent(); printf( "push class\n" ); indent += 
4; */
                          }
                        else
                          {
@@ -160,21 +163,21 @@
                         odl_class *c = NULL;
                         if (current_pass == 1)
                           {
-                            /*
-                            odl_container * tmp;
-                            tmp = (odl_container *) yycurrent_container;
-                            printf( "pop_class current name: %s\n", 
tmp->base.name);
-                            */
+                                        /*
+                                        odl_container * tmp;
+                                        tmp = (odl_container *) 
yycurrent_container;
+                                        printf( "pop_class current name: 
%s\n", tmp->base.name);
+                                        */
                             c = (odl_class *) yycurrent_container;
                             yycurrent_container = (odl_container *)
                               odl_container_get_parent (yycurrent_container);
-                            /*
-                            tmp = (odl_container *) yycurrent_container;
-                            printf( "pop_class new name: %s\n", 
tmp->base.fullname);
-                            */
-                            /* indent-=4; doindent(); printf( "pop class\n" ); 
*/
-                            /* add all the class's info to yycurrent_container 
*/
-                            /* add fields in the class (any subclasses already 
added) */
+                                        /*
+                                        tmp = (odl_container *) 
yycurrent_container;
+                                        printf( "pop_class new name: %s\n", 
tmp->base.fullname);
+                                        */
+                                        /* indent-=4; doindent(); printf( "pop 
class\n" ); */
+                                        /* add all the class's info to 
yycurrent_container */
+                                        /* add fields in the class (any 
subclasses already added) */
                             if ($<list>-1)
                               {
                                 if (c->contents)
@@ -238,19 +241,17 @@
                             odl_module * wanted = NULL;
                             wanted = odl_find_module( yycurrenttree, $1, 0);
                             /* printf("Looking for Module: %s, %p\n", $1, 
wanted); */
-                            if ((wanted == NULL) || (current_pass != 1))
+                            $$ = $1;
+                            if ((wanted != NULL) && (current_pass == 1))
                               {
-                                $$ = $1;
-                              }
-                            else
-                              {
                                 yyerror("Duplicate module name.");
-                                $$ = "Duplicate_Module_Name";
                               }
                           }
   ;
   
-new_class_name: SYMBOL   { $$ = $1; /*printf("[ (%s)\n",$1);*/ }
+new_class_name: SYMBOL    { /*printf("[ (%s)\n",$1);*/ 
+                            $$ = $1;
+                          }
   ;
 
 new_field_name: SYMBOL { $$ = $1; }
@@ -367,7 +368,7 @@
   |       qualified_name                   { $$ = 
alloc_odl_datatype(FALSE,$1,-1,DT_type); }
   |       qualified_name '*'               { $$ = 
alloc_odl_datatype(FALSE,$1,-1,DT_class); }
   |       qualified_name '[' ']'           { $$ = 
alloc_odl_datatype(FALSE,$1,0,DT_class); }
-  |       qualified_name '[' INTEGER ']'   { $$ = 
alloc_odl_datatype(FALSE,$1,$3,DT_class); yyerror("Bounded lists are not yet 
supported"); }
+  |       qualified_name '[' INTEGER ']'   { $$ = 
alloc_odl_datatype(FALSE,$1,$3,DT_class); yyerror("Bounded lists are not yet 
supported."); }
   ;
 
 opt_format: /* */                       { $$ = NULL; }
@@ -500,6 +501,7 @@
 
 lookup: new_field_name ':' lookup_data_source '=' search_fields  {
             odl_item *i = alloc_odl_item();
+            g_assert( i != NULL);
             if( i )
             {
                 i->base.parent   = (odl_base *)yycurrent_container;
@@ -520,7 +522,7 @@
                 $$ = i;
             }
             else {
-                yyerror("Out of memory");
+                yyerror("Out of memory.");
                 $$ = NULL;
             }
         }
@@ -529,9 +531,13 @@
 list: new_field_name ':' list_data_source '=' search_fields   {
             odl_item *i = NULL;
             
-            if( current_pass == 1 ) i = alloc_odl_item();
+            if( current_pass == 1 )
+              {
+                i = alloc_odl_item();
+                g_assert( i != NULL);
+              }
             if( i )
-            {
+              {
                 i->base.parent   = (odl_base *)yycurrent_container;
                 i->base.type     = IT_field;
                 i->base.name     = $1;
@@ -548,11 +554,12 @@
                 free_odl_datasource($3);
 
                 $$ = i;
-            }
-            else if( current_pass == 1 ) {
-                yyerror("Out of memory");
+              }
+            else if( current_pass == 1 )
+              {
+                yyerror("Out of memory.");
                 $$ = NULL;
-            }
+              }
         }
   ;
 
@@ -580,7 +587,7 @@
                 $$ = i;
             }
             else if( current_pass == 1 ) {
-                yyerror("Out of memory");
+                yyerror("Out of memory.");
                 $$ = NULL;
             }
         }
@@ -606,10 +613,20 @@
 language: SYMBOL  { $$ = $1; }
   ;
 
-help: language opt_help_fieldname stringlist { printf("Help for field %s in 
%s: '%s'\n",$2,$3,$1); }
+help: language opt_help_fieldname stringlist {
+                                               if ( current_pass == 1 )
+                                                 {
+                                                   /* printf("Help for field 
%s in %s: '%s'\n",$2,$3,$1); */
+                                                 }
+                                              }
   ;
 
-tooltip: language help_fieldname STRING  { printf("Tooltip for field %s in %s: 
'%s'\n",$2,$3,$1); }
+tooltip: language help_fieldname STRING  {
+                                           if ( current_pass == 1 )
+                                             {
+                                               /* printf("Tooltip for field %s 
in %s: '%s'\n",$2,$3,$1); */
+                                             }
+                                         }
   ;
 
 orderby: SYMBOL    { if( yycurrent_container->orderby )



reply via email to

[Prev in Thread] Current Thread [Next in Thread]