2 * Copyright (C) 1999 the Free Software Foundation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include "treefuncs.h"
32 static int parenth_depth = 0;
33 static int before_comment = INITIAL;
34 static gboolean class_after_c = FALSE;
35 static int code_type = CCODE;
36 static int before_string;
37 static int property_paren_depth = 0;
40 static char *gtk_doc_func = NULL; /* current gtk-doc func */
41 GHashTable *gtk_doc_hash = NULL;
43 static GString *cbuf = NULL;
46 GList *include_files = NULL;
47 /* 0 no, 1 means yes, 2+ means don't even start looking anymore */
48 static int look_for_includes = 0;
56 cbuf = g_string_new(NULL);
58 cbuf = g_string_assign(cbuf, "");
66 cbuf = g_string_new(s);
68 cbuf = g_string_append(cbuf,s);
73 add_gtk_doc_func(void)
79 gtk_doc_hash = g_hash_table_new(g_str_hash, g_str_equal);
80 g_hash_table_insert(gtk_doc_hash, gtk_doc_func, g_strdup(cbuf->str));
86 /* Ugly warning avoiding */
100 %x GTK_DOC_BEFORE_NAME
109 /* Avoid warning from flex, cuz flex sucks */
111 yy_current_state = 0;
116 <*>\n { line_no++; REJECT; }
118 <COMMENT>^(I(S.RI).E\(([1-9][0-9]+|[2-9]))/(\)) {
119 /* Thy evil easter egg */
121 #define KK(x) =atoi(__(&,,x,))
122 #define MM(x,a) {QQ(i);for(i=2;i<x;i++){a}}
123 #define PP(Q) (P%Q)==0
124 #define ___(x,y,z) if(x z y)
125 #define __(a,x,y,z) a(yytext[y] x z)
126 #define O__O(a,b) fprintf(stderr,"%s is %s!\n",a,b)
127 QQ(m)=1;___(__(,==,2,'P'),__(,==,5,'M'),&&
128 ){QQ(P)KK(8);MM(P,___(PP(i),,)m=0;)}__(,=,
129 7,0);___(,,m){O__O(__( &,,8,),__(&,,2,));}
140 \/\/.*$ { ; /*comment, ignore*/ }
141 <C_CODE>^#[ \t]*include[ \t][<"][^\n">]*[>"] {
142 if(look_for_includes==1) {
145 char *str = g_strdup(yytext);
146 file = strchr(str,'"');
147 if(!file) file = strchr(str,'<');
149 p = strchr(file,'"');
150 if(!p) p = strchr(file,'>');
152 include_files = g_list_prepend(include_files,g_strdup(file));
158 <CLASS_CODE_I>\/\*\*[ \t]*$ {
159 /* eat out gtk doc stuff */
160 BEGIN(GTK_DOC_BEFORE_NAME);
163 <GTK_DOC_BEFORE_NAME>^[ \t]*\*[ \t]*$ {
164 /* empty doc lines */
167 <GTK_DOC_BEFORE_NAME>^[ \t]*\*\ [_a-zA-Z][_a-zA-Z0-9]*:?[ \t]*$ {
170 p = strchr(yytext, '*');
171 g_free(gtk_doc_func);
172 gtk_doc_func = g_strdup(p+2);
173 p = strchr(gtk_doc_func, ':');
175 g_strstrip(gtk_doc_func);
177 <GTK_DOC_BEFORE_NAME>\*\/ {
180 <GTK_DOC_BEFORE_NAME>. {
182 before_comment = CLASS_CODE_I;
184 <GTK_DOC>^[ \t]*\*[ \t]*$ {
185 /* empty doc lines */
188 <GTK_DOC>^[ \t]*\*?\*\/ {
192 <GTK_DOC>^[ \t]*\*\ {
202 before_comment = CLASS_CODE_I;
219 <C_CODE>\/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ }
220 <CLASS_CODE>\/\/.*$ { ; /*comment, ignore*/ }
221 <CLASS_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
222 \/\* {BEGIN(COMMENT); before_comment = INITIAL; }
226 before_comment = C_CODE;
228 <CLASS_CODE>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; }
229 <CLASS_CODE_I>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; }
231 if(before_comment == C_CODE) add_to_cbuf(yytext);
232 BEGIN(before_comment);
235 /* comment, ignore */
236 if(before_comment == C_CODE) add_to_cbuf(yytext);
239 /* comment, ignore */
240 if(before_comment == C_CODE) add_to_cbuf(yytext);
246 class_after_c = FALSE;
249 ccode_line = line_no;
254 class_after_c = FALSE;
257 ccode_line = line_no;
260 ^\%(ht|headertop)\{ {
263 class_after_c = FALSE;
266 ccode_line = line_no;
268 ^\%(ph|privateheader)\{ {
271 class_after_c = FALSE;
274 ccode_line = line_no;
279 class_after_c = FALSE;
282 ccode_line = line_no;
287 class_after_c = FALSE;
290 ccode_line = line_no;
291 if(look_for_includes==0)
298 if(look_for_includes==1)
303 <C_CODE>\'\{\' { add_to_cbuf(yytext); }
304 <C_CODE>\'\\\{\' { add_to_cbuf(yytext); }
305 <C_CODE>\'\}\' { add_to_cbuf(yytext); }
306 <C_CODE>\'\\\}\' { add_to_cbuf(yytext); }
307 <C_CODE>\'\"\' { add_to_cbuf(yytext); }
308 <C_CODE>\'\\\"\' { add_to_cbuf(yytext); }
310 <C_CODE>\\. { add_to_cbuf(yytext); }
315 before_string = C_CODE;
318 <PROPERTY_CODE_I>\" {
320 before_string = PROPERTY_CODE_I;
323 <CODE_STRING>\\. { add_to_cbuf(yytext); }
325 BEGIN(before_string);
327 if (before_string == PROPERTY_CODE_I) {
328 yylval.id = cbuf->str;
329 g_string_free (cbuf, FALSE);
334 <CODE_STRING>. { add_to_cbuf(yytext); }
335 <CODE_STRING>\n { add_to_cbuf(yytext); }
343 if(parenth_depth<0) {
345 } else if(parenth_depth==0 && class_after_c) {
354 <C_CODE>. { add_to_cbuf(yytext); }
355 <C_CODE>\n { add_to_cbuf(yytext); }
358 static int found_classes = 0;
359 look_for_includes = 2;
362 if(++found_classes > 1) {
363 error_print(GOB_ERROR, line_no,
364 "Only one class per file allowed");
370 ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$ {
371 int maj = 0, min = 0, pl = 0;
372 int rmaj = 0, rmin = 0, rpl = 0;
373 int effective_maj = 0;
374 int effective_rmaj = 0;
377 sscanf (VERSION, "%d.%d.%d", &rmaj, &rmin, &rpl);
378 effective_rmaj = rmaj;
380 effective_rmaj = rmaj + 1;
382 p = strchr (yytext,'r');
383 g_assert (p); /* we MUST have found it */
384 sscanf (p, "requires %d.%d.%d", &maj, &min, &pl);
387 effective_maj = maj + 1;
390 (rmaj == maj && rmin < min) ||
391 (rmaj == maj && rmin == min && rpl < pl)) {
392 error_printf (GOB_ERROR, line_no,
393 "GOB version at least %d.%d.%d required "
395 "To upgrade your gob, see: "
396 "http://www.5z.com/jirka/gob.html",
397 maj, min, pl, VERSION);
400 if(effective_rmaj != effective_maj) {
401 error_printf(GOB_ERROR, line_no,
402 "GOB major version %d required "
404 "To upgrade your gob, see: "
405 "http://www.5z.com/jirka/gob.html",
411 <CLASS_CODE,CLASS_CODE_I>class|this {
413 error_printf(GOB_WARN, line_no,
414 "'%s' keyword should not "
415 "be used when generating "
421 <CLASS_CODE>from {return FROM;}
423 <CLASS_CODE_I,PROPERTY_CODE_I>void {return VOID;}
424 <CLASS_CODE_I,PROPERTY_CODE_I>struct {return STRUCT;}
425 <CLASS_CODE_I,PROPERTY_CODE_I>union {return UNION;}
426 <CLASS_CODE_I,PROPERTY_CODE_I>enum {return ENUM;}
427 <CLASS_CODE_I,PROPERTY_CODE_I>signed {return SIGNED;}
428 <CLASS_CODE_I,PROPERTY_CODE_I>unsigned {return UNSIGNED;}
429 <CLASS_CODE_I,PROPERTY_CODE_I>long {return LONG;}
430 <CLASS_CODE_I,PROPERTY_CODE_I>short {return SHORT;}
431 <CLASS_CODE_I,PROPERTY_CODE_I>int {return INT;}
432 <CLASS_CODE_I,PROPERTY_CODE_I>float {return FLOAT;}
433 <CLASS_CODE_I,PROPERTY_CODE_I>double {return DOUBLE;}
434 <CLASS_CODE_I,PROPERTY_CODE_I>char {return CHAR;}
435 <CLASS_CODE_I,PROPERTY_CODE_I>const {return CONST;}
437 <CLASS_CODE_I>\.\.\. {return THREEDOTS;}
439 <CLASS_CODE_I>public {yylval.line = line_no; return PUBLIC;}
440 <CLASS_CODE_I>private {yylval.line = line_no; return PRIVATE;}
441 <CLASS_CODE_I>protected {yylval.line = line_no; return PROTECTED;}
442 <CLASS_CODE_I>classwide {yylval.line = line_no; return CLASSWIDE;}
443 <CLASS_CODE_I>argument {yylval.line = line_no; return ARGUMENT;}
444 <CLASS_CODE_I>virtual {yylval.line = line_no; return VIRTUAL;}
445 <CLASS_CODE_I>signal {yylval.line = line_no; return SIGNAL;}
446 <CLASS_CODE_I>override {yylval.line = line_no; return OVERRIDE;}
447 <CLASS_CODE_I>property {
448 yylval.line = line_no;
449 BEGIN(PROPERTY_CODE);
452 <PROPERTY_CODE_I>nick { yylval.line = line_no; return NICK; }
453 <PROPERTY_CODE_I>blurb { yylval.line = line_no; return BLURB; }
454 <PROPERTY_CODE_I>maximum { yylval.line = line_no; return MAXIMUM; }
455 <PROPERTY_CODE_I>minimum { yylval.line = line_no; return MINIMUM; }
456 <PROPERTY_CODE_I>default_value { yylval.line = line_no; return DEFAULT_VALUE; }
457 <PROPERTY_CODE_I>flags { yylval.line = line_no; return FLAGS; }
458 <PROPERTY_CODE_I>type { yylval.line = line_no; return TYPE; }
459 <PROPERTY_CODE_I>flags_type { yylval.line = line_no; return FLAGS_TYPE; }
460 <PROPERTY_CODE_I>enum_type { yylval.line = line_no; return ENUM_TYPE; }
461 <PROPERTY_CODE_I>param_type { yylval.line = line_no; return PARAM_TYPE; }
462 <PROPERTY_CODE_I>boxed_type { yylval.line = line_no; return BOXED_TYPE; }
463 <PROPERTY_CODE_I>object_type { yylval.line = line_no; return OBJECT_TYPE; }
465 yylval.line = line_no;
466 property_paren_depth = 1;
467 BEGIN(PROPERTY_CODE_I);
470 <PROPERTY_CODE_I>[(] {
471 yylval.line = line_no;
472 property_paren_depth++;
475 <PROPERTY_CODE_I>[)] {
476 yylval.line = line_no;
477 property_paren_depth--;
478 if (property_paren_depth == 0) {
484 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I>0|[1-9][0-9]*|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+|\.[0-9][0-9]* {
485 yylval.id = g_strdup(yytext);
488 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I>[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ {
489 /* this one is for a classname with a namespace */
490 yylval.id = g_strdup(yytext);
493 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I>:[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)* {
494 /* this is for a classname with an empty namespace */
495 yylval.id = g_strdup(yytext);
498 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I>[A-Za-z_][A-Za-z0-9_]* {
499 yylval.id = g_strdup(yytext);
502 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I>\'\\.\'|\'.\' {
503 yylval.id = g_strdup(yytext);
507 <CLASS_CODE_I>(\[[0-9]*\]|\[[A-Za-z_][A-Za-z0-9_]*\])+ {
508 yylval.id = g_strdup(yytext);
519 class_after_c = TRUE;
520 yylval.line = line_no;
522 ccode_line = line_no;
530 <CLASS_CODE,CLASS_CODE_I,INITIAL,PROPERTY_CODE,PROPERTY_CODE_I>[\t ] ; /*ignore*/
533 yylval.line = line_no;
537 <*>[\n\r] ; /*ignore*/
541 /* Ugly warning avoiding */
543 static void warning_avoider(void) G_GNUC_UNUSED;
544 static void warning_avoider(void) {
545 yy_flex_realloc(NULL, 0);