Merge remote-tracking branch 'remotes/Daniel-Cortez/misc-fixes' into dev
This commit is contained in:
commit
e97a67a226
@ -32,6 +32,11 @@ memfile_t *memfile_creat(const char *name, size_t init)
|
|||||||
mf.offs = 0;
|
mf.offs = 0;
|
||||||
|
|
||||||
pmf = (memfile_t *)malloc(sizeof(memfile_t));
|
pmf = (memfile_t *)malloc(sizeof(memfile_t));
|
||||||
|
if (!pmf)
|
||||||
|
{
|
||||||
|
free(mf.base);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
memcpy(pmf, &mf, sizeof(memfile_t));
|
memcpy(pmf, &mf, sizeof(memfile_t));
|
||||||
|
|
||||||
pmf->name = strdup(name);
|
pmf->name = strdup(name);
|
||||||
|
@ -97,7 +97,7 @@ typedef struct s_constvalue {
|
|||||||
char name[sNAMEMAX+1];
|
char name[sNAMEMAX+1];
|
||||||
cell value;
|
cell value;
|
||||||
int index; /* index level, for constants referring to array sizes/tags
|
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 */
|
* tag for enumeration lists */
|
||||||
} constvalue;
|
} constvalue;
|
||||||
|
|
||||||
@ -203,7 +203,6 @@ typedef struct s_symbol {
|
|||||||
* bits: 0 (uDEFINE) the symbol is defined in the source file
|
* bits: 0 (uDEFINE) the symbol is defined in the source file
|
||||||
* 1 (uREAD) the constant is "read" (accessed) 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
|
* 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
|
* 5 (uENUMROOT) the constant is the "root" of an enumeration
|
||||||
* 6 (uENUMFIELD) the constant is a field in a named 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 uRETVALUE 0x004 /* function returns (or should return) a value */
|
||||||
#define uCONST 0x008
|
#define uCONST 0x008
|
||||||
#define uPROTOTYPED 0x008
|
#define uPROTOTYPED 0x008
|
||||||
#define uPREDEF 0x008 /* constant is pre-defined */
|
|
||||||
#define uPUBLIC 0x010
|
#define uPUBLIC 0x010
|
||||||
#define uNATIVE 0x020
|
#define uNATIVE 0x020
|
||||||
#define uENUMROOT 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 *findglb(const char *name,int filter);
|
||||||
SC_FUNC symbol *findloc(const char *name);
|
SC_FUNC symbol *findloc(const char *name);
|
||||||
SC_FUNC symbol *findconst(const char *name,int *cmptag);
|
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,
|
SC_FUNC symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag,
|
||||||
int usage);
|
int usage);
|
||||||
SC_FUNC symbol *addvariable(const char *name,cell addr,int ident,int vclass,int tag,
|
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_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 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 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_automaton_tab; /* automaton table */
|
||||||
SC_VDECL constvalue_root sc_state_tab; /* state table */
|
SC_VDECL constvalue_root sc_state_tab; /* state table */
|
||||||
|
@ -2812,7 +2812,7 @@ static cell initvector(int ident,int tag,cell size,int startlit,int fillzero,
|
|||||||
if (!matchtoken(',')) {
|
if (!matchtoken(',')) {
|
||||||
needtoken('}');
|
needtoken('}');
|
||||||
break;
|
break;
|
||||||
} /* for */
|
} /* if */
|
||||||
} /* for */
|
} /* for */
|
||||||
/* if this array is based on an enumeration, fill the "field" up with
|
/* if this array is based on an enumeration, fill the "field" up with
|
||||||
* zeros, and toggle the tag
|
* zeros, and toggle the tag
|
||||||
@ -2972,7 +2972,6 @@ static void decl_const(int vclass)
|
|||||||
*/
|
*/
|
||||||
static void decl_enum(int vclass,int fstatic)
|
static void decl_enum(int vclass,int fstatic)
|
||||||
{
|
{
|
||||||
extern const char *sc_tokens[];
|
|
||||||
char enumname[sNAMEMAX+1],constname[sNAMEMAX+1];
|
char enumname[sNAMEMAX+1],constname[sNAMEMAX+1];
|
||||||
cell val,value,size;
|
cell val,value,size;
|
||||||
char *str;
|
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 */
|
/* don't reset "warn_overflow" yet, we'll need to use it later */
|
||||||
} /* if */
|
} /* if */
|
||||||
if (warn_noeffect) {
|
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);
|
errorset(sSETPOS,noeffect_sym->lnumber);
|
||||||
error(245,str,increment,name); /* enum increment has no effect on zero value */
|
error(245,str,increment,name); /* enum increment has no effect on zero value */
|
||||||
errorset(sSETPOS,-1);
|
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) {
|
&& (lvar=findloc(sym->dim.arglist[i].name))!=NULL) {
|
||||||
if ((sym->dim.arglist[i].usage & uWRITTEN)==0) {
|
if ((sym->dim.arglist[i].usage & uWRITTEN)==0) {
|
||||||
/* check if the argument was written in this definition */
|
/* check if the argument was written in this definition */
|
||||||
depend=lvar;
|
for (depend=lvar; depend!=NULL; depend=depend->child) {
|
||||||
while (depend!=NULL) {
|
|
||||||
if ((depend->usage & uWRITTEN)!=0) {
|
if ((depend->usage & uWRITTEN)!=0) {
|
||||||
sym->dim.arglist[i].usage|=depend->usage & uWRITTEN;
|
sym->dim.arglist[i].usage|=depend->usage & uWRITTEN;
|
||||||
break;
|
break;
|
||||||
}
|
} /* if */
|
||||||
depend=finddepend(depend);
|
} /* for */
|
||||||
} /* while */
|
|
||||||
} /* if */
|
} /* if */
|
||||||
/* mark argument as written if it was written in another definition */
|
/* mark argument as written if it was written in another definition */
|
||||||
lvar->usage|=sym->dim.arglist[i].usage & uWRITTEN;
|
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)
|
static int declargs(symbol *sym,int chkshadow)
|
||||||
{
|
{
|
||||||
#define MAXTAGS 16
|
#define MAXTAGS 16
|
||||||
extern char* sc_tokens[];
|
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int argcnt,oldargcnt,tok,tags[MAXTAGS],numtags;
|
int argcnt,oldargcnt,tok,tags[MAXTAGS],numtags;
|
||||||
cell val;
|
cell val;
|
||||||
@ -4205,7 +4202,7 @@ static int declargs(symbol *sym,int chkshadow)
|
|||||||
if (matchtoken('}'))
|
if (matchtoken('}'))
|
||||||
break;
|
break;
|
||||||
needtoken(',');
|
needtoken(',');
|
||||||
} /* for */
|
} /* while */
|
||||||
needtoken(':');
|
needtoken(':');
|
||||||
tok=tLABEL; /* for outer loop: flag that we have seen a tagname */
|
tok=tLABEL; /* for outer loop: flag that we have seen a tagname */
|
||||||
break;
|
break;
|
||||||
@ -5036,7 +5033,7 @@ static long max_stacksize(symbol *root,int *recursion)
|
|||||||
if ((sym->usage & uNATIVE)==0)
|
if ((sym->usage & uNATIVE)==0)
|
||||||
numfunctions++;
|
numfunctions++;
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* for */
|
||||||
/* allocate function symbol stack */
|
/* allocate function symbol stack */
|
||||||
symstack=(symbol **)malloc((numfunctions+1)*sizeof(symbol*));
|
symstack=(symbol **)malloc((numfunctions+1)*sizeof(symbol*));
|
||||||
rsymstack=(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;
|
maxsize=0;
|
||||||
maxparams=0;
|
maxparams=0;
|
||||||
*recursion=0; /* assume no recursion */
|
*recursion=FALSE; /* assume no recursion */
|
||||||
for (sym=root->next; sym!=NULL; sym=sym->next) {
|
for (sym=root->next; sym!=NULL; sym=sym->next) {
|
||||||
int recursion_detected;
|
int recursion_detected;
|
||||||
/* drop out if this is not a user-implemented function */
|
/* 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);
|
errorset(sSETPOS,-1);
|
||||||
} else if ((sym->usage & (uWRITTEN | uPUBLIC | uCONST))==0 && sym->ident==iREFARRAY) {
|
} else if ((sym->usage & (uWRITTEN | uPUBLIC | uCONST))==0 && sym->ident==iREFARRAY) {
|
||||||
int warn = TRUE;
|
int warn = TRUE;
|
||||||
symbol* depend = finddepend(sym);
|
symbol *depend;
|
||||||
while (depend != NULL) {
|
for (depend=sym->child; depend!=NULL; depend=depend->child) {
|
||||||
if ((depend->usage & (uWRITTEN | uPUBLIC | uCONST)) != 0) {
|
if ((depend->usage & (uWRITTEN | uPUBLIC | uCONST))!=0) {
|
||||||
warn = FALSE;
|
warn=FALSE;
|
||||||
break;
|
break;
|
||||||
}
|
} /* if */
|
||||||
depend = finddepend(depend);
|
} /* for */
|
||||||
} /* while */
|
|
||||||
if (warn) {
|
if (warn) {
|
||||||
errorset(sSETPOS, sym->lnumber);
|
errorset(sSETPOS, sym->lnumber);
|
||||||
error(214, sym->name); /* make array argument "const" */
|
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 */
|
/* also mark the variable (local or global) to the debug information */
|
||||||
if ((sym->usage & (uWRITTEN | uREAD))!=0 && (sym->usage & uNATIVE)==0)
|
if ((sym->usage & (uWRITTEN | uREAD))!=0 && (sym->usage & uNATIVE)==0)
|
||||||
insert_dbgsymbol(sym);
|
insert_dbgsymbol(sym);
|
||||||
} /* if */
|
} /* switch */
|
||||||
sym=sym->next;
|
sym=sym->next;
|
||||||
} /* while */
|
} /* while */
|
||||||
|
|
||||||
@ -5182,7 +5178,7 @@ static cell calc_array_datasize(symbol *sym, cell *offset)
|
|||||||
assert(sym->ident==iARRAY || sym->ident==iREFARRAY);
|
assert(sym->ident==iARRAY || sym->ident==iREFARRAY);
|
||||||
length=sym->dim.array.length;
|
length=sym->dim.array.length;
|
||||||
if (sym->dim.array.level > 0) {
|
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)
|
if (offset!=NULL)
|
||||||
*offset=length*(*offset+sizeof(cell));
|
*offset=length*(*offset+sizeof(cell));
|
||||||
if (sublength>0)
|
if (sublength>0)
|
||||||
@ -5615,7 +5611,6 @@ static void statement(int *lastindent,int allow_decl)
|
|||||||
pragma_apply(curfunc);
|
pragma_apply(curfunc);
|
||||||
break;
|
break;
|
||||||
case t__EMIT: {
|
case t__EMIT: {
|
||||||
extern char *sc_tokens[];
|
|
||||||
const unsigned char *bck_lptr=lptr-strlen(sc_tokens[tok-tFIRST]);
|
const unsigned char *bck_lptr=lptr-strlen(sc_tokens[tok-tFIRST]);
|
||||||
if (matchtoken('{')) {
|
if (matchtoken('{')) {
|
||||||
emit_flags |= efBLOCK;
|
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 */
|
error(30,block_start); /* compound block not closed at end of file */
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if (count_stmt>0 && isterminal(lastst))
|
if (count_stmt>0 && isterminal(lastst)) {
|
||||||
if (matchtoken(tLABEL)) {
|
if (matchtoken(tLABEL)) {
|
||||||
cell val;
|
cell val;
|
||||||
char *name;
|
char *name;
|
||||||
@ -5689,12 +5684,13 @@ static void compound(int stmt_sameline,int starttok)
|
|||||||
sym=findloc(name);
|
sym=findloc(name);
|
||||||
/* before issuing a warning, check if the label was previously used (via 'goto') */
|
/* before issuing a warning, check if the label was previously used (via 'goto') */
|
||||||
if (sym!=NULL && sym->ident==iLABEL && (sym->usage & uREAD)==0)
|
if (sym!=NULL && sym->ident==iLABEL && (sym->usage & uREAD)==0)
|
||||||
error(225); /* unreachable code */
|
error(225); /* unreachable code */
|
||||||
} else if (lastst==tTERMSWITCH && matchtoken(tRETURN)) {
|
} else if (lastst==tTERMSWITCH && matchtoken(tRETURN)) {
|
||||||
lexpush(); /* push the token so it can be analyzed later */
|
lexpush(); /* push the token so it can be analyzed later */
|
||||||
} else {
|
} else {
|
||||||
error(225); /* unreachable code */
|
error(225); /* unreachable code */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
} /* if */
|
||||||
statement(&indent,TRUE); /* do a statement */
|
statement(&indent,TRUE); /* do a statement */
|
||||||
count_stmt++;
|
count_stmt++;
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -6210,7 +6206,7 @@ static int doswitch(void)
|
|||||||
error(40,val); /* duplicate "case" label */
|
error(40,val); /* duplicate "case" label */
|
||||||
assert(csp==NULL || csp->next==cse);
|
assert(csp==NULL || csp->next==cse);
|
||||||
insert_constval(csp,cse,itoh(lbl_case),val,0);
|
insert_constval(csp,cse,itoh(lbl_case),val,0);
|
||||||
} /* if */
|
} /* while */
|
||||||
} /* if */
|
} /* if */
|
||||||
} while (matchtoken(','));
|
} while (matchtoken(','));
|
||||||
needtoken(':'); /* ':' ends the case */
|
needtoken(':'); /* ':' ends the case */
|
||||||
@ -6250,26 +6246,25 @@ static int doswitch(void)
|
|||||||
|
|
||||||
if (enumsym!=NULL && swdefault==FALSE && enumsym->x.tags.unique-enumsymcount<=2) {
|
if (enumsym!=NULL && swdefault==FALSE && enumsym->x.tags.unique-enumsymcount<=2) {
|
||||||
constvalue_root *enumlist=enumsym->dim.enumlist;
|
constvalue_root *enumlist=enumsym->dim.enumlist;
|
||||||
constvalue *val,*prev=NULL,*save_next=NULL;
|
constvalue *cur,*found,*prev=NULL,*save_next=NULL;
|
||||||
for (val=enumlist->first; val!=NULL; prev=val,val=val->next) {
|
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 multiple enum elements share the same value, we only want to count the first one */
|
||||||
if (prev!=NULL) {
|
if (prev!=NULL) {
|
||||||
/* see if there's another constvalue before the current one that has the same value */
|
/* see if there's another constvalue before the current one that has the same value */
|
||||||
constvalue *save_next=prev->next;
|
save_next=prev->next;
|
||||||
constvalue *found;
|
|
||||||
prev->next=NULL;
|
prev->next=NULL;
|
||||||
found=find_constval_byval(enumlist,val->value);
|
found=find_constval_byval(enumlist,cur->value);
|
||||||
prev->next=save_next;
|
prev->next=save_next;
|
||||||
if (found!=NULL)
|
if (found!=NULL)
|
||||||
continue;
|
continue;
|
||||||
} /* if */
|
} /* if */
|
||||||
/* check if the value of this constant is handled in switch, if so - continue */
|
/* 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;
|
continue;
|
||||||
errorset(sSETPOS,save_fline);
|
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);
|
errorset(sSETPOS,-1);
|
||||||
} /* while */
|
} /* for */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
#if !defined NDEBUG
|
#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)
|
static void SC_FASTCALL emit_invalid_token(int expected_token,int found_token)
|
||||||
{
|
{
|
||||||
extern char *sc_tokens[];
|
|
||||||
char s[2];
|
char s[2];
|
||||||
|
|
||||||
assert(expected_token>=tFIRST);
|
assert(expected_token>=tFIRST);
|
||||||
@ -6797,7 +6791,6 @@ fetchtok:
|
|||||||
negate=TRUE;
|
negate=TRUE;
|
||||||
goto fetchtok;
|
goto fetchtok;
|
||||||
} else {
|
} else {
|
||||||
extern char *sc_tokens[];
|
|
||||||
char ival[sNAMEMAX+2];
|
char ival[sNAMEMAX+2];
|
||||||
invalid_token_neg:
|
invalid_token_neg:
|
||||||
if (tok<tFIRST)
|
if (tok<tFIRST)
|
||||||
@ -6851,7 +6844,6 @@ static void SC_FASTCALL emit_param_nonneg(emit_outval *p)
|
|||||||
if (!emit_param_any_internal(p,teNONNEG,FALSE,TRUE))
|
if (!emit_param_any_internal(p,teNONNEG,FALSE,TRUE))
|
||||||
return;
|
return;
|
||||||
if ((cell)p->value.ucell<(cell)0) {
|
if ((cell)p->value.ucell<(cell)0) {
|
||||||
extern char *sc_tokens[];
|
|
||||||
#if PAWN_CELL_SIZE==16
|
#if PAWN_CELL_SIZE==16
|
||||||
char ival[7];
|
char ival[7];
|
||||||
#elif PAWN_CELL_SIZE==32
|
#elif PAWN_CELL_SIZE==32
|
||||||
@ -6983,7 +6975,6 @@ fetchtok:
|
|||||||
negate=TRUE;
|
negate=TRUE;
|
||||||
goto fetchtok;
|
goto fetchtok;
|
||||||
} else {
|
} else {
|
||||||
extern char *sc_tokens[];
|
|
||||||
char ival[sNAMEMAX+2];
|
char ival[sNAMEMAX+2];
|
||||||
invalid_token_neg:
|
invalid_token_neg:
|
||||||
if (tok<tFIRST)
|
if (tok<tFIRST)
|
||||||
@ -7828,7 +7819,6 @@ static int emit_findopcode(const char *instr)
|
|||||||
|
|
||||||
SC_FUNC void emit_parse_line(void)
|
SC_FUNC void emit_parse_line(void)
|
||||||
{
|
{
|
||||||
extern char *sc_tokens[];
|
|
||||||
cell val;
|
cell val;
|
||||||
char* st;
|
char* st;
|
||||||
int tok,len,i;
|
int tok,len,i;
|
||||||
@ -7950,7 +7940,7 @@ static void doreturn(void)
|
|||||||
error(225); /* unreachable code */
|
error(225); /* unreachable code */
|
||||||
/* see if this function already has a sub type (an array attached) */
|
/* see if this function already has a sub type (an array attached) */
|
||||||
assert(curfunc!=NULL);
|
assert(curfunc!=NULL);
|
||||||
sub=finddepend(curfunc);
|
sub=curfunc->child;
|
||||||
assert(sub==NULL || sub->ident==iREFARRAY);
|
assert(sub==NULL || sub->ident==iREFARRAY);
|
||||||
if ((rettype & uRETVALUE)!=0) {
|
if ((rettype & uRETVALUE)!=0) {
|
||||||
int retarray=(ident==iARRAY || ident==iREFARRAY);
|
int retarray=(ident==iARRAY || ident==iREFARRAY);
|
||||||
@ -7982,8 +7972,8 @@ static void doreturn(void)
|
|||||||
if (sym->dim.array.length!=dim[numdim])
|
if (sym->dim.array.length!=dim[numdim])
|
||||||
error(47); /* array sizes must match */
|
error(47); /* array sizes must match */
|
||||||
if (numdim<level) {
|
if (numdim<level) {
|
||||||
sym=finddepend(sym);
|
sym=sym->child;
|
||||||
sub=finddepend(sub);
|
sub=sub->child;
|
||||||
assert(sym!=NULL && sub!=NULL);
|
assert(sym!=NULL && sub!=NULL);
|
||||||
/* ^^^ both arrays have the same dimensions (this was checked
|
/* ^^^ both arrays have the same dimensions (this was checked
|
||||||
* earlier) so the dependend should always be found
|
* earlier) so the dependend should always be found
|
||||||
@ -8004,7 +7994,7 @@ static void doreturn(void)
|
|||||||
dim[numdim]=(int)sub->dim.array.length;
|
dim[numdim]=(int)sub->dim.array.length;
|
||||||
idxtag[numdim]=sub->x.tags.index;
|
idxtag[numdim]=sub->x.tags.index;
|
||||||
if (numdim<level) {
|
if (numdim<level) {
|
||||||
sub=finddepend(sub);
|
sub=sub->child;
|
||||||
assert(sub!=NULL);
|
assert(sub!=NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
/* check that all dimensions are known */
|
/* check that all dimensions are known */
|
||||||
@ -8296,7 +8286,6 @@ static int *readwhile(void)
|
|||||||
|
|
||||||
static void dopragma(void)
|
static void dopragma(void)
|
||||||
{
|
{
|
||||||
extern char *sc_tokens[];
|
|
||||||
int tok;
|
int tok;
|
||||||
int bck_litidx,bck_packstr;
|
int bck_litidx,bck_packstr;
|
||||||
int i;
|
int i;
|
||||||
@ -8320,45 +8309,46 @@ static void dopragma(void)
|
|||||||
do {
|
do {
|
||||||
/* read the option string */
|
/* read the option string */
|
||||||
tok=lex(&val,&str);
|
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];
|
char tokstr[2];
|
||||||
|
if (tok==tSTRING)
|
||||||
|
tok='!';
|
||||||
if (tok<tFIRST) {
|
if (tok<tFIRST) {
|
||||||
sprintf(tokstr,"%c",tok);
|
sprintf(tokstr,"%c",tok);
|
||||||
str=tokstr;
|
str=tokstr;
|
||||||
} else {
|
} else {
|
||||||
str=sc_tokens[tok-tBEGIN];
|
str=sc_tokens[tok-tFIRST];
|
||||||
} /* if */
|
} /* if */
|
||||||
error(1,sc_tokens[tSTRING-tFIRST],str);
|
error(1,sc_tokens[tSTRING-tFIRST],str);
|
||||||
goto next;
|
goto next;
|
||||||
} /* if */
|
} /* if */
|
||||||
assert(litidx>bck_litidx);
|
assert(litidx>bck_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 */
|
/* swap the cell bytes if we're on a Little Endian platform */
|
||||||
#if BYTE_ORDER==LITTLE_ENDIAN
|
#if BYTE_ORDER==LITTLE_ENDIAN
|
||||||
{ /* local */
|
{ /* local */
|
||||||
char *bytes;
|
char *bytes;
|
||||||
i=0;
|
i=(int)val;
|
||||||
do {
|
do {
|
||||||
char t;
|
char t;
|
||||||
bytes=(char *)&litq[val+i];
|
bytes=(char *)&litq[i++];
|
||||||
i++;
|
t=bytes[0], bytes[0]=bytes[sizeof(cell)-1], bytes[sizeof(cell)-1]=t;
|
||||||
#if PAWN_CELL_SIZE>=16
|
#if PAWN_CELL_SIZE>=32
|
||||||
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;
|
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[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;
|
t=bytes[3], bytes[3]=bytes[sizeof(cell)-4], bytes[sizeof(cell)-4]=t;
|
||||||
#endif // PAWN_CELL_SIZE==64
|
#endif // PAWN_CELL_SIZE==64
|
||||||
#endif // PAWN_CELL_SIZE==32
|
#endif // PAWN_CELL_SIZE>=32
|
||||||
#endif // PAWN_CELL_SIZE==16
|
} while (bytes[0]!='\0' && bytes[1]!='\0'
|
||||||
} while (bytes[0]!='\0' && bytes[1]!='\0' && bytes[2]!='\0' && bytes[3]!='\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 */
|
} /* local */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -8376,7 +8366,7 @@ static void dopragma(void)
|
|||||||
* and parse the argument(s), if needed */
|
* and parse the argument(s), if needed */
|
||||||
if (!strcmp(str,"deprecated")) {
|
if (!strcmp(str,"deprecated")) {
|
||||||
free(pc_deprecate);
|
free(pc_deprecate);
|
||||||
pc_deprecate=strdup(&str[i]);
|
pc_deprecate=duplicatestring(&str[i]);
|
||||||
if (pc_deprecate==NULL)
|
if (pc_deprecate==NULL)
|
||||||
error(103); /* insufficient memory */
|
error(103); /* insufficient memory */
|
||||||
pc_attributes |= (1U << attrDEPRECATED);
|
pc_attributes |= (1U << attrDEPRECATED);
|
||||||
@ -8406,7 +8396,7 @@ static void dopragma(void)
|
|||||||
/* nothing */;
|
/* nothing */;
|
||||||
} /* if */
|
} /* if */
|
||||||
if (strcmp(str,"enable")==0 || strcmp(str,"disable")==0) {
|
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)
|
if (len==0)
|
||||||
goto unknown_pragma;
|
goto unknown_pragma;
|
||||||
pc_enablewarning((int)val,(str[0]=='e') ? warnENABLE : warnDISABLE);
|
pc_enablewarning((int)val,(str[0]=='e') ? warnENABLE : warnDISABLE);
|
||||||
|
@ -250,7 +250,7 @@ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths)
|
|||||||
strlcpy(path,ptr,arraysize(path));
|
strlcpy(path,ptr,arraysize(path));
|
||||||
strlcat(path,name,arraysize(path));
|
strlcat(path,name,arraysize(path));
|
||||||
result=plungequalifiedfile(path);
|
result=plungequalifiedfile(path);
|
||||||
} /* while */
|
} /* for */
|
||||||
} /* if */
|
} /* if */
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -404,7 +404,7 @@ static void readline(unsigned char *line)
|
|||||||
} else {
|
} else {
|
||||||
/* check whether to erase leading spaces */
|
/* check whether to erase leading spaces */
|
||||||
if (cont) {
|
if (cont) {
|
||||||
unsigned char *ptr=line;
|
ptr=line;
|
||||||
while (*ptr<=' ' && *ptr!='\0')
|
while (*ptr<=' ' && *ptr!='\0')
|
||||||
ptr++;
|
ptr++;
|
||||||
if (ptr!=line)
|
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:
|
* ends with the same multiline string, so that this won't trigger commands:
|
||||||
*
|
*
|
||||||
* new x[] = "Hello
|
* new x[] = "Hello
|
||||||
*
|
*
|
||||||
* #define X 0
|
* #define X 0
|
||||||
* ";
|
* ";
|
||||||
*
|
*
|
||||||
@ -608,9 +608,9 @@ static int stripcomment(unsigned char *line)
|
|||||||
} else {
|
} else {
|
||||||
if (incommand==2 && *line>' ') {
|
if (incommand==2 && *line>' ') {
|
||||||
/* line starting a command, may need raw strings */
|
/* line starting a command, may need raw strings */
|
||||||
if (strncmp(line, "#error", 6)==0 ||
|
if (strncmp((char*)line,"#error",6)==0 ||
|
||||||
strncmp(line, "#warning", 8)==0 ||
|
strncmp((char*)line,"#warning",8)==0 ||
|
||||||
strncmp(line, "#pragma", 7)==0) {
|
strncmp((char*)line,"#pragma",7)==0) {
|
||||||
/* is one of the pre-processor commands with pure raw strings */
|
/* is one of the pre-processor commands with pure raw strings */
|
||||||
incommand=1;
|
incommand=1;
|
||||||
} else {
|
} else {
|
||||||
@ -992,7 +992,7 @@ static const unsigned char *getstring(unsigned char *dest,int max,const unsigned
|
|||||||
if (len<max-1)
|
if (len<max-1)
|
||||||
dest[len++]=*line;
|
dest[len++]=*line;
|
||||||
line++;
|
line++;
|
||||||
} /* if */
|
} /* while */
|
||||||
dest[len]='\0';
|
dest[len]='\0';
|
||||||
if (*line=='"')
|
if (*line=='"')
|
||||||
line++; /* skip closing " */
|
line++; /* skip closing " */
|
||||||
@ -1010,7 +1010,7 @@ static const unsigned char *getstring(unsigned char *dest,int max,const unsigned
|
|||||||
*/
|
*/
|
||||||
static char* strdupwithouta(const char* sourcestring)
|
static char* strdupwithouta(const char* sourcestring)
|
||||||
{
|
{
|
||||||
char* result=strdup(sourcestring);
|
char* result=duplicatestring(sourcestring);
|
||||||
char* a=result;
|
char* a=result;
|
||||||
if (result==NULL) {
|
if (result==NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1220,7 +1220,6 @@ static int command(void)
|
|||||||
if (!cp_set(name))
|
if (!cp_set(name))
|
||||||
error(108); /* codepage mapping file not found */
|
error(108); /* codepage mapping file not found */
|
||||||
} else if (strcmp(str,"compress")==0) {
|
} else if (strcmp(str,"compress")==0) {
|
||||||
cell val;
|
|
||||||
preproc_expr(&val,NULL);
|
preproc_expr(&val,NULL);
|
||||||
sc_compress=(int)val; /* switch code packing on/off */
|
sc_compress=(int)val; /* switch code packing on/off */
|
||||||
} else if (strcmp(str,"ctrlchar")==0) {
|
} else if (strcmp(str,"ctrlchar")==0) {
|
||||||
@ -1272,7 +1271,6 @@ static int command(void)
|
|||||||
curlibrary=append_constval(&libname_tab,name,0,0);
|
curlibrary=append_constval(&libname_tab,name,0,0);
|
||||||
} /* if */
|
} /* if */
|
||||||
} else if (strcmp(str,"pack")==0) {
|
} else if (strcmp(str,"pack")==0) {
|
||||||
cell val;
|
|
||||||
preproc_expr(&val,NULL); /* default = packed/unpacked */
|
preproc_expr(&val,NULL); /* default = packed/unpacked */
|
||||||
sc_packstr=(int)val;
|
sc_packstr=(int)val;
|
||||||
} else if (strcmp(str,"rational")==0) {
|
} 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 */
|
error(69); /* rational number format already set, can only be set once */
|
||||||
} /* if */
|
} /* if */
|
||||||
} else if (strcmp(str,"semicolon")==0) {
|
} else if (strcmp(str,"semicolon")==0) {
|
||||||
cell val;
|
|
||||||
preproc_expr(&val,NULL);
|
preproc_expr(&val,NULL);
|
||||||
sc_needsemicolon=(int)val;
|
sc_needsemicolon=(int)val;
|
||||||
} else if (strcmp(str,"tabsize")==0) {
|
} else if (strcmp(str,"tabsize")==0) {
|
||||||
cell val;
|
|
||||||
preproc_expr(&val,NULL);
|
preproc_expr(&val,NULL);
|
||||||
if (val>0)
|
if (val>0)
|
||||||
sc_tabsize=(int)val;
|
sc_tabsize=(int)val;
|
||||||
@ -1379,7 +1375,6 @@ static int command(void)
|
|||||||
int ok=lex(&val,&str)==tSYMBOL;
|
int ok=lex(&val,&str)==tSYMBOL;
|
||||||
if (ok) {
|
if (ok) {
|
||||||
if (strcmp(str,"enable")==0 || strcmp(str,"disable")==0) {
|
if (strcmp(str,"enable")==0 || strcmp(str,"disable")==0) {
|
||||||
cell val;
|
|
||||||
enum s_warnmode enable=(str[0]=='e') ? warnENABLE : warnDISABLE;
|
enum s_warnmode enable=(str[0]=='e') ? warnENABLE : warnDISABLE;
|
||||||
do {
|
do {
|
||||||
preproc_expr(&val,NULL);
|
preproc_expr(&val,NULL);
|
||||||
@ -1397,7 +1392,6 @@ static int command(void)
|
|||||||
error(207); /* unknown #pragma */
|
error(207); /* unknown #pragma */
|
||||||
} /* if */
|
} /* if */
|
||||||
} else if (strcmp(str,"compat")==0) {
|
} else if (strcmp(str,"compat")==0) {
|
||||||
cell val;
|
|
||||||
symbol *sym;
|
symbol *sym;
|
||||||
preproc_expr(&val,NULL);
|
preproc_expr(&val,NULL);
|
||||||
pc_compat=(int)val; /* switch compatibility mode on/off */
|
pc_compat=(int)val; /* switch compatibility mode on/off */
|
||||||
@ -1495,7 +1489,6 @@ static int command(void)
|
|||||||
} /* if */
|
} /* if */
|
||||||
break;
|
break;
|
||||||
default: {
|
default: {
|
||||||
extern char *sc_tokens[];/* forward declaration */
|
|
||||||
char s2[33]="-";
|
char s2[33]="-";
|
||||||
if ((char)tok=='-') {
|
if ((char)tok=='-') {
|
||||||
int current_token=lex(&val,&str);
|
int current_token=lex(&val,&str);
|
||||||
@ -2298,24 +2291,6 @@ SC_FUNC void lexinit(void)
|
|||||||
_lexnewline=FALSE;
|
_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)
|
SC_FUNC int lex(cell *lexvalue,char **lexsym)
|
||||||
{
|
{
|
||||||
int i,toolong,newline,stringflags;
|
int i,toolong,newline,stringflags;
|
||||||
@ -2430,7 +2405,7 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym)
|
|||||||
error(220);
|
error(220);
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* 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 */
|
{ /* unpacked string literal */
|
||||||
_lextok=tSTRING;
|
_lextok=tSTRING;
|
||||||
stringflags=(*lptr==sc_ctrlchar) ? RAWMODE : 0;
|
stringflags=(*lptr==sc_ctrlchar) ? RAWMODE : 0;
|
||||||
@ -2440,6 +2415,7 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym)
|
|||||||
if ((stringflags & RAWMODE)!=0)
|
if ((stringflags & RAWMODE)!=0)
|
||||||
lptr+=1; /* skip "escape" character too */
|
lptr+=1; /* skip "escape" character too */
|
||||||
lptr=sc_packstr ? packedstring(lptr,&stringflags) : unpackedstring(lptr,&stringflags);
|
lptr=sc_packstr ? packedstring(lptr,&stringflags) : unpackedstring(lptr,&stringflags);
|
||||||
|
pc_ispackedstr=sc_packstr;
|
||||||
if (*lptr=='\"')
|
if (*lptr=='\"')
|
||||||
lptr+=1; /* skip final quote */
|
lptr+=1; /* skip final quote */
|
||||||
else if (!(stringflags & STRINGIZE))
|
else if (!(stringflags & STRINGIZE))
|
||||||
@ -2466,6 +2442,7 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym)
|
|||||||
if ((stringflags & RAWMODE)!=0)
|
if ((stringflags & RAWMODE)!=0)
|
||||||
lptr+=1; /* skip "escape" character too */
|
lptr+=1; /* skip "escape" character too */
|
||||||
lptr=sc_packstr ? unpackedstring(lptr,&stringflags) : packedstring(lptr,&stringflags);
|
lptr=sc_packstr ? unpackedstring(lptr,&stringflags) : packedstring(lptr,&stringflags);
|
||||||
|
pc_ispackedstr=!sc_packstr;
|
||||||
if (*lptr=='\"')
|
if (*lptr=='\"')
|
||||||
lptr+=1; /* skip final quote */
|
lptr+=1; /* skip final quote */
|
||||||
else if (!(stringflags & STRINGIZE))
|
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)
|
while (root->next!=NULL && strcmp(entry->name,root->next->name)>0)
|
||||||
root=root->next;
|
root=root->next;
|
||||||
|
|
||||||
if ((newsym=(symbol *)malloc(sizeof(symbol)))==NULL) {
|
if ((newsym=(symbol *)malloc(sizeof(symbol)))==NULL)
|
||||||
error(103);
|
error(103);
|
||||||
return NULL;
|
|
||||||
} /* if */
|
|
||||||
memcpy(newsym,entry,sizeof(symbol));
|
memcpy(newsym,entry,sizeof(symbol));
|
||||||
newsym->next=root->next;
|
newsym->next=root->next;
|
||||||
root->next=newsym;
|
root->next=newsym;
|
||||||
@ -3145,8 +3120,8 @@ SC_FUNC void delete_symbols(symbol *root,int level,int delete_labels,int delete_
|
|||||||
mustdelete=TRUE;
|
mustdelete=TRUE;
|
||||||
break;
|
break;
|
||||||
case iCONSTEXPR:
|
case iCONSTEXPR:
|
||||||
/* delete constants, except predefined constants */
|
/* delete constants (predefined constants are checked later) */
|
||||||
mustdelete=delete_functions || (sym->usage & uPREDEF)==0;
|
mustdelete=TRUE;
|
||||||
break;
|
break;
|
||||||
case iFUNCTN:
|
case iFUNCTN:
|
||||||
/* optionally preserve globals (variables & functions), but
|
/* 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;
|
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,
|
/* Adds "bywhom" to the list of referrers of "entry". Typically,
|
||||||
* bywhom will be the function that uses a variable or that calls
|
* bywhom will be the function that uses a variable or that calls
|
||||||
* the function.
|
* the function.
|
||||||
@ -3470,16 +3438,6 @@ SC_FUNC symbol *findconst(const char *name,int *cmptag)
|
|||||||
return sym;
|
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
|
/* addsym
|
||||||
*
|
*
|
||||||
* Adds a symbol to the symbol table (either global or local variables,
|
* 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);
|
assert(ident!=iLABEL || findloc(name)==NULL);
|
||||||
|
|
||||||
/* create an empty referrer list */
|
/* create an empty referrer list */
|
||||||
if ((refer=(symbol**)malloc(sizeof(symbol*)))==NULL) {
|
if ((refer=(symbol**)malloc(sizeof(symbol*)))==NULL)
|
||||||
error(103); /* insufficient memory */
|
error(103); /* insufficient memory */
|
||||||
return NULL;
|
|
||||||
} /* if */
|
|
||||||
*refer=NULL;
|
*refer=NULL;
|
||||||
|
|
||||||
/* first fill in the entry */
|
/* first fill in the entry */
|
||||||
|
@ -146,7 +146,7 @@ static void (*unopers[])(void) = { lneg, neg, user_inc, user_dec };
|
|||||||
if (lval!=NULL && (lval->ident==iARRAYCELL || lval->ident==iARRAYCHAR))
|
if (lval!=NULL && (lval->ident==iARRAYCELL || lval->ident==iARRAYCHAR))
|
||||||
savealt=TRUE;
|
savealt=TRUE;
|
||||||
} else {
|
} else {
|
||||||
assert( arraysize(binoperstr) == arraysize(op1) );
|
assert_static( arraysize(binoperstr) == arraysize(op1) );
|
||||||
for (i=0; i<arraysize(op1); i++) {
|
for (i=0; i<arraysize(op1); i++) {
|
||||||
if (oper==op1[i]) {
|
if (oper==op1[i]) {
|
||||||
strcpy(opername,binoperstr[i]);
|
strcpy(opername,binoperstr[i]);
|
||||||
@ -159,7 +159,7 @@ static void (*unopers[])(void) = { lneg, neg, user_inc, user_dec };
|
|||||||
assert(oper!=NULL);
|
assert(oper!=NULL);
|
||||||
assert(numparam==1);
|
assert(numparam==1);
|
||||||
/* try a select group of unary operators */
|
/* try a select group of unary operators */
|
||||||
assert( arraysize(unoperstr) == arraysize(unopers) );
|
assert_static( arraysize(unoperstr) == arraysize(unopers) );
|
||||||
if (opername[0]=='\0') {
|
if (opername[0]=='\0') {
|
||||||
for (i=0; i<arraysize(unopers); i++) {
|
for (i=0; i<arraysize(unopers); i++) {
|
||||||
if (oper==unopers[i]) {
|
if (oper==unopers[i]) {
|
||||||
@ -419,7 +419,7 @@ static int skim(int *opstr,void (*testfunc)(int),int dropval,int endval,
|
|||||||
break; /* none of the operators in "opstr" were found */
|
break; /* none of the operators in "opstr" were found */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
} /* while */
|
} /* for */
|
||||||
|
|
||||||
lval_stgidx=org_index;
|
lval_stgidx=org_index;
|
||||||
lval_cidx=org_cidx;
|
lval_cidx=org_cidx;
|
||||||
@ -587,7 +587,7 @@ static void plnge2(void (*oper)(void),
|
|||||||
rvalue(lval2);
|
rvalue(lval2);
|
||||||
if (lval2->ident==iCONSTEXPR) { /* constant on right side */
|
if (lval2->ident==iCONSTEXPR) { /* constant on right side */
|
||||||
if (commutative(oper)) { /* test for commutative operators */
|
if (commutative(oper)) { /* test for commutative operators */
|
||||||
value lvaltmp = {0};
|
value lvaltmp;
|
||||||
stgdel(lval_stgidx,lval_cidx); /* scratch pushreg() and constant fetch (then
|
stgdel(lval_stgidx,lval_cidx); /* scratch pushreg() and constant fetch (then
|
||||||
* fetch the constant again */
|
* fetch the constant again */
|
||||||
ldconst(lval2->constval<<dbltest(oper,lval1,lval2),sALT);
|
ldconst(lval2->constval<<dbltest(oper,lval1,lval2),sALT);
|
||||||
@ -817,7 +817,7 @@ SC_FUNC cell array_totalsize(symbol *sym)
|
|||||||
assert(sym->ident==iARRAY || sym->ident==iREFARRAY);
|
assert(sym->ident==iARRAY || sym->ident==iREFARRAY);
|
||||||
length=sym->dim.array.length;
|
length=sym->dim.array.length;
|
||||||
if (sym->dim.array.level > 0) {
|
if (sym->dim.array.level > 0) {
|
||||||
cell sublength=array_totalsize(finddepend(sym));
|
cell sublength=array_totalsize(sym->child);
|
||||||
if (sublength>0)
|
if (sublength>0)
|
||||||
length=length+length*sublength;
|
length=length+length*sublength;
|
||||||
else
|
else
|
||||||
@ -832,9 +832,9 @@ static cell array_levelsize(symbol *sym,int level)
|
|||||||
assert(sym->ident==iARRAY || sym->ident==iREFARRAY);
|
assert(sym->ident==iARRAY || sym->ident==iREFARRAY);
|
||||||
assert(level <= sym->dim.array.level);
|
assert(level <= sym->dim.array.level);
|
||||||
while (level-- > 0) {
|
while (level-- > 0) {
|
||||||
sym=finddepend(sym);
|
sym=sym->child;
|
||||||
assert(sym!=NULL);
|
assert(sym!=NULL);
|
||||||
} /* if */
|
} /* while */
|
||||||
return sym->dim.array.length;
|
return sym->dim.array.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1055,7 +1055,6 @@ static int hier14(value *lval1)
|
|||||||
/* check the sizes of all sublevels too */
|
/* check the sizes of all sublevels too */
|
||||||
symbol *sym1 = lval3.sym;
|
symbol *sym1 = lval3.sym;
|
||||||
symbol *sym2 = lval2.sym;
|
symbol *sym2 = lval2.sym;
|
||||||
int i;
|
|
||||||
assert(sym1!=NULL && sym2!=NULL);
|
assert(sym1!=NULL && sym2!=NULL);
|
||||||
/* ^^^ sym2 must be valid, because only variables can be
|
/* ^^^ sym2 must be valid, because only variables can be
|
||||||
* multi-dimensional (there are no multi-dimensional literals),
|
* multi-dimensional (there are no multi-dimensional literals),
|
||||||
@ -1063,8 +1062,8 @@ static int hier14(value *lval1)
|
|||||||
*/
|
*/
|
||||||
assert(exactmatch);
|
assert(exactmatch);
|
||||||
for (i=0; i<level; i++) {
|
for (i=0; i<level; i++) {
|
||||||
sym1=finddepend(sym1);
|
sym1=sym1->child;
|
||||||
sym2=finddepend(sym2);
|
sym2=sym2->child;
|
||||||
assert(sym1!=NULL && sym2!=NULL);
|
assert(sym1!=NULL && sym2!=NULL);
|
||||||
/* ^^^ both arrays have the same dimensions (this was checked
|
/* ^^^ both arrays have the same dimensions (this was checked
|
||||||
* earlier) so the dependend should always be found
|
* earlier) so the dependend should always be found
|
||||||
@ -1362,7 +1361,6 @@ static int hier2(value *lval)
|
|||||||
lval->tag=tag;
|
lval->tag=tag;
|
||||||
return lvalue;
|
return lvalue;
|
||||||
case t__ADDRESSOF: {
|
case t__ADDRESSOF: {
|
||||||
extern char *sc_tokens[];
|
|
||||||
static const char allowed_sym_types[]="-variable, array, array cell, label or function-";
|
static const char allowed_sym_types[]="-variable, array, array cell, label or function-";
|
||||||
paranthese=0;
|
paranthese=0;
|
||||||
while (matchtoken('('))
|
while (matchtoken('('))
|
||||||
@ -1430,7 +1428,7 @@ static int hier2(value *lval)
|
|||||||
numoffsets+=offsmul;
|
numoffsets+=offsmul;
|
||||||
offsmul*=subsym->dim.array.length;
|
offsmul*=subsym->dim.array.length;
|
||||||
arrayidx=(arrayidx*subsym->dim.array.length)+val;
|
arrayidx=(arrayidx*subsym->dim.array.length)+val;
|
||||||
subsym=finddepend(subsym);
|
subsym=subsym->child;
|
||||||
}
|
}
|
||||||
needtoken(']');
|
needtoken(']');
|
||||||
} /* for */
|
} /* for */
|
||||||
@ -1440,8 +1438,8 @@ static int hier2(value *lval)
|
|||||||
numoffsets+=offsmul;
|
numoffsets+=offsmul;
|
||||||
offsmul*=subsym->dim.array.length;
|
offsmul*=subsym->dim.array.length;
|
||||||
arrayidx*=arrayidx*subsym->dim.array.length;
|
arrayidx*=arrayidx*subsym->dim.array.length;
|
||||||
subsym=finddepend(subsym);
|
subsym=subsym->child;
|
||||||
} /* if */
|
} /* while */
|
||||||
lval->constval+=(numoffsets-1+arrayidx)*(cell)sizeof(cell);
|
lval->constval+=(numoffsets-1+arrayidx)*(cell)sizeof(cell);
|
||||||
ldconst(lval->constval,sPRI);
|
ldconst(lval->constval,sPRI);
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -1543,7 +1541,7 @@ static int hier2(value *lval)
|
|||||||
} /* if */
|
} /* if */
|
||||||
needtoken(']');
|
needtoken(']');
|
||||||
if (subsym!=NULL)
|
if (subsym!=NULL)
|
||||||
subsym=finddepend(subsym);
|
subsym=subsym->child;
|
||||||
} /* for */
|
} /* for */
|
||||||
if (level>sym->dim.array.level+1)
|
if (level>sym->dim.array.level+1)
|
||||||
error(28,sym->name); /* invalid subscript */
|
error(28,sym->name); /* invalid subscript */
|
||||||
@ -1595,7 +1593,7 @@ static int hier2(value *lval)
|
|||||||
} /* if */
|
} /* if */
|
||||||
needtoken(']');
|
needtoken(']');
|
||||||
if (subsym!=NULL)
|
if (subsym!=NULL)
|
||||||
subsym=finddepend(subsym);
|
subsym=subsym->child;
|
||||||
} /* for */
|
} /* for */
|
||||||
if (level>sym->dim.array.level+1)
|
if (level>sym->dim.array.level+1)
|
||||||
error(28,sym->name); /* invalid subscript */
|
error(28,sym->name); /* invalid subscript */
|
||||||
@ -1790,7 +1788,7 @@ restart:
|
|||||||
/* parse the next index if this is not the lowest array dimension */
|
/* 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) {
|
if (sym!=NULL && (sym->ident==iARRAY || sym->ident==iREFARRAY) && sym->dim.array.level>0) {
|
||||||
lval1->ident=iREFARRAY;
|
lval1->ident=iREFARRAY;
|
||||||
lval1->sym=finddepend(sym);
|
lval1->sym=sym->child;
|
||||||
assert(lval1->sym!=NULL);
|
assert(lval1->sym!=NULL);
|
||||||
assert(lval1->sym->dim.array.level==sym->dim.array.level-1);
|
assert(lval1->sym->dim.array.level==sym->dim.array.level-1);
|
||||||
cursym=lval1->sym;
|
cursym=lval1->sym;
|
||||||
@ -1877,7 +1875,7 @@ restart:
|
|||||||
ob_add();
|
ob_add();
|
||||||
/* adjust the "value" structure and find the referenced array */
|
/* adjust the "value" structure and find the referenced array */
|
||||||
lval1->ident=iREFARRAY;
|
lval1->ident=iREFARRAY;
|
||||||
lval1->sym=finddepend(sym);
|
lval1->sym=sym->child;
|
||||||
assert(lval1->sym!=NULL);
|
assert(lval1->sym!=NULL);
|
||||||
assert(lval1->sym->dim.array.level==sym->dim.array.level-1);
|
assert(lval1->sym->dim.array.level==sym->dim.array.level-1);
|
||||||
cursym=lval1->sym;
|
cursym=lval1->sym;
|
||||||
@ -2081,7 +2079,7 @@ static int primary(value *lval)
|
|||||||
return FALSE; /* return 0 for function (not an lvalue) */
|
return FALSE; /* return 0 for function (not an lvalue) */
|
||||||
} /* if */
|
} /* if */
|
||||||
lexpush(); /* push the token, it is analyzed by constant() */
|
lexpush(); /* push the token, it is analyzed by constant() */
|
||||||
if (constant(lval)==0) {
|
if (!constant(lval)) {
|
||||||
error(29); /* expression error, assumed 0 */
|
error(29); /* expression error, assumed 0 */
|
||||||
ldconst(0,sPRI); /* load 0 */
|
ldconst(0,sPRI); /* load 0 */
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -2197,7 +2195,7 @@ static int nesting=0;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* check whether this is a function that returns an array */
|
/* check whether this is a function that returns an array */
|
||||||
symret=finddepend(sym);
|
symret=sym->child;
|
||||||
assert(symret==NULL || symret->ident==iREFARRAY);
|
assert(symret==NULL || symret->ident==iREFARRAY);
|
||||||
if (symret!=NULL) {
|
if (symret!=NULL) {
|
||||||
int retsize;
|
int retsize;
|
||||||
@ -2453,7 +2451,7 @@ static int nesting=0;
|
|||||||
else
|
else
|
||||||
check_index_tagmismatch(sym->name,arg[argidx].idxtag[level],sym->x.tags.index,TRUE,0);
|
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);
|
append_constval(&arrayszlst,arg[argidx].name,sym->dim.array.length,level);
|
||||||
sym=finddepend(sym);
|
sym=sym->child;
|
||||||
assert(sym!=NULL);
|
assert(sym!=NULL);
|
||||||
level++;
|
level++;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -700,7 +700,6 @@ SC_FUNC int error_suggest(int number,const char *name,const char *name2,int type
|
|||||||
} /* if */
|
} /* if */
|
||||||
} else if (type==estNONSYMBOL) {
|
} else if (type==estNONSYMBOL) {
|
||||||
if (tMIDDLE<subtype && subtype<=tLAST) {
|
if (tMIDDLE<subtype && subtype<=tLAST) {
|
||||||
extern char *sc_tokens[];
|
|
||||||
name=sc_tokens[subtype-tFIRST];
|
name=sc_tokens[subtype-tFIRST];
|
||||||
subtype=esfVARCONST;
|
subtype=esfVARCONST;
|
||||||
goto find_symbol;
|
goto find_symbol;
|
||||||
|
@ -1699,10 +1699,8 @@ static char *replacesequence(char *pattern,char symbols[MAX_OPT_VARS][MAX_ALIAS+
|
|||||||
} /* while */
|
} /* while */
|
||||||
|
|
||||||
/* allocate a buffer to replace the sequence in */
|
/* allocate a buffer to replace the sequence in */
|
||||||
if ((buffer=(char*)malloc(*repl_length))==NULL) {
|
if ((buffer=(char*)malloc(*repl_length))==NULL)
|
||||||
error(103);
|
error(103);
|
||||||
return NULL;
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
/* replace the pattern into this temporary buffer */
|
/* replace the pattern into this temporary buffer */
|
||||||
lptr=buffer;
|
lptr=buffer;
|
||||||
|
@ -44,7 +44,8 @@
|
|||||||
SC_FUNC char* duplicatestring(const char* sourcestring)
|
SC_FUNC char* duplicatestring(const char* sourcestring)
|
||||||
{
|
{
|
||||||
char* result=(char*)malloc(strlen(sourcestring)+1);
|
char* result=(char*)malloc(strlen(sourcestring)+1);
|
||||||
strcpy(result,sourcestring);
|
if (result!=NULL)
|
||||||
|
strcpy(result,sourcestring);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,7 +483,7 @@ SC_FUNC stringlist *insert_dbgsymbol(symbol *sym)
|
|||||||
#endif
|
#endif
|
||||||
symbol *sub;
|
symbol *sub;
|
||||||
strcat(string," [ ");
|
strcat(string," [ ");
|
||||||
for (sub=sym; sub!=NULL; sub=finddepend(sub)) {
|
for (sub=sym; sub!=NULL; sub=sub->child) {
|
||||||
assert(sub->dim.array.level==count--);
|
assert(sub->dim.array.level==count--);
|
||||||
sprintf(string+strlen(string),"%x:%x ",sub->x.tags.index,sub->dim.array.length);
|
sprintf(string+strlen(string),"%x:%x ",sub->x.tags.index,sub->dim.array.length);
|
||||||
} /* for */
|
} /* for */
|
||||||
|
@ -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_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 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 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_automaton_tab = { NULL, NULL}; /* automaton table */
|
||||||
SC_VDEFINE constvalue_root sc_state_tab = { NULL, NULL}; /* state table */
|
SC_VDEFINE constvalue_root sc_state_tab = { NULL, NULL}; /* state table */
|
||||||
|
6
source/compiler/tests/error_047.meta
Normal file
6
source/compiler/tests/error_047.meta
Normal file
@ -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
|
||||||
|
"""
|
||||||
|
}
|
@ -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
|
|
||||||
"""
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user