Added the class and the scope operator to the intermediary representation
[fridhskrift.git] / fridh / variable.hpp
blobe9fe01ee9fb34f95266a0dabb430b459d3880bc1
1 #include <string>
2 #include <vector>
3 #include <map>
4 #include <ail/types.hpp>
6 namespace fridh
8 namespace variable_type_identifier
10 enum variable_type
12 undefined,
13 nil,
14 none,
15 boolean,
16 signed_integer,
17 unsigned_integer,
18 floating_point_value,
19 string,
20 array,
21 map,
22 function,
23 object
28 class variable;
30 typedef variable_type_identifier::variable_type variable_type;
32 struct unary_argument
34 variable & output;
35 std::string & error_message;
37 unary_argument(variable & output, std::string & error_message);
40 struct binary_argument
42 variable const & other;
43 variable & output;
44 std::string & error_message;
46 binary_argument(variable const & other, variable & output, std::string & error_message);
49 class variable;
51 namespace types
53 typedef bool boolean;
54 typedef word signed_integer;
55 typedef uword unsigned_integer;
56 typedef double floating_point_value;
57 typedef std::string string;
58 typedef std::vector<variable> vector;
59 typedef std::map<variable, variable> map;
62 class variable
64 public:
65 variable();
66 variable(variable const & other);
67 ~variable();
69 variable_type get_type() const;
71 void nil();
72 void none();
73 void new_boolean(types::boolean new_boolean);
74 void new_signed_integer(types::signed_integer new_signed_integer);
75 void new_unsigned_integer(types::unsigned_integer new_unsigned_integer);
76 void new_floating_point_value(types::floating_point_value new_floating_point_value);
77 void new_string(types::string const & new_string);
78 void new_array();
79 void new_map();
81 bool addition(binary_argument & argument) const;
82 bool subtraction(binary_argument & argument) const;
83 bool multiplication(binary_argument & argument) const;
84 bool division(binary_argument & argument) const;
85 bool modulo(binary_argument & argument) const;
87 bool negative(unary_argument & argument) const;
89 bool less_than(binary_argument & argument) const;
90 bool less_than_or_equal(binary_argument & argument) const;
91 bool greater_than(binary_argument & argument) const;
92 bool greater_than_or_equal(binary_argument & argument) const;
93 bool unequal(binary_argument & argument) const;
94 bool equal(binary_argument & argument) const;
96 bool logical_not(unary_argument & argument) const;
98 bool logical_and(binary_argument & argument) const;
99 bool logical_or(binary_argument & argument) const;
101 bool shift_left(binary_argument & argument) const;
102 bool shift_right(binary_argument & argument) const;
104 bool binary_and(binary_argument & argument) const;
105 bool binary_or(binary_argument & argument) const;
106 bool binary_xor(binary_argument & argument) const;
108 bool binary_not(unary_argument & argument) const;
110 bool operator==(variable const & other) const;
111 bool operator!=(variable const & other) const;
112 bool operator<(variable const & other) const;
114 private:
115 union
117 types::boolean boolean;
118 types::signed_integer signed_integer;
119 types::unsigned_integer unsigned_integer;
120 types::floating_point_value floating_point_value;
121 types::string * string;
122 types::vector * array;
123 types::map * map;
124 function * function_pointer;
125 void * hash_pointer;
128 variable_type type;
130 bool is_floating_point_operation(binary_argument & argument) const;
131 bool is_integer_type() const;
132 bool is_numeric_type() const;
133 bool is_zero() const;
135 types::floating_point_value get_floating_point_value() const;
136 bool get_string_representation(std::string & output) const;
137 bool get_boolean_value(bool & output) const;
139 bool array_addition(binary_argument & argument) const;
140 bool perform_string_conversion(std::string & output, bool & error) const;
141 bool string_addition(binary_argument & argument, bool & error) const;
143 bool array_equality(variable const & other) const;
144 bool map_equality(variable const & other) const;
146 uword array_hash(uword previous_hash) const;
147 uword map_hash(uword previous_hash) const;
148 uword hash(uword previous_hash = 0) const;
151 std::string get_type_string(variable_type type);
152 std::string get_unary_argument_type_error(std::string const & operation, variable_type type);
153 std::string get_binary_argument_type_error(std::string const & operation, variable_type left, variable_type right);