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