update dev300-m58
[ooovba.git] / idlc / source / astoperation.cxx
blob3fa6f68f370f56adff6aeeba0e36fa79ac329dc4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: astoperation.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_idlc.hxx"
33 #include <idlc/astoperation.hxx>
34 #include <idlc/asttype.hxx>
35 #include <idlc/astbasetype.hxx>
36 #include <idlc/astparameter.hxx>
37 #include <idlc/errorhandler.hxx>
39 #include "registry/writer.hxx"
41 using namespace ::rtl;
43 void AstOperation::setExceptions(DeclList const * pExceptions)
45 if (pExceptions != 0) {
46 if (isOneway()) {
47 idlc()->error()->error1(EIDL_ONEWAY_RAISE_CONFLICT, this);
49 m_exceptions = *pExceptions;
53 bool AstOperation::isVariadic() const {
54 DeclList::const_iterator i(getIteratorEnd());
55 return i != getIteratorBegin()
56 && static_cast< AstParameter const * >(*(--i))->isRest();
59 sal_Bool AstOperation::dumpBlob(typereg::Writer & rBlob, sal_uInt16 index)
61 sal_uInt16 nParam = getNodeCount(NT_parameter);
62 sal_uInt16 nExcep = nExceptions();
63 RTMethodMode methodMode = RT_MODE_TWOWAY;
65 if ( isOneway() )
66 methodMode = RT_MODE_ONEWAY;
68 rtl::OUString returnTypeName;
69 if (m_pReturnType == 0) {
70 returnTypeName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("void"));
71 } else {
72 returnTypeName = rtl::OStringToOUString(
73 m_pReturnType->getRelativName(), RTL_TEXTENCODING_UTF8);
75 rBlob.setMethodData(
76 index, getDocumentation(), methodMode,
77 OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8),
78 returnTypeName, nParam, nExcep);
80 if ( nParam )
82 DeclList::const_iterator iter = getIteratorBegin();
83 DeclList::const_iterator end = getIteratorEnd();
84 AstDeclaration* pDecl = NULL;
85 RTParamMode paramMode;
86 sal_uInt16 paramIndex = 0;
87 while ( iter != end )
89 pDecl = *iter;
90 if ( pDecl->getNodeType() == NT_parameter )
92 AstParameter* pParam = (AstParameter*)pDecl;
93 switch (pParam->getDirection())
95 case DIR_IN :
96 paramMode = RT_PARAM_IN;
97 break;
98 case DIR_OUT :
99 paramMode = RT_PARAM_OUT;
100 break;
101 case DIR_INOUT :
102 paramMode = RT_PARAM_INOUT;
103 break;
104 default:
105 paramMode = RT_PARAM_INVALID;
106 break;
108 if (pParam->isRest()) {
109 paramMode = static_cast< RTParamMode >(
110 paramMode | RT_PARAM_REST);
113 rBlob.setMethodParameterData(
114 index, paramIndex++, paramMode,
115 OStringToOUString(
116 pDecl->getLocalName(), RTL_TEXTENCODING_UTF8),
117 OStringToOUString(
118 pParam->getType()->getRelativName(),
119 RTL_TEXTENCODING_UTF8));
121 ++iter;
125 if ( nExcep )
127 DeclList::iterator iter = m_exceptions.begin();
128 DeclList::iterator end = m_exceptions.end();
129 sal_uInt16 exceptIndex = 0;
130 while ( iter != end )
132 rBlob.setMethodExceptionTypeName(
133 index, exceptIndex++,
134 OStringToOUString(
135 (*iter)->getRelativName(), RTL_TEXTENCODING_UTF8));
136 ++iter;
140 return sal_True;
143 AstDeclaration* AstOperation::addDeclaration(AstDeclaration* pDecl)
145 if ( pDecl->getNodeType() == NT_parameter )
147 AstParameter* pParam = (AstParameter*)pDecl;
148 if ( isOneway() &&
149 (pParam->getDirection() == DIR_OUT || pParam->getDirection() == DIR_INOUT) )
151 idlc()->error()->error2(EIDL_ONEWAY_CONFLICT, pDecl, this);
152 return NULL;
155 return AstScope::addDeclaration(pDecl);