From e2f8ec6f1475e5c09c313aa9328fa798c3b4b51e Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Tue, 5 Jun 2007 19:07:56 +0000 Subject: [PATCH] 2007-06-05 21:10 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbcompdf.h * formatting * harbour/include/hbexpra.c + added comment * harbour/source/common/expropt2.c + added optimization for == NIL, = NIL, != NIL ! disabled in macro compiler buggy Clipper compiler optimization for expressions like: AT( "", "" ), "" $ "", CHR(256), now the folowwing code gives the same results when compiled by Clipper and Harbour: proc main() ? ""$"", &('""$""') ? AT(""," "), &('AT(""," ")') ? LEN(CHR(0)+CHR(256)), &('LEN(CHR(0)+CHR(256))') return --- harbour/ChangeLog | 18 ++++++++ harbour/include/hbcompdf.h | 4 +- harbour/include/hbexpra.c | 2 +- harbour/source/common/expropt2.c | 79 +++++++++++++++++++++++++++----- 4 files changed, 88 insertions(+), 15 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 2bb1485e31..9ede1b5bc6 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,24 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-06-05 21:10 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbcompdf.h + * formatting + * harbour/include/hbexpra.c + + added comment + * harbour/source/common/expropt2.c + + added optimization for == NIL, = NIL, + != NIL + ! disabled in macro compiler buggy Clipper compiler optimization + for expressions like: AT( "", "" ), "" $ "", CHR(256), now the + folowwing code gives the same results when compiled by Clipper + and Harbour: + proc main() + ? ""$"", &('""$""') + ? AT(""," "), &('AT(""," ")') + ? LEN(CHR(0)+CHR(256)), &('LEN(CHR(0)+CHR(256))') + return + 2007-06-05 20:22 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * harbour/doc/linux1st.txt + Added info about required Ubuntu packages. diff --git a/harbour/include/hbcompdf.h b/harbour/include/hbcompdf.h index a9eab5008b..c686b67465 100644 --- a/harbour/include/hbcompdf.h +++ b/harbour/include/hbcompdf.h @@ -527,7 +527,7 @@ typedef struct HB_PCODE_INFO_ /* compiled pcode container for macro compiler */ typedef struct HB_MACRO_ /* a macro compiled pcode container */ { /* common to compiler members */ - int mode; + int mode; /* HB_MODE_* */ ULONG supported; /* various flags for supported capabilities */ const struct _HB_COMP_FUNCS * funcs; @@ -571,7 +571,7 @@ HB_EXPRLST, * PHB_EXPRLST; typedef struct _HB_COMP { /* common to macro compiler members */ - int mode; + int mode; /* HB_MODE_* */ ULONG supported; /* various flags for supported capabilities */ const struct _HB_COMP_FUNCS * funcs; diff --git a/harbour/include/hbexpra.c b/harbour/include/hbexpra.c index 17c64efaed..3544704309 100644 --- a/harbour/include/hbexpra.c +++ b/harbour/include/hbexpra.c @@ -163,7 +163,7 @@ HB_EXPR_PTR hb_compExprNewFunCall( HB_EXPR_PTR pName, HB_EXPR_PTR pParms, HB_COM #endif } /* TODO: EMPTY() (not done by Clipper) */ - else if( strcmp( "EVAL", pName->value.asSymbol ) == 0 ) + else if( strcmp( "EVAL", pName->value.asSymbol ) == 0 ) { HB_EXPR_PTR pEval; /* Optimize Eval( bBlock, [ArgList] ) to: bBlock:Eval( [ArgList] ) */ diff --git a/harbour/source/common/expropt2.c b/harbour/source/common/expropt2.c index 5ba0ef627f..4dcb1c6f66 100644 --- a/harbour/source/common/expropt2.c +++ b/harbour/source/common/expropt2.c @@ -653,17 +653,20 @@ HB_EXPR_PTR hb_compExprReducePlus( HB_EXPR_PTR pSelf, HB_COMP_DECL ) HB_EXPR_PTR hb_compExprReduceIN( HB_EXPR_PTR pSelf, HB_COMP_DECL ) { - if( ( pSelf->value.asOperator.pLeft->ExprType == pSelf->value.asOperator.pRight->ExprType ) && pSelf->value.asOperator.pLeft->ExprType == HB_ET_STRING ) + if( pSelf->value.asOperator.pLeft->ExprType == pSelf->value.asOperator.pRight->ExprType && + pSelf->value.asOperator.pLeft->ExprType == HB_ET_STRING ) { /* Both arguments are literal strings */ BOOL bResult; /* NOTE: CA-Cl*pper has a bug where the $ operator returns .T. - when an empty string is searched [vszakats] */ - + * when an empty string is searched [vszakats] + * But this bug exists only in compiler optimizer and + * macro compiler does not have optimizer [druzus] + */ if( pSelf->value.asOperator.pLeft->ulLength == 0 ) - bResult = TRUE; + bResult = HB_COMP_PARAM->mode == HB_MODE_COMPILER; else bResult = ( hb_strAt( pSelf->value.asOperator.pLeft->value.asString.string, pSelf->value.asOperator.pLeft->ulLength, pSelf->value.asOperator.pRight->value.asString.string, pSelf->value.asOperator.pRight->ulLength ) != 0 ); @@ -766,6 +769,29 @@ HB_EXPR_PTR hb_compExprReduceNE( HB_EXPR_PTR pSelf, HB_COMP_DECL ) break; } } + else if( ( pLeft->ExprType == HB_ET_NIL && + ( pRight->ExprType == HB_ET_NUMERIC || + pRight->ExprType == HB_ET_LOGICAL || + pRight->ExprType == HB_ET_DATE || + pRight->ExprType == HB_ET_STRING || + pRight->ExprType == HB_ET_CODEBLOCK || + pRight->ExprType == HB_ET_ARRAY || + pRight->ExprType == HB_ET_FUNREF ) ) || + ( pRight->ExprType == HB_ET_NIL && + ( pLeft->ExprType == HB_ET_NUMERIC || + pLeft->ExprType == HB_ET_LOGICAL || + pLeft->ExprType == HB_ET_DATE || + pLeft->ExprType == HB_ET_STRING || + pLeft->ExprType == HB_ET_CODEBLOCK || + pLeft->ExprType == HB_ET_ARRAY || + pLeft->ExprType == HB_ET_FUNREF ) ) ) + { + HB_COMP_EXPR_FREE( pLeft ); + HB_COMP_EXPR_FREE( pRight ); + pSelf->ExprType = HB_ET_LOGICAL; + pSelf->ValType = HB_EV_LOGICAL; + pSelf->value.asLogical = TRUE; + } /* TODO: add checking of incompatible types else { @@ -1058,7 +1084,7 @@ HB_EXPR_PTR hb_compExprReduceEQ( HB_EXPR_PTR pSelf, HB_COMP_DECL ) /* NOTE: when not exact comparison (==) is used * the result depends on SET EXACT setting then it * cannot be optimized except the case when NULL string are - * compared - "" = "" is always FALSE regardless of EXACT + * compared - "" = "" is always TRUE regardless of EXACT * setting */ if( pSelf->ExprType == HB_EO_EQ || @@ -1112,6 +1138,29 @@ HB_EXPR_PTR hb_compExprReduceEQ( HB_EXPR_PTR pSelf, HB_COMP_DECL ) break; } } + else if( ( pLeft->ExprType == HB_ET_NIL && + ( pRight->ExprType == HB_ET_NUMERIC || + pRight->ExprType == HB_ET_LOGICAL || + pRight->ExprType == HB_ET_DATE || + pRight->ExprType == HB_ET_STRING || + pRight->ExprType == HB_ET_CODEBLOCK || + pRight->ExprType == HB_ET_ARRAY || + pRight->ExprType == HB_ET_FUNREF ) ) || + ( pRight->ExprType == HB_ET_NIL && + ( pLeft->ExprType == HB_ET_NUMERIC || + pLeft->ExprType == HB_ET_LOGICAL || + pLeft->ExprType == HB_ET_DATE || + pLeft->ExprType == HB_ET_STRING || + pLeft->ExprType == HB_ET_CODEBLOCK || + pLeft->ExprType == HB_ET_ARRAY || + pLeft->ExprType == HB_ET_FUNREF ) ) ) + { + HB_COMP_EXPR_FREE( pLeft ); + HB_COMP_EXPR_FREE( pRight ); + pSelf->ExprType = HB_ET_LOGICAL; + pSelf->ValType = HB_EV_LOGICAL; + pSelf->value.asLogical = FALSE; + } /* TODO: add checking of incompatible types else { @@ -1372,10 +1421,12 @@ BOOL hb_compExprReduceAT( HB_EXPR_PTR pSelf, HB_COMP_DECL ) if( pSub->ExprType == HB_ET_STRING && pText->ExprType == HB_ET_STRING ) { - /* This is CA-Clipper optimizer behavior */ + /* This is CA-Clipper compiler optimizer behavior, + * macro compiler does not have optimizer [druzus] + */ if( pSub->ulLength == 0 ) { - pReduced = hb_compExprNewLong( 1, HB_COMP_PARAM ); + pReduced = hb_compExprNewLong( HB_COMP_PARAM->mode == HB_MODE_COMPILER ? 1 : 0, HB_COMP_PARAM ); } else { @@ -1404,16 +1455,20 @@ BOOL hb_compExprReduceCHR( HB_EXPR_PTR pSelf, HB_COMP_DECL ) if( pArg->ExprType == HB_ET_NUMERIC ) { /* NOTE: CA-Cl*pper's compiler optimizer will be wrong for those - CHR() cases where the passed parameter is a constant which - can be divided by 256 but it's not zero, in this case it - will return an empty string instead of a Chr(0). [vszakats] */ + * CHR() cases where the passed parameter is a constant which + * can be divided by 256 but it's not zero, in this case it + * will return an empty string instead of a Chr(0). [vszakats] + * But this bug exist only in compiler and macro compiler does + * not have optimizer [druzus] + */ HB_EXPR_PTR pExpr = HB_COMP_EXPR_NEW( HB_ET_STRING ); pExpr->ValType = HB_EV_STRING; if( pArg->value.asNum.NumType == HB_ET_LONG ) { - if( ( pArg->value.asNum.val.l & 0xff ) == 0 && + if( HB_COMP_PARAM->mode == HB_MODE_COMPILER && + ( pArg->value.asNum.val.l & 0xff ) == 0 && pArg->value.asNum.val.l != 0 ) { pExpr->value.asString.string = ""; @@ -1538,7 +1593,7 @@ BOOL hb_compExprReduceUPPER( HB_EXPR_PTR pSelf, HB_COMP_DECL ) { HB_EXPR_PTR pParms = pSelf->value.asFunCall.pParms; HB_EXPR_PTR pArg = pParms->value.asList.pExprList; - + if( pArg->ExprType == HB_ET_STRING ) { ULONG ulLen = pArg->ulLength;