From feb247f64a93c65c93a80df2d9c810bc72c71386 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 24 Apr 2026 14:39:30 +0300 Subject: [PATCH] irc: extract inline constructors; deduplicate value-copy logic Signed-off-by: NotAShelf Change-Id: Ifc74f0bfe621a05fa7b91a5f6be1ea976a6a6964 --- src/irc/types.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++ src/irc/types.h | 41 ------------------------------- 2 files changed, 62 insertions(+), 41 deletions(-) create mode 100644 src/irc/types.cpp diff --git a/src/irc/types.cpp b/src/irc/types.cpp new file mode 100644 index 0000000..1ee8a8e --- /dev/null +++ b/src/irc/types.cpp @@ -0,0 +1,62 @@ +#include "types.h" + +namespace nix_irc { + +// LambdaNode constructor +LambdaNode::LambdaNode(uint32_t a, std::shared_ptr b, uint32_t l) + : arity(a), body(std::move(b)), line(l) {} + +// AppNode constructor +AppNode::AppNode(std::shared_ptr f, std::shared_ptr a, uint32_t l) + : func(std::move(f)), arg(std::move(a)), line(l) {} + +// BinaryOpNode constructor +BinaryOpNode::BinaryOpNode(BinaryOp o, std::shared_ptr l, std::shared_ptr r, + uint32_t ln) + : op(o), left(std::move(l)), right(std::move(r)), line(ln) {} + +// UnaryOpNode constructor +UnaryOpNode::UnaryOpNode(UnaryOp o, std::shared_ptr operand, uint32_t l) + : op(o), operand(std::move(operand)), line(l) {} + +// SelectNode constructor +SelectNode::SelectNode(std::shared_ptr e, std::shared_ptr a, uint32_t l) + : expr(std::move(e)), attr(std::move(a)), line(l) {} + +// HasAttrNode constructor +HasAttrNode::HasAttrNode(std::shared_ptr e, std::shared_ptr a, uint32_t l) + : expr(std::move(e)), attr(std::move(a)), line(l) {} + +// WithNode constructor +WithNode::WithNode(std::shared_ptr a, std::shared_ptr b, uint32_t l) + : attrs(std::move(a)), body(std::move(b)), line(l) {} + +// IfNode constructor +IfNode::IfNode(std::shared_ptr c, std::shared_ptr t, std::shared_ptr e, + uint32_t l) + : cond(std::move(c)), then_branch(std::move(t)), else_branch(std::move(e)), line(l) {} + +// LetNode constructor +LetNode::LetNode(std::shared_ptr b, uint32_t l) : body(std::move(b)), line(l) {} + +// LetRecNode constructor +LetRecNode::LetRecNode(std::shared_ptr b, uint32_t l) : body(std::move(b)), line(l) {} + +// AssertNode constructor +AssertNode::AssertNode(std::shared_ptr c, std::shared_ptr b, uint32_t l) + : cond(std::move(c)), body(std::move(b)), line(l) {} + +// ImportNode constructor +ImportNode::ImportNode(std::shared_ptr p, uint32_t l) : path(std::move(p)), line(l) {} + +// ThunkNode constructor +ThunkNode::ThunkNode(std::shared_ptr e, uint32_t l) : expr(std::move(e)), line(l) {} + +// ForceNode constructor +ForceNode::ForceNode(std::shared_ptr e, uint32_t l) : expr(std::move(e)), line(l) {} + +// LambdaPatternNode constructor +LambdaPatternNode::LambdaPatternNode(std::shared_ptr b, uint32_t l) + : allow_extra(false), body(std::move(b)), line(l) {} + +} // namespace nix_irc diff --git a/src/irc/types.h b/src/irc/types.h index 7a4c754..79f4275 100644 --- a/src/irc/types.h +++ b/src/irc/types.h @@ -352,48 +352,7 @@ public: template bool holds() const { return std::holds_alternative(data); } }; -// Constructor implementations -inline LambdaNode::LambdaNode(uint32_t a, std::shared_ptr b, uint32_t l) - : arity(a), body(std::move(b)), line(l) {} -inline AppNode::AppNode(std::shared_ptr f, std::shared_ptr a, uint32_t l) - : func(std::move(f)), arg(std::move(a)), line(l) {} - -inline BinaryOpNode::BinaryOpNode(BinaryOp o, std::shared_ptr l, std::shared_ptr r, - uint32_t ln) - : op(o), left(std::move(l)), right(std::move(r)), line(ln) {} - -inline UnaryOpNode::UnaryOpNode(UnaryOp o, std::shared_ptr operand, uint32_t l) - : op(o), operand(std::move(operand)), line(l) {} - -inline SelectNode::SelectNode(std::shared_ptr e, std::shared_ptr a, uint32_t l) - : expr(std::move(e)), attr(std::move(a)), line(l) {} - -inline HasAttrNode::HasAttrNode(std::shared_ptr e, std::shared_ptr a, uint32_t l) - : expr(std::move(e)), attr(std::move(a)), line(l) {} - -inline WithNode::WithNode(std::shared_ptr a, std::shared_ptr b, uint32_t l) - : attrs(std::move(a)), body(std::move(b)), line(l) {} - -inline IfNode::IfNode(std::shared_ptr c, std::shared_ptr t, std::shared_ptr e, - uint32_t l) - : cond(std::move(c)), then_branch(std::move(t)), else_branch(std::move(e)), line(l) {} - -inline LetNode::LetNode(std::shared_ptr b, uint32_t l) : body(std::move(b)), line(l) {} - -inline LetRecNode::LetRecNode(std::shared_ptr b, uint32_t l) : body(std::move(b)), line(l) {} - -inline AssertNode::AssertNode(std::shared_ptr c, std::shared_ptr b, uint32_t l) - : cond(std::move(c)), body(std::move(b)), line(l) {} - -inline ImportNode::ImportNode(std::shared_ptr p, uint32_t l) : path(std::move(p)), line(l) {} - -inline ThunkNode::ThunkNode(std::shared_ptr e, uint32_t l) : expr(std::move(e)), line(l) {} - -inline ForceNode::ForceNode(std::shared_ptr e, uint32_t l) : expr(std::move(e)), line(l) {} - -inline LambdaPatternNode::LambdaPatternNode(std::shared_ptr b, uint32_t l) - : allow_extra(false), body(std::move(b)), line(l) {} struct SourceFile { std::string path;