nixd
Toggle main menu visibility
Loading...
Searching...
No Matches
libnixf
include
nixf
Basic
Nodes
Op.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
Basic.h
"
4
#include "Tokens.h"
5
6
#include "
nixf/Basic/Nodes/Attrs.h
"
7
8
#include <memory>
9
10
namespace
nixf
{
11
12
class
Op
:
public
Node
{
13
const
tok::TokenKind OpKind;
14
15
public
:
16
Op
(
LexerCursorRange
Range, tok::TokenKind OpKind)
17
:
Node
(NK_Op, Range), OpKind(OpKind) {}
18
19
[[nodiscard]] tok::TokenKind
op
()
const
{
return
OpKind; }
20
21
[[nodiscard]]
ChildVector
children
()
const override
{
return
{}; }
22
};
23
24
/// \brief Abstract class for binary operators and unary operators.
25
class
ExprOp
:
public
Expr
{
26
const
std::shared_ptr<Op> O;
27
28
public
:
29
ExprOp
(
NodeKind
Kind,
LexerCursorRange
Range, std::shared_ptr<Op> O)
30
:
Expr
(Kind, Range), O(std::move(O)) {
31
assert(this->O &&
"O must not be null"
);
32
}
33
34
[[nodiscard]]
Op
&
op
()
const
{
return
*O; }
35
36
[[nodiscard]]
ChildVector
children
()
const override
{
return
{O.get()}; }
37
};
38
39
class
ExprBinOp
:
public
ExprOp
{
40
const
std::shared_ptr<Expr> LHS;
41
const
std::shared_ptr<Expr> RHS;
42
43
public
:
44
ExprBinOp
(
LexerCursorRange
Range, std::shared_ptr<Op> O,
45
std::shared_ptr<Expr> LHS, std::shared_ptr<Expr> RHS)
46
:
ExprOp
(NK_ExprBinOp, Range, std::move(O)), LHS(std::move(LHS)),
47
RHS(std::move(RHS)) {}
48
49
[[nodiscard]]
Expr
*
lhs
()
const
{
return
LHS.get(); }
50
[[nodiscard]]
Expr
*
rhs
()
const
{
return
RHS.get(); }
51
52
[[nodiscard]]
ChildVector
children
()
const override
{
53
return
{&
op
(), LHS.get(), RHS.get()};
54
}
55
};
56
57
class
ExprOpHasAttr
:
public
ExprOp
{
58
const
std::shared_ptr<Expr> E;
59
const
std::shared_ptr<AttrPath> Path;
60
61
public
:
62
ExprOpHasAttr
(
LexerCursorRange
Range, std::shared_ptr<Op> O,
63
std::shared_ptr<Expr> E, std::shared_ptr<AttrPath> Path)
64
:
ExprOp
(NK_ExprOpHasAttr, Range, std::move(O)), E(std::move(E)),
65
Path(std::move(Path)) {}
66
67
[[nodiscard]]
Expr
*
expr
()
const
{
return
E.get(); }
68
[[nodiscard]]
AttrPath
*
attrpath
()
const
{
return
Path.get(); }
69
70
[[nodiscard]]
ChildVector
children
()
const override
{
71
return
{E.get(), Path.get()};
72
}
73
};
74
75
class
ExprUnaryOp
:
public
ExprOp
{
76
const
std::shared_ptr<Expr> E;
77
78
public
:
79
ExprUnaryOp
(
LexerCursorRange
Range, std::shared_ptr<Op> O,
80
std::shared_ptr<Expr> E)
81
:
ExprOp
(NK_ExprUnaryOp, Range, std::move(O)), E(std::move(E)) {}
82
83
[[nodiscard]]
Expr
*
expr
()
const
{
return
E.get(); }
84
85
[[nodiscard]]
ChildVector
children
()
const override
{
86
return
{&
op
(), E.get()};
87
}
88
};
89
90
}
// namespace nixf
Attrs.h
Basic.h
nixf::AttrPath
Definition
Attrs.h:90
nixf::ExprBinOp::ExprBinOp
ExprBinOp(LexerCursorRange Range, std::shared_ptr< Op > O, std::shared_ptr< Expr > LHS, std::shared_ptr< Expr > RHS)
Definition
Op.h:44
nixf::ExprBinOp::rhs
Expr * rhs() const
Definition
Op.h:50
nixf::ExprBinOp::lhs
Expr * lhs() const
Definition
Op.h:49
nixf::ExprBinOp::children
ChildVector children() const override
Definition
Op.h:52
nixf::ExprOpHasAttr::expr
Expr * expr() const
Definition
Op.h:67
nixf::ExprOpHasAttr::children
ChildVector children() const override
Definition
Op.h:70
nixf::ExprOpHasAttr::attrpath
AttrPath * attrpath() const
Definition
Op.h:68
nixf::ExprOpHasAttr::ExprOpHasAttr
ExprOpHasAttr(LexerCursorRange Range, std::shared_ptr< Op > O, std::shared_ptr< Expr > E, std::shared_ptr< AttrPath > Path)
Definition
Op.h:62
nixf::ExprOp::children
ChildVector children() const override
Definition
Op.h:36
nixf::ExprOp::op
Op & op() const
Definition
Op.h:34
nixf::ExprOp::ExprOp
ExprOp(NodeKind Kind, LexerCursorRange Range, std::shared_ptr< Op > O)
Definition
Op.h:29
nixf::ExprUnaryOp::ExprUnaryOp
ExprUnaryOp(LexerCursorRange Range, std::shared_ptr< Op > O, std::shared_ptr< Expr > E)
Definition
Op.h:79
nixf::ExprUnaryOp::children
ChildVector children() const override
Definition
Op.h:85
nixf::ExprUnaryOp::expr
Expr * expr() const
Definition
Op.h:83
nixf::Expr
Definition
Basic.h:70
nixf::Expr::Expr
Expr(NodeKind Kind, LexerCursorRange Range)
Definition
Basic.h:72
nixf::LexerCursorRange
Definition
Range.h:105
nixf::Node::NodeKind
NodeKind
Definition
Basic.h:14
nixf::Node::ChildVector
boost::container::small_vector< Node *, 8 > ChildVector
Definition
Basic.h:42
nixf::Node::Node
Node(NodeKind Kind, LexerCursorRange Range)
Definition
Basic.h:30
nixf::Op
Definition
Op.h:12
nixf::Op::children
ChildVector children() const override
Definition
Op.h:21
nixf::Op::op
tok::TokenKind op() const
Definition
Op.h:19
nixf::Op::Op
Op(LexerCursorRange Range, tok::TokenKind OpKind)
Definition
Op.h:16
nixf
Definition
Diagnostic.h:19
Generated by
1.17.0