7 #include "lang_features.h"
8 #include "diagnostic.h"
9 #include "string_rep.h"
19 #define INCLUDE_LIMIT 199 /* 199 is for gcc "compatibility" */
21 struct pp_definition_t {
23 source_position_t source_position;
24 pp_definition_t *parent_expansion;
27 bool is_expanding : 1;
28 size_t argument_count;
31 token_t *replacement_list;
34 typedef struct pp_input_t pp_input_t;
38 char buf[1024+MAX_PUTBACK];
41 source_position_t position;
49 static pp_input_t *input_stack;
50 static unsigned n_inputs;
51 static struct obstack input_obstack;
54 static bool resolve_escape_sequences = false;
55 static bool do_print_spaces = true;
57 static struct obstack pp_obstack;
58 static unsigned counted_newlines;
59 static unsigned counted_spaces;
60 static const char *printed_input_name = NULL;
61 static pp_definition_t *current_expansion = NULL;
62 static bool do_expansions;
64 static inline void next_char(void);
65 static void next_preprocessing_token(void);
66 static void print_line_directive(const source_position_t *pos, const char *add);
67 static void print_spaces(void);
69 static bool open_input(const char *filename)
71 FILE *file = fopen(filename, "r");
78 input.had_non_space = false;
79 input.position.input_name = filename;
80 input.position.linenr = 1;
82 /* indicate that we're at a new input */
83 print_line_directive(&input.position, input_stack != NULL ? "1" : NULL);
88 /* read first char and first token */
90 next_preprocessing_token();
95 static void close_input(void)
97 /* ensure we have a newline at EOF */
98 if (input.had_non_space) {
102 assert(input.file != NULL);
111 static void push_input(void)
113 pp_input_t *saved_input
114 = obstack_alloc(&input_obstack, sizeof(*saved_input));
116 memcpy(saved_input, &input, sizeof(*saved_input));
118 /* adjust buffer positions */
119 if (input.bufpos != NULL)
120 saved_input->bufpos = saved_input->buf + (input.bufpos - input.buf);
121 if (input.bufend != NULL)
122 saved_input->bufend = saved_input->buf + (input.bufend - input.buf);
124 saved_input->parent = input_stack;
125 input_stack = saved_input;
129 static void pop_restore_input(void)
131 assert(n_inputs > 0);
132 assert(input_stack != NULL);
134 pp_input_t *saved_input = input_stack;
136 memcpy(&input, saved_input, sizeof(input));
139 /* adjust buffer positions */
140 if (saved_input->bufpos != NULL)
141 input.bufpos = input.buf + (saved_input->bufpos - saved_input->buf);
142 if (saved_input->bufend != NULL)
143 input.bufend = input.buf + (saved_input->bufend - saved_input->buf);
145 input_stack = saved_input->parent;
146 obstack_free(&input_obstack, saved_input);
151 * Prints a parse error message at the current token.
153 * @param msg the error message
155 static void parse_error(const char *msg)
157 errorf(&pp_token.source_position, "%s", msg);
160 static inline void next_real_char(void)
162 assert(input.bufpos <= input.bufend);
163 if (input.bufpos >= input.bufend) {
164 size_t s = fread(input.buf + MAX_PUTBACK, 1,
165 sizeof(input.buf) - MAX_PUTBACK, input.file);
170 input.bufpos = input.buf + MAX_PUTBACK;
171 input.bufend = input.buf + MAX_PUTBACK + s;
173 CC = *input.bufpos++;
177 * Put a character back into the buffer.
179 * @param pc the character to put back
181 static inline void put_back(int pc)
183 assert(input.bufpos > input.buf);
184 *(--input.bufpos - input.buf + input.buf) = (char) pc;
187 printf("putback '%c'\n", pc);
191 #define MATCH_NEWLINE(code) \
197 ++input.position.linenr; \
201 ++input.position.linenr; \
204 #define eat(c_type) do { assert(CC == c_type); next_char(); } while(0)
206 static void maybe_concat_lines(void)
211 MATCH_NEWLINE(return;)
222 * Set c to the next input character, ie.
223 * after expanding trigraphs.
225 static inline void next_char(void)
229 /* filter trigraphs and concatenated lines */
230 if(UNLIKELY(CC == '\\')) {
231 maybe_concat_lines();
232 goto end_of_next_char;
235 if(LIKELY(CC != '?'))
236 goto end_of_next_char;
239 if(LIKELY(CC != '?')) {
242 goto end_of_next_char;
247 case '=': CC = '#'; break;
248 case '(': CC = '['; break;
249 case '/': CC = '\\'; maybe_concat_lines(); break;
250 case ')': CC = ']'; break;
251 case '\'': CC = '^'; break;
252 case '<': CC = '{'; break;
253 case '!': CC = '|'; break;
254 case '>': CC = '}'; break;
255 case '-': CC = '~'; break;
265 printf("nchar '%c'\n", CC);
272 * Returns true if the given char is a octal digit.
274 * @param char the character to check
276 static inline bool is_octal_digit(int chr)
294 * Returns the value of a digit.
295 * The only portable way to do it ...
297 static int digit_value(int digit) {
322 panic("wrong character given");
327 * Parses an octal character sequence.
329 * @param first_digit the already read first digit
331 static int parse_octal_sequence(const int first_digit)
333 assert(is_octal_digit(first_digit));
334 int value = digit_value(first_digit);
335 if (!is_octal_digit(CC)) return value;
336 value = 8 * value + digit_value(CC);
338 if (!is_octal_digit(CC)) return value;
339 value = 8 * value + digit_value(CC);
343 return (signed char) value;
345 return (unsigned char) value;
350 * Parses a hex character sequence.
352 static int parse_hex_sequence(void)
355 while(isxdigit(CC)) {
356 value = 16 * value + digit_value(CC);
361 return (signed char) value;
363 return (unsigned char) value;
368 * Parse an escape sequence.
370 static int parse_escape_sequence(void)
378 case '"': return '"';
379 case '\'': return '\'';
380 case '\\': return '\\';
381 case '?': return '\?';
382 case 'a': return '\a';
383 case 'b': return '\b';
384 case 'f': return '\f';
385 case 'n': return '\n';
386 case 'r': return '\r';
387 case 't': return '\t';
388 case 'v': return '\v';
390 return parse_hex_sequence();
399 return parse_octal_sequence(ec);
401 parse_error("reached end of file while parsing escape sequence");
404 parse_error("unknown escape sequence");
409 static void parse_string_literal(void)
411 const unsigned start_linenr = input.position.linenr;
419 if(resolve_escape_sequences) {
420 tc = parse_escape_sequence();
421 obstack_1grow(&symbol_obstack, (char) tc);
423 obstack_1grow(&symbol_obstack, (char) CC);
425 obstack_1grow(&symbol_obstack, (char) CC);
431 source_position_t source_position;
432 source_position.input_name = pp_token.source_position.input_name;
433 source_position.linenr = start_linenr;
434 errorf(&source_position, "string has no end");
435 pp_token.type = TP_ERROR;
444 obstack_1grow(&symbol_obstack, (char) CC);
451 /* add finishing 0 to the string */
452 obstack_1grow(&symbol_obstack, '\0');
453 const size_t size = (size_t)obstack_object_size(&symbol_obstack);
454 const char *const string = obstack_finish(&symbol_obstack);
456 #if 0 /* TODO hash */
457 /* check if there is already a copy of the string */
458 result = strset_insert(&stringset, string);
459 if(result != string) {
460 obstack_free(&symbol_obstack, string);
463 const char *const result = string;
466 pp_token.type = TP_STRING_LITERAL;
467 pp_token.v.string.begin = result;
468 pp_token.v.string.size = size;
471 static void parse_wide_character_constant(void)
479 found_char = parse_escape_sequence();
483 parse_error("newline while parsing character constant");
489 goto end_of_wide_char_constant;
492 parse_error("EOF while parsing character constant");
493 pp_token.type = TP_ERROR;
497 if(found_char != 0) {
498 parse_error("more than 1 characters in character "
500 goto end_of_wide_char_constant;
509 end_of_wide_char_constant:
510 pp_token.type = TP_WIDE_CHARACTER_CONSTANT;
514 static void parse_wide_string_literal(void)
516 const unsigned start_linenr = input.position.linenr;
524 wchar_rep_t tc = parse_escape_sequence();
525 obstack_grow(&symbol_obstack, &tc, sizeof(tc));
530 source_position_t source_position;
531 source_position.input_name = pp_token.source_position.input_name;
532 source_position.linenr = start_linenr;
533 errorf(&source_position, "string has no end");
534 pp_token.type = TP_ERROR;
544 obstack_grow(&symbol_obstack, &tc, sizeof(tc));
552 /* add finishing 0 to the string */
553 static const wchar_rep_t nul = L'\0';
554 obstack_grow(&symbol_obstack, &nul, sizeof(nul));
557 = (size_t)obstack_object_size(&symbol_obstack) / sizeof(wchar_rep_t);
558 const wchar_rep_t *const string = obstack_finish(&symbol_obstack);
560 #if 0 /* TODO hash */
561 /* check if there is already a copy of the string */
562 const wchar_rep_t *const result = strset_insert(&stringset, string);
563 if(result != string) {
564 obstack_free(&symbol_obstack, string);
567 const wchar_rep_t *const result = string;
570 pp_token.type = TP_WIDE_STRING_LITERAL;
571 pp_token.v.wide_string.begin = result;
572 pp_token.v.wide_string.size = size;
575 static void parse_character_constant(void)
577 const unsigned start_linenr = input.position.linenr;
585 tc = parse_escape_sequence();
586 obstack_1grow(&symbol_obstack, (char) tc);
590 parse_error("newline while parsing character constant");
595 source_position_t source_position;
596 source_position.input_name = pp_token.source_position.input_name;
597 source_position.linenr = start_linenr;
598 errorf(&source_position, "EOF while parsing character constant");
599 pp_token.type = TP_ERROR;
605 goto end_of_char_constant;
608 obstack_1grow(&symbol_obstack, (char) CC);
615 end_of_char_constant:;
616 const size_t size = (size_t)obstack_object_size(&symbol_obstack);
617 const char *const string = obstack_finish(&symbol_obstack);
619 pp_token.type = TP_CHARACTER_CONSTANT;
620 pp_token.v.string.begin = string;
621 pp_token.v.string.size = size;
624 #define SYMBOL_CHARS_WITHOUT_E_P \
675 #define SYMBOL_CHARS \
676 SYMBOL_CHARS_WITHOUT_E_P \
695 * returns next final token from a preprocessor macro expansion
697 static void expand_next(void)
699 assert(current_expansion != NULL);
701 pp_definition_t *definition = current_expansion;
704 if(definition->list_len == 0
705 || definition->expand_pos >= definition->list_len) {
706 /* we're finished with the current macro, move up 1 level in the
708 pp_definition_t *parent = definition->parent_expansion;
709 definition->parent_expansion = NULL;
710 definition->is_expanding = false;
712 /* it was the outermost expansion, parse normal pptoken */
714 current_expansion = NULL;
715 next_preprocessing_token();
719 current_expansion = definition;
722 pp_token = definition->replacement_list[definition->expand_pos];
723 ++definition->expand_pos;
725 if(pp_token.type != TP_IDENTIFIER)
728 /* if it was an identifier then we might need to expand again */
729 pp_definition_t *symbol_definition = pp_token.v.symbol->pp_definition;
730 if(symbol_definition != NULL && !symbol_definition->is_expanding) {
731 symbol_definition->parent_expansion = definition;
732 symbol_definition->expand_pos = 0;
733 symbol_definition->is_expanding = true;
734 definition = symbol_definition;
735 current_expansion = definition;
740 static void parse_symbol(void)
742 obstack_1grow(&symbol_obstack, (char) CC);
749 obstack_1grow(&symbol_obstack, (char) CC);
759 obstack_1grow(&symbol_obstack, '\0');
760 char *string = obstack_finish(&symbol_obstack);
762 /* might be a wide string or character constant ( L"string"/L'c' ) */
763 if(CC == '"' && string[0] == 'L' && string[1] == '\0') {
764 obstack_free(&symbol_obstack, string);
765 parse_wide_string_literal();
767 } else if(CC == '\'' && string[0] == 'L' && string[1] == '\0') {
768 obstack_free(&symbol_obstack, string);
769 parse_wide_character_constant();
773 symbol_t *symbol = symbol_table_insert(string);
775 pp_token.type = symbol->pp_ID;
776 pp_token.v.symbol = symbol;
778 /* we can free the memory from symbol obstack if we already had an entry in
779 * the symbol table */
780 if(symbol->string != string) {
781 obstack_free(&symbol_obstack, string);
784 pp_definition_t *pp_definition = symbol->pp_definition;
785 if(do_expansions && pp_definition != NULL) {
786 pp_definition->expand_pos = 0;
787 pp_definition->is_expanding = true,
788 current_expansion = pp_definition;
793 static void parse_number(void)
795 obstack_1grow(&symbol_obstack, (char) CC);
802 SYMBOL_CHARS_WITHOUT_E_P
803 obstack_1grow(&symbol_obstack, (char) CC);
811 obstack_1grow(&symbol_obstack, (char) CC);
813 if(CC == '+' || CC == '-') {
814 obstack_1grow(&symbol_obstack, (char) CC);
825 obstack_1grow(&symbol_obstack, '\0');
826 size_t size = obstack_object_size(&symbol_obstack);
827 char *string = obstack_finish(&symbol_obstack);
829 pp_token.type = TP_NUMBER;
830 pp_token.v.string.begin = string;
831 pp_token.v.string.size = size;
834 static void skip_multiline_comment(void)
836 unsigned start_linenr = input.position.linenr;
843 /* TODO: nested comment, warn here */
855 if(do_print_spaces) {
863 source_position_t source_position;
864 source_position.input_name = pp_token.source_position.input_name;
865 source_position.linenr = start_linenr;
866 errorf(&source_position, "at end of file while looking for comment end");
877 static void skip_line_comment(void)
897 #define MAYBE_PROLOG \
902 #define MAYBE(ch, set_type) \
905 pp_token.type = set_type; \
908 #define ELSE_CODE(code) \
912 } /* end of while(1) */ \
915 #define ELSE(set_type) \
917 pp_token.type = set_type; \
921 static void next_preprocessing_token(void)
923 if(current_expansion != NULL) {
928 pp_token.source_position = input.position;
942 pp_token.type = '\n';
955 parse_string_literal();
959 parse_character_constant();
981 MAYBE('.', TP_DOTDOTDOT)
991 MAYBE('&', TP_ANDAND)
992 MAYBE('=', TP_ANDEQUAL)
996 MAYBE('=', TP_ASTERISKEQUAL)
1000 MAYBE('+', TP_PLUSPLUS)
1001 MAYBE('=', TP_PLUSEQUAL)
1005 MAYBE('>', TP_MINUSGREATER)
1006 MAYBE('-', TP_MINUSMINUS)
1007 MAYBE('=', TP_MINUSEQUAL)
1011 MAYBE('=', TP_EXCLAMATIONMARKEQUAL)
1015 MAYBE('=', TP_SLASHEQUAL)
1018 skip_multiline_comment();
1024 skip_line_comment();
1032 MAYBE('=', TP_PERCENTEQUAL)
1037 MAYBE(':', TP_HASHHASH)
1041 pp_token.type = '#';
1050 MAYBE('=', TP_LESSEQUAL)
1053 MAYBE('=', TP_LESSLESSEQUAL)
1058 MAYBE('=', TP_GREATEREQUAL)
1061 MAYBE('=', TP_GREATERGREATEREQUAL)
1062 ELSE(TP_GREATERGREATER)
1066 MAYBE('=', TP_CARETEQUAL)
1070 MAYBE('=', TP_PIPEEQUAL)
1071 MAYBE('|', TP_PIPEPIPE)
1079 MAYBE('=', TP_EQUALEQUAL)
1083 MAYBE('#', TP_HASHHASH)
1102 if (input_stack != NULL) {
1104 pop_restore_input();
1105 counted_newlines = 0;
1107 /* hack to output correct line number */
1108 print_line_directive(&input.position, "2");
1109 next_preprocessing_token();
1111 pp_token.type = TP_EOF;
1117 errorf(&pp_token.source_position, "unknown character '%c' found\n", CC);
1118 pp_token.type = TP_ERROR;
1123 static void print_quoted_string(const char *const string)
1126 for (const char *c = string; *c != 0; ++c) {
1128 case '"': fputs("\\\"", out); break;
1129 case '\\': fputs("\\\\", out); break;
1130 case '\a': fputs("\\a", out); break;
1131 case '\b': fputs("\\b", out); break;
1132 case '\f': fputs("\\f", out); break;
1133 case '\n': fputs("\\n", out); break;
1134 case '\r': fputs("\\r", out); break;
1135 case '\t': fputs("\\t", out); break;
1136 case '\v': fputs("\\v", out); break;
1137 case '\?': fputs("\\?", out); break;
1140 fprintf(out, "\\%03o", *c);
1150 static void print_line_directive(const source_position_t *pos, const char *add)
1152 fprintf(out, "# %d ", pos->linenr);
1153 print_quoted_string(pos->input_name);
1160 printed_input_name = pos->input_name;
1163 static void print_spaces(void)
1165 if (counted_newlines >= 9) {
1166 if (input.had_non_space) {
1169 print_line_directive(&pp_token.source_position, NULL);
1170 counted_newlines = 0;
1172 for (unsigned i = 0; i < counted_newlines; ++i)
1174 counted_newlines = 0;
1176 for (unsigned i = 0; i < counted_spaces; ++i)
1181 static void emit_pp_token(void)
1183 if (pp_token.type != '\n') {
1185 input.had_non_space = true;
1188 switch(pp_token.type) {
1190 fputs(pp_token.v.symbol->string, out);
1193 fputs(pp_token.v.string.begin, out);
1195 case TP_STRING_LITERAL:
1197 fputs(pp_token.v.string.begin, out);
1203 print_pp_token_type(out, pp_token.type);
1208 static void eat_pp(preprocessor_token_type_t type)
1211 assert(pp_token.type == type);
1212 next_preprocessing_token();
1215 static void eat_pp_directive(void)
1217 while(pp_token.type != '\n' && pp_token.type != TP_EOF) {
1218 next_preprocessing_token();
1222 static bool strings_equal(const string_t *string1, const string_t *string2)
1224 size_t size = string1->size;
1225 if(size != string2->size)
1228 const char *c1 = string1->begin;
1229 const char *c2 = string2->begin;
1230 for(size_t i = 0; i < size; ++i, ++c1, ++c2) {
1237 static bool wide_strings_equal(const wide_string_t *string1,
1238 const wide_string_t *string2)
1240 size_t size = string1->size;
1241 if(size != string2->size)
1244 const wchar_rep_t *c1 = string1->begin;
1245 const wchar_rep_t *c2 = string2->begin;
1246 for(size_t i = 0; i < size; ++i, ++c1, ++c2) {
1253 static bool pp_tokens_equal(const token_t *token1, const token_t *token2)
1255 if(token1->type != token2->type)
1258 switch(token1->type) {
1263 return token1->v.symbol == token2->v.symbol;
1265 case TP_CHARACTER_CONSTANT:
1266 case TP_STRING_LITERAL:
1267 return strings_equal(&token1->v.string, &token2->v.string);
1269 case TP_WIDE_CHARACTER_CONSTANT:
1270 case TP_WIDE_STRING_LITERAL:
1271 return wide_strings_equal(&token1->v.wide_string,
1272 &token2->v.wide_string);
1278 static bool pp_definitions_equal(const pp_definition_t *definition1,
1279 const pp_definition_t *definition2)
1281 if(definition1->list_len != definition2->list_len)
1284 size_t len = definition1->list_len;
1285 const token_t *t1 = definition1->replacement_list;
1286 const token_t *t2 = definition2->replacement_list;
1287 for(size_t i = 0; i < len; ++i, ++t1, ++t2) {
1288 if(!pp_tokens_equal(t1, t2))
1294 static void parse_define_directive(void)
1298 if(pp_token.type != TP_IDENTIFIER) {
1299 errorf(&pp_token.source_position,
1300 "expected identifier after #define, got '%T'", &pp_token);
1304 symbol_t *symbol = pp_token.v.symbol;
1306 pp_definition_t *new_definition
1307 = obstack_alloc(&pp_obstack, sizeof(new_definition[0]));
1308 memset(new_definition, 0, sizeof(new_definition[0]));
1309 new_definition->source_position = input.position;
1311 /* this is probably the only place where spaces are significant in the
1312 * lexer (except for the fact that they separate tokens). #define b(x)
1313 * is something else than #define b (x) */
1314 //token_t *arguments = NULL;
1316 next_preprocessing_token();
1317 while(pp_token.type != ')') {
1318 if(pp_token.type == TP_DOTDOTDOT) {
1319 new_definition->is_variadic = true;
1320 next_preprocessing_token();
1321 if(pp_token.type != ')') {
1322 errorf(&input.position,
1323 "'...' not at end of macro argument list");
1326 } else if(pp_token.type != TP_IDENTIFIER) {
1327 next_preprocessing_token();
1331 next_preprocessing_token();
1334 /* construct a new pp_definition on the obstack */
1335 assert(obstack_object_size(&pp_obstack) == 0);
1336 size_t list_len = 0;
1337 while(pp_token.type != '\n' && pp_token.type != TP_EOF) {
1338 obstack_grow(&pp_obstack, &pp_token, sizeof(pp_token));
1340 next_preprocessing_token();
1343 new_definition->list_len = list_len;
1344 new_definition->replacement_list = obstack_finish(&pp_obstack);
1346 pp_definition_t *old_definition = symbol->pp_definition;
1347 if(old_definition != NULL) {
1348 if(!pp_definitions_equal(old_definition, new_definition)) {
1349 warningf(&input.position, "multiple definition of macro '%Y' (first defined %P)",
1350 symbol, &old_definition->source_position);
1352 /* reuse the old definition */
1353 obstack_free(&pp_obstack, new_definition);
1354 new_definition = old_definition;
1358 symbol->pp_definition = new_definition;
1361 static void parse_undef_directive(void)
1365 if(pp_token.type != TP_IDENTIFIER) {
1366 errorf(&input.position,
1367 "expected identifier after #undef, got '%T'", &pp_token);
1372 symbol_t *symbol = pp_token.v.symbol;
1373 symbol->pp_definition = NULL;
1374 next_preprocessing_token();
1376 if(pp_token.type != '\n') {
1377 warningf(&input.position, "extra tokens at end of #undef directive");
1379 /* eat until '\n' */
1383 static const char *parse_headername(void)
1385 /* behind an #include we can have the special headername lexems, check
1389 while (CC == ' ' || CC == '\t') {
1393 assert(obstack_object_size(&input_obstack) == 0);
1397 /* for now until we have proper searchpath handling */
1398 obstack_1grow(&input_obstack, '.');
1399 obstack_1grow(&input_obstack, '/');
1407 parse_error("header name without closing '>'");
1412 goto finished_headername;
1414 obstack_1grow(&input_obstack, (char) CC);
1417 /* we should never be here */
1420 /* for now until we have proper searchpath handling */
1421 obstack_1grow(&input_obstack, '.');
1422 obstack_1grow(&input_obstack, '/');
1430 parse_error("header name without closing '>'");
1435 goto finished_headername;
1437 obstack_1grow(&input_obstack, (char) CC);
1440 /* we should never be here */
1443 /* TODO: do normale pp_token parsing and concatenate results */
1444 panic("pp_token concat include not implemented yet");
1447 finished_headername:
1448 obstack_1grow(&input_obstack, '\0');
1449 char *headername = obstack_finish(&input_obstack);
1451 /* TODO: iterate search-path to find the file */
1453 next_preprocessing_token();
1458 static void parse_include_directive(void)
1460 /* don't eat the TP_include here!
1461 * we need an alternative parsing for the next token */
1465 const char *headername = parse_headername();
1466 if (headername == NULL) {
1471 if (pp_token.type != '\n' && pp_token.type != TP_EOF) {
1472 warningf(&pp_token.source_position,
1473 "extra tokens at end of #include directive");
1477 if (n_inputs > INCLUDE_LIMIT) {
1478 errorf(&pp_token.source_position, "#include nested too deeply");
1480 next_preprocessing_token();
1486 bool res = open_input(headername);
1488 errorf(&pp_token.source_position,
1489 "failed including '%s': %s", headername, strerror(errno));
1490 pop_restore_input();
1495 static void parse_preprocessing_directive(void)
1497 do_print_spaces = false;
1498 do_expansions = false;
1501 switch(pp_token.type) {
1503 parse_define_directive();
1506 parse_undef_directive();
1509 parse_include_directive();
1510 /* no need to parse ending '\n' */
1511 do_print_spaces = true;
1512 do_expansions = true;
1515 errorf(&pp_token.source_position,
1516 "invalid preprocessing directive #%T", &pp_token);
1521 do_print_spaces = true;
1522 do_expansions = true;
1525 assert(pp_token.type == '\n' || pp_token.type == TP_EOF);
1526 next_preprocessing_token();
1529 #define GCC_COMPAT_MODE
1531 int pptest_main(int argc, char **argv);
1532 int pptest_main(int argc, char **argv)
1534 init_symbol_table();
1537 obstack_init(&pp_obstack);
1538 obstack_init(&input_obstack);
1540 const char *filename = "t.c";
1546 #ifdef GCC_COMPAT_MODE
1547 /* this is here so we can directly compare "gcc -E" output and our output */
1548 fprintf(out, "# 1 \"%s\"\n", filename);
1549 fputs("# 1 \"<built-in>\"\n", out);
1550 fputs("# 1 \"<command-line>\"\n", out);
1553 bool ok = open_input(filename);
1557 /* we're at a line begin */
1558 if(pp_token.type == '#') {
1559 parse_preprocessing_directive();
1561 /* parse+emit a line */
1562 while(pp_token.type != '\n') {
1563 if(pp_token.type == TP_EOF)
1564 goto end_of_main_loop;
1566 next_preprocessing_token();
1569 next_preprocessing_token();
1576 obstack_free(&input_obstack, NULL);
1577 obstack_free(&pp_obstack, NULL);
1580 exit_symbol_table();