merge the formfield patch from ooo-build
[ooovba.git] / basic / source / inc / expr.hxx
blobb41d5aba30f7e165c934021c225d6259bd09cb94
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: expr.hxx,v $
10 * $Revision: 1.15.40.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _EXPR_HXX
32 #define _EXPR_HXX
34 #include "opcodes.hxx"
35 #include "token.hxx"
37 class SbiExprNode;
38 class SbiExpression;
39 class SbiExprList;
40 class SbiDimList;
41 class SbiParameters;
42 class SbiParser;
43 class SbiCodeGen;
44 class SbiSymDef;
45 class SbiProcDef;
48 #include <vector>
49 typedef ::std::vector<SbiExprList*> SbiExprListVector;
51 struct SbVar { // Variablen-Element:
52 SbiExprNode* pNext; // Weiteres Element (bei Strukturen)
53 SbiSymDef* pDef; // Symboldefinition
54 SbiExprList* pPar; // optionale Parameter (wird geloescht)
55 SbiExprListVector* pvMorePar; // Array of arrays foo(pPar)(avMorePar[0])(avMorePar[1])...
58 enum SbiExprType { // Expression-Typen:
59 SbSTDEXPR, // normaler Ausdruck
60 SbLVALUE, // beliebiger lValue
61 SbSYMBOL, // beliebiges zusammengesetztes Symbol
62 SbOPERAND // Variable/Funktion
65 enum SbiExprMode { // Expression context:
66 EXPRMODE_STANDARD, // default
67 EXPRMODE_STANDALONE, // a param1, param2 OR a( param1, param2 ) = 42
68 EXPRMODE_LPAREN_PENDING, // start of parameter list with bracket, special handling
69 EXPRMODE_LPAREN_NOT_NEEDED, // pending LPAREN has not been used
70 EXPRMODE_ARRAY_OR_OBJECT, // '=' or '(' or '.' found after ')' on ParenLevel 0, stopping
71 // expression, assuming array syntax a(...)[(...)] = ?
72 // or a(...).b(...)
73 EXPRMODE_EMPTY_PAREN // It turned out that the paren don't contain anything: a()
76 enum SbiNodeType {
77 SbxNUMVAL, // nVal = Wert
78 SbxSTRVAL, // aStrVal = Wert, before #i59791/#i45570: nStringId = Wert
79 SbxVARVAL, // aVar = Wert
80 SbxTYPEOF, // TypeOf ObjExpr Is Type
81 SbxNODE, // Node
82 SbxDUMMY
85 enum RecursiveMode
87 UNDEFINED,
88 FORCE_CALL,
89 PREVENT_CALL
92 class SbiExprNode { // Operatoren (und Operanden)
93 friend class SbiExpression;
94 friend class SbiConstExpression;
95 union {
96 USHORT nTypeStrId; // gepoolter String-ID, #i59791/#i45570 Now only for TypeOf
97 double nVal; // numerischer Wert
98 SbVar aVar; // oder Variable
100 String aStrVal; // #i59791/#i45570 Store string directly
101 SbiExprNode* pLeft; // linker Zweig
102 SbiExprNode* pRight; // rechter Zweig (NULL bei unaeren Ops)
103 SbiExprNode* pWithParent; // Knoten, dessen Member this per with ist
104 SbiCodeGen* pGen; // Code-Generator
105 SbiNodeType eNodeType; // Art des Nodes
106 SbxDataType eType; // aktueller Datentyp
107 SbiToken eTok; // Token des Operators
108 BOOL bComposite; // TRUE: Zusammengesetzter Ausdruck
109 BOOL bError; // TRUE: Fehlerhaft
110 void FoldConstants(); // Constant Folding durchfuehren
111 void CollectBits(); // Umwandeln von Zahlen in Strings
112 BOOL IsOperand() // TRUE, wenn Operand
113 { return BOOL( eNodeType != SbxNODE && eNodeType != SbxTYPEOF ); }
114 BOOL IsTypeOf()
115 { return BOOL( eNodeType == SbxTYPEOF ); }
116 BOOL IsNumber(); // TRUE bei Zahlen
117 BOOL IsString(); // TRUE bei Strings
118 BOOL IsLvalue(); // TRUE, falls als Lvalue verwendbar
119 void GenElement( SbiOpcode ); // Element
120 void BaseInit( SbiParser* p ); // Hilfsfunktion fuer Ctor, AB 17.12.95
121 public:
122 SbiExprNode( void );
123 SbiExprNode( SbiParser*, double, SbxDataType );
124 SbiExprNode( SbiParser*, const String& );
125 SbiExprNode( SbiParser*, const SbiSymDef&, SbxDataType, SbiExprList* = NULL );
126 SbiExprNode( SbiParser*, SbiExprNode*, SbiToken, SbiExprNode* );
127 SbiExprNode( SbiParser*, SbiExprNode*, USHORT ); // #120061 TypeOf
128 virtual ~SbiExprNode();
130 BOOL IsValid() { return BOOL( !bError ); }
131 BOOL IsConstant() // TRUE bei konstantem Operanden
132 { return BOOL( eNodeType == SbxSTRVAL || eNodeType == SbxNUMVAL ); }
133 BOOL IsIntConst(); // TRUE bei Integer-Konstanten
134 BOOL IsVariable(); // TRUE, wenn Variable
136 SbiExprNode* GetWithParent() { return pWithParent; }
137 void SetWithParent( SbiExprNode* p ) { pWithParent = p; }
139 SbxDataType GetType() { return eType; }
140 void SetType( SbxDataType eTp ) { eType = eTp; }
141 SbiNodeType GetNodeType() { return eNodeType; }
142 SbiSymDef* GetVar(); // Variable (falls vorhanden)
143 SbiSymDef* GetRealVar(); // letzte Variable in x.y.z
144 SbiExprNode* GetRealNode(); // letzter Knoten in x.y.z
145 short GetDepth(); // Tiefe eines Baumes berechnen
146 const String& GetString() { return aStrVal; }
147 short GetNumber() { return (short)nVal; }
148 SbiExprList* GetParameters() { return aVar.pPar; }
149 SbiExprListVector* GetMoreParameters() { return aVar.pvMorePar; }
151 void Optimize(); // Baumabgleich
153 void Gen( RecursiveMode eRecMode = UNDEFINED ); // Ausgabe eines Nodes
156 class SbiExpression { // der Ausdruck:
157 friend class SbiExprList;
158 friend class SbiParameters;
159 friend class SbiDimList;
160 protected:
161 String aArgName; // Name fuer bananntes Argument
162 SbiParser* pParser; // fuer Fehlermeldungen, Parsing
163 SbiExpression* pNext; // Link bei Parameterlisten
164 SbiExprNode* pExpr; // Der Expression-Baum
165 SbiExprType eCurExpr; // Art des Ausdrucks
166 SbiExprMode m_eMode; // Expression context
167 BOOL bBased; // TRUE: einfacher DIM-Teil (+BASE)
168 BOOL bError; // TRUE: Fehler
169 BOOL bByVal; // TRUE: ByVal-Parameter
170 BOOL bBracket; // TRUE: Parameter list with brackets
171 USHORT nParenLevel;
172 SbiExprNode* Term();
173 SbiExprNode* ObjTerm( SbiSymDef& );
174 SbiExprNode* Operand();
175 SbiExprNode* Unary();
176 SbiExprNode* Exp();
177 SbiExprNode* MulDiv();
178 SbiExprNode* IntDiv();
179 SbiExprNode* Mod();
180 SbiExprNode* AddSub();
181 SbiExprNode* Cat();
182 SbiExprNode* Like();
183 SbiExprNode* Comp();
184 SbiExprNode* Boolean();
185 public:
186 SbiExpression( SbiParser*, SbiExprType = SbSTDEXPR, SbiExprMode eMode = EXPRMODE_STANDARD ); // Parsender Ctor
187 SbiExpression( SbiParser*, const String& );
188 SbiExpression( SbiParser*, double, SbxDataType = SbxDOUBLE );
189 SbiExpression( SbiParser*, const SbiSymDef&, SbiExprList* = NULL );
190 SbiExpression( SbiParser*, SbiToken ); // Spezial-Expr mit Spezial-Tokens
191 ~SbiExpression();
192 String& GetName() { return aArgName; }
193 void SetBased() { bBased = TRUE; }
194 BOOL IsBased() { return bBased; }
195 void SetByVal() { bByVal = TRUE; }
196 BOOL IsByVal() { return bByVal; }
197 BOOL IsBracket() { return bBracket; }
198 BOOL IsValid() { return pExpr->IsValid(); }
199 BOOL IsConstant() { return pExpr->IsConstant(); }
200 BOOL IsVariable() { return pExpr->IsVariable(); }
201 BOOL IsLvalue() { return pExpr->IsLvalue(); }
202 BOOL IsIntConstant() { return pExpr->IsIntConst(); }
203 const String& GetString() { return pExpr->GetString(); }
204 SbiSymDef* GetVar() { return pExpr->GetVar(); }
205 SbiSymDef* GetRealVar() { return pExpr->GetRealVar(); }
206 SbiExprNode* GetExprNode() { return pExpr; }
207 SbxDataType GetType() { return pExpr->GetType(); }
208 void SetType( SbxDataType eType){ pExpr->eType = eType; }
209 void Gen( RecursiveMode eRecMode = UNDEFINED ); // Ausgabe eines Nodes
212 class SbiConstExpression : public SbiExpression {
213 double nVal;
214 String aVal;
215 SbxDataType eType;
216 public: // numerische Konstante
217 SbiConstExpression( SbiParser* );
218 SbxDataType GetType() { return eType; }
219 const String& GetString() { return aVal; }
220 double GetValue() { return nVal; }
221 short GetShortValue();
224 class SbiExprList { // Basisklasse fuer Parameter und Dims
225 protected:
226 SbiParser* pParser; // Parser
227 SbiExpression* pFirst; // Expressions
228 SbiProcDef* pProc; // DECLARE-Funktion (Parameter-Anpassung)
229 short nExpr; // Anzahl Expressions
230 short nDim; // Anzahl Dimensionen
231 BOOL bError; // TRUE: Fehler
232 BOOL bBracket; // TRUE: Klammern
233 public:
234 SbiExprList( SbiParser* );
235 virtual ~SbiExprList();
236 BOOL IsBracket() { return bBracket; }
237 BOOL IsValid() { return BOOL( !bError ); }
238 short GetSize() { return nExpr; }
239 short GetDims() { return nDim; }
240 SbiExpression* Get( short );
241 BOOL Test( const SbiProcDef& ); // Parameter-Checks
242 void Gen(); // Code-Erzeugung
243 // Setzen einer Funktionsdefinition zum Abgleich der Parameter
244 void SetProc( SbiProcDef* p ) { pProc = p; }
245 void addExpression( SbiExpression* pExpr );
248 class SbiParameters : public SbiExprList {
249 public:
250 SbiParameters( SbiParser*, BOOL bConst = FALSE, BOOL bPar = TRUE);// parsender Ctor
253 class SbiDimList : public SbiExprList {
254 BOOL bConst; // TRUE: Alles sind Integer-Konstanten
255 public:
256 SbiDimList( SbiParser* ); // Parsender Ctor
257 BOOL IsConstant() { return bConst; }
260 #endif