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/sc.h b/source/compiler/sc.h index 15cbd87..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; @@ -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 */ @@ -213,7 +212,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 @@ -741,7 +739,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, @@ -1011,6 +1008,9 @@ 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[]; 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..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 @@ -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; @@ -3089,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); @@ -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; @@ -4139,7 +4137,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; @@ -4205,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; @@ -5036,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*)); @@ -5047,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 */ @@ -5150,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" */ @@ -5167,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 */ @@ -5182,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) @@ -5615,7 +5611,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; @@ -5679,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; @@ -5689,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 */ @@ -6210,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 */ @@ -6250,26 +6246,25 @@ 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 */ + } /* for */ } /* if */ #if !defined NDEBUG @@ -6429,7 +6424,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 +6791,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 +6975,6 @@ fetchtok: negate=TRUE; goto fetchtok; } else { - extern char *sc_tokens[]; char ival[sNAMEMAX+2]; invalid_token_neg: if (tokchild; assert(sub==NULL || sub->ident==iREFARRAY); if ((rettype & uRETVALUE)!=0) { int retarray=(ident==iARRAY || ident==iREFARRAY); @@ -7982,8 +7972,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 @@ -8004,7 +7994,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 */ @@ -8296,7 +8286,6 @@ static int *readwhile(void) static void dopragma(void) { - extern char *sc_tokens[]; int tok; int bck_litidx,bck_packstr; int i; @@ -8320,45 +8309,46 @@ 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 */ 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 @@ -8376,7 +8366,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); @@ -8406,7 +8396,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); diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index aeb6029..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; } @@ -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) @@ -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 { @@ -992,7 +992,7 @@ static const unsigned char *getstring(unsigned char *dest,int max,const unsigned if (len0) 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 */ @@ -1495,7 +1489,6 @@ static int command(void) } /* if */ break; default: { - extern char *sc_tokens[];/* forward declaration */ char s2[33]="-"; if ((char)tok=='-') { int current_token=lex(&val,&str); @@ -2298,24 +2291,6 @@ SC_FUNC void lexinit(void) _lexnewline=FALSE; } -char *sc_tokens[] = { - "*=", "/=", "%=", "+=", "-=", "<<=", ">>>=", ">>=", "&=", "^=", "|=", - "||", "&&", "==", "!=", "<=", ">=", "<<", ">>>", ">>", "++", "--", - "...", "..", - "__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; @@ -2430,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; @@ -2440,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)) @@ -2466,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)) @@ -3023,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; @@ -3145,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 @@ -3247,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. @@ -3470,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, @@ -3493,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/sc3.c b/source/compiler/sc3.c index f54c545..8d8b03c 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; iident==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<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,9 +832,9 @@ 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 */ + } /* while */ return sym->dim.array.length; } @@ -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), @@ -1063,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 @@ -1362,7 +1361,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('(')) @@ -1430,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 */ @@ -1440,8 +1438,8 @@ static int hier2(value *lval) numoffsets+=offsmul; offsmul*=subsym->dim.array.length; arrayidx*=arrayidx*subsym->dim.array.length; - subsym=finddepend(subsym); - } /* if */ + subsym=subsym->child; + } /* while */ lval->constval+=(numoffsets-1+arrayidx)*(cell)sizeof(cell); ldconst(lval->constval,sPRI); } /* if */ @@ -1543,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 */ @@ -1595,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 */ @@ -1790,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; @@ -1877,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; @@ -2081,7 +2079,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 */ @@ -2197,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; @@ -2453,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/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 (tMIDDLEchild) { assert(sub->dim.array.level==count--); sprintf(string+strlen(string),"%x:%x ",sub->x.tags.index,sub->dim.array.length); } /* for */ diff --git a/source/compiler/scvars.c b/source/compiler/scvars.c index 7afb577..53158ad 100644 --- a/source/compiler/scvars.c +++ b/source/compiler/scvars.c @@ -102,6 +102,25 @@ 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[] = { + "*=", "/=", "%=", "+=", "-=", "<<=", ">>>=", ">>=", "&=", "^=", "|=", + "||", "&&", "==", "!=", "<=", ">=", "<<", ">>>", ">>", "++", "--", + "...", "..", + "__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 */ 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 -""" -}