Delete method and inline added

This commit is contained in:
Eddie Runia
1999-05-13 11:45:29 +00:00
parent 71608d2469
commit 445b265edc
2 changed files with 102 additions and 25 deletions

View File

@@ -1,6 +1,14 @@
--- \source\tcpp\cvstest\harbour\source\rtl\classes.c Tue May 11 20:23:38 1999
+++ \source\tcpp\harb21-2\source\rtl\classes.c Thu May 13 10:52:36 1999
@@ -136,12 +136,22 @@
+++ \source\tcpp\harb21-2\source\rtl\classes.c Thu May 13 12:34:32 1999
@@ -10,6 +10,7 @@
void PushSymbol( PSYMBOL );
void Message( PSYMBOL );
void Do( WORD wParams );
+void ArrayDel( PITEM, WORD );
#define MET_METHOD 0
#define MET_DATA 1
@@ -136,12 +137,22 @@
static HARBOUR GetData( void )
{
@@ -25,7 +33,7 @@
}
static HARBOUR GetClassData( void )
@@ -503,6 +513,59 @@
@@ -503,6 +514,114 @@
else
{ /* TODO: Crash code */
}
@@ -40,7 +48,7 @@
+} /* number of DATAs */
+
+HARBOUR CLASSMOD() /* Modify message (only for INLINE and METHOD) */
+ /* <xOld> := ClassMod(<oObj>,<cSymbol>,<pFunction> */
+ /* <xOld> := ClassMod( <oObj>, <cSymbol>, <pFunc> ) */
+{
+ PITEM pString = _param( 2, IT_STRING );
+ PSYMBOL pMessage = GetDynSym( pString->value.szText )->pSymbol;
@@ -59,27 +67,82 @@
+ wAt = ( ( ( unsigned ) pMsg ) % pClass->wHashKey ) * BUCKET;
+ wLimit = wAt + BUCKET;
+
+ while( wAt < wLimit )
+ {
+ if( pClass->pMethods[ wAt ].pMessage == pMsg )
+ { /* Requested method found */
+ pFunc = pClass->pMethods[ wAt ].pFunction;
+ if( pFunc == EvalInline ) /* INLINE method changed */
+ {
+ ArraySet( &pClass->aInlines, pClass->pMethods[ wAt ].wData,
+ _param( 3, IT_BLOCK ) );
+ }
+ else if( ( pFunc == SetData ) || ( pFunc == GetData ) )
+ /* Not allowed for DATA */
+ {
+ printf( "Cannot modify a DATA item\n");
+ } /* TODO : Real error */
+ else /* Modify METHOD */
+ {
+ pClass->pMethods[ wAt ].pFunction = ( HARBOURFUNC ) _parnl( 3 );
+ }
+ }
+ while( ( wAt < wLimit ) &&
+ ( pClass->pMethods[ wAt ].pMessage &&
+ ( pClass->pMethods[ wAt ].pMessage != pMsg ) ) )
+ wAt++;
+
+ if( wAt <= wLimit )
+ { /* Requested method found */
+ pFunc = pClass->pMethods[ wAt ].pFunction;
+ if( pFunc == EvalInline ) /* INLINE method changed */
+ {
+ ArraySet( &pClass->aInlines, pClass->pMethods[ wAt ].wData,
+ _param( 3, IT_BLOCK ) );
+ }
+ else if( ( pFunc == SetData ) || ( pFunc == GetData ) )
+ { /* Not allowed for DATA */
+ printf( "\nCannot modify a DATA item" );
+ exit(1);
+ } /* TODO : Real error */
+ else /* Modify METHOD */
+ {
+ pClass->pMethods[ wAt ].pFunction = ( HARBOURFUNC ) _parnl( 3 );
+ }
+ }
+ }
+}
+
+HARBOUR CLASSDEL() /* Delete message (only for INLINE and METHOD) */
+ /* <xOld> := ClassDel( <oObj>, <cSymbol> ) */
+{
+ PITEM pString = _param( 2, IT_STRING );
+ PSYMBOL pMessage = GetDynSym( pString->value.szText )->pSymbol;
+ PDYNSYM pMsg = ( PDYNSYM ) pMessage->pDynSym;
+ PCLASS pClass;
+
+ WORD wClass = _parni( 1 );
+ WORD wAt;
+ WORD wLimit;
+
+ HARBOURFUNC pFunc;
+
+ if( wClass && wClass <= wClasses )
+ {
+ pClass = &pClasses[ wClass - 1 ];
+ wAt = ( ( ( unsigned ) pMsg ) % pClass->wHashKey ) * BUCKET;
+ wLimit = wAt + BUCKET;
+
+ while( ( wAt < wLimit ) &&
+ ( pClass->pMethods[ wAt ].pMessage &&
+ ( pClass->pMethods[ wAt ].pMessage != pMsg ) ) )
+ wAt++;
+
+ if( wAt <= wLimit )
+ { /* Requested method found */
+ pFunc = pClass->pMethods[ wAt ].pFunction;
+ if( pFunc == EvalInline ) /* INLINE method deleted */
+ {
+ ArrayDel( &pClass->aInlines, pClass->pMethods[ wAt ].wData );
+ /* Delete INLINE block */
+ }
+ else if( ( pFunc == SetData ) || ( pFunc == GetData ) )
+ { /* Not allowed for DATA */
+ printf( "\nCannot delete a DATA item yet" );
+ exit(1); /* TODO : Real error */
+ }
+ /* Move messages */
+ for( ; pClass->pMethods[ wAt ].pMessage && wAt < wLimit; wAt ++ )
+ memcpy( &( pClass->pMethods[ wAt ] ),
+ &( pClass->pMethods[ wAt + 1 ] ), sizeof( METHOD ) );
+
+ pClass->pMethods[ wAt ].pFunction = NULL;
+ pClass->pMethods[ wAt ].pMessage = NULL;
+ pClass->pMethods[ wAt ].wData = NULL;
+ pClass->pMethods[ wAt ].wScope = NULL;
+ pClass->pMethods[ wAt ].wInitValue = NULL;
+
+ pClass->wMethods--; /* Decrease number messages */
+ }
+ }
}

View File

@@ -84,7 +84,21 @@ function Main()
QOut( "What is the Form area ?" )
QOut( oForm:CalcArea() )
QOut( "Just one left : Delete" )
QOut( "What methods are in the class :" )
HBDebug( aoMethod( oForm ) )
QOut( "Delete CalcArea" )
ClassDel( oForm:ClassH, "CalcArea" )
QOut( "What methods are in the class :" )
HBDebug( aoMethod( oForm ) )
QOut( "Delete Smile" )
ClassDel( oForm:ClassH, "Smile" )
QOut( "What methods are in the class :" )
HBDebug( aoMethod( oForm ) )
return nil