From bf9fd1abbafe5d1b88c55eaa513c4fc80c933b52 Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Mon, 9 Apr 2001 19:02:59 +0000 Subject: [PATCH] 2001-04-09 11:50 UTC-0800 Ron Pinkas * include/hberrors.h * source/compiler/hbgenerr.c + Added #define HB_COMP_WARN_PARAM_SUSPECT 18 -> "4Suspecious parameter: %s expected: \'%s\'" * include/hbcomp.h + Added extern PCOMDECLARED hb_comp_pReleaseDeclared; * source/compiler/harbour.c + Added static void hb_compDeclaredInit( void ) initializes decalaration of standard functions; * source/compiler/genc.c * Changed release code from hb_comp_pFirstDeclared to hb_comp_pReleaseDeclared. * source/compiler/hbpcode.c * Many refinments. --- harbour/ChangeLog | 17 +++++++ harbour/include/hbcomp.h | 1 + harbour/include/hberrors.h | 30 ++++++------ harbour/source/compiler/genc.c | 2 +- harbour/source/compiler/harbour.c | 47 +++++++++++++++--- harbour/source/compiler/hbgenerr.c | 9 ++-- harbour/source/compiler/hbpcode.c | 79 ++++++++++++++++++++---------- 7 files changed, 132 insertions(+), 53 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index fa7ca459cd..e3d6c794d0 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,20 @@ +2001-04-09 11:50 UTC-0800 Ron Pinkas + * include/hberrors.h + * source/compiler/hbgenerr.c + + Added #define HB_COMP_WARN_PARAM_SUSPECT 18 -> "4Suspecious parameter: %s expected: \'%s\'" + + * include/hbcomp.h + + Added extern PCOMDECLARED hb_comp_pReleaseDeclared; + + * source/compiler/harbour.c + + Added static void hb_compDeclaredInit( void ) initializes decalaration of standard functions; + + * source/compiler/genc.c + * Changed release code from hb_comp_pFirstDeclared to hb_comp_pReleaseDeclared. + + * source/compiler/hbpcode.c + * Many refinments. + 2001-04-08 16:15 UTC-0800 Ron Pinkas * include/hberrors.h ! Corrected typo. diff --git a/harbour/include/hbcomp.h b/harbour/include/hbcomp.h index 886cf02b74..bc6b654abf 100644 --- a/harbour/include/hbcomp.h +++ b/harbour/include/hbcomp.h @@ -407,6 +407,7 @@ extern FUNCTIONS hb_comp_funcalls; extern SYMBOLS hb_comp_symbols; extern PCOMDECLARED hb_comp_pFirstDeclared; extern PCOMDECLARED hb_comp_pLastDeclared; +extern PCOMDECLARED hb_comp_pReleaseDeclared; extern PCOMCLASS hb_comp_pFirstClass; extern PCOMCLASS hb_comp_pLastClass; extern char * hb_comp_szFromClass; diff --git a/harbour/include/hberrors.h b/harbour/include/hberrors.h index e126e8c078..c61f08c4fe 100644 --- a/harbour/include/hberrors.h +++ b/harbour/include/hberrors.h @@ -111,21 +111,21 @@ extern "C" { #define HB_COMP_WARN_OPERAND_SUSPECT 12 #define HB_COMP_WARN_NOT_ARRAY 13 #define HB_COMP_WARN_RETURN_TYPE 14 -#define HB_COMP_WARN_PARAM_COUNT 15 -#define HB_COMP_WARN_PARAM_TYPE 16 -#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_VAL_NOT_USED 20 -#define HB_COMP_WARN_ARRAY_ASSIGN_TYPE 21 -#define HB_COMP_WARN_ARRAY_ASSIGN_SUSPECT 22 -#define HB_COMP_WARN_CLASS_NOT_FOUND 23 -#define HB_COMP_WARN_MESSAGE_NOT_FOUND 24 -#define HB_COMP_WARN_MEANINGLESS 25 -#define HB_COMP_WARN_UNREACHABLE 26 -#define HB_COMP_WARN_DUPL_ANNOUNCE 27 -#define HB_COMP_WARN_DUPL_ANNOUNCE 27 -#define HB_COMP_WARN_RETURN_SUSPECT 28 +#define HB_COMP_WARN_RETURN_SUSPECT 15 +#define HB_COMP_WARN_PARAM_COUNT 16 +#define HB_COMP_WARN_PARAM_TYPE 17 +#define HB_COMP_WARN_PARAM_SUSPECT 18 +#define HB_COMP_WARN_DUP_DECLARATION 19 +#define HB_COMP_WARN_DECLARATION_CONFLICT 20 +#define HB_COMP_WARN_NOT_INITIALIZED 21 +#define HB_COMP_WARN_VAL_NOT_USED 22 +#define HB_COMP_WARN_ARRAY_ASSIGN_TYPE 23 +#define HB_COMP_WARN_ARRAY_ASSIGN_SUSPECT 24 +#define HB_COMP_WARN_CLASS_NOT_FOUND 25 +#define HB_COMP_WARN_MESSAGE_NOT_FOUND 26 +#define HB_COMP_WARN_MEANINGLESS 27 +#define HB_COMP_WARN_UNREACHABLE 28 +#define HB_COMP_WARN_DUPL_ANNOUNCE 29 /* * Errors generated by Harbour preprocessor diff --git a/harbour/source/compiler/genc.c b/harbour/source/compiler/genc.c index d1d8cf0705..93b8b12620 100644 --- a/harbour/source/compiler/genc.c +++ b/harbour/source/compiler/genc.c @@ -282,7 +282,7 @@ void hb_compGenCCode( PHB_FNAME pFileName ) /* generates the C language ou pInline = hb_comp_inlines.pFirst; } - pDeclared = hb_comp_pFirstDeclared; + pDeclared = hb_comp_pReleaseDeclared->pNext; while( pDeclared ) { hb_comp_pFirstDeclared = pDeclared->pNext; diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index ec23a95886..eb093c6fb3 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -40,6 +40,7 @@ * hb_compMethodAdd() * hb_compMethodFind() * hb_compDeclaredAdd() + * hb_compDeclaredInit() * * See doc/license.txt for licensing terms. * @@ -77,6 +78,8 @@ static void hb_compOptimizeJumps( void ); static void hb_compPrepareOptimize( void ); static void hb_compOptimizeFrames( PFUNCTION pFunc ); +static void hb_compDeclaredInit( void ); + /* global variables */ FILES hb_comp_files; FUNCTIONS hb_comp_functions; @@ -84,6 +87,7 @@ FUNCTIONS hb_comp_funcalls; SYMBOLS hb_comp_symbols; PCOMDECLARED hb_comp_pFirstDeclared; PCOMDECLARED hb_comp_pLastDeclared; +PCOMDECLARED hb_comp_pReleaseDeclared; PCOMCLASS hb_comp_pFirstClass; PCOMCLASS hb_comp_pLastClass; @@ -209,6 +213,10 @@ int main( int argc, char * argv[] ) /* Prepare the table of identifiers */ hb_compIdentifierOpen(); + /* Load standard Declarations. */ + if ( hb_comp_iWarnings >= 3 ) + hb_compDeclaredInit(); + /* Process all files passed via the command line. */ bAnyFiles = FALSE; @@ -885,6 +893,38 @@ PCOMDECLARED hb_compMethodFind( PCOMCLASS pClass, char * szMethodName ) return NULL; } +void hb_compDeclaredInit( void ) +{ + /* + \x5c -> ByRef (+60) '-' -> NIL + \x7a -> Optional (+90) 'U' -> Undefined + + ' ' -> AnyType 'A' -> Array 'B' -> Array + 'A' -> Array of AnyType 'a' -> Array of Arrays 'b' -> Array of Blocks + \x7a -> Optional AnyType \x9b -> Optional Array \x9c -> Optional Block + \x94 -> Optional Array of AnyType \xb5 -> Optional Array of Arrays \xb6 -> Optional Array of Blocks + + 'C' -> Character/String 'D' -> Date 'L' -> Logical + 'c' -> Array of Strings 'd' -> Array of Dates 'l' -> Array of Logicals + \x9d -> Optional Character \x9e -> Optional Date \xa6 -> Optional Logical + \xb7 -> Optional Array of Strings \xb8 -> Optional Array of Dates \xc0 -> Optional Array of Logicals + + 'N' -> Numeric 'O' -> Object 'S' -> Class + 'n' -> Array of Numerics 'o' -> Array of Objects 's' -> Array of Classes + \xa8 -> Optional Numeric \xa9 -> Optional Object \xad -> Optional Class + \xc2 -> Optional Array of Numerics \xc3 -> Optional Array of Objects \xc7 -> Optional Array of Classes + + Name Ret Param Types # of Prams Class Param Classes Next + ---------- --- ----------------------- ---------- ----- ------------- ------ */ + static COMDECLARED s_001 = { "AADD" , ' ', "A " , 2 , NULL , NULL , NULL }; + static COMDECLARED s_002 = { "ABS" , 'N', "N" , 1 , NULL , NULL , &s_001 }; + static COMDECLARED s_003 = { "ACHOICE" , 'N', "NNNNc\x7a\x9d\xa8\xa8", 9 , NULL , NULL , &s_002 }; + + hb_comp_pFirstDeclared = &s_003; /* Change to BOTTOM item. */ + hb_comp_pLastDeclared = &s_001; + hb_comp_pReleaseDeclared = &s_001; +} + PCOMDECLARED hb_compDeclaredAdd( char * szDeclaredName ) { PCOMDECLARED pDeclared; @@ -916,12 +956,7 @@ PCOMDECLARED hb_compDeclaredAdd( char * szDeclaredName ) pDeclared->pParamClasses = NULL; pDeclared->pNext = NULL; - /* First Declare */ - if ( hb_comp_pFirstDeclared == NULL ) - hb_comp_pFirstDeclared = pDeclared; - else - hb_comp_pLastDeclared->pNext = pDeclared; - + hb_comp_pLastDeclared->pNext = pDeclared; hb_comp_pLastDeclared = pDeclared; return pDeclared; diff --git a/harbour/source/compiler/hbgenerr.c b/harbour/source/compiler/hbgenerr.c index f32f1c6ce8..f5a7697426 100644 --- a/harbour/source/compiler/hbgenerr.c +++ b/harbour/source/compiler/hbgenerr.c @@ -108,13 +108,15 @@ char * hb_comp_szWarnings[] = "1Function \'%s\' does not end with RETURN statement", "3Incompatible type in assignment to: \'%s\' expected: \'%s\'", "3Incompatible operand type: \'%s\' expected: \'%s\'", + "4Suspicious operand type: \'unknown\' expected: \'%s\'", "3Incompatible operand types: \'%s\' and: \'%s\'", "4Suspicious type in assignment to: \'%s\' expected: \'%s\'", - "4Suspicious operand type: \'unknown\' expected: \'%s\'", "3Can\'t use array index with non-array", "3Incompatible return type: \'%s\' expected: \'%s\'", + "4Suspecious return type: \'%s\' expected: \'%s\'", "3Invalid number of parameters: %s expected: %s", - "3Incompatible parameter # %s expected: \'%s\'", + "3Incompatible parameter: %s expected: \'%s\'", + "4Suspecious parameter: %s expected: \'%s\'", "3Duplicate declaration of %s \'%s\'", "3Function \'%s\' conflicting with its declaration", "3Variable \'%s\' used but never initialized", @@ -125,8 +127,7 @@ char * hb_comp_szWarnings[] = "3Message \'%s\' not known in class \'%s\'", "0Meaningless use of expression: \'%s\'", "2Unreachable code", - "1Redundant \'ANNOUNCE %s\' statement ignored", - "4Suspecious return type: \'%s\' expected: \'%s\'" + "1Redundant \'ANNOUNCE %s\' statement ignored" }; void hb_compGenError( char * szErrors[], char cPrefix, int iError, const char * szError1, const char * szError2 ) diff --git a/harbour/source/compiler/hbpcode.c b/harbour/source/compiler/hbpcode.c index f526bd9907..eeb6a81f19 100644 --- a/harbour/source/compiler/hbpcode.c +++ b/harbour/source/compiler/hbpcode.c @@ -385,6 +385,8 @@ void hb_compStrongType( int iSize ) /* printf( "\nNeeded %i values, found %i!\n", wVar + 1, pFunc->iStackIndex - 1 ); */ + pFunc->iStackIndex = 1; + pFunc->pStack[ 0 ] = ' '; break; } @@ -406,9 +408,10 @@ void hb_compStrongType( int iSize ) break; } - /*printf( "\nOptionals: %i\n", iOptionals );*/ - - printf( "\nExec Function: %s, wVar: %i Parameters: %i Optionals: %i\n", pFunc->pStackFunctions[ pFunc->iStackFunctions ]->szName,wVar, hb_comp_iParamCount, iOptionals ); + /* + printf( "\nOptionals: %i\n", iOptionals ); + printf( "\nExec Function: %s, wVar: %i Parameters: %i Optionals: %i\n", pFunc->pStackFunctions[ pFunc->iStackFunctions ]->szName, wVar, hb_comp_iParamCount, iOptionals ); + */ /* Now, check the types. */ if( wVar >= ( hb_comp_iParamCount - iOptionals ) && wVar <= hb_comp_iParamCount ) @@ -418,6 +421,8 @@ void hb_compStrongType( int iSize ) while ( --iOffset >= 0 ) { + BOOL bByRef = FALSE; + cParamType = pFunc->pStack[ iParamBase + iOffset ]; if( ( cParamType == '-' + VT_OFFSET_VARIANT ) || cParamType >= ( 'A' + VT_OFFSET_VARIANT ) ) { @@ -425,28 +430,24 @@ void hb_compStrongType( int iSize ) } cFormalType = hb_comp_cParamTypes[ iOffset ]; + if( cFormalType == ( ' ' + VT_OFFSET_OPTIONAL ) || cFormalType >= ( 'A' + VT_OFFSET_OPTIONAL ) ) { cFormalType -= VT_OFFSET_OPTIONAL; } - if( cFormalType == ' ' + VT_OFFSET_BYREF ) + if( cFormalType == ' ' + VT_OFFSET_BYREF || cFormalType >= ( 'A' + VT_OFFSET_BYREF ) ) { - cFormalType = '@'; + bByRef = TRUE; + cFormalType -= VT_OFFSET_BYREF; } - if( cFormalType == ' ' ) + /* --- */ + + if( cFormalType == ' ' && ! bByRef ) { /* Declared is Variant, accept anything. */ } - else if( cParamType == '-' ) - { - /* Parameter is NIL, always accepted. */ - } - else if( cFormalType == '@' && cParamType >= ( 'A' + VT_OFFSET_BYREF ) ) - { - /* Prameter is ANY REFERENCE, and Parameter is SOME REFERENCE. */ - } else if( cFormalType == 'S' && cParamType == 'S' && pFunc->iStackClasses ) { PCOMCLASS hb_comp_pFormalClass = pFunc->pStackFunctions[ pFunc->iStackFunctions ]->pParamClasses[ iOffset ]; @@ -454,7 +455,7 @@ void hb_compStrongType( int iSize ) if( hb_comp_pFormalClass != hb_comp_pParamClass ) { - sprintf( ( char * ) szType1, "%i", iOffset + 1 ); + sprintf( ( char * ) szType1, "%s %i", pFunc->pStackFunctions[ pFunc->iStackFunctions ]->szName, iOffset + 1 ); sprintf( ( char * ) szType2, "%s", hb_comp_pFormalClass->szName ); hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_PARAM_TYPE, ( char * ) szType1, ( char * ) szType2 ); } @@ -466,7 +467,7 @@ void hb_compStrongType( int iSize ) if( hb_comp_pFormalClass != hb_comp_pParamClass ) { - sprintf( ( char * ) szType1, "%i", iOffset + 1 ); + sprintf( ( char * ) szType1, "%s %i", pFunc->pStackFunctions[ pFunc->iStackFunctions ]->szName, iOffset + 1 ); sprintf( ( char * ) szType2, "ARRAY OF %s", hb_comp_pFormalClass->szName ); hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_PARAM_TYPE, ( char * ) szType1, ( char * ) szType2 ); } @@ -485,30 +486,54 @@ void hb_compStrongType( int iSize ) } else { - if( cFormalType > ( 'A' + VT_OFFSET_BYREF ) ) - { - sprintf( ( char * ) szType2, "@%c", cFormalType - VT_OFFSET_BYREF ); - } - else if( toupper( pFunc->pStack[ iParamBase + iOffset ] ) == 'S' && pFunc->iStackClasses ) - { + /* Cleanup. */ + if( toupper( cParamType ) == 'S' && pFunc->iStackClasses ) + { --pFunc->iStackClasses; + } + + if( bByRef ) + { + sprintf( ( char * ) szType2, "@%c", cFormalType ); } - else + else if( islower( cFormalType ) ) + { + sprintf( ( char * ) szType2, "ARRAY OF %c", toupper( cFormalType ) ); + } + else { sprintf( ( char * ) szType2, "%c", cFormalType ); } } - sprintf( ( char * ) szType1, "%i", iOffset + 1 ); + sprintf( ( char * ) szType1, "%s #%i", pFunc->pStackFunctions[ pFunc->iStackFunctions ]->szName, iOffset + 1 ); - hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_PARAM_TYPE, ( char * ) szType1, ( char * ) szType2 ); + if( cParamType == ' ' || cParamType == '-' || cParamType == 'U' ) + { + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_PARAM_SUSPECT, ( char * ) szType1, ( char * ) szType2 ); + } + else if( bByRef && cParamType == ( ' ' + VT_OFFSET_BYREF ) || cParamType >= ( 'A' + VT_OFFSET_BYREF ) ) + { + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_PARAM_SUSPECT, ( char * ) szType1, ( char * ) szType2 ); + } + else + { + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_PARAM_TYPE, ( char * ) szType1, ( char * ) szType2 ); + } } } } else { - sprintf( ( char * ) szType1, "%i", wVar ); - sprintf( ( char * ) szType2, "%i", hb_comp_iParamCount - iOptionals ); + sprintf( ( char * ) szType1, "%s got %i", pFunc->pStackFunctions[ pFunc->iStackFunctions ]->szName, wVar ); + if( iOptionals ) + { + sprintf( ( char * ) szType2, "%i-%i", hb_comp_iParamCount - iOptionals, hb_comp_iParamCount ); + } + else + { + sprintf( ( char * ) szType2, "%i", hb_comp_iParamCount - iOptionals ); + } hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_PARAM_COUNT, ( char * ) szType1, ( char * ) szType2 ); } }