xref: /AOO41X/main/autodoc/inc/ary/cpp/usedtype.hxx (revision 1c78a5d6c0093dece4c096ba53051800fbad6e33)
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 
23 
24 #ifndef ARY_CPP_USEDTYPE_HXX
25 #define ARY_CPP_USEDTYPE_HXX
26 
27 // USED SERVICES
28     // BASE CLASSES
29 #include <ary/cpp/c_type.hxx>
30     // OTHER
31 #include <ary/cpp/namechain.hxx>
32 
33 namespace ary
34 {
35 namespace cpp
36 {
37     class CePilot;
38 
39 namespace ut
40 {
41     class List_TplParameter;
42 }
43 }
44 }
45 
46 
47 
48 
49 namespace ary
50 {
51 namespace cpp
52 {
53 
54 
55 /** This class represents a type in textual form, like it is parsed out of
56     source code as a variable type or function return type.
57 */
58 class UsedType : public Type
59 {
60   public:
61     enum E_ClassId { class_id = 1203 };
62 
63     explicit            UsedType(
64                             Ce_id               i_scope );
65                         ~UsedType();
66     // OPERATORS
67     bool                operator<(
68                             const UsedType &    i_rType ) const;
69     // OPERATIONS
70 
71         // Operations to build up the used type from parsing:
72     void                Set_Absolute();         /// "::" is in front.
73     void                Add_NameSegment(
74                             const char *        i_sSeg );
75     ut::List_TplParameter &
76                         Enter_Template();
77     void                Set_Unsigned();
78     void                Set_Signed();
79     void                Set_BuiltIn(
80                             const char *        i_sType );
81     void                Set_Const();            /// Sets CV to the type or the present pointer level, whatever is highest.
82     void                Set_Volatile();         /// Sets CV to the type or the present pointer level, whatever is highest.
83     void                Add_PtrLevel();         /// For an '*'.
84     void                Set_Reference();        /// For an '&'.
85 
86         // Operations to find the relating CodeEntity:
87     /** This needs to be called only one time. After that
88         RelatedCe() will return the value.
89 
90         When connectiing all parsed types, there are three steps:
91             1. Find related types in the same scope and namespaces above.
92             2. Then all classes can be connected to their base classes.
93             3. Lastly types can be connected to Ces only known via their base
94                classes. This is not possible at step 1.
95 
96         @see Connect2CeOnlyKnownViaBaseClass()
97     */
98     void                Connect2Ce(
99                             const CePilot &     i_ces );
100 
101     /** @see Connect2Ce()
102     */
103     void                Connect2CeOnlyKnownViaBaseClass(
104                             const Gate &        i_gate );
105 
106     // INQUIRY
107     /** @return True, if type consists of one built-in typename and
108                 nothing else.
109     */
110     bool                IsBuiltInType() const;
111     /** @return the full local name, including template instantiation, but without
112         '*','&' or modifiers.
113     */
114     const String  &     LocalName() const;
115     E_TypeSpecialisation
116                         TypeSpecialisation() const;
117 
118   private:
119     // Interface csv::ConstProcessorClient
120     virtual void        do_Accept(
121                             csv::ProcessorIfc & io_processor ) const;
122 
123     // Interface ary::Object:
124     virtual ClassId     get_AryClass() const;
125 
126     // Interface ary::cpp::Type:
127     virtual Rid         inq_RelatedCe() const;
128     virtual bool        inq_IsConst() const;
129     virtual void        inq_Get_Text(
130                             StreamStr &         o_rPreName,
131                             StreamStr &         o_rName,
132                             StreamStr &         o_rPostName,
133                             const ary::cpp::Gate &
134                                                 i_rGate ) const;
135     // Local
136     typedef std::vector< ary::cpp::E_ConVol >   PtrLevelVector;
137 
PtrLevel() const138     uintt               PtrLevel() const        { return uintt(aPtrLevels.size()); }
139     Ce_id               RecursiveSearchCe_InBaseClassesOf(
140                             const CodeEntity &  i_mayBeClass,
141                             const StringVector &
142                                                 i_myQualification,
143                             const String &      i_myName,
144                             const Gate &        i_gate ) const;
145     void                Get_NameParts(
146                             StringVector &      o_qualification,
147                             String &            o_name );
148 
149     // Forbidden functions
150                         UsedType(
151                             const UsedType &    i_rType );
152     bool                operator=(
153                             const UsedType &    i_rType );
154 
155     // DATA
156     ut::NameChain       aPath;
157     PtrLevelVector      aPtrLevels;
158     ary::cpp::E_ConVol  eConVol_Type;
159     bool                bIsReference;
160     bool                bIsAbsolute;
161     bool                bRefers2BuiltInType;
162     E_TypeSpecialisation
163                         eTypeSpecialisation;
164     Ce_id               nRelatedCe;
165 
166     /// Namespace or class scope where the type occurred.
167     Ce_id               nScope;
168 };
169 
170 
171 namespace ut
172 {
173     class TemplateParameter;
174 
175 class List_TplParameter
176 {
177   public:
178     typedef std::vector< DYN TemplateParameter * >::const_iterator  const_iterator;
179 
180                         List_TplParameter();
181                         ~List_TplParameter();
182 
183     void                AddParam_Type(
184                             Type_id             i_nType );
185     /// puts "< " TemplateArgumentList " >" to o_rOut.
186     void                Get_Text(
187                             StreamStr &         o_rOut,
188                             const ary::cpp::Gate &
189                                                 i_rGate ) const;
190     /// @return as strcmp().
191     intt                Compare(
192                             const List_TplParameter &
193                                                 i_rOther ) const;
194 
195   private:
196     typedef std::vector< DYN TemplateParameter * >  Vector_TplArgument;
197 
198     Vector_TplArgument  aTplParameters;
199 };
200 
201 }   // namespace ut
202 
203 
204 
205 
206 }   // namespace cpp
207 }   // namespace ary
208 #endif
209