summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
524755e)
- add infrastructure for further case label checks
[r18690]
};
struct switch_statement_t {
};
struct switch_statement_t {
- statement_base_t statement;
- expression_t *expression;
- statement_t *body;
+ statement_base_t statement;
+ expression_t *expression;
+ statement_t *body;
+ case_label_statement_t *first_case, *last_case;
};
struct goto_statement_t {
};
struct goto_statement_t {
};
struct case_label_statement_t {
};
struct case_label_statement_t {
- statement_base_t statement;
- expression_t *expression;
- statement_t *label_statement;
+ statement_base_t statement;
+ expression_t *expression;
+ statement_t *label_statement;
+ case_label_statement_t *next; /**< link to the next case label in the switch */
};
struct label_statement_t {
};
struct label_statement_t {
typedef declaration_t* (*parsed_declaration_func) (declaration_t *declaration);
typedef declaration_t* (*parsed_declaration_func) (declaration_t *declaration);
-static token_t token;
-static token_t lookahead_buffer[MAX_LOOKAHEAD];
-static int lookahead_bufpos;
-static stack_entry_t *environment_stack = NULL;
-static stack_entry_t *label_stack = NULL;
-static context_t *global_context = NULL;
-static context_t *context = NULL;
-static declaration_t *last_declaration = NULL;
-static declaration_t *current_function = NULL;
+static token_t token;
+static token_t lookahead_buffer[MAX_LOOKAHEAD];
+static int lookahead_bufpos;
+static stack_entry_t *environment_stack = NULL;
+static stack_entry_t *label_stack = NULL;
+static context_t *global_context = NULL;
+static context_t *context = NULL;
+static declaration_t *last_declaration = NULL;
+static declaration_t *current_function = NULL;
+static switch_statement_t *current_switch = NULL;
static struct obstack temp_obst;
/** The current source position. */
static struct obstack temp_obst;
/** The current source position. */
statement->case_label.expression = parse_expression();
expect(':');
statement->case_label.expression = parse_expression();
expect(':');
+
+ if (current_switch != NULL) {
+ /* link all cases into the switch statement */
+ if (current_switch->last_case == NULL) {
+ current_switch->first_case =
+ current_switch->last_case = &statement->case_label;
+ } else {
+ current_switch->last_case->next = &statement->case_label;
+ }
+ } else {
+ errorf(statement->base.source_position,
+ "case label not within a switch statement");
+ }
statement->case_label.label_statement = parse_statement();
return statement;
statement->case_label.label_statement = parse_statement();
return statement;
type_t *const type = promote_integer(skip_typeref(expr->base.datatype));
statement->expression = create_implicit_cast(expr, type);
expect(')');
type_t *const type = promote_integer(skip_typeref(expr->base.datatype));
statement->expression = create_implicit_cast(expr, type);
expect(')');
+
+ switch_statement_t *rem = current_switch;
+ current_switch = &statement;
statement->body = parse_statement();
statement->body = parse_statement();
return (statement_t*) statement;
}
return (statement_t*) statement;
}