update dev300-m58
[ooovba.git] / rdbmaker / source / codemaker / dependency.cxx
blobc3d61e224322bdef13b1d918207e5808a3f03423
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dependency.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <osl/interlck.h>
32 #include <rtl/alloc.h>
33 #include <codemaker/dependency.hxx>
35 using namespace rtl;
37 TypeDependency::TypeDependency()
39 m_pImpl = new TypeDependencyImpl();
40 acquire();
43 TypeDependency::~TypeDependency()
45 release();
48 void TypeDependency::acquire()
50 osl_incrementInterlockedCount(&m_pImpl->m_refCount);
53 void TypeDependency::release()
55 if (0 == osl_decrementInterlockedCount(&m_pImpl->m_refCount))
57 delete m_pImpl;
61 sal_Bool TypeDependency::insert(const OString& type, const OString& depend, sal_uInt16 use)
63 sal_Bool ret = sal_False;
65 if (type.getLength() > 0 && depend.getLength() > 0)
67 if (m_pImpl->m_dependencies.count(type) > 0)
69 TypeUsing typeUsing(depend, use);
70 TypeUsingSet::iterator iter;
71 if ((iter = m_pImpl->m_dependencies[type].find(typeUsing)) != m_pImpl->m_dependencies[type].end())
73 (((TypeUsing *) &(*iter))->m_use) = (*iter).m_use | use;
74 } else
76 m_pImpl->m_dependencies[type].insert(typeUsing);
78 } else
80 TypeUsing typeUsing(depend, use);
81 TypeUsingSet tmpSet;
82 tmpSet.insert(typeUsing);
83 m_pImpl->m_dependencies[type]=tmpSet;
87 return ret;
90 TypeUsingSet TypeDependency::getDependencies(const OString& type)
92 if (type.getLength() > 0)
94 if (m_pImpl->m_dependencies.count(type) > 0)
96 return m_pImpl->m_dependencies[type];
100 return TypeUsingSet();
103 sal_Bool TypeDependency::hasDependencies(const OString& type)
105 if (type.getLength() > 0)
107 if (m_pImpl->m_dependencies.count(type) > 0)
109 return sal_True;
113 return sal_False;
116 void TypeDependency::setGenerated(const OString& type, sal_uInt16 genFlag)
118 // m_pImpl->m_generatedTypes.insert(type);
119 if (m_pImpl->m_generatedTypes.count(type) > 0)
120 m_pImpl->m_generatedTypes[type]= m_pImpl->m_generatedTypes[type] | genFlag;
121 else
122 m_pImpl->m_generatedTypes[type]=genFlag;
125 sal_Bool TypeDependency::isGenerated(const OString& type, sal_uInt16 genFlag)
128 if (m_pImpl->m_generatedTypes.count(type) > 0)
129 return sal_True;
131 return sal_False;
133 if (m_pImpl->m_generatedTypes.count(type) > 0 &&
134 m_pImpl->m_generatedTypes[type] & genFlag)
136 return sal_True;
139 return sal_False;
142 static sal_Bool checkFieldDependencies(TypeManager& typeMgr, TypeDependency& dependencies,
143 TypeReader& reader, const OString& type)
145 sal_uInt32 count = reader.getFieldCount();
147 if (count == 0 || reader.getTypeClass() == RT_TYPE_ENUM)
148 return sal_True;
150 OString fieldType;
151 for (sal_uInt16 i=0; i < count; i++)
153 fieldType = reader.getFieldType(i);
155 if (fieldType.getLength() > 0)
157 dependencies.insert(type, fieldType, TYPEUSE_MEMBER);
158 checkTypeDependencies(typeMgr, dependencies, fieldType);
162 return sal_True;
165 static sal_Bool checkMethodDependencies(TypeManager& typeMgr, TypeDependency& dependencies,
166 TypeReader& reader, const OString& type)
168 sal_uInt32 count = reader.getMethodCount();
170 if (count == 0)
171 return sal_True;
173 OString returnType, paramType, excType;
174 sal_uInt32 paramCount = 0;
175 sal_uInt32 excCount = 0;
176 RTParamMode paramMode = RT_PARAM_INVALID;
177 for (sal_uInt16 i=0; i < count; i++)
179 returnType = reader.getMethodReturnType(i);
181 dependencies.insert(type, returnType, TYPEUSE_RETURN);
182 checkTypeDependencies(typeMgr, dependencies, returnType);
184 paramCount = reader.getMethodParamCount(i);
185 excCount = reader.getMethodExcCount(i);
187 sal_uInt16 j;
188 for (j=0; j < paramCount; j++)
190 paramType = reader.getMethodParamType(i, j);
191 paramMode = reader.getMethodParamMode(i, j);
193 switch (paramMode)
195 case RT_PARAM_IN:
196 dependencies.insert(type, paramType, TYPEUSE_INPARAM);
197 break;
198 case RT_PARAM_OUT:
199 dependencies.insert(type, paramType, TYPEUSE_OUTPARAM);
200 break;
201 case RT_PARAM_INOUT:
202 dependencies.insert(type, paramType, TYPEUSE_INOUTPARAM);
203 break;
204 default:
205 break;
208 checkTypeDependencies(typeMgr, dependencies, paramType);
211 for (j=0; j < excCount; j++)
213 excType = reader.getMethodExcType(i, j);
214 dependencies.insert(type, excType, TYPEUSE_EXCEPTION);
215 checkTypeDependencies(typeMgr, dependencies, excType);
220 return sal_True;
223 static sal_Bool checkReferenceDependencies(TypeManager& typeMgr, TypeDependency& dependencies,
224 TypeReader& reader, const OString& type)
226 sal_uInt32 count = reader.getReferenceCount();
228 if (count == 0)
229 return sal_True;
231 OString referenceName;
232 for (sal_uInt16 i=0; i < count; i++)
234 referenceName = reader.getReferenceName(i);
236 dependencies.insert(type, referenceName, TYPEUSE_NORMAL);
237 checkTypeDependencies(typeMgr, dependencies, referenceName);
240 return sal_True;
243 sal_Bool checkTypeDependencies(TypeManager& typeMgr, TypeDependency& dependencies, const OString& type, sal_Bool bDepend)
245 if (!typeMgr.isValidType(type))
246 return sal_False;
248 if (dependencies.hasDependencies(type))
249 return sal_True;
251 TypeReader reader = typeMgr.getTypeReader(type);
253 if ( !reader.isValid() )
255 if (type.equals("/"))
256 return sal_True;
257 else
258 return sal_False;
261 if ( bDepend && reader.getTypeClass() == RT_TYPE_MODULE)
263 checkFieldDependencies(typeMgr, dependencies, reader, type);
264 return sal_True;
267 for (sal_uInt16 i = 0; i < reader.getSuperTypeCount(); ++i) {
268 OString superType(reader.getSuperTypeName(i));
269 dependencies.insert(type, superType, TYPEUSE_SUPER);
270 checkTypeDependencies(typeMgr, dependencies, superType);
273 if (reader.getTypeClass() == RT_TYPE_INTERFACE)
275 dependencies.insert(type, "com/sun/star/uno/RuntimeException", TYPEUSE_EXCEPTION);
276 dependencies.insert(type, "com/sun/star/uno/TypeClass", TYPEUSE_NORMAL);
277 checkTypeDependencies(typeMgr, dependencies, "com/sun/star/uno/RuntimeException", bDepend);
280 checkFieldDependencies(typeMgr, dependencies, reader, type);
281 checkMethodDependencies(typeMgr, dependencies, reader, type);
282 checkReferenceDependencies(typeMgr, dependencies, reader, type);
284 // make the scope modules as dependencies
285 sal_Int32 nPos = type.lastIndexOf( '/' );
287 if ( nPos >= 0 )
289 OString aScope( type.copy( 0, nPos ) );
290 OStringBuffer tmpBuf(aScope.getLength());
292 nPos = 0;
295 tmpBuf.append(aScope.getToken(0, '/', nPos));
296 dependencies.insert(type, tmpBuf.getStr(), TYPEUSE_SCOPE);
297 tmpBuf.append('/');
298 } while( nPos != -1 );
301 return sal_True;