xref: /aoo42x/main/rsc/source/parser/rscyacc.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
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>
33 
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>
43 
44 #include "rsclex.hxx"
45 
46 /************** V a r i a b l e n ****************************************/
47 ObjectStack 					S;
48 RscTop *						pCurClass;
49 sal_uInt32						nCurMask;
50 char							szErrBuf[ 100 ];
51 
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 )
54 {
55 	RSCINST aInst;
56 
57 	aInst = rInst.pClass->GetVariable( rInst, pHS->getID( pVarName ),
58 									   RSCINST() );
59 
60 	if( !aInst.pData )
61 		pTC->pEH->Error( ERR_NOVARIABLENAME, rInst.pClass, RscId() );
62 
63 	return( aInst );
64 }
65 
66 void SetNumber( const RSCINST & rInst, const char * pVarName, sal_Int32 lValue )
67 {
68 	RSCINST aInst;
69 
70 	aInst = GetVarInst( rInst, pVarName );
71 
72 	if( aInst.pData ){
73 		ERRTYPE aError;
74 		aError = aInst.pClass->SetNumber( aInst, lValue );
75 
76 		if( aError.IsError() )
77 			pTC->pEH->Error( aError, aInst.pClass, RscId() );
78 	}
79 }
80 
81 void SetConst( const RSCINST & rInst, const char * pVarName,
82 			   Atom nValueId, sal_Int32 nVal )
83 {
84 	RSCINST aInst;
85 
86 	aInst = GetVarInst( rInst, pVarName );
87 	if( aInst.pData )
88 	{
89 		ERRTYPE aError;
90 		aError = aInst.pClass->SetConst( aInst, nValueId, nVal );
91 
92 		if( aError.IsError() )
93 			pTC->pEH->Error( aError, aInst.pClass, RscId() );
94 	}
95 }
96 
97 void SetString( const RSCINST & rInst, const char * pVarName, const char * pStr )
98 {
99 	RSCINST aInst;
100 
101 	aInst = GetVarInst( rInst, pVarName );
102 	if( aInst.pData ){
103 		ERRTYPE aError;
104 		aError = aInst.pClass->SetString( aInst, pStr );
105 
106 		if( aError.IsError() )
107 			pTC->pEH->Error( aError, aInst.pClass, RscId() );
108 	}
109 }
110 
111 RscId MakeRscId( RscExpType aExpType )
112 {
113 	if( !aExpType.IsNothing() ){
114 		sal_Int32		lValue;
115 
116 		if( !aExpType.Evaluate( &lValue ) )
117 			pTC->pEH->Error( ERR_ZERODIVISION, NULL, RscId() );
118 		if( lValue < 1 || lValue > (sal_Int32)0x7FFF )
119 		{
120 			pTC->pEH->Error( ERR_IDRANGE, NULL, RscId(),
121 							 ByteString::CreateFromInt32( lValue ).GetBuffer() );
122 		}
123 
124 		if( aExpType.IsDefinition() )
125 			return RscId( aExpType.aExp.pDef );
126 		else
127 			return RscId( lValue );
128 	}
129 	return RscId();
130 }
131 
132 sal_Bool DoClassHeader( RSCHEADER * pHeader, sal_Bool bMember )
133 {
134 	RSCINST aCopyInst;
135 	RscId aName1 = MakeRscId( pHeader->nName1 );
136 	RscId aName2 = MakeRscId( pHeader->nName2 );
137 
138 	if( pHeader->pRefClass )
139 		aCopyInst.pClass = pHeader->pRefClass;
140 	else
141 		aCopyInst.pClass = pHeader->pClass;
142 
143 	if( TYPE_COPY == pHeader->nTyp )
144 	{
145 		ObjNode * pCopyObj = aCopyInst.pClass->GetObjNode( aName2 );
146 
147 		if( !pCopyObj )
148 		{
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() );
154 		}
155 		else
156 			aCopyInst.pData = pCopyObj->GetRscObj();
157 	}
158 
159 	if( bMember )
160 	{
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) )
164 		{
165 			if( aCopyInst.IsInst() )
166 			{
167 				RSCINST aTmpI( S.Top() );
168 				aTmpI.pClass->Destroy( aTmpI );
169 				aTmpI.pClass->Create( &aTmpI, aCopyInst );
170 			};
171 		}
172 		else
173 			pTC->pEH->Error( ERR_FALSETYPE, S.Top().pClass, aName1,
174 							 pHS->getString( pHeader->pClass->GetId() ) );
175 	}
176 	else
177 	{
178 		if( S.IsEmpty() )
179 		{
180 			if( (sal_Int32)aName1 < 256 )
181 				pTC->pEH->Error( WRN_GLOBALID, pHeader->pClass, aName1 );
182 
183 			if( aCopyInst.IsInst() )
184 				S.Push( pHeader->pClass->Create( NULL, aCopyInst ) );
185 			else
186 				S.Push( pHeader->pClass->Create( NULL, RSCINST() ) );
187 
188 			ObjNode * pNode = new ObjNode( aName1, S.Top().pData,
189 										   pFI->GetFileIndex() );
190 			pTC->pEH->StdOut( ".", RscVerbosityVerbose );
191 
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 );
196 		}
197 		else
198 		{
199 			RSCINST aTmpI;
200 			ERRTYPE aError;
201 
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 );
206 
207 			if( aError.IsWarning() )
208 				pTC->pEH->Error( aError, pHeader->pClass, aName1 );
209 			else if( aError.IsError() )
210 			{
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 );
218 
219 				if( !aTmpI.IsInst() )
220 					return( sal_False );
221 			}
222 			S.Push( aTmpI );
223 		};
224 	};
225 	if( TYPE_REF == pHeader->nTyp )
226 	{
227 		ERRTYPE aError;
228 
229 		aError = S.Top().pClass->SetRef( S.Top(), aName2 );
230 		pTC->pEH->Error( aError, S.Top().pClass, aName1 );
231 	}
232 
233 	return( sal_True );
234 }
235 
236 RSCINST GetFirstTupelEle( const RSCINST & rTop )
237 { // Aufwaertskompatible, Tupel probieren
238 	RSCINST aInst;
239 	ERRTYPE aErr;
240 
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;
245 }
246 
247 /************** Y a c c   C o d e ****************************************/
248 //#define YYDEBUG 1
249 
250 #define TYPE_Atom 			  0
251 #define TYPE_RESID				  1
252 
253 #ifdef UNX
254 #define YYMAXDEPTH				2000
255 #else
256 #define YYMAXDEPTH				800
257 #endif
258 
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
267 
268