Skip to content

Commit c3a919f

Browse files
committed
Move value_t to parsetype code.
FIXME: need to clean up parsing/error code.
1 parent 9164986 commit c3a919f

File tree

3 files changed

+72
-59
lines changed

3 files changed

+72
-59
lines changed

libchecktestdata.cc

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -35,51 +35,10 @@ using namespace std;
3535

3636
namespace checktestdata {
3737

38-
struct none_t {};
39-
ostream& operator<<(ostream& os, const none_t&) {
40-
return os << "<no value>";
41-
}
42-
43-
struct value_t {
44-
boost::variant<none_t, mpz_class, mpf_class, string> val;
45-
46-
value_t(): val(none_t()) {}
47-
explicit value_t(mpz_class x): val(x) {}
48-
explicit value_t(mpf_class x): val(x) {}
49-
explicit value_t(string x): val(x) {}
50-
51-
operator mpz_class() const;
52-
operator mpf_class() const;
53-
54-
// This is a member function instead of a casting operator, since
55-
// otherwise the string could be used in other implicit casts.
56-
string getstr() const;
57-
58-
// This converts any value type to a string representation.
59-
string tostr() const;
60-
};
61-
62-
const int value_none = 0;
63-
const int value_int = 1;
64-
const int value_float = 2;
65-
const int value_string = 3;
66-
6738
class doesnt_match_exception {};
6839
class eof_found_exception {};
6940
class generate_exception {};
7041

71-
ostream& operator <<(ostream &os, const value_t &val)
72-
{
73-
return os << val.val;
74-
}
75-
76-
string value_t::tostr() const
77-
{
78-
stringstream ss;
79-
ss << *this;
80-
return ss.str();
81-
}
82-
8342
const int display_before_error = 65;
8443
const int display_after_error = 50;
8544

@@ -232,24 +191,6 @@ long string2int(string s)
232191
return res;
233192
}
234193

235-
value_t::operator mpz_class() const
236-
{
237-
return boost::get<mpz_class>(val);
238-
}
239-
240-
value_t::operator mpf_class() const
241-
{
242-
if(const mpz_class* p = boost::get<mpz_class>(&val))
243-
return *p;
244-
return boost::get<mpf_class>(val);
245-
}
246-
247-
string value_t::getstr() const
248-
{
249-
if ( val.which()!=value_string ) error("value is not a string");
250-
return boost::get<string>(val);
251-
}
252-
253194
value_t eval(const expr&); // forward declaration
254195

255196
value_t getvar(const expr& var, int use_preset = 0)

parsetype.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,40 @@ std::ostream &operator<<(std::ostream &out, const parse_t &obj)
5353
}
5454
return out;
5555
}
56+
57+
namespace checktestdata {
58+
59+
std::ostream& operator<<(std::ostream& os, const none_t&) {
60+
return os << "<no value>";
61+
}
62+
63+
value_t::operator mpz_class() const
64+
{
65+
return boost::get<mpz_class>(val);
66+
}
67+
68+
value_t::operator mpf_class() const
69+
{
70+
if(const mpz_class* p = boost::get<mpz_class>(&val))
71+
return *p;
72+
return boost::get<mpf_class>(val);
73+
}
74+
75+
std::ostream& operator <<(std::ostream &os, const value_t &val)
76+
{
77+
return os << val.val;
78+
}
79+
80+
std::string value_t::getstr() const
81+
{
82+
return boost::get<std::string>(val);
83+
}
84+
85+
std::string value_t::tostr() const
86+
{
87+
std::stringstream ss;
88+
ss << *this;
89+
return ss.str();
90+
}
91+
92+
} // namespace checktestdata

parsetype.hpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include <string>
55
#include <vector>
66
#include <iostream>
7+
#include <sstream>
8+
#include <boost/variant.hpp>
9+
#include <gmpxx.h>
710

811
struct parse_t;
912

@@ -14,6 +17,38 @@ typedef parse_t command;
1417
typedef parse_t expr;
1518
typedef parse_t test;
1619

20+
namespace checktestdata {
21+
22+
struct none_t {};
23+
24+
std::ostream& operator<<(std::ostream&, const none_t&);
25+
26+
struct value_t {
27+
boost::variant<none_t, mpz_class, mpf_class, std::string> val;
28+
29+
value_t(): val(none_t()) {}
30+
explicit value_t(mpz_class x): val(x) {}
31+
explicit value_t(mpf_class x): val(x) {}
32+
explicit value_t(std::string x): val(x) {}
33+
34+
operator mpz_class() const;
35+
operator mpf_class() const;
36+
37+
// This is a member function instead of a casting operator, since
38+
// otherwise the string could be used in other implicit casts.
39+
std::string getstr() const;
40+
41+
// This converts any value type to a string representation.
42+
std::string tostr() const;
43+
};
44+
45+
const int value_none = 0;
46+
const int value_int = 1;
47+
const int value_float = 2;
48+
const int value_string = 3;
49+
50+
} // namespace checktestdata
51+
1752
std::ostream &operator<<(std::ostream &, const parse_t &);
1853

1954
struct parse_t {

0 commit comments

Comments
 (0)