File grammar.y changed (mode: 100644) (index cdb9431..4ca41af) |
... |
... |
funcdefn: NEWLINE |
384 |
384 |
| statement { yyerrorex(0, "Statement outside of function"); } |
| statement { yyerrorex(0, "Statement outside of function"); } |
385 |
385 |
; |
; |
386 |
386 |
|
|
387 |
|
funcdefncore: funcbegin localblock codeblock funcend { if(retval != gNothing) { if ($3.ty == gAny || $3.ty == gNone) yyerrorline(1, lineno - 1, "Missing return"); else canconvertreturn($3.ty, retval, -1); } } |
|
|
387 |
|
funcdefncore: funcbegin localblock codeblock funcend { if(retval != gNothing) { if ($3.ty == gAny || $3.ty == gNone) yyerrorline(1, lineno - 1, "Missing return"); else if (returnbug) canconvertreturn($3.ty, retval, -1); } } |
388 |
388 |
| funcbegin localblock codeblock {yyerrorex(0, "Missing endfunction"); clear(¶ms); clear(&locals); curtab = &globals;} |
| funcbegin localblock codeblock {yyerrorex(0, "Missing endfunction"); clear(¶ms); clear(&locals); curtab = &globals;} |
389 |
389 |
; |
; |
390 |
390 |
|
|
|
... |
... |
statement: NEWLINE {$$.ty = gAny;} |
513 |
513 |
| loopstart NEWLINE codeblock loopend NEWLINE {$$.ty = $3.ty;} |
| loopstart NEWLINE codeblock loopend NEWLINE {$$.ty = $3.ty;} |
514 |
514 |
| loopstart NEWLINE codeblock {$$.ty = $3.ty; yyerrorex(0, "Missing endloop");} |
| loopstart NEWLINE codeblock {$$.ty = $3.ty; yyerrorex(0, "Missing endloop");} |
515 |
515 |
| EXITWHEN expr NEWLINE { canconvert($2.ty, gBoolean, -1); if (!inloop) yyerrorline(0, lineno - 1, "Exitwhen outside of loop"); $$.ty = gNone;} |
| EXITWHEN expr NEWLINE { canconvert($2.ty, gBoolean, -1); if (!inloop) yyerrorline(0, lineno - 1, "Exitwhen outside of loop"); $$.ty = gNone;} |
516 |
|
| RETURN expr NEWLINE { $$.ty = $2.ty; if(retval == gNothing) yyerrorline(1, lineno - 1, "Cannot return value from function that returns nothing");} |
|
|
516 |
|
| RETURN expr NEWLINE { $$.ty = $2.ty; if(retval == gNothing) yyerrorline(1, lineno - 1, "Cannot return value from function that returns nothing"); else if (!returnbug) canconvertreturn($2.ty, retval, 0); } |
517 |
517 |
| RETURN NEWLINE { if (retval != gNothing) yyerrorline(1, lineno - 1, "Return nothing in function that should return value"); $$.ty = gNone;} |
| RETURN NEWLINE { if (retval != gNothing) yyerrorline(1, lineno - 1, "Return nothing in function that should return value"); $$.ty = gNone;} |
518 |
518 |
| DEBUG statement {$$.ty = gNone;} |
| DEBUG statement {$$.ty = gNone;} |
519 |
519 |
| IF expr THEN NEWLINE codeblock elsifseq elseseq {canconvert($2.ty, gBoolean, 0); $$.ty = combinetype($6.ty!=gAny?combinetype($5.ty, $6.ty):$5.ty, $7.ty); yyerrorex(0, "Missing endif");} |
| IF expr THEN NEWLINE codeblock elsifseq elseseq {canconvert($2.ty, gBoolean, 0); $$.ty = combinetype($6.ty!=gAny?combinetype($5.ty, $6.ty):$5.ty, $7.ty); yyerrorex(0, "Missing endif");} |
File misc.c changed (mode: 100644) (index 88df964..2d95c67) |
11 |
11 |
#include "grammar.tab.h" |
#include "grammar.tab.h" |
12 |
12 |
#include "misc.h" |
#include "misc.h" |
13 |
13 |
|
|
14 |
|
#define VERSIONSTR "1.0j" |
|
|
14 |
|
#define VERSIONSTR "1.0l" |
15 |
15 |
#define ERRORLEVELNUM 4 |
#define ERRORLEVELNUM 4 |
16 |
16 |
|
|
17 |
17 |
int fno; |
int fno; |
|
... |
... |
int isconstant; |
24 |
24 |
int inconstant; |
int inconstant; |
25 |
25 |
int inblock; |
int inblock; |
26 |
26 |
int strict; |
int strict; |
|
27 |
|
int returnbug; |
27 |
28 |
int didparse; |
int didparse; |
28 |
29 |
int inloop; |
int inloop; |
29 |
30 |
int afterendglobals; |
int afterendglobals; |
|
... |
... |
void init(int argc, char **argv) |
60 |
61 |
curtab = &globals; |
curtab = &globals; |
61 |
62 |
fno = 0; |
fno = 0; |
62 |
63 |
strict = 0; |
strict = 0; |
|
64 |
|
returnbug = 0; |
63 |
65 |
haderrors = 0; |
haderrors = 0; |
64 |
66 |
ignorederrors = 0; |
ignorederrors = 0; |
65 |
67 |
islinebreak = 1; |
islinebreak = 1; |
|
... |
... |
struct typenode *binop(const struct typenode *a, const struct typenode *b) |
279 |
281 |
return gReal; |
return gReal; |
280 |
282 |
} |
} |
281 |
283 |
|
|
|
284 |
|
// this is used for reducing expressions in many places (if/exitwhen conditions, assignments etc.) |
282 |
285 |
int canconvert(const struct typenode *ufrom, const struct typenode *uto, const int linemod) |
int canconvert(const struct typenode *ufrom, const struct typenode *uto, const int linemod) |
283 |
286 |
{ |
{ |
284 |
287 |
const struct typenode *from = ufrom, *to = uto; |
const struct typenode *from = ufrom, *to = uto; |
285 |
288 |
char ebuf[1024]; |
char ebuf[1024]; |
286 |
|
|
|
287 |
|
if (from == NULL || to == NULL) return 0; |
|
288 |
|
if (from == gAny || to == gAny) return 1; |
|
|
289 |
|
if (from == NULL || to == NULL) |
|
290 |
|
return 0; |
|
291 |
|
if (from == gAny || to == gAny) |
|
292 |
|
return 1; |
289 |
293 |
if (isDerivedFrom(from, to)) |
if (isDerivedFrom(from, to)) |
290 |
294 |
return 1; |
return 1; |
291 |
|
//bug allows downcasting erroneously |
|
292 |
295 |
//if (isDerivedFrom(to, from)) |
//if (isDerivedFrom(to, from)) |
293 |
|
// return 1; |
|
294 |
|
if (from->typename == NULL || to->typename == NULL) return 0; |
|
295 |
|
if (from == gNone || to == gNone) return 0; |
|
|
296 |
|
// return 1; // blizzard bug allows downcasting erroneously, we don't support this though |
|
297 |
|
if (from->typename == NULL || to->typename == NULL) |
|
298 |
|
return 0; |
|
299 |
|
if (from == gNone || to == gNone) |
|
300 |
|
return 0; |
296 |
301 |
from = getPrimitiveAncestor(from); |
from = getPrimitiveAncestor(from); |
297 |
302 |
to = getPrimitiveAncestor(to); |
to = getPrimitiveAncestor(to); |
298 |
303 |
if ((from == gNull) && (to != gInteger) && (to != gReal) && (to != gBoolean)) |
if ((from == gNull) && (to != gInteger) && (to != gReal) && (to != gBoolean)) |
|
... |
... |
int canconvert(const struct typenode *ufrom, const struct typenode *uto, const i |
313 |
318 |
yyerrorline(3, lineno + linemod, ebuf); |
yyerrorline(3, lineno + linemod, ebuf); |
314 |
319 |
} |
} |
315 |
320 |
|
|
|
321 |
|
// this is used for return statements only |
316 |
322 |
int canconvertreturn(const struct typenode *ufrom, const struct typenode *uto, const int linemod) |
int canconvertreturn(const struct typenode *ufrom, const struct typenode *uto, const int linemod) |
317 |
323 |
{ |
{ |
318 |
324 |
const struct typenode *from = ufrom, *to = uto; |
const struct typenode *from = ufrom, *to = uto; |
319 |
325 |
char ebuf[1024]; |
char ebuf[1024]; |
320 |
|
if (from == NULL || to == NULL) return 0; |
|
321 |
|
if (from == gAny || to == gAny) return 1; |
|
|
326 |
|
if (from == NULL || to == NULL) |
|
327 |
|
return 0; // garbage |
|
328 |
|
if (from == gAny || to == gAny) |
|
329 |
|
return 1; // we don't care |
322 |
330 |
if (isDerivedFrom(from, to)) |
if (isDerivedFrom(from, to)) |
323 |
|
return 1; |
|
324 |
|
/* Blizzard bug: allows downcasting erroneously */ |
|
325 |
|
/* TODO: get Blizzard to fix this in Blizzard.j and the language */ |
|
326 |
|
// if (isDerivedFrom(to, from)) |
|
327 |
|
// return 1; |
|
328 |
|
if (from->typename == NULL || to->typename == NULL) return 0; |
|
329 |
|
if (from == gNone || to == gNone) return 0; |
|
|
331 |
|
return 1; // eg. from = unit, to = handle |
|
332 |
|
//if (isDerivedFrom(to, from)) |
|
333 |
|
// return 1; // blizzard bug allows downcasting erroneously, we don't support this though |
|
334 |
|
if (from->typename == NULL || to->typename == NULL) |
|
335 |
|
return 0; // garbage |
|
336 |
|
if (from == gNone || to == gNone) |
|
337 |
|
return 0; // garbage |
|
338 |
|
|
330 |
339 |
from = getPrimitiveAncestor(from); |
from = getPrimitiveAncestor(from); |
331 |
340 |
to = getPrimitiveAncestor(to); |
to = getPrimitiveAncestor(to); |
332 |
|
|
|
333 |
|
// can't return integer when it expects a real (added 9.5.2005) |
|
334 |
341 |
if ((to == gReal) && (from == gInteger)) { |
if ((to == gReal) && (from == gInteger)) { |
|
342 |
|
// can't return integer when it expects a real (added 9.5.2005) |
335 |
343 |
sprintf(ebuf, "Cannot convert returned value from %s to %s", from->typename, to->typename); |
sprintf(ebuf, "Cannot convert returned value from %s to %s", from->typename, to->typename); |
336 |
344 |
yyerrorline(1, lineno + linemod, ebuf); |
yyerrorline(1, lineno + linemod, ebuf); |
337 |
345 |
return 0; |
return 0; |
338 |
346 |
} |
} |
339 |
|
|
|
340 |
|
// can't return null when it expects integer, real or boolean (added 9.5.2005) |
|
341 |
347 |
if ((from == gNull) && (to != gInteger) && (to != gReal) && (to != gBoolean)) |
if ((from == gNull) && (to != gInteger) && (to != gReal) && (to != gBoolean)) |
342 |
|
return 1; |
|
|
348 |
|
return 1; // can't return null when it expects integer, real or boolean (added 9.5.2005) |
343 |
349 |
|
|
344 |
350 |
if (strict) { |
if (strict) { |
345 |
351 |
if (isDerivedFrom(uto, ufrom)) |
if (isDerivedFrom(uto, ufrom)) |
|
... |
... |
struct typenode *combinetype(struct typenode *n1, struct typenode *n2) { |
369 |
375 |
return gReal; |
return gReal; |
370 |
376 |
if ((n1 == gReal) && (n2 == gInteger)) |
if ((n1 == gReal) && (n2 == gInteger)) |
371 |
377 |
return gInteger; |
return gInteger; |
372 |
|
// printf("Cannot convert %s to %s", n1->typename, n2->typename); |
|
|
378 |
|
// printf("Cannot convert %s to %s", n1->typename, n2->typename); |
373 |
379 |
return gNone; |
return gNone; |
374 |
380 |
} |
} |
375 |
381 |
|
|
|
... |
... |
printf( |
498 |
504 |
"pjass +e2 Undo Ignore of error level 2\n" |
"pjass +e2 Undo Ignore of error level 2\n" |
499 |
505 |
"pjass +s Enable strict downcast evaluation\n" |
"pjass +s Enable strict downcast evaluation\n" |
500 |
506 |
"pjass -s Disable strict downcast evaluation\n" |
"pjass -s Disable strict downcast evaluation\n" |
|
507 |
|
"pjass +rb Enable returnbug\n" |
|
508 |
|
"pjass -rb Disable returnbug\n" |
501 |
509 |
"pjass - Read from standard input (may appear in a list)\n" |
"pjass - Read from standard input (may appear in a list)\n" |
502 |
510 |
); |
); |
503 |
511 |
exit(0); |
exit(0); |
|
... |
... |
printf( |
516 |
524 |
strict = 0; |
strict = 0; |
517 |
525 |
continue; |
continue; |
518 |
526 |
} |
} |
|
527 |
|
if (strcmp(argv[i], "+rb") == 0) { |
|
528 |
|
returnbug = 1; |
|
529 |
|
continue; |
|
530 |
|
} |
|
531 |
|
if (strcmp(argv[i], "-rb") == 0) { |
|
532 |
|
returnbug = 0; |
|
533 |
|
continue; |
|
534 |
|
} |
519 |
535 |
if (argv[i][0] == '-' && argv[i][1] == 'e' && argv[i][2] >= '0' && argv[i][2] < ('0' + ERRORLEVELNUM)) { |
if (argv[i][0] == '-' && argv[i][1] == 'e' && argv[i][2] >= '0' && argv[i][2] < ('0' + ERRORLEVELNUM)) { |
520 |
536 |
showerrorlevel[argv[i][2]-'0'] = 0; |
showerrorlevel[argv[i][2]-'0'] = 0; |
521 |
537 |
continue; |
continue; |