fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / idlc / source / parser.y
blob52bcdf862b7fe16c9306706e46050412b9b78522
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"
52 #include <osl/diagnose.h>
54 #include <algorithm>
55 #include <vector>
58 #define YYDEBUG 1
59 #if !(defined MACOSX && defined PPC)
60 #define YYERROR_VERBOSE 1
61 #endif
63 using ::rtl::OUString;
64 using ::rtl::OString;
65 using ::rtl::OStringToOUString;
66 using ::rtl::OStringBuffer;
68 extern int yylex(void);
69 void yyerror(char const *);
71 void checkIdentifier(::rtl::OString* id)
73 static short check = 0;
74 if (check == 0) {
75 if (idlc()->getOptions()->isValid("-cid"))
76 check = 1;
77 else
78 check = 2;
81 if ( id->indexOf('_') >= 0 )
82 if ( (id->pData->buffer[0] >= 97 && id->pData->buffer[0] <= 122)
83 || id->pData->buffer[0] == '_') {
84 if (check == 1) {
85 ::rtl::OStringBuffer msg(25 + id->getLength());
86 msg.append("mismatched identifier '");
87 msg.append(*id);
88 msg.append("'");
89 ErrorHandler::syntaxError(idlc()->getParseState(),
90 idlc()->getLineNumber(),
91 msg.getStr());
93 else
94 ErrorHandler::warning0(WIDL_WRONG_NAMING_CONV, id->getStr());
98 void reportDoubleMemberDeclarations(
99 AstInterface::DoubleMemberDeclarations const & doubleMembers)
101 for (AstInterface::DoubleMemberDeclarations::const_iterator i(
102 doubleMembers.begin());
103 i != doubleMembers.end(); ++i)
105 ErrorHandler::error2(EIDL_DOUBLE_MEMBER, i->first, i->second);
109 void addInheritedInterface(
110 AstInterface * ifc, rtl::OString const & name, bool optional,
111 rtl::OUString const & documentation)
113 AstDeclaration * decl = ifc->lookupByName(name);
114 AstDeclaration const * resolved = resolveTypedefs(decl);
115 if (resolved != 0 && resolved->getNodeType() == NT_interface) {
116 if (ErrorHandler::checkPublished(decl)) {
117 if (!static_cast< AstInterface const * >(resolved)->isDefined()) {
118 ErrorHandler::inheritanceError(
119 NT_interface, &ifc->getScopedName(), decl);
120 } else {
121 AstInterface::DoubleDeclarations doubleDecls(
122 ifc->checkInheritedInterfaceClashes(
123 static_cast< AstInterface const * >(resolved),
124 optional));
125 if (doubleDecls.interfaces.empty()
126 && doubleDecls.members.empty())
128 ifc->addInheritedInterface(
129 static_cast< AstType * >(decl), optional,
130 documentation);
131 } else {
132 for (AstInterface::DoubleInterfaceDeclarations::iterator i(
133 doubleDecls.interfaces.begin());
134 i != doubleDecls.interfaces.end(); ++i)
136 ErrorHandler::error1(
137 EIDL_DOUBLE_INHERITANCE, *i);
139 reportDoubleMemberDeclarations(doubleDecls.members);
143 } else {
144 ErrorHandler::lookupError(
145 EIDL_INTERFACEMEMBER_LOOKUP, name, scopeAsDecl(ifc));
149 AstDeclaration const * createNamedType(
150 rtl::OString const * scopedName, DeclList const * typeArgs)
152 AstDeclaration * decl = idlc()->scopes()->topNonNull()->lookupByName(
153 *scopedName);
154 AstDeclaration const * resolved = resolveTypedefs(decl);
155 if (decl == 0) {
156 ErrorHandler::lookupError(*scopedName);
157 } else if (!ErrorHandler::checkPublished(decl)) {
158 decl = 0;
159 } else if (resolved->getNodeType() == NT_struct) {
160 if (static_cast< AstStruct const * >(resolved)->getTypeParameterCount()
161 != (typeArgs == 0 ? 0 : typeArgs->size()))
163 ErrorHandler::error0(EIDL_WRONG_NUMBER_OF_TYPE_ARGUMENTS);
164 decl = 0;
165 } else if (typeArgs != 0) {
166 AstScope * global = idlc()->scopes()->bottom();
167 AstDeclaration * inst = new AstStructInstance(
168 static_cast< AstType * >(decl), typeArgs, global);
169 decl = global->addDeclaration(inst);
170 if (decl != inst) {
171 delete inst;
174 } else if (decl->isType()) {
175 if (typeArgs != 0) {
176 ErrorHandler::error0(EIDL_WRONG_NUMBER_OF_TYPE_ARGUMENTS);
177 decl = 0;
179 } else {
180 ErrorHandler::noTypeError(decl);
181 decl = 0;
183 delete scopedName;
184 delete typeArgs;
185 return decl;
188 bool includes(AstDeclaration const * type1, AstDeclaration const * type2) {
189 OSL_ASSERT(type2 != 0);
190 if (type1 != 0) {
191 if (type1->getNodeType() == NT_instantiated_struct) {
192 AstStructInstance const * inst
193 = static_cast< AstStructInstance const * >(type1);
194 if (inst->getTypeTemplate() == type2) {
195 return true;
197 for (DeclList::const_iterator i(inst->getTypeArgumentsBegin());
198 i != inst->getTypeArgumentsEnd(); ++i)
200 if (includes(*i, type2)) {
201 return true;
204 } else if (type1 == type2) {
205 return true;
208 return false;
211 // Suppress any warnings from generated code:
212 #if defined _MSC_VER
213 #pragma warning(push, 1)
214 #pragma warning(disable: 4273 4701 4702)
215 #endif
218 * Declare the type of values in the grammar
220 %union {
221 ExprType etval; /* Expression type */
222 AstDeclaration* dclval; /* Declaration */
223 AstDeclaration const * cdclval;
224 DeclList * dclsval;
225 AstExpression* exval; /* expression value */
226 FeDeclarator* fdval; /* declarator value */
227 FeDeclList* dlval; /* declarator list value */
228 FeInheritanceHeader* ihval; /* inheritance header value */
229 ::rtl::OString* sval; /* OString value */
230 std::vector< rtl::OString > * svals;
231 sal_Char* strval; /* sal_Char* value */
232 bool bval; /* sal_Boolean* value */
233 sal_Int64 ival; /* sal_Int64 value */
234 sal_uInt64 uval; /* sal_uInt64 value */
235 sal_uInt32 ulval; /* sal_uInt32 value */
236 double dval; /* double value */
237 float fval; /* float value */
238 StringList* slval; /* StringList value */
239 AttributeExceptions::Part attexcpval;
240 AttributeExceptions attexcval;
244 * Token types: These are returned by the lexer
247 %token <sval> IDL_IDENTIFIER
248 %token IDL_ATTRIBUTE
249 %token IDL_BOUND
250 %token IDL_CONST
251 %token IDL_CONSTANTS
252 %token IDL_CONSTRAINED
253 %token IDL_ENUM
254 %token IDL_EXCEPTION
255 %token IDL_INTERFACE
256 %token IDL_MAYBEAMBIGUOUS
257 %token IDL_MAYBEDEFAULT
258 %token IDL_MAYBEVOID
259 %token IDL_MODULE
260 %token IDL_NEEDS
261 %token IDL_OBSERVES
262 %token IDL_OPTIONAL
263 %token IDL_PROPERTY
264 %token IDL_RAISES
265 %token IDL_READONLY
266 %token IDL_REMOVABLE
267 %token IDL_SERVICE
268 %token IDL_SEQUENCE
269 %token IDL_SINGLETON
270 %token IDL_STRUCT
271 %token IDL_TYPEDEF
272 %token IDL_TRANSIENT
274 %token IDL_ANY
275 %token IDL_CHAR
276 %token IDL_BOOLEAN
277 %token IDL_BYTE
278 %token IDL_DOUBLE
279 %token IDL_FLOAT
280 %token IDL_HYPER
281 %token IDL_LONG
282 %token IDL_SHORT
283 %token IDL_VOID
284 %token IDL_STRING
285 %token IDL_TYPE
286 %token IDL_UNSIGNED
288 %token IDL_TRUE
289 %token IDL_FALSE
291 %token IDL_IN
292 %token IDL_OUT
293 %token IDL_INOUT
295 %token IDL_GET
296 %token IDL_SET
298 %token IDL_PUBLISHED
300 %token IDL_ELLIPSIS
302 %token <strval> IDL_LEFTSHIFT
303 %token <strval> IDL_RIGHTSHIFT
304 %token <strval> IDL_SCOPESEPARATOR
306 %token <ival> IDL_INTEGER_LITERAL
307 %token <uval> IDL_INTEGER_ULITERAL
308 %token <dval> IDL_FLOATING_PT_LITERAL
311 * These are production names:
313 %type <dclval> type_dcl
314 %type <dclval> exception_name
315 %type <cdclval> constructed_type_spec enum_type op_type_spec
316 %type <cdclval> sequence_type_spec simple_type_spec struct_type
317 %type <cdclval> type_spec
318 %type <cdclval> fundamental_type type_arg type_or_parameter
319 %type <dclsval> opt_raises raises exception_list
320 %type <attexcpval> opt_attribute_get_raises attribute_get_raises
321 %type <attexcpval> opt_attribute_set_raises attribute_set_raises
322 %type <dclsval> opt_type_args type_args
324 %type <sval> identifier
325 %type <sval> interface_decl
326 %type <sval> scoped_name inheritance_spec
327 %type <slval> scoped_names at_least_one_scoped_name
329 %type <etval> const_type integer_type char_type boolean_type
330 %type <etval> floating_pt_type any_type signed_int string_type
331 %type <etval> unsigned_int base_type_spec byte_type type_type
333 %type <exval> expression const_expr or_expr xor_expr and_expr
334 %type <exval> add_expr mult_expr unary_expr primary_expr shift_expr
335 %type <exval> literal
337 %type <fdval> declarator
338 %type <dlval> declarators at_least_one_declarator
340 %type <ihval> exception_header structure_header interfaceheader
342 %type <ulval> flag_header opt_attrflags opt_attrflag
343 %type <ulval> direction service_interface_header service_service_header
345 %type <bval> optional_inherited_interface opt_rest opt_service_body
347 %type <attexcval> opt_attribute_block attribute_block_rest opt_attribute_raises
349 %type <svals> opt_type_params type_params
353 * Grammar start here
355 start : definitions;
357 definitions :
358 definition definitions
359 | /* EMPTY */
362 definition :
363 opt_published publishable_definition
364 | module_dcl
366 idlc()->setParseState(PS_ModuleDeclSeen);
370 idlc()->setParseState(PS_NoState);
372 | error ';'
374 yyerror("definitions");
375 yyerrok;
379 opt_published:
380 IDL_PUBLISHED { idlc()->setPublished(true); }
381 | /* empty */ { idlc()->setPublished(false); }
384 publishable_definition:
385 type_dcl
387 idlc()->setParseState(PS_TypeDeclSeen);
391 idlc()->setParseState(PS_NoState);
393 | exception_dcl
395 idlc()->setParseState(PS_ExceptionDeclSeen);
399 idlc()->setParseState(PS_NoState);
401 | interface
403 idlc()->setParseState(PS_InterfaceDeclSeen);
407 idlc()->setParseState(PS_NoState);
409 | service_dcl
411 idlc()->setParseState(PS_ServiceDeclSeen);
415 idlc()->setParseState(PS_NoState);
417 | singleton_dcl
419 idlc()->setParseState(PS_SingletonDeclSeen);
423 idlc()->setParseState(PS_NoState);
425 | constants_dcl
427 idlc()->setParseState(PS_ConstantsDeclSeen);
431 idlc()->setParseState(PS_NoState);
435 module_dcl :
436 IDL_MODULE
438 idlc()->setParseState(PS_ModuleSeen);
439 idlc()->setPublished(false);
441 identifier
443 idlc()->setParseState(PS_ModuleIDSeen);
444 checkIdentifier($3);
446 AstScope* pScope = idlc()->scopes()->topNonNull();
447 AstModule* pModule = NULL;
448 AstDeclaration* pExists = NULL;
450 if ( pScope )
452 pModule = new AstModule(*$3, pScope);
453 if( (pExists = pScope->lookupForAdd(pModule)) )
455 pExists->setInMainfile(idlc()->isInMainFile());
456 pExists->setFileName(pModule->getFileName());
457 if (pExists->isPredefined())
459 pExists->setPredefined(false);
460 if (pExists->getDocumentation().getLength() == 0 &&
461 pModule->getDocumentation().getLength() > 0)
463 pExists->setDocumentation(pModule->getDocumentation());
466 delete(pModule);
467 pModule = static_cast<AstModule*>(pExists);
468 } else
470 pScope->addDeclaration(pModule);
472 idlc()->scopes()->push(pModule);
474 delete $3;
478 idlc()->setParseState(PS_ModuleSqSeen);
480 definitions
482 idlc()->setParseState(PS_ModuleBodySeen);
486 idlc()->setParseState(PS_ModuleQsSeen);
488 * Finished with this module - pop it from the scope stack
490 idlc()->scopes()->pop();
494 interface :
495 interface_dcl
496 | forward_dcl
499 interface_decl :
500 IDL_INTERFACE
502 idlc()->setParseState(PS_InterfaceSeen);
504 identifier
506 idlc()->setParseState(PS_InterfaceIDSeen);
507 checkIdentifier($3);
508 $$ = $3;
512 forward_dcl :
513 interface_decl
515 idlc()->setParseState(PS_ForwardDeclSeen);
517 AstScope* pScope = idlc()->scopes()->topNonNull();
518 AstInterface* pForward = NULL;
519 AstDeclaration* pDecl = NULL;
522 * Make a new forward interface node and add it to its enclosing scope
524 if ( pScope && $1 )
526 pForward = new AstInterface(*$1, NULL, pScope);
528 pDecl = pScope->lookupByName(pForward->getScopedName());
529 if ( pDecl )
531 if ( (pDecl != pForward) &&
532 (pDecl->getNodeType() == NT_interface) )
534 delete pForward;
535 } else
537 ErrorHandler::error2(EIDL_REDEF_SCOPE, scopeAsDecl(pScope), pDecl);
539 } else
542 * Add the interface to its definition scope
544 pScope->addDeclaration(pForward);
547 delete $1;
551 interface_dcl :
552 interfaceheader
554 idlc()->setParseState(PS_InterfaceHeadSeen);
556 AstScope* pScope = idlc()->scopes()->topNonNull();
557 AstInterface* pInterface = NULL;
558 AstInterface* pForward = NULL;
559 AstDeclaration* pDecl = NULL;
562 * Make a new interface node and add it to its enclosing scope
564 if ( pScope && $1 )
566 pInterface = new AstInterface(
567 *$1->getName(),
568 static_cast< AstInterface const * >(resolveTypedefs($1->getInherits())), pScope);
569 if ( (pDecl = pScope->lookupByName(pInterface->getScopedName())) )
572 * See if we're defining a forward declared interface.
574 if (pDecl->getNodeType() == NT_interface)
576 pForward = static_cast<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 ErrorHandler::error3(EIDL_SCOPE_CONFLICT,
587 pInterface, pForward, scopeAsDecl(pScope));
590 else if ( !pInterface->isPublished()
591 && pForward->isPublished() )
593 ErrorHandler::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 ErrorHandler::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 ErrorHandler::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 ErrorHandler::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 const *pType = static_cast<AstType const *>($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 = static_cast<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 ErrorHandler::error0(EIDL_CONSTRUCTOR_PARAMETER_NOT_IN);
1062 if (pScope->isVariadic()) {
1063 ErrorHandler::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 ErrorHandler::error0(EIDL_REST_PARAMETER_NOT_ANY);
1073 if (pScope->isConstructor()) {
1074 if (pScope->getIteratorBegin()
1075 != pScope->getIteratorEnd())
1077 ErrorHandler::error0(
1078 EIDL_CONSTRUCTOR_REST_PARAMETER_NOT_FIRST);
1080 } else {
1081 ErrorHandler::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 ErrorHandler::lookupError(*$1);
1180 } else if (!ErrorHandler::checkPublished(decl)) {
1181 decl = 0;
1182 } else if (decl->getNodeType() != NT_exception) {
1183 ErrorHandler::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 ErrorHandler::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 ErrorHandler::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 = static_cast<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 const_type :
1438 integer_type
1439 | byte_type
1440 | boolean_type
1441 | floating_pt_type
1442 | scoped_name
1444 AstScope* pScope = idlc()->scopes()->topNonNull();
1445 AstDeclaration const * type = 0;
1448 * If the constant's type is a scoped name, it must resolve
1449 * to a scalar constant type
1451 if ( pScope && (type = pScope->lookupByName(*$1)) ) {
1452 if (!ErrorHandler::checkPublished(type))
1454 type = 0;
1455 $$ = ET_none;
1457 else
1459 type = resolveTypedefs(type);
1460 if (type->getNodeType() == NT_predefined)
1462 $$ = static_cast< AstBaseType const * >(type)->
1463 getExprType();
1464 } else
1465 $$ = ET_any;
1467 } else
1468 $$ = ET_any;
1472 exception_header :
1473 IDL_EXCEPTION
1475 idlc()->setParseState(PS_ExceptSeen);
1477 identifier
1479 idlc()->setParseState(PS_ExceptIDSeen);
1480 checkIdentifier($3);
1482 inheritance_spec
1484 idlc()->setParseState(PS_InheritSpecSeen);
1486 $$ = new FeInheritanceHeader(NT_exception, $3, $5, 0);
1487 delete $5;
1491 exception_dcl :
1492 exception_header
1494 idlc()->setParseState(PS_ExceptHeaderSeen);
1496 AstScope* pScope = idlc()->scopes()->topNonNull();
1497 AstException* pExcept = NULL;
1499 if ( pScope )
1501 AstException* pBase = static_cast< AstException* >(
1502 $1->getInherits());
1503 pExcept = new AstException(*$1->getName(), pBase, pScope);
1504 pScope->addDeclaration(pExcept);
1507 * Push the scope of the exception on the scopes stack
1509 idlc()->scopes()->push(pExcept);
1510 delete $1;
1514 idlc()->setParseState(PS_ExceptSqSeen);
1516 members
1518 idlc()->setParseState(PS_ExceptBodySeen);
1522 idlc()->setParseState(PS_ExceptQsSeen);
1523 /* this exception is finished, pop its scope from the stack */
1524 idlc()->scopes()->pop();
1528 property :
1529 flag_header
1530 simple_type_spec
1532 idlc()->setParseState(PS_PropertyTypeSeen);
1534 at_least_one_declarator
1536 idlc()->setParseState(PS_PropertyCompleted);
1538 AstScope* pScope = idlc()->scopes()->topNonNull();
1539 AstAttribute* pAttr = NULL;
1540 FeDeclList* pList = $4;
1541 FeDeclarator* pDecl = NULL;
1542 AstType const * pType = NULL;
1544 if ( pScope->getScopeNodeType() == NT_singleton )
1546 ErrorHandler::error0(EIDL_ILLEGAL_ADD);
1547 } else
1549 if ( ($1 & AF_ATTRIBUTE) == AF_ATTRIBUTE )
1550 ErrorHandler::flagError(EIDL_WRONGATTRIBUTEKEYWORD, AF_ATTRIBUTE);
1552 if ( ($1 & AF_PROPERTY) != AF_PROPERTY )
1553 ErrorHandler::flagError(EIDL_MISSINGATTRIBUTEKEYWORD, AF_PROPERTY);
1556 * Create nodes representing attributes and add them to the
1557 * enclosing scope
1559 if ( pScope && $2 && pList )
1561 FeDeclList::iterator iter = pList->begin();
1562 FeDeclList::iterator end = pList->end();
1564 while (iter != end)
1566 pDecl = (*iter);
1567 if ( !pDecl )
1569 iter++;
1570 continue;
1573 pType = pDecl->compose($2);
1575 if ( !pType )
1577 iter++;
1578 continue;
1581 pAttr = new AstAttribute(NT_property, $1, pType, pDecl->getName(), pScope);
1583 pScope->addDeclaration(pAttr);
1584 iter++;
1585 delete pDecl;
1590 if ( pList )
1591 delete pList;
1593 | error ';'
1595 yyerror("property");
1596 yyerrok;
1600 service_exports :
1601 service_exports service_export
1602 | /* EMPTY */
1605 service_export :
1606 service_interface_header
1607 at_least_one_scoped_name
1610 idlc()->setParseState(PS_ServiceMemberSeen);
1612 AstScope* pScope = idlc()->scopes()->topNonNull();
1613 AstDeclaration* pDecl = NULL;
1614 AstInterfaceMember* pIMember = NULL;
1616 if ( pScope->getScopeNodeType() == NT_singleton )
1618 ErrorHandler::error0(EIDL_ILLEGAL_ADD);
1619 } else
1622 * Create a node representing a class member.
1623 * Store it in the enclosing scope
1625 if ( pScope && $2 )
1627 StringList::iterator iter = $2->begin();
1628 StringList::iterator end = $2->end();
1630 while ( iter != end )
1632 pDecl = pScope->lookupByName(*iter);
1633 if ( pDecl && (pDecl->getNodeType() == NT_interface) )
1635 /* we relax the strict published check and allow to add new
1636 * interfaces if they are optional
1638 bool bOptional = (($1 & AF_OPTIONAL) == AF_OPTIONAL);
1639 if ( ErrorHandler::checkPublished(pDecl, bOptional) )
1641 pIMember = new AstInterfaceMember(
1642 $1, static_cast<AstInterface*>(pDecl), *iter, pScope);
1643 pScope->addDeclaration(pIMember);
1645 } else
1647 ErrorHandler::lookupError(EIDL_INTERFACEMEMBER_LOOKUP, *iter, scopeAsDecl(pScope));
1649 iter++;
1653 delete $2;
1655 | service_service_header
1656 at_least_one_scoped_name
1659 idlc()->setParseState(PS_ServiceMemberSeen);
1661 AstScope* pScope = idlc()->scopes()->topNonNull();
1662 AstDeclaration* pDecl = NULL;
1663 AstServiceMember* pSMember = NULL;
1666 * Create a node representing a class member.
1667 * Store it in the enclosing scope
1669 if ( pScope && $2 )
1671 StringList::iterator iter = $2->begin();
1672 StringList::iterator end = $2->end();
1674 while ( iter != end )
1676 pDecl = pScope->lookupByName(*iter);
1677 if ( pDecl && (pDecl->getNodeType() == NT_service) )
1679 if ( static_cast< AstService * >(pDecl)->isSingleInterfaceBasedService() || (pScope->getScopeNodeType() == NT_singleton && pScope->nMembers() > 0) )
1680 ErrorHandler::error0(EIDL_ILLEGAL_ADD);
1681 else if ( ErrorHandler::checkPublished(pDecl) )
1683 pSMember = new AstServiceMember(
1684 $1, static_cast<AstService*>(pDecl), *iter, pScope);
1685 pScope->addDeclaration(pSMember);
1687 } else
1689 ErrorHandler::lookupError(EIDL_SERVICEMEMBER_LOOKUP, *iter, scopeAsDecl(pScope));
1691 iter++;
1694 delete $2;
1696 | IDL_OBSERVES
1697 at_least_one_scoped_name
1700 idlc()->setParseState(PS_ServiceMemberSeen);
1702 AstScope* pScope = idlc()->scopes()->topNonNull();
1703 AstDeclaration* pDecl = NULL;
1704 AstObserves* pObserves = NULL;
1706 if ( pScope->getScopeNodeType() == NT_singleton )
1708 ErrorHandler::error0(EIDL_ILLEGAL_ADD);
1709 } else
1712 * Create a node representing a class member.
1713 * Store it in the enclosing scope
1715 if ( pScope && $2 )
1717 StringList::iterator iter = $2->begin();
1718 StringList::iterator end = $2->end();
1720 while ( iter != end )
1722 pDecl = pScope->lookupByName(*iter);
1723 if ( pDecl && (pDecl->getNodeType() == NT_interface) )
1725 pObserves = new AstObserves(static_cast<AstInterface*>(pDecl), *iter, pScope);
1726 pScope->addDeclaration(pObserves);
1727 } else
1729 ErrorHandler::lookupError(EIDL_INTERFACEMEMBER_LOOKUP, *iter, scopeAsDecl(pScope));
1731 iter++;
1735 delete $2;
1737 | IDL_NEEDS
1738 at_least_one_scoped_name
1741 idlc()->setParseState(PS_ServiceMemberSeen);
1743 AstScope* pScope = idlc()->scopes()->topNonNull();
1744 AstDeclaration* pDecl = NULL;
1745 AstNeeds* pNeeds = NULL;
1747 if ( pScope->getScopeNodeType() == NT_singleton )
1749 ErrorHandler::error0(EIDL_ILLEGAL_ADD);
1750 } else
1753 * Create a node representing a class member.
1754 * Store it in the enclosing scope
1756 if ( pScope && $2 )
1758 StringList::iterator iter = $2->begin();
1759 StringList::iterator end = $2->end();
1761 while ( iter != end )
1763 pDecl = pScope->lookupByName(*iter);
1764 if ( pDecl && (pDecl->getNodeType() == NT_service) )
1766 pNeeds = new AstNeeds(static_cast<AstService*>(pDecl), *iter, pScope);
1767 pScope->addDeclaration(pNeeds);
1768 } else
1770 ErrorHandler::lookupError(EIDL_SERVICEMEMBER_LOOKUP, *iter, scopeAsDecl(pScope));
1772 iter++;
1776 delete $2;
1778 | property
1781 idlc()->setParseState(PS_PropertyDeclSeen);
1785 service_interface_header :
1786 IDL_INTERFACE
1788 idlc()->setParseState(PS_ServiceIFHeadSeen);
1789 $$ = AF_INVALID;
1791 | flag_header
1792 IDL_INTERFACE
1794 idlc()->setParseState(PS_ServiceIFHeadSeen);
1795 if ( (AF_OPTIONAL != $1) && ( AF_INVALID != $1) )
1796 ErrorHandler::flagError(EIDL_OPTIONALEXPECTED, $1);
1797 $$ = $1;
1801 service_service_header :
1802 IDL_SERVICE
1804 idlc()->setParseState(PS_ServiceSHeadSeen);
1805 $$ = AF_INVALID;
1807 | flag_header
1808 IDL_SERVICE
1810 idlc()->setParseState(PS_ServiceSHeadSeen);
1811 if ( (AF_OPTIONAL != $1) && ( AF_INVALID != $1) )
1812 ErrorHandler::flagError(EIDL_OPTIONALEXPECTED, $1);
1813 $$ = $1;
1817 service_dcl :
1818 IDL_SERVICE
1820 idlc()->setParseState(PS_ServiceSeen);
1822 identifier
1824 idlc()->setParseState(PS_ServiceIDSeen);
1825 checkIdentifier($3);
1827 AstScope* pScope = idlc()->scopes()->topNonNull();
1828 AstService* pService = NULL;
1831 * Make a new service and add it to the enclosing scope
1833 if (pScope != NULL)
1835 pService = new AstService(*$3, pScope);
1836 pScope->addDeclaration(pService);
1838 delete $3;
1840 * Push it on the stack
1842 idlc()->scopes()->push(pService);
1844 service_dfn
1846 /* this service is finished, pop its scope from the stack */
1847 idlc()->scopes()->pop();
1851 service_dfn:
1852 service_interface_dfn
1853 | service_obsolete_dfn
1856 service_interface_dfn:
1857 ':' scoped_name
1859 AstScope * scope = idlc()->scopes()->nextToTop();
1860 // skip the scope pushed by service_dcl
1861 AstDeclaration * decl = scope->lookupByName(*$2);
1862 if (decl != 0 && resolveTypedefs(decl)->getNodeType() == NT_interface) {
1863 if (ErrorHandler::checkPublished(decl)) {
1864 idlc()->scopes()->top()->addDeclaration(decl);
1866 } else {
1867 ErrorHandler::lookupError(
1868 EIDL_INTERFACEMEMBER_LOOKUP, *$2, scopeAsDecl(scope));
1870 delete $2;
1872 opt_service_body
1874 AstService * s = static_cast< AstService * >(idlc()->scopes()->top());
1875 if (s != 0) {
1876 s->setSingleInterfaceBasedService();
1877 s->setDefaultConstructor(!$4);
1882 opt_service_body:
1883 service_body { $$ = true; }
1884 | /* empty */ { $$ = false; }
1887 service_body:
1889 constructors
1893 constructors:
1894 constructors constructor
1895 | /* empty */
1898 constructor:
1899 identifier
1901 checkIdentifier($1);
1902 AstScope * scope = idlc()->scopes()->top();
1903 AstOperation * ctor = new AstOperation(0, *$1, scope);
1904 delete $1;
1905 scope->addDeclaration(ctor);
1906 idlc()->scopes()->push(ctor);
1909 parameters
1911 opt_raises
1913 static_cast< AstOperation * >(idlc()->scopes()->top())->setExceptions(
1914 $6);
1915 delete $6;
1916 idlc()->scopes()->pop();
1917 if (static_cast< AstService * >(idlc()->scopes()->top())->
1918 checkLastConstructor())
1920 ErrorHandler::error0(EIDL_SIMILAR_CONSTRUCTORS);
1926 singleton_dcl :
1927 IDL_SINGLETON
1929 idlc()->setParseState(PS_SingletonSeen);
1931 identifier
1933 idlc()->setParseState(PS_SingletonIDSeen);
1934 checkIdentifier($3);
1936 AstScope* pScope = idlc()->scopes()->topNonNull();
1937 AstService* pService = NULL;
1940 * Make a new service and add it to the enclosing scope
1942 if (pScope != NULL)
1944 pService = new AstService(NT_singleton, *$3, pScope);
1945 pScope->addDeclaration(pService);
1947 delete $3;
1949 * Push it on the stack
1951 idlc()->scopes()->push(pService);
1953 singleton_dfn
1955 /* this singelton is finished, pop its scope from the stack */
1956 idlc()->scopes()->pop();
1960 singleton_dfn:
1961 singleton_interface_dfn
1962 | service_obsolete_dfn
1965 singleton_interface_dfn:
1966 ':' scoped_name
1968 AstScope * scope = idlc()->scopes()->nextToTop();
1969 // skip the scope (needlessly) pushed by singleton_dcl
1970 AstDeclaration * decl = scope->lookupByName(*$2);
1971 if (decl != 0 && resolveTypedefs(decl)->getNodeType() == NT_interface) {
1972 if (ErrorHandler::checkPublished(decl)) {
1973 idlc()->scopes()->top()->addDeclaration(decl);
1975 } else {
1976 ErrorHandler::lookupError(
1977 EIDL_INTERFACEMEMBER_LOOKUP, *$2, scopeAsDecl(scope));
1979 delete $2;
1983 service_obsolete_dfn:
1986 idlc()->setParseState(
1987 idlc()->scopes()->top()->getScopeNodeType() == NT_service
1988 ? PS_ServiceSqSeen : PS_SingletonSqSeen);
1990 service_exports
1992 idlc()->setParseState(
1993 idlc()->scopes()->top()->getScopeNodeType() == NT_service
1994 ? PS_ServiceBodySeen : PS_SingletonBodySeen);
1998 idlc()->setParseState(
1999 idlc()->scopes()->top()->getScopeNodeType() == NT_service
2000 ? PS_ServiceQsSeen : PS_SingletonQsSeen);
2004 type_dcl :
2005 IDL_TYPEDEF
2007 idlc()->setParseState(PS_TypedefSeen);
2009 type_declarator {}
2010 | struct_type {}
2011 | enum_type {}
2014 type_declarator :
2015 type_spec
2017 idlc()->setParseState(PS_TypeSpecSeen);
2018 if ($1 != 0 && $1->getNodeType() == NT_instantiated_struct) {
2019 ErrorHandler::error0(EIDL_INSTANTIATED_STRUCT_TYPE_TYPEDEF);
2022 at_least_one_declarator
2024 idlc()->setParseState(PS_DeclaratorsSeen);
2026 AstScope* pScope = idlc()->scopes()->topNonNull();
2027 AstTypeDef* pTypeDef = NULL;
2028 FeDeclList* pList = $3;
2029 FeDeclarator* pDecl = NULL;
2030 AstType const * pType = NULL;
2033 * Create nodes representing typedefs and add them to the
2034 * enclosing scope
2036 if ( pScope && $1 && pList )
2038 FeDeclList::iterator iter = pList->begin();
2039 FeDeclList::iterator end = pList->end();
2041 while (iter != end)
2043 pDecl = (*iter);
2044 if ( !pDecl )
2046 iter++;
2047 continue;
2050 pType = pDecl->compose($1);
2052 if ( !pType )
2054 iter++;
2055 continue;
2058 pTypeDef = new AstTypeDef(pType, pDecl->getName(), pScope);
2060 pScope->addDeclaration(pTypeDef);
2061 iter++;
2062 delete pDecl;
2064 delete pList;
2069 at_least_one_declarator :
2070 declarator declarators
2072 if ( $2 )
2074 $2->push_back($1);
2075 $$ = $2;
2076 } else
2078 FeDeclList* pList = new FeDeclList();
2079 pList->push_back($1);
2080 $$ = pList;
2085 declarators :
2086 declarators
2089 idlc()->setParseState(PS_DeclsCommaSeen);
2091 declarator
2093 idlc()->setParseState(PS_DeclsDeclSeen);
2094 if ( $1 )
2096 $1->push_back($4);
2097 $$ = $1;
2098 } else
2100 FeDeclList* pList = new FeDeclList();
2101 pList->push_back($4);
2102 $$ = pList;
2105 | /* EMPTY */
2107 $$ = NULL;
2111 declarator :
2112 identifier
2114 // For historic reasons, the struct com.sun.star.uno.Uik contains
2115 // members with illegal names (of the form "m_DataN"); avoid useless
2116 // warnings about them:
2117 AstScope * scope = idlc()->scopes()->top();
2118 if (scope == 0 || scope->getScopeNodeType() != NT_struct
2119 || (scopeAsDecl(scope)->getScopedName()
2120 != "com::sun::star::uno::Uik"))
2122 checkIdentifier($1);
2125 $$ = new FeDeclarator(*$1, FeDeclarator::FD_simple, NULL);
2126 delete $1;
2130 at_least_one_scoped_name :
2131 scoped_name scoped_names
2133 if ($2)
2135 $2->push_front(*$1);
2136 $$ = $2;
2137 } else
2139 StringList* pScopedNames = new StringList();
2140 // coverity [copy_paste_error]
2141 pScopedNames->push_back(*$1);
2142 $$ = pScopedNames;
2144 delete($1);
2148 scoped_names :
2149 scoped_names
2152 idlc()->setParseState(PS_SNListCommaSeen);
2154 scoped_name
2156 idlc()->setParseState(PS_ScopedNameSeen);
2157 if ($1)
2159 $1->push_back(*$4);
2160 $$ = $1;
2161 } else
2163 StringList* pNames = new StringList();
2164 pNames->push_back(*$4);
2165 $$ = pNames;
2167 delete($4);
2169 | /* EMPTY */
2171 $$ = NULL;
2175 scoped_name :
2176 identifier
2178 idlc()->setParseState(PS_SN_IDSeen);
2179 checkIdentifier($1);
2180 $$ = $1;
2182 | IDL_SCOPESEPARATOR
2184 idlc()->setParseState(PS_ScopeDelimSeen);
2186 identifier
2188 checkIdentifier($3);
2189 OString* pName = new OString("::");
2190 *pName += *$3;
2191 delete $3;
2192 $$ = pName;
2194 | scoped_name
2195 IDL_SCOPESEPARATOR
2198 identifier
2200 checkIdentifier($4);
2201 *$1 += ::rtl::OString("::");
2202 *$1 += *$4;
2203 delete $4;
2204 $$ = $1;
2208 type_spec :
2209 simple_type_spec
2210 | constructed_type_spec
2213 simple_type_spec :
2214 fundamental_type
2215 | scoped_name opt_type_args
2217 $$ = createNamedType($1, $2);
2221 fundamental_type:
2222 base_type_spec
2224 $$ = idlc()->scopes()->bottom()->lookupPrimitiveType($1);
2226 | sequence_type_spec
2229 opt_type_args:
2230 '<' type_args '>' { $$ = $2; }
2231 | /* empty */ { $$ = 0; }
2234 type_args:
2235 type_arg
2237 $$ = new DeclList;
2238 $$->push_back(const_cast< AstDeclaration * >($1)); //TODO: const_cast
2240 | type_args ',' type_arg
2242 $1->push_back(const_cast< AstDeclaration * >($3)); //TODO: const_cast
2243 $$ = $1;
2247 type_arg:
2248 simple_type_spec
2250 if ($1 != 0 && static_cast< AstType const * >($1)->isUnsigned()) {
2251 ErrorHandler::error0(EIDL_UNSIGNED_TYPE_ARGUMENT);
2253 $$ = $1;
2257 base_type_spec :
2258 integer_type
2259 | floating_pt_type
2260 | char_type
2261 | boolean_type
2262 | byte_type
2263 | any_type
2264 | type_type
2265 | string_type
2268 integer_type :
2269 signed_int
2270 | unsigned_int
2273 signed_int :
2274 IDL_LONG
2276 $$ = ET_long;
2278 | IDL_HYPER
2280 $$ = ET_hyper;
2282 | IDL_SHORT
2284 $$ = ET_short;
2288 unsigned_int :
2289 IDL_UNSIGNED IDL_LONG
2291 $$ = ET_ulong;
2293 | IDL_UNSIGNED IDL_HYPER
2295 $$ = ET_uhyper;
2297 | IDL_UNSIGNED IDL_SHORT
2299 $$ = ET_ushort;
2303 floating_pt_type :
2304 IDL_DOUBLE
2306 $$ = ET_double;
2308 | IDL_FLOAT
2310 $$ = ET_float;
2314 char_type :
2315 IDL_CHAR
2317 $$ = ET_char;
2321 byte_type :
2322 IDL_BYTE
2324 $$ = ET_byte;
2328 boolean_type :
2329 IDL_BOOLEAN
2331 $$ = ET_boolean;
2335 any_type :
2336 IDL_ANY
2338 $$ = ET_any;
2342 type_type :
2343 IDL_TYPE
2345 $$ = ET_type;
2349 string_type :
2350 IDL_STRING
2352 $$ = ET_string;
2356 constructed_type_spec :
2357 struct_type
2358 | enum_type
2361 sequence_type_spec :
2362 IDL_SEQUENCE
2364 idlc()->setParseState(PS_SequenceSeen);
2366 * Push a sequence marker on scopes stack
2368 idlc()->scopes()->push(NULL);
2372 idlc()->setParseState(PS_SequenceSqSeen);
2374 simple_type_spec
2376 idlc()->setParseState(PS_SequenceTypeSeen);
2380 idlc()->setParseState(PS_SequenceQsSeen);
2382 * Remove sequence marker from scopes stack
2384 if (idlc()->scopes()->top() == NULL)
2385 idlc()->scopes()->pop();
2387 * Create a node representing a sequence
2389 AstScope* pScope = idlc()->scopes()->bottom();
2390 AstDeclaration* pDecl = NULL;
2391 AstDeclaration* pSeq = NULL;
2393 if ( $5 )
2395 AstType const *pType = static_cast<AstType const *>($5);
2396 if ( pType )
2398 pSeq = new AstSequence(pType, pScope);
2400 * Add this AstSequence to the types defined in the global scope
2402 pDecl = pScope->addDeclaration(pSeq);
2403 if ( pSeq != pDecl )
2405 // if sequence type already defined then use it
2406 delete pSeq;
2407 pSeq = pDecl;
2411 $$ = pSeq;
2413 | error '>'
2415 yyerror("sequence declaration");
2416 yyerrok;
2417 $$ = 0;
2421 struct_type :
2422 structure_header
2424 idlc()->setParseState(PS_StructHeaderSeen);
2426 AstScope* pScope = idlc()->scopes()->topNonNull();
2427 AstStruct* pStruct = NULL;
2429 if ( pScope )
2431 AstStruct const* pBase= static_cast< AstStruct const* >(resolveTypedefs($1->getInherits()));
2432 pStruct = new AstStruct(
2433 *$1->getName(), $1->getTypeParameters(), pBase, pScope);
2434 pScope->addDeclaration(pStruct);
2437 * Push the scope of the struct on the scopes stack
2439 idlc()->scopes()->push(pStruct);
2440 delete $1;
2444 idlc()->setParseState(PS_StructSqSeen);
2446 at_least_one_member
2448 idlc()->setParseState(PS_StructBodySeen);
2452 idlc()->setParseState(PS_StructQsSeen);
2453 /* this exception is finished, pop its scope from the stack */
2454 idlc()->scopes()->pop();
2458 structure_header :
2459 IDL_STRUCT
2461 idlc()->setParseState(PS_StructSeen);
2463 identifier
2465 idlc()->setParseState(PS_StructIDSeen);
2466 checkIdentifier($3);
2468 opt_type_params
2469 inheritance_spec
2471 idlc()->setParseState(PS_InheritSpecSeen);
2473 // Polymorphic struct type templates with base types would cause various
2474 // problems in language bindings, so forbid them here. For example,
2475 // GCC prior to version 3.4 fails with code like
2477 // struct Base { ... };
2478 // template< typename typeparam_T > struct Derived: public Base {
2479 // int member1 CPPU_GCC3_ALIGN(Base);
2480 // ... };
2482 // (Note that plain struct types with instantiated polymorphic struct
2483 // type bases, which might also cause problems in language bindings, are
2484 // already rejected on a syntactic level.)
2485 if ($5 != 0 && $6 != 0) {
2486 ErrorHandler::error0(EIDL_STRUCT_TYPE_TEMPLATE_WITH_BASE);
2489 $$ = new FeInheritanceHeader(NT_struct, $3, $6, $5);
2490 delete $5;
2491 delete $6;
2495 opt_type_params:
2496 '<' type_params '>' { $$ = $2; }
2497 | /* empty */ { $$ = 0; }
2500 type_params:
2501 identifier
2503 $$ = new std::vector< rtl::OString >;
2504 $$->push_back(*$1);
2505 delete $1;
2507 | type_params ',' identifier
2509 if (std::find($1->begin(), $1->end(), *$3) != $1->end()) {
2510 ErrorHandler::error0(EIDL_IDENTICAL_TYPE_PARAMETERS);
2512 $1->push_back(*$3);
2513 delete $3;
2514 $$ = $1;
2518 at_least_one_member : member members ;
2520 members :
2521 members member
2522 | /* EMPTY */
2525 member :
2526 type_or_parameter
2528 idlc()->setParseState(PS_MemberTypeSeen);
2530 at_least_one_declarator
2532 idlc()->setParseState(PS_MemberDeclsSeen);
2536 idlc()->setParseState(PS_MemberDeclsCompleted);
2538 AstScope* pScope = idlc()->scopes()->topNonNull();
2539 AstMember* pMember = NULL;
2540 FeDeclList* pList = $3;
2541 FeDeclarator* pDecl = NULL;
2542 AstType const * pType = NULL;
2544 // !!! check recursive type
2546 if ( pScope && pList && $1 )
2548 FeDeclList::iterator iter = pList->begin();
2549 FeDeclList::iterator end = pList->end();
2550 while (iter != end)
2552 pDecl = (*iter);
2553 if ( !pDecl )
2555 iter++;
2556 continue;
2559 pType = pDecl->compose($1);
2561 if ( !pType )
2563 iter++;
2564 continue;
2567 pMember = new AstMember(pType, pDecl->getName(), pScope);
2569 if ( !pDecl->checkType($1) )
2571 // WARNING
2574 pScope->addDeclaration(pMember);
2575 iter++;
2576 delete pDecl;
2578 delete pList;
2581 | error ';'
2583 yyerror("member definition");
2584 yyerrok;
2588 type_or_parameter:
2589 fundamental_type
2590 | scoped_name opt_type_args
2592 AstDeclaration const * decl = 0;
2593 AstStruct * scope = static_cast< AstStruct * >(idlc()->scopes()->top());
2594 if (scope != 0 && $2 == 0) {
2595 decl = scope->findTypeParameter(*$1);
2597 if (decl != 0) {
2598 delete $1;
2599 delete $2;
2600 } else {
2601 decl = createNamedType($1, $2);
2602 if (scope != 0 && includes(decl, scopeAsDecl(scope))) {
2603 ErrorHandler::error1(
2604 EIDL_RECURSIVE_TYPE, scopeAsDecl(scope));
2605 decl = 0;
2608 $$ = decl;
2612 enum_type :
2613 IDL_ENUM
2615 idlc()->setParseState(PS_EnumSeen);
2617 identifier
2619 idlc()->setParseState(PS_EnumIDSeen);
2620 checkIdentifier($3);
2622 AstScope* pScope = idlc()->scopes()->topNonNull();
2623 AstEnum* pEnum = NULL;
2626 * Create a node representing an enum and add it to its
2627 * enclosing scope
2629 if (pScope != NULL)
2631 pEnum = new AstEnum(*$3, pScope);
2633 * Add it to its defining scope
2635 pScope->addDeclaration(pEnum);
2637 delete $3;
2639 * Push the enum scope on the scopes stack
2641 idlc()->scopes()->push(pEnum);
2646 idlc()->setParseState(PS_EnumSqSeen);
2648 at_least_one_enumerator
2650 idlc()->setParseState(PS_EnumBodySeen);
2654 idlc()->setParseState(PS_EnumQsSeen);
2656 * Done with this enum. Pop its scope from the scopes stack
2658 if (idlc()->scopes()->top() == NULL)
2659 $$ = NULL;
2660 else
2662 $$ = static_cast<AstEnum*>(idlc()->scopes()->topNonNull());
2663 idlc()->scopes()->pop();
2668 at_least_one_enumerator : enumerator enumerators ;
2670 enumerators :
2671 enumerators
2674 idlc()->setParseState(PS_EnumCommaSeen);
2676 enumerator
2677 | /* EMPTY */
2678 | error ','
2680 yyerror("enumerator definition");
2681 yyerrok;
2685 enumerator :
2686 identifier
2688 checkIdentifier($1);
2690 AstScope* pScope = idlc()->scopes()->topNonNull();
2691 AstEnum* pEnum = NULL;
2692 AstConstant* pEnumVal = NULL;
2694 if ( pScope && pScope->getScopeNodeType() == NT_enum)
2696 pEnum = static_cast<AstEnum*>(pScope);
2697 if (pEnum && $1)
2699 AstExpression* pExpr = new AstExpression(pEnum->getEnumValueCount());
2700 pEnumVal = new AstConstant(ET_long , NT_enum_val,
2701 pExpr, *$1, pScope);
2703 if ( pEnum->checkValue(pEnumVal->getConstValue()) )
2704 ErrorHandler::error1(EIDL_EVAL_ERROR, pEnum);
2706 pScope->addDeclaration(pEnumVal);
2708 delete $1;
2710 | identifier
2712 const_expr
2714 checkIdentifier($1);
2716 AstScope* pScope = idlc()->scopes()->topNonNull();
2717 AstEnum* pEnum = NULL;
2718 AstConstant* pEnumVal = NULL;
2720 if ( $3 && pScope && pScope->getScopeNodeType() == NT_enum)
2722 $3->evaluate(EK_const);
2723 if ( $3->coerce(ET_long) )
2725 pEnum = static_cast<AstEnum*>(pScope);
2726 if (pEnum)
2728 pEnumVal = new AstConstant(ET_long , NT_enum_val,
2729 $3, *$1, pScope);
2731 if ( pEnum->checkValue(pEnumVal->getConstValue()) )
2732 ErrorHandler::error1(EIDL_EVAL_ERROR, pEnum);
2734 pScope->addDeclaration(pEnumVal);
2735 } else
2737 ErrorHandler::coercionError($3, ET_long);
2738 delete $3;
2741 delete $1;
2745 identifier:
2746 IDL_IDENTIFIER
2747 | IDL_GET { $$ = new OString("get"); }
2748 | IDL_SET { $$ = new OString("set"); }
2749 | IDL_PUBLISHED { $$ = new OString("published"); }
2755 * Report an error situation discovered in a production
2757 void yyerror(char const *errmsg)
2759 ErrorHandler::syntaxError(idlc()->getParseState(), idlc()->getLineNumber(), errmsg);
2760 idlc()->setParseState(PS_NoState);
2763 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */