Fixed the variable code, replacing it with simpler arguments and using exceptions...
[fridhskrift.git] / fridh / variable.hpp
blob304f8e8dd0d67696bc8751c1ccccc013e271bb2b
1 #include <string>
2 #include <vector>
3 #include <map>
4 #include <ail/types.hpp>
5 #include <ail/exceptionh.pp>
7 namespace fridh
9 namespace variable_type_identifier
11 enum variable_type
13 undefined,
14 nil,
15 none,
16 boolean,
17 signed_integer,
18 unsigned_integer,
19 floating_point_value,
20 string,
21 array,
22 map,
23 function,
24 object
29 class variable;
31 typedef variable_type_identifier::variable_type variable_type;
33 class variable;
35 namespace types
37 typedef bool boolean;
38 typedef word signed_integer;
39 typedef uword unsigned_integer;
40 typedef double floating_point_value;
41 typedef std::string string;
42 typedef std::vector<variable> vector;
43 typedef std::map<variable, variable> map;
46 class variable
48 public:
49 variable();
50 variable(variable const & other);
51 ~variable();
53 variable_type get_type() const;
55 void nil();
56 void none();
57 void new_boolean(types::boolean new_boolean);
58 void new_signed_integer(types::signed_integer new_signed_integer);
59 void new_unsigned_integer(types::unsigned_integer new_unsigned_integer);
60 void new_floating_point_value(types::floating_point_value new_floating_point_value);
61 void new_string(types::string const & new_string);
62 void new_array();
63 void new_map();
65 #define DECLARE_UNARY_OPERATOR(name) void name(variable & output) const;
66 #define DECLARE_BINARY_OPERATOR(name) void name(variable const & argument, variable & output) const;
68 DECLARE_BINARY_OPERATOR(addition)
69 DECLARE_BINARY_OPERATOR(subtraction)
70 DECLARE_BINARY_OPERATOR(multiplication)
71 DECLARE_BINARY_OPERATOR(division)
72 DECLARE_BINARY_OPERATOR(modulo)
74 DECLARE_BINARY_OPERATOR(negation)
76 DECLARE_BINARY_OPERATOR(less_than)
77 DECLARE_BINARY_OPERATOR(less_than_or_equal)
78 DECLARE_BINARY_OPERATOR(greater_than)
79 DECLARE_BINARY_OPERATOR(greater_than_or_equal)
80 DECLARE_BINARY_OPERATOR(unequal)
81 DECLARE_BINARY_OPERATOR(equal)
83 DECLARE_UNARY_OPERATOR(logical_not)
85 DECLARE_BINARY_OPERATOR(logical_and)
86 DECLARE_BINARY_OPERATOR(logical_or)
88 DECLARE_BINARY_OPERATOR(shift_left)
89 DECLARE_BINARY_OPERATOR(shift_right)
91 DECLARE_BINARY_OPERATOR(binary_and)
92 DECLARE_BINARY_OPERATOR(binary_or)
93 DECLARE_BINARY_OPERATOR(binary_xor)
95 DECLARE_UNARY_OPERATOR(binary_not)
97 #undef DECLARE_UNARY_OPERATOR
98 #undef DECLARE_BINARY_OPERATOR
100 bool operator==(variable const & other) const;
101 bool operator!=(variable const & other) const;
102 bool operator<(variable const & other) const;
104 private:
105 union
107 types::boolean boolean;
108 types::signed_integer signed_integer;
109 types::unsigned_integer unsigned_integer;
110 types::floating_point_value floating_point_value;
111 types::string * string;
112 types::vector * array;
113 types::map * map;
114 function * function_pointer;
115 void * hash_pointer;
118 variable_type type;
120 bool is_floating_point_operation(variable & argument) const;
121 bool is_integer_type() const;
122 bool is_numeric_type() const;
123 bool is_zero() const;
125 types::floating_point_value get_floating_point_value() const;
126 std::string get_string_representation() const;
127 bool get_boolean_value() const;
129 bool variable::array_addition(variable const & argument) const
130 bool string_addition(variable const & argument, variable & output) const;
132 bool array_equality(variable const & other) const;
133 bool map_equality(variable const & other) const;
135 uword array_hash(uword previous_hash) const;
136 uword map_hash(uword previous_hash) const;
137 uword hash(uword previous_hash = 0) const;
140 std::string get_type_string(variable_type type);
142 void unary_argument_type_error(std::string const & operation, variable_type type);
143 void binary_argument_type_error(std::string const & operation, variable_type left, variable_type right);