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 "aryattrs.hxx"
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <ary/getncast.hxx>
28 #include <ary/cpp/c_class.hxx>
29 #include <ary/cpp/c_enum.hxx>
30 #include <ary/cpp/c_funct.hxx>
31 #include <ary/cpp/c_gate.hxx>
32 #include <ary/cpp/c_namesp.hxx>
33 #include <ary/cpp/cp_ce.hxx>
34 #include <ary/cpp/cp_type.hxx>
35 #include "strconst.hxx"
36 
37 
38 
39 
40 //********************       HtmlDisplay_Impl        *********************//
41 
42 const char *
Get_ClassTypeKey(const ary::cpp::Class & i_rClass)43 Get_ClassTypeKey( const ary::cpp::Class & i_rClass )
44 {
45     return i_rClass.ClassKey() == ary::cpp::CK_class
46                             ?   C_sHFTypeTitle_Class
47                             :   i_rClass.ClassKey() == ary::cpp::CK_struct
48                                     ?   C_sHFTypeTitle_Struct
49                                     :   C_sHFTypeTitle_Union;
50 
51 }
52 
53 const char *
Get_TypeKey(const ary::cpp::CodeEntity & i_rCe)54 Get_TypeKey( const ary::cpp::CodeEntity & i_rCe )
55 {
56     if ( ary::is_type<ary::cpp::Class>(i_rCe) )
57     {
58         return Get_ClassTypeKey(
59                     ary::ary_cast<ary::cpp::Class>(i_rCe) );
60     }
61     if ( ary::is_type<ary::cpp::Enum>(i_rCe) )
62     {
63      	return "enum";
64     }
65     return "";
66 }
67 
68 bool
Ce_IsInternal(const ary::cpp::CodeEntity & i_rCe)69 Ce_IsInternal( const ary::cpp::CodeEntity & i_rCe )
70 {
71     return NOT i_rCe.IsVisible();
72 }
73 
74 const char *
SyntaxText_PreName(const ary::cpp::Function & i_rFunction,const ary::cpp::Gate & i_rAryGate)75 SyntaxText_PreName( const ary::cpp::Function &      i_rFunction,
76                     const ary::cpp::Gate &   i_rAryGate )
77 {
78     static StreamStr  sResult( 150 );
79     sResult.seekp(0);
80 
81     // write pre-name:
82     const ary::cpp::FunctionFlags & rFlags = i_rFunction.Flags();
83     if ( rFlags.IsStaticLocal() OR rFlags.IsStaticMember() )
84         sResult << "static ";
85     if ( rFlags.IsExplicit() )
86         sResult << "explicit ";
87     if ( rFlags.IsMutable() )
88         sResult << "mutable ";
89     if ( i_rFunction.Virtuality() != ary::cpp::VIRTUAL_none )
90         sResult << "virtual ";
91     i_rAryGate.Types().Get_TypeText( sResult, i_rFunction.ReturnType() );
92     sResult << " ";
93 
94     return sResult.c_str();
95 }
96 
97 const char *
SyntaxText_PostName(const ary::cpp::Function & i_rFunction,const ary::cpp::Gate & i_rAryGate)98 SyntaxText_PostName( const ary::cpp::Function &     i_rFunction,
99                      const ary::cpp::Gate &  i_rAryGate )
100 {
101     static StreamStr  sResult( 850 );
102     sResult.seekp(0);
103 
104     // parameters and con_vol
105     i_rAryGate.Ces().Get_SignatureText( sResult, i_rFunction.Signature(), &i_rFunction.ParamInfos() );
106 
107     // write Exceptions:
108     const std::vector< ary::cpp::Type_id > *
109             pThrow = i_rFunction.Exceptions();
110     if ( pThrow)
111     {
112 
113         std::vector< ary::cpp::Type_id >::const_iterator
114 		    	it = pThrow->begin();
115         std::vector< ary::cpp::Type_id >::const_iterator
116 	    		it_end = pThrow->end();
117 
118         if (it != it_end)
119         {
120             sResult << " throw( ";
121             i_rAryGate.Types().Get_TypeText(sResult, *it);
122 
123             for ( ++it; it != it_end; ++it )
124             {
125                 sResult << ", ";
126                 i_rAryGate.Types().Get_TypeText(sResult, *it);
127             }
128             sResult << " )";
129         }
130         else
131         {
132             sResult << " throw( )";
133         }
134     }   // endif // pThrow
135 
136     // abstractness:
137     if ( i_rFunction.Virtuality() == ary::cpp::VIRTUAL_abstract )
138         sResult << " = 0";
139 
140     // finish:
141     sResult << ";";
142 
143     return sResult.c_str();
144 }
145 
146 bool
Get_TypeText(const char * & o_rPreName,const char * & o_rName,const char * & o_rPostName,ary::cpp::Type_id i_nTypeid,const ary::cpp::Gate & i_rAryGate)147 Get_TypeText( const char * &                o_rPreName,
148               const char * &                o_rName,
149               const char * &                o_rPostName,
150               ary::cpp::Type_id             i_nTypeid,
151               const ary::cpp::Gate & i_rAryGate )
152 {
153     static StreamStr       sResult_PreName(250);
154     static StreamStr       sResult_Name(250);
155     static StreamStr       sResult_PostName(250);
156 
157     sResult_PreName.seekp(0);
158     sResult_Name.seekp(0);
159     sResult_PostName.seekp(0);
160 
161     bool    ret = i_rAryGate.Types().Get_TypeText(
162                                 sResult_PreName,
163                                 sResult_Name,
164                                 sResult_PostName,
165                                 i_nTypeid );
166     if ( sResult_PreName.tellp() > 0 )
167     {
168         char cLast = *( sResult_PreName.c_str() + (sResult_PreName.tellp() - 1) );
169         if (cLast != ':' AND cLast != ' ')
170             sResult_PreName << " ";
171     }
172 
173 
174     if (ret)
175     {
176         o_rPreName  = sResult_PreName.c_str();
177         o_rName     = sResult_Name.c_str();
178         o_rPostName = sResult_PostName.c_str();
179     }
180     else
181     {
182         o_rPreName  =  o_rName =  o_rPostName = "";
183     }
184     return ret;
185 }
186 
187 
188 
189 
190 //*********************         FunctionParam_Iterator      *****************//
191 
192 
FunctionParam_Iterator()193 FunctionParam_Iterator::FunctionParam_Iterator()
194     :   // itTypes
195         // itTypes_end
196         // itNames_andMore
197         // itNames_andMore_end
198         eConVol(ary::cpp::CONVOL_none)
199 {
200     static std::vector<ary::cpp::Type_id>   aTypesNull_;
201     static StringVector                     aNamesNull_;
202 
203     itTypes = itTypes_end = aTypesNull_.end();
204     itNames_andMore = itNames_andMore_end = aNamesNull_.end();
205 }
206 
~FunctionParam_Iterator()207 FunctionParam_Iterator::~FunctionParam_Iterator()
208 {
209 }
210 
211 FunctionParam_Iterator &
operator ++()212 FunctionParam_Iterator::operator++()
213 {
214     if ( IsValid() )
215     {
216         ++itTypes;
217         ++itNames_andMore;
218     }
219     return *this;
220 }
221 
222 void
Assign(const ary::cpp::Function & i_rFunction)223 FunctionParam_Iterator::Assign( const ary::cpp::Function &  i_rFunction )
224 {
225     const ary::cpp::OperationSignature &
226         rSigna = i_rFunction.Signature();
227 
228     const std::vector<ary::cpp::Type_id> &
229         rTypes = rSigna.Parameters();
230     const StringVector &
231         rNames = i_rFunction.ParamInfos();
232 
233     if ( rTypes.size() != rNames.size() OR rTypes.size() == 0 )
234         return;
235 
236     itTypes     = rTypes.begin();
237     itTypes_end = rTypes.end();
238     itNames_andMore     = rNames.begin();
239     itNames_andMore_end = rNames.end();
240 
241     eConVol = rSigna.ConVol();
242 }
243