Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / TAO_IDL / be / be_map.cpp
blobf51439c7ea22c0c68287480d2e0f0a92bcecb7c8
2 //=============================================================================
3 /**
4 * @file be_map.cpp
6 * Extension of class AST_Sequence that provides additional means for C++
7 * mapping.
9 * @author Tyler Mayoff
11 //=============================================================================
13 #include "be_map.h"
14 #include "ast_decl.h"
15 #include "ast_predefined_type.h"
16 #include "be_typedef.h"
17 #include "be_interface.h"
18 #include "be_interface_fwd.h"
19 #include "be_predefined_type.h"
20 #include "be_field.h"
21 #include "be_string.h"
22 #include "be_visitor.h"
23 #include "be_helper.h"
24 #include "be_extern.h"
26 #include "utl_identifier.h"
27 #include "idl_defines.h"
28 #include "nr_extern.h"
29 #include "global_extern.h"
31 #include "ace/Log_Msg.h"
33 be_map::be_map (AST_Expression *v,
34 AST_Type *kt,
35 AST_Type *vt,
36 UTL_ScopedName *n,
37 bool local,
38 bool abstract)
39 : COMMON_Base (kt->is_local () || vt->is_local() || local,
40 abstract),
41 AST_Decl (AST_Decl::NT_map,
43 true),
44 AST_Type (AST_Decl::NT_map,
45 n),
46 AST_ConcreteType (AST_Decl::NT_map,
47 n),
48 AST_Map (v,
49 kt,
50 vt,
52 kt->is_local () || vt->is_local () || local,
53 abstract),
54 UTL_Scope (AST_Decl::NT_map),
55 be_scope (AST_Decl::NT_map),
56 be_decl (AST_Decl::NT_map,
57 n),
58 be_type (AST_Decl::NT_map,
59 n),
60 field_node_ (nullptr)
62 // Always the case.
63 this->has_constructor (true);
65 // Don't want to set any bits below for imported nodes.
66 if (this->imported ())
68 return;
71 // This one gets set for all maps
72 idl_global->map_seen_ = true;
73 idl_global->var_size_decl_seen_ = true;
76 be_type *
77 be_map::key_type () const
79 return dynamic_cast<be_type*> (this->AST_Map::key_type ());
82 be_type *
83 be_map::value_type () const
85 return dynamic_cast<be_type*> (this->AST_Map::value_type ());
88 be_type *
89 be_map::primitive_key_type () const
91 be_type *type_node = key_type ();
92 if (type_node && type_node->node_type () == AST_Decl::NT_typedef)
94 be_typedef *const typedef_node = dynamic_cast<be_typedef *> (type_node);
95 if (!typedef_node) return nullptr;
96 type_node = typedef_node->primitive_base_type ();
98 return type_node;
101 be_type *
102 be_map::primitive_value_type () const
104 be_type *type_node = value_type ();
105 if (type_node && type_node->node_type () == AST_Decl::NT_typedef)
107 be_typedef *const typedef_node = dynamic_cast<be_typedef *> (type_node);
108 if (!typedef_node) return nullptr;
109 type_node = typedef_node->primitive_base_type ();
111 return type_node;
114 // Helper to create_name.
115 char *
116 be_map::gen_name ()
118 char namebuf [NAMEBUFSIZE];
119 be_type *kt = nullptr;
120 be_type *vt = nullptr;
122 // Reset the buffer.
123 ACE_OS::memset (namebuf,
124 '\0',
125 NAMEBUFSIZE);
127 // Retrieve the base type.
128 kt = dynamic_cast<be_type*> (this->key_type ());
129 vt = dynamic_cast<be_type*> (this->value_type ());
131 if (kt == nullptr)
133 ACE_ERROR_RETURN ((LM_ERROR,
134 "(%N:%l) be_map::"
135 "gen_name - "
136 "bad key type\n"),
140 if (kt == nullptr)
142 ACE_ERROR_RETURN ((LM_ERROR,
143 "(%N:%l) be_map::"
144 "gen_name - "
145 "bad value type\n"),
149 std::snprintf (namebuf,
150 NAMEBUFSIZE,
151 "_tao_map_%s_%s_",
152 kt->flat_name (), vt->flat_name ());
154 // Append the size (if any).
155 if (this->unbounded () == false)
157 char ulval_str [NAMEBUFSIZE];
158 std::snprintf (ulval_str,
159 NAMEBUFSIZE,
160 "_" ACE_UINT32_FORMAT_SPECIFIER_ASCII,
161 this->max_size ()->ev ()->u.ulval);
162 ACE_OS::strcat (namebuf,
163 ulval_str);
166 return ACE::strnew (namebuf);
169 // Create a name for ourselves.
171 be_map::create_name (be_typedef *node)
173 // If there is a typedef node, we use its name as our name.
174 if (node)
176 this->set_name (
177 dynamic_cast<UTL_ScopedName *> (node->name ()->copy ()));
179 else
181 // Generate a local name.
182 char *namebuf = this->gen_name ();
184 // Now see if we have a fully scoped name and if so, generate one.
185 be_decl *const scope = dynamic_cast<be_scope*> (defined_in ())->decl ();
187 if (scope != nullptr)
189 // Make a copy of the enclosing scope's name.
190 UTL_ScopedName *const n = static_cast<UTL_ScopedName *> (scope->name ()->copy ());
192 Identifier *id = nullptr;
193 ACE_NEW_RETURN (id,
194 Identifier (namebuf),
195 -1);
197 UTL_ScopedName *conc_name = nullptr;
198 ACE_NEW_RETURN (conc_name,
199 UTL_ScopedName (id,
200 nullptr),
201 -1);
203 // Add our local name as the last component.
204 n->nconc (conc_name);
206 // Set the fully scoped name.
207 this->set_name (n);
209 else
211 // We better be not here because we must be inside some scope,
212 // at least the ROOT scope.
213 return -1;
216 ACE::strdelete (namebuf);
219 return 0;
222 // Add this be_sequence to the locally defined types in this scope
223 AST_Map *
224 be_map::fe_add_map (AST_Map *t)
226 if (t == nullptr)
228 return nullptr;
231 this->add_to_local_types (t);
232 return t;
235 // Overridden method
236 be_decl *
237 be_map::decl ()
239 return this;
242 // Overridden method
243 void
244 be_map::gen_ostream_operator (TAO_OutStream * /*os*/,
245 bool /* use_underscore */)
250 be_map::accept (be_visitor *visitor)
252 return visitor->visit_map (this);
256 const char *
257 be_map::instance_name ()
259 return "";
262 be_field *
263 be_map::field_node () const
265 return this->field_node_;
268 void
269 be_map::field_node (be_field *node)
271 this->field_node_ = node;
274 const char *
275 be_map::smart_fwd_helper_name (AST_Decl *ctx_scope,
276 be_type *elem)
278 if (ScopeAsDecl (elem->defined_in ()) == ctx_scope)
280 ACE_CString retval = "tao_";
281 retval += elem->local_name ()->get_string ();
282 return retval.rep ();
285 return elem->fwd_helper_name ();
288 void
289 be_map::destroy ()
291 // Call the destroy methods of our base classes.
292 this->be_scope::destroy ();
293 this->be_type::destroy ();
294 this->AST_Map::destroy ();