merge the formfield patch from ooo-build
[ooovba.git] / rsc / source / parser / rscyacc.cxx
blob590aba6eebbd75d6157965ad75186eedc5b6f1a6
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: rscyacc.cxx,v $
10 * $Revision: 1.10 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_rsc.hxx"
33 #include <stdio.h>
34 #include <ctype.h>
35 #include <string.h>
37 #include <tools/rc.h>
38 #include <rscerror.h>
39 #include <rsctools.hxx>
40 #include <rscclass.hxx>
41 #include <rsccont.hxx>
42 #include <rsctree.hxx>
43 #include <rscdb.hxx>
44 #include <rscdef.hxx>
45 #include <rscpar.hxx>
47 #include "rsclex.hxx"
49 /************** V a r i a b l e n ****************************************/
50 ObjectStack S;
51 RscTop * pCurClass;
52 sal_uInt32 nCurMask;
53 char szErrBuf[ 100 ];
55 /************** H i l f s F u n k t i o n e n ****************************/
56 RSCINST GetVarInst( const RSCINST & rInst, const char * pVarName )
58 RSCINST aInst;
60 aInst = rInst.pClass->GetVariable( rInst, pHS->getID( pVarName ),
61 RSCINST() );
63 if( !aInst.pData )
64 pTC->pEH->Error( ERR_NOVARIABLENAME, rInst.pClass, RscId() );
66 return( aInst );
69 void SetNumber( const RSCINST & rInst, const char * pVarName, INT32 lValue )
71 RSCINST aInst;
73 aInst = GetVarInst( rInst, pVarName );
75 if( aInst.pData ){
76 ERRTYPE aError;
77 aError = aInst.pClass->SetNumber( aInst, lValue );
79 if( aError.IsError() )
80 pTC->pEH->Error( aError, aInst.pClass, RscId() );
84 void SetConst( const RSCINST & rInst, const char * pVarName,
85 Atom nValueId, INT32 nVal )
87 RSCINST aInst;
89 aInst = GetVarInst( rInst, pVarName );
90 if( aInst.pData )
92 ERRTYPE aError;
93 aError = aInst.pClass->SetConst( aInst, nValueId, nVal );
95 if( aError.IsError() )
96 pTC->pEH->Error( aError, aInst.pClass, RscId() );
100 void SetString( const RSCINST & rInst, const char * pVarName, const char * pStr )
102 RSCINST aInst;
104 aInst = GetVarInst( rInst, pVarName );
105 if( aInst.pData ){
106 ERRTYPE aError;
107 aError = aInst.pClass->SetString( aInst, pStr );
109 if( aError.IsError() )
110 pTC->pEH->Error( aError, aInst.pClass, RscId() );
114 RscId MakeRscId( RscExpType aExpType )
116 if( !aExpType.IsNothing() ){
117 INT32 lValue;
119 if( !aExpType.Evaluate( &lValue ) )
120 pTC->pEH->Error( ERR_ZERODIVISION, NULL, RscId() );
121 if( lValue < 1 || lValue > (INT32)0x7FFF )
123 pTC->pEH->Error( ERR_IDRANGE, NULL, RscId(),
124 ByteString::CreateFromInt32( lValue ).GetBuffer() );
127 if( aExpType.IsDefinition() )
128 return RscId( aExpType.aExp.pDef );
129 else
130 return RscId( lValue );
132 return RscId();
135 BOOL DoClassHeader( RSCHEADER * pHeader, BOOL bMember )
137 RSCINST aCopyInst;
138 RscId aName1 = MakeRscId( pHeader->nName1 );
139 RscId aName2 = MakeRscId( pHeader->nName2 );
141 if( pHeader->pRefClass )
142 aCopyInst.pClass = pHeader->pRefClass;
143 else
144 aCopyInst.pClass = pHeader->pClass;
146 if( TYPE_COPY == pHeader->nTyp )
148 ObjNode * pCopyObj = aCopyInst.pClass->GetObjNode( aName2 );
150 if( !pCopyObj )
152 ByteString aMsg( pHS->getString( aCopyInst.pClass->GetId() ) );
153 aMsg += ' ';
154 aMsg += aName2.GetName();
155 pTC->pEH->Error( ERR_NOCOPYOBJ, pHeader->pClass, aName1,
156 aMsg.GetBuffer() );
158 else
159 aCopyInst.pData = pCopyObj->GetRscObj();
162 if( bMember )
164 // Angabe von Superklassen oder abgeleiteten Klassen ist jetzt erlaubt
165 if( S.Top().pClass->InHierarchy( pHeader->pClass )
166 || pHeader->pClass->InHierarchy( S.Top().pClass) )
168 if( aCopyInst.IsInst() )
170 RSCINST aTmpI( S.Top() );
171 aTmpI.pClass->Destroy( aTmpI );
172 aTmpI.pClass->Create( &aTmpI, aCopyInst );
175 else
176 pTC->pEH->Error( ERR_FALSETYPE, S.Top().pClass, aName1,
177 pHS->getString( pHeader->pClass->GetId() ) );
179 else
181 if( S.IsEmpty() )
183 if( (INT32)aName1 < 256 )
184 pTC->pEH->Error( WRN_GLOBALID, pHeader->pClass, aName1 );
186 if( aCopyInst.IsInst() )
187 S.Push( pHeader->pClass->Create( NULL, aCopyInst ) );
188 else
189 S.Push( pHeader->pClass->Create( NULL, RSCINST() ) );
191 ObjNode * pNode = new ObjNode( aName1, S.Top().pData,
192 pFI->GetFileIndex() );
193 pTC->pEH->StdOut( ".", RscVerbosityVerbose );
195 if( !aName1.IsId() )
196 pTC->pEH->Error( ERR_IDEXPECTED, pHeader->pClass, aName1 );
197 else if( !pHeader->pClass->PutObjNode( pNode ) )
198 pTC->pEH->Error( ERR_DOUBLEID, pHeader->pClass, aName1 );
200 else
202 RSCINST aTmpI;
203 ERRTYPE aError;
205 if( (INT32)aName1 >= 256 && aName1.IsId() )
206 pTC->pEH->Error( WRN_LOCALID, pHeader->pClass, aName1 );
207 aError = S.Top().pClass->GetElement( S.Top(), aName1,
208 pHeader->pClass, aCopyInst, &aTmpI );
210 if( aError.IsWarning() )
211 pTC->pEH->Error( aError, pHeader->pClass, aName1 );
212 else if( aError.IsError() )
214 if( ERR_CONT_INVALIDTYPE == aError )
215 pTC->pEH->Error( aError, S.Top().pClass, aName1,
216 pHS->getString( pHeader->pClass->GetId() ) );
217 else
218 pTC->pEH->Error( aError, S.Top().pClass, aName1 );
219 S.Top().pClass->GetElement( S.Top(), RscId(),
220 pHeader->pClass, RSCINST(), &aTmpI );
222 if( !aTmpI.IsInst() )
223 return( FALSE );
225 S.Push( aTmpI );
228 if( TYPE_REF == pHeader->nTyp )
230 ERRTYPE aError;
232 aError = S.Top().pClass->SetRef( S.Top(), aName2 );
233 pTC->pEH->Error( aError, S.Top().pClass, aName1 );
236 return( TRUE );
239 RSCINST GetFirstTupelEle( const RSCINST & rTop )
240 { // Aufwaertskompatible, Tupel probieren
241 RSCINST aInst;
242 ERRTYPE aErr;
244 aErr = rTop.pClass->GetElement( rTop, RscId(), NULL, RSCINST(), &aInst );
245 if( !aErr.IsError() )
246 aInst = aInst.pClass->GetTupelVar( aInst, 0, RSCINST() );
247 return aInst;
250 /************** Y a c c C o d e ****************************************/
251 //#define YYDEBUG 1
253 #define TYPE_Atom 0
254 #define TYPE_RESID 1
256 #ifdef UNX
257 #define YYMAXDEPTH 2000
258 #else
259 #ifdef W30
260 #define YYMAXDEPTH 300
261 #else
262 #define YYMAXDEPTH 800
263 #endif
264 #endif
266 #if defined _MSC_VER
267 #pragma warning(push, 1)
268 #pragma warning(disable:4129 4273 4701)
269 #endif
270 #include "yyrscyacc.cxx"
271 #if defined _MSC_VER
272 #pragma warning(pop)
273 #endif