File misc.c changed (mode: 100644) (index d7b00b8..54f5583) |
... |
... |
struct funcdecl *newfuncdecl() |
298 |
298 |
|
|
299 |
299 |
const struct typenode *getPrimitiveAncestor(const struct typenode *cur) |
const struct typenode *getPrimitiveAncestor(const struct typenode *cur) |
300 |
300 |
{ |
{ |
301 |
|
while (cur->superclass) |
|
302 |
|
cur = cur->superclass; |
|
|
301 |
|
while (getTypePtr(cur)->superclass) |
|
302 |
|
cur = getTypePtr(cur)->superclass; |
303 |
303 |
return cur; |
return cur; |
304 |
304 |
} |
} |
305 |
305 |
|
|
|
... |
... |
int isDerivedFrom(const struct typenode *cur, const struct typenode *base) |
307 |
307 |
{ |
{ |
308 |
308 |
do { |
do { |
309 |
309 |
if (typeeq(cur, base)) return 1; |
if (typeeq(cur, base)) return 1; |
310 |
|
cur = cur->superclass; |
|
|
310 |
|
cur = getTypePtr(cur)->superclass; |
311 |
311 |
} while (cur); |
} while (cur); |
312 |
312 |
return 0; |
return 0; |
313 |
313 |
} |
} |
|
... |
... |
void showtypenode(const struct typenode *td) |
319 |
319 |
char *extends = ""; |
char *extends = ""; |
320 |
320 |
char ebuf[1024]; |
char ebuf[1024]; |
321 |
321 |
assert(td); |
assert(td); |
322 |
|
assert(td->typename); |
|
|
322 |
|
assert(getTypePtr(td)->typename); |
323 |
323 |
/* |
/* |
324 |
324 |
if (td->superclass) { |
if (td->superclass) { |
325 |
325 |
sprintf(ebuf, " extends %s", td->superclass->typename); |
sprintf(ebuf, " extends %s", td->superclass->typename); |
326 |
326 |
extends = ebuf; |
extends = ebuf; |
327 |
327 |
} |
} |
328 |
328 |
*/ |
*/ |
329 |
|
printf("%s %s \n", td->typename, extends); |
|
|
329 |
|
printf("%s %s \n", getTypePtr(td)->typename, extends); |
330 |
330 |
} |
} |
331 |
331 |
|
|
332 |
332 |
void showfuncdecl(struct funcdecl *fd) |
void showfuncdecl(struct funcdecl *fd) |
|
... |
... |
int canconvert(const struct typenode *ufrom, const struct typenode *uto, const i |
434 |
434 |
return 1; |
return 1; |
435 |
435 |
//if (isDerivedFrom(to, from)) |
//if (isDerivedFrom(to, from)) |
436 |
436 |
// return 1; // blizzard bug allows downcasting erroneously, we don't support this though |
// return 1; // blizzard bug allows downcasting erroneously, we don't support this though |
437 |
|
if (from->typename == NULL || to->typename == NULL) |
|
|
437 |
|
if (getTypePtr(from)->typename == NULL || getTypePtr(to)->typename == NULL) |
438 |
438 |
return 0; |
return 0; |
439 |
439 |
if (typeeq(from, gNone) || typeeq(to, gNone)) |
if (typeeq(from, gNone) || typeeq(to, gNone)) |
440 |
440 |
return 0; |
return 0; |
|
... |
... |
int canconvertreturn(const struct typenode *ufrom, const struct typenode *uto, c |
472 |
472 |
return 1; // eg. from = unit, to = handle |
return 1; // eg. from = unit, to = handle |
473 |
473 |
//if (isDerivedFrom(to, from)) |
//if (isDerivedFrom(to, from)) |
474 |
474 |
// return 1; // blizzard bug allows downcasting erroneously, we don't support this though |
// return 1; // blizzard bug allows downcasting erroneously, we don't support this though |
475 |
|
if (from->typename == NULL || to->typename == NULL) |
|
|
475 |
|
if (getTypePtr(from)->typename == NULL || getTypePtr(to)->typename == NULL) |
476 |
476 |
return 0; // garbage |
return 0; // garbage |
477 |
477 |
if (typeeq(from, gNone) || typeeq(to, gNone)) |
if (typeeq(from, gNone) || typeeq(to, gNone)) |
478 |
478 |
return 0; // garbage |
return 0; // garbage |
|
... |
... |
int canconvertreturn(const struct typenode *ufrom, const struct typenode *uto, c |
481 |
481 |
to = getPrimitiveAncestor(to); |
to = getPrimitiveAncestor(to); |
482 |
482 |
if ((typeeq(to, gReal)) && (typeeq(from, gInteger))) { |
if ((typeeq(to, gReal)) && (typeeq(from, gInteger))) { |
483 |
483 |
// can't return integer when it expects a real (added 9.5.2005) |
// can't return integer when it expects a real (added 9.5.2005) |
484 |
|
sprintf(ebuf, "Cannot convert returned value from %s to %s", from->typename, to->typename); |
|
|
484 |
|
sprintf(ebuf, "Cannot convert returned value from %s to %s", getTypePtr(from)->typename, getTypePtr(to)->typename); |
485 |
485 |
yyerrorline(1, lineno + linemod, ebuf); |
yyerrorline(1, lineno + linemod, ebuf); |
486 |
486 |
return 0; |
return 0; |
487 |
487 |
} |
} |
|
... |
... |
int canconvertreturn(const struct typenode *ufrom, const struct typenode *uto, c |
494 |
494 |
} else if (typeeq(from, to)) |
} else if (typeeq(from, to)) |
495 |
495 |
return 1; |
return 1; |
496 |
496 |
|
|
497 |
|
sprintf(ebuf, "Cannot convert returned value from %s to %s", ufrom->typename, uto->typename); |
|
|
497 |
|
sprintf(ebuf, "Cannot convert returned value from %s to %s", getTypePtr(ufrom)->typename, getTypePtr(uto)->typename); |
498 |
498 |
yyerrorline(1, lineno + linemod, ebuf); |
yyerrorline(1, lineno + linemod, ebuf); |
499 |
499 |
return 0; |
return 0; |
500 |
500 |
} |
} |
|
... |
... |
void isnumeric(const struct typenode *ty) |
578 |
578 |
void checkcomparisonsimple(const struct typenode *a) { |
void checkcomparisonsimple(const struct typenode *a) { |
579 |
579 |
const struct typenode *pa; |
const struct typenode *pa; |
580 |
580 |
pa = getPrimitiveAncestor(a); |
pa = getPrimitiveAncestor(a); |
581 |
|
if (pa == gString || pa == gHandle || pa == gCode || pa == gBoolean) { |
|
|
581 |
|
if (typeeq(pa, gString) || typeeq(pa, gHandle) || typeeq(pa, gCode) || typeeq(pa, gBoolean)) { |
582 |
582 |
yyerrorex(3, "Comparing the order/size of 2 variables only works on reals and integers"); |
yyerrorex(3, "Comparing the order/size of 2 variables only works on reals and integers"); |
583 |
583 |
return; |
return; |
584 |
584 |
} |
} |
585 |
|
if (pa == gNull) |
|
|
585 |
|
if (typeeq(pa, gNull)) |
586 |
586 |
yyerrorex(3, "Comparing null is not allowed"); |
yyerrorex(3, "Comparing null is not allowed"); |
587 |
587 |
} |
} |
588 |
588 |
|
|
|
... |
... |
void checkcomparison(const struct typenode *a, const struct typenode *b) |
591 |
591 |
const struct typenode *pa, *pb; |
const struct typenode *pa, *pb; |
592 |
592 |
pa = getPrimitiveAncestor(a); |
pa = getPrimitiveAncestor(a); |
593 |
593 |
pb = getPrimitiveAncestor(b); |
pb = getPrimitiveAncestor(b); |
594 |
|
if (pa == gString || pa == gHandle || pa == gCode || pa == gBoolean || pb == gString || pb == gCode || pb == gHandle || pb == gBoolean) { |
|
|
594 |
|
if (typeeq(pa, gString) || typeeq(pa, gHandle) || typeeq(pa, gCode) || typeeq(pa, gBoolean) || typeeq(pb, gString) || typeeq(pb, gCode) || typeeq(pb, gHandle) || typeeq(pb, gBoolean)) { |
595 |
595 |
yyerrorex(3, "Comparing the order/size of 2 variables only works on reals and integers"); |
yyerrorex(3, "Comparing the order/size of 2 variables only works on reals and integers"); |
596 |
596 |
return; |
return; |
597 |
597 |
} |
} |
598 |
|
if (pa == gNull && pb == gNull) |
|
|
598 |
|
if (typeeq(pa, gNull) && typeeq(pb, gNull)) |
599 |
599 |
yyerrorex(3, "Comparing null is not allowed"); |
yyerrorex(3, "Comparing null is not allowed"); |
600 |
600 |
} |
} |
601 |
601 |
|
|
|
... |
... |
void checkeqtest(const struct typenode *a, const struct typenode *b) |
604 |
604 |
const struct typenode *pa, *pb; |
const struct typenode *pa, *pb; |
605 |
605 |
pa = getPrimitiveAncestor(a); |
pa = getPrimitiveAncestor(a); |
606 |
606 |
pb = getPrimitiveAncestor(b); |
pb = getPrimitiveAncestor(b); |
607 |
|
if ((pa == gInteger || pa == gReal) && (pb == gInteger || pb == gReal)) |
|
|
607 |
|
if ((typeeq(pa, gInteger) || typeeq(pa, gReal)) && (typeeq(pb, gInteger) || typeeq(pb, gReal))) |
608 |
608 |
return; |
return; |
609 |
|
if (pa == gNull || pb == gNull) |
|
|
609 |
|
if (typeeq(pa, gNull) || typeeq(pb, gNull)) |
610 |
610 |
return; |
return; |
611 |
611 |
if (!typeeq(pa, pb)) { |
if (!typeeq(pa, pb)) { |
612 |
612 |
yyerrorex(3, "Comparing two variables of different primitive types (except real and integer) is not allowed"); |
yyerrorex(3, "Comparing two variables of different primitive types (except real and integer) is not allowed"); |