+/**
+ * Check that all enums are handled in a switch.
+ *
+ * @param statement the switch statement to check
+ */
+static void check_enum_cases(const switch_statement_t *statement) {
+ const type_t *type = skip_typeref(statement->expression->base.type);
+ if (! is_type_enum(type))
+ return;
+ const enum_type_t *enumt = &type->enumt;
+
+ /* if we have a default, no warnings */
+ if (statement->default_label != NULL)
+ return;
+
+ /* FIXME: calculation of value should be done while parsing */
+ const declaration_t *declaration;
+ long last_value = -1;
+ for (declaration = enumt->declaration->next;
+ declaration != NULL && declaration->storage_class == STORAGE_CLASS_ENUM_ENTRY;
+ declaration = declaration->next) {
+ const expression_t *expression = declaration->init.enum_value;
+ long value = expression != NULL ? fold_constant(expression) : last_value + 1;
+ bool found = false;
+ for (const case_label_statement_t *l = statement->first_case; l != NULL; l = l->next) {
+ if (l->expression == NULL)
+ continue;
+ if (l->first_case <= value && value <= l->last_case) {
+ found = true;
+ break;
+ }
+ }
+ if (! found) {
+ warningf(&statement->base.source_position,
+ "enumeration value '%Y' not handled in switch", declaration->symbol);
+ }
+ last_value = value;
+ }
+}
+