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: usedtype.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 ************************************************************************/
32 #include <ary/cpp/usedtype.hxx>
35 // NOT FULLY DEFINED SERVICES
36 #include <cosv/tpl/tpltools.hxx>
37 #include <ary/symtreenode.hxx>
38 #include <ary/cpp/c_ce.hxx>
39 #include <ary/cpp/c_class.hxx>
40 #include <ary/cpp/c_namesp.hxx>
41 #include <ary/cpp/c_slntry.hxx>
42 #include <ary/cpp/c_tydef.hxx>
43 #include <ary/cpp/c_traits.hxx>
44 #include <ary/cpp/c_types4cpp.hxx>
45 #include <ary/cpp/c_gate.hxx>
46 #include <ary/cpp/cp_ce.hxx>
47 #include <ary/cpp/cp_type.hxx>
48 #include <ary/doc/d_oldcppdocu.hxx>
49 #include <ary/getncast.hxx>
50 #include "tplparam.hxx"
57 using namespace ::ary::cpp
;
58 typedef std::vector
< ary::cpp::E_ConVol
> PtrLevelVector
;
62 result2bool( intt i_nResult
)
63 { return i_nResult
< 0; }
66 intt
compare_PtrLevelVector(
67 const PtrLevelVector
&
69 const PtrLevelVector
&
72 compare_ConVol( E_ConVol i_e1
,
74 { return intt(i_e1
) - intt(i_e2
); }
77 compare_bool( bool i_b1
,
85 compare_Specialisation( E_TypeSpecialisation i_e1
,
86 E_TypeSpecialisation i_e2
)
87 { return intt(i_e1
) - intt(i_e2
); }
90 is_const( E_ConVol i_eCV
)
91 { return ( intt(i_eCV
) & intt(CONVOL_const
) ) != 0; }
94 is_volatile( E_ConVol i_eCV
)
95 { return ( intt(i_eCV
) & intt(CONVOL_volatile
) ) != 0; }
99 compare_PtrLevelVector( const PtrLevelVector
& i_r1
,
100 const PtrLevelVector
& i_r2
)
102 intt nResult
= i_r1
.size() - i_r2
.size();
106 PtrLevelVector::const_iterator it1
= i_r1
.begin();
107 PtrLevelVector::const_iterator it1End
= i_r1
.end();
108 PtrLevelVector::const_iterator it2
= i_r2
.begin();
110 for ( ; it1
!= it1End
; ++it1
, ++it2
)
112 nResult
= compare_ConVol(*it1
, *it2
);
121 } // anonymous namespace
131 typedef symtree::Node
<CeNode_Traits
> CeNode
;
132 typedef ut::NameChain::const_iterator nc_iter
;
134 Ce_id
CheckForRelatedCe_inNode(
135 const CeNode
& i_node
,
136 const StringVector
& i_qualification
,
137 const String
& i_name
);
140 UsedType::UsedType(Ce_id i_scope
)
143 eConVol_Type(CONVOL_none
),
146 bRefers2BuiltInType(false),
147 eTypeSpecialisation(TYSP_none
),
153 UsedType::~UsedType()
159 UsedType::operator<( const UsedType
& i_rType
) const
161 intt nResult
= compare_bool( bIsAbsolute
, i_rType
.bIsAbsolute
);
163 return result2bool(nResult
);
165 nResult
= static_cast<intt
>(nScope
.Value())
167 static_cast<intt
>(i_rType
.nScope
.Value());
169 return result2bool(nResult
);
171 nResult
= aPath
.Compare( i_rType
.aPath
);
173 return result2bool(nResult
);
175 nResult
= compare_ConVol( eConVol_Type
, i_rType
.eConVol_Type
);
177 return result2bool(nResult
);
179 nResult
= compare_PtrLevelVector( aPtrLevels
, i_rType
.aPtrLevels
);
181 return result2bool(nResult
);
183 nResult
= compare_bool( bIsReference
, i_rType
.bIsReference
);
185 return result2bool(nResult
);
187 nResult
= compare_Specialisation( eTypeSpecialisation
, i_rType
.eTypeSpecialisation
);
189 return result2bool(nResult
);
195 UsedType::Set_Absolute()
201 UsedType::Add_NameSegment( const char * i_sSeg
)
203 aPath
.Add_Segment(i_sSeg
);
206 ut::List_TplParameter
&
207 UsedType::Enter_Template()
209 return aPath
.Templatize_LastSegment();
213 UsedType::Set_Unsigned()
215 eTypeSpecialisation
= TYSP_unsigned
;
219 UsedType::Set_Signed()
221 eTypeSpecialisation
= TYSP_signed
;
225 UsedType::Set_BuiltIn( const char * i_sType
)
227 aPath
.Add_Segment(i_sType
);
228 bRefers2BuiltInType
= true;
232 UsedType::Set_Const()
235 eConVol_Type
= E_ConVol(eConVol_Type
| CONVOL_const
);
237 aPtrLevels
.back() = E_ConVol(aPtrLevels
.back() | CONVOL_const
);
241 UsedType::Set_Volatile()
244 eConVol_Type
= E_ConVol(eConVol_Type
| CONVOL_volatile
);
246 aPtrLevels
.back() = E_ConVol(aPtrLevels
.back() | CONVOL_volatile
);
250 UsedType::Add_PtrLevel()
252 aPtrLevels
.push_back(CONVOL_none
);
256 UsedType::Set_Reference()
262 IsInternal(const ary::cpp::CodeEntity
& i_ce
)
264 const ary::doc::OldCppDocu
*
265 docu
= dynamic_cast< const ary::doc::OldCppDocu
* >(i_ce
.Docu().Data());
267 return docu
->IsInternal();
273 UsedType::Connect2Ce( const CePilot
& i_ces
)
279 Get_NameParts(qualification
, name
);
281 for ( const CeNode
* scope_node
= CeNode_Traits::NodeOf_(
282 i_ces
.Find_Ce(nScope
));
284 scope_node
= scope_node
->Parent() )
286 nRelatedCe
= CheckForRelatedCe_inNode(*scope_node
, qualification
, name
);
287 if ( nRelatedCe
.IsValid() )
289 if ( IsInternal(i_ces
.Find_Ce(nRelatedCe
)) )
290 nRelatedCe
= Ce_id(0);
297 UsedType::Connect2CeOnlyKnownViaBaseClass(const Gate
& i_gate
)
299 csv_assert(nScope
.IsValid());
301 instances
= i_gate
.Ces().Search_TypeName( LocalName() );
303 // If there are no matches, or only one match that was already
304 // accepted, all work is done.
305 if ( (nRelatedCe
.IsValid() AND instances
.size() == 1)
306 OR instances
.size() == 0 )
313 Get_NameParts(qualification
, name
);
316 scopece
= i_gate
.Ces().Find_Ce(nScope
);
318 // Else search for declaration in own class and then in base classes.
319 // These would be of higher priority than those in parent namespaces.
321 foundce
= RecursiveSearchCe_InBaseClassesOf(
322 scopece
, qualification
, name
, i_gate
);
323 if (foundce
.IsValid())
324 nRelatedCe
= foundce
;
326 if ( nRelatedCe
.IsValid() AND
IsInternal(i_gate
.Ces().Find_Ce(nRelatedCe
)) )
328 nRelatedCe
= Ce_id(0);
333 UsedType::IsBuiltInType() const
335 return bRefers2BuiltInType
336 AND aPtrLevels
.size() == 0
338 AND eConVol_Type
== ary::cpp::CONVOL_none
;
342 UsedType::LocalName() const
344 return aPath
.LastSegment();
348 UsedType::TypeSpecialisation() const
350 return eTypeSpecialisation
;
354 UsedType::do_Accept(csv::ProcessorIfc
& io_processor
) const
356 csv::CheckedCall(io_processor
,*this);
360 UsedType::get_AryClass() const
366 UsedType::inq_RelatedCe() const
368 return nRelatedCe
.Value();
372 UsedType::inq_IsConst() const
374 if ( is_const(eConVol_Type
) )
376 for ( PtrLevelVector::const_iterator it
= aPtrLevels
.begin();
377 it
!= aPtrLevels
.end();
388 UsedType::inq_Get_Text( StreamStr
& o_rPreName
,
390 StreamStr
& o_rPostName
,
391 const Gate
& i_rGate
) const
393 if ( is_const(eConVol_Type
) )
394 o_rPreName
<< "const ";
395 if ( is_volatile(eConVol_Type
) )
396 o_rPreName
<< "volatile ";
400 aPath
.Get_Text( o_rPreName
, o_rName
, o_rPostName
, i_rGate
);
402 for ( PtrLevelVector::const_iterator it
= aPtrLevels
.begin();
403 it
!= aPtrLevels
.end();
408 o_rPostName
<< " const";
409 if ( is_volatile(*it
) )
410 o_rPostName
<< " volatile";
417 UsedType::RecursiveSearchCe_InBaseClassesOf( const CodeEntity
& i_mayBeClass
,
418 const StringVector
& i_myQualification
,
419 const String
& i_myName
,
420 const Gate
& i_gate
) const
422 // Find in this class?
424 basenode
= CeNode_Traits::NodeOf_(i_mayBeClass
);
428 found
= CheckForRelatedCe_inNode(*basenode
, i_myQualification
, i_myName
);
434 cl
= ary_cast
<Class
>(&i_mayBeClass
);
438 for ( List_Bases::const_iterator it
= cl
->BaseClasses().begin();
439 it
!= cl
->BaseClasses().end();
442 csv_assert((*it
).nId
.IsValid());
444 base
= i_gate
.Types().Find_Type((*it
).nId
).RelatedCe();
445 while (base
.IsValid() AND is_type
<Typedef
>(i_gate
.Ces().Find_Ce(base
)) )
447 base
= i_gate
.Types().Find_Type(
448 ary_cast
<Typedef
>(i_gate
.Ces().Find_Ce(base
))
456 basece
= i_gate
.Ces().Find_Ce(base
);
457 found
= RecursiveSearchCe_InBaseClassesOf(
458 basece
, i_myQualification
, i_myName
, i_gate
);
469 UsedType::Get_NameParts( StringVector
& o_qualification
,
472 nc_iter nit
= aPath
.begin();
473 nc_iter nit_end
= aPath
.end();
474 csv_assert(nit
!= nit_end
); // Each UsedType has to have a local name.
477 o_name
= (*nit_end
).Name();
482 o_qualification
.push_back( (*nit
).Name() );
487 CheckForRelatedCe_inNode( const CeNode
& i_node
,
488 const StringVector
& i_qualification
,
489 const String
& i_name
)
491 if (i_qualification
.size() > 0)
495 i_node
.SearchBelow( ret
,
496 i_qualification
.begin(),
497 i_qualification
.end(),
503 return i_node
.Search(i_name
);
511 List_TplParameter::List_TplParameter()
516 List_TplParameter::~List_TplParameter()
518 csv::erase_container_of_heap_ptrs(aTplParameters
);
522 List_TplParameter::AddParam_Type( Type_id i_nType
)
524 aTplParameters
.push_back( new TplParameter_Type(i_nType
) );
528 List_TplParameter::Get_Text( StreamStr
& o_rOut
,
529 const ary::cpp::Gate
& i_rGate
) const
531 Vector_TplArgument::const_iterator it
= aTplParameters
.begin();
532 Vector_TplArgument::const_iterator itEnd
= aTplParameters
.end();
542 (*it
)->Get_Text( o_rOut
, i_rGate
);
544 for ( ++it
; it
!= itEnd
; ++it
)
547 (*it
)->Get_Text( o_rOut
, i_rGate
);
554 List_TplParameter::Compare( const List_TplParameter
& i_rOther
) const
556 intt nResult
= intt(aTplParameters
.size()) - intt(i_rOther
.aTplParameters
.size());
561 Vector_TplArgument::const_iterator it1
= aTplParameters
.begin();
562 Vector_TplArgument::const_iterator it1End
= aTplParameters
.end();
563 Vector_TplArgument::const_iterator it2
= i_rOther
.aTplParameters
.begin();
565 for ( ; it1
!= it1End
; ++it1
, ++it2
)
567 nResult
= (*it1
)->Compare( *(*it2
) );