irc: extract inline constructors; deduplicate value-copy logic
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ifc74f0bfe621a05fa7b91a5f6be1ea976a6a6964
This commit is contained in:
parent
28de44c598
commit
feb247f64a
2 changed files with 62 additions and 41 deletions
62
src/irc/types.cpp
Normal file
62
src/irc/types.cpp
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
namespace nix_irc {
|
||||||
|
|
||||||
|
// LambdaNode constructor
|
||||||
|
LambdaNode::LambdaNode(uint32_t a, std::shared_ptr<Node> b, uint32_t l)
|
||||||
|
: arity(a), body(std::move(b)), line(l) {}
|
||||||
|
|
||||||
|
// AppNode constructor
|
||||||
|
AppNode::AppNode(std::shared_ptr<Node> f, std::shared_ptr<Node> a, uint32_t l)
|
||||||
|
: func(std::move(f)), arg(std::move(a)), line(l) {}
|
||||||
|
|
||||||
|
// BinaryOpNode constructor
|
||||||
|
BinaryOpNode::BinaryOpNode(BinaryOp o, std::shared_ptr<Node> l, std::shared_ptr<Node> 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<Node> operand, uint32_t l)
|
||||||
|
: op(o), operand(std::move(operand)), line(l) {}
|
||||||
|
|
||||||
|
// SelectNode constructor
|
||||||
|
SelectNode::SelectNode(std::shared_ptr<Node> e, std::shared_ptr<Node> a, uint32_t l)
|
||||||
|
: expr(std::move(e)), attr(std::move(a)), line(l) {}
|
||||||
|
|
||||||
|
// HasAttrNode constructor
|
||||||
|
HasAttrNode::HasAttrNode(std::shared_ptr<Node> e, std::shared_ptr<Node> a, uint32_t l)
|
||||||
|
: expr(std::move(e)), attr(std::move(a)), line(l) {}
|
||||||
|
|
||||||
|
// WithNode constructor
|
||||||
|
WithNode::WithNode(std::shared_ptr<Node> a, std::shared_ptr<Node> b, uint32_t l)
|
||||||
|
: attrs(std::move(a)), body(std::move(b)), line(l) {}
|
||||||
|
|
||||||
|
// IfNode constructor
|
||||||
|
IfNode::IfNode(std::shared_ptr<Node> c, std::shared_ptr<Node> t, std::shared_ptr<Node> 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<Node> b, uint32_t l) : body(std::move(b)), line(l) {}
|
||||||
|
|
||||||
|
// LetRecNode constructor
|
||||||
|
LetRecNode::LetRecNode(std::shared_ptr<Node> b, uint32_t l) : body(std::move(b)), line(l) {}
|
||||||
|
|
||||||
|
// AssertNode constructor
|
||||||
|
AssertNode::AssertNode(std::shared_ptr<Node> c, std::shared_ptr<Node> b, uint32_t l)
|
||||||
|
: cond(std::move(c)), body(std::move(b)), line(l) {}
|
||||||
|
|
||||||
|
// ImportNode constructor
|
||||||
|
ImportNode::ImportNode(std::shared_ptr<Node> p, uint32_t l) : path(std::move(p)), line(l) {}
|
||||||
|
|
||||||
|
// ThunkNode constructor
|
||||||
|
ThunkNode::ThunkNode(std::shared_ptr<Node> e, uint32_t l) : expr(std::move(e)), line(l) {}
|
||||||
|
|
||||||
|
// ForceNode constructor
|
||||||
|
ForceNode::ForceNode(std::shared_ptr<Node> e, uint32_t l) : expr(std::move(e)), line(l) {}
|
||||||
|
|
||||||
|
// LambdaPatternNode constructor
|
||||||
|
LambdaPatternNode::LambdaPatternNode(std::shared_ptr<Node> b, uint32_t l)
|
||||||
|
: allow_extra(false), body(std::move(b)), line(l) {}
|
||||||
|
|
||||||
|
} // namespace nix_irc
|
||||||
|
|
@ -352,48 +352,7 @@ public:
|
||||||
template <typename T> bool holds() const { return std::holds_alternative<T>(data); }
|
template <typename T> bool holds() const { return std::holds_alternative<T>(data); }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Constructor implementations
|
|
||||||
inline LambdaNode::LambdaNode(uint32_t a, std::shared_ptr<Node> b, uint32_t l)
|
|
||||||
: arity(a), body(std::move(b)), line(l) {}
|
|
||||||
|
|
||||||
inline AppNode::AppNode(std::shared_ptr<Node> f, std::shared_ptr<Node> a, uint32_t l)
|
|
||||||
: func(std::move(f)), arg(std::move(a)), line(l) {}
|
|
||||||
|
|
||||||
inline BinaryOpNode::BinaryOpNode(BinaryOp o, std::shared_ptr<Node> l, std::shared_ptr<Node> r,
|
|
||||||
uint32_t ln)
|
|
||||||
: op(o), left(std::move(l)), right(std::move(r)), line(ln) {}
|
|
||||||
|
|
||||||
inline UnaryOpNode::UnaryOpNode(UnaryOp o, std::shared_ptr<Node> operand, uint32_t l)
|
|
||||||
: op(o), operand(std::move(operand)), line(l) {}
|
|
||||||
|
|
||||||
inline SelectNode::SelectNode(std::shared_ptr<Node> e, std::shared_ptr<Node> a, uint32_t l)
|
|
||||||
: expr(std::move(e)), attr(std::move(a)), line(l) {}
|
|
||||||
|
|
||||||
inline HasAttrNode::HasAttrNode(std::shared_ptr<Node> e, std::shared_ptr<Node> a, uint32_t l)
|
|
||||||
: expr(std::move(e)), attr(std::move(a)), line(l) {}
|
|
||||||
|
|
||||||
inline WithNode::WithNode(std::shared_ptr<Node> a, std::shared_ptr<Node> b, uint32_t l)
|
|
||||||
: attrs(std::move(a)), body(std::move(b)), line(l) {}
|
|
||||||
|
|
||||||
inline IfNode::IfNode(std::shared_ptr<Node> c, std::shared_ptr<Node> t, std::shared_ptr<Node> 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<Node> b, uint32_t l) : body(std::move(b)), line(l) {}
|
|
||||||
|
|
||||||
inline LetRecNode::LetRecNode(std::shared_ptr<Node> b, uint32_t l) : body(std::move(b)), line(l) {}
|
|
||||||
|
|
||||||
inline AssertNode::AssertNode(std::shared_ptr<Node> c, std::shared_ptr<Node> b, uint32_t l)
|
|
||||||
: cond(std::move(c)), body(std::move(b)), line(l) {}
|
|
||||||
|
|
||||||
inline ImportNode::ImportNode(std::shared_ptr<Node> p, uint32_t l) : path(std::move(p)), line(l) {}
|
|
||||||
|
|
||||||
inline ThunkNode::ThunkNode(std::shared_ptr<Node> e, uint32_t l) : expr(std::move(e)), line(l) {}
|
|
||||||
|
|
||||||
inline ForceNode::ForceNode(std::shared_ptr<Node> e, uint32_t l) : expr(std::move(e)), line(l) {}
|
|
||||||
|
|
||||||
inline LambdaPatternNode::LambdaPatternNode(std::shared_ptr<Node> b, uint32_t l)
|
|
||||||
: allow_extra(false), body(std::move(b)), line(l) {}
|
|
||||||
|
|
||||||
struct SourceFile {
|
struct SourceFile {
|
||||||
std::string path;
|
std::string path;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue