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/string.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 OString msg
= "mismatched identifier '" + *id
+ "'";
79 ErrorHandler
::syntaxError
(idlc
()->getParseState
(),
80 idlc
()->getLineNumber
(),
84 ErrorHandler
::warning0
(WarningCode
::WrongNamingConvention
, id
->getStr
());
88 static void reportDoubleMemberDeclarations
(
89 AstInterface
::DoubleMemberDeclarations
const & doubleMembers
)
91 for
(auto
const& doubleMember
: doubleMembers
)
93 ErrorHandler
::error2
(ErrorCode
::DoubleMember
, doubleMember.first
, doubleMember.second
);
97 static void addInheritedInterface
(
98 AstInterface
* ifc
, OString
const & name
, bool optional
,
99 OUString
const & documentation
)
101 AstDeclaration
* decl
= ifc
->lookupByName
(name
);
102 AstDeclaration
const * resolved
= resolveTypedefs
(decl
);
103 if
(resolved
!= nullptr
&& resolved
->getNodeType
() == NT_interface
) {
104 if
(ErrorHandler
::checkPublished
(decl
)) {
105 if
(!static_cast
< AstInterface
const * >(resolved
)->isDefined
()) {
106 ErrorHandler
::inheritanceError
(
107 NT_interface
, &ifc
->getScopedName
(), decl
);
109 AstInterface
::DoubleDeclarations doubleDecls
(
110 ifc
->checkInheritedInterfaceClashes
(
111 static_cast
< AstInterface
const * >(resolved
),
113 if
(doubleDecls.interfaces.empty
()
114 && doubleDecls.members.empty
())
116 ifc
->addInheritedInterface
(
117 static_cast
< AstType
* >(decl
), optional
,
120 for
(auto
const& elem
: doubleDecls.interfaces
)
122 ErrorHandler
::error1
(
123 ErrorCode
::DoubleInheritance
, elem
);
125 reportDoubleMemberDeclarations
(doubleDecls.members
);
130 ErrorHandler
::lookupError
(
131 ErrorCode
::InterfaceMemberLookup
, name
, scopeAsDecl
(ifc
));
135 static AstDeclaration
const * createNamedType
(
136 OString
const * scopedName
, DeclList
const * typeArgs
)
138 AstDeclaration
* decl
= idlc
()->scopes
()->topNonNull
()->lookupByName
(
140 AstDeclaration
const * resolved
= resolveTypedefs
(decl
);
141 if
(decl
== nullptr
) {
142 ErrorHandler
::lookupError
(*scopedName
);
143 } else if
(!ErrorHandler
::checkPublished
(decl
)) {
145 } else if
(resolved
->getNodeType
() == NT_struct
) {
146 if
(static_cast
< AstStruct
const * >(resolved
)->getTypeParameterCount
()
147 != (typeArgs
== nullptr ?
0 : typeArgs
->size
()))
149 ErrorHandler
::error0
(ErrorCode
::WrongNumberOfTypeArguments
);
151 } else if
(typeArgs
!= nullptr
) {
152 AstScope
* global
= idlc
()->scopes
()->bottom
();
153 AstDeclaration
* inst
= new AstStructInstance
(
154 static_cast
< AstType
* >(decl
), typeArgs
, global
);
155 decl
= global
->addDeclaration
(inst
);
160 } else if
(decl
->isType
()) {
161 if
(typeArgs
!= nullptr
) {
162 ErrorHandler
::error0
(ErrorCode
::WrongNumberOfTypeArguments
);
166 ErrorHandler
::noTypeError
(decl
);
174 static bool includes
(AstDeclaration
const * type1
, AstDeclaration
const * type2
) {
175 OSL_ASSERT
(type2
!= nullptr
);
176 if
(type1
!= nullptr
) {
177 if
(type1
->getNodeType
() == NT_instantiated_struct
) {
178 AstStructInstance
const * inst
179 = static_cast
< AstStructInstance
const * >(type1
);
180 if
(inst
->getTypeTemplate
() == type2
) {
183 for
(DeclList
::const_iterator i
(inst
->getTypeArgumentsBegin
());
184 i
!= inst
->getTypeArgumentsEnd
(); ++i
)
186 if
(includes
(*i
, type2
)) {
190 } else if
(type1
== type2
) {
197 // Suppress any warnings from generated code:
199 #pragma warning(disable: 4702) // unreachable code
203 * Declare the type of values in the grammar
206 ExprType etval
; /* Expression type */
207 AstDeclaration
* dclval
; /* Declaration */
208 AstDeclaration
const * cdclval
;
210 AstExpression
* exval
; /* expression value */
211 FeDeclarator
* fdval
; /* declarator value */
212 FeDeclList
* dlval
; /* declarator list value */
213 FeInheritanceHeader
* ihval
; /* inheritance header value */
214 OString
* sval
; /* OString value */
215 std
::vector
< OString
> * svals
;
216 sal_Char
* strval
; /* sal_Char* value */
217 bool bval
; /* sal_Boolean* value */
218 sal_Int64 ival
; /* sal_Int64 value */
219 sal_uInt64 uval
; /* sal_uInt64 value */
220 sal_uInt32 ulval
; /* sal_uInt32 value */
221 double dval
; /* double value */
222 float fval
; /* float value */
223 std
::list
< OString
>* slval
; /* StringList value */
224 AttributeExceptions
::Part attexcpval
;
225 AttributeExceptions attexcval
;
229 * Token types: These are returned by the lexer
232 %token
<sval
> IDL_IDENTIFIER
237 %token IDL_CONSTRAINED
241 %token IDL_MAYBEAMBIGUOUS
242 %token IDL_MAYBEDEFAULT
287 %token
<strval
> IDL_LEFTSHIFT
288 %token
<strval
> IDL_RIGHTSHIFT
289 %token
<strval
> IDL_SCOPESEPARATOR
291 %token
<ival
> IDL_INTEGER_LITERAL
292 %token
<uval
> IDL_INTEGER_ULITERAL
293 %token
<dval
> IDL_FLOATING_PT_LITERAL
296 * These are production names:
298 %type
<dclval
> type_dcl
299 %type
<dclval
> exception_name
300 %type
<cdclval
> constructed_type_spec enum_type op_type_spec
301 %type
<cdclval
> sequence_type_spec simple_type_spec struct_type
302 %type
<cdclval
> type_spec
303 %type
<cdclval
> fundamental_type type_arg type_or_parameter
304 %type
<dclsval
> opt_raises raises exception_list
305 %type
<attexcpval
> opt_attribute_get_raises attribute_get_raises
306 %type
<attexcpval
> opt_attribute_set_raises attribute_set_raises
307 %type
<dclsval
> opt_type_args type_args
309 %type
<sval
> identifier
310 %type
<sval
> interface_decl
311 %type
<sval
> scoped_name inheritance_spec
312 %type
<slval
> scoped_names at_least_one_scoped_name
314 %type
<etval
> const_type integer_type char_type boolean_type
315 %type
<etval
> floating_pt_type any_type signed_int string_type
316 %type
<etval
> unsigned_int base_type_spec byte_type type_type
318 %type
<exval
> expression const_expr or_expr xor_expr and_expr
319 %type
<exval
> add_expr mult_expr unary_expr primary_expr shift_expr
320 %type
<exval
> literal
322 %type
<fdval
> declarator
323 %type
<dlval
> declarators at_least_one_declarator
325 %type
<ihval
> exception_header structure_header interfaceheader
327 %type
<ulval
> flag_header opt_attrflags opt_attrflag
328 %type
<ulval
> direction service_interface_header service_service_header
330 %type
<bval
> optional_inherited_interface opt_rest opt_service_body
332 %type
<attexcval
> opt_attribute_block attribute_block_rest opt_attribute_raises
334 %type
<svals
> opt_type_params type_params
343 definition definitions
348 opt_published publishable_definition
351 idlc
()->setParseState
(PS_ModuleDeclSeen
);
355 idlc
()->setParseState
(PS_NoState
);
359 yyerror("definitions");
365 IDL_PUBLISHED
{ idlc
()->setPublished
(true
); }
366 |
/* empty */ { idlc
()->setPublished
(false
); }
369 publishable_definition:
372 idlc
()->setParseState
(PS_TypeDeclSeen
);
376 idlc
()->setParseState
(PS_NoState
);
380 idlc
()->setParseState
(PS_ExceptionDeclSeen
);
384 idlc
()->setParseState
(PS_NoState
);
388 idlc
()->setParseState
(PS_InterfaceDeclSeen
);
392 idlc
()->setParseState
(PS_NoState
);
396 idlc
()->setParseState
(PS_ServiceDeclSeen
);
400 idlc
()->setParseState
(PS_NoState
);
404 idlc
()->setParseState
(PS_SingletonDeclSeen
);
408 idlc
()->setParseState
(PS_NoState
);
412 idlc
()->setParseState
(PS_ConstantsDeclSeen
);
416 idlc
()->setParseState
(PS_NoState
);
423 idlc
()->setParseState
(PS_ModuleSeen
);
424 idlc
()->setPublished
(false
);
428 idlc
()->setParseState
(PS_ModuleIDSeen
);
431 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
432 AstModule
* pModule
= nullptr
;
436 pModule
= new AstModule
(*$3, pScope
);
437 if
( AstDeclaration
* pExists
= pScope
->lookupForAdd
(pModule
) )
439 pExists
->setInMainfile
(idlc
()->isInMainFile
());
440 pExists
->setFileName
(pModule
->getFileName
());
441 if
(pExists
->isPredefined
())
443 pExists
->setPredefined
(false
);
444 if
(pExists
->getDocumentation
().getLength
() == 0 &&
445 pModule
->getDocumentation
().getLength
() > 0)
447 pExists
->setDocumentation
(pModule
->getDocumentation
());
451 pModule
= static_cast
<AstModule
*>(pExists
);
454 pScope
->addDeclaration
(pModule
);
456 idlc
()->scopes
()->push
(pModule
);
462 idlc
()->setParseState
(PS_ModuleSqSeen
);
466 idlc
()->setParseState
(PS_ModuleBodySeen
);
470 idlc
()->setParseState
(PS_ModuleQsSeen
);
472 * Finished with this module - pop it from the scope stack
474 idlc
()->scopes
()->pop
();
486 idlc
()->setParseState
(PS_InterfaceSeen
);
490 idlc
()->setParseState
(PS_InterfaceIDSeen
);
499 idlc
()->setParseState
(PS_ForwardDeclSeen
);
501 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
502 AstInterface
* pForward
= nullptr
;
503 AstDeclaration
* pDecl
= nullptr
;
506 * Make a new forward interface node and add it to its enclosing scope
510 pForward
= new AstInterface
(*$1, nullptr
, pScope
);
512 pDecl
= pScope
->lookupByName
(pForward
->getScopedName
());
515 if
( (pDecl
!= pForward
) &&
516 (pDecl
->getNodeType
() == NT_interface
) )
521 ErrorHandler
::error2
(ErrorCode
::RedefScope
, scopeAsDecl
(pScope
), pDecl
);
526 * Add the interface to its definition scope
528 pScope
->addDeclaration
(pForward
);
538 idlc
()->setParseState
(PS_InterfaceHeadSeen
);
540 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
541 AstInterface
* pInterface
= nullptr
;
542 AstInterface
* pForward
= nullptr
;
545 * Make a new interface node and add it to its enclosing scope
549 pInterface
= new AstInterface
(
551 static_cast
< AstInterface
const * >(resolveTypedefs
($1->getInherits
())), pScope
);
552 if
( AstDeclaration
* pDecl
= pScope
->lookupByName
(pInterface
->getScopedName
()) )
555 * See if we're defining a forward declared interface.
557 if
(pDecl
->getNodeType
() == NT_interface
)
559 pForward
= static_cast
<AstInterface
*>(pDecl
);
560 if
( !pForward
->isDefined
() )
563 * Check if redefining in same scope
565 if
( pForward
->getScope
() != pScope
)
567 if
( pForward
->getScopedName
() != pInterface
->getScopedName
() )
569 ErrorHandler
::error3
(ErrorCode
::ScopeConflict
,
570 pInterface
, pForward
, scopeAsDecl
(pScope
));
573 else if
( !pInterface
->isPublished
()
574 && pForward
->isPublished
() )
576 ErrorHandler
::error0
(ErrorCode
::PublishedForward
);
579 * All OK, set full definition
583 pForward
->forwardDefined
(*pInterface
);
585 pInterface
= pForward
;
588 // special handling for XInterface because it is predefined
589 if
( pForward
->isPredefined
() &&
590 pForward
->getScopedName
() == "com::sun::star::uno::XInterface")
592 /* replace the predefined XInterface */
593 *pForward
= *pInterface
;
595 pInterface
= pForward
;
603 * Add the interface to its definition scope
605 pScope
->addDeclaration
(pInterface
);
609 * Push it on the scope stack
611 idlc
()->scopes
()->push
(pInterface
);
616 idlc
()->setParseState
(PS_InterfaceSqSeen
);
620 AstInterface
* ifc
= static_cast
< AstInterface
* >(
621 idlc
()->scopes
()->topNonNull
());
622 if
(!ifc
->hasMandatoryInheritedInterfaces
()
623 && ifc
->getScopedName
() != "com::sun::star::uno::XInterface")
625 addInheritedInterface
(
626 ifc
, "::com::sun::star::uno::XInterface", false
,
630 idlc
()->setParseState
(PS_InterfaceBodySeen
);
634 idlc
()->setParseState
(PS_InterfaceQsSeen
);
636 * Done with this interface - pop it off the scopes stack
638 idlc
()->scopes
()->pop
();
642 yyerror("interface definition");
648 interface_decl inheritance_spec
650 idlc
()->setParseState
(PS_InheritSpecSeen
);
652 $$
= new FeInheritanceHeader
(NT_interface
, $1, $2, nullptr
);
660 idlc
()->setParseState
(PS_InheritColonSeen
);
680 idlc
()->setParseState
(PS_AttributeDeclSeen
);
684 idlc
()->setParseState
(PS_NoState
);
688 idlc
()->setParseState
(PS_OperationDeclSeen
);
692 idlc
()->setParseState
(PS_NoState
);
694 | interface_inheritance_decl
696 idlc
()->setParseState
(PS_InterfaceInheritanceDeclSeen
);
700 idlc
()->setParseState
(PS_NoState
);
708 idlc
()->setParseState
(PS_AttrTypeSeen
);
712 idlc
()->setParseState
(PS_AttrCompleted
);
713 if
(($1 & ~
(AF_BOUND | AF_READONLY
)) != AF_ATTRIBUTE
) {
714 ErrorHandler
::flagError
(ErrorCode
::BadAttributeFlags
, $1);
716 AstInterface
* scope
= static_cast
< AstInterface
* >(
717 idlc
()->scopes
()->top
());
718 AstAttribute
* attr
= new AstAttribute
(
719 $1, FeDeclarator
::compose
($2), $4->getName
(), scope
);
721 AstInterface
::DoubleMemberDeclarations doubleMembers
(
722 scope
->checkMemberClashes
(attr
));
723 if
(doubleMembers.empty
()) {
724 scope
->addMember
(attr
);
726 reportDoubleMemberDeclarations
(doubleMembers
);
728 idlc
()->scopes
()->push
(attr
);
732 static_cast
< AstAttribute
* >(idlc
()->scopes
()->top
())->setExceptions
(
733 $6.get.documentation
, $6.get.exceptions
, $6.set.documentation
,
735 delete
$6.get.documentation
;
736 delete
$6.get.exceptions
;
737 delete
$6.set.documentation
;
738 delete
$6.set.exceptions
;
739 idlc
()->scopes
()->pop
();
744 '[' opt_attrflags
']'
746 idlc
()->setParseState
(PS_FlagHeaderSeen
);
752 opt_attrflags
',' opt_attrflag
754 if
( ($1 & $3) == $3 )
755 ErrorHandler
::flagError
(ErrorCode
::DefinedAttributeFlag
, $3);
768 idlc
()->setParseState
(PS_AttrSeen
);
773 idlc
()->setParseState
(PS_PropertySeen
);
778 idlc
()->setParseState
(PS_ReadOnlySeen
);
783 idlc
()->setParseState
(PS_OptionalSeen
);
788 idlc
()->setParseState
(PS_MayBeVoidSeen
);
793 idlc
()->setParseState
(PS_BoundSeen
);
798 idlc
()->setParseState
(PS_ConstrainedSeen
);
803 idlc
()->setParseState
(PS_TransientSeen
);
808 idlc
()->setParseState
(PS_MayBeAmbigiousSeen
);
809 $$
= AF_MAYBEAMBIGUOUS
;
813 idlc
()->setParseState
(PS_MayBeDefaultSeen
);
814 $$
= AF_MAYBEDEFAULT
;
818 idlc
()->setParseState
(PS_RemoveableSeen
);
823 yyerror("unknown property|attribute flag");
829 '{' attribute_block_rest
{ $$
= $2; }
832 $$.get.documentation
= nullptr
;
833 $$.get.exceptions
= nullptr
;
834 $$.set.documentation
= nullptr
;
835 $$.set.exceptions
= nullptr
;
839 attribute_block_rest:
840 opt_attribute_raises
'}'
843 yyerror("bad attribute raises block");
845 $$.get.documentation
= nullptr
;
846 $$.get.exceptions
= nullptr
;
847 $$.set.documentation
= nullptr
;
848 $$.set.exceptions
= nullptr
;
852 opt_attribute_raises:
854 opt_attribute_set_raises
859 | attribute_set_raises
860 opt_attribute_get_raises
867 $$.get.documentation
= nullptr
;
868 $$.get.exceptions
= nullptr
;
869 $$.set.documentation
= nullptr
;
870 $$.set.exceptions
= nullptr
;
874 opt_attribute_get_raises:
876 |
/* empty */ { $$.documentation
= nullptr
; $$.exceptions
= nullptr
; }
879 attribute_get_raises:
882 $$.documentation
= new OUString
(
884 idlc
()->getDocumentation
(), RTL_TEXTENCODING_UTF8
));
889 opt_attribute_set_raises:
891 |
/* empty */ { $$.documentation
= nullptr
; $$.exceptions
= nullptr
; }
894 attribute_set_raises:
897 if
(static_cast
< AstAttribute
* >(idlc
()->scopes
()->top
())->
900 ErrorHandler
::error0
(ErrorCode
::ReadOnlyAttributeSetExceptions
);
905 $$.documentation
= new OUString
(
907 idlc
()->getDocumentation
(), RTL_TEXTENCODING_UTF8
));
915 idlc
()->setParseState
(PS_OpTypeSeen
);
919 idlc
()->setParseState
(PS_OpIDSeen
);
922 AstInterface
* pScope
= static_cast
< AstInterface
* >(
923 idlc
()->scopes
()->top
());
924 AstOperation
* pOp
= nullptr
;
927 * Create a node representing an operation on an interface
928 * and add it to its enclosing scope
932 AstType
const *pType
= static_cast
<AstType
const *>($1);
933 if
( !pType ||
(pType
->getNodeType
() == NT_exception
) )
938 pOp
= new AstOperation
(pType
, *$3, pScope
);
940 AstInterface
::DoubleMemberDeclarations doubleMembers
(
941 pScope
->checkMemberClashes
(pOp
));
942 if
(doubleMembers.empty
()) {
943 pScope
->addMember
(pOp
);
945 reportDoubleMemberDeclarations
(doubleMembers
);
951 * Push the operation scope onto the scopes stack
953 idlc
()->scopes
()->push
(pOp
);
957 idlc
()->setParseState
(PS_OpSqSeen
);
961 idlc
()->setParseState
(PS_OpParsCompleted
);
965 idlc
()->setParseState
(PS_OpQsSeen
);
969 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
970 AstOperation
* pOp
= nullptr
;
972 * Add exceptions and context to the operation
974 if
( pScope
&& pScope
->getScopeNodeType
() == NT_operation
)
976 pOp
= static_cast
<AstOperation
*>(pScope
);
979 pOp
->setExceptions
($11);
983 * Done with this operation. Pop its scope from the scopes stack
985 idlc
()->scopes
()->pop
();
993 $$
= idlc
()->scopes
()->bottom
()->lookupPrimitiveType
(ET_void
);
1002 idlc
()->setParseState
(PS_OpParCommaSeen
);
1008 yyerror("parameter definition");
1018 idlc
()->setParseState
(PS_OpParDirSeen
);
1022 idlc
()->setParseState
(PS_OpParTypeSeen
);
1027 idlc
()->setParseState
(PS_OpParDeclSeen
);
1029 AstOperation
* pScope
= static_cast
< AstOperation
* >(
1030 idlc
()->scopes
()->top
());
1031 AstParameter
* pParam
= nullptr
;
1034 * Create a node representing an argument to an operation
1035 * Add it to the enclosing scope (the operation scope)
1037 if
( pScope
&& $5 && $8 )
1039 AstType
const * pType
= FeDeclarator
::compose
($5);
1042 if
(pScope
->isConstructor
() && $2 != DIR_IN
) {
1043 ErrorHandler
::error0
(ErrorCode
::ConstructorParameterNotIn
);
1045 if
(pScope
->isVariadic
()) {
1046 ErrorHandler
::error0
(ErrorCode
::RestParameterNotLast
);
1049 AstDeclaration
const * type
= resolveTypedefs
(pType
);
1050 if
(type
->getNodeType
() != NT_predefined
1051 ||
(static_cast
< AstBaseType
const * >(type
)->
1052 getExprType
() != ET_any
))
1054 ErrorHandler
::error0
(ErrorCode
::RestParameterNotAny
);
1056 if
(pScope
->isConstructor
()) {
1057 if
(pScope
->getIteratorBegin
()
1058 != pScope
->getIteratorEnd
())
1060 ErrorHandler
::error0
(
1061 ErrorCode
::ConstructorRestParameterNotFirst
);
1064 ErrorHandler
::error0
(ErrorCode
::MethodHasRestParameter
);
1068 pParam
= new AstParameter
(
1069 static_cast
< Direction
>($2), $7, pType
, $8->getName
(),
1072 if
( !$8->checkType
($5) )
1077 pScope
->addDeclaration
(pParam
);
1084 idlc
()->setParseState
(PS_NoState
);
1126 idlc
()->setParseState
(PS_RaiseSeen
);
1130 idlc
()->setParseState
(PS_RaiseSqSeen
);
1135 idlc
()->setParseState
(PS_RaiseQsSeen
);
1146 | exception_list
',' exception_name
1156 // The topmost scope is either an AstOperation (for interface methods
1157 // and service constructors) or an AstAttribute (for interface
1158 // attributes), so look up exception names in the next-to-topmost scope:
1159 AstDeclaration
* decl
= idlc
()->scopes
()->nextToTop
()->lookupByName
(
1161 if
(decl
== nullptr
) {
1162 ErrorHandler
::lookupError
(*$1);
1163 } else if
(!ErrorHandler
::checkPublished
(decl
)) {
1165 } else if
(decl
->getNodeType
() != NT_exception
) {
1166 ErrorHandler
::error1
(ErrorCode
::IllegalRaises
, decl
);
1174 interface_inheritance_decl:
1175 optional_inherited_interface
1178 idlc
()->setParseState
(PS_ServiceIFHeadSeen
);
1182 AstInterface
* ifc
= static_cast
< AstInterface
* >(
1183 idlc
()->scopes
()->top
());
1184 if
(ifc
->usesSingleInheritance
()) {
1185 ErrorHandler
::error0
(ErrorCode
::MixedInheritance
);
1187 addInheritedInterface
(
1190 idlc
()->getDocumentation
(), RTL_TEXTENCODING_UTF8
));
1196 optional_inherited_interface:
1197 '[' IDL_OPTIONAL
']' { $$
= true
; }
1198 |
/* EMPTY */ { $$
= false
; }
1202 constants_export constants_exports
1209 idlc
()->setParseState
(PS_ConstSeen
);
1213 idlc
()->setParseState
(PS_ConstTypeSeen
);
1217 idlc
()->setParseState
(PS_ConstIDSeen
);
1218 checkIdentifier
($5);
1222 idlc
()->setParseState
(PS_ConstAssignSeen
);
1226 idlc
()->setParseState
(PS_ConstExprSeen
);
1228 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1229 AstConstant
* pConstant
= nullptr
;
1233 if
( !$9->coerce
($3) )
1235 ErrorHandler
::coercionError
($9, $3);
1238 pConstant
= new AstConstant
($3, $9, *$5, pScope
);
1239 pScope
->addDeclaration
(pConstant
);
1244 idlc
()->setParseState
(PS_ConstantDeclSeen
);
1252 idlc
()->setParseState
(PS_ConstantsSeen
);
1256 idlc
()->setParseState
(PS_ConstantsIDSeen
);
1257 checkIdentifier
($3);
1261 idlc
()->setParseState
(PS_ConstantsSqSeen
);
1263 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1264 AstConstants
* pConstants
= nullptr
;
1268 pConstants
= new AstConstants
(*$3, pScope
);
1269 if
( AstDeclaration
* pExists
= pScope
->lookupForAdd
(pConstants
) )
1271 pExists
->setInMainfile
(idlc
()->isInMainFile
());
1273 pConstants
= static_cast
<AstConstants
*>(pExists
);
1276 pScope
->addDeclaration
(pConstants
);
1278 idlc
()->scopes
()->push
(pConstants
);
1284 idlc
()->setParseState
(PS_ConstantsBodySeen
);
1288 idlc
()->setParseState
(PS_ConstantsQsSeen
);
1290 * Finished with this constants - pop it from the scope stack
1292 idlc
()->scopes
()->pop
();
1296 expression
: const_expr
;
1298 const_expr
: or_expr
;
1302 | or_expr
'|' xor_expr
1304 $$
= new AstExpression
(ExprComb
::Or
, $1, $3);
1310 | xor_expr
'^' and_expr
1312 $$
= new AstExpression
(ExprComb
::Xor
, $1, $3);
1318 | and_expr
'&' shift_expr
1320 $$
= new AstExpression
(ExprComb
::And
, $1, $3);
1326 | shift_expr IDL_LEFTSHIFT add_expr
1328 $$
= new AstExpression
(ExprComb
::Left
, $1, $3);
1330 | shift_expr IDL_RIGHTSHIFT add_expr
1332 $$
= new AstExpression
(ExprComb
::Right
, $1, $3);
1338 | add_expr
'+' mult_expr
1340 $$
= new AstExpression
(ExprComb
::Add
, $1, $3);
1342 | add_expr
'-' mult_expr
1344 $$
= new AstExpression
(ExprComb
::Minus
, $1, $3);
1350 | mult_expr
'*' unary_expr
1352 $$
= new AstExpression
(ExprComb
::Mul
, $1, $3);
1354 | mult_expr
'/' unary_expr
1356 $$
= new AstExpression
(ExprComb
::Div
, $1, $3);
1358 | mult_expr
'%' unary_expr
1360 $$
= new AstExpression
(ExprComb
::Mod
, $1, $3);
1368 $$
= new AstExpression
(ExprComb
::UPlus
, $2, nullptr
);
1372 $$
= new AstExpression
(ExprComb
::UMinus
, $2, nullptr
);
1383 * An expression which is a scoped name is not resolved now,
1384 * but only when it is evaluated (such as when it is assigned
1385 * as a constant value)
1387 $$
= new AstExpression
($1);
1390 |
'(' const_expr
')'
1399 $$
= new AstExpression
($1);
1401 | IDL_INTEGER_ULITERAL
1403 $$
= new AstExpression
($1);
1405 | IDL_FLOATING_PT_LITERAL
1407 $$
= new AstExpression
($1);
1411 $$
= new AstExpression
(sal_Int32
(1), ET_boolean
);
1415 $$
= new AstExpression
(sal_Int32
(0), ET_boolean
);
1426 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1427 AstDeclaration
const * type
= nullptr
;
1430 * If the constant's type is a scoped name, it must resolve
1431 * to a scalar constant type
1433 if
( pScope
&& (type
= pScope
->lookupByName
(*$1)) ) {
1434 if
(!ErrorHandler
::checkPublished
(type
))
1441 type
= resolveTypedefs
(type
);
1442 if
(type
->getNodeType
() == NT_predefined
)
1444 $$
= static_cast
< AstBaseType
const * >(type
)->
1457 idlc
()->setParseState
(PS_ExceptSeen
);
1461 idlc
()->setParseState
(PS_ExceptIDSeen
);
1462 checkIdentifier
($3);
1466 idlc
()->setParseState
(PS_InheritSpecSeen
);
1468 $$
= new FeInheritanceHeader
(NT_exception
, $3, $5, nullptr
);
1476 idlc
()->setParseState
(PS_ExceptHeaderSeen
);
1478 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1479 AstException
* pExcept
= nullptr
;
1483 AstException
* pBase
= static_cast
< AstException
* >(
1485 pExcept
= new AstException
(*$1->getName
(), pBase
, pScope
);
1486 pScope
->addDeclaration
(pExcept
);
1489 * Push the scope of the exception on the scopes stack
1491 idlc
()->scopes
()->push
(pExcept
);
1496 idlc
()->setParseState
(PS_ExceptSqSeen
);
1500 idlc
()->setParseState
(PS_ExceptBodySeen
);
1504 idlc
()->setParseState
(PS_ExceptQsSeen
);
1505 /* this exception is finished, pop its scope from the stack */
1506 idlc
()->scopes
()->pop
();
1514 idlc
()->setParseState
(PS_PropertyTypeSeen
);
1516 at_least_one_declarator
1518 idlc
()->setParseState
(PS_PropertyCompleted
);
1520 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1521 AstAttribute
* pAttr
= nullptr
;
1522 FeDeclList
* pList
= $4;
1523 FeDeclarator
* pDecl
= nullptr
;
1524 AstType
const * pType
= nullptr
;
1526 if
( pScope
->getScopeNodeType
() == NT_singleton
)
1528 ErrorHandler
::error0
(ErrorCode
::IllegalAdd
);
1531 if
( ($1 & AF_ATTRIBUTE
) == AF_ATTRIBUTE
)
1532 ErrorHandler
::flagError
(ErrorCode
::WrongAttributeKeyword
, AF_ATTRIBUTE
);
1534 if
( ($1 & AF_PROPERTY
) != AF_PROPERTY
)
1535 ErrorHandler
::flagError
(ErrorCode
::MissingAttributeKeyword
, AF_PROPERTY
);
1538 * Create nodes representing attributes and add them to the
1541 if
( pScope
&& $2 && pList
)
1543 FeDeclList
::iterator iter
= pList
->begin
();
1544 FeDeclList
::iterator end
= pList
->end
();
1555 pType
= FeDeclarator
::compose
($2);
1563 pAttr
= new AstAttribute
(NT_property
, $1, pType
, pDecl
->getName
(), pScope
);
1565 pScope
->addDeclaration
(pAttr
);
1577 yyerror("property");
1583 service_exports service_export
1588 service_interface_header
1589 at_least_one_scoped_name
1592 idlc
()->setParseState
(PS_ServiceMemberSeen
);
1594 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1595 AstDeclaration
* pDecl
= nullptr
;
1596 AstInterfaceMember
* pIMember
= nullptr
;
1598 if
( pScope
->getScopeNodeType
() == NT_singleton
)
1600 ErrorHandler
::error0
(ErrorCode
::IllegalAdd
);
1604 * Create a node representing a class member.
1605 * Store it in the enclosing scope
1609 for
(auto
const& elem
: *($2))
1611 pDecl
= pScope
->lookupByName
(elem
);
1612 if
( pDecl
&& (pDecl
->getNodeType
() == NT_interface
) )
1614 /* we relax the strict published check and allow to add new
1615 * interfaces if they are optional
1617 bool bOptional
= (($1 & AF_OPTIONAL
) == AF_OPTIONAL
);
1618 if
( ErrorHandler
::checkPublished
(pDecl
, bOptional
) )
1620 pIMember
= new AstInterfaceMember
(
1621 $1, static_cast
<AstInterface
*>(pDecl
), elem
, pScope
);
1622 pScope
->addDeclaration
(pIMember
);
1626 ErrorHandler
::lookupError
(ErrorCode
::InterfaceMemberLookup
, elem
, scopeAsDecl
(pScope
));
1633 | service_service_header
1634 at_least_one_scoped_name
1637 idlc
()->setParseState
(PS_ServiceMemberSeen
);
1639 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1640 AstDeclaration
* pDecl
= nullptr
;
1641 AstServiceMember
* pSMember
= nullptr
;
1644 * Create a node representing a class member.
1645 * Store it in the enclosing scope
1649 for
(auto
const& elem
: *($2))
1651 pDecl
= pScope
->lookupByName
(elem
);
1652 if
( pDecl
&& (pDecl
->getNodeType
() == NT_service
) )
1654 if
( static_cast
< AstService
* >(pDecl
)->isSingleInterfaceBasedService
() ||
(pScope
->getScopeNodeType
() == NT_singleton
&& pScope
->nMembers
() > 0) )
1655 ErrorHandler
::error0
(ErrorCode
::IllegalAdd
);
1656 else if
( ErrorHandler
::checkPublished
(pDecl
) )
1658 pSMember
= new AstServiceMember
(
1659 $1, static_cast
<AstService
*>(pDecl
), elem
, pScope
);
1660 pScope
->addDeclaration
(pSMember
);
1664 ErrorHandler
::lookupError
(ErrorCode
::ServiceMemberLookup
, elem
, scopeAsDecl
(pScope
));
1671 at_least_one_scoped_name
1674 idlc
()->setParseState
(PS_ServiceMemberSeen
);
1676 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1677 AstDeclaration
* pDecl
= nullptr
;
1678 AstObserves
* pObserves
= nullptr
;
1680 if
( pScope
->getScopeNodeType
() == NT_singleton
)
1682 ErrorHandler
::error0
(ErrorCode
::IllegalAdd
);
1686 * Create a node representing a class member.
1687 * Store it in the enclosing scope
1691 for
(auto
const& elem
: *($2))
1693 pDecl
= pScope
->lookupByName
(elem
);
1694 if
( pDecl
&& (pDecl
->getNodeType
() == NT_interface
) )
1696 pObserves
= new AstObserves
(static_cast
<AstInterface
*>(pDecl
), elem
, pScope
);
1697 pScope
->addDeclaration
(pObserves
);
1700 ErrorHandler
::lookupError
(ErrorCode
::InterfaceMemberLookup
, elem
, scopeAsDecl
(pScope
));
1708 at_least_one_scoped_name
1711 idlc
()->setParseState
(PS_ServiceMemberSeen
);
1713 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1714 AstDeclaration
* pDecl
= nullptr
;
1715 AstNeeds
* pNeeds
= nullptr
;
1717 if
( pScope
->getScopeNodeType
() == NT_singleton
)
1719 ErrorHandler
::error0
(ErrorCode
::IllegalAdd
);
1723 * Create a node representing a class member.
1724 * Store it in the enclosing scope
1728 for
(auto
const& elem
: *($2))
1730 pDecl
= pScope
->lookupByName
(elem
);
1731 if
( pDecl
&& (pDecl
->getNodeType
() == NT_service
) )
1733 pNeeds
= new AstNeeds
(static_cast
<AstService
*>(pDecl
), elem
, pScope
);
1734 pScope
->addDeclaration
(pNeeds
);
1737 ErrorHandler
::lookupError
(ErrorCode
::ServiceMemberLookup
, elem
, scopeAsDecl
(pScope
));
1747 idlc
()->setParseState
(PS_PropertyDeclSeen
);
1751 service_interface_header
:
1754 idlc
()->setParseState
(PS_ServiceIFHeadSeen
);
1760 idlc
()->setParseState
(PS_ServiceIFHeadSeen
);
1761 if
( (AF_OPTIONAL
!= $1) && ( AF_INVALID
!= $1) )
1762 ErrorHandler
::flagError
(ErrorCode
::ExpectedOptional
, $1);
1767 service_service_header
:
1770 idlc
()->setParseState
(PS_ServiceSHeadSeen
);
1776 idlc
()->setParseState
(PS_ServiceSHeadSeen
);
1777 if
( (AF_OPTIONAL
!= $1) && ( AF_INVALID
!= $1) )
1778 ErrorHandler
::flagError
(ErrorCode
::ExpectedOptional
, $1);
1786 idlc
()->setParseState
(PS_ServiceSeen
);
1790 idlc
()->setParseState
(PS_ServiceIDSeen
);
1791 checkIdentifier
($3);
1793 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1794 AstService
* pService
= nullptr
;
1797 * Make a new service and add it to the enclosing scope
1799 if
(pScope
!= nullptr
)
1801 pService
= new AstService
(*$3, pScope
);
1802 pScope
->addDeclaration
(pService
);
1806 * Push it on the stack
1808 idlc
()->scopes
()->push
(pService
);
1812 /* this service is finished, pop its scope from the stack */
1813 idlc
()->scopes
()->pop
();
1818 service_interface_dfn
1819 | service_obsolete_dfn
1822 service_interface_dfn:
1825 AstScope
* scope
= idlc
()->scopes
()->nextToTop
();
1826 // skip the scope pushed by service_dcl
1827 AstDeclaration
* decl
= scope
->lookupByName
(*$2);
1829 && resolveTypedefs
(decl
)->getNodeType
() == NT_interface
)
1831 if
(ErrorHandler
::checkPublished
(decl
)) {
1832 idlc
()->scopes
()->top
()->addDeclaration
(decl
);
1835 ErrorHandler
::lookupError
(
1836 ErrorCode
::InterfaceMemberLookup
, *$2, scopeAsDecl
(scope
));
1842 AstService
* s
= static_cast
< AstService
* >(idlc
()->scopes
()->top
());
1844 s
->setSingleInterfaceBasedService
();
1845 s
->setDefaultConstructor
(!$4);
1851 service_body
{ $$
= true
; }
1852 |
/* empty */ { $$
= false
; }
1862 constructors constructor
1869 checkIdentifier
($1);
1870 AstScope
* scope
= idlc
()->scopes
()->top
();
1871 AstOperation
* ctor
= new AstOperation
(nullptr
, *$1, scope
);
1873 scope
->addDeclaration
(ctor
);
1874 idlc
()->scopes
()->push
(ctor
);
1881 static_cast
< AstOperation
* >(idlc
()->scopes
()->top
())->setExceptions
(
1884 idlc
()->scopes
()->pop
();
1885 if
(static_cast
< AstService
* >(idlc
()->scopes
()->top
())->
1886 checkLastConstructor
())
1888 ErrorHandler
::error0
(ErrorCode
::SimilarConstructors
);
1897 idlc
()->setParseState
(PS_SingletonSeen
);
1901 idlc
()->setParseState
(PS_SingletonIDSeen
);
1902 checkIdentifier
($3);
1904 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1905 AstService
* pService
= nullptr
;
1908 * Make a new service and add it to the enclosing scope
1910 if
(pScope
!= nullptr
)
1912 pService
= new AstService
(NT_singleton
, *$3, pScope
);
1913 pScope
->addDeclaration
(pService
);
1917 * Push it on the stack
1919 idlc
()->scopes
()->push
(pService
);
1923 /* this singleton is finished, pop its scope from the stack */
1924 idlc
()->scopes
()->pop
();
1929 singleton_interface_dfn
1930 | service_obsolete_dfn
1933 singleton_interface_dfn:
1936 AstScope
* scope
= idlc
()->scopes
()->nextToTop
();
1937 // skip the scope (needlessly) pushed by singleton_dcl
1938 AstDeclaration
* decl
= scope
->lookupByName
(*$2);
1940 && resolveTypedefs
(decl
)->getNodeType
() == NT_interface
)
1942 if
(ErrorHandler
::checkPublished
(decl
)) {
1943 idlc
()->scopes
()->top
()->addDeclaration
(decl
);
1946 ErrorHandler
::lookupError
(
1947 ErrorCode
::InterfaceMemberLookup
, *$2, scopeAsDecl
(scope
));
1953 service_obsolete_dfn:
1956 idlc
()->setParseState
(
1957 idlc
()->scopes
()->top
()->getScopeNodeType
() == NT_service
1958 ? PS_ServiceSqSeen
: PS_SingletonSqSeen
);
1962 idlc
()->setParseState
(
1963 idlc
()->scopes
()->top
()->getScopeNodeType
() == NT_service
1964 ? PS_ServiceBodySeen
: PS_SingletonBodySeen
);
1968 idlc
()->setParseState
(
1969 idlc
()->scopes
()->top
()->getScopeNodeType
() == NT_service
1970 ? PS_ServiceQsSeen
: PS_SingletonQsSeen
);
1977 idlc
()->setParseState
(PS_TypedefSeen
);
1987 idlc
()->setParseState
(PS_TypeSpecSeen
);
1988 if
($1 != nullptr
&& $1->getNodeType
() == NT_instantiated_struct
) {
1989 ErrorHandler
::error0
(ErrorCode
::InstantiatedStructTypeTypedef
);
1992 at_least_one_declarator
1994 idlc
()->setParseState
(PS_DeclaratorsSeen
);
1996 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
1997 AstTypeDef
* pTypeDef
= nullptr
;
1998 FeDeclList
* pList
= $3;
1999 FeDeclarator
* pDecl
= nullptr
;
2000 AstType
const * pType
= nullptr
;
2003 * Create nodes representing typedefs and add them to the
2006 if
( pScope
&& $1 && pList
)
2008 FeDeclList
::iterator iter
= pList
->begin
();
2009 FeDeclList
::iterator end
= pList
->end
();
2020 pType
= FeDeclarator
::compose
($1);
2028 pTypeDef
= new AstTypeDef
(pType
, pDecl
->getName
(), pScope
);
2030 pScope
->addDeclaration
(pTypeDef
);
2039 at_least_one_declarator
:
2040 declarator declarators
2048 FeDeclList
* pList
= new FeDeclList
;
2049 pList
->push_back
($1);
2059 idlc
()->setParseState
(PS_DeclsCommaSeen
);
2063 idlc
()->setParseState
(PS_DeclsDeclSeen
);
2070 FeDeclList
* pList
= new FeDeclList
;
2071 pList
->push_back
($4);
2084 // For historic reasons, the struct com.sun.star.uno.Uik contains
2085 // members with illegal names (of the form "m_DataN"); avoid useless
2086 // warnings about them:
2087 AstScope
* scope
= idlc
()->scopes
()->top
();
2088 if
(scope
== nullptr || scope
->getScopeNodeType
() != NT_struct
2089 ||
(scopeAsDecl
(scope
)->getScopedName
()
2090 != "com::sun::star::uno::Uik"))
2092 checkIdentifier
($1);
2095 $$
= new FeDeclarator
(*$1);
2100 at_least_one_scoped_name
:
2101 scoped_name scoped_names
2105 $2->push_front
(*$1);
2109 std
::list
< OString
>* pScopedNames
= new std
::list
< OString
>;
2110 // coverity[copy_paste_error : FALSE] - this is not a cut and paste
2111 pScopedNames
->push_back
(*$1);
2122 idlc
()->setParseState
(PS_SNListCommaSeen
);
2126 idlc
()->setParseState
(PS_ScopedNameSeen
);
2133 std
::list
< OString
>* pNames
= new std
::list
< OString
>;
2134 pNames
->push_back
(*$4);
2148 idlc
()->setParseState
(PS_SN_IDSeen
);
2149 checkIdentifier
($1);
2152 | IDL_SCOPESEPARATOR
2154 idlc
()->setParseState
(PS_ScopeDelimSeen
);
2158 checkIdentifier
($3);
2159 OString
* pName
= new OString
("::");
2170 checkIdentifier
($4);
2171 *$1 += OString
("::");
2180 | constructed_type_spec
2185 | scoped_name opt_type_args
2187 $$
= createNamedType
($1, $2);
2194 $$
= idlc
()->scopes
()->bottom
()->lookupPrimitiveType
($1);
2196 | sequence_type_spec
2200 '<' type_args
'>' { $$
= $2; }
2201 |
/* empty */ { $$
= nullptr
; }
2208 $$
->push_back
(const_cast
< AstDeclaration
* >($1)); //TODO: const_cast
2210 | type_args
',' type_arg
2212 $1->push_back
(const_cast
< AstDeclaration
* >($3)); //TODO: const_cast
2220 if
($1 != nullptr
&& static_cast
< AstType
const * >($1)->isUnsigned
()) {
2221 ErrorHandler
::error0
(ErrorCode
::UnsignedTypeArgument
);
2259 IDL_UNSIGNED IDL_LONG
2263 | IDL_UNSIGNED IDL_HYPER
2267 | IDL_UNSIGNED IDL_SHORT
2326 constructed_type_spec
:
2331 sequence_type_spec
:
2334 idlc
()->setParseState
(PS_SequenceSeen
);
2336 * Push a sequence marker on scopes stack
2338 idlc
()->scopes
()->push
(nullptr
);
2342 idlc
()->setParseState
(PS_SequenceSqSeen
);
2346 idlc
()->setParseState
(PS_SequenceTypeSeen
);
2350 idlc
()->setParseState
(PS_SequenceQsSeen
);
2352 * Remove sequence marker from scopes stack
2354 if
(idlc
()->scopes
()->top
() == nullptr
)
2355 idlc
()->scopes
()->pop
();
2357 * Create a node representing a sequence
2359 AstScope
* pScope
= idlc
()->scopes
()->bottom
();
2360 AstDeclaration
* pDecl
= nullptr
;
2361 AstDeclaration
* pSeq
= nullptr
;
2365 AstType
const *pType
= static_cast
<AstType
const *>($5);
2368 pSeq
= new AstSequence
(pType
, pScope
);
2370 * Add this AstSequence to the types defined in the global scope
2372 pDecl
= pScope
->addDeclaration
(pSeq
);
2373 if
( pSeq
!= pDecl
)
2375 // if sequence type already defined then use it
2385 yyerror("sequence declaration");
2394 idlc
()->setParseState
(PS_StructHeaderSeen
);
2396 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
2397 AstStruct
* pStruct
= nullptr
;
2401 AstStruct
const* pBase
= static_cast
< AstStruct
const* >(resolveTypedefs
($1->getInherits
()));
2402 pStruct
= new AstStruct
(
2403 *$1->getName
(), $1->getTypeParameters
(), pBase
, pScope
);
2404 pScope
->addDeclaration
(pStruct
);
2407 * Push the scope of the struct on the scopes stack
2409 idlc
()->scopes
()->push
(pStruct
);
2414 idlc
()->setParseState
(PS_StructSqSeen
);
2418 idlc
()->setParseState
(PS_StructBodySeen
);
2422 idlc
()->setParseState
(PS_StructQsSeen
);
2423 /* this exception is finished, pop its scope from the stack */
2424 idlc
()->scopes
()->pop
();
2431 idlc
()->setParseState
(PS_StructSeen
);
2435 idlc
()->setParseState
(PS_StructIDSeen
);
2436 checkIdentifier
($3);
2441 idlc
()->setParseState
(PS_InheritSpecSeen
);
2443 // Polymorphic struct type templates with base types would cause various
2444 // problems in language bindings, so forbid them here. For example,
2445 // GCC prior to version 3.4 fails with code like
2447 // struct Base { ... };
2448 // template< typename typeparam_T > struct Derived: public Base {
2449 // int member1 CPPU_GCC3_ALIGN(Base);
2452 // (Note that plain struct types with instantiated polymorphic struct
2453 // type bases, which might also cause problems in language bindings, are
2454 // already rejected on a syntactic level.)
2455 if
($5 != nullptr
&& $6 != nullptr
) {
2456 ErrorHandler
::error0
(ErrorCode
::StructTypeTemplateWithBase
);
2459 $$
= new FeInheritanceHeader
(NT_struct
, $3, $6, $5);
2466 '<' type_params
'>' { $$
= $2; }
2467 |
/* empty */ { $$
= nullptr
; }
2473 $$
= new std
::vector
< OString
>;
2477 | type_params
',' identifier
2479 if
(std
::find
($1->begin
(), $1->end
(), *$3) != $1->end
()) {
2480 ErrorHandler
::error0
(ErrorCode
::IdenticalTypeParameters
);
2488 at_least_one_member
: member members
;
2498 idlc
()->setParseState
(PS_MemberTypeSeen
);
2500 at_least_one_declarator
2502 idlc
()->setParseState
(PS_MemberDeclsSeen
);
2506 idlc
()->setParseState
(PS_MemberDeclsCompleted
);
2508 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
2509 AstMember
* pMember
= nullptr
;
2510 FeDeclList
* pList
= $3;
2511 FeDeclarator
* pDecl
= nullptr
;
2512 AstType
const * pType
= nullptr
;
2514 // !!! check recursive type
2516 if
( pScope
&& pList
&& $1 )
2518 FeDeclList
::iterator iter
= pList
->begin
();
2519 FeDeclList
::iterator end
= pList
->end
();
2529 pType
= FeDeclarator
::compose
($1);
2537 pMember
= new AstMember
(pType
, pDecl
->getName
(), pScope
);
2539 if
( !pDecl
->checkType
($1) )
2544 pScope
->addDeclaration
(pMember
);
2553 yyerror("member definition");
2560 | scoped_name opt_type_args
2562 AstDeclaration
const * decl
= nullptr
;
2563 AstStruct
* scope
= static_cast
< AstStruct
* >(idlc
()->scopes
()->top
());
2564 if
(scope
!= nullptr
&& $2 == nullptr
) {
2565 decl
= scope
->findTypeParameter
(*$1);
2567 if
(decl
!= nullptr
) {
2571 decl
= createNamedType
($1, $2);
2572 if
(scope
!= nullptr
&& includes
(decl
, scopeAsDecl
(scope
))) {
2573 ErrorHandler
::error1
(
2574 ErrorCode
::RecursiveType
, scopeAsDecl
(scope
));
2585 idlc
()->setParseState
(PS_EnumSeen
);
2589 idlc
()->setParseState
(PS_EnumIDSeen
);
2590 checkIdentifier
($3);
2592 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
2593 AstEnum
* pEnum
= nullptr
;
2596 * Create a node representing an enum and add it to its
2599 if
(pScope
!= nullptr
)
2601 pEnum
= new AstEnum
(*$3, pScope
);
2603 * Add it to its defining scope
2605 pScope
->addDeclaration
(pEnum
);
2609 * Push the enum scope on the scopes stack
2611 idlc
()->scopes
()->push
(pEnum
);
2616 idlc
()->setParseState
(PS_EnumSqSeen
);
2618 at_least_one_enumerator
2620 idlc
()->setParseState
(PS_EnumBodySeen
);
2624 idlc
()->setParseState
(PS_EnumQsSeen
);
2626 * Done with this enum. Pop its scope from the scopes stack
2628 if
(idlc
()->scopes
()->top
() == nullptr
)
2632 $$
= static_cast
<AstEnum
*>(idlc
()->scopes
()->topNonNull
());
2633 idlc
()->scopes
()->pop
();
2638 at_least_one_enumerator
: enumerator enumerators
;
2644 idlc
()->setParseState
(PS_EnumCommaSeen
);
2650 yyerror("enumerator definition");
2658 checkIdentifier
($1);
2660 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
2661 AstEnum
* pEnum
= nullptr
;
2662 AstConstant
* pEnumVal
= nullptr
;
2664 if
( pScope
&& pScope
->getScopeNodeType
() == NT_enum
)
2666 pEnum
= static_cast
<AstEnum
*>(pScope
);
2669 AstExpression
* pExpr
= new AstExpression
(pEnum
->getEnumValueCount
());
2670 pEnumVal
= new AstConstant
(ET_long
, NT_enum_val
,
2671 pExpr
, *$1, pScope
);
2673 if
( pEnum
->checkValue
(pEnumVal
->getConstValue
()) )
2674 ErrorHandler
::error1
(ErrorCode
::Eval
, pEnum
);
2676 pScope
->addDeclaration
(pEnumVal
);
2684 checkIdentifier
($1);
2686 AstScope
* pScope
= idlc
()->scopes
()->topNonNull
();
2687 AstEnum
* pEnum
= nullptr
;
2688 AstConstant
* pEnumVal
= nullptr
;
2690 if
( $3 && pScope
&& pScope
->getScopeNodeType
() == NT_enum
)
2693 if
( $3->coerce
(ET_long
) )
2695 pEnum
= static_cast
<AstEnum
*>(pScope
);
2698 pEnumVal
= new AstConstant
(ET_long
, NT_enum_val
,
2701 if
( pEnum
->checkValue
(pEnumVal
->getConstValue
()) )
2702 ErrorHandler
::error1
(ErrorCode
::Eval
, pEnum
);
2704 pScope
->addDeclaration
(pEnumVal
);
2707 ErrorHandler
::coercionError
($3, ET_long
);
2717 | IDL_GET
{ $$
= new OString
("get"); }
2718 | IDL_SET
{ $$
= new OString
("set"); }
2719 | IDL_PUBLISHED
{ $$
= new OString
("published"); }
2725 * Report an error situation discovered in a production
2727 void yyerror(char const *errmsg
)
2729 ErrorHandler
::syntaxError
(idlc
()->getParseState
(), idlc
()->getLineNumber
(), errmsg
);
2730 idlc
()->setParseState
(PS_NoState
);
2733 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */