1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "codegen.hxx"
25 // Transform table for token operators and opcodes
28 SbiToken eTok
; // Token
29 SbiOpcode eOp
; // Opcode
32 static const OpTable aOpTable
[] = {
58 // Output of an element
59 void SbiExprNode::Gen( RecursiveMode eRecMode
)
71 pGen
->Gen( _CONST
, (short) nVal
);
74 nStringId
= pGen
->GetParser()->aGblStrings
.Add( aStrVal
, true );
75 pGen
->Gen( _SCONST
, nStringId
);
78 nStringId
= pGen
->GetParser()->aGblStrings
.Add( nVal
, eType
);
79 pGen
->Gen( _NUMBER
, nStringId
);
83 else if( IsOperand() )
85 SbiExprNode
* pWithParent_
= NULL
;
87 if( aVar
.pDef
->GetScope() == SbPARAM
)
90 if( 0 == aVar
.pDef
->GetPos() )
92 bool bTreatFunctionAsParam
= true;
93 if( eRecMode
== FORCE_CALL
)
95 bTreatFunctionAsParam
= false;
97 else if( eRecMode
== UNDEFINED
)
99 if( aVar
.pPar
&& aVar
.pPar
->IsBracket() )
101 bTreatFunctionAsParam
= false;
104 if( !bTreatFunctionAsParam
)
106 eOp
= aVar
.pDef
->IsGlobal() ? _FIND_G
: _FIND
;
110 // special treatment for WITH
111 else if( (pWithParent_
= GetWithParent()) != NULL
)
113 eOp
= _ELEM
; // .-Term in WITH
117 eOp
= ( aVar
.pDef
->GetScope() == SbRTL
) ? _RTL
:
118 (aVar
.pDef
->IsGlobal() ? _FIND_G
: _FIND
);
124 SbiProcDef
* pProc
= aVar
.pDef
->GetProcDef();
125 if ( pGen
->GetParser()->bClassModule
)
129 else if ( aVar
.pDef
->IsStatic() || (pProc
&& pProc
->IsStatic()) )
134 for( SbiExprNode
* p
= this; p
; p
= p
->aVar
.pNext
)
136 if( p
== this && pWithParent_
!= NULL
)
140 p
->GenElement( eOp
);
144 else if( IsTypeOf() )
147 pGen
->Gen( _TESTCLASS
, nTypeStrId
);
151 pGen
->Gen( _CREATE
, 0, nTypeStrId
);
160 for( const OpTable
* p
= aOpTable
; p
->eTok
!= NIL
; p
++ )
162 if( p
->eTok
== eTok
)
164 pGen
->Gen( p
->eOp
); break;
170 // Output of an operand element
172 void SbiExprNode::GenElement( SbiOpcode eOp
)
175 if ((eOp
< _RTL
|| eOp
> _CALLC
) && eOp
!= _FIND_G
&& eOp
!= _FIND_CM
&& eOp
!= _FIND_STATIC
)
176 pGen
->GetParser()->Error( SbERR_INTERNAL_ERROR
, "Opcode" );
178 SbiSymDef
* pDef
= aVar
.pDef
;
179 // The ID is either the position or the String-ID
180 // If the bit Bit 0x8000 is set, the variable have
182 sal_uInt16 nId
= ( eOp
== _PARAM
) ? pDef
->GetPos() : pDef
->GetId();
183 // Build a parameter list
184 if( aVar
.pPar
&& aVar
.pPar
->GetSize() )
190 pGen
->Gen( eOp
, nId
, sal::static_int_cast
< sal_uInt16
>( GetType() ) );
194 SbiExprListVector
* pvMorePar
= aVar
.pvMorePar
;
195 SbiExprListVector::iterator it
;
196 for( it
= pvMorePar
->begin() ; it
!= pvMorePar
->end() ; ++it
)
198 SbiExprList
* pExprList
= *it
;
200 pGen
->Gen( _ARRAYACCESS
);
205 // Create an Argv-Table
206 // The first element remain available for return value etc.
207 // See as well SbiProcDef::SbiProcDef() in symtbl.cxx
209 void SbiExprList::Gen()
213 pParser
->aGen
.Gen( _ARGC
);
214 // Type adjustment at DECLARE
215 sal_uInt16 nCount
= 1;
217 for( SbiExpression
* pExpr
= pFirst
; pExpr
; pExpr
= pExpr
->pNext
,nCount
++ )
220 if( !pExpr
->GetName().isEmpty() )
223 sal_uInt16 nSid
= pParser
->aGblStrings
.Add( pExpr
->GetName() );
224 pParser
->aGen
.Gen( _ARGN
, nSid
);
226 /* TODO: Check after Declare concept change
227 // From 1996-01-10: Type adjustment at named -> search suitable parameter
230 // For the present: trigger an error
231 pParser->Error( SbERR_NO_NAMED_ARGS );
233 // Later, if Named Args at DECLARE is possible
234 //for( sal_uInt16 i = 1 ; i < nParAnz ; i++ )
236 // SbiSymDef* pDef = pPool->Get( i );
237 // const String& rName = pDef->GetName();
240 // if( pExpr->GetName().ICompare( rName )
241 // == COMPARE_EQUAL )
243 // pParser->aGen.Gen( _ARGTYP, pDef->GetType() );
253 pParser
->aGen
.Gen( _ARGV
);
259 void SbiExpression::Gen( RecursiveMode eRecMode
)
261 // special treatment for WITH
262 // If pExpr == .-term in With, approximately Gen for Basis-Object
263 pExpr
->Gen( eRecMode
);
266 pParser
->aGen
.Gen( _BYVAL
);
270 sal_uInt16 uBase
= pParser
->nBase
;
271 if( pParser
->IsCompatible() )
273 uBase
|= 0x8000; // #109275 Flag compatibility
275 pParser
->aGen
.Gen( _BASED
, uBase
);
276 pParser
->aGen
.Gen( _ARGV
);
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */