fixed many errors and cleaned up includes
[official-gcc.git] / gcc / python / py-decl.c
blob884c14a98503584b5185148e84786f5d17f73364
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-runtime.h"
47 VEC(tree,gc) * gpy_fold_primitive( const gpy_symbol_obj * const sym )
49 VEC(tree,gc) * retval = VEC_alloc(tree,gc,0);
50 switch( sym->op_a_t )
52 case TYPE_INTEGER:
53 VEC_safe_push( tree,gc,retval,
54 gpy_builtin_get_fold_int_call( sym->op_a.integer ) );
55 break;
57 default:
58 fatal_error("invalid primitive type <0x%x>!\n", sym->op_a_t );
59 break;
62 return retval;
65 VEC(tree,gc) * gpy_process_assign( gpy_symbol_obj ** op_a, gpy_symbol_obj ** op_b,
66 VEC(gpy_ctx_t,gc) * context )
68 VEC(tree,gc) * retval = NULL;
69 gpy_symbol_obj *opa, *opb;
71 if( op_a && op_b ) { opa= *op_a; opb= *op_b; }
72 else {
73 fatal_error("operands A or B are undefined!\n");
74 return NULL;
77 if( opa->type == SYMBOL_REFERENCE )
79 int l = (VEC_length( gpy_ctx_t, context));
80 VEC(tree,gc) * rhs_tree_vec = NULL; tree rhs_tree = NULL_TREE;
82 tree decl = gpy_ctx_lookup_decl( context, opa->op_a.string, VAR );
84 if( !decl )
86 gpy_ctx_t x = VEC_index( gpy_ctx_t, context, (l-1) );
88 decl = build_decl( opa->loc, VAR_DECL,
89 get_identifier( opa->op_a.string ),
90 build_pointer_type( void_type_node ) );
92 if( !(gpy_ctx_push_decl( decl, opa->op_a.string, x, VAR )) )
93 fatal_error("error pushing var decl <%s>!\n", opa->op_a.string );
96 rhs_tree_vec = gpy_process_expression( opb, context );
97 gcc_assert( VEC_length(tree,rhs_tree_vec) == 1 );
98 rhs_tree = VEC_index(tree,rhs_tree_vec,0);
100 retval = VEC_alloc(tree,gc,0);
102 tree address = build_decl( opa->loc, VAR_DECL, create_tmp_var_name("A"),
103 ptr_type_node );
104 VEC_safe_push( tree, gc, retval, build2( MODIFY_EXPR, ptr_type_node,
105 address, rhs_tree )
107 VEC_safe_push( tree,gc, retval, gpy_builtin_get_incr_ref_call( address ) );
108 VEC_safe_push( tree,gc, retval, build2( MODIFY_EXPR, ptr_type_node, decl, address ) );
110 else
111 fatal_error("Invalid accessor for assignment <0x%x>!\n", opa->type );
113 return retval;
116 VEC(tree,gc) * gpy_process_bin_expression( gpy_symbol_obj ** op_a, gpy_symbol_obj ** op_b,
117 gpy_opcode_t operation, VEC(gpy_ctx_t,gc) * context )
119 VEC(tree,gc) * retval = NULL;
120 VEC(tree,gc) * t1 = NULL, * t2 = NULL;
122 tree op = NULL;
123 gpy_symbol_obj *opa, *opb;
124 if( op_a && op_b ) { opa= *op_a; opb= *op_b; }
125 else {
126 fatal_error("operands A or B are undefined!\n");
127 return NULL;
130 t1 = gpy_process_expression( opa, context );
131 t2 = gpy_process_expression( opb, context );
133 gcc_assert( (VEC_length(tree,t1) == 1) &&
134 (VEC_length(tree,t2) == 1) );
136 tree t1_tree = VEC_index(tree,t1,0);
137 tree t2_tree = VEC_index(tree,t2,0);
139 switch( operation )
141 case OP_BIN_ADDITION:
142 op = gpy_builtin_get_eval_expression_call( t1_tree, t2_tree, operation );
143 break;
145 default:
146 fatal_error("unhandled symbol type <0x%x>!\n", operation);
147 break;
150 if( op )
152 retval = VEC_alloc(tree,gc,0);
153 VEC_safe_push(tree,gc,retval,op);
156 return retval;