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: pm_class.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 "pm_class.hxx"
35 // NOT FULLY DEFINED SERVICES
36 #include <ary/cpp/c_gate.hxx>
37 #include <ary/cpp/c_class.hxx>
38 #include <ary/cpp/c_tydef.hxx>
39 #include <ary/cpp/cp_ce.hxx>
40 #include <ary/loc/loc_file.hxx>
41 #include <ary/loc/locp_le.hxx>
42 #include <ary/getncast.hxx>
43 #include "hd_chlst.hxx"
44 #include "hd_docu.hxx"
46 #include "html_kit.hxx"
47 #include "navibar.hxx"
48 #include "opageenv.hxx"
49 #include "pagemake.hxx"
50 #include "strconst.hxx"
52 using namespace adcdisp
;
55 using csi::html::HorizontalLine
;
56 using csi::html::LineBreak
;
57 using csi::html::Link
;
58 using csi::html::Table
;
59 using csi::html::TableRow
;
60 using csi::html::TableCell
;
62 using ary::cpp::CesConstIterator
;
63 using ary::doc::OldCppDocu
;
65 const char * const C_sTitle_InnerClasses
= "Classes";
66 const char * const C_sTitle_InnerStructs
= "Structs";
67 const char * const C_sTitle_InnerUnions
= "Unions";
68 const char * const C_sTitle_Methods
= "Methods";
69 const char * const C_sTitle_StaticMethods
= "Static Methods";
70 const char * const C_sTitle_Data
= "Data";
71 const char * const C_sTitle_StaticData
= "Static Data";
73 const char * const C_sLabel_StaticOperations
= "static_ops";
74 const char * const C_sLabel_StaticVariables
= "static_vars";
76 const char * const C_sTitlePublic
= "Public Members";
77 const char * const C_sTitleProtected
= "Protected Members";
78 const char * const C_sTitlePrivate
= "Private Members";
79 const char * const C_sMprTitles
[3] = { C_sTitlePublic
,
83 const char * const C_sSummaryTitlePublic
= "Public Members";
84 const char * const C_sSummaryTitleProtected
= "Protected Members";
85 const char * const C_sSummaryTitlePrivate
= "Private Members";
87 C_sMprSummaryTitles
[3] =
88 { C_sSummaryTitlePublic
, C_sSummaryTitleProtected
, C_sSummaryTitlePrivate
};
91 { "publ_", "prot_", "priv_" };
93 C_sSummaryItems_Titles
[PageMaker_Class::cl_MAX
] =
94 { C_sTitle_InnerClasses
, C_sTitle_InnerStructs
, C_sTitle_InnerUnions
,
95 C_sTitle_Enums
, C_sTitle_Typedefs
,
96 C_sTitle_Methods
, C_sTitle_StaticMethods
, C_sTitle_Data
, C_sTitle_StaticData
};
98 C_sSummaryItems_Labels
[PageMaker_Class::cl_MAX
] =
99 { C_sLabel_Classes
, C_sLabel_Structs
, C_sLabel_Unions
,
100 C_sLabel_Enums
, C_sLabel_Typedefs
,
101 C_sLabel_Operations
, C_sLabel_StaticOperations
,
102 C_sLabel_Variables
, C_sLabel_StaticVariables
};
105 const ary::cpp::E_Protection
106 aProt
[3] = { ary::cpp::PROTECT_public
,
107 ary::cpp::PROTECT_protected
,
108 ary::cpp::PROTECT_private
};
111 PageMaker_Class::PageMaker_Class( PageDisplay
& io_rPage
,
112 const ary::cpp::Class
& i_rClass
)
113 : SpecializedPageMaker(io_rPage
),
115 pChildDisplay( new ChildList_Display(io_rPage
.Env(), i_rClass
) ),
120 int i_max
= 3 * cl_MAX
;
121 for (int i
= 0; i
< i_max
; i
++)
123 bChildLists_Exist
[i
] = false;
127 PageMaker_Class::~PageMaker_Class()
132 PageMaker_Class::MakePage()
134 pNavi
= new NavigationBar( Env(), Me() );
141 pNavi
->Write_SubRows();
146 PageMaker_Class::Write_NavBar()
148 NavigationBar
aNavi( Env(), Me() );
149 pNavi
->Write( CurOut() );
150 CurOut() << new HorizontalLine
;
154 IsInterface(const ary::doc::Documentation
& i_doc
)
157 doc
= Get_CppDocu(i_doc
);
164 PageMaker_Class::Write_TopArea()
166 TemplateClause fTemplateClause
;
167 PageTitle_Std fTitle
;
169 Page().Write_NameChainWithLinks( Me() );
171 fTemplateClause( CurOut(), Me().TemplateParameters() );
172 fTitle( CurOut(), Get_ClassTypeKey(Me()), Me().LocalName() );
174 CurOut() << new HorizontalLine
;
176 Write_BaseHierarchy();
179 CurOut() << new LineBreak
;
182 aFlags( CurOut(), 4 );
183 aFlags
.SetColumn( 0, "virtual",
184 Me().Virtuality() != ary::cpp::VIRTUAL_none
);
185 aFlags
.SetColumn( 1, "abstract",
186 Me().Virtuality() == ary::cpp::VIRTUAL_abstract
);
187 aFlags
.SetColumn( 2, "interface",
188 IsInterface(Me().Docu())
189 OR
Me().Virtuality() == ary::cpp::VIRTUAL_abstract
);
190 aFlags
.SetColumn( 3, "template",
191 Me().TemplateParameters().size() > 0 );
195 PageMaker_Class::Write_DocuArea()
197 Docu_Display
aDocuShow( Env() );
199 aDocuShow
.Assign_Out(CurOut());
200 Me().Accept( aDocuShow
);
201 aDocuShow
.Unassign_Out();
204 rFile
= Env().Gate().Locations().Find_File( Me().Location() );
206 adcdisp::ExplanationList
207 aFileText( CurOut() );
208 aFileText
.AddEntry("File");
210 << rFile
.LocalName();
212 CurOut() << new HorizontalLine
;
216 PageMaker_Class::Write_ChildLists()
218 int i_max
= 3 * cl_MAX
;
219 for (int i
= 0; i
< i_max
; i
++)
221 bChildLists_Exist
[i
] = false;
224 csi::html::DefListDefinition
&
225 rPublic
= Setup_MemberSegment_Out( mp_public
);
226 csi::html::DefListDefinition
&
227 rProtected
= Setup_MemberSegment_Out( mp_protected
);
228 csi::html::DefListDefinition
&
229 rPrivate
= Setup_MemberSegment_Out( mp_private
);
231 Write_ChildList_forClasses( rPublic
,
235 C_sTitle_InnerClasses
,
236 ary::cpp::CK_class
);
237 Write_ChildList_forClasses( rPublic
,
241 C_sTitle_InnerStructs
,
242 ary::cpp::CK_struct
);
243 Write_ChildList_forClasses( rPublic
,
247 C_sTitle_InnerUnions
,
248 ary::cpp::CK_union
);
250 Write_ChildList( ary::cpp::Class::SLOT_Enums
,
257 Write_ChildList( ary::cpp::Class::SLOT_Typedefs
,
265 Write_ChildList( ary::cpp::Class::SLOT_Operations
,
272 Write_ChildList( ary::cpp::Class::SLOT_StaticOperations
,
274 C_sLabel_StaticOperations
,
275 C_sTitle_StaticMethods
,
279 Write_ChildList( ary::cpp::Class::SLOT_Data
,
286 Write_ChildList( ary::cpp::Class::SLOT_StaticData
,
288 C_sLabel_StaticVariables
,
294 Create_NaviSubRow(mp_public
); // Also puts out or deletes pPublic.
295 Create_NaviSubRow(mp_protected
); // Also puts out or deletes pProtected.
296 Create_NaviSubRow(mp_private
); // Also puts out or deletes pPrivate.
300 PageMaker_Class::Write_ChildList( ary::SlotAccessId i_nSlot
,
301 E_ChidList i_eChildListIndex
,
302 const char * i_sLabel
,
303 const char * i_sListTitle
,
304 csi::xml::Element
& o_rPublic
,
305 csi::xml::Element
& o_rProtected
,
306 csi::xml::Element
& o_rPrivate
)
309 bool bPublic_ChildrenExist
= false;
310 bool bProtected_ChildrenExist
= false;
311 bool bPrivate_ChildrenExist
= false;
313 ChildList_Display::Area_Result
314 aPublic_Result( bPublic_ChildrenExist
, o_rPublic
);
315 ChildList_Display::Area_Result
316 aProtected_Result( bProtected_ChildrenExist
, o_rProtected
);
317 ChildList_Display::Area_Result
318 aPrivate_Result( bPrivate_ChildrenExist
, o_rPrivate
);
320 String sLabelPublic
= ChildListLabel(i_sLabel
, mp_public
);
321 String sLabelProtected
= ChildListLabel(i_sLabel
, mp_protected
);
322 String sLabelPrivate
= ChildListLabel(i_sLabel
, mp_private
);
324 pChildDisplay
->Run_Members( aPublic_Result
,
333 bChildLists_Exist
[i_eChildListIndex
]
334 = bPublic_ChildrenExist
;
335 bChildLists_Exist
[i_eChildListIndex
+ cl_MAX
]
336 = bProtected_ChildrenExist
;
337 bChildLists_Exist
[i_eChildListIndex
+ 2*cl_MAX
]
338 = bPrivate_ChildrenExist
;
340 if (bPublic_ChildrenExist
)
341 o_rPublic
<< new HorizontalLine
;
342 if (bProtected_ChildrenExist
)
343 o_rProtected
<< new HorizontalLine
;
344 if (bPrivate_ChildrenExist
)
345 o_rPrivate
<< new HorizontalLine
;
349 PageMaker_Class::Write_ChildList_forClasses( csi::xml::Element
& o_rPublic
,
350 csi::xml::Element
& o_rProtected
,
351 csi::xml::Element
& o_rPrivate
,
352 const char * i_sLabel
,
353 const char * i_sListTitle
,
354 ary::cpp::E_ClassKey i_eFilter
)
356 bool bPublic_ChildrenExist
= false;
357 bool bProtected_ChildrenExist
= false;
358 bool bPrivate_ChildrenExist
= false;
360 ChildList_Display::Area_Result
361 aPublic_Result( bPublic_ChildrenExist
, o_rPublic
);
362 ChildList_Display::Area_Result
363 aProtected_Result( bProtected_ChildrenExist
, o_rProtected
);
364 ChildList_Display::Area_Result
365 aPrivate_Result( bPrivate_ChildrenExist
, o_rPrivate
);
367 String sLabelPublic
= ChildListLabel(i_sLabel
, mp_public
);
368 String sLabelProtected
= ChildListLabel(i_sLabel
, mp_protected
);
369 String sLabelPrivate
= ChildListLabel(i_sLabel
, mp_private
);
371 pChildDisplay
->Run_MemberClasses( aPublic_Result
,
374 ary::cpp::Class::SLOT_NestedClasses
,
381 bChildLists_Exist
[int(cl_NestedClasses
)+int(i_eFilter
)]
382 = bPublic_ChildrenExist
;
383 bChildLists_Exist
[int(cl_NestedClasses
)+int(i_eFilter
) + cl_MAX
]
384 = bProtected_ChildrenExist
;
385 bChildLists_Exist
[int(cl_NestedClasses
)+int(i_eFilter
) + 2*cl_MAX
]
386 = bPrivate_ChildrenExist
;
388 if (bPublic_ChildrenExist
)
389 o_rPublic
<< new HorizontalLine
;
390 if (bProtected_ChildrenExist
)
391 o_rProtected
<< new HorizontalLine
;
392 if (bPrivate_ChildrenExist
)
393 o_rPrivate
<< new HorizontalLine
;
397 PageMaker_Class::ChildListLabel( const char * i_sLabel
, E_MemberProtection i_eMpr
)
399 static char sResult
[100];
400 strcpy( sResult
, C_sMprPrefixes
[i_eMpr
] ); // SAFE STRCPY (#100211# - checked)
401 strcat( sResult
, i_sLabel
); // SAFE STRCAT (#100211# - checked)
405 csi::html::DefListDefinition
&
406 PageMaker_Class::Setup_MemberSegment_Out( E_MemberProtection i_eMpr
)
408 html::DefList
* pDefList
= new html::DefList
;
409 pProtectionArea
[i_eMpr
] = pDefList
;
412 << new html::ClassAttr("subtitle")
413 >> *new html::Label( C_sMprPrefixes
[i_eMpr
] )
414 >> *new html::Headline(3)
415 << C_sMprTitles
[i_eMpr
];
416 return pDefList
->AddDefinition();
420 PageMaker_Class::Create_NaviSubRow( E_MemberProtection i_eMpr
)
422 int nIndexAdd
= int(cl_MAX
) * int(i_eMpr
);
425 for (int e
= 0; e
< cl_MAX
; e
++)
427 if ( bChildLists_Exist
[e
+ nIndexAdd
] )
435 pProtectionArea
[i_eMpr
] = 0;
440 CurOut() << pProtectionArea
[i_eMpr
].Release();
443 pNavi
->MakeSubRow( C_sMprSummaryTitles
[i_eMpr
] );
444 for (int i
= 0; i
< cl_MAX
; i
++)
446 pNavi
->AddItem( C_sSummaryItems_Titles
[i
],
447 ChildListLabel( C_sSummaryItems_Labels
[i
], i_eMpr
),
448 bChildLists_Exist
[i
+nIndexAdd
] );
453 PageMaker_Class::Write_DerivedList()
455 adcdisp::ExplanationList
456 aDeriveds( CurOut() );
457 aDeriveds
.AddEntry( "Known Derived Classes" );
459 if ( Me().KnownDerivatives().Size() == 0 )
461 aDeriveds
.Def() << "None.";
465 typedef ary::List_Rid RidList
;
468 itEnd
= Me().KnownDerivatives().End();
469 for ( CesConstIterator it
= Me().KnownDerivatives().Begin();
473 const ary::cpp::CodeEntity
&
474 rCe
= Env().Gate().Ces().Find_Ce(*it
);
477 >> *new html::Link( Link2Ce(Env(),rCe
) )
480 << new html::LineBreak
;
485 // ============== Creating a classes base hierarchy ====================== //
495 const ary::cpp::Class
&
497 ary::cpp::Type_id i_nClassType
,
498 const ary::cpp::Gate
&
500 intt i_nPositionOffset
,
501 Node
* io_pDerived
= 0,
502 ary::cpp::E_Protection
503 i_eProtection
= ary::cpp::PROTECT_global
,
504 bool i_bVirtual
= false );
507 void FillPositionList(
508 std::vector
< const Node
* > &
509 o_rPositionList
) const;
511 csi::xml::Element
& o_rOut
,
512 const OuputPage_Environment
&
515 intt
BaseCount() const { return nCountBases
; }
516 intt
Position() const { return nPosition
; }
517 int Xpos() const { return 3*Position(); }
518 int Ypos() const { return 2*Position(); }
519 const Node
* Derived() const { return pDerived
; }
522 typedef std::vector
< DYN Node
* > BaseList
;
524 void IncrBaseCount();
532 const ary::cpp::Class
*
534 ary::cpp::Type_id nClassType
;
535 ary::cpp::E_Protection
542 void WriteNodeHierarchy(
543 csi::xml::Element
& o_rOut
,
544 const OuputPage_Environment
&
546 const Node
& i_rClass
);
548 const ary::cpp::Class
*
550 const ary::cpp::Gate
&
552 ary::cpp::Type_id i_nReferingTypeId
);
554 } // anonymous namespace
557 PageMaker_Class::Write_BaseHierarchy()
559 adcdisp::ExplanationList
aBases( CurOut() );
560 aBases
.AddEntry( "Base Classes" );
562 if ( Me().BaseClasses().size() == 0 )
564 aBases
.Def() << "None.";
569 pBaseGraph( new Node(Me(), ary::cpp::Type_id(0), Env().Gate(), 0) );
570 WriteNodeHierarchy( aBases
.Def(), Env(), *pBaseGraph
);
580 WriteNodeHierarchy( csi::xml::Element
& o_rOut
,
581 const OuputPage_Environment
& i_rEnv
,
582 const Node
& i_rClass
)
584 typedef const Node
* NodePtr
;
585 typedef std::vector
<NodePtr
> NodeList
;
587 NodeList aPositionList
;
588 intt nSize
= i_rClass
.Position()+1;
589 aPositionList
.reserve(nSize
);
590 i_rClass
.FillPositionList( aPositionList
);
594 >> *new xml::AnElement("pre")
595 << new html::StyleAttr("font-family:monospace;");
597 for ( int line
= 0; line
< nSize
; ++line
)
599 char * sLine1
= new char[2 + line
*5];
600 char * sLine2
= new char[1 + line
*5];
604 bool bBaseForThisLineReached
= false;
605 for ( int col
= 0; col
< line
; ++col
)
607 intt nDerivPos
= aPositionList
[col
]->Derived()->Position();
609 if ( nDerivPos
>= line
)
610 strcat(sLine1
, " | ");
614 if ( nDerivPos
> line
)
616 strcat(sLine2
, " | ");
618 else if ( nDerivPos
== line
)
620 if (bBaseForThisLineReached
)
621 strcat(sLine2
, "--+--");
624 bBaseForThisLineReached
= true;
625 strcat(sLine2
, " +--");
628 else // nDerivPos < line
630 if (bBaseForThisLineReached
)
631 strcat(sLine2
, "-----");
643 aPositionList
[line
]->Write2( rPre
, i_rEnv
);
648 const ary::cpp::Class
*
649 HereFind_Class( const ary::cpp::Gate
& i_rGate
,
650 ary::cpp::Type_id i_nReferingTypeId
)
652 const ary::cpp::CodeEntity
*
653 pCe
= i_rGate
.Search_RelatedCe( i_nReferingTypeId
);
657 if ( ary::is_type
<ary::cpp::Class
>(*pCe
) )
659 return ary::ary_cast
<ary::cpp::Class
>(pCe
);
661 else if ( ary::is_type
<ary::cpp::Typedef
>(*pCe
) )
663 const ary::cpp::Typedef
*
664 pTydef
= ary::ary_cast
<ary::cpp::Typedef
>(pCe
);
665 return HereFind_Class( i_rGate
, pTydef
->DescribingType() );
669 static const ary::cpp::Class
aClassNull_( "Base class not found",
671 ary::cpp::PROTECT_global
,
673 ary::cpp::CK_class
);
679 //********************* Node ***********************//
681 Node::Node( const ary::cpp::Class
& i_rClass
,
682 ary::cpp::Type_id i_nClassType
,
683 const ary::cpp::Gate
& i_rGate
,
684 intt i_nPositionOffset
,
686 ary::cpp::E_Protection i_eProtection
,
690 pDerived(io_pDerived
),
692 nClassType(i_nClassType
),
693 eProtection(i_eProtection
),
694 bVirtual(i_bVirtual
),
695 nPosition(i_nPositionOffset
)
697 typedef ary::cpp::List_Bases BList
;
699 for ( BList::const_iterator it
= i_rClass
.BaseClasses().begin();
700 it
!= i_rClass
.BaseClasses().end();
703 const ary::cpp::Class
*
704 pBaseClass
= HereFind_Class( i_rGate
, (*it
).nId
);
707 pBase( new Node(*pBaseClass
,
713 (*it
).eVirtuality
== ary::cpp::VIRTUAL_virtual
)
716 nPosition
+= pBase
->BaseCount() + 1;
717 aBases
.push_back( pBase
.Release() );
726 Node::FillPositionList( std::vector
< const Node
* > & o_rPositionList
) const
728 for ( BaseList::const_iterator it
= aBases
.begin();
732 (*it
)->FillPositionList(o_rPositionList
);
735 if( o_rPositionList
.size() != uintt(Position()) )
739 o_rPositionList
.push_back(this);
743 Node::Write2( csi::xml::Element
& o_rOut
,
744 const OuputPage_Environment
& i_rEnv
) const
746 if ( Derived() == 0 )
749 >> *new xml::AnElement("span")
750 << new html::ClassAttr("btself")
751 << pClass
->LocalName();
756 pOut
= & ( o_rOut
>> *new xml::AnElement("span") );
757 switch ( eProtection
)
759 case ary::cpp::PROTECT_public
:
761 *pOut
<< new html::ClassAttr("btvpubl");
763 *pOut
<< new html::ClassAttr("btpubl");
765 case ary::cpp::PROTECT_protected
:
767 *pOut
<< new html::ClassAttr("btvprot");
769 *pOut
<< new html::ClassAttr("btprot");
771 case ary::cpp::PROTECT_private
:
773 *pOut
<< new html::ClassAttr("btvpriv");
775 *pOut
<< new html::ClassAttr("btpriv");
777 default: // do nothing.
781 csi::xml::Element
& rOut
= *pOut
;
783 Get_LinkedTypeText( rOut
, i_rEnv
, nClassType
, false );
787 switch ( eProtection
)
789 case ary::cpp::PROTECT_public
:
792 case ary::cpp::PROTECT_protected
:
793 rOut
<< "protected)";
795 case ary::cpp::PROTECT_private
:
798 default: // do nothing.
804 Node::IncrBaseCount()
808 pDerived
->IncrBaseCount();
812 } // anonymous namespace