From 30cc98a20d1741b633743de77c0f8ca42cd01891 Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Wed, 10 May 2000 10:13:16 +0000 Subject: [PATCH] 20000510-03:00 GMT-8 Ron Pinkas * include/hbcomp.h + Added new structures COMCLASS and COMMETHOD + Added new element pClass to structure VAR + Added: extern PCOMCLASS hb_compClassAdd( char * ); extern PCOMCLASS hb_compClassFind( char * ); extern PCOMMETHOD hb_compMethodAdd( PCOMCLASS pClass, char * ); extern PCOMMETHOD hb_compMethodFind( PCOMCLASS pClass, char * ); * source/compiler/harbour.c + Added: PCOMCLASS hb_compClassAdd( char * ); PCOMCLASS hb_compClassFind( char * ); PCOMMETHOD hb_compMethodAdd( PCOMCLASS pClass, char * ); PCOMMETHOD hb_compMethodFind( PCOMCLASS pClass, char * ); * Modified hb_compVariableAdd() to process params of declared class methods. * source/compiler/harbour.l + Added tokens CLASSMETHOD CLASSDATA and FROMCLASS * source/compiler/harbour.y + Added support for class declaration syntax: DECLARE CLASS ClassName HAS Method MethodName( ... ) As ... HAS Data PropertyName ... + Added support for declaration of Object of a sdeclared class sysntax: DECLARE oObjectVar AS Object FROM ClassName * source/compiler/hbpcode.c + Started support for object methods and properties type checking. * tests/testwarn.prg + Added code to demonstrate declarion of classes and objects of a declared class. --- harbour/ChangeLog | 34 +++++++ harbour/include/hbcomp.h | 40 +++++++- harbour/source/compiler/harbour.c | 147 +++++++++++++++++++++++++++--- harbour/source/compiler/harbour.l | 40 +++++--- harbour/source/compiler/harbour.y | 25 ++++- harbour/source/compiler/hbpcode.c | 81 +++++++++++++++- harbour/tests/testwarn.prg | 10 +- 7 files changed, 336 insertions(+), 41 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index a170a31037..ea80a88b4d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,37 @@ +20000510-03:00 GMT-8 Ron Pinkas + + * include/hbcomp.h + + Added new structures COMCLASS and COMMETHOD + + Added new element pClass to structure VAR + + Added: + extern PCOMCLASS hb_compClassAdd( char * ); + extern PCOMCLASS hb_compClassFind( char * ); + extern PCOMMETHOD hb_compMethodAdd( PCOMCLASS pClass, char * ); + extern PCOMMETHOD hb_compMethodFind( PCOMCLASS pClass, char * ); + + * source/compiler/harbour.c + + Added: + PCOMCLASS hb_compClassAdd( char * ); + PCOMCLASS hb_compClassFind( char * ); + PCOMMETHOD hb_compMethodAdd( PCOMCLASS pClass, char * ); + PCOMMETHOD hb_compMethodFind( PCOMCLASS pClass, char * ); + * Modified hb_compVariableAdd() to process params of declared class methods. + + * source/compiler/harbour.l + + Added tokens CLASSMETHOD CLASSDATA and FROMCLASS + + * source/compiler/harbour.y + + Added support for class declaration syntax: + DECLARE CLASS ClassName HAS Method MethodName( ... ) As ... HAS Data PropertyName ... + + Added support for declaration of Object of a sdeclared class sysntax: + DECLARE oObjectVar AS Object FROM ClassName + + * source/compiler/hbpcode.c + + Started support for object methods and properties type checking. + + * tests/testwarn.prg + + Added code to demonstrate declarion of classes and objects of a declared class. + 20000510-03:45 DST Paul Tucker * source/compiler/harbour.c change param 2 of hb_compFunctionNew() definition to BYTE diff --git a/harbour/include/hbcomp.h b/harbour/include/hbcomp.h index 1df5425a06..10b7c34157 100644 --- a/harbour/include/hbcomp.h +++ b/harbour/include/hbcomp.h @@ -84,14 +84,33 @@ typedef struct int iFiles; /* number of files currently opened */ } FILES; +/* Declared Method support structure */ +typedef struct _COMMETHOD +{ + char * szName; /* the name of the symbol */ + BYTE cType; + BYTE * cParamTypes; + USHORT iParamCount; + struct _COMMETHOD * pNext; /* pointer to the next declared function */ +} COMMETHOD, * PCOMMETHOD; + +/* Declared Class support structure */ +typedef struct _COMCLASS +{ + char * szName; /* the name of the symbol */ + PCOMMETHOD pMethod; /* Pointer to linked list of methods */ + struct _COMCLASS * pNext; /* pointer to the next declared function */ +} COMCLASS, * PCOMCLASS; + /* locals, static, public variables support */ typedef struct _VAR { - char * szName; /* variable name */ - char * szAlias; /* variable alias namespace */ - int iUsed; /* number of times used */ - BYTE cType; /* optional strong typing */ - struct _VAR * pNext; /* pointer to next defined variable */ + char * szName; /* variable name */ + char * szAlias; /* variable alias namespace */ + int iUsed; /* number of times used */ + BYTE cType; /* optional strong typing */ + PCOMCLASS pClass; + struct _VAR * pNext; /* pointer to next defined variable */ } VAR, * PVAR; /* pcode chunks bytes size */ @@ -218,6 +237,11 @@ extern PCOMSYMBOL hb_compSymbolGetPos( USHORT ); /* returns a symbol based on extern PCOMDECLARED hb_compDeclaredAdd( char * ); extern PCOMDECLARED hb_compDeclaredFind( char * ); +extern PCOMCLASS hb_compClassAdd( char * ); +extern PCOMCLASS hb_compClassFind( char * ); +extern PCOMMETHOD hb_compMethodAdd( PCOMCLASS pClass, char * ); +extern PCOMMETHOD hb_compMethodFind( PCOMCLASS pClass, char * ); + extern void hb_compGenBreak( void ); /* generate code for BREAK statement */ extern void hb_compExternGen( void ); /* generates the symbols for the EXTERN names */ @@ -335,6 +359,10 @@ extern FUNCTIONS hb_comp_funcalls; extern SYMBOLS hb_comp_symbols; extern PCOMDECLARED hb_comp_pFirstDeclared; extern PCOMDECLARED hb_comp_pLastDeclared; +extern PCOMCLASS hb_comp_pFirstClass; +extern PCOMCLASS hb_comp_pLastClass; +extern char * hb_comp_szClass; +extern PCOMMETHOD hb_comp_pLastMethod; extern PATHNAMES * hb_comp_pIncludePath; extern PFUNCTION hb_comp_pInitFunc; extern PHB_FNAME hb_comp_pFileName; @@ -379,6 +407,8 @@ extern USHORT hb_comp_wCaseCounter; extern BOOL hb_comp_EOL; extern char * hb_comp_szDeclaredFun; +extern char * hb_comp_szLastMethod; + extern char * hb_comp_szErrors[]; extern char * hb_comp_szWarnings[]; diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index a49531accf..75f8f89667 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -84,6 +84,11 @@ SYMBOLS hb_comp_symbols; PCOMDECLARED hb_comp_pFirstDeclared; PCOMDECLARED hb_comp_pLastDeclared; +PCOMCLASS hb_comp_pFirstClass; +PCOMCLASS hb_comp_pLastClass; +char * hb_comp_szClass; +PCOMMETHOD hb_comp_pLastMethod; + int hb_comp_iLine; /* currently processed line number */ PFUNCTION hb_comp_pInitFunc; PHB_FNAME hb_comp_pFileName = NULL; @@ -473,21 +478,32 @@ void hb_compVariableAdd( char * szVarName, BYTE cValueType ) else pDeclared->cParamTypes = ( BYTE * ) hb_xgrab( 1 ); - /* Store declared type of this parameter into the parameters type list. */ - /* - if ( cValueType == '-' ) - // Optional parameter - pDeclared->cParamTypes[ pDeclared->iParamCount - 1 ] = hb_comp_cVarType + 100; - else - pDeclared->cParamTypes[ pDeclared->iParamCount - 1 ] = hb_comp_cVarType; - */ - pDeclared->cParamTypes[ pDeclared->iParamCount - 1 ] = cValueType; return; } } } + /* Dummy Var - Parameter Declaration of Declared Method. */ + else if ( hb_comp_pLastMethod ) + { + /* Nothing to do since no warnings requested.*/ + if ( hb_comp_iWarnings < 3 ) + return; + + //printf( "\nAdding parameter: %s Type: %c\n", szVarName, cValueType ); + + hb_comp_pLastMethod->iParamCount++; + + if ( hb_comp_pLastMethod->cParamTypes ) + hb_comp_pLastMethod->cParamTypes = ( BYTE * ) hb_xrealloc( hb_comp_pLastMethod->cParamTypes, hb_comp_pLastMethod->iParamCount ); + else + hb_comp_pLastMethod->cParamTypes = ( BYTE * ) hb_xgrab( 1 ); + + hb_comp_pLastMethod->cParamTypes[ hb_comp_pLastMethod->iParamCount - 1 ] = cValueType; + + return; + } HB_SYMBOL_UNUSED( cValueType ); @@ -529,13 +545,15 @@ void hb_compVariableAdd( char * szVarName, BYTE cValueType ) pVar = ( PVAR ) hb_xgrab( sizeof( VAR ) ); pVar->szName = szVarName; pVar->szAlias = NULL; - pVar->cType = hb_comp_cVarType; + pVar->cType = cValueType; pVar->iUsed = VU_NOT_USED; pVar->pNext = NULL; - /* Correct Type was previously stored in the CodeBlock. */ - if( ! pFunc->szName ) - pVar->cType = cValueType; + if ( cValueType == '+' ) + { + //printf( "\nVariable %s is of Class: %s\n", szVarName, hb_comp_szClass ); + pVar->pClass = hb_compClassFind( hb_comp_szClass ); + } if ( hb_comp_iVarScope & VS_PARAMETER ) pVar->iUsed = VU_INITIALIZED; @@ -778,6 +796,108 @@ BOOL hb_compVariableMacroCheck( char * szVarName ) return bValid; } +PCOMCLASS hb_compClassAdd( char * szClassName ) +{ + PCOMCLASS pClass; + + printf( "\nDeclaring Class: %s\n", szClassName ); + + if ( hb_comp_iWarnings < 3 ) + return NULL; + + if ( ( pClass = hb_compClassFind( szClassName ) ) != NULL ) + { + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_DUP_DECLARATION, szClassName, NULL ); + return pClass; + } + + pClass = ( PCOMCLASS ) hb_xgrab( sizeof( COMCLASS ) ); + + pClass->szName = szClassName; + pClass->pMethod = NULL; + pClass->pNext = NULL; + + if ( hb_comp_pFirstClass == NULL ) + hb_comp_pFirstClass = pClass; + else + hb_comp_pLastClass->pNext = pClass; + + hb_comp_pLastClass = pClass; + + return pClass; +} + +PCOMCLASS hb_compClassFind( char * szClassName ) +{ + PCOMCLASS pClass = hb_comp_pFirstClass; + + while( pClass ) + { + if( ! strcmp( pClass->szName, szClassName ) ) + return pClass; + else + { + if( pClass->pNext ) + pClass = pClass->pNext; + else + return NULL; + } + } + return NULL; +} + +PCOMMETHOD hb_compMethodAdd( PCOMCLASS pClass, char * szMethodName ) +{ + PCOMMETHOD pMethod; + + //printf( "\nDeclaring Method: %s of Class: %s\n", szMethodName, pClass->szName ); + + if ( hb_comp_iWarnings < 3 ) + return NULL; + + if ( ( pMethod = hb_compMethodFind( pClass, szMethodName ) ) != NULL ) + { + hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_DUP_DECLARATION, szMethodName, NULL ); + return pMethod; + } + + pMethod = ( PCOMMETHOD ) hb_xgrab( sizeof( COMMETHOD ) ); + + pMethod->szName = szMethodName; + pMethod->cType = ' '; // Not known yet + pMethod->cParamTypes = NULL; + pMethod->iParamCount = 0; + pMethod->pNext = NULL; + + if ( pClass->pMethod == NULL ) + pClass->pMethod = pMethod; + else + pClass->pMethod->pNext = pMethod; + + hb_comp_pLastMethod = pMethod; + + return pMethod; +} + +PCOMMETHOD hb_compMethodFind( PCOMCLASS pClass, char * szMethodName ) +{ + PCOMMETHOD pMethod = pClass->pMethod; + + while( pMethod ) + { + if( ! strcmp( pMethod->szName, szMethodName ) ) + return pMethod; + else + { + if( pMethod->pNext ) + pMethod = pMethod->pNext; + else + return NULL; + } + } + return NULL; +} + PCOMDECLARED hb_compDeclaredAdd( char * szDeclaredName ) { PCOMDECLARED pDeclared; @@ -799,7 +919,6 @@ PCOMDECLARED hb_compDeclaredAdd( char * szDeclaredName ) pDeclared->iParamCount = 0; pDeclared->pNext = NULL; - /* First Declare */ if ( hb_comp_pFirstDeclared == NULL ) hb_comp_pFirstDeclared = pDeclared; diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index ea1c239430..ff98ef1f19 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -113,7 +113,7 @@ Separator {SpaceTab} %x FOR_ FUNCTION_ IIF_ IF_ IN_ INIT_ LOCAL_ LOOP_ %x MEMVAR_ PARAM_ PRIVATE_ PUBLIC_ STATIC_ RETURN_ RECOVER_ %x INVALIDNUM_ OTHERWISE_ PROCEDURE_ -%x OPTIONAL_ +%x OPTIONAL_ FROMCLASS_ %s INDEX %% @@ -357,6 +357,7 @@ Separator {SpaceTab} %{ /* ************************************************************************ */ %} + "optional" { BEGIN OPTIONAL_; } {Separator}+[_a-zA-Z\&] { unput( yytext[ yyleng-1 ] ); BEGIN 0; return OPTIONAL; } {Separator}*(.|\n) { /* end of line or any operator */ @@ -367,6 +368,16 @@ Separator {SpaceTab} return IDENTIFIER; } +"from" { BEGIN FROMCLASS_; } +{Separator}+[_a-zA-Z\&] { unput( yytext[ yyleng-1 ] ); BEGIN 0; return FROMCLASS; } +{Separator}*(.|\n) { /* end of line or any operator */ + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; + unput( yytext[ yyleng-1 ] ); + yylval.string = hb_strdup( "FROM" ); + hb_comp_iState = IDENTIFIER; + return IDENTIFIER; + } + "do" BEGIN DO_; {Separator}+"case" { /* DO CASE statement */ if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; @@ -1308,37 +1319,40 @@ Separator {SpaceTab} } } -"as num" { return AS_NUMERIC; } -"as numeric" { return AS_NUMERIC; } +"as array" { return AS_ARRAY; } +"as block" { return AS_BLOCK; } "as char" { return AS_CHARACTER; } "as character" { return AS_CHARACTER; } "as string" { return AS_CHARACTER; } +"as date" { return AS_DATE; } "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 num" { return AS_NUMERIC; } +"as numeric" { return AS_NUMERIC; } "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 var array" { return AS_ARRAY; } +"as variant array" { return AS_ARRAY; } +"as array array" { return AS_ARRAY_ARRAY; } +"as block array" { return AS_BLOCK_ARRAY; } "as char array" { return AS_CHARACTER_ARRAY; } "as character array" { return AS_CHARACTER_ARRAY; } "as string array" { return AS_CHARACTER_ARRAY; } +"as date array" { return AS_DATE_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 num array" { return AS_NUMERIC_ARRAY; } +"as numeric array" { return AS_NUMERIC_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; } +"declare class" { return DECLARE_CLASS; } +"has method" { return CLASS_METHOD; } +"has data" { return CLASS_DATA; } %{ /* ************************************************************************ */ diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index 1afcf10ddf..fe1f6feaad 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -161,8 +161,9 @@ 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 AS_VARIANT DECLARE_FUN OPTIONAL -%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 +%token AS_ARRAY AS_BLOCK AS_CHARACTER AS_DATE AS_LOGICAL AS_NUMERIC AS_OBJECT AS_VARIANT DECLARE_FUN OPTIONAL +%token AS_ARRAY_ARRAY AS_BLOCK_ARRAY AS_CHARACTER_ARRAY AS_DATE_ARRAY AS_LOGICAL_ARRAY AS_NUMERIC_ARRAY AS_OBJECT_ARRAY +%token DECLARE_CLASS CLASS_METHOD CLASS_DATA FROMCLASS /*the lowest precedence*/ /*postincrement and postdecrement*/ @@ -265,8 +266,25 @@ Function : FunScope FUNCTION IdentName { hb_comp_cVarType = ' '; hb_compFunct hb_comp_pLastDeclared->cType = hb_comp_cVarType; hb_comp_szDeclaredFun = NULL; hb_comp_cVarType = ' '; } + | DECLARE_CLASS IdentName { hb_comp_pLastClass = hb_compClassAdd( $2 ); } ClassInfo Crlf {} ; +ClassInfo : DecMethod + | ClassInfo DecMethod + | DecData + | ClassInfo DecData + ; + +DecMethod : CLASS_METHOD IdentName { hb_comp_pLastMethod = hb_compMethodAdd( hb_comp_pLastClass, $2 ); } DecParams AsType { hb_comp_pLastMethod->cType = hb_comp_cVarType; + hb_comp_pLastMethod = NULL; + hb_comp_cVarType = ' '; } + ; + +DecData : CLASS_DATA IdentName { hb_comp_pLastMethod = hb_compMethodAdd( hb_comp_pLastClass, $2 ); } AsType { hb_comp_pLastMethod->cType = hb_comp_cVarType; + hb_comp_pLastMethod = NULL; + hb_comp_cVarType = ' '; } + ; + FunScope : { $$ = HB_FS_PUBLIC; } | STATIC { $$ = HB_FS_STATIC; } | INIT { $$ = HB_FS_INIT; } @@ -308,6 +326,7 @@ 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_OBJECT FROMCLASS IdentName { hb_comp_cVarType = '+'; hb_comp_szClass = $3 } | AS_VARIANT { hb_comp_cVarType = ' '; } | AS_NUMERIC_ARRAY { hb_comp_cVarType = 'n'; } | AS_CHARACTER_ARRAY { hb_comp_cVarType = 'c'; } @@ -316,7 +335,6 @@ AsType : /* not specified */ { hb_comp_cVarType = ' '; } | 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'; } @@ -327,7 +345,6 @@ AsArray : AS_ARRAY { hb_comp_cVarType = 'A'; } | 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, hb_comp_cVarType ); $$ = 1; } diff --git a/harbour/source/compiler/hbpcode.c b/harbour/source/compiler/hbpcode.c index 4101f8d34c..6ed89d97da 100644 --- a/harbour/source/compiler/hbpcode.c +++ b/harbour/source/compiler/hbpcode.c @@ -171,8 +171,10 @@ static BYTE s_pcode_len[] = { 1 /* HB_P_ONE, */ }; -static BYTE * hb_comp_cParamTypes = NULL; -static int hb_comp_iParamCount = -1; +static BYTE * hb_comp_cParamTypes = NULL; +static int hb_comp_iParamCount = -1; +static PCOMCLASS hb_comp_pStackClass[8]; +static int hb_comp_iClasses; static PVAR hb_compPrivateFind( char * szPrivateName ) { @@ -385,6 +387,8 @@ void hb_compStrongType( int iSize ) if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] == 'O' ) ; + else if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] == '+' ) + ; else if ( pFunc->pStack[ pFunc->iStackIndex - 1 ] == ' ' ) hb_compGenWarning( hb_comp_szWarnings, 'W', HB_COMP_WARN_OPERAND_SUSPECT, "O", NULL ); else @@ -398,7 +402,17 @@ void hb_compStrongType( int iSize ) /* Handles by HB_P_MESSAGE. */ case HB_P_SENDSHORT : + wVar = ( SHORT ) pFunc->pCode[ ulPos + 1 ]; + + /* Fall Through - don't add break !!! */ + case HB_P_SEND : + if ( wVar == 0 ) + wVar = * ( ( SHORT * ) &( pFunc->pCode )[ ulPos + 1 ] ); + + if ( pFunc->pStack[ pFunc->iStackIndex - ( wVar + 1 ) ] == '+' ) + { + } break; case HB_P_DEC : @@ -889,6 +903,8 @@ void hb_compStrongType( int iSize ) /* Objects */ case HB_P_PUSHSELF : pFunc->pStack[ pFunc->iStackIndex++ ] = 'O'; + + /* Todo find Self's Class. */ break; /* Blcoks */ @@ -1010,7 +1026,13 @@ void hb_compStrongType( int iSize ) /* Mark as used */ pVar->iUsed |= VU_USED; - if ( pFunc->pCode[ ulPos ] == HB_P_PUSHLOCALREF ) + if ( pVar->cType == '+' ) + { + /* Object of declared class */ + hb_comp_pStackClass[ hb_comp_iClasses++ ] = pVar->pClass; + pFunc->pStack[ pFunc->iStackIndex++ ] = '+'; + } + else if ( pFunc->pCode[ ulPos ] == HB_P_PUSHLOCALREF ) pFunc->pStack[ pFunc->iStackIndex++ ] = pVar->cType + VT_OFFSET_BYREF; else pFunc->pStack[ pFunc->iStackIndex++ ] = pVar->cType; @@ -1046,6 +1068,12 @@ void hb_compStrongType( int iSize ) /* Mark as used */ pVar->iUsed |= VU_USED; + if ( pVar->cType == '+' ) + { + /* Object of declared class */ + hb_comp_pStackClass[ hb_comp_iClasses++ ] = pVar->pClass; + pFunc->pStack[ pFunc->iStackIndex++ ] = '+'; + } if ( pFunc->pCode[ ulPos ] == HB_P_PUSHSTATICREF ) pFunc->pStack[ pFunc->iStackIndex++ ] = pVar->cType + VT_OFFSET_BYREF; else @@ -1128,7 +1156,13 @@ void hb_compStrongType( int iSize ) /* Mark as used */ pVar->iUsed |= VU_USED; - if ( pFunc->pCode[ ulPos ] == HB_P_PUSHMEMVARREF ) + if ( pVar->cType == '+' ) + { + /* Object of declared class */ + hb_comp_pStackClass[ hb_comp_iClasses++ ] = pVar->pClass; + pFunc->pStack[ pFunc->iStackIndex++ ] = '+'; + } + else if ( pFunc->pCode[ ulPos ] == HB_P_PUSHMEMVARREF ) pFunc->pStack[ pFunc->iStackIndex - 1 ] = pVar->cType + VT_OFFSET_BYREF; else pFunc->pStack[ pFunc->iStackIndex - 1 ] = pVar->cType; @@ -1322,11 +1356,25 @@ void hb_compStrongType( int iSize ) case HB_P_POPVARIABLE : pFunc->iStackIndex--; + + if ( pFunc->pStack[ pFunc->iStackIndex ] == '+' ) + { + /* Object of declared class */ + hb_comp_pStackClass[ --hb_comp_iClasses ] = NULL; + } + break; case HB_P_POPALIASEDVAR : /* TODO: check what is aliasedvar? */ pFunc->iStackIndex--; + + if ( pFunc->pStack[ pFunc->iStackIndex ] == '+' ) + { + /* Object of declared class */ + hb_comp_pStackClass[ --hb_comp_iClasses ] = NULL; + } + break; case HB_P_POPALIASEDFIELDNEAR : @@ -1336,6 +1384,8 @@ void hb_compStrongType( int iSize ) pSym = hb_compSymbolGetPos( wVar ); } + /* Fall through, don't put break!!!*/ + case HB_P_POPALIASEDFIELD : case HB_P_POPFIELD : if ( pFunc->pCode[ ulPos ] == HB_P_POPFIELD || pFunc->pCode[ ulPos ] == HB_P_POPALIASEDFIELD ) @@ -1360,6 +1410,8 @@ void hb_compStrongType( int iSize ) pVar = hb_compVariableFind( hb_comp_functions.pFirst->pFields, wVar ); } + /* Fall through, don't put break!!!*/ + case HB_P_POPMEMVAR : pFunc->iStackIndex--; @@ -1367,6 +1419,13 @@ void hb_compStrongType( int iSize ) /* TODO Error Message after finalizing all possible pcodes. */ break; + if ( pFunc->pStack[ pFunc->iStackIndex ] == '+' ) + { + /* Object of declared class */ + hb_comp_pStackClass[ --hb_comp_iClasses ] = NULL; + pFunc->pStack[ pFunc->iStackIndex ] = 'O'; + } + if ( pFunc->pCode[ ulPos ] == HB_P_POPMEMVAR ) wVar = pFunc->pCode[ ulPos + 1 ] + pFunc->pCode[ ulPos + 2 ] * 256; @@ -1490,6 +1549,13 @@ void hb_compStrongType( int iSize ) /* TODO Error Message after finalizing all possible pcodes. */ break; + if ( pFunc->pStack[ pFunc->iStackIndex ] == '+' ) + { + /* Object of declared class */ + hb_comp_pStackClass[ --hb_comp_iClasses ] = NULL; + pFunc->pStack[ pFunc->iStackIndex ] = 'O'; + } + if ( pFunc->pCode[ ulPos ] == HB_P_POPLOCAL ) wVar = * ( ( SHORT * ) &( pFunc->pCode )[ ulPos + 1 ] ); else @@ -1552,6 +1618,13 @@ void hb_compStrongType( int iSize ) /* TODO Error Message after finalizing all possible pcodes. */ break; + if ( pFunc->pStack[ pFunc->iStackIndex ] == '+' ) + { + /* Object of declared class */ + hb_comp_pStackClass[ --hb_comp_iClasses ] = NULL; + pFunc->pStack[ pFunc->iStackIndex ] = 'O'; + } + pTmp = hb_comp_functions.pFirst; wVar = pFunc->pCode[ ulPos + 1 ] + pFunc->pCode[ ulPos + 2 ] * 256; diff --git a/harbour/tests/testwarn.prg b/harbour/tests/testwarn.prg index 0db02f5ac8..4dcb92b99a 100644 --- a/harbour/tests/testwarn.prg +++ b/harbour/tests/testwarn.prg @@ -61,6 +61,12 @@ DECLARE FUNCTION int( n AS NUMERIC ) AS NUMERIC DECLARE FUNCTION TEST AS NUMERIC +DECLARE CLASS MyClass ; + Has METHOD nMyFunc( nVal As Num ) As Num ; + Has METHOD nMyFunc( nVal As Num ) As Num ; + Has Data cMyData ; + Has Method FinalMethod + FIELD a AS CHAR FIELD b AS CHAR @@ -70,9 +76,11 @@ STATIC lGlobal AS LOGICAL PROCEDURE THEMAIN( optional ) - STATIC lStatic := 0 + STATIC lStatic := 0, oMyObj As Object From MyClass LOCAL cVar AS CHAR := [declare function] + oMyObj:MyMethod( 2, 3, 4 ) + FIELD b AS NUM USE TEMP