* 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 "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 "static inline const char * aterm2String(ATerm t) {\n";
print HEADER " return (const char *) ATgetName(ATgetAFun(t));\n"; print HEADER " return (const char *) ATgetName(ATgetAFun(t));\n";
print HEADER "}\n\n"; print HEADER "}\n\n";

View File

@ -328,11 +328,11 @@ Expr evalExpr2(EvalState & state, Expr e)
e2 = evalExpr(state, e2); e2 = evalExpr(state, e2);
ATerm s1, s2; ATerm s1, s2;
if (matchStr(e1, s1) && matchStr(e2, s2)) if (matchStr(e1, s1) && matchStr(e2, s2))
return makeStr(string2ATerm(( return makeStr(toATerm(
(string) aterm2String(s1) + (string) aterm2String(s2)).c_str())); (string) aterm2String(s1) + (string) aterm2String(s2)));
else if (matchPath(e1, s1) && matchPath(e2, s2)) else if (matchPath(e1, s1) && matchPath(e2, s2))
return makePath(string2ATerm(canonPath( return makePath(toATerm(canonPath(
(string) aterm2String(s1) + "/" + (string) aterm2String(s2)).c_str())); (string) aterm2String(s1) + "/" + (string) aterm2String(s2))));
else throw Error("wrong argument types in `+' operator"); 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) 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 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) 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) 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) 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); 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) static Pos makeCurPos(YYLTYPE * loc, void * data)
{ {
return makePos(string2ATerm(getPath(data)), return makePos(toATerm(getPath(data)),
loc->first_line, loc->first_column); loc->first_line, loc->first_column);
} }
@ -122,7 +127,7 @@ expr_simple
/* Let expressions `let {..., body = ...}' are just desugared /* Let expressions `let {..., body = ...}' are just desugared
into `(rec {..., body = ...}).body'. */ into `(rec {..., body = ...}).body'. */
| LET '{' binds '}' | LET '{' binds '}'
{ $$ = makeSelect(fixAttrs(1, $3), string2ATerm("body")); } { $$ = makeSelect(fixAttrs(1, $3), toATerm("body")); }
| REC '{' binds '}' | REC '{' binds '}'
{ $$ = fixAttrs(1, $3); } { $$ = fixAttrs(1, $3); }
| '{' binds '}' | '{' binds '}'

View File

@ -269,11 +269,11 @@ static Expr primDerivation(EvalState & state, const ATermVector & _args)
printMsg(lvlChatty, format("instantiated `%1%' -> `%2%'") printMsg(lvlChatty, format("instantiated `%1%' -> `%2%'")
% drvName % drvPath); % drvName % drvPath);
attrs.set("outPath", makeAttrRHS(makePath(string2ATerm(outPath.c_str())), makeNoPos())); attrs.set("outPath", makeAttrRHS(makePath(toATerm(outPath)), makeNoPos()));
attrs.set("drvPath", makeAttrRHS(makePath(string2ATerm(drvPath.c_str())), makeNoPos())); attrs.set("drvPath", makeAttrRHS(makePath(toATerm(drvPath)), makeNoPos()));
attrs.set("drvHash", attrs.set("drvHash",
makeAttrRHS(makeStr(string2ATerm(((string) drvHash).c_str())), makeNoPos())); makeAttrRHS(makeStr(toATerm((string) drvHash)), makeNoPos()));
attrs.set("type", makeAttrRHS(makeStr(string2ATerm("derivation")), makeNoPos())); attrs.set("type", makeAttrRHS(makeStr(toATerm("derivation")), makeNoPos()));
return makeAttrs(attrs); return makeAttrs(attrs);
} }
@ -283,7 +283,7 @@ static Expr primDerivation(EvalState & state, const ATermVector & _args)
following the last slash. */ following the last slash. */
static Expr primBaseNameOf(EvalState & state, const ATermVector & args) 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; ATermList l = ATempty;
for (PathSet::const_iterator i = paths.begin(); for (PathSet::const_iterator i = paths.begin();
i != paths.end(); i++) i != paths.end(); i++)
l = ATinsert(l, string2ATerm(i->c_str())); l = ATinsert(l, toATerm(*i));
return ATreverse(l); return ATreverse(l);
} }
@ -156,7 +156,7 @@ static ATerm unparseClosure(const Closure & closure)
i != closure.elems.end(); i++) i != closure.elems.end(); i++)
elems = ATinsert(elems, elems = ATinsert(elems,
makeClosureElem( makeClosureElem(
string2ATerm(i->first.c_str()), toATerm(i->first),
unparsePaths(i->second.refs))); unparsePaths(i->second.refs)));
return makeClosure(roots, elems); return makeClosure(roots, elems);
@ -168,21 +168,21 @@ static ATerm unparseDerivation(const Derivation & derivation)
ATermList args = ATempty; ATermList args = ATempty;
for (Strings::const_iterator i = derivation.args.begin(); for (Strings::const_iterator i = derivation.args.begin();
i != derivation.args.end(); i++) i != derivation.args.end(); i++)
args = ATinsert(args, string2ATerm(i->c_str())); args = ATinsert(args, toATerm(*i));
ATermList env = ATempty; ATermList env = ATempty;
for (StringPairs::const_iterator i = derivation.env.begin(); for (StringPairs::const_iterator i = derivation.env.begin();
i != derivation.env.end(); i++) i != derivation.env.end(); i++)
env = ATinsert(env, env = ATinsert(env,
makeEnvBinding( makeEnvBinding(
string2ATerm(i->first.c_str()), toATerm(i->first),
string2ATerm(i->second.c_str()))); toATerm(i->second)));
return makeDerive( return makeDerive(
unparsePaths(derivation.outputs), unparsePaths(derivation.outputs),
unparsePaths(derivation.inputs), unparsePaths(derivation.inputs),
string2ATerm(derivation.platform.c_str()), toATerm(derivation.platform),
string2ATerm(derivation.builder.c_str()), toATerm(derivation.builder),
ATreverse(args), ATreverse(args),
ATreverse(env)); 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); 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); Error badTerm(const format & f, ATerm t);
/* Convert strings to ATerms. */
ATerm toATerm(const char * s);
ATerm toATerm(const string & s);
#endif /* !__ATERM_H */ #endif /* !__ATERM_H */

View File

@ -192,18 +192,18 @@ void createUserEnv(EvalState & state, const DrvInfos & drvs,
i != drvs.end(); ++i) i != drvs.end(); ++i)
{ {
ATerm t = makeAttrs(ATmakeList6( ATerm t = makeAttrs(ATmakeList6(
makeBind(string2ATerm("type"), makeBind(toATerm("type"),
makeStr(string2ATerm("derivation")), makeNoPos()), makeStr(toATerm("derivation")), makeNoPos()),
makeBind(string2ATerm("name"), makeBind(toATerm("name"),
makeStr(string2ATerm(i->second.name.c_str())), makeNoPos()), makeStr(toATerm(i->second.name)), makeNoPos()),
makeBind(string2ATerm("system"), makeBind(toATerm("system"),
makeStr(string2ATerm(i->second.system.c_str())), makeNoPos()), makeStr(toATerm(i->second.system)), makeNoPos()),
makeBind(string2ATerm("drvPath"), makeBind(toATerm("drvPath"),
makePath(string2ATerm(i->second.drvPath.c_str())), makeNoPos()), makePath(toATerm(i->second.drvPath)), makeNoPos()),
makeBind(string2ATerm("drvHash"), makeBind(toATerm("drvHash"),
makeStr(string2ATerm(((string) i->second.drvHash).c_str())), makeNoPos()), makeStr(toATerm((string) i->second.drvHash)), makeNoPos()),
makeBind(string2ATerm("outPath"), makeBind(toATerm("outPath"),
makePath(string2ATerm(i->second.outPath.c_str())), makeNoPos()) makePath(toATerm(i->second.outPath)), makeNoPos())
)); ));
inputs = ATinsert(inputs, t); inputs = ATinsert(inputs, t);
} }
@ -215,11 +215,11 @@ void createUserEnv(EvalState & state, const DrvInfos & drvs,
Path inputsFile = writeTerm(inputs2, "-env-inputs"); Path inputsFile = writeTerm(inputs2, "-env-inputs");
Expr topLevel = makeCall(envBuilder, makeAttrs(ATmakeList3( Expr topLevel = makeCall(envBuilder, makeAttrs(ATmakeList3(
makeBind(string2ATerm("system"), makeBind(toATerm("system"),
makeStr(string2ATerm(thisSystem.c_str())), makeNoPos()), makeStr(toATerm(thisSystem)), makeNoPos()),
makeBind(string2ATerm("derivations"), inputs2, makeNoPos()), makeBind(toATerm("derivations"), inputs2, makeNoPos()),
makeBind(string2ATerm("manifest"), makeBind(toATerm("manifest"),
makePath(string2ATerm(inputsFile.c_str())), makeNoPos()) makePath(toATerm(inputsFile)), makeNoPos())
))); )));
/* Instantiate it. */ /* Instantiate it. */