nixd
Toggle main menu visibility
Loading...
Searching...
No Matches
libnixf
src
Sema
ParentMap.cpp
Go to the documentation of this file.
1
#include "
nixf/Sema/ParentMap.h
"
2
3
using namespace
nixf
;
4
5
void
ParentMapAnalysis::dfs(
const
Node
*N,
const
Node
*Parent) {
6
if
(!N)
7
return
;
8
ParentMap.insert({N, Parent});
9
for
(
const
Node *Ch : N->
children
())
10
dfs(Ch, N);
11
}
12
13
const
Node
*
ParentMapAnalysis::query
(
const
Node
&N)
const
{
14
return
ParentMap.contains(&N) ? ParentMap.at(&N) :
nullptr
;
15
}
16
17
const
Node
*
ParentMapAnalysis::upExpr
(
const
Node
&N)
const
{
18
19
if
(
Expr::isExpr
(N.
kind
()))
20
return
&N;
21
const
Node
*Up =
query
(N);
22
if
(
isRoot
(Up, N) || !Up)
23
return
nullptr
;
24
return
upExpr
(*Up);
25
}
26
27
const
Node
*
ParentMapAnalysis::upTo
(
const
Node
&N,
Node::NodeKind
Kind)
const
{
28
29
if
(N.
kind
() == Kind)
30
return
&N;
31
const
Node
*Up =
query
(N);
32
if
(
isRoot
(Up, N) || !Up)
33
return
nullptr
;
34
return
upTo
(*Up, Kind);
35
}
36
37
void
ParentMapAnalysis::runOnAST
(
const
Node
&Root) {
38
// Special case. Root node has itself as "parent".
39
dfs(&Root, &Root);
40
}
41
42
bool
nixf::ParentMapAnalysis::isRoot
(
const
Node
*Up,
const
Node
&N) {
43
return
Up == &N;
44
}
45
46
bool
nixf::ParentMapAnalysis::isRoot
(
const
Node
&N)
const
{
47
return
isRoot
(
query
(N), N);
48
}
ParentMap.h
ParentMap analysis.
nixf::Expr::isExpr
static bool isExpr(NodeKind Kind)
Definition
Basic.h:79
nixf::Node
Definition
Basic.h:12
nixf::Node::NodeKind
NodeKind
Definition
Basic.h:14
nixf::Node::kind
NodeKind kind() const
Definition
Basic.h:34
nixf::Node::children
virtual ChildVector children() const =0
nixf::ParentMapAnalysis::upExpr
const Node * upExpr(const Node &N) const
Search up until the node becomes a concrete expression. a ^<--— ID -> ExprVar.
Definition
ParentMap.cpp:17
nixf::ParentMapAnalysis::isRoot
static bool isRoot(const Node *Up, const Node &N)
Definition
ParentMap.cpp:42
nixf::ParentMapAnalysis::upTo
const Node * upTo(const Node &N, Node::NodeKind Kind) const
Search up until some kind of node is found.
Definition
ParentMap.cpp:27
nixf::ParentMapAnalysis::runOnAST
void runOnAST(const Node &Root)
Definition
ParentMap.cpp:37
nixf::ParentMapAnalysis::query
const Node * query(const Node &N) const
Definition
ParentMap.cpp:13
nixf
Definition
Diagnostic.h:19
Generated by
1.17.0