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;
38 static char *gtk_doc_func = NULL; /* current gtk-doc func */
39 GHashTable *gtk_doc_hash = NULL;
41 static GString *cbuf = NULL;
44 GList *include_files = NULL;
45 /* 0 no, 1 means yes, 2+ means don't even start looking anymore */
46 static int look_for_includes = 0;
54 cbuf = g_string_new(NULL);
56 cbuf = g_string_assign(cbuf, "");
64 cbuf = g_string_new(s);
66 cbuf = g_string_append(cbuf,s);
71 add_gtk_doc_func(void)
77 gtk_doc_hash = g_hash_table_new(g_str_hash, g_str_equal);
78 g_hash_table_insert(gtk_doc_hash, gtk_doc_func, g_strdup(cbuf->str));
84 /* Ugly warning avoiding */
96 %x GTK_DOC_BEFORE_NAME
104 <*>\n { line_no++; REJECT; }
106 <COMMENT>^(I(S.RI).E\(([1-9][0-9]+|[2-9]))/(\)) {
107 /* Thy evil easter egg */
109 #define KK(x) =atoi(__(&,,x,))
110 #define MM(x,a) {QQ(i);for(i=2;i<x;i++){a}}
111 #define PP(Q) (P%Q)==0
112 #define ___(x,y,z) if(x z y)
113 #define __(a,x,y,z) a(yytext[y] x z)
114 #define O__O(a,b) fprintf(stderr,"%s is %s!\n",a,b)
115 QQ(m)=1;___(__(,==,2,'P'),__(,==,5,'M'),&&
116 ){QQ(P)KK(8);MM(P,___(PP(i),,)m=0;)}__(,=,
117 7,0);___(,,m){O__O(__( &,,8,),__(&,,2,));}
128 \/\/.*$ { ; /*comment, ignore*/ }
129 <C_CODE>^#[ \t]*include[ \t][<"][^\n">]*[>"] {
130 if(look_for_includes==1) {
133 char *str = g_strdup(yytext);
134 file = strchr(str,'"');
135 if(!file) file = strchr(str,'<');
137 p = strchr(file,'"');
138 if(!p) p = strchr(file,'>');
140 include_files = g_list_prepend(include_files,g_strdup(file));
146 <CLASS_CODE_I>\/\*\*[ \t]*$ {
147 /* eat out gtk doc stuff */
148 BEGIN(GTK_DOC_BEFORE_NAME);
151 <GTK_DOC_BEFORE_NAME>^[ \t]*\*[ \t]*$ {
152 /* empty doc lines */
155 <GTK_DOC_BEFORE_NAME>^[ \t]*\*\ [_a-zA-Z][_a-zA-Z0-9]*:?[ \t]*$ {
158 p = strchr(yytext, '*');
159 g_free(gtk_doc_func);
160 gtk_doc_func = g_strdup(p+2);
161 p = strchr(gtk_doc_func, ':');
163 g_strstrip(gtk_doc_func);
165 <GTK_DOC_BEFORE_NAME>\*\/ {
168 <GTK_DOC_BEFORE_NAME>. {
170 before_comment = CLASS_CODE_I;
172 <GTK_DOC>^[ \t]*\*[ \t]*$ {
173 /* empty doc lines */
176 <GTK_DOC>^[ \t]*\*?\*\/ {
180 <GTK_DOC>^[ \t]*\*\ {
190 before_comment = CLASS_CODE_I;
207 <C_CODE>\/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ }
208 <CLASS_CODE>\/\/.*$ { ; /*comment, ignore*/ }
209 <CLASS_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
210 \/\* {BEGIN(COMMENT); before_comment = INITIAL; }
214 before_comment = C_CODE;
216 <CLASS_CODE>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; }
217 <CLASS_CODE_I>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; }
219 if(before_comment == C_CODE) add_to_cbuf(yytext);
220 BEGIN(before_comment);
223 /* comment, ignore */
224 if(before_comment == C_CODE) add_to_cbuf(yytext);
227 /* comment, ignore */
228 if(before_comment == C_CODE) add_to_cbuf(yytext);
234 class_after_c = FALSE;
237 ccode_line = line_no;
242 class_after_c = FALSE;
245 ccode_line = line_no;
248 ^\%(ht|headertop)\{ {
251 class_after_c = FALSE;
254 ccode_line = line_no;
256 ^\%(ph|privateheader)\{ {
259 class_after_c = FALSE;
262 ccode_line = line_no;
267 class_after_c = FALSE;
270 ccode_line = line_no;
275 class_after_c = FALSE;
278 ccode_line = line_no;
279 if(look_for_includes==0)
286 if(look_for_includes==1)
291 <C_CODE>\'\{\' { add_to_cbuf(yytext); }
292 <C_CODE>\'\\\{\' { add_to_cbuf(yytext); }
293 <C_CODE>\'\}\' { add_to_cbuf(yytext); }
294 <C_CODE>\'\\\}\' { add_to_cbuf(yytext); }
295 <C_CODE>\'\"\' { add_to_cbuf(yytext); }
296 <C_CODE>\'\\\"\' { add_to_cbuf(yytext); }
298 <C_CODE>\\. { add_to_cbuf(yytext); }
300 BEGIN(C_CODE_STRING);
303 <C_CODE_STRING>\\. { add_to_cbuf(yytext); }
308 <C_CODE_STRING>. { add_to_cbuf(yytext); }
309 <C_CODE_STRING>\n { add_to_cbuf(yytext); }
317 if(parenth_depth<0) {
319 } else if(parenth_depth==0 && class_after_c) {
328 <C_CODE>. { add_to_cbuf(yytext); }
329 <C_CODE>\n { add_to_cbuf(yytext); }
332 static int found_classes = 0;
333 look_for_includes = 2;
336 if(++found_classes > 1) {
337 error_print(GOB_ERROR, line_no,
338 "Only one class per file allowed");
344 ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$ {
345 int maj = 0,min = 0,pl = 0;
346 int rmaj = 0,rmin = 0,rpl = 0;
347 int effective_maj = 0;
348 int effective_rmaj = 0;
351 sscanf(VERSION,"%d.%d.%d",&rmaj,&rmin,&rpl);
352 effective_rmaj = rmaj;
354 effective_rmaj = rmaj + 1;
356 p = strchr(yytext,'r');
357 g_assert(p); /* we MUST have found it */
358 sscanf(p,"requires %d.%d.%d",&maj,&min,&pl);
361 effective_maj = maj + 1;
364 (rmaj == maj && rmin < min) ||
365 (rmaj == maj && rmin == min && rpl < pl)) {
366 error_printf(GOB_ERROR, line_no,
367 "GOB version at least %d.%d.%d required "
369 "To upgrade your gob, see: "
370 "http://www.5z.com/jirka/gob.html",
371 maj, min, pl, VERSION);
374 if(effective_rmaj != effective_maj) {
375 error_printf(GOB_ERROR, line_no,
376 "GOB major version %d required "
378 "To upgrade your gob, see: "
379 "http://www.5z.com/jirka/gob.html",
384 <CLASS_CODE,CLASS_CODE_I>class|this {
386 error_printf(GOB_WARN, line_no,
387 "'%s' keyword should not "
388 "be used when generating "
394 <CLASS_CODE>from {return FROM;}
396 <CLASS_CODE_I>void {return VOID;}
397 <CLASS_CODE_I>struct {return STRUCT;}
398 <CLASS_CODE_I>union {return UNION;}
399 <CLASS_CODE_I>enum {return ENUM;}
400 <CLASS_CODE_I>signed {return SIGNED;}
401 <CLASS_CODE_I>unsigned {return UNSIGNED;}
402 <CLASS_CODE_I>long {return LONG;}
403 <CLASS_CODE_I>short {return SHORT;}
404 <CLASS_CODE_I>int {return INT;}
405 <CLASS_CODE_I>float {return FLOAT;}
406 <CLASS_CODE_I>double {return DOUBLE;}
407 <CLASS_CODE_I>char {return CHAR;}
408 <CLASS_CODE_I>const {return CONST;}
410 <CLASS_CODE_I>\.\.\. {return THREEDOTS;}
412 <CLASS_CODE_I>public {yylval.line = line_no; return PUBLIC;}
413 <CLASS_CODE_I>private {yylval.line = line_no; return PRIVATE;}
414 <CLASS_CODE_I>protected {yylval.line = line_no; return PROTECTED;}
415 <CLASS_CODE_I>classwide {yylval.line = line_no; return CLASSWIDE;}
416 <CLASS_CODE_I>argument {yylval.line = line_no; return ARGUMENT;}
417 <CLASS_CODE_I>virtual {yylval.line = line_no; return VIRTUAL;}
418 <CLASS_CODE_I>signal {yylval.line = line_no; return SIGNAL;}
419 <CLASS_CODE_I>override {yylval.line = line_no; return OVERRIDE;}
420 <CLASS_CODE,CLASS_CODE_I>0|[1-9][0-9]*|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+|\.[0-9][0-9]* {
421 yylval.id = g_strdup(yytext);
424 <CLASS_CODE,CLASS_CODE_I>[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ {
425 /* this one is for a classname with a namespace */
426 yylval.id = g_strdup(yytext);
429 <CLASS_CODE,CLASS_CODE_I>:[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)* {
430 /* this is for a classname with an empty namespace */
431 yylval.id = g_strdup(yytext);
434 <CLASS_CODE,CLASS_CODE_I>[A-Za-z_][A-Za-z0-9_]* {
435 yylval.id = g_strdup(yytext);
439 <CLASS_CODE_I>(\[[0-9]*\]|\[[A-Za-z_][A-Za-z0-9_]*\])+ {
440 yylval.id = g_strdup(yytext);
451 class_after_c = TRUE;
452 yylval.line = line_no;
454 ccode_line = line_no;
462 <CLASS_CODE,CLASS_CODE_I,INITIAL>[\t ] ; /*ignore*/
465 yylval.line = line_no;
469 <*>[\n\r] ; /*ignore*/
473 /* Ugly warning avoiding */
475 static void warning_avoider(void) G_GNUC_UNUSED;
476 static void warning_avoider(void) {
477 yy_flex_realloc(NULL, 0);