2
Clif - A C-like Interpreter Framework
3
Copyright (C) 1998, 2000 L. Koren
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35
#include "comp_maint.h"
40
/* Lookup in tables of local variables, if the variable is not found
41
in the table of global variables. Setting of addresses for code
44
lookup_tables (var_name, variable)
46
struct var_s variable[];
48
struct ident_tab_loc *loc_var;
49
if (NULL == (loc_var = point_loc (var_name)))
51
struct ident_tab *var;
52
var = point (var_name);
55
if ((STRUCT_P(var->type)
56
|| UNION_P(var->type))
57
&& -1 == add_to_ident_list ())
59
variable[++set].adr = var->adr;
60
variable[set].name = var_name;
61
variable[set].offset = 0;
62
type_com[set] = var->type;
66
/* Address is non NULL only if the
67
local variable is declared static. */
68
if (NULL != loc_var->adr)
70
variable[set].offset = 0;
71
variable[set].adr = loc_var->adr;
72
variable[set].name = var_name;
76
/* First part of the offset is set in the
77
point_loc function. */
78
variable[set].offset += loc_var->offset;
79
variable[set].adr = NULL;
80
variable[set].name = var_name;
82
type_com[set] = loc_var->type;
84
if (NULL == type_com[set]->output)
85
type_ac[set] = type_com[set]->attribute.arit_class;
86
else if (LOCAL_P(type_com[set])
87
|| REMOTE_P(type_com[set]))
90
type_com[set]->output->attribute.arit_class;
91
proc_name_text[++proc] = text;
93
else if (ARRAY_P(type_com[set]))
96
type_com[set]->output->attribute.arit_class;
97
array_subscript (type_com[set]->input);
99
else if (POINTER_P(type_com[set]))
100
type_ac[set] = LONG_AC | INTEGER;
102
if (0 < variable[set].offset)
106
if (ARRAY_P(type_com[set]))
108
GEN_PUSHArr(variable[set].offset);
112
GEN_PUSHAr(variable[set].offset);
115
else if (call_by_reference)
117
GEN_PUSHArr(variable[set].offset);
121
else if (0 > variable[set].offset)
123
GEN_PUSHAr(variable[set].offset); GENCODE;
125
else if (! LOCAL_P(type_com[set])
126
&& ! REMOTE_P(type_com[set]))
128
GEN_PUSHA(variable[set].adr); GENCODE;
133
/* The typedef structure (only the beginning part) is copied, if
134
any non simple part was inserted, i.e. pointer, function, array,
138
struct internal_type *type;
140
typeh[type_spec_count] = (struct internal_type *)
141
allocate (sizeof(struct internal_type),
142
scope_level > PERM ? BLOCK : PERM);
143
init_zero ((char *)typeh[type_spec_count],
144
sizeof(struct internal_type));
145
typeh[type_spec_count]->attribute.function_class =
147
typeh[type_spec_count]->attribute.type_qualifier =
149
typeh[type_spec_count]->attribute.arit_class =
151
typeh[type_spec_count]->attribute.storage_class_specifier =
153
typeh[type_spec_count]->output = type;
157
/* For cast operator, size of operand is returned. */
159
set_memory_size (arit_class)
160
enum intern_arit_class arit_class;
165
case SIGNED_AC | INTEGER:
167
case UNSIGNED_AC | INTEGER:
168
return sizeof (unsigned int);
169
case LONG_AC | INTEGER:
170
case LONG_AC | SIGNED_AC | INTEGER:
171
return sizeof (long int);
172
case SHORT_AC | INTEGER:
173
case SHORT_AC | SIGNED_AC | INTEGER:
174
return sizeof (short int);
175
case LONG_AC | UNSIGNED_AC | INTEGER:
176
return sizeof (long unsigned int);
177
case SHORT_AC | UNSIGNED_AC | INTEGER:
178
return sizeof (short unsigned int);
180
return sizeof (double);
182
return sizeof (long double);
184
return sizeof (float);
186
/* Moze byt este problem so zarovnanim */
187
return sizeof (char);
188
case SIGNED_AC | CHR:
189
return sizeof (signed char);
190
case UNSIGNED_AC | CHR:
191
return sizeof (unsigned char);