* src/pp/ppcore.c
* src/pp/hbpp.c
* src/vm/macro.c
* src/vm/runner.c
* src/vm/estack.c
* src/vm/itemapi.c
* src/vm/hvm.c
* src/vm/cmdarg.c
* src/vm/maindllp.c
* src/vm/fm.c
* src/vm/thread.c
* src/vm/memvars.c
* src/vm/eval.c
* src/vm/extend.c
* src/vm/classes.c
* src/debug/dbgentry.c
* src/common/expropt1.c
* src/common/expropt2.c
* src/common/hbhash.c
* src/nortl/nortl.c
* src/macro/macrolex.c
* src/rtl/gtxwc/gtxwc.c
* src/rtl/gtstd/gtstd.c
* src/rtl/gtcgi/gtcgi.c
* src/rtl/errapi.c
* src/rtl/hbprocfn.c
* src/rtl/hbsocket.c
* src/rtl/gtpca/gtpca.c
* src/rtl/filebuf.c
* src/rtl/hbproces.c
* src/rdd/dbfntx/dbfntx1.c
* src/rdd/dbsql.c
* src/rdd/hbdbsort.c
* src/rdd/workarea.c
* src/rdd/wacore.c
* src/rdd/sdf1.c
* src/rdd/dbcmdx.c
* src/rdd/dbfnsx/dbfnsx1.c
* src/rdd/dbcmd.c
* src/rdd/dbfcdx/dbfcdx1.c
* src/rdd/delim1.c
* src/rdd/dbf1.c
* src/rdd/hsx/hsx.c
* src/rdd/usrrdd/usrrdd.c
* src/rdd/wafunc.c
* src/rdd/dbffpt/dbffpt1.c
* src/rdd/hbsix/sxord.c
* src/rdd/hbsix/sxfname.c
* src/rdd/hbsix/sxtable.c
* src/rdd/hbsix/sxutil.c
* src/rdd/hbsix/sxcrypt.c
* src/compiler/ppcomp.c
* src/compiler/hbmain.c
* src/compiler/compi18n.c
* src/compiler/cmdcheck.c
* src/compiler/hbdbginf.c
* src/compiler/hbpcode.c
* src/compiler/genhrb.c
* src/compiler/hbdead.c
* src/compiler/complex.c
* src/compiler/genobj32.c
* src/compiler/genc.c
* src/compiler/hbopt.c
* src/compiler/hbident.c
* src/compiler/gencc.c
* src/compiler/hbcmplib.c
* src/compiler/hblbl.c
* src/compiler/harbour.yyc
* src/compiler/harbour.y
* include/hbpp.h
* include/hbrdddbf.h
* include/hbvmpub.h
* include/hbrddnsx.h
* include/hbstack.h
* include/hbgtcore.h
* include/hbapifs.h
* include/hbthread.h
* include/hbdefs.h
* include/hbmacro.h
* include/hbinit.h
* include/hbtypes.h
* include/hbrddsdf.h
* include/hbapi.h
* include/hbapiitm.h
* include/hbrddntx.h
* include/hbvm.h
* include/hbapidbg.h
* include/hbcomp.h
* include/hbapirdd.h
* include/hbcompdf.h
* include/hbrdddel.h
* include/hbexpra.c
* include/hbexprop.h
* include/hbrddcdx.h
* include/hbapicls.h
* include/hbapierr.h
* include/hbrddfpt.h
* include/hbhash.h
* include/hbregex.h
* include/hbexprb.c
* contrib/hbct/screen2.c
* contrib/hbct/token2.c
* contrib/hbct/dbftools.c
* contrib/hbct/atadjust.c
* contrib/hbct/ctwin.c
* contrib/hbct/files.c
* contrib/hbct/dattime3.c
* contrib/hbct/ctstr.c
* contrib/hbct/screen1.c
* contrib/hbct/token1.c
* contrib/hbct/ctc.c
* contrib/hbct/ct.h
* contrib/hbct/atnum.c
* contrib/hbct/asciisum.c
* contrib/hbct/numat.c
* contrib/hbct/atrepl.c
* contrib/xhb/bkgtsks.c
* contrib/xhb/hbcrypt.c
* contrib/xhb/fparse.c
* contrib/xhb/datesxhb.c
* contrib/xhb/hbnxs.h
* contrib/hbqt/gtqtc/gtqtc.cpp
* contrib/xpp/dbcmdx.c
* contrib/hbnf/dispc.c
* contrib/hbnf/ftattr.c
* contrib/hbmemio/memio.c
* contrib/hbnetio/netiocli.c
* contrib/rddsql/sddmy/mysqldd.c
* contrib/rddsql/sddpg/pgsqldd.c
* contrib/rddsql/sddfb/fbirddd.c
* contrib/rddsql/sddodbc/odbcdd.c
* contrib/rddsql/hbrddsql.h
* contrib/rddsql/sqlbase.c
* contrib/rddsql/sqlmix.c
* contrib/rddads/adsx.c
* contrib/rddads/adsfunc.c
* contrib/rddads/rddads.h
* contrib/rddads/ads1.c
* contrib/rddads/adsmgmnt.c
* contrib/hbmisc/spd.c
* contrib/hbtip/utils.c
* contrib/hbtip/encmthd.c
* contrib/hbbmcdx/bmdbfcdx.c
* contrib/hbbmcdx/hbbmcdx.h
* contrib/hbbtree/hb_btree.h
* contrib/hbbtree/hb_btree.c
* ULONG -> HB_ULONG, HB_SIZE
(except for external (OS) API specific usage)
* Formatting.
; NOTE: I converted ULONG to HB_SIZE where I felt it appropriate,
but didn't touch compiler, codeblock handling, low-level
RDD (Set/GetVarLen method) and high-level contrib RDDs, so
this needs to be cleaned.
Also there may be cases where I didn't change the whole
call chain to HB_SIZE.
; NOTE: It would be probably worthy to add new types for these purposes:
- line number (HB_USHORT)
- record number (HB_ULONG)
- RDD connection (HB_ULONG)
- parameter count / stack position / class member positions / etc (HB_USHORT, sometimes HB_ULONG)
- pcode (HB_BYTE and char)
- flags / modes (HB_USHORT / HB_ULONG)
- timers (HB_ULONG, HB_MAXINT)
- GT API character (HB_USHORT)
; REQUESTS:
- Pls don't over-align variable declarations. It makes
modification much much slower. Sometimes declarations are
aligned even if there was only one or two of them in a block.
- Pls always add variable names in declarations, otherwise the purpose
of the function is very slow to decipher when looking at it.
- Keep up the nice formatting according to Harbour standards,
it makes modifications much much easier.
; TODO:
- Verify with grep script
- Verify with HB_USER_CFLAGS=-DHB_LEGACY_TYPES_OFF
- Make HB_LEGACY_TYPES_OFF default for Harbour builds.
- Tie HB_LEGACY_TYPES_OFF to HB_LEGACY_LEVEL3
- Replace current windows.h inclusion hack with regular method
- Delete hacks dealing with former type chaos:
HB_CLIPPER_INT_ITEMS, HB_DONT_DEFINE_BASIC_TYPES, HB_DONT_DEFINE_BOOL, HB_DONT_DEFINE_BYTE, HB_DONT_DEFINE_LONG
- Retest hbfimage on *nix, delete hacks
- Normalize HB_BYTE vs. HB_UCHAR usage
- Type cleanups, f.e. HB_SIZE vs. HB_ULONG
- Add new special types (see above)
- Switch HB_SIZE to signed (big project), and delete HB_ISIZ afterwards.
713 lines
24 KiB
C
713 lines
24 KiB
C
/*
|
|
* $Id$
|
|
*/
|
|
|
|
/*
|
|
* Harbour Project source code:
|
|
* Compiler Expression Optimizer
|
|
*
|
|
* Copyright 1999 Ryszard Glab
|
|
* www - http://www.harbour-project.org
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
* any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this software; see the file COPYING. If not, write to
|
|
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
|
|
*
|
|
* As a special exception, the Harbour Project gives permission for
|
|
* additional uses of the text contained in its release of Harbour.
|
|
*
|
|
* The exception is that, if you link the Harbour libraries with other
|
|
* files to produce an executable, this does not by itself cause the
|
|
* resulting executable to be covered by the GNU General Public License.
|
|
* Your use of that executable is in no way restricted on account of
|
|
* linking the Harbour library code into it.
|
|
*
|
|
* This exception does not however invalidate any other reasons why
|
|
* the executable file might be covered by the GNU General Public License.
|
|
*
|
|
* This exception applies only to the code released by the Harbour
|
|
* Project under the name Harbour. If you copy code from other
|
|
* Harbour Project or Free Software Foundation releases into a copy of
|
|
* Harbour, as the General Public License permits, the exception does
|
|
* not apply to the code that you add in this way. To avoid misleading
|
|
* anyone as to the status of such modified files, you must delete
|
|
* this exception notice from them.
|
|
*
|
|
* If you write modifications of your own for Harbour, it is your choice
|
|
* whether to permit this exception to apply to your modifications.
|
|
* If you do not wish that, delete this exception notice.
|
|
*
|
|
*/
|
|
|
|
|
|
#include "hbcomp.h"
|
|
|
|
/* ************************************************************************ */
|
|
|
|
#ifndef HB_MACRO_SUPPORT
|
|
HB_ULONG hb_compExprListEval( HB_COMP_DECL, HB_EXPR_PTR pExpr, HB_CARGO_FUNC_PTR pEval )
|
|
{
|
|
HB_ULONG ulLen = 0;
|
|
|
|
if( pEval && ( pExpr->ExprType == HB_ET_LIST ||
|
|
pExpr->ExprType == HB_ET_ARGLIST ) )
|
|
{
|
|
pExpr = pExpr->value.asList.pExprList;
|
|
while( pExpr )
|
|
{
|
|
( pEval )( HB_COMP_PARAM, ( void * ) pExpr );
|
|
pExpr = pExpr->pNext;
|
|
++ulLen;
|
|
}
|
|
}
|
|
return ulLen;
|
|
}
|
|
|
|
HB_ULONG hb_compExprListEval2( HB_COMP_DECL, HB_EXPR_PTR pExpr1, HB_EXPR_PTR pExpr2, HB_CARGO2_FUNC_PTR pEval )
|
|
{
|
|
HB_ULONG ulLen = 0;
|
|
|
|
if( !pEval )
|
|
return ulLen;
|
|
|
|
if( ( pExpr1->ExprType == HB_ET_LIST || pExpr1->ExprType == HB_ET_ARGLIST )
|
|
&&
|
|
( pExpr2->ExprType == HB_ET_LIST || pExpr2->ExprType == HB_ET_ARGLIST ) )
|
|
{
|
|
pExpr1 = pExpr1->value.asList.pExprList;
|
|
pExpr2 = pExpr2->value.asList.pExprList;
|
|
while( pExpr1 && pExpr2 )
|
|
{
|
|
( pEval )( HB_COMP_PARAM, ( void * ) pExpr1, ( void * ) pExpr2 );
|
|
pExpr1 = pExpr1->pNext;
|
|
pExpr2 = pExpr2->pNext;
|
|
++ulLen;
|
|
}
|
|
}
|
|
else if( pExpr1->ExprType == HB_ET_LIST || pExpr1->ExprType == HB_ET_ARGLIST )
|
|
{
|
|
pExpr1 = pExpr1->value.asList.pExprList;
|
|
while( pExpr1 )
|
|
{
|
|
( pEval )( HB_COMP_PARAM, ( void * ) pExpr1, ( void * ) pExpr2 );
|
|
pExpr1 = pExpr1->pNext;
|
|
++ulLen;
|
|
}
|
|
}
|
|
return ulLen;
|
|
}
|
|
#endif
|
|
|
|
/* Create function call
|
|
*/
|
|
#ifdef HB_MACRO_SUPPORT
|
|
HB_EXPR_PTR hb_macroExprNewFunCall( HB_EXPR_PTR pName, HB_EXPR_PTR pParms, HB_COMP_DECL )
|
|
#else
|
|
HB_EXPR_PTR hb_compExprNewFunCall( HB_EXPR_PTR pName, HB_EXPR_PTR pParms, HB_COMP_DECL )
|
|
#endif
|
|
{
|
|
HB_EXPR_PTR pExpr = NULL;
|
|
|
|
if( pName->ExprType == HB_ET_FUNNAME )
|
|
{
|
|
/* The name of a function is specified at compile time
|
|
* e.g. MyFunc()
|
|
*
|
|
* NOTE: 'pName' can be a macro expression that will be resolved
|
|
* at runtime - in this case pName is an expression of HB_ET_MACRO type
|
|
* e.g. &MyVar()
|
|
*/
|
|
int iLen;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_compExprNewFunCall(%s)", pName->value.asSymbol));
|
|
|
|
iLen = strlen( pName->value.asSymbol );
|
|
|
|
#if !defined( HB_MACRO_SUPPORT ) && defined( HB_USE_ENUM_FUNCTIONS )
|
|
if( iLen > 7 && memcmp( "HB_ENUM", pName->value.asSymbol, 7 ) == 0 )
|
|
{
|
|
char * szMessage = NULL;
|
|
|
|
if( iLen == 12 && memcmp( "INDEX", pName->value.asSymbol + 7, 5 ) == 0 )
|
|
szMessage = "__ENUMINDEX";
|
|
else if( iLen == 12 && memcmp( "VALUE", pName->value.asSymbol + 7, 5 ) == 0 )
|
|
szMessage = "__ENUMVALUE";
|
|
else if( iLen == 11 && memcmp( "BASE", pName->value.asSymbol + 7, 4 ) == 0 )
|
|
szMessage = "__ENUMBASE";
|
|
else if( iLen == 10 && memcmp( "KEY", pName->value.asSymbol + 7, 3 ) == 0 )
|
|
szMessage = "__ENUMKEY";
|
|
|
|
if( szMessage )
|
|
{
|
|
int iCount = ( int ) hb_compExprParamListLen( pParms );
|
|
char * szName = NULL;
|
|
|
|
if( iCount == 0 )
|
|
{
|
|
HB_ENUMERATOR_PTR pForVar, pEnumVar = NULL;
|
|
pForVar = HB_COMP_PARAM->functions.pLast->pEnum;
|
|
if( pForVar )
|
|
{
|
|
while( pForVar )
|
|
{
|
|
if( pForVar->bForEach )
|
|
pEnumVar = pForVar;
|
|
pForVar = pForVar->pNext;
|
|
}
|
|
if( pEnumVar )
|
|
szName = pEnumVar->szName;
|
|
}
|
|
}
|
|
else if( iCount == 1 )
|
|
{
|
|
if( pParms->value.asList.pExprList->ExprType == HB_ET_VARIABLE ||
|
|
pParms->value.asList.pExprList->ExprType == HB_ET_VARREF )
|
|
szName = pParms->value.asList.pExprList->value.asSymbol;
|
|
}
|
|
if( szName )
|
|
{
|
|
HB_COMP_EXPR_DELETE( pParms );
|
|
HB_COMP_EXPR_DELETE( pName );
|
|
return hb_compExprNewMethodObject(
|
|
hb_compExprNewSend( szMessage, HB_COMP_PARAM ),
|
|
hb_compExprNewVar( szName, HB_COMP_PARAM ) );
|
|
}
|
|
}
|
|
}
|
|
else
|
|
#endif
|
|
if( hb_compExprParamListLen( pParms ) == 0 )
|
|
{
|
|
/* nothing to do, both EVAL and _GET_ below need parameters */
|
|
}
|
|
else if( iLen == 4 && memcmp( "EVAL", pName->value.asSymbol, 4 ) == 0 )
|
|
{
|
|
HB_EXPR_PTR pEval;
|
|
|
|
/* Optimize Eval( bBlock, [ArgList] ) to: bBlock:Eval( [ArgList] ) */
|
|
if( !HB_SUPPORT_HARBOUR )
|
|
pParms = HB_EXPR_USE( pParms, HB_EA_REDUCE );
|
|
|
|
pEval = hb_compExprNewMethodCall(
|
|
hb_compExprNewMethodObject(
|
|
hb_compExprNewSend( "EVAL", HB_COMP_PARAM ),
|
|
pParms->value.asList.pExprList ),
|
|
hb_compExprNewArgList(
|
|
pParms->value.asList.pExprList->pNext,
|
|
HB_COMP_PARAM ) );
|
|
pParms->value.asList.pExprList = NULL;
|
|
HB_COMP_EXPR_DELETE( pParms );
|
|
HB_COMP_EXPR_DELETE( pName );
|
|
return pEval;
|
|
}
|
|
else if( iLen == 5 && memcmp( "_GET_", pName->value.asSymbol, 5 ) == 0 )
|
|
{
|
|
/* Reserved Clipper function used to handle GET variables
|
|
*/
|
|
HB_EXPR_PTR pArg, pNext;
|
|
HB_USHORT uiCount;
|
|
|
|
/* pArg has to be reduced to eliminate possible problems with
|
|
* cloned expressions in SETGET block
|
|
*/
|
|
if( HB_SUPPORT_HARBOUR )
|
|
{
|
|
pParms = HB_EXPR_USE( pParms, HB_EA_REDUCE );
|
|
pArg = pParms->value.asList.pExprList;
|
|
}
|
|
else
|
|
{
|
|
pArg = pParms->value.asList.pExprList;
|
|
pNext = pArg->pNext;
|
|
pArg->pNext = NULL;
|
|
pArg = hb_compExprListStrip( HB_EXPR_USE( pArg, HB_EA_REDUCE ), HB_COMP_PARAM );
|
|
pArg->pNext = pNext;
|
|
pParms->value.asList.pExprList = pArg;
|
|
}
|
|
|
|
if( pArg->ExprType == HB_ET_ARRAYAT )
|
|
{
|
|
/* replace:
|
|
_GET_( a[1], "a[1]", , , )
|
|
into:
|
|
__GETA( {||a }, "a", , , , { 1 } )
|
|
*/
|
|
HB_EXPR_PTR pIndex, pVar;
|
|
HB_EXPR_PTR pBase;
|
|
|
|
pName->value.asSymbol = "__GETA";
|
|
/* NOTE: a[ i, j ] is stored as: (pExprList)->(pIndex)
|
|
* ((a->[ i ])->[ j ])
|
|
*/
|
|
pVar = HB_EXPR_USE( pArg->value.asList.pExprList, HB_EA_REDUCE );
|
|
pBase = pVar->ExprType == HB_ET_ARRAYAT ? pVar : NULL;
|
|
pIndex = HB_EXPR_USE( pArg->value.asList.pIndex, HB_EA_REDUCE );
|
|
pIndex->pNext = NULL;
|
|
while( pVar->ExprType == HB_ET_ARRAYAT )
|
|
{
|
|
/* traverse back to a leftmost expression and build a list
|
|
* of index expressions
|
|
*/
|
|
pVar->value.asList.pIndex->pNext = pIndex;
|
|
pIndex = pVar->value.asList.pIndex;
|
|
pVar = pVar->value.asList.pExprList;
|
|
}
|
|
|
|
/* create a set only codeblock */
|
|
if( pVar->ExprType == HB_ET_MACRO )
|
|
{
|
|
/* &var[1] */
|
|
HB_COMP_EXPR_FREE( pVar );
|
|
pVar = hb_compExprNewNil( HB_COMP_PARAM );
|
|
}
|
|
else
|
|
{
|
|
pVar = hb_compExprAddCodeblockExpr( hb_compExprNewCodeBlock( NULL, 0, 0, HB_COMP_PARAM ), pVar );
|
|
}
|
|
|
|
/* pVar will be the first argument now
|
|
*/
|
|
pParms->value.asList.pExprList = pVar;
|
|
/* link the rest of parameters
|
|
*/
|
|
pVar->pNext = pArg->pNext;
|
|
/* Delete an argument that was the first one
|
|
*/
|
|
pArg->value.asList.pIndex = NULL;
|
|
pArg->value.asList.pExprList = NULL;
|
|
HB_COMP_EXPR_CLEAR( pArg );
|
|
/* Create an array with index elements
|
|
*/
|
|
pIndex = hb_compExprNewArray( hb_compExprNewList( pIndex, HB_COMP_PARAM ), HB_COMP_PARAM );
|
|
/* The array with index elements have to be the sixth argument
|
|
* of __GETA() call
|
|
*/
|
|
uiCount = 1;
|
|
while( ++uiCount < 6 )
|
|
{
|
|
if( pVar->pNext == NULL )
|
|
pVar->pNext = hb_compExprNewNil( HB_COMP_PARAM );
|
|
pVar = pVar->pNext;
|
|
}
|
|
if( pVar->pNext ) /* Delete 6-th argument if present */
|
|
{
|
|
pIndex->pNext = pVar->pNext->pNext;
|
|
HB_COMP_EXPR_DELETE( pVar->pNext );
|
|
}
|
|
pVar->pNext = pIndex; /* Set a new 6-th argument */
|
|
|
|
/* Remove the index expression from a string representation
|
|
*/
|
|
pVar = pParms->value.asList.pExprList->pNext;
|
|
if( pVar->ExprType == HB_ET_STRING )
|
|
{
|
|
HB_ULONG i = 0;
|
|
char *szVar = pVar->value.asString.string;
|
|
|
|
/* NOTE: Clipper strips a string at the first '[' character too
|
|
*/
|
|
while( ++i < pVar->ulLength )
|
|
{
|
|
if( szVar[ i ] == '[' )
|
|
{
|
|
szVar[ i ] = 0;
|
|
pVar->ulLength = i;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
/* clear expressions no longer used */
|
|
if( pBase )
|
|
{
|
|
while( pBase->ExprType == HB_ET_ARRAYAT )
|
|
{
|
|
pVar = pBase->value.asList.pExprList;
|
|
pBase->value.asList.pExprList = NULL;
|
|
HB_COMP_EXPR_CLEAR( pBase );
|
|
pBase = pVar;
|
|
}
|
|
}
|
|
}
|
|
else if( pArg->ExprType == HB_ET_MACRO )
|
|
{
|
|
/* @ 0,0 GET &var => __GET( NIL, var,... )
|
|
* @ 0,0 GET var&var => __GET( NIL, "var&var",... )
|
|
*/
|
|
pName->value.asSymbol = "__GET";
|
|
if( pArg->value.asMacro.pExprList == NULL )
|
|
{
|
|
/* Simple macro expansion (not a parenthesized expressions)
|
|
*/
|
|
HB_EXPR_PTR pFirst;
|
|
|
|
pFirst = pArg; /* first argument */
|
|
pNext = pFirst->pNext; /* second argument */
|
|
if( pNext )
|
|
pNext = pNext->pNext; /* third argument */
|
|
|
|
pArg = hb_compExprNewNil( HB_COMP_PARAM ); /* 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
|
|
*/
|
|
const char *szName = pFirst->value.asMacro.szMacro;
|
|
if( pFirst->pNext )
|
|
HB_COMP_EXPR_DELETE( pFirst->pNext ); /* delete a second argument */
|
|
pArg->pNext = hb_compExprNewVar( szName, HB_COMP_PARAM );
|
|
pArg->pNext->pNext = pNext; /* restore third argument */
|
|
HB_COMP_EXPR_DELETE( pFirst );
|
|
}
|
|
else
|
|
{
|
|
/* text substitution text&variable - replace the second
|
|
* argument with a string
|
|
*/
|
|
if( pArg->pNext == NULL )
|
|
{
|
|
/* no second argument */
|
|
const char *szText = pFirst->value.asMacro.szMacro;
|
|
pArg->pNext = hb_compExprNewString( szText, strlen( szText ), HB_FALSE, HB_COMP_PARAM );
|
|
pArg->pNext->pNext = pNext;
|
|
}
|
|
HB_COMP_EXPR_DELETE( pFirst ); /* delete first argument */
|
|
}
|
|
}
|
|
else
|
|
{ /* @ 0,0 GET &(var)
|
|
* TODO: generate a compilation time error -
|
|
* invalid GET expression
|
|
*/
|
|
}
|
|
}
|
|
else
|
|
{
|
|
pName->value.asSymbol = "__GET";
|
|
|
|
/* store second and a rest of arguments */
|
|
pNext = pArg->pNext;
|
|
pArg->pNext = NULL;
|
|
/* replace first argument with a set/get codeblock */
|
|
#if !defined( HB_MACRO_SUPPORT )
|
|
if( pArg->ExprType == HB_ET_VARIABLE )
|
|
{
|
|
if( hb_compVariableFind( HB_COMP_PARAM, pArg->value.asSymbol, NULL, NULL ) )
|
|
pArg = hb_compExprSetGetBlock( pArg, HB_COMP_PARAM );
|
|
else
|
|
{
|
|
/* Undeclared variable name - create a set/get codeblock
|
|
* at runtime
|
|
*/
|
|
HB_COMP_EXPR_FREE( pArg );
|
|
pArg = hb_compExprNewNil( HB_COMP_PARAM );
|
|
}
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
pArg = hb_compExprSetGetBlock( pArg, HB_COMP_PARAM );
|
|
}
|
|
/* restore next arguments */
|
|
pArg->pNext = pNext;
|
|
/* set an updated list of arguments */
|
|
pParms->value.asList.pExprList = pArg;
|
|
}
|
|
}
|
|
}
|
|
|
|
else if( pName->ExprType == HB_ET_MACRO )
|
|
{
|
|
/* Signal that macro compiler have to generate a pcode that will
|
|
* return function name as symbol instead of usual value
|
|
*/
|
|
pName->value.asMacro.SubType = HB_ET_MACRO_SYMBOL;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_compExprNewFunCall(&)"));
|
|
}
|
|
#ifdef HB_MACRO_SUPPORT
|
|
else if( pName->ExprType == HB_ET_VARIABLE )
|
|
{
|
|
/* My&var.1() executed by macro compiler
|
|
*/
|
|
/* NOTE: direct type change */
|
|
pName->ExprType = HB_ET_FUNNAME;
|
|
}
|
|
#endif
|
|
|
|
if( pExpr == NULL )
|
|
{
|
|
pExpr = HB_COMP_EXPR_NEW( HB_ET_FUNCALL );
|
|
pExpr->value.asFunCall.pParms = pParms;
|
|
pExpr->value.asFunCall.pFunName = pName;
|
|
}
|
|
|
|
return pExpr;
|
|
}
|
|
|
|
/* Creates new array access expression
|
|
* pArray[ pIndex ]
|
|
* NOTE: In case of multiple indexes it is called recursively
|
|
* array[ idx1, idx2 ] => ( array[ idx1 ] )[ idx2 ]
|
|
*/
|
|
#ifdef HB_MACRO_SUPPORT
|
|
HB_EXPR_PTR hb_macroExprNewArrayAt( HB_EXPR_PTR pArray, HB_EXPR_PTR pIndex, HB_COMP_DECL )
|
|
#else
|
|
HB_EXPR_PTR hb_compExprNewArrayAt( HB_EXPR_PTR pArray, HB_EXPR_PTR pIndex, HB_COMP_DECL )
|
|
#endif
|
|
{
|
|
HB_EXPR_PTR pExpr;
|
|
|
|
#ifdef HB_MACRO_SUPPORT
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_macroExprNewArrayAt()"));
|
|
#else
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_compExprNewArrayAt()"));
|
|
#endif
|
|
|
|
pExpr = HB_COMP_EXPR_NEW( HB_ET_ARRAYAT );
|
|
|
|
/* Check if this expression can be indexed */
|
|
if( ! HB_SUPPORT_ARRSTR )
|
|
HB_EXPR_USE( pArray, HB_EA_ARRAY_AT );
|
|
/* Check if this expression can be an index */
|
|
HB_EXPR_USE( pIndex, HB_EA_ARRAY_INDEX );
|
|
pExpr->value.asList.pExprList = pArray;
|
|
pExpr->value.asList.pIndex = pIndex;
|
|
pExpr->value.asList.reference = HB_FALSE;
|
|
|
|
return pExpr;
|
|
}
|
|
|
|
|
|
/* ************************************************************************* */
|
|
|
|
#ifndef HB_MACRO_SUPPORT
|
|
|
|
/* List of functions which can be used as static initializers */
|
|
static const char * s_szStaticFun[] = {
|
|
"HB_MUTEXCREATE"
|
|
};
|
|
|
|
#define STATIC_FUNCTIONS ( sizeof( s_szStaticFun ) / sizeof( char * ) )
|
|
|
|
static HB_BOOL hb_compStaticFunction( const char * szName )
|
|
{
|
|
unsigned int ui;
|
|
for( ui = 0; ui < STATIC_FUNCTIONS; ++ui )
|
|
{
|
|
if( strcmp( szName, s_szStaticFun[ ui ] ) == 0 )
|
|
return HB_TRUE;
|
|
}
|
|
return HB_FALSE;
|
|
}
|
|
|
|
|
|
static void hb_compExprCheckStaticInitializer( HB_EXPR_PTR pLeftExpr, HB_EXPR_PTR pRightExpr, HB_COMP_DECL )
|
|
{
|
|
if( ( pRightExpr->ExprType > HB_ET_FUNREF ||
|
|
pRightExpr->ExprType == HB_ET_SELF ) &&
|
|
!( pRightExpr->ExprType == HB_ET_FUNCALL &&
|
|
pRightExpr->value.asFunCall.pFunName->ExprType == HB_ET_FUNNAME &&
|
|
hb_compStaticFunction( pRightExpr->value.asFunCall.pFunName->
|
|
value.asSymbol ) &&
|
|
hb_compExprParamListLen( pRightExpr->value.asFunCall.pParms ) == 0 ) )
|
|
{
|
|
/* Illegal initializer for static variable (not a constant value)
|
|
*/
|
|
hb_compErrorStatic( HB_COMP_PARAM, pLeftExpr->value.asSymbol, pRightExpr );
|
|
}
|
|
}
|
|
|
|
static void hb_compExprCheckStaticListInitializers( HB_EXPR_PTR pLeftExpr, HB_EXPR_PTR pRightExpr, HB_COMP_DECL )
|
|
{
|
|
HB_EXPR_PTR * pExpr = &pRightExpr->value.asList.pExprList;
|
|
|
|
while( *pExpr )
|
|
{
|
|
if( !HB_SUPPORT_HARBOUR )
|
|
{
|
|
/* When -kc switch is used expression list is not stripped
|
|
* in reduce operation
|
|
*/
|
|
/* NOTE: During reduction the expression can be replaced by the
|
|
* new one - this will break the linked list of expressions.
|
|
* (classical case of replacing an item in a linked list)
|
|
*/
|
|
HB_EXPR_PTR pNext = ( *pExpr )->pNext; /* store next expression in case the current will be reduced */
|
|
*pExpr = hb_compExprListStrip( *pExpr, HB_COMP_PARAM );
|
|
( *pExpr )->pNext = pNext; /* restore the link to next expression */
|
|
}
|
|
|
|
if( (*pExpr)->ExprType == HB_ET_ARRAY ||
|
|
(*pExpr)->ExprType == HB_ET_HASH )
|
|
{
|
|
hb_compExprCheckStaticListInitializers( pLeftExpr, *pExpr, HB_COMP_PARAM );
|
|
}
|
|
else
|
|
{
|
|
hb_compExprCheckStaticInitializer( pLeftExpr, *pExpr, HB_COMP_PARAM );
|
|
}
|
|
pExpr = &( *pExpr )->pNext;
|
|
}
|
|
}
|
|
|
|
/* It initializes static variable.
|
|
* It is called in the following context:
|
|
* STATIC sVar := expression
|
|
*
|
|
* pLeftExpr - is a variable name
|
|
* pRightExpr - can be an expression of any type
|
|
*/
|
|
HB_EXPR_PTR hb_compExprAssignStatic( HB_EXPR_PTR pLeftExpr, HB_EXPR_PTR pRightExpr, HB_COMP_DECL )
|
|
{
|
|
HB_EXPR_PTR pExpr;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_compExprAssignStatic()"));
|
|
|
|
pExpr = HB_COMP_EXPR_NEW( HB_EO_ASSIGN );
|
|
|
|
pExpr->value.asOperator.pLeft = pLeftExpr;
|
|
/* Try to reduce the assigned value */
|
|
pRightExpr = HB_EXPR_USE( pRightExpr, HB_EA_REDUCE );
|
|
/* When -kc switch is used expression list is not stripped
|
|
* in reduce operation
|
|
*/
|
|
if( !HB_SUPPORT_HARBOUR )
|
|
pRightExpr = hb_compExprListStrip( pRightExpr, HB_COMP_PARAM );
|
|
|
|
pExpr->value.asOperator.pRight = pRightExpr;
|
|
|
|
if( pRightExpr->ExprType == HB_ET_ARGLIST )
|
|
{
|
|
/* HB_ET_ARGLIST is used in case of STATIC var[dim1, dim2, dimN]
|
|
* was used - we have to check if all array dimensions are
|
|
* constant values
|
|
*/
|
|
hb_compExprCheckStaticListInitializers( pLeftExpr, pRightExpr, HB_COMP_PARAM );
|
|
}
|
|
else if( pRightExpr->ExprType == HB_ET_ARRAY )
|
|
{
|
|
/* { elem1, elem2, elemN } was used as initializer
|
|
* Scan an array for illegal initializers.
|
|
* An array item have to be a const value too.
|
|
*/
|
|
hb_compExprCheckStaticListInitializers( pLeftExpr, pRightExpr, HB_COMP_PARAM );
|
|
}
|
|
else if( pRightExpr->ExprType == HB_ET_HASH )
|
|
{
|
|
/* { idx1=>var1, idx2=>var2, idxN=>varN } was used as initializer
|
|
* Scan a hash array for illegal initializers.
|
|
* A hash item have to be a const value too.
|
|
*/
|
|
hb_compExprCheckStaticListInitializers( pLeftExpr, pRightExpr, HB_COMP_PARAM );
|
|
}
|
|
else
|
|
{
|
|
hb_compExprCheckStaticInitializer( pLeftExpr, pRightExpr, HB_COMP_PARAM );
|
|
}
|
|
|
|
return pExpr;
|
|
}
|
|
|
|
HB_EXPR_PTR hb_compExprSetCodeblockBody( HB_EXPR_PTR pExpr, HB_BYTE * pCode, HB_ULONG ulLen )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_compExprSetCodeblockBody(%p,%p,%lu)", pExpr, pCode, ulLen));
|
|
|
|
pExpr->value.asCodeblock.string = ( char * ) hb_xgrab( ulLen + 1 );
|
|
memcpy( pExpr->value.asCodeblock.string, pCode, ulLen );
|
|
pExpr->value.asCodeblock.string[ ulLen ] = '\0';
|
|
pExpr->ulLength = ulLen;
|
|
|
|
return pExpr;
|
|
}
|
|
#endif
|
|
|
|
/* ************************************************************************* */
|
|
|
|
#if defined( HB_MACRO_SUPPORT )
|
|
|
|
/* Generates pcode to push an expressions
|
|
* NOTE: It pushes a value on the stack and leaves this value on the stack
|
|
*/
|
|
HB_EXPR_PTR hb_macroExprGenPush( HB_EXPR_PTR pExpr, HB_COMP_DECL )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_macroExprGenPush(%i)", pExpr->ExprType));
|
|
|
|
pExpr = HB_EXPR_USE( pExpr, HB_EA_REDUCE );
|
|
return HB_EXPR_USE( pExpr, HB_EA_PUSH_PCODE );
|
|
}
|
|
|
|
/* Generates pcode to pop an expressions
|
|
*/
|
|
HB_EXPR_PTR hb_macroExprGenPop( HB_EXPR_PTR pExpr, HB_COMP_DECL )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_macroExprGenPop(%i)", pExpr->ExprType));
|
|
|
|
pExpr = HB_EXPR_USE( pExpr, HB_EA_REDUCE );
|
|
HB_EXPR_USE( pExpr, HB_EA_LVALUE );
|
|
return HB_EXPR_USE( pExpr, HB_EA_POP_PCODE );
|
|
}
|
|
|
|
#else
|
|
|
|
/* Generates pcode to push an expressions
|
|
* NOTE: It pushes a value on the stack and leaves this value on the stack
|
|
*/
|
|
HB_EXPR_PTR hb_compExprGenPush( HB_EXPR_PTR pExpr, HB_COMP_DECL )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_compExprGenPush(%i)", pExpr->ExprType));
|
|
|
|
pExpr = HB_EXPR_USE( pExpr, HB_EA_REDUCE );
|
|
return HB_EXPR_USE( pExpr, HB_EA_PUSH_PCODE );
|
|
}
|
|
|
|
/* Generates pcode to pop an expressions
|
|
*/
|
|
HB_EXPR_PTR hb_compExprGenPop( HB_EXPR_PTR pExpr, HB_COMP_DECL )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_compExprGenPop(%i)", pExpr->ExprType));
|
|
|
|
HB_EXPR_USE( pExpr, HB_EA_LVALUE );
|
|
return HB_EXPR_USE( pExpr, HB_EA_POP_PCODE );
|
|
}
|
|
|
|
/* Generates pcode for inline expression used as a statement
|
|
* NOTE: It doesn't not leave any value on the eval stack
|
|
*/
|
|
HB_EXPR_PTR hb_compExprGenStatement( HB_EXPR_PTR pExpr, HB_COMP_DECL )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_compExprGenStatement(%p)", pExpr));
|
|
if( pExpr )
|
|
{
|
|
if( pExpr->ExprType == HB_EO_EQUAL )
|
|
{
|
|
/* NOTE: direct type change */
|
|
pExpr->ExprType = HB_EO_ASSIGN;
|
|
}
|
|
|
|
pExpr = HB_EXPR_USE( pExpr, HB_EA_REDUCE );
|
|
HB_EXPR_USE( pExpr, HB_EA_STATEMENT );
|
|
}
|
|
return pExpr;
|
|
}
|
|
|
|
HB_EXPR_PTR hb_compExprReduce( HB_EXPR_PTR pExpr, HB_COMP_DECL )
|
|
{
|
|
return HB_EXPR_USE( pExpr, HB_EA_REDUCE );
|
|
}
|
|
#endif
|
|
|
|
/* ************************************************************************* */
|