about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-11-03T18·12+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-11-03T18·12+0000
commitcb7ccb528bbaeb30d09fbb41e57ab75d3121e1bc (patch)
treed27270a2b3c6abc86f56956d906899374778f028 /src
parent4cbd845aa491b5cf534f8c031d285fc454933868 (diff)
* string2ATerm -> overloaded toATerm.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/aterm-helper.pl4
-rw-r--r--src/libexpr/eval.cc8
-rw-r--r--src/libexpr/nixexpr.cc6
-rw-r--r--src/libexpr/parser.cc2
-rw-r--r--src/libexpr/parser.y9
-rw-r--r--src/libexpr/primops.cc10
-rw-r--r--src/libstore/storeexpr.cc14
-rw-r--r--src/libutil/aterm.cc12
-rw-r--r--src/libutil/aterm.hh5
-rw-r--r--src/nix-env/main.cc34
10 files changed, 61 insertions, 43 deletions
diff --git a/src/aterm-helper.pl b/src/aterm-helper.pl
index 917b50852aa6..376691c9a210 100755
--- a/src/aterm-helper.pl
+++ b/src/aterm-helper.pl
@@ -130,10 +130,6 @@ while (<STDIN>) {
 
 print HEADER "void $initFun();\n\n";
 
-print HEADER "static inline ATerm string2ATerm(const char * s) {\n";
-print HEADER "    return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s, 0, ATtrue));\n";
-print HEADER "}\n\n";
-
 print HEADER "static inline const char * aterm2String(ATerm t) {\n";
 print HEADER "    return (const char *) ATgetName(ATgetAFun(t));\n";
 print HEADER "}\n\n";
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index cef346002962..d4593b5c0ec0 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -328,11 +328,11 @@ Expr evalExpr2(EvalState & state, Expr e)
         e2 = evalExpr(state, e2);
         ATerm s1, s2;
         if (matchStr(e1, s1) && matchStr(e2, s2))
-            return makeStr(string2ATerm((
-                (string) aterm2String(s1) + (string) aterm2String(s2)).c_str()));
+            return makeStr(toATerm(
+                (string) aterm2String(s1) + (string) aterm2String(s2)));
         else if (matchPath(e1, s1) && matchPath(e2, s2))
-            return makePath(string2ATerm(canonPath(
-                (string) aterm2String(s1) + "/" + (string) aterm2String(s2)).c_str()));
+            return makePath(toATerm(canonPath(
+                (string) aterm2String(s1) + "/" + (string) aterm2String(s2))));
         else throw Error("wrong argument types in `+' operator");
     }
 
diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc
index 56e053fd7ae4..d806a9130afd 100644
--- a/src/libexpr/nixexpr.cc
+++ b/src/libexpr/nixexpr.cc
@@ -42,7 +42,7 @@ void ATermMap::set(ATerm key, ATerm value)
 
 void ATermMap::set(const string & key, ATerm value)
 {
-    set(string2ATerm(key.c_str()), value);
+    set(toATerm(key), value);
 }
 
 
@@ -54,7 +54,7 @@ ATerm ATermMap::get(ATerm key) const
 
 ATerm ATermMap::get(const string & key) const
 {
-    return get(string2ATerm(key.c_str()));
+    return get(toATerm(key));
 }
 
 
@@ -66,7 +66,7 @@ void ATermMap::remove(ATerm key)
 
 void ATermMap::remove(const string & key)
 {
-    remove(string2ATerm(key.c_str()));
+    remove(toATerm(key));
 }
 
 
diff --git a/src/libexpr/parser.cc b/src/libexpr/parser.cc
index 8a199c00263f..8232b0de5f4a 100644
--- a/src/libexpr/parser.cc
+++ b/src/libexpr/parser.cc
@@ -35,7 +35,7 @@ void setParseResult(ParseData * data, ATerm t)
 
 ATerm absParsedPath(ParseData * data, ATerm t)
 {
-    return string2ATerm(absPath(aterm2String(t), data->basePath).c_str());
+    return toATerm(absPath(aterm2String(t), data->basePath));
 }
     
 void parseError(ParseData * data, char * error, int line, int column)
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index 8573697b634d..1f204a228009 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -31,9 +31,14 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, void * data, char * s)
     parseError(data, s, loc->first_line, loc->first_column);
 }
 
+ATerm toATerm(const char * s)
+{
+    return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s, 0, ATtrue));
+}
+
 static Pos makeCurPos(YYLTYPE * loc, void * data)
 {
-    return makePos(string2ATerm(getPath(data)),
+    return makePos(toATerm(getPath(data)),
         loc->first_line, loc->first_column);
 }
 
@@ -122,7 +127,7 @@ expr_simple
   /* Let expressions `let {..., body = ...}' are just desugared
      into `(rec {..., body = ...}).body'. */
   | LET '{' binds '}'
-    { $$ = makeSelect(fixAttrs(1, $3), string2ATerm("body")); }
+    { $$ = makeSelect(fixAttrs(1, $3), toATerm("body")); }
   | REC '{' binds '}'
     { $$ = fixAttrs(1, $3); }
   | '{' binds '}'
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 830a2c095839..41b444b20d44 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -269,11 +269,11 @@ static Expr primDerivation(EvalState & state, const ATermVector & _args)
     printMsg(lvlChatty, format("instantiated `%1%' -> `%2%'")
         % drvName % drvPath);
 
-    attrs.set("outPath", makeAttrRHS(makePath(string2ATerm(outPath.c_str())), makeNoPos()));
-    attrs.set("drvPath", makeAttrRHS(makePath(string2ATerm(drvPath.c_str())), makeNoPos()));
+    attrs.set("outPath", makeAttrRHS(makePath(toATerm(outPath)), makeNoPos()));
+    attrs.set("drvPath", makeAttrRHS(makePath(toATerm(drvPath)), makeNoPos()));
     attrs.set("drvHash",
-        makeAttrRHS(makeStr(string2ATerm(((string) drvHash).c_str())), makeNoPos()));
-    attrs.set("type", makeAttrRHS(makeStr(string2ATerm("derivation")), makeNoPos()));
+        makeAttrRHS(makeStr(toATerm((string) drvHash)), makeNoPos()));
+    attrs.set("type", makeAttrRHS(makeStr(toATerm("derivation")), makeNoPos()));
 
     return makeAttrs(attrs);
 }
@@ -283,7 +283,7 @@ static Expr primDerivation(EvalState & state, const ATermVector & _args)
    following the last slash. */
 static Expr primBaseNameOf(EvalState & state, const ATermVector & args)
 {
-    return makeStr(string2ATerm(baseNameOf(evalString(state, args[0])).c_str()));
+    return makeStr(toATerm(baseNameOf(evalString(state, args[0]))));
 }
 
 
diff --git a/src/libstore/storeexpr.cc b/src/libstore/storeexpr.cc
index 0b92be0e7117..8f5c5dea67e0 100644
--- a/src/libstore/storeexpr.cc
+++ b/src/libstore/storeexpr.cc
@@ -142,7 +142,7 @@ static ATermList unparsePaths(const PathSet & paths)
     ATermList l = ATempty;
     for (PathSet::const_iterator i = paths.begin();
          i != paths.end(); i++)
-        l = ATinsert(l, string2ATerm(i->c_str()));
+        l = ATinsert(l, toATerm(*i));
     return ATreverse(l);
 }
 
@@ -156,7 +156,7 @@ static ATerm unparseClosure(const Closure & closure)
          i != closure.elems.end(); i++)
         elems = ATinsert(elems,
             makeClosureElem(
-                string2ATerm(i->first.c_str()),
+                toATerm(i->first),
                 unparsePaths(i->second.refs)));
 
     return makeClosure(roots, elems);
@@ -168,21 +168,21 @@ static ATerm unparseDerivation(const Derivation & derivation)
     ATermList args = ATempty;
     for (Strings::const_iterator i = derivation.args.begin();
          i != derivation.args.end(); i++)
-        args = ATinsert(args, string2ATerm(i->c_str()));
+        args = ATinsert(args, toATerm(*i));
 
     ATermList env = ATempty;
     for (StringPairs::const_iterator i = derivation.env.begin();
          i != derivation.env.end(); i++)
         env = ATinsert(env,
             makeEnvBinding(
-                string2ATerm(i->first.c_str()),
-                string2ATerm(i->second.c_str())));
+                toATerm(i->first),
+                toATerm(i->second)));
 
     return makeDerive(
         unparsePaths(derivation.outputs),
         unparsePaths(derivation.inputs),
-        string2ATerm(derivation.platform.c_str()),
-        string2ATerm(derivation.builder.c_str()),
+        toATerm(derivation.platform),
+        toATerm(derivation.builder),
         ATreverse(args),
         ATreverse(env));
 }
diff --git a/src/libutil/aterm.cc b/src/libutil/aterm.cc
index 77bf8dab4c12..6ca4521909ea 100644
--- a/src/libutil/aterm.cc
+++ b/src/libutil/aterm.cc
@@ -27,3 +27,15 @@ Error badTerm(const format & f, ATerm t)
     }
     return Error(format("%1%, in `%2%'") % f.str() % (string) s);
 }
+
+
+ATerm toATerm(const char * s)
+{
+    return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s, 0, ATtrue));
+}
+
+
+ATerm toATerm(const string & s)
+{
+    return toATerm(s.c_str());
+}
diff --git a/src/libutil/aterm.hh b/src/libutil/aterm.hh
index 883d20c63ad1..22364ba0118f 100644
--- a/src/libutil/aterm.hh
+++ b/src/libutil/aterm.hh
@@ -41,4 +41,9 @@ public:
 Error badTerm(const format & f, ATerm t);
 
 
+/* Convert strings to ATerms. */
+ATerm toATerm(const char * s);
+ATerm toATerm(const string & s);
+
+
 #endif /* !__ATERM_H */
diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc
index 527dafbf7811..c2f5cdccb8c8 100644
--- a/src/nix-env/main.cc
+++ b/src/nix-env/main.cc
@@ -192,18 +192,18 @@ void createUserEnv(EvalState & state, const DrvInfos & drvs,
          i != drvs.end(); ++i)
     {
         ATerm t = makeAttrs(ATmakeList6(
-            makeBind(string2ATerm("type"),
-                makeStr(string2ATerm("derivation")), makeNoPos()),
-            makeBind(string2ATerm("name"),
-                makeStr(string2ATerm(i->second.name.c_str())), makeNoPos()),
-            makeBind(string2ATerm("system"),
-                makeStr(string2ATerm(i->second.system.c_str())), makeNoPos()),
-            makeBind(string2ATerm("drvPath"),
-                makePath(string2ATerm(i->second.drvPath.c_str())), makeNoPos()),
-            makeBind(string2ATerm("drvHash"),
-                makeStr(string2ATerm(((string) i->second.drvHash).c_str())), makeNoPos()),
-            makeBind(string2ATerm("outPath"),
-                makePath(string2ATerm(i->second.outPath.c_str())), makeNoPos())
+            makeBind(toATerm("type"),
+                makeStr(toATerm("derivation")), makeNoPos()),
+            makeBind(toATerm("name"),
+                makeStr(toATerm(i->second.name)), makeNoPos()),
+            makeBind(toATerm("system"),
+                makeStr(toATerm(i->second.system)), makeNoPos()),
+            makeBind(toATerm("drvPath"),
+                makePath(toATerm(i->second.drvPath)), makeNoPos()),
+            makeBind(toATerm("drvHash"),
+                makeStr(toATerm((string) i->second.drvHash)), makeNoPos()),
+            makeBind(toATerm("outPath"),
+                makePath(toATerm(i->second.outPath)), makeNoPos())
             ));
         inputs = ATinsert(inputs, t);
     }
@@ -215,11 +215,11 @@ void createUserEnv(EvalState & state, const DrvInfos & drvs,
     Path inputsFile = writeTerm(inputs2, "-env-inputs");
 
     Expr topLevel = makeCall(envBuilder, makeAttrs(ATmakeList3(
-        makeBind(string2ATerm("system"),
-            makeStr(string2ATerm(thisSystem.c_str())), makeNoPos()),
-        makeBind(string2ATerm("derivations"), inputs2, makeNoPos()),
-        makeBind(string2ATerm("manifest"),
-            makePath(string2ATerm(inputsFile.c_str())), makeNoPos())
+        makeBind(toATerm("system"),
+            makeStr(toATerm(thisSystem)), makeNoPos()),
+        makeBind(toATerm("derivations"), inputs2, makeNoPos()),
+        makeBind(toATerm("manifest"),
+            makePath(toATerm(inputsFile)), makeNoPos())
         )));
 
     /* Instantiate it. */