From f14599541d4af69e3e121efca1eec0c031b813b0 Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Mon, 1 May 2000 21:14:35 +0000 Subject: [PATCH] 20000501-14:15 GMT-8 Ron Pinkas * source/compiler/harbour.c * Minor correction to hb_compVariableAdd(). * source/compiler/hbpcode.c * Enhancements to hb_compStrongType() to support new PUSH/POPALIASEDFIELDNEAR. * tests/testwarn.prg + Added code to demonstrate more warnings. --- harbour/ChangeLog | 25 +++++++++++---- harbour/source/compiler/harbour.c | 47 ++++++++++++++++----------- harbour/source/compiler/hbpcode.c | 53 ++++++++++++++++++++++++++++--- harbour/tests/testwarn.prg | 16 +++++++++- 4 files changed, 109 insertions(+), 32 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f1dd3cbffe..4cc38d923f 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,14 @@ +20000501-14:15 GMT-8 Ron Pinkas + + * source/compiler/harbour.c + * Minor correction to hb_compVariableAdd(). + + * source/compiler/hbpcode.c + * Enhancements to hb_compStrongType() to support new PUSH/POPALIASEDFIELDNEAR. + + * tests/testwarn.prg + + Added code to demonstrate more warnings. + 20000501-19:05 GMT+1 Ryszard Glab *source/vm/hvm.c @@ -7,7 +18,7 @@ *source/rtl/filesys.c * added support for hb_fsCommit() in Unix-like OS - + *source/compiler/harbour.c * fixed signed/unsigned warnings @@ -20,7 +31,7 @@ * source/compiler/harbour.c * source/vm/hvm.c + Added new pcode: HB_P_PUSHBLOCKSHORT - This is used for codeblocks which have no parameters, use no locals, + This is used for codeblocks which have no parameters, use no locals, and the total size is smaller than 255 bytes. The majority of codeblocks falls into this category. HB_TEST is now 15K smaller. @@ -60,7 +71,7 @@ * makefile.bc - Removed duplicated and Borland only default language selection. - This feature is already built in to HBSETUP.H, so there's no + This feature is already built in to HBSETUP.H, so there's no point to duplicate it. Or I'm missing something obvious. 20000501-16:08 GMT+1 Victor Szakats @@ -88,16 +99,16 @@ passing no arguments to a codeblock * added hb_vmEvalBlockV() for a codeblock evaluation - it is using a variable number of arguments - + *source/rdd/dbcmd.c * fixed bug in defEvalBlock * fixed to call hb_vmEvalBlock() * some common parts moved into separate functions - + *include/hbcomp.h * changed 'BYTE iJumps' into 'ULONG iJumps' to stop reallocation error mentioned by Victor - + 20000501-15:37 GMT+1 Victor Szakats * source/rtl/teditor.prg @@ -119,7 +130,7 @@ + Developer list updated. * source/rtl/Makefile - ! Fixed back the indentation of the file list from three spaces to + ! Fixed back the indentation of the file list from three spaces to one tab. + Added memoedit.prg diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index ac066f148e..349bfee2f2 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -452,22 +452,31 @@ void hb_compVariableAdd( char * szVarName, char cValueType ) PVAR pVar, pLastVar; PFUNCTION pFunc = hb_comp_functions.pLast; - if ( hb_comp_iWarnings > 2 && hb_comp_szDeclaredFun ) + /* Dummy Var - Parameter Declaration of Declared Function. */ + if ( hb_comp_szDeclaredFun ) { - PCOMSYMBOL pSym = hb_compSymbolFind( hb_comp_szDeclaredFun, NULL ); - - if ( pSym ) - { - pSym->iParamCount++; - - if ( pSym->cParamTypes ) - pSym->cParamTypes = ( BYTE * ) hb_xrealloc( pSym->cParamTypes, pSym->iParamCount ); - else - pSym->cParamTypes = ( BYTE * ) hb_xgrab( 1 ); - - pSym->cParamTypes[ pSym->iParamCount - 1 ] = hb_comp_cVarType; - + /* Nothing to do since no warnings requested.*/ + if ( hb_comp_iWarnings < 3 ) return; + + { + /* Find the Declared Function owner of this parameter. */ + PCOMSYMBOL pSym = hb_compSymbolFind( hb_comp_szDeclaredFun, NULL ); + + if ( pSym ) + { + pSym->iParamCount++; + + if ( pSym->cParamTypes ) + pSym->cParamTypes = ( BYTE * ) hb_xrealloc( pSym->cParamTypes, pSym->iParamCount ); + else + pSym->cParamTypes = ( BYTE * ) hb_xgrab( 1 ); + + /* Store declared type of this parameter into the parameters type list. */ + pSym->cParamTypes[ pSym->iParamCount - 1 ] = hb_comp_cVarType; + + return; + } } } @@ -2899,21 +2908,21 @@ void hb_compCodeBlockEnd( void ) ++wLocals; } - if( ( pCodeblock->lPCodePos + 3 ) <= 255 && + if( ( pCodeblock->lPCodePos + 3 ) <= 255 && pCodeblock->wParamCount == 0 && wLocals == 0 ) { /* NOTE: 3 = HB_P_PUSHBLOCKSHORT + BYTE( size ) + _ENDBLOCK */ wSize = ( USHORT ) pCodeblock->lPCodePos + 3; - - hb_compGenPCode2( HB_P_PUSHBLOCKSHORT, ( BYTE ) wSize, ( BOOL ) 1 ); + + hb_compGenPCode2( HB_P_PUSHBLOCKSHORT, ( BYTE ) wSize, ( BOOL ) 0 ); } else { /* NOTE: 8 = HB_P_PUSHBLOCK + USHORT( size ) + USHORT( wParams ) + USHORT( wLocals ) + _ENDBLOCK */ wSize = ( USHORT ) pCodeblock->lPCodePos + 8 + wLocals * 2; - - hb_compGenPCode3( HB_P_PUSHBLOCK, HB_LOBYTE( wSize ), HB_HIBYTE( wSize ), ( BOOL ) 1 ); + + hb_compGenPCode3( HB_P_PUSHBLOCK, HB_LOBYTE( wSize ), HB_HIBYTE( wSize ), ( BOOL ) 0 ); hb_compGenPCode2( HB_LOBYTE( pCodeblock->wParamCount ), HB_HIBYTE( pCodeblock->wParamCount ), ( BOOL ) 0 ); hb_compGenPCode2( HB_LOBYTE( wLocals ), HB_HIBYTE( wLocals ), ( BOOL ) 0 ); } diff --git a/harbour/source/compiler/hbpcode.c b/harbour/source/compiler/hbpcode.c index 683695f7a2..a75709860d 100644 --- a/harbour/source/compiler/hbpcode.c +++ b/harbour/source/compiler/hbpcode.c @@ -533,7 +533,12 @@ void hb_compStrongType( int iSize ) pFunc->pStack[ pFunc->iStackIndex++ ] = 'O'; break; - /* Blcks */ + /* Blcoks */ + /* Nothing to do, handled by HB_P_ENDBLOCK. + case HB_P_PUSHBLOCK : + case HB_P_PUSHBLOCKSHORT : + */ + case HB_P_ENDBLOCK : /* Override the last value of the block left on the stack. */ pFunc->pStack[ pFunc->iStackIndex ] = 'B'; @@ -696,18 +701,34 @@ void hb_compStrongType( int iSize ) /* Question use type "REFERENCE" or the base type of the var */ pFunc->pStack[ pFunc->iStackIndex++ ] = 'R'; - /* MemVars */ + case HB_P_PUSHALIASEDFIELDNEAR : + pSym = hb_compSymbolGetPos( pFunc->pCode[ ulPos + 1 ] ); - case HB_P_PUSHVARIABLE : - case HB_P_PUSHMEMVAR : - pSym = hb_compSymbolGetPos( pFunc->pCode[ ulPos + 1 ] + pFunc->pCode[ ulPos + 2 ] * 256 ); if ( pSym ) pFunc->pStack[ pFunc->iStackIndex++ ] = pSym->cType; else pFunc->pStack[ pFunc->iStackIndex++ ] = ' '; + break; + + case HB_P_PUSHFIELD : + case HB_P_PUSHALIASEDFIELD : + case HB_P_PUSHALIASEDVAR : + case HB_P_PUSHVARIABLE : + case HB_P_PUSHMEMVAR : + pSym = hb_compSymbolGetPos( pFunc->pCode[ ulPos + 1 ] + pFunc->pCode[ ulPos + 2 ] * 256 ); + + if ( pSym ) + pFunc->pStack[ pFunc->iStackIndex++ ] = pSym->cType; + else + pFunc->pStack[ pFunc->iStackIndex++ ] = ' '; + + break; + case HB_P_PUSHMEMVARREF : + /* Question use type "REFERENCE" or the base type of the var */ pFunc->pStack[ pFunc->iStackIndex++ ] = 'R'; + break; /* Arrays. */ @@ -782,6 +803,28 @@ void hb_compStrongType( int iSize ) pFunc->iStackIndex--; break; + case HB_P_POPALIASEDFIELDNEAR : + pFunc->iStackIndex--; + + if ( pFunc->iStackIndex < 0 ) + /* TODO Error Message after finalizing all possible pcodes. */ + break; + + pSym = hb_compSymbolGetPos( pFunc->pCode[ ulPos + 1 ] ); + + if ( pSym->cType != ' ' ) + { + char szType[2]; + sprintf( szType, "%c", pSym->cType ); + + if ( pFunc->pStack[ pFunc->iStackIndex ] == ' ' ) + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_ASSIGN_SUSPECT, pSym->szName, szType ); + else if ( pSym->cType != pFunc->pStack[ pFunc->iStackIndex ] ) + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_ASSIGN_TYPE, pSym->szName, szType ); + } + + break; + case HB_P_POPFIELD : case HB_P_POPALIASEDFIELD : /* TODO: Add support for FIELD declarations. */ diff --git a/harbour/tests/testwarn.prg b/harbour/tests/testwarn.prg index 51b5b9c3c7..1e46721d29 100644 --- a/harbour/tests/testwarn.prg +++ b/harbour/tests/testwarn.prg @@ -11,7 +11,21 @@ DECLARE FUNCTION nMyFunc( cVar AS CHARACTER, nVar AS NUMERIC ) AS NUMERIC DECLARE FUNCTION cOtherFunc( ) AS CHARACTER -FUNCTION Main() +DECLARE FUNCTION seconds() AS NUMERIC + +DECLARE FUNCTION int( n AS NUMERIC ) AS NUMERIC + +Function Main() +Local n As Numeric + + n := 2 + n := 'a' + n := seconds() + 2 + n := int( seconds() + 2 ) + +Return( NIL ) + +FUNCTION Main1() LOCAL n AS NUMERIC, cVar AS CHARACTER, a[5,5,5] AS ARRAY