Revert "Add built-in __file constant"

This reverts commit d15fc2224be20eac391062d1c1898b027a168713.
This commit is contained in:
Zeex 2017-02-03 00:45:21 +06:00
parent a05033be20
commit 0cd10a73d6
4 changed files with 13 additions and 71 deletions

View File

@ -527,7 +527,6 @@ SC_FUNC constvalue *append_constval(constvalue *table,const char *name,cell val,
SC_FUNC constvalue *find_constval(constvalue *table,char *name,int index);
SC_FUNC void delete_consttable(constvalue *table);
SC_FUNC symbol *add_constant(char *name,cell val,int vclass,int tag);
SC_FUNC symbol *add_string_constant(char *name,const char *val,int vclass);
SC_FUNC void exporttag(int tag);
SC_FUNC void sc_attachdocumentation(symbol *sym);
@ -584,9 +583,7 @@ SC_FUNC void begcseg(void);
SC_FUNC void begdseg(void);
SC_FUNC void setline(int chkbounds);
SC_FUNC void setfiledirect(char *name);
SC_FUNC void setfileconst(char *name);
SC_FUNC void setlinedirect(int line);
SC_FUNC void setlineconst(int line);
SC_FUNC void setlabel(int index);
SC_FUNC void markexpr(optmark type,const char *name,cell offset);
SC_FUNC void startfunc(char *fname);

View File

@ -570,8 +570,8 @@ int pc_compile(int argc, char *argv[])
sc_needsemicolon ? "true" : "false",
sc_tabsize);
pc_writeasm(outf,string);
setfiledirect(inpfname);
} /* if */
setfiledirect(inpfname);
/* do the first pass through the file (or possibly two or more "first passes") */
sc_parsenum=0;
inpfmark=pc_getpossrc(inpf_org);
@ -596,7 +596,7 @@ int pc_compile(int argc, char *argv[])
fline=skipinput; /* reset line number */
sc_reparse=FALSE; /* assume no extra passes */
sc_status=statFIRST; /* resetglobals() resets it to IDLE */
setfileconst(inpfname);
if (strlen(incfname)>0) {
if (strcmp(incfname,sDEF_PREFIX)==0) {
plungefile(incfname,FALSE,TRUE); /* parse "default.inc" */
@ -661,7 +661,6 @@ int pc_compile(int argc, char *argv[])
lexinit(); /* clear internal flags of lex() */
sc_status=statWRITE; /* allow to write --this variable was reset by resetglobals() */
writeleader(&glbtab);
setfileconst(inpfname);
insert_dbgfile(inpfname);
if (strlen(incfname)>0) {
if (strcmp(incfname,sDEF_PREFIX)==0)
@ -4899,9 +4898,9 @@ SC_FUNC symbol *add_constant(char *name,cell val,int vclass,int tag)
* constants are stored in the symbols table, this also finds previously
* defind constants. */
sym=findglb(name,sSTATEVAR);
if (sym==NULL)
if (!sym)
sym=findloc(name);
if (sym!=NULL) {
if (sym) {
int redef=0;
if (sym->ident!=iCONSTEXPR)
redef=1; /* redefinition a function/variable to a constant is not allowed */
@ -4943,50 +4942,8 @@ SC_FUNC symbol *add_constant(char *name,cell val,int vclass,int tag)
redef_enumfield:
sym=addsym(name,val,iCONSTEXPR,vclass,tag,uDEFINE);
assert(sym!=NULL); /* fatal error 103 must be given on error */
if (sc_status==statIDLE)
sym->usage|=uPREDEF;
return sym;
}
/* add_string_constant
*
* Adds a string constant to the symbol table.
*/
SC_FUNC symbol *add_string_constant(char *name,const char *val,int vclass)
{
symbol *sym;
/* Test whether a global or local symbol with the same name exists. Since
* constants are stored in the symbols table, this also finds previously
* defind constants. */
sym=findglb(name,sSTATEVAR);
if (sym==NULL)
sym=findloc(name);
if (sym!=NULL) {
int redef=0;
if (sym->ident!=iARRAY) {
error(21,name); /* symbol already defined */
return NULL;
} /* if */
} else {
sym=addsym(name,0,iARRAY,vclass,0,uDEFINE);
sym->fnumber=fcurrent;
sym->usage|=uSTOCK;
} /* if */
sym->addr=(litidx+glb_declared)*sizeof(cell);
sym->usage|=(uDEFINE | uPREDEF);
/* Store this constant only if it's used somewhere. This can be detected
* in the second stage. */
if (sc_status==statWRITE && (sym->usage & uREAD)!=0) {
assert(litidx==0);
begdseg();
while (*val!='\0')
litadd(*val++);
litadd(0);
glb_declared+=litidx;
dumplits();
litidx=0;
}
if (sc_status == statIDLE)
sym->usage |= uPREDEF;
return sym;
}

View File

@ -198,7 +198,6 @@ static char extensions[][6] = { "", ".inc", ".p", ".pawn" };
icomment=0; /* not in a comment */
insert_dbgfile(inpfname);
setfiledirect(inpfname);
setfileconst(inpfname);
listline=-1; /* force a #line directive when changing the file */
sc_is_utf8=(short)scan_utf8(inpf,real_path);
free(real_path);
@ -351,6 +350,7 @@ static void readline(unsigned char *line)
{
int i,num,cont;
unsigned char *ptr;
symbol *sym;
if (lptr==term_expr)
return;
@ -429,7 +429,9 @@ static void readline(unsigned char *line)
line+=strlen((char*)line);
} /* if */
fline+=1;
setlineconst(fline);
sym=findconst("__line",NULL);
assert(sym!=NULL);
sym->addr=fline;
} while (num>=0 && cont);
}
@ -2201,8 +2203,8 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym)
} else if (*lptr=='\"' || *lptr=='#' || *lptr==sc_ctrlchar && (*(lptr+1)=='\"' || *(lptr+1)=='#'))
{ /* unpacked string literal */
_lextok=tSTRING;
stringflags=(*lptr==sc_ctrlchar) ? RAWMODE : 0;
stringflags|=(*lptr=='#' || (*lptr==sc_ctrlchar && *(lptr+1)=='#')) ? STRINGIZE : 0;
stringflags= (*lptr==sc_ctrlchar) ? RAWMODE : 0;
stringflags |= (*lptr=='#' || (*lptr==sc_ctrlchar && *(lptr+1)=='#')) ? STRINGIZE : 0;
*lexvalue=_lexval=litidx;
lptr+=1; /* skip double quote */
if ((stringflags & RAWMODE)!=0)
@ -2709,7 +2711,7 @@ SC_FUNC void delete_symbols(symbol *root,int level,int delete_labels,int delete_
case iVARIABLE:
case iARRAY:
/* do not delete global variables if functions are preserved */
mustdelete=delete_functions || (sym->usage & uPREDEF)==0;
mustdelete=delete_functions;
break;
case iREFERENCE:
/* always delete references (only exist as function parameters) */

View File

@ -270,11 +270,6 @@ SC_FUNC void setfiledirect(char *name)
} /* if */
}
SC_FUNC void setfileconst(char *name)
{
add_string_constant("__file",name,sGLOBAL);
}
SC_FUNC void setlinedirect(int line)
{
if (sc_status==statFIRST && sc_listing) {
@ -284,15 +279,6 @@ SC_FUNC void setlinedirect(int line)
} /* if */
}
SC_FUNC void setlineconst(int line)
{
symbol *sym;
sym=findconst("__line",NULL);
assert(sym!=NULL);
sym->addr=fline;
}
/* setlabel
*
* Post a code label (specified as a number), on a new line.