Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / be / be_string.cpp
blob4219440c8744af6a5b1cdd09acc3c76a5ee87a5f
2 //=============================================================================
3 /**
4 * @file be_string.cpp
6 * Extension of class AST_String that provides additional means for C++
7 * mapping.
9 * @author Copyright 1994-1995 by Sun Microsystems
10 * @author Inc. and Aniruddha Gokhale
12 //=============================================================================
14 #include "be_string.h"
15 #include "be_visitor.h"
16 #include "be_helper.h"
18 #include "utl_identifier.h"
19 #include "global_extern.h"
21 be_string::be_string (AST_Decl::NodeType nt,
22 UTL_ScopedName * n,
23 AST_Expression * v,
24 long width)
25 : COMMON_Base (),
26 AST_Decl (nt,
28 true),
29 AST_Type (nt,
30 n),
31 AST_ConcreteType (nt,
32 n),
33 AST_String (nt,
36 width),
37 be_decl (nt,
38 n),
39 be_type (nt,
42 if (!this->imported ())
44 idl_global->string_seen_ = true;
46 if (v->ev ()->u.ulval != 0)
48 idl_global->bd_string_seen_ = true;
50 else
52 idl_global->ub_string_seen_ = true;
57 // Overridden method.
58 void
59 be_string::gen_member_ostream_operator (TAO_OutStream *os,
60 const char *instance_name,
61 bool use_underscore,
62 bool accessor)
64 // For wide strings, generate code that outputs the hex values of
65 // the individual wchars inside square brackets, otherwise generate
66 // code that outputs the string literal bracketed with quotes.
67 if (this->width () == 1)
69 *os << "\"\\\"\" << ";
71 this->be_type::gen_member_ostream_operator (os,
72 instance_name,
73 use_underscore,
74 accessor);
76 *os << " << \"\\\"\"";
78 else
80 *os << "\"[\";" << be_nl_2
81 << "for (size_t i = 0; i < " << "ACE_OS::strlen ("
82 << instance_name
83 << (accessor ? " ()" : ".in ()") << "); ++i)" << be_idt_nl
84 << "{" << be_idt_nl
85 << "if (i != 0)" << be_idt_nl
86 << "{" << be_idt_nl
87 << "strm << \", \";" << be_uidt_nl
88 << "}" << be_uidt_nl << be_nl
89 << "strm << ACE_OutputCDR::from_wchar (" << instance_name
90 << (accessor ? " ()" : "") << "[i]);" << be_uidt_nl
91 << "}" << be_uidt_nl << be_nl
92 << "strm << \"]\"";
96 // Overriden method.
97 void
98 be_string::compute_tc_name (void)
100 Identifier * id = 0;
101 ACE_CDR::ULong val = 0UL;
102 AST_Expression zero (val);
104 if (*this->max_size () == &zero)
106 // If the string is unbounded, use the string TypeCode
107 // constants.
109 // Start with the head as the CORBA namespace.
110 Identifier * corba_id = 0;
111 ACE_NEW (corba_id,
112 Identifier ("CORBA"));
114 ACE_NEW (this->tc_name_,
115 UTL_ScopedName (corba_id,
116 0));
118 ACE_NEW (id,
119 Identifier (this->width () == 1
120 ? "_tc_string"
121 : "_tc_wstring"));
123 else
125 // We have a bounded string. Generate a TypeCode name that is
126 // meant for internal use alone.
128 Identifier * tao_id = 0;
129 ACE_NEW (tao_id,
130 Identifier ("TAO"));
132 ACE_NEW (this->tc_name_,
133 UTL_ScopedName (tao_id,
134 0));
136 ACE_CString local_tc_name =
137 ACE_CString ("tc_")
138 + ACE_CString (this->flat_name ());
140 Identifier * typecode_scope = 0;
141 ACE_NEW (typecode_scope,
142 Identifier ("TypeCode"));
144 UTL_ScopedName * tc_scope_conc_name = 0;
145 ACE_NEW (tc_scope_conc_name,
146 UTL_ScopedName (typecode_scope,
147 0));
149 this->tc_name_->nconc (tc_scope_conc_name);
151 ACE_NEW (id,
152 Identifier (local_tc_name.c_str ()));
155 zero.destroy ();
157 UTL_ScopedName *conc_name = 0;
158 ACE_NEW (conc_name,
159 UTL_ScopedName (id,
160 0));
162 this->tc_name_->nconc (conc_name);
166 be_string::accept (be_visitor * visitor)
168 return visitor->visit_string (this);
171 void
172 be_string::destroy (void)
174 this->be_type::destroy ();
175 this->AST_String::destroy ();
178 IMPL_NARROW_FROM_DECL (be_string)