From a12c61caa2b49d5be15c48ad2707e3faf23c80ae Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sun, 22 Nov 2020 23:40:33 +0100 Subject: [PATCH] :art: Introduce docstr --- ast | 2 +- include/env/context.h | 1 + include/env/value.h | 1 + src/env/context.c | 2 ++ src/parse/scan2.c | 18 ++++++++++++++++++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ast b/ast index 31bfb80a..ba9550c1 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 31bfb80acafe4235a0446cde7c93b0e3687d503c +Subproject commit ba9550c1d998f0ddf81b901e633c901ebc92cb18 diff --git a/include/env/context.h b/include/env/context.h index 0fea1b74..1810e04d 100644 --- a/include/env/context.h +++ b/include/env/context.h @@ -6,6 +6,7 @@ struct Context_ { Ast tree; Nspc nspc; struct Map_ lbls; + GwText *docstr; m_bool error; m_bool global; uint16_t ref; diff --git a/include/env/value.h b/include/env/value.h index c87da142..7adb5dcc 100644 --- a/include/env/value.h +++ b/include/env/value.h @@ -30,6 +30,7 @@ struct Value_ { m_uint* ptr; Func func_ref; } d; + GwText *docstr; uint16_t ref; ae_flag flag; enum vflag vflag; diff --git a/src/env/context.c b/src/env/context.c index c78d522e..0599442d 100644 --- a/src/env/context.c +++ b/src/env/context.c @@ -7,6 +7,8 @@ ANN void free_context(const Context a, Gwion gwion) { nspc_remref(a->nspc, gwion); free_mstr(gwion->mp, a->name); + if(a->docstr) + free_text(gwion->mp, a->docstr); mp_free(gwion->mp, Context, a); } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index ccaeb95e..20cb1ac3 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -286,9 +286,27 @@ ANN m_bool scan2_union_def(const Env env, const Union_Def udef) { #define scan2_stmt_break (void*)dummy_func #define scan2_stmt_return scan2_stmt_exp +#define DOCSTRING(name, value, prefix) \ +ANN static inline GwText* name##_docstr(const Env env) { \ + prefix \ + if(!(value)) \ + (value) = new_text(env->gwion->mp); \ + return value; \ +} +DOCSTRING(context, env->context->docstr,) +DOCSTRING(func, env->func->value_ref->docstr,) +DOCSTRING(class, v->docstr, const Value v = nspc_lookup_value0(env->curr->parent, insert_symbol(env->class_def->name));) +typedef GwText* (*docfunc)(Env); + ANN static m_bool scan2_stmt_pp(const Env env, const Stmt_PP stmt) { if(stmt->pp_type == ae_pp_include) env->name = stmt->data; + else if(stmt->pp_type == ae_pp_docstr) { + const docfunc df = env->func ? func_docstr : env->class_def ? class_docstr : context_docstr; + GwText *docstr = df(env); + text_add(docstr, stmt->data); + + } return GW_OK; } -- 2.43.0