diff options
author | pacien | 2018-06-05 22:41:15 +0200 |
---|---|---|
committer | pacien | 2018-06-05 22:41:15 +0200 |
commit | 0f4b1600983f8afda41a02fec07424338785d81d (patch) | |
tree | cd1a3b2f599f7242c9fe76f9d66ca95ba58e34c0 /src/symbol_table.c | |
parent | 864653f00dff0a8a1f37d8e9a732c1da8309a930 (diff) | |
download | tpc-compiler-0f4b1600983f8afda41a02fec07424338785d81d.tar.gz |
Prevent assigning to const
Diffstat (limited to 'src/symbol_table.c')
-rw-r--r-- | src/symbol_table.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/symbol_table.c b/src/symbol_table.c index 08124ac..68e24f0 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c | |||
@@ -228,3 +228,23 @@ void check_expected_type(int type_to_check, int type_expected) { | |||
228 | string_of_type(type_expected), string_of_type(type_to_check), | 228 | string_of_type(type_expected), string_of_type(type_to_check), |
229 | lineno); | 229 | lineno); |
230 | } | 230 | } |
231 | |||
232 | /* returns false if symbol can't be found too */ | ||
233 | bool is_read_only(const char name[], Scope scope) { | ||
234 | int count; | ||
235 | |||
236 | switch (scope) { | ||
237 | case LOCAL: | ||
238 | for (count = 0; count < loc_symbol_table.size; count++) | ||
239 | if (!strcmp(loc_symbol_table.entries[count].name, name)) | ||
240 | return loc_symbol_table.entries[count].read_only; | ||
241 | |||
242 | case GLOBAL: | ||
243 | for (count = 0; count < glo_symbol_table.size; count++) | ||
244 | if (!strcmp(glo_symbol_table.entries[count].name, name)) | ||
245 | return glo_symbol_table.entries[count].read_only; | ||
246 | |||
247 | default: | ||
248 | return false; | ||
249 | } | ||
250 | } | ||