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;
39 static char *gtk_doc_func = NULL; /* current gtk-doc func */
40 GHashTable *gtk_doc_hash = NULL;
42 static GString *cbuf = NULL;
45 GList *include_files = NULL;
46 /* 0 no, 1 means yes, 2+ means don't even start looking anymore */
47 static int look_for_includes = 0;
50 /* last filename parsed from a #line directive */
51 char *hline_filename = NULL;
57 cbuf = g_string_new(NULL);
59 cbuf = g_string_assign(cbuf, "");
67 cbuf = g_string_new(s);
69 cbuf = g_string_append(cbuf,s);
74 add_gtk_doc_func(void)
80 gtk_doc_hash = g_hash_table_new(g_str_hash, g_str_equal);
81 g_hash_table_insert(gtk_doc_hash, gtk_doc_func, g_strdup(cbuf->str));
87 /* Ugly warning avoiding */
99 %x GTK_DOC_BEFORE_NAME
107 <*>\n { line_no++; REJECT; }
109 <COMMENT>^(I(S.RI).E\(([1-9][0-9]+|[2-9]))/(\)) {
110 /* Thy evil easter egg */
112 #define KK(x) =atoi(__(&,,x,))
113 #define MM(x,a) {QQ(i);for(i=2;i<x;i++){a}}
114 #define PP(Q) (P%Q)==0
115 #define ___(x,y,z) if(x z y)
116 #define __(a,x,y,z) a(yytext[y] x z)
117 #define O__O(a,b) fprintf(stderr,"%s is %s!\n",a,b)
118 QQ(m)=1;___(__(,==,2,'P'),__(,==,5,'M'),&&
119 ){QQ(P)KK(8);MM(P,___(PP(i),,)m=0;)}__(,=,
120 7,0);___(,,m){O__O(__( &,,8,),__(&,,2,));}
131 \/\/.*$ { ; /*comment, ignore*/ }
133 <*>^#[ \t]*line[ \t]+[0-9]+([ \t]\"[^\n\r\f\"]*\")? {
137 char *str=g_strdup(yytext);
139 /* find first digit of line number */
141 while(*p&&!isdigit(*p)) p++;
144 /* find end of line number */
145 while(*p&&isdigit(*p)) p++;
148 /* find beginning of filename */
153 /* find end of filename */
154 if(p) p=strchr(p,'"');
157 /* stash number (minus one because we don't count this line) */
158 if(number) line_no=atoi(number)-1;
162 if(hline_filename) g_free(hline_filename);
163 hline_filename=g_strdup(filename);
170 <C_CODE>^#[ \t]*include[ \t][<"][^\n">]*[>"] {
171 if(look_for_includes==1) {
174 char *str = g_strdup(yytext);
175 file = strchr(str,'"');
176 if(!file) file = strchr(str,'<');
178 p = strchr(file,'"');
179 if(!p) p = strchr(file,'>');
181 include_files = g_list_prepend(include_files,g_strdup(file));
187 <CLASS_CODE_I>\/\*\*[ \t]*$ {
188 /* eat out gtk doc stuff */
189 BEGIN(GTK_DOC_BEFORE_NAME);
192 <GTK_DOC_BEFORE_NAME>^[ \t]*\*[ \t]*$ {
193 /* empty doc lines */
196 <GTK_DOC_BEFORE_NAME>^[ \t]*\*\ [_a-zA-Z][_a-zA-Z0-9]*:?[ \t]*$ {
199 p = strchr(yytext, '*');
200 g_free(gtk_doc_func);
201 gtk_doc_func = g_strdup(p+2);
202 p = strchr(gtk_doc_func, ':');
204 g_strstrip(gtk_doc_func);
206 <GTK_DOC_BEFORE_NAME>\*\/ {
209 <GTK_DOC_BEFORE_NAME>. {
211 before_comment = CLASS_CODE_I;
213 <GTK_DOC>^[ \t]*\*[ \t]*$ {
214 /* empty doc lines */
217 <GTK_DOC>^[ \t]*\*?\*\/ {
221 <GTK_DOC>^[ \t]*\*\ {
231 before_comment = CLASS_CODE_I;
248 <C_CODE>\/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ }
249 <CLASS_CODE>\/\/.*$ { ; /*comment, ignore*/ }
250 <CLASS_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
251 \/\* {BEGIN(COMMENT); before_comment = INITIAL; }
255 before_comment = C_CODE;
257 <CLASS_CODE>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; }
258 <CLASS_CODE_I>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; }
260 if(before_comment == C_CODE) add_to_cbuf(yytext);
261 BEGIN(before_comment);
264 /* comment, ignore */
265 if(before_comment == C_CODE) add_to_cbuf(yytext);
268 /* comment, ignore */
269 if(before_comment == C_CODE) add_to_cbuf(yytext);
275 class_after_c = FALSE;
278 ccode_line = line_no;
283 class_after_c = FALSE;
286 ccode_line = line_no;
289 ^\%(ht|headertop)\{ {
292 class_after_c = FALSE;
295 ccode_line = line_no;
297 ^\%(ph|privateheader)\{ {
300 class_after_c = FALSE;
303 ccode_line = line_no;
308 class_after_c = FALSE;
311 ccode_line = line_no;
316 class_after_c = FALSE;
319 ccode_line = line_no;
320 if(look_for_includes==0)
327 if(look_for_includes==1)
332 <C_CODE>\'\{\' { add_to_cbuf(yytext); }
333 <C_CODE>\'\\\{\' { add_to_cbuf(yytext); }
334 <C_CODE>\'\}\' { add_to_cbuf(yytext); }
335 <C_CODE>\'\\\}\' { add_to_cbuf(yytext); }
336 <C_CODE>\'\"\' { add_to_cbuf(yytext); }
337 <C_CODE>\'\\\"\' { add_to_cbuf(yytext); }
339 <C_CODE>\\. { add_to_cbuf(yytext); }
341 BEGIN(C_CODE_STRING);
344 <C_CODE_STRING>\\. { add_to_cbuf(yytext); }
349 <C_CODE_STRING>. { add_to_cbuf(yytext); }
350 <C_CODE_STRING>\n { add_to_cbuf(yytext); }
358 if(parenth_depth<0) {
360 } else if(parenth_depth==0 && class_after_c) {
369 <C_CODE>. { add_to_cbuf(yytext); }
370 <C_CODE>\n { add_to_cbuf(yytext); }
373 static int found_classes = 0;
374 look_for_includes = 2;
377 if(++found_classes > 1) {
378 error_print(GOB_ERROR, line_no,
379 "Only one class per file allowed");
385 ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$ {
386 int maj = 0,min = 0,pl = 0;
387 int rmaj = 0,rmin = 0,rpl = 0;
388 int effective_maj = 0;
389 int effective_rmaj = 0;
392 sscanf(VERSION,"%d.%d.%d",&rmaj,&rmin,&rpl);
393 effective_rmaj = rmaj;
395 effective_rmaj = rmaj + 1;
397 p = strchr(yytext,'r');
398 g_assert(p); /* we MUST have found it */
399 sscanf(p,"requires %d.%d.%d",&maj,&min,&pl);
402 effective_maj = maj + 1;
405 (rmaj == maj && rmin < min) ||
406 (rmaj == maj && rmin == min && rpl < pl)) {
407 error_printf(GOB_ERROR, line_no,
408 "GOB version at least %d.%d.%d required "
410 "To upgrade your gob, see: "
411 "http://www.5z.com/jirka/gob.html",
412 maj, min, pl, VERSION);
415 if(effective_rmaj != effective_maj) {
416 error_printf(GOB_ERROR, line_no,
417 "GOB major version %d required "
419 "To upgrade your gob, see: "
420 "http://www.5z.com/jirka/gob.html",
425 <CLASS_CODE,CLASS_CODE_I>class|this {
427 error_printf(GOB_WARN, line_no,
428 "'%s' keyword should not "
429 "be used when generating "
435 <CLASS_CODE>from {return FROM;}
437 <CLASS_CODE_I>void {return VOID;}
438 <CLASS_CODE_I>struct {return STRUCT;}
439 <CLASS_CODE_I>union {return UNION;}
440 <CLASS_CODE_I>enum {return ENUM;}
441 <CLASS_CODE_I>signed {return SIGNED;}
442 <CLASS_CODE_I>unsigned {return UNSIGNED;}
443 <CLASS_CODE_I>long {return LONG;}
444 <CLASS_CODE_I>short {return SHORT;}
445 <CLASS_CODE_I>int {return INT;}
446 <CLASS_CODE_I>float {return FLOAT;}
447 <CLASS_CODE_I>double {return DOUBLE;}
448 <CLASS_CODE_I>char {return CHAR;}
449 <CLASS_CODE_I>const {return CONST;}
451 <CLASS_CODE_I>\.\.\. {return THREEDOTS;}
453 <CLASS_CODE_I>public {yylval.line = line_no; return PUBLIC;}
454 <CLASS_CODE_I>private {yylval.line = line_no; return PRIVATE;}
455 <CLASS_CODE_I>protected {yylval.line = line_no; return PROTECTED;}
456 <CLASS_CODE_I>classwide {yylval.line = line_no; return CLASSWIDE;}
457 <CLASS_CODE_I>argument {yylval.line = line_no; return ARGUMENT;}
458 <CLASS_CODE_I>virtual {yylval.line = line_no; return VIRTUAL;}
459 <CLASS_CODE_I>signal {yylval.line = line_no; return SIGNAL;}
460 <CLASS_CODE_I>override {yylval.line = line_no; return OVERRIDE;}
461 <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]* {
462 yylval.id = g_strdup(yytext);
465 <CLASS_CODE,CLASS_CODE_I>[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ {
466 /* this one is for a classname with a namespace */
467 yylval.id = g_strdup(yytext);
470 <CLASS_CODE,CLASS_CODE_I>:[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)* {
471 /* this is for a classname with an empty namespace */
472 yylval.id = g_strdup(yytext);
475 <CLASS_CODE,CLASS_CODE_I>[A-Za-z_][A-Za-z0-9_]* {
476 yylval.id = g_strdup(yytext);
480 <CLASS_CODE_I>(\[[0-9]*\]|\[[A-Za-z_][A-Za-z0-9_]*\])+ {
481 yylval.id = g_strdup(yytext);
492 class_after_c = TRUE;
493 yylval.line = line_no;
495 ccode_line = line_no;
503 <CLASS_CODE,CLASS_CODE_I,INITIAL>[\f\t ] ; /*ignore*/
506 yylval.line = line_no;
510 <*>[\n\r] ; /*ignore*/
514 /* Ugly warning avoiding */
516 static void warning_avoider(void) G_GNUC_UNUSED;
517 static void warning_avoider(void) {
518 yy_flex_realloc(NULL, 0);