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,
30 extern gboolean for_cpp;
32 static int parenth_depth = 0;
33 static int before_comment = INITIAL;
34 static int class_after_c = FALSE;
35 static int header_c = FALSE;
37 static GString *cbuf = NULL;
40 GList *include_files = NULL;
41 /* 0 no, 1 means yes, 2+ means don't even start looking anymore */
42 static int look_for_includes = 0;
50 cbuf = g_string_new("");
52 cbuf = g_string_assign(cbuf,"");
60 cbuf = g_string_new(s);
62 cbuf = g_string_append(cbuf,s);
76 <*>\n { line_no++; REJECT; }
78 <*>MOTHERFUCKER { fprintf(stderr,"You are a bad bad person!\n"); REJECT; }
80 \/\/.*$ { ; /*comment, ignore*/ }
81 <C_CODE>^#[ \t]*include[ \t][<"][^\n">]*[>"] {
82 if(look_for_includes==1) {
85 char *str = g_strdup(yytext);
86 file = strchr(str,'"');
87 if(!file) file = strchr(str,'<');
90 if(!p) p = strchr(file,'>');
92 include_files = g_list_prepend(include_files,g_strdup(file));
98 <C_CODE>\/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ }
99 <CLASS_CODE>\/\/.*$ { ; /*comment, ignore*/ }
100 <CLASS_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
101 \/\* {BEGIN(COMMENT); before_comment = INITIAL; }
105 before_comment = C_CODE;
107 <CLASS_CODE>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; }
108 <CLASS_CODE_I>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; }
110 if(before_comment == C_CODE) add_to_cbuf(yytext);
111 BEGIN(before_comment);
114 /* comment, ignore */
115 if(before_comment == C_CODE) add_to_cbuf(yytext);
118 /* comment, ignore */
119 if(before_comment == C_CODE) add_to_cbuf(yytext);
125 class_after_c = FALSE;
128 ccode_line = line_no;
133 class_after_c = FALSE;
136 ccode_line = line_no;
137 if(look_for_includes==0)
144 if(look_for_includes==1)
152 <C_CODE>\'\{\' { add_to_cbuf(yytext); }
153 <C_CODE>\'\\\{\' { add_to_cbuf(yytext); }
154 <C_CODE>\'\}\' { add_to_cbuf(yytext); }
155 <C_CODE>\'\\\}\' { add_to_cbuf(yytext); }
156 <C_CODE>\'\"\' { add_to_cbuf(yytext); }
157 <C_CODE>\'\\\"\' { add_to_cbuf(yytext); }
159 <C_CODE>\\. { add_to_cbuf(yytext); }
161 BEGIN(C_CODE_STRING);
164 <C_CODE_STRING>\\. { add_to_cbuf(yytext); }
169 <C_CODE_STRING>. { add_to_cbuf(yytext); }
170 <C_CODE_STRING>\n { add_to_cbuf(yytext); }
178 if(parenth_depth<0) {
180 } else if(parenth_depth==0 && class_after_c) {
189 <C_CODE>. { add_to_cbuf(yytext); }
190 <C_CODE>\n { add_to_cbuf(yytext); }
193 look_for_includes = 2;
198 <CLASS_CODE,CLASS_CODE_I>class|this {
201 s = g_strdup_printf("'%s' keyword should not "
202 "be used when generating "
204 print_error(TRUE,s, line_no);
210 <CLASS_CODE>from {return FROM;}
212 <CLASS_CODE_I>void {return VOID;}
213 <CLASS_CODE_I>struct {return STRUCT;}
214 <CLASS_CODE_I>union {return UNION;}
215 <CLASS_CODE_I>enum {return ENUM;}
216 <CLASS_CODE_I>signed {return SIGNED;}
217 <CLASS_CODE_I>unsigned {return UNSIGNED;}
218 <CLASS_CODE_I>long {return LONG;}
219 <CLASS_CODE_I>short {return SHORT;}
220 <CLASS_CODE_I>int {return INT;}
221 <CLASS_CODE_I>float {return FLOAT;}
222 <CLASS_CODE_I>double {return DOUBLE;}
223 <CLASS_CODE_I>char {return CHAR;}
224 <CLASS_CODE_I>const {return CONST;}
226 <CLASS_CODE_I>\.\.\. {return THREEDOTS;}
228 <CLASS_CODE_I>public {yylval.line = line_no; return PUBLIC;}
229 <CLASS_CODE_I>private {yylval.line = line_no; return PRIVATE;}
230 <CLASS_CODE_I>argument {yylval.line = line_no; return ARGUMENT;}
231 <CLASS_CODE_I>virtual {yylval.line = line_no; return VIRTUAL;}
232 <CLASS_CODE_I>signal {yylval.line = line_no; return SIGNAL;}
233 <CLASS_CODE_I>override {yylval.line = line_no; return OVERRIDE;}
234 <CLASS_CODE_I>onerror {return ONERROR;}
235 <CLASS_CODE_I>0|[1-9][0-9]*|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+|\.[0-9][0-9]* {
236 yylval.id = g_strdup(yytext);
239 <CLASS_CODE,CLASS_CODE_I>:?[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ {
240 yylval.id = g_strdup(yytext);
243 <CLASS_CODE,CLASS_CODE_I>[A-Za-z_][A-Za-z0-9_]* {
244 yylval.id = g_strdup(yytext);
255 class_after_c = TRUE;
256 ccode_line = line_no;
257 yylval.line = line_no;
265 <CLASS_CODE,CLASS_CODE_I,INITIAL>[\t ] ; /*ignore*/
268 yylval.line = line_no;
272 <*>[\n\r] ; /*ignore*/