nixd
Loading...
Searching...
No Matches
Displacement.cpp
Go to the documentation of this file.
1#include "nixt/Displacement.h"
2
3namespace nixt {
4
5nix::PosIdx displOf(const nix::Expr *E, nix::Displacement Displ) {
6 if (const auto *CE = dynamic_cast<const nix::ExprAttrs *>(E))
7 return displOf(CE, Displ);
8 if (const auto *CE = dynamic_cast<const nix::ExprLet *>(E))
9 return displOf(CE, Displ);
10 if (const auto *CE = dynamic_cast<const nix::ExprLambda *>(E))
11 return displOf(CE, Displ);
12
13 assert(false && "The requested expr is not an env creator");
14 return nix::noPos; // unreachable
15}
16
17nix::PosIdx displOf(const nix::ExprAttrs *E, nix::Displacement Displ) {
18 assert(E->recursive && "Only recursive ExprAttr has displacement values");
19
20 auto DefIt = E->attrs.begin();
21 std::advance(DefIt, Displ);
22
23 return DefIt->second.pos;
24}
25
26nix::PosIdx displOf(const nix::ExprLet *E, nix::Displacement Displ) {
27 auto DefIt = E->attrs->attrs.begin();
28 std::advance(DefIt, Displ);
29
30 return DefIt->second.pos;
31}
32
33nix::PosIdx displOf(const nix::ExprLambda *E, nix::Displacement Displ) {
34 if (E->arg) {
35 if (Displ == 0)
36 // It is just a symbol, so noPos.
37 return nix::noPos;
38 Displ--;
39 }
40
41 assert(E->hasFormals() && "Lambda must has formals to create displ");
42 return E->formals->formals[Displ].pos;
43}
44
45} // namespace nixt
Get nix::PosIdx of an nix::Expr, from nix::Displacement.
Access EvalCache in nix::EvalState.
Definition ArrayRef.h:7
nix::PosIdx displOf(const nix::Expr *E, nix::Displacement Displ)
Get nix::PosIdx of an nix::Expr, from nix::Displacement.