}*/
static void skip_initializer (void) {
-
- if (tok.kind == TOK_LBRACE) {
- skip_balanced_until (TOK_COMMA, TOK_SEMI, TOK_EOF);
- } else {
- skip_balanced_until (TOK_COMMA, TOK_SEMI, TOK_EOF);
- }
-
+ skip_balanced_until (TOK_COMMA, TOK_RBRACE, TOK_EOF);
}
static void apply_typedef_array_to_declarator (void) {
static void parse_local_aggregate_initializer_values (struct local_init *inits, int *init_count, int max_inits, long base_offset, const int *fields, int field_count) {
int field_index = 0;
- long field_offset = 0;
int braced = 0;
+ long field_offset = 0;
+
if (tok.kind == TOK_LBRACE) {
+
braced = 1;
get_token ();
+
}
while (field_index < field_count) {
* The normal arithmetic path below can operate on the qword value already
* held in REG.
*/
- if (postfix_member_seen && postfix_member_is_unsigned) {
- is_unsigned = 1;
+ if (postfix_member_seen) {
+ is_unsigned = postfix_member_is_unsigned ? 1 : 0;
}
expr_pointer_depth = rhs_last_pointer_depth;
int64_s rhs_enum_value;
enum token_kind op;
- int lhs_pointer_depth;
- int is_unsigned;
+ int is_unsigned = emit_load_assignment_binary_expression_prec_to_reg (reg, 1);;
+ int lhs_pointer_depth = rhs_last_pointer_depth;
int rhs_is_enum;
- is_unsigned = rhs_current_operand_is_unsigned_now ();
-
- if (emit_load_assignment_binary_expression_prec_to_reg (reg, 1)) {
- is_unsigned = 1;
- }
-
- lhs_pointer_depth = rhs_last_pointer_depth;
-
if (assignment32_stop_before_condition_operator && is_assignment32_condition_stop_operator (tok.kind)) {
return;
}
emit_apply_postfix_member_access_to_reg_now ("rax");
}
- if (postfix_member_seen && postfix_member_is_unsigned) {
- is_unsigned = 1;
+ if (postfix_member_seen) {
+ is_unsigned = postfix_member_is_unsigned ? 1 : 0;
}
if (!token_is_statement_compare_operator (tok.kind)) {
}
+static int global_initializer_cast_before_symbol_now (void) {
+
+ const char *p = tok.caret;
+ int depth;
+
+ if (!p || *p != '(') {
+ return 0;
+ }
+
+ p++;
+ depth = 1;
+
+ while (*p && depth > 0) {
+
+ if (*p == '(') {
+ depth++;
+ } else if (*p == ')') {
+ depth--;
+ }
+
+ p++;
+
+ }
+
+ if (depth != 0) {
+ return 0;
+ }
+
+ while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n') {
+ p++;
+ }
+
+ return ident_start_now ((unsigned char) *p);
+
+}
+
static void append_global_zero_initializer_value (int64_s *values, char **symbols, int max_values, int *count) {
if (*count < max_values) {
expect (TOK_RPAREN, ")");
(*count)++;
+ } else if (global_initializer_accept_symbol_addresses && tok.kind == TOK_LPAREN && global_initializer_cast_before_symbol_now ()) {
+
+ int cast_size = 0;
+ int cast_is_unsigned = 0;
+ int cast_is_pointer = 0;
+
+ get_token ();
+
+ if (!token_starts_type_name () || !parse_cast_type_name (&cast_size, &cast_is_unsigned, &cast_is_pointer)) {
+ report_line_at (get_filename (), get_line_number (), REPORT_ERROR, tok.report_start, tok.report_caret, "invalid cast in global initializer");
+ } else if (tok.kind != TOK_IDENT || find_global_symbol (tok.ident) < 0) {
+ report_line_at (get_filename (), get_line_number (), REPORT_ERROR, tok.report_start, tok.report_caret, "global symbol expected after cast");
+ } else {
+
+ if (*count < max_values) {
+
+ values[*count].low = 0;
+ values[*count].high = 0;
+
+ if (symbols) {
+ symbols[*count] = xstrdup (tok.ident);
+ }
+
+ }
+
+ (*count)++;
+ get_token ();
+
+ }
+
} else if (tok.kind == TOK_LPAREN && global_initializer_cast_before_string_now ()) {
int cast_size = 0;
}*/
static void skip_initializer (void) {
-
- if (tok.kind == TOK_LBRACE) {
- skip_balanced_until (TOK_COMMA, TOK_SEMI, TOK_EOF);
- } else {
- skip_balanced_until (TOK_COMMA, TOK_SEMI, TOK_EOF);
- }
-
+ skip_balanced_until (TOK_COMMA, TOK_RBRACE, TOK_EOF);
}
static void apply_typedef_array_to_declarator (void) {
static void parse_local_aggregate_initializer_values (struct local_init *inits, int *init_count, int max_inits, long base_offset, const int *fields, int field_count) {
int field_index = 0;
- long field_offset = 0;
int braced = 0;
+ long field_offset = 0;
+
if (tok.kind == TOK_LBRACE) {
+
braced = 1;
get_token ();
+
}
while (field_index < field_count) {
}
- if (postfix_member_seen && postfix_member_is_unsigned) {
- is_unsigned = 1;
+ if (postfix_member_seen) {
+ is_unsigned = postfix_member_is_unsigned ? 1 : 0;
}
expr_pointer_depth = rhs_last_pointer_depth;
int64_s rhs_enum_value;
enum token_kind op;
- int lhs_pointer_depth;
- int is_unsigned;
+ int is_unsigned = emit_load_assignment_binary_expression_prec_to_reg (reg, 1);;
+ int lhs_pointer_depth = rhs_last_pointer_depth;
int rhs_is_enum;
- is_unsigned = rhs_current_operand_is_unsigned_now ();
-
- if (emit_load_assignment_binary_expression_prec_to_reg (reg, 1)) {
- is_unsigned = 1;
- }
-
- lhs_pointer_depth = rhs_last_pointer_depth;
-
if (assignment32_stop_before_condition_operator && is_assignment32_condition_stop_operator (tok.kind)) {
return;
}
emit_apply_postfix_member_access_to_reg_now ("eax");
}
- if (postfix_member_seen && postfix_member_is_unsigned) {
- is_unsigned = 1;
+ if (postfix_member_seen) {
+ is_unsigned = postfix_member_is_unsigned ? 1 : 0;
}
if (!token_is_statement_compare_operator (tok.kind)) {
}
+static int global_initializer_cast_before_symbol_now (void) {
+
+ const char *p = tok.caret;
+ int depth;
+
+ if (!p || *p != '(') {
+ return 0;
+ }
+
+ p++;
+ depth = 1;
+
+ while (*p && depth > 0) {
+
+ if (*p == '(') {
+ depth++;
+ } else if (*p == ')') {
+ depth--;
+ }
+
+ p++;
+
+ }
+
+ if (depth != 0) {
+ return 0;
+ }
+
+ while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n') {
+ p++;
+ }
+
+ return ident_start_now ((unsigned char) *p);
+
+}
+
static void append_global_zero_initializer_value (int64_s *values, char **symbols, int max_values, int *count) {
if (*count < max_values) {
expect (TOK_RPAREN, ")");
(*count)++;
+ } else if (global_initializer_accept_symbol_addresses && tok.kind == TOK_LPAREN && global_initializer_cast_before_symbol_now ()) {
+
+ int cast_size = 0;
+ int cast_is_unsigned = 0;
+ int cast_is_pointer = 0;
+
+ get_token ();
+
+ if (!token_starts_type_name () || !parse_cast_type_name (&cast_size, &cast_is_unsigned, &cast_is_pointer)) {
+ report_line_at (get_filename (), get_line_number (), REPORT_ERROR, tok.report_start, tok.report_caret, "invalid cast in global initializer");
+ } else if (tok.kind != TOK_IDENT || find_global_symbol (tok.ident) < 0) {
+ report_line_at (get_filename (), get_line_number (), REPORT_ERROR, tok.report_start, tok.report_caret, "global symbol expected after cast");
+ } else {
+
+ if (*count < max_values) {
+
+ values[*count].low = 0;
+ values[*count].high = 0;
+
+ if (symbols) {
+ symbols[*count] = xstrdup (tok.ident);
+ }
+
+ }
+
+ (*count)++;
+ get_token ();
+
+ }
+
} else if (tok.kind == TOK_LPAREN && global_initializer_cast_before_string_now ()) {
int cast_size = 0;
brace--;
} else {
- if (stop1 == TOK_RPAREN || stop2 == TOK_RPAREN || stop3 == TOK_RPAREN) {
+ if (stop1 == TOK_RBRACE || stop2 == TOK_RBRACE || stop3 == TOK_RBRACE) {
return;
}
brack--;
} else {
- if (stop1 == TOK_RPAREN || stop2 == TOK_RPAREN || stop3 == TOK_RPAREN) {
+ if (stop1 == TOK_RBRACK || stop2 == TOK_RBRACK || stop3 == TOK_RBRACK) {
return;
}
char *pm;
- if ((key = find_macro (sname))) {
+ if ((key = find_macro (sname)) && (m = get_macro (key)) && (m->nargs < 0 || *skip_whitespace (caret) == '(')) {
hashtab_put (&hashtab_seen_macros, key, sname);
- if ((m = get_macro (key))) {
+ {
if (m->nargs >= 0) {
caret = skip_whitespace (caret);
hashtab_remove (&hashtab_seen_macros, key);
- /*while (!is_end_of_line[(int) *caret]) {
-
- if (isspace ((int) *caret)) {
- break;
- }
-
- if (state->mode == CC_MODE_PREPROCESS) {
- fputc (*caret, state->ofp);
- }
-
- caret++;
-
- }*/
-
+ free (sname);
continue;
}
}
- free (sname);
-
if (state->mode == CC_MODE_PREPROCESS) {
if (state->ofp) {
- fprintf (state->ofp, "%.*s", (int) (caret - start), start);
+ fprintf (state->ofp, "%s", sname);
}
+ free (sname);
continue;
}
tok->report_start = in_macro ? (real_start ? real_start : *line) : *line;
tok->report_caret = in_macro ? (real_caret ? real_caret : start) : start;
- tok->ident = xstrndup (start, (int) (caret - start));
- tok->len = (caret - start);
-
+ tok->len = strlen (tok->ident = sname);
vec_push (&vector_tokens, tok);
+
continue;
}