From 78a4a8e84f290c0adcd6bf7e83f27d07929b1e87 Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Wed, 3 May 2000 08:00:23 +0000 Subject: [PATCH] 20000503-01:00 GMT-8 Ron Pinkas * source/compiler/hbpcode.c * Fixed hb_compStrongType() to difrentiate between a MEMVAR and a DECLARED FUNCTION with the same name. + Added support for HB_P_ARRAYPUSH * source/compiler/hbgenerr.c * Minor correction to "Incompatibe return type" * tests/testwarn.prg + Added code to demonstrate more warnings. --- harbour/ChangeLog | 11 ++++ harbour/source/compiler/hbgenerr.c | 2 +- harbour/source/compiler/hbpcode.c | 85 +++++++++++++++++++----------- harbour/tests/testwarn.prg | 17 ++++++ 4 files changed, 83 insertions(+), 32 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 1ce725d9a3..013af8449d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,14 @@ +20000503-01:00 GMT-8 Ron Pinkas + * source/compiler/hbpcode.c + * Fixed hb_compStrongType() to difrentiate between a MEMVAR and a DECLARED FUNCTION with the same name. + + Added support for HB_P_ARRAYPUSH + + * source/compiler/hbgenerr.c + * Minor correction to "Incompatibe return type" + + * tests/testwarn.prg + + Added code to demonstrate more warnings. + 20000502-23:15 GMT-8 Ron Pinkas * include/hbcomp.h diff --git a/harbour/source/compiler/hbgenerr.c b/harbour/source/compiler/hbgenerr.c index 79327806d8..5a049946aa 100644 --- a/harbour/source/compiler/hbgenerr.c +++ b/harbour/source/compiler/hbgenerr.c @@ -104,7 +104,7 @@ char * hb_comp_szWarnings[] = "3Suspicious type in assignment to: \'%s\' expected: \'%s\'", "3Suspicious operand type: \'unknown\' expected: \'%s\'", "3Can\'t use array index with non-array", - "3Incompatible return value: \'%s\' expected: \'%s\'", + "3Incompatible return type: \'%s\' expected: \'%s\'", "3Invalid number of parameters: %s expected: %s", "3Incompatible parameter number %s expected: \'%s\'", "3Duplicate Declaration of Function %s", diff --git a/harbour/source/compiler/hbpcode.c b/harbour/source/compiler/hbpcode.c index b1648308d8..7bd21b28b9 100644 --- a/harbour/source/compiler/hbpcode.c +++ b/harbour/source/compiler/hbpcode.c @@ -584,41 +584,51 @@ void hb_compStrongType( int iSize ) case HB_P_PUSHSYM : case HB_P_MPUSHSYM : - pSym = hb_compSymbolGetPos( pFunc->pCode[ ulPos + 1 ] + pFunc->pCode[ ulPos + 2 ] * 256 ); - - if ( pSym && pSym->szName ) - pDeclared = hb_compDeclaredFind( pSym->szName ); - - if ( pDeclared ) - { - pFunc->pStack[ pFunc->iStackIndex++ ] = pDeclared->cType; - - /* Storing, will be checked by FUNCTION* */ - hb_comp_cParamTypes = pDeclared->cParamTypes; - hb_comp_iParamCount = pDeclared->iParamCount; - } - else + /* In Private or Public statement can't be a declared function */ + if( ( hb_comp_iVarScope == VS_PRIVATE || hb_comp_iVarScope == VS_PUBLIC ) ) pFunc->pStack[ pFunc->iStackIndex++ ] = ' '; + else + { + pSym = hb_compSymbolGetPos( pFunc->pCode[ ulPos + 1 ] + pFunc->pCode[ ulPos + 2 ] * 256 ); + if ( pSym && pSym->szName ) + pDeclared = hb_compDeclaredFind( pSym->szName ); + + if ( pDeclared ) + { + pFunc->pStack[ pFunc->iStackIndex++ ] = pDeclared->cType; + + /* Storing, will be checked by FUNCTION* */ + hb_comp_cParamTypes = pDeclared->cParamTypes; + hb_comp_iParamCount = pDeclared->iParamCount; + } + else + pFunc->pStack[ pFunc->iStackIndex++ ] = ' '; + } break; case HB_P_PUSHSYMNEAR : - pSym = hb_compSymbolGetPos( pFunc->pCode[ ulPos + 1 ] ); - - if ( pSym && pSym->szName ) - pDeclared = hb_compDeclaredFind( pSym->szName ); - - if ( pDeclared ) - { - pFunc->pStack[ pFunc->iStackIndex++ ] = pDeclared->cType; - - /* Storing, will be checked by FUNCTION* */ - hb_comp_cParamTypes = pDeclared->cParamTypes; - hb_comp_iParamCount = pDeclared->iParamCount; - } + /* In Private or Public statement can't be a declared function */ + if( ( hb_comp_iVarScope == VS_PRIVATE || hb_comp_iVarScope == VS_PUBLIC ) ) + pFunc->pStack[ pFunc->iStackIndex++ ] = ' '; else - pFunc->pStack[ pFunc->iStackIndex++ ] = ' '; + { + pSym = hb_compSymbolGetPos( pFunc->pCode[ ulPos + 1 ] ); + if ( pSym && pSym->szName ) + pDeclared = hb_compDeclaredFind( pSym->szName ); + + if ( pDeclared ) + { + pFunc->pStack[ pFunc->iStackIndex++ ] = pDeclared->cType; + + /* Storing, will be checked by FUNCTION* */ + hb_comp_cParamTypes = pDeclared->cParamTypes; + hb_comp_iParamCount = pDeclared->iParamCount; + } + else + pFunc->pStack[ pFunc->iStackIndex++ ] = ' '; + } break; /* Local Variables */ @@ -776,8 +786,22 @@ void hb_compStrongType( int iSize ) break; case HB_P_ARRAYPUSH : - /* TODO: Deal with Array Elements. */ - pFunc->pStack[ pFunc->iStackIndex++ ] = ' '; + /* 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 ); + + /* TODO: allow declaration of the Array Elements Type. */ + + /* Now we have the array elent on the stack.*/ + pFunc->pStack[ pFunc->iStackIndex - 1 ] = ' '; break; /* Macros type unknown */ @@ -990,7 +1014,6 @@ void hb_compStrongType( int iSize ) /* TODO Error Message after finalizing all possible pcodes. */ break; - /* TODO: Deal with Array Elements. */ if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] == ' ' ) ; else if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] != 'A' ) diff --git a/harbour/tests/testwarn.prg b/harbour/tests/testwarn.prg index 93ea0cd839..0effdbe9f8 100644 --- a/harbour/tests/testwarn.prg +++ b/harbour/tests/testwarn.prg @@ -17,6 +17,23 @@ DECLARE FUNCTION seconds() AS NUM DECLARE FUNCTION int( n AS NUMERIC ) AS NUMERIC +DECLARE FUNCTION TEST AS NUMERIC + +PROC MAIN0() + PRIVATE OTHER, TEST AS CHAR + + Var1 := M->TEST + Var2 := Test() + + M->TEST := 1 + M->TEST := "incorrect warning" + test[ 1 ][ 2 ] := "incorrect warning" + +RETURN + +Function Test() +return .t. + Function Main() Local n As Numeric, lVar AS LOGICAL