static void declaration_statement_to_firm(declaration_statement_t *statement)
{
- entity_t *entity = statement->declarations_begin;
- entity_t *end = statement->declarations_end->base.next;
- for ( ; entity != end; entity = entity->base.next) {
- if (!is_declaration(entity))
- continue;
- initialize_local_declaration(entity);
+ entity_t * entity = statement->declarations_begin;
+ entity_t *const last = statement->declarations_end;
+ if (entity != NULL) {
+ for ( ;; entity = entity->base.next) {
+ if (is_declaration(entity))
+ initialize_local_declaration(entity);
+ if (entity == last)
+ break;
+ }
}
}
}
static int count_local_variables(const entity_t *entity,
- const entity_t *const end)
+ const entity_t *const last)
{
int count = 0;
- for (; entity != end; entity = entity->base.next) {
+ for (; entity != NULL; entity = entity->base.next) {
type_t *type;
bool address_taken;
if (!address_taken && is_type_scalar(type))
++count;
+
+ if (entity == last)
+ break;
}
return count;
}
case STATEMENT_DECLARATION: {
const declaration_statement_t *const decl_stmt = &stmt->declaration;
*count += count_local_variables(decl_stmt->declarations_begin,
- decl_stmt->declarations_end->base.next);
+ decl_stmt->declarations_end);
break;
}
declaration_statement_t const *const decl = &stmt->declaration;
entity_t const * ent = decl->declarations_begin;
entity_t const *const last = decl->declarations_end;
- for (;; ent = ent->base.next) {
- if (ent->kind == ENTITY_VARIABLE &&
- ent->variable.initializer != NULL &&
- !initializer_returns(ent->variable.initializer)) {
- return;
+ if (ent != NULL) {
+ for (;; ent = ent->base.next) {
+ if (ent->kind == ENTITY_VARIABLE &&
+ ent->variable.initializer != NULL &&
+ !initializer_returns(ent->variable.initializer)) {
+ return;
+ }
+ if (ent == last)
+ break;
}
- if (ent == last)
- break;
}
next = stmt->base.next;
break;
}
static void walk_declarations(const entity_t* entity,
- const entity_t* const end,
+ const entity_t* const last,
statement_callback const callback,
void *const env)
{
- for (; entity != end; entity = entity->base.next) {
+ for (; entity != NULL; entity = entity->base.next) {
/* we only look at variables */
if (entity->kind != ENTITY_VARIABLE)
continue;
if (initializer != NULL) {
walk_initializer(initializer, callback, env);
}
+
+ if (entity == last)
+ break;
}
}
case STATEMENT_DECLARATION:
walk_declarations(stmt->declaration.declarations_begin,
- stmt->declaration.declarations_end->base.next,
- callback, env);
+ stmt->declaration.declarations_end, callback, env);
return;
case STATEMENT_MS_TRY: