Branch data 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 <osl/interlck.h>
21 : : #include <rtl/alloc.h>
22 : : #include <codemaker/dependency.hxx>
23 : :
24 : : using ::rtl::OString;
25 : : using ::rtl::OStringBuffer;
26 : 2 : TypeDependency::TypeDependency()
27 : : {
28 [ + - ]: 2 : m_pImpl = new TypeDependencyImpl();
29 : 2 : acquire();
30 : 2 : }
31 : :
32 : 2 : TypeDependency::~TypeDependency()
33 : : {
34 : 2 : release();
35 : 2 : }
36 : :
37 : 2 : void TypeDependency::acquire()
38 : : {
39 : 2 : osl_incrementInterlockedCount(&m_pImpl->m_refCount);
40 : 2 : }
41 : :
42 : 2 : void TypeDependency::release()
43 : : {
44 [ + - ]: 2 : if (0 == osl_decrementInterlockedCount(&m_pImpl->m_refCount))
45 : : {
46 [ + - ]: 2 : delete m_pImpl;
47 : : }
48 : 2 : }
49 : :
50 : 1996 : sal_Bool TypeDependency::insert(const OString& type, const OString& depend, sal_uInt16 use)
51 : : {
52 : 1996 : sal_Bool ret = sal_False;
53 : :
54 [ + - ][ + - ]: 1996 : if (!type.isEmpty() && !depend.isEmpty())
[ + - ]
55 : : {
56 [ + + ]: 1996 : if (m_pImpl->m_dependencies.count(type) > 0)
57 : : {
58 : 1802 : TypeUsing typeUsing(depend, use);
59 : 1802 : TypeUsingSet::iterator iter;
60 [ + - ][ + - ]: 1802 : if ((iter = m_pImpl->m_dependencies[type].find(typeUsing)) != m_pImpl->m_dependencies[type].end())
[ + + ][ + - ]
61 : : {
62 : 368 : (((TypeUsing *) &(*iter))->m_use) = (*iter).m_use | use;
63 : : } else
64 : : {
65 [ + - ][ + - ]: 1434 : m_pImpl->m_dependencies[type].insert(typeUsing);
66 : 1802 : }
67 : : } else
68 : : {
69 : 194 : TypeUsing typeUsing(depend, use);
70 [ + - ]: 194 : TypeUsingSet tmpSet;
71 [ + - ]: 194 : tmpSet.insert(typeUsing);
72 [ + - ][ + - ]: 194 : m_pImpl->m_dependencies[type]=tmpSet;
73 : : }
74 : : }
75 : :
76 : 1996 : return ret;
77 : : }
78 : :
79 : 222 : TypeUsingSet TypeDependency::getDependencies(const OString& type)
80 : : {
81 [ + - ]: 222 : if (!type.isEmpty())
82 : : {
83 [ + + ]: 222 : if (m_pImpl->m_dependencies.count(type) > 0)
84 : : {
85 : 194 : return m_pImpl->m_dependencies[type];
86 : : }
87 : : }
88 : :
89 : 222 : return TypeUsingSet();
90 : : }
91 : :
92 : 824 : sal_Bool TypeDependency::hasDependencies(const OString& type)
93 : : {
94 [ + - ]: 824 : if (!type.isEmpty())
95 : : {
96 [ + + ]: 824 : if (m_pImpl->m_dependencies.count(type) > 0)
97 : : {
98 : 602 : return sal_True;
99 : : }
100 : : }
101 : :
102 : 824 : return sal_False;
103 : : }
104 : :
105 : 222 : void TypeDependency::setGenerated(const OString& type, sal_uInt16 genFlag)
106 : : {
107 [ - + ]: 222 : if (m_pImpl->m_generatedTypes.count(type) > 0)
108 : 0 : m_pImpl->m_generatedTypes[type]= m_pImpl->m_generatedTypes[type] | genFlag;
109 : : else
110 : 222 : m_pImpl->m_generatedTypes[type]=genFlag;
111 : 222 : }
112 : :
113 : 1510 : sal_Bool TypeDependency::isGenerated(const OString& type, sal_uInt16 genFlag)
114 : : {
115 [ + + + - ]: 2798 : if (m_pImpl->m_generatedTypes.count(type) > 0 &&
[ + + ]
116 : 1288 : m_pImpl->m_generatedTypes[type] & genFlag)
117 : : {
118 : 1288 : return sal_True;
119 : : }
120 : :
121 : 1510 : return sal_False;
122 : : }
123 : :
124 : 222 : static sal_Bool checkFieldDependencies(TypeManager& typeMgr, TypeDependency& dependencies,
125 : : TypeReader& reader, const OString& type)
126 : : {
127 : 222 : sal_uInt32 count = reader.getFieldCount();
128 : :
129 [ + + ][ + + ]: 222 : if (count == 0 || reader.getTypeClass() == RT_TYPE_ENUM)
[ + + ]
130 : 194 : return sal_True;
131 : :
132 [ + + ]: 102 : for (sal_uInt16 i=0; i < count; i++)
133 : : {
134 [ + - ]: 74 : const OString fieldType = reader.getFieldType(i);
135 : 74 : const bool bIsTypeParam(reader.getFieldAccess(i) & RT_ACCESS_PARAMETERIZED_TYPE);
136 : :
137 [ + - ][ + - ]: 74 : if (!fieldType.isEmpty() && !bIsTypeParam)
[ + - ]
138 : : {
139 [ + - ]: 74 : dependencies.insert(type, fieldType, TYPEUSE_MEMBER);
140 [ + - ]: 74 : checkTypeDependencies(typeMgr, dependencies, fieldType);
141 : : }
142 : 74 : }
143 : :
144 : 222 : return sal_True;
145 : : }
146 : :
147 : 194 : static sal_Bool checkMethodDependencies(TypeManager& typeMgr, TypeDependency& dependencies,
148 : : TypeReader& reader, const OString& type)
149 : : {
150 : 194 : sal_uInt32 count = reader.getMethodCount();
151 : :
152 [ + + ]: 194 : if (count == 0)
153 : 64 : return sal_True;
154 : :
155 : 130 : OString returnType, paramType, excType;
156 : 130 : sal_uInt32 paramCount = 0;
157 : 130 : sal_uInt32 excCount = 0;
158 : 130 : RTParamMode paramMode = RT_PARAM_INVALID;
159 [ + + ]: 484 : for (sal_uInt16 i=0; i < count; i++)
160 : : {
161 [ + - ]: 354 : returnType = reader.getMethodReturnType(i);
162 : :
163 [ + - ]: 354 : dependencies.insert(type, returnType, TYPEUSE_RETURN);
164 [ + - ]: 354 : checkTypeDependencies(typeMgr, dependencies, returnType);
165 : :
166 : 354 : paramCount = reader.getMethodParamCount(i);
167 : 354 : excCount = reader.getMethodExcCount(i);
168 : :
169 : : sal_uInt16 j;
170 [ + + ]: 548 : for (j=0; j < paramCount; j++)
171 : : {
172 [ + - ]: 194 : paramType = reader.getMethodParamType(i, j);
173 : 194 : paramMode = reader.getMethodParamMode(i, j);
174 : :
175 [ + - - - ]: 194 : switch (paramMode)
176 : : {
177 : : case RT_PARAM_IN:
178 [ + - ]: 194 : dependencies.insert(type, paramType, TYPEUSE_INPARAM);
179 : 194 : break;
180 : : case RT_PARAM_OUT:
181 [ # # ]: 0 : dependencies.insert(type, paramType, TYPEUSE_OUTPARAM);
182 : 0 : break;
183 : : case RT_PARAM_INOUT:
184 [ # # ]: 0 : dependencies.insert(type, paramType, TYPEUSE_INOUTPARAM);
185 : 0 : break;
186 : : default:
187 : 0 : break;
188 : : }
189 : :
190 [ + - ]: 194 : checkTypeDependencies(typeMgr, dependencies, paramType);
191 : : }
192 : :
193 [ + + ]: 526 : for (j=0; j < excCount; j++)
194 : : {
195 [ + - ]: 172 : excType = reader.getMethodExcType(i, j);
196 [ + - ]: 172 : dependencies.insert(type, excType, TYPEUSE_EXCEPTION);
197 [ + - ]: 172 : checkTypeDependencies(typeMgr, dependencies, excType);
198 : : }
199 : :
200 : : }
201 : :
202 : 194 : return sal_True;
203 : : }
204 : :
205 : 194 : static sal_Bool checkReferenceDependencies(TypeManager& typeMgr, TypeDependency& dependencies,
206 : : TypeReader& reader, const OString& type)
207 : : {
208 : 194 : sal_uInt32 count = reader.getReferenceCount();
209 : :
210 [ + - ]: 194 : if (count == 0)
211 : 194 : return sal_True;
212 : :
213 : 0 : OString referenceName;
214 [ # # ]: 0 : for (sal_uInt16 i=0; i < count; i++)
215 : : {
216 [ # # ]: 0 : referenceName = reader.getReferenceName(i);
217 : :
218 [ # # ]: 0 : if (reader.getReferenceType(i) != RT_REF_TYPE_PARAMETER)
219 : : {
220 [ # # ]: 0 : dependencies.insert(type, referenceName, TYPEUSE_NORMAL);
221 [ # # ]: 0 : checkTypeDependencies(typeMgr, dependencies, referenceName);
222 : : }
223 : : }
224 : :
225 : 194 : return sal_True;
226 : : }
227 : :
228 : 1312 : sal_Bool checkTypeDependencies(TypeManager& typeMgr, TypeDependency& dependencies, const OString& type, sal_Bool bDepend)
229 : : {
230 [ + - ][ + + ]: 1312 : if (!typeMgr.isValidType(type))
231 : 488 : return sal_False;
232 : :
233 [ + - ][ + + ]: 824 : if (dependencies.hasDependencies(type))
234 : 602 : return sal_True;
235 : :
236 [ + - ]: 222 : TypeReader reader = typeMgr.getTypeReader(type);
237 : :
238 [ - + ]: 222 : if ( !reader.isValid() )
239 : : {
240 [ # # ]: 0 : if (type.equals("/"))
241 : 0 : return sal_True;
242 : : else
243 : 0 : return sal_False;
244 : : }
245 : :
246 [ + + ][ + + ]: 222 : if ( bDepend && reader.getTypeClass() == RT_TYPE_MODULE)
[ + + ]
247 : : {
248 [ + - ]: 28 : checkFieldDependencies(typeMgr, dependencies, reader, type);
249 : 28 : return sal_True;
250 : : }
251 : :
252 [ + + ]: 360 : for (sal_uInt16 i = 0; i < reader.getSuperTypeCount(); ++i) {
253 [ + - ]: 166 : OString superType(reader.getSuperTypeName(i));
254 [ + - ]: 166 : dependencies.insert(type, superType, TYPEUSE_SUPER);
255 [ + - ]: 166 : checkTypeDependencies(typeMgr, dependencies, superType);
256 : 166 : }
257 : :
258 [ + + ]: 194 : if (reader.getTypeClass() == RT_TYPE_INTERFACE)
259 : : {
260 [ + - ]: 130 : dependencies.insert(type, "com/sun/star/uno/RuntimeException", TYPEUSE_EXCEPTION);
261 [ + - ]: 130 : dependencies.insert(type, "com/sun/star/uno/TypeClass", TYPEUSE_NORMAL);
262 [ + - ]: 130 : checkTypeDependencies(typeMgr, dependencies, "com/sun/star/uno/RuntimeException", bDepend);
263 : : }
264 : :
265 [ + - ]: 194 : checkFieldDependencies(typeMgr, dependencies, reader, type);
266 [ + - ]: 194 : checkMethodDependencies(typeMgr, dependencies, reader, type);
267 [ + - ]: 194 : checkReferenceDependencies(typeMgr, dependencies, reader, type);
268 : :
269 : : // make the scope modules as dependencies
270 : 194 : sal_Int32 nPos = type.lastIndexOf( '/' );
271 : :
272 [ + - ]: 194 : if ( nPos >= 0 )
273 : : {
274 : 194 : OString aScope( type.copy( 0, nPos ) );
275 : 194 : OStringBuffer tmpBuf(aScope.getLength());
276 : :
277 : 194 : nPos = 0;
278 [ + + ]: 776 : do
279 : : {
280 [ + - ]: 776 : tmpBuf.append(aScope.getToken(0, '/', nPos));
281 [ + - ]: 776 : dependencies.insert(type, tmpBuf.getStr(), TYPEUSE_SCOPE);
282 [ + - ]: 776 : tmpBuf.append('/');
283 : 194 : } while( nPos != -1 );
284 : : }
285 : :
286 [ + - ]: 1312 : return sal_True;
287 : : }
288 : :
289 : :
290 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|