From 6f98944f4906928a6daca29a8c3338cbed0d27c5 Mon Sep 17 00:00:00 2001 From: Dayvison Balmant Date: Fri, 2 Feb 2018 20:23:17 -0200 Subject: [PATCH 1/7] Fix `enum_root` and `constants` documentation detection, add `enum_field` documentation --- source/compiler/sc.h | 3 +- source/compiler/sc1.c | 113 +++++++++++++++++++++++++++++------------- source/compiler/sc2.c | 4 +- 3 files changed, 82 insertions(+), 38 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index 48d43fdc..f2db163c 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -157,6 +157,7 @@ typedef struct s_symbol { constvalue *states; /* list of state function/state variable ids + addresses */ int fnumber; /* static global variables: file number in which the declaration is visible */ int lnumber; /* line number (in the current source file) for the declaration */ + int lnumber_end; /* line number (in the current source file) for the end of declaration */ struct s_symbol **refer; /* referrer list, functions that "use" this symbol */ int numrefers; /* number of entries in the referrer list */ char *documentation; /* optional documentation string */ @@ -560,7 +561,7 @@ SC_FUNC symbol *add_constant(char *name,cell val,int vclass,int tag); SC_FUNC symbol *add_builtin_constant(char *name,cell val,int vclass,int tag); SC_FUNC symbol *add_builtin_string_constant(char *name,const char *val,int vclass); SC_FUNC void exporttag(int tag); -SC_FUNC void sc_attachdocumentation(symbol *sym); +SC_FUNC void sc_attachdocumentation(symbol *sym,int onlylastblock); SC_FUNC void emit_parse_line(void); /* function prototypes in SC2.C */ diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index b1ad703a..5ffb4131 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -165,7 +165,8 @@ static int wq[wqTABSZ]; /* "while queue", internal stack for nested loop static int *wqptr; /* pointer to next entry */ #if !defined SC_LIGHT static char sc_rootpath[_MAX_PATH]; - static char *sc_documentation=NULL;/* main documentation */ + static char *pc_globaldoc=NULL;/* main documentation */ + static char *pc_recentdoc=NULL; /* documentation from the most recent comment block */ #endif #if defined __WIN32__ || defined _WIN32 || defined _Windows static HWND hwndFinish = 0; @@ -643,9 +644,9 @@ int pc_compile(int argc, char *argv[]) if (strlen(reportname)>0) fclose(frep); } /* if */ - if (sc_documentation!=NULL) { - free(sc_documentation); - sc_documentation=NULL; + if (pc_globaldoc!=NULL) { + free(pc_globaldoc); + pc_globaldoc=NULL; } /* if */ } /* if */ #endif @@ -784,8 +785,10 @@ int pc_compile(int argc, char *argv[]) #endif #if !defined SC_LIGHT delete_docstringtable(); - if (sc_documentation!=NULL) - free(sc_documentation); + if (pc_globaldoc!=NULL) + free(pc_globaldoc); + if (pc_recentdoc!=NULL) + free(pc_recentdoc); #endif delete_autolisttable(); delete_heaplisttable(); @@ -949,7 +952,8 @@ static void initglobals(void) wqptr=wq; /* initialize while queue pointer */ #if !defined SC_LIGHT - sc_documentation=NULL; + pc_globaldoc=NULL; + pc_recentdoc=NULL; sc_makereport=FALSE; /* do not generate a cross-reference report */ #endif } @@ -1832,7 +1836,7 @@ static void aligndata(int numbytes) * appends documentation comments to the passed-in symbol, or to a global * string if "sym" is NULL. */ -void sc_attachdocumentation(symbol *sym) +void sc_attachdocumentation(symbol *sym,int onlylastblock) { int line; size_t length; @@ -1850,6 +1854,43 @@ void sc_attachdocumentation(symbol *sym) */ // assert(sym==NULL || sym->documentation==NULL || sym->states!=NULL); + if (pc_recentdoc!=NULL) { + /* either copy the most recent comment block to the current symbol, or + * append it to the global documentation + */ + length=strlen(pc_recentdoc); + if (onlylastblock) { + assert(sym!=NULL); + str=sym->documentation; + } else { + str=pc_globaldoc; + } /* if */ + /* set the documentation, or append it to it */ + if (str!=NULL) + length+=strlen(str)+1+4; /* plus 4 for "

" */ + doc=(char*)malloc((length+1)*sizeof(char)); + if (doc!=NULL) { + if (str!=NULL) { + strcpy(doc,str); + free(str); + strcat(doc,"

"); + } else { + *doc='\0'; + } /* if */ + strcat(doc,pc_recentdoc); + if (onlylastblock) { + sym->documentation=doc; + /* force adding the new strings (if any) to the global data */ + sym=NULL; + } else { + pc_globaldoc=doc; + } /* if */ + } /* if */ + /* remove the "recent block" string */ + free(pc_recentdoc); + pc_recentdoc=NULL; + } /* if */ + /* first check the size */ length=0; for (line=0; (str=get_docstring(line))!=NULL && *str!=sDOCSEP; line++) { @@ -1857,24 +1898,20 @@ void sc_attachdocumentation(symbol *sym) length++; /* count 1 extra for a separating space */ length+=strlen(str); } /* for */ - if (sym==NULL && sc_documentation!=NULL) { - length += strlen(sc_documentation) + 1 + 4; /* plus 4 for "

" */ - assert(length>strlen(sc_documentation)); - } /* if */ if (length>0) { /* allocate memory for the documentation */ if (sym!=NULL && sym->documentation!=NULL) - length+=strlen(sym->documentation) + 1 + 4;/* plus 4 for "

" */ + length+=strlen(sym->documentation)+1+4; /* plus 4 for "

" */ doc=(char*)malloc((length+1)*sizeof(char)); if (doc!=NULL) { /* initialize string or concatenate */ - if (sym==NULL && sc_documentation!=NULL) { - strcpy(doc,sc_documentation); - strcat(doc,"

"); - } else if (sym!=NULL && sym->documentation!=NULL) { + if (sym!=NULL && sym->documentation!=NULL) { + size_t len; strcpy(doc,sym->documentation); - strcat(doc,"

"); + len=strlen(doc); + if (len>0 && doc[len-1]!='>' || ((str=get_docstring(0))!=NULL && *str!=sDOCSEP && *str!='<')) + strcat(doc,"

"); free(sym->documentation); sym->documentation=NULL; } else { @@ -1882,7 +1919,7 @@ void sc_attachdocumentation(symbol *sym) } /* if */ /* collect all documentation */ while ((str=get_docstring(0))!=NULL && *str!=sDOCSEP) { - if (doc[0]!='\0') + if (doc[0]!='\0' && str[0]!='<') strcat(doc," "); strcat(doc,str); delete_docstring(0); @@ -1896,9 +1933,8 @@ void sc_attachdocumentation(symbol *sym) assert(sym->documentation==NULL); sym->documentation=doc; } else { - if (sc_documentation!=NULL) - free(sc_documentation); - sc_documentation=doc; + assert(pc_recentdoc==NULL); + pc_recentdoc=doc; } /* if */ } /* if */ } else { @@ -1914,7 +1950,7 @@ static void insert_docstring_separator(void) insert_docstring(sep); } #else - #define sc_attachdocumentation(s) (void)(s) + #define sc_attachdocumentation(s,f) (void)(s,f) #define insert_docstring_separator() #endif @@ -2012,6 +2048,7 @@ static void declglb(char *firstname,int firsttag,int fpublic,int fstatic,int fst ispublic=TRUE; /* implicitly public variable */ assert(!fstatic); } /* if */ + //START_LINE while (matchtoken('[')) { ident=iARRAY; if (numdim == sDIMEN_MAX) { @@ -2209,7 +2246,7 @@ static void declglb(char *firstname,int firsttag,int fpublic,int fstatic,int fst sym->usage|=uSTOCK; if (fstatic) sym->fnumber=filenum; - sc_attachdocumentation(sym);/* attach any documenation to the variable */ + sc_attachdocumentation(sym,TRUE);/* attach any documentation to the variable */ if (sc_status==statSKIP) { sc_status=statWRITE; code_idx=cidx; @@ -2853,7 +2890,9 @@ static void decl_const(int vclass) check_tagmismatch(tag,exprtag,FALSE,symbolline); sym=add_constant(constname,val,vclass,tag); if (sym!=NULL) - sc_attachdocumentation(sym);/* attach any documenation to the constant */ + //LINE_START + //LINE_END + sc_attachdocumentation(sym,TRUE);/* attach any documentation to the constant */ } while (matchtoken(',')); /* enddo */ /* more? */ needtoken(tTERM); } @@ -2900,6 +2939,7 @@ static void decl_enum(int vclass,int fstatic) /* get increment and multiplier */ increment=1; multiplier=1; + if (matchtoken('(')) { if (matchtoken(taADD)) { constexpr(&increment,NULL,NULL); @@ -2920,6 +2960,8 @@ static void decl_enum(int vclass,int fstatic) enumsym->usage |= uENUMROOT; if (fstatic) enumsym->fnumber=filenum; + + sc_attachdocumentation(enumsym,FALSE); /* attach any documentation to the enumeration */ } /* start a new list for the element names */ if ((enumroot=(constvalue*)malloc(sizeof(constvalue)))==NULL) @@ -2969,9 +3011,10 @@ static void decl_enum(int vclass,int fstatic) sym->parent=enumsym; if (enumsym) enumsym->child=sym; - if (fstatic) sym->fnumber=filenum; + + sc_attachdocumentation(sym,FALSE); /* attach any documenation to item */ /* add the constant to a separate list as well */ if (enumroot!=NULL) { @@ -2993,7 +3036,6 @@ static void decl_enum(int vclass,int fstatic) /* assign the constant list */ assert(enumroot!=NULL); enumsym->dim.enumlist=enumroot; - sc_attachdocumentation(enumsym); /* attach any documenation to the enumeration */ } /* if */ } @@ -3400,7 +3442,7 @@ SC_FUNC void check_tagmismatch(int formaltag,int actualtag,int allowcoerce,int e { if (!matchtag(formaltag,actualtag,allowcoerce)) { constvalue *tagsym; - char formal_tagname[sNAMEMAX+3]="none (\"_\"),",actual_tagname[sNAMEMAX+2]="none (\"_\")"; /* two extra characters for quotes */ + char formal_tagname[sNAMEMAX+4]="none (\"_\"),",actual_tagname[sNAMEMAX+3]="none (\"_\")"; /* two extra characters for quotes */ if(formaltag!=0) { tagsym=find_tag_byval(formaltag); sprintf(formal_tagname,"\"%s\",", (tagsym!=NULL) ? tagsym->name : "-unknown-"); @@ -3422,7 +3464,7 @@ SC_FUNC void check_tagmismatch_multiple(int formaltags[],int numtags,int actualt if (!checktag(formaltags, numtags, actualtag)) { int i; constvalue *tagsym; - char formal_tagnames[sLINEMAX]="",actual_tagname[sNAMEMAX+2]="none (\"_\")"; + char formal_tagnames[sLINEMAX]="",actual_tagname[sNAMEMAX+3]="none (\"_\")"; int notag_allowed=FALSE,add_comma=FALSE; for (i=0; iusage &= ~uDEFINE; @@ -3812,7 +3854,7 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc } /* if */ endfunc(); sym->codeaddr=code_idx; - sc_attachdocumentation(sym); /* attach collected documenation to the function */ + sc_attachdocumentation(sym,FALSE); /* attach collected documentation to the function */ if (litidx) { /* if there are literals defined */ glb_declared+=litidx; begdseg(); /* flip to DATA segment */ @@ -4362,10 +4404,10 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) fprintf(log,"\t\n\t\t%s\n\t\n",ptr); /* attach the global documentation, if any */ - if (sc_documentation!=NULL) { + if (pc_globaldoc!=NULL) { fprintf(log,"\n\t\n"); fprintf(log,"\t\n\t\t"); - fputs(sc_documentation,log); + fputs(pc_globaldoc,log); fprintf(log,"\n\t\n\n"); } /* if */ @@ -4382,14 +4424,13 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) || sym->ident==iARRAY || sym->ident==iFUNCTN); if (sym->ident!=iCONSTEXPR || (sym->usage & uENUMROOT)==0) continue; - if ((sym->usage & uREAD)==0) - continue; fprintf(log,"\t\t\n",funcdisplayname(symname,sym->name),sym->addr); if (sym->tag!=0) { tagsym=find_tag_byval(sym->tag); assert(tagsym!=NULL); fprintf(log,"\t\t\t\n",tagsym->name); } /* if */ + /* browse through all fields */ if ((enumroot=sym->dim.enumlist)!=NULL) { enumroot=enumroot->next; /* skip root */ @@ -4405,6 +4446,8 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) } /* if */ if (ref->dim.array.length!=1) fprintf(log,"\t\t\t\t\n",(long)ref->dim.array.length); + if (ref->documentation!=NULL) + fprintf(log,"\t\t\t\t%s\n",ref->documentation); } /* if */ fprintf(log,"\t\t\t\n"); enumroot=enumroot->next; diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 291d0860..3f489da3 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -500,7 +500,7 @@ static void stripcomment(unsigned char *line) * to the global documentation */ if (curfunc==NULL && get_docstring(0)!=NULL) - sc_attachdocumentation(NULL); + sc_attachdocumentation(NULL,FALSE); icomment=2; /* documentation comment */ } /* if */ commentidx=0; @@ -525,7 +525,7 @@ static void stripcomment(unsigned char *line) * block to the global documentation */ if (!singleline && curfunc==NULL && get_docstring(0)!=NULL) - sc_attachdocumentation(NULL); + sc_attachdocumentation(NULL,FALSE); insert_docstring(str); prev_singleline=TRUE; } /* if */ From f2a7a6f4328b5dc32d547a27e08205e5b7590cad Mon Sep 17 00:00:00 2001 From: Dayvison Balmant Date: Sat, 3 Feb 2018 17:34:13 -0200 Subject: [PATCH 2/7] Added location tag and new attributes for documentation I've change how the compiler check if symbol are static, but don't worry all work fine --- source/compiler/sc.h | 9 ++- source/compiler/sc1.c | 167 +++++++++++++++++++++++++++++++++++------- source/compiler/sc2.c | 2 +- 3 files changed, 150 insertions(+), 28 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index f2db163c..3ef806a4 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -155,9 +155,10 @@ typedef struct s_symbol { } array; } dim; /* for 'dimension', both functions and arrays */ constvalue *states; /* list of state function/state variable ids + addresses */ - int fnumber; /* static global variables: file number in which the declaration is visible */ + int fnumber; /* file number where is declared */ int lnumber; /* line number (in the current source file) for the declaration */ - int lnumber_end; /* line number (in the current source file) for the end of declaration */ + int lnumber_decl; /* line number where starts the declaration (ignore prototype) */ + int lnumber_end; /* line number for the end of declaration */ struct s_symbol **refer; /* referrer list, functions that "use" this symbol */ int numrefers; /* number of entries in the referrer list */ char *documentation; /* optional documentation string */ @@ -194,6 +195,7 @@ typedef struct s_symbol { * 3 (uCONST) the variable is constant (may not be assigned to) * 4 (uPUBLIC) the variable is public * 6 (uSTOCK) the variable is discardable (without warning) + * 7 (uSTATIC) the variable is static * * FUNCTION * bits: 0 (uDEFINE) the function is defined ("implemented") in the source file @@ -205,6 +207,7 @@ typedef struct s_symbol { * 6 (uSTOCK) the function is discardable (without warning) * 7 (uMISSING) the function is not implemented in this source file * 8 (uFORWARD) the function is explicitly forwardly declared + * 9 (uSTATIC) the function is static * * CONSTANT * bits: 0 (uDEFINE) the symbol is defined in the source file @@ -213,6 +216,7 @@ typedef struct s_symbol { * 3 (uPREDEF) the constant is pre-defined and should be kept between passes * 5 (uENUMROOT) the constant is the "root" of an enumeration * 6 (uENUMFIELD) the constant is a field in a named enumeration + * 7 (uSTATIC) the function is static */ #define uDEFINE 0x001 #define uREAD 0x002 @@ -228,6 +232,7 @@ typedef struct s_symbol { #define uENUMFIELD 0x040 #define uMISSING 0x080 #define uFORWARD 0x100 +#define uSTATIC 0x200 /* uRETNONE is not stored in the "usage" field of a symbol. It is * used during parsing a function, to detect a mix of "return;" and * "return value;" in a few special cases. diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 5ffb4131..6a428d0e 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -2017,6 +2017,7 @@ static void declglb(char *firstname,int firsttag,int fpublic,int fstatic,int fst char *str; int dim[sDIMEN_MAX]; int numdim; + int linenum; short filenum; symbol *sym; constvalue *enumroot; @@ -2028,6 +2029,7 @@ static void declglb(char *firstname,int firsttag,int fpublic,int fstatic,int fst insert_docstring_separator(); /* see comment in newfunc() */ filenum=fcurrent; /* save file number at the start of the declaration */ do { + linenum=fline; /* save line number at the start of the declaration */ size=1; /* single size (no array) */ numdim=0; /* no dimensions */ ident=iVARIABLE; @@ -2048,7 +2050,6 @@ static void declglb(char *firstname,int firsttag,int fpublic,int fstatic,int fst ispublic=TRUE; /* implicitly public variable */ assert(!fstatic); } /* if */ - //START_LINE while (matchtoken('[')) { ident=iARRAY; if (numdim == sDIMEN_MAX) { @@ -2245,7 +2246,10 @@ static void declglb(char *firstname,int firsttag,int fpublic,int fstatic,int fst if (fstock) sym->usage|=uSTOCK; if (fstatic) - sym->fnumber=filenum; + sym->usage|=uSTATIC; + sym->fnumber=filenum; + sym->lnumber_decl=linenum; + sym->lnumber_end=fline; sc_attachdocumentation(sym,TRUE);/* attach any documentation to the variable */ if (sc_status==statSKIP) { sc_status=statWRITE; @@ -2959,7 +2963,9 @@ static void decl_enum(int vclass,int fstatic) if (enumsym!=NULL) { enumsym->usage |= uENUMROOT; if (fstatic) - enumsym->fnumber=filenum; + enumsym->usage|=uSTATIC; + enumsym->fnumber=filenum; + enumsym->lnumber_decl=fline; sc_attachdocumentation(enumsym,FALSE); /* attach any documentation to the enumeration */ } @@ -3012,7 +3018,10 @@ static void decl_enum(int vclass,int fstatic) if (enumsym) enumsym->child=sym; if (fstatic) - sym->fnumber=filenum; + sym->usage|=uSTATIC; + sym->fnumber=filenum; + sym->lnumber_decl=fline; + sym->lnumber_end=fline; sc_attachdocumentation(sym,FALSE); /* attach any documenation to item */ @@ -3032,6 +3041,7 @@ static void decl_enum(int vclass,int fstatic) /* set the enum name to the "next" value (typically the last value plus one) */ if (enumsym!=NULL) { assert((enumsym->usage & uENUMROOT)!=0); + enumsym->lnumber_end=fline; enumsym->addr=value; /* assign the constant list */ assert(enumroot!=NULL); @@ -3743,7 +3753,9 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc if (fpublic) sym->usage|=uPUBLIC; if (fstatic) - sym->fnumber=filenum; + sym->usage|=uSTATIC; + + sym->fnumber=filenum; check_reparse(sym); /* we want public functions to be explicitly prototyped, as they are called * from the outside @@ -3771,6 +3783,7 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc delete_symbols(&loctab,0,TRUE,TRUE); /* prototype is done; forget everything */ return TRUE; } /* if */ + sym->lnumber_decl=funcline; /* so it is not a prototype, proceed */ /* if this is a function that is not referred to (this can only be detected * in the second stage), shut code generation off */ @@ -3853,6 +3866,7 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc } /* if */ } /* if */ endfunc(); + sym->lnumber_end=fline; sym->codeaddr=code_idx; sc_attachdocumentation(sym,FALSE); /* attach collected documentation to the function */ if (litidx) { /* if there are literals defined */ @@ -4364,6 +4378,14 @@ static char *xmlencode(char *dest,char *source) strcpy(ptr,"&"); ptr+=5; break; + case '\"': + strcpy(ptr,"""); + ptr+=6; + break; + case '\'': + strcpy(ptr,"'"); + ptr+=6; + break; default: *ptr++=*source; } /* switch */ @@ -4374,6 +4396,99 @@ static char *xmlencode(char *dest,char *source) return dest; } + +static void write_docattributes(FILE *log, symbol *sym) +{ + if ((sym->usage & uREAD)==0) + fprintf(log,"\t\t\t\n"); + if (sym->ident==iCONSTEXPR && (sym->usage & uENUMROOT)) { + if ((sym->usage & uCONST)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->usage & uPUBLIC)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->usage & uSTOCK)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->usage & uSTATIC)!=0) + fprintf(log,"\t\t\t\n"); + } + if (sym->ident==iCONSTEXPR && (sym->usage & (uENUMFIELD | uENUMROOT))==0) { + if ((sym->flags & flagPREDEF)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->usage & uENUMROOT)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->usage & uENUMFIELD)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->usage & uSTATIC)!=0) + fprintf(log,"\t\t\t\n"); + } + if (sym->ident==iVARIABLE || sym->ident==iARRAY) { + if ((sym->usage & uCONST)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->usage & uPUBLIC)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->usage & uSTOCK)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->usage & uSTATIC)!=0) + fprintf(log,"\t\t\t\n"); + } + if (sym->ident==iFUNCTN) { + if (strcmp(sym->name,uMAINFUNC)==0 || strcmp(sym->name,uENTRYFUNC)==0) + fprintf(log,"\t\t\t\n"); + if ((sym->flags & flgDEPRECATED)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->flags & flagNAKED)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->usage & uRETVALUE)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->usage & uPROTOTYPED)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->usage & uPUBLIC)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->usage & uNATIVE)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->usage & uSTOCK)!=0) + fprintf(log,"\t\t\t\n"); + if ((sym->usage & uMISSING)!=0) + fprintf(log,"\t\t\t\n"); + /*if ((sym->usage & uFORWARD)!=0) + fprintf(log,"\t\t\t\n");*/ + if ((sym->usage & uSTATIC)!=0) + fprintf(log,"\t\t\t\n"); + } +} +static void write_docstring(FILE *log,const char *string) +{ + int len; + const char *ptr; + + if (string==NULL) + return; + while (*string<=' ' && *string!='\0') + string++; /* skip white space */ + if (*string=='\0') + return; + + assert(strchr(string,sDOCSEP)==NULL); + /* optionally wrap in "

...", check whether this must happen */ + if (*string!='<') { /* wrap in "summary" */ + len=0; + for (ptr=string; *ptr!='\0' && *ptr!='<' && *ptr!='.'; ptr++) + len++; + if (*ptr=='.') + len++; + assert(len>0); + fprintf(log,"\t\t\t%.*s\n",len,string); + string+=len; + while (*string<=' ' && *string!='\0') + string++; /* skip white space */ + } else { + len=0; + } /* if */ + + if (*string!='\0') + fprintf(log,"\t\t\t%s\n",string); +} + static void make_report(symbol *root,FILE *log,char *sourcefile) { char symname[_MAX_PATH]; @@ -4425,10 +4540,14 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) if (sym->ident!=iCONSTEXPR || (sym->usage & uENUMROOT)==0) continue; fprintf(log,"\t\t\n",funcdisplayname(symname,sym->name),sym->addr); + fprintf(log,"\t\t\n", get_sourcefile(sym->fnumber), sym->lnumber_decl, sym->lnumber_end); + write_docattributes(log,sym); if (sym->tag!=0) { tagsym=find_tag_byval(sym->tag); assert(tagsym!=NULL); fprintf(log,"\t\t\t\n",tagsym->name); + } else { + fprintf(log,"\t\t\t\n"); } /* if */ /* browse through all fields */ @@ -4446,8 +4565,8 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) } /* if */ if (ref->dim.array.length!=1) fprintf(log,"\t\t\t\t\n",(long)ref->dim.array.length); - if (ref->documentation!=NULL) - fprintf(log,"\t\t\t\t%s\n",ref->documentation); + fprintf(log,"\t"); + write_docstring(log,ref->documentation); } /* if */ fprintf(log,"\t\t\t\n"); enumroot=enumroot->next; @@ -4458,8 +4577,7 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) if ((ref=sym->refer[i])!=NULL) fprintf(log,"\t\t\t\n",xmlencode(symname,funcdisplayname(symname,ref->name))); } /* for */ - if (sym->documentation!=NULL) - fprintf(log,"\t\t\t%s\n",sym->documentation); + write_docstring(log,ref->documentation); fprintf(log,"\t\t\n"); } /* for */ @@ -4474,6 +4592,8 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) if ((sym->usage & uREAD)==0 || (sym->usage & (uENUMFIELD | uENUMROOT))!=0) continue; fprintf(log,"\t\t\n",funcdisplayname(symname,sym->name),sym->addr); + fprintf(log,"\t\t\n", get_sourcefile(sym->fnumber), sym->lnumber_decl, sym->lnumber_end); + write_docattributes(log,sym); if (sym->tag!=0) { tagsym=find_tag_byval(sym->tag); assert(tagsym!=NULL); @@ -4484,8 +4604,7 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) if ((ref=sym->refer[i])!=NULL) fprintf(log,"\t\t\t\n",xmlencode(symname,funcdisplayname(symname,ref->name))); } /* for */ - if (sym->documentation!=NULL) - fprintf(log,"\t\t\t%s\n",sym->documentation); + write_docstring(log,sym->documentation); fprintf(log,"\t\t\n"); } /* for */ @@ -4496,20 +4615,19 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) if (sym->ident!=iVARIABLE && sym->ident!=iARRAY) continue; fprintf(log,"\t\t\n",funcdisplayname(symname,sym->name)); + fprintf(log,"\t\t\n", get_sourcefile(sym->fnumber), sym->lnumber_decl, sym->lnumber_end); + write_docattributes(log,sym); if (sym->tag!=0) { tagsym=find_tag_byval(sym->tag); assert(tagsym!=NULL); fprintf(log,"\t\t\t\n",tagsym->name); } /* if */ assert(sym->refer!=NULL); - if ((sym->usage & uPUBLIC)!=0) - fprintf(log,"\t\t\t\n"); for (i=0; inumrefers; i++) { if ((ref=sym->refer[i])!=NULL) fprintf(log,"\t\t\t\n",xmlencode(symname,funcdisplayname(symname,ref->name))); } /* for */ - if (sym->documentation!=NULL) - fprintf(log,"\t\t\t%s\n",sym->documentation); + write_docstring(log,sym->documentation); fprintf(log,"\t\t\n"); } /* for */ @@ -4539,8 +4657,12 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) break; case iREFARRAY: fprintf(log,"%s",sym->dim.arglist[arg].name); - for (dim=0; dimdim.arglist[arg].numdim;dim++) - fprintf(log,"[]"); + for (dim=0; dimdim.arglist[arg].numdim;dim++) { + if (sym->dim.arglist[arg].dim[dim]) + fprintf(log,"[%d]",sym->dim.arglist[arg].dim[dim]); + else + fprintf(log,"[]"); + } /* for */ break; case iVARARGS: fprintf(log,"..."); @@ -4549,18 +4671,14 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) } /* for */ /* ??? should also print an "array return" size */ fprintf(log,")\">\n"); + fprintf(log,"\t\t\n", get_sourcefile(sym->fnumber), sym->lnumber_decl, sym->lnumber_end); + write_docattributes(log,sym); if (sym->tag!=0) { tagsym=find_tag_byval(sym->tag); assert(tagsym!=NULL); fprintf(log,"\t\t\t\n",tagsym->name); } /* if */ /* check whether this function is called from the outside */ - if ((sym->usage & uNATIVE)!=0) - fprintf(log,"\t\t\t\n"); - if ((sym->usage & uPUBLIC)!=0) - fprintf(log,"\t\t\t\n"); - if (strcmp(sym->name,uMAINFUNC)==0 || strcmp(sym->name,uENTRYFUNC)==0) - fprintf(log,"\t\t\t\n"); if ((sym->usage & uNATIVE)==0) fprintf(log,"\t\t\t\n",(long)sym->x.stacksize); if (sym->states!=NULL) { @@ -4653,8 +4771,7 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) } /* if */ fprintf(log,"\t\t\t\n"); } /* for */ - if (sym->documentation!=NULL) - fprintf(log,"\t\t\t%s\n",sym->documentation); + write_docstring(log,sym->documentation); fprintf(log,"\t\t\n"); } /* for */ diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 3f489da3..4792a7a3 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -2987,7 +2987,7 @@ static symbol *find_symbol(const symbol *root,const char *name,int fnumber,int a while (sym!=NULL) { if ( (is_global || strcmp(name,sym->name)==0) /* check name */ && (sym->parent==NULL || sym->ident==iCONSTEXPR) /* sub-types (hierarchical types) are skipped, except for enum fields */ - && (sym->fnumber<0 || sym->fnumber==fnumber)) /* check file number for scope */ + && (!(sym->usage&uSTATIC) || sym->fnumber==fnumber)) /* check file number for scope */ { assert(sym->states==NULL || sym->states->next!=NULL); /* first element of the state list is the "root" */ if (sym->ident==iFUNCTN From 00218b42da5b1f5f73d75d75bd329c8905c4f91a Mon Sep 17 00:00:00 2001 From: Dayvison Balmant Date: Sat, 3 Feb 2018 17:52:23 -0200 Subject: [PATCH 3/7] Fix transition --- source/compiler/sc1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 6a428d0e..7137d230 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -7242,7 +7242,7 @@ static void dostate(void) length+=strlen(str); if ((doc=(char*)malloc(length*sizeof(char)))!=NULL) { do { - sprintf(doc,"name); + sprintf(doc,"\t\t\tname); if (listid>=0) { /* get the source state */ stateindex=state_listitem(listid,listindex); From 8556f4f3e0a87ce570f42d62726d6be6fe328219 Mon Sep 17 00:00:00 2001 From: Dayvison Balmant Date: Sat, 3 Feb 2018 18:43:42 -0200 Subject: [PATCH 4/7] Fix typo Remove xml escape --- source/compiler/sc1.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 7137d230..1ff88eff 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -4378,14 +4378,6 @@ static char *xmlencode(char *dest,char *source) strcpy(ptr,"&"); ptr+=5; break; - case '\"': - strcpy(ptr,"""); - ptr+=6; - break; - case '\'': - strcpy(ptr,"'"); - ptr+=6; - break; default: *ptr++=*source; } /* switch */ @@ -4456,6 +4448,7 @@ static void write_docattributes(FILE *log, symbol *sym) fprintf(log,"\t\t\t\n"); } } + static void write_docstring(FILE *log,const char *string) { int len; @@ -4577,7 +4570,7 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) if ((ref=sym->refer[i])!=NULL) fprintf(log,"\t\t\t\n",xmlencode(symname,funcdisplayname(symname,ref->name))); } /* for */ - write_docstring(log,ref->documentation); + write_docstring(log,sym->documentation); fprintf(log,"\t\t\n"); } /* for */ @@ -7270,7 +7263,6 @@ static void dostate(void) delete_autolisttable(); } - static void addwhile(int *ptr) { int k; From 47b6a87284bb7ed99ab72f8e45cf3cc36fd36f2a Mon Sep 17 00:00:00 2001 From: Dayvison Balmant Date: Sat, 3 Feb 2018 19:08:38 -0200 Subject: [PATCH 5/7] Update pawndoc.xsl remove comments from sc1. Missed / Fixed constant location --- source/compiler/sc1.c | 16 +++++++++------- xml/pawndoc.xsl | 9 +++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 1ff88eff..7f26fe7e 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -2893,10 +2893,12 @@ static void decl_const(int vclass) /* add_constant() checks for duplicate definitions */ check_tagmismatch(tag,exprtag,FALSE,symbolline); sym=add_constant(constname,val,vclass,tag); - if (sym!=NULL) - //LINE_START - //LINE_END + if (sym!=NULL) { + sym->fnumber = fcurrent; + sym->lnumber_decl = symbolline; + sym->lnumber_end = symbolline; sc_attachdocumentation(sym,TRUE);/* attach any documentation to the constant */ + } } while (matchtoken(',')); /* enddo */ /* more? */ needtoken(tTERM); } @@ -4533,7 +4535,7 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) if (sym->ident!=iCONSTEXPR || (sym->usage & uENUMROOT)==0) continue; fprintf(log,"\t\t\n",funcdisplayname(symname,sym->name),sym->addr); - fprintf(log,"\t\t\n", get_sourcefile(sym->fnumber), sym->lnumber_decl, sym->lnumber_end); + fprintf(log,"\t\t\n", get_sourcefile(sym->fnumber), sym->lnumber_decl, sym->lnumber_end); write_docattributes(log,sym); if (sym->tag!=0) { tagsym=find_tag_byval(sym->tag); @@ -4585,7 +4587,7 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) if ((sym->usage & uREAD)==0 || (sym->usage & (uENUMFIELD | uENUMROOT))!=0) continue; fprintf(log,"\t\t\n",funcdisplayname(symname,sym->name),sym->addr); - fprintf(log,"\t\t\n", get_sourcefile(sym->fnumber), sym->lnumber_decl, sym->lnumber_end); + fprintf(log,"\t\t\n", get_sourcefile(sym->fnumber), sym->lnumber_decl, sym->lnumber_end); write_docattributes(log,sym); if (sym->tag!=0) { tagsym=find_tag_byval(sym->tag); @@ -4608,7 +4610,7 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) if (sym->ident!=iVARIABLE && sym->ident!=iARRAY) continue; fprintf(log,"\t\t\n",funcdisplayname(symname,sym->name)); - fprintf(log,"\t\t\n", get_sourcefile(sym->fnumber), sym->lnumber_decl, sym->lnumber_end); + fprintf(log,"\t\t\n", get_sourcefile(sym->fnumber), sym->lnumber_decl, sym->lnumber_end); write_docattributes(log,sym); if (sym->tag!=0) { tagsym=find_tag_byval(sym->tag); @@ -4664,7 +4666,7 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) } /* for */ /* ??? should also print an "array return" size */ fprintf(log,")\">\n"); - fprintf(log,"\t\t\n", get_sourcefile(sym->fnumber), sym->lnumber_decl, sym->lnumber_end); + fprintf(log,"\t\t\n", get_sourcefile(sym->fnumber), sym->lnumber_decl, sym->lnumber_end); write_docattributes(log,sym); if (sym->tag!=0) { tagsym=find_tag_byval(sym->tag); diff --git a/xml/pawndoc.xsl b/xml/pawndoc.xsl index 99ba0b14..f6eab0cc 100644 --- a/xml/pawndoc.xsl +++ b/xml/pawndoc.xsl @@ -84,6 +84,7 @@

Depends on

+

See Also

@@ -108,6 +109,7 @@

Depends on

+

See Also

@@ -135,6 +137,7 @@

Depends on

+

Attributes

@@ -172,6 +175,7 @@

Depends on

+

See Also

@@ -214,6 +218,11 @@

+ +

Defined in

+

, line to

+
+

From 42fba46c41a9b21439e199b76ad53eb1ac8c1d93 Mon Sep 17 00:00:00 2001 From: Dayvison Balmant Date: Sat, 3 Feb 2018 19:18:24 -0200 Subject: [PATCH 6/7] Fix parentheses around the && --- source/compiler/sc1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 7f26fe7e..c655805b 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -1910,7 +1910,7 @@ void sc_attachdocumentation(symbol *sym,int onlylastblock) size_t len; strcpy(doc,sym->documentation); len=strlen(doc); - if (len>0 && doc[len-1]!='>' || ((str=get_docstring(0))!=NULL && *str!=sDOCSEP && *str!='<')) + if ((len>0 && doc[len-1]!='>') || ((str=get_docstring(0))!=NULL && *str!=sDOCSEP && *str!='<')) strcat(doc,"

"); free(sym->documentation); sym->documentation=NULL; From e9e37362926a7a813a912eefda205b922bc7f454 Mon Sep 17 00:00:00 2001 From: Dayvison Balmant Date: Sat, 3 Feb 2018 19:45:09 -0200 Subject: [PATCH 7/7] Removed auto implemention of

--- source/compiler/sc1.c | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index c655805b..ea5fc34f 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -4453,35 +4453,9 @@ static void write_docattributes(FILE *log, symbol *sym) static void write_docstring(FILE *log,const char *string) { - int len; - const char *ptr; - if (string==NULL) return; - while (*string<=' ' && *string!='\0') - string++; /* skip white space */ - if (*string=='\0') - return; - - assert(strchr(string,sDOCSEP)==NULL); - /* optionally wrap in "...", check whether this must happen */ - if (*string!='<') { /* wrap in "summary" */ - len=0; - for (ptr=string; *ptr!='\0' && *ptr!='<' && *ptr!='.'; ptr++) - len++; - if (*ptr=='.') - len++; - assert(len>0); - fprintf(log,"\t\t\t%.*s\n",len,string); - string+=len; - while (*string<=' ' && *string!='\0') - string++; /* skip white space */ - } else { - len=0; - } /* if */ - - if (*string!='\0') - fprintf(log,"\t\t\t%s\n",string); + fprintf(log,"\t\t\t%s\n",string); } static void make_report(symbol *root,FILE *log,char *sourcefile)