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,
28 #include "treefuncs.h"
33 static int parenth_depth = 0;
34 static int before_comment = INITIAL;
35 static gboolean class_after_c = FALSE;
36 static int code_type = CCODE;
37 static int before_string;
38 static int property_paren_depth = 0;
41 static char *gtk_doc_func = NULL; /* current gtk-doc func */
42 GHashTable *gtk_doc_hash = NULL;
44 static GString *cbuf = NULL;
47 GList *include_files = NULL;
48 /* 0 no, 1 means yes, 2+ means don't even start looking anymore */
49 static int look_for_includes = 0;
52 /* last filename parsed from a #line directive */
53 char *hline_filename = NULL;
59 cbuf = g_string_new(NULL);
61 cbuf = g_string_assign(cbuf, "");
69 cbuf = g_string_new(s);
71 cbuf = g_string_append(cbuf,s);
76 add_gtk_doc_func(void)
82 gtk_doc_hash = g_hash_table_new(g_str_hash, g_str_equal);
83 g_hash_table_insert(gtk_doc_hash, gtk_doc_func, g_strdup(cbuf->str));
89 /* Ugly warning avoiding */
103 %x GTK_DOC_BEFORE_NAME
112 /* Avoid warning from flex, cuz flex sucks */
114 yy_current_state = 0;
119 <*>\n { line_no++; REJECT; }
121 <COMMENT>^(I(S.RI).E\(([1-9][0-9]+|[2-9]))/(\)) {
122 /* Thy evil easter egg */
124 #define KK(x) =atoi(__(&,,x,))
125 #define MM(x,a) {QQ(i);for(i=2;i<x;i++){a}}
126 #define PP(Q) (P%Q)==0
127 #define ___(x,y,z) if(x z y)
128 #define __(a,x,y,z) a(yytext[y] x z)
129 #define O__O(a,b) fprintf(stderr,"%s is %s!\n",a,b)
130 QQ(m)=1;___(__(,==,2,'P'),__(,==,5,'M'),&&
131 ){QQ(P)KK(8);MM(P,___(PP(i),,)m=0;)}__(,=,
132 7,0);___(,,m){O__O(__( &,,8,),__(&,,2,));}
143 \/\/.*$ { ; /*comment, ignore*/ }
145 <*>^#[ \t]*line[ \t]+[0-9]+([ \t]\"[^\n\r\f\"]*\")? {
149 char *str=g_strdup(yytext);
151 /* find first digit of line number */
153 while(*p&&!isdigit(*p)) p++;
156 /* find end of line number */
157 while(*p&&isdigit(*p)) p++;
160 /* find beginning of filename */
165 /* find end of filename */
166 if(p) p=strchr(p,'"');
169 /* stash number (minus one because we don't count this line) */
170 if(number) line_no=atoi(number)-1;
174 if(hline_filename) g_free(hline_filename);
175 hline_filename=g_strdup(filename);
182 <C_CODE>^#[ \t]*include[ \t][<"][^\n">]*[>"] {
183 if(look_for_includes==1) {
186 char *str = g_strdup(yytext);
187 file = strchr(str,'"');
188 if(!file) file = strchr(str,'<');
190 p = strchr(file,'"');
191 if(!p) p = strchr(file,'>');
193 include_files = g_list_prepend(include_files,g_strdup(file));
199 <CLASS_CODE_I>\/\*\*[ \t]*$ {
200 /* eat out gtk doc stuff */
201 BEGIN(GTK_DOC_BEFORE_NAME);
204 <GTK_DOC_BEFORE_NAME>^[ \t]*\*[ \t]*$ {
205 /* empty doc lines */
208 <GTK_DOC_BEFORE_NAME>^[ \t]*\*\ [_a-zA-Z][_a-zA-Z0-9]*:?[ \t]*$ {
211 p = strchr(yytext, '*');
212 g_free(gtk_doc_func);
213 gtk_doc_func = g_strdup(p+2);
214 p = strchr(gtk_doc_func, ':');
216 g_strstrip(gtk_doc_func);
218 <GTK_DOC_BEFORE_NAME>\*\/ {
221 <GTK_DOC_BEFORE_NAME>. {
223 before_comment = CLASS_CODE_I;
225 <GTK_DOC>^[ \t]*\*[ \t]*$ {
226 /* empty doc lines */
229 <GTK_DOC>^[ \t]*\*?\*\/ {
233 <GTK_DOC>^[ \t]*\*\ {
243 before_comment = CLASS_CODE_I;
260 <C_CODE>\/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ }
261 <CLASS_CODE>\/\/.*$ { ; /*comment, ignore*/ }
262 <CLASS_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
263 \/\* {BEGIN(COMMENT); before_comment = INITIAL; }
267 before_comment = C_CODE;
269 <CLASS_CODE>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; }
270 <CLASS_CODE_I>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; }
272 if(before_comment == C_CODE) add_to_cbuf(yytext);
273 BEGIN(before_comment);
276 /* comment, ignore */
277 if(before_comment == C_CODE) add_to_cbuf(yytext);
280 /* comment, ignore */
281 if(before_comment == C_CODE) add_to_cbuf(yytext);
287 class_after_c = FALSE;
290 ccode_line = line_no;
295 class_after_c = FALSE;
298 ccode_line = line_no;
301 ^\%(ht|headertop)\{ {
304 class_after_c = FALSE;
307 ccode_line = line_no;
309 ^\%(ph|privateheader)\{ {
312 class_after_c = FALSE;
315 ccode_line = line_no;
320 class_after_c = FALSE;
323 ccode_line = line_no;
328 class_after_c = FALSE;
331 ccode_line = line_no;
332 if(look_for_includes==0)
339 if(look_for_includes==1)
344 <C_CODE>\'\{\' { add_to_cbuf(yytext); }
345 <C_CODE>\'\\\{\' { add_to_cbuf(yytext); }
346 <C_CODE>\'\}\' { add_to_cbuf(yytext); }
347 <C_CODE>\'\\\}\' { add_to_cbuf(yytext); }
348 <C_CODE>\'\"\' { add_to_cbuf(yytext); }
349 <C_CODE>\'\\\"\' { add_to_cbuf(yytext); }
351 <C_CODE>\\. { add_to_cbuf(yytext); }
356 before_string = C_CODE;
359 <PROPERTY_CODE_I>\" {
361 before_string = PROPERTY_CODE_I;
364 <CODE_STRING>\\. { add_to_cbuf(yytext); }
366 BEGIN(before_string);
368 if (before_string == PROPERTY_CODE_I) {
369 yylval.id = cbuf->str;
370 g_string_free (cbuf, FALSE);
375 <CODE_STRING>. { add_to_cbuf(yytext); }
376 <CODE_STRING>\n { add_to_cbuf(yytext); }
384 if(parenth_depth<0) {
386 } else if(parenth_depth==0 && class_after_c) {
395 <C_CODE>. { add_to_cbuf(yytext); }
396 <C_CODE>\n { add_to_cbuf(yytext); }
399 static int found_classes = 0;
400 look_for_includes = 2;
403 if(++found_classes > 1) {
404 error_print(GOB_ERROR, line_no,
405 "Only one class per file allowed");
411 error { return ERROR; }
412 enum { return ENUM; }
413 flags { return FLAGS; }
415 ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$ {
416 int maj = 0, min = 0, pl = 0;
417 int rmaj = 0, rmin = 0, rpl = 0;
418 int effective_maj = 0;
419 int effective_rmaj = 0;
422 sscanf (VERSION, "%d.%d.%d", &rmaj, &rmin, &rpl);
423 effective_rmaj = rmaj;
425 effective_rmaj = rmaj + 1;
427 p = strchr (yytext,'r');
428 g_assert (p); /* we MUST have found it */
429 sscanf (p, "requires %d.%d.%d", &maj, &min, &pl);
432 effective_maj = maj + 1;
435 (rmaj == maj && rmin < min) ||
436 (rmaj == maj && rmin == min && rpl < pl)) {
437 error_printf (GOB_ERROR, line_no,
438 "GOB version at least %d.%d.%d required "
440 "To upgrade your gob, see: "
441 "http://www.5z.com/jirka/gob.html",
442 maj, min, pl, VERSION);
445 if(effective_rmaj != effective_maj) {
446 error_printf(GOB_ERROR, line_no,
447 "GOB major version %d required "
449 "To upgrade your gob, see: "
450 "http://www.5z.com/jirka/gob.html",
451 effective_maj, VERSION);
456 <CLASS_CODE,CLASS_CODE_I>class|this {
458 error_printf(GOB_WARN, line_no,
459 "'%s' keyword should not "
460 "be used when generating "
466 <CLASS_CODE>from {return FROM;}
468 <CLASS_CODE_I,PROPERTY_CODE_I>void {return VOID;}
469 <CLASS_CODE_I,PROPERTY_CODE_I>struct {return STRUCT;}
470 <CLASS_CODE_I,PROPERTY_CODE_I>union {return UNION;}
471 <CLASS_CODE_I,PROPERTY_CODE_I>enum {return ENUM;}
472 <CLASS_CODE_I,PROPERTY_CODE_I>signed {return SIGNED;}
473 <CLASS_CODE_I,PROPERTY_CODE_I>unsigned {return UNSIGNED;}
474 <CLASS_CODE_I,PROPERTY_CODE_I>long {return LONG;}
475 <CLASS_CODE_I,PROPERTY_CODE_I>short {return SHORT;}
476 <CLASS_CODE_I,PROPERTY_CODE_I>int {return INT;}
477 <CLASS_CODE_I,PROPERTY_CODE_I>float {return FLOAT;}
478 <CLASS_CODE_I,PROPERTY_CODE_I>double {return DOUBLE;}
479 <CLASS_CODE_I,PROPERTY_CODE_I>char {return CHAR;}
480 <CLASS_CODE_I,PROPERTY_CODE_I>const {return CONST;}
482 <CLASS_CODE_I>\.\.\. {return THREEDOTS;}
484 <CLASS_CODE_I>public {yylval.line = line_no; return PUBLIC;}
485 <CLASS_CODE_I>private {yylval.line = line_no; return PRIVATE;}
486 <CLASS_CODE_I>protected {yylval.line = line_no; return PROTECTED;}
487 <CLASS_CODE_I>classwide {yylval.line = line_no; return CLASSWIDE;}
488 <CLASS_CODE_I>argument {yylval.line = line_no; return ARGUMENT;}
489 <CLASS_CODE_I>virtual {yylval.line = line_no; return VIRTUAL;}
490 <CLASS_CODE_I>signal {yylval.line = line_no; return SIGNAL;}
491 <CLASS_CODE_I>override {yylval.line = line_no; return OVERRIDE;}
492 <CLASS_CODE_I>property {
493 yylval.line = line_no;
494 BEGIN(PROPERTY_CODE);
497 <PROPERTY_CODE_I>nick { yylval.line = line_no; return NICK; }
498 <PROPERTY_CODE_I>blurb { yylval.line = line_no; return BLURB; }
499 <PROPERTY_CODE_I>maximum { yylval.line = line_no; return MAXIMUM; }
500 <PROPERTY_CODE_I>minimum { yylval.line = line_no; return MINIMUM; }
501 <PROPERTY_CODE_I>default_value { yylval.line = line_no; return DEFAULT_VALUE; }
502 <PROPERTY_CODE_I>flags { yylval.line = line_no; return FLAGS; }
503 <PROPERTY_CODE_I>type { yylval.line = line_no; return TYPE; }
504 <PROPERTY_CODE_I>flags_type { yylval.line = line_no; return FLAGS_TYPE; }
505 <PROPERTY_CODE_I>enum_type { yylval.line = line_no; return ENUM_TYPE; }
506 <PROPERTY_CODE_I>param_type { yylval.line = line_no; return PARAM_TYPE; }
507 <PROPERTY_CODE_I>boxed_type { yylval.line = line_no; return BOXED_TYPE; }
508 <PROPERTY_CODE_I>object_type { yylval.line = line_no; return OBJECT_TYPE; }
510 yylval.line = line_no;
511 property_paren_depth = 1;
512 BEGIN(PROPERTY_CODE_I);
515 <PROPERTY_CODE_I>[(] {
516 yylval.line = line_no;
517 property_paren_depth++;
520 <PROPERTY_CODE_I>[)] {
521 yylval.line = line_no;
522 property_paren_depth--;
523 if (property_paren_depth == 0) {
529 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>0|[1-9][0-9]*|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+|\.[0-9][0-9]* {
530 yylval.id = g_strdup(yytext);
533 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ {
534 /* this one is for a classname with a namespace */
535 yylval.id = g_strdup(yytext);
538 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>:[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)* {
539 /* this is for a classname with an empty namespace */
540 yylval.id = g_strdup(yytext);
543 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]* {
544 yylval.id = g_strdup(yytext);
547 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>\'\\.\'|\'.\' {
548 yylval.id = g_strdup(yytext);
552 <CLASS_CODE_I>(\[[0-9]*\]|\[[A-Za-z_][A-Za-z0-9_]*\])+ {
553 yylval.id = g_strdup(yytext);
564 class_after_c = TRUE;
565 yylval.line = line_no;
567 ccode_line = line_no;
575 <CLASS_CODE,CLASS_CODE_I,INITIAL,PROPERTY_CODE,PROPERTY_CODE_I>[\f\t ] ; /*ignore*/
578 yylval.line = line_no;
582 <*>[\n\r] ; /*ignore*/
586 /* Ugly warning avoiding */
588 static void warning_avoider(void) G_GNUC_UNUSED;
589 static void warning_avoider(void) {
590 yy_flex_realloc(NULL, 0);