]> git.draconx.ca Git - gob-dx.git/blobdiff - src/parse.y
Release 1.0.11
[gob-dx.git] / src / parse.y
index 09a871e5af14e6c46291a9c61e67171d231c0991..0bc9836e4ac20d57eefd200414308017b90ec7c9 100644 (file)
@@ -294,20 +294,38 @@ set_return_value(char *type, char *val)
 }
 
 static void
-export_accessors (char *var_name,
-                 GString *get_cbuf,
+export_accessors (const char *var_name,
+                 const char *get_cbuf,
                  int get_lineno,
-                 GString *set_cbuf,
+                 const char *set_cbuf,
                  int set_lineno,
                  Type *type,
+                 const char *gtktype,
                  int lineno)
 {      
-       if (get_cbuf) {
+       if (type == NULL) {
+               char *cast = g_strdup (get_cast (gtktype, FALSE));
+               char *p = strchr (cast, ' ');
+               if (p != NULL) {
+                       *p = '\0';
+                       p++;
+               }
+               /* leak, but we don't really care any more */
+               type = (Type *)new_type (cast,
+                                        g_strdup (p),
+                                        NULL);
+       }
+
+       if (get_cbuf != NULL) {
                char *get_id = g_strdup_printf ("get_%s", var_name);
-               GString *get_cbuf_copy = g_string_new (get_cbuf->str);
+               GString *get_cbuf_copy = g_string_new (get_cbuf);
                char *tmp;
-               Node *node1 = new_type (type->name, type->pointer, type->postfix);
-               Node *node3 = new_type (class->class.otype, "*", NULL);
+               Node *node1 = new_type (g_strdup (type->name),
+                                       g_strdup (type->pointer),
+                                       g_strdup (type->postfix));
+               Node *node3 = new_type (g_strdup (class->class.otype),
+                                       g_strdup ("*"),
+                                       NULL);
 
                tmp = g_strdup_printf ("\t%s%s ARG;\n", 
                                       type->name, 
@@ -329,12 +347,18 @@ export_accessors (char *var_name,
                               lineno, FALSE, NULL);
        }
        
-       if (set_cbuf) {
+       if (set_cbuf != NULL) {
                char *set_id = g_strdup_printf ("set_%s", var_name);
-               GString *set_cbuf_copy = g_string_new (set_cbuf->str);
-               Node *node1 = new_type (type->name, type->pointer, type->postfix);
-               Node *node2 = new_type ("void", NULL, NULL);
-               Node *node3 = new_type (class->class.otype, "*", NULL);
+               GString *set_cbuf_copy = g_string_new (set_cbuf);
+               Node *node1 = new_type (g_strdup (type->name),
+                                       g_strdup (type->pointer),
+                                       g_strdup (type->postfix));
+               Node *node2 = new_type (g_strdup ("void"),
+                                       NULL,
+                                       NULL);
+               Node *node3 = new_type (g_strdup (class->class.otype),
+                                       g_strdup ("*"),
+                                       NULL);
 
                typestack = g_list_prepend (typestack, node2);
                typestack = g_list_prepend (typestack, node1);
@@ -562,10 +586,12 @@ argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE ';
 
                                if ($<id>5) {
                                        export_accessors ($<id>4, 
-                                                         $<cbuf>8, $<line>7,
-                                                         $<cbuf>11, $<line>10,
+                                                         ($<cbuf>8)->str, $<line>7,
+                                                         ($<cbuf>11)->str, $<line>10,
                                                          type,
+                                                         $<id>3,
                                                          $<line>1);
+                                       g_free ($<id>5);
                                } 
 
                                g_string_free ($<cbuf>8, FALSE);
@@ -581,6 +607,17 @@ argument:  ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE ';
                                                     ($<cbuf>11)->str,$<line>10,
                                                     ($<cbuf>8)->str,$<line>7,
                                                     $<line>1);
+
+                               if ($<id>5) {
+                                       export_accessors ($<id>4, 
+                                                         ($<cbuf>11)->str, $<line>10,
+                                                         ($<cbuf>8)->str, $<line>7,
+                                                         type,
+                                                         $<id>3,
+                                                         $<line>1);
+                                       g_free ($<id>5);
+                               } 
+
                                g_string_free ($<cbuf>11, FALSE);
                                g_string_free ($<cbuf>8, FALSE);
                                class_nodes = g_list_append(class_nodes,node);
@@ -608,10 +645,12 @@ argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE ';
                                                     $<line>1);
                                if ($<id>5) {
                                        export_accessors ($<id>4, 
-                                                         $<cbuf>8, $<line>7,
+                                                         ($<cbuf>8)->str, $<line>7,
                                                          NULL, 0,
                                                          type,
+                                                         $<id>3,
                                                          $<line>1);
+                                       g_free ($<id>5);
                                } 
 
                                g_string_free ($<cbuf>8, FALSE);
@@ -627,9 +666,11 @@ argument:  ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE ';
                                if ($<id>5) {
                                        export_accessors ($<id>4, 
                                                          NULL, 0,
-                                                         $<cbuf>8, $<line>7,
+                                                         ($<cbuf>8)->str, $<line>7,
                                                          type,
+                                                         $<id>3,
                                                          $<line>1);
+                                       g_free ($<id>5);
                                } 
 
                                g_string_free ($<cbuf>8, FALSE);
@@ -699,11 +740,12 @@ argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE ';
                                g_assert_not_reached();
                        }
 
-                       if(strcmp ($<id>6, "stringlink")==0) {
+                       if (strcmp ($<id>6, "stringlink")==0) {
                                get = g_strdup_printf("ARG = g_strdup(%s->%s);", root, $<id>4);
-                       } else
+                       } else {
                                /* For everything else, get is just straight assignment */
                                get = g_strdup_printf("ARG = %s->%s;", root, $<id>4);
+                       }
 
                        g_free ($<id>6);
 
@@ -718,10 +760,12 @@ argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE ';
                                             $<line>1);
                        if ($<id>5) {
                                export_accessors ($<id>4, 
-                                                 g_string_new (get), $<line>1,
-                                                 g_string_new (set), $<line>1,
+                                                 get, $<line>1,
+                                                 set, $<line>1,
                                                  type,
+                                                 $<id>3,
                                                  $<line>1);
+                               g_free ($<id>5);
                        } 
 
                        class_nodes = g_list_append(class_nodes,node);