X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=preprocessor.c;h=e876e993ac05d47690de0b690d8eda71103d2ef0;hb=e0356ebe47a0d00d0b2d756de5daa5585542d4d9;hp=804921f691e765583fbc25da7dc5cede0a59a3d0;hpb=f9b4f77078061f79e1007fb396eb3504859cbb88;p=cparser diff --git a/preprocessor.c b/preprocessor.c index 804921f..e876e99 100644 --- a/preprocessor.c +++ b/preprocessor.c @@ -61,7 +61,7 @@ struct pp_input_t { pp_input_t *parent; }; -pp_input_t input; +static pp_input_t input; #define CC input.c static pp_input_t *input_stack; @@ -70,7 +70,7 @@ static struct obstack input_obstack; static pp_conditional_t *conditional_stack; -token_t pp_token; +static token_t pp_token; static bool resolve_escape_sequences = false; static bool do_print_spaces = true; static bool do_expansions; @@ -97,7 +97,7 @@ static bool open_input(const char *filename) input.bufpos = NULL; input.had_non_space = false; input.position.input_name = filename; - input.position.linenr = 1; + input.position.lineno = 1; /* indicate that we're at a new input */ print_line_directive(&input.position, input_stack != NULL ? "1" : NULL); @@ -214,14 +214,14 @@ static inline void put_back(int pc) if(CC == '\n') { \ next_char(); \ } \ - ++input.position.linenr; \ + ++input.position.lineno; \ code \ case '\n': \ next_char(); \ - ++input.position.linenr; \ + ++input.position.lineno; \ code -#define eat(c_type) do { assert(CC == c_type); next_char(); } while(0) +#define eat(c_type) (assert(CC == c_type), next_char()) static void maybe_concat_lines(void) { @@ -429,7 +429,7 @@ static int parse_escape_sequence(void) static void parse_string_literal(void) { - const unsigned start_linenr = input.position.linenr; + const unsigned start_linenr = input.position.lineno; eat('"'); @@ -451,7 +451,7 @@ static void parse_string_literal(void) case EOF: { source_position_t source_position; source_position.input_name = pp_token.source_position.input_name; - source_position.linenr = start_linenr; + source_position.lineno = start_linenr; errorf(&source_position, "string has no end"); pp_token.type = TP_ERROR; return; @@ -534,7 +534,7 @@ end_of_wide_char_constant: static void parse_character_constant(void) { - const unsigned start_linenr = input.position.linenr; + const unsigned start_linenr = input.position.lineno; eat('\''); @@ -554,7 +554,7 @@ static void parse_character_constant(void) case EOF: { source_position_t source_position; source_position.input_name = pp_token.source_position.input_name; - source_position.linenr = start_linenr; + source_position.lineno = start_linenr; errorf(&source_position, "EOF while parsing character constant"); pp_token.type = TP_ERROR; return; @@ -723,7 +723,7 @@ static void skip_multiline_comment(void) if(do_print_spaces) counted_spaces++; - unsigned start_linenr = input.position.linenr; + unsigned start_linenr = input.position.lineno; while(1) { switch(CC) { case '/': @@ -751,7 +751,7 @@ static void skip_multiline_comment(void) case EOF: { source_position_t source_position; source_position.input_name = pp_token.source_position.input_name; - source_position.linenr = start_linenr; + source_position.lineno = start_linenr; errorf(&source_position, "at end of file while looking for comment end"); return; } @@ -798,7 +798,7 @@ static void skip_spaces(bool skip_newline) if(CC == '\n') { next_char(); } - ++input.position.linenr; + ++input.position.lineno; if (do_print_spaces) ++counted_newlines; continue; @@ -808,7 +808,7 @@ static void skip_spaces(bool skip_newline) return; next_char(); - ++input.position.linenr; + ++input.position.lineno; if (do_print_spaces) ++counted_newlines; continue; @@ -951,15 +951,14 @@ end_number: #define ELSE_CODE(code) \ default: \ - code; \ + code \ + return; \ } \ } /* end of while(1) */ \ - break; #define ELSE(set_type) \ ELSE_CODE( \ pp_token.type = set_type; \ - return; \ ) static void next_preprocessing_token(void) @@ -1027,7 +1026,6 @@ restart: put_back(CC); CC = '.'; pp_token.type = '.'; - return; ) ELSE('.') case '&': @@ -1079,7 +1077,6 @@ restart: put_back(CC); CC = '%'; pp_token.type = '#'; - return; ) ELSE('#') ELSE('%') @@ -1177,7 +1174,7 @@ static void print_quoted_string(const char *const string) case '\?': fputs("\\?", out); break; default: if(!isprint(*c)) { - fprintf(out, "\\%03o", *c); + fprintf(out, "\\%03o", (unsigned)*c); break; } fputc(*c, out); @@ -1189,7 +1186,7 @@ static void print_quoted_string(const char *const string) static void print_line_directive(const source_position_t *pos, const char *add) { - fprintf(out, "# %u ", pos->linenr); + fprintf(out, "# %u ", pos->lineno); print_quoted_string(pos->input_name); if (add != NULL) { fputc(' ', out); @@ -1395,8 +1392,7 @@ static void parse_define_directive(void) pp_definition_t *old_definition = symbol->pp_definition; if (old_definition != NULL) { if (!pp_definitions_equal(old_definition, new_definition)) { - warningf(&input.position, "multiple definition of macro '%Y' (first defined %P)", - symbol, &old_definition->source_position); + warningf(WARN_OTHER, &input.position, "multiple definition of macro '%Y' (first defined %P)", symbol, &old_definition->source_position); } else { /* reuse the old definition */ obstack_free(&pp_obstack, new_definition); @@ -1431,7 +1427,7 @@ static void parse_undef_directive(void) next_preprocessing_token(); if(pp_token.type != '\n') { - warningf(&input.position, "extra tokens at end of #undef directive"); + warningf(WARN_OTHER, &input.position, "extra tokens at end of #undef directive"); } /* eat until '\n' */ eat_pp_directive(); @@ -1527,8 +1523,7 @@ static bool parse_include_directive(void) } if (pp_token.type != '\n' && pp_token.type != TP_EOF) { - warningf(&pp_token.source_position, - "extra tokens at end of #include directive"); + warningf(WARN_OTHER, &pp_token.source_position, "extra tokens at end of #include directive"); eat_pp_directive(); } @@ -1644,7 +1639,7 @@ static void parse_else_directive(void) if (pp_token.type != '\n') { if (!skip_mode) { - warningf(&pp_token.source_position, "extra tokens at end of #else"); + warningf(WARN_OTHER, &pp_token.source_position, "extra tokens at end of #else"); } eat_pp_directive(); } @@ -1676,8 +1671,7 @@ static void parse_endif_directive(void) if (pp_token.type != '\n') { if (!skip_mode) { - warningf(&pp_token.source_position, - "extra tokens at end of #endif"); + warningf(WARN_OTHER, &pp_token.source_position, "extra tokens at end of #endif"); } eat_pp_directive(); }