CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / rsc / source / parser / rscyacc.cxx
blob63be87f436496a293bcdd2e23a9d26c2037a00ea
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_rsc.hxx"
30 #include <stdio.h>
31 #include <ctype.h>
32 #include <string.h>
34 #include <tools/rc.h>
35 #include <rscerror.h>
36 #include <rsctools.hxx>
37 #include <rscclass.hxx>
38 #include <rsccont.hxx>
39 #include <rsctree.hxx>
40 #include <rscdb.hxx>
41 #include <rscdef.hxx>
42 #include <rscpar.hxx>
44 #include "rsclex.hxx"
46 /************** V a r i a b l e n ****************************************/
47 ObjectStack S;
48 RscTop * pCurClass;
49 sal_uInt32 nCurMask;
50 char szErrBuf[ 100 ];
52 /************** H i l f s F u n k t i o n e n ****************************/
53 RSCINST GetVarInst( const RSCINST & rInst, const char * pVarName )
55 RSCINST aInst;
57 aInst = rInst.pClass->GetVariable( rInst, pHS->getID( pVarName ),
58 RSCINST() );
60 if( !aInst.pData )
61 pTC->pEH->Error( ERR_NOVARIABLENAME, rInst.pClass, RscId() );
63 return( aInst );
66 void SetNumber( const RSCINST & rInst, const char * pVarName, sal_Int32 lValue )
68 RSCINST aInst;
70 aInst = GetVarInst( rInst, pVarName );
72 if( aInst.pData ){
73 ERRTYPE aError;
74 aError = aInst.pClass->SetNumber( aInst, lValue );
76 if( aError.IsError() )
77 pTC->pEH->Error( aError, aInst.pClass, RscId() );
81 void SetConst( const RSCINST & rInst, const char * pVarName,
82 Atom nValueId, sal_Int32 nVal )
84 RSCINST aInst;
86 aInst = GetVarInst( rInst, pVarName );
87 if( aInst.pData )
89 ERRTYPE aError;
90 aError = aInst.pClass->SetConst( aInst, nValueId, nVal );
92 if( aError.IsError() )
93 pTC->pEH->Error( aError, aInst.pClass, RscId() );
97 void SetString( const RSCINST & rInst, const char * pVarName, const char * pStr )
99 RSCINST aInst;
101 aInst = GetVarInst( rInst, pVarName );
102 if( aInst.pData ){
103 ERRTYPE aError;
104 aError = aInst.pClass->SetString( aInst, pStr );
106 if( aError.IsError() )
107 pTC->pEH->Error( aError, aInst.pClass, RscId() );
111 RscId MakeRscId( RscExpType aExpType )
113 if( !aExpType.IsNothing() ){
114 sal_Int32 lValue;
116 if( !aExpType.Evaluate( &lValue ) )
117 pTC->pEH->Error( ERR_ZERODIVISION, NULL, RscId() );
118 if( lValue < 1 || lValue > (sal_Int32)0x7FFF )
120 pTC->pEH->Error( ERR_IDRANGE, NULL, RscId(),
121 ByteString::CreateFromInt32( lValue ).GetBuffer() );
124 if( aExpType.IsDefinition() )
125 return RscId( aExpType.aExp.pDef );
126 else
127 return RscId( lValue );
129 return RscId();
132 sal_Bool DoClassHeader( RSCHEADER * pHeader, sal_Bool bMember )
134 RSCINST aCopyInst;
135 RscId aName1 = MakeRscId( pHeader->nName1 );
136 RscId aName2 = MakeRscId( pHeader->nName2 );
138 if( pHeader->pRefClass )
139 aCopyInst.pClass = pHeader->pRefClass;
140 else
141 aCopyInst.pClass = pHeader->pClass;
143 if( TYPE_COPY == pHeader->nTyp )
145 ObjNode * pCopyObj = aCopyInst.pClass->GetObjNode( aName2 );
147 if( !pCopyObj )
149 ByteString aMsg( pHS->getString( aCopyInst.pClass->GetId() ) );
150 aMsg += ' ';
151 aMsg += aName2.GetName();
152 pTC->pEH->Error( ERR_NOCOPYOBJ, pHeader->pClass, aName1,
153 aMsg.GetBuffer() );
155 else
156 aCopyInst.pData = pCopyObj->GetRscObj();
159 if( bMember )
161 // Angabe von Superklassen oder abgeleiteten Klassen ist jetzt erlaubt
162 if( S.Top().pClass->InHierarchy( pHeader->pClass )
163 || pHeader->pClass->InHierarchy( S.Top().pClass) )
165 if( aCopyInst.IsInst() )
167 RSCINST aTmpI( S.Top() );
168 aTmpI.pClass->Destroy( aTmpI );
169 aTmpI.pClass->Create( &aTmpI, aCopyInst );
172 else
173 pTC->pEH->Error( ERR_FALSETYPE, S.Top().pClass, aName1,
174 pHS->getString( pHeader->pClass->GetId() ) );
176 else
178 if( S.IsEmpty() )
180 if( (sal_Int32)aName1 < 256 )
181 pTC->pEH->Error( WRN_GLOBALID, pHeader->pClass, aName1 );
183 if( aCopyInst.IsInst() )
184 S.Push( pHeader->pClass->Create( NULL, aCopyInst ) );
185 else
186 S.Push( pHeader->pClass->Create( NULL, RSCINST() ) );
188 ObjNode * pNode = new ObjNode( aName1, S.Top().pData,
189 pFI->GetFileIndex() );
190 pTC->pEH->StdOut( ".", RscVerbosityVerbose );
192 if( !aName1.IsId() )
193 pTC->pEH->Error( ERR_IDEXPECTED, pHeader->pClass, aName1 );
194 else if( !pHeader->pClass->PutObjNode( pNode ) )
195 pTC->pEH->Error( ERR_DOUBLEID, pHeader->pClass, aName1 );
197 else
199 RSCINST aTmpI;
200 ERRTYPE aError;
202 if( (sal_Int32)aName1 >= 256 && aName1.IsId() )
203 pTC->pEH->Error( WRN_LOCALID, pHeader->pClass, aName1 );
204 aError = S.Top().pClass->GetElement( S.Top(), aName1,
205 pHeader->pClass, aCopyInst, &aTmpI );
207 if( aError.IsWarning() )
208 pTC->pEH->Error( aError, pHeader->pClass, aName1 );
209 else if( aError.IsError() )
211 if( ERR_CONT_INVALIDTYPE == aError )
212 pTC->pEH->Error( aError, S.Top().pClass, aName1,
213 pHS->getString( pHeader->pClass->GetId() ) );
214 else
215 pTC->pEH->Error( aError, S.Top().pClass, aName1 );
216 S.Top().pClass->GetElement( S.Top(), RscId(),
217 pHeader->pClass, RSCINST(), &aTmpI );
219 if( !aTmpI.IsInst() )
220 return( sal_False );
222 S.Push( aTmpI );
225 if( TYPE_REF == pHeader->nTyp )
227 ERRTYPE aError;
229 aError = S.Top().pClass->SetRef( S.Top(), aName2 );
230 pTC->pEH->Error( aError, S.Top().pClass, aName1 );
233 return( sal_True );
236 RSCINST GetFirstTupelEle( const RSCINST & rTop )
237 { // Aufwaertskompatible, Tupel probieren
238 RSCINST aInst;
239 ERRTYPE aErr;
241 aErr = rTop.pClass->GetElement( rTop, RscId(), NULL, RSCINST(), &aInst );
242 if( !aErr.IsError() )
243 aInst = aInst.pClass->GetTupelVar( aInst, 0, RSCINST() );
244 return aInst;
247 /************** Y a c c C o d e ****************************************/
248 //#define YYDEBUG 1
250 #define TYPE_Atom 0
251 #define TYPE_RESID 1
253 #ifdef UNX
254 #define YYMAXDEPTH 2000
255 #else
256 #define YYMAXDEPTH 800
257 #endif
259 #if defined _MSC_VER
260 #pragma warning(push, 1)
261 #pragma warning(disable:4129 4273 4701)
262 #endif
263 #include "yyrscyacc.cxx"
264 #if defined _MSC_VER
265 #pragma warning(pop)
266 #endif