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