nixd
|
Access EvalCache in nix::EvalState
.
More...
Namespaces | |
namespace | detail |
namespace | ek |
"ek" is short for "ExprKind". | |
Classes | |
struct | ArrayRef |
Weak reference to an array, with begin and end pointers. More... | |
struct | ASTHeader |
Header of serialized AST. More... | |
struct | DeserializeContext |
API Wrapper around nix:: More... | |
struct | HookExprAssert |
struct | HookExprAttrs |
struct | HookExprCall |
struct | HookExprConcatStrings |
struct | HookExprFloat |
struct | HookExprIf |
struct | HookExprInt |
struct | HookExprLambda |
struct | HookExprLet |
struct | HookExprList |
struct | HookExprOpAnd |
struct | HookExprOpConcatLists |
struct | HookExprOpEq |
struct | HookExprOpHasAttr |
struct | HookExprOpImpl |
struct | HookExprOpNEq |
struct | HookExprOpNot |
struct | HookExprOpOr |
struct | HookExprOpUpdate |
struct | HookExprPath |
struct | HookExprPos |
struct | HookExprSelect |
struct | HookExprString |
struct | HookExprVar |
struct | HookExprWith |
struct | PtrPool |
A simple pointer pool, a vector of unique_ptr s. More... | |
struct | RecursiveASTVisitor |
A CRTP base class for traversing nix::Expr * nodes. More... | |
Typedefs | |
using | BytesRef = ArrayRef<char> |
using | FileEvalCache = std::map<nix::SourcePath, nix::Expr *> |
using | ValueMap = std::map<std::uintptr_t, nix::Value> |
using | EnvMap = std::map<std::uintptr_t, nix::Env *> |
using | ParentMap = std::map<const nix::Expr *, const nix::Expr *> |
The parent map. The key is "child", the value is "parent". | |
Enumerations | |
enum class | EncodeKind : uint32_t { NIX_EXPR , /home/runner/work/nixd/nixd/libnixt/include/nixt/Serialize.h , AttrNameSymbol } |
Functions | |
template<class T > | |
const T * | begin (ArrayRef< T > B) |
Iterator begin. Used for range-based-for | |
template<class T > | |
const T * | end (ArrayRef< T > B) |
Iterator end. | |
std::string_view | view (BytesRef B) |
template<class T > | |
ArrayRef< T > | advance (ArrayRef< T > B, long Offset) |
Advance the beginning pointer of bytes array. | |
template<class T > | |
std::size_t | lengthof (ArrayRef< T > B) |
Get length of this array. | |
DeserializeContext | getDeserializeContext (nix::EvalState &State, std::string_view BasePath, const nix::Pos::Origin &Origin) |
Stable API wrapper around official nix. | |
nix::Expr * | deserializeHookable (std::string_view &Data, DeserializeContext &Ctx, PtrPool< nix::Expr > &Pool, ValueMap &VMap, EnvMap &EMap) |
nix::PosIdx | displOf (const nix::Expr *E, nix::Displacement Displ) |
Get nix::PosIdx of an nix::Expr , from nix::Displacement . | |
nix::PosIdx | displOf (const nix::ExprAttrs *E, nix::Displacement Displ) |
nix::PosIdx | displOf (const nix::ExprLet *E, nix::Displacement Displ) |
nix::PosIdx | displOf (const nix::ExprLambda *E, nix::Displacement Displ) |
void | callDirtyFlake (nix::EvalState &State, std::string_view SrcPath, nix::Value &VRes) |
Call nix flake, but do not use any "fetchers". | |
FileEvalCache & | getFileEvalCache (nix::EvalState &S) |
void | initEval () |
ek::ExprKind | kindOf (const nix::Expr &E) |
Determine the kind of nix::Expr . | |
const char * | nameOf (ek::ExprKind Kind) |
Get printable name of some kind. | |
ParentMap | parentMap (const nix::Expr *Root) |
Construct child -> parent relations of nix::Expr nodes. | |
template<class T > requires std::is_standard_layout_v<T> && std::is_trivial_v<T> | |
std::size_t | encode (std::ostream &OS, const T &Data) |
Basic primitives. Trivial data types are just written to a stream. | |
std::size_t | encode (std::ostream &OS, const std::string &Data) |
Encode string to bytes. | |
std::size_t | encode (std::ostream &OS, const nix::Pos::Origin &Origin) |
Encode string to bytes. | |
void | encodeAST (std::ostream &OS, const nix::SymbolTable &STable, const nix::PosTable &PTable, const nix::Pos::Origin &Origin, const nix::Expr *E) |
Encode an AST. E is the root of the AST. | |
template<class T > requires std::is_standard_layout_v<T> && std::is_trivial_v<T> | |
std::size_t | decode (BytesRef Data, T &Obj) |
Basic primitives. Deocde from bytes by memcpy . | |
std::size_t | decode (BytesRef Data, std::string &Str) |
Decode string from bytes. | |
template<class T > | |
T | consume (BytesRef &Data) |
Consume bytes from Data and construct an object of type T . | |
nix::Expr * | consumeAST (BytesRef &Data, PtrPool< nix::Expr > &Pool, nix::PosTable &PTable, nix::SymbolTable &STable) |
std::optional< nix::Value > | getField (nix::EvalState &State, nix::Value &V, std::string_view Field) |
std::optional< std::string_view > | getFieldString (nix::EvalState &State, nix::Value &V, std::string_view Field) |
bool | checkField (nix::EvalState &State, nix::Value &V, std::string_view Field, std::string_view Pred) |
Check if value V is an attrset, has the field, and equals to Pred . | |
bool | checkType (nix::EvalState &State, nix::Value &V, std::string_view Pred) |
Check if value is an attrset, and it's "_type" equals to Pred . | |
bool | isOption (nix::EvalState &State, nix::Value &V) |
bool | isDerivation (nix::EvalState &State, nix::Value &V) |
std::string | attrPathStr (nix::EvalState &State, nix::Value &V, const std::string &AttrPath) |
std::vector< nix::Symbol > | toSymbols (nix::SymbolTable &STable, const std::vector< std::string > &Names) |
Transform a vector of string into a vector of nix symbols. | |
std::vector< nix::Symbol > | toSymbols (nix::SymbolTable &STable, const std::vector< std::string_view > &Names) |
Transform a vector of string into a vector of nix symbols. | |
nix::Value & | selectAttr (nix::EvalState &State, nix::Value &V, nix::Symbol Attr) |
Select attribute Attr . | |
nix::Value & | selectOption (nix::EvalState &State, nix::Value &V, nix::Symbol Attr) |
nix::Value & | selectAttrPath (nix::EvalState &State, nix::Value &V, std::vector< nix::Symbol >::const_iterator Begin, std::vector< nix::Symbol >::const_iterator End) |
Given an attrpath in nix::Value V , select it. | |
nix::Value | selectOptions (nix::EvalState &State, nix::Value &V, std::vector< nix::Symbol >::const_iterator Begin, std::vector< nix::Symbol >::const_iterator End) |
Select the option declaration list, V , dive into "submodules". | |
nix::Value | selectOptions (nix::EvalState &State, nix::Value &V, const std::vector< nix::Symbol > &AttrPath) |
nix::Value & | selectSymbols (nix::EvalState &State, nix::Value &V, const std::vector< nix::Symbol > &AttrPath) |
Given an attrpath in nix::Value V , select it. | |
nix::Value & | selectStrings (nix::EvalState &State, nix::Value &V, const std::vector< std::string > &AttrPath) |
Given an attrpath in nix::Value V , select it. | |
nix::Value & | selectStringViews (nix::EvalState &State, nix::Value &V, const std::vector< std::string_view > &AttrPath) |
Given an attrpath in nix::Value V , select it. | |
DEF_TRAVERSE_TYPE (ExprAssert, { TRY_TO_TRAVERSE(T->cond);TRY_TO_TRAVERSE(T->body);}) DEF_TRAVERSE_TYPE(ExprAttrs | |
for (auto &DAD :T->dynamicAttrs) | |
DEF_TRAVERSE_TYPE (ExprCall, { for(auto &Arg :T->args) TRY_TO_TRAVERSE(Arg);TRY_TO_TRAVERSE(T->fun);}) DEF_TRAVERSE_TYPE(ExprConcatStrings | |
DEF_TRAVERSE_TYPE (ExprIf, { TRY_TO_TRAVERSE(T->cond);TRY_TO_TRAVERSE(T->then);TRY_TO_TRAVERSE(T->else_);}) DEF_TRAVERSE_TYPE(ExprLambda | |
TRY_TO_TRAVERSE (T->body) | |
DEF_TRAVERSE_TYPE (ExprLet, { TRY_TO_TRAVERSE(T->attrs);TRY_TO_TRAVERSE(T->body);}) DEF_TRAVERSE_TYPE(ExprList | |
DEF_TRAVERSE_TYPE (ExprOpHasAttr, { TRY_TO_TRAVERSE(T->e);for(auto &E :T->attrPath) if(!E.symbol) TRY_TO_TRAVERSE(E.expr);}) DEF_TRAVERSE_TYPE(ExprSelect | |
for (auto &E :T->attrPath) | |
Access EvalCache in nix::EvalState
.
Library for playing with nix::Expr
nodes.
This is a library with some utilities playing with nix AST nodes (e.g. traversing, visiting, encoding, decoding, dispatching, printing). It is not a parser, so you should use other libraries to parse nix code.
using nixt::BytesRef = ArrayRef<char> |
Definition at line 16 of file ArrayRef.h.
using nixt::EnvMap = std::map<std::uintptr_t, nix::Env *> |
Definition at line 10 of file HookExpr.h.
using nixt::FileEvalCache = std::map<nix::SourcePath, nix::Expr *> |
Definition at line 14 of file HackCache.h.
using nixt::ParentMap = std::map<const nix::Expr *, const nix::Expr *> |
The parent map. The key is "child", the value is "parent".
Definition at line 11 of file libnixt/include/nixt/ParentMap.h.
using nixt::ValueMap = std::map<std::uintptr_t, nix::Value> |
Definition at line 9 of file HookExpr.h.
|
strong |
Definition at line 19 of file Serialize.h.
Advance the beginning pointer of bytes array.
Definition at line 27 of file ArrayRef.h.
References nixt::ArrayRef< T >::Begin, and nixt::ArrayRef< T >::End.
Referenced by consume().
std::string nixt::attrPathStr | ( | nix::EvalState & | State, |
nix::Value & | V, | ||
const std::string & | AttrPath ) |
|
inline |
Iterator begin. Used for range-based-for
Definition at line 19 of file ArrayRef.h.
References nixt::ArrayRef< T >::Begin.
Referenced by decode().
void nixt::callDirtyFlake | ( | nix::EvalState & | State, |
std::string_view | SrcPath, | ||
nix::Value & | VRes ) |
Call nix flake, but do not use any "fetchers".
bool nixt::checkField | ( | nix::EvalState & | State, |
nix::Value & | V, | ||
std::string_view | Field, | ||
std::string_view | Pred ) |
Check if value V
is an attrset, has the field, and equals to Pred
.
Definition at line 36 of file Value.cpp.
References getFieldString().
Referenced by checkType(), isDerivation(), and selectOptions().
bool nixt::checkType | ( | nix::EvalState & | State, |
nix::Value & | V, | ||
std::string_view | Pred ) |
Check if value is an attrset, and it's "_type" equals to Pred
.
Definition at line 41 of file Value.cpp.
References checkField().
Referenced by isOption().
T nixt::consume | ( | BytesRef & | Data | ) |
Consume bytes from Data
and construct an object of type T
.
Definition at line 84 of file Serialize.h.
nix::Expr * nixt::consumeAST | ( | BytesRef & | Data, |
PtrPool< nix::Expr > & | Pool, | ||
nix::PosTable & | PTable, | ||
nix::SymbolTable & | STable ) |
std::size_t nixt::decode | ( | BytesRef | Data, |
std::string & | Str ) |
Decode string from bytes.
std::size_t nixt::decode | ( | BytesRef | Data, |
T & | Obj ) |
Basic primitives. Deocde from bytes by memcpy
.
Definition at line 74 of file Serialize.h.
References begin(), and lengthof().
Referenced by consume().
nixt::DEF_TRAVERSE_TYPE | ( | ExprAssert | , |
{ TRY_TO_TRAVERSE(T->cond);TRY_TO_TRAVERSE(T->body);} | ) |
Traverse.inc, the file declares how to traverse nix::Expr
The file provides: DEF_TRAVERSE_TYPE(Name, Stmt) Stmt defines how to traverse AST nodes (i.e. visit it's subnodes) The subnodes is wrapped around with macro TRY_TO_TRAVERSE.
nixt::DEF_TRAVERSE_TYPE | ( | ExprCall | , |
{ for(auto &Arg :T->args) TRY_TO_TRAVERSE(Arg);TRY_TO_TRAVERSE(T->fun);} | ) |
nixt::DEF_TRAVERSE_TYPE | ( | ExprIf | , |
{ TRY_TO_TRAVERSE(T->cond);TRY_TO_TRAVERSE(T->then);TRY_TO_TRAVERSE(T->else_);} | ) |
nixt::DEF_TRAVERSE_TYPE | ( | ExprLet | , |
{ TRY_TO_TRAVERSE(T->attrs);TRY_TO_TRAVERSE(T->body);} | ) |
nixt::DEF_TRAVERSE_TYPE | ( | ExprOpHasAttr | , |
{ TRY_TO_TRAVERSE(T->e);for(auto &E :T->attrPath) if(!E.symbol) TRY_TO_TRAVERSE(E.expr);} | ) |
nix::Expr * nixt::deserializeHookable | ( | std::string_view & | Data, |
DeserializeContext & | Ctx, | ||
PtrPool< nix::Expr > & | Pool, | ||
ValueMap & | VMap, | ||
EnvMap & | EMap ) |
nix::PosIdx nixt::displOf | ( | const nix::Expr * | E, |
nix::Displacement | Displ ) |
Get nix::PosIdx
of an nix::Expr
, from nix::Displacement
.
The function actually invokes displOf()
of the corresponding Expr
type.
Definition at line 5 of file Displacement.cpp.
References displOf().
Referenced by displOf().
nix::PosIdx nixt::displOf | ( | const nix::ExprAttrs * | E, |
nix::Displacement | Displ ) |
E->recursive
. Since normal ExprAttrs
cannot do variable binding. Definition at line 17 of file Displacement.cpp.
nix::PosIdx nixt::displOf | ( | const nix::ExprLambda * | E, |
nix::Displacement | Displ ) |
Definition at line 33 of file Displacement.cpp.
nix::PosIdx nixt::displOf | ( | const nix::ExprLet * | E, |
nix::Displacement | Displ ) |
Definition at line 26 of file Displacement.cpp.
std::size_t nixt::encode | ( | std::ostream & | OS, |
const nix::Pos::Origin & | Origin ) |
Encode string to bytes.
std::size_t nixt::encode | ( | std::ostream & | OS, |
const std::string & | Data ) |
Encode string to bytes.
std::size_t nixt::encode | ( | std::ostream & | OS, |
const T & | Data ) |
Basic primitives. Trivial data types are just written to a stream.
Definition at line 49 of file Serialize.h.
void nixt::encodeAST | ( | std::ostream & | OS, |
const nix::SymbolTable & | STable, | ||
const nix::PosTable & | PTable, | ||
const nix::Pos::Origin & | Origin, | ||
const nix::Expr * | E ) |
Encode an AST. E
is the root of the AST.
|
inline |
DeserializeContext nixt::getDeserializeContext | ( | nix::EvalState & | State, |
std::string_view | BasePath, | ||
const nix::Pos::Origin & | Origin ) |
Stable API wrapper around official nix.
Because of "lazy-trees", these APIs have always breaked among nix updates, the function wraps the context with a "stable" class nix::EvalState
.
std::optional< nix::Value > nixt::getField | ( | nix::EvalState & | State, |
nix::Value & | V, | ||
std::string_view | Field ) |
Definition at line 10 of file Value.cpp.
Referenced by getFieldString().
std::optional< std::string_view > nixt::getFieldString | ( | nix::EvalState & | State, |
nix::Value & | V, | ||
std::string_view | Field ) |
|
inline |
Definition at line 46 of file HackCache.h.
|
inline |
Definition at line 14 of file InitEval.h.
Referenced by main().
bool nixt::isDerivation | ( | nix::EvalState & | State, |
nix::Value & | V ) |
Definition at line 50 of file Value.cpp.
References checkField().
bool nixt::isOption | ( | nix::EvalState & | State, |
nix::Value & | V ) |
Definition at line 46 of file Value.cpp.
References checkType().
Referenced by nixd::AttrSetProvider::onOptionComplete(), and selectOptions().
ek::ExprKind nixt::kindOf | ( | const nix::Expr & | E | ) |
Determine the kind of nix::Expr
.
|
inline |
Get length of this array.
Definition at line 31 of file ArrayRef.h.
References nixt::ArrayRef< T >::Begin, and nixt::ArrayRef< T >::End.
Referenced by decode().
const char * nixt::nameOf | ( | ek::ExprKind | Kind | ) |
Get printable name of some kind.
ParentMap nixt::parentMap | ( | const nix::Expr * | Root | ) |
Construct child -> parent relations of nix::Expr
nodes.
Definition at line 5 of file libnixt/lib/ParentMap.cpp.
nix::Value & nixt::selectAttr | ( | nix::EvalState & | State, |
nix::Value & | V, | ||
nix::Symbol | Attr ) |
Select attribute Attr
.
Definition at line 84 of file Value.cpp.
Referenced by selectAttrPath(), and selectOptions().
nix::Value & nixt::selectAttrPath | ( | nix::EvalState & | State, |
nix::Value & | V, | ||
std::vector< nix::Symbol >::const_iterator | Begin, | ||
std::vector< nix::Symbol >::const_iterator | End ) |
Given an attrpath in nix::Value V
, select it.
Definition at line 102 of file Value.cpp.
References selectAttr(), and selectAttrPath().
Referenced by selectAttrPath(), and selectSymbols().
nix::Value & nixt::selectOption | ( | nix::EvalState & | State, |
nix::Value & | V, | ||
nix::Symbol | Attr ) |
|
inline |
Definition at line 49 of file Value.h.
References selectOptions().
nix::Value nixt::selectOptions | ( | nix::EvalState & | State, |
nix::Value & | V, | ||
std::vector< nix::Symbol >::const_iterator | Begin, | ||
std::vector< nix::Symbol >::const_iterator | End ) |
Select the option declaration list, V
, dive into "submodules".
Definition at line 159 of file Value.cpp.
References checkField(), isOption(), selectAttr(), and selectOptions().
Referenced by nixd::AttrSetProvider::onOptionComplete(), nixd::AttrSetProvider::onOptionInfo(), selectOptions(), and selectOptions().
|
inline |
Given an attrpath in nix::Value V
, select it.
Definition at line 61 of file Value.h.
References selectSymbols(), and toSymbols().
Referenced by nixd::AttrSetProvider::onAttrPathComplete(), and nixd::AttrSetProvider::onAttrPathInfo().
|
inline |
Given an attrpath in nix::Value V
, select it.
Definition at line 68 of file Value.h.
References selectSymbols(), and toSymbols().
|
inline |
Given an attrpath in nix::Value V
, select it.
Definition at line 55 of file Value.h.
References selectAttrPath().
Referenced by selectStrings(), and selectStringViews().
std::vector< nix::Symbol > nixt::toSymbols | ( | nix::SymbolTable & | STable, |
const std::vector< std::string > & | Names ) |
Transform a vector of string into a vector of nix symbols.
Definition at line 63 of file Value.cpp.
Referenced by nixd::AttrSetProvider::onOptionComplete(), nixd::AttrSetProvider::onOptionInfo(), selectStrings(), and selectStringViews().
std::vector< nix::Symbol > nixt::toSymbols | ( | nix::SymbolTable & | STable, |
const std::vector< std::string_view > & | Names ) |
nixt::TRY_TO_TRAVERSE | ( | T-> | body | ) |
|
inline |
Definition at line 24 of file ArrayRef.h.
References nixt::ArrayRef< T >::Begin, and nixt::ArrayRef< T >::End.