From 8d68c4da51338e2b49e55da65610e9933d920eb9 Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Sun, 7 May 2000 20:36:33 +0000 Subject: [PATCH] 20000507-13:35 GMT-8 Ron Pinkas * include/hberrors.h + Added : #define HB_COMP_WARN_VAL_NOT_USED 20 * source/compiler/harbour.c + Added logic to hb_compOptimizeFrames() to warn about invalid statics usage. * source/compiler/hbgenerr.c + Added: "3Value of Variable \'%s\' never used" * source/compiler/hbpcode.c * Enhanced support for statics * tests/testwarn.prg + Added more code to demonstrate more warnings. --- harbour/ChangeLog | 20 +++++++++++++++++++- harbour/include/hberrors.h | 11 ++++++----- harbour/source/compiler/harbour.c | 24 +++++++++++++++++++++--- harbour/source/compiler/hbgenerr.c | 1 + harbour/source/compiler/hbpcode.c | 8 ++++++-- harbour/tests/testwarn.prg | 15 ++++++++++++++- 6 files changed, 67 insertions(+), 12 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 5ef81c4f73..4735bd5cfd 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,20 @@ +20000507-13:35 GMT-8 Ron Pinkas + + * include/hberrors.h + + Added : #define HB_COMP_WARN_VAL_NOT_USED 20 + + * source/compiler/harbour.c + + Added logic to hb_compOptimizeFrames() to warn about invalid statics usage. + + * source/compiler/hbgenerr.c + + Added: "3Value of Variable \'%s\' never used" + + * source/compiler/hbpcode.c + * Enhanced support for statics + + * tests/testwarn.prg + + Added more code to demonstrate more warnings. + 20000507-05:20 GMT-8 Ron Pinkas * include/hbpcomp.c @@ -10,11 +27,12 @@ + Added support for MEMVAR AS ... syntax. * source/compiler/hbpcode.c + + Added static PVAR hb_compPrivateFind( char * szPrivateName ) + Added support for FIELD AS ... and MEMVAR AS both local and global. ! More refinments * tests/testwarn.prg - + Added code to demonstrate "Adaptive Type Checking". + + Added more code to demonstrate more warnings. 20000507-14:05 GMT+1 Ryszard Glab diff --git a/harbour/include/hberrors.h b/harbour/include/hberrors.h index a86801b24c..8764669840 100644 --- a/harbour/include/hberrors.h +++ b/harbour/include/hberrors.h @@ -110,11 +110,12 @@ extern "C" { #define HB_COMP_WARN_DUP_DECLARATION 17 #define HB_COMP_WARN_DECLARATION_CONFLICT 18 #define HB_COMP_WARN_NOT_INITIALIZED 19 -#define HB_COMP_WARN_ARRAY_ASSIGN_TYPE 20 -#define HB_COMP_WARN_ARRAY_ASSIGN_SUSPECT 21 -#define HB_COMP_WARN_MEANINGLESS 22 -#define HB_COMP_WARN_UNREACHABLE 23 -#define HB_COMP_WARN_DUPL_ANNOUNCE 24 +#define HB_COMP_WARN_VAL_NOT_USED 20 +#define HB_COMP_WARN_ARRAY_ASSIGN_TYPE 21 +#define HB_COMP_WARN_ARRAY_ASSIGN_SUSPECT 22 +#define HB_COMP_WARN_MEANINGLESS 23 +#define HB_COMP_WARN_UNREACHABLE 24 +#define HB_COMP_WARN_DUPL_ANNOUNCE 25 /* * Errors generated by Harbour preprocessor diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index f14aa0c054..b9a301e1c3 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -258,9 +258,6 @@ int main( int argc, char * argv[] ) if( ! hb_comp_bStartProc ) --hb_comp_iFunctionCnt; - if( ! hb_comp_bQuiet ) - printf( "\rLines %i, Functions/Procedures %i\n", hb_comp_iLine, hb_comp_iFunctionCnt ); - pFunc = hb_comp_functions.pFirst; while( pFunc ) { @@ -268,6 +265,9 @@ int main( int argc, char * argv[] ) pFunc = pFunc->pNext; } + if( ! hb_comp_bQuiet ) + printf( "\rLines %i, Functions/Procedures %i\n", hb_comp_iLine, hb_comp_iFunctionCnt ); + hb_compGenOutput( hb_comp_iLanguage ); } } @@ -2654,6 +2654,24 @@ static void hb_compOptimizeFrames( PFUNCTION pFunc ) pFunc->lPCodePos -= 3; memmove( pFunc->pCode + 5, pFunc->pCode + 8, pFunc->lPCodePos - 5 ); } + else + /* Check Global Statics. */ + { + //PVAR pVar = pFunc->pStatics; + PVAR pVar = hb_comp_functions.pFirst->pStatics; + + while( pVar ) + { + //printf( "\nChecking: %s Used: %i\n", pVar->szName, pVar->iUsed ); + + if ( ( ! pVar->iUsed & VU_USED ) && pVar->iUsed & VU_INITIALIZED ) + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_VAL_NOT_USED, pVar->szName, NULL ); + else if ( pVar->iUsed & VU_USED && ! ( pVar->iUsed & VU_INITIALIZED ) ) + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_NOT_INITIALIZED, pVar->szName, NULL ); + + pVar = pVar->pNext; + } + } } } else if( pFunc->pCode[ 0 ] == HB_P_FRAME && diff --git a/harbour/source/compiler/hbgenerr.c b/harbour/source/compiler/hbgenerr.c index e6ea80677e..e0b0df8144 100644 --- a/harbour/source/compiler/hbgenerr.c +++ b/harbour/source/compiler/hbgenerr.c @@ -110,6 +110,7 @@ char * hb_comp_szWarnings[] = "3Duplicate Declaration of Function %s", "3Function \'%s\' conflicting with its declaration", "3Variable \'%s\' used but never initialized", + "3Value of Variable \'%s\' never used", "3Incompatible type in assignment to declared array element expected: \'%s\'", "4Suspicious type in assignment to declared array element expected: \'%s\'", "0Meaningless use of expression: \'%s\'", diff --git a/harbour/source/compiler/hbpcode.c b/harbour/source/compiler/hbpcode.c index 4e0d78d3f8..7238e6929c 100644 --- a/harbour/source/compiler/hbpcode.c +++ b/harbour/source/compiler/hbpcode.c @@ -969,8 +969,12 @@ void hb_compStrongType( int iSize ) if ( pVar ) { - if ( ! ( pVar->iUsed & VU_INITIALIZED ) ) - hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_NOT_INITIALIZED, pVar->szName, NULL ); + //printf( "\nStatic: %s Function: %s Found in: %s\n", pVar->szName, pFunc->szName, pTmp->szName ); + + /* Only if "private" static, since global static may be intialized elsewhere. */ + if ( pTmp == pFunc ) + if ( ! ( pVar->iUsed & VU_INITIALIZED ) ) + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_NOT_INITIALIZED, pVar->szName, NULL ); /* Mark as used */ pVar->iUsed |= VU_USED; diff --git a/harbour/tests/testwarn.prg b/harbour/tests/testwarn.prg index cc2c41b21a..810d2f10e5 100644 --- a/harbour/tests/testwarn.prg +++ b/harbour/tests/testwarn.prg @@ -66,8 +66,12 @@ FIELD b AS CHAR MEMVAR Var1 AS CHAR +STATIC lGlobal AS LOGICAL + PROCEDURE THEMAIN() + STATIC lStatic := 0 + FIELD b AS NUM USE TEMP @@ -82,7 +86,13 @@ PROCEDURE THEMAIN() b := 'a' - Var1 := .f. + if lStatic + Var1 := .F. + endif + + IF lGlobal + Var1 := .T. + ENDIF RETURN @@ -104,6 +114,9 @@ PROCEDURE SOMEPROC() Var1 := 1 + if lGlobal = 0 + endif + RETURN PROC MAIN1()