From aea0c6633ff51e79b5428a58bf4fb8e63dd96f57 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 11 Jun 2023 07:11:03 +0300 Subject: [PATCH 20/33] Add ASSERT_UNUSED_ACTRES_CASES and ASSERT_UNUSED_ACTION_CASES See osdn #48214 Signed-off-by: Marko Lindqvist --- ai/default/daidiplomacy.c | 2 ++ common/actions.c | 40 +++++++++++++++++++++++++++++++++++++++ common/actions.h | 14 ++++++++++++++ common/actres.c | 2 ++ common/actres.h | 14 ++++++++++++++ server/advisors/advdata.c | 2 ++ server/unithand.c | 4 ++++ 7 files changed, 78 insertions(+) diff --git a/ai/default/daidiplomacy.c b/ai/default/daidiplomacy.c index 1bfbb766af..2d1b224056 100644 --- a/ai/default/daidiplomacy.c +++ b/ai/default/daidiplomacy.c @@ -2061,6 +2061,8 @@ void dai_incident(struct ai_type *ait, enum incident_type type, /* Various */ dai_incident_simple(receiver, violator, victim, scope, 1); break; + + ASSERT_UNUSED_ACTRES_CASES; } break; case INCIDENT_WAR: diff --git a/common/actions.c b/common/actions.c index da58750ab1..c3bceba4ae 100644 --- a/common/actions.c +++ b/common/actions.c @@ -2278,6 +2278,8 @@ bool action_creates_extra(const struct action *paction, case ACTRES_ENABLER_CHECK: case ACTRES_NONE: break; + + ASSERT_UNUSED_ACTRES_CASES; } return FALSE; @@ -2371,6 +2373,8 @@ bool action_removes_extra(const struct action *paction, case ACTRES_ENABLER_CHECK: case ACTRES_NONE: break; + + ASSERT_UNUSED_ACTRES_CASES; } return FALSE; @@ -3474,6 +3478,8 @@ action_actor_utype_hard_reqs_ok_full(const struct action *paction, case ACTRES_NONE: /* No hard unit type requirements. */ break; + + ASSERT_UNUSED_ACTRES_CASES; } return TRUE; @@ -3670,6 +3676,8 @@ action_hard_reqs_actor(const struct action *paction, case ACTRES_NONE: /* No hard unit requirements. */ break; + + ASSERT_UNUSED_ACTRES_CASES; } return TRI_YES; @@ -4986,6 +4994,8 @@ action_prob(const action_id wanted_action, * Lua? */ chance = ACTPROB_NOT_IMPLEMENTED; break; + + ASSERT_UNUSED_ACTRES_CASES; } /* Non signal action probabilities should be in range. */ @@ -6871,9 +6881,12 @@ const char *action_ui_name_ruleset_var_name(int act) break; case ACTION_COUNT: break; + + ASSERT_UNUSED_ACTION_CASES; } fc_assert(act >= 0 && act < ACTION_COUNT); + return NULL; } @@ -7338,9 +7351,12 @@ const char *action_min_range_ruleset_var_name(int act) return "user_action_4_min_range"; case ACTION_COUNT: break; + + ASSERT_UNUSED_ACTION_CASES; } fc_assert(act >= 0 && act < ACTION_COUNT); + return NULL; } @@ -7424,9 +7440,12 @@ int action_min_range_default(enum action_result result) return RS_DEFAULT_MOVE_MIN_RANGE; case ACTRES_NONE: return RS_DEFAULT_ACTION_MIN_RANGE; + + ASSERT_UNUSED_ACTRES_CASES; } fc_assert(action_result_is_valid(result) || result == ACTRES_NONE); + return 0; } @@ -7576,9 +7595,12 @@ const char *action_max_range_ruleset_var_name(int act) return "user_action_4_max_range"; case ACTION_COUNT: break; + + ASSERT_UNUSED_ACTION_CASES; } fc_assert(act >= 0 && act < ACTION_COUNT); + return NULL; } @@ -7665,6 +7687,8 @@ int action_max_range_default(enum action_result result) return ACTION_DISTANCE_UNLIMITED; case ACTRES_NONE: return RS_DEFAULT_ACTION_MAX_RANGE; + + ASSERT_UNUSED_ACTRES_CASES; } fc_assert(action_result_is_valid(result) || result == ACTRES_NONE); @@ -7810,9 +7834,12 @@ const char *action_target_kind_ruleset_var_name(int act) return "user_action_4_target_kind"; case ACTION_COUNT: break; + + ASSERT_UNUSED_ACTION_CASES; } fc_assert(act >= 0 && act < ACTION_COUNT); + return NULL; } @@ -7901,6 +7928,8 @@ action_target_kind_default(enum action_result result) return ATK_SELF; case ACTRES_NONE: return RS_DEFAULT_USER_ACTION_TARGET_KIND; + + ASSERT_UNUSED_ACTRES_CASES; } /* Should never be reached. */ @@ -8010,6 +8039,8 @@ bool action_result_legal_target_kind(enum action_result result, break; } break; + + ASSERT_UNUSED_ACTRES_CASES; } /* Should never be reached. */ @@ -8105,6 +8136,8 @@ action_sub_target_kind_default(enum action_result result) return ASTK_NONE; case ACTRES_NONE: return ASTK_NONE; + + ASSERT_UNUSED_ACTRES_CASES; } /* Should never be reached. */ @@ -8252,9 +8285,12 @@ const char *action_actor_consuming_always_ruleset_var_name(action_id act) return "user_action_4_actor_consuming_always"; case ACTION_COUNT: break; + + ASSERT_UNUSED_ACTION_CASES; } fc_assert(act >= 0 && act < ACTION_COUNT); + return NULL; } @@ -8412,6 +8448,8 @@ const char *action_blocked_by_ruleset_var_name(const struct action *act) case ACTION_COUNT: fc_assert_ret_val(action_number(act) != ACTION_COUNT, NULL); break; + + ASSERT_UNUSED_ACTION_CASES; } return NULL; @@ -8560,6 +8598,8 @@ action_post_success_forced_ruleset_var_name(const struct action *act) case ACTION_COUNT: fc_assert_ret_val(action_number(act) != ACTION_COUNT, NULL); break; + + ASSERT_UNUSED_ACTION_CASES; } return NULL; diff --git a/common/actions.h b/common/actions.h index 8f980cb95d..f9666f1f6b 100644 --- a/common/actions.h +++ b/common/actions.h @@ -23,6 +23,20 @@ extern "C" { #endif /* __cplusplus */ +/* If 'enum gen_action' has currently unused values that should + * not be used in 'switch - cases', put those cases here. E.g.: + * + *#define ASSERT_UNUSED_ACTION_CASES \ + * case ACTION_UNUSED_1: \ + * fc_assert_msg(FALSE, "ACTION_UNUSED_1"); \ + * break; \ + * case ACTION_UNUSED_2: \ + * fc_assert_msg(FALSE, "ACTION_UNUSED_2"); \ + * break; + */ +#define ASSERT_UNUSED_ACTION_CASES \ + /* No unused actions at the moment */ + #define SPECENUM_NAME action_actor_kind #define SPECENUM_VALUE0 AAK_UNIT #define SPECENUM_VALUE0NAME N_("a unit") diff --git a/common/actres.c b/common/actres.c index f136302db3..13f5404aab 100644 --- a/common/actres.c +++ b/common/actres.c @@ -1148,6 +1148,8 @@ enum fc_tristate actres_possible(enum action_result result, case ACTRES_NONE: /* No known hard coded requirements. */ break; + + ASSERT_UNUSED_ACTRES_CASES; } return def; diff --git a/common/actres.h b/common/actres.h index 64b3ddd164..c6f5933d47 100644 --- a/common/actres.h +++ b/common/actres.h @@ -22,6 +22,20 @@ extern "C" { struct req_context; +/* If 'enum action_result' has currently unused values that should + * not be used in 'switch - cases', put those cases here. E.g.: + * + *#define ASSERT_UNUSED_ACTRES_CASES \ + * case ACTRES_UNUSED_1: \ + * fc_assert_msg(FALSE, "ACTRES_UNUSED_1"); \ + * break; \ + * case ACTRES_UNUSED_2: \ + * fc_assert_msg(FALSE, "ACTRES_UNUSED_2"); \ + * break; + */ +#define ASSERT_UNUSED_ACTRES_CASES \ + /* No unused action results at the moment */ + /* When making changes to this, update also atk_helpnames at actions.c */ #define SPECENUM_NAME action_target_kind #define SPECENUM_VALUE0 ATK_CITY diff --git a/server/advisors/advdata.c b/server/advisors/advdata.c index d546f5a208..ec5de35f6f 100644 --- a/server/advisors/advdata.c +++ b/server/advisors/advdata.c @@ -933,6 +933,8 @@ adv_want adv_gov_action_immunity_want(struct government *gov) * wonder gives shields. */ /* TODO: Individual and well balanced values. */ break; + + ASSERT_UNUSED_ACTRES_CASES; } } action_iterate_end; diff --git a/server/unithand.c b/server/unithand.c index a299513033..a3016da199 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -1182,6 +1182,8 @@ static struct player *need_war_player_hlp(const struct unit *actor, case ACTRES_NONE: /* No special help. */ break; + + ASSERT_UNUSED_ACTRES_CASES; } /* Look for war requirements from the action enablers. */ @@ -3972,6 +3974,8 @@ bool unit_perform_action(struct player *pplayer, case ACTRES_ENABLER_CHECK: fc_assert(paction->result != ACTRES_ENABLER_CHECK); return FALSE; + + ASSERT_UNUSED_ACTRES_CASES; } /* Something must have gone wrong. */ -- 2.39.2