From a10ec0d5011df6ba00c8c2811ec4d37efd6ae14e Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Mon, 1 May 2000 08:00:25 +0000 Subject: [PATCH] 20000501-01:0 GMT-8 Ron Pinkas * include/hbcomp.h + Added to COMSYMBOL : BYTE * cParamTypes; int iParamCount; + Added : extern char * hb_comp_szDeclaredFun * source/compiler/harbour.y * Enhanced DECLARE FUNCTION parsing to properly maintain number and type of declared function parameters. * source/compiler/harbour.c + Added char * hb_comp_szDeclaredFun * Modified hb_compVariableAdd() to support dummy parameter vars in Function Decleration. * source/compiler/hbpcode.c * Enhancements to hb_compStrongType() to support parameter checks of declared function. * tests/testwarn.prg + Added code to demonstrate more warnings. * include/hberrors.h + Added : #define HB_COMP_PARAM_COUNT 15 #define HB_COMP_PARAM_TYPE 16 * source/compiler/hbgenerr.c + added : "3Invalid number of parameters: \'%s\' expected: \'%s\'" "3Incompatible parameter # %s expected: \'%s\'" --- harbour/ChangeLog | 34 ++++++++++++++++- harbour/include/hbcomp.h | 3 ++ harbour/include/hberrors.h | 8 ++-- harbour/source/compiler/harbour.c | 23 ++++++++++- harbour/source/compiler/harbour.y | 3 +- harbour/source/compiler/hbgenerr.c | 2 + harbour/source/compiler/hbpcode.c | 61 +++++++++++++++++++++++------- harbour/tests/testwarn.prg | 4 +- 8 files changed, 116 insertions(+), 22 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f8e1664798..44f3cce9fe 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,35 @@ +20000501-01:0 GMT-8 Ron Pinkas + + * include/hbcomp.h + + Added to COMSYMBOL : + BYTE * cParamTypes; + int iParamCount; + + Added : + extern char * hb_comp_szDeclaredFun + + * source/compiler/harbour.y + * Enhanced DECLARE FUNCTION parsing to properly maintain number and type of declared function parameters. + + * source/compiler/harbour.c + + Added char * hb_comp_szDeclaredFun + * Modified hb_compVariableAdd() to support dummy parameter vars in Function Decleration. + + * source/compiler/hbpcode.c + * Enhancements to hb_compStrongType() to support parameter checks of declared function. + + * tests/testwarn.prg + + Added code to demonstrate more warnings. + + * include/hberrors.h + + Added : + #define HB_COMP_PARAM_COUNT 15 + #define HB_COMP_PARAM_TYPE 16 + + * source/compiler/hbgenerr.c + + added : + "3Invalid number of parameters: \'%s\' expected: \'%s\'" + "3Incompatible parameter # %s expected: \'%s\'" + 20000430-21:30 GMT-8 Ron Pinkas * source/compiler/harbour.c - Removed refrence to pFunc->iFunctionIndex. @@ -8,7 +40,7 @@ * tests/testwarn.prg + Added code to demonstrate more warnings. - * include/hberrors.h + * include/hbcomp.h - Removed pFunctionCalls and iFunctionIndex members of _FUNC structure. 20000430-22:15 GMT-8 Ron Pinkas diff --git a/harbour/include/hbcomp.h b/harbour/include/hbcomp.h index 97836a30a3..7843591a64 100644 --- a/harbour/include/hbcomp.h +++ b/harbour/include/hbcomp.h @@ -137,6 +137,8 @@ typedef struct _COMSYMBOL char * szName; /* the name of the symbol */ char cScope; /* the scope of the symbol */ char cType; + BYTE * cParamTypes; + int iParamCount; struct _COMSYMBOL * pNext; /* pointer to the next defined symbol */ } COMSYMBOL, * PCOMSYMBOL; @@ -349,6 +351,7 @@ extern USHORT hb_comp_wWhileCounter; extern USHORT hb_comp_wCaseCounter; extern BOOL hb_comp_EOL; +extern char * hb_comp_szDeclaredFun; extern char * hb_comp_szErrors[]; extern char * hb_comp_szWarnings[]; diff --git a/harbour/include/hberrors.h b/harbour/include/hberrors.h index c572de6641..1b44939d65 100644 --- a/harbour/include/hberrors.h +++ b/harbour/include/hberrors.h @@ -105,9 +105,11 @@ extern "C" { #define HB_COMP_WARN_OPERAND_SUSPECT 12 #define HB_COMP_WARN_NOT_ARRAY 13 #define HB_COMP_RETURN_TYPE 14 -#define HB_COMP_WARN_MEANINGLESS 15 -#define HB_COMP_WARN_UNREACHABLE 16 -#define HB_COMP_WARN_DUPL_ANNOUNCE 17 +#define HB_COMP_PARAM_COUNT 15 +#define HB_COMP_PARAM_TYPE 16 +#define HB_COMP_WARN_MEANINGLESS 17 +#define HB_COMP_WARN_UNREACHABLE 18 +#define HB_COMP_WARN_DUPL_ANNOUNCE 19 /* * Errors generated by Harbour preprocessor diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index 1bf5868f39..f554485773 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -116,6 +116,7 @@ BOOL hb_comp_bSyntaxCheckOnly = FALSE; /* syntax check only */ int hb_comp_iLanguage = LANG_C; /* default Harbour generated output language */ int hb_comp_iJumpOptimize = 1; BOOL hb_comp_EOL; +char * hb_comp_szDeclaredFun = NULL; typedef struct __EXTERN { @@ -431,6 +432,25 @@ void hb_compVariableAdd( char * szVarName, char cValueType ) PVAR pVar, pLastVar; PFUNCTION pFunc = hb_comp_functions.pLast; + if ( hb_comp_iWarnings > 2 && 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; + + return; + } + } + HB_SYMBOL_UNUSED( cValueType ); if( ! hb_comp_bStartProc && hb_comp_functions.iCount <= 1 && hb_comp_iVarScope == VS_LOCAL ) { @@ -643,7 +663,6 @@ BOOL hb_compVariableMacroCheck( char * szVarName ) return bValid; } - PCOMSYMBOL hb_compSymbolAdd( char * szSymbolName, USHORT * pwPos ) { PCOMSYMBOL pSym; @@ -659,6 +678,8 @@ PCOMSYMBOL hb_compSymbolAdd( char * szSymbolName, USHORT * pwPos ) pSym->szName = szSymbolName; pSym->cScope = 0; pSym->cType = hb_comp_cVarType; + pSym->cParamTypes = NULL; + pSym->iParamCount = 0; pSym->pNext = NULL; if( ! hb_comp_symbols.iCount ) diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index 25c4786311..c71b782b0e 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -124,7 +124,6 @@ static PTR_LOOPEXIT hb_comp_pLoops = NULL; static HB_RTVAR_PTR hb_comp_rtvars = NULL; char * hb_comp_szAnnounce = NULL; /* ANNOUNCEd procedure */ - %} %union /* special structure used by lex and yacc to share info */ @@ -260,7 +259,7 @@ Line : LINE NUM_INTEGER LITERAL Crlf Function : FunScope FUNCTION IdentName { hb_comp_cVarType = ' '; hb_compFunctionAdd( $3, ( HB_SYMBOLSCOPE ) $1, 0 ); } Params Crlf {} | FunScope PROCEDURE IdentName { hb_comp_cVarType = ' '; hb_compFunctionAdd( $3, ( HB_SYMBOLSCOPE ) $1, FUN_PROCEDURE ); } Params Crlf {} - | FunScope DECLARE_FUN IdentName Params AsType Crlf { hb_compSymbolAdd( $3, NULL ); } + | FunScope DECLARE_FUN IdentName { hb_compSymbolAdd( $3, NULL ); hb_comp_szDeclaredFun = $3 ; } Params AsType Crlf { hb_comp_symbols.pLast->cType = hb_comp_cVarType; hb_comp_szDeclaredFun = NULL; } ; FunScope : { $$ = HB_FS_PUBLIC; } diff --git a/harbour/source/compiler/hbgenerr.c b/harbour/source/compiler/hbgenerr.c index 2228f7dc5c..a745e0db8e 100644 --- a/harbour/source/compiler/hbgenerr.c +++ b/harbour/source/compiler/hbgenerr.c @@ -105,6 +105,8 @@ char * hb_comp_szWarnings[] = "3Suspicious operand type: \'UnKnown\' expected: \'%s\'", "3Can\'t use array index with NON Array", "3Incompatible return value: \'%s\' expected: \'%s\'", + "3Invalid number of parameters: \'%s\' expected: \'%s\'", + "3Incompatible parameter # %s expected: \'%s\'", "0Meaningless use of expression: \'%s\'", "2Unreachable code", "1Redundant \'ANNOUNCE %s\' statement ignored" diff --git a/harbour/source/compiler/hbpcode.c b/harbour/source/compiler/hbpcode.c index a3dec34895..de8fb43e89 100644 --- a/harbour/source/compiler/hbpcode.c +++ b/harbour/source/compiler/hbpcode.c @@ -166,6 +166,9 @@ static BYTE s_pcode_len[] = { 1 /* HB_P_ONE, */ }; +static BYTE * cParamTypes = NULL; +static int iParamCount = -1; + void hb_compPCodeEval( PFUNCTION pFunc, HB_PCODE_FUNC_PTR * pFunctions, void * cargo ) { ULONG ulPos = 0; @@ -244,11 +247,41 @@ void hb_compStrongType( int iSize ) /* TODO: Add support for Function Parameters Declaration. */ wVar = pFunc->pCode[ ulPos + 1 ]; + if ( iParamCount > -1 ) + { + if( iParamCount == wVar ) + { + BYTE iOffset = 0; + + while ( iParamCount-- > 0 ) + { + iOffset++; + if ( cParamTypes[ iParamCount ] != pFunc->pStack[ pFunc->iStackIndex - iOffset ] ) + { + sprintf( szType1, "%i", iParamCount + 1 ); + sprintf( szType2, "%c", cParamTypes[ iParamCount ] ); + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_PARAM_TYPE, szType1, szType2 ); + } + } + } + else + { + sprintf( szType1, "%i", wVar ); + sprintf( szType2, "%i", iParamCount ); + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_PARAM_COUNT, szType1, szType2 ); + } + } + /* Removing all the optional parameters. Rteurn type already pushed just prior to parameters */ pFunc->iStackIndex -= wVar; /* Removing the NIL */ pFunc->iStackIndex--; + + /* Resetting */ + cParamTypes = NULL; + iParamCount = -1; + break; case HB_P_DO : @@ -492,34 +525,36 @@ void hb_compStrongType( int iSize ) /* Charcters */ case HB_P_PUSHSTRSHORT : case HB_P_PUSHSTR : - pFunc->pStack[ pFunc->iStackIndex++ ] = 'C'; - break; + pFunc->pStack[ pFunc->iStackIndex++ ] = 'C'; + break; case HB_P_PUSHSYM : case HB_P_MPUSHSYM : pSym = hb_compSymbolGetPos( pFunc->pCode[ ulPos + 1 ] + pFunc->pCode[ ulPos + 2 ] * 256 ); - if ( pSym ) + if ( pSym && pSym->cType ) + { pFunc->pStack[ pFunc->iStackIndex++ ] = pSym->cType; + + /* Storing, will be checked by FUNCTION* */ + cParamTypes = pSym->cParamTypes; + iParamCount = pSym->iParamCount; + } else - pFunc->pStack[ pFunc->iStackIndex++ ] = ' '; + pFunc->pStack[ pFunc->iStackIndex++ ] = ' '; break; case HB_P_PUSHSYMNEAR : pSym = hb_compSymbolGetPos( pFunc->pCode[ ulPos + 1 ] ); - if ( pSym ) + if ( pSym && pSym->cType ) { - /* TODO: Check this!!! - if ( ( pSym->cScope & HB_FS_PUBLIC ) == HB_FS_PUBLIC || - ( pSym->cScope & HB_FS_STATIC ) == HB_FS_STATIC || - ( pSym->cScope & HB_FS_INIT ) == HB_FS_INIT || - ( pSym->cScope & HB_FS_EXIT ) == HB_FS_EXIT ) - */ - /* Storing a Book Mark of the last pushed symbol so we know how many bytes to pop when encountering function call. */ - pFunc->pStack[ pFunc->iStackIndex++ ] = pSym->cType; + + /* Storing, will be checked by FUNCTION* */ + cParamTypes = pSym->cParamTypes; + iParamCount = pSym->iParamCount; } else pFunc->pStack[ pFunc->iStackIndex++ ] = ' '; diff --git a/harbour/tests/testwarn.prg b/harbour/tests/testwarn.prg index 89a4e27c20..57e7714125 100644 --- a/harbour/tests/testwarn.prg +++ b/harbour/tests/testwarn.prg @@ -7,7 +7,7 @@ #pragma -es0 #endif -DECLARE FUNCTION nMyFunc( ) AS NUMERIC +DECLARE FUNCTION nMyFunc( cVar AS CHARACTER, nVar AS NUMERIC ) AS NUMERIC FUNCTION Main() @@ -15,7 +15,7 @@ FUNCTION Main() n := &SomeFun( 2, 3 ) - n := nMyFunc( .F., 'A' ) + n := nMyFunc( a, cVar ) + 3 n := &(cVar)