1*ff7655f0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ff7655f0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ff7655f0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ff7655f0SAndrew Rist  * distributed with this work for additional information
6*ff7655f0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ff7655f0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ff7655f0SAndrew Rist  * "License"); you may not use this file except in compliance
9*ff7655f0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ff7655f0SAndrew Rist  *
11*ff7655f0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ff7655f0SAndrew Rist  *
13*ff7655f0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ff7655f0SAndrew Rist  * software distributed under the License is distributed on an
15*ff7655f0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ff7655f0SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ff7655f0SAndrew Rist  * specific language governing permissions and limitations
18*ff7655f0SAndrew Rist  * under the License.
19*ff7655f0SAndrew Rist  *
20*ff7655f0SAndrew Rist  *************************************************************/
21*ff7655f0SAndrew Rist 
22*ff7655f0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_codemaker.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "codemaker/dependencies.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "codemaker/typemanager.hxx"
30cdf0e10cSrcweir #include "codemaker/unotype.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "osl/diagnose.h"
33cdf0e10cSrcweir #include "registry/reader.hxx"
34cdf0e10cSrcweir #include "rtl/string.hxx"
35cdf0e10cSrcweir #include "rtl/textcvt.h"
36cdf0e10cSrcweir #include "rtl/textenc.h"
37cdf0e10cSrcweir #include "rtl/ustring.hxx"
38cdf0e10cSrcweir #include "sal/types.h"
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <vector>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using codemaker::Dependencies;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir namespace {
45cdf0e10cSrcweir 
46cdf0e10cSrcweir struct Bad {};
47cdf0e10cSrcweir 
48cdf0e10cSrcweir }
49cdf0e10cSrcweir 
Dependencies(TypeManager const & manager,rtl::OString const & type)50cdf0e10cSrcweir Dependencies::Dependencies(
51cdf0e10cSrcweir     TypeManager const & manager, rtl::OString const & type):
52cdf0e10cSrcweir     m_voidDependency(false), m_booleanDependency(false),
53cdf0e10cSrcweir     m_byteDependency(false), m_shortDependency(false),
54cdf0e10cSrcweir     m_unsignedShortDependency(false), m_longDependency(false),
55cdf0e10cSrcweir     m_unsignedLongDependency(false), m_hyperDependency(false),
56cdf0e10cSrcweir     m_unsignedHyperDependency(false), m_floatDependency(false),
57cdf0e10cSrcweir     m_doubleDependency(false), m_charDependency(false),
58cdf0e10cSrcweir     m_stringDependency(false), m_typeDependency(false), m_anyDependency(false),
59cdf0e10cSrcweir     m_sequenceDependency(false)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     typereg::Reader reader(manager.getTypeReader(type));
62cdf0e10cSrcweir     m_valid = reader.isValid();
63cdf0e10cSrcweir     if (m_valid) {
64cdf0e10cSrcweir         // Not everything is checked for consistency, just things that are cheap
65cdf0e10cSrcweir         // to test:
66cdf0e10cSrcweir         try {
67cdf0e10cSrcweir             RTTypeClass tc = reader.getTypeClass();
68cdf0e10cSrcweir             if (tc != RT_TYPE_SERVICE) {
69cdf0e10cSrcweir                 for (sal_Int16 i = 0; i < reader.getSuperTypeCount(); ++i) {
70cdf0e10cSrcweir                     insert(reader.getSuperTypeName(i), true);
71cdf0e10cSrcweir                 }
72cdf0e10cSrcweir             }
73cdf0e10cSrcweir             if (tc != RT_TYPE_ENUM) {
74cdf0e10cSrcweir                 {for (sal_Int16 i = 0; i < reader.getFieldCount(); ++i) {
75cdf0e10cSrcweir                     if ((reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE)
76cdf0e10cSrcweir                         == 0)
77cdf0e10cSrcweir                     {
78cdf0e10cSrcweir                         insert(reader.getFieldTypeName(i), false);
79cdf0e10cSrcweir                     }
80cdf0e10cSrcweir                 }}
81cdf0e10cSrcweir             }
82cdf0e10cSrcweir             for (sal_Int16 i = 0; i < reader.getMethodCount(); ++i) {
83cdf0e10cSrcweir                 insert(reader.getMethodReturnTypeName(i), false);
84cdf0e10cSrcweir                 for (sal_Int16 j = 0; j < reader.getMethodParameterCount(i);
85cdf0e10cSrcweir                       ++j)
86cdf0e10cSrcweir                 {
87cdf0e10cSrcweir                     if ((reader.getMethodParameterFlags(i, j) & RT_PARAM_REST)
88cdf0e10cSrcweir                         != 0)
89cdf0e10cSrcweir                     {
90cdf0e10cSrcweir                         m_sequenceDependency = true;
91cdf0e10cSrcweir                     }
92cdf0e10cSrcweir                     insert(reader.getMethodParameterTypeName(i, j), false);
93cdf0e10cSrcweir                 }
94cdf0e10cSrcweir                 for (sal_Int16 j = 0; j < reader.getMethodExceptionCount(i);
95cdf0e10cSrcweir                       ++j)
96cdf0e10cSrcweir                 {
97cdf0e10cSrcweir                     insert(reader.getMethodExceptionTypeName(i, j), false);
98cdf0e10cSrcweir                 }
99cdf0e10cSrcweir             }
100cdf0e10cSrcweir             for (sal_Int16 i = 0; i < reader.getReferenceCount(); ++i) {
101cdf0e10cSrcweir                 if (reader.getReferenceSort(i) != RT_REF_TYPE_PARAMETER) {
102cdf0e10cSrcweir                     insert(reader.getReferenceTypeName(i), false);
103cdf0e10cSrcweir                 }
104cdf0e10cSrcweir             }
105cdf0e10cSrcweir         } catch (Bad &) {
106cdf0e10cSrcweir             m_map.clear();
107cdf0e10cSrcweir             m_valid = false;
108cdf0e10cSrcweir             m_voidDependency = false;
109cdf0e10cSrcweir             m_booleanDependency = false;
110cdf0e10cSrcweir             m_byteDependency = false;
111cdf0e10cSrcweir             m_shortDependency = false;
112cdf0e10cSrcweir             m_unsignedShortDependency = false;
113cdf0e10cSrcweir             m_longDependency = false;
114cdf0e10cSrcweir             m_unsignedLongDependency = false;
115cdf0e10cSrcweir             m_hyperDependency = false;
116cdf0e10cSrcweir             m_unsignedHyperDependency = false;
117cdf0e10cSrcweir             m_floatDependency = false;
118cdf0e10cSrcweir             m_doubleDependency = false;
119cdf0e10cSrcweir             m_charDependency = false;
120cdf0e10cSrcweir             m_stringDependency = false;
121cdf0e10cSrcweir             m_typeDependency = false;
122cdf0e10cSrcweir             m_anyDependency = false;
123cdf0e10cSrcweir             m_sequenceDependency = false;
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
~Dependencies()128cdf0e10cSrcweir Dependencies::~Dependencies()
129cdf0e10cSrcweir {}
130cdf0e10cSrcweir 
insert(rtl::OUString const & type,bool base)131cdf0e10cSrcweir void Dependencies::insert(rtl::OUString const & type, bool base) {
132cdf0e10cSrcweir     rtl::OString t;
133cdf0e10cSrcweir     if (!type.convertToString(
134cdf0e10cSrcweir             &t, RTL_TEXTENCODING_UTF8,
135cdf0e10cSrcweir             (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
136cdf0e10cSrcweir              | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
137cdf0e10cSrcweir     {
138cdf0e10cSrcweir         throw Bad();
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir     insert(t, base);
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
insert(rtl::OString const & type,bool base)143cdf0e10cSrcweir void Dependencies::insert(rtl::OString const & type, bool base) {
144cdf0e10cSrcweir     sal_Int32 rank;
145cdf0e10cSrcweir     std::vector< rtl::OString > args;
146cdf0e10cSrcweir     rtl::OString t(UnoType::decompose(type, &rank, &args));
147cdf0e10cSrcweir     if (rank > 0) {
148cdf0e10cSrcweir         m_sequenceDependency = true;
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir     switch (UnoType::getSort(t)) {
151cdf0e10cSrcweir     case UnoType::SORT_VOID:
152cdf0e10cSrcweir         if (rank != 0 || !args.empty()) {
153cdf0e10cSrcweir             throw Bad();
154cdf0e10cSrcweir         }
155cdf0e10cSrcweir         m_voidDependency = true;
156cdf0e10cSrcweir         break;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     case UnoType::SORT_BOOLEAN:
159cdf0e10cSrcweir         if (!args.empty()) {
160cdf0e10cSrcweir             throw Bad();
161cdf0e10cSrcweir         }
162cdf0e10cSrcweir         m_booleanDependency = true;
163cdf0e10cSrcweir         break;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     case UnoType::SORT_BYTE:
166cdf0e10cSrcweir         if (!args.empty()) {
167cdf0e10cSrcweir             throw Bad();
168cdf0e10cSrcweir         }
169cdf0e10cSrcweir         m_byteDependency = true;
170cdf0e10cSrcweir         break;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     case UnoType::SORT_SHORT:
173cdf0e10cSrcweir         if (!args.empty()) {
174cdf0e10cSrcweir             throw Bad();
175cdf0e10cSrcweir         }
176cdf0e10cSrcweir         m_shortDependency = true;
177cdf0e10cSrcweir         break;
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     case UnoType::SORT_UNSIGNED_SHORT:
180cdf0e10cSrcweir         if (!args.empty()) {
181cdf0e10cSrcweir             throw Bad();
182cdf0e10cSrcweir         }
183cdf0e10cSrcweir         m_unsignedShortDependency = true;
184cdf0e10cSrcweir         break;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     case UnoType::SORT_LONG:
187cdf0e10cSrcweir         if (!args.empty()) {
188cdf0e10cSrcweir             throw Bad();
189cdf0e10cSrcweir         }
190cdf0e10cSrcweir         m_longDependency = true;
191cdf0e10cSrcweir         break;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     case UnoType::SORT_UNSIGNED_LONG:
194cdf0e10cSrcweir         if (!args.empty()) {
195cdf0e10cSrcweir             throw Bad();
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir         m_unsignedLongDependency = true;
198cdf0e10cSrcweir         break;
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     case UnoType::SORT_HYPER:
201cdf0e10cSrcweir         if (!args.empty()) {
202cdf0e10cSrcweir             throw Bad();
203cdf0e10cSrcweir         }
204cdf0e10cSrcweir         m_hyperDependency = true;
205cdf0e10cSrcweir         break;
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     case UnoType::SORT_UNSIGNED_HYPER:
208cdf0e10cSrcweir         if (!args.empty()) {
209cdf0e10cSrcweir             throw Bad();
210cdf0e10cSrcweir         }
211cdf0e10cSrcweir         m_unsignedHyperDependency = true;
212cdf0e10cSrcweir         break;
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     case UnoType::SORT_FLOAT:
215cdf0e10cSrcweir         if (!args.empty()) {
216cdf0e10cSrcweir             throw Bad();
217cdf0e10cSrcweir         }
218cdf0e10cSrcweir         m_floatDependency = true;
219cdf0e10cSrcweir         break;
220cdf0e10cSrcweir 
221cdf0e10cSrcweir     case UnoType::SORT_DOUBLE:
222cdf0e10cSrcweir         if (!args.empty()) {
223cdf0e10cSrcweir             throw Bad();
224cdf0e10cSrcweir         }
225cdf0e10cSrcweir         m_doubleDependency = true;
226cdf0e10cSrcweir         break;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir     case UnoType::SORT_CHAR:
229cdf0e10cSrcweir         if (!args.empty()) {
230cdf0e10cSrcweir             throw Bad();
231cdf0e10cSrcweir         }
232cdf0e10cSrcweir         m_charDependency = true;
233cdf0e10cSrcweir         break;
234cdf0e10cSrcweir 
235cdf0e10cSrcweir     case UnoType::SORT_STRING:
236cdf0e10cSrcweir         if (!args.empty()) {
237cdf0e10cSrcweir             throw Bad();
238cdf0e10cSrcweir         }
239cdf0e10cSrcweir         m_stringDependency = true;
240cdf0e10cSrcweir         break;
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     case UnoType::SORT_TYPE:
243cdf0e10cSrcweir         if (!args.empty()) {
244cdf0e10cSrcweir             throw Bad();
245cdf0e10cSrcweir         }
246cdf0e10cSrcweir         m_typeDependency = true;
247cdf0e10cSrcweir         break;
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     case UnoType::SORT_ANY:
250cdf0e10cSrcweir         if (!args.empty()) {
251cdf0e10cSrcweir             throw Bad();
252cdf0e10cSrcweir         }
253cdf0e10cSrcweir         m_anyDependency = true;
254cdf0e10cSrcweir         break;
255cdf0e10cSrcweir 
256cdf0e10cSrcweir     case UnoType::SORT_COMPLEX:
257cdf0e10cSrcweir         {
258cdf0e10cSrcweir             {for (std::vector< rtl::OString >::iterator i(args.begin());
259cdf0e10cSrcweir                   i != args.end(); ++i)
260cdf0e10cSrcweir             {
261cdf0e10cSrcweir                 insert(*i, false);
262cdf0e10cSrcweir             }}
263cdf0e10cSrcweir             Map::iterator i(m_map.find(t));
264cdf0e10cSrcweir             if (i == m_map.end()) {
265cdf0e10cSrcweir                 m_map.insert(
266cdf0e10cSrcweir                     Map::value_type(t, base ? KIND_BASE : KIND_NO_BASE));
267cdf0e10cSrcweir             } else if (base) {
268cdf0e10cSrcweir                 i->second = KIND_BASE;
269cdf0e10cSrcweir             }
270cdf0e10cSrcweir             break;
271cdf0e10cSrcweir         }
272cdf0e10cSrcweir 
273cdf0e10cSrcweir     default:
274cdf0e10cSrcweir         OSL_ASSERT(false);
275cdf0e10cSrcweir         break;
276cdf0e10cSrcweir     }
277cdf0e10cSrcweir }
278