Update ooo320-m1
[ooovba.git] / autodoc / source / ary / cpp / ca_ce.cxx
blobc1357e1f3b4c640809d31e80f75ab636ac444778
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: ca_ce.cxx,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
32 #include <precomp.h>
33 #include "ca_ce.hxx"
36 // NOT FULLY DEFINED SERVICES
37 #include <ary/qualiname.hxx>
38 #include <ary/cpp/inpcontx.hxx>
39 #include <ary/cpp/c_namesp.hxx>
40 #include <ary/cpp/c_class.hxx>
41 #include <ary/cpp/c_enum.hxx>
42 #include <ary/cpp/c_enuval.hxx>
43 #include <ary/cpp/c_funct.hxx>
44 #include <ary/cpp/c_tydef.hxx>
45 #include <ary/cpp/c_type.hxx>
46 #include <ary/cpp/c_vari.hxx>
47 #include <ary/cpp/cp_type.hxx>
48 #include <ary/loc/loc_file.hxx>
49 #include <ary/getncast.hxx>
56 namespace
59 String Get_NewAnonymousNamespaceName();
60 String Get_NewAnonymousName(
61 char i_start );
64 } // anonymous namespace
69 namespace ary
71 namespace cpp
75 // KORR_FUTURE
76 // What about namespace visibility ?
77 // Perhaps handle all/some visibility transfer only after parse is complete.
78 void
79 transfer_visibility( const Class * i_owner,
80 CodeEntity & o_child )
82 if ( i_owner != 0 ? NOT i_owner->IsVisible() : false )
83 o_child.Set_InVisible();
86 inline const TypePilot &
87 CeAdmin::Types() const
89 csv_assert(pTypes != 0);
90 return *pTypes;
98 CeAdmin::CeAdmin(RepositoryPartition & io_myReposyPartition)
99 : aStorage(),
100 pTypes(0),
101 pCppRepositoryPartition(&io_myReposyPartition)
105 void
106 CeAdmin::Set_Related(const TypePilot & i_types)
108 pTypes = &i_types;
111 CeAdmin::~CeAdmin()
115 Namespace &
116 CeAdmin::CheckIn_Namespace( const InputContext & i_context,
117 const String & i_localName )
119 const String
120 local_name = NOT i_localName.empty()
121 ? i_localName
122 : Get_NewAnonymousNamespaceName();
123 Namespace &
124 rParent = i_context.CurNamespace();
125 Namespace *
126 ret = rParent.Search_LocalNamespace(local_name);
127 if ( ret == 0 )
129 ret = &Create_Namespace(rParent, local_name);
131 return *ret;
134 Class &
135 CeAdmin::Store_Class( const InputContext & i_context,
136 const String & i_localName,
137 E_ClassKey i_eClassKey )
139 const String
140 local_name = i_localName.empty()
141 ? Get_NewAnonymousName( i_eClassKey == CK_class
142 ? 'c'
143 : i_eClassKey == CK_struct
144 ? 's'
145 : 'u' )
146 : i_localName;
148 Class &
149 ret = * new Class( local_name,
150 i_context.CurOwner().CeId(),
151 i_context.CurProtection(),
152 i_context.CurFile().LeId(),
153 i_eClassKey );
154 aStorage.Store_Type(ret);
155 i_context.CurOwner().Add_Class(local_name, ret.CeId());
156 transfer_visibility(i_context.CurClass(), ret);
158 return ret;
161 Enum &
162 CeAdmin::Store_Enum( const InputContext & i_context,
163 const String & i_localName )
165 const String
166 local_name = i_localName.empty()
167 ? Get_NewAnonymousName('e')
168 : i_localName;
169 Enum &
170 ret = * new Enum( local_name,
171 i_context.CurOwner().CeId(),
172 i_context.CurProtection(),
173 i_context.CurFile().LeId() );
174 aStorage.Store_Type(ret);
175 i_context.CurOwner().Add_Enum(local_name, ret.CeId());
176 transfer_visibility(i_context.CurClass(), ret);
178 return ret;
181 Typedef &
182 CeAdmin::Store_Typedef( const InputContext& i_context,
183 const String & i_localName,
184 Type_id i_referredType )
186 Typedef &
187 ret = * new Typedef( i_localName,
188 i_context.CurOwner().CeId(),
189 i_context.CurProtection(),
190 i_context.CurFile().LeId(),
191 i_referredType );
192 aStorage.Store_Type(ret);
193 i_context.CurOwner().Add_Typedef(i_localName, ret.CeId());
194 transfer_visibility(i_context.CurClass(), ret);
196 return ret;
199 Function *
200 CeAdmin::Store_Operation( const InputContext & i_context,
201 const String & i_localName,
202 Type_id i_returnType,
203 const std::vector<S_Parameter> & i_parameters,
204 E_Virtuality i_virtuality,
205 E_ConVol i_conVol,
206 FunctionFlags i_flags,
207 bool i_throwExists,
208 const std::vector<Type_id> & i_exceptions )
210 Function &
211 ret = * new Function( i_localName,
212 i_context.CurOwner().CeId(),
213 i_context.CurProtection(),
214 i_context.CurFile().LeId(),
215 i_returnType,
216 i_parameters,
217 i_conVol,
218 i_virtuality,
219 i_flags,
220 i_throwExists,
221 i_exceptions );
223 // Check for double declaration:
224 Ce_id
225 nAlreadyExistingFunction(0);
226 switch ( lhf_CheckAndHandle_DuplicateOperation(
227 nAlreadyExistingFunction,
228 i_context,
229 ret) )
231 case df_discard_new:
232 delete &ret;
233 return 0;
234 case df_replace:
235 csv_assert(nAlreadyExistingFunction.IsValid());
236 aStorage.Replace_Entity(
237 nAlreadyExistingFunction,
238 ret );
239 break;
240 case df_no:
241 aStorage.Store_Operation(ret); // Now it has a valid id.
242 i_context.CurOwner().Add_Operation( i_localName, ret.CeId(), i_flags.IsStaticMember() );
243 break;
244 default:
245 csv_assert(false);
248 transfer_visibility(i_context.CurClass(), ret);
249 if ( i_context.CurProtection() != PROTECT_global )
251 Class *
252 pClass = i_context.CurClass();
253 if ( pClass != 0 AND i_virtuality != VIRTUAL_none)
255 pClass->UpdateVirtuality(i_virtuality);
259 return &ret;
262 Variable &
263 CeAdmin::Store_Variable( const InputContext& i_context,
264 const String & i_localName,
265 Type_id i_type,
266 VariableFlags i_flags,
267 const String & i_arraySize,
268 const String & i_initValue )
270 Variable &
271 ret = * new Variable( i_localName,
272 i_context.CurOwner().CeId(),
273 i_context.CurProtection(),
274 i_context.CurFile().LeId(),
275 i_type,
276 i_flags,
277 i_arraySize,
278 i_initValue );
280 bool
281 is_const = Types().Find_Type(i_type).IsConst();
282 aStorage.Store_Datum(ret);
283 i_context.CurOwner().Add_Variable(
284 i_localName,
285 ret.CeId(),
286 is_const,
287 i_flags.IsStaticMember() );
288 transfer_visibility(i_context.CurClass(), ret);
290 return ret;
293 EnumValue &
294 CeAdmin::Store_EnumValue( const InputContext & i_context,
295 const String & i_localName,
296 const String & i_initValue )
298 Enum *
299 parent = i_context.CurEnum();
300 csv_assert( parent != 0 );
302 EnumValue &
303 ret = * new EnumValue( i_localName,
304 parent->CeId(),
305 i_initValue );
306 aStorage.Store_Datum(ret);
307 parent->Add_Value(ret.CeId());
309 // KORR also for current enum:
310 transfer_visibility(i_context.CurClass(), ret);
312 return ret;
315 const Namespace &
316 CeAdmin::GlobalNamespace() const
318 return ary_cast<Namespace>( aStorage[predefined::ce_GlobalNamespace] );
321 const CodeEntity &
322 CeAdmin::Find_Ce(Ce_id i_id) const
324 return aStorage[i_id];
327 const CodeEntity *
328 CeAdmin::Search_Ce(Ce_id i_id) const
330 return aStorage.Exists(i_id)
331 ? & aStorage[i_id]
332 : (const CodeEntity*)(0);
335 const CodeEntity *
336 CeAdmin::Search_CeAbsolute( const CodeEntity & i_curScope,
337 const QualifiedName & i_rSearchedName ) const
339 const symtree::Node<CeNode_Traits> *
340 cur_node = CeNode_Traits::NodeOf_(i_curScope);
341 csv_assert(cur_node != 0);
343 Ce_id
344 ret(0);
345 cur_node->SearchUp( ret,
346 i_rSearchedName.first_namespace(),
347 i_rSearchedName.end_namespace(),
348 i_rSearchedName.LocalName() );
349 return Search_Ce(ret);
352 const CodeEntity *
353 CeAdmin::Search_CeLocal( const String & i_localName,
354 bool i_bIsFunction,
355 const Namespace & i_rCurNamespace,
356 const Class * i_pCurClass ) const
358 // KORR_FUTURE
359 // See if this is correct.
361 Ce_id
362 ret(0);
364 if ( NOT i_bIsFunction )
366 CesResultList
367 type_instances = aStorage.TypeIndex().SearchAll(i_localName);
368 CesResultList
369 data_instances = aStorage.DataIndex().SearchAll(i_localName);
370 Ce_id
371 ret1 = Search_MatchingInstance(
372 type_instances,
373 (i_pCurClass
374 ? i_pCurClass->CeId()
375 : i_rCurNamespace.CeId())
377 Ce_id
378 ret2 = Search_MatchingInstance(
379 data_instances,
380 (i_pCurClass
381 ? i_pCurClass->CeId()
382 : i_rCurNamespace.CeId())
384 if (NOT ret2.IsValid())
385 ret = ret1;
386 else if (NOT ret1.IsValid())
387 ret = ret2;
389 else
391 CesResultList
392 function_instances = aStorage.OperationIndex().SearchAll(i_localName);
393 if ( function_instances.size() == 1 )
394 ret = *function_instances.begin();
395 else
397 ret = Search_MatchingInstance(
398 function_instances,
399 (i_pCurClass
400 ? i_pCurClass->CeId()
401 : i_rCurNamespace.CeId())
406 if ( ret.IsValid() )
407 return & Find_Ce(ret);
409 return 0;
412 void
413 CeAdmin::Get_QualifiedName( StreamStr & o_rOut,
414 const String & i_localName,
415 Ce_id i_nOwner,
416 const char * i_sDelimiter ) const
418 if ( i_localName.empty() OR NOT i_nOwner.IsValid() )
419 return;
421 const CodeEntity *
422 pOwner = & Find_Ce( i_nOwner );
423 if ( is_type<Enum>(*pOwner) )
424 pOwner = &Find_Ce( Ce_id(pOwner->Owner()) );
426 Get_QualifiedName( o_rOut,
427 pOwner->LocalName(),
428 Ce_id(pOwner->Owner()),
429 i_sDelimiter );
430 o_rOut
431 << i_sDelimiter
432 << i_localName;
435 void
436 CeAdmin::Get_SignatureText( StreamStr & o_rOut,
437 const OperationSignature & i_signature,
438 const StringVector * i_sParameterNames ) const
440 OperationSignature::ParameterTypeList::const_iterator
441 it = i_signature.Parameters().begin();
442 OperationSignature::ParameterTypeList::const_iterator
443 it_end = i_signature.Parameters().end();
445 const StringVector aDummy;
446 StringVector::const_iterator
447 itName = i_sParameterNames != 0
448 ? i_sParameterNames->begin()
449 : aDummy.begin();
450 StringVector::const_iterator
451 itName_end = i_sParameterNames != 0
452 ? i_sParameterNames->end()
453 : aDummy.end();
455 bool
456 bEmpty = (it == it_end);
457 if (NOT bEmpty)
459 o_rOut << "( ";
460 Types().Get_TypeText(o_rOut, *it);
461 if (itName != itName_end)
462 o_rOut << " " << (*itName);
464 for ( ++it; it != it_end; ++it )
466 o_rOut << ", ";
467 Types().Get_TypeText(o_rOut, *it);
468 if (itName != itName_end)
470 ++itName;
471 if (itName != itName_end)
472 o_rOut << " " << (*itName);
475 o_rOut << " )";
477 else
479 o_rOut << "( )";
482 if ( intt(i_signature.ConVol()) & intt(ary::cpp::CONVOL_const) )
483 o_rOut << " const";
484 if ( intt(i_signature.ConVol()) & intt(ary::cpp::CONVOL_volatile) )
485 o_rOut << " volatile";
488 CesResultList
489 CeAdmin::Search_TypeName(const String & i_sName) const
491 return aStorage.TypeIndex().SearchAll(i_sName);
494 Namespace &
495 CeAdmin::GlobalNamespace()
497 return ary_cast<Namespace>( aStorage[predefined::ce_GlobalNamespace] );
500 CeAdmin::E_DuplicateFunction
501 CeAdmin::lhf_CheckAndHandle_DuplicateOperation(
502 Ce_id & o_existentFunction,
503 const InputContext & i_context,
504 const Function & i_newFunction )
506 if (i_context.CurProtection() != PROTECT_global)
508 // Assume, there will be no duplicates within the same class.
510 // KORR_FUTURE
511 // Assumption may be wrong in case of #defines providing different
512 // versions for different compilers.
513 return df_no;
516 std::vector<Ce_id>
517 aOperationsWithSameName;
518 i_context.CurNamespace().Search_LocalOperations(
519 aOperationsWithSameName,
520 i_newFunction.LocalName() );
522 for ( std::vector<Ce_id>::const_iterator
523 it = aOperationsWithSameName.begin();
524 it != aOperationsWithSameName.end();
525 ++it )
527 const Function &
528 rFunction = ary_cast<Function>(aStorage[*it]);
529 if ( rFunction.LocalName() == i_newFunction.LocalName()
530 AND rFunction.Signature() == i_newFunction.Signature() )
532 if (NOT rFunction.IsIdentical(i_newFunction))
534 // KORR_FUTURE Make this more detailed.
535 Cerr() << "Non identical function with same signature "
536 << "found: "
537 << i_context.CurNamespace().LocalName()
538 << "::"
539 << i_newFunction.LocalName()
540 << "(..)"
541 << Endl();
543 o_existentFunction = rFunction.CeId();
544 if (rFunction.Docu().Data() == 0)
545 return df_replace;
546 else
547 return df_discard_new;
549 } // end for
551 return df_no;
554 Namespace &
555 CeAdmin::Create_Namespace( Namespace & o_parent,
556 const String & i_localName )
558 DYN Namespace &
559 ret = *new Namespace(i_localName, o_parent);
560 aStorage.Store_Entity(ret);
561 o_parent.Add_LocalNamespace(ret);
562 return ret;
565 Ce_id
566 CeAdmin::Search_MatchingInstance( CesResultList i_list,
567 Ce_id i_owner ) const
569 // KORR
570 // Multiple results?
572 for ( CesList::const_iterator it = i_list.begin();
573 it != i_list.end();
574 ++it )
576 const CodeEntity &
577 ce = aStorage[*it];
578 if ( ce.Owner() == i_owner)
580 return *it;
583 return Ce_id(0);
588 } // namespace cpp
589 } // namespace ary
593 namespace
596 uintt G_nLastFreeAnonymousNamespaceNr = 0;
597 uintt G_nLastFreeAnonymousEntityNr = 0;
599 String
600 Get_NewAnonymousNamespaceName()
602 StreamLock
603 sl(100);
604 return String( sl()
605 << "namespace_anonymous_"
606 << ++G_nLastFreeAnonymousNamespaceNr
607 << csv::c_str );
611 String
612 Get_NewAnonymousName(char i_cStart)
614 StreamLock
615 sl(100);
616 return String( sl()
617 << i_cStart
618 << "_Anonymous__"
619 << ++G_nLastFreeAnonymousEntityNr
620 << c_str );
625 } // namespace anonymous