Go to the documentation of this file.00001
00002
00003
00004 #include "PSDL_Type_Dcl_Visitor.h"
00005 #include "PSDL_Stream.h"
00006
00007 ACE_RCSID (PSS, PSDL_Type_Dcl_Visitor, "$Id: PSDL_Type_Dcl_Visitor.cpp 62978 2005-01-02 12:43:20Z jwillemsen $")
00008
00009 TAO_PSDL_Type_Dcl_Visitor::TAO_PSDL_Type_Dcl_Visitor (void)
00010 {
00011 }
00012
00013 TAO_PSDL_Type_Dcl_Visitor::~TAO_PSDL_Type_Dcl_Visitor (void)
00014 {
00015 }
00016
00017 int
00018 TAO_PSDL_Type_Dcl_Visitor::visit_identifier (TAO_PSDL_Identifier *identifier)
00019 {
00020 if (this->identifiers_.size () == 0)
00021 {
00022 this->identifiers_.size (1);
00023 this->count_ = 0;
00024 }
00025
00026 if (this->identifiers_.size () < this->count_ + 1)
00027 this->identifiers_.size (this->count_ + 1);
00028
00029 this->identifiers_ [this->count_] = identifier->value ();
00030 ++this->count_;
00031
00032 return 0;
00033 }
00034
00035 int
00036 TAO_PSDL_Type_Dcl_Visitor::visit_type_declarator (TAO_PSDL_Type_Declarator *type_declarator)
00037 {
00038
00039 this->count_ = 0;
00040 this->identifiers_.size (2);
00041 this->predefined_type_.size (2);
00042
00043 this->predefined_type_[this->count_] = 0;
00044
00045 if (type_declarator->type_spec ()->accept (this) == -1)
00046 return -1;
00047
00048 if (type_declarator->declarators ()->accept (this) == -1)
00049 return -1;
00050
00051 ACE_CString type;
00052
00053
00054
00055 if (this->predefined_type_ [0] == 0)
00056 {
00057 if (this->base_type (this->identifiers_[this->count_ -1], type))
00058 {
00059 if (ACE_OS::strcmp (type.c_str (), "struct") != 0)
00060 this->identifiers_[0] = type;
00061 }
00062 }
00063
00064
00065
00066
00067
00068 if (ACE_OS::strcmp (this->identifiers_[0].c_str (), "sequence") != 0)
00069 {
00070 this->print_for_simple_typedefs ();
00071 }
00072 else
00073 this->print_for_sequence_typedefs (this->identifiers_[1],
00074 this->identifiers_[2]);
00075
00076 return 0;
00077 }
00078
00079
00080
00081
00082
00083
00084
00085 void
00086 TAO_PSDL_Type_Dcl_Visitor::print_for_sequence_typedefs (ACE_CString identifier_type,
00087 ACE_CString identifier)
00088 {
00089 ACE_CString name_space = TAO_PSDL_Scope::instance ()->get_name_space ();
00090
00091
00092 TAO_PSDL_Stream *ps_sh = TAO_PSDL_Scope::instance ()->get_sh ();
00093
00094 ps_sh->nl ();
00095 *ps_sh << "#if !defined (TAO_USE_SEQUENCE_TEMPLATES)";
00096 ps_sh->nl ();
00097 *ps_sh << "#if !defined (__TAO_UNBOUNDED_SEQUENCE_" << name_space.c_str ()
00098 << "_" << identifier.c_str () << "_CH_)";
00099 ps_sh->nl ();
00100 *ps_sh << "#define __TAO_UNBOUNDED_SEQUENCE_" << name_space.c_str ()
00101 << "_" << identifier.c_str () << "_CH_";
00102 ps_sh->nl ();
00103 *ps_sh << "class TAO_EXPORT_MACRO _TAO_Unbounded_Sequence_CosNaming_"
00104 << identifier.c_str ();
00105 ps_sh->nl ();
00106 *ps_sh << ": public TAO_Unbounded_Base_Sequence";
00107 ps_sh->nl ();
00108 *ps_sh << "{";
00109 ps_sh->incr_indent ();
00110 ps_sh->nl ();
00111 *ps_sh << "public:";
00112 ps_sh->nl ();
00113 *ps_sh << "// = Initialization and termination methods.";
00114 ps_sh->nl ();
00115 *ps_sh << "_TAO_Unbounded_Sequence_" << name_space.c_str ()
00116 << "_" << identifier.c_str () << " (void);";
00117 ps_sh->nl ();
00118 *ps_sh << "_TAO_Unbounded_Sequence_" << name_space.c_str ()
00119 << "_" << identifier.c_str () << " (CORBA::ULong maximum);";
00120 ps_sh->nl ();
00121 *ps_sh << "_TAO_Unbounded_Sequence_" << name_space.c_str () << "_"
00122 << identifier.c_str () << " (";
00123 ps_sh->nl ();
00124 *ps_sh << "CORBA::ULong maximum,";
00125 ps_sh->nl ();
00126 *ps_sh << "CORBA::ULong length,";
00127 ps_sh->nl ();
00128 *ps_sh << identifier_type << " *data,";
00129 ps_sh->nl ();
00130 *ps_sh << "CORBA::Boolean release = 0";
00131 ps_sh->nl ();
00132 *ps_sh << ");";
00133 ps_sh->nl ();
00134 *ps_sh << "_TAO_Unbounded_Sequence_" << name_space.c_str () << "_" << identifier.c_str () << " (";
00135 ps_sh->nl ();
00136 *ps_sh << "const _TAO_Unbounded_Sequence_" << name_space.c_str () << "_" << identifier.c_str () << " &rhs\n";
00137 *ps_sh << ");\n";
00138 *ps_sh << "_TAO_Unbounded_Sequence_" << name_space.c_str () << "_" << identifier.c_str () << " &operator= (\n";
00139 *ps_sh << "const _TAO_Unbounded_Sequence_" << name_space.c_str () << "_" << identifier.c_str () << " &rhs\n";
00140 *ps_sh << ");\n";
00141 *ps_sh << "virtual ~_TAO_Unbounded_Sequence_" << name_space << "_" << identifier << " (void);";
00142 ps_sh->nl ();
00143 ps_sh->nl ();
00144 *ps_sh << "// = Accessors.\n";
00145 *ps_sh << identifier_type << " &operator[] (CORBA::ULong i);\n";
00146 *ps_sh << "const " << identifier_type << " &operator[] (CORBA::ULong i) const;\n";
00147 ps_sh->nl ();
00148 *ps_sh << "// = Static operations.\n";
00149 *ps_sh << "static " << identifier_type << " *allocbuf (CORBA::ULong size);\n";
00150 *ps_sh << "static void freebuf (" << identifier_type << " *buffer);\n";
00151 ps_sh->nl ();
00152 *ps_sh << "// Implement the TAO_Base_Sequence methods (see Sequence.h)"; ps_sh->nl ();
00153 *ps_sh << "virtual void _allocate_buffer (CORBA::ULong length);"; ps_sh->nl ();
00154 *ps_sh << "virtual void _deallocate_buffer (void);"; ps_sh->nl ();
00155 *ps_sh << identifier_type << " *get_buffer (CORBA::Boolean orphan = 0);"; ps_sh->nl ();
00156 *ps_sh << "const " << identifier_type << " *get_buffer (void) const;"; ps_sh->nl ();
00157 *ps_sh << "void replace ("; ps_sh->nl ();
00158 *ps_sh << " CORBA::ULong max,"; ps_sh->nl ();
00159 *ps_sh << " CORBA::ULong length,"; ps_sh->nl ();
00160 *ps_sh << identifier_type << " *data,"; ps_sh->nl ();
00161 *ps_sh << "CORBA::Boolean release"; ps_sh->nl ();
00162 *ps_sh << ");"; ps_sh->nl ();
00163 ps_sh->decr_indent ();
00164 *ps_sh << "};"; ps_sh->nl ();
00165 ps_sh->decr_indent ();
00166 ps_sh->nl ();
00167 *ps_sh << "#endif /* end #if !defined */"; ps_sh->nl ();
00168 ps_sh->nl ();
00169 ps_sh->nl ();
00170 *ps_sh << "#endif /* !TAO_USE_SEQUENCE_TEMPLATES */ "; ps_sh->nl ();
00171
00172 ps_sh->nl ();
00173 ps_sh->nl ();
00174
00175 *ps_sh << "#if !defined (_" << name_space.c_str () << "_" << identifier.c_str () << "_CH_)"; ps_sh->nl ();
00176 *ps_sh << "#define _" << name_space.c_str () << "_" << identifier.c_str () << "_CH_"; ps_sh->nl ();
00177 ps_sh->nl ();
00178
00179 *ps_sh << "class " << identifier.c_str () << ";"; ps_sh->nl ();
00180 *ps_sh << "class " << identifier.c_str () << "_var;"; ps_sh->nl ();
00181 ps_sh->nl ();
00182
00183 *ps_sh << "// *************************************************************"; ps_sh->nl ();
00184 *ps_sh << "// " << identifier.c_str () ; ps_sh->nl ();
00185 *ps_sh << "// *************************************************************"; ps_sh->nl ();
00186
00187 ps_sh->nl ();
00188
00189 *ps_sh << "class " << identifier.c_str () << " : public"; ps_sh->nl ();
00190
00191 ps_sh->nl ();
00192
00193 *ps_sh << "#if !defined (TAO_USE_SEQUENCE_TEMPLATES)"; ps_sh->nl ();
00194 *ps_sh << "_TAO_Unbounded_Sequence_" << name_space.c_str () << "_" << identifier.c_str () ; ps_sh->nl ();
00195 *ps_sh << "#else /* TAO_USE_SEQUENCE_TEMPLATES */"; ps_sh->nl ();
00196 *ps_sh << "TAO_Unbounded_Sequence<" << identifier.c_str () << "Component>"; ps_sh->nl ();
00197 *ps_sh << "#endif /* !TAO_USE_SEQUENCE_TEMPLATES */ "; ps_sh->nl ();
00198 *ps_sh << "{"; ps_sh->nl ();
00199 ps_sh->incr_indent ();
00200 *ps_sh << "public:"; ps_sh->nl ();
00201 *ps_sh << identifier.c_str () << " (void); // default ctor"; ps_sh->nl ();
00202 *ps_sh << identifier.c_str () << " (CORBA::ULong max); // uses max size"; ps_sh->nl ();
00203 *ps_sh << identifier.c_str () << " ("; ps_sh->nl ();
00204 *ps_sh << "CORBA::ULong max, "; ps_sh->nl ();
00205 *ps_sh << "CORBA::ULong length, "; ps_sh->nl ();
00206 *ps_sh << identifier.c_str () << "Component *buffer, "; ps_sh->nl ();
00207 *ps_sh << "CORBA::Boolean release = 0"; ps_sh->nl ();
00208 *ps_sh << ");"; ps_sh->nl ();
00209
00210 *ps_sh << identifier.c_str () << " (const " << identifier.c_str () << " &); // copy ctor"; ps_sh->nl ();
00211 *ps_sh << "~" << identifier.c_str () << " (void);"; ps_sh->nl ();
00212 *ps_sh << "static void _tao_any_destructor (void*);"; ps_sh->nl ();
00213 ps_sh->nl ();
00214 *ps_sh << "typedef " << identifier.c_str () << "_var _var_type;"; ps_sh->nl ();
00215 ps_sh->nl ();
00216 ps_sh->nl ();
00217 *ps_sh << "};"; ps_sh->nl ();
00218 ps_sh->decr_indent ();
00219 ps_sh->nl ();
00220 *ps_sh << "#endif /* end #if !defined */"; ps_sh->nl ();
00221 ps_sh->nl ();
00222 ps_sh->nl ();
00223 *ps_sh << "#if !defined (_" << name_space.c_str () << "_" << identifier.c_str () << "___VAR_CH_)"; ps_sh->nl ();
00224 *ps_sh << "#define _" << name_space.c_str () << "_" << identifier.c_str () << "___VAR_CH_"; ps_sh->nl ();
00225 ps_sh->nl ();
00226 *ps_sh << "// *************************************************************"; ps_sh->nl ();
00227 *ps_sh << "// class " << name_space.c_str () << "::" << identifier.c_str () << "_var"; ps_sh->nl ();
00228 *ps_sh << "// *************************************************************"; ps_sh->nl ();
00229 ps_sh->nl ();
00230 *ps_sh << "class " << identifier.c_str () << "_var"; ps_sh->nl ();
00231 *ps_sh << "{"; ps_sh->nl ();
00232 ps_sh->incr_indent ();
00233 *ps_sh << "public:"; ps_sh->nl ();
00234 *ps_sh << identifier.c_str () << "_var (void);"; ps_sh->nl ();
00235 *ps_sh << identifier.c_str () << "_var (" << identifier.c_str () << " *);"; ps_sh->nl ();
00236 *ps_sh << identifier.c_str () << "_var (const " << identifier.c_str () << "_var &);"; ps_sh->nl ();
00237 *ps_sh << "~" << identifier.c_str () << "_var (void);"; ps_sh->nl ();
00238 ps_sh->nl ();
00239 *ps_sh << identifier.c_str () << "_var &operator= (" << identifier.c_str () << " *);"; ps_sh->nl ();
00240 *ps_sh << identifier.c_str () << "_var &operator= (const " << identifier.c_str () << "_var &);"; ps_sh->nl ();
00241 *ps_sh << identifier.c_str () << " *operator-> (void);"; ps_sh->nl ();
00242 *ps_sh << "const " << identifier.c_str () << " *operator-> (void) const;"; ps_sh->nl ();
00243 ps_sh->nl ();
00244 *ps_sh << "operator const " << identifier.c_str () << " &() const;"; ps_sh->nl ();
00245 *ps_sh << "operator " << identifier.c_str () << " &();"; ps_sh->nl ();
00246 *ps_sh << "operator " << identifier.c_str () << " &() const;"; ps_sh->nl ();
00247 *ps_sh << "operator " << identifier.c_str () << " *&(); // variable-size base types only"; ps_sh->nl ();
00248 ps_sh->nl ();
00249 *ps_sh << identifier.c_str () << "Component & operator[] (CORBA::ULong index);"; ps_sh->nl ();
00250 *ps_sh << "const " << identifier.c_str () << "Component & operator[] (CORBA::ULong index) const;";
00251
00252 ps_sh->nl ();
00253 ps_sh->nl ();
00254
00255 *ps_sh << "// in, inout, out, _retn "; ps_sh->nl ();
00256 *ps_sh << "const " << identifier.c_str () << " &in (void) const;"; ps_sh->nl ();
00257 *ps_sh << identifier.c_str () << " &inout (void);"; ps_sh->nl ();
00258 *ps_sh << identifier.c_str () << " *&out (void);"; ps_sh->nl ();
00259 *ps_sh << identifier.c_str () << " *_retn (void);"; ps_sh->nl ();
00260 *ps_sh << identifier.c_str () << " *ptr (void) const;";
00261
00262 ps_sh->decr_indent (0);
00263
00264 ps_sh->nl ();
00265 ps_sh->nl ();
00266
00267 *ps_sh << "private:";
00268
00269 ps_sh->incr_indent (0);
00270 ps_sh->nl ();
00271
00272 *ps_sh << identifier.c_str () << " *ptr_;"; ps_sh->nl ();
00273 *ps_sh << "};";
00274
00275 ps_sh->nl ();
00276 ps_sh->nl ();
00277 ps_sh->nl ();
00278
00279 *ps_sh << "#endif /* end #if !defined */"; ps_sh->nl ();
00280 ps_sh->nl ();
00281 ps_sh->nl ();
00282 *ps_sh << "#if !defined (_" << name_space.c_str () << "_" << identifier.c_str () << "___OUT_CH_)"; ps_sh->nl ();
00283 *ps_sh << "#define _" << name_space.c_str () << "_" << identifier.c_str () << "___OUT_CH_"; ps_sh->nl ();
00284 ps_sh->nl ();
00285 *ps_sh << "class " << identifier.c_str () << "_out"; ps_sh->nl ();
00286 *ps_sh << "{"; ps_sh->nl ();
00287 ps_sh->incr_indent ();
00288 *ps_sh << "public:"; ps_sh->nl ();
00289 *ps_sh << identifier.c_str () << "_out (" << identifier.c_str () << " *&);"; ps_sh->nl ();
00290 *ps_sh << identifier.c_str () << "_out (" << identifier.c_str () << "_var &);"; ps_sh->nl ();
00291 *ps_sh << identifier.c_str () << "_out (const " << identifier.c_str () << "_out &);"; ps_sh->nl ();
00292 *ps_sh << identifier.c_str () << "_out &operator= (const " << identifier.c_str () << "_out &);"; ps_sh->nl ();
00293 *ps_sh << identifier.c_str () << "_out &operator= (" << identifier.c_str () << " *);"; ps_sh->nl ();
00294 *ps_sh << "operator " << identifier.c_str () << " *&();"; ps_sh->nl ();
00295 *ps_sh << identifier.c_str () << " *&ptr (void);"; ps_sh->nl ();
00296 *ps_sh << identifier.c_str () << " *operator-> (void);"; ps_sh->nl ();
00297 *ps_sh << identifier.c_str () << "Component & operator[] (CORBA::ULong index);"; ps_sh->nl ();
00298 ps_sh->nl ();
00299 *ps_sh << "private:"; ps_sh->nl ();
00300 *ps_sh << identifier.c_str () << " *&ptr_;"; ps_sh->nl ();
00301 *ps_sh << "// Assignment from T_var not allowed."; ps_sh->nl ();
00302 *ps_sh << "void operator= (const " << identifier.c_str () << "_var &);"; ps_sh->nl ();
00303 *ps_sh << "};"; ps_sh->nl ();
00304 ps_sh->decr_indent ();
00305 ps_sh->nl ();
00306 ps_sh->nl ();
00307 *ps_sh << "#endif /* end #if !defined */"; ps_sh->nl ();
00308
00309 *ps_sh << "TAO_NAMESPACE_STORAGE_CLASS ::CORBA::TypeCode_ptr "
00310 << "_tc_" << identifier.c_str () << ";"; ps_sh->nl ();
00311 }
00312
00313 void
00314 TAO_PSDL_Type_Dcl_Visitor::print_for_simple_typedefs (void)
00315 {
00316 ACE_CString type;
00317
00318
00319 this->base_type (this->identifiers_ [0], type);
00320
00321
00322 TAO_PSDL_Stream *ps_sh = TAO_PSDL_Scope::instance ()->get_sh ();
00323
00324 if (ACE_OS::strcmp (type.c_str (), "char *") == 0)
00325 {
00326 ps_sh->reset ();
00327 ps_sh->nl ();
00328
00329 *ps_sh << "typedef " << type.c_str () << " "
00330 << this->identifiers_ [1].c_str () << ";";
00331 }
00332
00333 ps_sh->nl ();
00334 *ps_sh << "typedef " << this->version_for_stub (type).c_str () << " "
00335 << this->identifiers_[1].c_str ();
00336
00337 if (ACE_OS::strcmp (type.c_str (), "char *") == 0)
00338 *ps_sh << "_var;";
00339 else
00340 *ps_sh << ";";
00341
00342 ps_sh->nl ();
00343 *ps_sh << "typedef " << this->version_for_stub (type).c_str () << "_out"
00344 << " " << this->identifiers_[1].c_str () << "_out;"; ps_sh->nl ();
00345 *ps_sh << "TAO_NAMESPACE_STORAGE_CLASS ::CORBA::TypeCode_ptr"
00346 << " _tc_" << this->identifiers_[1].c_str () << ";"; ps_sh->nl ();
00347 ps_sh->nl ();
00348
00349
00350 this->gen_code_for_si ();
00351 }
00352
00353 void
00354 TAO_PSDL_Type_Dcl_Visitor::gen_code_for_si (void)
00355 {
00356 TAO_PSDL_Stream *ps_si = TAO_PSDL_Scope::instance ()->get_si ();
00357
00358 ps_si->reset ();
00359 ps_si->indent ();
00360
00361
00362 *ps_si << "static const CORBA::Long _oc_";
00363
00364
00365 *ps_si << this->identifiers_[1];
00366 *ps_si << "[] =";
00367 ps_si->nl ();
00368 *ps_si << "{";
00369 ps_si->nl ();
00370
00371
00372
00373 *ps_si << "// Typecode related information should go in here";
00374 ps_si->nl ();
00375
00376 *ps_si << "};";
00377 ps_si->nl ();
00378 ps_si->nl ();
00379
00380 *ps_si << "static CORBA::TypeCode _tc_TAO_tc_";
00381 *ps_si << this->identifiers_[1];
00382 *ps_si << " (";
00383 ps_si->nl ();
00384 ps_si->incr_indent ();
00385 *ps_si << "CORBA::tk_alias,";
00386 ps_si->nl ();
00387 *ps_si << "sizeof (_oc_" << this->identifiers_[1] << "),";
00388 ps_si->nl ();
00389 *ps_si << "(char *) &_oc_";
00390 *ps_si << this->identifiers_[1] << ",";
00391 ps_si->nl ();
00392 *ps_si << "0,";
00393 ps_si->nl ();
00394 *ps_si << "sizeof (" << this->identifiers_[1] << ")";
00395 ps_si->nl ();
00396 *ps_si << ");";
00397 ps_si->decr_indent ();
00398
00399 ps_si->nl ();
00400 ps_si->nl ();
00401 *ps_si << "::CORBA::TypeCode_ptr _tc_" << this->identifiers_[1] << " =";
00402 ps_si->nl ();
00403 ps_si->incr_indent ();
00404
00405 *ps_si << "&_tc_TAO_tc_" << this->identifiers_[1] << ";";
00406 ps_si->decr_indent ();
00407 ps_si->nl ();
00408 ps_si->nl ();
00409
00410
00411 return;
00412 }
00413
00414 int
00415 TAO_PSDL_Type_Dcl_Visitor::visit_predefined_type (TAO_PSDL_Predefined_Type *predefined_type)
00416 {
00417 if (predefined_type->type_one () != 0)
00418 {
00419 this->identifiers_ [this->count_] =
00420 TAO_PSDL_Scope::instance ()->convert_str (predefined_type->type_one ());
00421 if (this->count_ == 0)
00422 {
00423
00424 this->predefined_type_ [this->count_] = 1;
00425 }
00426 ++this->count_;
00427 }
00428
00429 if (predefined_type->type_two () != 0)
00430 {}
00431
00432 if (predefined_type->type_three () != 0)
00433 {}
00434
00435 if (predefined_type->type_of_variable_one () != 0)
00436 {
00437 if (predefined_type->type_of_variable_one ()->accept (this) == -1)
00438 return -1;
00439 }
00440 if (predefined_type->type_of_variable_two () != 0)
00441 {}
00442 if (predefined_type->type_of_variable_three () != 0)
00443 {}
00444 return 0;
00445 }