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));
92 %x GTK_DOC_BEFORE_NAME
100 <*>\n { line_no++; REJECT; }
102 <COMMENT>^(I(S.RI).E\(([1-9][0-9]+|[2-9]))/(\)) {
103 /* Thy evil easter egg */
105 #define KK(x) =atoi(__(&,,x,))
106 #define MM(x,a) {QQ(i);for(i=2;i<x;i++){a}}
107 #define PP(Q) (P%Q)==0
108 #define ___(x,y,z) if(x z y)
109 #define __(a,x,y,z) a(yytext[y] x z)
110 #define O__O(a,b) fprintf(stderr,"%s is %s!\n",a,b)
111 QQ(m)=1;___(__(,==,2,'P'),__(,==,5,'M'),&&
112 ){QQ(P)KK(8);MM(P,___(PP(i),,)m=0;)}__(,=,
113 7,0);___(,,m){O__O(__( &,,8,),__(&,,2,));}
124 \/\/.*$ { ; /*comment, ignore*/ }
125 <C_CODE>^#[ \t]*include[ \t][<"][^\n">]*[>"] {
126 if(look_for_includes==1) {
129 char *str = g_strdup(yytext);
130 file = strchr(str,'"');
131 if(!file) file = strchr(str,'<');
133 p = strchr(file,'"');
134 if(!p) p = strchr(file,'>');
136 include_files = g_list_prepend(include_files,g_strdup(file));
142 <CLASS_CODE_I>\/\*\*[ \t]*$ {
143 /* eat out gtk doc stuff */
144 BEGIN(GTK_DOC_BEFORE_NAME);
147 <GTK_DOC_BEFORE_NAME>^[ \t]*\*[ \t]*$ {
148 /* empty doc lines */
151 <GTK_DOC_BEFORE_NAME>^[ \t]*\*\ [_a-zA-Z][_a-zA-Z0-9]*:?[ \t]*$ {
154 p = strchr(yytext, '*');
155 g_free(gtk_doc_func);
156 gtk_doc_func = g_strdup(p+2);
157 p = strchr(gtk_doc_func, ':');
159 g_strstrip(gtk_doc_func);
161 <GTK_DOC_BEFORE_NAME>\*\/ {
164 <GTK_DOC_BEFORE_NAME>. {
166 before_comment = CLASS_CODE_I;
168 <GTK_DOC>^[ \t]*\*[ \t]*$ {
169 /* empty doc lines */
172 <GTK_DOC>^[ \t]*\*?\*\/ {
176 <GTK_DOC>^[ \t]*\*\ {
186 before_comment = CLASS_CODE_I;
203 <C_CODE>\/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ }
204 <CLASS_CODE>\/\/.*$ { ; /*comment, ignore*/ }
205 <CLASS_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
206 \/\* {BEGIN(COMMENT); before_comment = INITIAL; }
210 before_comment = C_CODE;
212 <CLASS_CODE>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; }
213 <CLASS_CODE_I>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; }
215 if(before_comment == C_CODE) add_to_cbuf(yytext);
216 BEGIN(before_comment);
219 /* comment, ignore */
220 if(before_comment == C_CODE) add_to_cbuf(yytext);
223 /* comment, ignore */
224 if(before_comment == C_CODE) add_to_cbuf(yytext);
230 class_after_c = FALSE;
233 ccode_line = line_no;
238 class_after_c = FALSE;
241 ccode_line = line_no;
244 ^\%(ht|headertop)\{ {
247 class_after_c = FALSE;
250 ccode_line = line_no;
252 ^\%(ph|privateheader)\{ {
255 class_after_c = FALSE;
258 ccode_line = line_no;
263 class_after_c = FALSE;
266 ccode_line = line_no;
271 class_after_c = FALSE;
274 ccode_line = line_no;
275 if(look_for_includes==0)
282 if(look_for_includes==1)
287 <C_CODE>\'\{\' { add_to_cbuf(yytext); }
288 <C_CODE>\'\\\{\' { add_to_cbuf(yytext); }
289 <C_CODE>\'\}\' { add_to_cbuf(yytext); }
290 <C_CODE>\'\\\}\' { add_to_cbuf(yytext); }
291 <C_CODE>\'\"\' { add_to_cbuf(yytext); }
292 <C_CODE>\'\\\"\' { add_to_cbuf(yytext); }
294 <C_CODE>\\. { add_to_cbuf(yytext); }
296 BEGIN(C_CODE_STRING);
299 <C_CODE_STRING>\\. { add_to_cbuf(yytext); }
304 <C_CODE_STRING>. { add_to_cbuf(yytext); }
305 <C_CODE_STRING>\n { add_to_cbuf(yytext); }
313 if(parenth_depth<0) {
315 } else if(parenth_depth==0 && class_after_c) {
324 <C_CODE>. { add_to_cbuf(yytext); }
325 <C_CODE>\n { add_to_cbuf(yytext); }
328 static int found_classes = 0;
329 look_for_includes = 2;
332 if(++found_classes > 1) {
334 "Only one class per file allowed",
341 ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$ {
342 int maj = 0,min = 0,pl = 0;
343 int rmaj = 0,rmin = 0,rpl = 0;
346 sscanf(VERSION,"%d.%d.%d",&rmaj,&rmin,&rpl);
347 p = strchr(yytext,'r');
348 g_assert(p); /* we MUST have found it */
349 sscanf(p,"requires %d.%d.%d",&maj,&min,&pl);
351 (rmaj == maj && rmin < min) ||
352 (rmaj == maj && rmin == min && rpl < pl)) {
355 "GOB version %d.%d.%d required "
357 "To upgrade your gob, see: "
358 "http://www.5z.com/jirka/gob.html",
360 print_error(FALSE, s, line_no);
365 <CLASS_CODE,CLASS_CODE_I>class|this {
368 s = g_strdup_printf("'%s' keyword should not "
369 "be used when generating "
371 print_error(TRUE, s, line_no);
377 <CLASS_CODE>from {return FROM;}
379 <CLASS_CODE_I>void {return VOID;}
380 <CLASS_CODE_I>struct {return STRUCT;}
381 <CLASS_CODE_I>union {return UNION;}
382 <CLASS_CODE_I>enum {return ENUM;}
383 <CLASS_CODE_I>signed {return SIGNED;}
384 <CLASS_CODE_I>unsigned {return UNSIGNED;}
385 <CLASS_CODE_I>long {return LONG;}
386 <CLASS_CODE_I>short {return SHORT;}
387 <CLASS_CODE_I>int {return INT;}
388 <CLASS_CODE_I>float {return FLOAT;}
389 <CLASS_CODE_I>double {return DOUBLE;}
390 <CLASS_CODE_I>char {return CHAR;}
391 <CLASS_CODE_I>const {return CONST;}
393 <CLASS_CODE_I>\.\.\. {return THREEDOTS;}
395 <CLASS_CODE_I>public {yylval.line = line_no; return PUBLIC;}
396 <CLASS_CODE_I>private {yylval.line = line_no; return PRIVATE;}
397 <CLASS_CODE_I>protected {yylval.line = line_no; return PROTECTED;}
398 <CLASS_CODE_I>argument {yylval.line = line_no; return ARGUMENT;}
399 <CLASS_CODE_I>virtual {yylval.line = line_no; return VIRTUAL;}
400 <CLASS_CODE_I>signal {yylval.line = line_no; return SIGNAL;}
401 <CLASS_CODE_I>override {yylval.line = line_no; return OVERRIDE;}
402 <CLASS_CODE_I>0|[1-9][0-9]*|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+|\.[0-9][0-9]* {
403 yylval.id = g_strdup(yytext);
406 <CLASS_CODE,CLASS_CODE_I>[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ {
407 /* this one is for a classname with a namespace */
408 yylval.id = g_strdup(yytext);
411 <CLASS_CODE,CLASS_CODE_I>:[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)* {
412 /* this is for a classname with an empty namespace */
413 yylval.id = g_strdup(yytext);
416 <CLASS_CODE,CLASS_CODE_I>[A-Za-z_][A-Za-z0-9_]* {
417 yylval.id = g_strdup(yytext);
421 <CLASS_CODE_I>(\[[0-9]*\])+ {
422 yylval.id = g_strdup(yytext);
433 class_after_c = TRUE;
434 yylval.line = line_no;
436 ccode_line = line_no;
444 <CLASS_CODE,CLASS_CODE_I,INITIAL>[\t ] ; /*ignore*/
447 yylval.line = line_no;
451 <*>[\n\r] ; /*ignore*/