build fix
[LibreOffice.git] / idlc / source / parser.y
blob6e7bf785154f700aa4b652e78c28e25955cbe995
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.hxx>
28 #include <errorhandler.hxx>
29 #include <fehelper.hxx>
30 #include <astexpression.hxx>
31 #include <astconstants.hxx>
32 #include <astconstant.hxx>
33 #include <astbasetype.hxx>
34 #include <asttypedef.hxx>
35 #include <astexception.hxx>
36 #include <astmember.hxx>
37 #include <astenum.hxx>
38 #include <astsequence.hxx>
39 #include <astattribute.hxx>
40 #include <astoperation.hxx>
41 #include <astparameter.hxx>
42 #include <astinterfacemember.hxx>
43 #include <astservicemember.hxx>
44 #include <astobserves.hxx>
45 #include <astneeds.hxx>
47 #include "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 != nullptr && 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 == nullptr) {
156 ErrorHandler::lookupError(*scopedName);
157 } else if (!ErrorHandler::checkPublished(decl)) {
158 decl = nullptr;
159 } else if (resolved->getNodeType() == NT_struct) {
160 if (static_cast< AstStruct const * >(resolved)->getTypeParameterCount()
161 != (typeArgs == nullptr ? 0 : typeArgs->size()))
163 ErrorHandler::error0(EIDL_WRONG_NUMBER_OF_TYPE_ARGUMENTS);
164 decl = nullptr;
165 } else if (typeArgs != nullptr) {
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 != nullptr) {
176 ErrorHandler::error0(EIDL_WRONG_NUMBER_OF_TYPE_ARGUMENTS);
177 decl = nullptr;
179 } else {
180 ErrorHandler::noTypeError(decl);
181 decl = nullptr;
183 delete scopedName;
184 delete typeArgs;
185 return decl;
188 bool includes(AstDeclaration const * type1, AstDeclaration const * type2) {
189 OSL_ASSERT(type2 != nullptr);
190 if (type1 != nullptr) {
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 std::list< OString >* 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 = nullptr;
448 AstDeclaration* pExists = nullptr;
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 = nullptr;
519 AstDeclaration* pDecl = nullptr;
522 * Make a new forward interface node and add it to its enclosing scope
524 if ( pScope && $1 )
526 pForward = new AstInterface(*$1, nullptr, 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 = nullptr;
558 AstInterface* pForward = nullptr;
559 AstDeclaration* pDecl = nullptr;
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, nullptr);
670 delete $2;
674 inheritance_spec :
677 idlc()->setParseState(PS_InheritColonSeen);
679 scoped_name
681 $$ = $3;
683 | /* EMPTY */
685 $$ = nullptr;
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, FeDeclarator::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 = nullptr;
850 $$.get.exceptions = nullptr;
851 $$.set.documentation = nullptr;
852 $$.set.exceptions = nullptr;
856 attribute_block_rest:
857 opt_attribute_raises '}'
858 | error '}'
860 yyerror("bad attribute raises block");
861 yyerrok;
862 $$.get.documentation = nullptr;
863 $$.get.exceptions = nullptr;
864 $$.set.documentation = nullptr;
865 $$.set.exceptions = nullptr;
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 = nullptr;
885 $$.get.exceptions = nullptr;
886 $$.set.documentation = nullptr;
887 $$.set.exceptions = nullptr;
891 opt_attribute_get_raises:
892 attribute_get_raises
893 | /* empty */ { $$.documentation = nullptr; $$.exceptions = nullptr; }
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 = nullptr; $$.exceptions = nullptr; }
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 = nullptr;
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 = nullptr;
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 = nullptr;
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 = FeDeclarator::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 $$ = nullptr;
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 == nullptr) {
1179 ErrorHandler::lookupError(*$1);
1180 } else if (!ErrorHandler::checkPublished(decl)) {
1181 decl = nullptr;
1182 } else if (decl->getNodeType() != NT_exception) {
1183 ErrorHandler::error1(EIDL_ILLEGAL_RAISES, decl);
1184 decl = nullptr;
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 = nullptr;
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 = nullptr;
1282 AstDeclaration* pExists = nullptr;
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, nullptr);
1388 | '-' primary_expr
1390 $$ = new AstExpression(EC_u_minus, $2, nullptr);
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 = nullptr;
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 = nullptr;
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, nullptr);
1487 delete $5;
1491 exception_dcl :
1492 exception_header
1494 idlc()->setParseState(PS_ExceptHeaderSeen);
1496 AstScope* pScope = idlc()->scopes()->topNonNull();
1497 AstException* pExcept = nullptr;
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 = nullptr;
1540 FeDeclList* pList = $4;
1541 FeDeclarator* pDecl = nullptr;
1542 AstType const * pType = nullptr;
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 = FeDeclarator::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 = nullptr;
1614 AstInterfaceMember* pIMember = nullptr;
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 std::list< OString >::iterator iter = $2->begin();
1628 std::list< OString >::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 = nullptr;
1663 AstServiceMember* pSMember = nullptr;
1666 * Create a node representing a class member.
1667 * Store it in the enclosing scope
1669 if ( pScope && $2 )
1671 std::list< OString >::iterator iter = $2->begin();
1672 std::list< OString >::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 = nullptr;
1704 AstObserves* pObserves = nullptr;
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 std::list< OString >::iterator iter = $2->begin();
1718 std::list< OString >::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 = nullptr;
1745 AstNeeds* pNeeds = nullptr;
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 std::list< OString >::iterator iter = $2->begin();
1759 std::list< OString >::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 = nullptr;
1831 * Make a new service and add it to the enclosing scope
1833 if (pScope != nullptr)
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 != nullptr
1863 && resolveTypedefs(decl)->getNodeType() == NT_interface)
1865 if (ErrorHandler::checkPublished(decl)) {
1866 idlc()->scopes()->top()->addDeclaration(decl);
1868 } else {
1869 ErrorHandler::lookupError(
1870 EIDL_INTERFACEMEMBER_LOOKUP, *$2, scopeAsDecl(scope));
1872 delete $2;
1874 opt_service_body
1876 AstService * s = static_cast< AstService * >(idlc()->scopes()->top());
1877 if (s != nullptr) {
1878 s->setSingleInterfaceBasedService();
1879 s->setDefaultConstructor(!$4);
1884 opt_service_body:
1885 service_body { $$ = true; }
1886 | /* empty */ { $$ = false; }
1889 service_body:
1891 constructors
1895 constructors:
1896 constructors constructor
1897 | /* empty */
1900 constructor:
1901 identifier
1903 checkIdentifier($1);
1904 AstScope * scope = idlc()->scopes()->top();
1905 AstOperation * ctor = new AstOperation(nullptr, *$1, scope);
1906 delete $1;
1907 scope->addDeclaration(ctor);
1908 idlc()->scopes()->push(ctor);
1911 parameters
1913 opt_raises
1915 static_cast< AstOperation * >(idlc()->scopes()->top())->setExceptions(
1916 $6);
1917 delete $6;
1918 idlc()->scopes()->pop();
1919 if (static_cast< AstService * >(idlc()->scopes()->top())->
1920 checkLastConstructor())
1922 ErrorHandler::error0(EIDL_SIMILAR_CONSTRUCTORS);
1928 singleton_dcl :
1929 IDL_SINGLETON
1931 idlc()->setParseState(PS_SingletonSeen);
1933 identifier
1935 idlc()->setParseState(PS_SingletonIDSeen);
1936 checkIdentifier($3);
1938 AstScope* pScope = idlc()->scopes()->topNonNull();
1939 AstService* pService = nullptr;
1942 * Make a new service and add it to the enclosing scope
1944 if (pScope != nullptr)
1946 pService = new AstService(NT_singleton, *$3, pScope);
1947 pScope->addDeclaration(pService);
1949 delete $3;
1951 * Push it on the stack
1953 idlc()->scopes()->push(pService);
1955 singleton_dfn
1957 /* this singelton is finished, pop its scope from the stack */
1958 idlc()->scopes()->pop();
1962 singleton_dfn:
1963 singleton_interface_dfn
1964 | service_obsolete_dfn
1967 singleton_interface_dfn:
1968 ':' scoped_name
1970 AstScope * scope = idlc()->scopes()->nextToTop();
1971 // skip the scope (needlessly) pushed by singleton_dcl
1972 AstDeclaration * decl = scope->lookupByName(*$2);
1973 if (decl != nullptr
1974 && resolveTypedefs(decl)->getNodeType() == NT_interface)
1976 if (ErrorHandler::checkPublished(decl)) {
1977 idlc()->scopes()->top()->addDeclaration(decl);
1979 } else {
1980 ErrorHandler::lookupError(
1981 EIDL_INTERFACEMEMBER_LOOKUP, *$2, scopeAsDecl(scope));
1983 delete $2;
1987 service_obsolete_dfn:
1990 idlc()->setParseState(
1991 idlc()->scopes()->top()->getScopeNodeType() == NT_service
1992 ? PS_ServiceSqSeen : PS_SingletonSqSeen);
1994 service_exports
1996 idlc()->setParseState(
1997 idlc()->scopes()->top()->getScopeNodeType() == NT_service
1998 ? PS_ServiceBodySeen : PS_SingletonBodySeen);
2002 idlc()->setParseState(
2003 idlc()->scopes()->top()->getScopeNodeType() == NT_service
2004 ? PS_ServiceQsSeen : PS_SingletonQsSeen);
2008 type_dcl :
2009 IDL_TYPEDEF
2011 idlc()->setParseState(PS_TypedefSeen);
2013 type_declarator {}
2014 | struct_type {}
2015 | enum_type {}
2018 type_declarator :
2019 type_spec
2021 idlc()->setParseState(PS_TypeSpecSeen);
2022 if ($1 != nullptr && $1->getNodeType() == NT_instantiated_struct) {
2023 ErrorHandler::error0(EIDL_INSTANTIATED_STRUCT_TYPE_TYPEDEF);
2026 at_least_one_declarator
2028 idlc()->setParseState(PS_DeclaratorsSeen);
2030 AstScope* pScope = idlc()->scopes()->topNonNull();
2031 AstTypeDef* pTypeDef = nullptr;
2032 FeDeclList* pList = $3;
2033 FeDeclarator* pDecl = nullptr;
2034 AstType const * pType = nullptr;
2037 * Create nodes representing typedefs and add them to the
2038 * enclosing scope
2040 if ( pScope && $1 && pList )
2042 FeDeclList::iterator iter = pList->begin();
2043 FeDeclList::iterator end = pList->end();
2045 while (iter != end)
2047 pDecl = (*iter);
2048 if ( !pDecl )
2050 iter++;
2051 continue;
2054 pType = FeDeclarator::compose($1);
2056 if ( !pType )
2058 iter++;
2059 continue;
2062 pTypeDef = new AstTypeDef(pType, pDecl->getName(), pScope);
2064 pScope->addDeclaration(pTypeDef);
2065 iter++;
2066 delete pDecl;
2068 delete pList;
2073 at_least_one_declarator :
2074 declarator declarators
2076 if ( $2 )
2078 $2->push_back($1);
2079 $$ = $2;
2080 } else
2082 FeDeclList* pList = new FeDeclList();
2083 pList->push_back($1);
2084 $$ = pList;
2089 declarators :
2090 declarators
2093 idlc()->setParseState(PS_DeclsCommaSeen);
2095 declarator
2097 idlc()->setParseState(PS_DeclsDeclSeen);
2098 if ( $1 )
2100 $1->push_back($4);
2101 $$ = $1;
2102 } else
2104 FeDeclList* pList = new FeDeclList();
2105 pList->push_back($4);
2106 $$ = pList;
2109 | /* EMPTY */
2111 $$ = nullptr;
2115 declarator :
2116 identifier
2118 // For historic reasons, the struct com.sun.star.uno.Uik contains
2119 // members with illegal names (of the form "m_DataN"); avoid useless
2120 // warnings about them:
2121 AstScope * scope = idlc()->scopes()->top();
2122 if (scope == nullptr || scope->getScopeNodeType() != NT_struct
2123 || (scopeAsDecl(scope)->getScopedName()
2124 != "com::sun::star::uno::Uik"))
2126 checkIdentifier($1);
2129 $$ = new FeDeclarator(*$1);
2130 delete $1;
2134 at_least_one_scoped_name :
2135 scoped_name scoped_names
2137 if ($2)
2139 $2->push_front(*$1);
2140 $$ = $2;
2141 } else
2143 std::list< OString >* pScopedNames = new std::list< OString >();
2144 // coverity [copy_paste_error]
2145 pScopedNames->push_back(*$1);
2146 $$ = pScopedNames;
2148 delete($1);
2152 scoped_names :
2153 scoped_names
2156 idlc()->setParseState(PS_SNListCommaSeen);
2158 scoped_name
2160 idlc()->setParseState(PS_ScopedNameSeen);
2161 if ($1)
2163 $1->push_back(*$4);
2164 $$ = $1;
2165 } else
2167 std::list< OString >* pNames = new std::list< OString >();
2168 pNames->push_back(*$4);
2169 $$ = pNames;
2171 delete($4);
2173 | /* EMPTY */
2175 $$ = nullptr;
2179 scoped_name :
2180 identifier
2182 idlc()->setParseState(PS_SN_IDSeen);
2183 checkIdentifier($1);
2184 $$ = $1;
2186 | IDL_SCOPESEPARATOR
2188 idlc()->setParseState(PS_ScopeDelimSeen);
2190 identifier
2192 checkIdentifier($3);
2193 OString* pName = new OString("::");
2194 *pName += *$3;
2195 delete $3;
2196 $$ = pName;
2198 | scoped_name
2199 IDL_SCOPESEPARATOR
2202 identifier
2204 checkIdentifier($4);
2205 *$1 += ::rtl::OString("::");
2206 *$1 += *$4;
2207 delete $4;
2208 $$ = $1;
2212 type_spec :
2213 simple_type_spec
2214 | constructed_type_spec
2217 simple_type_spec :
2218 fundamental_type
2219 | scoped_name opt_type_args
2221 $$ = createNamedType($1, $2);
2225 fundamental_type:
2226 base_type_spec
2228 $$ = idlc()->scopes()->bottom()->lookupPrimitiveType($1);
2230 | sequence_type_spec
2233 opt_type_args:
2234 '<' type_args '>' { $$ = $2; }
2235 | /* empty */ { $$ = nullptr; }
2238 type_args:
2239 type_arg
2241 $$ = new DeclList;
2242 $$->push_back(const_cast< AstDeclaration * >($1)); //TODO: const_cast
2244 | type_args ',' type_arg
2246 $1->push_back(const_cast< AstDeclaration * >($3)); //TODO: const_cast
2247 $$ = $1;
2251 type_arg:
2252 simple_type_spec
2254 if ($1 != nullptr && static_cast< AstType const * >($1)->isUnsigned()) {
2255 ErrorHandler::error0(EIDL_UNSIGNED_TYPE_ARGUMENT);
2257 $$ = $1;
2261 base_type_spec :
2262 integer_type
2263 | floating_pt_type
2264 | char_type
2265 | boolean_type
2266 | byte_type
2267 | any_type
2268 | type_type
2269 | string_type
2272 integer_type :
2273 signed_int
2274 | unsigned_int
2277 signed_int :
2278 IDL_LONG
2280 $$ = ET_long;
2282 | IDL_HYPER
2284 $$ = ET_hyper;
2286 | IDL_SHORT
2288 $$ = ET_short;
2292 unsigned_int :
2293 IDL_UNSIGNED IDL_LONG
2295 $$ = ET_ulong;
2297 | IDL_UNSIGNED IDL_HYPER
2299 $$ = ET_uhyper;
2301 | IDL_UNSIGNED IDL_SHORT
2303 $$ = ET_ushort;
2307 floating_pt_type :
2308 IDL_DOUBLE
2310 $$ = ET_double;
2312 | IDL_FLOAT
2314 $$ = ET_float;
2318 char_type :
2319 IDL_CHAR
2321 $$ = ET_char;
2325 byte_type :
2326 IDL_BYTE
2328 $$ = ET_byte;
2332 boolean_type :
2333 IDL_BOOLEAN
2335 $$ = ET_boolean;
2339 any_type :
2340 IDL_ANY
2342 $$ = ET_any;
2346 type_type :
2347 IDL_TYPE
2349 $$ = ET_type;
2353 string_type :
2354 IDL_STRING
2356 $$ = ET_string;
2360 constructed_type_spec :
2361 struct_type
2362 | enum_type
2365 sequence_type_spec :
2366 IDL_SEQUENCE
2368 idlc()->setParseState(PS_SequenceSeen);
2370 * Push a sequence marker on scopes stack
2372 idlc()->scopes()->push(nullptr);
2376 idlc()->setParseState(PS_SequenceSqSeen);
2378 simple_type_spec
2380 idlc()->setParseState(PS_SequenceTypeSeen);
2384 idlc()->setParseState(PS_SequenceQsSeen);
2386 * Remove sequence marker from scopes stack
2388 if (idlc()->scopes()->top() == nullptr)
2389 idlc()->scopes()->pop();
2391 * Create a node representing a sequence
2393 AstScope* pScope = idlc()->scopes()->bottom();
2394 AstDeclaration* pDecl = nullptr;
2395 AstDeclaration* pSeq = nullptr;
2397 if ( $5 )
2399 AstType const *pType = static_cast<AstType const *>($5);
2400 if ( pType )
2402 pSeq = new AstSequence(pType, pScope);
2404 * Add this AstSequence to the types defined in the global scope
2406 pDecl = pScope->addDeclaration(pSeq);
2407 if ( pSeq != pDecl )
2409 // if sequence type already defined then use it
2410 delete pSeq;
2411 pSeq = pDecl;
2415 $$ = pSeq;
2417 | error '>'
2419 yyerror("sequence declaration");
2420 yyerrok;
2421 $$ = nullptr;
2425 struct_type :
2426 structure_header
2428 idlc()->setParseState(PS_StructHeaderSeen);
2430 AstScope* pScope = idlc()->scopes()->topNonNull();
2431 AstStruct* pStruct = nullptr;
2433 if ( pScope )
2435 AstStruct const* pBase= static_cast< AstStruct const* >(resolveTypedefs($1->getInherits()));
2436 pStruct = new AstStruct(
2437 *$1->getName(), $1->getTypeParameters(), pBase, pScope);
2438 pScope->addDeclaration(pStruct);
2441 * Push the scope of the struct on the scopes stack
2443 idlc()->scopes()->push(pStruct);
2444 delete $1;
2448 idlc()->setParseState(PS_StructSqSeen);
2450 at_least_one_member
2452 idlc()->setParseState(PS_StructBodySeen);
2456 idlc()->setParseState(PS_StructQsSeen);
2457 /* this exception is finished, pop its scope from the stack */
2458 idlc()->scopes()->pop();
2462 structure_header :
2463 IDL_STRUCT
2465 idlc()->setParseState(PS_StructSeen);
2467 identifier
2469 idlc()->setParseState(PS_StructIDSeen);
2470 checkIdentifier($3);
2472 opt_type_params
2473 inheritance_spec
2475 idlc()->setParseState(PS_InheritSpecSeen);
2477 // Polymorphic struct type templates with base types would cause various
2478 // problems in language bindings, so forbid them here. For example,
2479 // GCC prior to version 3.4 fails with code like
2481 // struct Base { ... };
2482 // template< typename typeparam_T > struct Derived: public Base {
2483 // int member1 CPPU_GCC3_ALIGN(Base);
2484 // ... };
2486 // (Note that plain struct types with instantiated polymorphic struct
2487 // type bases, which might also cause problems in language bindings, are
2488 // already rejected on a syntactic level.)
2489 if ($5 != nullptr && $6 != nullptr) {
2490 ErrorHandler::error0(EIDL_STRUCT_TYPE_TEMPLATE_WITH_BASE);
2493 $$ = new FeInheritanceHeader(NT_struct, $3, $6, $5);
2494 delete $5;
2495 delete $6;
2499 opt_type_params:
2500 '<' type_params '>' { $$ = $2; }
2501 | /* empty */ { $$ = nullptr; }
2504 type_params:
2505 identifier
2507 $$ = new std::vector< rtl::OString >;
2508 $$->push_back(*$1);
2509 delete $1;
2511 | type_params ',' identifier
2513 if (std::find($1->begin(), $1->end(), *$3) != $1->end()) {
2514 ErrorHandler::error0(EIDL_IDENTICAL_TYPE_PARAMETERS);
2516 $1->push_back(*$3);
2517 delete $3;
2518 $$ = $1;
2522 at_least_one_member : member members ;
2524 members :
2525 members member
2526 | /* EMPTY */
2529 member :
2530 type_or_parameter
2532 idlc()->setParseState(PS_MemberTypeSeen);
2534 at_least_one_declarator
2536 idlc()->setParseState(PS_MemberDeclsSeen);
2540 idlc()->setParseState(PS_MemberDeclsCompleted);
2542 AstScope* pScope = idlc()->scopes()->topNonNull();
2543 AstMember* pMember = nullptr;
2544 FeDeclList* pList = $3;
2545 FeDeclarator* pDecl = nullptr;
2546 AstType const * pType = nullptr;
2548 // !!! check recursive type
2550 if ( pScope && pList && $1 )
2552 FeDeclList::iterator iter = pList->begin();
2553 FeDeclList::iterator end = pList->end();
2554 while (iter != end)
2556 pDecl = (*iter);
2557 if ( !pDecl )
2559 iter++;
2560 continue;
2563 pType = FeDeclarator::compose($1);
2565 if ( !pType )
2567 iter++;
2568 continue;
2571 pMember = new AstMember(pType, pDecl->getName(), pScope);
2573 if ( !pDecl->checkType($1) )
2575 // WARNING
2578 pScope->addDeclaration(pMember);
2579 iter++;
2580 delete pDecl;
2582 delete pList;
2585 | error ';'
2587 yyerror("member definition");
2588 yyerrok;
2592 type_or_parameter:
2593 fundamental_type
2594 | scoped_name opt_type_args
2596 AstDeclaration const * decl = nullptr;
2597 AstStruct * scope = static_cast< AstStruct * >(idlc()->scopes()->top());
2598 if (scope != nullptr && $2 == nullptr) {
2599 decl = scope->findTypeParameter(*$1);
2601 if (decl != nullptr) {
2602 delete $1;
2603 delete $2;
2604 } else {
2605 decl = createNamedType($1, $2);
2606 if (scope != nullptr && includes(decl, scopeAsDecl(scope))) {
2607 ErrorHandler::error1(
2608 EIDL_RECURSIVE_TYPE, scopeAsDecl(scope));
2609 decl = nullptr;
2612 $$ = decl;
2616 enum_type :
2617 IDL_ENUM
2619 idlc()->setParseState(PS_EnumSeen);
2621 identifier
2623 idlc()->setParseState(PS_EnumIDSeen);
2624 checkIdentifier($3);
2626 AstScope* pScope = idlc()->scopes()->topNonNull();
2627 AstEnum* pEnum = nullptr;
2630 * Create a node representing an enum and add it to its
2631 * enclosing scope
2633 if (pScope != nullptr)
2635 pEnum = new AstEnum(*$3, pScope);
2637 * Add it to its defining scope
2639 pScope->addDeclaration(pEnum);
2641 delete $3;
2643 * Push the enum scope on the scopes stack
2645 idlc()->scopes()->push(pEnum);
2650 idlc()->setParseState(PS_EnumSqSeen);
2652 at_least_one_enumerator
2654 idlc()->setParseState(PS_EnumBodySeen);
2658 idlc()->setParseState(PS_EnumQsSeen);
2660 * Done with this enum. Pop its scope from the scopes stack
2662 if (idlc()->scopes()->top() == nullptr)
2663 $$ = nullptr;
2664 else
2666 $$ = static_cast<AstEnum*>(idlc()->scopes()->topNonNull());
2667 idlc()->scopes()->pop();
2672 at_least_one_enumerator : enumerator enumerators ;
2674 enumerators :
2675 enumerators
2678 idlc()->setParseState(PS_EnumCommaSeen);
2680 enumerator
2681 | /* EMPTY */
2682 | error ','
2684 yyerror("enumerator definition");
2685 yyerrok;
2689 enumerator :
2690 identifier
2692 checkIdentifier($1);
2694 AstScope* pScope = idlc()->scopes()->topNonNull();
2695 AstEnum* pEnum = nullptr;
2696 AstConstant* pEnumVal = nullptr;
2698 if ( pScope && pScope->getScopeNodeType() == NT_enum)
2700 pEnum = static_cast<AstEnum*>(pScope);
2701 if (pEnum && $1)
2703 AstExpression* pExpr = new AstExpression(pEnum->getEnumValueCount());
2704 pEnumVal = new AstConstant(ET_long , NT_enum_val,
2705 pExpr, *$1, pScope);
2707 if ( pEnum->checkValue(pEnumVal->getConstValue()) )
2708 ErrorHandler::error1(EIDL_EVAL_ERROR, pEnum);
2710 pScope->addDeclaration(pEnumVal);
2712 delete $1;
2714 | identifier
2716 const_expr
2718 checkIdentifier($1);
2720 AstScope* pScope = idlc()->scopes()->topNonNull();
2721 AstEnum* pEnum = nullptr;
2722 AstConstant* pEnumVal = nullptr;
2724 if ( $3 && pScope && pScope->getScopeNodeType() == NT_enum)
2726 $3->evaluate();
2727 if ( $3->coerce(ET_long) )
2729 pEnum = static_cast<AstEnum*>(pScope);
2730 if (pEnum)
2732 pEnumVal = new AstConstant(ET_long , NT_enum_val,
2733 $3, *$1, pScope);
2735 if ( pEnum->checkValue(pEnumVal->getConstValue()) )
2736 ErrorHandler::error1(EIDL_EVAL_ERROR, pEnum);
2738 pScope->addDeclaration(pEnumVal);
2739 } else
2741 ErrorHandler::coercionError($3, ET_long);
2742 delete $3;
2745 delete $1;
2749 identifier:
2750 IDL_IDENTIFIER
2751 | IDL_GET { $$ = new OString("get"); }
2752 | IDL_SET { $$ = new OString("set"); }
2753 | IDL_PUBLISHED { $$ = new OString("published"); }
2759 * Report an error situation discovered in a production
2761 void yyerror(char const *errmsg)
2763 ErrorHandler::syntaxError(idlc()->getParseState(), idlc()->getLineNumber(), errmsg);
2764 idlc()->setParseState(PS_NoState);
2767 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */