Update bug_report.md
[ACE_TAO.git] / TAO / TAO_IDL / be / be_identifier_helper.cpp
blob72c848882b1dea58224e2ffd6730695d12b5a99e
1 /* -*- c++ -*- */
2 #include "be_identifier_helper.h"
3 #include "be_type.h"
5 #include "utl_identifier.h"
6 #include "utl_string.h"
7 #include "fe_private.h"
8 #include "global_extern.h"
10 ACE_CString IdentifierHelper::tmp_retval_;
12 const char *
13 IdentifierHelper::type_name (be_type *t, be_visitor *visitor)
15 AST_PredefinedType *pdt = nullptr;
17 switch (t->node_type ())
19 case AST_Decl::NT_sequence:
20 case AST_Decl::NT_wstring:
21 case AST_Decl::NT_string:
22 (void) t->accept (visitor);
23 return "";
24 case AST_Decl::NT_pre_defined:
25 pdt = dynamic_cast<AST_PredefinedType*> (t);
27 switch (pdt->pt ())
29 case AST_PredefinedType::PT_pseudo:
30 return t->full_name ();
31 case AST_PredefinedType::PT_object:
32 return "Object";
33 case AST_PredefinedType::PT_any:
34 return "any";
35 case AST_PredefinedType::PT_long:
36 return "long";
37 case AST_PredefinedType::PT_ulong:
38 return "unsigned long";
39 case AST_PredefinedType::PT_longlong:
40 return "long long";
41 case AST_PredefinedType::PT_ulonglong:
42 return "unsigned long long";
43 case AST_PredefinedType::PT_short:
44 return "short";
45 case AST_PredefinedType::PT_ushort:
46 return "unsigned short";
47 case AST_PredefinedType::PT_float:
48 return "float";
49 case AST_PredefinedType::PT_double:
50 return "double";
51 case AST_PredefinedType::PT_longdouble:
52 return "long double";
53 case AST_PredefinedType::PT_char:
54 return "char";
55 case AST_PredefinedType::PT_wchar:
56 return "wchar";
57 case AST_PredefinedType::PT_boolean:
58 return "boolean";
59 case AST_PredefinedType::PT_octet:
60 return "octet";
61 case AST_PredefinedType::PT_void:
62 return "void";
63 default:
64 break;
67 // Not reached.
68 return "";
69 break;
70 default:
71 IdentifierHelper::tmp_retval_ = "::";
72 IdentifierHelper::tmp_retval_ +=
73 IdentifierHelper::orig_sn (t->name ()).c_str ();
74 return IdentifierHelper::tmp_retval_.c_str ();
78 Identifier *
79 IdentifierHelper::original_local_name (Identifier * local_name)
81 Identifier * id = nullptr;
82 const char *lname = local_name->get_string ();
84 // Remove _cxx_ if:
85 // 1. it occurs and
86 // 2. it occurs at the beginning of the string and
87 // 3. the rest of the string is a C++ keyword
88 if (ACE_OS::strstr (lname, "_cxx_") == lname)
90 TAO_IDL_CPP_Keyword_Table cpp_key_tbl;
92 unsigned int len =
93 static_cast<unsigned int> (ACE_OS::strlen (lname + 5));
95 const TAO_IDL_CPP_Keyword_Entry *entry =
96 cpp_key_tbl.lookup (lname + 5, len);
98 if (entry != nullptr)
100 // Remove _cxx_ and assign to the Identifier variable.
101 ACE_NEW_RETURN (id,
102 Identifier (lname + 5),
103 nullptr);
107 if (id == nullptr)
109 id = local_name->copy ();
112 return id;
115 ACE_CString
116 IdentifierHelper::orig_sn (UTL_IdList * sn, bool for_idl)
118 ACE_CString retval;
119 bool first = true;
120 bool second = false;
121 Identifier *id = nullptr;
123 for (UTL_IdListActiveIterator i (sn); !i.is_done ();)
125 if (!first)
127 retval += "::";
129 else if (second)
131 first = second = false;
134 id =
135 for_idl
136 ? IdentifierHelper::original_local_name (i.item ())
137 : i.item ()->copy ();
139 i.next ();
141 // Append the identifier.
142 retval +=
143 for_idl
144 ? IdentifierHelper::try_escape (id).c_str ()
145 : id->get_string ();
147 if (first)
149 if (ACE_OS::strcmp (id->get_string (), "") != 0)
151 // Does not start with a "".
152 first = false;
154 else
156 second = true;
160 id->destroy ();
161 delete id;
162 id = nullptr;
165 return retval;
168 bool
169 IdentifierHelper::is_idl_keyword (Identifier * local_name)
171 // Convert the identifier string into a
172 // canonical (uppercase) form as a ACE_CString
173 char *tmp = local_name->get_string ();
174 ACE_CString ext_id (tmp);
175 UTL_String::get_canonical_rep (ext_id);
177 return !idl_global->idl_keywords ().find (ext_id);
180 ACE_CString
181 IdentifierHelper::try_escape (Identifier * local_name)
183 ACE_CString s_local_name (local_name->get_string ());
185 if (IdentifierHelper::is_idl_keyword (local_name))
187 return "_" + s_local_name;
189 else
191 return s_local_name;