]> git.draconx.ca Git - gob-dx.git/blobdiff - src/parse.y
Release 0.92.4
[gob-dx.git] / src / parse.y
index f4c4a409f7bfc7c5089813b8f3f452e813071ff5..63f0a7a1d21e743c9051b6c571785fe2ed23c3a0 100644 (file)
 
 #include "tree.h"
 #include "main.h"
+#include "util.h"
 
 #define _(x) (x)
        
-extern char *filename;
-       
 GList *nodes = NULL;
 
 static GList *class_nodes = NULL;
@@ -83,12 +82,19 @@ yyerror(char *str)
        exit(1);
 }
 
+static Type *
+pop_type(void)
+{
+       Type *type = typestack->data;
+       typestack = g_list_remove(typestack,typestack->data);
+       return type;
+}
+
 static void
 push_variable(char *name, int scope, int line_no, char *postfix)
 {
        Node *var;
-       Type *type = typestack->data;
-       typestack = g_list_remove(typestack,typestack->data);
+       Type *type = pop_type();
 
        type->postfix = postfix;
        
@@ -98,15 +104,15 @@ push_variable(char *name, int scope, int line_no, char *postfix)
 
 static void
 push_function(int scope, int method, char *oid, char *id, char *onerror,
-             GString *cbuf,int line_no, int ccode_line, int vararg)
+             GString *cbuf, int line_no, int ccode_line, gboolean vararg,
+             GList *flags)
 {
        Node *node;
        Type *type;
        char *c_cbuf;
        
        if(method!=INIT_METHOD && method!=CLASS_INIT_METHOD) {
-               type = typestack->data;
-               typestack = g_list_remove(typestack,typestack->data);
+               type = pop_type();
        } else {
                type = (Type *)new_type(0,g_strdup("void"),NULL);
        }
@@ -133,8 +139,9 @@ push_function(int scope, int method, char *oid, char *id, char *onerror,
        } else
                c_cbuf = NULL;
 
-       node = new_method(scope,method,type,oid,gtktypes,id,funcargs,
-                         onerror,c_cbuf,line_no,ccode_line,vararg);
+       node = new_method(scope, method, type, oid, gtktypes, flags,
+                         id, funcargs, onerror, c_cbuf, line_no,
+                         ccode_line, vararg);
 
        if(cbuf)
                g_string_free(cbuf,
@@ -151,8 +158,7 @@ static void
 push_funcarg(char *name, char *postfix)
 {
        Node *node;
-       Type *type = typestack->data;
-       typestack = g_list_remove(typestack,typestack->data);
+       Type *type = pop_type();
 
        type->postfix = postfix;
        
@@ -208,7 +214,7 @@ push_self(char *id)
 %token ONERROR
 
 %token <id> TOKEN NUMBER TYPETOKEN ARRAY_DIM
-%token <cbuf> CCODE HCODE
+%token <cbuf> CCODE HTCODE PHCODE HCODE ACODE ATCODE
 %token <line> PUBLIC PRIVATE PROTECTED ARGUMENT VIRTUAL SIGNAL OVERRIDE
 
 %%
@@ -219,28 +225,46 @@ prog:             ccodes class ccodes     { ; }
        |       class                   { ; }
        ;
 
-ccodes:                ccodes CCODE            {
-                       Node *node = new_ccode(FALSE,($<cbuf>2)->str,
+ccode:         CCODE                   {
+                       Node *node = new_ccode(C_CCODE,($<cbuf>1)->str,
                                               ccode_line);
                        nodes = g_list_append(nodes,node);
-                       g_string_free($<cbuf>2,FALSE);
+                       g_string_free($<cbuf>1,FALSE);
                                        }
-       |       ccodes HCODE            {
-                       Node *node = new_ccode(TRUE,($<cbuf>2)->str,ccode_line);
+       |       HCODE                   {
+                       Node *node = new_ccode(H_CCODE,($<cbuf>1)->str,
+                                              ccode_line);
                        nodes = g_list_append(nodes,node);
-                       g_string_free($<cbuf>2,FALSE);
+                       g_string_free($<cbuf>1,FALSE);
                                        }
-       |       CCODE                   {
-                       Node *node = new_ccode(FALSE,($<cbuf>1)->str,
+       |       HTCODE                  {
+                       Node *node = new_ccode(HT_CCODE,($<cbuf>1)->str,
                                               ccode_line);
                        nodes = g_list_append(nodes,node);
                        g_string_free($<cbuf>1,FALSE);
                                        }
-       |       HCODE                   {
-                       Node *node = new_ccode(TRUE,($<cbuf>1)->str,ccode_line);
+       |       PHCODE                  {
+                       Node *node = new_ccode(PH_CCODE,($<cbuf>1)->str,
+                                              ccode_line);
+                       nodes = g_list_append(nodes,node);
+                       g_string_free($<cbuf>1,FALSE);
+                                       }
+       |       ACODE                   {
+                       Node *node = new_ccode(A_CCODE,($<cbuf>1)->str,
+                                              ccode_line);
                        nodes = g_list_append(nodes,node);
                        g_string_free($<cbuf>1,FALSE);
                                        }
+       |       ATCODE                  {
+                       Node *node = new_ccode(AT_CCODE,($<cbuf>1)->str,
+                                              ccode_line);
+                       nodes = g_list_append(nodes,node);
+                       g_string_free($<cbuf>1,FALSE);
+                                       }
+       ;
+
+ccodes:                ccodes ccode            { ; }
+       |       ccode                   { ; }
        ;
 
 class:         classdec '{' classcode '}'      {
@@ -280,12 +304,13 @@ variable: scope type TOKEN ';'            {
                        push_variable($<id>3,the_scope,$<line>1,$<id>4);
                                                }
        ;
-argument:      ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE TOKEN '{' CCODE ';' {
+argument:      ARGUMENT flags argtype TOKEN TOKEN '{' CCODE TOKEN '{' CCODE ';' {
                        if(strcmp($<id>5,"get")==0 &&
                           strcmp($<id>8,"set")==0) {
                                Node *node;
+                               Type *type = pop_type();
                                g_free($<id>5); g_free($<id>8);
-                               node = new_argument($<id>3,$<list>2,$<id>4,
+                               node = new_argument($<id>3,type,$<list>2,$<id>4,
                                                    ($<cbuf>7)->str,$<line>6,
                                                    ($<cbuf>10)->str,$<line>9,
                                                    $<line>1);
@@ -295,8 +320,9 @@ argument:   ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE TOKEN '{' CCODE ';' {
                        } else if(strcmp($<id>5,"set")==0 &&
                                strcmp($<id>8,"get")==0) {
                                Node *node;
+                               Type *type = pop_type();
                                g_free($<id>5); g_free($<id>8);
-                               node = new_argument($<id>3,$<list>2,$<id>4,
+                               node = new_argument($<id>3,type,$<list>2,$<id>4,
                                                    ($<cbuf>10)->str,$<line>9,
                                                    ($<cbuf>7)->str,$<line>6,
                                                    $<line>1);
@@ -313,19 +339,21 @@ argument: ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE TOKEN '{' CCODE ';' {
                                YYERROR;
                        }
                                                }
-       |       ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE ';' {
+       |       ARGUMENT flags argtype TOKEN TOKEN '{' CCODE ';' {
                        if(strcmp($<id>5,"get")==0) {
                                Node *node;
+                               Type *type = pop_type();
                                g_free($<id>5);
-                               node = new_argument($<id>3,$<list>2,$<id>4,
+                               node = new_argument($<id>3,type,$<list>2,$<id>4,
                                                    ($<cbuf>7)->str,$<line>6,
                                                    NULL,0, $<line>1);
                                g_string_free($<cbuf>7,FALSE);
                                class_nodes = g_list_append(class_nodes,node);
                        } else if(strcmp($<id>5,"set")==0) {
                                Node *node;
+                               Type *type = pop_type();
                                g_free($<id>5);
-                               node = new_argument($<id>3,$<list>2,$<id>4,
+                               node = new_argument($<id>3,type,$<list>2,$<id>4,
                                                    NULL,0,($<cbuf>7)->str,
                                                    $<line>6, $<line>1);
                                g_string_free($<cbuf>7,FALSE);
@@ -340,8 +368,23 @@ argument:  ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE TOKEN '{' CCODE ';' {
                        }
                                                }
        ;
+
+argtype:       TOKEN '(' TOKEN type ')'        {
+                       if(strcmp($<id>3,"type")!=0) {
+                               g_free($<id>1);
+                               g_free($<id>3);
+                               yyerror(_("parse error"));
+                               YYERROR;
+                       }
+                       $<id>$ = $<id>1;
+                                               }
+       |       TOKEN                           {
+                       $<id>$ = $<id>1;
+                       typestack = g_list_prepend(typestack,NULL);
+                                               }
+       ;
        
-argflags:      '(' flaglist ')'                { $<list>$ = $<list>2; }
+flags:         '(' flaglist ')'                { $<list>$ = $<list>2; }
        |                                       { $<list>$ = NULL; }
        ;
 
@@ -515,25 +558,25 @@ codenocode:       '{' CCODE                       { $<cbuf>$ = $<cbuf>2; }
        ;
 
 /*here CCODE will include the ending '}' */
-method:                SIGNAL fullsigtype type TOKEN '(' funcargs ')' onerror codenocode {
+method:                SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' onerror codenocode {
                        if(!has_self) {
                                yyerror(_("signal without 'self' as "
                                          "first parameter"));
                                YYERROR;
                        }
-                       push_function(the_scope, $<sigtype>2,NULL,
-                                     $<id>4, $<id>8, $<cbuf>9,$<line>1,
-                                     ccode_line,vararg);
+                       push_function(the_scope, $<sigtype>3,NULL,
+                                     $<id>5, $<id>9, $<cbuf>10,$<line>1,
+                                     ccode_line, vararg, $<list>2);
                                                                        }
-       |       scope SIGNAL simplesigtype type TOKEN '(' funcargs ')' onerror codenocode {
+       |       scope SIGNAL flags simplesigtype type TOKEN '(' funcargs ')' onerror codenocode {
                        if(!has_self) {
                                yyerror(_("signal without 'self' as "
                                          "first parameter"));
                                YYERROR;
                        }
-                       push_function(the_scope, $<sigtype>3,NULL,
-                                     $<id>5, $<id>9, $<cbuf>10,$<line>2,
-                                     ccode_line,vararg);
+                       push_function(the_scope, $<sigtype>4, NULL,
+                                     $<id>6, $<id>10, $<cbuf>11, $<line>2,
+                                     ccode_line, vararg, $<list>3);
                                                                        }
        |       VIRTUAL scope type TOKEN '(' funcargs ')' onerror codenocode    {
                        if(!has_self) {
@@ -542,8 +585,8 @@ method:             SIGNAL fullsigtype type TOKEN '(' funcargs ')' onerror codenocode {
                                YYERROR;
                        }
                        push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
-                                     $<id>8, $<cbuf>9,$<line>1,
-                                     ccode_line,vararg);
+                                     $<id>8, $<cbuf>9, $<line>1,
+                                     ccode_line, vararg, NULL);
                                                                        }
        |       scope VIRTUAL type TOKEN '(' funcargs ')' onerror codenocode    {
                        if(!has_self) {
@@ -552,8 +595,8 @@ method:             SIGNAL fullsigtype type TOKEN '(' funcargs ')' onerror codenocode {
                                YYERROR;
                        }
                        push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
-                                     $<id>8, $<cbuf>9,$<line>2,
-                                     ccode_line,vararg);
+                                     $<id>8, $<cbuf>9, $<line>2,
+                                     ccode_line, vararg, NULL);
                                                                        }
        |       VIRTUAL type TOKEN '(' funcargs ')' onerror codenocode  {
                        if(!has_self) {
@@ -562,31 +605,31 @@ method:           SIGNAL fullsigtype type TOKEN '(' funcargs ')' onerror codenocode {
                                YYERROR;
                        }
                        push_function(PUBLIC_SCOPE, VIRTUAL_METHOD, NULL,
-                                     $<id>3, $<id>7, $<cbuf>8,$<line>1,
-                                     ccode_line,vararg);
+                                     $<id>3, $<id>7, $<cbuf>8, $<line>1,
+                                     ccode_line, vararg, NULL);
                                                                        }
        |       OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' onerror codenocode       {
                        push_function(NO_SCOPE, OVERRIDE_METHOD, $<id>3,
                                      $<id>6, $<id>10, $<cbuf>11,
-                                     $<line>1,ccode_line,
-                                     vararg);
+                                     $<line>1, ccode_line,
+                                     vararg, NULL);
                                                                        }
        |       scope type TOKEN '(' funcargs ')' onerror codenocode    {
                        push_function(the_scope, REGULAR_METHOD, NULL, $<id>3,
-                                     $<id>7, $<cbuf>8,$<line>1,ccode_line,
-                                     vararg);
+                                     $<id>7, $<cbuf>8, $<line>1, ccode_line,
+                                     vararg, NULL);
                                                                }
        |       TOKEN '(' TOKEN ')' codenocode  {
                        if(strcmp($<id>1,"init")==0) {
                                push_init_arg($<id>3,FALSE);
                                push_function(NO_SCOPE, INIT_METHOD, NULL,
-                                             $<id>1, NULL, $<cbuf>5,$<line>2,
-                                             ccode_line,FALSE);
+                                             $<id>1, NULL, $<cbuf>5, $<line>2,
+                                             ccode_line, FALSE, NULL);
                        } else if(strcmp($<id>1,"class_init")==0) {
                                push_init_arg($<id>3,TRUE);
                                push_function(NO_SCOPE, CLASS_INIT_METHOD, NULL,
-                                             $<id>1, NULL, $<cbuf>5,$<line>2,
-                                             ccode_line,FALSE);
+                                             $<id>1, NULL, $<cbuf>5, $<line>2,
+                                             ccode_line, FALSE, NULL);
                        } else {
                                g_free($<id>1);
                                g_free($<id>3);