GCC Rust: Parsing in floats now
[official-gcc.git] / gcc / rust / rdot-impl.cc
blobbe4421b52a1b36aa7e993bddd6df77b9c76bdac9
1 /* This file is part of GCC.
3 GCC is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 3, or (at your option)
6 any later version.
8 GCC is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with GCC; see the file COPYING3. If not see
15 <http://www.gnu.org/licenses/>. */
17 #include "rust.h"
19 static bool initilized = false;
21 static const char * opcodeStrings [] = {
22 /* [D_IDENTIFIER] */ "identifier",
23 /* [D_T_INTEGER] */ "literal_integer",
24 /* [D_T_FLOAT] */ "literal_float",
25 /* [D_T_STRING] */ "literal_string",
26 /* [D_T_LIST] */ "liteal_list",
27 /* [D_VAR_DECL] */ "var_decl",
28 /* [D_MODIFY_EXPR] */ "modify_expr",
29 /* [D_MULT_EXPR] */ "multiply_expr",
30 /* [D_DIVD_EXPR] */ "divide_expr",
31 /* [D_ADD_EXPR] */ "plus_expr",
32 /* [D_MINUS_EXPR] */ "minus_expr",
33 /* [D_EQ_EQ_EXPR] */ "equivilant_expr",
34 /* [D_LESS_EXPR] */ "less_than_expr",
35 /* [D_LESS_EQ_EXPR] */ "less_eq_expr",
36 /* [D_GREATER_EXPR] */ "greater_expr",
37 /* [D_GREATER_EQ_EXPR] */ "greater_eq_expr",
38 /* [D_NOT_EQ_EXPR] */ "not_equal_expr",
39 /* [D_CALL_EXPR] */ "call_expr",
40 /* [D_ATTRIB_EXPR] */ "attribute_reference",
41 /* [D_ACC_EXPR] */ "accessor_reference",
42 /* [D_STRUCT_METHOD] */ "struct_method",
43 /* [D_STRUCT_WHILE] */ "struct_while",
44 /* [D_STRUCT_LOOP] */ "struct_loop",
45 /* [D_D_EXPR] */ "enc_expression",
46 /* [D_TD_COM] */ "TD_COM",
47 /* [D_TD_DOT] */ "TD_DOT",
48 /* [D_TD_NULL] */ "TD_NULL",
49 /* [D_PRIMITIVE] */ "primitive",
50 /* [D_STRUCT_IF] */ "struct_if",
51 /* [D_STRUCT_ELIF] */ "struct_elif",
52 /* [D_STRUCT_ELSE] */ "struct_else",
53 /* [D_STRUCT_CONDITIONAL] */ "struct_conditional",
54 /* [RTYPE_BOOL] */ "type_bool",
55 /* [RTYPE_INT] */ "type_int",
56 /* [RTYPE_FLOAT] */ "type_float",
57 /* [RTYPE_UINT] */ "type_uint",
58 /* [RTYPE_INFER] */ "type_infer",
59 /* [D_PARAMETER] */ "parameter",
60 /* [D_STRUCT_TYPE] */ "struct_definition",
61 /* [D_STRUCT_PARAM] */ "struct_init_param",
62 /* [D_STRUCT_INIT] */ "struct_initilization",
63 /* [RTYPE_USER_STRUCT] */ "user_struct_type",
64 /* [D_STRUCT_ENUM] */ "struct_enum",
65 /* [D_STRUCT_IMPL] */ "impl_block",
66 /* [D_BOOLEAN] */ "d_boolean",
67 /* [D_T_BOOL] */ "d_t_bool",
68 /* [C_BREAK_STMT] */ "break_stmt",
69 /* [C_CONT_STMT] */ "continue_stmt",
70 /* [C_RETURN_STMT] */ "return_stmt",
73 const char *
74 rdot_getOpString_T (const opcode_t o)
76 return opcodeStrings [o];
79 const char *
80 rdot_getOpString (const rdot dot)
82 return rdot_getOpString_T (RDOT_TYPE (dot));
85 void rdot_init (void)
87 if (initilized)
88 return;
89 //... probably should get rid of this function ...
90 initilized = true;
93 rdot rdot_build_varDecl (rdot type, bool final, rdot id)
95 rdot decl = rdot_build_decl2 (D_VAR_DECL, id, type);
96 RDOT_qual (decl) = final;
97 return decl;
100 rdot rdot_alloc (void)
102 rdot retval = (struct grs_tree_dot *)
103 xmalloc (sizeof (struct grs_tree_dot));
104 gcc_assert (retval);
105 memset (retval, 0, sizeof (struct grs_tree_dot));
106 RDOT_LOCATION (retval) = UNKNOWN_LOCATION;
107 return retval;
110 rdot rdot_build_decl1 (opcode_t o, rdot t1)
112 rdot decl = RDOT_alloc;
114 RDOT_TYPE(decl) = o;
115 RDOT_T_FIELD(decl) = D_TD_NULL;
116 RDOT_FIELD(decl) = NULL_DOT;
118 decl->opaT = D_TD_DOT;
119 decl->opa.t = t1;
120 decl->opbT = D_TD_NULL;
122 RDOT_CHAIN(decl) = NULL_DOT;
124 return decl;
127 rdot rdot_build_decl2 (opcode_t o, rdot t1, rdot t2)
129 rdot decl = RDOT_alloc;
131 RDOT_TYPE (decl) = o;
132 if ((o == D_VAR_DECL)
133 || (o == D_MODIFY_EXPR)
134 || (o == D_ADD_EXPR)
135 || (o == D_MINUS_EXPR)
136 || (o == D_MULT_EXPR)
137 || (o == D_DIVD_EXPR)
138 || (o == D_CALL_EXPR)
139 || (o == D_EQ_EQ_EXPR)
140 || (o == D_LESS_EXPR)
141 || (o == D_LESS_EQ_EXPR)
142 || (o == D_GREATER_EXPR)
143 || (o == D_GREATER_EQ_EXPR)
144 || (o == D_NOT_EQ_EXPR)
145 || (o == D_ATTRIB_REF)
146 || (o == D_ACC_EXPR)
147 || (o == D_STRUCT_INIT)
149 RDOT_T_FIELD(decl) = D_D_EXPR;
150 else
151 RDOT_T_FIELD(decl) = D_TD_NULL;
153 RDOT_FIELD (decl) = NULL_DOT;
155 decl->opaT = D_TD_DOT;
156 decl->opa.t = t1;
157 decl->opbT = D_TD_DOT;
158 decl->opb.t = t2;
160 RDOT_CHAIN(decl) = NULL_DOT;
162 return decl;
165 rdot rdot_build_fndecl (rdot ident, bool pub, rdot params, rdot rtype, rdot suite)
167 rdot decl = RDOT_alloc;
169 RDOT_TYPE (decl) = D_STRUCT_METHOD;
170 RDOT_T_FIELD (decl) = D_TD_NULL;
172 RDOT_FIELD (decl) = ident;
173 RDOT_FIELD2 (decl) = rtype;
174 DOT_RETVAL (decl) = pub;
176 decl->opaT = D_TD_DOT;
177 decl->opa.t = params;
178 decl->opbT = D_TD_DOT;
179 decl->opb.t = suite;
181 RDOT_CHAIN(decl) = NULL_DOT;
183 return decl;
186 rdot rdot_build_integer (const int i)
188 rdot decl = RDOT_alloc;
189 RDOT_TYPE(decl) = D_PRIMITIVE;
191 RDOT_FIELD(decl) = NULL_DOT;
192 RDOT_T_FIELD(decl) = D_D_EXPR;
194 decl->opaT = D_TD_COM;
195 decl->opa.tc.T = D_T_INTEGER;
196 decl->opa.tc.o.integer = i;
198 return decl;
201 rdot rdot_build_float (const float f)
203 rdot decl = RDOT_alloc;
204 RDOT_TYPE(decl) = D_PRIMITIVE;
206 RDOT_FIELD(decl) = NULL_DOT;
207 RDOT_T_FIELD(decl) = D_D_EXPR;
209 decl->opaT = D_TD_COM;
210 decl->opa.tc.T = D_T_FLOAT;
211 decl->opa.tc.o.ffloat = f;
213 return decl;
216 rdot rdot_build_string (const char * s)
218 rdot decl = RDOT_alloc;
219 RDOT_TYPE (decl) = D_PRIMITIVE;
221 RDOT_FIELD (decl) = NULL_DOT;
222 RDOT_T_FIELD (decl) = D_D_EXPR;
224 decl->opaT = D_TD_COM;
225 decl->opa.tc.T = D_T_STRING;
226 decl->opa.tc.o.string = xstrdup (s);
228 return decl;
231 rdot rdot_build_identifier (const char * s)
233 rdot decl = RDOT_alloc;
235 RDOT_TYPE(decl) = D_IDENTIFIER;
236 RDOT_FIELD(decl) = NULL_DOT;
237 RDOT_T_FIELD(decl) = D_D_EXPR;
239 decl->opaT = D_TD_COM;
240 decl->opa.tc.T = D_T_STRING;
241 decl->opa.tc.o.string = xstrdup (s);
243 decl->opbT = D_TD_NULL;
245 RDOT_CHAIN(decl) = NULL_DOT;
247 return decl;
250 rdot rdot_build_bool (bool val)
252 rdot decl = RDOT_alloc;
254 RDOT_TYPE(decl) = D_BOOLEAN;
255 RDOT_FIELD(decl) = NULL_DOT;
256 RDOT_T_FIELD(decl) = D_D_EXPR;
258 decl->opaT = D_TD_COM;
259 decl->opa.tc.T = D_T_BOOL;
260 decl->opa.tc.o.boolean = val;
262 decl->opbT = D_TD_NULL;
264 RDOT_CHAIN(decl) = NULL_DOT;
266 return decl;