Port sc1 to C++.
This commit is contained in:
parent
48d228e2b1
commit
29fbbade69
sourcepawn/compiler
@ -82,7 +82,7 @@ binary.sources += [
|
||||
'lstring.cpp',
|
||||
'memfile.cpp',
|
||||
'pawncc.cpp',
|
||||
'sc1.c',
|
||||
'sc1.cpp',
|
||||
'sc2.cpp',
|
||||
'sc3.cpp',
|
||||
'sc4.cpp',
|
||||
|
@ -546,7 +546,7 @@ typedef enum s_optmark {
|
||||
* Functions you call from the "driver" program
|
||||
*/
|
||||
int pc_compile(int argc, char **argv);
|
||||
int pc_addconstant(char *name,cell value,int tag);
|
||||
int pc_addconstant(const char *name,cell value,int tag);
|
||||
int pc_addtag(const char *name);
|
||||
int pc_addtag_flags(const char *name, int flags);
|
||||
int pc_findtag(const char *name);
|
||||
@ -616,15 +616,15 @@ SC_FUNC void sp_fdbg_ntv_start(int num_natives);
|
||||
SC_FUNC void sp_fdbg_ntv_hook(int index, symbol *sym);
|
||||
|
||||
/* function prototypes in SC1.C */
|
||||
SC_FUNC void set_extension(char *filename,char *extension,int force);
|
||||
SC_FUNC void set_extension(char *filename,const char *extension,int force);
|
||||
SC_FUNC symbol *fetchfunc(char *name);
|
||||
SC_FUNC char *operator_symname(char *symname,char *opername,int tag1,int tag2,int numtags,int resulttag);
|
||||
SC_FUNC char *operator_symname(char *symname,const char *opername,int tag1,int tag2,int numtags,int resulttag);
|
||||
SC_FUNC char *funcdisplayname(char *dest,char *funcname);
|
||||
SC_FUNC int exprconst(cell *val,int *tag,symbol **symptr);
|
||||
SC_FUNC constvalue *append_constval(constvalue *table,const char *name,cell val,int index);
|
||||
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_constant(const char *name,cell val,int vclass,int tag);
|
||||
SC_FUNC void exporttag(int tag);
|
||||
SC_FUNC void sc_attachdocumentation(symbol *sym);
|
||||
SC_FUNC constvalue *find_tag_byval(int tag);
|
||||
@ -794,7 +794,7 @@ SC_FUNC int error(int number,...);
|
||||
SC_FUNC void errorset(int code,int line);
|
||||
|
||||
/* function prototypes in SC6.C */
|
||||
SC_FUNC int assemble(FILE *fout,FILE *fin);
|
||||
SC_FUNC int assemble(void *fout,void *fin);
|
||||
|
||||
/* function prototypes in SC7.C */
|
||||
SC_FUNC void stgbuffer_cleanup(void);
|
||||
@ -816,7 +816,7 @@ SC_FUNC void delete_aliastable(void);
|
||||
SC_FUNC stringlist *insert_path(char *path);
|
||||
SC_FUNC char *get_path(int index);
|
||||
SC_FUNC void delete_pathtable(void);
|
||||
SC_FUNC stringpair *insert_subst(char *pattern,char *substitution,int prefixlen);
|
||||
SC_FUNC stringpair *insert_subst(const char *pattern,const char *substitution,int prefixlen);
|
||||
SC_FUNC int get_subst(int index,char **pattern,char **substitution);
|
||||
SC_FUNC stringpair *find_subst(char *name,int length);
|
||||
SC_FUNC int delete_subst(char *name,int length);
|
||||
|
@ -585,7 +585,7 @@ cleanup:
|
||||
#if defined __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
int pc_addconstant(char *name,cell value,int tag)
|
||||
int pc_addconstant(const char *name,cell value,int tag)
|
||||
{
|
||||
errorset(sFORCESET,0); /* make sure error engine is silenced */
|
||||
sc_status=statIDLE;
|
||||
@ -833,7 +833,7 @@ static char *get_extension(char *filename)
|
||||
* Set the default extension, or force an extension. To erase the
|
||||
* extension of a filename, set "extension" to an empty string.
|
||||
*/
|
||||
SC_FUNC void set_extension(char *filename,char *extension,int force)
|
||||
SC_FUNC void set_extension(char *filename,const char *extension,int force)
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
@ -1364,35 +1364,14 @@ static void setconstants(void)
|
||||
add_constant("false",0,sGLOBAL,1);
|
||||
add_constant("EOS",0,sGLOBAL,0); /* End Of String, or '\0' */
|
||||
add_constant("INVALID_FUNCTION", -1, sGLOBAL, pc_tag_nullfunc_t);
|
||||
#if PAWN_CELL_SIZE==16
|
||||
add_constant("cellbits",16,sGLOBAL,0);
|
||||
#if defined _I16_MAX
|
||||
add_constant("cellmax",_I16_MAX,sGLOBAL,0);
|
||||
add_constant("cellmin",_I16_MIN,sGLOBAL,0);
|
||||
#else
|
||||
add_constant("cellmax",SHRT_MAX,sGLOBAL,0);
|
||||
add_constant("cellmin",SHRT_MIN,sGLOBAL,0);
|
||||
#endif
|
||||
#elif PAWN_CELL_SIZE==32
|
||||
add_constant("cellbits",32,sGLOBAL,0);
|
||||
#if defined _I32_MAX
|
||||
add_constant("cellmax",_I32_MAX,sGLOBAL,0);
|
||||
add_constant("cellmin",_I32_MIN,sGLOBAL,0);
|
||||
#else
|
||||
add_constant("cellmax",LONG_MAX,sGLOBAL,0);
|
||||
add_constant("cellmin",LONG_MIN,sGLOBAL,0);
|
||||
#endif
|
||||
#elif PAWN_CELL_SIZE==64
|
||||
#if !defined _I64_MIN
|
||||
#define _I64_MIN (-9223372036854775807ULL - 1)
|
||||
#define _I64_MAX 9223372036854775807ULL
|
||||
#endif
|
||||
add_constant("cellbits",64,sGLOBAL,0);
|
||||
add_constant("cellmax",_I64_MAX,sGLOBAL,0);
|
||||
add_constant("cellmin",_I64_MIN,sGLOBAL,0);
|
||||
#else
|
||||
#error Unsupported cell size
|
||||
#endif
|
||||
add_constant("cellbits",32,sGLOBAL,0);
|
||||
#if defined _I32_MAX
|
||||
add_constant("cellmax",_I32_MAX,sGLOBAL,0);
|
||||
add_constant("cellmin",_I32_MIN,sGLOBAL,0);
|
||||
#else
|
||||
add_constant("cellmax",LONG_MAX,sGLOBAL,0);
|
||||
add_constant("cellmin",LONG_MIN,sGLOBAL,0);
|
||||
#endif
|
||||
add_constant("charbits",sCHARBITS,sGLOBAL,0);
|
||||
add_constant("charmin",0,sGLOBAL,0);
|
||||
add_constant("charmax",~(-1 << sCHARBITS) - 1,sGLOBAL,0);
|
||||
@ -4061,19 +4040,36 @@ static void domethodmap(LayoutSpec spec)
|
||||
require_newline(TRUE);
|
||||
}
|
||||
|
||||
class AutoStage
|
||||
{
|
||||
public:
|
||||
AutoStage() : lcl_staging_(FALSE)
|
||||
{
|
||||
if (!staging) {
|
||||
stgset(TRUE);
|
||||
lcl_staging_ = TRUE;
|
||||
lcl_stgidx_ = stgidx;
|
||||
assert(stgidx == 0);
|
||||
}
|
||||
}
|
||||
~AutoStage() {
|
||||
if (lcl_staging_) {
|
||||
stgout(lcl_stgidx_);
|
||||
stgset(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int lcl_staging_;
|
||||
int lcl_stgidx_;
|
||||
};
|
||||
|
||||
// delete ::= "delete" expr
|
||||
static void dodelete()
|
||||
{
|
||||
AutoStage staging_on;
|
||||
|
||||
svalue sval;
|
||||
|
||||
int lcl_staging = FALSE;
|
||||
if (!staging) {
|
||||
stgset(TRUE);
|
||||
lcl_staging = TRUE;
|
||||
assert(stgidx == 0);
|
||||
}
|
||||
int lcl_stgidx = stgidx;
|
||||
|
||||
int ident = lvalexpr(&sval);
|
||||
needtoken(tTERM);
|
||||
|
||||
@ -4081,7 +4077,7 @@ static void dodelete()
|
||||
case iFUNCTN:
|
||||
case iREFFUNC:
|
||||
error(115, "functions");
|
||||
goto cleanup;
|
||||
return;
|
||||
|
||||
case iARRAY:
|
||||
case iREFARRAY:
|
||||
@ -4091,7 +4087,7 @@ static void dodelete()
|
||||
symbol *sym = sval.val.sym;
|
||||
if (!sym || sym->dim.array.level > 0) {
|
||||
error(115, "arrays");
|
||||
goto cleanup;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -4099,13 +4095,13 @@ static void dodelete()
|
||||
|
||||
if (sval.val.tag == 0) {
|
||||
error(115, "primitive types or enums");
|
||||
goto cleanup;
|
||||
return;
|
||||
}
|
||||
|
||||
methodmap_t *map = methodmap_find_by_tag(sval.val.tag);
|
||||
if (!map) {
|
||||
error(115, pc_tagname(sval.val.tag));
|
||||
goto cleanup;
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
@ -4121,7 +4117,7 @@ static void dodelete()
|
||||
|
||||
if (!map || !map->dtor) {
|
||||
error(115, layout_spec_name(map->spec), map->name);
|
||||
goto cleanup;
|
||||
return;
|
||||
}
|
||||
|
||||
// Only zap non-const lvalues.
|
||||
@ -4182,12 +4178,6 @@ static void dodelete()
|
||||
}
|
||||
|
||||
markexpr(sEXPR, NULL, 0);
|
||||
|
||||
cleanup:
|
||||
if (lcl_staging) {
|
||||
stgout(lcl_stgidx);
|
||||
stgset(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4965,7 +4955,7 @@ static char *tag2str(char *dest,int tag)
|
||||
return isdigit(dest[1]) ? &dest[1] : dest;
|
||||
}
|
||||
|
||||
SC_FUNC char *operator_symname(char *symname,char *opername,int tag1,int tag2,int numtags,int resulttag)
|
||||
SC_FUNC char *operator_symname(char *symname,const char *opername,int tag1,int tag2,int numtags,int resulttag)
|
||||
{
|
||||
char tagstr1[10], tagstr2[10];
|
||||
int opertok;
|
||||
@ -5281,7 +5271,7 @@ static int newfunc(declinfo_t *decl, const int *thistag, int fpublic, int fstati
|
||||
} /* if */
|
||||
|
||||
if ((sym->flags & flgDEPRECATED) != 0 && (sym->usage & uSTOCK) == 0) {
|
||||
char *ptr= (sym->documentation!=NULL) ? sym->documentation : "";
|
||||
const char *ptr= (sym->documentation!=NULL) ? sym->documentation : "";
|
||||
error(234, decl->name, ptr); /* deprecated (probably a public function) */
|
||||
} /* if */
|
||||
begcseg();
|
||||
@ -5472,7 +5462,7 @@ static int declargs(symbol *sym, int chkshadow, const int *thistag)
|
||||
memset(argptr, 0, sizeof(*argptr));
|
||||
strcpy(argptr->name, "this");
|
||||
argptr->ident = iVARIABLE;
|
||||
argptr->tags = malloc(sizeof(int));
|
||||
argptr->tags = (int *)malloc(sizeof(int));
|
||||
argptr->tags[0] = *thistag;
|
||||
argptr->numtags = 1;
|
||||
} else {
|
||||
@ -5775,11 +5765,12 @@ static int count_referrers(symbol *entry)
|
||||
}
|
||||
|
||||
#if !defined SC_LIGHT
|
||||
static int find_xmltag(char *source,char *xmltag,char *xmlparam,char *xmlvalue,
|
||||
static int find_xmltag(char *source, const char *xmltag, const char *xmlparam, const char *xmlvalue,
|
||||
char **outer_start,int *outer_length,
|
||||
char **inner_start,int *inner_length)
|
||||
const char **inner_start,int *inner_length)
|
||||
{
|
||||
char *ptr,*inner_end;
|
||||
char *ptr;
|
||||
const char *inner_end;
|
||||
int xmltag_len,xmlparam_len,xmlvalue_len;
|
||||
int match;
|
||||
|
||||
@ -6122,7 +6113,8 @@ static void make_report(symbol *root,FILE *log,char *sourcefile)
|
||||
assert(sym->dim.arglist!=NULL);
|
||||
for (arg=0; sym->dim.arglist[arg].ident!=0; arg++) {
|
||||
int dim,paraminfo;
|
||||
char *outer_start,*inner_start;
|
||||
char *outer_start;
|
||||
const char *inner_start;
|
||||
int outer_length,inner_length;
|
||||
if (sym->dim.arglist[arg].ident==iVARARGS)
|
||||
fprintf(log,"\t\t\t<param name=\"...\">\n");
|
||||
@ -6175,10 +6167,9 @@ static void make_report(symbol *root,FILE *log,char *sourcefile)
|
||||
&& find_xmltag(sym->documentation, "param", "name", sym->dim.arglist[arg].name,
|
||||
&outer_start, &outer_length, &inner_start, &inner_length))
|
||||
{
|
||||
char *tail;
|
||||
fprintf(log,"\t\t\t\t%.*s\n",inner_length,inner_start);
|
||||
/* delete from documentation string */
|
||||
tail=outer_start+outer_length;
|
||||
char *tail=outer_start+outer_length;
|
||||
memmove(outer_start,tail,strlen(tail)+1);
|
||||
} /* if */
|
||||
fprintf(log,"\t\t\t</param>\n");
|
||||
@ -6571,7 +6562,7 @@ SC_FUNC void delete_consttable(constvalue *table)
|
||||
*
|
||||
* Adds a symbol to the symbol table. Returns NULL on failure.
|
||||
*/
|
||||
SC_FUNC symbol *add_constant(char *name,cell val,int vclass,int tag)
|
||||
SC_FUNC symbol *add_constant(const char *name,cell val,int vclass,int tag)
|
||||
{
|
||||
symbol *sym;
|
||||
|
||||
@ -6980,7 +6971,7 @@ static int test(int label,int parens,int invert)
|
||||
if (endtok!=0)
|
||||
needtoken(endtok);
|
||||
if (ident==iARRAY || ident==iREFARRAY) {
|
||||
char *ptr=(sym->name!=NULL) ? sym->name : "-unknown-";
|
||||
const char *ptr=(sym->name!=NULL) ? sym->name : "-unknown-";
|
||||
error(33,ptr); /* array must be indexed */
|
||||
} /* if */
|
||||
if (ident==iCONSTEXPR) { /* constant expression */
|
@ -37,10 +37,10 @@
|
||||
#endif
|
||||
|
||||
|
||||
static void append_dbginfo(FILE *fout);
|
||||
static void append_dbginfo(void *fout);
|
||||
|
||||
|
||||
typedef cell (*OPCODE_PROC)(FILE *fbin,char *params,cell opcode);
|
||||
typedef cell (*OPCODE_PROC)(void *fbin,char *params,cell opcode);
|
||||
|
||||
typedef struct {
|
||||
cell opcode;
|
||||
@ -192,7 +192,7 @@ static char *stripcomment(char *str)
|
||||
return str;
|
||||
}
|
||||
|
||||
static void write_encoded(FILE *fbin,ucell *c,int num)
|
||||
static void write_encoded(void *fbin,ucell *c,int num)
|
||||
{
|
||||
#if PAWN_CELL_SIZE == 16
|
||||
#define ENC_MAX 3 /* a 16-bit cell is encoded in max. 3 bytes */
|
||||
@ -246,7 +246,7 @@ static void write_encoded(FILE *fbin,ucell *c,int num)
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
static cell noop(FILE *fbin,char *params,cell opcode)
|
||||
static cell noop(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -254,7 +254,7 @@ static cell noop(FILE *fbin,char *params,cell opcode)
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
static cell set_currentfile(FILE *fbin,char *params,cell opcode)
|
||||
static cell set_currentfile(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
fcurrent=(short)getparam(params,NULL);
|
||||
return 0;
|
||||
@ -263,14 +263,14 @@ static cell set_currentfile(FILE *fbin,char *params,cell opcode)
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
static cell parm0(FILE *fbin,char *params,cell opcode)
|
||||
static cell parm0(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
if (fbin!=NULL)
|
||||
write_encoded(fbin,(ucell*)&opcode,1);
|
||||
return opcodes(1);
|
||||
}
|
||||
|
||||
static cell parm1(FILE *fbin,char *params,cell opcode)
|
||||
static cell parm1(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
ucell p=getparam(params,NULL);
|
||||
if (fbin!=NULL) {
|
||||
@ -280,7 +280,7 @@ static cell parm1(FILE *fbin,char *params,cell opcode)
|
||||
return opcodes(1)+opargs(1);
|
||||
}
|
||||
|
||||
static cell parm2(FILE *fbin,char *params,cell opcode)
|
||||
static cell parm2(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
ucell p1=getparam(params,¶ms);
|
||||
ucell p2=getparam(params,NULL);
|
||||
@ -292,7 +292,7 @@ static cell parm2(FILE *fbin,char *params,cell opcode)
|
||||
return opcodes(1)+opargs(2);
|
||||
}
|
||||
|
||||
static cell parm3(FILE *fbin,char *params,cell opcode)
|
||||
static cell parm3(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
ucell p1=getparam(params,¶ms);
|
||||
ucell p2=getparam(params,¶ms);
|
||||
@ -306,7 +306,7 @@ static cell parm3(FILE *fbin,char *params,cell opcode)
|
||||
return opcodes(1)+opargs(3);
|
||||
}
|
||||
|
||||
static cell parm4(FILE *fbin,char *params,cell opcode)
|
||||
static cell parm4(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
ucell p1=getparam(params,¶ms);
|
||||
ucell p2=getparam(params,¶ms);
|
||||
@ -322,7 +322,7 @@ static cell parm4(FILE *fbin,char *params,cell opcode)
|
||||
return opcodes(1)+opargs(4);
|
||||
}
|
||||
|
||||
static cell parm5(FILE *fbin,char *params,cell opcode)
|
||||
static cell parm5(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
ucell p1=getparam(params,¶ms);
|
||||
ucell p2=getparam(params,¶ms);
|
||||
@ -343,7 +343,7 @@ static cell parm5(FILE *fbin,char *params,cell opcode)
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
static cell do_dump(FILE *fbin,char *params,cell opcode)
|
||||
static cell do_dump(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
ucell p;
|
||||
int num = 0;
|
||||
@ -359,7 +359,7 @@ static cell do_dump(FILE *fbin,char *params,cell opcode)
|
||||
return num*sizeof(cell);
|
||||
}
|
||||
|
||||
static cell do_call(FILE *fbin,char *params,cell opcode)
|
||||
static cell do_call(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
char name[sNAMEMAX+1];
|
||||
int i;
|
||||
@ -399,7 +399,7 @@ static cell do_call(FILE *fbin,char *params,cell opcode)
|
||||
return opcodes(1)+opargs(1);
|
||||
}
|
||||
|
||||
static cell do_jump(FILE *fbin,char *params,cell opcode)
|
||||
static cell do_jump(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
int i;
|
||||
ucell p;
|
||||
@ -416,7 +416,7 @@ static cell do_jump(FILE *fbin,char *params,cell opcode)
|
||||
return opcodes(1)+opargs(1);
|
||||
}
|
||||
|
||||
static cell do_switch(FILE *fbin,char *params,cell opcode)
|
||||
static cell do_switch(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
int i;
|
||||
ucell p;
|
||||
@ -436,7 +436,7 @@ static cell do_switch(FILE *fbin,char *params,cell opcode)
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
static cell do_case(FILE *fbin,char *params,cell opcode)
|
||||
static cell do_case(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
int i;
|
||||
ucell p,v;
|
||||
@ -659,7 +659,7 @@ static int findopcode(char *instr,int maxlen)
|
||||
return 0; /* not found, return special index */
|
||||
}
|
||||
|
||||
SC_FUNC int assemble(FILE *fout,FILE *fin)
|
||||
SC_FUNC int assemble(void *fout, void *fin)
|
||||
{
|
||||
AMX_HEADER hdr;
|
||||
AMX_FUNCSTUBNT func;
|
||||
@ -1058,7 +1058,7 @@ SC_FUNC int assemble(FILE *fout,FILE *fin)
|
||||
return size;
|
||||
}
|
||||
|
||||
static void append_dbginfo(FILE *fout)
|
||||
static void append_dbginfo(void *fout)
|
||||
{
|
||||
AMX_DBG_HDR dbghdr;
|
||||
AMX_DBG_LINE dbgline;
|
||||
|
@ -49,7 +49,7 @@ SC_FUNC char* duplicatestring(const char* sourcestring)
|
||||
}
|
||||
|
||||
|
||||
static stringpair *insert_stringpair(stringpair *root,char *first,char *second,int matchlength)
|
||||
static stringpair *insert_stringpair(stringpair *root,const char *first,const char *second,int matchlength)
|
||||
{
|
||||
stringpair *cur,*pred;
|
||||
|
||||
@ -275,7 +275,7 @@ static void adjustindex(char c)
|
||||
substindex[(int)c-PUBLIC_CHAR]=cur;
|
||||
}
|
||||
|
||||
SC_FUNC stringpair *insert_subst(char *pattern,char *substitution,int prefixlen)
|
||||
SC_FUNC stringpair *insert_subst(const char *pattern,const char *substitution,int prefixlen)
|
||||
{
|
||||
stringpair *cur;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user