From e692ba89595c423f97968796d958db2b0fce0f4f Mon Sep 17 00:00:00 2001 From: Ryszard Glab Date: Sat, 13 May 2000 12:44:55 +0000 Subject: [PATCH] ChangeLog 20000513-14:50 GMT+1 --- harbour/ChangeLog | 12 ++++++++++++ harbour/include/hbcomp.h | 1 + harbour/source/compiler/harbour.c | 14 ++++++++++++-- harbour/source/compiler/harbour.y | 14 +++++++++----- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 16d289c58f..d07494697b 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,15 @@ +20000513-14:50 GMT+1 Ryszard Glab + + *include/hbcomp.h + * added 'int iDeclLine' to VAR structure to hold the line number + where a variable was declared + + *source/compiler/harbour.c + *source/compiler/harbour.y + * fixed generation of 'unreachable code' warnings + * warnings for declared but not used variable reports the line + number where this variable was declared + 20000513-13:51 GMT+2 Maurilio Longo - source/rtl/stringsx.c diff --git a/harbour/include/hbcomp.h b/harbour/include/hbcomp.h index 10b7c34157..016e656629 100644 --- a/harbour/include/hbcomp.h +++ b/harbour/include/hbcomp.h @@ -108,6 +108,7 @@ typedef struct _VAR char * szName; /* variable name */ char * szAlias; /* variable alias namespace */ int iUsed; /* number of times used */ + int iDeclLine; /* declaration line number */ BYTE cType; /* optional strong typing */ PCOMCLASS pClass; struct _VAR * pNext; /* pointer to next defined variable */ diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index 42fe4c0efb..f97632efea 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -548,6 +548,7 @@ void hb_compVariableAdd( char * szVarName, BYTE cValueType ) pVar->cType = cValueType; pVar->iUsed = VU_NOT_USED; pVar->pNext = NULL; + pVar->iDeclLine = hb_comp_iLine; if ( cValueType == '+' ) { @@ -1440,6 +1441,7 @@ static int hb_compLocalGetPos( char * szVarName ) /* returns the order + 1 of a pVar->cType = ' '; pVar->iUsed = VU_NOT_USED; pVar->pNext = NULL; + pVar->iDeclLine = hb_comp_iLine; /* Use negative order to signal that we are accessing a local * variable from a codeblock @@ -2724,7 +2726,11 @@ void hb_compFinalizeFunction( void ) /* fixes all last defined function returns while( pVar ) { 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 ); + { + char szFun[ 256 ]; + sprintf( szFun, "%s(%i)", pFunc->szName, pVar->iDeclLine ); + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_VAR_NOT_USED, pVar->szName, szFun ); + } pVar = pVar->pNext; } @@ -2733,7 +2739,11 @@ void hb_compFinalizeFunction( void ) /* fixes all last defined function returns while( pVar ) { 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 ); + { + char szFun[ 256 ]; + sprintf( szFun, "%s(%i)", pFunc->szName, pVar->iDeclLine ); + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_VAR_NOT_USED, pVar->szName, szFun ); + } pVar = pVar->pNext; } diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index d3c24944f4..9caba34fa7 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -410,8 +410,8 @@ Statement : ExecFlow CrlfStmnt { } ExtVarList { hb_compRTVariableGen( "__MVPRIVATE" ); hb_comp_cVarType = ' '; hb_comp_iVarScope = VS_NONE; } CrlfStmnt - | EXITLOOP CrlfStmnt { hb_compLoopExit(); hb_comp_functions.pLast->bFlags |= FUN_BREAK_CODE; } - | LOOP CrlfStmnt { hb_compLoopLoop(); hb_comp_functions.pLast->bFlags |= FUN_BREAK_CODE; } + | EXITLOOP { hb_comp_bDontGenLineNum = TRUE; hb_compLoopExit(); } CrlfStmnt { hb_comp_functions.pLast->bFlags |= FUN_BREAK_CODE; } + | LOOP { hb_comp_bDontGenLineNum = TRUE; hb_compLoopLoop(); } CrlfStmnt { hb_comp_functions.pLast->bFlags |= FUN_BREAK_CODE; } | EXTERN ExtList Crlf | ANNOUNCE IdentName { if( hb_comp_szAnnounce == NULL ) @@ -438,7 +438,7 @@ LineStat : Crlf { $$ = 0; hb_comp_bDontGenLineNum = TRUE; } ; Statements : LineStat { $$ = $1; hb_compLinePush(); } - | Statements LineStat { $$ += $2; hb_compLinePush(); } + | Statements LineStat { $$ += $2; hb_compLinePush(); } ; ExtList : IdentName { hb_compExternAdd( $1 ); } @@ -1191,8 +1191,12 @@ IfEndif : IfBegin EndIf { hb_compGenJumpHere( $1 ); } | IfBegin IfElseIf IfElse EndIf { hb_compGenJumpHere( $1 ); hb_compElseIfFix( $2 ); } ; -EmptyStats : /* empty */ { hb_comp_bDontGenLineNum = TRUE; hb_comp_EOL = FALSE; } - | Statements { hb_comp_EOL = FALSE; } +EmptyStatements : LineStat { } + | EmptyStatements { hb_compLinePush(); } LineStat { } + ; + +EmptyStats : /* empty */ { hb_comp_bDontGenLineNum = TRUE; hb_comp_EOL = FALSE; } + | EmptyStatements { hb_comp_EOL = FALSE; } ; IfBegin : IF SimpleExpression { ++hb_comp_wIfCounter; hb_compLinePush(); } Crlf { hb_compExprDelete( hb_compExprGenPush( $2 ) ); $$ = hb_compGenJumpFalse( 0 ); hb_compLinePush(); }