1 : #include "aterm.hh"
2 :
3 : #include <cstring>
4 :
5 : using std::string;
6 :
7 :
8 601 : string nix::atPrint(ATerm t)
9 : {
10 601 : if (!t) throw Error("attempt to print null aterm");
11 601 : char * s = ATwriteToString(t);
12 601 : if (!s) throw Error("cannot print term");
13 601 : return s;
14 : }
15 :
16 :
17 37 : std::ostream & operator << (std::ostream & stream, ATerm e)
18 : {
19 37 : return stream << nix::atPrint(e);
20 : }
21 :
22 :
23 0 : nix::Error nix::badTerm(const format & f, ATerm t)
24 : {
25 0 : char * s = ATwriteToString(t);
26 0 : if (!s) throw Error("cannot print term");
27 0 : if (strlen(s) > 1000) {
28 : int len;
29 0 : s = ATwriteToSharedString(t, &len);
30 0 : if (!s) throw Error("cannot print term");
31 : }
32 0 : return Error(format("%1%, in `%2%'") % f.str() % (string) s);
33 : }
34 :
35 :
36 42914 : ATerm nix::toATerm(const char * s)
37 : {
38 42914 : return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s, 0, ATtrue));
39 : }
40 :
41 :
42 32305 : ATerm nix::toATerm(const string & s)
43 : {
44 32305 : return toATerm(s.c_str());
45 : }
46 :
47 :
48 1974 : ATermList nix::toATermList(const StringSet & ss)
49 : {
50 1974 : ATermList l = ATempty;
51 3296 : for (StringSet::const_reverse_iterator i = ss.rbegin();
52 : i != ss.rend(); ++i)
53 1322 : l = ATinsert(l, toATerm(*i));
54 1974 : return l;
55 : }
|