1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_idlc.hxx" 26 #include <idlc/astoperation.hxx> 27 #include <idlc/asttype.hxx> 28 #include <idlc/astbasetype.hxx> 29 #include <idlc/astparameter.hxx> 30 #include <idlc/errorhandler.hxx> 31 32 #include "registry/writer.hxx" 33 34 using namespace ::rtl; 35 36 void AstOperation::setExceptions(DeclList const * pExceptions) 37 { 38 if (pExceptions != 0) { 39 if (isOneway()) { 40 idlc()->error()->error1(EIDL_ONEWAY_RAISE_CONFLICT, this); 41 } 42 m_exceptions = *pExceptions; 43 } 44 } 45 46 bool AstOperation::isVariadic() const { 47 DeclList::const_iterator i(getIteratorEnd()); 48 return i != getIteratorBegin() 49 && static_cast< AstParameter const * >(*(--i))->isRest(); 50 } 51 52 sal_Bool AstOperation::dumpBlob(typereg::Writer & rBlob, sal_uInt16 index) 53 { 54 sal_uInt16 nParam = getNodeCount(NT_parameter); 55 sal_uInt16 nExcep = nExceptions(); 56 RTMethodMode methodMode = RT_MODE_TWOWAY; 57 58 if ( isOneway() ) 59 methodMode = RT_MODE_ONEWAY; 60 61 rtl::OUString returnTypeName; 62 if (m_pReturnType == 0) { 63 returnTypeName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("void")); 64 } else { 65 returnTypeName = rtl::OStringToOUString( 66 m_pReturnType->getRelativName(), RTL_TEXTENCODING_UTF8); 67 } 68 rBlob.setMethodData( 69 index, getDocumentation(), methodMode, 70 OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8), 71 returnTypeName, nParam, nExcep); 72 73 if ( nParam ) 74 { 75 DeclList::const_iterator iter = getIteratorBegin(); 76 DeclList::const_iterator end = getIteratorEnd(); 77 AstDeclaration* pDecl = NULL; 78 RTParamMode paramMode; 79 sal_uInt16 paramIndex = 0; 80 while ( iter != end ) 81 { 82 pDecl = *iter; 83 if ( pDecl->getNodeType() == NT_parameter ) 84 { 85 AstParameter* pParam = (AstParameter*)pDecl; 86 switch (pParam->getDirection()) 87 { 88 case DIR_IN : 89 paramMode = RT_PARAM_IN; 90 break; 91 case DIR_OUT : 92 paramMode = RT_PARAM_OUT; 93 break; 94 case DIR_INOUT : 95 paramMode = RT_PARAM_INOUT; 96 break; 97 default: 98 paramMode = RT_PARAM_INVALID; 99 break; 100 } 101 if (pParam->isRest()) { 102 paramMode = static_cast< RTParamMode >( 103 paramMode | RT_PARAM_REST); 104 } 105 106 rBlob.setMethodParameterData( 107 index, paramIndex++, paramMode, 108 OStringToOUString( 109 pDecl->getLocalName(), RTL_TEXTENCODING_UTF8), 110 OStringToOUString( 111 pParam->getType()->getRelativName(), 112 RTL_TEXTENCODING_UTF8)); 113 } 114 ++iter; 115 } 116 } 117 118 if ( nExcep ) 119 { 120 DeclList::iterator iter = m_exceptions.begin(); 121 DeclList::iterator end = m_exceptions.end(); 122 sal_uInt16 exceptIndex = 0; 123 while ( iter != end ) 124 { 125 rBlob.setMethodExceptionTypeName( 126 index, exceptIndex++, 127 OStringToOUString( 128 (*iter)->getRelativName(), RTL_TEXTENCODING_UTF8)); 129 ++iter; 130 } 131 } 132 133 return sal_True; 134 } 135 136 AstDeclaration* AstOperation::addDeclaration(AstDeclaration* pDecl) 137 { 138 if ( pDecl->getNodeType() == NT_parameter ) 139 { 140 AstParameter* pParam = (AstParameter*)pDecl; 141 if ( isOneway() && 142 (pParam->getDirection() == DIR_OUT || pParam->getDirection() == DIR_INOUT) ) 143 { 144 idlc()->error()->error2(EIDL_ONEWAY_CONFLICT, pDecl, this); 145 return NULL; 146 } 147 } 148 return AstScope::addDeclaration(pDecl); 149 } 150