2 //=============================================================================
6 * Extension of class AST_Sequence that provides additional means for C++
11 //=============================================================================
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"
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
,
39 : COMMON_Base (kt
->is_local () || vt
->is_local() || local
,
41 AST_Decl (AST_Decl::NT_map
,
44 AST_Type (AST_Decl::NT_map
,
46 AST_ConcreteType (AST_Decl::NT_map
,
52 kt
->is_local () || vt
->is_local () || local
,
54 UTL_Scope (AST_Decl::NT_map
),
55 be_scope (AST_Decl::NT_map
),
56 be_decl (AST_Decl::NT_map
,
58 be_type (AST_Decl::NT_map
,
63 this->has_constructor (true);
65 // Don't want to set any bits below for imported nodes.
66 if (this->imported ())
71 // This one gets set for all maps
72 idl_global
->map_seen_
= true;
73 idl_global
->var_size_decl_seen_
= true;
77 be_map::key_type () const
79 return dynamic_cast<be_type
*> (this->AST_Map::key_type ());
83 be_map::value_type () const
85 return dynamic_cast<be_type
*> (this->AST_Map::value_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 ();
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 ();
114 // Helper to create_name.
118 char namebuf
[NAMEBUFSIZE
];
119 be_type
*kt
= nullptr;
120 be_type
*vt
= nullptr;
123 ACE_OS::memset (namebuf
,
127 // Retrieve the base type.
128 kt
= dynamic_cast<be_type
*> (this->key_type ());
129 vt
= dynamic_cast<be_type
*> (this->value_type ());
133 ACE_ERROR_RETURN ((LM_ERROR
,
142 ACE_ERROR_RETURN ((LM_ERROR
,
149 std::snprintf (namebuf
,
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
,
160 "_" ACE_UINT32_FORMAT_SPECIFIER_ASCII
,
161 this->max_size ()->ev ()->u
.ulval
);
162 ACE_OS::strcat (namebuf
,
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.
177 dynamic_cast<UTL_ScopedName
*> (node
->name ()->copy ()));
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;
194 Identifier (namebuf
),
197 UTL_ScopedName
*conc_name
= nullptr;
198 ACE_NEW_RETURN (conc_name
,
203 // Add our local name as the last component.
204 n
->nconc (conc_name
);
206 // Set the fully scoped name.
211 // We better be not here because we must be inside some scope,
212 // at least the ROOT scope.
216 ACE::strdelete (namebuf
);
222 // Add this be_sequence to the locally defined types in this scope
224 be_map::fe_add_map (AST_Map
*t
)
231 this->add_to_local_types (t
);
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);
257 be_map::instance_name ()
263 be_map::field_node () const
265 return this->field_node_
;
269 be_map::field_node (be_field
*node
)
271 this->field_node_
= node
;
275 be_map::smart_fwd_helper_name (AST_Decl
*ctx_scope
,
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 ();
291 // Call the destroy methods of our base classes.
292 this->be_scope::destroy ();
293 this->be_type::destroy ();
294 this->AST_Map::destroy ();