Go to the documentation of this file.00001
00002
00003
00004 #include "ast_enum.h"
00005 #include "ast_expression.h"
00006 #include "ast_field.h"
00007 #include "ast_union.h"
00008 #include "utl_identifier.h"
00009
00010 #include "ifr_adding_visitor_structure.h"
00011 #include "ifr_adding_visitor_union.h"
00012
00013 ACE_RCSID (IFR_Service,
00014 ifr_adding_visitor_structure,
00015 "$Id: ifr_adding_visitor_structure.cpp 83731 2008-11-13 21:54:42Z fields_t $")
00016
00017 ifr_adding_visitor_structure::ifr_adding_visitor_structure (AST_Decl *scope)
00018 : ifr_adding_visitor (scope)
00019 {
00020 }
00021
00022 ifr_adding_visitor_structure::~ifr_adding_visitor_structure (void)
00023 {
00024 }
00025
00026
00027 int
00028 ifr_adding_visitor_structure::visit_scope (UTL_Scope *node)
00029 {
00030
00031
00032 if (node->scope_node_type () != AST_Decl::NT_struct)
00033 {
00034 return ifr_adding_visitor::visit_scope (node);
00035 }
00036
00037 AST_Structure *s = AST_Structure::narrow_from_scope (node);
00038 CORBA::ULong nfields = static_cast<CORBA::ULong> (s->nfields ());
00039 this->members_.length (nfields);
00040 AST_Field **f = 0;
00041
00042 try
00043 {
00044
00045 for (CORBA::ULong i = 0; i < nfields; ++i)
00046 {
00047 if (s->field (f, i) != 0)
00048 {
00049 ACE_ERROR_RETURN ((
00050 LM_ERROR,
00051 ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::")
00052 ACE_TEXT ("visit_scope -")
00053 ACE_TEXT (" field node access failed\n")),
00054 -1);
00055 }
00056
00057 AST_Type *ft = (*f)->field_type ();
00058 bool defined_here = ft->is_child (this->scope_);
00059
00060
00061
00062 if (defined_here)
00063 {
00064 if (ft->node_type () == AST_Decl::NT_struct)
00065 {
00066
00067
00068
00069 ifr_adding_visitor_structure visitor (ft);
00070
00071 if (ft->ast_accept (&visitor) == -1)
00072 {
00073 ACE_ERROR_RETURN ((
00074 LM_ERROR,
00075 ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::")
00076 ACE_TEXT ("visit_scope -")
00077 ACE_TEXT (" failed to accept visitor\n")),
00078 -1);
00079 }
00080
00081 this->ir_current_ =
00082 CORBA::IDLType::_duplicate (visitor.ir_current ());
00083 }
00084 else
00085 {
00086 if (ft->ast_accept (this) == -1)
00087 {
00088 ACE_ERROR_RETURN ((
00089 LM_ERROR,
00090 ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::")
00091 ACE_TEXT ("visit_scope -")
00092 ACE_TEXT (" failed to accept visitor\n")),
00093 -1);
00094 }
00095 }
00096 }
00097 else
00098 {
00099
00100 this->get_referenced_type (ft);
00101 }
00102
00103 this->members_[i].name =
00104 CORBA::string_dup ((*f)->local_name ()->get_string ());
00105
00106
00107
00108 this->members_[i].type =
00109 CORBA::TypeCode::_duplicate (CORBA::_tc_void);
00110
00111 this->members_[i].type_def =
00112 CORBA::IDLType::_duplicate (this->ir_current_.in ());
00113 }
00114 }
00115 catch (const CORBA::Exception& ex)
00116 {
00117 ex._tao_print_exception (
00118 ACE_TEXT (
00119 "ifr_adding_visitor_structure::visit_scope"));
00120
00121 return -1;
00122 }
00123
00124 return 0;
00125 }
00126
00127 int
00128 ifr_adding_visitor_structure::visit_structure (AST_Structure *node)
00129 {
00130 try
00131 {
00132 CORBA::StructDef_var struct_def;
00133 CORBA::Contained_var prev_def =
00134 be_global->repository ()->lookup_id (node->repoID ());
00135
00136 if (CORBA::is_nil (prev_def.in ()))
00137 {
00138 CORBA::StructDef_var struct_def;
00139 CORBA::StructMemberSeq dummyMembers;
00140 dummyMembers.length (0);
00141
00142 CORBA::Container_ptr current_scope = CORBA::Container::_nil ();
00143
00144 if (be_global->ifr_scopes ().top (current_scope) != 0)
00145 {
00146 ACE_ERROR_RETURN ((
00147 LM_ERROR,
00148 ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::")
00149 ACE_TEXT ("visit_structure -")
00150 ACE_TEXT (" scope stack is empty\n")),
00151 -1);
00152 }
00153
00154
00155 struct_def =
00156 current_scope->create_struct (
00157 node->repoID (),
00158 node->local_name ()->get_string (),
00159 node->version (),
00160 dummyMembers
00161 );
00162
00163 if (be_global->ifr_scopes ().push (struct_def.in ()) != 0)
00164 {
00165 ACE_ERROR_RETURN ((
00166 LM_ERROR,
00167 ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::")
00168 ACE_TEXT ("visit_structure -")
00169 ACE_TEXT (" scope push failed\n")
00170 ),
00171 -1
00172 );
00173 }
00174
00175
00176 if (this->add_members (node, struct_def.in ()) == -1)
00177 {
00178 ACE_ERROR_RETURN ((
00179 LM_ERROR,
00180 ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::")
00181 ACE_TEXT ("visit_structure -")
00182 ACE_TEXT (" visit_scope failed\n")),
00183 -1);
00184 }
00185
00186 this->ir_current_ = CORBA::IDLType::_narrow (struct_def.in ());
00187
00188 CORBA::Container_ptr used_scope =
00189 CORBA::Container::_nil ();
00190
00191
00192 if (be_global->ifr_scopes ().pop (used_scope) != 0)
00193 {
00194 ACE_ERROR_RETURN ((
00195 LM_ERROR,
00196 ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::")
00197 ACE_TEXT ("visit_structure -")
00198 ACE_TEXT (" scope pop failed\n")
00199 ),
00200 -1
00201 );
00202 }
00203 }
00204 else
00205 {
00206
00207
00208
00209
00210 struct_def = CORBA::StructDef::_narrow (prev_def.in ());
00211
00212 if (be_global->ifr_scopes ().push (struct_def.in ()) != 0)
00213 {
00214 ACE_ERROR_RETURN ((
00215 LM_ERROR,
00216 ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::")
00217 ACE_TEXT ("visit_structure -")
00218 ACE_TEXT (" scope push failed\n")
00219 ),
00220 -1
00221 );
00222 }
00223
00224 if (this->add_members (node, struct_def.in ()) == -1)
00225 {
00226 ACE_ERROR_RETURN ((
00227 LM_ERROR,
00228 ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::")
00229 ACE_TEXT ("visit_structure -")
00230 ACE_TEXT (" visit_scope failed\n")),
00231 -1);
00232 }
00233
00234 this->ir_current_ = CORBA::IDLType::_narrow (prev_def.in ());
00235
00236 CORBA::Container_ptr used_scope =
00237 CORBA::Container::_nil ();
00238
00239
00240 if (be_global->ifr_scopes ().pop (used_scope) != 0)
00241 {
00242 ACE_ERROR_RETURN ((
00243 LM_ERROR,
00244 ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::")
00245 ACE_TEXT ("visit_structure -")
00246 ACE_TEXT (" scope pop failed\n")
00247 ),
00248 -1
00249 );
00250 }
00251 }
00252 }
00253 catch (const CORBA::Exception& ex)
00254 {
00255 ex._tao_print_exception (
00256 ACE_TEXT (
00257 "ifr_adding_visitor_structure::visit_structure"));
00258
00259 return -1;
00260 }
00261
00262 return 0;
00263 }
00264
00265 int
00266 ifr_adding_visitor_structure::visit_enum (AST_Enum *node)
00267 {
00268 try
00269 {
00270
00271 CORBA::Contained_var prev_def =
00272 be_global->repository ()->lookup_id (node->repoID ());
00273
00274
00275 if (CORBA::is_nil (prev_def.in ()))
00276 {
00277 CORBA::ULong member_count =
00278 static_cast<CORBA::ULong> (node->member_count ());
00279
00280 CORBA::EnumMemberSeq members (member_count);
00281 members.length (member_count);
00282
00283 UTL_ScopedName *member_name = 0;
00284
00285
00286 for (CORBA::ULong i = 0; i < member_count; ++i)
00287 {
00288 member_name = node->value_to_name (i);
00289
00290 members[i] =
00291 CORBA::string_dup (
00292 member_name->last_component ()->get_string ()
00293 );
00294 }
00295
00296 this->ir_current_ =
00297 be_global->repository ()->create_enum (
00298 node->repoID (),
00299 node->local_name ()->get_string (),
00300 node->version (),
00301 members
00302 );
00303
00304 node->ifr_added (true);
00305 }
00306 else
00307 {
00308
00309
00310
00311
00312 if (!node->ifr_added ())
00313 {
00314 prev_def->destroy ();
00315
00316
00317 return this->visit_enum (node);
00318 }
00319
00320 this->ir_current_ =
00321 CORBA::IDLType::_narrow (prev_def.in ());
00322 }
00323 }
00324 catch (const CORBA::Exception& ex)
00325 {
00326 ex._tao_print_exception (
00327 ACE_TEXT (
00328 "ifr_adding_visitor_structure::visit_enum"));
00329
00330 return -1;
00331 }
00332
00333 return 0;
00334 }
00335
00336 int
00337 ifr_adding_visitor_structure::visit_union (AST_Union *node)
00338 {
00339 try
00340 {
00341
00342 CORBA::Contained_var prev_def =
00343 be_global->repository ()->lookup_id (node->repoID ());
00344
00345
00346 if (CORBA::is_nil (prev_def.in ()))
00347 {
00348 ifr_adding_visitor_union visitor (node);
00349 int retval = visitor.visit_union (node);
00350
00351 if (retval == 0)
00352 {
00353
00354 this->ir_current_ =
00355 CORBA::IDLType::_duplicate (visitor.ir_current ());
00356 }
00357
00358 return retval;
00359 }
00360 else
00361 {
00362
00363
00364
00365
00366 if (!node->ifr_added ())
00367 {
00368 prev_def->destroy ();
00369
00370
00371 return this->visit_union (node);
00372 }
00373
00374 this->ir_current_ =
00375 CORBA::IDLType::_narrow (prev_def.in ());
00376 }
00377 }
00378 catch (const CORBA::Exception& ex)
00379 {
00380 ex._tao_print_exception (
00381 ACE_TEXT (
00382 "ifr_adding_visitor_structure::visit_union"));
00383
00384 return -1;
00385 }
00386
00387 return 0;
00388 }
00389
00390 CORBA::IDLType_ptr
00391 ifr_adding_visitor_structure::ir_current (void) const
00392 {
00393 return this->ir_current_.in ();
00394 }
00395
00396 int
00397 ifr_adding_visitor_structure::add_members (AST_Structure *node,
00398 CORBA::StructDef_ptr struct_def)
00399 {
00400 if (this->visit_scope (node) == -1)
00401 {
00402 ACE_ERROR_RETURN ((
00403 LM_ERROR,
00404 ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::")
00405 ACE_TEXT ("visit_structure -")
00406 ACE_TEXT (" visit_scope failed\n")),
00407 -1);
00408 }
00409
00410
00411 this->ir_current_= CORBA::StructDef::_duplicate (struct_def);
00412 struct_def->members (this->members_);
00413
00414 node->ifr_added (true);
00415 return 0;
00416 }