xref: /AOO41X/main/autodoc/source/ary/cpp/ca_ce.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir #include <precomp.h>
30*cdf0e10cSrcweir #include "ca_ce.hxx"
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES
34*cdf0e10cSrcweir #include <ary/qualiname.hxx>
35*cdf0e10cSrcweir #include <ary/cpp/inpcontx.hxx>
36*cdf0e10cSrcweir #include <ary/cpp/c_namesp.hxx>
37*cdf0e10cSrcweir #include <ary/cpp/c_class.hxx>
38*cdf0e10cSrcweir #include <ary/cpp/c_enum.hxx>
39*cdf0e10cSrcweir #include <ary/cpp/c_enuval.hxx>
40*cdf0e10cSrcweir #include <ary/cpp/c_funct.hxx>
41*cdf0e10cSrcweir #include <ary/cpp/c_tydef.hxx>
42*cdf0e10cSrcweir #include <ary/cpp/c_type.hxx>
43*cdf0e10cSrcweir #include <ary/cpp/c_vari.hxx>
44*cdf0e10cSrcweir #include <ary/cpp/cp_type.hxx>
45*cdf0e10cSrcweir #include <ary/loc/loc_file.hxx>
46*cdf0e10cSrcweir #include <ary/getncast.hxx>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir namespace
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir String              Get_NewAnonymousNamespaceName();
57*cdf0e10cSrcweir String              Get_NewAnonymousName(
58*cdf0e10cSrcweir                         char                i_start );
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir }   // anonymous namespace
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir namespace ary
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir namespace cpp
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir // KORR_FUTURE
73*cdf0e10cSrcweir // What about namespace visibility ?
74*cdf0e10cSrcweir // Perhaps handle all/some visibility transfer only after parse is complete.
75*cdf0e10cSrcweir void
76*cdf0e10cSrcweir transfer_visibility( const Class *  i_owner,
77*cdf0e10cSrcweir                      CodeEntity &   o_child )
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir     if ( i_owner != 0 ? NOT i_owner->IsVisible() : false )
80*cdf0e10cSrcweir         o_child.Set_InVisible();
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir inline const TypePilot &
84*cdf0e10cSrcweir CeAdmin::Types() const
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir     csv_assert(pTypes != 0);
87*cdf0e10cSrcweir     return *pTypes;
88*cdf0e10cSrcweir }
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir CeAdmin::CeAdmin(RepositoryPartition & io_myReposyPartition)
96*cdf0e10cSrcweir     :   aStorage(),
97*cdf0e10cSrcweir         pTypes(0),
98*cdf0e10cSrcweir         pCppRepositoryPartition(&io_myReposyPartition)
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir void
103*cdf0e10cSrcweir CeAdmin::Set_Related(const TypePilot & i_types)
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir     pTypes = &i_types;
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir CeAdmin::~CeAdmin()
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir Namespace &
113*cdf0e10cSrcweir CeAdmin::CheckIn_Namespace( const InputContext & i_context,
114*cdf0e10cSrcweir                             const String  &      i_localName )
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir     const String
117*cdf0e10cSrcweir         local_name = NOT i_localName.empty()
118*cdf0e10cSrcweir                                 ?   i_localName
119*cdf0e10cSrcweir                                 :   Get_NewAnonymousNamespaceName();
120*cdf0e10cSrcweir     Namespace &
121*cdf0e10cSrcweir         rParent = i_context.CurNamespace();
122*cdf0e10cSrcweir 	Namespace *
123*cdf0e10cSrcweir 	    ret = rParent.Search_LocalNamespace(local_name);
124*cdf0e10cSrcweir 	if ( ret == 0 )
125*cdf0e10cSrcweir 	{
126*cdf0e10cSrcweir         ret = &Create_Namespace(rParent, local_name);
127*cdf0e10cSrcweir 	}
128*cdf0e10cSrcweir 	return *ret;
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir Class &
132*cdf0e10cSrcweir CeAdmin::Store_Class( const InputContext & i_context,
133*cdf0e10cSrcweir 					  const String  &      i_localName,
134*cdf0e10cSrcweir                       E_ClassKey           i_eClassKey )
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir     const String
137*cdf0e10cSrcweir         local_name = i_localName.empty()
138*cdf0e10cSrcweir                         ?   Get_NewAnonymousName( i_eClassKey == CK_class
139*cdf0e10cSrcweir                                                     ?   'c'
140*cdf0e10cSrcweir                                                     :   i_eClassKey == CK_struct
141*cdf0e10cSrcweir                                                             ?   's'
142*cdf0e10cSrcweir                                                             :   'u' )
143*cdf0e10cSrcweir                         :   i_localName;
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir     Class &
146*cdf0e10cSrcweir         ret = * new Class( local_name,
147*cdf0e10cSrcweir                            i_context.CurOwner().CeId(),
148*cdf0e10cSrcweir                            i_context.CurProtection(),
149*cdf0e10cSrcweir                            i_context.CurFile().LeId(),
150*cdf0e10cSrcweir                            i_eClassKey );
151*cdf0e10cSrcweir     aStorage.Store_Type(ret);
152*cdf0e10cSrcweir     i_context.CurOwner().Add_Class(local_name, ret.CeId());
153*cdf0e10cSrcweir     transfer_visibility(i_context.CurClass(), ret);
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir     return ret;
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir Enum &
159*cdf0e10cSrcweir CeAdmin::Store_Enum( const InputContext & i_context,
160*cdf0e10cSrcweir 					 const String  &      i_localName )
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir     const String
163*cdf0e10cSrcweir         local_name = i_localName.empty()
164*cdf0e10cSrcweir                         ?   Get_NewAnonymousName('e')
165*cdf0e10cSrcweir                         :   i_localName;
166*cdf0e10cSrcweir     Enum &
167*cdf0e10cSrcweir         ret  = * new Enum( local_name,
168*cdf0e10cSrcweir                            i_context.CurOwner().CeId(),
169*cdf0e10cSrcweir 						   i_context.CurProtection(),
170*cdf0e10cSrcweir                            i_context.CurFile().LeId() );
171*cdf0e10cSrcweir     aStorage.Store_Type(ret);
172*cdf0e10cSrcweir     i_context.CurOwner().Add_Enum(local_name, ret.CeId());
173*cdf0e10cSrcweir     transfer_visibility(i_context.CurClass(), ret);
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir     return ret;
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir Typedef &
179*cdf0e10cSrcweir CeAdmin::Store_Typedef( const InputContext& i_context,
180*cdf0e10cSrcweir 						const String  &     i_localName,
181*cdf0e10cSrcweir                         Type_id             i_referredType )
182*cdf0e10cSrcweir {
183*cdf0e10cSrcweir     Typedef &
184*cdf0e10cSrcweir         ret  = * new Typedef( i_localName,
185*cdf0e10cSrcweir                               i_context.CurOwner().CeId(),
186*cdf0e10cSrcweir                               i_context.CurProtection(),
187*cdf0e10cSrcweir                               i_context.CurFile().LeId(),
188*cdf0e10cSrcweir                               i_referredType );
189*cdf0e10cSrcweir     aStorage.Store_Type(ret);
190*cdf0e10cSrcweir     i_context.CurOwner().Add_Typedef(i_localName, ret.CeId());
191*cdf0e10cSrcweir     transfer_visibility(i_context.CurClass(), ret);
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir     return ret;
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir Function *
197*cdf0e10cSrcweir CeAdmin::Store_Operation(   const InputContext &                i_context,
198*cdf0e10cSrcweir 					        const String  &                     i_localName,
199*cdf0e10cSrcweir                             Type_id                             i_returnType,
200*cdf0e10cSrcweir 					        const std::vector<S_Parameter> &    i_parameters,
201*cdf0e10cSrcweir                             E_Virtuality                        i_virtuality,
202*cdf0e10cSrcweir                             E_ConVol                            i_conVol,
203*cdf0e10cSrcweir                             FunctionFlags                       i_flags,
204*cdf0e10cSrcweir                             bool                                i_throwExists,
205*cdf0e10cSrcweir                             const std::vector<Type_id> &        i_exceptions )
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir     Function &
208*cdf0e10cSrcweir         ret     = * new Function(   i_localName,
209*cdf0e10cSrcweir                                     i_context.CurOwner().CeId(),
210*cdf0e10cSrcweir                                     i_context.CurProtection(),
211*cdf0e10cSrcweir                                     i_context.CurFile().LeId(),
212*cdf0e10cSrcweir                                     i_returnType,
213*cdf0e10cSrcweir                                     i_parameters,
214*cdf0e10cSrcweir                                     i_conVol,
215*cdf0e10cSrcweir                                     i_virtuality,
216*cdf0e10cSrcweir                                     i_flags,
217*cdf0e10cSrcweir                                     i_throwExists,
218*cdf0e10cSrcweir                                     i_exceptions );
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir     // Check for double declaration:
221*cdf0e10cSrcweir     Ce_id
222*cdf0e10cSrcweir         nAlreadyExistingFunction(0);
223*cdf0e10cSrcweir     switch ( lhf_CheckAndHandle_DuplicateOperation(
224*cdf0e10cSrcweir                                         nAlreadyExistingFunction,
225*cdf0e10cSrcweir                                         i_context,
226*cdf0e10cSrcweir                                         ret) )
227*cdf0e10cSrcweir     {
228*cdf0e10cSrcweir         case df_discard_new:
229*cdf0e10cSrcweir                 delete &ret;
230*cdf0e10cSrcweir                 return 0;
231*cdf0e10cSrcweir         case df_replace:
232*cdf0e10cSrcweir                 csv_assert(nAlreadyExistingFunction.IsValid());
233*cdf0e10cSrcweir                 aStorage.Replace_Entity(
234*cdf0e10cSrcweir                                 nAlreadyExistingFunction,
235*cdf0e10cSrcweir                                 ret );
236*cdf0e10cSrcweir                 break;
237*cdf0e10cSrcweir         case df_no:
238*cdf0e10cSrcweir                 aStorage.Store_Operation(ret);   // Now it has a valid id.
239*cdf0e10cSrcweir                 i_context.CurOwner().Add_Operation( i_localName, ret.CeId(), i_flags.IsStaticMember() );
240*cdf0e10cSrcweir                 break;
241*cdf0e10cSrcweir         default:
242*cdf0e10cSrcweir                 csv_assert(false);
243*cdf0e10cSrcweir     }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir     transfer_visibility(i_context.CurClass(), ret);
246*cdf0e10cSrcweir     if ( i_context.CurProtection() != PROTECT_global )
247*cdf0e10cSrcweir     {
248*cdf0e10cSrcweir         Class *
249*cdf0e10cSrcweir             pClass = i_context.CurClass();
250*cdf0e10cSrcweir         if ( pClass != 0  AND i_virtuality != VIRTUAL_none)
251*cdf0e10cSrcweir         {
252*cdf0e10cSrcweir             pClass->UpdateVirtuality(i_virtuality);
253*cdf0e10cSrcweir         }
254*cdf0e10cSrcweir     }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir     return &ret;
257*cdf0e10cSrcweir }
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir Variable &
260*cdf0e10cSrcweir CeAdmin::Store_Variable( const InputContext& i_context,
261*cdf0e10cSrcweir 						 const String  &     i_localName,
262*cdf0e10cSrcweir                          Type_id             i_type,
263*cdf0e10cSrcweir                          VariableFlags       i_flags,
264*cdf0e10cSrcweir                          const String  &     i_arraySize,
265*cdf0e10cSrcweir                          const String  &     i_initValue )
266*cdf0e10cSrcweir {
267*cdf0e10cSrcweir     Variable &
268*cdf0e10cSrcweir         ret = * new Variable( i_localName,
269*cdf0e10cSrcweir                               i_context.CurOwner().CeId(),
270*cdf0e10cSrcweir                               i_context.CurProtection(),
271*cdf0e10cSrcweir                               i_context.CurFile().LeId(),
272*cdf0e10cSrcweir                               i_type,
273*cdf0e10cSrcweir                               i_flags,
274*cdf0e10cSrcweir                               i_arraySize,
275*cdf0e10cSrcweir                               i_initValue );
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir     bool
278*cdf0e10cSrcweir         is_const = Types().Find_Type(i_type).IsConst();
279*cdf0e10cSrcweir     aStorage.Store_Datum(ret);
280*cdf0e10cSrcweir     i_context.CurOwner().Add_Variable(
281*cdf0e10cSrcweir                                 i_localName,
282*cdf0e10cSrcweir                                 ret.CeId(),
283*cdf0e10cSrcweir                                 is_const,
284*cdf0e10cSrcweir                                 i_flags.IsStaticMember() );
285*cdf0e10cSrcweir     transfer_visibility(i_context.CurClass(), ret);
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir     return ret;
288*cdf0e10cSrcweir }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir EnumValue &
291*cdf0e10cSrcweir CeAdmin::Store_EnumValue( const InputContext & i_context,
292*cdf0e10cSrcweir 						  const String  &      i_localName,
293*cdf0e10cSrcweir                           const String  &      i_initValue )
294*cdf0e10cSrcweir {
295*cdf0e10cSrcweir     Enum *
296*cdf0e10cSrcweir         parent  = i_context.CurEnum();
297*cdf0e10cSrcweir     csv_assert( parent != 0 );
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir     EnumValue &
300*cdf0e10cSrcweir         ret = * new EnumValue( i_localName,
301*cdf0e10cSrcweir                                parent->CeId(),
302*cdf0e10cSrcweir                                i_initValue );
303*cdf0e10cSrcweir     aStorage.Store_Datum(ret);
304*cdf0e10cSrcweir     parent->Add_Value(ret.CeId());
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir     // KORR also for current enum:
307*cdf0e10cSrcweir     transfer_visibility(i_context.CurClass(), ret);
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir     return ret;
310*cdf0e10cSrcweir }
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir const Namespace &
313*cdf0e10cSrcweir CeAdmin::GlobalNamespace() const
314*cdf0e10cSrcweir {
315*cdf0e10cSrcweir     return ary_cast<Namespace>( aStorage[predefined::ce_GlobalNamespace] );
316*cdf0e10cSrcweir }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir const CodeEntity &
319*cdf0e10cSrcweir CeAdmin::Find_Ce(Ce_id i_id) const
320*cdf0e10cSrcweir {
321*cdf0e10cSrcweir     return aStorage[i_id];
322*cdf0e10cSrcweir }
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir const CodeEntity *
325*cdf0e10cSrcweir CeAdmin::Search_Ce(Ce_id i_id) const
326*cdf0e10cSrcweir {
327*cdf0e10cSrcweir     return aStorage.Exists(i_id)
328*cdf0e10cSrcweir                 ?   & aStorage[i_id]
329*cdf0e10cSrcweir                 :   (const CodeEntity*)(0);
330*cdf0e10cSrcweir }
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir const CodeEntity *
333*cdf0e10cSrcweir CeAdmin::Search_CeAbsolute( const CodeEntity &      i_curScope,
334*cdf0e10cSrcweir                             const QualifiedName &   i_rSearchedName ) const
335*cdf0e10cSrcweir {
336*cdf0e10cSrcweir     const symtree::Node<CeNode_Traits> *
337*cdf0e10cSrcweir         cur_node = CeNode_Traits::NodeOf_(i_curScope);
338*cdf0e10cSrcweir     csv_assert(cur_node != 0);
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir     Ce_id
341*cdf0e10cSrcweir         ret(0);
342*cdf0e10cSrcweir     cur_node->SearchUp( ret,
343*cdf0e10cSrcweir                         i_rSearchedName.first_namespace(),
344*cdf0e10cSrcweir                         i_rSearchedName.end_namespace(),
345*cdf0e10cSrcweir                         i_rSearchedName.LocalName()  );
346*cdf0e10cSrcweir     return Search_Ce(ret);
347*cdf0e10cSrcweir }
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir const CodeEntity *
350*cdf0e10cSrcweir CeAdmin::Search_CeLocal( const String  &     i_localName,
351*cdf0e10cSrcweir                          bool                i_bIsFunction,
352*cdf0e10cSrcweir                          const Namespace &   i_rCurNamespace,
353*cdf0e10cSrcweir                          const Class *       i_pCurClass ) const
354*cdf0e10cSrcweir {
355*cdf0e10cSrcweir     // KORR_FUTURE
356*cdf0e10cSrcweir     // See if this is correct.
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir     Ce_id
359*cdf0e10cSrcweir         ret(0);
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir     if ( NOT i_bIsFunction )
362*cdf0e10cSrcweir     {
363*cdf0e10cSrcweir         CesResultList
364*cdf0e10cSrcweir             type_instances = aStorage.TypeIndex().SearchAll(i_localName);
365*cdf0e10cSrcweir         CesResultList
366*cdf0e10cSrcweir             data_instances = aStorage.DataIndex().SearchAll(i_localName);
367*cdf0e10cSrcweir         Ce_id
368*cdf0e10cSrcweir             ret1 = Search_MatchingInstance(
369*cdf0e10cSrcweir                         type_instances,
370*cdf0e10cSrcweir                         (i_pCurClass
371*cdf0e10cSrcweir                                 ?   i_pCurClass->CeId()
372*cdf0e10cSrcweir                                 :   i_rCurNamespace.CeId())
373*cdf0e10cSrcweir                                      );
374*cdf0e10cSrcweir         Ce_id
375*cdf0e10cSrcweir             ret2 = Search_MatchingInstance(
376*cdf0e10cSrcweir                         data_instances,
377*cdf0e10cSrcweir                         (i_pCurClass
378*cdf0e10cSrcweir                                 ?   i_pCurClass->CeId()
379*cdf0e10cSrcweir                                 :   i_rCurNamespace.CeId())
380*cdf0e10cSrcweir                                      );
381*cdf0e10cSrcweir         if (NOT ret2.IsValid())
382*cdf0e10cSrcweir             ret = ret1;
383*cdf0e10cSrcweir         else if (NOT ret1.IsValid())
384*cdf0e10cSrcweir             ret = ret2;
385*cdf0e10cSrcweir     }
386*cdf0e10cSrcweir     else
387*cdf0e10cSrcweir     {
388*cdf0e10cSrcweir         CesResultList
389*cdf0e10cSrcweir             function_instances = aStorage.OperationIndex().SearchAll(i_localName);
390*cdf0e10cSrcweir         if ( function_instances.size() == 1 )
391*cdf0e10cSrcweir             ret = *function_instances.begin();
392*cdf0e10cSrcweir         else
393*cdf0e10cSrcweir         {
394*cdf0e10cSrcweir             ret = Search_MatchingInstance(
395*cdf0e10cSrcweir                         function_instances,
396*cdf0e10cSrcweir                         (i_pCurClass
397*cdf0e10cSrcweir                                 ?   i_pCurClass->CeId()
398*cdf0e10cSrcweir                                 :   i_rCurNamespace.CeId())
399*cdf0e10cSrcweir                                      );
400*cdf0e10cSrcweir         }
401*cdf0e10cSrcweir     }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir     if ( ret.IsValid() )
404*cdf0e10cSrcweir         return & Find_Ce(ret);
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir     return 0;
407*cdf0e10cSrcweir }
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir void
410*cdf0e10cSrcweir CeAdmin::Get_QualifiedName( StreamStr &         o_rOut,
411*cdf0e10cSrcweir                             const String  &     i_localName,
412*cdf0e10cSrcweir                             Ce_id               i_nOwner,
413*cdf0e10cSrcweir                             const char *        i_sDelimiter ) const
414*cdf0e10cSrcweir {
415*cdf0e10cSrcweir 	if ( i_localName.empty() OR NOT i_nOwner.IsValid() )
416*cdf0e10cSrcweir 		return;
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir     const CodeEntity *
419*cdf0e10cSrcweir         pOwner = & Find_Ce( i_nOwner );
420*cdf0e10cSrcweir     if ( is_type<Enum>(*pOwner) )
421*cdf0e10cSrcweir         pOwner = &Find_Ce( Ce_id(pOwner->Owner()) );
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir     Get_QualifiedName( o_rOut,
424*cdf0e10cSrcweir                        pOwner->LocalName(),
425*cdf0e10cSrcweir                        Ce_id(pOwner->Owner()),
426*cdf0e10cSrcweir                        i_sDelimiter );
427*cdf0e10cSrcweir     o_rOut
428*cdf0e10cSrcweir         << i_sDelimiter
429*cdf0e10cSrcweir         << i_localName;
430*cdf0e10cSrcweir }
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir void
433*cdf0e10cSrcweir CeAdmin::Get_SignatureText( StreamStr &                 o_rOut,
434*cdf0e10cSrcweir                             const OperationSignature &  i_signature,
435*cdf0e10cSrcweir                             const StringVector *        i_sParameterNames ) const
436*cdf0e10cSrcweir {
437*cdf0e10cSrcweir     OperationSignature::ParameterTypeList::const_iterator
438*cdf0e10cSrcweir 			it = i_signature.Parameters().begin();
439*cdf0e10cSrcweir     OperationSignature::ParameterTypeList::const_iterator
440*cdf0e10cSrcweir             it_end = i_signature.Parameters().end();
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir     const StringVector aDummy;
443*cdf0e10cSrcweir     StringVector::const_iterator
444*cdf0e10cSrcweir 			itName = i_sParameterNames != 0
445*cdf0e10cSrcweir                             ?   i_sParameterNames->begin()
446*cdf0e10cSrcweir                             :   aDummy.begin();
447*cdf0e10cSrcweir     StringVector::const_iterator
448*cdf0e10cSrcweir             itName_end = i_sParameterNames != 0
449*cdf0e10cSrcweir                             ?   i_sParameterNames->end()
450*cdf0e10cSrcweir                             :   aDummy.end();
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir     bool
453*cdf0e10cSrcweir         bEmpty = (it == it_end);
454*cdf0e10cSrcweir     if (NOT bEmpty)
455*cdf0e10cSrcweir     {
456*cdf0e10cSrcweir         o_rOut << "( ";
457*cdf0e10cSrcweir         Types().Get_TypeText(o_rOut, *it);
458*cdf0e10cSrcweir         if (itName != itName_end)
459*cdf0e10cSrcweir             o_rOut << " " << (*itName);
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir         for ( ++it; it != it_end; ++it )
462*cdf0e10cSrcweir         {
463*cdf0e10cSrcweir             o_rOut << ", ";
464*cdf0e10cSrcweir             Types().Get_TypeText(o_rOut, *it);
465*cdf0e10cSrcweir             if (itName != itName_end)
466*cdf0e10cSrcweir             {
467*cdf0e10cSrcweir                 ++itName;
468*cdf0e10cSrcweir                 if (itName != itName_end)
469*cdf0e10cSrcweir                    o_rOut << " " << (*itName);
470*cdf0e10cSrcweir             }
471*cdf0e10cSrcweir         }
472*cdf0e10cSrcweir         o_rOut << " )";
473*cdf0e10cSrcweir     }
474*cdf0e10cSrcweir     else
475*cdf0e10cSrcweir     {
476*cdf0e10cSrcweir         o_rOut << "( )";
477*cdf0e10cSrcweir     }
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir     if ( intt(i_signature.ConVol()) & intt(ary::cpp::CONVOL_const) )
480*cdf0e10cSrcweir         o_rOut << " const";
481*cdf0e10cSrcweir     if ( intt(i_signature.ConVol()) & intt(ary::cpp::CONVOL_volatile) )
482*cdf0e10cSrcweir         o_rOut << " volatile";
483*cdf0e10cSrcweir }
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir CesResultList
486*cdf0e10cSrcweir CeAdmin::Search_TypeName(const String & i_sName) const
487*cdf0e10cSrcweir {
488*cdf0e10cSrcweir     return aStorage.TypeIndex().SearchAll(i_sName);
489*cdf0e10cSrcweir }
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir Namespace &
492*cdf0e10cSrcweir CeAdmin::GlobalNamespace()
493*cdf0e10cSrcweir {
494*cdf0e10cSrcweir     return ary_cast<Namespace>( aStorage[predefined::ce_GlobalNamespace] );
495*cdf0e10cSrcweir }
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir CeAdmin::E_DuplicateFunction
498*cdf0e10cSrcweir CeAdmin::lhf_CheckAndHandle_DuplicateOperation(
499*cdf0e10cSrcweir                                 Ce_id &                 o_existentFunction,
500*cdf0e10cSrcweir                                 const InputContext &    i_context,
501*cdf0e10cSrcweir                                 const Function &        i_newFunction )
502*cdf0e10cSrcweir {
503*cdf0e10cSrcweir     if (i_context.CurProtection() != PROTECT_global)
504*cdf0e10cSrcweir     {
505*cdf0e10cSrcweir         // Assume, there will be no duplicates within the same class.
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir         // KORR_FUTURE
508*cdf0e10cSrcweir         // Assumption may be wrong in case of #defines providing different
509*cdf0e10cSrcweir         // versions for different compilers.
510*cdf0e10cSrcweir         return df_no;
511*cdf0e10cSrcweir     }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir     std::vector<Ce_id>
514*cdf0e10cSrcweir         aOperationsWithSameName;
515*cdf0e10cSrcweir     i_context.CurNamespace().Search_LocalOperations(
516*cdf0e10cSrcweir                                         aOperationsWithSameName,
517*cdf0e10cSrcweir                                         i_newFunction.LocalName() );
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir     for ( std::vector<Ce_id>::const_iterator
520*cdf0e10cSrcweir              it = aOperationsWithSameName.begin();
521*cdf0e10cSrcweir           it != aOperationsWithSameName.end();
522*cdf0e10cSrcweir           ++it )
523*cdf0e10cSrcweir     {
524*cdf0e10cSrcweir         const Function &
525*cdf0e10cSrcweir             rFunction = ary_cast<Function>(aStorage[*it]);
526*cdf0e10cSrcweir         if (     rFunction.LocalName() == i_newFunction.LocalName()
527*cdf0e10cSrcweir              AND rFunction.Signature() == i_newFunction.Signature() )
528*cdf0e10cSrcweir         {
529*cdf0e10cSrcweir             if (NOT rFunction.IsIdentical(i_newFunction))
530*cdf0e10cSrcweir             {
531*cdf0e10cSrcweir                 // KORR_FUTURE Make this more detailed.
532*cdf0e10cSrcweir                 Cerr() << "Non identical function with same signature "
533*cdf0e10cSrcweir                        << "found: "
534*cdf0e10cSrcweir                        <<  i_context.CurNamespace().LocalName()
535*cdf0e10cSrcweir                        << "::"
536*cdf0e10cSrcweir                        << i_newFunction.LocalName()
537*cdf0e10cSrcweir                        << "(..)"
538*cdf0e10cSrcweir                        << Endl();
539*cdf0e10cSrcweir             }
540*cdf0e10cSrcweir             o_existentFunction = rFunction.CeId();
541*cdf0e10cSrcweir             if (rFunction.Docu().Data() == 0)
542*cdf0e10cSrcweir                 return df_replace;
543*cdf0e10cSrcweir             else
544*cdf0e10cSrcweir                 return df_discard_new;
545*cdf0e10cSrcweir         }
546*cdf0e10cSrcweir     }   // end for
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir     return df_no;
549*cdf0e10cSrcweir }
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir Namespace &
552*cdf0e10cSrcweir CeAdmin::Create_Namespace( Namespace &      o_parent,
553*cdf0e10cSrcweir                            const String  &  i_localName )
554*cdf0e10cSrcweir {
555*cdf0e10cSrcweir 	DYN Namespace &
556*cdf0e10cSrcweir 	    ret = *new Namespace(i_localName, o_parent);
557*cdf0e10cSrcweir     aStorage.Store_Entity(ret);
558*cdf0e10cSrcweir     o_parent.Add_LocalNamespace(ret);
559*cdf0e10cSrcweir     return ret;
560*cdf0e10cSrcweir }
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir Ce_id
563*cdf0e10cSrcweir CeAdmin::Search_MatchingInstance( CesResultList         i_list,
564*cdf0e10cSrcweir                                   Ce_id                 i_owner ) const
565*cdf0e10cSrcweir {
566*cdf0e10cSrcweir     // KORR
567*cdf0e10cSrcweir     // Multiple results?
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir     for ( CesList::const_iterator it = i_list.begin();
570*cdf0e10cSrcweir           it != i_list.end();
571*cdf0e10cSrcweir           ++it )
572*cdf0e10cSrcweir     {
573*cdf0e10cSrcweir         const CodeEntity &
574*cdf0e10cSrcweir             ce = aStorage[*it];
575*cdf0e10cSrcweir         if ( ce.Owner() == i_owner)
576*cdf0e10cSrcweir         {
577*cdf0e10cSrcweir             return *it;
578*cdf0e10cSrcweir         }
579*cdf0e10cSrcweir     }
580*cdf0e10cSrcweir     return Ce_id(0);
581*cdf0e10cSrcweir }
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir }   // namespace cpp
586*cdf0e10cSrcweir }   // namespace ary
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir namespace
591*cdf0e10cSrcweir {
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir uintt G_nLastFreeAnonymousNamespaceNr = 0;
594*cdf0e10cSrcweir uintt G_nLastFreeAnonymousEntityNr = 0;
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir String
597*cdf0e10cSrcweir Get_NewAnonymousNamespaceName()
598*cdf0e10cSrcweir {
599*cdf0e10cSrcweir     StreamLock
600*cdf0e10cSrcweir         sl(100);
601*cdf0e10cSrcweir     return String( sl()
602*cdf0e10cSrcweir                     << "namespace_anonymous_"
603*cdf0e10cSrcweir                     << ++G_nLastFreeAnonymousNamespaceNr
604*cdf0e10cSrcweir                     << csv::c_str );
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir }
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir String
609*cdf0e10cSrcweir Get_NewAnonymousName(char i_cStart)
610*cdf0e10cSrcweir {
611*cdf0e10cSrcweir     StreamLock
612*cdf0e10cSrcweir         sl(100);
613*cdf0e10cSrcweir     return String( sl()
614*cdf0e10cSrcweir                     << i_cStart
615*cdf0e10cSrcweir                     << "_Anonymous__"
616*cdf0e10cSrcweir                     << ++G_nLastFreeAnonymousEntityNr
617*cdf0e10cSrcweir                     << c_str );
618*cdf0e10cSrcweir }
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir }   // namespace anonymous
623