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 152 : void AstOperation::setExceptions(DeclList const * pExceptions)
29 : {
30 152 : if (pExceptions != 0) {
31 16 : m_exceptions = *pExceptions;
32 : }
33 152 : }
34 :
35 98 : bool AstOperation::isVariadic() const {
36 98 : DeclList::const_iterator i(getIteratorEnd());
37 392 : return i != getIteratorBegin()
38 392 : && static_cast< AstParameter const * >(*(--i))->isRest();
39 : }
40 :
41 74 : bool AstOperation::dumpBlob(typereg::Writer & rBlob, sal_uInt16 index)
42 : {
43 74 : sal_uInt16 nParam = getNodeCount(NT_parameter);
44 74 : sal_uInt16 nExcep = nExceptions();
45 74 : RTMethodMode methodMode = RT_MODE_TWOWAY;
46 :
47 74 : OUString returnTypeName;
48 74 : if (m_pReturnType == 0) {
49 36 : returnTypeName = "void";
50 : } else {
51 76 : returnTypeName = OStringToOUString(
52 76 : m_pReturnType->getRelativName(), RTL_TEXTENCODING_UTF8);
53 : }
54 : rBlob.setMethodData(
55 74 : index, getDocumentation(), methodMode,
56 74 : OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8),
57 222 : returnTypeName, nParam, nExcep);
58 :
59 74 : if ( nParam )
60 : {
61 34 : DeclList::const_iterator iter = getIteratorBegin();
62 34 : DeclList::const_iterator end = getIteratorEnd();
63 34 : AstDeclaration* pDecl = NULL;
64 : RTParamMode paramMode;
65 34 : sal_uInt16 paramIndex = 0;
66 110 : while ( iter != end )
67 : {
68 42 : pDecl = *iter;
69 42 : if ( pDecl->getNodeType() == NT_parameter )
70 : {
71 42 : AstParameter* pParam = static_cast<AstParameter*>(pDecl);
72 42 : switch (pParam->getDirection())
73 : {
74 : case DIR_IN :
75 42 : paramMode = RT_PARAM_IN;
76 42 : break;
77 : case DIR_OUT :
78 0 : paramMode = RT_PARAM_OUT;
79 0 : break;
80 : case DIR_INOUT :
81 0 : paramMode = RT_PARAM_INOUT;
82 0 : break;
83 : default:
84 0 : paramMode = RT_PARAM_INVALID;
85 0 : break;
86 : }
87 42 : if (pParam->isRest()) {
88 : paramMode = static_cast< RTParamMode >(
89 8 : paramMode | RT_PARAM_REST);
90 : }
91 :
92 : rBlob.setMethodParameterData(
93 : index, paramIndex++, paramMode,
94 : OStringToOUString(
95 42 : pDecl->getLocalName(), RTL_TEXTENCODING_UTF8),
96 : OStringToOUString(
97 42 : pParam->getType()->getRelativName(),
98 84 : RTL_TEXTENCODING_UTF8));
99 : }
100 42 : ++iter;
101 : }
102 : }
103 :
104 74 : if ( nExcep )
105 : {
106 12 : DeclList::iterator iter = m_exceptions.begin();
107 12 : DeclList::iterator end = m_exceptions.end();
108 12 : sal_uInt16 exceptIndex = 0;
109 36 : while ( iter != end )
110 : {
111 : rBlob.setMethodExceptionTypeName(
112 : index, exceptIndex++,
113 : OStringToOUString(
114 12 : (*iter)->getRelativName(), RTL_TEXTENCODING_UTF8));
115 12 : ++iter;
116 : }
117 : }
118 :
119 74 : return true;
120 : }
121 :
122 738 : AstDeclaration* AstOperation::addDeclaration(AstDeclaration* pDecl)
123 : {
124 738 : return AstScope::addDeclaration(pDecl);
125 : }
126 :
127 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|