예제 #1
0
void be_sequence::Generate (be_ClientHeader& source)
{
   DDS_StdString scopedName = typeName;

   if (BE_Globals::ignore_interfaces && IsInterfaceDependant ())
   {
      return;
   }

   if (Generated ())
   {
      return;
   }

   if (anonymous && !isPrimitiveSeq && !isStringSeq
       && (!baseType->IsSequenceType ()
           || generatedSequences.find (baseType->TypeName ())
           == generatedSequences.end ()))
   {
      be_root::DeferSequence (this);
      deferred = pbtrue;
      return;
   }

   if (generatedSequences.find (scopedName) == generatedSequences.end ())
   {
      Generated (pbtrue);
      generatedSequences[scopedName] = scopedName;

      if (anonymous)
      {
         baseType->GenerateFwdDecls (source);
      }

      GenerateSequence (source);
      GenerateAuxTypes (source);

      be_root::AddStreamOps (*this);
      be_root::AddAnyOps (*this);
      be_root::AddPutGetOps (*this);
      be_root::AddImplementations (*this);
      be_root::AddTypedef (*this);
      be_root::AddTypecode (*this);
   }
}
예제 #2
0
void
be_typedef::Generate(be_ClientHeader& source)
{
   if (BE_Globals::ignore_interfaces && IsInterfaceDependant ())
   {
      return;
   }

   if (!Generated())
   {
      be_Type * btype;

      m_generated = TRUE;

      if (base_type() &&
          (btype = (be_Type*)base_type()->narrow((long) & be_Type::type_id)))
      {
         if (m_generateBase)
         {
            be_CodeGenerator * cg;
            if ((cg = (be_CodeGenerator *) btype->narrow((long) & be_CodeGenerator::type_id)))
            {
               cg->isAtModuleScope (this->isAtModuleScope());
            }
            btype->GenerateType(source);
         }
         else
         {
            btype->GenerateTypedefs(enclosingScope, *this, source);

            be_root::AddTypedef(*this);
            be_root::AddTypecode(*this);
         }
      }
      else
      {
         assert(pbfalse);
      }
   }
}
예제 #3
0
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);
   }
}
예제 #4
0
void be_exception::Generate (be_ClientHeader & source)
{
   if (!Generated ())
   {
      ostream & os = source.Stream ();
      be_Tab tab (source);
      DDS_StdString lname = LocalName ();

      Generated (pbtrue);

      be_root::AddGlobalDeclarations (this);
      be_root::AddAnyOps (*this);
      be_root::AddStreamOps (*this);
      be_root::AddTypedef (*this);
      be_root::AddTypecode (*this);

      GenerateOpenClassDefinition (source);
      GenerateClassDeclarations (source);
      SetAccess (source, CA_PUBLIC);

      // now define nested types

      be_CodeGenerator::Generate (source);

      // generate _downcast

      os << tab << "static " << lname << "* _downcast ("
         << "DDS::Exception *);" << nl;
      os << tab << "static const " << lname << "* _downcast ("
         << "const DDS::Exception *);" << nl;

      // generate factory and builder

      os << tab << "static DDS::Exception * factory ();" << nl;
      os << tab << "static DDS::ExceptionInitializer m_initializer;" << nl << nl;

      // generate inline default constructor

      os << tab << lname << " () {};" << nl;

      // generate convenience constructor

      if (nmembers())
      {
         GenerateConvenienceConstructor (source);
      }

      // generate copy constructor

      os << tab << lname << " (const " << lname << " &);" << nl;

      // generate assignment operator

      os << tab << lname << "& operator = " << "(const " << lname << " &);" << nl;

      // generate duplicate

      os << tab << "virtual DDS::Exception * _clone () const;" << nl;

      // generate raise

      os << tab << "virtual void _raise (" << XBE_Ev::arg (XBE_ENV_ARG1)
         << ") const;" << nl;

      // generate name

      os << tab << "virtual const char * _name () const { return m_name; };" << nl;

      // generate repository id

      os << tab << "virtual const char * _rep_id () const { return m_id; };" << nl;

      // generate virtual destructor

      os << tab << "virtual ~" << lname << " () {}" << nl;

      GenerateMembers (source);
      SetAccess (source, CA_PRIVATE);

      os << tab << "static const char * m_name;" << nl;
      os << tab << "static const char * m_id;" << nl;

      GenerateCloseClassDefinition (source);

      be_root::GenerateDependants
      (
         source,
         SequenceMemberTypeName (),
         EnclosingScope ()
      );
   }
}
예제 #5
0
void be_structure::Generate (be_ClientHeader& source)
{
   if (BE_Globals::ignore_interfaces && IsInterfaceDependant ())
   {
      return;
   }

   if (!Generated())
   {
      be_root::AddAnyOps(*this);
      be_root::AddPutGetOps(*this);
      be_root::AddStreamOps(*this);
      be_root::AddTypedef(*this);
      be_root::AddTypecode(*this);

      ostream & os = source.Stream();
      DDS_StdString scopedName = ScopedName();
      DDS_StdString relativeName;
      be_Tab tab(source);
      TList<be_field *>::iterator mit;
      be_field * field;

      Generated (pbtrue);

      be_root::GenerateDependants(source, SequenceMemberTypeName(),
                                  EnclosingScope());

      g_cppScopeStack.Push(m_cppType);

      // struct definition

      os << nl;
      os << tab << "struct " << DLLMACRO << LocalName () << nl;
      os << tab << "{" << nl;
      source.Indent ();

      // declare nested types

      be_CodeGenerator::Generate(source);

      // member declarations

      for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
      {
         field = *mit;
         relativeName = BE_Globals::RelativeScope
            (scopedName, field->StructMemberTypeName ());
         os << tab << relativeName << " "
            << field->get_local_name() << ";" << nl;
      }

      source.Outdent();

      source.Stream() << tab << "};" << nl << nl;

      g_cppScopeStack.Pop();

      GenerateAuxTypes (source);

      be_root::GenerateDependants(source, SequenceMemberTypeName(),
                                  EnclosingScope());
   }
}
예제 #6
0
void be_structure::Generate (be_ClientHeader& source)
{
   if (BE_Globals::ignore_interfaces && IsInterfaceDependant ())
   {
      return;
   }

   if (!Generated())
   {
      be_root::AddAnyOps(*this);
      be_root::AddPutGetOps(*this);
      be_root::AddStreamOps(*this);
      be_root::AddTypedef(*this);
      be_root::AddTypecode(*this);

      ostream & os = source.Stream();
      DDS_StdString scopedName = ScopedName();
      DDS_StdString relativeName;
      be_Tab tab(source);
      TList<be_field *>::iterator mit;
      be_field * field;

      Generated (pbtrue);

      be_root::GenerateDependants(source, SequenceMemberTypeName(),
                                  EnclosingScope());

      g_cppScopeStack.Push(m_cppType);

      // struct definition

      os << nl;
      os << tab << (BE_Globals::isocpp_new_types ? "class " : "struct ") << DLLMACRO << LocalName ()
                <<  (BE_Globals::isocpp_new_types ? " OSPL_DDS_FINAL" : "") << nl;
      os << tab << "{" << nl;
      if (BE_Globals::isocpp_new_types)
        os << tab << "public:" << nl;

      source.Indent();

      // declare nested types

      source.Indent();
      be_CodeGenerator::Generate(source);

      // member accessor functions for isocpp new types
      if (BE_Globals::isocpp_new_types)
      {
        /** @internal
         * @todo OSPL-3369 Repetition; the sort of code people go to hell
         * for (rightfully); is_sequency is already evideantally a stupid name; &c... */
        // Constructors
        if (m_fields.size() > 0)
        {
          os << tab << LocalName() << "() {}" << nl;
          os << tab << "explicit " << LocalName() << "(" << nl;
          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
            field = *mit;
            bool is_sequency = !(field->get_be_type()->IsPrimitiveType()
                                  || field->get_be_type()->IsEnumeratedType());
            relativeName = BE_Globals::RelativeScope
                (scopedName, field->StructMemberTypeName ());
            TList<be_field *>::iterator final_field = m_fields.end();
            --final_field;
            os << tab << tab << (is_sequency ? "const " : "") << relativeName
                << (is_sequency ? "& " : " ") << field->get_local_name();
            if (mit == final_field)
              os << ")";
            else
              os <<"," << nl;
          }
          os << tab << ":" << nl;
          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
            field = *mit;
            TList<be_field *>::iterator final_field = m_fields.end();
            --final_field;
            os << tab << tab << tab << field->get_local_name() << "_(" << field->get_local_name() << ")" << (mit == final_field ? " {}" : ",") << nl;
          }
        }
        // C++ 11 move constructor, copy consructor, and assignement ops
        source.Outdent();
        os << "#ifdef OSPL_DDS_CXX11" << nl;
        os << "#  ifdef OSPL_CXX11_NO_FUNCTION_DEFAULTS" << nl;
        source.Indent();
        os << tab << LocalName() << "(const " << LocalName() << "& _other)" << nl;
        if (m_fields.size() > 0)
        {
          os << tab << ":" << nl;
          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
            field = *mit;
            TList<be_field *>::iterator final_field = m_fields.end();
            --final_field;
            os << tab << tab << tab << field->get_local_name() << "_(_other." << field->get_local_name() << "_)" << (mit == final_field ? "" : ",") << nl;
          }
        }
        os << tab << "{}" << nl;
        os << tab << LocalName() << "(" << LocalName() << "&& _other)" << nl;
        if (m_fields.size() > 0)
        {
          os << tab << ":" << nl;
          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
            field = *mit;
            TList<be_field *>::iterator final_field = m_fields.end();
            --final_field;
            os << tab << tab << tab << field->get_local_name() << "_(::std::move(_other." << field->get_local_name() << "_))" << (mit == final_field ? "" : ",") << nl;
          }
        }
        os << tab << "{}" << nl;
        os << tab <<  LocalName() << "& operator=(" << LocalName() << "&& _other)" << nl;
        os << tab << "{" << nl ;
        if (m_fields.size() > 0)
        {
          os << tab << tab << "if (this != &_other)" << nl;
          os << tab << tab << "{" << nl;
          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
            field = *mit;
            TList<be_field *>::iterator final_field = m_fields.end();
            --final_field;
            os << tab << tab << tab << field->get_local_name() << "_ = ::std::move(_other." << field->get_local_name() << "_);" << nl;
          }
          os << tab << tab << "}" << nl;
        }
        os << tab << tab << "return *this;" << nl;
        os << tab << "}" << nl;
        os << tab <<  LocalName() << "& operator=(const "  << LocalName() << "& _other)" << nl;
        os << tab << "{" << nl ;
        if (m_fields.size() > 0)
        {
          os << tab << tab << "if (this != &_other)" << nl;
          os << tab << tab << "{" << nl;
          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
            field = *mit;
            TList<be_field *>::iterator final_field = m_fields.end();
            --final_field;
            os << tab << tab << tab << field->get_local_name() << "_ = _other." << field->get_local_name() << "_;" << nl;
          }
          os << tab << tab << "}" << nl;
        }
        os << tab << tab << "return *this;" << nl;
        os << tab << "}" << nl;
        source.Outdent();
        os << "#  else" << nl;
        source.Indent();
        os << tab << LocalName() << "(const " << LocalName() << "& _other) = default;" << nl;
        os << tab << LocalName() << "(" << LocalName() << "&& _other) = default;" << nl;
        os << tab <<  LocalName() << "& operator=(" << LocalName() << "&& _other) = default;" << nl;
        os << tab <<  LocalName() << "& operator=(const "  << LocalName() << "& _other) = default;" << nl;
        source.Outdent();
        os << "#  endif" << nl;
        os << "#endif" << nl;
        source.Indent();
        for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
        {
          field = *mit;
          bool is_sequency = !(field->get_be_type()->IsPrimitiveType()
                                || field->get_be_type()->IsEnumeratedType());
          relativeName = BE_Globals::RelativeScope
              (scopedName, field->StructMemberTypeName ());
          // const get accessor
          os << tab << (is_sequency ? "const " : "") << relativeName << (is_sequency ? "& " : " ")
              << field->get_local_name() << "() const { return this->" << field->get_local_name() << "_; }" << nl;
          // reference get accessor
          os << tab << relativeName << "& "
              << field->get_local_name() << "() { return this->" << field->get_local_name() << "_; }" << nl;
          // const set accessor
          os << tab << "void "
              << field->get_local_name() << (is_sequency ? "(const " : "(") << relativeName
              << (is_sequency ? "&" : "") << " _val_) { this->" << field->get_local_name() << "_ = _val_; }" << nl;
          source.Outdent();
          if (!(field->get_be_type()->IsPrimitiveType()
                  && !field->get_be_type()->IsEnumeratedType())) {
              os << "#ifdef OSPL_DDS_CXX11" << nl;
              source.Indent();
              // C++ 11 move assignement op
              os << tab << "void "
                      << field->get_local_name() <<  "(" << relativeName << "&& _val_) { this->" << field->get_local_name() << "_ = _val_; }" << nl;
              source.Outdent();
              os << "#endif" << nl;
          }
          source.Indent();
        }
      }

      if (BE_Globals::gen_equality)
      {
          os << tab << "bool operator==(const " << LocalName() << "& _other) const" <<
            nl << tab << "{" << nl << tab << tab << "return ";
          DDS_StdString relName;
          for(mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
            field = *mit;
            relName = BE_Globals::RelativeScope
            (scopedName, field->get_local_name());
            TList<be_field *>::iterator final_field = m_fields.end();
            --final_field;

            if(mit != m_fields.begin())
                os << tab << tab;

            os  << relName << (BE_Globals::isocpp_new_types ? "_" : "")
                << " == _other."
                << relName << (BE_Globals::isocpp_new_types ? "_" : "")
                << (mit != final_field ? " &&" : ";") << nl;

          }
          os << tab << "}" << nl;

          os << tab << "bool operator!=(const " << LocalName() << "& other) const" <<
                nl << tab << "{" << nl << tab << tab << "return !(*this == other);"
                << nl << tab << "}" << nl;

      }

      // member declarations
      for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
      {
         field = *mit;
         relativeName = BE_Globals::RelativeScope
            (scopedName, field->StructMemberTypeName ());
         os << tab << relativeName << " "
            << field->get_local_name() << (BE_Globals::isocpp_new_types ? "_" : "") << ";" << nl;
      }

      source.Outdent();
      source.Outdent();

      source.Stream() << tab << "};" << nl << nl;
      g_cppScopeStack.Pop();



      if (BE_Globals::isocpp_test_methods)
      {
          //Get base filename and append _testmethod.h
          DDS_StdString BaseFilename;
          BaseFilename = StripExtension(source.Filename());
          BaseFilename += "_testmethod.h";

          //Open or append to file
          be_Source testsource;
          ostream & ts = testsource.Stream();
          if(!testsource.Open(BaseFilename))
              cerr << "Cannot open: " << BaseFilename << endl;

          testsource.Indent();
          ts <<  "namespace {" << nl
                              <<  "template <>" << nl <<  "::std::vector< ::"
                              << ScopedName() <<  " > generate_test_values< ::"
                              << ScopedName() << " >()"  << nl
                              << "{" << nl;

          ts << tab << "::std::vector< ::" << ScopedName() << " > values;" << nl
                              << tab << "::" << ScopedName() << " next;" << nl
                              << tab << "::std::size_t biggest = 0;" << nl;

          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
             field = *mit;
             relativeName = field->StructMemberTypeName ();

             ts << tab <<"::std::vector< " << field->StructMemberTypeName() << " > " << field->get_local_name() << "_ = generate_test_values< "
                                 << field->StructMemberTypeName() << " >();" << nl;
             ts << tab << "if(" << field->get_local_name() << "_.size() > biggest)"
                                 << nl << tab << tab << "biggest = " << field->get_local_name() << "_.size();"
                                 << nl;
          }
          ts << tab << "for(::std::size_t i = 0; i < biggest; ++i)" << nl << tab << "{" << nl;
          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
             field = *mit;
             relativeName = BE_Globals::RelativeScope(scopedName, field->StructMemberTypeName ());

             ts << tab << tab << "next." << field->get_local_name() << "_ = " << field->get_local_name()
                << "_[i < " << field->get_local_name() << "_.size()? i : " << field->get_local_name()
                << "_.size() -1];" << nl;
          }
          ts << tab << tab << "values.push_back(next);" << nl
             << tab << "}" << nl
             << tab << "return values;" << nl;
          ts << "} }" << nl << nl;
          testsource.Outdent();
          testsource.Close();
      }

      GenerateAuxTypes (source);

      be_root::GenerateDependants(source, SequenceMemberTypeName(),
                                  EnclosingScope());
   }
}