| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// copyright : (C) 2014 Eran Ifrah |
| 5 |
// file name : pp.cpp |
| 6 |
// |
| 7 |
// ------------------------------------------------------------------------- |
| 8 |
// A |
| 9 |
// _____ _ _ _ _ |
| 10 |
// / __ \ | | | | (_) | |
| 11 |
// | / \/ ___ __| | ___| | _| |_ ___ |
| 12 |
// | | / _ \ / _ |/ _ \ | | | __/ _ ) |
| 13 |
// | \__/\ (_) | (_| | __/ |___| | || __/ |
| 14 |
// \____/\___/ \__,_|\___\_____/_|\__\___| |
| 15 |
// |
| 16 |
// F i l e |
| 17 |
// |
| 18 |
// This program is free software; you can redistribute it and/or modify |
| 19 |
// it under the terms of the GNU General Public License as published by |
| 20 |
// the Free Software Foundation; either version 2 of the License, or |
| 21 |
// (at your option) any later version. |
| 22 |
// |
| 23 |
////////////////////////////////////////////////////////////////////////////// |
| 24 |
////////////////////////////////////////////////////////////////////////////// |
| 25 |
|
| 26 |
#ifndef lint |
| 27 |
static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; |
| 28 |
#endif |
| 29 |
#define YYBYACC 1 |
| 30 |
#define YYMAJOR 1 |
| 31 |
#define YYMINOR 9 |
| 32 |
#define yyclearin (yychar=(-1)) |
| 33 |
#define yyerrok (yyerrflag=0) |
| 34 |
#define YYRECOVERING (yyerrflag!=0) |
| 35 |
#define yyparse pp_parse |
| 36 |
#define yylex pp_lex |
| 37 |
#define yyerror pp_error |
| 38 |
#define yychar pp_char |
| 39 |
#define yyval pp_val |
| 40 |
#define yylval pp_lval |
| 41 |
#define yydebug pp_debug |
| 42 |
#define yynerrs pp_nerrs |
| 43 |
#define yyerrflag pp_errflag |
| 44 |
#define yyss pp_ss |
| 45 |
#define yyssp pp_ssp |
| 46 |
#define yyvs pp_vs |
| 47 |
#define yyvsp pp_vsp |
| 48 |
#define yylhs pp_lhs |
| 49 |
#define yylen pp_len |
| 50 |
#define yydefred pp_defred |
| 51 |
#define yydgoto pp_dgoto |
| 52 |
#define yysindex pp_sindex |
| 53 |
#define yyrindex pp_rindex |
| 54 |
#define yygindex pp_gindex |
| 55 |
#define yytable pp_table |
| 56 |
#define yycheck pp_check |
| 57 |
#define yyname pp_name |
| 58 |
#define yyrule pp_rule |
| 59 |
#define YYPREFIX "pp_" |
| 60 |
/* Copyright Eran Ifrah(c)*/ |
| 61 |
/*************** Includes and Defines *****************************/ |
| 62 |
#include <wx/string.h> |
| 63 |
#include "pptable.h" |
| 64 |
|
| 65 |
#define YYSTYPE wxString |
| 66 |
#define YYDEBUG 0 /* get the pretty debugging code to compile*/ |
| 67 |
|
| 68 |
#ifdef yylex |
| 69 |
#undef yylex |
| 70 |
#define yylex pp_lex |
| 71 |
#endif |
| 72 |
|
| 73 |
extern void pp_error(char *st); |
| 74 |
extern int pp_lex(); |
| 75 |
extern wxString g_definition; |
| 76 |
extern int in_if_1; |
| 77 |
extern bool g_forCC; |
| 78 |
extern wxString g_filename; |
| 79 |
|
| 80 |
/* Static*/ |
| 81 |
static std::vector<wxString> g_tmpMacros; |
| 82 |
|
| 83 |
/*************** Standard ytab.c continues here *********************/ |
| 84 |
#define PP_DEFINE 257 |
| 85 |
#define PP_IF 258 |
| 86 |
#define PP_IFDEF 259 |
| 87 |
#define PP_DEFINED 260 |
| 88 |
#define PP_UNDEF 261 |
| 89 |
#define PP_ELSE 262 |
| 90 |
#define PP_ELIF 263 |
| 91 |
#define PP_ENDIF 264 |
| 92 |
#define PP_POUND 265 |
| 93 |
#define PP_IDENTIFIER 266 |
| 94 |
#define PP_COMPLEX_REPLACEMENT 267 |
| 95 |
#define PP_IFNDEF 268 |
| 96 |
#define PP_ZERO 269 |
| 97 |
#define PP_CPLUSPLUS 270 |
| 98 |
#define PP_INCLUDE 271 |
| 99 |
#define PP_AND 272 |
| 100 |
#define PP_OR 273 |
| 101 |
#define PP_EQUAL 274 |
| 102 |
#define PP_NEQUAL 275 |
| 103 |
#define PP_INT 276 |
| 104 |
#define PP_LOWERTHAN 277 |
| 105 |
#define PP_GREATERTHAN 278 |
| 106 |
#define YYERRCODE 256 |
| 107 |
short pp_lhs[] = { -1, |
| 108 |
0, 0, 3, 1, 2, 2, 2, 2, 2, 2, |
| 109 |
2, 2, 10, 6, 4, 5, 11, 11, 11, 7, |
| 110 |
8, 9, 12, 13, 13, 14, 14, 14, 14, 14, |
| 111 |
14, 15, 15, 16, 16, 16, 16, |
| 112 |
}; |
| 113 |
short pp_len[] = { 2, |
| 114 |
0, 2, 0, 2, 1, 1, 1, 1, 1, 1, |
| 115 |
1, 1, 1, 2, 3, 6, 0, 1, 3, 2, |
| 116 |
2, 2, 1, 1, 3, 0, 3, 1, 3, 5, |
| 117 |
4, 1, 1, 1, 1, 1, 1, |
| 118 |
}; |
| 119 |
short pp_defred[] = { 1, |
| 120 |
3, 2, 0, 12, 0, 0, 0, 0, 13, 4, |
| 121 |
5, 6, 7, 8, 9, 10, 11, 0, 0, 0, |
| 122 |
14, 0, 21, 0, 24, 20, 22, 15, 0, 0, |
| 123 |
34, 35, 36, 37, 0, 0, 32, 33, 0, 18, |
| 124 |
0, 0, 29, 27, 0, 25, 0, 0, 31, 0, |
| 125 |
16, 19, 30, |
| 126 |
}; |
| 127 |
short pp_dgoto[] = { 1, |
| 128 |
2, 10, 3, 11, 12, 13, 14, 15, 16, 17, |
| 129 |
41, 23, 24, 25, 39, 35, |
| 130 |
}; |
| 131 |
short pp_sindex[] = { 0, |
| 132 |
0, 0, -250, 0, -244, -38, -241, -35, 0, 0, |
| 133 |
0, 0, 0, 0, 0, 0, 0, -37, -36, -259, |
| 134 |
0, -240, 0, -262, 0, 0, 0, 0, -239, -238, |
| 135 |
0, 0, 0, 0, -247, -41, 0, 0, -35, 0, |
| 136 |
-24, -11, 0, 0, -245, 0, -235, -233, 0, -7, |
| 137 |
0, 0, 0, |
| 138 |
}; |
| 139 |
short pp_rindex[] = { 0, |
| 140 |
0, 0, 0, 0, 0, 1, 0, 1, 0, 0, |
| 141 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 12, |
| 142 |
0, 0, 0, 23, 0, 0, 0, 0, -20, 0, |
| 143 |
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, |
| 144 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 145 |
0, 0, 0, |
| 146 |
}; |
| 147 |
short pp_gindex[] = { 0, |
| 148 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 149 |
0, 27, 0, -3, 0, 2, |
| 150 |
}; |
| 151 |
#define YYTABLESIZE 287 |
| 152 |
short pp_table[] = { 44, |
| 153 |
26, 22, 29, 30, 22, 4, 5, 6, 7, 37, |
| 154 |
38, 28, 8, 9, 31, 32, 47, 33, 34, 48, |
| 155 |
17, 18, 23, 17, 26, 36, 40, 42, 43, 49, |
| 156 |
50, 51, 52, 53, 27, 46, 0, 45, 0, 0, |
| 157 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 158 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 159 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 160 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 161 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 162 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 163 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 164 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 165 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 166 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 167 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 168 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 169 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 170 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 171 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 172 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 173 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 174 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 175 |
0, 19, 0, 0, 19, 0, 0, 20, 0, 28, |
| 176 |
20, 21, 31, 32, 0, 33, 34, 0, 0, 0, |
| 177 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 178 |
0, 0, 0, 0, 0, 0, 26, 26, 26, 26, |
| 179 |
0, 0, 0, 26, 26, 0, 0, 28, 28, 28, |
| 180 |
28, 0, 26, 26, 28, 28, 0, 0, 23, 23, |
| 181 |
23, 23, 0, 28, 28, 23, 23, |
| 182 |
}; |
| 183 |
short pp_check[] = { 41, |
| 184 |
0, 40, 40, 40, 40, 256, 257, 258, 259, 272, |
| 185 |
273, 0, 263, 264, 274, 275, 41, 277, 278, 44, |
| 186 |
41, 266, 0, 44, 266, 266, 266, 266, 276, 41, |
| 187 |
276, 267, 266, 41, 8, 39, -1, 36, -1, -1, |
| 188 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 189 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 190 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 191 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 192 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 193 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 194 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 195 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 196 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 197 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 198 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 199 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 200 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 201 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 202 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 203 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 204 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 205 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 206 |
-1, 260, -1, -1, 260, -1, -1, 266, -1, 267, |
| 207 |
266, 270, 274, 275, -1, 277, 278, -1, -1, -1, |
| 208 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 209 |
-1, -1, -1, -1, -1, -1, 256, 257, 258, 259, |
| 210 |
-1, -1, -1, 263, 264, -1, -1, 256, 257, 258, |
| 211 |
259, -1, 272, 273, 263, 264, -1, -1, 256, 257, |
| 212 |
258, 259, -1, 272, 273, 263, 264, |
| 213 |
}; |
| 214 |
#define YYFINAL 1 |
| 215 |
#ifndef YYDEBUG |
| 216 |
#define YYDEBUG 1 |
| 217 |
#endif |
| 218 |
#define YYMAXTOKEN 278 |
| 219 |
#if YYDEBUG |
| 220 |
char *pp_name[] = { |
| 221 |
"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 222 |
0,0,0,0,0,0,"'('","')'",0,0,"','",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 223 |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 224 |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 225 |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 226 |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 227 |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"PP_DEFINE","PP_IF", |
| 228 |
"PP_IFDEF","PP_DEFINED","PP_UNDEF","PP_ELSE","PP_ELIF","PP_ENDIF","PP_POUND", |
| 229 |
"PP_IDENTIFIER","PP_COMPLEX_REPLACEMENT","PP_IFNDEF","PP_ZERO","PP_CPLUSPLUS", |
| 230 |
"PP_INCLUDE","PP_AND","PP_OR","PP_EQUAL","PP_NEQUAL","PP_INT","PP_LOWERTHAN", |
| 231 |
"PP_GREATERTHAN", |
| 232 |
}; |
| 233 |
char *pp_rule[] = { |
| 234 |
"$accept : translation_unit", |
| 235 |
"translation_unit :", |
| 236 |
"translation_unit : translation_unit the_macros_rule", |
| 237 |
"$$1 :", |
| 238 |
"the_macros_rule : $$1 macros", |
| 239 |
"macros : define_simple_macros", |
| 240 |
"macros : define_func_like_macros", |
| 241 |
"macros : if_cplusplus", |
| 242 |
"macros : ifdef_simple_macro", |
| 243 |
"macros : if_macros", |
| 244 |
"macros : elif_macros", |
| 245 |
"macros : end_if", |
| 246 |
"macros : error", |
| 247 |
"end_if : PP_ENDIF", |
| 248 |
"if_cplusplus : PP_IF PP_CPLUSPLUS", |
| 249 |
"define_simple_macros : PP_DEFINE PP_IDENTIFIER PP_COMPLEX_REPLACEMENT", |
| 250 |
"define_func_like_macros : PP_DEFINE PP_IDENTIFIER '(' args_list ')' PP_COMPLEX_REPLACEMENT", |
| 251 |
"args_list :", |
| 252 |
"args_list : PP_IDENTIFIER", |
| 253 |
"args_list : args_list ',' PP_IDENTIFIER", |
| 254 |
"ifdef_simple_macro : PP_IFDEF PP_IDENTIFIER", |
| 255 |
"if_macros : PP_IF if_condition", |
| 256 |
"elif_macros : PP_ELIF if_condition", |
| 257 |
"if_condition : generic_condition", |
| 258 |
"generic_condition : generic_condition_base", |
| 259 |
"generic_condition : generic_condition logical_operator generic_condition_base", |
| 260 |
"generic_condition_base :", |
| 261 |
"generic_condition_base : '(' PP_IDENTIFIER ')'", |
| 262 |
"generic_condition_base : PP_IDENTIFIER", |
| 263 |
"generic_condition_base : PP_IDENTIFIER test_operator PP_INT", |
| 264 |
"generic_condition_base : '(' PP_IDENTIFIER test_operator PP_INT ')'", |
| 265 |
"generic_condition_base : PP_DEFINED '(' PP_IDENTIFIER ')'", |
| 266 |
"logical_operator : PP_AND", |
| 267 |
"logical_operator : PP_OR", |
| 268 |
"test_operator : PP_EQUAL", |
| 269 |
"test_operator : PP_NEQUAL", |
| 270 |
"test_operator : PP_LOWERTHAN", |
| 271 |
"test_operator : PP_GREATERTHAN", |
| 272 |
}; |
| 273 |
#endif |
| 274 |
#ifndef YYSTYPE |
| 275 |
typedef int YYSTYPE; |
| 276 |
#endif |
| 277 |
#ifdef YYSTACKSIZE |
| 278 |
#undef YYMAXDEPTH |
| 279 |
#define YYMAXDEPTH YYSTACKSIZE |
| 280 |
#else |
| 281 |
#ifdef YYMAXDEPTH |
| 282 |
#define YYSTACKSIZE YYMAXDEPTH |
| 283 |
#else |
| 284 |
#define YYSTACKSIZE 500 |
| 285 |
#define YYMAXDEPTH 500 |
| 286 |
#endif |
| 287 |
#endif |
| 288 |
int yydebug; |
| 289 |
int yynerrs; |
| 290 |
int yyerrflag; |
| 291 |
int yychar; |
| 292 |
short *yyssp; |
| 293 |
YYSTYPE *yyvsp; |
| 294 |
YYSTYPE yyval; |
| 295 |
YYSTYPE yylval; |
| 296 |
short yyss[YYSTACKSIZE]; |
| 297 |
YYSTYPE yyvs[YYSTACKSIZE]; |
| 298 |
#define yystacksize YYSTACKSIZE |
| 299 |
|
| 300 |
#define YYABORT goto yyabort |
| 301 |
#define YYREJECT goto yyabort |
| 302 |
#define YYACCEPT goto yyaccept |
| 303 |
#define YYERROR goto yyerrlab |
| 304 |
int |
| 305 |
yyparse() |
| 306 |
{ |
| 307 |
register int yym, yyn, yystate; |
| 308 |
#if YYDEBUG |
| 309 |
register char *yys; |
| 310 |
extern char *getenv(); |
| 311 |
|
| 312 |
if (yys = getenv("YYDEBUG")) |
| 313 |
{ |
| 314 |
yyn = *yys; |
| 315 |
if (yyn >= '0' && yyn <= '9') |
| 316 |
yydebug = yyn - '0'; |
| 317 |
} |
| 318 |
#endif |
| 319 |
|
| 320 |
yynerrs = 0; |
| 321 |
yyerrflag = 0; |
| 322 |
yychar = (-1); |
| 323 |
|
| 324 |
yyssp = yyss; |
| 325 |
yyvsp = yyvs; |
| 326 |
*yyssp = yystate = 0; |
| 327 |
|
| 328 |
yyloop: |
| 329 |
if (yyn = yydefred[yystate]) goto yyreduce; |
| 330 |
if (yychar < 0) |
| 331 |
{ |
| 332 |
if ((yychar = yylex()) < 0) yychar = 0; |
| 333 |
#if YYDEBUG |
| 334 |
if (yydebug) |
| 335 |
{ |
| 336 |
yys = 0; |
| 337 |
if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; |
| 338 |
if (!yys) yys = "illegal-symbol"; |
| 339 |
printf("%sdebug: state %d, reading %d (%s)\n", |
| 340 |
YYPREFIX, yystate, yychar, yys); |
| 341 |
} |
| 342 |
#endif |
| 343 |
} |
| 344 |
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && |
| 345 |
yyn <= YYTABLESIZE && yycheck[yyn] == yychar) |
| 346 |
{ |
| 347 |
#if YYDEBUG |
| 348 |
if (yydebug) |
| 349 |
printf("%sdebug: state %d, shifting to state %d\n", |
| 350 |
YYPREFIX, yystate, yytable[yyn]); |
| 351 |
#endif |
| 352 |
if (yyssp >= yyss + yystacksize - 1) |
| 353 |
{ |
| 354 |
goto yyoverflow; |
| 355 |
} |
| 356 |
*++yyssp = yystate = yytable[yyn]; |
| 357 |
*++yyvsp = yylval; |
| 358 |
yychar = (-1); |
| 359 |
if (yyerrflag > 0) --yyerrflag; |
| 360 |
goto yyloop; |
| 361 |
} |
| 362 |
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && |
| 363 |
yyn <= YYTABLESIZE && yycheck[yyn] == yychar) |
| 364 |
{ |
| 365 |
yyn = yytable[yyn]; |
| 366 |
goto yyreduce; |
| 367 |
} |
| 368 |
if (yyerrflag) goto yyinrecovery; |
| 369 |
#ifdef lint |
| 370 |
goto yynewerror; |
| 371 |
#endif |
| 372 |
yynewerror: |
| 373 |
yyerror("syntax error"); |
| 374 |
#ifdef lint |
| 375 |
goto yyerrlab; |
| 376 |
#endif |
| 377 |
yyerrlab: |
| 378 |
++yynerrs; |
| 379 |
yyinrecovery: |
| 380 |
if (yyerrflag < 3) |
| 381 |
{ |
| 382 |
yyerrflag = 3; |
| 383 |
for (;;) |
| 384 |
{ |
| 385 |
if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && |
| 386 |
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) |
| 387 |
{ |
| 388 |
#if YYDEBUG |
| 389 |
if (yydebug) |
| 390 |
printf("%sdebug: state %d, error recovery shifting\ |
| 391 |
to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); |
| 392 |
#endif |
| 393 |
if (yyssp >= yyss + yystacksize - 1) |
| 394 |
{ |
| 395 |
goto yyoverflow; |
| 396 |
} |
| 397 |
*++yyssp = yystate = yytable[yyn]; |
| 398 |
*++yyvsp = yylval; |
| 399 |
goto yyloop; |
| 400 |
} |
| 401 |
else |
| 402 |
{ |
| 403 |
#if YYDEBUG |
| 404 |
if (yydebug) |
| 405 |
printf("%sdebug: error recovery discarding state %d\n", |
| 406 |
YYPREFIX, *yyssp); |
| 407 |
#endif |
| 408 |
if (yyssp <= yyss) goto yyabort; |
| 409 |
--yyssp; |
| 410 |
--yyvsp; |
| 411 |
} |
| 412 |
} |
| 413 |
} |
| 414 |
else |
| 415 |
{ |
| 416 |
if (yychar == 0) goto yyabort; |
| 417 |
#if YYDEBUG |
| 418 |
if (yydebug) |
| 419 |
{ |
| 420 |
yys = 0; |
| 421 |
if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; |
| 422 |
if (!yys) yys = "illegal-symbol"; |
| 423 |
printf("%sdebug: state %d, error recovery discards token %d (%s)\n", |
| 424 |
YYPREFIX, yystate, yychar, yys); |
| 425 |
} |
| 426 |
#endif |
| 427 |
yychar = (-1); |
| 428 |
goto yyloop; |
| 429 |
} |
| 430 |
yyreduce: |
| 431 |
#if YYDEBUG |
| 432 |
if (yydebug) |
| 433 |
printf("%sdebug: state %d, reducing by rule %d (%s)\n", |
| 434 |
YYPREFIX, yystate, yyn, yyrule[yyn]); |
| 435 |
#endif |
| 436 |
yym = yylen[yyn]; |
| 437 |
yyval = yyvsp[1-yym]; |
| 438 |
switch (yyn) |
| 439 |
{ |
| 440 |
case 3: |
| 441 |
{g_tmpMacros.clear();} |
| 442 |
break; |
| 443 |
case 12: |
| 444 |
{ |
| 445 |
/*wxPrintf(wxT("CodeLite: syntax error, unexpected token '%s' found\n"), pp_lval.c_str());*/ |
| 446 |
} |
| 447 |
break; |
| 448 |
case 14: |
| 449 |
{ |
| 450 |
if(in_if_1 == 0) |
| 451 |
in_if_1 = 1; |
| 452 |
} |
| 453 |
break; |
| 454 |
case 15: |
| 455 |
{ |
| 456 |
PPToken token; |
| 457 |
token.fileName = g_filename; |
| 458 |
token.name = yyvsp[-1]; |
| 459 |
token.flags = (PPToken::IsValid | PPToken::IsOverridable); |
| 460 |
|
| 461 |
if(in_if_1) { |
| 462 |
/* the token was found in a '#if 1' block - dont allow overriding it*/ |
| 463 |
token.flags &= ~(PPToken::IsOverridable); |
| 464 |
} |
| 465 |
|
| 466 |
token.replacement = g_definition; |
| 467 |
|
| 468 |
if(g_forCC) { |
| 469 |
|
| 470 |
if(!token.replacement.empty()) { |
| 471 |
wxChar ch = token.replacement.at(0); |
| 472 |
if( !(ch >= (int)wxT('0') && ch <= (int)wxT('9')) ) |
| 473 |
PPTable::Instance()->Add( token ); |
| 474 |
} |
| 475 |
|
| 476 |
} else { |
| 477 |
PPTable::Instance()->Add( token ); |
| 478 |
} |
| 479 |
} |
| 480 |
break; |
| 481 |
case 16: |
| 482 |
{ |
| 483 |
PPToken token; |
| 484 |
token.fileName = g_filename; |
| 485 |
token.name = yyvsp[-4]; |
| 486 |
token.replacement = g_definition; |
| 487 |
token.flags = (PPToken::IsFunctionLike | PPToken::IsValid | PPToken::IsOverridable); |
| 488 |
if(in_if_1) { |
| 489 |
/* the token was found in a '#if 1' block - dont allow overriding it*/ |
| 490 |
token.flags &= ~(PPToken::IsOverridable); |
| 491 |
} |
| 492 |
token.processArgs( yyvsp[-2] ); |
| 493 |
PPTable::Instance()->Add( token ); |
| 494 |
} |
| 495 |
break; |
| 496 |
case 18: |
| 497 |
{ yyval = yyvsp[0]; } |
| 498 |
break; |
| 499 |
case 19: |
| 500 |
{ yyval = yyvsp[-2] + yyvsp[-1] + yyvsp[0]; } |
| 501 |
break; |
| 502 |
case 20: |
| 503 |
{ |
| 504 |
PPTable::Instance()->AddUsed(yyvsp[0]); |
| 505 |
} |
| 506 |
break; |
| 507 |
case 23: |
| 508 |
{ |
| 509 |
for(size_t i=0; i<g_tmpMacros.size(); i++) { |
| 510 |
/*wxPrintf(wxT("Collected: %s\n"), g_tmpMacros[i].c_str());*/ |
| 511 |
PPTable::Instance()->AddUsed(g_tmpMacros[i]); |
| 512 |
} |
| 513 |
} |
| 514 |
break; |
| 515 |
case 27: |
| 516 |
{g_tmpMacros.push_back(yyvsp[-1]);} |
| 517 |
break; |
| 518 |
case 28: |
| 519 |
{g_tmpMacros.push_back(yyvsp[0]);} |
| 520 |
break; |
| 521 |
case 29: |
| 522 |
{g_tmpMacros.push_back(yyvsp[-2]);} |
| 523 |
break; |
| 524 |
case 30: |
| 525 |
{g_tmpMacros.push_back(yyvsp[-3]);} |
| 526 |
break; |
| 527 |
case 31: |
| 528 |
{g_tmpMacros.push_back(yyvsp[-1]);} |
| 529 |
break; |
| 530 |
} |
| 531 |
yyssp -= yym; |
| 532 |
yystate = *yyssp; |
| 533 |
yyvsp -= yym; |
| 534 |
yym = yylhs[yyn]; |
| 535 |
if (yystate == 0 && yym == 0) |
| 536 |
{ |
| 537 |
#if YYDEBUG |
| 538 |
if (yydebug) |
| 539 |
printf("%sdebug: after reduction, shifting from state 0 to\ |
| 540 |
state %d\n", YYPREFIX, YYFINAL); |
| 541 |
#endif |
| 542 |
yystate = YYFINAL; |
| 543 |
*++yyssp = YYFINAL; |
| 544 |
*++yyvsp = yyval; |
| 545 |
if (yychar < 0) |
| 546 |
{ |
| 547 |
if ((yychar = yylex()) < 0) yychar = 0; |
| 548 |
#if YYDEBUG |
| 549 |
if (yydebug) |
| 550 |
{ |
| 551 |
yys = 0; |
| 552 |
if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; |
| 553 |
if (!yys) yys = "illegal-symbol"; |
| 554 |
printf("%sdebug: state %d, reading %d (%s)\n", |
| 555 |
YYPREFIX, YYFINAL, yychar, yys); |
| 556 |
} |
| 557 |
#endif |
| 558 |
} |
| 559 |
if (yychar == 0) goto yyaccept; |
| 560 |
goto yyloop; |
| 561 |
} |
| 562 |
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && |
| 563 |
yyn <= YYTABLESIZE && yycheck[yyn] == yystate) |
| 564 |
yystate = yytable[yyn]; |
| 565 |
else |
| 566 |
yystate = yydgoto[yym]; |
| 567 |
#if YYDEBUG |
| 568 |
if (yydebug) |
| 569 |
printf("%sdebug: after reduction, shifting from state %d \ |
| 570 |
to state %d\n", YYPREFIX, *yyssp, yystate); |
| 571 |
#endif |
| 572 |
if (yyssp >= yyss + yystacksize - 1) |
| 573 |
{ |
| 574 |
goto yyoverflow; |
| 575 |
} |
| 576 |
*++yyssp = yystate; |
| 577 |
*++yyvsp = yyval; |
| 578 |
goto yyloop; |
| 579 |
yyoverflow: |
| 580 |
yyerror("yacc stack overflow"); |
| 581 |
yyabort: |
| 582 |
return (1); |
| 583 |
yyaccept: |
| 584 |
return (0); |
| 585 |
} |