nixd
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Enumerations | Functions
nixt Namespace Reference

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_ptrs. 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 , 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".
 
FileEvalCachegetFileEvalCache (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 >
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.
 

Detailed Description

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.

Typedef Documentation

◆ BytesRef

using nixt::BytesRef = ArrayRef<char>

Definition at line 16 of file ArrayRef.h.

◆ EnvMap

using nixt::EnvMap = std::map<std::uintptr_t, nix::Env *>

Definition at line 10 of file HookExpr.h.

◆ FileEvalCache

using nixt::FileEvalCache = std::map<nix::SourcePath, nix::Expr *>

Definition at line 14 of file HackCache.h.

◆ ParentMap

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.

◆ ValueMap

using nixt::ValueMap = std::map<std::uintptr_t, nix::Value>

Definition at line 9 of file HookExpr.h.

Enumeration Type Documentation

◆ EncodeKind

enum class nixt::EncodeKind : uint32_t
strong
Enumerator
NIX_EXPR 
AttrNameSymbol 

Definition at line 19 of file Serialize.h.

Function Documentation

◆ advance()

template<class T >
ArrayRef< T > nixt::advance ( ArrayRef< T > B,
long Offset )
inline

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().

◆ attrPathStr()

std::string nixt::attrPathStr ( nix::EvalState & State,
nix::Value & V,
const std::string & AttrPath )

Definition at line 54 of file Value.cpp.

◆ begin()

template<class T >
const T * nixt::begin ( ArrayRef< T > B)
inline

Iterator begin. Used for range-based-for

Definition at line 19 of file ArrayRef.h.

References nixt::ArrayRef< T >::Begin.

Referenced by decode().

◆ callDirtyFlake()

void nixt::callDirtyFlake ( nix::EvalState & State,
std::string_view SrcPath,
nix::Value & VRes )

Call nix flake, but do not use any "fetchers".

◆ checkField()

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().

◆ checkType()

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().

◆ consume()

template<class T >
T nixt::consume ( BytesRef & Data)

Consume bytes from Data and construct an object of type T.

Definition at line 84 of file Serialize.h.

References advance(), and decode().

◆ consumeAST()

nix::Expr * nixt::consumeAST ( BytesRef & Data,
PtrPool< nix::Expr > & Pool,
nix::PosTable & PTable,
nix::SymbolTable & STable )

◆ decode() [1/2]

std::size_t nixt::decode ( BytesRef Data,
std::string & Str )

Decode string from bytes.

◆ decode() [2/2]

template<class T >
requires std::is_standard_layout_v<T> && std::is_trivial_v<T>
std::size_t nixt::decode ( BytesRef Data,
T & Obj )

Basic primitives. Deocde from bytes by memcpy.

Returns
Size of bytes consumed.

Definition at line 74 of file Serialize.h.

References begin(), and lengthof().

Referenced by consume().

◆ deserializeHookable()

nix::Expr * nixt::deserializeHookable ( std::string_view & Data,
DeserializeContext & Ctx,
PtrPool< nix::Expr > & Pool,
ValueMap & VMap,
EnvMap & EMap )

◆ displOf() [1/4]

nix::PosIdx nixt::displOf ( const nix::Expr * E,
nix::Displacement Displ )

Get nix::PosIdx of an nix::Expr, from nix::Displacement.

Note
This is based on dynamic_cast, so it is not very efficient.

The function actually invokes displOf() of the corresponding Expr type.

Definition at line 5 of file Displacement.cpp.

References displOf().

Referenced by displOf().

◆ displOf() [2/4]

nix::PosIdx nixt::displOf ( const nix::ExprAttrs * E,
nix::Displacement Displ )
Note
The function asserts E->recursive. Since normal ExprAttrs cannot do variable binding.

Definition at line 17 of file Displacement.cpp.

◆ displOf() [3/4]

nix::PosIdx nixt::displOf ( const nix::ExprLambda * E,
nix::Displacement Displ )

Definition at line 33 of file Displacement.cpp.

◆ displOf() [4/4]

nix::PosIdx nixt::displOf ( const nix::ExprLet * E,
nix::Displacement Displ )

Definition at line 26 of file Displacement.cpp.

◆ encode() [1/3]

std::size_t nixt::encode ( std::ostream & OS,
const nix::Pos::Origin & Origin )

Encode string to bytes.

◆ encode() [2/3]

std::size_t nixt::encode ( std::ostream & OS,
const std::string & Data )

Encode string to bytes.

◆ encode() [3/3]

template<class T >
requires std::is_standard_layout_v<T> && std::is_trivial_v<T>
std::size_t nixt::encode ( std::ostream & OS,
const T & Data )

Basic primitives. Trivial data types are just written to a stream.

Returns
The beginning offset of the data in the stream.

Definition at line 49 of file Serialize.h.

◆ encodeAST()

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.

◆ end()

template<class T >
const T * nixt::end ( ArrayRef< T > B)
inline

Iterator end.

Definition at line 22 of file ArrayRef.h.

References nixt::ArrayRef< T >::End.

◆ getDeserializeContext()

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.

◆ getField()

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().

◆ getFieldString()

std::optional< std::string_view > nixt::getFieldString ( nix::EvalState & State,
nix::Value & V,
std::string_view Field )

Definition at line 23 of file Value.cpp.

References getField().

Referenced by checkField().

◆ getFileEvalCache()

FileEvalCache & nixt::getFileEvalCache ( nix::EvalState & S)
inline

Definition at line 46 of file HackCache.h.

◆ initEval()

void nixt::initEval ( )
inline

Definition at line 9 of file InitEval.h.

Referenced by main().

◆ isDerivation()

bool nixt::isDerivation ( nix::EvalState & State,
nix::Value & V )

Definition at line 50 of file Value.cpp.

References checkField().

◆ isOption()

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().

◆ kindOf()

ExprKind nixt::kindOf ( const nix::Expr & E)

Determine the kind of nix::Expr.

Note
This is based on dynamic_cast, so it is not very efficient.

Definition at line 9 of file Kinds.cpp.

References nixt::ek::LastExprKind.

◆ lengthof()

template<class T >
std::size_t nixt::lengthof ( ArrayRef< T > B)
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().

◆ nameOf()

const char * nixt::nameOf ( ek::ExprKind Kind)

Get printable name of some kind.

Definition at line 22 of file Kinds.cpp.

References nixt::ek::LastExprKind.

◆ parentMap()

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.

References nixt::RecursiveASTVisitor< Derived >::traverseExpr().

◆ selectAttr()

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().

◆ selectAttrPath()

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().

◆ selectOption()

nix::Value & nixt::selectOption ( nix::EvalState & State,
nix::Value & V,
nix::Symbol Attr )

◆ selectOptions() [1/2]

nix::Value nixt::selectOptions ( nix::EvalState & State,
nix::Value & V,
const std::vector< nix::Symbol > & AttrPath )
inline

Definition at line 49 of file Value.h.

References selectOptions().

◆ selectOptions() [2/2]

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 158 of file Value.cpp.

References checkField(), isOption(), selectAttr(), and selectOptions().

Referenced by nixd::AttrSetProvider::onOptionComplete(), nixd::AttrSetProvider::onOptionInfo(), selectOptions(), and selectOptions().

◆ selectStrings()

nix::Value & nixt::selectStrings ( nix::EvalState & State,
nix::Value & V,
const std::vector< std::string > & AttrPath )
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().

◆ selectStringViews()

nix::Value & nixt::selectStringViews ( nix::EvalState & State,
nix::Value & V,
const std::vector< std::string_view > & AttrPath )
inline

Given an attrpath in nix::Value V, select it.

Definition at line 68 of file Value.h.

References selectSymbols(), and toSymbols().

◆ selectSymbols()

nix::Value & nixt::selectSymbols ( nix::EvalState & State,
nix::Value & V,
const std::vector< nix::Symbol > & AttrPath )
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().

◆ toSymbols() [1/2]

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().

◆ toSymbols() [2/2]

std::vector< nix::Symbol > nixt::toSymbols ( nix::SymbolTable & STable,
const std::vector< std::string_view > & Names )

Transform a vector of string into a vector of nix symbols.

Definition at line 74 of file Value.cpp.

◆ view()

std::string_view nixt::view ( BytesRef B)
inline

Definition at line 24 of file ArrayRef.h.

References nixt::ArrayRef< T >::Begin, and nixt::ArrayRef< T >::End.