From 6d27bffe6f3ded2eb9b0f9f2e951d862db4aeb50 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 27 Oct 2020 21:29:30 +0700 Subject: [PATCH 01/21] Fix use of `0`/`1` instead of `FALSE`/`TRUE` --- source/compiler/sc3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/sc3.c b/source/compiler/sc3.c index f54c545..4ea35fc 100644 --- a/source/compiler/sc3.c +++ b/source/compiler/sc3.c @@ -2081,7 +2081,7 @@ static int primary(value *lval) return FALSE; /* return 0 for function (not an lvalue) */ } /* if */ lexpush(); /* push the token, it is analyzed by constant() */ - if (constant(lval)==0) { + if (!constant(lval)) { error(29); /* expression error, assumed 0 */ ldconst(0,sPRI); /* load 0 */ } /* if */ From 640aadb05f239c8a828e99532ed0d18b94a624e3 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sat, 31 Oct 2020 18:36:12 +0700 Subject: [PATCH 02/21] Move array `sc_tokens` from sc2.c to scvars.c and add a declaration for it in sc.h --- source/compiler/sc.h | 2 ++ source/compiler/sc1.c | 9 --------- source/compiler/sc2.c | 19 ------------------- source/compiler/sc3.c | 1 - source/compiler/sc5.c | 1 - source/compiler/scvars.c | 18 ++++++++++++++++++ 6 files changed, 20 insertions(+), 30 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index 15cbd87..520b7a4 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -1012,6 +1012,8 @@ SC_VDECL int pc_retheap; /* heap space (in bytes) to be manually freed when SC_VDECL int pc_nestlevel; /* number of active (open) compound statements */ SC_VDECL unsigned int pc_attributes;/* currently set attribute flags (for the "__pragma" operator) */ +SC_VDECL char *sc_tokens[]; + SC_VDECL constvalue_root sc_automaton_tab; /* automaton table */ SC_VDECL constvalue_root sc_state_tab; /* state table */ diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 85dafe7..65db991 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -2972,7 +2972,6 @@ static void decl_const(int vclass) */ static void decl_enum(int vclass,int fstatic) { - extern const char *sc_tokens[]; char enumname[sNAMEMAX+1],constname[sNAMEMAX+1]; cell val,value,size; char *str; @@ -4139,7 +4138,6 @@ static int argcompare(arginfo *a1,arginfo *a2) static int declargs(symbol *sym,int chkshadow) { #define MAXTAGS 16 - extern char* sc_tokens[]; char *ptr; int argcnt,oldargcnt,tok,tags[MAXTAGS],numtags; cell val; @@ -5615,7 +5613,6 @@ static void statement(int *lastindent,int allow_decl) pragma_apply(curfunc); break; case t__EMIT: { - extern char *sc_tokens[]; const unsigned char *bck_lptr=lptr-strlen(sc_tokens[tok-tFIRST]); if (matchtoken('{')) { emit_flags |= efBLOCK; @@ -6429,7 +6426,6 @@ static symbol *fetchlab(char *name) static void SC_FASTCALL emit_invalid_token(int expected_token,int found_token) { - extern char *sc_tokens[]; char s[2]; assert(expected_token>=tFIRST); @@ -6797,7 +6793,6 @@ fetchtok: negate=TRUE; goto fetchtok; } else { - extern char *sc_tokens[]; char ival[sNAMEMAX+2]; invalid_token_neg: if (tokvalue.ucell<(cell)0) { - extern char *sc_tokens[]; #if PAWN_CELL_SIZE==16 char ival[7]; #elif PAWN_CELL_SIZE==32 @@ -6983,7 +6977,6 @@ fetchtok: negate=TRUE; goto fetchtok; } else { - extern char *sc_tokens[]; char ival[sNAMEMAX+2]; invalid_token_neg: if (tok>>=", ">>=", "&=", "^=", "|=", - "||", "&&", "==", "!=", "<=", ">=", "<<", ">>>", ">>", "++", "--", - "...", "..", - "__addressof", "assert", "*begin", "break", "case", "char", "const", "continue", - "default", "defined", "do", "else", "__emit", "*end", "enum", "exit", "for", - "forward", "goto", "if", "__nameof", "native", "new", "operator", "__pragma", - "public", "return", "sizeof", "sleep", "state", "static", "stock", "switch", - "tagof", "*then", "while", - "#assert", "#define", "#else", "#elseif", "#emit", "#endif", "#endinput", - "#endscript", "#error", "#file", "#if", "#include", "#line", "#pragma", - "#tryinclude", "#undef", "#warning", - ";", ";", "-integer value-", "-rational value-", "-identifier-", - "-label-", "-string-", - "-any value-", "-numeric value-", "-data offset-", "-local variable-", - "-reference-", "-function-", "-native function-", "-nonnegative integer-" - }; - SC_FUNC int lex(cell *lexvalue,char **lexsym) { int i,toolong,newline,stringflags; diff --git a/source/compiler/sc3.c b/source/compiler/sc3.c index 4ea35fc..875a7da 100644 --- a/source/compiler/sc3.c +++ b/source/compiler/sc3.c @@ -1362,7 +1362,6 @@ static int hier2(value *lval) lval->tag=tag; return lvalue; case t__ADDRESSOF: { - extern char *sc_tokens[]; static const char allowed_sym_types[]="-variable, array, array cell, label or function-"; paranthese=0; while (matchtoken('(')) diff --git a/source/compiler/sc5.c b/source/compiler/sc5.c index 3302cfa..7672f45 100644 --- a/source/compiler/sc5.c +++ b/source/compiler/sc5.c @@ -700,7 +700,6 @@ SC_FUNC int error_suggest(int number,const char *name,const char *name2,int type } /* if */ } else if (type==estNONSYMBOL) { if (tMIDDLE>>=", ">>=", "&=", "^=", "|=", + "||", "&&", "==", "!=", "<=", ">=", "<<", ">>>", ">>", "++", "--", + "...", "..", + "__addressof", "assert", "*begin", "break", "case", "char", "const", "continue", + "default", "defined", "do", "else", "__emit", "*end", "enum", "exit", "for", + "forward", "goto", "if", "__nameof", "native", "new", "operator", "__pragma", + "public", "return", "sizeof", "sleep", "state", "static", "stock", "switch", + "tagof", "*then", "while", + "#assert", "#define", "#else", "#elseif", "#emit", "#endif", "#endinput", + "#endscript", "#error", "#file", "#if", "#include", "#line", "#pragma", + "#tryinclude", "#undef", "#warning", + ";", ";", "-integer value-", "-rational value-", "-identifier-", + "-label-", "-string-", + "-any value-", "-numeric value-", "-data offset-", "-local variable-", + "-reference-", "-function-", "-native function-", "-nonnegative integer-" +}; + SC_VDEFINE constvalue_root sc_automaton_tab = { NULL, NULL}; /* automaton table */ SC_VDEFINE constvalue_root sc_state_tab = { NULL, NULL}; /* state table */ From e7e648f2b37e84c7a2e48c6a4b7f54e917a21566 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 5 Nov 2020 20:46:19 +0700 Subject: [PATCH 03/21] Fix incompatible pointer type being passed to function `number()` --- source/compiler/sc1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 65db991..554a96c 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -8397,7 +8397,7 @@ static void dopragma(void) /* nothing */; } /* if */ if (strcmp(str,"enable")==0 || strcmp(str,"disable")==0) { - int len=number(&val,&str[i]); + int len=number(&val,(unsigned char *)&str[i]); if (len==0) goto unknown_pragma; pc_enablewarning((int)val,(str[0]=='e') ? warnENABLE : warnDISABLE); From 6f1817b1060f0ade9cf7ace0bfab929557f4b4cf Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 5 Nov 2020 20:51:21 +0700 Subject: [PATCH 04/21] Fix invalid token index --- source/compiler/sc1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 554a96c..f532c74 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -8317,7 +8317,7 @@ static void dopragma(void) sprintf(tokstr,"%c",tok); str=tokstr; } else { - str=sc_tokens[tok-tBEGIN]; + str=sc_tokens[tok-tFIRST]; } /* if */ error(1,sc_tokens[tSTRING-tFIRST],str); goto next; From 8b53b26228c60e64783c0015095cba69d32499e1 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 5 Nov 2020 23:45:58 +0700 Subject: [PATCH 05/21] Fix variables shadowing outer variables, remove redundant variable declarations --- source/compiler/sc1.c | 16 ++++++++-------- source/compiler/sc2.c | 8 +------- source/compiler/sc3.c | 1 - 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index f532c74..31e65f5 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -3088,7 +3088,8 @@ static void decl_enum(int vclass,int fstatic) /* don't reset "warn_overflow" yet, we'll need to use it later */ } /* if */ if (warn_noeffect) { - const char *str=sc_tokens[inctok-tFIRST],*name=noeffect_sym->name; + const char *name=noeffect_sym->name; + str=sc_tokens[inctok-tFIRST]; errorset(sSETPOS,noeffect_sym->lnumber); error(245,str,increment,name); /* enum increment has no effect on zero value */ errorset(sSETPOS,-1); @@ -6247,24 +6248,23 @@ static int doswitch(void) if (enumsym!=NULL && swdefault==FALSE && enumsym->x.tags.unique-enumsymcount<=2) { constvalue_root *enumlist=enumsym->dim.enumlist; - constvalue *val,*prev=NULL,*save_next=NULL; - for (val=enumlist->first; val!=NULL; prev=val,val=val->next) { + constvalue *cur,*found,*prev=NULL,*save_next=NULL; + for (cur=enumlist->first; cur!=NULL; prev=cur,cur=cur->next) { /* if multiple enum elements share the same value, we only want to count the first one */ if (prev!=NULL) { /* see if there's another constvalue before the current one that has the same value */ - constvalue *save_next=prev->next; - constvalue *found; + save_next=prev->next; prev->next=NULL; - found=find_constval_byval(enumlist,val->value); + found=find_constval_byval(enumlist,cur->value); prev->next=save_next; if (found!=NULL) continue; } /* if */ /* check if the value of this constant is handled in switch, if so - continue */ - if (find_constval_byval(&caselist,val->value)!=NULL) + if (find_constval_byval(&caselist,cur->value)!=NULL) continue; errorset(sSETPOS,save_fline); - error(244,val->name); /* enum element not handled in switch */ + error(244,cur->name); /* enum element not handled in switch */ errorset(sSETPOS,-1); } /* while */ } /* if */ diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 6ea7645..94fe28e 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -404,7 +404,7 @@ static void readline(unsigned char *line) } else { /* check whether to erase leading spaces */ if (cont) { - unsigned char *ptr=line; + ptr=line; while (*ptr<=' ' && *ptr!='\0') ptr++; if (ptr!=line) @@ -1220,7 +1220,6 @@ static int command(void) if (!cp_set(name)) error(108); /* codepage mapping file not found */ } else if (strcmp(str,"compress")==0) { - cell val; preproc_expr(&val,NULL); sc_compress=(int)val; /* switch code packing on/off */ } else if (strcmp(str,"ctrlchar")==0) { @@ -1272,7 +1271,6 @@ static int command(void) curlibrary=append_constval(&libname_tab,name,0,0); } /* if */ } else if (strcmp(str,"pack")==0) { - cell val; preproc_expr(&val,NULL); /* default = packed/unpacked */ sc_packstr=(int)val; } else if (strcmp(str,"rational")==0) { @@ -1307,11 +1305,9 @@ static int command(void) error(69); /* rational number format already set, can only be set once */ } /* if */ } else if (strcmp(str,"semicolon")==0) { - cell val; preproc_expr(&val,NULL); sc_needsemicolon=(int)val; } else if (strcmp(str,"tabsize")==0) { - cell val; preproc_expr(&val,NULL); if (val>0) sc_tabsize=(int)val; @@ -1379,7 +1375,6 @@ static int command(void) int ok=lex(&val,&str)==tSYMBOL; if (ok) { if (strcmp(str,"enable")==0 || strcmp(str,"disable")==0) { - cell val; enum s_warnmode enable=(str[0]=='e') ? warnENABLE : warnDISABLE; do { preproc_expr(&val,NULL); @@ -1397,7 +1392,6 @@ static int command(void) error(207); /* unknown #pragma */ } /* if */ } else if (strcmp(str,"compat")==0) { - cell val; symbol *sym; preproc_expr(&val,NULL); pc_compat=(int)val; /* switch compatibility mode on/off */ diff --git a/source/compiler/sc3.c b/source/compiler/sc3.c index 875a7da..f557654 100644 --- a/source/compiler/sc3.c +++ b/source/compiler/sc3.c @@ -1055,7 +1055,6 @@ static int hier14(value *lval1) /* check the sizes of all sublevels too */ symbol *sym1 = lval3.sym; symbol *sym2 = lval2.sym; - int i; assert(sym1!=NULL && sym2!=NULL); /* ^^^ sym2 must be valid, because only variables can be * multi-dimensional (there are no multi-dimensional literals), From d5ab9f07eefada7efb429c2d6f09d98e71220f32 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 6 Nov 2020 22:48:29 +0700 Subject: [PATCH 06/21] Fix unused assignment at initialization --- source/compiler/sc3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/sc3.c b/source/compiler/sc3.c index f557654..8633336 100644 --- a/source/compiler/sc3.c +++ b/source/compiler/sc3.c @@ -587,7 +587,7 @@ static void plnge2(void (*oper)(void), rvalue(lval2); if (lval2->ident==iCONSTEXPR) { /* constant on right side */ if (commutative(oper)) { /* test for commutative operators */ - value lvaltmp = {0}; + value lvaltmp; stgdel(lval_stgidx,lval_cidx); /* scratch pushreg() and constant fetch (then * fetch the constant again */ ldconst(lval2->constval< Date: Tue, 10 Nov 2020 18:37:44 +0700 Subject: [PATCH 07/21] Remove unused `uPREDEF` flag --- source/compiler/sc.h | 1 - source/compiler/sc2.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index 520b7a4..0044847 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -213,7 +213,6 @@ typedef struct s_symbol { #define uRETVALUE 0x004 /* function returns (or should return) a value */ #define uCONST 0x008 #define uPROTOTYPED 0x008 -#define uPREDEF 0x008 /* constant is pre-defined */ #define uPUBLIC 0x010 #define uNATIVE 0x020 #define uENUMROOT 0x020 diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 94fe28e..83a0ac7 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -3120,8 +3120,8 @@ SC_FUNC void delete_symbols(symbol *root,int level,int delete_labels,int delete_ mustdelete=TRUE; break; case iCONSTEXPR: - /* delete constants, except predefined constants */ - mustdelete=delete_functions || (sym->usage & uPREDEF)==0; + /* delete constants (predefined constants are checked later) */ + mustdelete=TRUE; break; case iFUNCTN: /* optionally preserve globals (variables & functions), but From 4b4319aa746b4f8ce15e71e79599da524654f8fe Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 10 Nov 2020 19:54:56 +0700 Subject: [PATCH 08/21] Get rid of function `finddepend()` --- source/compiler/sc.h | 1 - source/compiler/sc1.c | 31 ++++++++++++++----------------- source/compiler/sc2.c | 17 ----------------- source/compiler/sc3.c | 24 ++++++++++++------------ source/compiler/sclist.c | 2 +- 5 files changed, 27 insertions(+), 48 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index 0044847..a2f7936 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -740,7 +740,6 @@ SC_FUNC void rename_symbol(symbol *sym,const char *newname); SC_FUNC symbol *findglb(const char *name,int filter); SC_FUNC symbol *findloc(const char *name); SC_FUNC symbol *findconst(const char *name,int *cmptag); -SC_FUNC symbol *finddepend(const symbol *parent); SC_FUNC symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag, int usage); SC_FUNC symbol *addvariable(const char *name,cell addr,int ident,int vclass,int tag, diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 31e65f5..5c08a99 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -4058,14 +4058,12 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc && (lvar=findloc(sym->dim.arglist[i].name))!=NULL) { if ((sym->dim.arglist[i].usage & uWRITTEN)==0) { /* check if the argument was written in this definition */ - depend=lvar; - while (depend!=NULL) { + for (depend=lvar; depend!=NULL; depend=depend->child) { if ((depend->usage & uWRITTEN)!=0) { sym->dim.arglist[i].usage|=depend->usage & uWRITTEN; break; - } - depend=finddepend(depend); - } /* while */ + } /* if */ + } /* for */ } /* if */ /* mark argument as written if it was written in another definition */ lvar->usage|=sym->dim.arglist[i].usage & uWRITTEN; @@ -5149,14 +5147,13 @@ static int testsymbols(symbol *root,int level,int testlabs,int testconst) errorset(sSETPOS,-1); } else if ((sym->usage & (uWRITTEN | uPUBLIC | uCONST))==0 && sym->ident==iREFARRAY) { int warn = TRUE; - symbol* depend = finddepend(sym); - while (depend != NULL) { - if ((depend->usage & (uWRITTEN | uPUBLIC | uCONST)) != 0) { - warn = FALSE; + symbol *depend; + for (depend=sym->child; depend!=NULL; depend=depend->child) { + if ((depend->usage & (uWRITTEN | uPUBLIC | uCONST))!=0) { + warn=FALSE; break; - } - depend = finddepend(depend); - } /* while */ + } /* if */ + } /* for */ if (warn) { errorset(sSETPOS, sym->lnumber); error(214, sym->name); /* make array argument "const" */ @@ -5181,7 +5178,7 @@ static cell calc_array_datasize(symbol *sym, cell *offset) assert(sym->ident==iARRAY || sym->ident==iREFARRAY); length=sym->dim.array.length; if (sym->dim.array.level > 0) { - cell sublength=calc_array_datasize(finddepend(sym),offset); + cell sublength=calc_array_datasize(sym->child,offset); if (offset!=NULL) *offset=length*(*offset+sizeof(cell)); if (sublength>0) @@ -7942,7 +7939,7 @@ static void doreturn(void) error(225); /* unreachable code */ /* see if this function already has a sub type (an array attached) */ assert(curfunc!=NULL); - sub=finddepend(curfunc); + sub=curfunc->child; assert(sub==NULL || sub->ident==iREFARRAY); if ((rettype & uRETVALUE)!=0) { int retarray=(ident==iARRAY || ident==iREFARRAY); @@ -7974,8 +7971,8 @@ static void doreturn(void) if (sym->dim.array.length!=dim[numdim]) error(47); /* array sizes must match */ if (numdimchild; + sub=sub->child; assert(sym!=NULL && sub!=NULL); /* ^^^ both arrays have the same dimensions (this was checked * earlier) so the dependend should always be found @@ -7996,7 +7993,7 @@ static void doreturn(void) dim[numdim]=(int)sub->dim.array.length; idxtag[numdim]=sub->x.tags.index; if (numdimchild; assert(sub!=NULL); } /* if */ /* check that all dimensions are known */ diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 83a0ac7..7888e5c 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -3222,13 +3222,6 @@ static symbol *find_symbol(const symbol *root,const char *name,int fnumber,int a return firstmatch; } -static symbol *find_symbol_child(const symbol *root,const symbol *sym) -{ - if (sym->child && sym->child->parent==sym) - return sym->child; - return NULL; -} - /* Adds "bywhom" to the list of referrers of "entry". Typically, * bywhom will be the function that uses a variable or that calls * the function. @@ -3445,16 +3438,6 @@ SC_FUNC symbol *findconst(const char *name,int *cmptag) return sym; } -SC_FUNC symbol *finddepend(const symbol *parent) -{ - symbol *sym; - - sym=find_symbol_child(&loctab,parent); /* try local symbols first */ - if (sym==NULL) /* not found */ - sym=find_symbol_child(&glbtab,parent); - return sym; -} - /* addsym * * Adds a symbol to the symbol table (either global or local variables, diff --git a/source/compiler/sc3.c b/source/compiler/sc3.c index 8633336..a76c3b0 100644 --- a/source/compiler/sc3.c +++ b/source/compiler/sc3.c @@ -817,7 +817,7 @@ SC_FUNC cell array_totalsize(symbol *sym) assert(sym->ident==iARRAY || sym->ident==iREFARRAY); length=sym->dim.array.length; if (sym->dim.array.level > 0) { - cell sublength=array_totalsize(finddepend(sym)); + cell sublength=array_totalsize(sym->child); if (sublength>0) length=length+length*sublength; else @@ -832,7 +832,7 @@ static cell array_levelsize(symbol *sym,int level) assert(sym->ident==iARRAY || sym->ident==iREFARRAY); assert(level <= sym->dim.array.level); while (level-- > 0) { - sym=finddepend(sym); + sym=sym->child; assert(sym!=NULL); } /* if */ return sym->dim.array.length; @@ -1062,8 +1062,8 @@ static int hier14(value *lval1) */ assert(exactmatch); for (i=0; ichild; + sym2=sym2->child; assert(sym1!=NULL && sym2!=NULL); /* ^^^ both arrays have the same dimensions (this was checked * earlier) so the dependend should always be found @@ -1428,7 +1428,7 @@ static int hier2(value *lval) numoffsets+=offsmul; offsmul*=subsym->dim.array.length; arrayidx=(arrayidx*subsym->dim.array.length)+val; - subsym=finddepend(subsym); + subsym=subsym->child; } needtoken(']'); } /* for */ @@ -1438,7 +1438,7 @@ static int hier2(value *lval) numoffsets+=offsmul; offsmul*=subsym->dim.array.length; arrayidx*=arrayidx*subsym->dim.array.length; - subsym=finddepend(subsym); + subsym=subsym->child; } /* if */ lval->constval+=(numoffsets-1+arrayidx)*(cell)sizeof(cell); ldconst(lval->constval,sPRI); @@ -1541,7 +1541,7 @@ static int hier2(value *lval) } /* if */ needtoken(']'); if (subsym!=NULL) - subsym=finddepend(subsym); + subsym=subsym->child; } /* for */ if (level>sym->dim.array.level+1) error(28,sym->name); /* invalid subscript */ @@ -1593,7 +1593,7 @@ static int hier2(value *lval) } /* if */ needtoken(']'); if (subsym!=NULL) - subsym=finddepend(subsym); + subsym=subsym->child; } /* for */ if (level>sym->dim.array.level+1) error(28,sym->name); /* invalid subscript */ @@ -1788,7 +1788,7 @@ restart: /* parse the next index if this is not the lowest array dimension */ if (sym!=NULL && (sym->ident==iARRAY || sym->ident==iREFARRAY) && sym->dim.array.level>0) { lval1->ident=iREFARRAY; - lval1->sym=finddepend(sym); + lval1->sym=sym->child; assert(lval1->sym!=NULL); assert(lval1->sym->dim.array.level==sym->dim.array.level-1); cursym=lval1->sym; @@ -1875,7 +1875,7 @@ restart: ob_add(); /* adjust the "value" structure and find the referenced array */ lval1->ident=iREFARRAY; - lval1->sym=finddepend(sym); + lval1->sym=sym->child; assert(lval1->sym!=NULL); assert(lval1->sym->dim.array.level==sym->dim.array.level-1); cursym=lval1->sym; @@ -2195,7 +2195,7 @@ static int nesting=0; return; } /* check whether this is a function that returns an array */ - symret=finddepend(sym); + symret=sym->child; assert(symret==NULL || symret->ident==iREFARRAY); if (symret!=NULL) { int retsize; @@ -2451,7 +2451,7 @@ static int nesting=0; else check_index_tagmismatch(sym->name,arg[argidx].idxtag[level],sym->x.tags.index,TRUE,0); append_constval(&arrayszlst,arg[argidx].name,sym->dim.array.length,level); - sym=finddepend(sym); + sym=sym->child; assert(sym!=NULL); level++; } /* if */ diff --git a/source/compiler/sclist.c b/source/compiler/sclist.c index 2c44e55..516a276 100644 --- a/source/compiler/sclist.c +++ b/source/compiler/sclist.c @@ -482,7 +482,7 @@ SC_FUNC stringlist *insert_dbgsymbol(symbol *sym) #endif symbol *sub; strcat(string," [ "); - for (sub=sym; sub!=NULL; sub=finddepend(sub)) { + for (sub=sym; sub!=NULL; sub=sub->child) { assert(sub->dim.array.level==count--); sprintf(string+strlen(string),"%x:%x ",sub->x.tags.index,sub->dim.array.length); } /* for */ From c9b2945e04af30850e2a5742138fdeebc7cb1549 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 10 Nov 2020 20:14:15 +0700 Subject: [PATCH 09/21] Rename "warning_047.pwn/meta" to "error_047.pwn/meta" --- source/compiler/tests/error_047.meta | 6 ++++++ source/compiler/tests/{warning_047.pwn => error_047.pwn} | 0 source/compiler/tests/warning_047.meta | 6 ------ 3 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 source/compiler/tests/error_047.meta rename source/compiler/tests/{warning_047.pwn => error_047.pwn} (100%) delete mode 100644 source/compiler/tests/warning_047.meta diff --git a/source/compiler/tests/error_047.meta b/source/compiler/tests/error_047.meta new file mode 100644 index 0000000..844ec83 --- /dev/null +++ b/source/compiler/tests/error_047.meta @@ -0,0 +1,6 @@ +{ + 'test_type': 'output_check', + 'errors': """ +error_047.pwn(8) : error 047: array sizes do not match, or destination array is too small +""" +} diff --git a/source/compiler/tests/warning_047.pwn b/source/compiler/tests/error_047.pwn similarity index 100% rename from source/compiler/tests/warning_047.pwn rename to source/compiler/tests/error_047.pwn diff --git a/source/compiler/tests/warning_047.meta b/source/compiler/tests/warning_047.meta deleted file mode 100644 index 5a81f5e..0000000 --- a/source/compiler/tests/warning_047.meta +++ /dev/null @@ -1,6 +0,0 @@ -{ - 'test_type': 'output_check', - 'errors': """ -warning_047.pwn(8) : error 047: array sizes do not match, or destination array is too small -""" -} From 4a4ba1e8b9eda4b3c4873e17ea862c4586510220 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sat, 14 Nov 2020 18:43:44 +0700 Subject: [PATCH 10/21] Fix the character conversion loop relying on a 4-byte cell size --- source/compiler/sc1.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 5c08a99..aa952d0 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -8331,22 +8331,26 @@ static void dopragma(void) #if BYTE_ORDER==LITTLE_ENDIAN { /* local */ char *bytes; - i=0; + i=(int)val; do { char t; - bytes=(char *)&litq[val+i]; - i++; - #if PAWN_CELL_SIZE>=16 - t=bytes[0], bytes[0]=bytes[sizeof(cell)-1], bytes[sizeof(cell)-1]=t; - #if PAWN_CELL_SIZE>=32 + bytes=(char *)&litq[i++]; + t=bytes[0], bytes[0]=bytes[sizeof(cell)-1], bytes[sizeof(cell)-1]=t; +#if PAWN_CELL_SIZE>=32 t=bytes[1], bytes[1]=bytes[sizeof(cell)-2], bytes[sizeof(cell)-2]=t; - #if PAWN_CELL_SIZE==64 +#if PAWN_CELL_SIZE==64 t=bytes[2], bytes[2]=bytes[sizeof(cell)-3], bytes[sizeof(cell)-3]=t; t=bytes[3], bytes[3]=bytes[sizeof(cell)-4], bytes[sizeof(cell)-4]=t; - #endif // PAWN_CELL_SIZE==64 - #endif // PAWN_CELL_SIZE==32 - #endif // PAWN_CELL_SIZE==16 - } while (bytes[0]!='\0' && bytes[1]!='\0' && bytes[2]!='\0' && bytes[3]!='\0'); +#endif // PAWN_CELL_SIZE==64 +#endif // PAWN_CELL_SIZE>=32 + } while (bytes[0]!='\0' && bytes[1]!='\0' +#if PAWN_CELL_SIZE>=32 + && bytes[2]!='\0' && bytes[3]!='\0' +#if PAWN_CELL_SIZE==64 + && bytes[4]!='\0' && bytes[5]!='\0' && bytes[6]!='\0' && bytes[7]!='\0' +#endif // PAWN_CELL_SIZE==64 +#endif // PAWN_CELL_SIZE>=32 + ); /* do */ } /* local */ #endif From 3a9cfd8e466262d09f0305f8d903de2bbeed4eb3 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sat, 14 Nov 2020 20:41:45 +0700 Subject: [PATCH 11/21] __pragma: Check if the option string is packed/unpacked in a more reliable way --- source/compiler/sc.h | 1 + source/compiler/sc1.c | 11 ++++------- source/compiler/sc2.c | 2 ++ source/compiler/scvars.c | 1 + 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index a2f7936..7b151c4 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -1009,6 +1009,7 @@ SC_VDECL int pc_retexpr; /* true if the current expression is a part of a " SC_VDECL int pc_retheap; /* heap space (in bytes) to be manually freed when returning an array returned by another function */ SC_VDECL int pc_nestlevel; /* number of active (open) compound statements */ SC_VDECL unsigned int pc_attributes;/* currently set attribute flags (for the "__pragma" operator) */ +SC_VDECL int pc_ispackedstr; /* true if the last tokenized string is packed */ SC_VDECL char *sc_tokens[]; diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index aa952d0..ca0a1c4 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -8308,8 +8308,11 @@ static void dopragma(void) do { /* read the option string */ tok=lex(&val,&str); - if (tok!=tSTRING) { + if (tok!=tSTRING || !pc_ispackedstr) { + /* either not a string, or the user prepended "!" to the option string */ char tokstr[2]; + if (tok==tSTRING) + tok='!'; if (tokbck_litidx); - /* the user shouldn't prepend "!" to the option string */ - if (litq[val]<=UNPACKEDMAX && litq[val]!=0) { - error(1,sc_tokens[tSTRING-tFIRST],"!"); - goto next; - } /* if */ - /* swap the cell bytes if we're on a Little Endian platform */ #if BYTE_ORDER==LITTLE_ENDIAN { /* local */ diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 7888e5c..fdb2df9 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -2415,6 +2415,7 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym) if ((stringflags & RAWMODE)!=0) lptr+=1; /* skip "escape" character too */ lptr=sc_packstr ? packedstring(lptr,&stringflags) : unpackedstring(lptr,&stringflags); + pc_ispackedstr=sc_packstr; if (*lptr=='\"') lptr+=1; /* skip final quote */ else if (!(stringflags & STRINGIZE)) @@ -2441,6 +2442,7 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym) if ((stringflags & RAWMODE)!=0) lptr+=1; /* skip "escape" character too */ lptr=sc_packstr ? unpackedstring(lptr,&stringflags) : packedstring(lptr,&stringflags); + pc_ispackedstr=!sc_packstr; if (*lptr=='\"') lptr+=1; /* skip final quote */ else if (!(stringflags & STRINGIZE)) diff --git a/source/compiler/scvars.c b/source/compiler/scvars.c index 41115ce..53158ad 100644 --- a/source/compiler/scvars.c +++ b/source/compiler/scvars.c @@ -102,6 +102,7 @@ SC_VDEFINE int pc_retexpr=FALSE; /* true if the current expression is SC_VDEFINE int pc_retheap=0; /* heap space (in bytes) to be manually freed when returning an array returned by another function */ SC_VDEFINE int pc_nestlevel=0; /* number of active (open) compound statements */ SC_VDEFINE unsigned int pc_attributes=0; /* currently set attribute flags (for the "__pragma" operator) */ +SC_VDEFINE int pc_ispackedstr=FALSE; /* true if the last tokenized string is packed */ SC_VDEFINE char *sc_tokens[] = { "*=", "/=", "%=", "+=", "-=", "<<=", ">>>=", ">>=", "&=", "^=", "|=", From dc789353fd0c1fe9b896623ce10c0c8d50db7f9c Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sun, 15 Nov 2020 02:23:42 +0700 Subject: [PATCH 12/21] Use `duplicatestring()` instead of `strdup()` --- source/compiler/sc1.c | 2 +- source/compiler/sc2.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index ca0a1c4..b7fc74f 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -8365,7 +8365,7 @@ static void dopragma(void) * and parse the argument(s), if needed */ if (!strcmp(str,"deprecated")) { free(pc_deprecate); - pc_deprecate=strdup(&str[i]); + pc_deprecate=duplicatestring(&str[i]); if (pc_deprecate==NULL) error(103); /* insufficient memory */ pc_attributes |= (1U << attrDEPRECATED); diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index fdb2df9..cac5fbc 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1010,7 +1010,7 @@ static const unsigned char *getstring(unsigned char *dest,int max,const unsigned */ static char* strdupwithouta(const char* sourcestring) { - char* result=strdup(sourcestring); + char* result=duplicatestring(sourcestring); char* a=result; if (result==NULL) { return NULL; From 67a5cabb3ce948bcee72b269cd047ee39da9fe2e Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 19 Nov 2020 20:26:39 +0700 Subject: [PATCH 13/21] Fix clang warnings --- source/compiler/sc1.c | 5 +++-- source/compiler/sc2.c | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index b7fc74f..9b30d31 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -5674,7 +5674,7 @@ static void compound(int stmt_sameline,int starttok) error(30,block_start); /* compound block not closed at end of file */ break; } else { - if (count_stmt>0 && isterminal(lastst)) + if (count_stmt>0 && isterminal(lastst)) { if (matchtoken(tLABEL)) { cell val; char *name; @@ -5684,12 +5684,13 @@ static void compound(int stmt_sameline,int starttok) sym=findloc(name); /* before issuing a warning, check if the label was previously used (via 'goto') */ if (sym!=NULL && sym->ident==iLABEL && (sym->usage & uREAD)==0) - error(225); /* unreachable code */ + error(225); /* unreachable code */ } else if (lastst==tTERMSWITCH && matchtoken(tRETURN)) { lexpush(); /* push the token so it can be analyzed later */ } else { error(225); /* unreachable code */ } /* if */ + } /* if */ statement(&indent,TRUE); /* do a statement */ count_stmt++; } /* if */ diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index cac5fbc..99c5a1b 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -457,7 +457,7 @@ static void readline(unsigned char *line) * ends with the same multiline string, so that this won't trigger commands: * * new x[] = "Hello - * + * * #define X 0 * "; * @@ -608,9 +608,9 @@ static int stripcomment(unsigned char *line) } else { if (incommand==2 && *line>' ') { /* line starting a command, may need raw strings */ - if (strncmp(line, "#error", 6)==0 || - strncmp(line, "#warning", 8)==0 || - strncmp(line, "#pragma", 7)==0) { + if (strncmp((char*)line,"#error",6)==0 || + strncmp((char*)line,"#warning",8)==0 || + strncmp((char*)line,"#pragma",7)==0) { /* is one of the pre-processor commands with pure raw strings */ incommand=1; } else { From 55d89321a0c3ff29fdba3f89f797b16c2510b3c0 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sun, 6 Dec 2020 20:11:20 +0700 Subject: [PATCH 14/21] Indentation fix --- source/compiler/sc2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 99c5a1b..7fbf72c 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -2405,7 +2405,7 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym) error(220); } /* if */ } /* if */ - } else if (*lptr=='\"' || *lptr=='#' || (*lptr==sc_ctrlchar && (*(lptr+1)=='\"' || *(lptr+1)=='#'))) + } else if (*lptr=='\"' || *lptr=='#' || (*lptr==sc_ctrlchar && (*(lptr+1)=='\"' || *(lptr+1)=='#'))) { /* unpacked string literal */ _lextok=tSTRING; stringflags=(*lptr==sc_ctrlchar) ? RAWMODE : 0; From 98c521793e28054722a8fc0007d4f68d28e94c51 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sun, 6 Dec 2020 20:41:52 +0700 Subject: [PATCH 15/21] Fix potential NULL pointer dereferences --- source/compiler/memfile.c | 5 +++++ source/compiler/sclist.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/source/compiler/memfile.c b/source/compiler/memfile.c index 4307589..71fa50f 100644 --- a/source/compiler/memfile.c +++ b/source/compiler/memfile.c @@ -32,6 +32,11 @@ memfile_t *memfile_creat(const char *name, size_t init) mf.offs = 0; pmf = (memfile_t *)malloc(sizeof(memfile_t)); + if (!pmf) + { + free(mf.base); + return NULL; + } memcpy(pmf, &mf, sizeof(memfile_t)); pmf->name = strdup(name); diff --git a/source/compiler/sclist.c b/source/compiler/sclist.c index 516a276..f15ddd5 100644 --- a/source/compiler/sclist.c +++ b/source/compiler/sclist.c @@ -44,7 +44,8 @@ SC_FUNC char* duplicatestring(const char* sourcestring) { char* result=(char*)malloc(strlen(sourcestring)+1); - strcpy(result,sourcestring); + if (result!=NULL) + strcpy(result,sourcestring); return result; } From a68bacf86ead58bdf3060d7d3745a307bc4909ee Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sun, 6 Dec 2020 21:49:51 +0700 Subject: [PATCH 16/21] Remove unreachable `return` statements --- source/compiler/sc2.c | 8 ++------ source/compiler/sc7.c | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 7fbf72c..2de0832 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -3000,10 +3000,8 @@ static symbol *add_symbol(symbol *root,symbol *entry,int sort) while (root->next!=NULL && strcmp(entry->name,root->next->name)>0) root=root->next; - if ((newsym=(symbol *)malloc(sizeof(symbol)))==NULL) { + if ((newsym=(symbol *)malloc(sizeof(symbol)))==NULL) error(103); - return NULL; - } /* if */ memcpy(newsym,entry,sizeof(symbol)); newsym->next=root->next; root->next=newsym; @@ -3453,10 +3451,8 @@ SC_FUNC symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag,i assert(ident!=iLABEL || findloc(name)==NULL); /* create an empty referrer list */ - if ((refer=(symbol**)malloc(sizeof(symbol*)))==NULL) { + if ((refer=(symbol**)malloc(sizeof(symbol*)))==NULL) error(103); /* insufficient memory */ - return NULL; - } /* if */ *refer=NULL; /* first fill in the entry */ diff --git a/source/compiler/sc7.c b/source/compiler/sc7.c index 5b2c454..b0855f5 100644 --- a/source/compiler/sc7.c +++ b/source/compiler/sc7.c @@ -1699,10 +1699,8 @@ static char *replacesequence(char *pattern,char symbols[MAX_OPT_VARS][MAX_ALIAS+ } /* while */ /* allocate a buffer to replace the sequence in */ - if ((buffer=(char*)malloc(*repl_length))==NULL) { + if ((buffer=(char*)malloc(*repl_length))==NULL) error(103); - return NULL; - } /* if */ /* replace the pattern into this temporary buffer */ lptr=buffer; From a1165ace5410496f1a3b92c7e3ee0f90f1f84e42 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sun, 3 Jan 2021 17:05:28 +0700 Subject: [PATCH 17/21] Fix the use of `0` instead of `FALSE` --- source/compiler/sc1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 9b30d31..8ffe87e 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -5044,7 +5044,7 @@ static long max_stacksize(symbol *root,int *recursion) maxsize=0; maxparams=0; - *recursion=0; /* assume no recursion */ + *recursion=FALSE; /* assume no recursion */ for (sym=root->next; sym!=NULL; sym=sym->next) { int recursion_detected; /* drop out if this is not a user-implemented function */ From deec15fcc94507b6c74ec31a39cf1b0263cc128a Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sun, 3 Jan 2021 17:07:55 +0700 Subject: [PATCH 18/21] Turn array-size-related assertions into compile-time checks --- source/compiler/sc3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/compiler/sc3.c b/source/compiler/sc3.c index a76c3b0..3ec6141 100644 --- a/source/compiler/sc3.c +++ b/source/compiler/sc3.c @@ -146,7 +146,7 @@ static void (*unopers[])(void) = { lneg, neg, user_inc, user_dec }; if (lval!=NULL && (lval->ident==iARRAYCELL || lval->ident==iARRAYCHAR)) savealt=TRUE; } else { - assert( arraysize(binoperstr) == arraysize(op1) ); + assert_static( arraysize(binoperstr) == arraysize(op1) ); for (i=0; i Date: Tue, 5 Jan 2021 13:36:16 +0700 Subject: [PATCH 19/21] Remove the description for already removed flag "uPREDEF" --- source/compiler/sc.h | 1 - 1 file changed, 1 deletion(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index 7b151c4..a88290d 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -203,7 +203,6 @@ typedef struct s_symbol { * bits: 0 (uDEFINE) the symbol is defined in the source file * 1 (uREAD) the constant is "read" (accessed) in the source file * 2 (uWRITTEN) redundant, but may be set for constants passed by reference - * 3 (uPREDEF) the constant is pre-defined and should be kept between passes * 5 (uENUMROOT) the constant is the "root" of an enumeration * 6 (uENUMFIELD) the constant is a field in a named enumeration */ From 3b04173d83e06abcd3b6f4b93e4de35d0a31a742 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 8 Jan 2021 18:19:54 +0700 Subject: [PATCH 20/21] Fix typo in the description for `constvalue::index` --- source/compiler/sc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index a88290d..483ac31 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -97,7 +97,7 @@ typedef struct s_constvalue { char name[sNAMEMAX+1]; cell value; int index; /* index level, for constants referring to array sizes/tags - * automaton id. for states and automatons + * automaton id, for states and automatons * tag for enumeration lists */ } constvalue; From 05dcdc151be7336e690fbf56691e5853024c5b8f Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sat, 13 Mar 2021 19:48:48 +0700 Subject: [PATCH 21/21] Fix misleading closing comments --- source/compiler/sc1.c | 12 ++++++------ source/compiler/sc2.c | 4 ++-- source/compiler/sc3.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 8ffe87e..3ed634f 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -2812,7 +2812,7 @@ static cell initvector(int ident,int tag,cell size,int startlit,int fillzero, if (!matchtoken(',')) { needtoken('}'); break; - } /* for */ + } /* if */ } /* for */ /* if this array is based on an enumeration, fill the "field" up with * zeros, and toggle the tag @@ -4202,7 +4202,7 @@ static int declargs(symbol *sym,int chkshadow) if (matchtoken('}')) break; needtoken(','); - } /* for */ + } /* while */ needtoken(':'); tok=tLABEL; /* for outer loop: flag that we have seen a tagname */ break; @@ -5033,7 +5033,7 @@ static long max_stacksize(symbol *root,int *recursion) if ((sym->usage & uNATIVE)==0) numfunctions++; } /* if */ - } /* if */ + } /* for */ /* allocate function symbol stack */ symstack=(symbol **)malloc((numfunctions+1)*sizeof(symbol*)); rsymstack=(symbol **)malloc((numfunctions+1)*sizeof(symbol*)); @@ -5163,7 +5163,7 @@ static int testsymbols(symbol *root,int level,int testlabs,int testconst) /* also mark the variable (local or global) to the debug information */ if ((sym->usage & (uWRITTEN | uREAD))!=0 && (sym->usage & uNATIVE)==0) insert_dbgsymbol(sym); - } /* if */ + } /* switch */ sym=sym->next; } /* while */ @@ -6206,7 +6206,7 @@ static int doswitch(void) error(40,val); /* duplicate "case" label */ assert(csp==NULL || csp->next==cse); insert_constval(csp,cse,itoh(lbl_case),val,0); - } /* if */ + } /* while */ } /* if */ } while (matchtoken(',')); needtoken(':'); /* ':' ends the case */ @@ -6264,7 +6264,7 @@ static int doswitch(void) errorset(sSETPOS,save_fline); error(244,cur->name); /* enum element not handled in switch */ errorset(sSETPOS,-1); - } /* while */ + } /* for */ } /* if */ #if !defined NDEBUG diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 2de0832..18d8f30 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -250,7 +250,7 @@ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths) strlcpy(path,ptr,arraysize(path)); strlcat(path,name,arraysize(path)); result=plungequalifiedfile(path); - } /* while */ + } /* for */ } /* if */ return result; } @@ -992,7 +992,7 @@ static const unsigned char *getstring(unsigned char *dest,int max,const unsigned if (len 0) { sym=sym->child; assert(sym!=NULL); - } /* if */ + } /* while */ return sym->dim.array.length; } @@ -1439,7 +1439,7 @@ static int hier2(value *lval) offsmul*=subsym->dim.array.length; arrayidx*=arrayidx*subsym->dim.array.length; subsym=subsym->child; - } /* if */ + } /* while */ lval->constval+=(numoffsets-1+arrayidx)*(cell)sizeof(cell); ldconst(lval->constval,sPRI); } /* if */