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 <constValue> == NIL, <constValue> = NIL,
      <constValue> != 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
This commit is contained in:
Przemyslaw Czerpak
2007-06-05 19:07:56 +00:00
parent ebb1fc5f7b
commit e2f8ec6f14
4 changed files with 88 additions and 15 deletions

View File

@@ -8,6 +8,24 @@
2002-12-01 13:30 UTC+0100 Foo Bar <foo.bar@foobar.org>
*/
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 <constValue> == NIL, <constValue> = NIL,
<constValue> != 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.

View File

@@ -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;

View File

@@ -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] ) */

View File

@@ -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;