1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
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>
59 #define YYERROR_VERBOSE 1
61 extern
int yylex(void);
62 static void yyerror(char const *);
64 static void checkIdentifier
(OString
const * id
)
66 static short check
= 0;
68 if
(idlc
()->getOptions
()->isValid
("-cid"))
74 if
( id
->indexOf
('_') >= 0 )
75 if
( (id
->pData
->buffer
[0] >= 97 && id
->pData
->buffer
[0] <= 122)
76 || id
->pData
->buffer
[0] == '_') {
78 OStringBuffer msg
(25 + id
->getLength
());
79 msg.append
("mismatched identifier '");
82 ErrorHandler
::syntaxError
(idlc
()->getParseState
(),
83 idlc
()->getLineNumber
(),
87 ErrorHandler
::warning0
(WarningCode
::WrongNamingConvention
, id
->getStr
());
91 static void reportDoubleMemberDeclarations
(
92 AstInterface
::DoubleMemberDeclarations
const & doubleMembers
)
94 for
(auto
const& doubleMember
: doubleMembers
)
96 ErrorHandler
::error2
(ErrorCode
::DoubleMember
, doubleMember.first
, doubleMember.second
);
100 static void addInheritedInterface
(
101 AstInterface
* ifc
, OString
const & name
, bool optional
,
102 OUString
const & documentation
)
104 AstDeclaration
* decl
= ifc
->lookupByName
(name
);
105 AstDeclaration
const * resolved
= resolveTypedefs
(decl
);
106 if
(resolved
!= nullptr
&& resolved
->getNodeType
() == NT_interface
) {
107 if
(ErrorHandler
::checkPublished
(decl
)) {
108 if
(!static_cast
< AstInterface
const * >(resolved
)->isDefined
()) {
109 ErrorHandler
::inheritanceError
(
110 NT_interface
, &ifc
->getScopedName
(), decl
);
112 AstInterface
::DoubleDeclarations doubleDecls
(
113 ifc
->checkInheritedInterfaceClashes
(
114 static_cast
< AstInterface
const * >(resolved
),
116 if
(doubleDecls.interfaces.empty
()
117 && doubleDecls.members.empty
())
119 ifc
->addInheritedInterface
(
120 static_cast
< AstType
* >(decl
), optional
,
123 for
(auto
const& elem
: doubleDecls.interfaces
)
125 ErrorHandler
::error1
(
126 ErrorCode
::DoubleInheritance
, elem
);
128 reportDoubleMemberDeclarations
(doubleDecls.members
);
133 ErrorHandler
::lookupError
(
134 ErrorCode
::InterfaceMemberLookup
, name
, scopeAsDecl
(ifc
));
138 static AstDeclaration
const * createNamedType
(
139 OString
const * scopedName
, DeclList
const * typeArgs
)
141 AstDeclaration
* decl
= idlc
()->scopes
()->topNonNull
()->lookupByName
(
143 AstDeclaration
const * resolved
= resolveTypedefs
(decl
);
144 if
(decl
== nullptr
) {
145 ErrorHandler
::lookupError
(*scopedName
);
146 } else if
(!ErrorHandler
::checkPublished
(decl
)) {
148 } else if
(resolved
->getNodeType
() == NT_struct
) {
149 if
(static_cast
< AstStruct
const * >(resolved
)->getTypeParameterCount
()
150 != (typeArgs
== nullptr ?
0 : typeArgs
->size
()))
152 ErrorHandler
::error0
(ErrorCode
::WrongNumberOfTypeArguments
);
154 } else if
(typeArgs
!= nullptr
) {
155 AstScope
* global
= idlc
()->scopes
()->bottom
();
156 AstDeclaration
* inst
= new AstStructInstance
(
157 static_cast
< AstType
* >(decl
), typeArgs
, global
);
158 decl
= global
->addDeclaration
(inst
);
163 } else if
(decl
->isType
()) {
164 if
(typeArgs
!= nullptr
) {
165 ErrorHandler
::error0
(ErrorCode
::WrongNumberOfTypeArguments
);
169 ErrorHandler
::noTypeError
(decl
);
177 static bool includes
(AstDeclaration
const * type1
, AstDeclaration
const * type2
) {
178 OSL_ASSERT
(type2
!= nullptr
);
179 if
(type1
!= nullptr
) {
180 if
(type1
->getNodeType
() == NT_instantiated_struct
) {
181 AstStructInstance
const * inst
182 = static_cast
< AstStructInstance
const * >(type1
);
183 if
(inst
->getTypeTemplate
() == type2
) {
186 for
(DeclList
::const_iterator i
(inst
->getTypeArgumentsBegin
());
187 i
!= inst
->getTypeArgumentsEnd
(); ++i
)
189 if
(includes
(*i
, type2
)) {
193 } else if
(type1
== type2
) {
200 // Suppress any warnings from generated code:
202 #pragma warning(disable: 4702) // unreachable code
206 * Declare the type of values in the grammar
209 ExprType etval
; /* Expression type */
210 AstDeclaration
* dclval
; /* Declaration */
211 AstDeclaration
const * cdclval
;
213 AstExpression
* exval
; /* expression value */
214 FeDeclarator
* fdval
; /* declarator value */
215 FeDeclList
* dlval
; /* declarator list value */
216 FeInheritanceHeader
* ihval
; /* inheritance header value */
217 OString
* sval
; /* OString value */
218 std
::vector
< OString
> * svals
;
219 sal_Char
* strval
; /* sal_Char* value */
220 bool bval
; /* sal_Boolean* value */
221 sal_Int64 ival
; /* sal_Int64 value */
222 sal_uInt64 uval
; /* sal_uInt64 value */
223 sal_uInt32 ulval
; /* sal_uInt32 value */
224 double dval
; /* double value */
225 float fval
; /* float value */
226 std
::list
< OString
>* slval
; /* StringList value */
227 AttributeExceptions
::Part attexcpval
;
228 AttributeExceptions attexcval
;
232 * Token types: These are returned by the lexer
235 %token
<sval
> IDL_IDENTIFIER
240 %token IDL_CONSTRAINED
244 %token IDL_MAYBEAMBIGUOUS
245 %token IDL_MAYBEDEFAULT
290 %token
<strval
> IDL_LEFTSHIFT
291 %token
<strval
> IDL_RIGHTSHIFT
292 %token
<strval
> IDL_SCOPESEPARATOR
294 %token
<ival
> IDL_INTEGER_LITERAL
295 %token
<uval
> IDL_INTEGER_ULITERAL
296 %token
<dval
> IDL_FLOATING_PT_LITERAL
299 * These are production names:
301 %type
<dclval
> type_dcl
302 %type
<dclval
> exception_name
303 %type
<cdclval
> constructed_type_spec enum_type op_type_spec
304 %type
<cdclval
> sequence_type_spec simple_type_spec struct_type
305 %type
<cdclval
> type_spec
306 %type
<cdclval
> fundamental_type type_arg type_or_parameter
307 %type
<dclsval
> opt_raises raises exception_list
308 %type
<attexcpval
> opt_attribute_get_raises attribute_get_raises
309 %type
<attexcpval
> opt_attribute_set_raises attribute_set_raises
310 %type
<dclsval
> opt_type_args type_args
312 %type
<sval
> identifier
313 %type
<sval
> interface_decl
314 %type
<sval
> scoped_name inheritance_spec
315 %type
<slval
> scoped_names at_least_one_scoped_name
317 %type
<etval
> const_type integer_type char_type boolean_type
318 %type
<etval
> floating_pt_type any_type signed_int string_type
319 %type
<etval
> unsigned_int base_type_spec byte_type type_type
321 %type
<exval
> expression const_expr or_expr xor_expr and_expr
322 %type
<exval
> add_expr mult_expr unary_expr primary_expr shift_expr
323 %type
<exval
> literal
325 %type
<fdval
> declarator
326 %type
<dlval
> declarators at_least_one_declarator
328 %type
<ihval
> exception_header structure_header interfaceheader
330 %type
<ulval
> flag_header opt_attrflags opt_attrflag
331 %type
<ulval
> direction service_interface_header service_service_header
333 %type
<bval
> optional_inherited_interface opt_rest opt_service_body
335 %type
<attexcval
> opt_attribute_block attribute_block_rest opt_attribute_raises
337 %type
<svals
> opt_type_params type_params
346 definition definitions
351 opt_published publishable_definition
354 idlc
()->setParseState
(PS_ModuleDeclSeen
);
358 idlc
()->setParseState
(PS_NoState
);
362 yyerror("definitions");
368 IDL_PUBLISHED
{ idlc
()->setPublished
(true
); }
369 |
/* empty */ { idlc
()->setPublished
(false
); }
372 publishable_definition:
375 idlc
()->setParseState
(PS_TypeDeclSeen
);
379 idlc
()->setParseState
(PS_NoState
);
383 idlc
()->setParseState
(PS_ExceptionDeclSeen
);
387 idlc
()->setParseState
(PS_NoState
);
391 idlc
()->setParseState
(PS_InterfaceDeclSeen
);
395 idlc
()->setParseState
(PS_NoState
);
399 idlc
()->setParseState
(PS_ServiceDeclSeen
);
403 idlc
()->setParseState
(PS_NoState
);
407 idlc
()->setParseState
(PS_SingletonDeclSeen
);
411 idlc
()->setParseState
(PS_NoState
);
415 idlc
()->setParseState
(PS_ConstantsDeclSeen
);
419 idlc
()->setParseState
(PS_NoState
);
426 idlc
()->setParseState
(PS_ModuleSeen
);
427 idlc
()->setPublished
(false
);
431 idlc
()->setParseState
(PS_ModuleIDSeen
);
434 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
435 AstModule
* pModule
= nullptr
;
439 pModule
= new AstModule
(*$3, pScope
);
440 if
( AstDeclaration
* pExists
= pScope
->lookupForAdd
(pModule
) )
442 pExists
->setInMainfile
(idlc
()->isInMainFile
());
443 pExists
->setFileName
(pModule
->getFileName
());
444 if
(pExists
->isPredefined
())
446 pExists
->setPredefined
(false
);
447 if
(pExists
->getDocumentation
().getLength
() == 0 &&
448 pModule
->getDocumentation
().getLength
() > 0)
450 pExists
->setDocumentation
(pModule
->getDocumentation
());
454 pModule
= static_cast
<AstModule
*>(pExists
);
457 pScope
->addDeclaration
(pModule
);
459 idlc
()->scopes
()->push
(pModule
);
465 idlc
()->setParseState
(PS_ModuleSqSeen
);
469 idlc
()->setParseState
(PS_ModuleBodySeen
);
473 idlc
()->setParseState
(PS_ModuleQsSeen
);
475 * Finished with this module - pop it from the scope stack
477 idlc
()->scopes
()->pop
();
489 idlc
()->setParseState
(PS_InterfaceSeen
);
493 idlc
()->setParseState
(PS_InterfaceIDSeen
);
502 idlc
()->setParseState
(PS_ForwardDeclSeen
);
504 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
505 AstInterface
* pForward
= nullptr
;
506 AstDeclaration
* pDecl
= nullptr
;
509 * Make a new forward interface node and add it to its enclosing scope
513 pForward
= new AstInterface
(*$1, nullptr
, pScope
);
515 pDecl
= pScope
->lookupByName
(pForward
->getScopedName
());
518 if
( (pDecl
!= pForward
) &&
519 (pDecl
->getNodeType
() == NT_interface
) )
524 ErrorHandler
::error2
(ErrorCode
::RedefScope
, scopeAsDecl
(pScope
), pDecl
);
529 * Add the interface to its definition scope
531 pScope
->addDeclaration
(pForward
);
541 idlc
()->setParseState
(PS_InterfaceHeadSeen
);
543 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
544 AstInterface
* pInterface
= nullptr
;
545 AstInterface
* pForward
= nullptr
;
548 * Make a new interface node and add it to its enclosing scope
552 pInterface
= new AstInterface
(
554 static_cast
< AstInterface
const * >(resolveTypedefs
($1->getInherits
())), pScope
);
555 if
( AstDeclaration
* pDecl
= pScope
->lookupByName
(pInterface
->getScopedName
()) )
558 * See if we're defining a forward declared interface.
560 if
(pDecl
->getNodeType
() == NT_interface
)
562 pForward
= static_cast
<AstInterface
*>(pDecl
);
563 if
( !pForward
->isDefined
() )
566 * Check if redefining in same scope
568 if
( pForward
->getScope
() != pScope
)
570 if
( pForward
->getScopedName
() != pInterface
->getScopedName
() )
572 ErrorHandler
::error3
(ErrorCode
::ScopeConflict
,
573 pInterface
, pForward
, scopeAsDecl
(pScope
));
576 else if
( !pInterface
->isPublished
()
577 && pForward
->isPublished
() )
579 ErrorHandler
::error0
(ErrorCode
::PublishedForward
);
582 * All OK, set full definition
586 pForward
->forwardDefined
(*pInterface
);
588 pInterface
= pForward
;
591 // special handling for XInterface because it is predefined
592 if
( pForward
->isPredefined
() &&
593 pForward
->getScopedName
() == "com::sun::star::uno::XInterface")
595 /* replace the predefined XInterface */
596 *pForward
= *pInterface
;
598 pInterface
= pForward
;
606 * Add the interface to its definition scope
608 pScope
->addDeclaration
(pInterface
);
612 * Push it on the scope stack
614 idlc
()->scopes
()->push
(pInterface
);
619 idlc
()->setParseState
(PS_InterfaceSqSeen
);
623 AstInterface
* ifc
= static_cast
< AstInterface
* >(
624 idlc
()->scopes
()->topNonNull
());
625 if
(!ifc
->hasMandatoryInheritedInterfaces
()
626 && ifc
->getScopedName
() != "com::sun::star::uno::XInterface")
628 addInheritedInterface
(
629 ifc
, "::com::sun::star::uno::XInterface", false
,
633 idlc
()->setParseState
(PS_InterfaceBodySeen
);
637 idlc
()->setParseState
(PS_InterfaceQsSeen
);
639 * Done with this interface - pop it off the scopes stack
641 idlc
()->scopes
()->pop
();
645 yyerror("interface definition");
651 interface_decl inheritance_spec
653 idlc
()->setParseState
(PS_InheritSpecSeen
);
655 $$
= new FeInheritanceHeader
(NT_interface
, $1, $2, nullptr
);
663 idlc
()->setParseState
(PS_InheritColonSeen
);
683 idlc
()->setParseState
(PS_AttributeDeclSeen
);
687 idlc
()->setParseState
(PS_NoState
);
691 idlc
()->setParseState
(PS_OperationDeclSeen
);
695 idlc
()->setParseState
(PS_NoState
);
697 | interface_inheritance_decl
699 idlc
()->setParseState
(PS_InterfaceInheritanceDeclSeen
);
703 idlc
()->setParseState
(PS_NoState
);
711 idlc
()->setParseState
(PS_AttrTypeSeen
);
715 idlc
()->setParseState
(PS_AttrCompleted
);
716 if
(($1 & ~
(AF_BOUND | AF_READONLY
)) != AF_ATTRIBUTE
) {
717 ErrorHandler
::flagError
(ErrorCode
::BadAttributeFlags
, $1);
719 AstInterface
* scope
= static_cast
< AstInterface
* >(
720 idlc
()->scopes
()->top
());
721 AstAttribute
* attr
= new AstAttribute
(
722 $1, FeDeclarator
::compose
($2), $4->getName
(), scope
);
724 AstInterface
::DoubleMemberDeclarations doubleMembers
(
725 scope
->checkMemberClashes
(attr
));
726 if
(doubleMembers.empty
()) {
727 scope
->addMember
(attr
);
729 reportDoubleMemberDeclarations
(doubleMembers
);
731 idlc
()->scopes
()->push
(attr
);
735 static_cast
< AstAttribute
* >(idlc
()->scopes
()->top
())->setExceptions
(
736 $6.get.documentation
, $6.get.exceptions
, $6.set.documentation
,
738 delete
$6.get.documentation
;
739 delete
$6.get.exceptions
;
740 delete
$6.set.documentation
;
741 delete
$6.set.exceptions
;
742 idlc
()->scopes
()->pop
();
747 '[' opt_attrflags
']'
749 idlc
()->setParseState
(PS_FlagHeaderSeen
);
755 opt_attrflags
',' opt_attrflag
757 if
( ($1 & $3) == $3 )
758 ErrorHandler
::flagError
(ErrorCode
::DefinedAttributeFlag
, $3);
771 idlc
()->setParseState
(PS_AttrSeen
);
776 idlc
()->setParseState
(PS_PropertySeen
);
781 idlc
()->setParseState
(PS_ReadOnlySeen
);
786 idlc
()->setParseState
(PS_OptionalSeen
);
791 idlc
()->setParseState
(PS_MayBeVoidSeen
);
796 idlc
()->setParseState
(PS_BoundSeen
);
801 idlc
()->setParseState
(PS_ConstrainedSeen
);
806 idlc
()->setParseState
(PS_TransientSeen
);
811 idlc
()->setParseState
(PS_MayBeAmbigiousSeen
);
812 $$
= AF_MAYBEAMBIGUOUS
;
816 idlc
()->setParseState
(PS_MayBeDefaultSeen
);
817 $$
= AF_MAYBEDEFAULT
;
821 idlc
()->setParseState
(PS_RemoveableSeen
);
826 yyerror("unknown property|attribute flag");
832 '{' attribute_block_rest
{ $$
= $2; }
835 $$.get.documentation
= nullptr
;
836 $$.get.exceptions
= nullptr
;
837 $$.set.documentation
= nullptr
;
838 $$.set.exceptions
= nullptr
;
842 attribute_block_rest:
843 opt_attribute_raises
'}'
846 yyerror("bad attribute raises block");
848 $$.get.documentation
= nullptr
;
849 $$.get.exceptions
= nullptr
;
850 $$.set.documentation
= nullptr
;
851 $$.set.exceptions
= nullptr
;
855 opt_attribute_raises:
857 opt_attribute_set_raises
862 | attribute_set_raises
863 opt_attribute_get_raises
870 $$.get.documentation
= nullptr
;
871 $$.get.exceptions
= nullptr
;
872 $$.set.documentation
= nullptr
;
873 $$.set.exceptions
= nullptr
;
877 opt_attribute_get_raises:
879 |
/* empty */ { $$.documentation
= nullptr
; $$.exceptions
= nullptr
; }
882 attribute_get_raises:
885 $$.documentation
= new OUString
(
887 idlc
()->getDocumentation
(), RTL_TEXTENCODING_UTF8
));
892 opt_attribute_set_raises:
894 |
/* empty */ { $$.documentation
= nullptr
; $$.exceptions
= nullptr
; }
897 attribute_set_raises:
900 if
(static_cast
< AstAttribute
* >(idlc
()->scopes
()->top
())->
903 ErrorHandler
::error0
(ErrorCode
::ReadOnlyAttributeSetExceptions
);
908 $$.documentation
= new OUString
(
910 idlc
()->getDocumentation
(), RTL_TEXTENCODING_UTF8
));
918 idlc
()->setParseState
(PS_OpTypeSeen
);
922 idlc
()->setParseState
(PS_OpIDSeen
);
925 AstInterface
* pScope
= static_cast
< AstInterface
* >(
926 idlc
()->scopes
()->top
());
927 AstOperation
* pOp
= nullptr
;
930 * Create a node representing an operation on an interface
931 * and add it to its enclosing scope
935 AstType
const *pType
= static_cast
<AstType
const *>($1);
936 if
( !pType ||
(pType
->getNodeType
() == NT_exception
) )
941 pOp
= new AstOperation
(pType
, *$3, pScope
);
943 AstInterface
::DoubleMemberDeclarations doubleMembers
(
944 pScope
->checkMemberClashes
(pOp
));
945 if
(doubleMembers.empty
()) {
946 pScope
->addMember
(pOp
);
948 reportDoubleMemberDeclarations
(doubleMembers
);
954 * Push the operation scope onto the scopes stack
956 idlc
()->scopes
()->push
(pOp
);
960 idlc
()->setParseState
(PS_OpSqSeen
);
964 idlc
()->setParseState
(PS_OpParsCompleted
);
968 idlc
()->setParseState
(PS_OpQsSeen
);
972 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
973 AstOperation
* pOp
= nullptr
;
975 * Add exceptions and context to the operation
977 if
( pScope
&& pScope
->getScopeNodeType
() == NT_operation
)
979 pOp
= static_cast
<AstOperation
*>(pScope
);
982 pOp
->setExceptions
($11);
986 * Done with this operation. Pop its scope from the scopes stack
988 idlc
()->scopes
()->pop
();
996 $$
= idlc
()->scopes
()->bottom
()->lookupPrimitiveType
(ET_void
);
1005 idlc
()->setParseState
(PS_OpParCommaSeen
);
1011 yyerror("parameter definition");
1021 idlc
()->setParseState
(PS_OpParDirSeen
);
1025 idlc
()->setParseState
(PS_OpParTypeSeen
);
1030 idlc
()->setParseState
(PS_OpParDeclSeen
);
1032 AstOperation
* pScope
= static_cast
< AstOperation
* >(
1033 idlc
()->scopes
()->top
());
1034 AstParameter
* pParam
= nullptr
;
1037 * Create a node representing an argument to an operation
1038 * Add it to the enclosing scope (the operation scope)
1040 if
( pScope
&& $5 && $8 )
1042 AstType
const * pType
= FeDeclarator
::compose
($5);
1045 if
(pScope
->isConstructor
() && $2 != DIR_IN
) {
1046 ErrorHandler
::error0
(ErrorCode
::ConstructorParameterNotIn
);
1048 if
(pScope
->isVariadic
()) {
1049 ErrorHandler
::error0
(ErrorCode
::RestParameterNotLast
);
1052 AstDeclaration
const * type
= resolveTypedefs
(pType
);
1053 if
(type
->getNodeType
() != NT_predefined
1054 ||
(static_cast
< AstBaseType
const * >(type
)->
1055 getExprType
() != ET_any
))
1057 ErrorHandler
::error0
(ErrorCode
::RestParameterNotAny
);
1059 if
(pScope
->isConstructor
()) {
1060 if
(pScope
->getIteratorBegin
()
1061 != pScope
->getIteratorEnd
())
1063 ErrorHandler
::error0
(
1064 ErrorCode
::ConstructorRestParameterNotFirst
);
1067 ErrorHandler
::error0
(ErrorCode
::MethodHasRestParameter
);
1071 pParam
= new AstParameter
(
1072 static_cast
< Direction
>($2), $7, pType
, $8->getName
(),
1075 if
( !$8->checkType
($5) )
1080 pScope
->addDeclaration
(pParam
);
1087 idlc
()->setParseState
(PS_NoState
);
1129 idlc
()->setParseState
(PS_RaiseSeen
);
1133 idlc
()->setParseState
(PS_RaiseSqSeen
);
1138 idlc
()->setParseState
(PS_RaiseQsSeen
);
1149 | exception_list
',' exception_name
1159 // The topmost scope is either an AstOperation (for interface methods
1160 // and service constructors) or an AstAttribute (for interface
1161 // attributes), so look up exception names in the next-to-topmost scope:
1162 AstDeclaration
* decl
= idlc
()->scopes
()->nextToTop
()->lookupByName
(
1164 if
(decl
== nullptr
) {
1165 ErrorHandler
::lookupError
(*$1);
1166 } else if
(!ErrorHandler
::checkPublished
(decl
)) {
1168 } else if
(decl
->getNodeType
() != NT_exception
) {
1169 ErrorHandler
::error1
(ErrorCode
::IllegalRaises
, decl
);
1177 interface_inheritance_decl:
1178 optional_inherited_interface
1181 idlc
()->setParseState
(PS_ServiceIFHeadSeen
);
1185 AstInterface
* ifc
= static_cast
< AstInterface
* >(
1186 idlc
()->scopes
()->top
());
1187 if
(ifc
->usesSingleInheritance
()) {
1188 ErrorHandler
::error0
(ErrorCode
::MixedInheritance
);
1190 addInheritedInterface
(
1193 idlc
()->getDocumentation
(), RTL_TEXTENCODING_UTF8
));
1199 optional_inherited_interface:
1200 '[' IDL_OPTIONAL
']' { $$
= true
; }
1201 |
/* EMPTY */ { $$
= false
; }
1205 constants_export constants_exports
1212 idlc
()->setParseState
(PS_ConstSeen
);
1216 idlc
()->setParseState
(PS_ConstTypeSeen
);
1220 idlc
()->setParseState
(PS_ConstIDSeen
);
1221 checkIdentifier
($5);
1225 idlc
()->setParseState
(PS_ConstAssignSeen
);
1229 idlc
()->setParseState
(PS_ConstExprSeen
);
1231 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1232 AstConstant
* pConstant
= nullptr
;
1236 if
( !$9->coerce
($3) )
1238 ErrorHandler
::coercionError
($9, $3);
1241 pConstant
= new AstConstant
($3, $9, *$5, pScope
);
1242 pScope
->addDeclaration
(pConstant
);
1247 idlc
()->setParseState
(PS_ConstantDeclSeen
);
1255 idlc
()->setParseState
(PS_ConstantsSeen
);
1259 idlc
()->setParseState
(PS_ConstantsIDSeen
);
1260 checkIdentifier
($3);
1264 idlc
()->setParseState
(PS_ConstantsSqSeen
);
1266 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1267 AstConstants
* pConstants
= nullptr
;
1271 pConstants
= new AstConstants
(*$3, pScope
);
1272 if
( AstDeclaration
* pExists
= pScope
->lookupForAdd
(pConstants
) )
1274 pExists
->setInMainfile
(idlc
()->isInMainFile
());
1276 pConstants
= static_cast
<AstConstants
*>(pExists
);
1279 pScope
->addDeclaration
(pConstants
);
1281 idlc
()->scopes
()->push
(pConstants
);
1287 idlc
()->setParseState
(PS_ConstantsBodySeen
);
1291 idlc
()->setParseState
(PS_ConstantsQsSeen
);
1293 * Finished with this constants - pop it from the scope stack
1295 idlc
()->scopes
()->pop
();
1299 expression
: const_expr
;
1301 const_expr
: or_expr
;
1305 | or_expr
'|' xor_expr
1307 $$
= new AstExpression
(ExprComb
::Or
, $1, $3);
1313 | xor_expr
'^' and_expr
1315 $$
= new AstExpression
(ExprComb
::Xor
, $1, $3);
1321 | and_expr
'&' shift_expr
1323 $$
= new AstExpression
(ExprComb
::And
, $1, $3);
1329 | shift_expr IDL_LEFTSHIFT add_expr
1331 $$
= new AstExpression
(ExprComb
::Left
, $1, $3);
1333 | shift_expr IDL_RIGHTSHIFT add_expr
1335 $$
= new AstExpression
(ExprComb
::Right
, $1, $3);
1341 | add_expr
'+' mult_expr
1343 $$
= new AstExpression
(ExprComb
::Add
, $1, $3);
1345 | add_expr
'-' mult_expr
1347 $$
= new AstExpression
(ExprComb
::Minus
, $1, $3);
1353 | mult_expr
'*' unary_expr
1355 $$
= new AstExpression
(ExprComb
::Mul
, $1, $3);
1357 | mult_expr
'/' unary_expr
1359 $$
= new AstExpression
(ExprComb
::Div
, $1, $3);
1361 | mult_expr
'%' unary_expr
1363 $$
= new AstExpression
(ExprComb
::Mod
, $1, $3);
1371 $$
= new AstExpression
(ExprComb
::UPlus
, $2, nullptr
);
1375 $$
= new AstExpression
(ExprComb
::UMinus
, $2, nullptr
);
1386 * An expression which is a scoped name is not resolved now,
1387 * but only when it is evaluated (such as when it is assigned
1388 * as a constant value)
1390 $$
= new AstExpression
($1);
1393 |
'(' const_expr
')'
1402 $$
= new AstExpression
($1);
1404 | IDL_INTEGER_ULITERAL
1406 $$
= new AstExpression
($1);
1408 | IDL_FLOATING_PT_LITERAL
1410 $$
= new AstExpression
($1);
1414 $$
= new AstExpression
(sal_Int32
(1), ET_boolean
);
1418 $$
= new AstExpression
(sal_Int32
(0), ET_boolean
);
1429 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1430 AstDeclaration
const * type
= nullptr
;
1433 * If the constant's type is a scoped name, it must resolve
1434 * to a scalar constant type
1436 if
( pScope
&& (type
= pScope
->lookupByName
(*$1)) ) {
1437 if
(!ErrorHandler
::checkPublished
(type
))
1444 type
= resolveTypedefs
(type
);
1445 if
(type
->getNodeType
() == NT_predefined
)
1447 $$
= static_cast
< AstBaseType
const * >(type
)->
1460 idlc
()->setParseState
(PS_ExceptSeen
);
1464 idlc
()->setParseState
(PS_ExceptIDSeen
);
1465 checkIdentifier
($3);
1469 idlc
()->setParseState
(PS_InheritSpecSeen
);
1471 $$
= new FeInheritanceHeader
(NT_exception
, $3, $5, nullptr
);
1479 idlc
()->setParseState
(PS_ExceptHeaderSeen
);
1481 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1482 AstException
* pExcept
= nullptr
;
1486 AstException
* pBase
= static_cast
< AstException
* >(
1488 pExcept
= new AstException
(*$1->getName
(), pBase
, pScope
);
1489 pScope
->addDeclaration
(pExcept
);
1492 * Push the scope of the exception on the scopes stack
1494 idlc
()->scopes
()->push
(pExcept
);
1499 idlc
()->setParseState
(PS_ExceptSqSeen
);
1503 idlc
()->setParseState
(PS_ExceptBodySeen
);
1507 idlc
()->setParseState
(PS_ExceptQsSeen
);
1508 /* this exception is finished, pop its scope from the stack */
1509 idlc
()->scopes
()->pop
();
1517 idlc
()->setParseState
(PS_PropertyTypeSeen
);
1519 at_least_one_declarator
1521 idlc
()->setParseState
(PS_PropertyCompleted
);
1523 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1524 AstAttribute
* pAttr
= nullptr
;
1525 FeDeclList
* pList
= $4;
1526 FeDeclarator
* pDecl
= nullptr
;
1527 AstType
const * pType
= nullptr
;
1529 if
( pScope
->getScopeNodeType
() == NT_singleton
)
1531 ErrorHandler
::error0
(ErrorCode
::IllegalAdd
);
1534 if
( ($1 & AF_ATTRIBUTE
) == AF_ATTRIBUTE
)
1535 ErrorHandler
::flagError
(ErrorCode
::WrongAttributeKeyword
, AF_ATTRIBUTE
);
1537 if
( ($1 & AF_PROPERTY
) != AF_PROPERTY
)
1538 ErrorHandler
::flagError
(ErrorCode
::MissingAttributeKeyword
, AF_PROPERTY
);
1541 * Create nodes representing attributes and add them to the
1544 if
( pScope
&& $2 && pList
)
1546 FeDeclList
::iterator iter
= pList
->begin
();
1547 FeDeclList
::iterator end
= pList
->end
();
1558 pType
= FeDeclarator
::compose
($2);
1566 pAttr
= new AstAttribute
(NT_property
, $1, pType
, pDecl
->getName
(), pScope
);
1568 pScope
->addDeclaration
(pAttr
);
1580 yyerror("property");
1586 service_exports service_export
1591 service_interface_header
1592 at_least_one_scoped_name
1595 idlc
()->setParseState
(PS_ServiceMemberSeen
);
1597 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1598 AstDeclaration
* pDecl
= nullptr
;
1599 AstInterfaceMember
* pIMember
= nullptr
;
1601 if
( pScope
->getScopeNodeType
() == NT_singleton
)
1603 ErrorHandler
::error0
(ErrorCode
::IllegalAdd
);
1607 * Create a node representing a class member.
1608 * Store it in the enclosing scope
1612 for
(auto
const& elem
: *($2))
1614 pDecl
= pScope
->lookupByName
(elem
);
1615 if
( pDecl
&& (pDecl
->getNodeType
() == NT_interface
) )
1617 /* we relax the strict published check and allow to add new
1618 * interfaces if they are optional
1620 bool bOptional
= (($1 & AF_OPTIONAL
) == AF_OPTIONAL
);
1621 if
( ErrorHandler
::checkPublished
(pDecl
, bOptional
) )
1623 pIMember
= new AstInterfaceMember
(
1624 $1, static_cast
<AstInterface
*>(pDecl
), elem
, pScope
);
1625 pScope
->addDeclaration
(pIMember
);
1629 ErrorHandler
::lookupError
(ErrorCode
::InterfaceMemberLookup
, elem
, scopeAsDecl
(pScope
));
1636 | service_service_header
1637 at_least_one_scoped_name
1640 idlc
()->setParseState
(PS_ServiceMemberSeen
);
1642 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1643 AstDeclaration
* pDecl
= nullptr
;
1644 AstServiceMember
* pSMember
= nullptr
;
1647 * Create a node representing a class member.
1648 * Store it in the enclosing scope
1652 for
(auto
const& elem
: *($2))
1654 pDecl
= pScope
->lookupByName
(elem
);
1655 if
( pDecl
&& (pDecl
->getNodeType
() == NT_service
) )
1657 if
( static_cast
< AstService
* >(pDecl
)->isSingleInterfaceBasedService
() ||
(pScope
->getScopeNodeType
() == NT_singleton
&& pScope
->nMembers
() > 0) )
1658 ErrorHandler
::error0
(ErrorCode
::IllegalAdd
);
1659 else if
( ErrorHandler
::checkPublished
(pDecl
) )
1661 pSMember
= new AstServiceMember
(
1662 $1, static_cast
<AstService
*>(pDecl
), elem
, pScope
);
1663 pScope
->addDeclaration
(pSMember
);
1667 ErrorHandler
::lookupError
(ErrorCode
::ServiceMemberLookup
, elem
, scopeAsDecl
(pScope
));
1674 at_least_one_scoped_name
1677 idlc
()->setParseState
(PS_ServiceMemberSeen
);
1679 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1680 AstDeclaration
* pDecl
= nullptr
;
1681 AstObserves
* pObserves
= nullptr
;
1683 if
( pScope
->getScopeNodeType
() == NT_singleton
)
1685 ErrorHandler
::error0
(ErrorCode
::IllegalAdd
);
1689 * Create a node representing a class member.
1690 * Store it in the enclosing scope
1694 for
(auto
const& elem
: *($2))
1696 pDecl
= pScope
->lookupByName
(elem
);
1697 if
( pDecl
&& (pDecl
->getNodeType
() == NT_interface
) )
1699 pObserves
= new AstObserves
(static_cast
<AstInterface
*>(pDecl
), elem
, pScope
);
1700 pScope
->addDeclaration
(pObserves
);
1703 ErrorHandler
::lookupError
(ErrorCode
::InterfaceMemberLookup
, elem
, scopeAsDecl
(pScope
));
1711 at_least_one_scoped_name
1714 idlc
()->setParseState
(PS_ServiceMemberSeen
);
1716 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1717 AstDeclaration
* pDecl
= nullptr
;
1718 AstNeeds
* pNeeds
= nullptr
;
1720 if
( pScope
->getScopeNodeType
() == NT_singleton
)
1722 ErrorHandler
::error0
(ErrorCode
::IllegalAdd
);
1726 * Create a node representing a class member.
1727 * Store it in the enclosing scope
1731 for
(auto
const& elem
: *($2))
1733 pDecl
= pScope
->lookupByName
(elem
);
1734 if
( pDecl
&& (pDecl
->getNodeType
() == NT_service
) )
1736 pNeeds
= new AstNeeds
(static_cast
<AstService
*>(pDecl
), elem
, pScope
);
1737 pScope
->addDeclaration
(pNeeds
);
1740 ErrorHandler
::lookupError
(ErrorCode
::ServiceMemberLookup
, elem
, scopeAsDecl
(pScope
));
1750 idlc
()->setParseState
(PS_PropertyDeclSeen
);
1754 service_interface_header
:
1757 idlc
()->setParseState
(PS_ServiceIFHeadSeen
);
1763 idlc
()->setParseState
(PS_ServiceIFHeadSeen
);
1764 if
( (AF_OPTIONAL
!= $1) && ( AF_INVALID
!= $1) )
1765 ErrorHandler
::flagError
(ErrorCode
::ExpectedOptional
, $1);
1770 service_service_header
:
1773 idlc
()->setParseState
(PS_ServiceSHeadSeen
);
1779 idlc
()->setParseState
(PS_ServiceSHeadSeen
);
1780 if
( (AF_OPTIONAL
!= $1) && ( AF_INVALID
!= $1) )
1781 ErrorHandler
::flagError
(ErrorCode
::ExpectedOptional
, $1);
1789 idlc
()->setParseState
(PS_ServiceSeen
);
1793 idlc
()->setParseState
(PS_ServiceIDSeen
);
1794 checkIdentifier
($3);
1796 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1797 AstService
* pService
= nullptr
;
1800 * Make a new service and add it to the enclosing scope
1802 if
(pScope
!= nullptr
)
1804 pService
= new AstService
(*$3, pScope
);
1805 pScope
->addDeclaration
(pService
);
1809 * Push it on the stack
1811 idlc
()->scopes
()->push
(pService
);
1815 /* this service is finished, pop its scope from the stack */
1816 idlc
()->scopes
()->pop
();
1821 service_interface_dfn
1822 | service_obsolete_dfn
1825 service_interface_dfn:
1828 AstScope
* scope
= idlc
()->scopes
()->nextToTop
();
1829 // skip the scope pushed by service_dcl
1830 AstDeclaration
* decl
= scope
->lookupByName
(*$2);
1832 && resolveTypedefs
(decl
)->getNodeType
() == NT_interface
)
1834 if
(ErrorHandler
::checkPublished
(decl
)) {
1835 idlc
()->scopes
()->top
()->addDeclaration
(decl
);
1838 ErrorHandler
::lookupError
(
1839 ErrorCode
::InterfaceMemberLookup
, *$2, scopeAsDecl
(scope
));
1845 AstService
* s
= static_cast
< AstService
* >(idlc
()->scopes
()->top
());
1847 s
->setSingleInterfaceBasedService
();
1848 s
->setDefaultConstructor
(!$4);
1854 service_body
{ $$
= true
; }
1855 |
/* empty */ { $$
= false
; }
1865 constructors constructor
1872 checkIdentifier
($1);
1873 AstScope
* scope
= idlc
()->scopes
()->top
();
1874 AstOperation
* ctor
= new AstOperation
(nullptr
, *$1, scope
);
1876 scope
->addDeclaration
(ctor
);
1877 idlc
()->scopes
()->push
(ctor
);
1884 static_cast
< AstOperation
* >(idlc
()->scopes
()->top
())->setExceptions
(
1887 idlc
()->scopes
()->pop
();
1888 if
(static_cast
< AstService
* >(idlc
()->scopes
()->top
())->
1889 checkLastConstructor
())
1891 ErrorHandler
::error0
(ErrorCode
::SimilarConstructors
);
1900 idlc
()->setParseState
(PS_SingletonSeen
);
1904 idlc
()->setParseState
(PS_SingletonIDSeen
);
1905 checkIdentifier
($3);
1907 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1908 AstService
* pService
= nullptr
;
1911 * Make a new service and add it to the enclosing scope
1913 if
(pScope
!= nullptr
)
1915 pService
= new AstService
(NT_singleton
, *$3, pScope
);
1916 pScope
->addDeclaration
(pService
);
1920 * Push it on the stack
1922 idlc
()->scopes
()->push
(pService
);
1926 /* this singelton is finished, pop its scope from the stack */
1927 idlc
()->scopes
()->pop
();
1932 singleton_interface_dfn
1933 | service_obsolete_dfn
1936 singleton_interface_dfn:
1939 AstScope
* scope
= idlc
()->scopes
()->nextToTop
();
1940 // skip the scope (needlessly) pushed by singleton_dcl
1941 AstDeclaration
* decl
= scope
->lookupByName
(*$2);
1943 && resolveTypedefs
(decl
)->getNodeType
() == NT_interface
)
1945 if
(ErrorHandler
::checkPublished
(decl
)) {
1946 idlc
()->scopes
()->top
()->addDeclaration
(decl
);
1949 ErrorHandler
::lookupError
(
1950 ErrorCode
::InterfaceMemberLookup
, *$2, scopeAsDecl
(scope
));
1956 service_obsolete_dfn:
1959 idlc
()->setParseState
(
1960 idlc
()->scopes
()->top
()->getScopeNodeType
() == NT_service
1961 ? PS_ServiceSqSeen
: PS_SingletonSqSeen
);
1965 idlc
()->setParseState
(
1966 idlc
()->scopes
()->top
()->getScopeNodeType
() == NT_service
1967 ? PS_ServiceBodySeen
: PS_SingletonBodySeen
);
1971 idlc
()->setParseState
(
1972 idlc
()->scopes
()->top
()->getScopeNodeType
() == NT_service
1973 ? PS_ServiceQsSeen
: PS_SingletonQsSeen
);
1980 idlc
()->setParseState
(PS_TypedefSeen
);
1990 idlc
()->setParseState
(PS_TypeSpecSeen
);
1991 if
($1 != nullptr
&& $1->getNodeType
() == NT_instantiated_struct
) {
1992 ErrorHandler
::error0
(ErrorCode
::InstantiatedStructTypeTypedef
);
1995 at_least_one_declarator
1997 idlc
()->setParseState
(PS_DeclaratorsSeen
);
1999 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
2000 AstTypeDef
* pTypeDef
= nullptr
;
2001 FeDeclList
* pList
= $3;
2002 FeDeclarator
* pDecl
= nullptr
;
2003 AstType
const * pType
= nullptr
;
2006 * Create nodes representing typedefs and add them to the
2009 if
( pScope
&& $1 && pList
)
2011 FeDeclList
::iterator iter
= pList
->begin
();
2012 FeDeclList
::iterator end
= pList
->end
();
2023 pType
= FeDeclarator
::compose
($1);
2031 pTypeDef
= new AstTypeDef
(pType
, pDecl
->getName
(), pScope
);
2033 pScope
->addDeclaration
(pTypeDef
);
2042 at_least_one_declarator
:
2043 declarator declarators
2051 FeDeclList
* pList
= new FeDeclList
;
2052 pList
->push_back
($1);
2062 idlc
()->setParseState
(PS_DeclsCommaSeen
);
2066 idlc
()->setParseState
(PS_DeclsDeclSeen
);
2073 FeDeclList
* pList
= new FeDeclList
;
2074 pList
->push_back
($4);
2087 // For historic reasons, the struct com.sun.star.uno.Uik contains
2088 // members with illegal names (of the form "m_DataN"); avoid useless
2089 // warnings about them:
2090 AstScope
* scope
= idlc
()->scopes
()->top
();
2091 if
(scope
== nullptr || scope
->getScopeNodeType
() != NT_struct
2092 ||
(scopeAsDecl
(scope
)->getScopedName
()
2093 != "com::sun::star::uno::Uik"))
2095 checkIdentifier
($1);
2098 $$
= new FeDeclarator
(*$1);
2103 at_least_one_scoped_name
:
2104 scoped_name scoped_names
2108 $2->push_front
(*$1);
2112 std
::list
< OString
>* pScopedNames
= new std
::list
< OString
>;
2113 // coverity[copy_paste_error : FALSE] - this is not a cut and paste
2114 pScopedNames
->push_back
(*$1);
2125 idlc
()->setParseState
(PS_SNListCommaSeen
);
2129 idlc
()->setParseState
(PS_ScopedNameSeen
);
2136 std
::list
< OString
>* pNames
= new std
::list
< OString
>;
2137 pNames
->push_back
(*$4);
2151 idlc
()->setParseState
(PS_SN_IDSeen
);
2152 checkIdentifier
($1);
2155 | IDL_SCOPESEPARATOR
2157 idlc
()->setParseState
(PS_ScopeDelimSeen
);
2161 checkIdentifier
($3);
2162 OString
* pName
= new OString
("::");
2173 checkIdentifier
($4);
2174 *$1 += OString
("::");
2183 | constructed_type_spec
2188 | scoped_name opt_type_args
2190 $$
= createNamedType
($1, $2);
2197 $$
= idlc
()->scopes
()->bottom
()->lookupPrimitiveType
($1);
2199 | sequence_type_spec
2203 '<' type_args
'>' { $$
= $2; }
2204 |
/* empty */ { $$
= nullptr
; }
2211 $$
->push_back
(const_cast
< AstDeclaration
* >($1)); //TODO: const_cast
2213 | type_args
',' type_arg
2215 $1->push_back
(const_cast
< AstDeclaration
* >($3)); //TODO: const_cast
2223 if
($1 != nullptr
&& static_cast
< AstType
const * >($1)->isUnsigned
()) {
2224 ErrorHandler
::error0
(ErrorCode
::UnsignedTypeArgument
);
2262 IDL_UNSIGNED IDL_LONG
2266 | IDL_UNSIGNED IDL_HYPER
2270 | IDL_UNSIGNED IDL_SHORT
2329 constructed_type_spec
:
2334 sequence_type_spec
:
2337 idlc
()->setParseState
(PS_SequenceSeen
);
2339 * Push a sequence marker on scopes stack
2341 idlc
()->scopes
()->push
(nullptr
);
2345 idlc
()->setParseState
(PS_SequenceSqSeen
);
2349 idlc
()->setParseState
(PS_SequenceTypeSeen
);
2353 idlc
()->setParseState
(PS_SequenceQsSeen
);
2355 * Remove sequence marker from scopes stack
2357 if
(idlc
()->scopes
()->top
() == nullptr
)
2358 idlc
()->scopes
()->pop
();
2360 * Create a node representing a sequence
2362 AstScope
* pScope
= idlc
()->scopes
()->bottom
();
2363 AstDeclaration
* pDecl
= nullptr
;
2364 AstDeclaration
* pSeq
= nullptr
;
2368 AstType
const *pType
= static_cast
<AstType
const *>($5);
2371 pSeq
= new AstSequence
(pType
, pScope
);
2373 * Add this AstSequence to the types defined in the global scope
2375 pDecl
= pScope
->addDeclaration
(pSeq
);
2376 if
( pSeq
!= pDecl
)
2378 // if sequence type already defined then use it
2388 yyerror("sequence declaration");
2397 idlc
()->setParseState
(PS_StructHeaderSeen
);
2399 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
2400 AstStruct
* pStruct
= nullptr
;
2404 AstStruct
const* pBase
= static_cast
< AstStruct
const* >(resolveTypedefs
($1->getInherits
()));
2405 pStruct
= new AstStruct
(
2406 *$1->getName
(), $1->getTypeParameters
(), pBase
, pScope
);
2407 pScope
->addDeclaration
(pStruct
);
2410 * Push the scope of the struct on the scopes stack
2412 idlc
()->scopes
()->push
(pStruct
);
2417 idlc
()->setParseState
(PS_StructSqSeen
);
2421 idlc
()->setParseState
(PS_StructBodySeen
);
2425 idlc
()->setParseState
(PS_StructQsSeen
);
2426 /* this exception is finished, pop its scope from the stack */
2427 idlc
()->scopes
()->pop
();
2434 idlc
()->setParseState
(PS_StructSeen
);
2438 idlc
()->setParseState
(PS_StructIDSeen
);
2439 checkIdentifier
($3);
2444 idlc
()->setParseState
(PS_InheritSpecSeen
);
2446 // Polymorphic struct type templates with base types would cause various
2447 // problems in language bindings, so forbid them here. For example,
2448 // GCC prior to version 3.4 fails with code like
2450 // struct Base { ... };
2451 // template< typename typeparam_T > struct Derived: public Base {
2452 // int member1 CPPU_GCC3_ALIGN(Base);
2455 // (Note that plain struct types with instantiated polymorphic struct
2456 // type bases, which might also cause problems in language bindings, are
2457 // already rejected on a syntactic level.)
2458 if
($5 != nullptr
&& $6 != nullptr
) {
2459 ErrorHandler
::error0
(ErrorCode
::StructTypeTemplateWithBase
);
2462 $$
= new FeInheritanceHeader
(NT_struct
, $3, $6, $5);
2469 '<' type_params
'>' { $$
= $2; }
2470 |
/* empty */ { $$
= nullptr
; }
2476 $$
= new std
::vector
< OString
>;
2480 | type_params
',' identifier
2482 if
(std
::find
($1->begin
(), $1->end
(), *$3) != $1->end
()) {
2483 ErrorHandler
::error0
(ErrorCode
::IdenticalTypeParameters
);
2491 at_least_one_member
: member members
;
2501 idlc
()->setParseState
(PS_MemberTypeSeen
);
2503 at_least_one_declarator
2505 idlc
()->setParseState
(PS_MemberDeclsSeen
);
2509 idlc
()->setParseState
(PS_MemberDeclsCompleted
);
2511 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
2512 AstMember
* pMember
= nullptr
;
2513 FeDeclList
* pList
= $3;
2514 FeDeclarator
* pDecl
= nullptr
;
2515 AstType
const * pType
= nullptr
;
2517 // !!! check recursive type
2519 if
( pScope
&& pList
&& $1 )
2521 FeDeclList
::iterator iter
= pList
->begin
();
2522 FeDeclList
::iterator end
= pList
->end
();
2532 pType
= FeDeclarator
::compose
($1);
2540 pMember
= new AstMember
(pType
, pDecl
->getName
(), pScope
);
2542 if
( !pDecl
->checkType
($1) )
2547 pScope
->addDeclaration
(pMember
);
2556 yyerror("member definition");
2563 | scoped_name opt_type_args
2565 AstDeclaration
const * decl
= nullptr
;
2566 AstStruct
* scope
= static_cast
< AstStruct
* >(idlc
()->scopes
()->top
());
2567 if
(scope
!= nullptr
&& $2 == nullptr
) {
2568 decl
= scope
->findTypeParameter
(*$1);
2570 if
(decl
!= nullptr
) {
2574 decl
= createNamedType
($1, $2);
2575 if
(scope
!= nullptr
&& includes
(decl
, scopeAsDecl
(scope
))) {
2576 ErrorHandler
::error1
(
2577 ErrorCode
::RecursiveType
, scopeAsDecl
(scope
));
2588 idlc
()->setParseState
(PS_EnumSeen
);
2592 idlc
()->setParseState
(PS_EnumIDSeen
);
2593 checkIdentifier
($3);
2595 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
2596 AstEnum
* pEnum
= nullptr
;
2599 * Create a node representing an enum and add it to its
2602 if
(pScope
!= nullptr
)
2604 pEnum
= new AstEnum
(*$3, pScope
);
2606 * Add it to its defining scope
2608 pScope
->addDeclaration
(pEnum
);
2612 * Push the enum scope on the scopes stack
2614 idlc
()->scopes
()->push
(pEnum
);
2619 idlc
()->setParseState
(PS_EnumSqSeen
);
2621 at_least_one_enumerator
2623 idlc
()->setParseState
(PS_EnumBodySeen
);
2627 idlc
()->setParseState
(PS_EnumQsSeen
);
2629 * Done with this enum. Pop its scope from the scopes stack
2631 if
(idlc
()->scopes
()->top
() == nullptr
)
2635 $$
= static_cast
<AstEnum
*>(idlc
()->scopes
()->topNonNull
());
2636 idlc
()->scopes
()->pop
();
2641 at_least_one_enumerator
: enumerator enumerators
;
2647 idlc
()->setParseState
(PS_EnumCommaSeen
);
2653 yyerror("enumerator definition");
2661 checkIdentifier
($1);
2663 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
2664 AstEnum
* pEnum
= nullptr
;
2665 AstConstant
* pEnumVal
= nullptr
;
2667 if
( pScope
&& pScope
->getScopeNodeType
() == NT_enum
)
2669 pEnum
= static_cast
<AstEnum
*>(pScope
);
2672 AstExpression
* pExpr
= new AstExpression
(pEnum
->getEnumValueCount
());
2673 pEnumVal
= new AstConstant
(ET_long
, NT_enum_val
,
2674 pExpr
, *$1, pScope
);
2676 if
( pEnum
->checkValue
(pEnumVal
->getConstValue
()) )
2677 ErrorHandler
::error1
(ErrorCode
::Eval
, pEnum
);
2679 pScope
->addDeclaration
(pEnumVal
);
2687 checkIdentifier
($1);
2689 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
2690 AstEnum
* pEnum
= nullptr
;
2691 AstConstant
* pEnumVal
= nullptr
;
2693 if
( $3 && pScope
&& pScope
->getScopeNodeType
() == NT_enum
)
2696 if
( $3->coerce
(ET_long
) )
2698 pEnum
= static_cast
<AstEnum
*>(pScope
);
2701 pEnumVal
= new AstConstant
(ET_long
, NT_enum_val
,
2704 if
( pEnum
->checkValue
(pEnumVal
->getConstValue
()) )
2705 ErrorHandler
::error1
(ErrorCode
::Eval
, pEnum
);
2707 pScope
->addDeclaration
(pEnumVal
);
2710 ErrorHandler
::coercionError
($3, ET_long
);
2720 | IDL_GET
{ $$
= new OString
("get"); }
2721 | IDL_SET
{ $$
= new OString
("set"); }
2722 | IDL_PUBLISHED
{ $$
= new OString
("published"); }
2728 * Report an error situation discovered in a production
2730 void yyerror(char const *errmsg
)
2732 ErrorHandler
::syntaxError
(idlc
()->getParseState
(), idlc
()->getLineNumber
(), errmsg
);
2733 idlc
()->setParseState
(PS_NoState
);
2736 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */