From 15b51bbe0a5c6357fcd91c4de1642141c2734efd Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Thu, 28 Jan 2010 22:25:09 +0000 Subject: [PATCH] 2010-01-28 23:24 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/rdd/dbfcdx/dbfcdx1.c + enabled automatic template order setting in Harbour SIXCDX RDD using the same method as SIX3 SIXCDX RDD seems to use: by checking leading character of key expression for: "sxChar(", "sxDate(", "sxNum(" and "sxLog(" Warning: This code is enabled only for SIXCDX RDD and DBFCDX was not modified. * disabled RTE in SIXCDX when key add/del operation are executed for non custom indexes and * do not add keys with different type to template indexes in SIXCDX RDD for strict SIX3 compatibility. * harbour/doc/cmpopt.txt + added information about missing in Clipper expression optimization in LOCAL, PRIVATE and PUBLIC variable declaration. Clipper optimize only expressions used in STATIC declarations. --- harbour/ChangeLog | 18 +++++ harbour/doc/cmpopt.txt | 16 ++++ harbour/src/rdd/dbfcdx/dbfcdx1.c | 130 +++++++++++++++++++------------ 3 files changed, 116 insertions(+), 48 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 791df35c88..6072fa1584 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,24 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-01-28 23:24 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/src/rdd/dbfcdx/dbfcdx1.c + + enabled automatic template order setting in Harbour SIXCDX RDD using + the same method as SIX3 SIXCDX RDD seems to use: by checking leading + character of key expression for: "sxChar(", "sxDate(", "sxNum(" and + "sxLog(" + Warning: This code is enabled only for SIXCDX RDD and DBFCDX was not + modified. + * disabled RTE in SIXCDX when key add/del operation are executed + for non custom indexes and + * do not add keys with different type to template indexes in SIXCDX + RDD for strict SIX3 compatibility. + + * harbour/doc/cmpopt.txt + + added information about missing in Clipper expression optimization + in LOCAL, PRIVATE and PUBLIC variable declaration. Clipper optimize + only expressions used in STATIC declarations. + 2010-01-28 20:20 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * utils/hbmk2/hbmk2.prg + Added -env:- support to delete envvars completely. diff --git a/harbour/doc/cmpopt.txt b/harbour/doc/cmpopt.txt index 6bebe44e0d..f6322de300 100644 --- a/harbour/doc/cmpopt.txt +++ b/harbour/doc/cmpopt.txt @@ -183,6 +183,22 @@ Expressions fully optimized to constant values at compile time can be used to intialize static variables, f.e.: static s_var := ( 1 + 2 / 3 ) +Clipper does not optimize expression used in LOCAL, PRIVATE and +PUBLIC variables declarations but it optimize expressions for STATIC +declarations. This code illustrates it: + + proc main() + memvar v, p + local l := "" $ "" + static s := "" $ "" + private v := "" $ "" + public p := "" $ "" + ? l, s, v, p, "" $ "" + return + +This behavior is not replicated in Harbour even if -kc switch is used +and Harbour optimize expressions in all declarations. + Harbour has additional optimization phase which operates on generated PCODE. It can also reduce expressions, joins jumps, removes death or meaningless code which can appear after all other optimizations and were not optimized diff --git a/harbour/src/rdd/dbfcdx/dbfcdx1.c b/harbour/src/rdd/dbfcdx/dbfcdx1.c index 9c221a9c39..5e0db8b62a 100644 --- a/harbour/src/rdd/dbfcdx/dbfcdx1.c +++ b/harbour/src/rdd/dbfcdx/dbfcdx1.c @@ -3436,6 +3436,17 @@ static void hb_cdxTagHeaderStore( LPCDXTAG pTag ) hb_cdxIndexPageWrite( pTag->pIndex, pTag->TagBlock, (BYTE *) &tagHeader, sizeof( CDXTAGHEADER ) ); } +#if defined( HB_SIXCDX ) +static HB_BOOL hb_cdxIsTemplateFunc( const char * szKeyExpr ) +{ + /* For CDX format SIx3 really makes sth like that */ + return hb_strnicmp( szKeyExpr, "sxChar(", 7 ) == 0 || + hb_strnicmp( szKeyExpr, "sxDate(", 7 ) == 0 || + hb_strnicmp( szKeyExpr, "sxNum(", 6 ) == 0 || + hb_strnicmp( szKeyExpr, "sxLog(", 6 ) == 0; +} +#endif + /* * Read a tag definition from the index file */ @@ -3494,16 +3505,12 @@ static void hb_cdxTagLoad( LPCDXTAG pTag ) ( pTag->OptFlags & CDX_TYPE_TEMPORARY ) == 0; pTag->Partial = ( pTag->OptFlags & CDX_TYPE_CUSTOM ) != 0 || ( pTag->OptFlags & CDX_TYPE_TEMPORARY ) != 0; -#if 0 - /* For CDX format SIx3 really makes sth like that */ - pTag->Template = hb_strnicmp( pTag->KeyExpr, "sxChar(", 7 ) == 0 || - hb_strnicmp( pTag->KeyExpr, "sxDate(", 7 ) == 0 || - hb_strnicmp( pTag->KeyExpr, "sxNum(", 6 ) == 0 || - hb_strnicmp( pTag->KeyExpr, "sxLog(", 6 ) == 0 ) + + pTag->Template = hb_cdxIsTemplateFunc( pTag->KeyExpr ); + if( pTag->Template ) + pTag->Custom = HB_TRUE; /* SIx3 does not support repeated key value for the same record */ pTag->MultiKey = HB_FALSE; -#endif - pTag->Template = pTag->MultiKey = pTag->Custom; #else pTag->Temporary = ( pTag->OptFlags & CDX_TYPE_TEMPORARY ) != 0; pTag->Custom = ( pTag->OptFlags & CDX_TYPE_CUSTOM ) != 0; @@ -4547,7 +4554,16 @@ static LPCDXTAG hb_cdxIndexCreateTag( HB_BOOL fStruct, LPCDXINDEX pIndex, pTag->UsrUnique = HB_FALSE; pTag->IgnoreCase = fNoCase && bType == 'C'; pTag->Custom = fCustom; + +#if defined( HB_SIXCDX ) + pTag->Template = pTag->KeyExpr && hb_cdxIsTemplateFunc( pTag->KeyExpr ); + if( pTag->Template ) + pTag->Custom = HB_TRUE; + /* SIx3 does not support repeated key value for the same record */ + pTag->MultiKey = HB_FALSE; +#else pTag->Template = pTag->MultiKey = pTag->Custom; +#endif pTag->Partial = pTag->ChgOnly = HB_FALSE; pTag->uiType = bType; pTag->bTrail = ( bType == 'C' ) ? ' ' : '\0'; @@ -8381,74 +8397,89 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO */ case DBOI_KEYADD: - if( !pTag ) - { - pInfo->itmResult = hb_itemPutL( pInfo->itmResult, HB_FALSE ); - } - else + { + HB_BOOL fResult = HB_FALSE; + if( pTag ) { if( pTag->Custom ) { if( pArea->dbfarea.lpdbPendingRel ) SELF_FORCEREL( ( AREAP ) pArea ); - if( !pArea->dbfarea.fPositioned || - ( pTag->pForItem && - !hb_cdxEvalCond( pArea, pTag->pForItem, HB_TRUE ) ) ) - { - pInfo->itmResult = hb_itemPutL( pInfo->itmResult, HB_FALSE ); - } - else + if( pArea->dbfarea.fPositioned && + ( !pTag->pForItem || + hb_cdxEvalCond( pArea, pTag->pForItem, HB_TRUE ) ) ) { LPCDXKEY pKey; hb_cdxIndexLockWrite( pTag->pIndex ); +#if defined( HB_SIXCDX ) + if( pTag->Template ) + { + if( pTag->uiType == hb_cdxItemType( pInfo->itmNewVal ) ) + pKey = hb_cdxKeyPutItem( NULL, pInfo->itmNewVal, + pArea->dbfarea.ulRecNo, pTag, + HB_TRUE, CDX_CMP_EXACT ); + else + pKey = NULL; + } +#else if( pInfo->itmNewVal && !HB_IS_NIL( pInfo->itmNewVal ) && pTag->Template ) pKey = hb_cdxKeyPutItem( NULL, pInfo->itmNewVal, pArea->dbfarea.ulRecNo, pTag, HB_TRUE, CDX_CMP_EXACT ); +#endif else pKey = hb_cdxKeyEval( NULL, pTag ); - pInfo->itmResult = hb_itemPutL( pInfo->itmResult, - hb_cdxTagKeyAdd( pTag, pKey ) ); - hb_cdxIndexUnLockWrite( pTag->pIndex ); - hb_cdxKeyFree( pKey ); + if( pKey ) + { + fResult = hb_cdxTagKeyAdd( pTag, pKey ); + hb_cdxIndexUnLockWrite( pTag->pIndex ); + hb_cdxKeyFree( pKey ); + } } } +#if !defined( HB_SIXCDX ) else - { - hb_cdxErrorRT( pArea, 0, EDBF_NOTCUSTOM, NULL, 0, 0, NULL ); - } + hb_cdxErrorRT( pArea, EG_ARG, EDBF_NOTCUSTOM, NULL, 0, 0, NULL ); +#endif } + pInfo->itmResult = hb_itemPutL( pInfo->itmResult, fResult ); break; - + } case DBOI_KEYDELETE: - if( !pTag ) - { - pInfo->itmResult = hb_itemPutL( pInfo->itmResult, HB_FALSE ); - } - else + { + HB_BOOL fResult = HB_FALSE; + if( pTag ) { if( pTag->Custom ) { if( pArea->dbfarea.lpdbPendingRel ) SELF_FORCEREL( ( AREAP ) pArea ); - if( !pArea->dbfarea.fPositioned || - ( pTag->pForItem && - !hb_cdxEvalCond( pArea, pTag->pForItem, HB_TRUE ) ) ) - { - pInfo->itmResult = hb_itemPutL( pInfo->itmResult, HB_FALSE ); - } - else + if( pArea->dbfarea.fPositioned && + ( !pTag->pForItem || + hb_cdxEvalCond( pArea, pTag->pForItem, HB_TRUE ) ) ) { LPCDXKEY pKey; hb_cdxIndexLockWrite( pTag->pIndex ); +#if defined( HB_SIXCDX ) + if( pTag->Template ) + { + if( pTag->uiType == hb_cdxItemType( pInfo->itmNewVal ) ) + pKey = hb_cdxKeyPutItem( NULL, pInfo->itmNewVal, + pArea->dbfarea.ulRecNo, pTag, + HB_TRUE, CDX_CMP_EXACT ); + else + pKey = NULL; + } +#else if( pInfo->itmNewVal && !HB_IS_NIL( pInfo->itmNewVal ) && pTag->Template ) pKey = hb_cdxKeyPutItem( NULL, pInfo->itmNewVal, pArea->dbfarea.ulRecNo, pTag, HB_TRUE, CDX_CMP_EXACT ); +#endif else { if( pTag->CurKey->rec != pArea->dbfarea.ulRecNo ) @@ -8459,19 +8490,22 @@ static HB_ERRCODE hb_cdxOrderInfo( CDXAREAP pArea, USHORT uiIndex, LPDBORDERINFO else pKey = hb_cdxKeyEval( NULL, pTag ); } - pInfo->itmResult = hb_itemPutL( pInfo->itmResult, - hb_cdxTagKeyDel( pTag, pKey ) ); - hb_cdxIndexUnLockWrite( pTag->pIndex ); - hb_cdxKeyFree( pKey ); + if( pKey ) + { + fResult = hb_cdxTagKeyDel( pTag, pKey ); + hb_cdxIndexUnLockWrite( pTag->pIndex ); + hb_cdxKeyFree( pKey ); + } } } +#if !defined( HB_SIXCDX ) else - { - hb_cdxErrorRT( pArea, 0, EDBF_NOTCUSTOM, NULL, 0, 0, NULL ); - } + hb_cdxErrorRT( pArea, EG_ARG, EDBF_NOTCUSTOM, NULL, 0, 0, NULL ); +#endif } + pInfo->itmResult = hb_itemPutL( pInfo->itmResult, fResult ); break; - + } case DBOI_READLOCK: if( pTag ) {