2003-10-30 18:48:26 +02:00
|
|
|
#ifndef __EVAL_H
|
|
|
|
#define __EVAL_H
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
2003-11-18 13:22:29 +02:00
|
|
|
#include "aterm.hh"
|
2003-11-18 14:06:07 +02:00
|
|
|
#include "nixexpr.hh"
|
2003-10-30 18:48:26 +02:00
|
|
|
|
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
|
|
class Hash;
|
|
|
|
|
|
|
|
|
|
|
|
typedef std::map<Path, PathSet> DrvRoots;
|
|
|
|
typedef std::map<Path, Hash> DrvHashes;
|
2003-10-30 18:48:26 +02:00
|
|
|
|
2006-03-09 17:09:18 +02:00
|
|
|
/* Cache for calls to addToStore(); maps source paths to the store
|
|
|
|
paths. */
|
2006-09-05 00:06:23 +03:00
|
|
|
typedef std::map<Path, Path> SrcToStore;
|
2006-03-09 17:09:18 +02:00
|
|
|
|
2004-02-04 18:03:29 +02:00
|
|
|
struct EvalState;
|
2004-08-04 13:59:20 +03:00
|
|
|
|
|
|
|
/* Note: using a ATermVector is safe here, since when we call a primop
|
|
|
|
we also have an ATermList on the stack. */
|
|
|
|
typedef Expr (* PrimOp) (EvalState &, const ATermVector & args);
|
2004-02-04 18:03:29 +02:00
|
|
|
|
|
|
|
|
2003-10-30 18:48:26 +02:00
|
|
|
struct EvalState
|
|
|
|
{
|
2003-11-03 22:30:40 +02:00
|
|
|
ATermMap normalForms;
|
2004-08-04 13:59:20 +03:00
|
|
|
ATermMap primOps;
|
2004-10-25 17:38:23 +03:00
|
|
|
DrvRoots drvRoots;
|
2003-10-31 19:09:31 +02:00
|
|
|
DrvHashes drvHashes; /* normalised derivation hashes */
|
2006-03-09 17:09:18 +02:00
|
|
|
SrcToStore srcToStore;
|
2003-10-30 18:48:26 +02:00
|
|
|
|
2003-10-31 19:09:31 +02:00
|
|
|
unsigned int nrEvaluated;
|
|
|
|
unsigned int nrCached;
|
|
|
|
|
2003-10-30 18:48:26 +02:00
|
|
|
EvalState();
|
2004-02-04 18:03:29 +02:00
|
|
|
|
2004-08-04 13:59:20 +03:00
|
|
|
void addPrimOps();
|
|
|
|
void addPrimOp(const string & name,
|
|
|
|
unsigned int arity, PrimOp primOp);
|
2003-10-30 18:48:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Evaluate an expression to normal form. */
|
|
|
|
Expr evalExpr(EvalState & state, Expr e);
|
|
|
|
|
|
|
|
/* Evaluate an expression read from the given file to normal form. */
|
|
|
|
Expr evalFile(EvalState & state, const Path & path);
|
|
|
|
|
2006-08-24 16:39:22 +03:00
|
|
|
/* Evaluate an expression, and recursively evaluate list elements and
|
2006-08-30 16:10:04 +03:00
|
|
|
attributes. If `canonicalise' is true, we remove things like
|
|
|
|
position information and make sure that attribute sets are in
|
|
|
|
sorded order. */
|
|
|
|
Expr strictEvalExpr(EvalState & state, Expr e,
|
|
|
|
bool canonicalise = false);
|
2006-08-24 16:39:22 +03:00
|
|
|
|
2003-10-31 19:09:31 +02:00
|
|
|
/* Specific results. */
|
2006-10-16 18:55:34 +03:00
|
|
|
string evalString(EvalState & state, Expr e, PathSet & context);
|
|
|
|
string evalStringNoCtx(EvalState & state, Expr e);
|
2006-09-22 18:29:21 +03:00
|
|
|
int evalInt(EvalState & state, Expr e);
|
2006-03-23 18:43:07 +02:00
|
|
|
bool evalBool(EvalState & state, Expr e);
|
2005-07-25 18:05:34 +03:00
|
|
|
ATermList evalList(EvalState & state, Expr e);
|
2003-10-31 19:09:31 +02:00
|
|
|
|
2006-10-16 18:55:34 +03:00
|
|
|
/* Flatten nested lists into a single list (or expand a singleton into
|
|
|
|
a list). */
|
|
|
|
ATermList flattenList(EvalState & state, Expr e);
|
|
|
|
|
|
|
|
/* String coercion. Converts strings, paths and derivations to a
|
|
|
|
string. If `coerceMore' is set, also converts nulls, integers,
|
|
|
|
booleans and lists to a string. */
|
|
|
|
string coerceToString(EvalState & state, Expr e, PathSet & context,
|
|
|
|
bool coerceMore = false, bool copyToStore = true);
|
|
|
|
|
|
|
|
/* Path coercion. Converts strings, paths and derivations to a path.
|
|
|
|
The result is guaranteed to be an canonicalised, absolute path.
|
|
|
|
Nothing is copied to the store. */
|
|
|
|
Path coerceToPath(EvalState & state, Expr e, PathSet & context);
|
2006-05-01 12:56:56 +03:00
|
|
|
|
2006-07-26 18:05:15 +03:00
|
|
|
/* Automatically call a function for which each argument has a default
|
2006-07-28 19:03:28 +03:00
|
|
|
value or has a binding in the `args' map. Note: result is a call,
|
|
|
|
not a normal form; it should be evaluated by calling evalExpr(). */
|
|
|
|
Expr autoCallFunction(Expr e, const ATermMap & args);
|
2006-07-26 18:05:15 +03:00
|
|
|
|
2003-10-31 19:09:31 +02:00
|
|
|
/* Print statistics. */
|
|
|
|
void printEvalStats(EvalState & state);
|
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-10-30 18:48:26 +02:00
|
|
|
|
|
|
|
#endif /* !__EVAL_H */
|