From 64277a2767697e68afd84a560c8d51cea41fbf57 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sat, 8 May 2021 17:43:09 +0700 Subject: [PATCH 1/7] Remove unused duplicate functions from sc1.c --- source/compiler/CMakeLists.txt | 1 - source/compiler/sc1.c | 283 --------------------------------- 2 files changed, 284 deletions(-) diff --git a/source/compiler/CMakeLists.txt b/source/compiler/CMakeLists.txt index 5bf31730..d1de5f95 100644 --- a/source/compiler/CMakeLists.txt +++ b/source/compiler/CMakeLists.txt @@ -92,7 +92,6 @@ set(PAWNC_SRCS scstate.c scvars.c version.h) -set_source_files_properties(sc1.c COMPILE_FLAGS -DNO_MAIN) if(WIN32) set(PAWNC_SRCS ${PAWNC_SRCS} libpawnc.rc) set_source_files_properties(libpawnc.c COMPILE_FLAGS -DPAWNC_DLL) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index cedcbcbb..92ff0ce4 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -231,289 +231,6 @@ static char reportname[_MAX_PATH];/* report file name */ static HWND hwndFinish = 0; #endif -#if !defined NO_MAIN - -#if defined __TURBOC__ && !defined __32BIT__ - extern unsigned int _stklen = 0x2000; -#endif - -int main(int argc, char *argv[]) -{ - return pc_compile(argc,argv); -} - -/* pc_printf() - * Called for general purpose "console" output. This function prints general - * purpose messages; errors go through pc_error(). The function is modelled - * after printf(). - */ -int pc_printf(const char *message,...) -{ - int ret; - va_list argptr; - - va_start(argptr,message); - ret=vprintf(message,argptr); - va_end(argptr); - - return ret; -} - -/* pc_error() - * Called for producing error output. - * number the error number (as documented in the manual) - * message a string describing the error with embedded %d and %s tokens - * filename the name of the file currently being parsed - * firstline the line number at which the expression started on which - * the error was found, or -1 if there is no "starting line" - * lastline the line number at which the error was detected - * argptr a pointer to the first of a series of arguments (for macro - * "va_arg") - * Return: - * If the function returns 0, the parser attempts to continue compilation. - * On a non-zero return value, the parser aborts. - */ -int pc_error(int number,char *message,char *filename,int firstline,int lastline,va_list argptr) -{ -static char *prefix[3]={ "error", "fatal error", "warning" }; - - if (number!=0) { - char *pre; - - pre=prefix[number/100]; - if (number>=200 && pc_geterrorwarnings()){ - pre=prefix[0]; - } - if (firstline>=0) - fprintf(stderr,"%s(%d -- %d) : %s %03d: ",filename,firstline,lastline,pre,number); - else - fprintf(stderr,"%s(%d) : %s %03d: ",filename,lastline,pre,number); - } /* if */ - vfprintf(stderr,message,argptr); - fflush(stderr); - return 0; -} - -/* pc_opensrc() - * Opens a source file (or include file) for reading. The "file" does not have - * to be a physical file, one might compile from memory. - * filename the name of the "file" to read from - * Return: - * The function must return a pointer, which is used as a "magic cookie" to - * all I/O functions. When failing to open the file for reading, the - * function must return NULL. - * Note: - * Several "source files" may be open at the same time. Specifically, one - * file can be open for reading and another for writing. - */ -void *pc_opensrc(char *filename) -{ - return fopen(filename,"r"); -} - -/* pc_createsrc() - * Creates/overwrites a source file for writing. The "file" does not have - * to be a physical file, one might compile from memory. - * filename the name of the "file" to create - * Return: - * The function must return a pointer, which is used as a "magic cookie" to - * all I/O functions. When failing to open the file for reading, the - * function must return NULL. - * Note: - * Several "source files" may be open at the same time. Specifically, one - * file can be open for reading and another for writing. - */ -void *pc_createsrc(char *filename) -{ - return fopen(filename,"w"); -} - -/* pc_createtmpsrc() - * Creates a temporary source file with a unique name for writing. - * Return: - * The function must return a pointer, which is used as a "magic cookie" to - * all I/O functions. When failing to open the file for reading, the - * function must return NULL. - */ -void *pc_createtmpsrc(char **filename) -{ - char *tname=NULL; - FILE *ftmp=NULL; - - #if defined __WIN32__ || defined _WIN32 - tname=_tempnam(NULL,"pawn"); - ftmp=fopen(tname,"wt"); - #elif defined __MSDOS__ || defined _Windows - tname=tempnam(NULL,"pawn"); - ftmp=fopen(tname,"wt"); - #else - static const char template[]="/tmp/pawnXXXXXX"; - if ((tname=malloc(sizeof(template)))!=NULL) { - int fdtmp; - strncpy(tname,template,arraysize(template)); - if ((fdtmp=mkstemp(tname)) >= 0) { - ftmp=fdopen(fdtmp,"wt"); - } else { - free(tname); - tname=NULL; - } /* if */ - } /* if */ - #endif - if (filename!=NULL) - *filename=tname; - return ftmp; -} - -/* pc_closesrc() - * Closes a source file (or include file). The "handle" parameter has the - * value that pc_opensrc() returned in an earlier call. - */ -void pc_closesrc(void *handle) -{ - assert(handle!=NULL); - fclose((FILE*)handle); -} - -/* pc_resetsrc() - * "position" may only hold a pointer that was previously obtained from - * pc_getpossrc() - */ -void pc_resetsrc(void *handle,void *position) -{ - assert(handle!=NULL); - fsetpos((FILE*)handle,(fpos_t *)position); -} - -/* pc_readsrc() - * Reads a single line from the source file (or up to a maximum number of - * characters if the line in the input file is too long). - */ -char *pc_readsrc(void *handle,unsigned char *target,int maxchars) -{ - return fgets((char*)target,maxchars,(FILE*)handle); -} - -/* pc_writesrc() - * Writes to to the source file. There is no automatic line ending; to end a - * line, write a "\n". - */ -int pc_writesrc(void *handle,unsigned char *source) -{ - return fputs((char*)source,(FILE*)handle) >= 0; -} - -void *pc_getpossrc(void *handle) -{ - static fpos_t lastpos; /* may need to have a LIFO stack of such positions */ - - fgetpos((FILE*)handle,&lastpos); - return &lastpos; -} - -int pc_eofsrc(void *handle) -{ - return feof((FILE*)handle); -} - -/* should return a pointer, which is used as a "magic cookie" to all I/O - * functions; return NULL for failure - */ -void *pc_openasm(char *filename) -{ - #if defined __MSDOS__ || defined SC_LIGHT - return fopen(filename,"w+"); - #else - return mfcreate(filename); - #endif -} - -void pc_closeasm(void *handle, int deletefile) -{ - #if defined __MSDOS__ || defined SC_LIGHT - if (handle!=NULL) - fclose((FILE*)handle); - if (deletefile) - remove(outfname); - #else - if (handle!=NULL) { - if (!deletefile) - mfdump((MEMFILE*)handle); - mfclose((MEMFILE*)handle); - } /* if */ - #endif -} - -void pc_resetasm(void *handle) -{ - assert(handle!=NULL); - #if defined __MSDOS__ || defined SC_LIGHT - fflush((FILE*)handle); - fseek((FILE*)handle,0,SEEK_SET); - #else - mfseek((MEMFILE*)handle,0,SEEK_SET); - #endif -} - -int pc_writeasm(void *handle,char *string) -{ - #if defined __MSDOS__ || defined SC_LIGHT - return fputs(string,(FILE*)handle) >= 0; - #else - return mfputs((MEMFILE*)handle,string); - #endif -} - -char *pc_readasm(void *handle, char *string, int maxchars) -{ - #if defined __MSDOS__ || defined SC_LIGHT - return fgets(string,maxchars,(FILE*)handle); - #else - return mfgets((MEMFILE*)handle,string,maxchars); - #endif -} - -/* Should return a pointer, which is used as a "magic cookie" to all I/O - * functions; return NULL for failure. - */ -void *pc_openbin(char *filename) -{ - FILE *fbin; - - fbin=fopen(filename,"wb"); - setvbuf(fbin,NULL,_IOFBF,1UL<<20); - return fbin; -} - -void pc_closebin(void *handle,int deletefile) -{ - fclose((FILE*)handle); - if (deletefile) - remove(binfname); -} - -/* pc_resetbin() - * Can seek to any location in the file. - * The offset is always from the start of the file. - */ -void pc_resetbin(void *handle,long offset) -{ - fflush((FILE*)handle); - fseek((FILE*)handle,offset,SEEK_SET); -} - -int pc_writebin(void *handle,void *buffer,int size) -{ - return (int)fwrite(buffer,1,size,(FILE*)handle) == size; -} - -long pc_lengthbin(void *handle) -{ - return ftell((FILE*)handle); -} - -#endif /* !defined NO_MAIN */ - - /* "main" of the compiler */ #if defined __cplusplus From 0584a2e5c001f3833bdc74d230ce65c34d34710a Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sun, 20 Mar 2022 22:16:51 +0700 Subject: [PATCH 2/7] Update the description for function `stripcomment()` --- source/compiler/sc2.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 0895dfac..f0552898 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -442,7 +442,7 @@ static void readline(unsigned char *line) } while (num>=0 && cont); } -/* stripcom +/* stripcomment * * Replaces all comments from the line by space characters. It updates * a global variable ("icomment") for multiline comments, and a global @@ -454,8 +454,8 @@ static void readline(unsigned char *line) * The function also detects (and manages) "documentation comments". The * global variable "icomment" is set to 2 for documentation comments. * - * Global references: icomment (private to "stripcom") - * Global references: imlstring (private to "stripcom") + * Global references: icomment (private to "stripcomment") + * Global references: imlstring (private to "stripcomment") * * Returns 1 if the line started with a multiline string, and 2 if it also * ends with the same multiline string, so that this won't trigger commands: @@ -467,7 +467,6 @@ static void readline(unsigned char *line) * * Some code might see that as a line starting with `#define` because there * was no explicit line continuation, merely an implicit string one. - * */ static int stripcomment(unsigned char *line) { From dff0236743140a39a80e82ea1adfd923501214d5 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sun, 20 Mar 2022 23:01:54 +0700 Subject: [PATCH 3/7] Fix indentation and add a description for warning 239 --- source/compiler/sc3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/sc3.c b/source/compiler/sc3.c index 44e9de05..0881d3bd 100644 --- a/source/compiler/sc3.c +++ b/source/compiler/sc3.c @@ -2469,7 +2469,7 @@ static int nesting=0; error(48); /* array dimensions must match */ } else { if (lval.sym==NULL && (arg[argidx].usage & uCONST)==0) - error(239); + error(239); /* literal array/string passed to a non-const parameter */ if (arg[argidx].dim[0]!=0) { assert(arg[argidx].dim[0]>0); if (lval.ident==iARRAYCELL) { From 0231a64ab9e4c88b3fbe1cc869c444b73f296910 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sat, 9 Apr 2022 16:25:00 +0700 Subject: [PATCH 4/7] Update the description for `sc_alignnext` --- source/compiler/sc.h | 2 +- source/compiler/scvars.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index d5576510..3cb24f50 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -992,7 +992,7 @@ SC_VDECL int sc_listing; /* create .LST file? */ SC_VDECL int sc_compress; /* compress bytecode? */ SC_VDECL int sc_needsemicolon;/* semicolon required to terminate expressions? */ SC_VDECL int sc_dataalign; /* data alignment value */ -SC_VDECL int sc_alignnext; /* must frame of the next function be aligned? */ +SC_VDECL int sc_alignnext; /* must the next variable or the frame of the next function be aligned? */ SC_VDECL int pc_docexpr; /* must expression be attached to documentation comment? */ SC_VDECL int curseg; /* 1 if currently parsing CODE, 2 if parsing DATA */ SC_VDECL cell pc_stksize; /* stack size */ diff --git a/source/compiler/scvars.c b/source/compiler/scvars.c index d43604ba..532f7629 100644 --- a/source/compiler/scvars.c +++ b/source/compiler/scvars.c @@ -68,7 +68,7 @@ SC_VDEFINE int sc_listing= FALSE; /* create .LST file? */ SC_VDEFINE int sc_compress=TRUE; /* compress bytecode? */ SC_VDEFINE int sc_needsemicolon=TRUE; /* semicolon required to terminate expressions? */ SC_VDEFINE int sc_dataalign=sizeof(cell); /* data alignment value */ -SC_VDEFINE int sc_alignnext=FALSE; /* must frame of the next function be aligned? */ +SC_VDEFINE int sc_alignnext=FALSE; /* must the next variable or the frame of the next function be aligned? */ SC_VDEFINE int pc_docexpr=FALSE; /* must expression be attached to documentation comment? */ SC_VDEFINE int curseg=0; /* 1 if currently parsing CODE, 2 if parsing DATA */ SC_VDEFINE cell pc_stksize=sDEF_AMXSTACK; /* default stack size */ From 91699a26ba2ab86c7ca4d55bed63a0143c6afc65 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sat, 9 Apr 2022 19:29:12 +0700 Subject: [PATCH 5/7] Fix the description for `sc_allowproccall` It seems that the whole line for `sc_allowproccall` was simply copy-pasted from `sc_allowtags` without changing the description. --- source/compiler/sc.h | 2 +- source/compiler/scvars.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index 3cb24f50..ed52fbb9 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -1012,7 +1012,7 @@ SC_VDECL short sc_allowtags; /* allow/detect tagnames in lex() */ SC_VDECL int sc_status; /* read/write status */ 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 int sc_allowproccall;/* allow "procedure call" syntax */ 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 int sc_curstates; /* ID of the current state list */ diff --git a/source/compiler/scvars.c b/source/compiler/scvars.c index 532f7629..5a59848f 100644 --- a/source/compiler/scvars.c +++ b/source/compiler/scvars.c @@ -89,7 +89,7 @@ SC_VDEFINE short sc_allowtags=TRUE; /* allow/detect tagnames in lex() */ SC_VDEFINE int sc_status; /* read/write status */ 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=FALSE; /* allow/detect tagnames in lex() */ +SC_VDEFINE int sc_allowproccall=FALSE; /* allow "procedure call" syntax */ 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_curstates=0; /* ID of the current state list */ From a03cc31e4beefc1d939bd4564d6258ea6a921e92 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 20 Jun 2022 21:49:38 +0700 Subject: [PATCH 6/7] `pc_createtmpsrc()`: use `arraysize` when passing the number of characters to copy to `strncpy()` --- source/compiler/libpawnc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/libpawnc.c b/source/compiler/libpawnc.c index 9f55deac..17986571 100644 --- a/source/compiler/libpawnc.c +++ b/source/compiler/libpawnc.c @@ -204,7 +204,7 @@ void *pc_createtmpsrc(char **filename) static const char template[]="/tmp/pawnXXXXXX"; if ((tname=malloc(sizeof(template)))!=NULL) { int fdtmp; - strncpy(tname,template,sizeof(template)); + strncpy(tname,template,arraysize(template)); if ((fdtmp=mkstemp(tname))>=0) ftmp=fdopen(fdtmp,"wt"); if (fdtmp<0 || filename==NULL) { From e5cc1dbb084ae746c33bc51816a85d85c3705cb8 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sun, 1 Jan 2023 23:24:07 +0700 Subject: [PATCH 7/7] Update the description for `arginfo.hasdefault` --- source/compiler/sc.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index ed52fbb9..e6cea2de 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -74,7 +74,10 @@ typedef struct s_arginfo { /* function argument info */ int dim[sDIMEN_MAX]; int idxtag[sDIMEN_MAX]; int numdim; /* number of dimensions */ - unsigned char hasdefault; /* bit0: is there a default value? bit6: "tagof"; bit7: "sizeof" */ + unsigned char hasdefault; /* bit0: is there a default value? + * bit5: "tagof" (with tag name as an argument); + * bit6: "tagof" (with symbol name as an argument); + * bit7: "sizeof" */ union { cell val; /* default value */ struct {