From 811542bb5f269ac2e520656718b25eb36df0d06b Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Wed, 30 Apr 2025 21:07:51 +0200 Subject: [PATCH] libexpr: remove COMMON_METHODS macro it just pollutes the namespace. Change-Id: Ib191f139916a03e5a56a07638cc5da6c80a87043 --- lix/libexpr/nixexpr.hh | 69 +++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/lix/libexpr/nixexpr.hh b/lix/libexpr/nixexpr.hh index efefa190d..ecdce22d7 100644 --- a/lix/libexpr/nixexpr.hh +++ b/lix/libexpr/nixexpr.hh @@ -67,11 +67,6 @@ public: PosIdx getPos() const { return pos; } }; -#define COMMON_METHODS \ - JSON toJSON(const SymbolTable & symbols) const override; \ - void eval(EvalState & state, Env & env, Value & v) override; \ - void bindVars(Evaluator & es, const std::shared_ptr & env) override; - struct ExprLiteral : Expr { protected: @@ -83,7 +78,9 @@ public: ExprLiteral(const PosIdx pos, NewValueAs::integer_t, NixInt::Inner n) : Expr(pos) { v.mkInt(n); }; ExprLiteral(const PosIdx pos, NewValueAs::floating_t, NixFloat nf) : Expr(pos) { v.mkFloat(nf); }; Value * maybeThunk(EvalState & state, Env & env) override; - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; }; struct ExprString : ExprLiteral @@ -130,7 +127,9 @@ struct ExprVar : Expr ExprVar(Symbol name) : name(name), needsRoot(false) { }; ExprVar(const PosIdx & pos, Symbol name, bool needsRoot = false) : Expr(pos), name(name), needsRoot(needsRoot) { }; Value * maybeThunk(EvalState & state, Env & env) override; - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; }; /** @@ -148,7 +147,9 @@ struct ExprInheritFrom : Expr { } - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; }; struct ExprSelect : Expr @@ -166,7 +167,9 @@ struct ExprSelect : Expr ExprSelect(const PosIdx & pos, std::unique_ptr e, AttrPath attrPath, std::unique_ptr def) : Expr(pos), e(std::move(e)), def(std::move(def)), attrPath(std::move(attrPath)) { }; ExprSelect(const PosIdx & pos, std::unique_ptr e, const PosIdx namePos, Symbol name) : Expr(pos), e(std::move(e)) { attrPath.push_back(AttrName(namePos, name)); }; - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; }; struct ExprOpHasAttr : Expr @@ -174,7 +177,9 @@ struct ExprOpHasAttr : Expr std::unique_ptr e; AttrPath attrPath; ExprOpHasAttr(const PosIdx & pos, std::unique_ptr e, AttrPath attrPath) : Expr(pos), e(std::move(e)), attrPath(std::move(attrPath)) { }; - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; }; /* Helper struct to contain the data shared across lets and sets */ @@ -242,7 +247,9 @@ struct ExprSet : Expr, ExprAttrs { ExprSet(const PosIdx &pos, bool recursive = false) : Expr(pos), recursive(recursive) { }; ExprSet() { }; - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; }; struct ExprReplBindings { @@ -258,7 +265,9 @@ struct ExprList : Expr { std::vector> elems; ExprList(PosIdx pos) : Expr(pos) { }; - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; Value * maybeThunk(EvalState & state, Env & env) override; }; @@ -371,7 +380,9 @@ struct ExprLambda : Expr return "anonymous lambda"; } - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; }; struct ExprCall : Expr @@ -381,13 +392,17 @@ struct ExprCall : Expr ExprCall(const PosIdx & pos, std::unique_ptr fun, std::vector> && args) : Expr(pos), fun(std::move(fun)), args(std::move(args)) { } - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; }; struct ExprLet : Expr, ExprAttrs { std::unique_ptr body; - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; }; struct ExprWith : Expr @@ -396,28 +411,36 @@ struct ExprWith : Expr size_t prevWith; ExprWith * parentWith; ExprWith(const PosIdx & pos, std::unique_ptr attrs, std::unique_ptr body) : Expr(pos), attrs(std::move(attrs)), body(std::move(body)) { }; - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; }; struct ExprIf : Expr { std::unique_ptr cond, then, else_; ExprIf(const PosIdx & pos, std::unique_ptr cond, std::unique_ptr then, std::unique_ptr else_) : Expr(pos), cond(std::move(cond)), then(std::move(then)), else_(std::move(else_)) { }; - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; }; struct ExprAssert : Expr { std::unique_ptr cond, body; ExprAssert(const PosIdx & pos, std::unique_ptr cond, std::unique_ptr body) : Expr(pos), cond(std::move(cond)), body(std::move(body)) { }; - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; }; struct ExprOpNot : Expr { std::unique_ptr e; ExprOpNot(const PosIdx & pos, std::unique_ptr e) : Expr(pos), e(std::move(e)) { }; - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; }; #define MakeBinOp(name, s) \ @@ -455,13 +478,17 @@ struct ExprConcatStrings : Expr std::vector>> es; ExprConcatStrings(const PosIdx & pos, bool forceString, std::vector>> es) : Expr(pos), forceString(forceString), es(std::move(es)) { }; - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; }; struct ExprPos : Expr { ExprPos(const PosIdx & pos) : Expr(pos) { }; - COMMON_METHODS + JSON toJSON(const SymbolTable & symbols) const override; + void eval(EvalState & state, Env & env, Value & v) override; + void bindVars(Evaluator & es, const std ::shared_ptr & env) override; }; /* only used to mark thunks as black holes. */