* string2ATerm -> overloaded toATerm.

This commit is contained in:
Eelco Dolstra 2004-11-03 18:12:03 +00:00
parent 4cbd845aa4
commit cb7ccb528b
10 changed files with 61 additions and 43 deletions

View File

@ -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";

View File

@ -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");
}

View File

@ -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));
}

View File

@ -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)

View File

@ -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 '}'

View File

@ -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]))));
}

View File

@ -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));
}

View File

@ -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());
}

View File

@ -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 */

View File

@ -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. */