1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include <precomp.h>
23 #include "hd_chlst.hxx"
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <ary/ceslot.hxx>
28 #include <ary/cpp/c_gate.hxx>
29 #include <ary/cpp/c_namesp.hxx>
30 #include <ary/cpp/c_class.hxx>
31 #include <ary/cpp/c_enum.hxx>
32 #include <ary/cpp/c_tydef.hxx>
33 #include <ary/cpp/c_funct.hxx>
34 #include <ary/cpp/c_vari.hxx>
35 #include <ary/cpp/c_enuval.hxx>
36 #include <ary/loc/loc_file.hxx>
37 #include <ary/loc/locp_le.hxx>
38 #include <ary/doc/d_oldcppdocu.hxx>
39 #include <ary/info/ci_attag.hxx>
40 #include <ary/info/ci_text.hxx>
41 #include <ary/info/all_dts.hxx>
42 #include "hd_docu.hxx"
43 #include "opageenv.hxx"
44 #include "protarea.hxx"
45 #include "strconst.hxx"
46 
47 
48 using namespace csi;
49 using html::Table;
50 using html::TableRow;
51 using html::TableCell;
52 using html::Font;
53 using html::SizeAttr;
54 using html::BgColorAttr;
55 using html::WidthAttr;
56 
57 
58 const int   ixPublic = 0;
59 const int   ixProtected = 1;
60 const int   ixPrivate = 2;
61 
62 struct ChildList_Display::S_AreaCo
63 {
64   public:
65     ProtectionArea      aArea;
66     Area_Result *       pResult;
67 
68                         S_AreaCo(
69                             Area_Result &       o_rResult,
70                             const char *        i_sLabel,
71                             const char *        i_sTitle );
72                         ~S_AreaCo();
73 
74     void                PerformResult();
75 
76   private:
OutChildList_Display::S_AreaCo77     csi::xml::Element & Out()                   { return pResult->rOut; }
78 };
79 
80 
81 const ary::info::DocuText &
ShortDocu(const ary::cpp::CodeEntity & i_rCe)82 ShortDocu( const ary::cpp::CodeEntity & i_rCe )
83 {
84     static const ary::info::DocuText
85         aNull_;
86 
87     const ary::doc::OldCppDocu *
88             pInfo = dynamic_cast< const ary::doc::OldCppDocu* >( i_rCe.Docu().Data() );
89     if (pInfo == 0)
90         return aNull_;
91 
92     return pInfo->Short().CText();
93 }
94 
95 
ChildList_Display(OuputPage_Environment & io_rEnv)96 ChildList_Display::ChildList_Display( OuputPage_Environment & io_rEnv )
97     :   HtmlDisplay_Impl( io_rEnv ),
98         pShortDocu_Display( new Docu_Display(io_rEnv) ),
99         pActiveParentClass(0),
100         pActiveParentEnum(0),
101         // pSglArea,
102         // aMemberAreas,
103         peClassesFilter(0)
104 {
105 }
106 
ChildList_Display(OuputPage_Environment & io_rEnv,const ary::cpp::Class & i_rClass)107 ChildList_Display::ChildList_Display( OuputPage_Environment & io_rEnv,
108                                       const ary::cpp::Class & i_rClass )
109     :   HtmlDisplay_Impl( io_rEnv ),
110         pShortDocu_Display( new Docu_Display(io_rEnv) ),
111         pActiveParentClass(&i_rClass),
112         pActiveParentEnum(0),
113         // pSglArea,
114         // aMemberAreas,
115         peClassesFilter(0)
116 {
117 }
118 
ChildList_Display(OuputPage_Environment & io_rEnv,const ary::cpp::Enum & i_rEnum)119 ChildList_Display::ChildList_Display( OuputPage_Environment & io_rEnv,
120                                       const ary::cpp::Enum &  i_rEnum )
121     :   HtmlDisplay_Impl( io_rEnv ),
122         pShortDocu_Display( new Docu_Display(io_rEnv) ),
123         pActiveParentClass(0),
124         pActiveParentEnum(&i_rEnum),
125         // pSglArea,
126         // aMemberAreas,
127         peClassesFilter(0)
128 {
129 }
130 
~ChildList_Display()131 ChildList_Display::~ChildList_Display()
132 {
133 }
134 
135 void
Run_Simple(Area_Result & o_rResult,ary::SlotAccessId i_nSlot,const char * i_sListLabel,const char * i_sListTitle)136 ChildList_Display::Run_Simple( Area_Result &       o_rResult,
137                                ary::SlotAccessId   i_nSlot,
138                                const char *        i_sListLabel,
139                                const char *        i_sListTitle )
140 {
141 	ary::Slot_AutoPtr
142             pSlot( ActiveParent().Create_Slot( i_nSlot ) );
143     if ( pSlot->Size() == 0 )
144         return;
145 
146     pSglArea = new S_AreaCo( o_rResult,
147                              i_sListLabel,
148                              i_sListTitle );
149 
150     pSlot->StoreAt(*this);
151 
152     pSglArea->PerformResult();
153     pSglArea = 0;
154 }
155 
156 void
Run_GlobalClasses(Area_Result & o_rResult,ary::SlotAccessId i_nSlot,const char * i_sListLabel,const char * i_sListTitle,ary::cpp::E_ClassKey i_eFilter)157 ChildList_Display::Run_GlobalClasses( Area_Result &        o_rResult,
158                                       ary::SlotAccessId    i_nSlot,
159                                       const char *         i_sListLabel,
160                                       const char *         i_sListTitle,
161                                       ary::cpp::E_ClassKey i_eFilter )
162 {
163 	ary::Slot_AutoPtr
164             pSlot( ActiveParent().Create_Slot( i_nSlot ) );
165     if ( pSlot->Size() == 0 )
166         return;
167 
168     pSglArea = new S_AreaCo( o_rResult,
169                              i_sListLabel,
170                              i_sListTitle );
171 
172     SetClassesFilter(i_eFilter);
173     pSlot->StoreAt(*this);
174     UnsetClassesFilter();
175 
176     pSglArea->PerformResult();
177     pSglArea = 0;
178 }
179 
180 void
Run_Members(Area_Result & o_rResult_public,Area_Result & o_rResult_protected,Area_Result & o_rResult_private,ary::SlotAccessId i_nSlot,const char * i_sListLabel_public,const char * i_sListLabel_protected,const char * i_sListLabel_private,const char * i_sListTitle)181 ChildList_Display::Run_Members( Area_Result &           o_rResult_public,
182                                 Area_Result &           o_rResult_protected,
183                                 Area_Result &           o_rResult_private,
184                                 ary::SlotAccessId       i_nSlot,
185                                 const char *            i_sListLabel_public,
186                                 const char *            i_sListLabel_protected,
187                                 const char *            i_sListLabel_private,
188                                 const char *            i_sListTitle )
189 {
190 	ary::Slot_AutoPtr
191             pSlot( ActiveParent().Create_Slot(i_nSlot) );
192     if ( pSlot->Size() == 0 )
193         return;
194 
195     aMemberAreas[ixPublic] = new S_AreaCo( o_rResult_public,
196                                          i_sListLabel_public,
197                                          i_sListTitle );
198     aMemberAreas[ixProtected] = new S_AreaCo( o_rResult_protected,
199                                             i_sListLabel_protected,
200                                             i_sListTitle );
201     aMemberAreas[ixPrivate] = new S_AreaCo( o_rResult_private,
202                                           i_sListLabel_private,
203                                           i_sListTitle );
204 
205     pSlot->StoreAt(*this);
206 
207     aMemberAreas[ixPublic]->PerformResult();
208     aMemberAreas[ixProtected]->PerformResult();
209     aMemberAreas[ixPrivate]->PerformResult();
210 
211     aMemberAreas[ixPublic] = 0;
212     aMemberAreas[ixProtected] = 0;
213     aMemberAreas[ixPrivate] = 0;
214 }
215 
216 void
Run_MemberClasses(Area_Result & o_rResult_public,Area_Result & o_rResult_protected,Area_Result & o_rResult_private,ary::SlotAccessId i_nSlot,const char * i_sListLabel_public,const char * i_sListLabel_protected,const char * i_sListLabel_private,const char * i_sListTitle,ary::cpp::E_ClassKey i_eFilter)217 ChildList_Display::Run_MemberClasses( Area_Result &         o_rResult_public,
218                                       Area_Result &         o_rResult_protected,
219                                       Area_Result &         o_rResult_private,
220                                       ary::SlotAccessId     i_nSlot,
221                                       const char *          i_sListLabel_public,
222                                       const char *          i_sListLabel_protected,
223                                       const char *          i_sListLabel_private,
224                                       const char *          i_sListTitle,
225                                       ary::cpp::E_ClassKey  i_eFilter )
226 {
227 	ary::Slot_AutoPtr
228             pSlot( ActiveParent().Create_Slot(i_nSlot) );
229     if ( pSlot->Size() == 0 )
230         return;
231 
232     aMemberAreas[ixPublic] = new S_AreaCo( o_rResult_public,
233                                            i_sListLabel_public,
234                                            i_sListTitle );
235     aMemberAreas[ixProtected] = new S_AreaCo( o_rResult_protected,
236                                               i_sListLabel_protected,
237                                               i_sListTitle );
238     aMemberAreas[ixPrivate] = new S_AreaCo( o_rResult_private,
239                                             i_sListLabel_private,
240                                             i_sListTitle );
241 
242     SetClassesFilter(i_eFilter);
243     pSlot->StoreAt(*this);
244     UnsetClassesFilter();
245 
246     aMemberAreas[ixPublic]->PerformResult();
247     aMemberAreas[ixProtected]->PerformResult();
248     aMemberAreas[ixPrivate]->PerformResult();
249 
250     aMemberAreas[ixPublic] = 0;
251     aMemberAreas[ixProtected] = 0;
252     aMemberAreas[ixPrivate] = 0;
253 }
254 
255 void
do_Process(const ary::cpp::Namespace & i_rData)256 ChildList_Display::do_Process( const ary::cpp::Namespace & i_rData )
257 {
258     Write_ListItem( i_rData.LocalName(),
259                     Path2ChildNamespace(i_rData.LocalName()),
260                     ShortDocu( i_rData ),
261                     GetArea().GetTable() );
262 }
263 
264 void
do_Process(const ary::cpp::Class & i_rData)265 ChildList_Display::do_Process( const ary::cpp::Class & i_rData )
266 {
267     if ( Ce_IsInternal(i_rData) )
268         return;
269 
270     if (peClassesFilter)
271     {
272      	if (*peClassesFilter != i_rData.ClassKey() )
273             return;
274     }
275 
276     String  sLink;
277     if ( i_rData.Protection() == ary::cpp::PROTECT_global )
278     {
279         sLink = ClassFileName(i_rData.LocalName());
280 
281     }
282     else
283     {
284         csv_assert( pActiveParentClass != 0 );
285         sLink = Path2Child( ClassFileName(i_rData.LocalName()), pActiveParentClass->LocalName() );
286     }
287 
288     if (peClassesFilter)
289     {
290         Write_ListItem( i_rData.LocalName(),
291                         sLink,
292                         ShortDocu( i_rData ),
293                         GetArea(i_rData.Protection())
294                             .GetTable() );
295     }
296     else
297     {
298         Write_ListItem( i_rData.LocalName(),
299                         sLink,
300                         ShortDocu( i_rData ),
301                         GetArea(i_rData.Protection())
302                             .GetTable(i_rData.ClassKey()) );
303     }
304 }
305 
306 void
do_Process(const ary::cpp::Enum & i_rData)307 ChildList_Display::do_Process( const ary::cpp::Enum & i_rData )
308 {
309     if ( Ce_IsInternal(i_rData) )
310         return;
311 
312     String  sLink;
313     if ( i_rData.Protection() == ary::cpp::PROTECT_global )
314     {
315         sLink = EnumFileName(i_rData.LocalName());
316     }
317     else
318     {
319         csv_assert( pActiveParentClass != 0 );
320         sLink = Path2Child( EnumFileName(i_rData.LocalName()),
321                             pActiveParentClass->LocalName() );
322     }
323 
324     Write_ListItem( i_rData.LocalName(),
325                     sLink,
326                     ShortDocu( i_rData ),
327                     GetArea(i_rData.Protection()).GetTable() );
328 }
329 
330 void
do_Process(const ary::cpp::Typedef & i_rData)331 ChildList_Display::do_Process( const ary::cpp::Typedef & i_rData )
332 {
333     if ( Ce_IsInternal(i_rData) )
334         return;
335 
336     String  sLink;
337     if ( i_rData.Protection() == ary::cpp::PROTECT_global )
338     {
339         sLink = TypedefFileName(i_rData.LocalName());
340     }
341     else
342     {
343         csv_assert( pActiveParentClass != 0 );
344         sLink = Path2Child( TypedefFileName(i_rData.LocalName()),
345                             pActiveParentClass->LocalName() );
346     }
347 
348     Write_ListItem( i_rData.LocalName(),
349                     sLink,
350                     ShortDocu( i_rData ),
351                     GetArea(i_rData.Protection()).GetTable() );
352 }
353 
354 void
do_Process(const ary::cpp::Function & i_rData)355 ChildList_Display::do_Process( const ary::cpp::Function & i_rData )
356 {
357     if ( Ce_IsInternal(i_rData) )
358         return;
359 
360     String  sLinkPrePath;
361     if ( i_rData.Protection() == ary::cpp::PROTECT_global )
362     {
363         const ary::loc::File &
364                 rFile = Env().Gate().Locations().Find_File( i_rData.Location() );
365         sLinkPrePath = HtmlFileName( "o-", rFile.LocalName() );
366     }
367     else
368     {
369         csv_assert( pActiveParentClass != 0 );
370         sLinkPrePath = Path2Child( HtmlFileName( "o", "" ),
371                                    pActiveParentClass->LocalName() );
372     }
373 
374     // Out
375     Table & rOut = GetArea(i_rData.Protection()).GetTable();
376     TableRow * dpRow = new TableRow;
377     rOut << dpRow;
378     TableCell & rCell1 = dpRow->AddCell();
379 
380     rCell1
381         << SyntaxText_PreName( i_rData, Env().Gate() )
382         << new html::LineBreak;
383     rCell1
384         >> *new html::Link( OperationLink(
385                                 Env().Gate(),
386                                 i_rData.LocalName(),
387                                 i_rData.CeId(),
388                                 sLinkPrePath) )
389             << i_rData.LocalName();
390     rCell1
391         << SyntaxText_PostName( i_rData, Env().Gate() );
392     TableCell &
393         rCell2 = dpRow->AddCell();
394     rCell2
395         << new WidthAttr("50%")
396         << " ";
397 
398     pShortDocu_Display->Assign_Out( rCell2 );
399     ShortDocu( i_rData ).StoreAt( *pShortDocu_Display );
400     pShortDocu_Display->Unassign_Out();
401 }
402 
403 void
do_Process(const ary::cpp::Variable & i_rData)404 ChildList_Display::do_Process( const ary::cpp::Variable & i_rData )
405 {
406     if ( Ce_IsInternal(i_rData) )
407         return;
408 
409     String  sLinkPrePath;
410     if ( i_rData.Protection() == ary::cpp::PROTECT_global )
411     {
412         const ary::loc::File &
413             rFile = Env().Gate().Locations().Find_File( i_rData.Location() );
414         sLinkPrePath = HtmlFileName( "d-", rFile.LocalName() );
415     }
416     else
417     {
418         csv_assert( pActiveParentClass != 0 );
419         sLinkPrePath = Path2Child( HtmlFileName( "d", "" ),
420                                    pActiveParentClass->LocalName() );
421     }
422 
423     TableRow * dpRow = new TableRow;
424     GetArea(i_rData.Protection()).GetTable() << dpRow;
425 
426     *dpRow << new html::BgColorAttr("white");
427     csi::xml::Element &
428         rCell1 = dpRow->AddCell();
429 
430     dshelp::Get_LinkedTypeText( rCell1, Env(), i_rData.Type() );
431     rCell1
432         << " "
433         >> *new html::Link( DataLink(i_rData.LocalName(), sLinkPrePath.c_str()) )
434             >> *new html::Strong
435                 << i_rData.LocalName()
436                 << ";";
437 
438     TableCell & rShortDocu = dpRow->AddCell();
439     pShortDocu_Display->Assign_Out( rShortDocu );
440     ShortDocu( i_rData ).StoreAt( *pShortDocu_Display );
441     pShortDocu_Display->Unassign_Out();
442 }
443 
444 void
do_Process(const ary::cpp::EnumValue & i_rData)445 ChildList_Display::do_Process( const ary::cpp::EnumValue & i_rData )
446 {
447     if ( Ce_IsInternal(i_rData) )
448         return;
449 
450     Table & rOut = GetArea().GetTable();
451 
452     TableRow * dpRow = new TableRow;
453     rOut << dpRow;
454 
455     *dpRow << new html::BgColorAttr("white");
456     dpRow->AddCell()
457         << new WidthAttr("20%")
458         << new xml::AnAttribute("valign", "top")
459         >> *new html::Label(i_rData.LocalName())
460             >> *new html::Bold
461                 << i_rData.LocalName();
462 
463     TableCell & rValueDocu = dpRow->AddCell();
464     pShortDocu_Display->Assign_Out( rValueDocu );
465     i_rData.Docu().Accept( *pShortDocu_Display );
466     pShortDocu_Display->Unassign_Out();
467 }
468 
469 void
do_StartSlot()470 ChildList_Display::do_StartSlot()
471 {
472 }
473 
474 void
do_FinishSlot()475 ChildList_Display::do_FinishSlot()
476 {
477 }
478 
479 const ary::cpp::Gate *
inq_Get_ReFinder() const480 ChildList_Display::inq_Get_ReFinder() const
481 {
482     return & Env().Gate();
483 }
484 
485 void
Write_ListItem(const String & i_sLeftText,const char * i_sLink,const ary::info::DocuText & i_rRightText,csi::xml::Element & o_rOut)486 ChildList_Display::Write_ListItem( const String &               i_sLeftText,
487                                    const char *                 i_sLink,
488                                    const ary::info::DocuText &  i_rRightText,
489                                    csi::xml::Element &          o_rOut )
490 {
491     TableRow * dpRow = new TableRow;
492     o_rOut << dpRow;
493 
494     *dpRow << new html::BgColorAttr("white");
495     dpRow->AddCell()
496         << new WidthAttr("20%")
497         >> *new html::Link( i_sLink )
498                 >> *new html::Bold
499                         << i_sLeftText;
500 
501     TableCell & rShortDocu = dpRow->AddCell();
502     pShortDocu_Display->Assign_Out( rShortDocu );
503     i_rRightText.StoreAt( *pShortDocu_Display );
504     pShortDocu_Display->Unassign_Out();
505 }
506 
507 const ary::AryGroup &
ActiveParent()508 ChildList_Display::ActiveParent()
509 {
510     return pActiveParentClass != 0
511                 ?   static_cast< const ary::AryGroup& >(*pActiveParentClass)
512                 :   pActiveParentEnum != 0
513                         ?   static_cast< const ary::AryGroup& >(*pActiveParentEnum)
514                         :   static_cast< const ary::AryGroup& >(*Env().CurNamespace());
515 }
516 
517 ProtectionArea &
GetArea()518 ChildList_Display::GetArea()
519 {
520     return pSglArea->aArea;
521 }
522 
523 ProtectionArea &
GetArea(ary::cpp::E_Protection i_eProtection)524 ChildList_Display::GetArea( ary::cpp::E_Protection i_eProtection )
525 {
526     switch ( i_eProtection )
527     {
528      	case ary::cpp::PROTECT_public:
529                         return aMemberAreas[ixPublic]->aArea;
530      	case ary::cpp::PROTECT_protected:
531                         return aMemberAreas[ixProtected]->aArea;
532      	case ary::cpp::PROTECT_private:
533                         return aMemberAreas[ixPrivate]->aArea;
534         default:
535                         return pSglArea->aArea;
536     }
537 }
538 
539 
540 //*******************               ********************//
541 
542 ChildList_Display::
S_AreaCo(Area_Result & o_rResult,const char * i_sLabel,const char * i_sTitle)543 S_AreaCo::S_AreaCo( Area_Result &       o_rResult,
544                     const char *        i_sLabel,
545                     const char *        i_sTitle )
546     :   aArea(i_sLabel, i_sTitle),
547         pResult(&o_rResult)
548 {
549 }
550 
551 ChildList_Display::
~S_AreaCo()552 S_AreaCo::~S_AreaCo()
553 {
554 }
555 
556 void
557 ChildList_Display::
PerformResult()558 S_AreaCo::PerformResult()
559 {
560     bool bUsed = aArea.WasUsed_Area();
561     pResult->rChildrenExist = bUsed;
562     if ( bUsed )
563     {
564         Create_ChildListLabel( Out(), aArea.Label() );
565 
566         if ( aArea.Size() == 1 )
567         {
568             Out() << aArea.ReleaseTable();
569         }
570         else
571         {
572          	Table * pTable = aArea.ReleaseTable( ary::cpp::CK_class );
573             if (pTable != 0)
574                 Out() << pTable;
575          	pTable = aArea.ReleaseTable( ary::cpp::CK_struct );
576             if (pTable != 0)
577                 Out() << pTable;
578          	pTable = aArea.ReleaseTable( ary::cpp::CK_union );
579             if (pTable != 0)
580                 Out() << pTable;
581         }
582     }
583 }
584