From 065a119f5190c27e1f4da60aaed3df37ffb82dcc Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Fri, 12 Dec 2008 17:04:16 +0000 Subject: [PATCH] 2008-12-12 18:06 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbapicls.h * harbour/source/vm/codebloc.c * harbour/source/vm/proc.c * harbour/source/vm/classes.c + added support for messages in PROCFILE() * modified PROCFILE() and HB_METHODNAME() output - PROCFILE() should be fully Clipper compatible and HB_METHODNAME() works in a little bit different way for evaluated codeblocks created in methods or associated with method and returns (b): instead of (b) so the output is more similar to xHarbour. * harbour/contrib/gtwvg/gtwvg.h ! disabled NONAMELESSUNION - wvgwin.c uses TVINSERTSTRUCT item member without union name what breaks MINGW compilation * added hardcoded TVIS_EXPANDPARTIAL when it does not exist in header files - MINGW 3.4 does not have it. --- harbour/ChangeLog | 18 ++++++++++++ harbour/contrib/gtwvg/gtwvg.h | 6 +++- harbour/include/hbapicls.h | 4 ++- harbour/source/vm/classes.c | 53 +++++++++++++++++++++++++++++------ harbour/source/vm/codebloc.c | 12 ++++++-- harbour/source/vm/proc.c | 24 ++++++++++++---- 6 files changed, 98 insertions(+), 19 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 8ee47ef21a..1042a1892d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,24 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-12-12 18:06 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbapicls.h + * harbour/source/vm/codebloc.c + * harbour/source/vm/proc.c + * harbour/source/vm/classes.c + + added support for messages in PROCFILE() + * modified PROCFILE() and HB_METHODNAME() output - PROCFILE() + should be fully Clipper compatible and HB_METHODNAME() works + in a little bit different way for evaluated codeblocks created + in methods or associated with method and returns (b): + instead of (b) so the output is more similar to xHarbour. + + * harbour/contrib/gtwvg/gtwvg.h + ! disabled NONAMELESSUNION - wvgwin.c uses TVINSERTSTRUCT item + member without union name what breaks MINGW compilation + * added hardcoded TVIS_EXPANDPARTIAL when it does not exist + in header files - MINGW 3.4 does not have it. + 2008-12-11 19:48 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbthread.h * harbour/source/vm/thread.c diff --git a/harbour/contrib/gtwvg/gtwvg.h b/harbour/contrib/gtwvg/gtwvg.h index 6d73fcea82..535dfe7e63 100644 --- a/harbour/contrib/gtwvg/gtwvg.h +++ b/harbour/contrib/gtwvg/gtwvg.h @@ -66,7 +66,7 @@ #define CINTERFACE 1 #endif -#define NONAMELESSUNION +/* #define NONAMELESSUNION */ //-------------------------------------------------------------------// @@ -447,6 +447,10 @@ typedef struct #define GCLP_HCURSOR (-12) #endif +#ifndef TVIS_EXPANDPARTIAL + #define TVIS_EXPANDPARTIAL 0x0080 +#endif + //----------------------------------------------------------------------// typedef enum diff --git a/harbour/include/hbapicls.h b/harbour/include/hbapicls.h index 0e5eb13f53..822f8555e8 100644 --- a/harbour/include/hbapicls.h +++ b/harbour/include/hbapicls.h @@ -95,6 +95,7 @@ extern void hb_clsDoInit( void ); /* initialize Classy/OO system . extern void hb_clsReleaseAll( void ); /* releases all defined classes */ extern void hb_clsIsClassRef( void ); /* classes.c - mark all class internals as used */ extern BOOL hb_clsHasDestructor( USHORT uiClass ); +extern PHB_SYMB hb_clsMethodSym( PHB_ITEM pBaseSymbol ); /* returns the real method symbol for given stack symbol */ extern PHB_SYMB hb_objGetMethod( PHB_ITEM pObject, PHB_SYMB pSymMsg, PHB_STACK_STATE pStack ); /* returns the method pointer of an object class */ extern BOOL hb_objGetVarRef( PHB_ITEM pObject, PHB_SYMB pMessage, PHB_STACK_STATE pStack ); /* create object variable reference */ @@ -107,11 +108,12 @@ extern void hb_objDestructorCall( PHB_ITEM pObject ); extern void hb_mthAddTime( ULONG ); /* profiler from classes.c */ #endif -#endif +#endif /* _HB_API_INTERNAL_ */ /* class management */ HB_EXPORT extern const char * hb_clsName( USHORT uiClass ); HB_EXPORT extern const char * hb_clsFuncName( USHORT uiClass ); +HB_EXPORT extern const char * hb_clsMethodName( USHORT uiClass, USHORT uiMethod ); HB_EXPORT extern BOOL hb_clsIsParent( USHORT uiClass, const char * szParentName ); /* is a class handle inherited from szParentName Class ? */ HB_EXPORT extern USHORT hb_clsFindClass( const char * szClass, const char * szFunc ); diff --git a/harbour/source/vm/classes.c b/harbour/source/vm/classes.c index 8e59e074e0..d876f35dac 100644 --- a/harbour/source/vm/classes.c +++ b/harbour/source/vm/classes.c @@ -1378,6 +1378,18 @@ const char * hb_clsFuncName( USHORT uiClass ) return NULL; } +const char * hb_clsMethodName( USHORT uiClass, USHORT uiMethod ) +{ + if( uiClass && uiClass <= s_uiClasses && + uiMethod < hb_clsMthNum( s_pClasses[ uiClass ] ) ) + { + PMETHOD pMethod = s_pClasses[ uiClass ]->pMethods + uiMethod; + if( pMethod->pMessage ) + return pMethod->pMessage->pSymbol->szName; + } + return NULL; +} + USHORT hb_clsFindClass( const char * szClass, const char * szFunc ) { USHORT uiClass; @@ -1408,6 +1420,32 @@ static USHORT hb_clsFindClassByFunc( PHB_SYMB pClassFuncSym ) return 0; } +/* + * Get the real method symbol for given stack symbol + */ +PHB_SYMB hb_clsMethodSym( PHB_ITEM pBaseSymbol ) +{ + PHB_STACK_STATE pStack = pBaseSymbol->item.asSymbol.stackstate; + + if( pStack->uiClass ) + { + PMETHOD pMethod = s_pClasses[ pStack->uiClass ]->pMethods + pStack->uiMethod; + + if( pMethod->pFuncSym == &s___msgEvalInline ) + return hb_arrayGetItemPtr( s_pClasses[ pMethod->uiSprClass ]->pInlines, + pMethod->uiData )->item.asBlock.value->pDefSymb; +/* + else if( pMethod->pFuncSym == &s___msgPerform ) +*/ + else if( pMethod->pFuncSym == &s___msgDelegate ) + return s_pClasses[ pStack->uiClass ]->pMethods[ pMethod->uiData ].pFuncSym; + else + return pMethod->pFuncSym; + } + + return pBaseSymbol->item.asSymbol.value; +} + /* * Get the real class name of an object message * Will return the class name from wich the message is inherited in case @@ -4509,17 +4547,14 @@ void hb_mthAddTime( ULONG ulClockTicks ) { PHB_ITEM pObject = hb_stackSelfItem(); PCLASS pClass = s_pClasses[ hb_objGetClassH( pObject ) ]; + USHORT uiMethod = hb_stackBaseItem()->item.asSymbol.stackstate->uiMethod; - if( pClass ) + if( pClass && uiMethod < hb_clsMthNum( pClass ) ) { - PMETHOD pMethod = pClass->pMethods; - if( pMethod ) - { - pMethod += hb_stackBaseItem()->item.asSymbol.stackstate->uiMethod; - pMethod->ulCalls++; - pMethod->ulTime += ulClockTicks; - return; - } + PMETHOD pMethod = pClass->pMethods + uiMethod; + pMethod->ulCalls++; + pMethod->ulTime += ulClockTicks; + return; } if( HB_IS_BLOCK( pObject ) ) diff --git a/harbour/source/vm/codebloc.c b/harbour/source/vm/codebloc.c index 983146394a..26730ebb6a 100644 --- a/harbour/source/vm/codebloc.c +++ b/harbour/source/vm/codebloc.c @@ -55,6 +55,7 @@ #include "hbvmopt.h" #include "hbapi.h" #include "hbapiitm.h" +#include "hbapicls.h" #include "hbvm.h" #include "hbstack.h" #include "hbpcode.h" @@ -121,7 +122,7 @@ HB_CODEBLOCK_PTR hb_codeblockNew( const BYTE * pBuffer, ULONG ulLen ) { HB_CODEBLOCK_PTR pCBlock; - PHB_ITEM pLocals; + PHB_ITEM pLocals, pBase; BYTE * pCode; HB_TRACE(HB_TR_DEBUG, ("hb_codeblockNew(%p, %hu, %p, %p, %lu)", pBuffer, uiLocals, pLocalPosTable, pSymbols, ulLen)); @@ -212,11 +213,13 @@ HB_CODEBLOCK_PTR hb_codeblockNew( const BYTE * pBuffer, pLocals = NULL; } + pBase = hb_stackBaseItem(); pCBlock = ( HB_CODEBLOCK_PTR ) hb_gcAlloc( sizeof( HB_CODEBLOCK ), hb_codeblockDeleteGarbage ); pCBlock->pCode = pCode; pCBlock->dynBuffer = ulLen != 0; - pCBlock->pDefSymb = hb_stackBaseItem()->item.asSymbol.value; + pCBlock->pDefSymb = pBase->item.asSymbol.stackstate->uiClass ? + hb_clsMethodSym( pBase ) : pBase->item.asSymbol.value; pCBlock->pSymbols = pSymbols; pCBlock->lStatics = hb_stackGetStaticsBase(); pCBlock->uiLocals = uiLocals; @@ -230,6 +233,7 @@ HB_CODEBLOCK_PTR hb_codeblockNew( const BYTE * pBuffer, HB_CODEBLOCK_PTR hb_codeblockMacroNew( const BYTE * pBuffer, ULONG ulLen ) { HB_CODEBLOCK_PTR pCBlock; + PHB_ITEM pBase; BYTE * pCode; HB_TRACE(HB_TR_DEBUG, ("hb_codeblockMacroNew(%p, %lu)", pBuffer, ulLen)); @@ -248,10 +252,12 @@ HB_CODEBLOCK_PTR hb_codeblockMacroNew( const BYTE * pBuffer, ULONG ulLen ) memcpy( pCode, pBuffer, ulLen ); pCBlock = ( HB_CODEBLOCK_PTR ) hb_gcAlloc( sizeof( HB_CODEBLOCK ), hb_codeblockDeleteGarbage ); + pBase = hb_stackBaseItem(); /* Store the number of referenced local variables */ pCBlock->pCode = pCode; pCBlock->dynBuffer = TRUE; - pCBlock->pDefSymb = hb_stackBaseItem()->item.asSymbol.value; + pCBlock->pDefSymb = pBase->item.asSymbol.stackstate->uiClass ? + hb_clsMethodSym( pBase ) : pBase->item.asSymbol.value; pCBlock->pSymbols = NULL; /* macro-compiled codeblock cannot acces a local symbol table */ pCBlock->lStatics = hb_stackGetStaticsBase(); pCBlock->uiLocals = 0; diff --git a/harbour/source/vm/proc.c b/harbour/source/vm/proc.c index f10a9227fb..48cc86cc3b 100644 --- a/harbour/source/vm/proc.c +++ b/harbour/source/vm/proc.c @@ -124,18 +124,22 @@ HB_FUNC( PROCFILE ) if( lOffset > 0 ) { - pSym = hb_stackItem( lOffset )->item.asSymbol.value; + PHB_ITEM pBase = hb_stackItem( lOffset ); + pSym = pBase->item.asSymbol.value; if( pSym == &hb_symEval || pSym->pDynSym == hb_symEval.pDynSym ) { PHB_ITEM pSelf = hb_stackItem( lOffset + 1 ); if( HB_IS_BLOCK( pSelf ) ) pSym = pSelf->item.asBlock.value->pDefSymb; + else if( pBase->item.asSymbol.stackstate->uiClass ) + pSym = hb_clsMethodSym( pBase ); } + else if( pBase->item.asSymbol.stackstate->uiClass ) + pSym = hb_clsMethodSym( pBase ); } } - hb_retc( hb_vmFindModuleSymbolName( hb_vmGetRealFuncSym( pSym ) ) ); #else hb_retc( NULL ); @@ -179,8 +183,16 @@ char * hb_procname( int iLevel, char * szName, BOOL fMethodName ) pBase->item.asSymbol.value->pDynSym == hb_symEval.pDynSym ) { hb_strncat( szName, "(b)", HB_PROCBUF_LEN ); - - if( HB_IS_BLOCK( pSelf ) ) + /* it is a method name? */ + if( fMethodName && pBase->item.asSymbol.stackstate->uiClass ) + { + hb_strncat( szName, hb_clsName( pBase->item.asSymbol.stackstate->uiClass ), + HB_PROCBUF_LEN ); + hb_strncat( szName, ":", HB_PROCBUF_LEN ); + hb_strncat( szName, hb_clsMethodName( pBase->item.asSymbol.stackstate->uiClass, + pBase->item.asSymbol.stackstate->uiMethod ), HB_PROCBUF_LEN ); + } + else if( HB_IS_BLOCK( pSelf ) ) hb_strncat( szName, pSelf->item.asBlock.value->pDefSymb->szName, HB_PROCBUF_LEN ); else @@ -251,11 +263,13 @@ BOOL hb_procinfo( int iLevel, char * szName, USHORT * puiLine, char * szFile ) if( szFile ) { - char * szModule; + const char * szModule; if( HB_IS_BLOCK( pSelf ) && ( pSym == &hb_symEval || pSym->pDynSym == hb_symEval.pDynSym ) ) pSym = pSelf->item.asBlock.value->pDefSymb; + else if( pBase->item.asSymbol.stackstate->uiClass ) + pSym = hb_clsMethodSym( pBase ); szModule = hb_vmFindModuleSymbolName( hb_vmGetRealFuncSym( pSym ) );