]> git.draconx.ca Git - gob-dx.git/blobdiff - src/parse.y
Release 1.99.2
[gob-dx.git] / src / parse.y
index 36f9abc19c338fbb3e39e42edcab411bae14743d..a8d3341f07d56ca14b105f3d0b589bb30ca3af40 100644 (file)
 #include "main.h"
 #include "util.h"
 
+/* FIXME: add gettext support */
 #define _(x) (x)
        
 GList *nodes = NULL;
 
 static GList *class_nodes = NULL;
 Node *class = NULL;
+GList *enums = NULL;
+static GList *enum_vals = NULL;
+static GList *flag_vals = NULL;
+static GList *error_vals = NULL;
 
 static char *chunk_size = NULL;
-static char *bonobo_x_class = NULL;
+static char *bonobo_object_class = NULL;
+static GList *interfaces = NULL;
 static GList *typestack = NULL;
 static GList *funcargs = NULL;
 static GList *checks = NULL;
@@ -462,8 +468,8 @@ property_link_and_export (Node *node)
                }
 
                if (strcmp (prop->gtktype, "STRING") == 0) {
-                       set = g_strdup_printf("g_free (%s->%s); "
-                                             "%s->%s = g_value_dup_string (VAL);",
+                       set = g_strdup_printf("{ char *old = %s->%s; "
+                                             "%s->%s = g_value_dup_string (VAL); g_free (old); }",
                                              root, prop->name,
                                              root, prop->name);
                        get = g_strdup_printf("g_value_set_string (VAL, %s->%s);",
@@ -583,7 +589,7 @@ ensure_property (void)
 %token <cbuf> CCODE HTCODE PHCODE HCODE ACODE ATCODE STRING
 %token <line> PUBLIC PRIVATE PROTECTED CLASSWIDE PROPERTY ARGUMENT
 %token <line> VIRTUAL SIGNAL OVERRIDE
-%token <line> NICK BLURB MAXIMUM MINIMUM DEFAULT_VALUE FLAGS TYPE
+%token <line> NICK BLURB MAXIMUM MINIMUM DEFAULT_VALUE ERROR FLAGS TYPE
 %token <line> FLAGS_TYPE ENUM_TYPE PARAM_TYPE BOXED_TYPE OBJECT_TYPE
 
 %%
@@ -651,7 +657,13 @@ ccode:             CCODE                   {
        ;
 
 ccodes:                ccodes ccode            { ; }
+       |       ccodes enumcode         { ; }
+       |       ccodes flagcode         { ; }
+       |       ccodes errorcode        { ; }
        |       ccode                   { ; }
+       |       enumcode                { ; }
+       |       flagcode                { ; }
+       |       errorcode               { ; }
        ;
 
 class:         classdec '{' classcode '}'      {
@@ -670,9 +682,13 @@ classdec:  CLASS TYPETOKEN FROM TYPETOKEN  classflags {
                        class = node_new (CLASS_NODE,
                                          "otype:steal", $<id>2,
                                          "ptype:steal", $<id>4,
-                                         "bonobo_x_class:steal", bonobo_x_class,
+                                         "bonobo_object_class:steal", bonobo_object_class,
+                                         "interfaces:steal", interfaces,
                                          "chunk_size:steal", chunk_size,
                                          NULL);
+                       bonobo_object_class = NULL;
+                       chunk_size = NULL;
+                       interfaces = NULL;
                                                }
        ;
 
@@ -681,9 +697,18 @@ classflags:
                        if(strcmp($<id>2,"chunks") == 0) {
                                g_free (chunk_size);
                                chunk_size = g_strdup($<id>3);
-                       } else if(strcmp($<id>2,"BonoboX") == 0) {
-                               g_free (bonobo_x_class);
-                               bonobo_x_class = g_strdup($<id>3);
+                       } else if(strcmp($<id>2,"BonoboObject") == 0) {
+                               g_free (bonobo_object_class);
+                               bonobo_object_class = g_strdup($<id>3);
+                       } else {
+                               yyerror(_("parse error"));
+                               YYERROR;
+                       }
+               }
+       | '(' TOKEN TYPETOKEN ')' classflags {
+                       if (strcmp ($<id>2, "interface") == 0) {
+                               interfaces = g_list_append (interfaces,
+                                                           g_strdup ($<id>3));
                        } else {
                                yyerror(_("parse error"));
                                YYERROR;
@@ -709,12 +734,25 @@ classcode:        classcode thing                 { ; }
 
 thing:                 method                          { ; }
        |       TOKEN method                    {
-                       if (strcmp ($<id>1, "BonoboX") != 0) {
-                               g_free($<id>1);
-                               yyerror(_("parse error"));
+                       if (strcmp ($<id>1, "BonoboObject") != 0) {
+                               g_free ($<id>1);
+                               yyerror (_("parse error"));
                                YYERROR;
                        }
-                       last_added_method->bonobo_x_func = TRUE;
+                       g_free ($<id>1);
+                       last_added_method->bonobo_object_func = TRUE;
+                                               }
+       |       TOKEN TYPETOKEN method                  {
+                       if (strcmp ($<id>1, "interface") != 0) {
+                               g_free ($<id>1);
+                               g_free ($<id>2);
+                               yyerror (_("parse error"));
+                               YYERROR;
+                       }
+                       g_free ($<id>1);
+                       node_set ((Node *)last_added_method,
+                                 "interface:steal", $<id>2,
+                                 NULL);
                                                }
        |       variable                        { ; }
        |       argument                        { ; }
@@ -1764,7 +1802,118 @@ check:          TOKEN                   {
                        checks = g_list_append(checks,node);
                                        }
        ;
-       
+
+enumcode:      ENUM TOKEN '{' enumvals '}' TYPETOKEN ';' {
+                       Node *node = node_new (ENUMDEF_NODE,
+                                              "etype:steal", $<id>6,
+                                              "prefix:steal", $<id>2,
+                                              "values:steal", enum_vals,
+                                              NULL);
+                       enum_vals = NULL;
+                       nodes = g_list_append (nodes, node);
+                       }
+       |       ENUM TOKEN '{' enumvals ',' '}' TYPETOKEN ';' {
+                       Node *node = node_new (ENUMDEF_NODE,
+                                              "etype:steal", $<id>7,
+                                              "prefix:steal", $<id>2,
+                                              "values:steal", enum_vals,
+                                              NULL);
+                       enum_vals = NULL;
+                       nodes = g_list_append (nodes, node);
+                       }
+       ;
+
+enumvals:      enumvals ',' enumval    {;}
+       |       enumval                 {;}
+       ;
+
+enumval:       TOKEN '=' numtok        {
+                       Node *node;
+                       char *num = $<id>3;
+
+                       /* A float value, that's a bad enum */
+                       if (num[0] >= '0' &&
+                           num[0] <= '9' &&
+                           strchr (num, '.') != NULL) {
+                               g_free ($<id>1);
+                               g_free (num);
+                               yyerror(_("parse error (enumerator value not integer constant)"));
+                               YYERROR;
+                       }
+                      
+                       node = node_new (ENUMVALUE_NODE,
+                                        "name:steal", $<id>1,
+                                        "value:steal", num,
+                                        NULL);
+                       enum_vals = g_list_append (enum_vals, node);
+                       }
+       |       TOKEN                   {
+                       Node *node;
+
+                       node = node_new (ENUMVALUE_NODE,
+                                        "name:steal", $<id>1,
+                                        NULL);
+                       enum_vals = g_list_append (enum_vals, node);
+       }
+       ;
+
+flagcode:      FLAGS TOKEN '{' flagvals '}' TYPETOKEN ';' {
+                       Node *node = node_new (FLAGS_NODE,
+                                              "ftype:steal", $<id>6,
+                                              "prefix:steal", $<id>2,
+                                              "values:steal", flag_vals,
+                                              NULL);
+                       flag_vals = NULL;
+                       nodes = g_list_append (nodes, node);
+                       }
+       |       FLAGS TOKEN '{' flagvals ',' '}' TYPETOKEN ';' {
+                       Node *node = node_new (FLAGS_NODE,
+                                              "ftype:steal", $<id>7,
+                                              "prefix:steal", $<id>2,
+                                              "values:steal", flag_vals,
+                                              NULL);
+                       flag_vals = NULL;
+                       nodes = g_list_append (nodes, node);
+                       }
+       ;
+
+flagvals:      flagvals ',' TOKEN      {
+                       flag_vals = g_list_append (flag_vals, $<id>3);
+               }
+       |       TOKEN                   {
+                       flag_vals = g_list_append (flag_vals, $<id>1);
+               }
+       ;
+
+errorcode:     ERROR TOKEN '{' errorvals '}' TYPETOKEN ';' {
+                       Node *node = node_new (ERROR_NODE,
+                                              "etype:steal", $<id>6,
+                                              "prefix:steal", $<id>2,
+                                              "values:steal", error_vals,
+                                              NULL);
+                       error_vals = NULL;
+                       nodes = g_list_append (nodes, node);
+                       }
+       |       ERROR TOKEN '{' errorvals ',' '}' TYPETOKEN ';' {
+                       Node *node = node_new (ERROR_NODE,
+                                              "etype:steal", $<id>7,
+                                              "prefix:steal", $<id>2,
+                                              "values:steal", error_vals,
+                                              NULL);
+                       error_vals = NULL;
+                       nodes = g_list_append (nodes, node);
+                       }
+       ;
+
+errorvals:     errorvals ',' TOKEN     {
+                       error_vals = g_list_append (error_vals, $<id>3);
+               }
+       |       TOKEN                   {
+                       error_vals = g_list_append (error_vals, $<id>1);
+               }
+       ;
+
+
 numtok:                NUMBER                  { $<id>$ = $<id>1; }
        |       '-' NUMBER              {
                        $<id>$ = g_strconcat("-",$<id>2,NULL);