2003-10-30 17:48:26 +01:00
|
|
|
#ifndef __EVAL_H
|
|
|
|
#define __EVAL_H
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
2003-11-18 12:22:29 +01:00
|
|
|
#include "aterm.hh"
|
2003-11-18 13:06:07 +01:00
|
|
|
#include "nixexpr.hh"
|
2003-10-30 17:48:26 +01:00
|
|
|
|
|
|
|
|
2006-09-04 23:06:23 +02:00
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
|
|
class Hash;
|
|
|
|
|
|
|
|
|
|
|
|
typedef std::map<Path, PathSet> DrvRoots;
|
|
|
|
typedef std::map<Path, Hash> DrvHashes;
|
2003-10-30 17:48:26 +01:00
|
|
|
|
2006-03-09 16:09:18 +01:00
|
|
|
/* Cache for calls to addToStore(); maps source paths to the store
|
|
|
|
paths. */
|
2006-09-04 23:06:23 +02:00
|
|
|
typedef std::map<Path, Path> SrcToStore;
|
2006-03-09 16:09:18 +01:00
|
|
|
|
2004-02-04 17:03:29 +01:00
|
|
|
struct EvalState;
|
2004-08-04 12:59:20 +02: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 17:03:29 +01:00
|
|
|
|
|
|
|
|
2003-10-30 17:48:26 +01:00
|
|
|
struct EvalState
|
|
|
|
{
|
2003-11-03 21:30:40 +01:00
|
|
|
ATermMap normalForms;
|
2004-08-04 12:59:20 +02:00
|
|
|
ATermMap primOps;
|
2004-10-25 16:38:23 +02:00
|
|
|
DrvRoots drvRoots;
|
2003-10-31 18:09:31 +01:00
|
|
|
DrvHashes drvHashes; /* normalised derivation hashes */
|
2006-03-09 16:09:18 +01:00
|
|
|
SrcToStore srcToStore;
|
2003-10-30 17:48:26 +01:00
|
|
|
|
2003-10-31 18:09:31 +01:00
|
|
|
unsigned int nrEvaluated;
|
|
|
|
unsigned int nrCached;
|
|
|
|
|
2003-10-30 17:48:26 +01:00
|
|
|
EvalState();
|
2004-02-04 17:03:29 +01:00
|
|
|
|
2004-08-04 12:59:20 +02:00
|
|
|
void addPrimOps();
|
|
|
|
void addPrimOp(const string & name,
|
|
|
|
unsigned int arity, PrimOp primOp);
|
2003-10-30 17:48:26 +01: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 15:39:22 +02:00
|
|
|
/* Evaluate an expression, and recursively evaluate list elements and
|
2006-08-30 15:10:04 +02:00
|
|
|
attributes. If `canonicalise' is true, we remove things like
|
|
|
|
position information and make sure that attribute sets are in
|
|
|
|
sorded order. */
|
2007-01-13 16:41:54 +01:00
|
|
|
Expr strictEvalExpr(EvalState & state, Expr e);
|
2006-08-24 15:39:22 +02:00
|
|
|
|
2003-10-31 18:09:31 +01:00
|
|
|
/* Specific results. */
|
2006-10-16 17:55:34 +02:00
|
|
|
string evalString(EvalState & state, Expr e, PathSet & context);
|
|
|
|
string evalStringNoCtx(EvalState & state, Expr e);
|
2006-09-22 17:29:21 +02:00
|
|
|
int evalInt(EvalState & state, Expr e);
|
2006-03-23 17:43:07 +01:00
|
|
|
bool evalBool(EvalState & state, Expr e);
|
2005-07-25 17:05:34 +02:00
|
|
|
ATermList evalList(EvalState & state, Expr e);
|
2003-10-31 18:09:31 +01:00
|
|
|
|
2006-10-16 17:55:34 +02: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 11:56:56 +02:00
|
|
|
|
2006-07-26 17:05:15 +02:00
|
|
|
/* Automatically call a function for which each argument has a default
|
2006-07-28 18:03:28 +02: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 17:05:15 +02:00
|
|
|
|
2003-10-31 18:09:31 +01:00
|
|
|
/* Print statistics. */
|
|
|
|
void printEvalStats(EvalState & state);
|
|
|
|
|
2006-09-04 23:06:23 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-10-30 17:48:26 +01:00
|
|
|
|
|
|
|
#endif /* !__EVAL_H */
|