Impress: Implement getPartName.
[LibreOffice.git] / idlc / source / parser.y
blobe06b967f42256a1cf02a674d9aa3a18fd2fc863b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 * parser.yy - BISON grammar for IDLC 1.0
25 #include <string.h>
27 #include <idlc/idlc.hxx>
28 #include <idlc/errorhandler.hxx>
29 #include <idlc/fehelper.hxx>
30 #include <idlc/astexpression.hxx>
31 #include <idlc/astconstants.hxx>
32 #include <idlc/astconstant.hxx>
33 #include <idlc/astbasetype.hxx>
34 #include <idlc/asttypedef.hxx>
35 #include <idlc/astexception.hxx>
36 #include <idlc/astmember.hxx>
37 #include <idlc/astenum.hxx>
38 #include <idlc/astsequence.hxx>
39 #include <idlc/astattribute.hxx>
40 #include <idlc/astoperation.hxx>
41 #include <idlc/astparameter.hxx>
42 #include <idlc/astinterfacemember.hxx>
43 #include <idlc/astservicemember.hxx>
44 #include <idlc/astobserves.hxx>
45 #include <idlc/astneeds.hxx>
47 #include "idlc/aststructinstance.hxx"
49 #include "attributeexceptions.hxx"
51 #include "rtl/strbuf.hxx"
53 #include <algorithm>
54 #include <vector>
57 #define YYDEBUG 1
58 #if !(defined MACOSX && defined PPC)
59 #define YYERROR_VERBOSE 1
60 #endif
62 using ::rtl::OUString;
63 using ::rtl::OString;
64 using ::rtl::OStringToOUString;
65 using ::rtl::OStringBuffer;
67 extern int yylex(void);
68 void yyerror(char const *);
70 void checkIdentifier(::rtl::OString* id)
72 static short check = 0;
73 if (check == 0) {
74 if (idlc()->getOptions()->isValid("-cid"))
75 check = 1;
76 else
77 check = 2;
80 if ( id->indexOf('_') >= 0 )
81 if ( (id->pData->buffer[0] >= 97 && id->pData->buffer[0] <= 122)
82 || id->pData->buffer[0] == '_') {
83 if (check == 1) {
84 ::rtl::OStringBuffer msg(25 + id->getLength());
85 msg.append("mismatched identifier '");
86 msg.append(*id);
87 msg.append("'");
88 idlc()->error()->syntaxError(idlc()->getParseState(),
89 idlc()->getLineNumber(),
90 msg.getStr());
92 else
93 idlc()->error()->warning0(WIDL_WRONG_NAMING_CONV, id->getStr());
97 void reportDoubleMemberDeclarations(
98 AstInterface::DoubleMemberDeclarations const & doubleMembers)
100 for (AstInterface::DoubleMemberDeclarations::const_iterator i(
101 doubleMembers.begin());
102 i != doubleMembers.end(); ++i)
104 idlc()->error()->error2(EIDL_DOUBLE_MEMBER, i->first, i->second);
108 void addInheritedInterface(
109 AstInterface * ifc, rtl::OString const & name, bool optional,
110 rtl::OUString const & documentation)
112 AstDeclaration * decl = ifc->lookupByName(name);
113 AstDeclaration const * resolved = resolveTypedefs(decl);
114 if (resolved != 0 && resolved->getNodeType() == NT_interface) {
115 if (idlc()->error()->checkPublished(decl)) {
116 if (!static_cast< AstInterface const * >(resolved)->isDefined()) {
117 idlc()->error()->inheritanceError(
118 NT_interface, &ifc->getScopedName(), decl);
119 } else {
120 AstInterface::DoubleDeclarations doubleDecls(
121 ifc->checkInheritedInterfaceClashes(
122 static_cast< AstInterface const * >(resolved),
123 optional));
124 if (doubleDecls.interfaces.empty()
125 && doubleDecls.members.empty())
127 ifc->addInheritedInterface(
128 static_cast< AstType * >(decl), optional,
129 documentation);
130 } else {
131 for (AstInterface::DoubleInterfaceDeclarations::iterator i(
132 doubleDecls.interfaces.begin());
133 i != doubleDecls.interfaces.end(); ++i)
135 idlc()->error()->error1(
136 EIDL_DOUBLE_INHERITANCE, *i);
138 reportDoubleMemberDeclarations(doubleDecls.members);
142 } else {
143 idlc()->error()->lookupError(
144 EIDL_INTERFACEMEMBER_LOOKUP, name, scopeAsDecl(ifc));
148 AstDeclaration const * createNamedType(
149 rtl::OString const * scopedName, DeclList const * typeArgs)
151 AstDeclaration * decl = idlc()->scopes()->topNonNull()->lookupByName(
152 *scopedName);
153 AstDeclaration const * resolved = resolveTypedefs(decl);
154 if (decl == 0) {
155 idlc()->error()->lookupError(*scopedName);
156 } else if (!idlc()->error()->checkPublished(decl)) {
157 decl = 0;
158 } else if (resolved->getNodeType() == NT_struct) {
159 if (static_cast< AstStruct const * >(resolved)->getTypeParameterCount()
160 != (typeArgs == 0 ? 0 : typeArgs->size()))
162 idlc()->error()->error0(EIDL_WRONG_NUMBER_OF_TYPE_ARGUMENTS);
163 decl = 0;
164 } else if (typeArgs != 0) {
165 AstScope * global = idlc()->scopes()->bottom();
166 AstDeclaration * inst = new AstStructInstance(
167 static_cast< AstType * >(decl), typeArgs, global);
168 decl = global->addDeclaration(inst);
169 if (decl != inst) {
170 delete inst;
173 } else if (decl->isType()) {
174 if (typeArgs != 0) {
175 idlc()->error()->error0(EIDL_WRONG_NUMBER_OF_TYPE_ARGUMENTS);
176 decl = 0;
178 } else {
179 idlc()->error()->noTypeError(decl);
180 decl = 0;
182 delete scopedName;
183 delete typeArgs;
184 return decl;
187 bool includes(AstDeclaration const * type1, AstDeclaration const * type2) {
188 OSL_ASSERT(type2 != 0);
189 if (type1 != 0) {
190 if (type1->getNodeType() == NT_instantiated_struct) {
191 AstStructInstance const * inst
192 = static_cast< AstStructInstance const * >(type1);
193 if (inst->getTypeTemplate() == type2) {
194 return true;
196 for (DeclList::const_iterator i(inst->getTypeArgumentsBegin());
197 i != inst->getTypeArgumentsEnd(); ++i)
199 if (includes(*i, type2)) {
200 return true;
203 } else if (type1 == type2) {
204 return true;
207 return false;
210 // Suppress any warnings from generated code:
211 #if defined _MSC_VER
212 #pragma warning(push, 1)
213 #pragma warning(disable: 4273 4701 4702)
214 #endif
217 * Declare the type of values in the grammar
219 %union {
220 ExprType etval; /* Expression type */
221 AstDeclaration* dclval; /* Declaration */
222 AstDeclaration const * cdclval;
223 DeclList * dclsval;
224 AstExpression* exval; /* expression value */
225 FeDeclarator* fdval; /* declarator value */
226 FeDeclList* dlval; /* declarator list value */
227 FeInheritanceHeader* ihval; /* inheritance header value */
228 ::rtl::OString* sval; /* OString value */
229 std::vector< rtl::OString > * svals;
230 sal_Char* strval; /* sal_Char* value */
231 bool bval; /* sal_Boolean* value */
232 sal_Int64 ival; /* sal_Int64 value */
233 sal_uInt64 uval; /* sal_uInt64 value */
234 sal_uInt32 ulval; /* sal_uInt32 value */
235 double dval; /* double value */
236 float fval; /* float value */
237 StringList* slval; /* StringList value */
238 AttributeExceptions::Part attexcpval;
239 AttributeExceptions attexcval;
243 * Token types: These are returned by the lexer
246 %token <sval> IDL_IDENTIFIER
247 %token IDL_ATTRIBUTE
248 %token IDL_BOUND
249 %token IDL_CONST
250 %token IDL_CONSTANTS
251 %token IDL_CONSTRAINED
252 %token IDL_ENUM
253 %token IDL_EXCEPTION
254 %token IDL_INTERFACE
255 %token IDL_MAYBEAMBIGUOUS
256 %token IDL_MAYBEDEFAULT
257 %token IDL_MAYBEVOID
258 %token IDL_MODULE
259 %token IDL_NEEDS
260 %token IDL_OBSERVES
261 %token IDL_OPTIONAL
262 %token IDL_PROPERTY
263 %token IDL_RAISES
264 %token IDL_READONLY
265 %token IDL_REMOVABLE
266 %token IDL_SERVICE
267 %token IDL_SEQUENCE
268 %token IDL_SINGLETON
269 %token IDL_STRUCT
270 %token IDL_TYPEDEF
271 %token IDL_TRANSIENT
273 %token IDL_ANY
274 %token IDL_CHAR
275 %token IDL_BOOLEAN
276 %token IDL_BYTE
277 %token IDL_DOUBLE
278 %token IDL_FLOAT
279 %token IDL_HYPER
280 %token IDL_LONG
281 %token IDL_SHORT
282 %token IDL_VOID
283 %token IDL_STRING
284 %token IDL_TYPE
285 %token IDL_UNSIGNED
287 %token IDL_TRUE
288 %token IDL_FALSE
290 %token IDL_IN
291 %token IDL_OUT
292 %token IDL_INOUT
294 %token IDL_GET
295 %token IDL_SET
297 %token IDL_PUBLISHED
299 %token IDL_ELLIPSIS
301 %token <strval> IDL_LEFTSHIFT
302 %token <strval> IDL_RIGHTSHIFT
303 %token <strval> IDL_SCOPESEPARATOR
305 %token <ival> IDL_INTEGER_LITERAL
306 %token <uval> IDL_INTEGER_ULITERAL
307 %token <dval> IDL_FLOATING_PT_LITERAL
310 * These are production names:
312 %type <dclval> type_dcl
313 %type <dclval> exception_name
314 %type <cdclval> constructed_type_spec enum_type op_type_spec
315 %type <cdclval> sequence_type_spec simple_type_spec struct_type
316 %type <cdclval> type_spec
317 %type <cdclval> fundamental_type type_arg type_or_parameter
318 %type <dclsval> opt_raises raises exception_list
319 %type <attexcpval> opt_attribute_get_raises attribute_get_raises
320 %type <attexcpval> opt_attribute_set_raises attribute_set_raises
321 %type <dclsval> opt_type_args type_args
323 %type <sval> identifier
324 %type <sval> interface_decl
325 %type <sval> scoped_name inheritance_spec
326 %type <slval> scoped_names at_least_one_scoped_name
328 %type <etval> const_type integer_type char_type boolean_type
329 %type <etval> floating_pt_type any_type signed_int string_type
330 %type <etval> unsigned_int base_type_spec byte_type type_type
332 %type <exval> expression const_expr or_expr xor_expr and_expr
333 %type <exval> add_expr mult_expr unary_expr primary_expr shift_expr
334 %type <exval> literal positive_int_expr
336 %type <fdval> declarator
337 %type <dlval> declarators at_least_one_declarator
339 %type <ihval> exception_header structure_header interfaceheader
341 %type <ulval> flag_header opt_attrflags opt_attrflag
342 %type <ulval> direction service_interface_header service_service_header
344 %type <bval> optional_inherited_interface opt_rest opt_service_body
346 %type <attexcval> opt_attribute_block attribute_block_rest opt_attribute_raises
348 %type <svals> opt_type_params type_params
352 * Grammar start here
354 start : definitions;
356 definitions :
357 definition definitions
358 | /* EMPTY */
361 definition :
362 opt_published publishable_definition
363 | module_dcl
365 idlc()->setParseState(PS_ModuleDeclSeen);
369 idlc()->setParseState(PS_NoState);
371 | error ';'
373 yyerror("definitions");
374 yyerrok;
378 opt_published:
379 IDL_PUBLISHED { idlc()->setPublished(true); }
380 | /* empty */ { idlc()->setPublished(false); }
383 publishable_definition:
384 type_dcl
386 idlc()->setParseState(PS_TypeDeclSeen);
390 idlc()->setParseState(PS_NoState);
392 | exception_dcl
394 idlc()->setParseState(PS_ExceptionDeclSeen);
398 idlc()->setParseState(PS_NoState);
400 | interface
402 idlc()->setParseState(PS_InterfaceDeclSeen);
406 idlc()->setParseState(PS_NoState);
408 | service_dcl
410 idlc()->setParseState(PS_ServiceDeclSeen);
414 idlc()->setParseState(PS_NoState);
416 | singleton_dcl
418 idlc()->setParseState(PS_SingletonDeclSeen);
422 idlc()->setParseState(PS_NoState);
424 | constants_dcl
426 idlc()->setParseState(PS_ConstantsDeclSeen);
430 idlc()->setParseState(PS_NoState);
434 module_dcl :
435 IDL_MODULE
437 idlc()->setParseState(PS_ModuleSeen);
438 idlc()->setPublished(false);
440 identifier
442 idlc()->setParseState(PS_ModuleIDSeen);
443 checkIdentifier($3);
445 AstScope* pScope = idlc()->scopes()->topNonNull();
446 AstModule* pModule = NULL;
447 AstDeclaration* pExists = NULL;
449 if ( pScope )
451 pModule = new AstModule(*$3, pScope);
452 if( (pExists = pScope->lookupForAdd(pModule)) )
454 pExists->setInMainfile(idlc()->isInMainFile());
455 pExists->setFileName(pModule->getFileName());
456 if (pExists->isPredefined())
458 pExists->setPredefined(false);
459 if (pExists->getDocumentation().getLength() == 0 &&
460 pModule->getDocumentation().getLength() > 0)
462 pExists->setDocumentation(pModule->getDocumentation());
465 delete(pModule);
466 pModule = (AstModule*)pExists;
467 } else
469 pScope->addDeclaration(pModule);
471 idlc()->scopes()->push(pModule);
473 delete $3;
477 idlc()->setParseState(PS_ModuleSqSeen);
479 definitions
481 idlc()->setParseState(PS_ModuleBodySeen);
485 idlc()->setParseState(PS_ModuleQsSeen);
487 * Finished with this module - pop it from the scope stack
489 idlc()->scopes()->pop();
493 interface :
494 interface_dcl
495 | forward_dcl
498 interface_decl :
499 IDL_INTERFACE
501 idlc()->setParseState(PS_InterfaceSeen);
503 identifier
505 idlc()->setParseState(PS_InterfaceIDSeen);
506 checkIdentifier($3);
507 $$ = $3;
511 forward_dcl :
512 interface_decl
514 idlc()->setParseState(PS_ForwardDeclSeen);
516 AstScope* pScope = idlc()->scopes()->topNonNull();
517 AstInterface* pForward = NULL;
518 AstDeclaration* pDecl = NULL;
521 * Make a new forward interface node and add it to its enclosing scope
523 if ( pScope && $1 )
525 pForward = new AstInterface(*$1, NULL, pScope);
527 pDecl = pScope->lookupByName(pForward->getScopedName());
528 if ( pDecl )
530 if ( (pDecl != pForward) &&
531 (pDecl->getNodeType() == NT_interface) )
533 delete pForward;
534 } else
536 idlc()->error()->error2(EIDL_REDEF_SCOPE, scopeAsDecl(pScope), pDecl);
538 } else
541 * Add the interface to its definition scope
543 pScope->addDeclaration(pForward);
546 delete $1;
550 interface_dcl :
551 interfaceheader
553 idlc()->setParseState(PS_InterfaceHeadSeen);
555 AstScope* pScope = idlc()->scopes()->topNonNull();
556 AstInterface* pInterface = NULL;
557 AstInterface* pForward = NULL;
558 AstDeclaration* pDecl = NULL;
561 * Make a new interface node and add it to its enclosing scope
563 if ( pScope && $1 )
565 pInterface = new AstInterface(
566 *$1->getName(),
567 static_cast< AstInterface const * >(resolveTypedefs($1->getInherits())), pScope);
568 if ( pInterface &&
569 (pDecl = pScope->lookupByName(pInterface->getScopedName())) )
572 * See if we're defining a forward declared interface.
574 if (pDecl->getNodeType() == NT_interface)
576 pForward = (AstInterface*)pDecl;
577 if ( !pForward->isDefined() )
580 * Check if redefining in same scope
582 if ( pForward->getScope() != pScope )
584 if ( pForward->getScopedName() != pInterface->getScopedName() )
586 idlc()->error()->error3(EIDL_SCOPE_CONFLICT,
587 pInterface, pForward, scopeAsDecl(pScope));
590 else if ( !pInterface->isPublished()
591 && pForward->isPublished() )
593 idlc()->error()->error0(EIDL_PUBLISHED_FORWARD);
596 * All OK, set full definition
598 else
600 pForward->forwardDefined(*pInterface);
601 delete pInterface;
602 pInterface = pForward;
604 } else {
605 // special handling for XInterface because it is predefined
606 if ( pForward->isPredefined() &&
607 pForward->getScopedName() == "com::sun::star::uno::XInterface")
609 /* replace the predefined XInterface */
610 *pForward = *pInterface;
611 delete pInterface;
612 pInterface = pForward;
617 } else
620 * Add the interface to its definition scope
622 pScope->addDeclaration(pInterface);
626 * Push it on the scope stack
628 idlc()->scopes()->push(pInterface);
629 delete($1);
633 idlc()->setParseState(PS_InterfaceSqSeen);
635 exports
637 AstInterface * ifc = static_cast< AstInterface * >(
638 idlc()->scopes()->topNonNull());
639 if (!ifc->hasMandatoryInheritedInterfaces()
640 && ifc->getScopedName() != "com::sun::star::uno::XInterface")
642 addInheritedInterface(
643 ifc, rtl::OString("::com::sun::star::uno::XInterface"), false,
644 rtl::OUString());
646 ifc->setDefined();
647 idlc()->setParseState(PS_InterfaceBodySeen);
651 idlc()->setParseState(PS_InterfaceQsSeen);
653 * Done with this interface - pop it off the scopes stack
655 idlc()->scopes()->pop();
657 | error '}'
659 yyerror("interface definition");
660 yyerrok;
664 interfaceheader :
665 interface_decl inheritance_spec
667 idlc()->setParseState(PS_InheritSpecSeen);
669 $$ = new FeInheritanceHeader(NT_interface, $1, $2, 0);
670 delete $2;
674 inheritance_spec :
677 idlc()->setParseState(PS_InheritColonSeen);
679 scoped_name
681 $$ = $3;
683 | /* EMPTY */
685 $$ = NULL;
689 exports :
690 exports export
691 | /* EMPTY */
694 export :
695 attribute
697 idlc()->setParseState(PS_AttributeDeclSeen);
701 idlc()->setParseState(PS_NoState);
703 | operation
705 idlc()->setParseState(PS_OperationDeclSeen);
709 idlc()->setParseState(PS_NoState);
711 | interface_inheritance_decl
713 idlc()->setParseState(PS_InterfaceInheritanceDeclSeen);
717 idlc()->setParseState(PS_NoState);
721 attribute :
722 flag_header
723 simple_type_spec
725 idlc()->setParseState(PS_AttrTypeSeen);
727 declarator
729 idlc()->setParseState(PS_AttrCompleted);
730 if (($1 & ~(AF_BOUND | AF_READONLY)) != AF_ATTRIBUTE) {
731 idlc()->error()->flagError(EIDL_BAD_ATTRIBUTE_FLAGS, $1);
733 AstInterface * scope = static_cast< AstInterface * >(
734 idlc()->scopes()->top());
735 AstAttribute * attr = new AstAttribute(
736 $1, $4->compose($2), $4->getName(), scope);
737 delete $4;
738 AstInterface::DoubleMemberDeclarations doubleMembers(
739 scope->checkMemberClashes(attr));
740 if (doubleMembers.empty()) {
741 scope->addMember(attr);
742 } else {
743 reportDoubleMemberDeclarations(doubleMembers);
745 idlc()->scopes()->push(attr);
747 opt_attribute_block
749 static_cast< AstAttribute * >(idlc()->scopes()->top())->setExceptions(
750 $6.get.documentation, $6.get.exceptions, $6.set.documentation,
751 $6.set.exceptions);
752 delete $6.get.documentation;
753 delete $6.get.exceptions;
754 delete $6.set.documentation;
755 delete $6.set.exceptions;
756 idlc()->scopes()->pop();
760 flag_header :
761 '[' opt_attrflags ']'
763 idlc()->setParseState(PS_FlagHeaderSeen);
764 $$ = $2;
768 opt_attrflags :
769 opt_attrflags ',' opt_attrflag
771 if ( ($1 & $3) == $3 )
772 idlc()->error()->flagError(EIDL_DEFINED_ATTRIBUTEFLAG, $3);
774 $$ = $1 | $3;
776 | opt_attrflag
778 $$ = $1;
782 opt_attrflag :
783 IDL_ATTRIBUTE
785 idlc()->setParseState(PS_AttrSeen);
786 $$ = AF_ATTRIBUTE;
788 | IDL_PROPERTY
790 idlc()->setParseState(PS_PropertySeen);
791 $$ = AF_PROPERTY;
793 | IDL_READONLY
795 idlc()->setParseState(PS_ReadOnlySeen);
796 $$ = AF_READONLY;
798 | IDL_OPTIONAL
800 idlc()->setParseState(PS_OptionalSeen);
801 $$ = AF_OPTIONAL;
803 | IDL_MAYBEVOID
805 idlc()->setParseState(PS_MayBeVoidSeen);
806 $$ = AF_MAYBEVOID;
808 | IDL_BOUND
810 idlc()->setParseState(PS_BoundSeen);
811 $$ = AF_BOUND;
813 | IDL_CONSTRAINED
815 idlc()->setParseState(PS_ConstrainedSeen);
816 $$ = AF_CONSTRAINED;
818 | IDL_TRANSIENT
820 idlc()->setParseState(PS_TransientSeen);
821 $$ = AF_TRANSIENT;
823 | IDL_MAYBEAMBIGUOUS
825 idlc()->setParseState(PS_MayBeAmbigiousSeen);
826 $$ = AF_MAYBEAMBIGUOUS;
828 | IDL_MAYBEDEFAULT
830 idlc()->setParseState(PS_MayBeDefaultSeen);
831 $$ = AF_MAYBEDEFAULT;
833 | IDL_REMOVABLE
835 idlc()->setParseState(PS_RemoveableSeen);
836 $$ = AF_REMOVABLE;
838 | error ']'
840 yyerror("unknown property|attribute flag");
841 yyerrok;
845 opt_attribute_block:
846 '{' attribute_block_rest { $$ = $2; }
847 | /* empty */
849 $$.get.documentation = 0;
850 $$.get.exceptions = 0;
851 $$.set.documentation = 0;
852 $$.set.exceptions = 0;
856 attribute_block_rest:
857 opt_attribute_raises '}'
858 | error '}'
860 yyerror("bad attribute raises block");
861 yyerrok;
862 $$.get.documentation = 0;
863 $$.get.exceptions = 0;
864 $$.set.documentation = 0;
865 $$.set.exceptions = 0;
869 opt_attribute_raises:
870 attribute_get_raises
871 opt_attribute_set_raises
873 $$.get = $1;
874 $$.set = $2;
876 | attribute_set_raises
877 opt_attribute_get_raises
879 $$.get = $2;
880 $$.set = $1;
882 | /* empty */
884 $$.get.documentation = 0;
885 $$.get.exceptions = 0;
886 $$.set.documentation = 0;
887 $$.set.exceptions = 0;
891 opt_attribute_get_raises:
892 attribute_get_raises
893 | /* empty */ { $$.documentation = 0; $$.exceptions = 0; }
896 attribute_get_raises:
897 IDL_GET raises ';'
899 $$.documentation = new rtl::OUString(
900 rtl::OStringToOUString(
901 idlc()->getDocumentation(), RTL_TEXTENCODING_UTF8));
902 $$.exceptions = $2;
906 opt_attribute_set_raises:
907 attribute_set_raises
908 | /* empty */ { $$.documentation = 0; $$.exceptions = 0; }
911 attribute_set_raises:
912 IDL_SET
914 if (static_cast< AstAttribute * >(idlc()->scopes()->top())->
915 isReadonly())
917 idlc()->error()->error0(EIDL_READONLY_ATTRIBUTE_SET_EXCEPTIONS);
920 raises ';'
922 $$.documentation = new rtl::OUString(
923 rtl::OStringToOUString(
924 idlc()->getDocumentation(), RTL_TEXTENCODING_UTF8));
925 $$.exceptions = $3;
929 operation :
930 op_type_spec
932 idlc()->setParseState(PS_OpTypeSeen);
934 identifier
936 idlc()->setParseState(PS_OpIDSeen);
937 checkIdentifier($3);
939 AstInterface * pScope = static_cast< AstInterface * >(
940 idlc()->scopes()->top());
941 AstOperation* pOp = NULL;
944 * Create a node representing an operation on an interface
945 * and add it to its enclosing scope
947 if ( pScope && $1 )
949 AstType *pType = (AstType*)$1;
950 if ( !pType || (pType->getNodeType() == NT_exception) )
952 // type ERROR
953 } else
955 pOp = new AstOperation(pType, *$3, pScope);
957 AstInterface::DoubleMemberDeclarations doubleMembers(
958 pScope->checkMemberClashes(pOp));
959 if (doubleMembers.empty()) {
960 pScope->addMember(pOp);
961 } else {
962 reportDoubleMemberDeclarations(doubleMembers);
966 delete $3;
968 * Push the operation scope onto the scopes stack
970 idlc()->scopes()->push(pOp);
974 idlc()->setParseState(PS_OpSqSeen);
976 parameters
978 idlc()->setParseState(PS_OpParsCompleted);
982 idlc()->setParseState(PS_OpQsSeen);
984 opt_raises
986 AstScope* pScope = idlc()->scopes()->topNonNull();
987 AstOperation* pOp = NULL;
989 * Add exceptions and context to the operation
991 if ( pScope && pScope->getScopeNodeType() == NT_operation)
993 pOp = (AstOperation*)pScope;
995 if ( pOp )
996 pOp->setExceptions($11);
998 delete $11;
1000 * Done with this operation. Pop its scope from the scopes stack
1002 idlc()->scopes()->pop();
1006 op_type_spec :
1007 simple_type_spec
1008 | IDL_VOID
1010 $$ = idlc()->scopes()->bottom()->lookupPrimitiveType(ET_void);
1014 parameters :
1015 parameter
1016 | parameters
1019 idlc()->setParseState(PS_OpParCommaSeen);
1021 parameter
1022 | /* EMPTY */
1023 | error ','
1025 yyerror("parameter definition");
1026 yyerrok;
1030 parameter :
1032 direction
1035 idlc()->setParseState(PS_OpParDirSeen);
1037 simple_type_spec
1039 idlc()->setParseState(PS_OpParTypeSeen);
1041 opt_rest
1042 declarator
1044 idlc()->setParseState(PS_OpParDeclSeen);
1046 AstOperation * pScope = static_cast< AstOperation * >(
1047 idlc()->scopes()->top());
1048 AstParameter* pParam = NULL;
1051 * Create a node representing an argument to an operation
1052 * Add it to the enclosing scope (the operation scope)
1054 if ( pScope && $5 && $8 )
1056 AstType const * pType = $8->compose($5);
1057 if ( pType )
1059 if (pScope->isConstructor() && $2 != DIR_IN) {
1060 idlc()->error()->error0(EIDL_CONSTRUCTOR_PARAMETER_NOT_IN);
1062 if (pScope->isVariadic()) {
1063 idlc()->error()->error0(EIDL_REST_PARAMETER_NOT_LAST);
1065 if ($7) {
1066 AstDeclaration const * type = resolveTypedefs(pType);
1067 if (type->getNodeType() != NT_predefined
1068 || (static_cast< AstBaseType const * >(type)->
1069 getExprType() != ET_any))
1071 idlc()->error()->error0(EIDL_REST_PARAMETER_NOT_ANY);
1073 if (pScope->isConstructor()) {
1074 if (pScope->getIteratorBegin()
1075 != pScope->getIteratorEnd())
1077 idlc()->error()->error0(
1078 EIDL_CONSTRUCTOR_REST_PARAMETER_NOT_FIRST);
1080 } else {
1081 idlc()->error()->error0(EIDL_METHOD_HAS_REST_PARAMETER);
1085 pParam = new AstParameter(
1086 static_cast< Direction >($2), $7, pType, $8->getName(),
1087 pScope);
1089 if ( !$8->checkType($5) )
1091 // WARNING
1094 pScope->addDeclaration(pParam);
1098 | error
1099 simple_type_spec
1101 idlc()->setParseState(PS_NoState);
1102 yyerrok;
1106 direction :
1107 IDL_IN
1109 $$ = DIR_IN;
1111 | IDL_OUT
1113 $$ = DIR_OUT;
1115 | IDL_INOUT
1117 $$ = DIR_INOUT;
1121 opt_rest:
1122 IDL_ELLIPSIS
1124 $$ = true;
1126 | /* empty */
1128 $$ = false;
1132 opt_raises:
1133 raises
1134 | /* empty */
1136 $$ = 0;
1140 raises:
1141 IDL_RAISES
1143 idlc()->setParseState(PS_RaiseSeen);
1147 idlc()->setParseState(PS_RaiseSqSeen);
1149 exception_list
1152 idlc()->setParseState(PS_RaiseQsSeen);
1153 $$ = $5;
1157 exception_list:
1158 exception_name
1160 $$ = new DeclList;
1161 $$->push_back($1);
1163 | exception_list ',' exception_name
1165 $1->push_back($3);
1166 $$ = $1;
1170 exception_name:
1171 scoped_name
1173 // The topmost scope is either an AstOperation (for interface methods
1174 // and service constructors) or an AstAttribute (for interface
1175 // attributes), so look up exception names in the next-to-topmost scope:
1176 AstDeclaration * decl = idlc()->scopes()->nextToTop()->lookupByName(
1177 *$1);
1178 if (decl == 0) {
1179 idlc()->error()->lookupError(*$1);
1180 } else if (!idlc()->error()->checkPublished(decl)) {
1181 decl = 0;
1182 } else if (decl->getNodeType() != NT_exception) {
1183 idlc()->error()->error1(EIDL_ILLEGAL_RAISES, decl);
1184 decl = 0;
1186 delete $1;
1187 $$ = decl;
1191 interface_inheritance_decl:
1192 optional_inherited_interface
1193 IDL_INTERFACE
1195 idlc()->setParseState(PS_ServiceIFHeadSeen);
1197 scoped_name
1199 AstInterface * ifc = static_cast< AstInterface * >(
1200 idlc()->scopes()->top());
1201 if (ifc->usesSingleInheritance()) {
1202 idlc()->error()->error0(EIDL_MIXED_INHERITANCE);
1203 } else {
1204 addInheritedInterface(
1205 ifc, *$4, $1,
1206 rtl::OStringToOUString(
1207 idlc()->getDocumentation(), RTL_TEXTENCODING_UTF8));
1209 delete $4;
1213 optional_inherited_interface:
1214 '[' IDL_OPTIONAL ']' { $$ = true; }
1215 | /* EMPTY */ { $$ = false; }
1218 constants_exports :
1219 constants_export constants_exports
1220 | /* EMPTY */
1223 constants_export :
1224 IDL_CONST
1226 idlc()->setParseState(PS_ConstSeen);
1228 const_type
1230 idlc()->setParseState(PS_ConstTypeSeen);
1232 identifier
1234 idlc()->setParseState(PS_ConstIDSeen);
1235 checkIdentifier($5);
1239 idlc()->setParseState(PS_ConstAssignSeen);
1241 expression
1243 idlc()->setParseState(PS_ConstExprSeen);
1245 AstScope* pScope = idlc()->scopes()->topNonNull();
1246 AstConstant* pConstant = NULL;
1248 if ( $9 && pScope )
1250 if ( !$9->coerce($3) )
1252 idlc()->error()->coercionError($9, $3);
1253 } else
1255 pConstant = new AstConstant($3, $9, *$5, pScope);
1256 pScope->addDeclaration(pConstant);
1259 delete $5;
1261 idlc()->setParseState(PS_ConstantDeclSeen);
1263 ';' {};
1266 constants_dcl :
1267 IDL_CONSTANTS
1269 idlc()->setParseState(PS_ConstantsSeen);
1271 identifier
1273 idlc()->setParseState(PS_ConstantsIDSeen);
1274 checkIdentifier($3);
1278 idlc()->setParseState(PS_ConstantsSqSeen);
1280 AstScope* pScope = idlc()->scopes()->topNonNull();
1281 AstConstants* pConstants = NULL;
1282 AstDeclaration* pExists = NULL;
1284 if ( pScope )
1286 pConstants = new AstConstants(*$3, pScope);
1287 if( (pExists = pScope->lookupForAdd(pConstants)) )
1289 pExists->setInMainfile(idlc()->isInMainFile());
1290 delete(pConstants);
1291 pConstants = (AstConstants*)pExists;
1292 } else
1294 pScope->addDeclaration(pConstants);
1296 idlc()->scopes()->push(pConstants);
1298 delete $3;
1300 constants_exports
1302 idlc()->setParseState(PS_ConstantsBodySeen);
1306 idlc()->setParseState(PS_ConstantsQsSeen);
1308 * Finished with this constants - pop it from the scope stack
1310 idlc()->scopes()->pop();
1314 expression : const_expr ;
1316 const_expr : or_expr ;
1318 or_expr :
1319 xor_expr
1320 | or_expr '|' xor_expr
1322 $$ = new AstExpression(EC_or, $1, $3);
1326 xor_expr :
1327 and_expr
1328 | xor_expr '^' and_expr
1330 $$ = new AstExpression(EC_xor, $1, $3);
1334 and_expr :
1335 shift_expr
1336 | and_expr '&' shift_expr
1338 $$ = new AstExpression(EC_and, $1, $3);
1342 shift_expr :
1343 add_expr
1344 | shift_expr IDL_LEFTSHIFT add_expr
1346 $$ = new AstExpression(EC_left, $1, $3);
1348 | shift_expr IDL_RIGHTSHIFT add_expr
1350 $$ = new AstExpression(EC_right, $1, $3);
1354 add_expr :
1355 mult_expr
1356 | add_expr '+' mult_expr
1358 $$ = new AstExpression(EC_add, $1, $3);
1360 | add_expr '-' mult_expr
1362 $$ = new AstExpression(EC_minus, $1, $3);
1366 mult_expr :
1367 unary_expr
1368 | mult_expr '*' unary_expr
1370 $$ = new AstExpression(EC_mul, $1, $3);
1372 | mult_expr '/' unary_expr
1374 $$ = new AstExpression(EC_div, $1, $3);
1376 | mult_expr '%' unary_expr
1378 $$ = new AstExpression(EC_mod, $1, $3);
1382 unary_expr :
1383 primary_expr
1384 | '+' primary_expr
1386 $$ = new AstExpression(EC_u_plus, $2, NULL);
1388 | '-' primary_expr
1390 $$ = new AstExpression(EC_u_minus, $2, NULL);
1392 | '~' primary_expr
1397 primary_expr :
1398 scoped_name
1401 * An expression which is a scoped name is not resolved now,
1402 * but only when it is evaluated (such as when it is assigned
1403 * as a constant value)
1405 $$ = new AstExpression($1);
1407 | literal
1408 | '(' const_expr ')'
1410 $$ = $2;
1414 literal :
1415 IDL_INTEGER_LITERAL
1417 $$ = new AstExpression($1);
1419 | IDL_INTEGER_ULITERAL
1421 $$ = new AstExpression($1);
1423 | IDL_FLOATING_PT_LITERAL
1425 $$ = new AstExpression($1);
1427 | IDL_TRUE
1429 $$ = new AstExpression((sal_Int32)1, ET_boolean);
1431 | IDL_FALSE
1433 $$ = new AstExpression((sal_Int32)0, ET_boolean);
1437 positive_int_expr :
1438 const_expr
1440 $1->evaluate(EK_const);
1441 if ( !$1->coerce(ET_ulong) )
1443 idlc()->error()->coercionError($1, ET_ulong);
1444 delete $1;
1445 $$ = NULL;
1450 const_type :
1451 integer_type
1452 | byte_type
1453 | boolean_type
1454 | floating_pt_type
1455 | scoped_name
1457 AstScope* pScope = idlc()->scopes()->topNonNull();
1458 AstDeclaration const * type = 0;
1461 * If the constant's type is a scoped name, it must resolve
1462 * to a scalar constant type
1464 if ( pScope && (type = pScope->lookupByName(*$1)) ) {
1465 if (!idlc()->error()->checkPublished(type))
1467 type = 0;
1468 $$ = ET_none;
1470 else
1472 type = resolveTypedefs(type);
1473 if (type->getNodeType() == NT_predefined)
1475 $$ = static_cast< AstBaseType const * >(type)->
1476 getExprType();
1477 } else
1478 $$ = ET_any;
1480 } else
1481 $$ = ET_any;
1485 exception_header :
1486 IDL_EXCEPTION
1488 idlc()->setParseState(PS_ExceptSeen);
1490 identifier
1492 idlc()->setParseState(PS_ExceptIDSeen);
1493 checkIdentifier($3);
1495 inheritance_spec
1497 idlc()->setParseState(PS_InheritSpecSeen);
1499 $$ = new FeInheritanceHeader(NT_exception, $3, $5, 0);
1500 delete $5;
1504 exception_dcl :
1505 exception_header
1507 idlc()->setParseState(PS_ExceptHeaderSeen);
1509 AstScope* pScope = idlc()->scopes()->topNonNull();
1510 AstException* pExcept = NULL;
1512 if ( pScope )
1514 AstException* pBase = static_cast< AstException* >(
1515 $1->getInherits());
1516 pExcept = new AstException(*$1->getName(), pBase, pScope);
1517 pScope->addDeclaration(pExcept);
1520 * Push the scope of the exception on the scopes stack
1522 idlc()->scopes()->push(pExcept);
1523 delete $1;
1527 idlc()->setParseState(PS_ExceptSqSeen);
1529 members
1531 idlc()->setParseState(PS_ExceptBodySeen);
1535 idlc()->setParseState(PS_ExceptQsSeen);
1536 /* this exception is finished, pop its scope from the stack */
1537 idlc()->scopes()->pop();
1541 property :
1542 flag_header
1543 simple_type_spec
1545 idlc()->setParseState(PS_PropertyTypeSeen);
1547 at_least_one_declarator
1549 idlc()->setParseState(PS_PropertyCompleted);
1551 AstScope* pScope = idlc()->scopes()->topNonNull();
1552 AstAttribute* pAttr = NULL;
1553 FeDeclList* pList = $4;
1554 FeDeclarator* pDecl = NULL;
1555 AstType const * pType = NULL;
1557 if ( pScope->getScopeNodeType() == NT_singleton )
1559 idlc()->error()->error0(EIDL_ILLEGAL_ADD);
1560 } else
1562 if ( ($1 & AF_ATTRIBUTE) == AF_ATTRIBUTE )
1563 idlc()->error()->flagError(EIDL_WRONGATTRIBUTEKEYWORD, AF_ATTRIBUTE);
1565 if ( ($1 & AF_PROPERTY) != AF_PROPERTY )
1566 idlc()->error()->flagError(EIDL_MISSINGATTRIBUTEKEYWORD, AF_PROPERTY);
1569 * Create nodes representing attributes and add them to the
1570 * enclosing scope
1572 if ( pScope && $2 && pList )
1574 FeDeclList::iterator iter = pList->begin();
1575 FeDeclList::iterator end = pList->end();
1577 while (iter != end)
1579 pDecl = (*iter);
1580 if ( !pDecl )
1582 iter++;
1583 continue;
1586 pType = pDecl->compose($2);
1588 if ( !pType )
1590 iter++;
1591 continue;
1594 pAttr = new AstAttribute(NT_property, $1, pType, pDecl->getName(), pScope);
1596 pScope->addDeclaration(pAttr);
1597 iter++;
1598 delete pDecl;
1603 if ( pList )
1604 delete pList;
1606 | error ';'
1608 yyerror("property");
1609 yyerrok;
1613 service_exports :
1614 service_exports service_export
1615 | /* EMPTY */
1618 service_export :
1619 service_interface_header
1620 at_least_one_scoped_name
1623 idlc()->setParseState(PS_ServiceMemberSeen);
1625 AstScope* pScope = idlc()->scopes()->topNonNull();
1626 AstDeclaration* pDecl = NULL;
1627 AstInterfaceMember* pIMember = NULL;
1629 if ( pScope->getScopeNodeType() == NT_singleton )
1631 idlc()->error()->error0(EIDL_ILLEGAL_ADD);
1632 } else
1635 * Create a node representing a class member.
1636 * Store it in the enclosing scope
1638 if ( pScope && $2 )
1640 StringList::iterator iter = $2->begin();
1641 StringList::iterator end = $2->end();
1643 while ( iter != end )
1645 pDecl = pScope->lookupByName(*iter);
1646 if ( pDecl && (pDecl->getNodeType() == NT_interface) )
1648 /* we relax the strict published check and allow to add new
1649 * interfaces if they are optional
1651 bool bOptional = (($1 & AF_OPTIONAL) == AF_OPTIONAL);
1652 if ( idlc()->error()->checkPublished(pDecl, bOptional) )
1654 pIMember = new AstInterfaceMember(
1655 $1, (AstInterface*)pDecl, *iter, pScope);
1656 pScope->addDeclaration(pIMember);
1658 } else
1660 idlc()->error()->
1661 lookupError(EIDL_INTERFACEMEMBER_LOOKUP, *iter, scopeAsDecl(pScope));
1663 iter++;
1667 delete $2;
1669 | service_service_header
1670 at_least_one_scoped_name
1673 idlc()->setParseState(PS_ServiceMemberSeen);
1675 AstScope* pScope = idlc()->scopes()->topNonNull();
1676 AstDeclaration* pDecl = NULL;
1677 AstServiceMember* pSMember = NULL;
1680 * Create a node representing a class member.
1681 * Store it in the enclosing scope
1683 if ( pScope && $2 )
1685 StringList::iterator iter = $2->begin();
1686 StringList::iterator end = $2->end();
1688 while ( iter != end )
1690 pDecl = pScope->lookupByName(*iter);
1691 if ( pDecl && (pDecl->getNodeType() == NT_service) )
1693 if ( static_cast< AstService * >(pDecl)->isSingleInterfaceBasedService() || (pScope->getScopeNodeType() == NT_singleton && pScope->nMembers() > 0) )
1694 idlc()->error()->error0(EIDL_ILLEGAL_ADD);
1695 else if ( idlc()->error()->checkPublished(pDecl) )
1697 pSMember = new AstServiceMember(
1698 $1, (AstService*)pDecl, *iter, pScope);
1699 pScope->addDeclaration(pSMember);
1701 } else
1703 idlc()->error()->
1704 lookupError(EIDL_SERVICEMEMBER_LOOKUP, *iter, scopeAsDecl(pScope));
1706 iter++;
1709 delete $2;
1711 | IDL_OBSERVES
1712 at_least_one_scoped_name
1715 idlc()->setParseState(PS_ServiceMemberSeen);
1717 AstScope* pScope = idlc()->scopes()->topNonNull();
1718 AstDeclaration* pDecl = NULL;
1719 AstObserves* pObserves = NULL;
1721 if ( pScope->getScopeNodeType() == NT_singleton )
1723 idlc()->error()->error0(EIDL_ILLEGAL_ADD);
1724 } else
1727 * Create a node representing a class member.
1728 * Store it in the enclosing scope
1730 if ( pScope && $2 )
1732 StringList::iterator iter = $2->begin();
1733 StringList::iterator end = $2->end();
1735 while ( iter != end )
1737 pDecl = pScope->lookupByName(*iter);
1738 if ( pDecl && (pDecl->getNodeType() == NT_interface) )
1740 pObserves = new AstObserves((AstInterface*)pDecl, *iter, pScope);
1741 pScope->addDeclaration(pObserves);
1742 } else
1744 idlc()->error()->
1745 lookupError(EIDL_INTERFACEMEMBER_LOOKUP, *iter, scopeAsDecl(pScope));
1747 iter++;
1751 delete $2;
1753 | IDL_NEEDS
1754 at_least_one_scoped_name
1757 idlc()->setParseState(PS_ServiceMemberSeen);
1759 AstScope* pScope = idlc()->scopes()->topNonNull();
1760 AstDeclaration* pDecl = NULL;
1761 AstNeeds* pNeeds = NULL;
1763 if ( pScope->getScopeNodeType() == NT_singleton )
1765 idlc()->error()->error0(EIDL_ILLEGAL_ADD);
1766 } else
1769 * Create a node representing a class member.
1770 * Store it in the enclosing scope
1772 if ( pScope && $2 )
1774 StringList::iterator iter = $2->begin();
1775 StringList::iterator end = $2->end();
1777 while ( iter != end )
1779 pDecl = pScope->lookupByName(*iter);
1780 if ( pDecl && (pDecl->getNodeType() == NT_service) )
1782 pNeeds = new AstNeeds((AstService*)pDecl, *iter, pScope);
1783 pScope->addDeclaration(pNeeds);
1784 } else
1786 idlc()->error()->
1787 lookupError(EIDL_SERVICEMEMBER_LOOKUP, *iter, scopeAsDecl(pScope));
1789 iter++;
1793 delete $2;
1795 | property
1798 idlc()->setParseState(PS_PropertyDeclSeen);
1802 service_interface_header :
1803 IDL_INTERFACE
1805 idlc()->setParseState(PS_ServiceIFHeadSeen);
1806 $$ = AF_INVALID;
1808 | flag_header
1809 IDL_INTERFACE
1811 idlc()->setParseState(PS_ServiceIFHeadSeen);
1812 if ( (AF_OPTIONAL != $1) && ( AF_INVALID != $1) )
1813 idlc()->error()->flagError(EIDL_OPTIONALEXPECTED, $1);
1814 $$ = $1;
1818 service_service_header :
1819 IDL_SERVICE
1821 idlc()->setParseState(PS_ServiceSHeadSeen);
1822 $$ = AF_INVALID;
1824 | flag_header
1825 IDL_SERVICE
1827 idlc()->setParseState(PS_ServiceSHeadSeen);
1828 if ( (AF_OPTIONAL != $1) && ( AF_INVALID != $1) )
1829 idlc()->error()->flagError(EIDL_OPTIONALEXPECTED, $1);
1830 $$ = $1;
1834 service_dcl :
1835 IDL_SERVICE
1837 idlc()->setParseState(PS_ServiceSeen);
1839 identifier
1841 idlc()->setParseState(PS_ServiceIDSeen);
1842 checkIdentifier($3);
1844 AstScope* pScope = idlc()->scopes()->topNonNull();
1845 AstService* pService = NULL;
1848 * Make a new service and add it to the enclosing scope
1850 if (pScope != NULL)
1852 pService = new AstService(*$3, pScope);
1853 pScope->addDeclaration(pService);
1855 delete $3;
1857 * Push it on the stack
1859 idlc()->scopes()->push(pService);
1861 service_dfn
1863 /* this service is finished, pop its scope from the stack */
1864 idlc()->scopes()->pop();
1868 service_dfn:
1869 service_interface_dfn
1870 | service_obsolete_dfn
1873 service_interface_dfn:
1874 ':' scoped_name
1876 AstScope * scope = idlc()->scopes()->nextToTop();
1877 // skip the scope pushed by service_dcl
1878 AstDeclaration * decl = scope->lookupByName(*$2);
1879 if (decl != 0 && resolveTypedefs(decl)->getNodeType() == NT_interface) {
1880 if (idlc()->error()->checkPublished(decl)) {
1881 idlc()->scopes()->top()->addDeclaration(decl);
1883 } else {
1884 idlc()->error()->lookupError(
1885 EIDL_INTERFACEMEMBER_LOOKUP, *$2, scopeAsDecl(scope));
1887 delete $2;
1889 opt_service_body
1891 AstService * s = static_cast< AstService * >(idlc()->scopes()->top());
1892 if (s != 0) {
1893 s->setSingleInterfaceBasedService();
1894 s->setDefaultConstructor(!$4);
1899 opt_service_body:
1900 service_body { $$ = true; }
1901 | /* empty */ { $$ = false; }
1904 service_body:
1906 constructors
1910 constructors:
1911 constructors constructor
1912 | /* empty */
1915 constructor:
1916 identifier
1918 checkIdentifier($1);
1919 AstScope * scope = idlc()->scopes()->top();
1920 AstOperation * ctor = new AstOperation(0, *$1, scope);
1921 delete $1;
1922 scope->addDeclaration(ctor);
1923 idlc()->scopes()->push(ctor);
1926 parameters
1928 opt_raises
1930 static_cast< AstOperation * >(idlc()->scopes()->top())->setExceptions(
1931 $6);
1932 delete $6;
1933 idlc()->scopes()->pop();
1934 if (static_cast< AstService * >(idlc()->scopes()->top())->
1935 checkLastConstructor())
1937 idlc()->error()->error0(EIDL_SIMILAR_CONSTRUCTORS);
1943 singleton_dcl :
1944 IDL_SINGLETON
1946 idlc()->setParseState(PS_SingletonSeen);
1948 identifier
1950 idlc()->setParseState(PS_SingletonIDSeen);
1951 checkIdentifier($3);
1953 AstScope* pScope = idlc()->scopes()->topNonNull();
1954 AstService* pService = NULL;
1957 * Make a new service and add it to the enclosing scope
1959 if (pScope != NULL)
1961 pService = new AstService(NT_singleton, *$3, pScope);
1962 pScope->addDeclaration(pService);
1964 delete $3;
1966 * Push it on the stack
1968 idlc()->scopes()->push(pService);
1970 singleton_dfn
1972 /* this singelton is finished, pop its scope from the stack */
1973 idlc()->scopes()->pop();
1977 singleton_dfn:
1978 singleton_interface_dfn
1979 | service_obsolete_dfn
1982 singleton_interface_dfn:
1983 ':' scoped_name
1985 AstScope * scope = idlc()->scopes()->nextToTop();
1986 // skip the scope (needlessly) pushed by singleton_dcl
1987 AstDeclaration * decl = scope->lookupByName(*$2);
1988 if (decl != 0 && resolveTypedefs(decl)->getNodeType() == NT_interface) {
1989 if (idlc()->error()->checkPublished(decl)) {
1990 idlc()->scopes()->top()->addDeclaration(decl);
1992 } else {
1993 idlc()->error()->lookupError(
1994 EIDL_INTERFACEMEMBER_LOOKUP, *$2, scopeAsDecl(scope));
1996 delete $2;
2000 service_obsolete_dfn:
2003 idlc()->setParseState(
2004 idlc()->scopes()->top()->getScopeNodeType() == NT_service
2005 ? PS_ServiceSqSeen : PS_SingletonSqSeen);
2007 service_exports
2009 idlc()->setParseState(
2010 idlc()->scopes()->top()->getScopeNodeType() == NT_service
2011 ? PS_ServiceBodySeen : PS_SingletonBodySeen);
2015 idlc()->setParseState(
2016 idlc()->scopes()->top()->getScopeNodeType() == NT_service
2017 ? PS_ServiceQsSeen : PS_SingletonQsSeen);
2021 type_dcl :
2022 IDL_TYPEDEF
2024 idlc()->setParseState(PS_TypedefSeen);
2026 type_declarator {}
2027 | struct_type {}
2028 | enum_type {}
2031 type_declarator :
2032 type_spec
2034 idlc()->setParseState(PS_TypeSpecSeen);
2035 if ($1 != 0 && $1->getNodeType() == NT_instantiated_struct) {
2036 idlc()->error()->error0(EIDL_INSTANTIATED_STRUCT_TYPE_TYPEDEF);
2039 at_least_one_declarator
2041 idlc()->setParseState(PS_DeclaratorsSeen);
2043 AstScope* pScope = idlc()->scopes()->topNonNull();
2044 AstTypeDef* pTypeDef = NULL;
2045 FeDeclList* pList = $3;
2046 FeDeclarator* pDecl = NULL;
2047 AstType const * pType = NULL;
2050 * Create nodes representing typedefs and add them to the
2051 * enclosing scope
2053 if ( pScope && $1 && pList )
2055 FeDeclList::iterator iter = pList->begin();
2056 FeDeclList::iterator end = pList->end();
2058 while (iter != end)
2060 pDecl = (*iter);
2061 if ( !pDecl )
2063 iter++;
2064 continue;
2067 pType = pDecl->compose($1);
2069 if ( !pType )
2071 iter++;
2072 continue;
2075 pTypeDef = new AstTypeDef(pType, pDecl->getName(), pScope);
2077 pScope->addDeclaration(pTypeDef);
2078 iter++;
2079 delete pDecl;
2081 delete pList;
2086 at_least_one_declarator :
2087 declarator declarators
2089 if ( $2 )
2091 $2->push_back($1);
2092 $$ = $2;
2093 } else
2095 FeDeclList* pList = new FeDeclList();
2096 pList->push_back($1);
2097 $$ = pList;
2102 declarators :
2103 declarators
2106 idlc()->setParseState(PS_DeclsCommaSeen);
2108 declarator
2110 idlc()->setParseState(PS_DeclsDeclSeen);
2111 if ( $1 )
2113 $1->push_back($4);
2114 $$ = $1;
2115 } else
2117 FeDeclList* pList = new FeDeclList();
2118 pList->push_back($4);
2119 $$ = pList;
2122 | /* EMPTY */
2124 $$ = NULL;
2128 declarator :
2129 identifier
2131 // For historic reasons, the struct com.sun.star.uno.Uik contains
2132 // members with illegal names (of the form "m_DataN"); avoid useless
2133 // warnings about them:
2134 AstScope * scope = idlc()->scopes()->top();
2135 if (scope == 0 || scope->getScopeNodeType() != NT_struct
2136 || (scopeAsDecl(scope)->getScopedName()
2137 != "com::sun::star::uno::Uik"))
2139 checkIdentifier($1);
2142 $$ = new FeDeclarator(*$1, FeDeclarator::FD_simple, NULL);
2143 delete $1;
2147 at_least_one_scoped_name :
2148 scoped_name scoped_names
2150 if ($2)
2152 $2->push_front(*$1);
2153 $$ = $2;
2154 } else
2156 StringList* pNames = new StringList();
2157 pNames->push_back(*$1);
2158 $$ = pNames;
2160 delete($1);
2164 scoped_names :
2165 scoped_names
2168 idlc()->setParseState(PS_SNListCommaSeen);
2170 scoped_name
2172 idlc()->setParseState(PS_ScopedNameSeen);
2173 if ($1)
2175 $1->push_back(*$4);
2176 $$ = $1;
2177 } else
2179 StringList* pNames = new StringList();
2180 pNames->push_back(*$4);
2181 $$ = pNames;
2183 delete($4);
2185 | /* EMPTY */
2187 $$ = NULL;
2191 scoped_name :
2192 identifier
2194 idlc()->setParseState(PS_SN_IDSeen);
2195 checkIdentifier($1);
2196 $$ = $1;
2198 | IDL_SCOPESEPARATOR
2200 idlc()->setParseState(PS_ScopeDelimSeen);
2202 identifier
2204 checkIdentifier($3);
2205 OString* pName = new OString("::");
2206 *pName += *$3;
2207 delete $3;
2208 $$ = pName;
2210 | scoped_name
2211 IDL_SCOPESEPARATOR
2214 identifier
2216 checkIdentifier($4);
2217 *$1 += ::rtl::OString("::");
2218 *$1 += *$4;
2219 delete $4;
2220 $$ = $1;
2224 type_spec :
2225 simple_type_spec
2226 | constructed_type_spec
2229 simple_type_spec :
2230 fundamental_type
2231 | scoped_name opt_type_args
2233 $$ = createNamedType($1, $2);
2237 fundamental_type:
2238 base_type_spec
2240 $$ = idlc()->scopes()->bottom()->lookupPrimitiveType($1);
2242 | sequence_type_spec
2245 opt_type_args:
2246 '<' type_args '>' { $$ = $2; }
2247 | /* empty */ { $$ = 0; }
2250 type_args:
2251 type_arg
2253 $$ = new DeclList;
2254 $$->push_back(const_cast< AstDeclaration * >($1)); //TODO: const_cast
2256 | type_args ',' type_arg
2258 $1->push_back(const_cast< AstDeclaration * >($3)); //TODO: const_cast
2259 $$ = $1;
2263 type_arg:
2264 simple_type_spec
2266 if ($1 != 0 && static_cast< AstType const * >($1)->isUnsigned()) {
2267 idlc()->error()->error0(EIDL_UNSIGNED_TYPE_ARGUMENT);
2269 $$ = $1;
2273 base_type_spec :
2274 integer_type
2275 | floating_pt_type
2276 | char_type
2277 | boolean_type
2278 | byte_type
2279 | any_type
2280 | type_type
2281 | string_type
2284 integer_type :
2285 signed_int
2286 | unsigned_int
2289 signed_int :
2290 IDL_LONG
2292 $$ = ET_long;
2294 | IDL_HYPER
2296 $$ = ET_hyper;
2298 | IDL_SHORT
2300 $$ = ET_short;
2304 unsigned_int :
2305 IDL_UNSIGNED IDL_LONG
2307 $$ = ET_ulong;
2309 | IDL_UNSIGNED IDL_HYPER
2311 $$ = ET_uhyper;
2313 | IDL_UNSIGNED IDL_SHORT
2315 $$ = ET_ushort;
2319 floating_pt_type :
2320 IDL_DOUBLE
2322 $$ = ET_double;
2324 | IDL_FLOAT
2326 $$ = ET_float;
2330 char_type :
2331 IDL_CHAR
2333 $$ = ET_char;
2337 byte_type :
2338 IDL_BYTE
2340 $$ = ET_byte;
2344 boolean_type :
2345 IDL_BOOLEAN
2347 $$ = ET_boolean;
2351 any_type :
2352 IDL_ANY
2354 $$ = ET_any;
2358 type_type :
2359 IDL_TYPE
2361 $$ = ET_type;
2365 string_type :
2366 IDL_STRING
2368 $$ = ET_string;
2372 constructed_type_spec :
2373 struct_type
2374 | enum_type
2377 sequence_type_spec :
2378 IDL_SEQUENCE
2380 idlc()->setParseState(PS_SequenceSeen);
2382 * Push a sequence marker on scopes stack
2384 idlc()->scopes()->push(NULL);
2388 idlc()->setParseState(PS_SequenceSqSeen);
2390 simple_type_spec
2392 idlc()->setParseState(PS_SequenceTypeSeen);
2396 idlc()->setParseState(PS_SequenceQsSeen);
2398 * Remove sequence marker from scopes stack
2400 if (idlc()->scopes()->top() == NULL)
2401 idlc()->scopes()->pop();
2403 * Create a node representing a sequence
2405 AstScope* pScope = idlc()->scopes()->bottom();
2406 AstDeclaration* pDecl = NULL;
2407 AstDeclaration* pSeq = NULL;
2409 if ( $5 )
2411 AstType *pType = (AstType*)$5;
2412 if ( pType )
2414 pSeq = new AstSequence(pType, pScope);
2416 * Add this AstSequence to the types defined in the global scope
2418 pDecl = pScope->addDeclaration(pSeq);
2419 if ( pSeq != pDecl )
2421 // if sequence type already defined then use it
2422 delete pSeq;
2423 pSeq = pDecl;
2427 $$ = pSeq;
2429 | error '>'
2431 yyerror("sequence declaration");
2432 yyerrok;
2433 $$ = 0;
2437 struct_type :
2438 structure_header
2440 idlc()->setParseState(PS_StructHeaderSeen);
2442 AstScope* pScope = idlc()->scopes()->topNonNull();
2443 AstStruct* pStruct = NULL;
2445 if ( pScope )
2447 AstStruct const* pBase= static_cast< AstStruct const* >(resolveTypedefs($1->getInherits()));
2448 pStruct = new AstStruct(
2449 *$1->getName(), $1->getTypeParameters(), pBase, pScope);
2450 pScope->addDeclaration(pStruct);
2453 * Push the scope of the struct on the scopes stack
2455 idlc()->scopes()->push(pStruct);
2456 delete $1;
2460 idlc()->setParseState(PS_StructSqSeen);
2462 at_least_one_member
2464 idlc()->setParseState(PS_StructBodySeen);
2468 idlc()->setParseState(PS_StructQsSeen);
2469 /* this exception is finished, pop its scope from the stack */
2470 idlc()->scopes()->pop();
2474 structure_header :
2475 IDL_STRUCT
2477 idlc()->setParseState(PS_StructSeen);
2479 identifier
2481 idlc()->setParseState(PS_StructIDSeen);
2482 checkIdentifier($3);
2484 opt_type_params
2485 inheritance_spec
2487 idlc()->setParseState(PS_InheritSpecSeen);
2489 // Polymorphic struct type templates with base types would cause various
2490 // problems in language bindings, so forbid them here. For example,
2491 // GCC prior to version 3.4 fails with code like
2493 // struct Base { ... };
2494 // template< typename typeparam_T > struct Derived: public Base {
2495 // int member1 CPPU_GCC3_ALIGN(Base);
2496 // ... };
2498 // (Note that plain struct types with instantiated polymorphic struct
2499 // type bases, which might also cause problems in language bindings, are
2500 // already rejected on a syntactic level.)
2501 if ($5 != 0 && $6 != 0) {
2502 idlc()->error()->error0(EIDL_STRUCT_TYPE_TEMPLATE_WITH_BASE);
2505 $$ = new FeInheritanceHeader(NT_struct, $3, $6, $5);
2506 delete $5;
2507 delete $6;
2511 opt_type_params:
2512 '<' type_params '>' { $$ = $2; }
2513 | /* empty */ { $$ = 0; }
2516 type_params:
2517 identifier
2519 $$ = new std::vector< rtl::OString >;
2520 $$->push_back(*$1);
2521 delete $1;
2523 | type_params ',' identifier
2525 if (std::find($1->begin(), $1->end(), *$3) != $1->end()) {
2526 idlc()->error()->error0(EIDL_IDENTICAL_TYPE_PARAMETERS);
2528 $1->push_back(*$3);
2529 delete $3;
2530 $$ = $1;
2534 at_least_one_member : member members ;
2536 members :
2537 members member
2538 | /* EMPTY */
2541 member :
2542 type_or_parameter
2544 idlc()->setParseState(PS_MemberTypeSeen);
2546 at_least_one_declarator
2548 idlc()->setParseState(PS_MemberDeclsSeen);
2552 idlc()->setParseState(PS_MemberDeclsCompleted);
2554 AstScope* pScope = idlc()->scopes()->topNonNull();
2555 AstMember* pMember = NULL;
2556 FeDeclList* pList = $3;
2557 FeDeclarator* pDecl = NULL;
2558 AstType const * pType = NULL;
2560 // !!! check recursive type
2562 if ( pScope && pList && $1 )
2564 FeDeclList::iterator iter = pList->begin();
2565 FeDeclList::iterator end = pList->end();
2566 while (iter != end)
2568 pDecl = (*iter);
2569 if ( !pDecl )
2571 iter++;
2572 continue;
2575 pType = pDecl->compose($1);
2577 if ( !pType )
2579 iter++;
2580 continue;
2583 pMember = new AstMember(pType, pDecl->getName(), pScope);
2585 if ( !pDecl->checkType($1) )
2587 // WARNING
2590 pScope->addDeclaration(pMember);
2591 iter++;
2592 delete pDecl;
2594 delete pList;
2597 | error ';'
2599 yyerror("member definition");
2600 yyerrok;
2604 type_or_parameter:
2605 fundamental_type
2606 | scoped_name opt_type_args
2608 AstDeclaration const * decl = 0;
2609 AstStruct * scope = static_cast< AstStruct * >(idlc()->scopes()->top());
2610 if (scope != 0 && $2 == 0) {
2611 decl = scope->findTypeParameter(*$1);
2613 if (decl != 0) {
2614 delete $1;
2615 delete $2;
2616 } else {
2617 decl = createNamedType($1, $2);
2618 if (scope != 0 && includes(decl, scopeAsDecl(scope))) {
2619 idlc()->error()->error1(
2620 EIDL_RECURSIVE_TYPE, scopeAsDecl(scope));
2621 decl = 0;
2624 $$ = decl;
2628 enum_type :
2629 IDL_ENUM
2631 idlc()->setParseState(PS_EnumSeen);
2633 identifier
2635 idlc()->setParseState(PS_EnumIDSeen);
2636 checkIdentifier($3);
2638 AstScope* pScope = idlc()->scopes()->topNonNull();
2639 AstEnum* pEnum = NULL;
2642 * Create a node representing an enum and add it to its
2643 * enclosing scope
2645 if (pScope != NULL)
2647 pEnum = new AstEnum(*$3, pScope);
2649 * Add it to its defining scope
2651 pScope->addDeclaration(pEnum);
2653 delete $3;
2655 * Push the enum scope on the scopes stack
2657 idlc()->scopes()->push(pEnum);
2662 idlc()->setParseState(PS_EnumSqSeen);
2664 at_least_one_enumerator
2666 idlc()->setParseState(PS_EnumBodySeen);
2670 idlc()->setParseState(PS_EnumQsSeen);
2672 * Done with this enum. Pop its scope from the scopes stack
2674 if (idlc()->scopes()->top() == NULL)
2675 $$ = NULL;
2676 else
2678 $$ = (AstEnum*)idlc()->scopes()->topNonNull();
2679 idlc()->scopes()->pop();
2684 at_least_one_enumerator : enumerator enumerators ;
2686 enumerators :
2687 enumerators
2690 idlc()->setParseState(PS_EnumCommaSeen);
2692 enumerator
2693 | /* EMPTY */
2694 | error ','
2696 yyerror("enumerator definition");
2697 yyerrok;
2701 enumerator :
2702 identifier
2704 checkIdentifier($1);
2706 AstScope* pScope = idlc()->scopes()->topNonNull();
2707 AstEnum* pEnum = NULL;
2708 AstConstant* pEnumVal = NULL;
2710 if ( pScope && pScope->getScopeNodeType() == NT_enum)
2712 pEnum = (AstEnum*)pScope;
2713 if (pEnum && $1)
2715 AstExpression* pExpr = new AstExpression(pEnum->getEnumValueCount());
2716 pEnumVal = new AstConstant(ET_long , NT_enum_val,
2717 pExpr, *$1, pScope);
2719 if ( pEnum->checkValue(pEnumVal->getConstValue()) )
2720 idlc()->error()->error1(EIDL_EVAL_ERROR, pEnum);
2722 pScope->addDeclaration(pEnumVal);
2724 delete $1;
2726 | identifier
2728 const_expr
2730 checkIdentifier($1);
2732 AstScope* pScope = idlc()->scopes()->topNonNull();
2733 AstEnum* pEnum = NULL;
2734 AstConstant* pEnumVal = NULL;
2736 if ( $3 && pScope && pScope->getScopeNodeType() == NT_enum)
2738 $3->evaluate(EK_const);
2739 if ( $3->coerce(ET_long) )
2741 pEnum = (AstEnum*)pScope;
2742 if (pEnum)
2744 pEnumVal = new AstConstant(ET_long , NT_enum_val,
2745 $3, *$1, pScope);
2747 if ( pEnum->checkValue(pEnumVal->getConstValue()) )
2748 idlc()->error()->error1(EIDL_EVAL_ERROR, pEnum);
2750 pScope->addDeclaration(pEnumVal);
2751 } else
2753 idlc()->error()->coercionError($3, ET_long);
2754 delete $3;
2757 delete $1;
2761 identifier:
2762 IDL_IDENTIFIER
2763 | IDL_GET { $$ = new OString("get"); }
2764 | IDL_SET { $$ = new OString("set"); }
2765 | IDL_PUBLISHED { $$ = new OString("published"); }
2771 * Report an error situation discovered in a production
2773 void yyerror(char const *errmsg)
2775 idlc()->error()->syntaxError(idlc()->getParseState(), idlc()->getLineNumber(), errmsg);
2776 idlc()->setParseState(PS_NoState);
2779 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */