void be_CodeGenerator::Generate(be_ClientImplementation& source) { UTL_ScopeActiveIterator* i; AST_Decl * d; UTL_Scope * s = (UTL_Scope*)narrow((long) & UTL_Scope::type_id); if (s) { i = new UTL_ScopeActiveIterator(s, UTL_Scope::IK_decls); while (!(i->is_done())) { be_CodeGenerator * cg; d = i->item(); if (!d->imported() && (cg = (be_CodeGenerator*)d->narrow((long) & be_CodeGenerator::type_id))) { cg->Generate(source); } i->next(); } delete i; } else { assert(pbfalse); } }
void be_exception::GenerateAssignmentOperator (be_ClientImplementation& source) { ostream & os = source.Stream (); DDS_StdString that (""); be_Type * btype; if (nmembers ()) { that = " that"; } os << ScopedName () << " & " << ScopedName () << "::operator = (const " << LocalName () << " &" << that << ")" << nl; os << "{" << nl; UTL_Scope * s = (UTL_Scope*)narrow((long) & UTL_Scope::type_id); assert (s); UTL_ScopeActiveIterator *it; // Iterate through decls for ( it = new UTL_ScopeActiveIterator (s, UTL_Scope::IK_decls); ! it->is_done (); it->next () ) { AST_Decl * adecl = it->item (); assert (adecl); be_field *bfield = (be_field *) adecl->narrow ((long) & be_field::type_id); if (bfield) { btype = bfield->get_be_type (); if (btype && btype->IsArrayType ()) { // Need to copy array elements os << " " << (char*) BE_Globals::RelativeScope (ScopedName (), bfield->StructMemberTypeName ()) << "_copy (" << bfield->get_local_name () << ", that." << bfield->get_local_name () << ");" << nl; } else { os << " " << bfield->get_local_name () << " = that." << bfield->get_local_name() << ";" << nl; } } } delete it; os << " return *this;" << nl; os << "}" << nl << nl; }
void be_root::GenerateGlobalDecls (be_ClientHeader & source) { UTL_ScopeActiveIterator * i; be_CodeGenerator * cg; AST_Decl * d; UTL_Scope * s = (UTL_Scope*) narrow ((long) & UTL_Scope::type_id); if (s) { // Iterate through decls i = new UTL_ScopeActiveIterator (s, UTL_Scope::IK_decls); while (!(i->is_done ())) { d = i->item (); if (!d->imported ()) { cg = (be_CodeGenerator*) d->narrow ((long) & be_CodeGenerator::type_id); if (cg) { cg->Generate (source); } } i->next (); } delete i; } }
void be_root::GenerateGlobalTypes (be_ClientHeader& source) { UTL_ScopeActiveIterator * i; be_CodeGenerator * cg; AST_Decl * d; be_Type * bt; DDS_StdString scope; UTL_Scope * s = (UTL_Scope*) narrow ((long) & UTL_Scope::type_id); if (s) { // Iterate through types i = new UTL_ScopeActiveIterator (s, UTL_Scope::IK_localtypes); while (! i->is_done ()) { d = i->item (); if (! d->imported ()) { cg = (be_CodeGenerator*) d->narrow ((long) & be_CodeGenerator::type_id); if (cg) { bt = (be_Type*) d->narrow ((long) & be_Type::type_id); scope = bt->EnclosingScope (); if (! bt->HasTypeDef () && scope == NULL) { cg->Generate (source); } } } i->next (); } delete i; } }
void be_structure::Generate (be_ClientImplementation & source) { UTL_ScopeActiveIterator * i; AST_Decl * d; UTL_Scope * s = (UTL_Scope*)narrow((long) & UTL_Scope::type_id); if (BE_Globals::ignore_interfaces && IsInterfaceDependant ()) { return; } if (s) { i = new UTL_ScopeActiveIterator(s, UTL_Scope::IK_localtypes); while (!(i->is_done())) { be_CodeGenerator * cg; d = i->item(); if (!d->imported() && (cg = (be_CodeGenerator*)d->narrow((long) & be_CodeGenerator::type_id))) { cg->Generate (source); } i->next(); } delete i; } else { assert(pbfalse); } }
void be_CodeGenerator::Generate(be_ClientHeader& source) { UTL_Scope* s = (UTL_Scope*)narrow((long) & UTL_Scope::type_id); assert(s); // ITERATE THROUGH DECLS UTL_ScopeActiveIterator iter(s, UTL_Scope::IK_both); while (!(iter.is_done())) { be_CodeGenerator* cg; AST_Decl* d = iter.item(); if (!d->imported() && (cg = (be_CodeGenerator*)d->narrow((long) & be_CodeGenerator::type_id))) { cg->Generate(source); } iter.next(); } }
void be_enum::Generate(be_ClientHeader& source) { if (!Generated()) { UTL_ScopeActiveIterator* i = new UTL_ScopeActiveIterator(this, IK_decls); ostream & os = source.Stream(); unsigned long expectedValue = 0; be_Tab tab(source); AST_Decl * d; Generated(pbtrue); os << tab << "enum " << *local_name() << nl; os << tab << "{" << nl; tab.indent(); while (!(i->is_done())) { d = i->item (); if (d) { be_enum_val * ev = (be_enum_val*) d->narrow ((long) & be_enum_val::type_id); if (ev) { os << tab << *ev->local_name(); if (ev->Value() != expectedValue) { expectedValue = ev->Value(); os << " = " << expectedValue; } expectedValue++; i->next(); if (!(i->is_done())) { os << ","; } os << nl; } else { DDSError(NameToString(name()) + " contains non-enum val"); assert(pbfalse); } } else { DDSError(NameToString(name()) + " declaration is corrupted"); assert(pbfalse); } } //os << tab << "DDS_DCPS_FORCE_ENUM32(__" << *local_name() << ")" << nl; tab.outdent(); os << tab << "};" << nl; delete i; // GENERATE STREAMING OPERATORS be_root::AddAnyOps(*this); be_root::AddPutGetOps(*this); be_root::AddStreamOps(*this); be_root::AddTypedef(*this); be_root::AddTypecode(*this); } }
void be_exception::GenerateConvenienceConstructor (be_ClientImplementation & source) { ostream & os = source.Stream (); const char * argPrefix = "_"; pbbool first = pbtrue; be_Tab tab (source); be_Type * btype; os << ScopedName () << "::" << LocalName () << " ("; UTL_Scope * s = (UTL_Scope*)narrow ((long) & UTL_Scope::type_id); assert (s); // Iterate through decls UTL_ScopeActiveIterator * it; for ( it = new UTL_ScopeActiveIterator (s, UTL_Scope::IK_decls); !it->is_done (); it->next () ) { AST_Decl * adecl = it->item (); assert (adecl); be_field *bfield = (be_field *)adecl->narrow ((long) & be_field::type_id); if (bfield) { btype = bfield->get_be_type (); if (!first) { os << ", "; } first = pbfalse; if (btype && btype->IsStringType ()) { // Strings are special case os << (char*) BE_Globals::RelativeScope (ScopedName (), bfield->InTypeName ()); } else { os << (char*) BE_Globals::RelativeScope (ScopedName (), bfield->StructMemberTypeName ()); } os << " " << argPrefix << (char*) bfield->get_local_name (); } } delete it; os << ")" << nl; // Iterate thru members initializing if (nmembers ()) { source.Indent (); first = pbtrue; for ( it = new UTL_ScopeActiveIterator (s, UTL_Scope::IK_decls); !it->is_done (); it->next () ) { AST_Decl * adecl = it->item (); assert (adecl); be_field *bfield = (be_field *)adecl->narrow ((long) & be_field::type_id); if (bfield) { btype = bfield->get_be_type (); // Array members are assigned in body of method if (btype && ! btype->IsArrayType ()) { if (first) { first = pbfalse; os << " : " << nl; } else { os << "," << nl; } os << " " << (char*) bfield->get_local_name () << "(" << argPrefix << (char*) bfield->get_local_name () << ")"; } } } delete it; source.Outdent (); } os << nl; os << tab << "{" << nl; for ( it = new UTL_ScopeActiveIterator (s, UTL_Scope::IK_decls); ! it->is_done (); it->next () ) { AST_Decl * adecl = it->item (); assert (adecl); be_field *bfield = (be_field *) adecl->narrow ((long) & be_field::type_id); if (bfield) { btype = bfield->get_be_type (); if (btype && btype->IsArrayType ()) { // Need to copy array elements os << " " << (char*) BE_Globals::RelativeScope (ScopedName (), bfield->StructMemberTypeName ()) << "_copy (" << argPrefix << bfield->get_local_name () << ", " << bfield->get_local_name () << ");" << nl; } } } delete it; os << "}" << nl << nl; }
DDS_StdString be_operation::DirectSignature ( OP_SignatureType sigType, const DDS_StdString & implclassname ) { UTL_ScopeActiveIterator *i = new UTL_ScopeActiveIterator (this, IK_decls); ostringstream os; pbbool first = pbtrue; DDS_StdString ret; AST_Decl *d; // GENERATE RETURN TYPE if (sigType != OP_Invoke) { assert (returnType); os << returnType->MakeSignature (VT_Return, "") << " "; } if (sigType != OP_Declaration) { os << implclassname << "::"; } // OP NAME os << LocalName (); // GENERATE PARAMETER LIST os << "("; for (; !(i->is_done ()); i->next ()) { be_argument *arg; d = i->item (); arg = (be_argument *) d->narrow ((long) &be_argument::type_id); if (arg) { if (!first) os << ", "; first = pbfalse; if (sigType != OP_Invoke) { os << arg->Signature (""); } os << " " << *arg->local_name (); } } delete i; #if defined(CONTEXT_SUPPORT) // ADD CONTEXT if (context ()) { if (!first) { os << ", "; } first = pbfalse; if (sigType != OP_Invoke) { os << BE_Globals::CorbaScope ("Context_ptr"); } os << " " << DDSCtxVar; } #endif if (sigType == OP_Invoke) { if (!first) { os << XBE_Ev::arg (XBE_ENV_VARN); } else { os << XBE_Ev::arg (XBE_ENV_VAR1); } } else { if (!first) { os << XBE_Ev::arg (XBE_ENV_ARGN); } else { os << XBE_Ev::arg (XBE_ENV_ARG1); } } os << ")" << ends; ret = os.str ().c_str (); return ret; }
DDS_StdString be_operation::ReplySignature (ExceptionStatus excStat, OP_SignatureType sigType) { UTL_ScopeActiveIterator *i = new UTL_ScopeActiveIterator (this, IK_decls); ostringstream os; DDS_StdString ret = ""; AST_Decl *d; DDS_StdString op_suffix = ""; // VOID RETURN if (sigType == OP_Declaration || sigType == OP_Implementation) { os << "void "; } if (excStat == OP_NoException) { // no suffix } else if (excStat == OP_Exception) { op_suffix = "_exc"; } else { op_suffix = "_retry"; } // OP NAME os << "handle_" << LocalName () << op_suffix; // GENERATE PARAMETER LIST os << "("; os << "DDS::Codec::RequestId rid, "; os << "DDS::Stub_ptr stub"; if (excStat == OP_NoException) { // GENERATE RETURN if (HasReturn ()) { assert (returnType); os << ", "; if (returnType->IsFixedLength () && returnType->IsStructuredType ()) { os << returnType->MakeSignature (VT_InOutParam, ""); } else { os << returnType->MakeSignature (VT_Return, ""); } } for (; !(i->is_done ()); i->next ()) { be_argument *arg; d = i->item (); arg = (be_argument *) d->narrow ((long) &be_argument::type_id); if (arg) { if (arg->is_out_arg () || arg->is_inout_arg ()) { be_Type *argtype = be_Type::_narrow (arg->field_type ()); os << ", "; if (sigType != OP_Invoke) { if (argtype->IsFixedLength () && argtype->IsStructuredType ()) { os << argtype->MakeSignature (VT_InOutParam, ""); } else { os << argtype->MakeSignature (VT_Return, ""); } } os << " " << *arg->local_name (); } } } delete i; os << ")" << ends; } else if (excStat == OP_Exception) { os << ", DDS::Exception & exception)" << ends; } else // (excStat == OP_Retry) { os << ")" << ends; } ret = os.str ().c_str(); return ret; }
DDS_StdString be_operation::StubSignature (OP_SignatureType sigType) { UTL_ScopeActiveIterator * i = new UTL_ScopeActiveIterator (this, IK_decls); ostringstream os; pbbool first = pbtrue; DDS_StdString ret; AST_Decl * d; // Generate return type assert (returnType); if (sigType == OP_Implementation) { os << returnType->MakeSignature (VT_Return, "") << " " << nl; } else { os << returnType->MakeSignature (VT_Return, iface->ScopedName ()) << " "; } // Op name if (sigType == OP_Implementation) { os << iface->Scope (iface->StubClassname ()) << "::" << LocalName (); } else { os << LocalName (); } // Generate parameter list os << " ("; for (; !(i->is_done ()); i->next ()) { be_argument * arg; d = i->item (); arg = (be_argument *) d->narrow ((long) &be_argument::type_id); if (arg) { if (!first) { os << ", "; } first = pbfalse; os << arg->Signature (iface->ScopedName ()); os << " " << *arg->local_name (); } } delete i; #if defined (CONTEXT_SUPPORT) // Add context if (context ()) { if (!first) { os << ", "; } first = pbfalse; os << BE_Globals::CorbaScope ("Context_ptr"); os << " " << DDSCtxVar; } #endif if (!first) { os << XBE_Ev::arg (XBE_ENV_ARGN); } else { os << XBE_Ev::arg (XBE_ENV_ARG1); } os << ")" << ends; ret = os.str().c_str(); return ret; }
DDS_StdString be_operation::ScopedBaseRequestCall () { UTL_ScopeActiveIterator * i = new UTL_ScopeActiveIterator (this, IK_decls); ostringstream os; pbbool first = pbtrue; DDS_StdString ret; AST_Decl * d; DDS_StdString ifaceBasename_nocolons = NoColons (iface->ScopedName ()); if (ifaceBasename_nocolons.length ()) { os << ifaceBasename_nocolons << "::" << LocalName (); } else { os << LocalName (); } // GENERATE PARAMETER LIST os << "("; for (; !(i->is_done ()); i->next ()) { be_argument * arg; d = i->item (); arg = (be_argument *) d->narrow ((long) &be_argument::type_id); if (arg) { if (!first) { os << ", "; } first = pbfalse; os << " " << arg->LocalName (); } } delete i; // ADD CONTEXT if (context ()) { if (!first) os << ", "; first = pbfalse; os << " " << DDSCtxVar; } // THIS IS FOR PROPERTIES if (!first) os << ", "; os << "0"; first = pbfalse; os << ")" << ends; ret = os.str().c_str(); return ret; }
DDS_StdString be_operation::BaseSignature (const DDS_StdString & implclassname) { UTL_ScopeActiveIterator * i = new UTL_ScopeActiveIterator (this, IK_decls); ostringstream os; pbbool first = pbtrue; DDS_StdString ret; AST_Decl * d; bool fullScope = (iface->BaseClassname () != implclassname); // GENERATE RETURN TYPE assert (returnType); if (fullScope) { os << returnType->MakeSignature (VT_Return, "") << " "; } else { os << returnType->MakeSignature (VT_Return, iface->ScopedName ()) << " "; } os << LocalName (); // GENERATE PARAMETER LIST os << " ("; for (; !(i->is_done ()); i->next ()) { be_argument *arg; d = i->item (); arg = (be_argument *) d->narrow ((long) &be_argument::type_id); if (arg) { if (!first) os << ", "; first = pbfalse; if (fullScope) { os << arg->Signature (""); } else { os << arg->Signature (iface->ScopedName ()); } os << " " << *arg->local_name (); } } delete i; #if defined(CONTEXT_SUPPORT) // // add context // if (context ()) { if (!first) { os << ", "; } first = pbfalse; os << BE_Globals::CorbaScope ("Context_ptr"); os << " " << DDSCtxVar; } #endif if (!first) { os << XBE_Ev::arg (XBE_ENV_ARGN); } else { os << XBE_Ev::arg (XBE_ENV_ARG1); } os << ")" << ends; ret = os.str().c_str(); return ret; }