20000501-01:0 GMT-8 Ron Pinkas <Ron@Profit-Master.com>
* 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\'"
This commit is contained in:
@@ -1,3 +1,35 @@
|
||||
20000501-01:0 GMT-8 Ron Pinkas <Ron@Profit-Master.com>
|
||||
|
||||
* 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 <Ron@Profit-Master.com>
|
||||
* 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 <Ron@Profit-Master.com>
|
||||
|
||||
@@ -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[];
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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++ ] = ' ';
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user