1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ca_ce.cxx,v $
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 ************************************************************************/
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>
59 String
Get_NewAnonymousNamespaceName();
60 String
Get_NewAnonymousName(
64 } // anonymous namespace
76 // What about namespace visibility ?
77 // Perhaps handle all/some visibility transfer only after parse is complete.
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);
98 CeAdmin::CeAdmin(RepositoryPartition
& io_myReposyPartition
)
101 pCppRepositoryPartition(&io_myReposyPartition
)
106 CeAdmin::Set_Related(const TypePilot
& i_types
)
116 CeAdmin::CheckIn_Namespace( const InputContext
& i_context
,
117 const String
& i_localName
)
120 local_name
= NOT i_localName
.empty()
122 : Get_NewAnonymousNamespaceName();
124 rParent
= i_context
.CurNamespace();
126 ret
= rParent
.Search_LocalNamespace(local_name
);
129 ret
= &Create_Namespace(rParent
, local_name
);
135 CeAdmin::Store_Class( const InputContext
& i_context
,
136 const String
& i_localName
,
137 E_ClassKey i_eClassKey
)
140 local_name
= i_localName
.empty()
141 ? Get_NewAnonymousName( i_eClassKey
== CK_class
143 : i_eClassKey
== CK_struct
149 ret
= * new Class( local_name
,
150 i_context
.CurOwner().CeId(),
151 i_context
.CurProtection(),
152 i_context
.CurFile().LeId(),
154 aStorage
.Store_Type(ret
);
155 i_context
.CurOwner().Add_Class(local_name
, ret
.CeId());
156 transfer_visibility(i_context
.CurClass(), ret
);
162 CeAdmin::Store_Enum( const InputContext
& i_context
,
163 const String
& i_localName
)
166 local_name
= i_localName
.empty()
167 ? Get_NewAnonymousName('e')
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
);
182 CeAdmin::Store_Typedef( const InputContext
& i_context
,
183 const String
& i_localName
,
184 Type_id i_referredType
)
187 ret
= * new Typedef( i_localName
,
188 i_context
.CurOwner().CeId(),
189 i_context
.CurProtection(),
190 i_context
.CurFile().LeId(),
192 aStorage
.Store_Type(ret
);
193 i_context
.CurOwner().Add_Typedef(i_localName
, ret
.CeId());
194 transfer_visibility(i_context
.CurClass(), ret
);
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
,
206 FunctionFlags i_flags
,
208 const std::vector
<Type_id
> & i_exceptions
)
211 ret
= * new Function( i_localName
,
212 i_context
.CurOwner().CeId(),
213 i_context
.CurProtection(),
214 i_context
.CurFile().LeId(),
223 // Check for double declaration:
225 nAlreadyExistingFunction(0);
226 switch ( lhf_CheckAndHandle_DuplicateOperation(
227 nAlreadyExistingFunction
,
235 csv_assert(nAlreadyExistingFunction
.IsValid());
236 aStorage
.Replace_Entity(
237 nAlreadyExistingFunction
,
241 aStorage
.Store_Operation(ret
); // Now it has a valid id.
242 i_context
.CurOwner().Add_Operation( i_localName
, ret
.CeId(), i_flags
.IsStaticMember() );
248 transfer_visibility(i_context
.CurClass(), ret
);
249 if ( i_context
.CurProtection() != PROTECT_global
)
252 pClass
= i_context
.CurClass();
253 if ( pClass
!= 0 AND i_virtuality
!= VIRTUAL_none
)
255 pClass
->UpdateVirtuality(i_virtuality
);
263 CeAdmin::Store_Variable( const InputContext
& i_context
,
264 const String
& i_localName
,
266 VariableFlags i_flags
,
267 const String
& i_arraySize
,
268 const String
& i_initValue
)
271 ret
= * new Variable( i_localName
,
272 i_context
.CurOwner().CeId(),
273 i_context
.CurProtection(),
274 i_context
.CurFile().LeId(),
281 is_const
= Types().Find_Type(i_type
).IsConst();
282 aStorage
.Store_Datum(ret
);
283 i_context
.CurOwner().Add_Variable(
287 i_flags
.IsStaticMember() );
288 transfer_visibility(i_context
.CurClass(), ret
);
294 CeAdmin::Store_EnumValue( const InputContext
& i_context
,
295 const String
& i_localName
,
296 const String
& i_initValue
)
299 parent
= i_context
.CurEnum();
300 csv_assert( parent
!= 0 );
303 ret
= * new EnumValue( i_localName
,
306 aStorage
.Store_Datum(ret
);
307 parent
->Add_Value(ret
.CeId());
309 // KORR also for current enum:
310 transfer_visibility(i_context
.CurClass(), ret
);
316 CeAdmin::GlobalNamespace() const
318 return ary_cast
<Namespace
>( aStorage
[predefined::ce_GlobalNamespace
] );
322 CeAdmin::Find_Ce(Ce_id i_id
) const
324 return aStorage
[i_id
];
328 CeAdmin::Search_Ce(Ce_id i_id
) const
330 return aStorage
.Exists(i_id
)
332 : (const CodeEntity
*)(0);
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);
345 cur_node
->SearchUp( ret
,
346 i_rSearchedName
.first_namespace(),
347 i_rSearchedName
.end_namespace(),
348 i_rSearchedName
.LocalName() );
349 return Search_Ce(ret
);
353 CeAdmin::Search_CeLocal( const String
& i_localName
,
355 const Namespace
& i_rCurNamespace
,
356 const Class
* i_pCurClass
) const
359 // See if this is correct.
364 if ( NOT i_bIsFunction
)
367 type_instances
= aStorage
.TypeIndex().SearchAll(i_localName
);
369 data_instances
= aStorage
.DataIndex().SearchAll(i_localName
);
371 ret1
= Search_MatchingInstance(
374 ? i_pCurClass
->CeId()
375 : i_rCurNamespace
.CeId())
378 ret2
= Search_MatchingInstance(
381 ? i_pCurClass
->CeId()
382 : i_rCurNamespace
.CeId())
384 if (NOT ret2
.IsValid())
386 else if (NOT ret1
.IsValid())
392 function_instances
= aStorage
.OperationIndex().SearchAll(i_localName
);
393 if ( function_instances
.size() == 1 )
394 ret
= *function_instances
.begin();
397 ret
= Search_MatchingInstance(
400 ? i_pCurClass
->CeId()
401 : i_rCurNamespace
.CeId())
407 return & Find_Ce(ret
);
413 CeAdmin::Get_QualifiedName( StreamStr
& o_rOut
,
414 const String
& i_localName
,
416 const char * i_sDelimiter
) const
418 if ( i_localName
.empty() OR NOT i_nOwner
.IsValid() )
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
,
428 Ce_id(pOwner
->Owner()),
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()
450 StringVector::const_iterator
451 itName_end
= i_sParameterNames
!= 0
452 ? i_sParameterNames
->end()
456 bEmpty
= (it
== it_end
);
460 Types().Get_TypeText(o_rOut
, *it
);
461 if (itName
!= itName_end
)
462 o_rOut
<< " " << (*itName
);
464 for ( ++it
; it
!= it_end
; ++it
)
467 Types().Get_TypeText(o_rOut
, *it
);
468 if (itName
!= itName_end
)
471 if (itName
!= itName_end
)
472 o_rOut
<< " " << (*itName
);
482 if ( intt(i_signature
.ConVol()) & intt(ary::cpp::CONVOL_const
) )
484 if ( intt(i_signature
.ConVol()) & intt(ary::cpp::CONVOL_volatile
) )
485 o_rOut
<< " volatile";
489 CeAdmin::Search_TypeName(const String
& i_sName
) const
491 return aStorage
.TypeIndex().SearchAll(i_sName
);
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.
511 // Assumption may be wrong in case of #defines providing different
512 // versions for different compilers.
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();
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 "
537 << i_context
.CurNamespace().LocalName()
539 << i_newFunction
.LocalName()
543 o_existentFunction
= rFunction
.CeId();
544 if (rFunction
.Docu().Data() == 0)
547 return df_discard_new
;
555 CeAdmin::Create_Namespace( Namespace
& o_parent
,
556 const String
& i_localName
)
559 ret
= *new Namespace(i_localName
, o_parent
);
560 aStorage
.Store_Entity(ret
);
561 o_parent
.Add_LocalNamespace(ret
);
566 CeAdmin::Search_MatchingInstance( CesResultList i_list
,
567 Ce_id i_owner
) const
572 for ( CesList::const_iterator it
= i_list
.begin();
578 if ( ce
.Owner() == i_owner
)
596 uintt G_nLastFreeAnonymousNamespaceNr
= 0;
597 uintt G_nLastFreeAnonymousEntityNr
= 0;
600 Get_NewAnonymousNamespaceName()
605 << "namespace_anonymous_"
606 << ++G_nLastFreeAnonymousNamespaceNr
612 Get_NewAnonymousName(char i_cStart
)
619 << ++G_nLastFreeAnonymousEntityNr
625 } // namespace anonymous