Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <idlc/astoperation.hxx>
21 : #include <idlc/asttype.hxx>
22 : #include <idlc/astbasetype.hxx>
23 : #include <idlc/astparameter.hxx>
24 : #include <idlc/errorhandler.hxx>
25 :
26 : #include "registry/writer.hxx"
27 :
28 : using namespace ::rtl;
29 :
30 76 : void AstOperation::setExceptions(DeclList const * pExceptions)
31 : {
32 76 : if (pExceptions != 0) {
33 8 : m_exceptions = *pExceptions;
34 : }
35 76 : }
36 :
37 49 : bool AstOperation::isVariadic() const {
38 49 : DeclList::const_iterator i(getIteratorEnd());
39 196 : return i != getIteratorBegin()
40 196 : && static_cast< AstParameter const * >(*(--i))->isRest();
41 : }
42 :
43 37 : bool AstOperation::dumpBlob(typereg::Writer & rBlob, sal_uInt16 index)
44 : {
45 37 : sal_uInt16 nParam = getNodeCount(NT_parameter);
46 37 : sal_uInt16 nExcep = nExceptions();
47 37 : RTMethodMode methodMode = RT_MODE_TWOWAY;
48 :
49 37 : OUString returnTypeName;
50 37 : if (m_pReturnType == 0) {
51 18 : returnTypeName = "void";
52 : } else {
53 38 : returnTypeName = OStringToOUString(
54 38 : m_pReturnType->getRelativName(), RTL_TEXTENCODING_UTF8);
55 : }
56 : rBlob.setMethodData(
57 37 : index, getDocumentation(), methodMode,
58 37 : OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8),
59 111 : returnTypeName, nParam, nExcep);
60 :
61 37 : if ( nParam )
62 : {
63 17 : DeclList::const_iterator iter = getIteratorBegin();
64 17 : DeclList::const_iterator end = getIteratorEnd();
65 17 : AstDeclaration* pDecl = NULL;
66 : RTParamMode paramMode;
67 17 : sal_uInt16 paramIndex = 0;
68 55 : while ( iter != end )
69 : {
70 21 : pDecl = *iter;
71 21 : if ( pDecl->getNodeType() == NT_parameter )
72 : {
73 21 : AstParameter* pParam = (AstParameter*)pDecl;
74 21 : switch (pParam->getDirection())
75 : {
76 : case DIR_IN :
77 21 : paramMode = RT_PARAM_IN;
78 21 : break;
79 : case DIR_OUT :
80 0 : paramMode = RT_PARAM_OUT;
81 0 : break;
82 : case DIR_INOUT :
83 0 : paramMode = RT_PARAM_INOUT;
84 0 : break;
85 : default:
86 0 : paramMode = RT_PARAM_INVALID;
87 0 : break;
88 : }
89 21 : if (pParam->isRest()) {
90 : paramMode = static_cast< RTParamMode >(
91 4 : paramMode | RT_PARAM_REST);
92 : }
93 :
94 : rBlob.setMethodParameterData(
95 : index, paramIndex++, paramMode,
96 : OStringToOUString(
97 21 : pDecl->getLocalName(), RTL_TEXTENCODING_UTF8),
98 : OStringToOUString(
99 21 : pParam->getType()->getRelativName(),
100 42 : RTL_TEXTENCODING_UTF8));
101 : }
102 21 : ++iter;
103 : }
104 : }
105 :
106 37 : if ( nExcep )
107 : {
108 6 : DeclList::iterator iter = m_exceptions.begin();
109 6 : DeclList::iterator end = m_exceptions.end();
110 6 : sal_uInt16 exceptIndex = 0;
111 18 : while ( iter != end )
112 : {
113 : rBlob.setMethodExceptionTypeName(
114 : index, exceptIndex++,
115 : OStringToOUString(
116 6 : (*iter)->getRelativName(), RTL_TEXTENCODING_UTF8));
117 6 : ++iter;
118 : }
119 : }
120 :
121 37 : return true;
122 : }
123 :
124 369 : AstDeclaration* AstOperation::addDeclaration(AstDeclaration* pDecl)
125 : {
126 369 : return AstScope::addDeclaration(pDecl);
127 : }
128 :
129 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|