fixes to strings in generic usuage
[official-gcc.git] / gcc / python / py-decl.c
blob8d08fbec7b91b804f65f803adb0e9cb5eedd849a
1 /* This file is part of GCC.
3 GCC is free software; you can redistribute it and/or modify it under
4 the terms of the GNU General Public License as published by the Free
5 Software Foundation; either version 3, or (at your option) any later
6 version.
8 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
9 WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 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 "config.h"
18 #include "system.h"
19 #include "ansidecl.h"
20 #include "coretypes.h"
21 #include "opts.h"
22 #include "tree.h"
23 #include "gimple.h"
24 #include "toplev.h"
25 #include "debug.h"
26 #include "options.h"
27 #include "flags.h"
28 #include "convert.h"
29 #include "diagnostic-core.h"
30 #include "langhooks.h"
31 #include "langhooks-def.h"
32 #include "target.h"
34 #include <gmp.h>
35 #include <mpfr.h>
37 #include "vec.h"
38 #include "hashtab.h"
40 #include "gpython.h"
41 #include "py-dot-codes.def"
42 #include "py-dot.h"
43 #include "py-vec.h"
44 #include "py-tree.h"
45 #include "py-types.h"
46 #include "py-runtime.h"
48 VEC(tree,gc) * gpy_fold_primitive (const gpy_symbol_obj * const sym)
50 VEC(tree,gc) * retval = VEC_alloc(tree,gc,0);
51 switch( sym->op_a_t )
53 case TYPE_INTEGER:
55 tree address = build_decl (sym->loc, VAR_DECL, create_tmp_var_name("P"),
56 gpy_object_type_ptr);
57 VEC_safe_push (tree, gc, retval,
58 build2 (MODIFY_EXPR, gpy_object_type_ptr,
59 address, gpy_builtin_get_fold_int_call (sym->op_a.integer))
61 VEC_safe_push (tree, gc, retval, address);
63 break;
65 default:
66 fatal_error("invalid primitive type <0x%x>!\n", sym->op_a_t );
67 break;
70 return retval;
73 VEC(tree,gc) * gpy_fold_call (tree decl, location_t l)
75 VEC(tree,gc) * retval = VEC_alloc(tree,gc,0);
77 return retval;
80 VEC(tree,gc) * gpy_process_assign (gpy_symbol_obj ** op_a, gpy_symbol_obj ** op_b,
81 VEC(gpy_ctx_t,gc) * context)
83 VEC(tree,gc) * retval = NULL;
84 gpy_symbol_obj *opa, *opb;
86 if( op_a && op_b ) { opa= *op_a; opb= *op_b; }
87 else {
88 fatal_error("operands A or B are undefined!\n");
89 return NULL;
92 if( opa->type == SYMBOL_REFERENCE )
94 int l = (VEC_length( gpy_ctx_t, context));
95 VEC(tree,gc) * rhs_tree_vec = NULL;
97 tree decl = gpy_ctx_lookup_decl (context, opa->op_a.string);
99 if (!decl)
101 gpy_ctx_t x = VEC_index (gpy_ctx_t, context, (l-1));
103 decl = build_decl (opa->loc, VAR_DECL,
104 get_identifier (opa->op_a.string),
105 gpy_object_type_ptr);
107 if (!gpy_ctx_push_decl (decl, opa->op_a.string, x))
108 fatal_error("error pushing var decl <%s>!\n", opa->op_a.string );
111 rhs_tree_vec = gpy_process_expression (opb, context);
112 tree rhs_tree_res_decl = VEC_pop (tree, rhs_tree_vec);
114 retval = rhs_tree_vec;
116 VEC_safe_push (tree, gc, retval, build2 (MODIFY_EXPR, gpy_object_type_ptr,
117 decl,rhs_tree_res_decl));
118 VEC_safe_push (tree, gc, retval, gpy_builtin_get_incr_ref_call (decl));
119 VEC_safe_push (tree, gc, retval, gpy_builtin_get_set_decl_call (decl));
120 VEC_safe_push (tree, gc, retval, decl);
123 else
124 fatal_error("Invalid accessor for assignment <0x%x>!\n", opa->type );
126 return retval;
129 VEC(tree,gc) *
130 gpy_process_bin_expression (gpy_symbol_obj ** op_a, gpy_symbol_obj ** op_b,
131 gpy_opcode_t operation, VEC(gpy_ctx_t,gc) * context)
133 VEC(tree,gc) * retval = NULL;
134 VEC(tree,gc) * t1 = NULL, * t2 = NULL;
136 tree op = NULL;
137 gpy_symbol_obj *opa, *opb;
138 if( op_a && op_b ) { opa= *op_a; opb= *op_b; }
139 else {
140 fatal_error("operands A or B are undefined!\n");
141 return NULL;
144 t1 = gpy_process_expression (opa, context);
145 t2 = gpy_process_expression (opb, context);
147 tree t1_res_decl = VEC_pop (tree, t1);
148 tree t2_res_decl = VEC_pop (tree, t2);
150 switch (operation)
152 case OP_BIN_ADDITION:
153 op = gpy_builtin_get_eval_expression_call (t1_res_decl, t2_res_decl,
154 operation);
155 break;
157 default:
158 fatal_error("unhandled symbol type <0x%x>!\n", operation);
159 break;
162 if( op )
164 retval = t2;
166 int idx = 0; tree itx = NULL_TREE;
167 for ( ; VEC_iterate(tree,t1,idx,itx); ++idx )
169 VEC_safe_push (tree,gc,retval,itx);
172 tree address = build_decl (opa->loc, VAR_DECL, create_tmp_var_name("T"),
173 gpy_object_type_ptr);
174 VEC_safe_push (tree, gc, retval,
175 build2 (MODIFY_EXPR, gpy_object_type_ptr, address, op));
177 VEC_safe_push (tree,gc,retval,address);
180 return retval;