File hashtable.c changed (mode: 100644) (index 6fd3bb8..b143313) |
... |
... |
void * ht_lookup(struct hashtable *h, const char *name) |
82 |
82 |
|
|
83 |
83 |
static void resize(struct hashtable *h) |
static void resize(struct hashtable *h) |
84 |
84 |
{ |
{ |
85 |
|
struct hashtable new; |
|
86 |
|
ht_init(&new, h->size*2 +1); |
|
|
85 |
|
struct hashtable newht; |
|
86 |
|
ht_init(&newht, h->size*2 +1); |
87 |
87 |
size_t i; |
size_t i; |
88 |
88 |
for(i = 0; i != h->size; i++){ |
for(i = 0; i != h->size; i++){ |
89 |
89 |
if(h->bucket[i].name){ |
if(h->bucket[i].name){ |
90 |
|
ht_put(&new, h->bucket[i].name, h->bucket[i].val); |
|
|
90 |
|
ht_put(&newht, h->bucket[i].name, h->bucket[i].val); |
91 |
91 |
} |
} |
92 |
92 |
} |
} |
93 |
93 |
free(h->bucket); |
free(h->bucket); |
94 |
|
h->bucket = new.bucket; |
|
95 |
|
h->size = new.size; |
|
96 |
|
h->count = new.count; |
|
|
94 |
|
h->bucket = newht.bucket; |
|
95 |
|
h->size = newht.size; |
|
96 |
|
h->count = newht.count; |
97 |
97 |
} |
} |
98 |
98 |
|
|
99 |
99 |
bool ht_put(struct hashtable *h, const char *name, void *val) |
bool ht_put(struct hashtable *h, const char *name, void *val) |
File misc.c changed (mode: 100644) (index f4721e4..a12bec6) |
... |
... |
const struct typenode *combinetype(const struct typenode *n1, const struct typen |
330 |
330 |
} |
} |
331 |
331 |
|
|
332 |
332 |
// this is used for reducing expressions in many places (if/exitwhen conditions, assignments etc.) |
// this is used for reducing expressions in many places (if/exitwhen conditions, assignments etc.) |
333 |
|
int canconvert(const struct typenode *ufrom, const struct typenode *uto, const int linemod) |
|
|
333 |
|
void canconvert(const struct typenode *ufrom, const struct typenode *uto, const int linemod) |
334 |
334 |
{ |
{ |
335 |
335 |
const struct typenode *from = ufrom, *to = uto; |
const struct typenode *from = ufrom, *to = uto; |
336 |
336 |
char ebuf[1024]; |
char ebuf[1024]; |
337 |
337 |
if (from == NULL || to == NULL) |
if (from == NULL || to == NULL) |
338 |
|
return 0; |
|
|
338 |
|
return; |
339 |
339 |
if (typeeq(from, gAny) || typeeq(to, gAny)) |
if (typeeq(from, gAny) || typeeq(to, gAny)) |
340 |
|
return 1; |
|
|
340 |
|
return; |
341 |
341 |
if (isDerivedFrom(from, to)) |
if (isDerivedFrom(from, to)) |
342 |
|
return 1; |
|
|
342 |
|
return; |
343 |
343 |
if (getTypePtr(from)->typename == NULL || getTypePtr(to)->typename == NULL) |
if (getTypePtr(from)->typename == NULL || getTypePtr(to)->typename == NULL) |
344 |
|
return 0; |
|
|
344 |
|
return; |
345 |
345 |
if (typeeq(from, gNone) || typeeq(to, gNone)) |
if (typeeq(from, gNone) || typeeq(to, gNone)) |
346 |
|
return 0; |
|
|
346 |
|
return; |
347 |
347 |
from = getPrimitiveAncestor(from); |
from = getPrimitiveAncestor(from); |
348 |
348 |
to = getPrimitiveAncestor(to); |
to = getPrimitiveAncestor(to); |
349 |
349 |
if (typeeq(from, gNull) && !typeeq(to, gInteger) && !typeeq(to, gReal) && !typeeq(to, gBoolean)) |
if (typeeq(from, gNull) && !typeeq(to, gInteger) && !typeeq(to, gReal) && !typeeq(to, gBoolean)) |
350 |
|
return 1; |
|
351 |
|
if (strict) { |
|
352 |
|
if (typeeq(ufrom, gInteger) && (typeeq(to, gReal) || typeeq(to, gInteger))) |
|
353 |
|
return 1; |
|
354 |
|
if (typeeq(ufrom, to) && (typeeq(ufrom, gBoolean) || typeeq(ufrom, gString) || typeeq(ufrom, gReal) || typeeq(ufrom, gInteger) || typeeq(ufrom, gCode))) |
|
355 |
|
return 1; |
|
356 |
|
} else { |
|
357 |
|
if (typeeq(from, gInteger) && (typeeq(to, gReal) || typeeq(to, gInteger))) |
|
358 |
|
return 1; |
|
359 |
|
if (typeeq(from, to) && (typeeq(from, gBoolean) || typeeq(from, gString) || typeeq(from, gReal) || typeeq(from, gInteger) || typeeq(from, gCode))) |
|
360 |
|
return 1; |
|
361 |
|
} |
|
|
350 |
|
return; |
|
351 |
|
if (typeeq(from, gInteger) && (typeeq(to, gReal) || typeeq(to, gInteger))) |
|
352 |
|
return; |
|
353 |
|
if (typeeq(from, to) && (typeeq(from, gBoolean) || typeeq(from, gString) || typeeq(from, gReal) || typeeq(from, gInteger) || typeeq(from, gCode))) |
|
354 |
|
return; |
362 |
355 |
|
|
363 |
356 |
snprintf(ebuf, 1024, "Cannot convert %s to %s", ufrom->typename, uto->typename); |
snprintf(ebuf, 1024, "Cannot convert %s to %s", ufrom->typename, uto->typename); |
364 |
357 |
yyerrorline(3, lineno + linemod, ebuf); |
yyerrorline(3, lineno + linemod, ebuf); |
365 |
|
return 0; |
|
|
358 |
|
return; |
366 |
359 |
} |
} |
367 |
360 |
|
|
368 |
361 |
// this is used for return statements only |
// this is used for return statements only |
|
... |
... |
void canconvertreturn(const struct typenode *ufrom, const struct typenode *uto, |
398 |
391 |
if ((typeeq(from, gNull)) && (!typeeq(to, gInteger)) && (!typeeq(to, gReal)) && (!typeeq(to, gBoolean))) |
if ((typeeq(from, gNull)) && (!typeeq(to, gInteger)) && (!typeeq(to, gReal)) && (!typeeq(to, gBoolean))) |
399 |
392 |
return; // can't return null when it expects integer, real or boolean (added 9.5.2005) |
return; // can't return null when it expects integer, real or boolean (added 9.5.2005) |
400 |
393 |
|
|
401 |
|
if (strict) { |
|
402 |
|
if (isDerivedFrom(ufrom, uto)) |
|
403 |
|
return; |
|
404 |
|
} else if (typeeq(ufrom, uto)){ |
|
|
394 |
|
if (typeeq(ufrom, uto)){ |
405 |
395 |
return; |
return; |
406 |
396 |
} |
} |
407 |
397 |
|
|