X-Git-Url: https://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/4d534c82fb65897999ade6867534ab952a9bc019..02cf98875fd0b8462ce39778db16cfd347b5c2d0:/src/parse.y diff --git a/src/parse.y b/src/parse.y index 53d32eb..46df2d6 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1,7 +1,7 @@ /* GOB C Preprocessor * Copyright (C) 1999-2000 the Free Software Foundation. * Copyright (C) 2000 Eazel, Inc. - * Copyright (C) 2001-2004 George (Jiri) Lebl + * Copyright (C) 2001-2009 George (Jiri) Lebl * * Author: George Lebl * @@ -22,7 +22,7 @@ */ %{ -#include "config.h" +#include #include #include #include @@ -45,6 +45,7 @@ static GList *flag_vals = NULL; static GList *error_vals = NULL; static gboolean abstract = FALSE; +static gboolean dynamic = FALSE; static char *chunk_size = NULL; static char *bonobo_object_class = NULL; static int glade_xml = FALSE; @@ -65,10 +66,12 @@ static char *initializer = NULL; static int initializer_line = 0; static int glade_widget = FALSE; +static char *funcattrs = NULL; static char *onerror = NULL; static char *defreturn = NULL; static GList *gtktypes = NULL; +static char *signal_name=NULL; static Property *property = NULL; @@ -91,9 +94,10 @@ yyerror(char *str) char *out=NULL; char *p; - if(strcmp(yytext,"\n")==0) { - out=g_strconcat("Error: ",str," before newline",NULL); - } else if(yytext[0]=='\0') { + if (strcmp (yytext, "\n") == 0 || + strcmp (yytext, "\r") == 0) { + out = g_strconcat ("Error: ", str, " before end of line", NULL); + } else if (yytext[0] == '\0') { out=g_strconcat("Error: ", str, " at end of input", NULL); } else { char *tmp = g_strdup(yytext); @@ -155,7 +159,11 @@ push_function (int scope, int method, char *oid, char *id, g_assert(scope != CLASS_SCOPE); - if(method == INIT_METHOD || method == CLASS_INIT_METHOD) { + if(method == INIT_METHOD || + method == CLASS_INIT_METHOD || + method == CONSTRUCTOR_METHOD || + method == DISPOSE_METHOD || + method == FINALIZE_METHOD) { type = (Type *)node_new (TYPE_NODE, "name", "void", NULL); @@ -196,6 +204,13 @@ push_function (int scope, int method, char *oid, char *id, } else c_cbuf = NULL; + if (signal_name == NULL ) + { + GString * buffer=g_string_new(""); + g_string_printf(buffer, "\"%s\"", id); + signal_name = buffer->str; + g_string_free(buffer, FALSE); + } node = node_new (METHOD_NODE, "scope", scope, "method", method, @@ -204,7 +219,9 @@ push_function (int scope, int method, char *oid, char *id, "gtktypes:steal", gtktypes, "flags:steal", flags, "id:steal", id, + "signal_name:steal", signal_name, "args:steal", funcargs, + "funcattrs:steal", funcattrs, "onerror:steal", onerror, "defreturn:steal", defreturn, "cbuf:steal", c_cbuf, @@ -222,8 +239,9 @@ push_function (int scope, int method, char *oid, char *id, above */ c_cbuf?FALSE:TRUE); gtktypes = NULL; + signal_name = NULL; funcargs = NULL; - + funcattrs = NULL; onerror = NULL; defreturn = NULL; @@ -233,6 +251,8 @@ push_function (int scope, int method, char *oid, char *id, static void free_all_global_state(void) { + g_free(funcattrs); + funcattrs = NULL; g_free(onerror); onerror = NULL; g_free(defreturn); @@ -336,9 +356,15 @@ find_var_or_die(const char *id, int line) } static gboolean -set_return_value(char *type, char *val) +set_attr_value(char *type, char *val) { - if(strcmp(type, "onerror")==0) { + if(strcmp(type, "attr")==0) { + if(!funcattrs) { + funcattrs = val; + return TRUE; + } else + return FALSE; + } else if(strcmp(type, "onerror")==0) { if(!onerror) { onerror = val; return TRUE; @@ -390,15 +416,15 @@ export_accessors (const char *var_name, "pointer", "*", NULL); - g_string_sprintf (get_cbuf, - "\t%s%s val; " - "g_object_get (G_OBJECT (self), \"%s\", " - "&val, NULL); " - "return val;\n", - the_type->name, - the_type->pointer ? the_type->pointer : "", - var_name); - + g_string_printf(get_cbuf, + "\t%s%s val; " + "g_object_get (G_OBJECT (self), \"%s\", " + "&val, NULL); " + "return val;\n", + the_type->name, + the_type->pointer ? the_type->pointer : "", + var_name); + typestack = g_list_prepend (typestack, node1); typestack = g_list_prepend (typestack, node3); @@ -425,10 +451,10 @@ export_accessors (const char *var_name, "pointer", "*", NULL); - g_string_sprintf (set_cbuf, - "\tg_object_set (G_OBJECT (self), " - "\"%s\", val, NULL);\n", - var_name); + g_string_printf(set_cbuf, + "\tg_object_set (G_OBJECT (self), " + "\"%s\", val, NULL);\n", + var_name); typestack = g_list_prepend (typestack, node2); typestack = g_list_prepend (typestack, node1); @@ -473,7 +499,6 @@ add_construct_glade (char * file, char * root, char * domain) { Node *var; Type * type; - GList * flags = NULL; type = (Type *)node_new (TYPE_NODE, "name", "GladeXML", @@ -589,9 +614,9 @@ property_link_and_export (Node *node) const char *setcast = ""; char *to_free = NULL; set_func = g_strdup_printf ("g_value_set_%s", prop->gtktype); - g_strdown (set_func); + gob_strdown (set_func); get_func = g_strdup_printf ("g_value_get_%s", prop->gtktype); - g_strdown (get_func); + gob_strdown (get_func); if (for_cpp) { if (strcmp (prop->gtktype, "FLAGS") == 0) { @@ -678,10 +703,10 @@ ensure_property (void) %token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR %token TOKEN NUMBER TYPETOKEN ARRAY_DIM SINGLE_CHAR -%token CCODE HTCODE PHCODE HCODE ACODE ATCODE STRING +%token CCODE CTCODE ADCODE HTCODE PHCODE HCODE ACODE ATCODE STRING %token PUBLIC PRIVATE PROTECTED CLASSWIDE PROPERTY ARGUMENT %token VIRTUAL SIGNAL OVERRIDE -%token NICK BLURB MAXIMUM MINIMUM DEFAULT_VALUE ERROR FLAGS TYPE +%token NAME NICK BLURB MAXIMUM MINIMUM DEFAULT_VALUE ERROR FLAGS TYPE %token FLAGS_TYPE ENUM_TYPE PARAM_TYPE BOXED_TYPE OBJECT_TYPE %% @@ -701,6 +726,15 @@ ccode: CCODE { nodes = g_list_append(nodes,node); g_string_free($1,FALSE); } + | ADCODE { + Node *node = node_new (CCODE_NODE, + "cctype", AD_CCODE, + "cbuf:steal", ($1)->str, + "line_no", ccode_line, + NULL); + nodes = g_list_append(nodes,node); + g_string_free($1,FALSE); + } | HCODE { Node *node = node_new (CCODE_NODE, "cctype", H_CCODE, @@ -746,6 +780,15 @@ ccode: CCODE { nodes = g_list_append(nodes,node); g_string_free($1,FALSE); } + | CTCODE { + Node *node = node_new (CCODE_NODE, + "cctype", CT_CCODE, + "cbuf:steal", ($1)->str, + "line_no", ccode_line, + NULL); + nodes = g_list_append(nodes,node); + g_string_free($1,FALSE); + } ; ccodes: ccodes ccode { ; } @@ -779,6 +822,7 @@ classdec: CLASS TYPETOKEN FROM TYPETOKEN classflags { "interfaces:steal", interfaces, "chunk_size:steal", chunk_size, "abstract", abstract, + "dynamic", dynamic, NULL); bonobo_object_class = NULL; glade_xml = FALSE; @@ -791,6 +835,8 @@ classflags: | '(' TOKEN ')' classflags { if(strcmp($2,"abstract") == 0) { abstract = TRUE; + } else if(strcmp($2,"dynamic") == 0) { + dynamic = TRUE; } else { yyerror(_("parse error")); YYERROR; @@ -1336,7 +1382,13 @@ anyval: numtok { $$ = $1; } | string { $$ = $1; } ; -param_spec_value: NICK '=' string { +param_spec_value: NAME '=' string { + ensure_property (); + node_set ((Node *)property, + "canonical_name:steal", gob_str_delete_quotes($3), + NULL); + } + | NICK '=' string { ensure_property (); node_set ((Node *)property, "nick:steal", $3, @@ -1650,6 +1702,10 @@ fullsigtype: scope TOKEN sigtype { sigtype: TOKEN '(' tokenlist ')' { gtktypes = g_list_prepend(gtktypes, debool ($1)); } + | TOKEN STRING '(' tokenlist ')' { + gtktypes = g_list_prepend(gtktypes, debool ($1)); + signal_name=$2; + } ; tokenlist: tokenlist ',' TOKEN { @@ -1665,7 +1721,7 @@ codenocode: '{' CCODE { $$ = $2; } ; /*here CCODE will include the ending '}' */ -method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' returnvals codenocode { +method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' methodmods codenocode { if(!has_self) { yyerror(_("signal without 'self' as " "first parameter")); @@ -1677,11 +1733,18 @@ method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' returnvals codenoc free_all_global_state(); YYERROR; } + if (funcattrs != NULL) { + char *error = g_strdup_printf + (_("function attribute macros ('%s' in this case) may not be used with signal methods"), + funcattrs); + yyerror (error); + YYERROR; + } push_function(the_scope, $3,NULL, $5, $10,$1, ccode_line, vararg, $2); } - | scope SIGNAL flags simplesigtype type TOKEN '(' funcargs ')' returnvals codenocode { + | scope SIGNAL flags simplesigtype type TOKEN '(' funcargs ')' methodmods codenocode { if(!has_self) { yyerror(_("signal without 'self' as " "first parameter")); @@ -1693,11 +1756,18 @@ method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' returnvals codenoc free_all_global_state(); YYERROR; } + if (funcattrs != NULL) { + char *error = g_strdup_printf + (_("function attribute macros ('%s' in this case) may not be used with signal methods"), + funcattrs); + yyerror (error); + YYERROR; + } push_function(the_scope, $4, NULL, $6, $11, $2, ccode_line, vararg, $3); } - | VIRTUAL scope type TOKEN '(' funcargs ')' returnvals codenocode { + | VIRTUAL scope type TOKEN '(' funcargs ')' methodmods codenocode { if(!has_self) { yyerror(_("virtual method without 'self' as " "first parameter")); @@ -1709,11 +1779,18 @@ method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' returnvals codenoc free_all_global_state(); YYERROR; } + if (funcattrs != NULL) { + char *error = g_strdup_printf + (_("function attribute macros ('%s' in this case) may not be used with virtual methods"), + funcattrs); + yyerror (error); + YYERROR; + } push_function(the_scope, VIRTUAL_METHOD, NULL, $4, $9, $1, ccode_line, vararg, NULL); } - | scope VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode { + | scope VIRTUAL type TOKEN '(' funcargs ')' methodmods codenocode { if(!has_self) { yyerror(_("virtual method without 'self' as " "first parameter")); @@ -1725,28 +1802,49 @@ method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' returnvals codenoc free_all_global_state(); YYERROR; } + if (funcattrs != NULL) { + char *error = g_strdup_printf + (_("function attribute macros ('%s' in this case) may not be used with virtual methods"), + funcattrs); + yyerror (error); + YYERROR; + } push_function(the_scope, VIRTUAL_METHOD, NULL, $4, $9, $2, ccode_line, vararg, NULL); } - | VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode { + | VIRTUAL type TOKEN '(' funcargs ')' methodmods codenocode { if(!has_self) { - yyerror(_("virtual method without 'self' as " + yyerror(_("virtual method without 'szelf' as " "first parameter")); free_all_global_state(); YYERROR; } + if (funcattrs != NULL) { + char *error = g_strdup_printf + (_("function attribute macros ('%s' in this case) may not be used with virtual methods"), + funcattrs); + yyerror (error); + YYERROR; + } push_function(PUBLIC_SCOPE, VIRTUAL_METHOD, NULL, $3, $8, $1, ccode_line, vararg, NULL); } - | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' returnvals codenocode { + | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' methodmods codenocode { + if (funcattrs != NULL) { + char *error = g_strdup_printf + (_("function attribute macros ('%s' in this case) may not be used with override methods"), + funcattrs); + yyerror (error); + YYERROR; + } push_function(NO_SCOPE, OVERRIDE_METHOD, $3, $6, $11, $1, ccode_line, vararg, NULL); } - | scope type TOKEN '(' funcargs ')' returnvals codenocode { + | scope type TOKEN '(' funcargs ')' methodmods codenocode { if(the_scope == CLASS_SCOPE) { yyerror(_("a method cannot be of class scope")); free_all_global_state(); @@ -1767,22 +1865,40 @@ method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' returnvals codenoc push_function(NO_SCOPE, CLASS_INIT_METHOD, NULL, $1, $5, $2, ccode_line, FALSE, NULL); + } else if(strcmp($1, "constructor")==0) { + push_init_arg($3, FALSE); + push_function(NO_SCOPE, CONSTRUCTOR_METHOD, NULL, + $1, $5, $2, + ccode_line, FALSE, NULL); + } else if(strcmp($1, "dispose")==0) { + push_init_arg($3, FALSE); + push_function(NO_SCOPE, DISPOSE_METHOD, NULL, + $1, $5, $2, + ccode_line, FALSE, NULL); + } else if(strcmp($1, "finalize")==0) { + push_init_arg($3, FALSE); + push_function(NO_SCOPE, FINALIZE_METHOD, NULL, + $1, $5, $2, + ccode_line, FALSE, NULL); + } else { g_free($1); g_free($3); g_string_free($5,TRUE); yyerror(_("parse error " - "(untyped blocks must be init or " - "class_init)")); + "(untyped blocks must be init, " + "class_init, constructor, dispose " + "or finalize)")); YYERROR; } } ; -returnvals: TOKEN retcode { +methodmods: TOKEN retcode { + g_free(funcattrs); funcattrs = NULL; g_free(onerror); onerror = NULL; g_free(defreturn); defreturn = NULL; - if(!set_return_value($1, $2)) { + if(!set_attr_value($1, $2)) { g_free($1); g_free($2); yyerror(_("parse error")); @@ -1791,25 +1907,58 @@ returnvals: TOKEN retcode { g_free($1); } | TOKEN retcode TOKEN retcode { + g_free(funcattrs); funcattrs = NULL; + g_free(onerror); onerror = NULL; + g_free(defreturn); defreturn = NULL; + if(!set_attr_value($1, $2)) { + g_free($1); g_free($2); + g_free($3); g_free($4); + yyerror(_("parse error")); + YYERROR; + } + if(!set_attr_value($3, $4)) { + funcattrs = onerror = defreturn = NULL; + g_free($1); g_free($2); + g_free($3); g_free($4); + yyerror(_("parse error")); + YYERROR; + } + g_free($1); + g_free($3); + } + | TOKEN retcode TOKEN retcode TOKEN retcode { + g_free(funcattrs); funcattrs = NULL; g_free(onerror); onerror = NULL; g_free(defreturn); defreturn = NULL; - if(!set_return_value($1, $2)) { + if(!set_attr_value($1, $2)) { g_free($1); g_free($2); g_free($3); g_free($4); + g_free($5); g_free($6); yyerror(_("parse error")); YYERROR; } - if(!set_return_value($3, $4)) { - onerror = defreturn = NULL; + if(!set_attr_value($3, $4)) { + funcattrs = onerror = defreturn = NULL; g_free($1); g_free($2); g_free($3); g_free($4); + g_free($5); g_free($6); + yyerror(_("parse error")); + YYERROR; + } + if(!set_attr_value($5, $6)) { + funcattrs = onerror = defreturn = NULL; + g_free($1); g_free($2); + g_free($3); g_free($4); + g_free($5); g_free($6); yyerror(_("parse error")); YYERROR; } g_free($1); g_free($3); + g_free($5); } | { + g_free(funcattrs); funcattrs = NULL; g_free(onerror); onerror = NULL; g_free(defreturn); defreturn = NULL; }