From 86e2384686fcfb49f3f96a9011fdfda361c8ae52 Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Thu, 4 May 2000 10:26:57 +0000 Subject: [PATCH] 20000504-03:10 GMT-8 Ron Pinkas * source/compiler/harbour.l + Added: "as bool array" { return AS_LOGICAL_ARRAY; } "as boolean array" { return AS_LOGICAL_ARRAY; } "as var" { return AS_VARIANT; } "as variant" { return AS_VARIANT; } "as num array" { return AS_NUMERIC_ARRAY; } "as numeric array" { return AS_NUMERIC_ARRAY; } "as char array" { return AS_CHARACTER_ARRAY; } "as character array" { return AS_CHARACTER_ARRAY; } "as string array" { return AS_CHARACTER_ARRAY; } "as logical array" { return AS_LOGICAL_ARRAY; } "as bool array" { return AS_LOGICAL_ARRAY; } "as boolean array" { return AS_LOGICAL_ARRAY; } "as date array" { return AS_DATE_ARRAY; } "as array array" { return AS_ARRAY_ARRAY; } "as block array" { return AS_BLOCK_ARRAY; } "as object array" { return AS_OBJECT_ARRAY; } "as var array" { return AS_VARIANT; } "as variant array" { return AS_VARIANT; } * source/compiler/harbour.y + Added AsArray + Added : %token AS_NUMERIC_ARRAY AS_CHARACTER_ARRAY AS_LOGICAL_ARRAY AS_DATE_ARRAY AS_ARRAY_ARRAY AS_BLOCK_ARRAY AS_OBJECT_ARRAY AS_VARIANT_ARRAY + Added rules to support declarion of array elements type * source/compiler/harbour.c ! Minor fix to hb_compVariableGetPos() to signify var usage if warning level lower than 3 * source/compiler/hbpcode.c + Added logic to hb_compStrongType() to support type checking of array elements declared type. * include/hberrors.h + Added #define HB_COMP_ARRAY_ASSIGN_TYPE * source/compiler/hbgenerr.c + Added : "3Incompatible type in assignment to declared array element expected: \'%s\'" * tests/testwarn.prg + Added code to demonstrate more warnings. * contrib/hbclip/hbclip.ch + Added additional strong typing compatibility translations --- harbour/ChangeLog | 52 +++++++++++++- harbour/contrib/hbclip/hbclip.ch | 50 ++++++++++--- harbour/include/hberrors.h | 7 +- harbour/source/compiler/harbour.c | 9 ++- harbour/source/compiler/harbour.l | 40 ++++++++--- harbour/source/compiler/harbour.y | 31 +++++++-- harbour/source/compiler/hbgenerr.c | 1 + harbour/source/compiler/hbpcode.c | 108 ++++++++++++++++++++--------- harbour/tests/testwarn.prg | 53 +++++++++++++- 9 files changed, 281 insertions(+), 70 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 6bb528caac..39bd92565a 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,16 +1,62 @@ +20000504-03:10 GMT-8 Ron Pinkas + + * source/compiler/harbour.l + + Added: + "as bool array" { return AS_LOGICAL_ARRAY; } + "as boolean array" { return AS_LOGICAL_ARRAY; } + "as var" { return AS_VARIANT; } + "as variant" { return AS_VARIANT; } + "as num array" { return AS_NUMERIC_ARRAY; } + "as numeric array" { return AS_NUMERIC_ARRAY; } + "as char array" { return AS_CHARACTER_ARRAY; } + "as character array" { return AS_CHARACTER_ARRAY; } + "as string array" { return AS_CHARACTER_ARRAY; } + "as logical array" { return AS_LOGICAL_ARRAY; } + "as bool array" { return AS_LOGICAL_ARRAY; } + "as boolean array" { return AS_LOGICAL_ARRAY; } + "as date array" { return AS_DATE_ARRAY; } + "as array array" { return AS_ARRAY_ARRAY; } + "as block array" { return AS_BLOCK_ARRAY; } + "as object array" { return AS_OBJECT_ARRAY; } + "as var array" { return AS_VARIANT; } + "as variant array" { return AS_VARIANT; } + + * source/compiler/harbour.y + + Added AsArray + + Added : %token AS_NUMERIC_ARRAY AS_CHARACTER_ARRAY AS_LOGICAL_ARRAY AS_DATE_ARRAY AS_ARRAY_ARRAY AS_BLOCK_ARRAY AS_OBJECT_ARRAY AS_VARIANT_ARRAY + + Added rules to support declarion of array elements type + + * source/compiler/harbour.c + ! Minor fix to hb_compVariableGetPos() to signify var usage if warning level lower than 3 + + * source/compiler/hbpcode.c + + Added logic to hb_compStrongType() to support type checking of array elements declared type. + + * include/hberrors.h + + Added #define HB_COMP_ARRAY_ASSIGN_TYPE + + * source/compiler/hbgenerr.c + + Added : "3Incompatible type in assignment to declared array element expected: \'%s\'" + + * tests/testwarn.prg + + Added code to demonstrate more warnings. + + * contrib/hbclip/hbclip.ch + + Added additional strong typing compatibility translations + 20000504-12:07 GMT+3 Chen Kedem * doc/en/array.txt ! Change ASORT() $COMPLIANCE$ as suggested by Victor Szakats 20000504-09:12 GMT+1 Victor Szakats - * contrib/hbclip/hbclip.ch + * contrib/hbclip/hbclip.ch + Added strong typing compatibility translation * include/hbcomp.h * include/hberrors.h - * source/compiler/harbour.c - * source/compiler/hbpcode.c + * source/compiler/harbour.c + * source/compiler/hbpcode.c ! Some macros renamed ! One warning fixed. ! Minor fixes. diff --git a/harbour/contrib/hbclip/hbclip.ch b/harbour/contrib/hbclip/hbclip.ch index 1610dbd59f..b583786901 100644 --- a/harbour/contrib/hbclip/hbclip.ch +++ b/harbour/contrib/hbclip/hbclip.ch @@ -61,18 +61,46 @@ #xtranslate HB_SETKEYSAVE( [] ) => ( {} ) #xtranslate HB_SETKEYCHECK( [, [, [, ]]] ) => ( .F. ) -#translate AS CHAR => -#translate AS CHARACTER => -#translate AS STRING => -#translate AS NUM => -#translate AS NUMERIC => -#translate AS DATE => -#translate AS ARRAY => -#translate AS BLOCK => -#translate AS OBJECT => -#translate AS LOGICAL => +#TRANSLATE AS CHAR ARRAY => +#TRANSLATE AS CHARACTER ARRAY => +#TRANSLATE AS STRING ARRAY => -#command DECLARE FUNCTION <*x*> => +#TRANSLATE AS NUM ARRAY => +#TRANSLATE AS NUMERIC ARRAY => + +#TRANSLATE AS DATE ARRAY => +#TRANSLATE AS ARRAY ARRAY => +#TRANSLATE AS BLOCK ARRAY => +#TRANSLATE AS OBJECT ARRAY => + +#TRANSLATE AS BOOL ARRAY => +#TRANSLATE AS BOOLEAN ARRAY => +#TRANSLATE AS LOGICAL ARRAY => + +#TRANSLATE AS VAR ARRAY => +#TRANSLATE AS VARIANT ARRAY => + + +#TRANSLATE AS CHAR => +#TRANSLATE AS CHARACTER => +#TRANSLATE AS STRING => + +#TRANSLATE AS NUM => +#TRANSLATE AS NUMERIC => + +#TRANSLATE AS DATE => +#TRANSLATE AS ARRAY => +#TRANSLATE AS BLOCK => +#TRANSLATE AS OBJECT => + +#TRANSLATE AS BOOL => +#TRANSLATE AS BOOLEAN => +#TRANSLATE AS LOGICAL => + +#TRANSLATE AS VAR => +#TRANSLATE AS VARIANT => + +#COMMAND DECLARE FUNCTION <*x*> => #endif /* HB_CLIP_CH_ */ diff --git a/harbour/include/hberrors.h b/harbour/include/hberrors.h index 17aad799a2..9f6492b212 100644 --- a/harbour/include/hberrors.h +++ b/harbour/include/hberrors.h @@ -110,9 +110,10 @@ extern "C" { #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_MEANINGLESS 20 -#define HB_COMP_WARN_UNREACHABLE 21 -#define HB_COMP_WARN_DUPL_ANNOUNCE 22 +#define HB_COMP_ARRAY_ASSIGN_TYPE 20 +#define HB_COMP_WARN_MEANINGLESS 21 +#define HB_COMP_WARN_UNREACHABLE 22 +#define HB_COMP_WARN_DUPL_ANNOUNCE 23 /* * Errors generated by Harbour preprocessor diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index 3bf2681f99..6309c992b9 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -1102,10 +1102,13 @@ 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. - Handled by hb_compStrongType() - pVars->iUsed |= VU_USED; + if ( hb_comp_iWarnings < 3 ) + pVars->iUsed |= VU_USED; + /* + else + Handled by hb_compStrongType() */ + return wVar; } else diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index c51181fb58..58448614e2 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -1297,16 +1297,36 @@ Separator {SpaceTab} } } -"as numeric" { return AS_NUMERIC; } -"as num" { return AS_NUMERIC; } -"as character" { return AS_CHARACTER; } -"as char" { return AS_CHARACTER; } -"as string" { return AS_CHARACTER; } -"as logical" { return AS_LOGICAL; } -"as date" { return AS_DATE; } -"as array" { return AS_ARRAY; } -"as block" { return AS_BLOCK; } -"as object" { return AS_OBJECT; } +"as num" { return AS_NUMERIC; } +"as numeric" { return AS_NUMERIC; } +"as char" { return AS_CHARACTER; } +"as character" { return AS_CHARACTER; } +"as string" { return AS_CHARACTER; } +"as logical" { return AS_LOGICAL; } +"as bool" { return AS_LOGICAL; } +"as boolean" { return AS_LOGICAL; } +"as date" { return AS_DATE; } +"as array" { return AS_ARRAY; } +"as block" { return AS_BLOCK; } +"as object" { return AS_OBJECT; } +"as var" { return AS_VARIANT; } +"as variant" { return AS_VARIANT; } + +"as num array" { return AS_NUMERIC_ARRAY; } +"as numeric array" { return AS_NUMERIC_ARRAY; } +"as char array" { return AS_CHARACTER_ARRAY; } +"as character array" { return AS_CHARACTER_ARRAY; } +"as string array" { return AS_CHARACTER_ARRAY; } +"as logical array" { return AS_LOGICAL_ARRAY; } +"as bool array" { return AS_LOGICAL_ARRAY; } +"as boolean array" { return AS_LOGICAL_ARRAY; } +"as date array" { return AS_DATE_ARRAY; } +"as array array" { return AS_ARRAY_ARRAY; } +"as block array" { return AS_BLOCK_ARRAY; } +"as object array" { return AS_OBJECT_ARRAY; } +"as var array" { return AS_VARIANT; } +"as variant array" { return AS_VARIANT; } + "declare function" { return DECLARE_FUN; } %{ diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index b9fb5f93cf..8c36c2dc22 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -161,7 +161,8 @@ char * hb_comp_szAnnounce = NULL; /* ANNOUNCEd procedure */ %token PLUSEQ MINUSEQ MULTEQ DIVEQ POWER EXPEQ MODEQ EXITLOOP %token PRIVATE BEGINSEQ BREAK RECOVER RECOVERUSING DO WITH SELF LINE %token MACROVAR MACROTEXT -%token AS_NUMERIC AS_CHARACTER AS_LOGICAL AS_DATE AS_ARRAY AS_BLOCK AS_OBJECT DECLARE_FUN +%token AS_NUMERIC AS_CHARACTER AS_LOGICAL AS_DATE AS_ARRAY AS_BLOCK AS_OBJECT AS_VARIANT DECLARE_FUN +%token AS_NUMERIC_ARRAY AS_CHARACTER_ARRAY AS_LOGICAL_ARRAY AS_DATE_ARRAY AS_ARRAY_ARRAY AS_BLOCK_ARRAY AS_OBJECT_ARRAY AS_VARIANT_ARRAY /*the lowest precedence*/ /*postincrement and postdecrement*/ @@ -193,7 +194,7 @@ char * hb_comp_szAnnounce = NULL; /* ANNOUNCEd procedure */ %type NUM_DOUBLE %type NUM_INTEGER %type NUM_LONG -%type FunScope AsType +%type FunScope AsType AsArray %type Params ParamList %type IfBegin VarList ExtVarList %type FieldList @@ -285,6 +286,26 @@ AsType : /* not specified */ { hb_comp_cVarType = ' '; } | AS_ARRAY { hb_comp_cVarType = 'A'; } | AS_BLOCK { hb_comp_cVarType = 'B'; } | AS_OBJECT { hb_comp_cVarType = 'O'; } + | AS_VARIANT { hb_comp_cVarType = ' '; } + | AS_NUMERIC_ARRAY { hb_comp_cVarType = 'n'; } + | AS_CHARACTER_ARRAY { hb_comp_cVarType = 'c'; } + | AS_DATE_ARRAY { hb_comp_cVarType = 'd'; } + | AS_LOGICAL_ARRAY { hb_comp_cVarType = 'l'; } + | AS_ARRAY_ARRAY { hb_comp_cVarType = 'a'; } + | AS_BLOCK_ARRAY { hb_comp_cVarType = 'b'; } + | AS_OBJECT_ARRAY { hb_comp_cVarType = 'o'; } + | AS_VARIANT_ARRAY { hb_comp_cVarType = 'A'; } + ; + +AsArray : AS_ARRAY { hb_comp_cVarType = 'A'; } + | AS_NUMERIC_ARRAY { hb_comp_cVarType = 'n'; } + | AS_CHARACTER_ARRAY { hb_comp_cVarType = 'c'; } + | AS_DATE_ARRAY { hb_comp_cVarType = 'd'; } + | AS_LOGICAL_ARRAY { hb_comp_cVarType = 'l'; } + | AS_ARRAY_ARRAY { hb_comp_cVarType = 'a'; } + | AS_BLOCK_ARRAY { hb_comp_cVarType = 'b'; } + | AS_OBJECT_ARRAY { hb_comp_cVarType = 'o'; } + | AS_VARIANT_ARRAY { hb_comp_cVarType = 'A'; } ; ParamList : IdentName AsType { hb_compVariableAdd( $1, ' ' ); $$ = 1; } @@ -1041,7 +1062,7 @@ ExtVarDef : VarDef hb_compGenPCode3( HB_P_ARRAYDIM, HB_LOBYTE( uCount ), HB_HIBYTE( uCount ), ( BOOL ) 1 ); hb_compRTVariableAdd( hb_compExprNewRTVar( NULL, $1 ), TRUE ); } - | MacroVar DimList AS_ARRAY + | MacroVar DimList AsArray { USHORT uCount = hb_compExprListLen( $2 ); hb_compExprDelete( hb_compExprGenPush( $2 ) ); @@ -1087,8 +1108,8 @@ VarDef : IdentName AsType { hb_compVariableAdd( $1, $2 ); } hb_comp_iVarScope = $3; } - | IdentName DimList { hb_compVariableDim( $1, $2 ); } - | IdentName DimList AS_ARRAY { hb_comp_cVarType = 'A'; hb_compVariableDim( $1, $2 ); } + | IdentName DimList { hb_compVariableDim( $1, $2 ); } + | IdentName DimList AsArray { hb_compVariableDim( $1, $2 ); } ; /* NOTE: DimList and DimIndex is the same as ArrayIndex and IndexList diff --git a/harbour/source/compiler/hbgenerr.c b/harbour/source/compiler/hbgenerr.c index 33cde31259..b528626cc8 100644 --- a/harbour/source/compiler/hbgenerr.c +++ b/harbour/source/compiler/hbgenerr.c @@ -110,6 +110,7 @@ char * hb_comp_szWarnings[] = "3Duplicate Declaration of Function %s", "3Function \'%s\' conflicting with its declaration", "3Variable \'%s\' used but never initialized", + "3Incompatible type in assignment to declared array element 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 f216529716..6805623381 100644 --- a/harbour/source/compiler/hbpcode.c +++ b/harbour/source/compiler/hbpcode.c @@ -218,7 +218,7 @@ void hb_compStrongType( int iSize ) ULONG ulPos = pFunc->lPCodePos - iSize; SHORT wVar; int iVar; - char szType1[32], szType2[32]; + char szType1[32], szType2[32], cType; BYTE bLast1, bLast2; /* Make sure we have enough stack space. */ @@ -659,10 +659,6 @@ void hb_compStrongType( int iSize ) /* Mark as used */ pVar->iUsed |= VU_USED; - /* Review with Ryszard. */ - if ( pVar->cType == 'U' ) - pVar->cType = ' '; - pFunc->pStack[ pFunc->iStackIndex++ ] = pVar->cType; } else @@ -776,9 +772,23 @@ void hb_compStrongType( int iSize ) /* TODO Error Message after finalizing all possible pcodes. */ break; - pFunc->iStackIndex -= wVar; + cType = pFunc->pStack[ pFunc->iStackIndex - 1 ]; + while ( --wVar ) + { + pFunc->iStackIndex--; - pFunc->pStack[ pFunc->iStackIndex++ ] = 'A'; + if ( cType == ' ' || cType != pFunc->pStack[ pFunc->iStackIndex - 1 ] ) + { + cType = 'A'; + break; + } + } + + /* Lower Case Indicates array of ...*/ + if ( cType != 'A' ) + cType = tolower( cType ); + + pFunc->pStack[ pFunc->iStackIndex - 1 ] = cType; break; @@ -789,9 +799,23 @@ void hb_compStrongType( int iSize ) /* TODO Error Message after finalizing all possible pcodes. */ break; - pFunc->iStackIndex -= wVar; + cType = pFunc->pStack[ pFunc->iStackIndex - 1 ]; + while ( --wVar ) + { + pFunc->iStackIndex--; - pFunc->pStack[ pFunc->iStackIndex++ ] = 'A'; + if ( cType == ' ' || cType != pFunc->pStack[ pFunc->iStackIndex - 1 ] ) + { + cType = 'A'; + break; + } + } + + /* Lowe Case Indicates array of ...*/ + if ( cType != 'A' ) + cType = tolower( cType ); + + pFunc->pStack[ pFunc->iStackIndex - 1 ] = cType; break; @@ -805,13 +829,37 @@ void hb_compStrongType( int iSize ) if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] == ' ' ) ; - else if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] != 'A' ) + else if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] != 'A' && isupper( pFunc->pStack[ pFunc->iStackIndex - 1 ] ) ) hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_NOT_ARRAY, NULL, NULL ); /* TODO: allow declaration of the Array Elements Type. */ /* Now we have the array elent on the stack.*/ - pFunc->pStack[ pFunc->iStackIndex - 1 ] = ' '; + pFunc->pStack[ pFunc->iStackIndex - 1 ] = toupper( pFunc->pStack[ pFunc->iStackIndex - 1 ] ); + break; + + case HB_P_ARRAYPOP : + /* Poping the Array Index. */ + pFunc->iStackIndex--; + + if ( pFunc->iStackIndex < 1 ) + /* TODO Error Message after finalizing all possible pcodes. */ + break; + + if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] == ' ' ) + ; + else if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] != 'A' && isupper( pFunc->pStack[ pFunc->iStackIndex - 1 ] ) ) + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_NOT_ARRAY, NULL, NULL ); + else if ( toupper( pFunc->pStack[ pFunc->iStackIndex - 1 ] ) != pFunc->pStack[ pFunc->iStackIndex - 1 ] ) + { + char szType[2]; + sprintf( szType, "%c", toupper( pFunc->pStack[ pFunc->iStackIndex - 1 ] ) ); + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_ARRAY_ASSIGN_TYPE, szType, NULL ); + } + + /* Poping the Assigned Value. */ + pFunc->iStackIndex--; + break; /* Macros type unknown */ @@ -870,8 +918,10 @@ void hb_compStrongType( int iSize ) 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 ] ) + else if ( isupper( pSym->cType ) && pSym->cType != pFunc->pStack[ pFunc->iStackIndex ] ) hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_ASSIGN_TYPE, pSym->szName, szType ); + else if ( toupper( pSym->cType ) != pFunc->pStack[ pFunc->iStackIndex ] ) + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_ARRAY_ASSIGN_TYPE, szType, NULL ); } break; @@ -897,8 +947,10 @@ void hb_compStrongType( int iSize ) 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 ] ) + else if ( isupper( pSym->cType ) && pSym->cType != pFunc->pStack[ pFunc->iStackIndex ] ) hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_ASSIGN_TYPE, pSym->szName, szType ); + else if ( toupper( pSym->cType ) != pFunc->pStack[ pFunc->iStackIndex ] ) + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_ARRAY_ASSIGN_TYPE, szType, NULL ); } break; @@ -937,8 +989,10 @@ void hb_compStrongType( int iSize ) if ( pFunc->pStack[ pFunc->iStackIndex ] == ' ' ) hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_ASSIGN_SUSPECT, pVar->szName, szType ); - else if ( pVar->cType != pFunc->pStack[ pFunc->iStackIndex ] ) + else if ( isupper( pVar->cType ) && pVar->cType != pFunc->pStack[ pFunc->iStackIndex ] ) hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_ASSIGN_TYPE, pVar->szName, szType ); + else if ( toupper( pVar->cType ) != pFunc->pStack[ pFunc->iStackIndex ] ) + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_ARRAY_ASSIGN_TYPE, szType, NULL ); } break; @@ -973,12 +1027,14 @@ void hb_compStrongType( int iSize ) if ( pVar && pVar->cType != ' ' ) { char szType[2]; - sprintf( szType, "%c", pVar->cType ); + sprintf( szType, "%c", toupper( pVar->cType ) ); if ( pFunc->pStack[ pFunc->iStackIndex ] == ' ' ) hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_ASSIGN_SUSPECT, pVar->szName, szType ); - else if ( pVar->cType != pFunc->pStack[ pFunc->iStackIndex ] ) + else if ( isupper( pVar->cType ) && pVar->cType != pFunc->pStack[ pFunc->iStackIndex ] ) hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_ASSIGN_TYPE, pVar->szName, szType ); + else if ( toupper( pVar->cType ) != pFunc->pStack[ pFunc->iStackIndex ] ) + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_ARRAY_ASSIGN_TYPE, szType, NULL ); } break; @@ -1010,6 +1066,8 @@ void hb_compStrongType( int iSize ) hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_ASSIGN_SUSPECT, pVar->szName, szType ); else if ( pVar->cType != pFunc->pStack[ pFunc->iStackIndex ] ) hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_ASSIGN_TYPE, pVar->szName, szType ); + else if ( toupper( pVar->cType ) != pFunc->pStack[ pFunc->iStackIndex ] ) + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_ARRAY_ASSIGN_TYPE, szType, NULL ); } break; @@ -1024,24 +1082,6 @@ void hb_compStrongType( int iSize ) case HB_P_MACROPOPALIASED : pFunc->iStackIndex--; break; - - case HB_P_ARRAYPOP : - /* Poping the Array Index. */ - pFunc->iStackIndex--; - - if ( pFunc->iStackIndex < 0 ) - /* TODO Error Message after finalizing all possible pcodes. */ - break; - - if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] == ' ' ) - ; - else if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] != 'A' ) - hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_NOT_ARRAY, NULL, NULL ); - - /* Poping the Assigned Value. */ - pFunc->iStackIndex--; - - break; } /* TODO Error or trace messages when completed. */ diff --git a/harbour/tests/testwarn.prg b/harbour/tests/testwarn.prg index 501ee99cf6..5e49b79981 100644 --- a/harbour/tests/testwarn.prg +++ b/harbour/tests/testwarn.prg @@ -5,6 +5,48 @@ // This file is OK to have warnings. #ifdef __HARBOUR__ #pragma -es0 +#else + + #TRANSLATE AS CHAR ARRAY => + #TRANSLATE AS CHARACTER ARRAY => + #TRANSLATE AS STRING ARRAY => + + #TRANSLATE AS NUM ARRAY => + #TRANSLATE AS NUMERIC ARRAY => + + #TRANSLATE AS DATE ARRAY => + #TRANSLATE AS ARRAY ARRAY => + #TRANSLATE AS BLOCK ARRAY => + #TRANSLATE AS OBJECT ARRAY => + + #TRANSLATE AS BOOL ARRAY => + #TRANSLATE AS BOOLEAN ARRAY => + #TRANSLATE AS LOGICAL ARRAY => + + #TRANSLATE AS VAR ARRAY => + #TRANSLATE AS VARIANT ARRAY => + + + #TRANSLATE AS CHAR => + #TRANSLATE AS CHARACTER => + #TRANSLATE AS STRING => + + #TRANSLATE AS NUM => + #TRANSLATE AS NUMERIC => + + #TRANSLATE AS DATE => + #TRANSLATE AS ARRAY => + #TRANSLATE AS BLOCK => + #TRANSLATE AS OBJECT => + + #TRANSLATE AS BOOL => + #TRANSLATE AS BOOLEAN => + #TRANSLATE AS LOGICAL => + + #TRANSLATE AS VAR => + #TRANSLATE AS VARIANT => + + #COMMAND DECLARE FUNCTION <*x*> => #endif DECLARE FUNCTION nMyFunc( cVar AS STRING, nVar AS NUMERIC ) AS NUMERIC @@ -20,8 +62,15 @@ DECLARE FUNCTION int( n AS NUMERIC ) AS NUMERIC DECLARE FUNCTION TEST AS NUMERIC PROCEDURE MAIN( Param1 ) + + LOCAL cVar as char, a[2,3,4] AS BOOL ARRAY + LOCAL RPT, APARAMS + a[1] = 2 + + cVAr := a[1] + Rpt := IIF( Param1, 1 , 0 ) Rpt := Array( Len( AParams ) - 2 ) @@ -56,7 +105,9 @@ Return( NIL ) FUNCTION Main3() - LOCAL n AS NUMERIC, cVar AS CHARACTER, a[5,5,5] AS ARRAY + LOCAL n AS NUMERIC, cVar AS CHARACTER, a[5,5,5] AS CHARACTER ARRAY + + cVar := a[1] n := &SomeFun( 2, 3 )