From 55c69a0a189cd6c87ccb403f7ecb3e558fb775aa Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Fri, 18 Jun 1999 04:50:48 +0000 Subject: [PATCH] 19990615-23:20 PST Ron Pinkas * compiler.h added member cType to struct VAR * harbour.y added { iVarScope = VS_MEMVAR; } to PRIVATE, PUBLIC, and PARAMETERS statements to avoid errounous error: "declaration follows executable statement" added: AliasExp '=' Expression Crlf { /* TODO */ GenPCode1( _POP ); } to statement definition to avoid parse error on M->Var = "Value" statments. the _POP will balance the stack but the assignment is not implemented yet. changed --iLine to iLine in yyerror() to correct errornous line numbers in parase error messages. added check for null pointer on few references to pVars->szName * hbpp.c, hbpmain.c, hbpint.c prefixed messages in all printf() with \n and postfixed with \n until modification to GenWarning() and GenError() --- harbour/ChangeLog | 131 +++++++++++++++++------------- harbour/include/compiler.h | 3 +- harbour/source/compiler/harbour.y | 21 ++--- harbour/source/hbpp/hbpp.c | 4 +- harbour/source/hbpp/hbppint.c | 6 +- harbour/source/hbpp/hbppmain.c | 12 +-- harbour/tests/working/testcgi.prg | 8 +- 7 files changed, 101 insertions(+), 84 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index cf5ff3a505..3a712b8b46 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,18 @@ +19990615-23:20 PST Ron Pinkas + * compiler.h + added member cType to struct VAR + * harbour.y + added { iVarScope = VS_MEMVAR; } to PRIVATE, PUBLIC, and PARAMETERS statements to avoid errounous error: + "declaration follows executable statement" + added: AliasExp '=' Expression Crlf { /* TODO */ GenPCode1( _POP ); } + to statement definition to avoid parse error on M->Var = "Value" statments. + the _POP will balance the stack but the assignment is not implemented yet. + changed --iLine to iLine in yyerror() to correct errornous line numbers in parase error messages. + added check for null pointer on few references to pVars->szName + + * hbpp.c, hbpmain.c, hbpint.c + prefixed messages in all printf() with \n and postfixed with \n until modification to GenWarning() and GenError() + 19990617-18:55 EDT David G. Holm * include/set.h - SET DEBUG is numeric, not logical @@ -45,70 +60,70 @@ Thu Jun 17 11:34:35 1999 Gonzalo A. Diethelm - * source/Makefile: - * source/compiler/Makefile: - * source/hbpp/Makefile: + * source/Makefile: + * source/compiler/Makefile: + * source/hbpp/Makefile: Now the hbpp preprocessor is compiled before the compiler, and it generates a library. No stand-alone preprocessor is generated. The compiler links against the new preprocessor library. - * include/Makefile: - * tests/working/Makefile: + * include/Makefile: + * tests/working/Makefile: Updated the list of files. - * include/compiler.h: - * include/ctoharb.h: - * include/dates.h: - * include/error.api: - * include/errorapi.h: - * include/extend.h: - * include/filesys.h: - * include/gtapi.h: - * include/hberrors.h: - * include/hbsetup.h: - * include/init.h: - * include/itemapi.h: - * include/pcode.h: - * include/set.h: - * include/types.h: - * include/version.h: - * source/compiler/fixflex.c: - * source/compiler/genobj32.c: - * source/compiler/harbour.l: - * source/compiler/harbour.y: - * source/hbpp/harb.h: - * source/hbpp/hbpp.c: - * source/rtl/asort.prg: - * source/rtl/descend.c: - * source/rtl/error.prg: - * source/rtl/errorsys.prg: - * source/rtl/hardcr.c: - * source/rtl/itemapi.c: - * source/rtl/mtran.c: - * source/rtl/objfunc.prg: - * source/rtl/tclass.prg: - * source/tools/asciisum.c: - * source/tools/ascpos.c: - * source/tools/atdiff.c: - * source/tools/chareven.c: - * source/tools/charmix.c: - * source/tools/charodd.c: - * source/tools/chrcount.c: - * source/tools/chrfirst.c: - * source/tools/chrtotal.c: - * source/tools/debug.c: - * source/tools/hb_f.c: - * source/tools/strasint.c: - * source/tools/strcount.c: - * source/tools/strcspn.c: - * source/tools/strdiff.c: - * source/tools/strexpan.c: - * source/tools/stringp.prg: - * source/tools/strleft.c: - * source/tools/strpbrk.c: - * source/tools/strright.c: - * source/vm/hvm.c: - * source/vm/initsymb.c: + * include/compiler.h: + * include/ctoharb.h: + * include/dates.h: + * include/error.api: + * include/errorapi.h: + * include/extend.h: + * include/filesys.h: + * include/gtapi.h: + * include/hberrors.h: + * include/hbsetup.h: + * include/init.h: + * include/itemapi.h: + * include/pcode.h: + * include/set.h: + * include/types.h: + * include/version.h: + * source/compiler/fixflex.c: + * source/compiler/genobj32.c: + * source/compiler/harbour.l: + * source/compiler/harbour.y: + * source/hbpp/harb.h: + * source/hbpp/hbpp.c: + * source/rtl/asort.prg: + * source/rtl/descend.c: + * source/rtl/error.prg: + * source/rtl/errorsys.prg: + * source/rtl/hardcr.c: + * source/rtl/itemapi.c: + * source/rtl/mtran.c: + * source/rtl/objfunc.prg: + * source/rtl/tclass.prg: + * source/tools/asciisum.c: + * source/tools/ascpos.c: + * source/tools/atdiff.c: + * source/tools/chareven.c: + * source/tools/charmix.c: + * source/tools/charodd.c: + * source/tools/chrcount.c: + * source/tools/chrfirst.c: + * source/tools/chrtotal.c: + * source/tools/debug.c: + * source/tools/hb_f.c: + * source/tools/strasint.c: + * source/tools/strcount.c: + * source/tools/strcspn.c: + * source/tools/strdiff.c: + * source/tools/strexpan.c: + * source/tools/stringp.prg: + * source/tools/strleft.c: + * source/tools/strpbrk.c: + * source/tools/strright.c: + * source/vm/hvm.c: + * source/vm/initsymb.c: Made sure all *.{h,c,ch,api,prg,l,y} files under include/ and source/ have an RCS Id keyword. Got rid of the RCS Log keyword on several files; this keyword diff --git a/harbour/include/compiler.h b/harbour/include/compiler.h index e039078817..41eb8fbf2e 100644 --- a/harbour/include/compiler.h +++ b/harbour/include/compiler.h @@ -11,8 +11,9 @@ typedef struct _VAR /* locals, static, public variables support */ { char *szName; /* variable name */ char *szAlias; /* variable alias namespace */ - struct _VAR * pNext; /* pointer to next defined variable */ int iUsed; /* number of times used */ + char cType; /* future optional strong typing */ + struct _VAR * pNext; /* pointer to next defined variable */ } VAR, * PVAR; typedef struct __FUNC /* functions definition support */ diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index 75615ae12b..ad039bab43 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -425,7 +425,7 @@ PATHNAMES *_pIncludePath = NULL; %token INC DEC ALIAS DOCASE CASE OTHERWISE ENDCASE ENDDO MEMVAR %token WHILE EXIT LOOP END FOR NEXT TO STEP LE GE FIELD IN PARAMETERS %token PLUSEQ MINUSEQ MULTEQ DIVEQ POWER EXPEQ MODEQ EXITLOOP -%token PRIVATE BEGINSEQ BREAK RECOVER USING DO WITH SELF +%token PRIVATE BEGINSEQ BREAK RECOVER USING DO WITH SELF MEMVAR /*the lowest precedence*/ /*postincrement and postdecrement*/ @@ -527,6 +527,7 @@ Statement : ExecFlow Crlf {} | VarAssign Crlf { GenPCode1( _POP ); } | IDENTIFIER '=' Expression Crlf { PopId( $1 ); } + | AliasExp '=' Expression Crlf { /* TODO */ GenPCode1( _POP ); } | VarId ArrayIndex '=' Expression Crlf { GenPCode1( _ARRAYPUT ); GenPCode1( _POP ); } | FunArrayCall '=' Expression Crlf { GenPCode1( _ARRAYPUT ); GenPCode1( _POP ); } | IdSend IDENTIFIER '=' { Message( SetData( $2 ) ); } Expression Crlf { Function( 1 ); } @@ -537,9 +538,9 @@ Statement : ExecFlow Crlf {} | BREAK Expression Crlf | RETURN Crlf { GenReturn( Jump( 0 ) ); } | RETURN Expression Crlf { GenPCode1( _RETVALUE ); GenReturn( Jump ( 0 ) ); } - | PUBLIC VarList Crlf - | PRIVATE VarList Crlf - | PARAMETERS IdentList Crlf + | PUBLIC { iVarScope = VS_MEMVAR; } VarList Crlf + | PRIVATE { iVarScope = VS_MEMVAR; } VarList Crlf + | PARAMETERS { iVarScope = VS_MEMVAR; } IdentList Crlf | EXITLOOP Crlf { LoopExit(); } | LOOP Crlf { LoopLoop(); } | DoProc Crlf @@ -976,7 +977,7 @@ Crlf : '\n' void yyerror( char * s ) { - printf( "\n%s at line %i\n", s, --iLine ); + printf( "\n%s at line %i\n", s, iLine ); exit( 1 ); } @@ -1594,7 +1595,7 @@ void AddVar( char * szVarName ) pVar = ( PVAR ) OurMalloc( sizeof( VAR ) ); pVar->szName = szVarName; pVar->szAlias = NULL; - /* pVar->cType = 'U'; */ + pVar->cType = 'U'; pVar->iUsed = 0; pVar->pNext = NULL; @@ -2631,7 +2632,7 @@ WORD GetVarPos( PVAR pVars, char * szVarName ) /* returns the order + 1 of a var while( pVars ) { - if( ! strcmp( pVars->szName, szVarName ) ) + if( pVars->szName && ! strcmp( pVars->szName, szVarName ) ) { if( _iWarnings ) pVars->iUsed = 1; @@ -2702,7 +2703,7 @@ int GetLocalVarPos( char * szVarName ) /* returns the order + 1 of a variable if pVar = (PVAR) OurMalloc( sizeof(VAR) ); pVar->szName = szVarName; - /* pVar->cType = 'U'; */ + pVar->cType = 'U'; pVar->iUsed = 0; pVar->pNext = NULL; iVar = 1; /* first variable */ @@ -3190,7 +3191,7 @@ void FixReturns( void ) /* fixes all last defined function returns jumps offsets pVar = functions.pLast->pLocals; while ( pVar ) { - if( pVar->szName && ! pVar->iUsed ) + if( pVar->szName && functions.pLast->szName && ! pVar->iUsed ) GenWarning( WARN_VAR_NOT_USED, pVar->szName, functions.pLast->szName ); pVar = pVar->pNext; @@ -3199,7 +3200,7 @@ void FixReturns( void ) /* fixes all last defined function returns jumps offsets pVar = functions.pLast->pStatics; while ( pVar ) { - if( pVar->szName && ! pVar->iUsed ) + if( pVar->szName && functions.pLast->szName && ! pVar->iUsed ) GenWarning( WARN_VAR_NOT_USED, pVar->szName, functions.pLast->szName ); pVar = pVar->pNext; diff --git a/harbour/source/hbpp/hbpp.c b/harbour/source/hbpp/hbpp.c index 5ec8fba62c..0dda83ca14 100644 --- a/harbour/source/hbpp/hbpp.c +++ b/harbour/source/hbpp/hbpp.c @@ -144,7 +144,7 @@ int ParseDirective( char* sLine ) /* if ((handl_i = fopen(sLine, "r")) == NULL) */ if ( !OpenInclude( sLine, _pIncludePath, &handl_i ) ) - { printf("\nCan't open %s",sLine); return 1001; } + { printf("\nCan't open %s\n",sLine); return 1001; } lInclude++; Hp_Parse(handl_i, 0 ); lInclude--; @@ -178,7 +178,7 @@ int ParseDirective( char* sLine ) else if ( i == 5 && memcmp ( sDirective, "error", 5 ) == 0 ) { /* --- #error --- */ - printf ( " #error: %s", sLine ); + printf ( "\n#error: %s\n", sLine ); return 2000; } else return 1; diff --git a/harbour/source/hbpp/hbppint.c b/harbour/source/hbpp/hbppint.c index 2f118c591a..d68d80a4db 100644 --- a/harbour/source/hbpp/hbppint.c +++ b/harbour/source/hbpp/hbppint.c @@ -89,7 +89,7 @@ int PreProcess( FILE* handl_i, FILE* handl_o, char *sOut ) if ( (rezParse=ParseDirective( ptr+1 )) > 0 ) { if ( !lInclude ) - printf ( "\nError number %u in line %u", rezParse, nline ); + printf ( "\nError number %u in line %u\n", rezParse, nline ); } *sLine = '\0'; } @@ -99,7 +99,7 @@ int PreProcess( FILE* handl_i, FILE* handl_o, char *sOut ) { if ( (rezParse = ParseExpression( ptr, sOutLine)) > 0 ) { - printf ( "\nError number %u in line %u", rezParse, nline ); + printf ( "\nError number %u in line %u\n", rezParse, nline ); } } else *sLine = '\0'; @@ -153,7 +153,7 @@ int Hp_Parse( FILE* handl_i, FILE* handl_o ) *sLine = '\0'; } else - printf ( "\nNon directive in include file"); + printf ( "\nNon directive in include file\n"); } } } diff --git a/harbour/source/hbpp/hbppmain.c b/harbour/source/hbpp/hbppmain.c index 0d23191911..33e7895af3 100644 --- a/harbour/source/hbpp/hbppmain.c +++ b/harbour/source/hbpp/hbppmain.c @@ -71,7 +71,7 @@ int iArg = 1; AddSearchPath( argv[ iArg ]+2, &_pIncludePath ); break; default: - printf( "Invalid command line option: %s\n", &argv[ iArg ][ 1 ] ); + printf( "\nInvalid command line option: %s\n", &argv[ iArg ][ 1 ] ); break; } } @@ -84,15 +84,15 @@ int iArg = 1; MakeFilename( szFileName, pFileName ); if ((handl_i = fopen(szFileName, "r")) == NULL) - { printf("Can't open %s",szFileName); return 1; } + { printf("\nCan't open %s\n",szFileName); return 1; } } - else { printf("File name absent"); return 1; } + else { printf("\nFile name absent\n"); return 1; } pFileName->extension =".ppo"; MakeFilename( szFileName, pFileName ); if ((handl_o = fopen(szFileName, "wt" )) == NULL) - { printf("Can't open %s",szFileName); return 1; } + { printf("\nCan't open %s\n",szFileName); return 1; } aCondCompile = (int*) _xgrab( sizeof(int) * 5 ); aDefnew = ( DEFINES * ) _xgrab( sizeof(DEFINES) * 50 ); @@ -147,7 +147,7 @@ int Hp_Parse( FILE* handl_i, FILE* handl_o ) if ( (rezParse=ParseDirective( ptr+1 )) > 0 ) { if ( !lInclude ) - printf ( "\nError number %u in line %u", rezParse, nline ); + printf ( "\nError number %u in line %u\n", rezParse, nline ); return rezParse; } *sLine = '\0'; @@ -158,7 +158,7 @@ int Hp_Parse( FILE* handl_i, FILE* handl_o ) { if ( (rezParse = ParseExpression( ptr, sOutLine)) > 0 ) { - printf ( "\nError number %u in line %u", rezParse, nline ); + printf ( "\nError number %u in line %u\n", rezParse, nline ); return rezParse; } } diff --git a/harbour/tests/working/testcgi.prg b/harbour/tests/working/testcgi.prg index cbba4b8065..f1a1953b5c 100644 --- a/harbour/tests/working/testcgi.prg +++ b/harbour/tests/working/testcgi.prg @@ -40,14 +40,14 @@ FUNCTION Main() // Builds dynamic table replacement WHILE (nPos := fRead( hFile, @cString, IF_BUFFER )) > 0 i := 1 - DO WHILE i <= nPos + DO WHILE i <= nPos IF substr( cString, i, 1 ) = chr( 13 ) i := i + 1 cLine := cBuf cBuf := "" - IF left( cLine, 1 ) <> ';' + IF left( cLine, 1 ) <> ';' cTable += '' + chr(10)+chr(13) + ; '' + ; ParseString( cLine, ';', 1 ) + '' + chr(10)+chr(13) + ; @@ -104,14 +104,14 @@ FUNCTION ParseString( cString, cDelim, nRet ) FOR i := 1 TO nSize nPosFim := at( cDelim, cBuf ) - IF nPosFim > 0 + IF nPosFim > 0 aElem[i] := substr( cBuf, 1, nPosFim - 1 ) ELSE aElem[i] := cBuf ENDIF cBuf := substr( cBuf, nPosFim + 1, len( cBuf ) ) - + NEXT i RETURN( aElem[ nRet ] )