xref: /aoo42x/main/rsc/source/parser/rscyacc.cxx (revision 477794c1)
1*477794c1SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*477794c1SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*477794c1SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*477794c1SAndrew Rist  * distributed with this work for additional information
6*477794c1SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*477794c1SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*477794c1SAndrew Rist  * "License"); you may not use this file except in compliance
9*477794c1SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*477794c1SAndrew Rist  *
11*477794c1SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*477794c1SAndrew Rist  *
13*477794c1SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*477794c1SAndrew Rist  * software distributed under the License is distributed on an
15*477794c1SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*477794c1SAndrew Rist  * KIND, either express or implied.  See the License for the
17*477794c1SAndrew Rist  * specific language governing permissions and limitations
18*477794c1SAndrew Rist  * under the License.
19*477794c1SAndrew Rist  *
20*477794c1SAndrew Rist  *************************************************************/
21*477794c1SAndrew Rist 
22*477794c1SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_rsc.hxx"
26cdf0e10cSrcweir #include <stdio.h>
27cdf0e10cSrcweir #include <ctype.h>
28cdf0e10cSrcweir #include <string.h>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <tools/rc.h>
31cdf0e10cSrcweir #include <rscerror.h>
32cdf0e10cSrcweir #include <rsctools.hxx>
33cdf0e10cSrcweir #include <rscclass.hxx>
34cdf0e10cSrcweir #include <rsccont.hxx>
35cdf0e10cSrcweir #include <rsctree.hxx>
36cdf0e10cSrcweir #include <rscdb.hxx>
37cdf0e10cSrcweir #include <rscdef.hxx>
38cdf0e10cSrcweir #include <rscpar.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include "rsclex.hxx"
41cdf0e10cSrcweir 
42cdf0e10cSrcweir /************** V a r i a b l e n ****************************************/
43cdf0e10cSrcweir ObjectStack 					S;
44cdf0e10cSrcweir RscTop *						pCurClass;
45cdf0e10cSrcweir sal_uInt32						nCurMask;
46cdf0e10cSrcweir char							szErrBuf[ 100 ];
47cdf0e10cSrcweir 
48cdf0e10cSrcweir /************** H i l f s F u n k t i o n e n ****************************/
GetVarInst(const RSCINST & rInst,const char * pVarName)49cdf0e10cSrcweir RSCINST GetVarInst( const RSCINST & rInst, const char * pVarName )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 	RSCINST aInst;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	aInst = rInst.pClass->GetVariable( rInst, pHS->getID( pVarName ),
54cdf0e10cSrcweir 									   RSCINST() );
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	if( !aInst.pData )
57cdf0e10cSrcweir 		pTC->pEH->Error( ERR_NOVARIABLENAME, rInst.pClass, RscId() );
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	return( aInst );
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
SetNumber(const RSCINST & rInst,const char * pVarName,sal_Int32 lValue)62cdf0e10cSrcweir void SetNumber( const RSCINST & rInst, const char * pVarName, sal_Int32 lValue )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 	RSCINST aInst;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 	aInst = GetVarInst( rInst, pVarName );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	if( aInst.pData ){
69cdf0e10cSrcweir 		ERRTYPE aError;
70cdf0e10cSrcweir 		aError = aInst.pClass->SetNumber( aInst, lValue );
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 		if( aError.IsError() )
73cdf0e10cSrcweir 			pTC->pEH->Error( aError, aInst.pClass, RscId() );
74cdf0e10cSrcweir 	}
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
SetConst(const RSCINST & rInst,const char * pVarName,Atom nValueId,sal_Int32 nVal)77cdf0e10cSrcweir void SetConst( const RSCINST & rInst, const char * pVarName,
78cdf0e10cSrcweir 			   Atom nValueId, sal_Int32 nVal )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	RSCINST aInst;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	aInst = GetVarInst( rInst, pVarName );
83cdf0e10cSrcweir 	if( aInst.pData )
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 		ERRTYPE aError;
86cdf0e10cSrcweir 		aError = aInst.pClass->SetConst( aInst, nValueId, nVal );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 		if( aError.IsError() )
89cdf0e10cSrcweir 			pTC->pEH->Error( aError, aInst.pClass, RscId() );
90cdf0e10cSrcweir 	}
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
SetString(const RSCINST & rInst,const char * pVarName,const char * pStr)93cdf0e10cSrcweir void SetString( const RSCINST & rInst, const char * pVarName, const char * pStr )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	RSCINST aInst;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	aInst = GetVarInst( rInst, pVarName );
98cdf0e10cSrcweir 	if( aInst.pData ){
99cdf0e10cSrcweir 		ERRTYPE aError;
100cdf0e10cSrcweir 		aError = aInst.pClass->SetString( aInst, pStr );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 		if( aError.IsError() )
103cdf0e10cSrcweir 			pTC->pEH->Error( aError, aInst.pClass, RscId() );
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
MakeRscId(RscExpType aExpType)107cdf0e10cSrcweir RscId MakeRscId( RscExpType aExpType )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	if( !aExpType.IsNothing() ){
110cdf0e10cSrcweir 		sal_Int32		lValue;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 		if( !aExpType.Evaluate( &lValue ) )
113cdf0e10cSrcweir 			pTC->pEH->Error( ERR_ZERODIVISION, NULL, RscId() );
114cdf0e10cSrcweir 		if( lValue < 1 || lValue > (sal_Int32)0x7FFF )
115cdf0e10cSrcweir 		{
116cdf0e10cSrcweir 			pTC->pEH->Error( ERR_IDRANGE, NULL, RscId(),
117cdf0e10cSrcweir 							 ByteString::CreateFromInt32( lValue ).GetBuffer() );
118cdf0e10cSrcweir 		}
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 		if( aExpType.IsDefinition() )
121cdf0e10cSrcweir 			return RscId( aExpType.aExp.pDef );
122cdf0e10cSrcweir 		else
123cdf0e10cSrcweir 			return RscId( lValue );
124cdf0e10cSrcweir 	}
125cdf0e10cSrcweir 	return RscId();
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
DoClassHeader(RSCHEADER * pHeader,sal_Bool bMember)128cdf0e10cSrcweir sal_Bool DoClassHeader( RSCHEADER * pHeader, sal_Bool bMember )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir 	RSCINST aCopyInst;
131cdf0e10cSrcweir 	RscId aName1 = MakeRscId( pHeader->nName1 );
132cdf0e10cSrcweir 	RscId aName2 = MakeRscId( pHeader->nName2 );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	if( pHeader->pRefClass )
135cdf0e10cSrcweir 		aCopyInst.pClass = pHeader->pRefClass;
136cdf0e10cSrcweir 	else
137cdf0e10cSrcweir 		aCopyInst.pClass = pHeader->pClass;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	if( TYPE_COPY == pHeader->nTyp )
140cdf0e10cSrcweir 	{
141cdf0e10cSrcweir 		ObjNode * pCopyObj = aCopyInst.pClass->GetObjNode( aName2 );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 		if( !pCopyObj )
144cdf0e10cSrcweir 		{
145cdf0e10cSrcweir 			ByteString aMsg( pHS->getString( aCopyInst.pClass->GetId() ) );
146cdf0e10cSrcweir 			aMsg += ' ';
147cdf0e10cSrcweir 			aMsg += aName2.GetName();
148cdf0e10cSrcweir 			pTC->pEH->Error( ERR_NOCOPYOBJ, pHeader->pClass, aName1,
149cdf0e10cSrcweir 							 aMsg.GetBuffer() );
150cdf0e10cSrcweir 		}
151cdf0e10cSrcweir 		else
152cdf0e10cSrcweir 			aCopyInst.pData = pCopyObj->GetRscObj();
153cdf0e10cSrcweir 	}
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	if( bMember )
156cdf0e10cSrcweir 	{
157cdf0e10cSrcweir 		// Angabe von Superklassen oder abgeleiteten Klassen ist jetzt erlaubt
158cdf0e10cSrcweir 		if( S.Top().pClass->InHierarchy( pHeader->pClass )
159cdf0e10cSrcweir 		  ||  pHeader->pClass->InHierarchy( S.Top().pClass) )
160cdf0e10cSrcweir 		{
161cdf0e10cSrcweir 			if( aCopyInst.IsInst() )
162cdf0e10cSrcweir 			{
163cdf0e10cSrcweir 				RSCINST aTmpI( S.Top() );
164cdf0e10cSrcweir 				aTmpI.pClass->Destroy( aTmpI );
165cdf0e10cSrcweir 				aTmpI.pClass->Create( &aTmpI, aCopyInst );
166cdf0e10cSrcweir 			};
167cdf0e10cSrcweir 		}
168cdf0e10cSrcweir 		else
169cdf0e10cSrcweir 			pTC->pEH->Error( ERR_FALSETYPE, S.Top().pClass, aName1,
170cdf0e10cSrcweir 							 pHS->getString( pHeader->pClass->GetId() ) );
171cdf0e10cSrcweir 	}
172cdf0e10cSrcweir 	else
173cdf0e10cSrcweir 	{
174cdf0e10cSrcweir 		if( S.IsEmpty() )
175cdf0e10cSrcweir 		{
176cdf0e10cSrcweir 			if( (sal_Int32)aName1 < 256 )
177cdf0e10cSrcweir 				pTC->pEH->Error( WRN_GLOBALID, pHeader->pClass, aName1 );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 			if( aCopyInst.IsInst() )
180cdf0e10cSrcweir 				S.Push( pHeader->pClass->Create( NULL, aCopyInst ) );
181cdf0e10cSrcweir 			else
182cdf0e10cSrcweir 				S.Push( pHeader->pClass->Create( NULL, RSCINST() ) );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 			ObjNode * pNode = new ObjNode( aName1, S.Top().pData,
185cdf0e10cSrcweir 										   pFI->GetFileIndex() );
186cdf0e10cSrcweir 			pTC->pEH->StdOut( ".", RscVerbosityVerbose );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 			if( !aName1.IsId() )
189cdf0e10cSrcweir 				pTC->pEH->Error( ERR_IDEXPECTED, pHeader->pClass, aName1 );
190cdf0e10cSrcweir 			else if( !pHeader->pClass->PutObjNode( pNode ) )
191cdf0e10cSrcweir 				pTC->pEH->Error( ERR_DOUBLEID, pHeader->pClass, aName1 );
192cdf0e10cSrcweir 		}
193cdf0e10cSrcweir 		else
194cdf0e10cSrcweir 		{
195cdf0e10cSrcweir 			RSCINST aTmpI;
196cdf0e10cSrcweir 			ERRTYPE aError;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 			if( (sal_Int32)aName1 >= 256 && aName1.IsId() )
199cdf0e10cSrcweir 				pTC->pEH->Error( WRN_LOCALID, pHeader->pClass, aName1 );
200cdf0e10cSrcweir 			aError = S.Top().pClass->GetElement( S.Top(), aName1,
201cdf0e10cSrcweir 												 pHeader->pClass, aCopyInst, &aTmpI );
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 			if( aError.IsWarning() )
204cdf0e10cSrcweir 				pTC->pEH->Error( aError, pHeader->pClass, aName1 );
205cdf0e10cSrcweir 			else if( aError.IsError() )
206cdf0e10cSrcweir 			{
207cdf0e10cSrcweir 				if( ERR_CONT_INVALIDTYPE == aError )
208cdf0e10cSrcweir 					pTC->pEH->Error( aError, S.Top().pClass, aName1,
209cdf0e10cSrcweir 									 pHS->getString( pHeader->pClass->GetId() ) );
210cdf0e10cSrcweir 				else
211cdf0e10cSrcweir 					pTC->pEH->Error( aError, S.Top().pClass, aName1 );
212cdf0e10cSrcweir 				S.Top().pClass->GetElement( S.Top(), RscId(),
213cdf0e10cSrcweir 											pHeader->pClass, RSCINST(), &aTmpI );
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 				if( !aTmpI.IsInst() )
216cdf0e10cSrcweir 					return( sal_False );
217cdf0e10cSrcweir 			}
218cdf0e10cSrcweir 			S.Push( aTmpI );
219cdf0e10cSrcweir 		};
220cdf0e10cSrcweir 	};
221cdf0e10cSrcweir 	if( TYPE_REF == pHeader->nTyp )
222cdf0e10cSrcweir 	{
223cdf0e10cSrcweir 		ERRTYPE aError;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 		aError = S.Top().pClass->SetRef( S.Top(), aName2 );
226cdf0e10cSrcweir 		pTC->pEH->Error( aError, S.Top().pClass, aName1 );
227cdf0e10cSrcweir 	}
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 	return( sal_True );
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
GetFirstTupelEle(const RSCINST & rTop)232cdf0e10cSrcweir RSCINST GetFirstTupelEle( const RSCINST & rTop )
233cdf0e10cSrcweir { // Aufwaertskompatible, Tupel probieren
234cdf0e10cSrcweir 	RSCINST aInst;
235cdf0e10cSrcweir 	ERRTYPE aErr;
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 	aErr = rTop.pClass->GetElement( rTop, RscId(), NULL, RSCINST(), &aInst );
238cdf0e10cSrcweir 	if( !aErr.IsError() )
239cdf0e10cSrcweir 		aInst = aInst.pClass->GetTupelVar( aInst, 0, RSCINST() );
240cdf0e10cSrcweir 	return aInst;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir /************** Y a c c   C o d e ****************************************/
244cdf0e10cSrcweir //#define YYDEBUG 1
245cdf0e10cSrcweir 
246cdf0e10cSrcweir #define TYPE_Atom 			  0
247cdf0e10cSrcweir #define TYPE_RESID				  1
248cdf0e10cSrcweir 
249cdf0e10cSrcweir #ifdef UNX
250cdf0e10cSrcweir #define YYMAXDEPTH				2000
251cdf0e10cSrcweir #else
252cdf0e10cSrcweir #define YYMAXDEPTH				800
253cdf0e10cSrcweir #endif
254cdf0e10cSrcweir 
255cdf0e10cSrcweir #if defined _MSC_VER
256cdf0e10cSrcweir #pragma warning(push, 1)
257cdf0e10cSrcweir #pragma warning(disable:4129 4273 4701)
258cdf0e10cSrcweir #endif
259cdf0e10cSrcweir #include "yyrscyacc.cxx"
260cdf0e10cSrcweir #if defined _MSC_VER
261cdf0e10cSrcweir #pragma warning(pop)
262cdf0e10cSrcweir #endif
263cdf0e10cSrcweir 
264