#define MATCH_NEWLINE(code) \
case '\r': \
next_char(); \
- if(input.c == '\n') { \
+ if (input.c == '\n') { \
next_char(); \
} \
++input.position.lineno; \
{
eat('\\');
- switch(input.c) {
+ switch (input.c) {
MATCH_NEWLINE(return;)
default:
next_real_char();
/* filter trigraphs and concatenated lines */
- if(UNLIKELY(input.c == '\\')) {
+ if (UNLIKELY(input.c == '\\')) {
maybe_concat_lines();
goto end_of_next_char;
}
- if(LIKELY(input.c != '?'))
+ if (LIKELY(input.c != '?'))
goto end_of_next_char;
next_real_char();
- if(LIKELY(input.c != '?')) {
+ if (LIKELY(input.c != '?')) {
put_back(input.c);
input.c = '?';
goto end_of_next_char;
}
next_real_char();
- switch(input.c) {
+ switch (input.c) {
case '=': input.c = '#'; break;
case '(': input.c = '['; break;
case '/': input.c = '\\'; maybe_concat_lines(); break;
*/
static inline bool is_octal_digit(int chr)
{
- switch(chr) {
+ switch (chr) {
case '0':
case '1':
case '2':
value = 8 * value + digit_value(input.c);
next_char();
- if(char_is_signed) {
+ if (char_is_signed) {
return (signed char) value;
} else {
return (unsigned char) value;
static int parse_hex_sequence(void)
{
int value = 0;
- while(isxdigit(input.c)) {
+ while (isxdigit(input.c)) {
value = 16 * value + digit_value(input.c);
next_char();
}
- if(char_is_signed) {
+ if (char_is_signed) {
return (signed char) value;
} else {
return (unsigned char) value;
int ec = input.c;
next_char();
- switch(ec) {
+ switch (ec) {
case '"': return '"';
case '\'': return '\'';
case '\\': return '\\';
eat('"');
int tc;
- while(1) {
- switch(input.c) {
+ while (true) {
+ switch (input.c) {
case '\\':
- if(resolve_escape_sequences) {
+ if (resolve_escape_sequences) {
tc = parse_escape_sequence();
obstack_1grow(&symbol_obstack, (char) tc);
} else {
#if 0 /* TODO hash */
/* check if there is already a copy of the string */
result = strset_insert(&stringset, string);
- if(result != string) {
+ if (result != string) {
obstack_free(&symbol_obstack, string);
}
#else
eat('\'');
int found_char = 0;
- while(1) {
- switch(input.c) {
+ while (true) {
+ switch (input.c) {
case '\\':
found_char = parse_escape_sequence();
break;
return;
default:
- if(found_char != 0) {
+ if (found_char != 0) {
parse_error("more than 1 characters in character "
"constant");
goto end_of_wide_char_constant;
eat('\'');
int tc;
- while(1) {
- switch(input.c) {
+ while (true) {
+ switch (input.c) {
case '\\':
tc = parse_escape_sequence();
obstack_1grow(&symbol_obstack, (char) tc);
pp_definition_t *definition = current_expansion;
restart:
- if(definition->list_len == 0
+ if (definition->list_len == 0
|| definition->expand_pos >= definition->list_len) {
/* we're finished with the current macro, move up 1 level in the
* expansion stack */
definition->is_expanding = false;
/* it was the outermost expansion, parse normal pptoken */
- if(parent == NULL) {
+ if (parent == NULL) {
current_expansion = NULL;
next_preprocessing_token();
return;
pp_token = definition->token_list[definition->expand_pos];
++definition->expand_pos;
- if(pp_token.type != TP_IDENTIFIER)
+ if (pp_token.type != TP_IDENTIFIER)
return;
/* if it was an identifier then we might need to expand again */
pp_definition_t *symbol_definition = pp_token.symbol->pp_definition;
- if(symbol_definition != NULL && !symbol_definition->is_expanding) {
+ if (symbol_definition != NULL && !symbol_definition->is_expanding) {
symbol_definition->parent_expansion = definition;
symbol_definition->expand_pos = 0;
symbol_definition->is_expanding = true;
static void skip_line_comment(void)
{
- if(do_print_spaces)
+ if (do_print_spaces)
counted_spaces++;
- while(1) {
- switch(input.c) {
+ while (true) {
+ switch (input.c) {
case EOF:
return;
static void skip_multiline_comment(void)
{
- if(do_print_spaces)
+ if (do_print_spaces)
counted_spaces++;
unsigned start_linenr = input.position.lineno;
- while(1) {
- switch(input.c) {
+ while (true) {
+ switch (input.c) {
case '/':
next_char();
if (input.c == '*') {
break;
case '*':
next_char();
- if(input.c == '/') {
+ if (input.c == '/') {
next_char();
return;
}
break;
MATCH_NEWLINE(
- if(do_print_spaces) {
+ if (do_print_spaces) {
counted_newlines++;
counted_spaces = 0;
}
return;
next_char();
- if(input.c == '\n') {
+ if (input.c == '\n') {
next_char();
}
++input.position.lineno;
obstack_1grow(&symbol_obstack, (char) input.c);
next_char();
- while(1) {
- switch(input.c) {
+ while (true) {
+ switch (input.c) {
DIGITS
SYMBOL_CHARS
obstack_1grow(&symbol_obstack, (char) input.c);
obstack_1grow(&symbol_obstack, (char) input.c);
next_char();
- while(1) {
- switch(input.c) {
+ while (true) {
+ switch (input.c) {
case '.':
DIGITS
SYMBOL_CHARS_WITHOUT_E_P
case 'P':
obstack_1grow(&symbol_obstack, (char) input.c);
next_char();
- if(input.c == '+' || input.c == '-') {
+ if (input.c == '+' || input.c == '-') {
obstack_1grow(&symbol_obstack, (char) input.c);
next_char();
}
#define MAYBE_PROLOG \
next_char(); \
- while(1) { \
- switch(input.c) {
+ while (true) { \
+ switch (input.c) {
#define MAYBE(ch, set_type) \
case ch: \
code \
return; \
} \
- } /* end of while(1) */ \
+ }
#define ELSE(set_type) \
ELSE_CODE( \
static void next_preprocessing_token(void)
{
- if(current_expansion != NULL) {
+ if (current_expansion != NULL) {
expand_next();
return;
}
pp_token.source_position = input.position;
restart:
- switch(input.c) {
+ switch (input.c) {
case ' ':
case '\t':
if (do_print_spaces)
{
fputc('"', out);
for (const char *c = string; *c != 0; ++c) {
- switch(*c) {
+ switch (*c) {
case '"': fputs("\\\"", out); break;
case '\\': fputs("\\\\", out); break;
case '\a': fputs("\\a", out); break;
case '\v': fputs("\\v", out); break;
case '\?': fputs("\\?", out); break;
default:
- if(!isprint(*c)) {
+ if (!isprint(*c)) {
fprintf(out, "\\%03o", (unsigned)*c);
break;
}
input.had_non_space = true;
}
- switch(pp_token.type) {
+ switch (pp_token.type) {
case TP_IDENTIFIER:
fputs(pp_token.symbol->string, out);
break;
static void eat_pp_directive(void)
{
- while(pp_token.type != '\n' && pp_token.type != TP_EOF) {
+ while (pp_token.type != '\n' && pp_token.type != TP_EOF) {
next_preprocessing_token();
}
}
static bool strings_equal(const string_t *string1, const string_t *string2)
{
size_t size = string1->size;
- if(size != string2->size)
+ if (size != string2->size)
return false;
const char *c1 = string1->begin;
const char *c2 = string2->begin;
- for(size_t i = 0; i < size; ++i, ++c1, ++c2) {
- if(*c1 != *c2)
+ for (size_t i = 0; i < size; ++i, ++c1, ++c2) {
+ if (*c1 != *c2)
return false;
}
return true;
static bool pp_tokens_equal(const token_t *token1, const token_t *token2)
{
- if(token1->type != token2->type)
+ if (token1->type != token2->type)
return false;
- switch(token1->type) {
+ switch (token1->type) {
case TP_HEADERNAME:
/* TODO */
return false;
static bool pp_definitions_equal(const pp_definition_t *definition1,
const pp_definition_t *definition2)
{
- if(definition1->list_len != definition2->list_len)
+ if (definition1->list_len != definition2->list_len)
return false;
size_t len = definition1->list_len;
const token_t *t1 = definition1->token_list;
const token_t *t2 = definition2->token_list;
- for(size_t i = 0; i < len; ++i, ++t1, ++t2) {
- if(!pp_tokens_equal(t1, t2))
+ for (size_t i = 0; i < len; ++i, ++t1, ++t2) {
+ if (!pp_tokens_equal(t1, t2))
return false;
}
return true;
{
eat_pp(TP_undef);
- if(pp_token.type != TP_IDENTIFIER) {
+ if (pp_token.type != TP_IDENTIFIER) {
errorf(&input.position,
"expected identifier after #undef, got '%t'", &pp_token);
eat_pp_directive();
symbol->pp_definition = NULL;
next_preprocessing_token();
- if(pp_token.type != '\n') {
+ if (pp_token.type != '\n') {
warningf(WARN_OTHER, &input.position, "extra tokens at end of #undef directive");
}
/* eat until '\n' */
eat_pp('#');
if (skip_mode) {
- switch(pp_token.type) {
+ switch (pp_token.type) {
case TP_ifdef:
case TP_ifndef:
parse_ifdef_ifndef_directive();
break;
}
} else {
- switch(pp_token.type) {
+ switch (pp_token.type) {
case TP_define:
parse_define_directive();
break;
bool ok = open_input(filename);
assert(ok);
- while(true) {
+ while (true) {
/* we're at a line begin */
- if(pp_token.type == '#') {
+ if (pp_token.type == '#') {
parse_preprocessing_directive();
} else {
/* parse+emit a line */
- while(pp_token.type != '\n') {
- if(pp_token.type == TP_EOF)
+ while (pp_token.type != '\n') {
+ if (pp_token.type == TP_EOF)
goto end_of_main_loop;
emit_pp_token();
next_preprocessing_token();