From eec5c93ec10163e3f6cb7fb37dce7fb99a90dfde Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Thu, 4 May 2000 04:35:54 +0000 Subject: [PATCH] 20000503-21:30 GMT-8 Ron Pinkas * include/hbcomp.h + Added: #define VU_NOT_USED 0 #define VU_INITIALIZED 1 #define VU_USED 2 * source/compiler/harbour.c * Modified refrences to pVar->iUsed to use new VU_* constants. * source/compiler/hbpcode.c * Enhanced hb_compStrongType() to check and set pVar->iUsed with new VU_*constants. --- harbour/ChangeLog | 14 ++++++++++++++ harbour/include/hbcomp.h | 4 ++++ harbour/source/compiler/harbour.c | 19 ++++++++++++------- harbour/source/compiler/hbpcode.c | 21 +++++++++++++++------ harbour/tests/testwarn.prg | 4 +++- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index d3b30f10db..722f7c0d81 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,17 @@ +20000503-21:30 GMT-8 Ron Pinkas + + * include/hbcomp.h + + Added: + #define VU_NOT_USED 0 + #define VU_INITIALIZED 1 + #define VU_USED 2 + + * source/compiler/harbour.c + * Modified refrences to pVar->iUsed to use new VU_* constants. + + * source/compiler/hbpcode.c + * Enhanced hb_compStrongType() to check and set pVar->iUsed with new VU_*constants. + 20000503-19:25 GMT-8 Ron Pinkas * source/compiler/harbour.c diff --git a/harbour/include/hbcomp.h b/harbour/include/hbcomp.h index 87114be50b..8b475a5468 100644 --- a/harbour/include/hbcomp.h +++ b/harbour/include/hbcomp.h @@ -175,6 +175,10 @@ void hb_compPCodeEval( PFUNCTION, HB_PCODE_FUNC_PTR *, void * ); #define VS_PUBLIC 128 #define VS_MEMVAR ( VS_PUBLIC | VS_PRIVATE ) +#define VU_NOT_USED 0 +#define VU_INITIALIZED 1 +#define VU_USED 2 + /* * flags for bFlags member */ diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index 8ce4c1a66b..e1bb29ce72 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -522,13 +522,16 @@ void hb_compVariableAdd( char * szVarName, char cValueType ) pVar->szName = szVarName; pVar->szAlias = NULL; pVar->cType = hb_comp_cVarType; - pVar->iUsed = 0; + pVar->iUsed = VU_NOT_USED; pVar->pNext = NULL; /* Correct Type was previously stored in the CodeBlock. */ if( ! pFunc->szName ) pVar->cType = cValueType; + if ( hb_comp_iVarScope & VS_PARAMETER ) + pVar->iUsed = VU_INITIALIZED; + if( hb_comp_iVarScope & VS_MEMVAR ) { PCOMSYMBOL pSym; @@ -1099,8 +1102,10 @@ USHORT hb_compVariableGetPos( PVAR pVars, char * szVarName ) /* returns the orde { if( pVars->szName && ! strcmp( pVars->szName, szVarName ) ) { - /* Might be set to -1 by StrongType if so leave without change, otherwise set to 1. */ - pVars->iUsed |= 1; + /* Might be set to -1 by StrongType if so leave without change, otherwise set to 1. + Handled by hb_compStrongType() + pVars->iUsed |= VU_USED; + */ return wVar; } else @@ -1212,7 +1217,7 @@ static int hb_compLocalGetPos( char * szVarName ) /* returns the order + 1 of a pVar = ( PVAR ) hb_xgrab( sizeof( VAR ) ); pVar->szName = szVarName; pVar->cType = ' '; - pVar->iUsed = 0; + pVar->iUsed = VU_NOT_USED; pVar->pNext = NULL; /* Use negative order to signal that we are accessing a local @@ -2497,7 +2502,7 @@ void hb_compFinalizeFunction( void ) /* fixes all last defined function returns pVar = pFunc->pLocals; while( pVar ) { - if( pVar->szName && pFunc->szName && pFunc->szName[0] && ! pVar->iUsed ) + if( pVar->szName && pFunc->szName && pFunc->szName[0] && ! ( pVar->iUsed & VU_USED ) ) hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_VAR_NOT_USED, pVar->szName, pFunc->szName ); pVar = pVar->pNext; @@ -2506,7 +2511,7 @@ void hb_compFinalizeFunction( void ) /* fixes all last defined function returns pVar = pFunc->pStatics; while( pVar ) { - if( pVar->szName && pFunc->szName && pFunc->szName[0] && ! pVar->iUsed ) + if( pVar->szName && pFunc->szName && pFunc->szName[0] && ! ( pVar->iUsed & VU_USED ) ) hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_VAR_NOT_USED, pVar->szName, pFunc->szName ); pVar = pVar->pNext; @@ -3007,7 +3012,7 @@ void hb_compCodeBlockEnd( void ) pVar = pCodeblock->pLocals; while( pVar ) { - if( hb_comp_iWarnings && pFunc->szName && pVar->szName && ! pVar->iUsed ) + if( hb_comp_iWarnings && pFunc->szName && pVar->szName && ! ( pVar->iUsed & VU_USED ) ) hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_BLOCKVAR_NOT_USED, pVar->szName, pFunc->szName ); /* free used variables */ diff --git a/harbour/source/compiler/hbpcode.c b/harbour/source/compiler/hbpcode.c index cd918d7a9a..2400740b1c 100644 --- a/harbour/source/compiler/hbpcode.c +++ b/harbour/source/compiler/hbpcode.c @@ -653,9 +653,12 @@ void hb_compStrongType( int iSize ) if ( pVar ) { - if ( pVar->iUsed >= 0 ) + 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; + /* Review with Ryszard. */ if ( pVar->cType == 'U' ) pVar->cType = ' '; @@ -692,9 +695,12 @@ void hb_compStrongType( int iSize ) if ( pVar ) { - if ( pVar->iUsed >= 0 ) + 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; + pFunc->pStack[ pFunc->iStackIndex++ ] = pVar->cType; } else @@ -715,9 +721,12 @@ void hb_compStrongType( int iSize ) if ( pVar ) { - if ( pVar->iUsed >= 0 ) + 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; + pFunc->pStack[ pFunc->iStackIndex++ ] = pVar->cType; } else @@ -919,7 +928,7 @@ void hb_compStrongType( int iSize ) pVar = hb_compVariableFind( pFunc->pLocals, wVar ); if ( pVar ) - pVar->iUsed = -1; + pVar->iUsed |= VU_INITIALIZED; if ( pVar && pVar->cType != ' ' ) { @@ -959,7 +968,7 @@ void hb_compStrongType( int iSize ) pVar = hb_compVariableFind( pFunc->pLocals, iVar ); if ( pVar ) - pVar->iUsed = -1; + pVar->iUsed |= VU_INITIALIZED; if ( pVar && pVar->cType != ' ' ) { @@ -990,7 +999,7 @@ void hb_compStrongType( int iSize ) pVar = hb_compVariableFind( pTmp->pStatics, wVar - pTmp->iStaticsBase ); if ( pVar ) - pVar->iUsed = -1; + pVar->iUsed |= VU_INITIALIZED; if ( pVar && pVar->cType != ' ' ) { diff --git a/harbour/tests/testwarn.prg b/harbour/tests/testwarn.prg index 99ae0d9340..501ee99cf6 100644 --- a/harbour/tests/testwarn.prg +++ b/harbour/tests/testwarn.prg @@ -19,9 +19,11 @@ DECLARE FUNCTION int( n AS NUMERIC ) AS NUMERIC DECLARE FUNCTION TEST AS NUMERIC -PROCEDURE MAIN +PROCEDURE MAIN( Param1 ) LOCAL RPT, APARAMS + Rpt := IIF( Param1, 1 , 0 ) + Rpt := Array( Len( AParams ) - 2 ) RETURN