bump product version to 5.0.4.1
[LibreOffice.git] / rsc / source / parser / rscyacc.y
blobc084d9b2e9886939066474525ddc10a5ecf44790
1 %{
2 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 /*
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "sal/config.h"
23 #include <stdio.h>
24 #include <ctype.h>
25 #include <string.h>
27 #include <rtl/strbuf.hxx>
28 #include <tools/rc.h>
29 #include <rscerror.h>
30 #include <rsctools.hxx>
31 #include <rscclass.hxx>
32 #include <rsccont.hxx>
33 #include <rsctree.hxx>
34 #include <rscdb.hxx>
35 #include <rscdef.hxx>
36 #include <rscpar.hxx>
38 #include <rsclex.hxx>
40 ObjectStack S;
41 RscTop * pCurClass;
42 sal_uInt32 nCurMask;
43 char szErrBuf[ 100 ];
45 RSCINST GetVarInst( const RSCINST & rInst, const char * pVarName )
47 RSCINST aInst;
49 aInst = rInst.pClass->GetVariable( rInst, pHS->getID( pVarName ),
50 RSCINST() );
52 if( !aInst.pData )
53 pTC->pEH->Error( ERR_NOVARIABLENAME, rInst.pClass, RscId() );
55 return aInst;
58 void SetNumber( const RSCINST & rInst, const char * pVarName, sal_Int32 lValue )
60 RSCINST aInst;
62 aInst = GetVarInst( rInst, pVarName );
64 if( aInst.pData )
66 ERRTYPE aError;
67 aError = aInst.pClass->SetNumber( aInst, lValue );
69 if( aError.IsError() )
70 pTC->pEH->Error( aError, aInst.pClass, RscId() );
74 void SetConst( const RSCINST & rInst, const char * pVarName,
75 Atom nValueId, sal_Int32 nVal )
77 RSCINST aInst;
79 aInst = GetVarInst( rInst, pVarName );
80 if( aInst.pData )
82 ERRTYPE aError;
83 aError = aInst.pClass->SetConst( aInst, nValueId, nVal );
85 if( aError.IsError() )
86 pTC->pEH->Error( aError, aInst.pClass, RscId() );
90 void SetString( const RSCINST & rInst, const char * pVarName, const char * pStr )
92 RSCINST aInst;
94 aInst = GetVarInst( rInst, pVarName );
95 if( aInst.pData ){
96 ERRTYPE aError;
97 aError = aInst.pClass->SetString( aInst, pStr );
99 if( aError.IsError() )
100 pTC->pEH->Error( aError, aInst.pClass, RscId() );
104 RscId MakeRscId( RscExpType aExpType )
106 if( !aExpType.IsNothing() )
108 sal_Int32 lValue(0);
110 if( !aExpType.Evaluate( &lValue ) )
111 pTC->pEH->Error( ERR_ZERODIVISION, NULL, RscId() );
112 if( lValue < 1 || lValue > (sal_Int32)0x7FFF )
114 pTC->pEH->Error( ERR_IDRANGE, NULL, RscId(),
115 rtl::OString::number(lValue).getStr() );
118 if( aExpType.IsDefinition() )
119 return RscId( aExpType.aExp.pDef );
120 else
121 return RscId( lValue );
123 return RscId();
126 bool DoClassHeader( RSCHEADER * pHeader, bool bMember )
128 RSCINST aCopyInst;
129 RscId aName1 = MakeRscId( pHeader->nName1 );
130 RscId aName2 = MakeRscId( pHeader->nName2 );
132 if( pHeader->pRefClass )
133 aCopyInst.pClass = pHeader->pRefClass;
134 else
135 aCopyInst.pClass = pHeader->pClass;
137 if( TYPE_COPY == pHeader->nTyp )
139 ObjNode * pCopyObj = aCopyInst.pClass->GetObjNode( aName2 );
141 if( !pCopyObj )
143 rtl::OStringBuffer aMsg( pHS->getString( aCopyInst.pClass->GetId() ) );
144 aMsg.append(' ');
145 aMsg.append(aName2.GetName());
146 pTC->pEH->Error( ERR_NOCOPYOBJ, pHeader->pClass, aName1,
147 aMsg.getStr() );
149 else
150 aCopyInst.pData = pCopyObj->GetRscObj();
153 if( bMember )
155 // Angabe von Superklassen oder abgeleiteten Klassen ist jetzt erlaubt
156 if( S.Top().pClass->InHierarchy( pHeader->pClass ) ||
157 pHeader->pClass->InHierarchy( S.Top().pClass) )
159 if( aCopyInst.IsInst() )
161 RSCINST aTmpI( S.Top() );
162 aTmpI.pClass->Destroy( aTmpI );
163 aTmpI.pClass->Create( &aTmpI, aCopyInst );
166 else
167 pTC->pEH->Error( ERR_FALSETYPE, S.Top().pClass, aName1,
168 pHS->getString( pHeader->pClass->GetId() ).getStr() );
170 else
172 if( S.IsEmpty() )
174 if( (sal_Int32)aName1 < 256 )
175 pTC->pEH->Error( WRN_GLOBALID, pHeader->pClass, aName1 );
177 if( aCopyInst.IsInst() )
178 S.Push( pHeader->pClass->Create( NULL, aCopyInst ) );
179 else
180 S.Push( pHeader->pClass->Create( NULL, RSCINST() ) );
182 pTC->pEH->StdOut( ".", RscVerbosityVerbose );
184 if( !aName1.IsId() )
185 pTC->pEH->Error( ERR_IDEXPECTED, pHeader->pClass, aName1 );
186 else
188 ObjNode * pNode = new ObjNode( aName1, S.Top().pData,
189 pFI->GetFileIndex() );
190 if( !pHeader->pClass->PutObjNode( pNode ) )
191 pTC->pEH->Error( ERR_DOUBLEID, pHeader->pClass, aName1 );
194 else
196 RSCINST aTmpI;
197 ERRTYPE aError;
199 if( (sal_Int32)aName1 >= 256 && aName1.IsId() )
200 pTC->pEH->Error( WRN_LOCALID, pHeader->pClass, aName1 );
202 aError = S.Top().pClass->GetElement( S.Top(), aName1,
203 pHeader->pClass, aCopyInst, &aTmpI );
205 if( aError.IsWarning() )
207 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() ).getStr() );
214 else
215 pTC->pEH->Error( aError, S.Top().pClass, aName1 );
217 S.Top().pClass->GetElement( S.Top(), RscId(),
218 pHeader->pClass, RSCINST(), &aTmpI );
220 if( !aTmpI.IsInst() )
221 return false;
223 S.Push( aTmpI );
226 if( TYPE_REF == pHeader->nTyp )
228 ERRTYPE aError;
230 aError = S.Top().pClass->SetRef( S.Top(), aName2 );
231 pTC->pEH->Error( aError, S.Top().pClass, aName1 );
234 return true ;
237 RSCINST GetFirstTupelEle( const RSCINST & rTop )
238 { // Aufwaertskompatible, Tupel probieren
239 RSCINST aInst;
240 ERRTYPE aErr;
242 aErr = rTop.pClass->GetElement( rTop, RscId(), NULL, RSCINST(), &aInst );
243 if( !aErr.IsError() )
244 aInst = aInst.pClass->GetTupelVar( aInst, 0, RSCINST() );
245 return aInst;
248 //#define YYDEBUG 1
250 #ifdef UNX
251 #define YYMAXDEPTH 2000
252 #else
253 #define YYMAXDEPTH 800
254 #endif
256 #if defined _MSC_VER
257 #pragma warning(push, 1)
258 #pragma warning(disable:4129 4273 4701 4702)
259 #endif
260 #ifdef __GNUC__
261 #pragma GCC diagnostic ignored "-Wwrite-strings"
262 #endif
265 /* Compilerstack */
267 %union {
268 Atom varid;
269 struct {
270 Atom hashid;
271 sal_Int32 nValue;
272 } constname;
273 RscTop * pClass;
274 RSCHEADER header;
275 struct {
276 CLASS_DATA pData;
277 RscTop * pClass;
278 } instance;
279 sal_Int32 value;
280 sal_uInt16 ushort;
281 short exp_short;
282 char * string;
283 bool svbool;
284 REF_ENUM copyref;
285 RscDefine * defineele;
286 rtl_TextEncoding charset;
287 RscExpType macrostruct;
290 /* Token */
291 %token <value> NUMBER
292 %token <string> SYMBOL
293 %token <defineele> RSCDEFINE
294 %token <string> STRING
295 %token <string> INCLUDE_STRING
296 %token <character> CHARACTER
297 %token <svbool> BOOLEAN
299 %token LINE
300 %token AUTO_ID
301 %token NOT
302 %token XSCALE
303 %token YSCALE
304 %token RGB
305 %token GEOMETRY
306 %token POSITION
307 %token DIMENSION
308 %token INZOOMOUTPUTSIZE
309 %token FLOATINGPOS
310 %token DEFINE
311 %token INCLUDE
312 %token MACROTARGET
313 %token DEFAULT
316 %token <pClass> CLASSNAME
317 %token <varid> VARNAME
318 %token <constname> CONSTNAME
319 %token CLASS
320 %token EXTENDABLE
321 %token WRITEIFSET
324 %type <macrostruct> macro_expression
325 %type <macrostruct> id_expression
326 %type <value> long_expression
327 %type <string> string_multiline
329 %type <pClass> type
330 %type <pClass> type_base
331 %type <header> class_header_body
332 %type <header> class_header
333 %type <header> var_header_class
334 %type <copyref> copy_ref
335 %type <ushort> type_flags
338 %left '|'
339 %left '&'
340 %left LEFTSHIFT RIGHTSHIFT
341 %left '+' '-'
342 %left '*' '/'
343 %left UNARYMINUS
344 %left UNARYPLUS
345 %left ','
346 %left '(' ')'
349 /* Grammatik */
351 %start resource_definitions
355 resource_definitions
357 | resource_definitions resource_definition
358 | MACROTARGET macro_expression
360 RscExpType aExpType;
361 sal_Int32 lValue;
363 aExpType.cUnused = false;
364 aExpType.cType = RSCEXP_NOTHING;
365 pExp = new RscExpression( aExpType, '+', $2 );
366 if( !pExp->Evaluate( &lValue ) )
368 pTC->pEH->Error( ERR_ZERODIVISION, NULL, RscId() );
370 delete pExp;
374 resource_definition
375 : line_number
376 | '#' DEFINE SYMBOL macro_expression
378 bool bError = false;
380 if( $4.IsNumber() )
382 if( !pTC->aFileTab.NewDef( pFI->GetFileIndex(),
383 rtl::OString( $3 ),
384 $4.GetLong(), ULONG_MAX ) )
385 bError = true;
387 else if( $4.IsDefinition() )
389 RscExpType aExpType;
390 RscExpression * pExpr;
392 aExpType.cUnused = false;
393 aExpType.cType = RSCEXP_NOTHING;
394 aExpType.SetLong( 0 );
395 aExpType.cType = RSCEXP_LONG;
396 pExpr = new RscExpression( aExpType, '+', $4 );
398 if( !pTC->aFileTab.NewDef( pFI->GetFileIndex(),
399 rtl::OString( $3 ), pExpr, ULONG_MAX ) )
401 bError =true;
404 else if( $4.IsExpression() )
406 if( !pTC->aFileTab.NewDef( pFI->GetFileIndex(),
407 rtl::OString( $3 ), $4.aExp.pExp,
408 ULONG_MAX ) )
410 bError = true;
414 if( bError )
416 pTC->pEH->Error( ERR_DECLAREDEFINE, NULL, RscId(), $3 );
419 | '#' DEFINE RSCDEFINE macro_expression
421 pTC->pEH->Error( ERR_DOUBLEDEFINE, NULL, RscId(), $3->GetName().getStr() );
423 | '#' INCLUDE STRING
426 | '#' INCLUDE INCLUDE_STRING
429 | class_definition ';'
431 #ifdef D40
432 void * pMem;
433 pMem = rtl_allocateMemory( 20000 );
434 rtl_freeMemory( pMem );
435 #endif
437 | new_class_definition_header '{' new_class_definition_body '}' ';'
438 | new_class_definition_header ';'
441 new_class_definition_header
442 : CLASS SYMBOL id_expression ':' CLASSNAME
444 sal_Int32 lType;
446 $3.Evaluate( &lType );
448 // Klasse anlegen
449 Atom nId = pHS->getID( $2 );
450 pCurClass = new RscClass( nId, lType, $5 );
451 nCurMask = 1;
452 pTC->aNmTb.Put( nId, CLASSNAME, pCurClass );
453 pTC->GetRoot()->Insert( pCurClass );
455 | CLASS CLASSNAME id_expression ':' CLASSNAME
457 pCurClass = $2;
458 nCurMask = 1;
462 new_class_definition_body
464 | property_definition ';' new_class_definition_body
467 property_definition
468 : type_flags type SYMBOL
470 // Variable anlegen
471 Atom nId = pTC->aNmTb.Put( $3, VARNAME );
472 pCurClass->SetVariable( nId, $2, NULL, $1, nCurMask );
473 nCurMask <<= 1;
475 | type_flags type VARNAME
477 pCurClass->SetVariable( $3, $2, NULL, $1, nCurMask );
478 nCurMask <<= 1;
482 type_flags
483 : type_flags EXTENDABLE
485 $$ = $1 | VAR_EXTENDABLE;
487 | type_flags WRITEIFSET
489 $$ = $1 | VAR_SVDYNAMIC;
493 $$ = 0;
497 type
498 : type_base
500 $$ = $1;
502 | type_base '[' ']'
504 if( $1 )
506 rtl::OString aTypeName = rtl::OStringBuffer(pHS->getString($1->GetId())).
507 append("[]").makeStringAndClear();
508 $$ = pTC->SearchType( pHS->getID( aTypeName.getStr(), true ) );
509 if( !$$ )
511 RscCont * pCont;
512 pCont = new RscCont( pHS->getID( aTypeName.getStr() ), RSC_NOTYPE );
513 pCont->SetTypeClass( $1 );
514 pTC->InsertType( pCont );
515 $$ = pCont;
518 else
520 $$ = NULL;
525 type_base
526 : CLASSNAME
528 $$ = $1;
530 | SYMBOL
532 RscTop * pType = pTC->SearchType( pHS->getID( $1, true ) );
533 if( !pType )
534 pTC->pEH->Error( ERR_NOTYPE, pCurClass, RscId() );
535 $$ = pType;
539 class_definition
540 : class_header class_body
542 if( TYPE_REF == $1.nTyp )
544 pTC->pEH->Error( ERR_REFNOTALLOWED, S.Top().pClass,
545 RscId( $1.nName1 ) );
547 S.Pop();
549 | class_header
551 ERRTYPE aError;
552 RscId aRscId( $1.nName1 );
554 if( TYPE_NOTHING == $1.nTyp && aRscId.IsId() )
555 aError = S.Top().pClass->SetRef( S.Top(), aRscId );
556 else if( TYPE_COPY == $1.nTyp )
557 aError = ERR_COPYNOTALLOWED;
558 if( aError.IsError() || aError.IsWarning() )
559 pTC->pEH->Error( aError, S.Top().pClass, aRscId );
560 S.Pop();
564 class_header
565 : class_header_body
567 if( !DoClassHeader( &$1, false ) )
568 return ERR_ERROR;
569 $$ = $1;
573 copy_ref
574 : '<'
576 $$ = TYPE_COPY;
578 | ','
580 $$ = TYPE_REF;
584 class_header_body
585 : CLASSNAME id_expression copy_ref CLASSNAME id_expression
587 $$.pClass = $1;
588 $$.nName1 = $2;
589 $$.nTyp = $3;
590 $$.pRefClass = $4;
591 $$.nName2 = $5;
593 | CLASSNAME id_expression copy_ref id_expression
595 $$.pClass = $1;
596 $$.nName1 = $2;
597 $$.nTyp = $3;
598 $$.pRefClass = NULL;
599 $$.nName2 = $4;
601 | CLASSNAME id_expression
603 $$.pClass = $1;
604 $$.nName1 = $2;
605 $$.nTyp = TYPE_NOTHING;
606 $$.pRefClass = NULL;
607 $$.nName2.cType = RSCEXP_NOTHING;
609 | CLASSNAME copy_ref id_expression
611 $$.pClass = $1;
612 $$.nName1.cType = RSCEXP_NOTHING;
613 $$.nTyp = $2;
614 $$.pRefClass = NULL;
615 $$.nName2 = $3;
617 | CLASSNAME copy_ref CLASSNAME id_expression
619 $$.pClass = $1;
620 $$.nName1.cType = RSCEXP_NOTHING;
621 $$.nTyp = $2;
622 $$.pRefClass = $3;
623 $$.nName2 = $4;
625 | CLASSNAME
627 $$.pClass = $1;
628 $$.nName1.cType = RSCEXP_NOTHING;
629 $$.nTyp = TYPE_NOTHING;
630 $$.nName2.cType = RSCEXP_NOTHING;
634 class_body
635 : '{' var_definitions '}'
636 | '{' '}'
637 | string_multiline
639 SetString( S.Top(), "TEXT", $1 );
643 var_definitions
644 : var_definition
645 | var_definitions var_definition
648 xy_mapmode
649 : CONSTNAME
651 SetConst( S.Top(), "_XYMAPMODE", $1.hashid, $1.nValue );
656 wh_mapmode
657 : CONSTNAME
659 SetConst( S.Top(), "_WHMAPMODE", $1.hashid, $1.nValue );
664 xywh_mapmode
665 : CONSTNAME
667 SetConst( S.Top(), "_XYMAPMODE", $1.hashid, $1.nValue );
668 SetConst( S.Top(), "_WHMAPMODE", $1.hashid, $1.nValue );
673 var_definition
674 : line_number
675 | var_header var_body ';'
677 S.Pop();
679 | class_definition ';'
680 | var_header_class class_body ';'
682 if( TYPE_REF == $1.nTyp )
683 pTC->pEH->Error( ERR_REFNOTALLOWED, S.Top().pClass,
684 RscId( $1.nName1 ) );
686 if( S.Top().pClass->GetCount( S.Top() ) )
687 pTC->pEH->Error( WRN_SUBINMEMBER, S.Top().pClass,
688 RscId( $1.nName1 ) );
690 S.Pop();
692 | var_header_class ';'
694 ERRTYPE aError;
695 RscId aRscId( $1.nName1 );
697 if( TYPE_NOTHING == $1.nTyp && aRscId.IsId() )
698 aError = S.Top().pClass->SetRef( S.Top(), aRscId );
699 else if( TYPE_COPY == $1.nTyp )
700 aError = ERR_COPYNOTALLOWED;
701 if( S.Top().pClass->GetCount( S.Top() ) )
702 aError = WRN_SUBINMEMBER;
703 if( aError.IsError() || aError.IsWarning() )
704 pTC->pEH->Error( aError, S.Top().pClass, aRscId );
706 S.Pop();
708 | XSCALE '=' '(' long_expression ',' long_expression ')' ';'
710 SetNumber( S.Top(), "_XNUMERATOR", $4 );
711 SetNumber( S.Top(), "_XDENOMINATOR", $6 );
713 | YSCALE '=' '(' long_expression ',' long_expression ')' ';'
715 SetNumber( S.Top(), "_YNUMERATOR", $4 );
716 SetNumber( S.Top(), "_YDENOMINATOR", $6 );
718 | RGB '=' '(' long_expression ',' long_expression
719 ',' long_expression ')' ';'
721 SetNumber( S.Top(), "RED", $4 );
722 SetNumber( S.Top(), "GREEN", $6 );
723 SetNumber( S.Top(), "BLUE", $8 );
725 | GEOMETRY '=' xywh_mapmode '(' long_expression ',' long_expression ','
726 long_expression ',' long_expression ')' ';'
728 SetNumber( S.Top(), "_X", $5 );
729 SetNumber( S.Top(), "_Y", $7 );
730 SetNumber( S.Top(), "_WIDTH", $9 );
731 SetNumber( S.Top(), "_HEIGHT", $11 );
733 | POSITION '=' xy_mapmode '(' long_expression ',' long_expression
734 ')' ';'
736 SetNumber( S.Top(), "_X", $5 );
737 SetNumber( S.Top(), "_Y", $7 );
739 | DIMENSION '=' wh_mapmode '(' long_expression ',' long_expression
740 ')' ';'
742 SetNumber( S.Top(), "_WIDTH", $5 );
743 SetNumber( S.Top(), "_HEIGHT", $7 );
745 | INZOOMOUTPUTSIZE '=' CONSTNAME '(' long_expression ',' long_expression
746 ')' ';'
748 SetConst( S.Top(), "_ZOOMINMAPMODE", $3.hashid, $3.nValue );
749 SetNumber( S.Top(), "_ZOOMINWIDTH", $5 );
750 SetNumber( S.Top(), "_ZOOMINHEIGHT", $7 );
752 | INZOOMOUTPUTSIZE '=' '(' long_expression ',' long_expression ')' ';'
754 SetNumber( S.Top(), "_ZOOMINWIDTH", $4 );
755 SetNumber( S.Top(), "_ZOOMINHEIGHT", $6 );
757 | FLOATINGPOS '=' CONSTNAME '(' long_expression ',' long_expression
758 ')' ';'
760 SetConst( S.Top(), "_FLOATINGPOSMAPMODE", $3.hashid, $3.nValue );
761 SetNumber( S.Top(), "_FLOATINGPOSX", $5 );
762 SetNumber( S.Top(), "_FLOATINGPOSY", $7 );
764 | FLOATINGPOS '=' '(' long_expression ',' long_expression ')' ';'
766 SetNumber( S.Top(), "_FLOATINGPOSX", $4 );
767 SetNumber( S.Top(), "_FLOATINGPOSY", $6 );
771 var_header_class
772 : VARNAME '=' class_header_body
774 RSCINST aInst;
776 aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST(), false, $3.pClass );
778 if( aInst.pData )
779 S.Push( aInst );
780 else
782 pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(),
783 pHS->getString( $1 ).getStr() );
784 return ERR_ERROR;
787 if( !DoClassHeader( &$3, true ) )
788 return ERR_ERROR;
789 $$ = $3;
791 | VARNAME '[' CONSTNAME ']' '=' class_header_body
793 RSCINST aInst;
795 aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST() );
797 if( aInst.pData )
799 ERRTYPE aError;
800 RSCINST aIdxInst;
802 aError = aInst.pClass->GetArrayEle( aInst, $3.hashid, NULL, &aIdxInst );
803 if( aError.IsError() || aError.IsWarning() )
804 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
805 if( aError.IsError() )
806 return ERR_ERROR;
807 S.Push( aIdxInst );
809 else
811 pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(),
812 pHS->getString( $1 ).getStr() );
813 return ERR_ERROR;
815 if( !DoClassHeader( &$6, true ) )
816 return ERR_ERROR;
817 $$ = $6;
819 | VARNAME '[' SYMBOL ']' '=' class_header_body
821 RSCINST aInst;
823 aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST() );
825 if( aInst.pData )
827 long nNewLang = pTC->AddLanguage( $3 );
828 ERRTYPE aError;
829 RSCINST aIdxInst;
831 aError = aInst.pClass->GetArrayEle( aInst, nNewLang, NULL, &aIdxInst );
832 if( aError.IsError() || aError.IsWarning() )
833 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
834 if( aError.IsError() )
835 return ERR_ERROR;
836 S.Push( aIdxInst );
838 else
840 pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(),
841 pHS->getString( $1 ).getStr() );
842 return ERR_ERROR;
844 if( !DoClassHeader( &$6, true ) )
845 return ERR_ERROR;
846 $$ = $6;
850 var_header
851 : VARNAME '='
853 RSCINST aInst;
855 aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST() );
857 if( aInst.pData )
858 S.Push( aInst );
859 else
861 pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(),
862 pHS->getString( $1 ).getStr() );
863 return ERR_ERROR;
866 | VARNAME '[' CONSTNAME ']' '='
868 RSCINST aInst;
870 aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST() );
872 if( aInst.pData )
874 ERRTYPE aError;
875 RSCINST aIdxInst;
877 aError = aInst.pClass->GetArrayEle( aInst, $3.hashid, NULL, &aIdxInst );
878 if( aError.IsError() || aError.IsWarning() )
879 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
880 if( aError.IsError() )
881 return ERR_ERROR;
882 S.Push( aIdxInst );
884 else
886 pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(),
887 pHS->getString( $1 ).getStr() );
888 return ERR_ERROR;
891 | VARNAME '[' SYMBOL ']' '='
893 RSCINST aInst;
895 aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST() );
897 if( aInst.pData )
899 long nNewLang = pTC->AddLanguage( $3 );
900 ERRTYPE aError;
901 RSCINST aIdxInst;
903 aError = aInst.pClass->GetArrayEle( aInst, nNewLang, NULL, &aIdxInst );
904 if( aError.IsError() || aError.IsWarning() )
905 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
906 if( aError.IsError() )
907 return ERR_ERROR;
908 S.Push( aIdxInst );
910 else
912 pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(),
913 pHS->getString( $1 ).getStr() );
914 return ERR_ERROR;
919 tupel_header0
922 RSCINST aInst;
924 aInst = S.Top().pClass->GetTupelVar( S.Top(), 0, RSCINST() );
925 if( aInst.pData )
926 S.Push( aInst );
927 else
929 pTC->pEH->Error( ERR_NOTUPELNAME, S.Top().pClass, RscId() );
930 return ERR_ERROR;
935 tupel_header1
938 RSCINST aInst;
940 aInst = S.Top().pClass->GetTupelVar( S.Top(), 1, RSCINST() );
941 if( aInst.pData )
942 S.Push( aInst );
943 else
945 pTC->pEH->Error( ERR_NOTUPELNAME, S.Top().pClass, RscId() );
946 return ERR_ERROR;
951 tupel_header2
954 RSCINST aInst;
956 aInst = S.Top().pClass->GetTupelVar( S.Top(), 2, RSCINST() );
957 if( aInst.pData )
958 S.Push( aInst );
959 else
961 pTC->pEH->Error( ERR_NOTUPELNAME, S.Top().pClass, RscId() );
962 return ERR_ERROR;
967 tupel_header3
970 RSCINST aInst;
972 aInst = S.Top().pClass->GetTupelVar( S.Top(), 3, RSCINST() );
973 if( !aInst.pData )
975 pTC->pEH->Error( ERR_NOTUPELNAME, S.Top().pClass, RscId() );
976 return ERR_ERROR;
978 S.Push( aInst );
982 tupel_body
983 : var_body
985 S.Pop();
989 var_list_header
992 ERRTYPE aError;
993 RSCINST aInst;
995 aError = S.Top().pClass->GetElement( S.Top(), RscId(),
996 NULL, RSCINST(), &aInst );
997 if( aError.IsError() || aError.IsWarning() )
998 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
999 if( aError.IsError() )
1000 { // unbedingt Instanz auf den Stack bringen
1001 aInst = S.Top().pClass->Create( NULL, RSCINST() );
1003 S.Push( aInst );
1007 list_body
1008 : var_bodycomplex
1010 S.Pop();
1014 list_header
1017 sal_uInt32 nCount = S.Top().pClass->GetCount( S.Top() );
1018 sal_uInt32 i;
1020 for( i = nCount; i > 0; i-- )
1021 S.Top().pClass->DeletePos( S.Top(), i -1 );
1025 list
1026 : list var_list_header list_body ';'
1027 | list var_bodysimple ';'
1028 | list class_definition ';'
1029 | list line_number
1033 var_bodysimple
1034 : macro_expression
1036 sal_Int32 l;
1037 ERRTYPE aError;
1039 if( !$1.Evaluate( &l ) )
1040 pTC->pEH->Error( ERR_ZERODIVISION, NULL, RscId() );
1041 else
1043 aError = S.Top().pClass->SetRef( S.Top(), RscId( $1 ) );
1044 if( aError.IsError() )
1046 aError.Clear();
1047 aError = S.Top().pClass->SetNumber( S.Top(), l );
1049 if( aError.IsError() )
1050 { // Aufwaertskompatible, Tupel probieren
1051 RSCINST aInst = GetFirstTupelEle( S.Top() );
1052 if( aInst.pData )
1054 aError.Clear(); // Fehler zuruecksetzen
1055 aError = aInst.pClass->SetRef( aInst, RscId( $1 ) );
1056 if( aError.IsError() )
1058 aError.Clear();
1059 aError = aInst.pClass->SetNumber( aInst, l );
1065 if( $1.IsExpression() )
1066 delete $1.aExp.pExp;
1068 if( aError.IsError() || aError.IsWarning() )
1069 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
1071 | CONSTNAME
1073 ERRTYPE aError;
1074 aError = S.Top().pClass->SetConst( S.Top(), $1.hashid, $1.nValue );
1075 if( aError.IsError() )
1076 { // Aufwaertskompatible, Tupel probieren
1077 RSCINST aInst = GetFirstTupelEle( S.Top() );
1078 if( aInst.pData )
1080 aError.Clear(); // Fehler zuruecksetzen
1081 aError = aInst.pClass->SetConst( aInst, $1.hashid, $1.nValue );
1085 if( aError.IsError() || aError.IsWarning() )
1086 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
1088 | NOT CONSTNAME
1090 ERRTYPE aError;
1091 aError = S.Top().pClass->SetNotConst( S.Top(), $2.hashid );
1092 if( aError.IsError() )
1093 { // Aufwaertskompatible, Tupel probieren
1094 RSCINST aInst = GetFirstTupelEle( S.Top() );
1095 if( aInst.pData )
1097 aError.Clear(); // Fehler zuruecksetzen
1098 aError = aInst.pClass->SetNotConst( aInst, $2.hashid );
1102 if( aError.IsError() || aError.IsWarning() )
1103 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
1105 | BOOLEAN
1107 ERRTYPE aError;
1108 aError = S.Top().pClass->SetBool( S.Top(), $1 );
1109 if( aError.IsError() )
1110 { // Aufwaertskompatible, Tupel probieren
1111 RSCINST aInst = GetFirstTupelEle( S.Top() );
1112 if( aInst.pData )
1114 aError.Clear(); // Fehler zuruecksetzen
1115 aError = aInst.pClass->SetBool( aInst, $1 );
1119 if( aError.IsError() || aError.IsWarning() )
1120 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
1122 | string_multiline
1124 ERRTYPE aError;
1125 aError = S.Top().pClass->SetString( S.Top(), $1 );
1126 if( aError.IsError() )
1127 { // Aufwaertskompatible, Tupel probieren
1128 RSCINST aInst = GetFirstTupelEle( S.Top() );
1129 if( aInst.pData )
1131 aError.Clear(); // Fehler zuruecksetzen
1132 aError = aInst.pClass->SetString( aInst, $1 );
1136 if( aError.IsError() || aError.IsWarning() )
1137 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
1139 | DEFAULT
1142 var_bodycomplex
1143 : '{' list_header list '}'
1144 | '<' tupel_header0 tupel_body ';' '>'
1145 | '<' tupel_header0 tupel_body ';' tupel_header1 tupel_body ';' '>'
1146 | '<' tupel_header0 tupel_body ';' tupel_header1 tupel_body ';'
1147 tupel_header2 tupel_body ';' '>'
1148 | '<' tupel_header0 tupel_body ';' tupel_header1 tupel_body ';'
1149 tupel_header2 tupel_body ';' tupel_header3 tupel_body ';' '>'
1152 var_body
1153 : var_bodysimple
1154 | var_bodycomplex
1157 string_multiline
1158 : STRING
1160 $$ = $1;
1162 | string_multiline STRING
1164 rtl::OStringBuffer aBuf( 256 );
1165 aBuf.append( $1 );
1166 aBuf.append( $2 );
1167 $$ = const_cast<char*>(pStringContainer->putString( aBuf.getStr() ));
1171 long_expression
1172 : macro_expression
1174 if( !$1.Evaluate( &$$ ) )
1175 pTC->pEH->Error( ERR_ZERODIVISION, NULL, RscId() );
1176 if( $1.IsExpression() )
1177 delete $1.aExp.pExp;
1181 macro_expression
1182 : RSCDEFINE
1184 $$.cType = RSCEXP_DEF;
1185 $$.aExp.pDef = $1;
1187 | NUMBER
1189 $$.cType = RSCEXP_LONG;
1190 $$.SetLong( $1 );
1192 | '-' macro_expression %prec UNARYMINUS
1194 if( $2.IsNumber() ){
1195 $$.cType = $2.cType;
1196 $$.SetLong( - $2.GetLong() );
1198 else
1200 RscExpType aLeftExp;
1202 aLeftExp.cType = RSCEXP_NOTHING;
1203 $$.cType = RSCEXP_EXP;
1204 $$.aExp.pExp = new RscExpression( aLeftExp, '-', $2 );
1207 | '+' macro_expression %prec UNARYPLUS
1209 $$ = $2;
1211 | macro_expression '+' macro_expression
1213 if( $1.IsNumber() && $3.IsNumber() )
1215 $$.cType = RSCEXP_LONG;
1216 $$.SetLong( $1.GetLong() + $3.GetLong() );
1218 else
1220 $$.cType = RSCEXP_EXP;
1221 $$.aExp.pExp = new RscExpression( $1, '+', $3 );
1224 | macro_expression '-' macro_expression
1226 if( $1.IsNumber() && $3.IsNumber() )
1228 $$.cType = RSCEXP_LONG;
1229 $$.SetLong( $1.GetLong() - $3.GetLong() );
1231 else
1233 $$.cType = RSCEXP_EXP;
1234 $$.aExp.pExp = new RscExpression( $1, '-', $3 );
1237 | macro_expression '*' macro_expression
1239 if( $1.IsNumber() && $3.IsNumber() )
1241 $$.cType = RSCEXP_LONG;
1242 $$.SetLong( $1.GetLong() * $3.GetLong() );
1244 else
1246 $$.cType = RSCEXP_EXP;
1247 $$.aExp.pExp = new RscExpression( $1, '*', $3 );
1250 | macro_expression '/' macro_expression
1252 if( $1.IsNumber() && $3.IsNumber() )
1254 if( 0 == $3.GetLong() )
1256 $$.cType = RSCEXP_EXP;
1257 $$.aExp.pExp = new RscExpression( $1, '/', $3 );
1259 else
1261 $$.cType = RSCEXP_LONG;
1262 $$.SetLong( $1.GetLong() / $3.GetLong() );
1265 else
1267 $$.cType = RSCEXP_EXP;
1268 $$.aExp.pExp = new RscExpression( $1, '/', $3 );
1271 | macro_expression '&' macro_expression
1273 if( $1.IsNumber() && $3.IsNumber() )
1275 $$.cType = RSCEXP_LONG;
1276 $$.SetLong( $1.GetLong() & $3.GetLong() );
1278 else
1280 $$.cType = RSCEXP_EXP;
1281 $$.aExp.pExp = new RscExpression( $1, '&', $3 );
1284 | macro_expression '|' macro_expression
1286 if( $1.IsNumber() && $3.IsNumber() )
1288 $$.cType = RSCEXP_LONG;
1289 $$.SetLong( $1.GetLong() | $3.GetLong() );
1291 else
1293 $$.cType = RSCEXP_EXP;
1294 $$.aExp.pExp = new RscExpression( $1, '|', $3 );
1297 | '(' macro_expression ')'
1299 $$ = $2;
1301 | macro_expression LEFTSHIFT macro_expression
1303 if( $1.IsNumber() && $3.IsNumber() )
1305 $$.cType = RSCEXP_LONG;
1306 $$.SetLong( $1.GetLong() << $3.GetLong() );
1308 else
1310 $$.cType = RSCEXP_EXP;
1311 $$.aExp.pExp = new RscExpression( $1, 'l', $3 );
1314 | macro_expression RIGHTSHIFT macro_expression
1316 if( $1.IsNumber() && $3.IsNumber() )
1318 $$.cType = RSCEXP_LONG;
1319 $$.SetLong( $1.GetLong() >> $3.GetLong() );
1321 else
1323 $$.cType = RSCEXP_EXP;
1324 $$.aExp.pExp = new RscExpression( $1, 'r', $3 );
1329 id_expression
1330 : id_expression line_number
1331 | macro_expression
1332 { // pExpession auswerten und loeschen
1333 if( RSCEXP_EXP == $1.cType )
1335 sal_Int32 lValue;
1337 if( !$1.Evaluate( &lValue ) )
1338 pTC->pEH->Error( ERR_ZERODIVISION, NULL, RscId() );
1339 delete $1.aExp.pExp;
1340 $$.cType = RSCEXP_LONG;
1341 $$.SetLong( lValue );
1343 else
1345 $$ = $1;
1350 DUMMY_NUMBER
1351 : NUMBER
1359 line_number
1360 : '#' LINE NUMBER STRING
1362 RscFile * pFName;
1364 pFI->SetLineNo( $3 );
1365 pFI->SetFileIndex( pTC->aFileTab.NewCodeFile( rtl::OString( $4 ) ) );
1366 pFName = pTC->aFileTab.Get( pFI->GetFileIndex() );
1367 pFName->bLoaded = true;
1368 pFName->bScanned = true;
1370 | '#' NUMBER STRING DUMMY_NUMBER
1372 RscFile * pFName;
1374 pFI->SetLineNo( $2 );
1375 pFI->SetFileIndex( pTC->aFileTab.NewCodeFile( rtl::OString( $3 ) ) );
1376 pFName = pTC->aFileTab.Get( pFI->GetFileIndex() );
1377 pFName->bLoaded = true;
1378 pFName->bScanned = true;
1380 | '#' NUMBER
1382 pFI->SetLineNo( $2 );
1387 #if defined _MSC_VER
1388 #pragma warning(pop)
1389 #endif
1391 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */