Compiler: Add #pragma deprecated.

This is based on SM, including patch to support macros/constants (https://hg.alliedmods.net/sourcemod-central/rev/ef8dd1cddc35).
Updated also some pawn includes to use this new pragma.
This commit is contained in:
Arkshine 2014-08-13 13:18:33 +02:00
parent 09303625fb
commit 520493fab1
11 changed files with 5685 additions and 5613 deletions

View File

@ -128,6 +128,7 @@ typedef struct s_symbol {
char vclass; /* sLOCAL if "addr" refers to a local symbol */
char ident; /* see below for possible values */
char usage; /* see below for possible values */
char flags; /* see below for possible values */
int compound; /* compound level (braces nesting level) */
int tag; /* tagname id */
int fieldtag; /* enumeration fields, where a size is attached to the field */
@ -221,6 +222,8 @@ typedef struct s_symbol {
*/
#define uRETNONE 0x10
#define flgDEPRECATED 0x01 /* symbol is deprecated (avoid use) */
#define uTAGOF 0x40 /* set in the "hasdefault" field of the arginfo struct */
#define uSIZEOF 0x80 /* set in the "hasdefault" field of the arginfo struct */
@ -270,6 +273,8 @@ typedef struct s_stringpair {
char *first;
char *second;
int matchlength;
char flags;
char *documentation;
} stringpair;
/* macros for code generation */
@ -783,6 +788,7 @@ SC_VDECL int sc_rationaltag; /* tag for rational numbers */
SC_VDECL int rational_digits; /* number of fractional digits */
SC_VDECL int sc_allowproccall;/* allow/detect tagnames in lex() */
SC_VDECL short sc_is_utf8; /* is this source file in UTF-8 encoding */
SC_VDECL char *pc_deprecate; /* if non-NULL, mark next declaration as deprecated */
SC_VDECL constvalue sc_automaton_tab; /* automaton table */
SC_VDECL constvalue sc_state_tab; /* state table */

View File

@ -828,6 +828,7 @@ static void resetglobals(void)
pc_addlibtable=TRUE; /* by default, add a "library table" to the output file */
sc_alignnext=FALSE;
pc_docexpr=FALSE;
pc_deprecate = FALSE;
}
static void initglobals(void)
@ -2740,7 +2741,20 @@ SC_FUNC symbol *fetchfunc(char *name,int tag)
/* set the required stack size to zero (only for non-native functions) */
sym->x.stacksize=1; /* 1 for PROC opcode */
} /* if */
if (pc_deprecate!=NULL) {
assert(sym!=NULL);
sym->flags |= flgDEPRECATED;
if (sc_status==statWRITE) {
if (sym->documentation!=NULL) {
free(sym->documentation);
sym->documentation=NULL;
} /* if */
sym->documentation=pc_deprecate;
} else {
free(pc_deprecate);
} /* if */
pc_deprecate=NULL;
}/* if */
return sym;
}
@ -3244,6 +3258,10 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc
cidx=code_idx;
glbdecl=glb_declared;
} /* if */
if ((sym->flags & flgDEPRECATED) != 0 && (sym->usage & uSTOCK) == 0) {
char *ptr = (sym->documentation != NULL) ? sym->documentation : "";
error(233, symbolname, ptr); /* deprecated (probably a public function) */
} /* if */
begcseg();
sym->usage|=uDEFINE; /* set the definition flag */
if (fpublic)
@ -5230,18 +5248,6 @@ static symbol *fetchlab(char *name)
return sym;
}
static int is_variadic(symbol *sym)
{
arginfo *arg;
assert(sym->ident==iFUNCTN);
for (arg = sym->dim.arglist; arg->ident; arg++) {
if (arg->ident == iVARARGS)
return TRUE;
}
return FALSE;
}
/* doreturn
*
* Global references: rettype (altered)
@ -5341,11 +5347,7 @@ static void doreturn(void)
* it stays on the heap for the moment, and it is removed -usually- at
* the end of the expression/statement, see expression() in SC3.C)
*/
if (is_variadic(curfunc)) {
load_hidden_arg();
} else {
address(sub,sALT); /* ALT = destination */
}
arraysize=calc_arraysize(dim,numdim,0);
memcopy(arraysize*sizeof(cell)); /* source already in PRI */
/* moveto1(); is not necessary, callfunction() does a popreg() */
@ -5460,6 +5462,7 @@ static void dostate(void)
pc_docexpr=TRUE; /* attach expression as a documentation string */
test(flabel,FALSE,FALSE); /* get expression, branch to flabel if false */
pc_docexpr=FALSE;
pc_deprecate=NULL;
needtoken(')');
} else {
flabel=-1;
@ -5607,4 +5610,3 @@ static int *readwhile(void)
return (wqptr-wqSIZE);
} /* if */
}

View File

@ -850,6 +850,7 @@ static int command(void)
char *str;
int index;
cell code_index;
size_t len;
while (*lptr<=' ' && *lptr!='\0')
lptr+=1;
@ -1003,6 +1004,19 @@ static int command(void)
error(27); /* invalid character constant */
sc_ctrlchar=(char)val;
} /* if */
}
else if (strcmp(str, "deprecated") == 0) {
while (*lptr <= ' ' && *lptr != '\0')
lptr++;
len = strlen((char*)lptr);
pc_deprecate = (char*)malloc(len + 1);
if (pc_deprecate != NULL)
{
strcpy(pc_deprecate, (char*)lptr);
if (pc_deprecate[len - 1] == '\n') /* remove extra \n as already appended in .scp file */
pc_deprecate[len-1] = '\0';
}
lptr = (unsigned char*)strchr((char*)lptr, '\0'); /* skip to end (ignore "extra characters on line") */
} else if (strcmp(str,"dynamic")==0) {
preproc_expr(&sc_stksize,NULL);
} else if ( !strcmp(str,"library") ||
@ -2658,6 +2672,7 @@ SC_FUNC symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag,i
entry.ident=(char)ident;
entry.tag=tag;
entry.usage=(char)usage;
entry.flags=0;
entry.compound=0; /* may be overridden later */
entry.states=NULL;
entry.fnumber=-1; /* assume global visibility (ignored for local symbols) */

View File

@ -1862,6 +1862,11 @@ static int nesting=0;
assert(nest_stkusage==0);
#endif
if ((sym->flags & flgDEPRECATED)!=0) {
char *ptr= (sym->documentation!=NULL) ? sym->documentation : "";
error(233,sym->name,ptr); /* deprecated (probably a native function) */
} /* if */
/* run through the arguments */
arg=sym->dim.arglist;
assert(arg!=NULL);

View File

@ -290,6 +290,7 @@ static char *warnmsg[] = {
/*230*/ "no implementation for state \"%s\" / function \"%s\", no fall-back\n",
/*231*/ "state specification on forward declaration is ignored\n",
/*232*/ "output file is written, but with compact encoding disabled\n"
/*233*/ "symbol \"%s\" is marked as deprecated: %s\n",
#else
"\345 \274tr\240\226\233\277 %\206\273\337c\367\305",
"\222\323i\231\300\344\224t/\314cr\375\364",

View File

@ -276,6 +276,26 @@ SC_FUNC stringpair *insert_subst(char *pattern,char *substitution,int prefixlen)
if ((cur=insert_stringpair(&substpair,pattern,substitution,prefixlen))==NULL)
error(103); /* insufficient memory (fatal error) */
adjustindex(*pattern);
if (pc_deprecate != NULL) {
assert(cur != NULL);
cur->flags |= flgDEPRECATED;
if (sc_status == statWRITE) {
if (cur->documentation != NULL) {
free(cur->documentation);
cur->documentation = NULL;
} /* if */
cur->documentation = pc_deprecate;
}
else {
free(pc_deprecate);
} /* if */
pc_deprecate = NULL;
}
else {
cur->flags = 0;
cur->documentation = NULL;
} /* if */
return cur;
}
@ -288,6 +308,24 @@ SC_FUNC stringpair *find_subst(char *name,int length)
item=substindex[(int)*name-'A'];
if (item!=NULL)
item=find_stringpair(item,name,length);
if (item && (item->flags & flgDEPRECATED) != 0)
{
static char macro[128];
char *rem, *msg = (item->documentation != NULL) ? item->documentation : "";
strncpy(macro, item->first, sizeof(macro));
macro[sizeof(macro) - 1] = '\0';
/* If macro contains an opening parentheses and a percent sign, then assume that
* it takes arguments and remove them from the warning message.
*/
if ((rem = strchr(macro, '(')) != NULL && strchr(macro, '%') > rem)
{
*rem = '\0';
}
error(233, macro, msg); /* deprecated (macro/constant) */
}
return item;
}

View File

@ -84,6 +84,7 @@ SC_VDEFINE int sc_rationaltag=0; /* tag for rational numbers */
SC_VDEFINE int rational_digits=0; /* number of fractional digits */
SC_VDEFINE int sc_allowproccall=0; /* allow/detect tagnames in lex() */
SC_VDEFINE short sc_is_utf8=FALSE; /* is this source file in UTF-8 encoding */
SC_VDEFINE char *pc_deprecate = NULL;/* if non-null, mark next declaration as deprecated */
SC_VDEFINE int sc_showincludes=0; /* show include files */
SC_VDEFINE constvalue sc_automaton_tab = { NULL, "", 0, 0}; /* automaton table */

View File

@ -2535,6 +2535,7 @@ native plugin_flags(hdr=0, plid=-1);
*
* @noreturn
*/
#pragma deprecated Module dependency is now automatically handled by the compiler. This forward is no longer called.
forward plugin_modules();
/**
@ -2545,6 +2546,7 @@ forward plugin_modules();
*
* @noreturn
*/
#pragma deprecated Module dependency is now automatically handled by the compiler. This native has no effect.
native require_module(const module[]);
/**
@ -2556,6 +2558,7 @@ native require_module(const module[]);
*
* @return 1 if the server is 64 bit, 0 otherwise
*/
#pragma deprecated AMXX is not shipping 64bits builds anymore. This native is basically guaranteed to return 0.
native is_amd64_server();
/**

View File

@ -62,7 +62,7 @@ native bool:geoip_code3_ex(const ip[], result[4]);
*
* @return 1 on a successful lookup, 0 otherwise.
*/
//#pragma deprecated Use geoip_code2_ex() instead.
#pragma deprecated Use geoip_code2_ex() instead.
native geoip_code2(const ip[], ccode[3]);
/**
@ -76,7 +76,7 @@ native geoip_code2(const ip[], ccode[3]);
*
* @return 1 on a successful lookup, 0 otherwise.
*/
//#pragma deprecated Use geoip_code3() instead.
#pragma deprecated Use geoip_code3() instead.
native geoip_code3(const ip[], result[4]);
/**

View File

@ -543,6 +543,7 @@ forward client_spawn(id);
* @param Damage The amount of damage being done.
* @param DamageType The damage type being done (bitmask).
*/
#pragma deprecated It is suggested to use hamsandwich for this action instead.
native ns_takedamage(IDVictim, IDInflictor, IDAttacker, Float:Damage, DamageType);
/**

View File

@ -711,7 +711,7 @@ native strncmp(const string1[], const string2[], num, bool:ignorecase=false);
* Backwards compatibility stock - use argbreak or argparse.
* @deprecated this function does not work properly.
*/
//#pragma deprecated Use argbreak() instead
#pragma deprecated Use argbreak() instead
stock strbreak(const text[], Left[], leftLen, Right[], rightLen)
{
return argbreak(text, Left, leftLen, Right, rightLen);