From 12e69edb86c99f561751ccc3e3d7ea3630d9ddea Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Fri, 22 Aug 2025 13:06:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20`chef=5Fprep=5Fthis()`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/framework/chef.c | 5 ----- src/framework/struct.h | 14 ++++++++++++-- src/recipe/recipe-template.c | 9 +++------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/framework/chef.c b/src/framework/chef.c index be3b39a..16e4956 100644 --- a/src/framework/chef.c +++ b/src/framework/chef.c @@ -12,11 +12,6 @@ #pragma once -#define chef_allow_gsr(t) this->getfn = t##_getsrc; this->setfn = t##_setsrc; this->resetfn = t##_resetsrc; -#define chef_allow_s(t) this->getfn = NULL; this->setfn = t##_setsrc; this->resetfn = NULL; -#define chef_allow_sr(t) this->getfn = NULL; this->setfn = t##_setsrc; this->resetfn = t##_resetsrc; -#define chef_allow_gs(t) this->getfn = t##_getsrc; this->setfn = t##_setsrc; this->resetfn = NULL; - /** * @brief 登记所有贡献者 * diff --git a/src/framework/struct.h b/src/framework/struct.h index 7b2f50e..ab9d123 100644 --- a/src/framework/struct.h +++ b/src/framework/struct.h @@ -126,6 +126,10 @@ typedef struct Target_t void (*setfn) (char *option); void (*resetfn) (char *option); + /* 初始化函数,用于填充该 struct 的各种信息 */ + void (*preludefn) (void); + bool inited; /* 是否执行过了 preludefn() */ + Source_t *sources; size_t sources_n; @@ -167,9 +171,15 @@ TargetRegisterInfo_t; #define def_target(t, aliases) void t##_getsrc(char *option);void t##_setsrc(char *option);void t##_resetsrc(char *option); Target_t t##_target={aliases}; -/* 以下宏仅能放在 prelude() 中使用 */ +#define chef_allow_gsr(t) this->getfn = t##_getsrc; this->setfn = t##_setsrc; this->resetfn = t##_resetsrc; +#define chef_allow_s(t) this->getfn = NULL; this->setfn = t##_setsrc; this->resetfn = NULL; +#define chef_allow_sr(t) this->getfn = NULL; this->setfn = t##_setsrc; this->resetfn = t##_resetsrc; +#define chef_allow_gs(t) this->getfn = t##_getsrc; this->setfn = t##_setsrc; this->resetfn = NULL; +#define chef_allow_NOOP(t) +#define chef_prep_this(t,op) Target_t *this = &t##_target; this->inited = true; chef_allow_##op(t); + #define use_this(t) Target_t *this = &t##_target; -#define use_this_source(t) use_this(t); Source_t source = chsrc_yield_source_and_confirm (this, option); +#define use_this_source(t) Target_t *this = &t##_target; Source_t source = chsrc_yield_source_and_confirm (this, option); #define def_sources_begin() Source_t sources[] = { #define def_sources_end() }; \ diff --git a/src/recipe/recipe-template.c b/src/recipe/recipe-template.c index 41a1549..1d2c2d1 100644 --- a/src/recipe/recipe-template.c +++ b/src/recipe/recipe-template.c @@ -6,7 +6,7 @@ * Contributors : Mikachu2333 * | * Created On : <2024-08-09> - * Last Modified : <2025-08-21> + * Last Modified : <2025-08-22> * ------------------------------------------------------------- * 本文件作为一个通用模板: * @@ -58,11 +58,8 @@ RubyMetric = { void __prelude (void) { - use_this(_); - chef_allow_gsr(_); // 代表支持 Get Set Reset 三种操作 - // chef_allow_s(_); // 以此类推 - // chef_allow_gs(_); - // chef_allow_sr(_); + // op 可以为 NOOP|s|sr|gsr|gs, 代表支持 Get Set Reset 三种操作 + chef_prep_this (_, op); chef_set_created_on (this, "2024-08-09"); // 文件创建日期 chef_set_last_updated (this, "2025-08-12"); // 文件最后一次更新日期