diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 6d75f0ea3f..9acb99f2f4 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,14 @@ +2000-11-07 16:25 UTC+0100 Ryszard Glab + + *include/hbexpra.c + *source/compiler/expropta.c + *source/macro/macroa.c + *fixed internal _GET_ optimization for macro variables + + *source/rtl/tgetint.prg + *__GET uses macro operator if no initial value is passed and + there is no set/get block + 2000-11-06 22:10 UTC+0800 Ron Pinkas * source/compiler/cmdcheck.c * utils/hbpp/hbpp.c diff --git a/harbour/include/hbexpra.c b/harbour/include/hbexpra.c index 51a563bf5d..b63c58e0eb 100644 --- a/harbour/include/hbexpra.c +++ b/harbour/include/hbexpra.c @@ -392,6 +392,73 @@ HB_EXPR_PTR hb_compExprNewFunCall( HB_EXPR_PTR pName, HB_EXPR_PTR pParms ) } } } + else if( pArg->ExprType == HB_ET_MACRO ) + { + /* @ 0,0 GET &var => __GET( NIL, var,... ) + * @ 0,0 GET var&var => __GET( NIL, "var&var",... ) + */ +#ifdef HB_MACRO_SUPPORT + HB_XFREE( pName->value.asSymbol ); + pName->value.asSymbol = hb_strdup( "__GET" ); +#else + pName->value.asSymbol = hb_compIdentifierNew( "__GET", TRUE ); +#endif + if( pArg->value.asMacro.pExprList == NULL ) + { + /* Simple macro expansion (not a parenthesized expressions) + */ + HB_EXPR_PTR pFirst, pNext; + + pFirst = pArg; /* first argument */ + pNext = pFirst->pNext; /* second argument */ + if( pNext ) + pNext = pNext->pNext; /* third argument */ + + pArg = hb_compExprNewNil(); /* replace 1st with NIL */ + pParms->value.asList.pExprList = pArg; + pArg->pNext = pFirst->pNext; + if( pFirst->value.asMacro.cMacroOp == '&' ) + { + /* simple &variable - replace the second argument with + * a variable name + */ +#ifdef HB_MACRO_SUPPORT + char *szName = hb_strdup( pFirst->value.asMacro.szMacro ); +#else + char *szName = hb_compIdentifierNew( pFirst->value.asMacro.szMacro, FALSE ); +#endif + if( pFirst->pNext ) + HB_EXPR_PCODE1( hb_compExprDelete, pFirst->pNext ); /* delete a second argument */ + pArg->pNext = hb_compExprNewVar( szName ); + pArg->pNext->pNext = pNext; /* restore third argument */ + HB_EXPR_PCODE1( hb_compExprDelete, pFirst ); + } + else + { + /* text substitution text&variable - replace the second + * argument with a string + */ + if( pArg->pNext == NULL ) + { + /* no second argument */ +#ifdef HB_MACRO_SUPPORT + char *szText = hb_strdup( pFirst->value.asMacro.szMacro ); +#else + char *szText = hb_compIdentifierNew( pFirst->value.asMacro.szMacro, FALSE ); +#endif + pArg->pNext = hb_compExprNewString( szText ); + pArg->pNext->pNext = pNext; + } + HB_EXPR_PCODE1( hb_compExprDelete, pFirst ); /* delete first argument */ + } + } + else + { /* @ 0,0 GET &(var) + * TODO: generate a compilation time error - + * invalid GET expression + */ + } + } else #ifdef HB_MACRO_SUPPORT HB_XFREE( pName->value.asSymbol ); diff --git a/harbour/source/compiler/expropta.c b/harbour/source/compiler/expropta.c index 84b50250b9..414a33a659 100644 --- a/harbour/source/compiler/expropta.c +++ b/harbour/source/compiler/expropta.c @@ -5,6 +5,6 @@ /* hbexpra.c is also included from ../macro/macro.c * However it produces a slighty different code if used in * macro compiler (there is an additional parameter passed to some functions) - * 2 - ignore this magic number - this is used to force compilation + * 3 - ignore this magic number - this is used to force compilation */ #include "hbexpra.c" diff --git a/harbour/source/macro/macroa.c b/harbour/source/macro/macroa.c index 0e480c2c40..e920ca01ac 100644 --- a/harbour/source/macro/macroa.c +++ b/harbour/source/macro/macroa.c @@ -5,7 +5,7 @@ /* hbexpra.c is also included from ../compiler/expropta.c * However it produces a slighty different code if used in * macro compiler (there is an additional parameter passed to some functions) - * 2 - ignore this magic number - this is used to force compilation + * 3 - ignore this magic number - this is used to force compilation */ #define HB_MACRO_SUPPORT diff --git a/harbour/source/rtl/tgetint.prg b/harbour/source/rtl/tgetint.prg index 5668dce8ed..4e25ee2bcc 100644 --- a/harbour/source/rtl/tgetint.prg +++ b/harbour/source/rtl/tgetint.prg @@ -49,7 +49,11 @@ FUNCTION __GET( uVar, cVarName, cPicture, bValid, bWhen, bSetGet ) LOCAL oGet IF( bSetGet == NIL ) - bSetGet := {|xValue| IIF( PCOUNT()==0, uVar, uVar:=xValue)} + IF( uVar == NIL ) + bSetGet := {|xValue| IIF( PCOUNT()==0, &cVarName, &cVarname:=xValue)} + ELSE + bSetGet := {|xValue| IIF( PCOUNT()==0, uVar, uVar:=xValue)} + ENDIF ENDIF oGet := Get():New(,, bSetGet, cVarName, cPicture )