diff options
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/Makefile.am | 8 | ||||
-rw-r--r-- | src/libexpr/attr-path.cc | 7 | ||||
-rw-r--r-- | src/libexpr/attr-path.hh | 6 | ||||
-rw-r--r-- | src/libexpr/eval.cc | 10 | ||||
-rw-r--r-- | src/libexpr/eval.hh | 16 | ||||
-rw-r--r-- | src/libexpr/expr-to-xml.cc | 9 | ||||
-rw-r--r-- | src/libexpr/expr-to-xml.hh | 6 | ||||
-rw-r--r-- | src/libexpr/get-drvs.cc | 9 | ||||
-rw-r--r-- | src/libexpr/get-drvs.hh | 10 | ||||
-rw-r--r-- | src/libexpr/lexer.l | 8 | ||||
-rw-r--r-- | src/libexpr/nixexpr.cc | 8 | ||||
-rw-r--r-- | src/libexpr/nixexpr.hh | 8 | ||||
-rw-r--r-- | src/libexpr/parser.cc | 40 | ||||
-rw-r--r-- | src/libexpr/parser.hh | 6 | ||||
-rw-r--r-- | src/libexpr/parser.y | 47 | ||||
-rw-r--r-- | src/libexpr/primops.cc | 16 |
16 files changed, 158 insertions, 56 deletions
diff --git a/src/libexpr/Makefile.am b/src/libexpr/Makefile.am index f08504259..3696e99d5 100644 --- a/src/libexpr/Makefile.am +++ b/src/libexpr/Makefile.am @@ -2,13 +2,13 @@ pkglib_LTLIBRARIES = libexpr.la libexpr_la_SOURCES = nixexpr.cc nixexpr.hh parser.cc parser.hh \ eval.cc eval.hh primops.cc \ - lexer-tab.c lexer-tab.h parser-tab.c parser-tab.h \ + lexer-tab.c lexer-tab.h parser-tab.cc parser-tab.hh \ get-drvs.cc get-drvs.hh \ attr-path.cc attr-path.hh \ expr-to-xml.cc expr-to-xml.hh BUILT_SOURCES = nixexpr-ast.cc nixexpr-ast.hh \ - parser-tab.h lexer-tab.h parser-tab.c lexer-tab.c + parser-tab.hh lexer-tab.h parser-tab.cc lexer-tab.c EXTRA_DIST = lexer.l parser.y nixexpr-ast.def nixexpr-ast.cc @@ -21,8 +21,8 @@ AM_CFLAGS = \ # Parser generation. -parser-tab.c parser-tab.h: parser.y - $(bison) -v -o parser-tab.c $(srcdir)/parser.y -d +parser-tab.cc parser-tab.hh: parser.y + $(bison) -v -o parser-tab.cc $(srcdir)/parser.y -d lexer-tab.c lexer-tab.h: lexer.l $(flex) --outfile lexer-tab.c --header-file=lexer-tab.h $(srcdir)/lexer.l diff --git a/src/libexpr/attr-path.cc b/src/libexpr/attr-path.cc index 7228adf95..8606da559 100644 --- a/src/libexpr/attr-path.cc +++ b/src/libexpr/attr-path.cc @@ -1,5 +1,9 @@ #include "attr-path.hh" #include "nixexpr-ast.hh" +#include "util.hh" + + +namespace nix { bool isAttrs(EvalState & state, Expr e, ATermMap & attrs) @@ -73,3 +77,6 @@ Expr findAlongAttrPath(EvalState & state, const string & attrPath, return e; } + + +} diff --git a/src/libexpr/attr-path.hh b/src/libexpr/attr-path.hh index 0797ecc58..7abaa83a0 100644 --- a/src/libexpr/attr-path.hh +++ b/src/libexpr/attr-path.hh @@ -7,8 +7,14 @@ #include "eval.hh" +namespace nix { + + Expr findAlongAttrPath(EvalState & state, const string & attrPath, const ATermMap & autoArgs, Expr e); + +} + #endif /* !__ATTR_PATH_H */ diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index aacdc1c8e..02df4a4a3 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1,8 +1,13 @@ #include "eval.hh" #include "parser.hh" +#include "hash.hh" +#include "util.hh" #include "nixexpr-ast.hh" +namespace nix { + + EvalState::EvalState() : normalForms(32768), primOps(128) { @@ -271,7 +276,7 @@ Expr wrapInContext(ATermList context, Expr e) static ATerm concatStrings(EvalState & state, const ATermVector & args) { ATermList context = ATempty; - ostringstream s; + std::ostringstream s; bool isPath = false; for (ATermVector::const_iterator i = args.begin(); i != args.end(); ++i) { @@ -666,3 +671,6 @@ void printEvalStats(EvalState & state) if (showStats) printATermMapStats(); } + + +} diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index c95a30935..b34e91055 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -4,16 +4,21 @@ #include <map> #include "aterm.hh" -#include "hash.hh" #include "nixexpr.hh" -typedef map<Path, PathSet> DrvRoots; -typedef map<Path, Hash> DrvHashes; +namespace nix { + + +class Hash; + + +typedef std::map<Path, PathSet> DrvRoots; +typedef std::map<Path, Hash> DrvHashes; /* Cache for calls to addToStore(); maps source paths to the store paths. */ -typedef map<Path, Path> SrcToStore; +typedef std::map<Path, Path> SrcToStore; struct EvalState; @@ -74,5 +79,8 @@ Expr autoCallFunction(Expr e, const ATermMap & args); /* Print statistics. */ void printEvalStats(EvalState & state); + +} + #endif /* !__EVAL_H */ diff --git a/src/libexpr/expr-to-xml.cc b/src/libexpr/expr-to-xml.cc index cd9112a42..b84c0058e 100644 --- a/src/libexpr/expr-to-xml.cc +++ b/src/libexpr/expr-to-xml.cc @@ -1,10 +1,12 @@ #include "expr-to-xml.hh" - #include "xml-writer.hh" #include "nixexpr-ast.hh" #include "aterm.hh" +namespace nix { + + static XMLAttrs singletonAttrs(const string & name, const string & value) { XMLAttrs attrs; @@ -84,9 +86,12 @@ static void printTermAsXML(Expr e, XMLWriter & doc) } -void printTermAsXML(Expr e, ostream & out) +void printTermAsXML(Expr e, std::ostream & out) { XMLWriter doc(true, out); XMLOpenElement root(doc, "expr"); printTermAsXML(e, doc); } + + +} diff --git a/src/libexpr/expr-to-xml.hh b/src/libexpr/expr-to-xml.hh index 56f947e52..6b95c88f5 100644 --- a/src/libexpr/expr-to-xml.hh +++ b/src/libexpr/expr-to-xml.hh @@ -6,8 +6,10 @@ #include "nixexpr.hh" +namespace nix { -void printTermAsXML(Expr e, ostream & out); - +void printTermAsXML(Expr e, std::ostream & out); + +} #endif /* !__EXPR_TO_XML_H */ diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc index 07dd88e4c..808e12ffd 100644 --- a/src/libexpr/get-drvs.cc +++ b/src/libexpr/get-drvs.cc @@ -1,5 +1,9 @@ #include "get-drvs.hh" #include "nixexpr-ast.hh" +#include "util.hh" + + +namespace nix { string DrvInfo::queryDrvPath(EvalState & state) const @@ -66,7 +70,7 @@ static bool getDerivation(EvalState & state, Expr e, e = evalExpr(state, e); if (!matchAttrs(e, es)) return true; - shared_ptr<ATermMap> attrs(new ATermMap(32)); /* !!! */ + boost::shared_ptr<ATermMap> attrs(new ATermMap(32)); /* !!! */ queryAllAttrs(e, *attrs, false); Expr a = attrs->get(toATerm("type")); @@ -183,3 +187,6 @@ void getDerivations(EvalState & state, Expr e, const string & pathPrefix, Exprs doneExprs; getDerivations(state, e, pathPrefix, autoArgs, drvs, doneExprs); } + + +} diff --git a/src/libexpr/get-drvs.hh b/src/libexpr/get-drvs.hh index 75f6bcf9d..3dac56a4f 100644 --- a/src/libexpr/get-drvs.hh +++ b/src/libexpr/get-drvs.hh @@ -9,7 +9,10 @@ #include "eval.hh" -typedef map<string, string> MetaInfo; +namespace nix { + + +typedef std::map<string, string> MetaInfo; struct DrvInfo @@ -23,7 +26,7 @@ public: string attrPath; /* path towards the derivation */ string system; - shared_ptr<ATermMap> attrs; + boost::shared_ptr<ATermMap> attrs; string queryDrvPath(EvalState & state) const; string queryOutPath(EvalState & state) const; @@ -52,5 +55,8 @@ bool getDerivation(EvalState & state, Expr e, DrvInfo & drv); void getDerivations(EvalState & state, Expr e, const string & pathPrefix, const ATermMap & autoArgs, DrvInfos & drvs); + +} + #endif /* !__GET_DRVS_H */ diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index fb19e16b4..bbf872ff6 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -9,7 +9,7 @@ %{ #include <string.h> #include <aterm2.h> -#include "parser-tab.h" +#include "parser-tab.hh" static void initLoc(YYLTYPE * loc) { @@ -35,7 +35,11 @@ static void adjustLoc(YYLTYPE * loc, const char * s, size_t len) } } -ATerm toATerm(const char * s); +ATerm toATerm(const char * s) +{ + return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s, 0, ATtrue)); +} + ATerm unescapeStr(const char * s); #define YY_USER_INIT initLoc(yylloc) diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index fac2c0e5c..b7ccb656c 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -1,11 +1,14 @@ #include "nixexpr.hh" #include "derivations.hh" - +#include "util.hh" #include "nixexpr-ast.hh" #include "nixexpr-ast.cc" +namespace nix { + + string showPos(ATerm pos) { ATerm path; @@ -332,3 +335,6 @@ string showValue(Expr e) /* !!! incomplete */ return "<unknown>"; } + + +} diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 3eb4d4cb2..af39997c5 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -6,7 +6,10 @@ #include <aterm2.h> #include "aterm-map.hh" -#include "util.hh" +#include "types.hh" + + +namespace nix { MakeError(EvalError, Error) @@ -95,5 +98,8 @@ string showType(Expr e); string showValue(Expr e); + +} + #endif /* !__NIXEXPR_H */ diff --git a/src/libexpr/parser.cc b/src/libexpr/parser.cc index fa6c4e2f3..20a6c9be2 100644 --- a/src/libexpr/parser.cc +++ b/src/libexpr/parser.cc @@ -1,3 +1,8 @@ +#include "parser.hh" +#include "aterm.hh" +#include "util.hh" +#include "nixexpr-ast.hh" + #include <sstream> #include <sys/types.h> @@ -5,9 +10,15 @@ #include <fcntl.h> #include <unistd.h> -#include "aterm.hh" -#include "parser.hh" -#include "nixexpr-ast.hh" + +extern "C" { + +#include "parser-tab.hh" +#include "lexer-tab.h" + +} + +namespace nix { struct ParseData @@ -17,16 +28,15 @@ struct ParseData Path path; string error; }; + +} -extern "C" { +int yyparse(yyscan_t scanner, nix::ParseData * data); + + +namespace nix { -#include "parser-tab.h" -#include "lexer-tab.h" - -/* Callbacks for getting from C to C++. Due to a (small) bug in the - GLR code of Bison we cannot currently compile the parser as C++ - code. */ void setParseResult(ParseData * data, ATerm t) { @@ -71,6 +81,7 @@ const char * getPath(ParseData * data) return data->path.c_str(); } +extern "C" { Expr unescapeStr(const char * s) { string t; @@ -93,11 +104,7 @@ Expr unescapeStr(const char * s) } return makeStr(toATerm(t)); } - -int yyparse(yyscan_t scanner, ParseData * data); - - -} /* end of C functions */ +} static void checkAttrs(ATermMap & names, ATermList bnds) @@ -232,3 +239,6 @@ Expr parseExprFromString(EvalState & state, { return parse(state, s.c_str(), "(string)", basePath); } + + +} diff --git a/src/libexpr/parser.hh b/src/libexpr/parser.hh index 2af5385f6..334822b5e 100644 --- a/src/libexpr/parser.hh +++ b/src/libexpr/parser.hh @@ -4,6 +4,9 @@ #include "eval.hh" +namespace nix { + + /* Parse a Nix expression from the specified file. If `path' refers to a directory, the "/default.nix" is appended. */ Expr parseExprFromFile(EvalState & state, Path path); @@ -13,4 +16,7 @@ Expr parseExprFromString(EvalState & state, const string & s, const Path & basePath); +} + + #endif /* !__PARSER_H */ diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index c1e3b48a7..7714a5911 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -3,7 +3,7 @@ %locations %error-verbose %parse-param { yyscan_t scanner } -%parse-param { void * data } +%parse-param { ParseData * data } %lex-param { yyscan_t scanner } %{ @@ -12,34 +12,47 @@ #include <string.h> #include <aterm2.h> -#include "parser-tab.h" +#include "parser-tab.hh" +extern "C" { #include "lexer-tab.h" +} -typedef ATerm Expr; -typedef ATerm ValidValues; -typedef ATerm DefaultValue; -typedef ATerm Pos; +#include "aterm.hh" +#include "nixexpr.hh" #include "nixexpr-ast.hh" -void setParseResult(void * data, ATerm t); -void parseError(void * data, char * error, int line, int column); -ATerm absParsedPath(void * data, ATerm t); -ATerm fixAttrs(int recursive, ATermList as); -const char * getPath(void * data); -void backToString(yyscan_t scanner); +using namespace nix; -void yyerror(YYLTYPE * loc, yyscan_t scanner, void * data, char * s) +namespace nix { + +struct ParseData { - parseError(data, s, loc->first_line, loc->first_column); + Expr result; + Path basePath; + Path path; + string error; +}; + +void setParseResult(ParseData * data, ATerm t); +void parseError(ParseData * data, char * error, int line, int column); +ATerm absParsedPath(ParseData * data, ATerm t); +ATerm fixAttrs(int recursive, ATermList as); +const char * getPath(ParseData * data); +Expr unescapeStr(const char * s); + +extern "C" { + void backToString(yyscan_t scanner); +} + } -ATerm toATerm(const char * s) +void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, char * s) { - return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s, 0, ATtrue)); + parseError(data, s, loc->first_line, loc->first_column); } -static Pos makeCurPos(YYLTYPE * loc, void * data) +static Pos makeCurPos(YYLTYPE * loc, ParseData * data) { return makePos(toATerm(getPath(data)), loc->first_line, loc->first_column); diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 5dfe90a8f..3f915fc23 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1,11 +1,16 @@ -#include <algorithm> - #include "build.hh" #include "misc.hh" #include "eval.hh" #include "globals.hh" -#include "nixexpr-ast.hh" +#include "store.hh" +#include "util.hh" #include "expr-to-xml.hh" +#include "nixexpr-ast.hh" + +#include <algorithm> + + +namespace nix { static Expr primBuiltins(EvalState & state, const ATermVector & args) @@ -472,7 +477,7 @@ static Expr primToString(EvalState & state, const ATermVector & args) be sensibly or completely represented (e.g., functions). */ static Expr primToXML(EvalState & state, const ATermVector & args) { - ostringstream out; + std::ostringstream out; printTermAsXML(strictEvalExpr(state, args[0]), out); return makeStr(toATerm(out.str())); } @@ -746,3 +751,6 @@ void EvalState::addPrimOps() addPrimOp("removeAttrs", 2, primRemoveAttrs); addPrimOp("relativise", 2, primRelativise); } + + +} |